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 7283D385772F for ; Mon, 15 May 2023 19:28:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7283D385772F 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=1684178882; 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=U5uwxB0PtTniEt8wXUeFtzeCiCa0Ohe2WV+Ily+kHGc=; b=e/Ui+C9T/tdAGYQmW1PEe/Wep6D9EClf1Q8TQSyvHmJtgVswCtjHNr1+ow6Ztko72rh2W6 yK0TGOGRDdWUiEsd/NKQnctembsgokcFJlzxJbgUUeHTtk8A3oaOnH8bqe24DStVSV8Rsj 2ZmOpTekUFTIGgJCWFyTvjOiAaC45G0= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-38-qHF4xwrmOvCjvoUoo8f1IA-1; Mon, 15 May 2023 15:28:01 -0400 X-MC-Unique: qHF4xwrmOvCjvoUoo8f1IA-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-3f4245ffbb4so51376915e9.3 for ; Mon, 15 May 2023 12:28:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684178880; x=1686770880; 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=U5uwxB0PtTniEt8wXUeFtzeCiCa0Ohe2WV+Ily+kHGc=; b=cmMJ4tMdGbqjQSeqKw7rINSRI/IbQyvPYqPOi0nQ96R098Abz2tjSuRcerjqOyEmT7 2YTPxNF0TPxFuzo/H2lC35Qc5w8JTdybNCEJ8eOtzWbh9IGGGzybuMZC16Zt4fOBRR7n O2Iw2kQlwxt4p77vKvtijqpbbaUtxrbhHbhxhrzSVxapxFHPCoJ4IIQB/OkN3rTtfLTc 5Xy/1wMez1cgMhl1CULAyNWwLJj7wwCJbhpOvPyOiKblRpN+gd/I7aO0JVTs8nWwGEzO cZx+lZjo3VpilpZWzViOETTKd9GteQKVer08F2A00JDNgsuht1iuMYWXbwdoFO16tMx4 u+ZA== X-Gm-Message-State: AC+VfDw5rzE8F+cFZVnRAzefG/NVikJizMZL+ELhZfsZtC1Jf6b6uw6y 8hVMu8STSm7NbOe3xGgMAr5iJRqGxMZxSpGVFo29Uot6fQxzTvbFNg4JjhFesHXTGGUMvx7p4aI uGdhGuz8t/Ex8vSjzHR+gGDYgNJX21/REq7Z3gAuoX87qmrVAS2RUyHpnR6NXzkuKGGg34A0rib Zho4l0xg== X-Received: by 2002:a05:600c:2191:b0:3f4:1a97:ab1d with SMTP id e17-20020a05600c219100b003f41a97ab1dmr25543065wme.1.1684178879663; Mon, 15 May 2023 12:27:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ku48GQd9t3z3TkYUpAWQdfwuXOnP0b0lM6TM0WzGoHtO+QxN7jVeH9LGakpyEgtlyrnd2Mg== X-Received: by 2002:a05:600c:2191:b0:3f4:1a97:ab1d with SMTP id e17-20020a05600c219100b003f41a97ab1dmr25543053wme.1.1684178879192; Mon, 15 May 2023 12:27:59 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id y13-20020a1c4b0d000000b003f19b3d89e9sm285723wma.33.2023.05.15.12.27.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 12:27:58 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 5/9] gdb: don't display inferior list for pending breakpoints Date: Mon, 15 May 2023 20:27:41 +0100 Message-Id: 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 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,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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 List-Id: 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. --- 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 | 115 +++++++++++++++++++++++ 4 files changed, 204 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 d03c55587be..f9020c49d90 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -6467,7 +6467,7 @@ print_one_breakpoint_location (struct breakpoint *b, } } - if (loc != NULL && !header_of_multiple) + if (loc != NULL && !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..ca8a3c20b72 --- /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 () +{ + /* 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..4a65f79cfc4 --- /dev/null +++ b/gdb/testsuite/gdb.multi/pending-bp.exp @@ -0,0 +1,115 @@ +# 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 pthreads]] } { + return -1 +} + +# Used to override delete_breakpoints when we don't want breakpoints +# deleted. +proc do_nothing {} {} + +# 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" + + with_override delete_breakpoints do_nothing { + 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 close" "Break before open" + + # Create a breakpoint on 'foo'. This will find a location in inferior 1, + # but will not find a location in inferior 2 -- the shared library is not + # yet loaded in that inferior. + gdb_breakpoint "foo" + set bpnum [get_integer_valueof "\$bpnum" "*INVALID*" \ + "get foo breakpoint number"] + + # 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" + + # Ensure we are in inferior 1, move the inferior forward until the shared + # library has been unloaded. The breakpoint on 'foo' will return to the + # pending state. + gdb_test "inferior 1" "Switching to inferior 1 .*" + gdb_breakpoint [gdb_get_line_number "Break after close"] temporary + 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" \ + "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+\\s+foo" \ + "check info breakpoints while breakpoint is pending" +} + +# Run all the tests. +test_no_inf_display -- 2.25.4