Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing multiple variables in GDB?

Tags:

c

debugging

gdb

I am encountering a problem to print multiple variables (say 25) in a function on GDB Prompt.

Is there any convenient way to do this instead of printing every variables manually ?

can I have a script or a simpler way which can do my job ?

like image 923
San Avatar asked Jul 05 '13 03:07

San


1 Answers

You can print multiple values using printf command in gdb.

printf "%d,%d\n", a, b

To use it in future, you can either define a gdb-function or use gdb-history feature.

  1. To define a gdb-function, create/modify file $HOME/.gdbinit with the following conten,

    define print_all
        printf "%d,%d\n", a, b
    end
    document print_all
        Prints all my variables.
    end
    

    Then you can use print_all as a command.

  2. For history trick, create/modify file $HOME/.gdbinit with the following content:

    set history filename ~/.gdb_history
    set history save
    

    and get it using ctrl+r same like in bash. Actual gdb-history answer is here.

like image 81
VoidPointer Avatar answered Nov 10 '22 22:11

VoidPointer