Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb: printing a variable not in the current scope

I am using gdb and I was wanting to print a variable not currently in the scope. I am not sure what the exact name of the variable is so I would like to be able to change scopes rather than printing a specific variable in a specific file.

like image 655
user972276 Avatar asked Nov 23 '11 21:11

user972276


People also ask

What does @entry mean in GDB?

The @entry form refers to the value of the parameter when the function was entered. This isn't always available, but sometimes it is -- there is a DWARF extension for it, and GCC emits this when possible. There's some information here: https://sourceware.org/gdb/onlinedocs/gdb/Variables.html.

What does P do in GDB?

The usual way to examine data in your program is with the print command (abbreviated p ), or its synonym inspect . It evaluates and prints the value of an expression of the language your program is written in (see section Using GDB with Different Languages).

How do I create a variable in GDB?

You can create variables in the context of gdb for your convenience, like set $foo = ... and later reference $foo . Obviously such variables are in no way visible to the running code, however. it's not only for inspection. you can change variable values in gdb: stackoverflow.com/questions/3305164/….

What is display GDB?

Enables automatic displaying of certain expressions each time GDB stops at a breakpoint or after a step.


1 Answers

You can use the frame, up and down commands to access scopes on the stack.

frame N
f N
    Select frame number N. (The current instruction is in frame 0.)

up [N]
    Move N frames up the stack (away from frame 0).

down [N]
    Move N frames down the stack (towards frame 0).
like image 117
Neil Avatar answered Nov 15 '22 01:11

Neil