Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: "Laurent G." <vrygoud@gmail.com>
To: gdb@sourceware.org
Subject: Delete a watchpoint by address to automate segfault tracking
Date: Thu, 27 Sep 2012 11:43:00 -0000	[thread overview]
Message-ID: <CAD=JCDtHcnOozsXKrTnBiT2hhUqXARDrb2iuLDKyzb+=r5cwBw@mail.gmail.com> (raw)

Hi,

I'm debugging a segfault in a pretty large real-time program (the kind
of which we can't figure out what's wrong just by looking at the
code).

In short, I know where the program crash (non-valid pointer) but I
don't known who and when my pointer gets corrupted, as the program
alloc & destroy 2/3 similar buffers by second.

I find out a nice technique is this article
(http://www.outflux.net/blog/archives/2007/09/15/catching-stack-overflows-in-gdb-as-they-happen/)
which automate the creation of watchpoint on malloced buffer:
(gdb) commands 1
>silent
>set variable $m = p_mypointer
>watch *$m
>cont
>end

In the article, the author says "I couldn’t find an easy way to track
the memory watch number that was created during the first breakpoint,
I just built a gdb counter, and deleted the memory watch when leaving,
since I could predict gdb’s numbering" and implements watchpoints
destruction this way:
(gdb) set variable $count = 3
(gdb) commands 2
>silent
>delete $count
>set variable $count = $count + 1
>cont
>end

This technique works well when the buffers get destroyed in the same
order than there are created. But in my program this is not the case.

From the value passed to free() I can get the memory address of the
to-be-destroyed buffer, but I couldn't find a way to tell GDB to
delete that specific watchpoint:

(gdb) delete *0x080483c6
-> OK but can't be automated

(gdb) set variable $d = p_mypointer
(gdb) p $d
0x080483c6
(gdb) d $d
-> Can't do. "Convenience variables used in line specs must have
integer values."

How can I do a "delete *`print $d`" in GDB?
Thanks!

Regards,
Laurent


             reply	other threads:[~2012-09-27 11:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-27 11:43 Laurent G. [this message]
2012-09-27 13:39 ` Tom Tromey
2012-09-28 13:32   ` Laurent G.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAD=JCDtHcnOozsXKrTnBiT2hhUqXARDrb2iuLDKyzb+=r5cwBw@mail.gmail.com' \
    --to=vrygoud@gmail.com \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox