1

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])
end

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?

1 Answer 1

2

You seem to be missing a ).

define print_array
    print *($arg0)@(sizeof($arg0)/ sizeof($arg0[0]))
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.