6This script tries to set breakpoint on the requested line, but if this
7line does not generate any code, then it tries to find the first line,
8where breakpoint can be set.
12import isystem.connect
as ic
18def initTarget(isRunUntilMain):
20 Initializes target - downloads only if target
is not in stopped state.
23 isRunUntilMain -
if true, target
is reset, then runUntilFunction(
'main')
26 Return: ic.ConnectionMgr(), ic.CDebugFacade(cmgr)
29 print('isystem.connect version: ' + ic.getModuleVersion())
31 cmgr = ic.ConnectionMgr()
32 cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
34 debugCtrl = ic.CDebugFacade(cmgr)
37 cpuStatus = debugCtrl.getCPUStatus()
39 if not cpuStatus.isStopped():
44 debugCtrl.runUntilFunction(
"main")
45 debugCtrl.waitUntilStopped()
47 return cmgr, debugCtrl
50def findLine(addrCtrl, functionName, searchString):
51 lineDesc = ic.CLineDescription(ic.CLineDescription.E_RESOURCE_FUNCTION,
56 ic.CLineDescription.E_SEARCH_ANY,
57 ic.CLineDescription.E_MATCH_PLAIN,
60 ic.CLineDescription.ELocalHost)
62 lineLocation = addrCtrl.getSourceLocation(lineDesc)
67def setAdaptiveBPInFile(debugCtrl, fileName, startLine, maxOffset):
69 This function tries to find the first line, where breakpoint can be set.
73 debugCtrl - instance of CDebugFacade
75 fileName - name of source file to set breakpoint in. Make sure that it also
76 includes path,
if necessary. See Symbol browser
in winIDEA,
77 tab Modules, to find out correct path.
79 startLine - the first line where we
'd like to set a breakpoint
81 maxOffset - maximum number of lines, where to search for line which
82 generated object code. If positive, following lines are searched,
83 if negative, preceding lines are searched. Should
not be 0.
89 for line
in range(startLine, startLine + maxOffset, int(math.copysign(1, maxOffset))):
90 addresses = debugCtrl.getAddressOfSourceLine(fileName, line)
91 if addresses.size() > 0:
92 debugCtrl.setBP(line, fileName)
97 raise Exception(
"Can not set breakpoint at '{}', line {}, maxOffset = {}!"
98 .format(fileName, startLine, maxOffset))
101def setAdaptiveBPInFunction(debugCtrl, addrCtrl, functionName, searchString, maxOffset):
103 This function tries to find the first line, where breakpoint can be set.
107 debugCtrl - instance of CDebugFacade
109 addrCtrl - instance of CAddressController
111 functionName - name of function to set breakpoint in.
113 searchString - string
in line where we want to set a breakpoint
115 maxOffset - maximum number of lines, where to search
for line which
116 generated object code. If positive, following lines are searched,
117 if negative, preceding lines are searched. Should
not be 0.
119 lineLocation = findLine(addrCtrl, functionName, searchString)
120 print('file: ', lineLocation.getFileName())
121 print(
'line: ', lineLocation.getLineNumber())
123 setAdaptiveBPInFile(debugCtrl,
124 lineLocation.getFileName(),
125 lineLocation.getLineNumber(),
129cmgr, debugCtrl = initTarget(
False)
130addrCtrl = ic.CAddressController(cmgr)
132setAdaptiveBPInFile(debugCtrl,
'src\\utils.cpp', 271, -50)
133setAdaptiveBPInFunction(debugCtrl, addrCtrl,
'fibonacci',
'}', 10)
134setAdaptiveBPInFunction(debugCtrl, addrCtrl,
'trim',
'for', -10)
135setAdaptiveBPInFunction(debugCtrl, addrCtrl,
'split',
'if (strstr(input, delimiter) == NULL)', 10)