This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Watching memory adress given by an expression


Recently, I stumbled upon a dangling pointer in some code I'm maintaining.
The best reproducible crash was still very time sensitive (order of a few seconds at most),
so I couldn't really debug interactively.
Some structure on the heap was corrupted, so I set up a breakpoint when the structure was correctly initialized with commands to set up a watchpoint on the memory that would be corrupted.
Unfortunately, the expression I had for the to-be-corrupted memory was going out of scope before the corruption.
I resorted to this:

ignore $bpnum 9
print entry
x &(entry.pc)
set $targetpc=$_
watch *($targetpc)

Which is ugly because: I works only for a single triggering of the breakpoint. It prints an extra value. The $_ business I'm doing is really a hack.

I could remove the first problem using shell, source, etc. but this isn't cleaner.

Is there a cleaner way to do this kind of debugging?

I would have liked to have a command like:
watchmem &(entry.pc)
which would immediately evaluate it's expression to a pointer and set a watcher to the pointed space.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]