demonking demonking - 1 year ago 69
C Question

Why is it possible to print an array but not an array of structs with gdb?

I have written a python function for gdb to print an
array to save me time,to type the same line everytime.

define print_array
print *($arg0)@(sizeof($arg0)/ sizeof($arg0[0])

It works like expected, but when I try to print an array of structs, I get the following error :

>>> print_array opcode_list
A syntax error in expression, near `'.

When I type it by hand, it works without errors.

>>> print *(opcode_list)@(sizeof(opcode_list)/sizeof(opcode_list[0]))
$2 = {[0] = {
opcode_str = 0x401484 "halt",
output = 0
}, [1] = {
opcode_str = 0x401489 "pushc",
output = 1
}, ...

Could someone explain me, what is my fault?
And also give me maybe a hint/better solution for this?

jxh jxh
Answer Source

You seem to be missing a ).

define print_array
    print *($arg0)@(sizeof($arg0)/ sizeof($arg0[0]))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download