winIDEA SDK
stack_frames.py
1# This script is licensed under BSD License, see file LICENSE.txt.
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
55cmgr = ic.ConnectionMgr()
56cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
57debugCtrl = initTarget(cmgr)
58
59debugCtrl.setBP('test_func1')
60debugCtrl.run()
61debugCtrl.waitUntilStopped()
62debugCtrl.stepHigh()
63debugCtrl.stepHigh()
64
65dataCtrl = ic.CDataController2(cmgr)
66
67stackFrames = ic.StackFrameVector()
68dataCtrl.getStackFrames(False, False, stackFrames)
69
70paths = ic.StrVector()
71fileNames = ic.StrVector()
72dataCtrl.getPartitions(paths, fileNames)
73
74downloadFiles = [list(paths), list(fileNames)]
75
76stackFrameIdx = 0
77for stackFrame in stackFrames:
78 dataCtrl.setStackFrameContext(0, stackFrameIdx)
79 printStackFrame(dataCtrl, stackFrame, downloadFiles)
80 stackFrameIdx += 1