On Thu, 2017-08-03 at 19:21 -0400, Serhei Makarov wrote:
> Hello all,
> 
> I'm working on a project based on Valgrind and I have a question about
> Valgrind's debuginfo interface. Namely, is there any functionality to
> obtain the offset of a variable, given its name?
> 
> The Valgrind instrumentation tool I'm writing needs to access the
> contents of some variables specified by the user of the tool. I've
> looked at include/pub_tool_debuginfo.h as well as
> coregrind/pub_core_debuginfo.h (in the 3.13 codebase). There are
> functions get_datasym_and_offset() and get_data_addr() which return
> the name of a variable, given a known memory address, but I can't find
> anything which would let me go in the opposite direction (given a
> variable name, compute its address).
> 
> My current best bet seems to be to patch Valgrind's DWARF parser to
> store the offsets of requested variables in a table, and add some
> functions for reading the table to pub_tool_debuginfo.h. Am I correct
> in my understanding, or is there any functionality I missed which
> would let me obtain a variable offset without having to extend
> Valgrind's pub_tool_* interfaces?
Effectively, typically, Valgrind has to report information about
an address (e.g. when an error is encountered), and that is what
pub_tool_debuginfo.h provides.

If all what you need is to translate the name of a global variable
in an address, that should be relatively easy to implement,
in particular if there is no high performance requirement: you can
just scan all the loaded debug info, and compare all names
in the debug info to the searched name.
This is ok if you only have to translate once per run a variable name
into an address.
If you need to do that often, you probably should build an index
  name -> address.

Now, if what you need to translate is the name of a local (stack)
variable, then that will be more complex than the above.

Philippe



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to