winIDEA SDK
Loading...
Searching...
No Matches
stack_frames.py
1# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
2#
3# (c) TASKING Germany GmbH, 2023
4
5import isystem.connect as ic
6
7winidea_id = ''
8
9
10def initTarget(cmgr):
11 """
12 This function initializes the target. Customize it according to
13 your needs.
14 """
15
16 debugCtrl = ic.CDebugFacade(cmgr)
17
18 debugCtrl.download()
19 debugCtrl.runUntilFunction("main")
20 debugCtrl.waitUntilStopped()
21
22 # configure global variables so that required functions will be executed
23 debugCtrl.modify(ic.IConnectDebug.fMonitor, "debug_flag", "true")
24
25 debugCtrl.run()
26
27 return debugCtrl
28
29
30def printVars(dataCtrl, cvars):
31 for cvar in cvars:
32 print(' Name: ', cvar.getName())
33 print(' Type: ', cvar.getType())
34 print(' Value: ', dataCtrl.evaluate(ic.IConnectDebug.fMonitor, cvar.getName()).getResult())
35 print(' ----')
36
37
38def printStackFrame(dataCtrl, stackFrame, partitions):
39 print('Address: ', stackFrame.getAddress())
40 print('Mem area: ', stackFrame.getMemArea())
41 print('File name: ', stackFrame.getFileName())
42 print('Line num: ', stackFrame.getLineNumber())
43 print('Partition: ', partitions[1][stackFrame.getPartition()])
44 function = stackFrame.getFunction()
45 print('Function: ', function.getName())
46 print(' Scope: ', function.getScope())
47 print(' Type: ', function.getReturnType())
48 print(' Module idx: ', function.getModuleIndex())
49 print(' Parameters:')
50 printVars(dataCtrl, function.getParameters())
51 print(' Local variables:')
52 printVars(dataCtrl, function.getLocalVars())
53
54
55def main():
56 cmgr = ic.ConnectionMgr()
57 cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
58 debugCtrl = initTarget(cmgr)
59
60 debugCtrl.setBP('test_func1')
61 debugCtrl.run()
62 debugCtrl.waitUntilStopped()
63 debugCtrl.stepHigh()
64 debugCtrl.stepHigh()
65
66 dataCtrl = ic.CDataController2(cmgr)
67
68 stackFrames = ic.StackFrameVector()
69 dataCtrl.getStackFrames(False, False, stackFrames)
70
71 paths = ic.StrVector()
72 fileNames = ic.StrVector()
73 dataCtrl.getPartitions(paths, fileNames)
74
75 downloadFiles = [list(paths), list(fileNames)]
76
77 stackFrameIdx = 0
78 for stackFrame in stackFrames:
79 dataCtrl.setStackFrameContext(0, stackFrameIdx)
80 printStackFrame(dataCtrl, stackFrame, downloadFiles)
81 stackFrameIdx += 1
82
83
84if __name__ == "__main__":
85 main()