I have a script to work out how much free stack space there is in each FreeRTOS task. GDB’s language is set to auto
. The script works fine when the current language is c
, but fails when the current language is ada
.
I have, in the class Stacks
,
tcb_t = gdb.lookup_type("TCB_t")
int_t = gdb.lookup_type("int")
used to:
find {Ada task control block}.Common.Thread,
thread = atcb["common"]["thread"]
convert to a pointer to the FreeRTOS task control block,
tcb = thread.cast(Stacks.tcb_t.pointer()).dereference()
find the logical top of the stack
stk = tcb["pxStack"].cast(Stacks.int_t.pointer())
Now I need to loop logically down the stack until I find an entry not equal to the initialised value,
free = 0
while stk[free] == 0xa5a5a5a5:
free = free + 1
which works fine if the current frame’s language is c
, but if it’s ada
I get
Python Exception <class 'gdb.error'> not an array or string: Error occurred in Python command: not an array or string
I’ve traced this to the expression stk[free]
, which is being interpreted using the rules of the current language (in Ada, array indexing uses parentheses, so it would be stk(free)
, which is of course illegal since Python treats it as a function call).
I’ve worked round this by
def invoke(self, arg, from_tty):
gdb.execute("set language c")
...
gdb.execute("set language auto")
but it seems wrong not to set the language back to what it was originally.
So,
- is there a way of detecting the current GDB language setting from Python?
- is there an alternate way of indexing that doesn’t depend on the current GDB language setting?