From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23777 invoked by alias); 31 Jul 2006 20:07:07 -0000 Received: (qmail 23418 invoked by uid 22791); 31 Jul 2006 20:07:05 -0000 X-Spam-Check-By: sourceware.org Received: from smtp2-g19.free.fr (HELO smtp2-g19.free.fr) (212.27.42.28) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 31 Jul 2006 20:07:01 +0000 Received: from [192.168.0.10] (pas38-3-82-229-199-15.fbx.proxad.net [82.229.199.15]) by smtp2-g19.free.fr (Postfix) with ESMTP id 78E8775BD5; Mon, 31 Jul 2006 22:06:58 +0200 (CEST) Subject: Re: [RFC] New threadnum command for breakpoints From: =?ISO-8859-1?Q?Fr=E9d=E9ric?= Riss To: Frederic RISS Cc: Daniel Jacobowitz , Andreas Schwab , gdb-patches@sources.redhat.com In-Reply-To: <1154354425.28300.335.camel@crx549.cro.st.com> References: <1154093921.28300.236.camel@crx549.cro.st.com> <1154093921.28300.236.camel@crx549.cro.st.com> <20060728141339.GA15103@nevyn.them.org> <1154098563.28300.282.camel@crx549.cro.st.com> <20060728151434.GA17238@nevyn.them.org> <1154334744.28300.302.camel@crx549.cro.st.com> <20060731125311.GA1272@nevyn.them.org> <1154354425.28300.335.camel@crx549.cro.st.com> Content-Type: multipart/mixed; boundary="=-jF/WsqeZB9lmU4ZnuS7g" Date: Mon, 31 Jul 2006 20:07:00 -0000 Message-Id: <1154376407.5120.27.camel@funkylaptop> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-07/txt/msg00434.txt.bz2 --=-jF/WsqeZB9lmU4ZnuS7g Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-length: 1503 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. --=-jF/WsqeZB9lmU4ZnuS7g Content-Disposition: attachment; filename=gdb_thread.patch Content-Type: text/x-patch; name=gdb_thread.patch; charset=utf-8 Content-Transfer-Encoding: 7bit Content-length: 1513 2006-07-31 Frederic Riss * infrun.c (handle_inferior_event): Set the $_gdb_thread convenience variable. Don't call breakpoint_thread_match anymore. Suggested by Vladimir Prus 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) { --=-jF/WsqeZB9lmU4ZnuS7g Content-Disposition: attachment; filename=gdb_thread_doc.patch Content-Type: text/x-patch; name=gdb_thread_doc.patch; charset=utf-8 Content-Transfer-Encoding: 8bit Content-length: 1589 2006-07-31 Frederic Riss * 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 --=-jF/WsqeZB9lmU4ZnuS7g--