From: Alex B. <ker...@be...> - 2009-05-21 14:22:24
|
Hi, I'm currently chasing down a bug in my application which looks like a pointer being corrupted after being cleared. The default Valgrind run dutifully shows the SEGV caused by following the corrupted pointer but I'd like a way of seeing all the places this pointer is touched. So far adding fprintf's to the code hasn't helped which leads me to believe its not any of the could that *should* be touching this location. I've tried tracking it down with gdb awatch statements but it's proving more than a little problamatic (and very manual). Is there any way I could mark an interesting location in memory with the client mechanism and then get Valgrind to show me a backtrace everytime the location was touched? If not it would be a really useful tool :-) -- Alex, homepage: http://www.bennee.com/~alex/ CV: http://www.bennee.com/~alex/cv.php |
From: Dan K. <da...@ke...> - 2009-05-21 14:41:38
|
On Thu, May 21, 2009 at 7:22 AM, Alex Bennee <ker...@be...> wrote: > Is there any way I could mark an interesting location in memory with > the client mechanism and then get > Valgrind to show me a backtrace everytime the location was touched? If > not it would be a really useful tool :-) That would be cool. That said, have you tried a watchpoint in gdb? http://stackoverflow.com/questions/58851/can-i-set-a-breakpoint-on-memory-access-in-gdb - Dan |
From: Alex B. <ker...@be...> - 2009-05-21 15:41:00
|
2009/5/21 Dan Kegel <da...@ke...>: > On Thu, May 21, 2009 at 7:22 AM, Alex Bennee <ker...@be...> wrote: >> Is there any way I could mark an interesting location in memory with >> the client mechanism and then get >> Valgrind to show me a backtrace everytime the location was touched? If >> not it would be a really useful tool :-) > > That would be cool. That said, have you tried a watchpoint in gdb? > http://stackoverflow.com/questions/58851/can-i-set-a-breakpoint-on-memory-access-in-gdb Yep I had been trying that. The main problem was not being able to do ith progamatically: b 869 if awatch (void *) *&n->timer Would of been useful. But conditinal breakpoints aren't really designed for setting newer breakpoints. In the end I did solve it with a client request: n->timer = NULL; fprintf(stderr," 2:checking n=%p n->timer=%p\n", n, n->timer); VALGRIND_MAKE_MEM_NOACCESS(&n->timer, sizeof(n->timer)); And almost imeadiatly Valgrind showed me an invalid write: ==31858== Invalid write of size 4 ==31858== at 0x413B1D: function (snmp_interface.c:2699) Which lead to: n->vc_qam[us]++; Which funnily enough was an incorrectly sized array just before n->timer Time spent reading Valgrind's fine manual: 10 minutes, Time spent hacking in the macro and running Valgrind 5 minutes, Time I *would have* saved if I had done this earlier: 4 hours ;-) -- Alex, homepage: http://www.bennee.com/~alex/ CV: http://www.bennee.com/~alex/cv.php |
From: Colin M. <col...@pi...> - 2009-05-21 15:56:28
|
Alex Bennee wrote: > Yep I had been trying that. The main problem was not being able to do > ith progamatically: > > b 869 if awatch (void *) *&n->timer > > Would of been useful. But conditinal breakpoints aren't really > designed for setting newer breakpoints. > > > In GDB you can use the "comm(and)" command to run an GDB command when a break point is hit, for example, if you want to watch the first time the function "goo" is entered after "foo" has been entered, do this b foo b goo disable 2 comm 1 enable 2 cont <blank line> run This sets breakpoint 1 on "foo", breakpoint 2 on "goo". It then disables breakpoint 2. breakpoint 1, when hit, runs "enable 2" and "cont" to re-enable breakpoint 2, and then continue the debuggee. The should work if breakpoint 1 is conditional. HTH, Colin S. Miller |
From: Julian S. <js...@ac...> - 2009-05-21 14:46:04
|
> Is there any way I could mark an interesting location in memory with > the client mechanism and then get > Valgrind to show me a backtrace everytime the location was touched? If > not it would be a really useful tool :-) yeh #include <memcheck/memcheck.h> VALGRIND_MAKE_MEM_UNADDRESSABLE(address, size); See memcheck/tests/clientperm.c for an example. J |
From: Alex B. <ker...@be...> - 2009-05-21 15:06:50
|
2009/5/21 Julian Seward <js...@ac...>: > >> Is there any way I could mark an interesting location in memory with >> the client mechanism and then get >> Valgrind to show me a backtrace everytime the location was touched? If >> not it would be a really useful tool :-) > > yeh > > #include <memcheck/memcheck.h> > > VALGRIND_MAKE_MEM_UNADDRESSABLE(address, size); Yeah I found VALGRIND_MAKE_MEM_NOACCESS in the end. I was going word blind reading section 3.1 and wondering why I thought there were more client requests. It might be an idea to generate an index of all Client requests (and parameters) and the end of the manual. Is it some sort of docbook generated thing? -- Alex, homepage: http://www.bennee.com/~alex/ CV: http://www.bennee.com/~alex/cv.php |