aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorHannes Domani <ssbssa@yahoo.de>2023-12-08 19:06:14 +0100
committerHannes Domani <ssbssa@yahoo.de>2023-12-08 19:07:50 +0100
commit576745e26c0ec76a53ba45b20af464628a50b3e4 (patch)
tree61ba84e9c70d2eb29d59bf23555fbd4d54d71a9a /gdb/testsuite
parentcff71358132db440b82747707b3c7c99efca6670 (diff)
downloadgdb-576745e26c0ec76a53ba45b20af464628a50b3e4.zip
gdb-576745e26c0ec76a53ba45b20af464628a50b3e4.tar.gz
gdb-576745e26c0ec76a53ba45b20af464628a50b3e4.tar.bz2
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>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.cp/print-global-stub.cc31
-rw-r--r--gdb/testsuite/gdb.cp/print-global-stub.exp32
2 files changed, 63 insertions, 0 deletions
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 0000000..bc12707
--- /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 0000000..039e825
--- /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>"