|
From: Vadim A. <av...@gm...> - 2008-10-06 17:09:02
|
Hi!
I'm a student of the Moscow State University, faculty of computational
mathematics and cybernetics. Now I'm working on valgrind's tool, which can
help to decompile programs. I want to analyze variables' values to
understand, which types these variables have (also I want to analyze
pointers, and I think, that I can do it. The main difference between simple
variables and pointers - their values. Pointers have very specific values).
But I have some troubles with valgrind's core. I can't understand, how to
get variables' values correctly. I'm trying to work with it by follow code:
VG_(track_pre_mem_read) (fb_pre_mem_read);
VG_(track_pre_mem_write) (fb_pre_mem_write);
VG_(track_post_mem_write) (fb_post_mem_write);
void fb_post_mem_write(CorePart part, ThreadId tid, Addr a, SizeT size)
{
if (size == 4)
VG_(message)(Vg_DebugMsg, "post_mem_write %u %d %u\n\r", (unsigned
int)size, *((int*)a), a);
}
void fb_pre_mem_write(CorePart part, ThreadId tid, Addr a, SizeT size)
{
if (size == 4)
VG_(message)(Vg_DebugMsg, "pre_mem_write %u %d %u\n\r", (unsigned
int)size, *((int*)a), a);
}
void fb_pre_mem_read(CorePart part, ThreadId tid, Char* s, Addr a, SizeT
size) {
if (size == 4) {
VG_(message)(Vg_DebugMsg, "%d", (int)*s);
VG_(message)(Vg_DebugMsg, "pre_mem_read %u %d %u\n\r", (unsigned
int)size, *((int*)a), a);
}
}
But I can't understand, why it doesn't work.
Values, which are printed by these code aren't values of my program, which
i'm analyzing.
Can you help me?
P.S. Also I tried to work with registers by VG_(track_pre_reg_read) and
VG_(track_post_reg_write), but I also had only strange values on them...
--
Best regards,
Antonov Vadim
mailto: av...@gm...
mobile: +79099933666
|
|
From: Vadim A. <av...@gm...> - 2008-10-06 17:09:26
|
Hi!
I'm a student of the Moscow State University, faculty of computational
mathematics and cybernetics. Now I'm working on valgrind's tool, which can
help to decompile programs. I want to analyze variables' values to
understand, which types these variables have (also I want to analyze
pointers, and I think, that I can do it. The main difference between simple
variables and pointers - their values. Pointers have very specific values).
But I have some troubles with valgrind's core. I can't understand, how to
get variables' values correctly. I'm trying to work with it by follow code:
VG_(track_pre_mem_read) (fb_pre_mem_read);
VG_(track_pre_mem_write) (fb_pre_mem_write);
VG_(track_post_mem_write) (fb_post_mem_write);
void fb_post_mem_write(CorePart part, ThreadId tid, Addr a, SizeT size)
{
if (size == 4)
VG_(message)(Vg_DebugMsg, "post_mem_write %u %d %u\n\r", (unsigned
int)size, *((int*)a), a);
}
void fb_pre_mem_write(CorePart part, ThreadId tid, Addr a, SizeT size)
{
if (size == 4)
VG_(message)(Vg_DebugMsg, "pre_mem_write %u %d %u\n\r", (unsigned
int)size, *((int*)a), a);
}
void fb_pre_mem_read(CorePart part, ThreadId tid, Char* s, Addr a, SizeT
size) {
if (size == 4) {
VG_(message)(Vg_DebugMsg, "%d", (int)*s);
VG_(message)(Vg_DebugMsg, "pre_mem_read %u %d %u\n\r", (unsigned
int)size, *((int*)a), a);
}
}
But I can't understand, why it doesn't work.
Values, which are printed by these code aren't values of my program, which
i'm analyzing.
Can you help me?
P.S. Also I tried to work with registers by VG_(track_pre_reg_read) and
VG_(track_post_reg_write), but I also had only strange values on them...
--
Best regards,
Antonov Vadim
mailto: av...@gm...
mobile: +79099933666
|
|
From: Bart V. A. <bar...@gm...> - 2008-10-08 06:31:27
|
On Mon, Oct 6, 2008 at 6:56 PM, Vadim Antonov <av...@gm...> wrote: > But I can't understand, why it doesn't work. > Values, which are printed by these code aren't values of my program, which > i'm analyzing. Are you aware that Valgrind loads executables at another address than ld.so ? Bart. |
|
From: Bart V. A. <bar...@gm...> - 2008-10-08 06:49:30
|
On Wed, Oct 8, 2008 at 8:37 AM, Vadim Antonov <av...@gm...> wrote: > Maybe, you can give an advice, how to find real addresses? Why do you need the absolute addresses ? Do you know that Valgrind's core can translate addresses into names if debug information is present in an executable ? Bart. |
|
From: Vadim A. <av...@gm...> - 2008-10-08 07:14:32
|
---------- Forwarded message ---------- From: Vadim Antonov <av...@gm...> Date: 2008/10/8 Subject: Re: [Valgrind-developers] how i can read variables' values with valgrind core? To: Bart Van Assche <bar...@gm...> I want to find variables' values during program's execution. I think, that variables names can't give me this information. 2008/10/8 Bart Van Assche <bar...@gm...> > On Wed, Oct 8, 2008 at 8:37 AM, Vadim Antonov <av...@gm...> wrote: > > > Maybe, you can give an advice, how to find real addresses? > > Why do you need the absolute addresses ? Do you know that Valgrind's > core can translate addresses into names if debug information is > present in an executable ? > > Bart. > -- Best regards, Antonov Vadim mailto: av...@gm... mobile: +79099933666 -- Best regards, Antonov Vadim mailto: av...@gm... mobile: +79099933666 |
|
From: Julian S. <js...@ac...> - 2008-10-08 09:01:16
|
You should study the Lackey tool, and even use it as a starting point
for your experiments. It shows how you can see all the memory accesses
in a program.
> VG_(track_pre_mem_read) (fb_pre_mem_read);
> VG_(track_pre_mem_write) (fb_pre_mem_write);
> VG_(track_post_mem_write) (fb_post_mem_write);
These only show some very specialised accesses, for system call handling
and signal handling mostly. You will not see the normal data accesses
like this. You need to write an instrumentation function.
> P.S. Also I tried to work with registers by VG_(track_pre_reg_read) and
> VG_(track_post_reg_write), but I also had only strange values on them...
Same problem as with track_{pre,post}_mem_{read,write}.
Even when you see all the memory accesses, there is the problem of
mapping them to source level variables.
Some accesses -- caller save register saves and restores in function
prologues and epilogues -- do not correspond to any specific variables,
and they do not correspond to user-written loads/stores. Others
-- register spills and reloads -- might correspond to a given variable,
but they do not correspond to any user-written loads/stores.
Heap block accesses, you can detect by intercepting all mallocs/frees
so you know the bounds of heap blocks.
For stack and global variables, you can detect accesses (for objects
compiled with -g) by writing a function similar to VG_(get_data_description).
At least in theory you could use VG_(get_data_description), but it can be
very slow and so it won't be practical like that. You would need to
reformat the data in some faster-to-access way.
J
|