aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.cp/local-static.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2017-09-04 20:21:15 +0100
committerPedro Alves <palves@redhat.com>2017-09-04 20:21:15 +0100
commit858be34c5a03bb8973679ebf00d360182434dc00 (patch)
treef8f2ee3b71ccc4b20b8501a00b113975b4c48013 /gdb/testsuite/gdb.cp/local-static.c
parentdd5901a6a5bba75f3dee49f9a27640eedad90afe (diff)
downloadgdb-858be34c5a03bb8973679ebf00d360182434dc00.zip
gdb-858be34c5a03bb8973679ebf00d360182434dc00.tar.gz
gdb-858be34c5a03bb8973679ebf00d360182434dc00.tar.bz2
Handle "p S::method()::static_var" in the C++ parser
This commit makes "print S::method()::static_var" actually find the debug symbol for static_var. Currently, you get: (gdb) print S::method()::static_var A syntax error in expression, near `'. Quoting the whole string would seemingly work before the previous patch that made GDB stop assuming int for no-debug-info variables: (gdb) p 'S::method()::static_var' $1 = 1 ... except that's incorrect output, because: (gdb) ptype 'S::method()::static_var' type = <data variable, no debug info> The way to make it work correctly currently is by quoting the function/method part, like this: (gdb) print 'S::method()'::static_var $1 = {i1 = 1, i2 = 2, i3 = 3} (gdb) ptype 'S::method()'::static_var type = struct aggregate { int i1; int i2; int i3; } At least after the "stop assuming int" patch, this is what we now get: (gdb) p 'S::method()::static_var' 'S::method()::static_var' has unknown type; cast it to its declared type (gdb) p (struct aggregate) 'S::method()::static_var' $1 = {i1 = 1, i2 = 2, i3 = 3} However, IMO, users shouldn't really have to care about any of this. GDB should Just Work, without quoting, IMO. So here's a patch that implements support for that in the C++ parser. With this patch, you now get: (gdb) p S::method()::S_M_s_var_aggregate $1 = {i1 = 1, i2 = 2, i3 = 3} (gdb) ptype S::method()::S_M_s_var_aggregate type = struct aggregate { int i1; int i2; int i3; } gdb/ChangeLog: 2017-09-04 Pedro Alves <palves@redhat.com> (%type <voidval>): Add function_method. * c-exp.y (exp): New production for calls with no arguments. (function_method, function_method_void_or_typelist): New productions. (exp): New production for "method()::static_var". * eval.c (evaluate_subexp_standard): Handle OP_FUNC_STATIC_VAR. * expprint.c (print_subexp_standard, dump_subexp_body_standard): Handle OP_FUNC_STATIC_VAR. * parse.c (operator_length_standard): Handle OP_FUNC_STATIC_VAR. * std-operator.def (OP_FUNC_STATIC_VAR): New. gdb/testsuite/ChangeLog: 2017-09-04 Pedro Alves <palves@redhat.com> * gdb.base/local-static.c: New. * gdb.base/local-static.cc: New. * gdb.base/local-static.exp: New.
Diffstat (limited to 'gdb/testsuite/gdb.cp/local-static.c')
-rw-r--r--gdb/testsuite/gdb.cp/local-static.c142
1 files changed, 142 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.cp/local-static.c b/gdb/testsuite/gdb.cp/local-static.c
new file mode 100644
index 0000000..5bfff8d
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/local-static.c
@@ -0,0 +1,142 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2002-2017 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 aggregate
+{
+ int i1;
+ int i2;
+ int i3;
+};
+
+void keepalive_float (double *var) { }
+void keepalive_int (int *var) { }
+void keepalive_aggregate (struct aggregate *var) { }
+
+#define PREFIXIFY(PREFIX, VAR) \
+ PREFIX ## _ ## VAR
+
+#define DEF_STATICS(PREFIX) \
+ static int PREFIXIFY(PREFIX, s_var_int) = 4; \
+ static double PREFIXIFY(PREFIX, s_var_float) = 3.14f; \
+ static struct aggregate PREFIXIFY(PREFIX, s_var_aggregate) \
+ = { 1, 2, 3 }; \
+ \
+ keepalive_int (&PREFIXIFY(PREFIX, s_var_int)); \
+ keepalive_float (&PREFIXIFY(PREFIX, s_var_float)); \
+ keepalive_aggregate (&PREFIXIFY(PREFIX, s_var_aggregate));
+
+#ifdef __cplusplus
+
+struct S
+{
+ void inline_method ()
+ {
+ DEF_STATICS (S_IM);
+ }
+ static void static_inline_method ()
+ {
+ DEF_STATICS (S_SIM);
+ }
+
+ void method ();
+ static void static_method ();
+};
+
+S s;
+
+void
+S::method ()
+{
+ DEF_STATICS (S_M);
+}
+
+void
+S::static_method ()
+{
+ DEF_STATICS (S_SM);
+}
+
+template <typename T>
+struct S2
+{
+ void method ();
+ static void static_method ();
+
+ void inline_method ()
+ {
+ DEF_STATICS (S2_IM);
+ }
+
+ static void static_inline_method ()
+ {
+ DEF_STATICS (S2_SIM);
+ }
+};
+
+template<typename T>
+void
+S2<T>::method ()
+{
+ DEF_STATICS (S2_M);
+}
+
+template<typename T>
+void
+S2<T>::static_method ()
+{
+ DEF_STATICS (S2_SM);
+}
+
+S2<int> s2;
+
+#endif
+
+void
+free_func (void)
+{
+ DEF_STATICS (FF);
+}
+
+static inline void
+free_inline_func (void)
+{
+ DEF_STATICS (FIF);
+}
+
+int
+main ()
+{
+ for (int i = 0; i < 1000; i++)
+ {
+ free_func ();
+ free_inline_func ();
+
+#ifdef __cplusplus
+ s.method ();
+ s.inline_method ();
+ S::static_method ();
+ S::static_inline_method ();
+
+ s2.method ();
+ s2.inline_method ();
+ S2<int>::static_method ();
+ S2<int>::static_inline_method ();
+#endif
+ }
+
+ return 0;
+}