public inbox for gdb-cvs@sourceware.org help / color / mirror / Atom feed
From: Hannes Domani <ssbssa@sourceware.org> To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Fix printing of global variable stubs if no inferior is running Date: Fri, 8 Dec 2023 18:08:17 +0000 (GMT) [thread overview] Message-ID: <20231208180817.297B83858CD1@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=576745e26c0ec76a53ba45b20af464628a50b3e4 commit 576745e26c0ec76a53ba45b20af464628a50b3e4 Author: Hannes Domani <ssbssa@yahoo.de> Date: Fri Dec 8 19:06:14 2023 +0100 Fix printing of global variable stubs if no inferior is running 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 = <incomplete type> ``` Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31128 Approved-By: Tom Tromey <tom@tromey.com> Diff: --- 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(-) 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 <http://www.gnu.org/licenses/>. */ + +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 <http://www.gnu.org/licenses/>. + +# 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" " = <incomplete type>"
reply other threads:[~2023-12-08 18:08 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20231208180817.297B83858CD1@sourceware.org \ --to=ssbssa@sourceware.org \ --cc=gdb-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).