Printing multiple variables in gdb?

I ran into the problem of printing multiple variables ( say 25 ) in a function on GDB Prompt .

Is there a convenient way to do this, and not print all the variables manually?

Can I have a script or an easier way that can do my job?

+6
source share
1 answer

You can print multiple values ​​using the printf command in gdb.

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

To use it in the future, you can define the gdb function or use the gdb-history function.

  • To define the gdb function, create / modify the $HOME/.gdbinit with the following content,

     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.

  • For the story trick, create / modify the $HOME/.gdbinit with the following contents:

     set history filename ~/.gdb_history set history save 

    and use it ctrl+r , as in bash. The actual answer of gdb-history is here .

+12
source

Source: https://habr.com/ru/post/948757/


All Articles