|
From: Christian C. <chr...@gm...> - 2016-07-26 18:04:33
|
Hi guys,
I'm writing my first Valgrind tool, and I'm unsure of the best way to
get something done. Any suggestions?
Suppose I have a simple target program like this:
int main( int argc, const char* argv[] ) {
int x = 42;
return 0;
}
I want my tool to have this functionality: When the program's
execution is paused at the "return 0;" statement, the user can enter
this command, which my tool receives via vgdbserver:
monitor foo x
When my tool's gdb-monitor handler is invoked with the "foo x"
argument, it should resolve the memory-address, size, and content of
the inferior's variable "x".
I saw some promising leads, but none of them looks like what I want:
* "v.translate" seems designed to translate from a numeric address
to a symbolic address, but not vice versa.
* "VG_(strtok_get_address_and_size)" only performs simple
string-to-number parsing.
* "VG_(get_data_description)" seems to be on the right track,
because it searches (nearby) stack frames as well as global variables.
But it seems designed for address-to-symbol translation (I need the
opposite), and it doesn't sound smart about C's rules regarding
identifier scoping, etc.
* "pub_tool_debuginfo.h" doesn't appear to have what I need, and
(even if it were okay for a tool to #include it) neither does
"pub_core_debuginfo.h".
* Ditto for "pub_tool_gdbserver.h" and "pub_core_gdbserver.h", respectively.
(Another reason I'm doubtful that Valgrind has support for what I want
is that an example regarding "v.set hostvisibility" shows a user
having to manually resolve a C-language lvalue expression into a
numeric address,length pair.)
I have two backup plans, but I don't love either of them:
* I can resolve the symbol myself, using debug info and the current
state of the call stack. (I've never done this, but I assume it's not
too hard.) Or,
* I can write a custom GDB command (i.e., in gdb's scripting
language, or using Python), which uses GDB's facilities for converting
the string "x" to a numeric address,length pair, and then provides
that numeric pair to my Valgrind tool's "monitor" handler. The main
downside I see to this is that my end users will (I think) need to
take the additional step of making this custom command available to
their GDB sessions.
Any suggestions would be greatly appreciated. Thanks!
- Christian
|