Search code examples
cgdbu-boot

in gdb, can we set a variable as an expression?


In the u-boot C code, the value "gd" is declared like this. (arm)

register volatile gd_t *gd asm ("r9")  

and register r9 contains the pointer to the struct global_data. (typedef'd to gd_t)

While debugging/analying, to see gd->malloc_base in the C code, typing "p gd->malloc_base" doesn't work. it says Missing ELF symbol "gd".
I later learned that I should do "p ((gd_t *)$r9)->malloc_base" to see the value. I'm typing this kind of command many times a day. Isn't there a way that I can assign a variable in gdb that represents ((gd_t *)$r9)? and why doesn't gdb recognize the value gd in the code?
What I want to do is make a variable representing ((gd_t *)$r9) so that I can use it like gd->ram_top or gd->env_has_init, etc. according to the value I'm curious about.


Solution

  • This is the comment of @ssbssa to my quetion (thanks @ssbssa). I asked him to put his answer but he doesn't. so I add the answer myself.
    You can define macro like macro define gd ((gd_t *)$r0) and then you can later use p /x gd->reloc_off or p /x gd->flags. Of course you can put this macro define command in the command file and start gdb like this arm-none-eabi-gdb u-boot -x gdb_command.