This is the mail archive of the gdb-testers@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Handle "p S::method()::static_var" in the C++ parser


*** TEST RESULTS FOR COMMIT 858be34c5a03bb8973679ebf00d360182434dc00 ***

Author: Pedro Alves <palves@redhat.com>
Branch: master
Commit: 858be34c5a03bb8973679ebf00d360182434dc00

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]