From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15390 invoked by alias); 28 Jul 2006 13:44:26 -0000 Received: (qmail 15380 invoked by uid 22791); 28 Jul 2006 13:44:25 -0000 X-Spam-Check-By: sourceware.org Received: from fra-del-03.spheriq.net (HELO fra-del-03.spheriq.net) (195.46.51.99) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 28 Jul 2006 13:44:10 +0000 Received: from fra-out-03.spheriq.net (fra-out-03.spheriq.net [195.46.51.131]) by fra-del-03.spheriq.net with ESMTP id k6SDi7i9031197 for ; Fri, 28 Jul 2006 13:44:07 GMT Received: from fra-cus-02.spheriq.net (fra-cus-02.spheriq.net [195.46.51.38]) by fra-out-03.spheriq.net with ESMTP id k6SDi4W1021511 for ; Fri, 28 Jul 2006 13:44:04 GMT Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by fra-cus-02.spheriq.net with ESMTP id k6SDi2bh025739 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK) for ; Fri, 28 Jul 2006 13:44:03 GMT Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A8DB8DB51 for ; Fri, 28 Jul 2006 13:38:39 +0000 (GMT) Received: from mail1.cro.st.com (mail1.cro.st.com [164.129.40.131]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 74E61474AD for ; Fri, 28 Jul 2006 13:38:39 +0000 (GMT) Received: from crx549.cro.st.com (crx549.cro.st.com [164.129.44.49]) by mail1.cro.st.com (MOS 3.5.8-GR) with ESMTP id CIB85035 (AUTH "frederic riss"); Fri, 28 Jul 2006 15:38:38 +0200 (CEST) Subject: [RFC] New threadnum command for breakpoints From: Frederic RISS To: gdb-patches@sources.redhat.com Content-Type: multipart/mixed; boundary="=-nBPCK4dBd9jmzcWd0jKU" Date: Fri, 28 Jul 2006 13:44:00 -0000 Message-Id: <1154093921.28300.236.camel@crx549.cro.st.com> Mime-Version: 1.0 X-Mailer: Evolution 2.6.0 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/msg00412.txt.bz2 --=-nBPCK4dBd9jmzcWd0jKU Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-length: 1513 Hello, I recently got really frustrated that I couldn't set thread-specific breakpoints when using the "*" linespec location. The reason for this has been discussed already, but I can't seem to find the thread in the archives. Basically, the "*" notation treats 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. --=-nBPCK4dBd9jmzcWd0jKU Content-Disposition: attachment; filename=threadnum.patch Content-Type: text/x-patch; name=threadnum.patch; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-length: 2096 2006-07-28 Frederic Riss * 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\ --=-nBPCK4dBd9jmzcWd0jKU--