Message ID | d8fdb97bb59b7f74846906995ba0d1f1d9d2385c.1674207665.git.aburgess@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A4A0238493D0 for <patchwork@sourceware.org>; Fri, 20 Jan 2023 09:47:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4A0238493D0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674208063; bh=VPYKM/inPaEgz0ub78Z3IPCd+GHCrzFHZ0dYuU4qUXM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=b+Hex4vcctXv4jiwbKZGCcTvgYB1dx+YewJag9hZnf2lGEcEBbKzKIB9nK7qFRpf3 +K7DJe9rqtOcHNZNn4ySd2wkb82aDwxlbMK1bHds4WTd8gFKxjaRX6J4wGLVcDxeui aqjPZDkPqSIVaadubuTbuwNKdrKoTXnuakPS419M= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id CD58638582BC for <gdb-patches@sourceware.org>; Fri, 20 Jan 2023 09:46:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD58638582BC Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-332-0ZGLFB9ANDOLVRmKq4DF2w-1; Fri, 20 Jan 2023 04:46:44 -0500 X-MC-Unique: 0ZGLFB9ANDOLVRmKq4DF2w-1 Received: by mail-qt1-f200.google.com with SMTP id a13-20020ac84d8d000000b003b63a85ae73so2183356qtw.21 for <gdb-patches@sourceware.org>; Fri, 20 Jan 2023 01:46:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VPYKM/inPaEgz0ub78Z3IPCd+GHCrzFHZ0dYuU4qUXM=; b=QgDVUZCyxXSVFiGYUB05WWKhfFAGKQEnec3qCUaMqseyYnc92gFcU0wSSYfV1VjHWX 9Y+VHzJ9R7xs7yKzOoLtGqTpcztULnVDlXj3lbJd7adjXFsa6GZicvLmHdInd8yS4Lxg kbDrzTm7B61yS8ug1AvjDcNbMytTFRsJOXfo4yAhufENn1uGGsf13UlPxJMbSgshIR5V GRk+sahBQDVAivg8E8saywklZ4VlaGntWPbaPO14hWP2VYW0thvUKFI2V9qivXf+0XdC 7lnyBJIbpO6w3As2K+SXrFyPWbIx0V61mTbTqx3jSsEj3WPxgKzyfrRG5fJY+7mt1uAp JvUw== X-Gm-Message-State: AFqh2kq+UDR2hoeAx9AuSNpoajD/43FIty4OPv1LLxXh2v3+EBNFIdhf OnS1fOKcWDlpkRKMRb1IANanFhIL4vzSxIvN6zihEh+JpH6YY1gnxLJEWOsp4Y3cW1l1p/entTD gAiFIfqVJnEGR5sWCyUtxo2Yl9ysVMqUES8e02w2lLYeahD6pc0AFMREOMIpeGomOpv8eg8qmFg == X-Received: by 2002:a05:622a:5d86:b0:3b6:301f:7b3d with SMTP id fu6-20020a05622a5d8600b003b6301f7b3dmr19212306qtb.65.1674208003530; Fri, 20 Jan 2023 01:46:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXvQLTCofZv0xoWcEPEuVhWzdUe8r6cuzabLO3GFNdKmDWxkMHYy4w9D3qg8eMDYbzwSeUt/Qw== X-Received: by 2002:a05:622a:5d86:b0:3b6:301f:7b3d with SMTP id fu6-20020a05622a5d8600b003b6301f7b3dmr19212281qtb.65.1674208003069; Fri, 20 Jan 2023 01:46:43 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id cb15-20020a05622a1f8f00b003ab43dabfb1sm7429015qtb.55.2023.01.20.01.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 01:46:42 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess <aburgess@redhat.com> Subject: [PATCHv2 4/6] gdb: error if 'thread' or 'task' keywords are overused Date: Fri, 20 Jan 2023 09:46:27 +0000 Message-Id: <d8fdb97bb59b7f74846906995ba0d1f1d9d2385c.1674207665.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <cover.1674207665.git.aburgess@redhat.com> References: <cover.1669634536.git.aburgess@redhat.com> <cover.1674207665.git.aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> From: Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> Reply-To: Andrew Burgess <aburgess@redhat.com> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
Inferior specific breakpoints
|
|
Commit Message
Andrew Burgess
Jan. 20, 2023, 9:46 a.m. UTC
When creating a breakpoint or watchpoint, the 'thread' and 'task' keywords can be used to create a thread or task specific breakpoint or watchpoint. Currently, a thread or task specific breakpoint can only apply for a single thread or task, if multiple threads or tasks are specified when creating the breakpoint (or watchpoint), then the last specified id will be used. The exception to the above is that when the 'thread' keyword is used during the creation of a watchpoint, GDB will give an error if 'thread' is given more than once. In this commit I propose making this behaviour consistent, if the 'thread' or 'task' keywords are used more than once when creating either a breakpoint or watchpoint, then GDB will give an error. I haven't updated the manual, we don't explicitly say that these keywords can be repeated, and (to me), given the keyword takes a single id, I don't think it makes much sense to repeat the keyword. As such, I see this more as adding a missing error to GDB, rather than making some big change. However, I have added an entry to the NEWS file as I guess it is possible that some people might hit this new error with an existing (I claim, badly written) GDB script. I've added some new tests to check for the new error. Just one test needed updating, gdb.linespec/keywords.exp, this test did use the 'thread' keyword twice, and expected the breakpoint to be created. Looking at what this test was for though, it was checking the use of '-force-condition', and I don't think that being able to repeat 'thread' was actually a critical part of this test. As such, I've updated this test to expect the error when 'thread' is repeated. --- gdb/NEWS | 9 +++++++++ gdb/breakpoint.c | 9 +++++++++ gdb/testsuite/gdb.ada/tasks.exp | 4 ++++ gdb/testsuite/gdb.linespec/keywords.exp | 10 ++++++++-- gdb/testsuite/gdb.threads/thread-specific-bp.exp | 4 ++++ gdb/testsuite/gdb.threads/watchthreads2.exp | 3 +++ 6 files changed, 37 insertions(+), 2 deletions(-)
Comments
> Cc: Andrew Burgess <aburgess@redhat.com> > Date: Fri, 20 Jan 2023 09:46:27 +0000 > From: Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> > > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -9,6 +9,15 @@ > This support requires that GDB be built with Python scripting > enabled. > > +* For the break command, multiple uses of the 'thread' or 'task' > + keywords will now give an error instead of just using the thread or > + task id from the last instance of the keyword. > + > +* For the watch command, multiple uses of the 'task' keyword will now > + give an error instead of just using the task id from the last > + instance of the keyword. The 'thread' keyword already gave an error > + when used multiple times with the watch command, this remains unchanged. This part is OK, but I wonder whether we should provide an example of such incorrect usage which will now be flagged, because I'm not sure everyone will understand what "multiple uses" means in this context. Thanks.
Eli Zaretskii <eliz@gnu.org> writes: >> Cc: Andrew Burgess <aburgess@redhat.com> >> Date: Fri, 20 Jan 2023 09:46:27 +0000 >> From: Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> >> >> --- a/gdb/NEWS >> +++ b/gdb/NEWS >> @@ -9,6 +9,15 @@ >> This support requires that GDB be built with Python scripting >> enabled. >> >> +* For the break command, multiple uses of the 'thread' or 'task' >> + keywords will now give an error instead of just using the thread or >> + task id from the last instance of the keyword. >> + >> +* For the watch command, multiple uses of the 'task' keyword will now >> + give an error instead of just using the task id from the last >> + instance of the keyword. The 'thread' keyword already gave an error >> + when used multiple times with the watch command, this remains unchanged. > > This part is OK, but I wonder whether we should provide an example of > such incorrect usage which will now be flagged, because I'm not sure > everyone will understand what "multiple uses" means in this context. I've now written: * For the break command, multiple uses of the 'thread' or 'task' keywords will now give an error instead of just using the thread or task id from the last instance of the keyword. e.g.: break foo thread 1 thread 2 will now give an error rather than using 'thread 2'. * For the watch command, multiple uses of the 'task' keyword will now give an error instead of just using the task id from the last instance of the keyword. e.g.: watch my_var task 1 task 2 will now give an error rather than using 'task 2'. The 'thread' keyword already gave an error when used multiple times with the watch command, this remains unchanged. How's that? Thanks, Andrew
> From: Andrew Burgess <aburgess@redhat.com> > Cc: gdb-patches@sourceware.org > Date: Thu, 02 Feb 2023 14:08:08 +0000 > > * For the break command, multiple uses of the 'thread' or 'task' > keywords will now give an error instead of just using the thread or > task id from the last instance of the keyword. e.g.: > break foo thread 1 thread 2 > will now give an error rather than using 'thread 2'. > > * For the watch command, multiple uses of the 'task' keyword will now > give an error instead of just using the task id from the last > instance of the keyword. e.g.: > watch my_var task 1 task 2 > will now give an error rather than using 'task 2'. The 'thread' > keyword already gave an error when used multiple times with the > watch command, this remains unchanged. > > How's that? That's fine, but please capitalize "E.g." and leave 2 spaces before it.
On 2023-01-20 9:46 a.m., Andrew Burgess via Gdb-patches wrote: > When creating a breakpoint or watchpoint, the 'thread' and 'task' > keywords can be used to create a thread or task specific breakpoint or > watchpoint. > > Currently, a thread or task specific breakpoint can only apply for a > single thread or task, if multiple threads or tasks are specified when > creating the breakpoint (or watchpoint), then the last specified id > will be used. > > The exception to the above is that when the 'thread' keyword is used > during the creation of a watchpoint, GDB will give an error if > 'thread' is given more than once. > > In this commit I propose making this behaviour consistent, if the > 'thread' or 'task' keywords are used more than once when creating > either a breakpoint or watchpoint, then GDB will give an error. The patch looks fine, but does it make sense to allow both thread and task at the same time? For instance, with gdb.ada/tasks.exp : (gdb) b foo thread 1 task 2 Breakpoint 1 at 0x555555557bd6: file /home/pedro/gdb/rocm/gdb/src/gdb/testsuite/gdb.ada/tasks/foo.adb, line 16. (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 0x0000555555557bd6 in foo at /home/pedro/gdb/rocm/gdb/src/gdb/testsuite/gdb.ada/tasks/foo.adb:16 thread 1 stop only in thread 1 Pedro Alves > > I haven't updated the manual, we don't explicitly say that these > keywords can be repeated, and (to me), given the keyword takes a > single id, I don't think it makes much sense to repeat the keyword. > As such, I see this more as adding a missing error to GDB, rather than > making some big change. However, I have added an entry to the NEWS > file as I guess it is possible that some people might hit this new > error with an existing (I claim, badly written) GDB script. > > I've added some new tests to check for the new error. > > Just one test needed updating, gdb.linespec/keywords.exp, this test > did use the 'thread' keyword twice, and expected the breakpoint to be > created. Looking at what this test was for though, it was checking > the use of '-force-condition', and I don't think that being able to > repeat 'thread' was actually a critical part of this test. > > As such, I've updated this test to expect the error when 'thread' is > repeated. > --- > gdb/NEWS | 9 +++++++++ > gdb/breakpoint.c | 9 +++++++++ > gdb/testsuite/gdb.ada/tasks.exp | 4 ++++ > gdb/testsuite/gdb.linespec/keywords.exp | 10 ++++++++-- > gdb/testsuite/gdb.threads/thread-specific-bp.exp | 4 ++++ > gdb/testsuite/gdb.threads/watchthreads2.exp | 3 +++ > 6 files changed, 37 insertions(+), 2 deletions(-) > > diff --git a/gdb/NEWS b/gdb/NEWS > index c0aac212e30..fb49f62f7e6 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -9,6 +9,15 @@ > This support requires that GDB be built with Python scripting > enabled. > > +* For the break command, multiple uses of the 'thread' or 'task' > + keywords will now give an error instead of just using the thread or > + task id from the last instance of the keyword. > + > +* For the watch command, multiple uses of the 'task' keyword will now > + give an error instead of just using the task id from the last > + instance of the keyword. The 'thread' keyword already gave an error > + when used multiple times with the watch command, this remains unchanged. > + > * New commands > > maintenance print record-instruction [ N ] > diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c > index b2cd89511fb..1400fd49642 100644 > --- a/gdb/breakpoint.c > +++ b/gdb/breakpoint.c > @@ -8801,6 +8801,9 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, > const char *tmptok; > struct thread_info *thr; > > + if (*thread != -1) > + error(_("You can specify only one thread.")); > + > tok = end_tok + 1; > thr = parse_thread_id (tok, &tmptok); > if (tok == tmptok) > @@ -8812,6 +8815,9 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, > { > char *tmptok; > > + if (*task != 0) > + error(_("You can specify only one task.")); > + > tok = end_tok + 1; > *task = strtol (tok, &tmptok, 0); > if (tok == tmptok) > @@ -10094,6 +10100,9 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, > { > char *tmp; > > + if (task != 0) > + error(_("You can specify only one task.")); > + > task = strtol (value_start, &tmp, 0); > if (tmp == value_start) > error (_("Junk after task keyword.")); > diff --git a/gdb/testsuite/gdb.ada/tasks.exp b/gdb/testsuite/gdb.ada/tasks.exp > index 23bf3937a20..4441d92719c 100644 > --- a/gdb/testsuite/gdb.ada/tasks.exp > +++ b/gdb/testsuite/gdb.ada/tasks.exp > @@ -39,6 +39,10 @@ gdb_test "info tasks" \ > "\r\n"] \ > "info tasks before inserting breakpoint" > > +# Check that multiple uses of the 'task' keyword will give an error. > +gdb_test "break break_me task 1 task 3" "You can specify only one task\\." > +gdb_test "watch j task 1 task 3" "You can specify only one task\\." > + > # Insert a breakpoint that should stop only if task 1 stops. Since > # task 1 never calls break_me, this shouldn't actually ever trigger. > # The fact that this breakpoint is created _before_ the next one > diff --git a/gdb/testsuite/gdb.linespec/keywords.exp b/gdb/testsuite/gdb.linespec/keywords.exp > index bff64249542..dc66e32237c 100644 > --- a/gdb/testsuite/gdb.linespec/keywords.exp > +++ b/gdb/testsuite/gdb.linespec/keywords.exp > @@ -80,8 +80,14 @@ foreach prefix {"" "thread 1 "} { > foreach suffix {"" " " " thread 1"} { > foreach cond {"" " if 1"} { > with_test_prefix "prefix: '$prefix', suffix: '$suffix', cond: '$cond'" { > - gdb_breakpoint "main ${prefix}-force-condition${suffix}${cond}"\ > - "message" > + > + if { [regexp thread $prefix] && [regexp thread $suffix] } { > + gdb_test "break main ${prefix}-force-condition${suffix}${cond}" \ > + "You can specify only one thread\\." > + } else { > + gdb_breakpoint "main ${prefix}-force-condition${suffix}${cond}"\ > + "message" > + } > } > } > } > diff --git a/gdb/testsuite/gdb.threads/thread-specific-bp.exp b/gdb/testsuite/gdb.threads/thread-specific-bp.exp > index d33b4f47258..008ae5ed05e 100644 > --- a/gdb/testsuite/gdb.threads/thread-specific-bp.exp > +++ b/gdb/testsuite/gdb.threads/thread-specific-bp.exp > @@ -63,6 +63,10 @@ proc check_thread_specific_breakpoint {non_stop} { > return -1 > } > > + # Check that multiple uses of 'thread' keyword give an error. > + gdb_test "break main thread $start_thre thread $main_thre" \ > + "You can specify only one thread\\." > + > # Set a thread-specific breakpoint at "main". This can't ever > # be hit, but that's OK. > gdb_breakpoint "main thread $start_thre" > diff --git a/gdb/testsuite/gdb.threads/watchthreads2.exp b/gdb/testsuite/gdb.threads/watchthreads2.exp > index 09858aee486..a1398d668a4 100644 > --- a/gdb/testsuite/gdb.threads/watchthreads2.exp > +++ b/gdb/testsuite/gdb.threads/watchthreads2.exp > @@ -71,6 +71,9 @@ if { $nr_started == $NR_THREADS } { > return -1 > } > > +# Check that multiple uses of the 'thread' keyword will give an error. > +gdb_test "watch x thread 1 thread 2" "You can specify only one thread\\." > + > # Watch X, it will be modified by all threads. > # We want this watchpoint to be set *after* all threads are running. > gdb_test "watch x" "Hardware watchpoint 3: x" >
Pedro Alves <pedro@palves.net> writes: > On 2023-01-20 9:46 a.m., Andrew Burgess via Gdb-patches wrote: >> When creating a breakpoint or watchpoint, the 'thread' and 'task' >> keywords can be used to create a thread or task specific breakpoint or >> watchpoint. >> >> Currently, a thread or task specific breakpoint can only apply for a >> single thread or task, if multiple threads or tasks are specified when >> creating the breakpoint (or watchpoint), then the last specified id >> will be used. >> >> The exception to the above is that when the 'thread' keyword is used >> during the creation of a watchpoint, GDB will give an error if >> 'thread' is given more than once. >> >> In this commit I propose making this behaviour consistent, if the >> 'thread' or 'task' keywords are used more than once when creating >> either a breakpoint or watchpoint, then GDB will give an error. > > The patch looks fine, but does it make sense to allow both thread and task > at the same time? I don't know enough about Ada tasks to comment here. If someone who knows can say categorically that threads and tasks can't coexist than I'd be happy to add a patch to prevent them being used together. Thanks, Andrew > > For instance, with gdb.ada/tasks.exp : > > (gdb) b foo thread 1 task 2 > Breakpoint 1 at 0x555555557bd6: file /home/pedro/gdb/rocm/gdb/src/gdb/testsuite/gdb.ada/tasks/foo.adb, line 16. > (gdb) info breakpoints > Num Type Disp Enb Address What > 1 breakpoint keep y 0x0000555555557bd6 in foo at /home/pedro/gdb/rocm/gdb/src/gdb/testsuite/gdb.ada/tasks/foo.adb:16 thread 1 > stop only in thread 1 > > Pedro Alves > >> >> I haven't updated the manual, we don't explicitly say that these >> keywords can be repeated, and (to me), given the keyword takes a >> single id, I don't think it makes much sense to repeat the keyword. >> As such, I see this more as adding a missing error to GDB, rather than >> making some big change. However, I have added an entry to the NEWS >> file as I guess it is possible that some people might hit this new >> error with an existing (I claim, badly written) GDB script. >> >> I've added some new tests to check for the new error. >> >> Just one test needed updating, gdb.linespec/keywords.exp, this test >> did use the 'thread' keyword twice, and expected the breakpoint to be >> created. Looking at what this test was for though, it was checking >> the use of '-force-condition', and I don't think that being able to >> repeat 'thread' was actually a critical part of this test. >> >> As such, I've updated this test to expect the error when 'thread' is >> repeated. >> --- >> gdb/NEWS | 9 +++++++++ >> gdb/breakpoint.c | 9 +++++++++ >> gdb/testsuite/gdb.ada/tasks.exp | 4 ++++ >> gdb/testsuite/gdb.linespec/keywords.exp | 10 ++++++++-- >> gdb/testsuite/gdb.threads/thread-specific-bp.exp | 4 ++++ >> gdb/testsuite/gdb.threads/watchthreads2.exp | 3 +++ >> 6 files changed, 37 insertions(+), 2 deletions(-) >> >> diff --git a/gdb/NEWS b/gdb/NEWS >> index c0aac212e30..fb49f62f7e6 100644 >> --- a/gdb/NEWS >> +++ b/gdb/NEWS >> @@ -9,6 +9,15 @@ >> This support requires that GDB be built with Python scripting >> enabled. >> >> +* For the break command, multiple uses of the 'thread' or 'task' >> + keywords will now give an error instead of just using the thread or >> + task id from the last instance of the keyword. >> + >> +* For the watch command, multiple uses of the 'task' keyword will now >> + give an error instead of just using the task id from the last >> + instance of the keyword. The 'thread' keyword already gave an error >> + when used multiple times with the watch command, this remains unchanged. >> + >> * New commands >> >> maintenance print record-instruction [ N ] >> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c >> index b2cd89511fb..1400fd49642 100644 >> --- a/gdb/breakpoint.c >> +++ b/gdb/breakpoint.c >> @@ -8801,6 +8801,9 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, >> const char *tmptok; >> struct thread_info *thr; >> >> + if (*thread != -1) >> + error(_("You can specify only one thread.")); >> + >> tok = end_tok + 1; >> thr = parse_thread_id (tok, &tmptok); >> if (tok == tmptok) >> @@ -8812,6 +8815,9 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, >> { >> char *tmptok; >> >> + if (*task != 0) >> + error(_("You can specify only one task.")); >> + >> tok = end_tok + 1; >> *task = strtol (tok, &tmptok, 0); >> if (tok == tmptok) >> @@ -10094,6 +10100,9 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, >> { >> char *tmp; >> >> + if (task != 0) >> + error(_("You can specify only one task.")); >> + >> task = strtol (value_start, &tmp, 0); >> if (tmp == value_start) >> error (_("Junk after task keyword.")); >> diff --git a/gdb/testsuite/gdb.ada/tasks.exp b/gdb/testsuite/gdb.ada/tasks.exp >> index 23bf3937a20..4441d92719c 100644 >> --- a/gdb/testsuite/gdb.ada/tasks.exp >> +++ b/gdb/testsuite/gdb.ada/tasks.exp >> @@ -39,6 +39,10 @@ gdb_test "info tasks" \ >> "\r\n"] \ >> "info tasks before inserting breakpoint" >> >> +# Check that multiple uses of the 'task' keyword will give an error. >> +gdb_test "break break_me task 1 task 3" "You can specify only one task\\." >> +gdb_test "watch j task 1 task 3" "You can specify only one task\\." >> + >> # Insert a breakpoint that should stop only if task 1 stops. Since >> # task 1 never calls break_me, this shouldn't actually ever trigger. >> # The fact that this breakpoint is created _before_ the next one >> diff --git a/gdb/testsuite/gdb.linespec/keywords.exp b/gdb/testsuite/gdb.linespec/keywords.exp >> index bff64249542..dc66e32237c 100644 >> --- a/gdb/testsuite/gdb.linespec/keywords.exp >> +++ b/gdb/testsuite/gdb.linespec/keywords.exp >> @@ -80,8 +80,14 @@ foreach prefix {"" "thread 1 "} { >> foreach suffix {"" " " " thread 1"} { >> foreach cond {"" " if 1"} { >> with_test_prefix "prefix: '$prefix', suffix: '$suffix', cond: '$cond'" { >> - gdb_breakpoint "main ${prefix}-force-condition${suffix}${cond}"\ >> - "message" >> + >> + if { [regexp thread $prefix] && [regexp thread $suffix] } { >> + gdb_test "break main ${prefix}-force-condition${suffix}${cond}" \ >> + "You can specify only one thread\\." >> + } else { >> + gdb_breakpoint "main ${prefix}-force-condition${suffix}${cond}"\ >> + "message" >> + } >> } >> } >> } >> diff --git a/gdb/testsuite/gdb.threads/thread-specific-bp.exp b/gdb/testsuite/gdb.threads/thread-specific-bp.exp >> index d33b4f47258..008ae5ed05e 100644 >> --- a/gdb/testsuite/gdb.threads/thread-specific-bp.exp >> +++ b/gdb/testsuite/gdb.threads/thread-specific-bp.exp >> @@ -63,6 +63,10 @@ proc check_thread_specific_breakpoint {non_stop} { >> return -1 >> } >> >> + # Check that multiple uses of 'thread' keyword give an error. >> + gdb_test "break main thread $start_thre thread $main_thre" \ >> + "You can specify only one thread\\." >> + >> # Set a thread-specific breakpoint at "main". This can't ever >> # be hit, but that's OK. >> gdb_breakpoint "main thread $start_thre" >> diff --git a/gdb/testsuite/gdb.threads/watchthreads2.exp b/gdb/testsuite/gdb.threads/watchthreads2.exp >> index 09858aee486..a1398d668a4 100644 >> --- a/gdb/testsuite/gdb.threads/watchthreads2.exp >> +++ b/gdb/testsuite/gdb.threads/watchthreads2.exp >> @@ -71,6 +71,9 @@ if { $nr_started == $NR_THREADS } { >> return -1 >> } >> >> +# Check that multiple uses of the 'thread' keyword will give an error. >> +gdb_test "watch x thread 1 thread 2" "You can specify only one thread\\." >> + >> # Watch X, it will be modified by all threads. >> # We want this watchpoint to be set *after* all threads are running. >> gdb_test "watch x" "Hardware watchpoint 3: x" >>
Hi Andrew, > > On 2023-01-20 9:46 a.m., Andrew Burgess via Gdb-patches wrote: > >> When creating a breakpoint or watchpoint, the 'thread' and 'task' > >> keywords can be used to create a thread or task specific breakpoint or > >> watchpoint. > >> > >> Currently, a thread or task specific breakpoint can only apply for a > >> single thread or task, if multiple threads or tasks are specified when > >> creating the breakpoint (or watchpoint), then the last specified id > >> will be used. > >> > >> The exception to the above is that when the 'thread' keyword is used > >> during the creation of a watchpoint, GDB will give an error if > >> 'thread' is given more than once. > >> > >> In this commit I propose making this behaviour consistent, if the > >> 'thread' or 'task' keywords are used more than once when creating > >> either a breakpoint or watchpoint, then GDB will give an error. > > > > The patch looks fine, but does it make sense to allow both thread and task > > at the same time? > > I don't know enough about Ada tasks to comment here. If someone who > knows can say categorically that threads and tasks can't coexist than > I'd be happy to add a patch to prevent them being used together. Pedro raises a good question! At the language level, I don't think there is anything that says that Ada tasks can't be implemented independently of threads. In fact, on baremetal targets, that's what we have to do, since we don't have an underlying thread layer. With that said, for GDB itself, the implementation of the ada tasking layer is done on top of the GDB's thread layer. In simple terms, what the ada-task.c module does is simply translating Ada task IDs into thread ptid-s. So, when we say "switch to task X", or "break on task X", internally, it essentially translates "task X" into "thread Y". Based on this implementation, it is always suspicious if someone uses both a thread ID and a task ID in the same command (or I would view those as "additive", but that's not the direction taken by your patch series). I would therefore indeed raise an error if both are used in the same command. One side note about the baremetal platforms, since I mentioned them: While the platform itself doesn't provide threads [1], you might ask yourself how the Ada tasking layer might be implemented. This is where the ravenscar-thread layer kicks in. It actually relies on the Ada runtime to determine the list of tasks that exists, and constructs a list of threads from that data, thus providing the threads that the ada-task module needs to function. [1] On baremetal target, we've seen multicore system report each CPU as a thread. That's what QEMU does, for instance. I hope this helps!
Joel Brobecker via Gdb-patches <gdb-patches@sourceware.org> writes: > Hi Andrew, > >> > On 2023-01-20 9:46 a.m., Andrew Burgess via Gdb-patches wrote: >> >> When creating a breakpoint or watchpoint, the 'thread' and 'task' >> >> keywords can be used to create a thread or task specific breakpoint or >> >> watchpoint. >> >> >> >> Currently, a thread or task specific breakpoint can only apply for a >> >> single thread or task, if multiple threads or tasks are specified when >> >> creating the breakpoint (or watchpoint), then the last specified id >> >> will be used. >> >> >> >> The exception to the above is that when the 'thread' keyword is used >> >> during the creation of a watchpoint, GDB will give an error if >> >> 'thread' is given more than once. >> >> >> >> In this commit I propose making this behaviour consistent, if the >> >> 'thread' or 'task' keywords are used more than once when creating >> >> either a breakpoint or watchpoint, then GDB will give an error. >> > >> > The patch looks fine, but does it make sense to allow both thread and task >> > at the same time? >> >> I don't know enough about Ada tasks to comment here. If someone who >> knows can say categorically that threads and tasks can't coexist than >> I'd be happy to add a patch to prevent them being used together. > > Pedro raises a good question! > > At the language level, I don't think there is anything that says > that Ada tasks can't be implemented independently of threads. > In fact, on baremetal targets, that's what we have to do, since > we don't have an underlying thread layer. > > With that said, for GDB itself, the implementation of the ada tasking > layer is done on top of the GDB's thread layer. In simple terms, > what the ada-task.c module does is simply translating Ada task IDs > into thread ptid-s. So, when we say "switch to task X", or "break on > task X", internally, it essentially translates "task X" into "thread Y". > > Based on this implementation, it is always suspicious if someone > uses both a thread ID and a task ID in the same command (or I would > view those as "additive", but that's not the direction taken by > your patch series). I would therefore indeed raise an error if > both are used in the same command. > > One side note about the baremetal platforms, since I mentioned them: > While the platform itself doesn't provide threads [1], you might ask > yourself how the Ada tasking layer might be implemented. This is where > the ravenscar-thread layer kicks in. It actually relies on the Ada > runtime to determine the list of tasks that exists, and constructs > a list of threads from that data, thus providing the threads that > the ada-task module needs to function. > > [1] On baremetal target, we've seen multicore system report each CPU > as a thread. That's what QEMU does, for instance. > > I hope this helps! Thanks for the detailed write up. I'm going to keep the original patch as is for now, but will follow up with an additional patch that will give an error if a user tries to use 'task' and 'thread' in the same command. Thanks, Andrew
Pedro Alves <pedro@palves.net> writes: > On 2023-01-20 9:46 a.m., Andrew Burgess via Gdb-patches wrote: >> When creating a breakpoint or watchpoint, the 'thread' and 'task' >> keywords can be used to create a thread or task specific breakpoint or >> watchpoint. >> >> Currently, a thread or task specific breakpoint can only apply for a >> single thread or task, if multiple threads or tasks are specified when >> creating the breakpoint (or watchpoint), then the last specified id >> will be used. >> >> The exception to the above is that when the 'thread' keyword is used >> during the creation of a watchpoint, GDB will give an error if >> 'thread' is given more than once. >> >> In this commit I propose making this behaviour consistent, if the >> 'thread' or 'task' keywords are used more than once when creating >> either a breakpoint or watchpoint, then GDB will give an error. > > The patch looks fine, but does it make sense to allow both thread and task > at the same time? Thanks for the review. I've made the fix Eli suggested, and pushed this patch. Given Joel's feedback I'll take a look at a follow up patch the prevents thread and task being used together. Thanks, Andrew > > For instance, with gdb.ada/tasks.exp : > > (gdb) b foo thread 1 task 2 > Breakpoint 1 at 0x555555557bd6: file /home/pedro/gdb/rocm/gdb/src/gdb/testsuite/gdb.ada/tasks/foo.adb, line 16. > (gdb) info breakpoints > Num Type Disp Enb Address What > 1 breakpoint keep y 0x0000555555557bd6 in foo at /home/pedro/gdb/rocm/gdb/src/gdb/testsuite/gdb.ada/tasks/foo.adb:16 thread 1 > stop only in thread 1 > > Pedro Alves > >> >> I haven't updated the manual, we don't explicitly say that these >> keywords can be repeated, and (to me), given the keyword takes a >> single id, I don't think it makes much sense to repeat the keyword. >> As such, I see this more as adding a missing error to GDB, rather than >> making some big change. However, I have added an entry to the NEWS >> file as I guess it is possible that some people might hit this new >> error with an existing (I claim, badly written) GDB script. >> >> I've added some new tests to check for the new error. >> >> Just one test needed updating, gdb.linespec/keywords.exp, this test >> did use the 'thread' keyword twice, and expected the breakpoint to be >> created. Looking at what this test was for though, it was checking >> the use of '-force-condition', and I don't think that being able to >> repeat 'thread' was actually a critical part of this test. >> >> As such, I've updated this test to expect the error when 'thread' is >> repeated. >> --- >> gdb/NEWS | 9 +++++++++ >> gdb/breakpoint.c | 9 +++++++++ >> gdb/testsuite/gdb.ada/tasks.exp | 4 ++++ >> gdb/testsuite/gdb.linespec/keywords.exp | 10 ++++++++-- >> gdb/testsuite/gdb.threads/thread-specific-bp.exp | 4 ++++ >> gdb/testsuite/gdb.threads/watchthreads2.exp | 3 +++ >> 6 files changed, 37 insertions(+), 2 deletions(-) >> >> diff --git a/gdb/NEWS b/gdb/NEWS >> index c0aac212e30..fb49f62f7e6 100644 >> --- a/gdb/NEWS >> +++ b/gdb/NEWS >> @@ -9,6 +9,15 @@ >> This support requires that GDB be built with Python scripting >> enabled. >> >> +* For the break command, multiple uses of the 'thread' or 'task' >> + keywords will now give an error instead of just using the thread or >> + task id from the last instance of the keyword. >> + >> +* For the watch command, multiple uses of the 'task' keyword will now >> + give an error instead of just using the task id from the last >> + instance of the keyword. The 'thread' keyword already gave an error >> + when used multiple times with the watch command, this remains unchanged. >> + >> * New commands >> >> maintenance print record-instruction [ N ] >> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c >> index b2cd89511fb..1400fd49642 100644 >> --- a/gdb/breakpoint.c >> +++ b/gdb/breakpoint.c >> @@ -8801,6 +8801,9 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, >> const char *tmptok; >> struct thread_info *thr; >> >> + if (*thread != -1) >> + error(_("You can specify only one thread.")); >> + >> tok = end_tok + 1; >> thr = parse_thread_id (tok, &tmptok); >> if (tok == tmptok) >> @@ -8812,6 +8815,9 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, >> { >> char *tmptok; >> >> + if (*task != 0) >> + error(_("You can specify only one task.")); >> + >> tok = end_tok + 1; >> *task = strtol (tok, &tmptok, 0); >> if (tok == tmptok) >> @@ -10094,6 +10100,9 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, >> { >> char *tmp; >> >> + if (task != 0) >> + error(_("You can specify only one task.")); >> + >> task = strtol (value_start, &tmp, 0); >> if (tmp == value_start) >> error (_("Junk after task keyword.")); >> diff --git a/gdb/testsuite/gdb.ada/tasks.exp b/gdb/testsuite/gdb.ada/tasks.exp >> index 23bf3937a20..4441d92719c 100644 >> --- a/gdb/testsuite/gdb.ada/tasks.exp >> +++ b/gdb/testsuite/gdb.ada/tasks.exp >> @@ -39,6 +39,10 @@ gdb_test "info tasks" \ >> "\r\n"] \ >> "info tasks before inserting breakpoint" >> >> +# Check that multiple uses of the 'task' keyword will give an error. >> +gdb_test "break break_me task 1 task 3" "You can specify only one task\\." >> +gdb_test "watch j task 1 task 3" "You can specify only one task\\." >> + >> # Insert a breakpoint that should stop only if task 1 stops. Since >> # task 1 never calls break_me, this shouldn't actually ever trigger. >> # The fact that this breakpoint is created _before_ the next one >> diff --git a/gdb/testsuite/gdb.linespec/keywords.exp b/gdb/testsuite/gdb.linespec/keywords.exp >> index bff64249542..dc66e32237c 100644 >> --- a/gdb/testsuite/gdb.linespec/keywords.exp >> +++ b/gdb/testsuite/gdb.linespec/keywords.exp >> @@ -80,8 +80,14 @@ foreach prefix {"" "thread 1 "} { >> foreach suffix {"" " " " thread 1"} { >> foreach cond {"" " if 1"} { >> with_test_prefix "prefix: '$prefix', suffix: '$suffix', cond: '$cond'" { >> - gdb_breakpoint "main ${prefix}-force-condition${suffix}${cond}"\ >> - "message" >> + >> + if { [regexp thread $prefix] && [regexp thread $suffix] } { >> + gdb_test "break main ${prefix}-force-condition${suffix}${cond}" \ >> + "You can specify only one thread\\." >> + } else { >> + gdb_breakpoint "main ${prefix}-force-condition${suffix}${cond}"\ >> + "message" >> + } >> } >> } >> } >> diff --git a/gdb/testsuite/gdb.threads/thread-specific-bp.exp b/gdb/testsuite/gdb.threads/thread-specific-bp.exp >> index d33b4f47258..008ae5ed05e 100644 >> --- a/gdb/testsuite/gdb.threads/thread-specific-bp.exp >> +++ b/gdb/testsuite/gdb.threads/thread-specific-bp.exp >> @@ -63,6 +63,10 @@ proc check_thread_specific_breakpoint {non_stop} { >> return -1 >> } >> >> + # Check that multiple uses of 'thread' keyword give an error. >> + gdb_test "break main thread $start_thre thread $main_thre" \ >> + "You can specify only one thread\\." >> + >> # Set a thread-specific breakpoint at "main". This can't ever >> # be hit, but that's OK. >> gdb_breakpoint "main thread $start_thre" >> diff --git a/gdb/testsuite/gdb.threads/watchthreads2.exp b/gdb/testsuite/gdb.threads/watchthreads2.exp >> index 09858aee486..a1398d668a4 100644 >> --- a/gdb/testsuite/gdb.threads/watchthreads2.exp >> +++ b/gdb/testsuite/gdb.threads/watchthreads2.exp >> @@ -71,6 +71,9 @@ if { $nr_started == $NR_THREADS } { >> return -1 >> } >> >> +# Check that multiple uses of the 'thread' keyword will give an error. >> +gdb_test "watch x thread 1 thread 2" "You can specify only one thread\\." >> + >> # Watch X, it will be modified by all threads. >> # We want this watchpoint to be set *after* all threads are running. >> gdb_test "watch x" "Hardware watchpoint 3: x" >>
diff --git a/gdb/NEWS b/gdb/NEWS index c0aac212e30..fb49f62f7e6 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -9,6 +9,15 @@ This support requires that GDB be built with Python scripting enabled. +* For the break command, multiple uses of the 'thread' or 'task' + keywords will now give an error instead of just using the thread or + task id from the last instance of the keyword. + +* For the watch command, multiple uses of the 'task' keyword will now + give an error instead of just using the task id from the last + instance of the keyword. The 'thread' keyword already gave an error + when used multiple times with the watch command, this remains unchanged. + * New commands maintenance print record-instruction [ N ] diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index b2cd89511fb..1400fd49642 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -8801,6 +8801,9 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, const char *tmptok; struct thread_info *thr; + if (*thread != -1) + error(_("You can specify only one thread.")); + tok = end_tok + 1; thr = parse_thread_id (tok, &tmptok); if (tok == tmptok) @@ -8812,6 +8815,9 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, { char *tmptok; + if (*task != 0) + error(_("You can specify only one task.")); + tok = end_tok + 1; *task = strtol (tok, &tmptok, 0); if (tok == tmptok) @@ -10094,6 +10100,9 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, { char *tmp; + if (task != 0) + error(_("You can specify only one task.")); + task = strtol (value_start, &tmp, 0); if (tmp == value_start) error (_("Junk after task keyword.")); diff --git a/gdb/testsuite/gdb.ada/tasks.exp b/gdb/testsuite/gdb.ada/tasks.exp index 23bf3937a20..4441d92719c 100644 --- a/gdb/testsuite/gdb.ada/tasks.exp +++ b/gdb/testsuite/gdb.ada/tasks.exp @@ -39,6 +39,10 @@ gdb_test "info tasks" \ "\r\n"] \ "info tasks before inserting breakpoint" +# Check that multiple uses of the 'task' keyword will give an error. +gdb_test "break break_me task 1 task 3" "You can specify only one task\\." +gdb_test "watch j task 1 task 3" "You can specify only one task\\." + # Insert a breakpoint that should stop only if task 1 stops. Since # task 1 never calls break_me, this shouldn't actually ever trigger. # The fact that this breakpoint is created _before_ the next one diff --git a/gdb/testsuite/gdb.linespec/keywords.exp b/gdb/testsuite/gdb.linespec/keywords.exp index bff64249542..dc66e32237c 100644 --- a/gdb/testsuite/gdb.linespec/keywords.exp +++ b/gdb/testsuite/gdb.linespec/keywords.exp @@ -80,8 +80,14 @@ foreach prefix {"" "thread 1 "} { foreach suffix {"" " " " thread 1"} { foreach cond {"" " if 1"} { with_test_prefix "prefix: '$prefix', suffix: '$suffix', cond: '$cond'" { - gdb_breakpoint "main ${prefix}-force-condition${suffix}${cond}"\ - "message" + + if { [regexp thread $prefix] && [regexp thread $suffix] } { + gdb_test "break main ${prefix}-force-condition${suffix}${cond}" \ + "You can specify only one thread\\." + } else { + gdb_breakpoint "main ${prefix}-force-condition${suffix}${cond}"\ + "message" + } } } } diff --git a/gdb/testsuite/gdb.threads/thread-specific-bp.exp b/gdb/testsuite/gdb.threads/thread-specific-bp.exp index d33b4f47258..008ae5ed05e 100644 --- a/gdb/testsuite/gdb.threads/thread-specific-bp.exp +++ b/gdb/testsuite/gdb.threads/thread-specific-bp.exp @@ -63,6 +63,10 @@ proc check_thread_specific_breakpoint {non_stop} { return -1 } + # Check that multiple uses of 'thread' keyword give an error. + gdb_test "break main thread $start_thre thread $main_thre" \ + "You can specify only one thread\\." + # Set a thread-specific breakpoint at "main". This can't ever # be hit, but that's OK. gdb_breakpoint "main thread $start_thre" diff --git a/gdb/testsuite/gdb.threads/watchthreads2.exp b/gdb/testsuite/gdb.threads/watchthreads2.exp index 09858aee486..a1398d668a4 100644 --- a/gdb/testsuite/gdb.threads/watchthreads2.exp +++ b/gdb/testsuite/gdb.threads/watchthreads2.exp @@ -71,6 +71,9 @@ if { $nr_started == $NR_THREADS } { return -1 } +# Check that multiple uses of the 'thread' keyword will give an error. +gdb_test "watch x thread 1 thread 2" "You can specify only one thread\\." + # Watch X, it will be modified by all threads. # We want this watchpoint to be set *after* all threads are running. gdb_test "watch x" "Hardware watchpoint 3: x"