winIDEA SDK
dynamic_options.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
7
8winidea_id = ''
9
10
11def printAllBPs():
12
13 numOfBreakpoints = ideCtrl.getDynamicOptionSize('/IDE/ExecBPs.BP')
14
15 for i in range(0, numOfBreakpoints):
16 print('- location: ' + ideCtrl.getOptionStr('/IDE/ExecBPs.BP[' + str(i) + '].Location'))
17 print(' enabled: ' + str(ideCtrl.getOptionInt('/IDE/ExecBPs.BP[' + str(i) + '].Enabled')))
18 print(' condition: ' + str(ideCtrl.getOptionInt('/IDE/ExecBPs.BP[' + str(i) + '].Condition')))
19 print(' count: ' + str(ideCtrl.getOptionInt('/IDE/ExecBPs.BP[' + str(i) + '].Count')))
20 # example of the long form of getOptionStr
21 print(' expression: ' + ideCtrl.getOptionStr(ic.ofDestIDE, '', 'ExecBPs.BP[' + str(i) + '].Expression'))
22
23
24cmgr = ic.ConnectionMgr()
25cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
26
27ideCtrl = ic.CIDEController(cmgr)
28
29numOfBreakpoints = ideCtrl.getDynamicOptionSize('/IDE/ExecBPs.BP')
30
31print("Number of breakpoints: ", numOfBreakpoints)
32
33numOfDlFiles = ideCtrl.getDynamicOptionSize('/IDE/Debug.DownloadFiles.File')
34print("Number of dl. files: ", numOfDlFiles)
35
36downloadFiles = ic.StrVector()
37ideCtrl.getDynamicOptions('/IDE/Debug.DownloadFiles.File',
38 'Path', downloadFiles)
39print("List of download files: ")
40for downloadFile in downloadFiles:
41 print(downloadFile)
42
43if numOfBreakpoints < 3:
44 raise Exception("Please define at least three breakpoints in winIDEA before running this script!")
45
46print(r'Index of option "common\main.cpp"::27:',
47 ideCtrl.findDynamicOption('/IDE/ExecBPs.BP',
48 'Location',
49 r'"src\main.cpp"::27'))
50
51print('Breakpoints defined before running this script:')
52printAllBPs()
53
54# insert the option
55ideCtrl.addDynamicOption('/IDE/ExecBPs.BP', -1)
56# example of the long form of setOption
57ideCtrl.setOption(ic.ofDestIDE, '', 'ExecBPs.BP[1].Enabled', 'false')
58
59
60# append the option with default values
61ideCtrl.addDynamicOption(ic.ofDestIDE, '', 'ExecBPs.BP')
62
63
64print('Two new BPs added:')
65printAllBPs()
66
67
68# remove dynamic items
69ideCtrl.removeDynamicOption('/IDE/ExecBPs.BP', 0)
70print('BP at index 0 removed:')
71printAllBPs()
72ideCtrl.removeDynamicOption(ic.ofDestIDE, '', 'ExecBPs.BP')
73
74
75# verify the result
76numOfBreakpoints = ideCtrl.getDynamicOptionSize('/IDE/ExecBPs.BP')
77
78if numOfBreakpoints != 0:
79 raise Exception("Number of breakpoints is expected to be 0, but it is " + str(numOfBreakpoints))
80
81# append dynamic option and get its URL
82print('Added option 1: ', ideCtrl.addDynamicOptionUrl('/IDE/ExecBPs.BP', -1))
83print('Added option 2: ', ideCtrl.addDynamicOptionUrl('/IDE/ExecBPs.BP', -1))
84