|
From: gleepglop <dar...@ga...> - 2008-04-09 05:25:41
|
Hi, I am new to Valgrind and program understanding tools in general. (I have
used gdb once or twice, but I'm very much a novice to the nitty gritty
details of how programs work)
I wish to write a tool that creates points-to data such that for each
pointer access I can see what source code variable name the pointer was
pointing to.
That is, given a load or store address, I want to lookup in the debug info
what the variable name being accessed is.
I found the function
VG_(get_datasym_and_offset)( Addr data_addr,
/*OUT*/Char* dname, Int n_dname,
/*OUT*/OffT* offset )
and this seems to work for global variables. But for local variables, it
seems to just return the name "temporary".
But I assume there must be a way to derive the names associated with a stack
variable from the debug info. Perhaps taking the address minus the stack
pointer value, and scanning the debug info for that result?
Uh, and as for pointers to heap data, I haven't put much thought into that
yet. Perhaps that's a much different problem.
--
View this message in context: http://www.nabble.com/how-to-get-local-variable-name-from-data-address-tp16579254p16579254.html
Sent from the Valgrind - Users mailing list archive at Nabble.com.
|
|
From: Bart V. A. <bar...@gm...> - 2008-04-09 06:09:31
|
On Wed, Apr 9, 2008 at 7:25 AM, gleepglop <dar...@ga...> wrote: > > I found the function > VG_(get_datasym_and_offset)( Addr data_addr, > /*OUT*/Char* dname, Int n_dname, > /*OUT*/OffT* offset ) > > and this seems to work for global variables. But for local variables, it > seems to just return the name "temporary". > But I assume there must be a way to derive the names associated with a stack > variable from the debug info. Perhaps taking the address minus the stack > pointer value, and scanning the debug info for that result? Did you already try VG_(get_data_description)() ? > Uh, and as for pointers to heap data, I haven't put much thought into that > yet. Perhaps that's a much different problem. You can track all malloc() / free() calls in your tool. See e.g. memcheck for an example. Bart. |
|
From: gleepglop <dar...@ga...> - 2008-04-09 16:12:52
|
Bart Van Assche wrote: > > > Did you already try VG_(get_data_description)() ? > > Bart. > > > Yes, I did, and both dname1, and dname2 seemed to just return empty strings, even for the globals that get_datasym_and_offset returned names for. Should VG_(get_data_description)() and VG_(get_datasym_and_offset)() definitely return some info for local/stack variables? What if the locals only exist in registers? (that can happen, right?) I compiled a stupid little C program with some globals and a single function (besides main) with some locals. And I put some random addition operations in the function using the locals and the globals. I compiled as: gcc -g test.c For the tool, I just changed lackey a little bit. I added calls to VG_(get_data_description)() and VG_(get_datasym_and_offset)() inside of the trace_load() and trace_store() helper functions and printf'd the results in those functions. And I modified the trace-mem stuff to only run on instructions inside of the function specified with the --fnname option. -- View this message in context: http://www.nabble.com/how-to-get-local-variable-name-from-data-address-tp16579254p16589561.html Sent from the Valgrind - Users mailing list archive at Nabble.com. |
|
From: Bart V. A. <bar...@gm...> - 2008-04-09 17:41:56
|
On Wed, Apr 9, 2008 at 6:12 PM, gleepglop <dar...@ga...> wrote: > > Bart Van Assche wrote: > > > > Did you already try VG_(get_data_description)() ? > > Yes, I did, and both dname1, and dname2 seemed to just return empty strings, > even for the globals that get_datasym_and_offset returned names for. VG_(get_data_description)() only works if you call VG_(needs_var_info)() from your tool's pre_clo_init() or post_clo_init() function first. Bart. |
|
From: gleepglop <dar...@ga...> - 2008-04-09 19:35:34
|
Ohhh, yes, now I get local and global variable info from VG_(get_data_description)(). Thank you very much. But, VG_(get_datasym_and_offset)() still doesn't work on locals. Strangely it returns "temporary" sometimes, and an empty string other times. I can't see any pattern either, even for the same memory location it sometimes returns "temporary" and a few instructions later it returns nothing. I guess I need to start looking at the code for VG_(get_data_description)() and VG_(get_datasym_and_offset)(). Maybe I could write my own function that just returns the variable name that I get as part of the string from the first argument to VG_(get_data_description)() . -- View this message in context: http://www.nabble.com/how-to-get-local-variable-name-from-data-address-tp16579254p16594884.html Sent from the Valgrind - Users mailing list archive at Nabble.com. |
|
From: Julian S. <js...@ac...> - 2008-04-09 20:01:11
|
> But, VG_(get_datasym_and_offset)() still doesn't work on locals. It's not intended to work on locals. (What would this even mean? The offset relative to what?) Basically, forget about get_datasym_and_offset, and use get_data_description instead. That should always give at least as much information. If you ask V to load Dwarf3 variable/type info -- either by the "var_info" core/tool interface "need", or by --read-var-info=yes, then you should hopefully get info about locals too. J |
|
From: gleepglop <dar...@ga...> - 2008-04-09 20:56:57
|
I don't understand what the offset means in any case. I know the comments say: "Also data_addr's offset from the symbol start is put into *offset.' I figured the offset was for accesses into an array, or structure. That it was the number of bytes from whereever in memory the variable currently started at. I don't understand why that wouldn't apply to locals as well. Sorry if these are dumb questions. Julian Seward-2 wrote: > > >> But, VG_(get_datasym_and_offset)() still doesn't work on locals. > > It's not intended to work on locals. (What would this even mean? > The offset relative to what?) > > Basically, forget about get_datasym_and_offset, and use > get_data_description instead. That should always give at least > as much information. If you ask V to load Dwarf3 variable/type > info -- either by the "var_info" core/tool interface "need", or > by --read-var-info=yes, then you should hopefully get info about > locals too. > > J > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save $100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > _______________________________________________ > Valgrind-users mailing list > Val...@li... > https://lists.sourceforge.net/lists/listinfo/valgrind-users > > -- View this message in context: http://www.nabble.com/how-to-get-local-variable-name-from-data-address-tp16579254p16596600.html Sent from the Valgrind - Users mailing list archive at Nabble.com. |
|
From: Julian S. <js...@ac...> - 2008-04-09 21:01:36
|
> Sorry if these are dumb questions. No, not at all. Nevertheless, it doesn't work for local variables. VG_(get_datasym_and_offset) is really what you need to use. J |
|
From: Nicholas N. <nj...@cs...> - 2008-04-09 22:09:03
|
On Wed, 9 Apr 2008, Julian Seward wrote: >> Sorry if these are dumb questions. > > No, not at all. Nevertheless, it doesn't work for local variables. > VG_(get_datasym_and_offset) is really what you need to use. I think Julian meant "VG_(get_data_description) is really what you need to use". Nick |