public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Dynamic watchpoints in dynamic memory
@ 2016-02-05 23:21 Giles Atkinson
  2016-02-06  3:44 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Giles Atkinson @ 2016-02-05 23:21 UTC (permalink / raw)
  To: gdb

Greetings,

I have a suspicion that these may be somewhat stupid questions, but I feel I have done enough searching of documentation, FAQs etc.,
without result, to be ready to ask.  I think this could be a FAQ-level query, but found no reference to the topic.

I have a C program that crashes on a modify access via a dynamically-allocated structure member with an illegal address, not NULL.
The core file, circumstances, and code review suggest that an unusual event has previously corrupted a pointer
in the structure, which the failing instruction dereferences.

My approach was to set a breakpoint on structure initialisation, with a command list to set  a watchpoint on the 
pointer member.  The watchpoint command list is backtrace and continue, output to file.  By setting the breakpoint on the
right instruction, the breakpoint command list can pick the structure address from a register, adding an offset.

That works: so far, so good.

The target structures are created and destroyed fairly frequently, responding to user input.
To avoid noise in the output, and limit the number of watchpoints, there is a breakpoint before deallocation
that attempts to remove the watchpoint on the structure, again using a register value.

Questions:
Does this make sense, or have I missed a better way?
How to remove the watchpoint? I can not identify the right syntax.

The watchpoint is set like this: watch -location *(void **)($esi + $offset)
I have tried to remove it with 'clear', but that seems to match watchpoints
using the 'watch' expression, and what I have is a different expression that should yield the same address.
The register is different on deallocation and the original command is not unique.

More puzzlement: my printf commands in (nested) command lists do nothing.

Environment: Ubuntu  X86 32-bit Ubuntu15.10, system supplied gdb 7.10. Program compiled on vanilla Debian 5.

Any advice will be appreciated,

Thanks,

Giles


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-02-06 21:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-05 23:21 Dynamic watchpoints in dynamic memory Giles Atkinson
2016-02-06  3:44 ` Simon Marchi
2016-02-06 21:43   ` Giles Atkinson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).