Print multiple variables with one command in GDB

后端 未结 4 1389
南笙
南笙 2020-12-14 13:45

I want to execute the very simple command

print var1, var2, var3, var4 

in gdb to examine the values of the vars from time to time.

相关标签:
4条回答
  • 2020-12-14 14:29

    Use the printf command. It's a bit of a hassle, but it gives good control over the formatting. From the command line:

    (gdb) help printf
    printf "printf format string", arg1, arg2, arg3, ..., argn
    This is useful for formatted output in user-defined commands.
    

    The format string is like in C (%d for normal size ints, %s for null terminated strings, etc.).

    0 讨论(0)
  • 2020-12-14 14:33

    There may be a simpler solution, but you might be able to put together something using GDB macros: http://www.ibm.com/developerworks/aix/library/au-gdb.html

    0 讨论(0)
  • 2020-12-14 14:37

    Use Macros:

    For example to continue to next break point and print

    (gdb) define prm 
    

    Type commands for definition of prm. End with a line saying just end.

    >continue
    >print var1
    >print var2
    >print var3
    >end
    
    (gdb) prm
    $5 = 0
    $6 = 10
    $7 = -1
    
    0 讨论(0)
  • 2020-12-14 14:42

    You can simply do this

    print {var1,var2,var3,var4}
    

    This will do the job.

    0 讨论(0)
提交回复
热议问题