From patchwork Fri Dec 8 17:41:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Domani X-Patchwork-Id: 81759 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 C82F73858422 for ; Fri, 8 Dec 2023 17:42:16 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from sonic301-22.consmr.mail.ir2.yahoo.com (sonic301-22.consmr.mail.ir2.yahoo.com [77.238.176.99]) by sourceware.org (Postfix) with ESMTPS id 474393858CD1 for ; Fri, 8 Dec 2023 17:42:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 474393858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=yahoo.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=yahoo.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 474393858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=77.238.176.99 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702057324; cv=none; b=Fto5ny6Lv5/di6dDKDhEyJgaa1QJnDmwhCsUkavGyAT+81wTepCMlFGI99TvVrYdZIPniooOlJi7vvOIQjwHhPn3Qpw5JGAv+BmHblaBmNTz0hWnrlNV6vVytC7cFQM3btV5X1q2kOyXvxJXi7CqNhMHX6eYiFXgBfhng/oyA2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702057324; c=relaxed/simple; bh=V1yS3QgTFlhyAZ6BINfRgx9G0zifQ+I1ykksqa6H5eE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=KtRw5bV2mu/foVeV4ry9nXMAy+CkxKjedc+Fhidvlb7ap2DlVV/KMxmHyb40pNy0NpA/PMxHYOGGPiDCjg/E2iDrGcTgNWFMNqfQPnnKWydeqSZ1CYfr9tdAtDLHIcjpKWlhfdJiftOkfJNZMvN/9vTgEnxeaaUeJuQUiE59x8g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s2048; t=1702057321; bh=9kpFt2/HP+VddT2RUFhP8OH1F/hmupe/RnkiFaWMYnM=; h=From:To:Subject:Date:References:From:Subject:Reply-To; b=P0ok2wf/VPkXNh4q5f1TVraXiN88FlD5k5fALexC4yDI9St21snEovrCkeg3Fu6Rdc/TeOjT7MKY94evnYcBcUe3jWnpsqe45qUAPct7XutU33n4WAU0a2t91JmLV9X+W/nQ0u/B4niqqko6dKUIFHHis6jzFFZidU75KTQLO9VPDlpfFaIc12+jKvOdN4iBzvWswJ0N/fXS53yBRAGdIgIjj1KwykD0PxOhvsN3WGCT1WBGskmVIwkFna7fZ9PWDUAyT1dKJez4j+DOlsij4o9CAfw4rw2ORWGZnN8VpYASsv1VThlutdd2NqSCciqnnDDskouw+Gd/mOSlAkg7ig== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1702057321; bh=GV/2LcdkcogzT52G7uQ0V8FspMGQtNgIxtn2BeNGU+a=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=R130nb/S/41L/AF84/1Re16nvcir0DpS7S6tYGyAgmsXKj+bW8ZweJ4V4SxIGYJaslp1NCLxEhI992zMSqPLxMVerDU3bYW/uVMT5utOuk3qztFfST8HuvQsLZeX5qks6gD9CI/vHRM1CTleRezlsmyC4v47zg6stoC/iefw80MwJqEEElEkqElKUt4uEYOyJMq+7XCvkHhHIZI4Ac36ENjv5IxhlxursOfZk+HCIvW3wB0/52PKx9ErAkfQGwFESOYrxsjP0eT1s5XPjo058OUqRwUYs52o5DRRgY0rA61CYip43PsOjkbe4SSjNm/GtebJGVJ+1LzBBJ5SGkSVWw== X-YMail-OSG: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.BAE_EzJcxAhGwJzTGtyG5bcZh5_ensHcEbYlN7 zM3HUQ9LVBUvrhNZ0DBmqmzwzBJGkDSoKdpQ8r_gkP.7xAVpW9oLHFT6Wf.R9zolC1n4vHL04d8a E5._JQhOT3_10YxSz2f9L6EZAzpJf6DE3wtI- X-Sonic-MF: X-Sonic-ID: d9db718b-8a5a-4eda-ba9f-2f40e93443d9 Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ir2.yahoo.com with HTTP; Fri, 8 Dec 2023 17:42:01 +0000 Received: by hermes--production-ir2-95776f84c-rphpl (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 9c1c0afd39c08ca263dc88e7f542d024; Fri, 08 Dec 2023 17:41:56 +0000 (UTC) From: Hannes Domani To: gdb-patches@sourceware.org Subject: [PATCH] Fix printing of global variable stubs if no inferior is running Date: Fri, 8 Dec 2023 18:41:28 +0100 Message-Id: <20231208174128.2632-1-ssbssa@yahoo.de> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Antivirus: Avast (VPS 231208-2, 12/08/2023), Outbound message X-Antivirus-Status: Clean References: <20231208174128.2632-1-ssbssa.ref@yahoo.de> X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, 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 Since 3c45e9f915ae4aeab7312d6fc55a947859057572 gdb crashes when trying to print a global variable stub without a running inferior, because of a missing nullptr-check (the block_scope function took care of that check before it was converted to a method). With this check it works again: ``` (gdb) print s $1 = ``` --- gdb/cp-namespace.c | 6 +++- gdb/testsuite/gdb.cp/print-global-stub.cc | 31 +++++++++++++++++++++ gdb/testsuite/gdb.cp/print-global-stub.exp | 32 ++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.cp/print-global-stub.cc create mode 100644 gdb/testsuite/gdb.cp/print-global-stub.exp diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 975e789f18a..1ec00dc7fde 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -1027,7 +1027,11 @@ cp_lookup_transparent_type (const char *name) /* If that doesn't work and we're within a namespace, look there instead. */ - scope = get_selected_block (0)->scope (); + const block *block = get_selected_block (0); + if (block == nullptr) + return nullptr; + + scope = block->scope (); if (scope[0] == '\0') return NULL; diff --git a/gdb/testsuite/gdb.cp/print-global-stub.cc b/gdb/testsuite/gdb.cp/print-global-stub.cc new file mode 100644 index 00000000000..bc12707e87e --- /dev/null +++ b/gdb/testsuite/gdb.cp/print-global-stub.cc @@ -0,0 +1,31 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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 . */ + +struct S +{ + S (int); + virtual ~S (); + + int m_i; +}; + +S s (5); + +int main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.cp/print-global-stub.exp b/gdb/testsuite/gdb.cp/print-global-stub.exp new file mode 100644 index 00000000000..039e8251afe --- /dev/null +++ b/gdb/testsuite/gdb.cp/print-global-stub.exp @@ -0,0 +1,32 @@ +# Copyright (C) 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 . + +# This file is part of the GDB testsuite. +# It tests printing of a global stub without inferior. + +require allow_cplus_tests + +standard_testfile .cc +set objfile [standard_output_file ${testfile}.o] + +if { [gdb_compile $srcdir/$subdir/$srcfile $objfile object \ + {c++ debug}] != "" } { + untested "failed to compile" + return -1 +} + +clean_restart $objfile + +gdb_test "print s" " = "