public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Giles Atkinson <gatk@btinternet.com>
To: gdb-patches@sourceware.org
Subject: Tentative: add -location option to clear command
Date: Sat, 20 Feb 2016 19:17:00 -0000	[thread overview]
Message-ID: <F3638BB1-F4C1-4AE8-8E67-F3A1F88E4BFE@btinternet.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1840 bytes --]

Greetings.

This patch adds a variation of the "clear" command, "clear -location",
so that (some) watchpoints can be removed by expression.  The idea is
to support setting watchpoints in dynamically-allocated memory,
removing them automatically when the memory is released.
Something like this:

# Break on malloc()d memory initialisation.
break new_stuff:init
commands
  watch -location new->foo[0]
  commands
    printf "Item %d next %p\n", it->count, it->next
    bt
    continue
  end
  continue
end
#
# Break just before free().
break free_stuff:release
commands
  clear -location old->foo[0]
  continue
end

The delete command will not work here without an external mechanism to
associate the watchpoint number with the memory address.

Some background to this is in the recent thread
"Dynamic watchpoints in dynamic memory" on the gdb list.

The change works by pulling out bits of the watch and clear commands
into new functions, and re-using them.  No real understanding of gdb
internals was needed, so there may be some subtle errors.
In making parse_expression_for_watchpoint(), I removed what looked like
redundant stripping of whitespace from the expression.

In its current form, the change appears to pass the tests as well as
the original.  (I get some variation with repeated runs of "make check".)
The results for changes named "watch*" and "break*" seem identical.

If the change can be accepted in principle, I will add tests, and
documention changes.  There is also a potential extension to other watchpoints
(set without -location).  The clear command would only remove watchpoints
after failing to match any breakpoints, and would probably select watchpoints
to be removed by matching the frame and parsed expression.

Diff is relative to 7.10.1.

Thanks,

Giles

[-- Attachment #2: patch.gz --]
[-- Type: application/x-gzip, Size: 4879 bytes --]

             reply	other threads:[~2016-02-20 19:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-20 19:17 Giles Atkinson [this message]
2016-03-29 14:50 ` Giles Atkinson
2016-04-05 20:07   ` Luis Machado

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=F3638BB1-F4C1-4AE8-8E67-F3A1F88E4BFE@btinternet.com \
    --to=gatk@btinternet.com \
    --cc=gdb-patches@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).