3

Let's say I'm debugging with valgrind and gdb by doing:

$ valgrind --vgdb-error=0 ./magic

...and then in a second terminal:

$ gdb ./magic
...
(gdb) target remote | /usr/lib/valgrind/../../bin/vgdb

If I want to examine the defined-ness of some memory, I can use:

(gdb) p &batman
$1 = (float *) 0xffeffe20c
(gdb) p sizeof(batman)
$2 = 4
(gdb) monitor get_vbits 0xffeffe20c 4
ffffffff

Using three commands to do one thing is kind of annoying, especially since I usually want to do this a few times for many different variables in the same stack frame. But if I try the obvious thing, I get:

(gdb) monitor get_vbits &batman sizeof(batman)
missing or malformed address

Is it possible to get gdb to evaluate &batman and sizeof(batman) on the same line as my monitor command?

0

1 Answer 1

7

But if I try the obvious thing, I get: missing or malformed address

This is from GDB doc (http://sourceware.org/gdb/onlinedocs/gdb/Connecting.html#index-monitor-1210) for the monitor cmd:

monitor cmd

This command allows you to send arbitrary commands directly to the remote monitor. Since gdb doesn't care about the commands it sends like this, this command is the way to extend gdb—you can add new commands that only the external monitor will understand and implement.

As you can see "gdb doesn't care about the commands it sends like this". It probably means that the command after monitor is not processed in any way and sent AS IS.

What you can do to evaluate your variable on the same line is to use user defined commands in gdb (http://sourceware.org/gdb/onlinedocs/gdb/Define.html). Define your own comand and use the eval gdb command to prepare your command with necessary values (http://sourceware.org/gdb/current/onlinedocs/gdb/Output.html#index-eval-1744):

define monitor_var
  eval "monitor get_vbits %p %d", &$arg0, sizeof($arg0)
end

And then use it like this:

(gdb) monitor_var batman
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.