Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a custom name for an address in gdb?

Tags:

gdb

I'm reverse engineering a program using gdb and I'm getting confused in all the addresses I enter to various commands. Is there a way to create (and store) a custom variable so that I could say x/i my_addr_name instead of x/i 0xdeadbeef?

like image 352
d33tah Avatar asked Sep 03 '25 07:09

d33tah


1 Answers

gdb has user-definable convenience variables to hold various values.

(gdb) set $my_addr_name=$pc
(gdb) x/i $my_addr_name
=> 0x400c7d <main+390>: lea    -0xa0(%rbp),%rax
(gdb) ptype $my_addr_name
type = void (*)()

Convenience variable have a type, and the print command will make use of that, but the x command uses explicit or default formats and doesn't take the type of the expression into account.

could I have x/i 0xdeadbeff say my_addr_name+16

I don't think so, unless some additional C or python code is written. gdb's C source code has a build_address_symbolic function, which looks through the symbol tables to find the symbol nearest to an address. Short of creating a custom symbol table, then loading it with the add-symbol-file command, or writing a python extension to implement an alternative to the x command, I don't think such a customization is possible, currently.

like image 174
Mark Plotnick Avatar answered Sep 05 '25 00:09

Mark Plotnick