From: "Frédéric Riss" <frederic.riss@gmail.com>
To: Frederic RISS <frederic.riss@st.com>
Cc: Daniel Jacobowitz <drow@false.org>,
Andreas Schwab <schwab@suse.de>,
gdb-patches@sources.redhat.com
Subject: Re: [RFC] New threadnum command for breakpoints
Date: Mon, 31 Jul 2006 20:07:00 -0000 [thread overview]
Message-ID: <1154376407.5120.27.camel@funkylaptop> (raw)
In-Reply-To: <1154354425.28300.335.camel@crx549.cro.st.com>
[-- Attachment #1: Type: text/plain, Size: 1507 bytes --]
Le lundi 31 juillet 2006 à 16:00 +0200, Frederic RISS a écrit :
> I'll follow up soon with a patch doing this.
Here's a code patch for discussion and a tentative doco patch. I've
chosen to initialize the variable early in handle_inferior_event, so
that it's set whatever happens. I thought that if we document it, it'd
rather be always set and not only for breakpoint condition evaluation.
I'm still wondering about 2 things:
1. Should it change on a user requested thread switch? That would be a
simple patch to thread.c:switch_to_thread. But maybe documenting it as
'the id of the last stopped thread' wouldn't be a bad idea. I don't
think GDB provides a way for the user to get this information (I mean
once he has selected another thread). This way 'thread $_gdb_thread'
would always bring you back to the stopped thread.
2. Should we add support for read-only convenience variables? Writing in
$_gdb_thread makes no sense... but it causes no harm either. We already
have $bpnum in the same situation. I see some ways to support this:
- Add lval_internalvar_readonly
- Add a read_only flag to struct internalvar and check it at
assignment time. Internal vars are already special-cased there,
so this should be easy. Would be my solution of choice.
- Don't create a real convenience variable, but add OP_THREADID
to expression.h and generate it in write_dollar_var. Also add
some API to infrun.c to export the stopped threadid.
Fred.
[-- Attachment #2: gdb_thread.patch --]
[-- Type: text/x-patch, Size: 1513 bytes --]
2006-07-31 Frederic Riss <frederic.riss@st.com>
* infrun.c (handle_inferior_event): Set the $_gdb_thread convenience
variable. Don't call breakpoint_thread_match anymore. Suggested by
Vladimir Prus <vladimir@codesourcery.com>
Index: infrun.c
===================================================================
RCS file: /cvs/src/src/gdb/infrun.c,v
retrieving revision 1.213
diff -u -p -r1.213 infrun.c
--- infrun.c 22 Jul 2006 14:48:03 -0000 1.213
+++ infrun.c 31 Jul 2006 19:26:33 -0000
@@ -1250,6 +1250,10 @@ handle_inferior_event (struct execution_
int sw_single_step_trap_p = 0;
int stopped_by_watchpoint = -1; /* Mark as unknown. */
+ static struct internalvar *gdb_thread_var = NULL;
+
+ if (gdb_thread_var == NULL)
+ gdb_thread_var = lookup_internalvar("_gdb_thread");
/* Cache the last pid/waitstatus. */
target_last_wait_ptid = ecs->ptid;
@@ -1307,6 +1311,10 @@ handle_inferior_event (struct execution_
ui_out_text (uiout, "]\n");
}
+ set_internalvar (gdb_thread_var,
+ value_from_longest (builtin_type_int,
+ pid_to_thread_id (ecs->ptid)));
+
switch (ecs->ws.kind)
{
case TARGET_WAITKIND_LOADED:
@@ -1589,8 +1597,6 @@ handle_inferior_event (struct execution_
if (breakpoints_inserted && breakpoint_here_p (stop_pc))
{
ecs->random_signal = 0;
- if (!breakpoint_thread_match (stop_pc, ecs->ptid))
- thread_hop_needed = 1;
}
else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p)
{
[-- Attachment #3: gdb_thread_doc.patch --]
[-- Type: text/x-patch, Size: 1591 bytes --]
2006-07-31 Frederic Riss <frederic.riss@st.com>
* gdb.texinfo (Stopping and starting multi-thread programs): Mention
the $_gdb_thread convenience variable.
Index: gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.345
diff -u -p -r1.345 gdb.texinfo
--- gdb.texinfo 21 Jul 2006 14:46:55 -0000 1.345
+++ gdb.texinfo 31 Jul 2006 19:22:50 -0000
@@ -4208,8 +4208,10 @@ breakpoints on all threads, or on a part
@cindex breakpoints and threads
@cindex thread breakpoints
@kindex break @dots{} thread @var{threadno}
+@vindex $_gdb_thread@r{, convenience variable}
@item break @var{linespec} thread @var{threadno}
@itemx break @var{linespec} thread @var{threadno} if @dots{}
+@itemx break @var{linespec} if $_gdb_thread == @var{threadno} @r{[} && @dots@r{]}
@var{linespec} specifies source lines; there are several ways of
writing them, but the effect is always to specify some source line.
@@ -4231,6 +4233,15 @@ breakpoint condition, like this:
(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
@end smallexample
+Alternatively, you can use the @samp{$_gdb_thread} convenience variable in
+the breakpoint's condition. The @samp{$_gdb_thread} variable is set by
+@value{GDBN} to the thread identifier of the stopped thread. This can be used
+for example to make a breakpoint trigger in multiple threads, like this:
+
+@smallexample
+(@value{GDBP}) break frik.c:13 if $_gdb_thread == 8 ||Â $_gdb_thread == 9
+@end smallexample
+
@end table
@cindex stopped threads
next prev parent reply other threads:[~2006-07-31 20:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-28 13:44 Frederic RISS
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 [this message]
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=1154376407.5120.27.camel@funkylaptop \
--to=frederic.riss@gmail.com \
--cc=drow@false.org \
--cc=frederic.riss@st.com \
--cc=gdb-patches@sources.redhat.com \
--cc=schwab@suse.de \
/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