Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Frederic RISS <frederic.riss@st.com>
To: gdb-patches@sources.redhat.com
Subject: [RFC] New threadnum command for breakpoints
Date: Fri, 28 Jul 2006 13:44:00 -0000	[thread overview]
Message-ID: <1154093921.28300.236.camel@crx549.cro.st.com> (raw)

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

Hello,

I recently got really frustrated that I couldn't set thread-specific
breakpoints when using the "*<addr>" linespec location. The reason for
this has been discussed already, but I can't seem to find the thread in
the archives. Basically, the "*<addr>" notation treats <addr> as an
expression and the expression parser emits a parse error if you add
'thread xxx' to the line.

This works for breakpoint conditions because "if" is special-cased in
the expression parsers to stop the parsing. At least for C(++), there
can't be any expression typed in GDB that would contain the "if"
reserved keyword, so handling it as a stop condition in the expression
parser is OK. That can't be done for "thread" because it's a valid
language identifier.

The attached patch doesn't try to solve the parsing issue, but it simply
adds a 'threadnum' command that one can use to (un)set the thread of a
particular breakpoint. I'm not sure about the command name, because it
will conflict with the thread command. Suggestions appreciated. I also
wonder if new CLI commands should be added only in the 'cli' subdir?

Of course, the patch is missing a doco part and maybe testsuite
coverage, but I thought I'd first ask if there's interest for this or if
I missed an existing way to do it (seems quite surprising that this
doesn't already exist).
Maybe the alternate approach of adding a $thread variable to use in bp
conditions ( http://www.sourceware.org/ml/gdb/2006-02/msg00017.html )
should be implemented instead ?

Fred.

[-- Attachment #2: threadnum.patch --]
[-- Type: text/x-patch, Size: 2096 bytes --]


2006-07-28  Frederic Riss  <frederic.riss@st.com>

	* breakpoint.c (threadnum_command): New function.
	(_initialize_breakpoint): Register new threadnum command.
	


Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.227
diff -u -p -r1.227 breakpoint.c
--- breakpoint.c	2 Jun 2006 03:43:18 -0000	1.227
+++ breakpoint.c	27 Jul 2006 20:49:28 -0000
@@ -592,6 +592,43 @@ condition_command (char *arg, int from_t
   error (_("No breakpoint number %d."), bnum);
 }
 
+/* threadnum N TID -- set thread of breakpoint N to TID.  */
+
+static void
+threadnum_command (char *arg, int from_tty)
+{
+  struct breakpoint *b;
+  char *p;
+  int bnum, threadnum;
+
+  if (arg == 0)
+    error_no_arg (_("breakpoint number"));
+
+  p = arg;
+  bnum = get_number (&p);
+  if (bnum == 0)
+    error (_("Bad breakpoint argument: '%s'"), arg);
+
+  arg = p;
+  threadnum = get_number (&p);
+  if (threadnum == 0)
+    error (_("Bad thread id argument: '%s'"), arg);
+
+  if (threadnum != -1 && !valid_thread_id (threadnum))
+    error (_("Unknown thread %d."), threadnum);
+    
+  ALL_BREAKPOINTS (b)
+    if (b->number == bnum)
+    {
+      b->thread = threadnum;
+      breakpoints_changed ();
+      breakpoint_modify_event (b->number);
+      return;
+    }
+
+  error (_("No breakpoint number %d."), bnum);
+}
+
 static void
 commands_command (char *arg, int from_tty)
 {
@@ -7796,6 +7833,12 @@ Specify breakpoint number N to break onl
 Usage is `condition N COND', where N is an integer and COND is an\n\
 expression to be evaluated whenever breakpoint N is reached."));
 
+  add_com ("threadnum", class_breakpoint, threadnum_command, _("\
+Specify breakpoint number N to break only in thread TID.\n\
+Usage is `threadnum N TID', where N is an integer and TID is a\n\
+thread identifier as printed by \"info threads\", or -1 for\n\
+any thread."));
+
   c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
 Set a temporary breakpoint.\n\
 Like \"break\" except the breakpoint is only temporary,\n\

             reply	other threads:[~2006-07-28 13:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-28 13:44 Frederic RISS [this message]
2006-07-28 14:03 ` Andreas Schwab
2006-07-28 14:13   ` Daniel Jacobowitz
2006-07-28 14:20     ` Andreas Schwab
2006-07-28 14:59     ` Frederic RISS
2006-07-28 15:14       ` Daniel Jacobowitz
2006-07-31  8:32         ` Frederic RISS
2006-07-31 12:53           ` Daniel Jacobowitz
2006-07-31 14:00             ` Frederic RISS
2006-07-31 20:07               ` Frédéric Riss
2006-07-31 20:14                 ` Eli Zaretskii
2006-08-08 18:22                 ` Daniel Jacobowitz
2006-08-08 19:43                   ` Frédéric Riss
2006-08-16 14:15                     ` Frederic RISS
2006-08-31  7:23                       ` Frederic RISS
2006-07-28 14:28   ` Frederic RISS
2006-07-28 14:30     ` Frederic RISS

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=1154093921.28300.236.camel@crx549.cro.st.com \
    --to=frederic.riss@st.com \
    --cc=gdb-patches@sources.redhat.com \
    /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