From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 151D03858C30 for ; Mon, 6 Feb 2023 14:48:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 151D03858C30 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675694929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KZUfV1Kzq+lJcY33na/35QwFMM+NfXG/PSoJyrEWm1s=; b=ai9vgkWg+7xmKON52QADCikYOo5QeUZUV/QajexKeQ4SfkbqvObL6l/WmJ6tDifoAJ4kUU +vG08yPZXYpZMdXDNTGyjvha/DRDFMct3e29clmDfo4wd4l9/1reM0gaKJ4VuccPBKbvr4 nnytwcgrM43Ur6GI5q1tCa3ezPImnIc= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-308-GrgZDpixP9iMyLMfB2E6TQ-1; Mon, 06 Feb 2023 09:48:48 -0500 X-MC-Unique: GrgZDpixP9iMyLMfB2E6TQ-1 Received: by mail-qt1-f198.google.com with SMTP id p6-20020a05622a048600b003b9a3ab9153so6550079qtx.8 for ; Mon, 06 Feb 2023 06:48:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KZUfV1Kzq+lJcY33na/35QwFMM+NfXG/PSoJyrEWm1s=; b=TwwRZ7tv6g7iq8MzX4s7vK/XWpXx2fFb3JxEby0WEfjnNVz4S0zEkg0Pb4Vd/l8S3M 7L7gs6QUubnGkKC2SFRW/NJ2eO7KN7W7UGw46z9fWYqSQD15ElXbPW3g16qo72PhnWdW oZeBgtv1Zre5QgiGhKaV6iOpitev2FSGg9OEe90CSfOvcFokLpq5QpGw/RNIq2sVZk6m b9QBSBPNVizNH822rcE0p7v5TzIdny2CdvmH+yRudoEIvX6atqznwQns9yC3+t1aJZRr utx7e8HT602g5bjVaMHVNpF7WzaSXIfOavnv2e8K4WID6lybE93UuoUEhv3MKyL7+Y8T 4jQw== X-Gm-Message-State: AO0yUKUnSOZo+Fz4hzQEK9bWqXHgMUZbvYu04nEufGM9rU2UBbqsX87n 8KA5Nq/d7rcCftveUseVpdKwOFWYowLEBCGURQ14HQeBTJFWa2QU8+MlyJ7jnSVvJWS/Q99jg7K 6kerylT+iDSBkpNmb7cDHXw== X-Received: by 2002:a05:622a:1909:b0:3b9:c44e:368 with SMTP id w9-20020a05622a190900b003b9c44e0368mr30195423qtc.55.1675694927134; Mon, 06 Feb 2023 06:48:47 -0800 (PST) X-Google-Smtp-Source: AK7set9aZKzR6STfHbXpnUeiLLQcKQPz0P8P0yssymEmptEFhmB2UzB+tM6TQBomvJz2mxXgBdE2Ew== X-Received: by 2002:a05:622a:1909:b0:3b9:c44e:368 with SMTP id w9-20020a05622a190900b003b9c44e0368mr30195339qtc.55.1675694926387; Mon, 06 Feb 2023 06:48:46 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id 16-20020a05620a049000b0072692330190sm7508859qkr.64.2023.02.06.06.48.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 06:48:46 -0800 (PST) From: Andrew Burgess To: Pedro Alves , gdb-patches@sourceware.org Subject: Re: [PATCHv2 3/6] gdb: fix display of thread condition for multi-location breakpoints In-Reply-To: References: <403eeb015d985423d995b34a345e4e7816b8c349.1674207665.git.aburgess@redhat.com> Date: Mon, 06 Feb 2023 14:48:44 +0000 Message-ID: <87h6vyx31v.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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,KAM_SHORT,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 List-Id: Pedro Alves writes: > On 2023-01-20 9:46 a.m., Andrew Burgess via Gdb-patches wrote: >> If a breakpoint with multiple locations has a thread condition, then >> the 'info breakpoints' output is a little messed up, here's an example >> of the current output: >> >> (gdb) break foo thread 1 >> Breakpoint 2 at 0x401114: foo. (3 locations) >> (gdb) break bar thread 1 >> Breakpoint 3 at 0x40110a: file /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c, line 32. >> (gdb) info breakpoints >> Num Type Disp Enb Address What >> 2 breakpoint keep y thread 1 >> stop only in thread 1 >> 2.1 y 0x0000000000401114 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 >> 2.2 y 0x0000000000401146 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 >> 2.3 y 0x0000000000401168 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 >> 3 breakpoint keep y 0x000000000040110a in bar at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:32 thread 1 >> stop only in thread 1 >> >> Notice that, at the end of the location for breakpoint 3, the 'thread >> 1' condition is printed, but this is then repeated on the next line >> with 'stop only in thread 1'. >> >> In contrast, for breakpoint 2, the 'thread 1' appears randomly, in the >> "What" column, though slightly offset, non of the separate locations >> have the 'thread 1' information. Additionally for breakpoint 2 we >> also get a 'stop only in thread 1' line. >> >> There's two things going on here. First the randomly placed 'thread >> 1' for breakpoint 2 is due to a bug in print_one_breakpoint_location, >> where we check the variable part_of_multiple instead of >> header_of_multiple. >> >> If I fix this oversight, then the output is now: >> >> (gdb) break foo thread 1 >> Breakpoint 2 at 0x401114: foo. (3 locations) >> (gdb) break bar thread 1 >> Breakpoint 3 at 0x40110a: file /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c, line 32. >> (gdb) info breakpoints >> Num Type Disp Enb Address What >> 2 breakpoint keep y >> stop only in thread 1 >> 2.1 y 0x0000000000401114 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 thread 1 >> 2.2 y 0x0000000000401146 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 thread 1 >> 2.3 y 0x0000000000401168 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 thread 1 >> 3 breakpoint keep y 0x000000000040110a in bar at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:32 thread 1 >> stop only in thread 1 >> >> The 'thread 1' condition is now displayed at the end of each location, >> which makes the output the same for single location breakpoints and >> multi-location breakpoints. >> >> However, there's still some duplication here. Both breakpoints 2 and >> 3 include a 'stop only in thread 1' line, and it feels like the >> additional 'thread 1' is redundant. In fact, there's a comment to >> this very effect in the code: >> >> /* FIXME: This seems to be redundant and lost here; see the >> "stop only in" line a little further down. */ >> >> So, lets fix this FIXME. The new plan is to remove all the trailing >> 'thread 1' markers from the CLI output, we now get this: >> >> (gdb) break foo thread 1 >> Breakpoint 2 at 0x401114: foo. (3 locations) >> (gdb) break bar thread 1 >> Breakpoint 3 at 0x40110a: file /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c, line 32. >> (gdb) info breakpoints >> Num Type Disp Enb Address What >> 2 breakpoint keep y >> stop only in thread 1 >> 2.1 y 0x0000000000401114 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 >> 2.2 y 0x0000000000401146 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 >> 2.3 y 0x0000000000401168 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 >> 3 breakpoint keep y 0x000000000040110a in bar at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:32 >> stop only in thread 1 >> > > This is the right direction, IMO. The "thread 1" string is at best part of the breakpoint's > location spec, not of the code locations that spec resolved to. > > If we went forward with my proposal to always show breakpoints using the multi-locations mode, > and, to include the location spec in the "What" column of the breakpoint header, we could show: > > (gdb) info breakpoints > Num Type Disp Enb Address What > 2 breakpoint keep y foo thread 1 > stop only in thread 1 > 2.1 y 0x0000000000401114 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 > 2.2 y 0x0000000000401146 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 > 2.3 y 0x0000000000401168 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 > 3 breakpoint keep y bar thread 1 > stop only in thread 1 > 3.1 breakpoint keep y 0x000000000040110a in bar at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:32 > > ... for instance. Or not include the "thread 1". But my point is that if we were to show it, that's where we would > show it, not in the breapoint locations. I dug out your multi-location proposal, and it looks good. It's a shame it got bogged down as it did.... > >> All of the above points are also true for the Ada 'task' breakpoint >> condition, and the changes I've made also update how the task >> information is printed, though in the case of the Ada task there was >> no 'stop only in task XXX' line printed, so I've added one of those. >> >> Obviously it can't be quite that easy. For MI backwards compatibility >> I've retained the existing code (but now only for MI like outputs), >> which ensures we should generate backwards compatible output. >> >> I've extended an Ada test to cover the new task related output, and >> updated all the tests I could find that checked for the old output. >> --- >> gdb/breakpoint.c | 30 ++++---- >> gdb/testsuite/gdb.ada/tasks.exp | 15 ++-- >> gdb/testsuite/gdb.base/save-bp.exp | 2 +- >> gdb/testsuite/gdb.base/thread-bp-multi-loc.c | 44 ++++++++++++ >> .../gdb.base/thread-bp-multi-loc.exp | 72 +++++++++++++++++++ >> 5 files changed, 141 insertions(+), 22 deletions(-) >> create mode 100644 gdb/testsuite/gdb.base/thread-bp-multi-loc.c >> create mode 100644 gdb/testsuite/gdb.base/thread-bp-multi-loc.exp >> >> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c >> index 00cc2ab401c..b2cd89511fb 100644 >> --- a/gdb/breakpoint.c >> +++ b/gdb/breakpoint.c >> @@ -6468,20 +6468,19 @@ print_one_breakpoint_location (struct breakpoint *b, >> output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); >> } >> >> - if (!part_of_multiple) >> + /* In the MI output, each location of a thread or task specific >> + breakpoint is with the relevant thread or task ID. This is done for >> + backwards compatibility reasons. > > Is "is with" idiomatic English meaning "includes"? I don't think I ever heard that. > Or is some word missing somewhere? I'd suggest using "includes" or some > such instead. Fixed. > >> + >> + For the CLI output, the thread/task information is printed on a >> + separate line, see the 'stop only in thread' and 'stop only in task' >> + output below. */ >> + if (!header_of_multiple && uiout->is_mi_like_p ()) >> { >> if (b->thread != -1) >> - { >> - /* FIXME: This seems to be redundant and lost here; see the >> - "stop only in" line a little further down. */ >> - uiout->text (" thread "); >> - uiout->field_signed ("thread", b->thread); >> - } >> + uiout->field_signed ("thread", b->thread); >> else if (b->task != 0) >> - { >> - uiout->text (" task "); >> - uiout->field_signed ("task", b->task); >> - } >> + uiout->field_signed ("task", b->task); >> } >> >> uiout->text ("\n"); >> @@ -6536,7 +6535,14 @@ print_one_breakpoint_location (struct breakpoint *b, >> } >> uiout->text ("\n"); >> } >> - >> + >> + if (!part_of_multiple && b->task != 0) >> + { >> + uiout->text ("\tstop only in task "); >> + uiout->field_signed ("task", b->task); >> + uiout->text ("\n"); >> + } >> + >> if (!part_of_multiple) >> { >> if (b->hit_count) >> diff --git a/gdb/testsuite/gdb.ada/tasks.exp b/gdb/testsuite/gdb.ada/tasks.exp >> index a9b58f20cf6..23bf3937a20 100644 >> --- a/gdb/testsuite/gdb.ada/tasks.exp >> +++ b/gdb/testsuite/gdb.ada/tasks.exp >> @@ -46,21 +46,18 @@ gdb_test "info tasks" \ >> # breakpoint in the list that matched the triggered-breakpoint's >> # address, no matter which task it was specific to. >> gdb_test "break break_me task 1" "Breakpoint .* at .*" >> +gdb_test "info breakpoints" "foo.adb:${decimal}\r\n\\s+stop only in task 1" \ >> + "check info breakpoints for task 1 breakpoint" >> >> # Now, insert a breakpoint that should stop only if task 3 stops, and >> # extract its number. >> -set bp_number -1 >> -set test "break break_me task 3" >> -gdb_test_multiple $test $test { >> - -re "Breakpoint (.*) at .*$gdb_prompt $" { >> - set bp_number $expect_out(1,string) >> - pass $test >> - } >> -} >> - >> +gdb_breakpoint "break_me task 3" >> +set bp_number [get_integer_valueof "\$bpnum" -1] >> if {$bp_number < 0} { >> return >> } >> +gdb_test "info breakpoints" "foo.adb:${decimal}\r\n\\s+stop only in task 3" \ >> + "check info breakpoints for task 3 breakpoint" >> >> # Continue to that breakpoint. Task 2 should hit it first, and GDB >> # is expected to ignore that hit and resume the execution. Only then >> diff --git a/gdb/testsuite/gdb.base/save-bp.exp b/gdb/testsuite/gdb.base/save-bp.exp >> index a39712c7f5c..41d71837fb6 100644 >> --- a/gdb/testsuite/gdb.base/save-bp.exp >> +++ b/gdb/testsuite/gdb.base/save-bp.exp >> @@ -79,7 +79,7 @@ gdb_test_sequence "info break" "info break" [list \ >> "\[\r\n\]+Num +Type +Disp +Enb +Address +What" \ >> "\[\r\n\]+$bp_row_start break_me at \[^\r\n\]*$srcfile:\[0-9\]+" \ >> "\[\r\n\]+$bp_row_start main at \[^\r\n\]*$srcfile:$loc_bp2" \ >> - "\[\r\n\]+$bp_row_start main at \[^\r\n\]*$srcfile:$loc_bp3 +thread 1" \ >> + "\[\r\n\]+$bp_row_start main at \[^\r\n\]*$srcfile:$loc_bp3" \ >> "\[\r\n\]+\[ \t]+stop only in thread 1" \ >> "\[\r\n\]+$bp_row_start main at \[^\r\n\]*$srcfile:$loc_bp4" \ >> "\[\r\n\]+\[ \t\]+stop only if i == 1( \\((host|target) evals\\))?" \ >> diff --git a/gdb/testsuite/gdb.base/thread-bp-multi-loc.c b/gdb/testsuite/gdb.base/thread-bp-multi-loc.c >> new file mode 100644 >> index 00000000000..cab009c39ec >> --- /dev/null >> +++ b/gdb/testsuite/gdb.base/thread-bp-multi-loc.c >> @@ -0,0 +1,44 @@ >> +/* This testcase is part of GDB, the GNU debugger. >> + >> + Copyright 2022 Free Software Foundation, Inc. > > Needs to include 2023 in range now. Fixed. > >> + >> + This program is free software; you can redistribute it and/or modify >> + it under the terms of the GNU General Public License as published by >> + the Free Software Foundation; either version 3 of the License, or >> + (at your option) any later version. >> + >> + This program is distributed in the hope that it will be useful, >> + but WITHOUT ANY WARRANTY; without even the implied warranty of >> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> + GNU General Public License for more details. >> + >> + You should have received a copy of the GNU General Public License >> + along with this program. If not, see . */ >> + >> +volatile int global_var = 0; >> + >> +__attribute__((__always_inline__)) static inline void >> +foo (void) >> +{ >> + int i; >> + >> + for (i = 0; i < 10; ++i) >> + global_var = i; >> +} >> + >> +static void >> +bar (void) >> +{ >> + global_var = 0; >> + foo (); >> +} >> + >> +int >> +main (void) >> +{ >> + global_var = 0; >> + foo (); >> + bar (); >> + foo (); >> + return 0; >> +} >> diff --git a/gdb/testsuite/gdb.base/thread-bp-multi-loc.exp b/gdb/testsuite/gdb.base/thread-bp-multi-loc.exp >> new file mode 100644 >> index 00000000000..9665fe9e21f >> --- /dev/null >> +++ b/gdb/testsuite/gdb.base/thread-bp-multi-loc.exp >> @@ -0,0 +1,72 @@ >> +# Copyright 2022 Free Software Foundation, Inc. > > Ditto. > >> + >> +# This program is free software; you can redistribute it and/or modify >> +# it under the terms of the GNU General Public License as published by >> +# the Free Software Foundation; either version 3 of the License, or >> +# (at your option) any later version. >> +# >> +# This program is distributed in the hope that it will be useful, >> +# but WITHOUT ANY WARRANTY; without even the implied warranty of >> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> +# GNU General Public License for more details. >> +# >> +# You should have received a copy of the GNU General Public License >> +# along with this program. If not, see . >> + >> +# Create a multi-location breakpoint with a thread condition, then check the >> +# output of 'info breakpoints' to ensure that the thread condition is >> +# displayed correctly. >> + >> +standard_testfile >> + >> +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { >> + return -1 >> +} >> + >> +if {![runto_main]} { >> + return -1 >> +} >> + >> +delete_breakpoints >> + >> +gdb_breakpoint "foo thread 1" >> +set bp_number [get_integer_valueof "\$bpnum" 0] >> +if { $bp_number == 0 } { >> + unresolved "breakpoint not placed correctly" >> + return -1 >> +} >> + >> +set saw_header false >> +set saw_cond false >> +set loc_count 0 >> +gdb_test_multiple "info breakpoints" "" { >> + -re "\r\nNum\\s+\[^\r\n\]+\r\n" { >> + exp_continue >> + } >> + >> + -re "^$bp_number\\s+breakpoint\\s+keep\\s+y\\s+\\s*\r\n" { >> + set saw_header true >> + exp_continue >> + } >> + >> + -re "^\\s+stop only in thread 1\r\n" { >> + set saw_cond true >> + exp_continue >> + } >> + >> + -re "^$bp_number\\.\[123\]\\s+\[^\r\n\]+:${decimal}\r\n" { >> + incr loc_count >> + exp_continue >> + } >> + >> + -re "^$gdb_prompt $" { >> + with_test_prefix $gdb_test_name { >> + gdb_assert { $saw_header } \ >> + "saw header line" >> + gdb_assert { $saw_cond } \ >> + "saw b/p condition line" >> + gdb_assert { $loc_count == 3 } \ >> + "saw all three locations" > > It's better if the tests are written such that FAIL/PASSes match. In this case, > if gdb_test_multiple hits an internal pattern, then we'll have a single > > FAIL: info breakpoints > > To fix that, we should merge those three gdb_asserts into a single gdb_assert, > and we should $gdb_test_name for its test name, along with passing a meaningful > test name to gdb_test_multiple, so internal FAILs get that meaningful name > as well. If we want to show the individual conditions, that can > still be done by outputting them to the log. Done. I agree that, if/when your multi-location work is merged we might want to once again adjust how this information is displayed, inline with your suggestion above. However... how would you feel if this patch (as shown below) was merged now? I think this fixes the stray "thread 1" text immediately, and the multi-location display patch should be easily updated on top of this, if that was something that you plan to continue developing? Thanks, Andrew --- commit fb13c47255f0738644ac85f705f1dae4ec3890e7 Author: Andrew Burgess Date: Mon Nov 7 17:18:55 2022 +0000 gdb: fix display of thread condition for multi-location breakpoints If a breakpoint with multiple locations has a thread condition, then the 'info breakpoints' output is a little messed up, here's an example of the current output: (gdb) break foo thread 1 Breakpoint 2 at 0x401114: foo. (3 locations) (gdb) break bar thread 1 Breakpoint 3 at 0x40110a: file /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c, line 32. (gdb) info breakpoints Num Type Disp Enb Address What 2 breakpoint keep y thread 1 stop only in thread 1 2.1 y 0x0000000000401114 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 2.2 y 0x0000000000401146 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 2.3 y 0x0000000000401168 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 3 breakpoint keep y 0x000000000040110a in bar at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:32 thread 1 stop only in thread 1 Notice that, at the end of the location for breakpoint 3, the 'thread 1' condition is printed, but this is then repeated on the next line with 'stop only in thread 1'. In contrast, for breakpoint 2, the 'thread 1' appears randomly, in the "What" column, though slightly offset, non of the separate locations have the 'thread 1' information. Additionally for breakpoint 2 we also get a 'stop only in thread 1' line. There's two things going on here. First the randomly placed 'thread 1' for breakpoint 2 is due to a bug in print_one_breakpoint_location, where we check the variable part_of_multiple instead of header_of_multiple. If I fix this oversight, then the output is now: (gdb) break foo thread 1 Breakpoint 2 at 0x401114: foo. (3 locations) (gdb) break bar thread 1 Breakpoint 3 at 0x40110a: file /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c, line 32. (gdb) info breakpoints Num Type Disp Enb Address What 2 breakpoint keep y stop only in thread 1 2.1 y 0x0000000000401114 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 thread 1 2.2 y 0x0000000000401146 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 thread 1 2.3 y 0x0000000000401168 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 thread 1 3 breakpoint keep y 0x000000000040110a in bar at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:32 thread 1 stop only in thread 1 The 'thread 1' condition is now displayed at the end of each location, which makes the output the same for single location breakpoints and multi-location breakpoints. However, there's still some duplication here. Both breakpoints 2 and 3 include a 'stop only in thread 1' line, and it feels like the additional 'thread 1' is redundant. In fact, there's a comment to this very effect in the code: /* FIXME: This seems to be redundant and lost here; see the "stop only in" line a little further down. */ So, lets fix this FIXME. The new plan is to remove all the trailing 'thread 1' markers from the CLI output, we now get this: (gdb) break foo thread 1 Breakpoint 2 at 0x401114: foo. (3 locations) (gdb) break bar thread 1 Breakpoint 3 at 0x40110a: file /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c, line 32. (gdb) info breakpoints Num Type Disp Enb Address What 2 breakpoint keep y stop only in thread 1 2.1 y 0x0000000000401114 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 2.2 y 0x0000000000401146 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 2.3 y 0x0000000000401168 in foo at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:25 3 breakpoint keep y 0x000000000040110a in bar at /tmp/src/gdb/testsuite/gdb.base/thread-bp-multi-loc.c:32 stop only in thread 1 All of the above points are also true for the Ada 'task' breakpoint condition, and the changes I've made also update how the task information is printed, though in the case of the Ada task there was no 'stop only in task XXX' line printed, so I've added one of those. Obviously it can't be quite that easy. For MI backwards compatibility I've retained the existing code (but now only for MI like outputs), which ensures we should generate backwards compatible output. I've extended an Ada test to cover the new task related output, and updated all the tests I could find that checked for the old output. diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 8bc62743bb5..adf38e7d722 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -6468,20 +6468,19 @@ print_one_breakpoint_location (struct breakpoint *b, output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); } - if (!part_of_multiple) + /* In the MI output, each location of a thread or task specific + breakpoint includes the relevant thread or task ID. This is done for + backwards compatibility reasons. + + For the CLI output, the thread/task information is printed on a + separate line, see the 'stop only in thread' and 'stop only in task' + output below. */ + if (!header_of_multiple && uiout->is_mi_like_p ()) { if (b->thread != -1) - { - /* FIXME: This seems to be redundant and lost here; see the - "stop only in" line a little further down. */ - uiout->text (" thread "); - uiout->field_signed ("thread", b->thread); - } + uiout->field_signed ("thread", b->thread); else if (b->task != 0) - { - uiout->text (" task "); - uiout->field_signed ("task", b->task); - } + uiout->field_signed ("task", b->task); } uiout->text ("\n"); @@ -6536,7 +6535,14 @@ print_one_breakpoint_location (struct breakpoint *b, } uiout->text ("\n"); } - + + if (!part_of_multiple && b->task != 0) + { + uiout->text ("\tstop only in task "); + uiout->field_signed ("task", b->task); + uiout->text ("\n"); + } + if (!part_of_multiple) { if (b->hit_count) diff --git a/gdb/testsuite/gdb.ada/tasks.exp b/gdb/testsuite/gdb.ada/tasks.exp index 3eea04b3911..4441d92719c 100644 --- a/gdb/testsuite/gdb.ada/tasks.exp +++ b/gdb/testsuite/gdb.ada/tasks.exp @@ -50,21 +50,18 @@ gdb_test "watch j task 1 task 3" "You can specify only one task\\." # breakpoint in the list that matched the triggered-breakpoint's # address, no matter which task it was specific to. gdb_test "break break_me task 1" "Breakpoint .* at .*" +gdb_test "info breakpoints" "foo.adb:${decimal}\r\n\\s+stop only in task 1" \ + "check info breakpoints for task 1 breakpoint" # Now, insert a breakpoint that should stop only if task 3 stops, and # extract its number. -set bp_number -1 -set test "break break_me task 3" -gdb_test_multiple $test $test { - -re "Breakpoint (.*) at .*$gdb_prompt $" { - set bp_number $expect_out(1,string) - pass $test - } -} - +gdb_breakpoint "break_me task 3" +set bp_number [get_integer_valueof "\$bpnum" -1] if {$bp_number < 0} { return } +gdb_test "info breakpoints" "foo.adb:${decimal}\r\n\\s+stop only in task 3" \ + "check info breakpoints for task 3 breakpoint" # Continue to that breakpoint. Task 2 should hit it first, and GDB # is expected to ignore that hit and resume the execution. Only then diff --git a/gdb/testsuite/gdb.base/save-bp.exp b/gdb/testsuite/gdb.base/save-bp.exp index a39712c7f5c..41d71837fb6 100644 --- a/gdb/testsuite/gdb.base/save-bp.exp +++ b/gdb/testsuite/gdb.base/save-bp.exp @@ -79,7 +79,7 @@ gdb_test_sequence "info break" "info break" [list \ "\[\r\n\]+Num +Type +Disp +Enb +Address +What" \ "\[\r\n\]+$bp_row_start break_me at \[^\r\n\]*$srcfile:\[0-9\]+" \ "\[\r\n\]+$bp_row_start main at \[^\r\n\]*$srcfile:$loc_bp2" \ - "\[\r\n\]+$bp_row_start main at \[^\r\n\]*$srcfile:$loc_bp3 +thread 1" \ + "\[\r\n\]+$bp_row_start main at \[^\r\n\]*$srcfile:$loc_bp3" \ "\[\r\n\]+\[ \t]+stop only in thread 1" \ "\[\r\n\]+$bp_row_start main at \[^\r\n\]*$srcfile:$loc_bp4" \ "\[\r\n\]+\[ \t\]+stop only if i == 1( \\((host|target) evals\\))?" \ diff --git a/gdb/testsuite/gdb.base/thread-bp-multi-loc.c b/gdb/testsuite/gdb.base/thread-bp-multi-loc.c new file mode 100644 index 00000000000..2adb179d93c --- /dev/null +++ b/gdb/testsuite/gdb.base/thread-bp-multi-loc.c @@ -0,0 +1,44 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022-2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +volatile int global_var = 0; + +__attribute__((__always_inline__)) static inline void +foo (void) +{ + int i; + + for (i = 0; i < 10; ++i) + global_var = i; +} + +static void +bar (void) +{ + global_var = 0; + foo (); +} + +int +main (void) +{ + global_var = 0; + foo (); + bar (); + foo (); + return 0; +} diff --git a/gdb/testsuite/gdb.base/thread-bp-multi-loc.exp b/gdb/testsuite/gdb.base/thread-bp-multi-loc.exp new file mode 100644 index 00000000000..6e1121e867a --- /dev/null +++ b/gdb/testsuite/gdb.base/thread-bp-multi-loc.exp @@ -0,0 +1,67 @@ +# Copyright 2022-2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Create a multi-location breakpoint with a thread condition, then check the +# output of 'info breakpoints' to ensure that the thread condition is +# displayed correctly. + +standard_testfile + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { + return -1 +} + +if {![runto_main]} { + return -1 +} + +delete_breakpoints + +gdb_breakpoint "foo thread 1" +set bp_number [get_integer_valueof "\$bpnum" 0] +if { $bp_number == 0 } { + unresolved "breakpoint not placed correctly" + return -1 +} + +set saw_header false +set saw_cond false +set loc_count 0 +gdb_test_multiple "info breakpoints" \ + "check thread condition is displayed correctly" { + -re "\r\nNum\\s+\[^\r\n\]+\r\n" { + exp_continue + } + + -re "^$bp_number\\s+breakpoint\\s+keep\\s+y\\s+\\s*\r\n" { + set saw_header true + exp_continue + } + + -re "^\\s+stop only in thread 1\r\n" { + set saw_cond true + exp_continue + } + + -re "^$bp_number\\.\[123\]\\s+\[^\r\n\]+:${decimal}\r\n" { + incr loc_count + exp_continue + } + + -re "^$gdb_prompt $" { + gdb_assert { $saw_header && $saw_cond && $loc_count == 3} \ + $gdb_test_name + } +}