This is the mail archive of the gdb-patches@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]

RFC: fix PR symtab/11462


This patch fixes PR symtab/11462.

The bug is that expressions like 'obj.~Destructor' don't work.
c-exp.y was just missing some productions, so this adds them.

It would have been nice to add this directly to name lexing, but I
thought that seemed too tricky; and likewise adding it to the parser in
a more generic way seems like it would cause lookahead problems.

Built and regtested on x86-64 Fedora 16.
New test case included.

Tom

2013-01-11  Tom Tromey  <tromey@redhat.com>

	PR symtab/11462:
	* c-exp.y (exp): Add new productions for destructors after '.' and
	'->'.
	(write_destructor_name): New function.

2013-01-11  Tom Tromey  <tromey@redhat.com>

	* gdb.cp/m-static.exp: Add destructor-printing tests.

diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 9ef4b39..e4cfb64 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -170,6 +170,7 @@ void yyerror (char *);
 static int parse_number (char *, int, int, YYSTYPE *);
 static struct stoken operator_stoken (const char *);
 static void check_parameter_typelist (VEC (type_ptr) *);
+static void write_destructor_name (struct stoken);
 %}
 
 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
@@ -372,6 +373,19 @@ exp	:	exp ARROW COMPLETE
 			  write_exp_elt_opcode (STRUCTOP_PTR); }
 	;
 
+exp	:	exp ARROW '~' name
+			{ write_exp_elt_opcode (STRUCTOP_PTR);
+			  write_destructor_name ($4);
+			  write_exp_elt_opcode (STRUCTOP_PTR); }
+	;
+
+exp	:	exp ARROW '~' name COMPLETE
+			{ mark_struct_expression ();
+			  write_exp_elt_opcode (STRUCTOP_PTR);
+			  write_destructor_name ($4);
+			  write_exp_elt_opcode (STRUCTOP_PTR); }
+	;
+
 exp	:	exp ARROW qualified_name
 			{ /* exp->type::name becomes exp->*(&type::name) */
 			  /* Note: this doesn't work if name is a
@@ -407,6 +421,19 @@ exp	:	exp '.' COMPLETE
 			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
 	;
 
+exp	:	exp '.' '~' name
+			{ write_exp_elt_opcode (STRUCTOP_STRUCT);
+			  write_destructor_name ($4);
+			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
+	;
+
+exp	:	exp '.' '~' name COMPLETE
+			{ mark_struct_expression ();
+			  write_exp_elt_opcode (STRUCTOP_STRUCT);
+			  write_destructor_name ($4);
+			  write_exp_elt_opcode (STRUCTOP_STRUCT); }
+	;
+
 exp	:	exp '.' qualified_name
 			{ /* exp.type::name becomes exp.*(&type::name) */
 			  /* Note: this doesn't work if name is a
@@ -1592,6 +1619,22 @@ name_not_typename :	NAME
 
 %%
 
+/* Like write_exp_string, but prepends a '~'.  */
+
+static void
+write_destructor_name (struct stoken token)
+{
+  char *copy = alloca (token.length + 1);
+
+  copy[0] = '~';
+  memcpy (&copy[1], token.ptr, token.length);
+
+  token.ptr = copy;
+  ++token.length;
+
+  write_exp_string (token);
+}
+
 /* Returns a stoken of the operator name given by OP (which does not
    include the string "operator").  */ 
 static struct stoken
diff --git a/gdb/testsuite/gdb.cp/m-static.exp b/gdb/testsuite/gdb.cp/m-static.exp
index 4dce778..e336231 100644
--- a/gdb/testsuite/gdb.cp/m-static.exp
+++ b/gdb/testsuite/gdb.cp/m-static.exp
@@ -74,6 +74,13 @@ gdb_test "ptype gnu_obj_1::gnu_obj_1" \
     {type = void \(gnu_obj_1 \* const, gnu_obj_1::antiquities, long\)} \
     "simple object class, ptype constructor"
 
+gdb_test "print test1.~gnu_obj_1" \
+    { = {void \(gnu_obj_1 \* const, int\)} 0x[0-9a-f]+ <gnu_obj_1::~gnu_obj_1\(\)>} \
+    "simple object instance, print destructor"
+gdb_test "ptype test1.~gnu_obj_1" \
+    {type = void \(gnu_obj_1 \* const, int\)} \
+    "simple object instance, ptype destructor"
+
 gdb_test "print test1.'~gnu_obj_1'" \
     { = {void \(gnu_obj_1 \*( const)?, int\)} 0x[0-9a-f]+ <gnu_obj_1::~gnu_obj_1\(\)>} \
     "simple object instance, print quoted destructor"


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