winIDEA SDK
Loading...
Searching...
No Matches
test_seed_get_stack_usage.py
# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
#
# (c) TASKING Germany GmbH, 2023
import isystem.connect as ic
winidea_id = ''
def test_seedGetStackUsage():
connMgr = ic.ConnectionMgr()
connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
# Initialize controllers
sessCtrl = ic.CSessionCtrl(connMgr)
execCtrl = ic.CExecutionController(connMgr)
addrCtrl = ic.CAddressController(connMgr)
cfgCtrl = ic.CConfigurationController(connMgr)
dataCtrl = ic.CDataController(connMgr)
# Get stack end from program symbols
userStackEnd = addrCtrl.getVariableAddress('_edata')
# Define addresses and value to write to the unused stack area
endAddr = userStackEnd.getAddress()
startAddr = endAddr - 1024
value = 0x55
# Get current process and choose option controller for its StackUsage
stack_cfg = cfgCtrl.ide_app().opt('StackUsage')
# Configure stack
stack_cfg.set_bool('Use', True)
stack_cfg.set_uint('Pattern', value)
stack_cfg.set('Position', 'End')
stack_cfg.set('Start', str(hex(startAddr)))
stack_cfg.set('End', str(hex(endAddr)))
sessCtrl.begin_reset()
execCtrl.run()
execCtrl.stop()
dataCtrl.seedStack()
stackUsage = dataCtrl.getStackUsage()
print(f"Base address: {stackUsage.getBase()}")
print(f"Stack size: {stackUsage.getSize()}")
print(f"Used stack size: {stackUsage.getUsed()}")
stack_cfg.set_bool('Use', False)
if __name__ == "__main__":
test_seedGetStackUsage()