From patchwork Fri Dec 29 09:27:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 82987 Return-Path: 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 5B1B0385842C for ; Fri, 29 Dec 2023 09:35:06 +0000 (GMT) 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 DF0013858412 for ; Fri, 29 Dec 2023 09:27:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DF0013858412 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DF0013858412 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703842071; cv=none; b=F9B6Kl8MYuGRt7M9zjNdEY/e0iEMKg9v5ydmbPRQ9UiTgassgSEHbZ88iP+vVE7yk/G6G0NAyYaDKbLj0GYiVRCh4bIe1lDjO+kqaH0xkLNxsXjbKExoHky3msc9e1AXdDoi/C6uH+K4UpWaG+THpoX/nkehbJKWllgWfWMbKH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703842071; c=relaxed/simple; bh=kzrKDBOeush5MqL7+h2TkuqcLVyyOAqjdsM1MN2xHOY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=wJul9Wp+x2RY1YA9IwhpBSm4qJmp4b3GZScg+AZUxUQz0glMELX47mkyMvF+I/Wiff6HVdPVA+iO5GU/qQ6EFuq1UcuARruJjdoVTMQmP+paPUBM2pQMC8ZwT0rR14cSW41ioW99s2imBq7Eony79qeFr7/53lyzhenqmUH6UgI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703842051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2lP+OfCNnwSFY4SdWiGbxjgBZjBPg2lza3dzTYmfltQ=; b=BmDkGavWfDv6ER8e7Co72/Nz8lQaAr2euzjzmvpPReACt3+5YpsFR9vyiq1u0sBpf7WxaG GI/84l7xyFzOiTp02HZ0IJ5f4ofPpAlm1uezh4p5RU+Hkl9ft2kFZxK28fEQCaZXjMSq9E 4i8Lyu19wjWYuCncHPqjfdCke9bEi3o= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-310-zdLHG3k5OCqs27lS6uJnWA-1; Fri, 29 Dec 2023 04:27:25 -0500 X-MC-Unique: zdLHG3k5OCqs27lS6uJnWA-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-40d27ea0165so63412285e9.1 for ; Fri, 29 Dec 2023 01:27:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703842043; x=1704446843; 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=2lP+OfCNnwSFY4SdWiGbxjgBZjBPg2lza3dzTYmfltQ=; b=OqRpNqkU1snt4CiCLEEw3XpgbNBem5BG0GHD63EfVOQQmwjocHXaE5plrpeCwOavk9 13ZJ4p71AlDyfdgT95y924Ybvg1icPkohlVbi77fT9ktiwpDl74AJjoiGUl5thLXgjZn A7sR5QBm4yTMO6K0LPVg08c0gz9NGw6ZB6JdgwgQWSSkYOKnwQrzH5JAlHH/bnimTMXF f1/byy9W6q7ZwoTZMk6IfLDJd0Ielgm6NHgX8/KIT5wOr3cBzjqBiuwW0ZOMKd5VhZQS HXQ8iBTLeL/HnQ0X06y1GLXS1aHsjs6KatLBxfAC3SBJy1JtY4crx8+w9PFEjMJq8qkc qBqw== X-Gm-Message-State: AOJu0YxEZroesojLYRSiMFGor/RnfS0GD4UgpEY8hRZLZP75HTmQ4tfk jRlmkRehA/8sOAPIXiDkPOp/bgNuLN3NJbaFosmg9G9o6GDHlQOrxSpLqlkp6mqvBQ/Ngx6ean/ g2R7vRvA8zYj7V2+R03aqoXb0AV3J+No26Az34Guex3eMLHK7/w1rdJa79QV7QqJggM1vN8qtNC g144I5ZAArn/9UyA== X-Received: by 2002:a7b:ca4a:0:b0:40c:2b13:95f8 with SMTP id m10-20020a7bca4a000000b0040c2b1395f8mr6223363wml.141.1703842043339; Fri, 29 Dec 2023 01:27:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGHdrKceYwKOhTgCfxplMfoZR7hXwJHMQDRe6RQPYfutTjOb9doaWr3Dd6UJVWyplp7hTiBpA== X-Received: by 2002:a7b:ca4a:0:b0:40c:2b13:95f8 with SMTP id m10-20020a7bca4a000000b0040c2b1395f8mr6223354wml.141.1703842042961; Fri, 29 Dec 2023 01:27:22 -0800 (PST) Received: from localhost ([2a00:23c7:c696:e701:85a5:8a0c:1403:2dc]) by smtp.gmail.com with ESMTPSA id o20-20020a05600c4fd400b004094d4292aesm30188095wmq.18.2023.12.29.01.27.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Dec 2023 01:27:22 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv8 06/14] gdb: don't display inferior list for pending breakpoints Date: Fri, 29 Dec 2023 09:27:01 +0000 Message-Id: <6efcaaf2ba80c1eec8f895e8291836bfa70778f5.1703841366.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org I noticed that in the 'info breakpoints' output, GDB sometimes prints the inferior list for pending breakpoints, this doesn't seem right to me. A pending breakpoint has no locations (at least, as far as we display things in the 'info breakpoints' output), so including an inferior list seems odd. Here's what I see right now: (gdb) info breakpoint 5 Num Type Disp Enb Address What 5 breakpoint keep y foo inf 1 (gdb) It's the 'inf 1' at the end of the line that I'm objecting too. To trigger this behaviour we need to be in a multi-inferior debug session. The breakpoint must have been non-pending at some point in the past, and so have a location assigned to it. The breakpoint becomes pending again as a result of a shared library being unloaded. When this happens the location itself is marked pending (via bp_location::shlib_disabled). In print_one_breakpoint_location, in order to print the inferior list we check that the breakpoint has a location, and that we have multiple inferiors, but we don't check if the location itself is pending. This commit adds that check, which means the output is now: (gdb) info breakpoint 5 Num Type Disp Enb Address What 5 breakpoint keep y foo (gdb) Which I think makes more sense -- indeed, the format without the inferior list is what we display for a pending breakpoint that has never had any locations assigned, so I think this change in behaviour makes GDB more consistent. --- gdb/breakpoint.c | 2 +- gdb/testsuite/gdb.multi/pending-bp-lib.c | 22 ++++ gdb/testsuite/gdb.multi/pending-bp.c | 66 ++++++++++++ gdb/testsuite/gdb.multi/pending-bp.exp | 126 +++++++++++++++++++++++ 4 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.multi/pending-bp-lib.c create mode 100644 gdb/testsuite/gdb.multi/pending-bp.c create mode 100644 gdb/testsuite/gdb.multi/pending-bp.exp diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 7951b7c5801..f0724b416d3 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -6597,7 +6597,7 @@ print_one_breakpoint_location (struct breakpoint *b, } } - if (loc != NULL && !header_of_multiple) + if (loc != nullptr && !header_of_multiple && !loc->shlib_disabled) { std::vector inf_nums; int mi_only = 1; diff --git a/gdb/testsuite/gdb.multi/pending-bp-lib.c b/gdb/testsuite/gdb.multi/pending-bp-lib.c new file mode 100644 index 00000000000..15d1b9833dd --- /dev/null +++ b/gdb/testsuite/gdb.multi/pending-bp-lib.c @@ -0,0 +1,22 @@ +/* Copyright 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 . */ + +int global_var = 0; + +void +foo (int arg) +{ + global_var = arg; +} diff --git a/gdb/testsuite/gdb.multi/pending-bp.c b/gdb/testsuite/gdb.multi/pending-bp.c new file mode 100644 index 00000000000..879e0b11ac7 --- /dev/null +++ b/gdb/testsuite/gdb.multi/pending-bp.c @@ -0,0 +1,66 @@ +/* Copyright 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 . */ + +#include +#include + +void +breakpt (void) +{ + /* Nothing. */ +} + +volatile int global_counter = 0; + +volatile int call_count = 1; + +int +main (void) +{ + void *handle; + void (*func)(int); + + /* Some filler work so that we don't initially stop on the breakpt call + below. */ + ++global_counter; + + breakpt (); /* Break before open. */ + + /* Now load the shared library. */ + handle = dlopen (SHLIB_NAME, RTLD_LAZY); + if (handle == NULL) + abort (); + + breakpt (); /* Break after open. */ + + /* Find the function symbol. */ + func = (void (*)(int)) dlsym (handle, "foo"); + + for (; call_count > 0; --call_count) + { + /* Call the library function. */ + func (1); + } + + breakpt (); /* Break before close. */ + + /* Unload the shared library. */ + if (dlclose (handle) != 0) + abort (); + + breakpt (); /* Break after close. */ + + return 0; +} diff --git a/gdb/testsuite/gdb.multi/pending-bp.exp b/gdb/testsuite/gdb.multi/pending-bp.exp new file mode 100644 index 00000000000..478d8d7c037 --- /dev/null +++ b/gdb/testsuite/gdb.multi/pending-bp.exp @@ -0,0 +1,126 @@ +# Copyright 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 . + +# Tests related to pending breakpoints in a multi-inferior environment. + +require allow_shlib_tests !use_gdb_stub + +standard_testfile + +set libname $testfile-lib +set srcfile_lib $srcdir/$subdir/$libname.c +set binfile_lib [standard_output_file $libname.so] + +if { [gdb_compile_shlib $srcfile_lib $binfile_lib {}] != "" } { + untested "failed to compile shared library 1" + return -1 +} + +set binfile_lib_target [gdb_download_shlib $binfile_lib] + +if { [build_executable "failed to prepare" $testfile $srcfile \ + [list debug \ + additional_flags=-DSHLIB_NAME=\"$binfile_lib_target\" \ + shlib_load]] } { + return -1 +} + +# Start two inferiors, both running the same test binary. The arguments +# INF_1_STOP and INF_2_STOP are source code patterns that are passed to +# gdb_get_line_number to figure out where each inferior should be stopped. +# +# This proc does a clean_restart and leaves inferior 2 selected. Also the +# 'breakpoint pending' flag is enabled, so pending breakpoints can be created +# without GDB prompting the user. +proc do_test_setup { inf_1_stop inf_2_stop } { + clean_restart ${::binfile} + + gdb_locate_shlib $::binfile_lib + + if {![runto_main]} { + return false + } + + gdb_breakpoint [gdb_get_line_number ${inf_1_stop}] temporary + gdb_continue_to_breakpoint "move inferior 1 into position" + + gdb_test "add-inferior -exec ${::binfile}" \ + "Added inferior 2.*" "add inferior 2" + gdb_test "inferior 2" "Switching to inferior 2 .*" "switch to inferior 2" + + if {![runto_main]} { + return false + } + + gdb_breakpoint [gdb_get_line_number ${inf_2_stop}] temporary + gdb_continue_to_breakpoint "move inferior 2 into position" + + gdb_test_no_output "set breakpoint pending on" + + return true +} + +# Check that when a breakpoint is in the pending state, but that breakpoint +# does have some locations (those locations themselves are pending), GDB +# doesn't display the inferior list in the 'info breakpoints' output. +proc_with_prefix test_no_inf_display {} { + do_test_setup "Break before open" "Break before open" + + # Create a breakpoint on 'foo'. As the shared library (that + # contains foo) has not been loaded into any inferior yet, then + # there will be no locations and the breakpoint will be created + # pending. Pass the 'allow-pending' flag so the gdb_breakpoint + # correctly expects the new breakpoint to be pending. + gdb_breakpoint "foo" allow-pending + set bpnum [get_integer_valueof "\$bpnum" "*INVALID*" \ + "get foo breakpoint number"] + + # Check the 'info breakpoints' output; the breakpoint is pending with + # no 'inf X' appearing at the end of the line. + gdb_test "info breakpoint $bpnum" \ + "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+\\s+foo" \ + "check info bp before locations have been created" + + # Now select inferior 1 and allow the inferior to run forward to the + # point where a breakpoint location for foo will have been created. + gdb_test "inferior 1" "Switching to inferior 1 .*" + gdb_breakpoint [gdb_get_line_number "Break after open"] temporary + gdb_continue_to_breakpoint \ + "move inferior 1 until a location has been added" + + # Check the 'info breakpoints' output. Notice we display the inferior + # list at the end of the breakpoint line. + gdb_test "info breakpoint $bpnum" \ + "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+$::hex\\s+\]*>\\s+inf 1" \ + "check info breakpoints while breakpoint is inserted" + + # Continue inferior 1 until the shared library has been unloaded. The + # breakpoint on 'foo' will return to the pending state. We will need to + # 'continue' twice as the first time will hit the 'foo' breakpoint. + gdb_breakpoint [gdb_get_line_number "Break after close"] temporary + gdb_continue_to_breakpoint "hit the breakpoint in foo" + gdb_continue_to_breakpoint "after close library" + + # Check the 'info breakpoints' output, check there is no 'inf 1' at the + # end of the breakpoint line. + gdb_test "info breakpoint $bpnum" \ + [multi_line \ + "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+\\s+foo" \ + "\\s+breakpoint already hit 1 time"] \ + "check info breakpoints while breakpoint is pending" +} + +# Run all the tests. +test_no_inf_display