Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Doug Evans <dje@google.com>
To: gdb-patches@sourceware.org
Subject: [RFA] fix disassemble foo::bar::~bar
Date: Thu, 14 Feb 2013 00:14:00 -0000	[thread overview]
Message-ID: <yjt2liarg3az.fsf@ruffy.mtv.corp.google.com> (raw)

I happened to try this and noticed it failing with
"name of destructor must equal name of class".

This is because destructor_name_p doesn't handle foo::bar
for the type's name.

Regression tested on amd64-linux.

Ok to commit?

2013-02-13  Doug Evans  <dje@google.com>

	* valops.c (destructor_name_p): Fix handling of classes in namespaces.

	testsuite/
	* gdb.cp/cp-disasm.cc: New file.
	* gdb.cp/cp-disasm.exp: New file.

Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.312
diff -u -p -r1.312 valops.c
--- valops.c	11 Feb 2013 18:05:33 -0000	1.312
+++ valops.c	14 Feb 2013 00:13:16 -0000
@@ -3160,20 +3160,28 @@ destructor_name_p (const char *name, str
 {
   if (name[0] == '~')
     {
-      const char *dname = type_name_no_tag_or_error (type);
-      const char *cp = strchr (dname, '<');
+      char *type_name = xstrdup (type_name_no_tag_or_error (type));
+      char *cp = strchr (type_name, '<');
+      char *colon;
+      struct cleanup *cleanups = make_cleanup (xfree, type_name);
       unsigned int len;
 
       /* Do not compare the template part for template classes.  */
-      if (cp == NULL)
-	len = strlen (dname);
-      else
-	len = cp - dname;
-      if (strlen (name + 1) != len || strncmp (dname, name + 1, len) != 0)
+      if (cp != NULL)
+	*cp = '\0';
+
+      /* If TYPE_TYPE is foo::bar, we only want bar.  */
+      colon = strrchr (type_name, ':');
+      if (colon != NULL)
+	type_name = colon + 1;
+
+      if (strcmp (type_name, name + 1) != 0)
 	error (_("name of destructor must equal name of class"));
-      else
-	return 1;
+
+      do_cleanups (cleanups);
+      return 1;
     }
+
   return 0;
 }
 
Index: testsuite/gdb.cp/cp-disasm.cc
===================================================================
RCS file: testsuite/gdb.cp/cp-disasm.cc
diff -N testsuite/gdb.cp/cp-disasm.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.cp/cp-disasm.cc	14 Feb 2013 00:13:16 -0000
@@ -0,0 +1,44 @@
+/* This test file is part of GDB, the GNU debugger.
+
+   Copyright 2013 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/>.  */
+
+class bar
+{
+ public:
+  int x;
+  bar () {}
+  ~bar () {}
+};
+
+namespace foo
+{
+  class bar
+  {
+   public:
+    int x;
+    bar () {}
+    ~bar () {}
+  };
+}
+
+bar x;
+foo::bar y;
+
+int
+main ()
+{
+  return 0;
+}
Index: testsuite/gdb.cp/cp-disasm.exp
===================================================================
RCS file: testsuite/gdb.cp/cp-disasm.exp
diff -N testsuite/gdb.cp/cp-disasm.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.cp/cp-disasm.exp	14 Feb 2013 00:13:16 -0000
@@ -0,0 +1,52 @@
+# Copyright 2013 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/>.
+
+# Test disassembling ctors and dtors.
+
+standard_testfile .cc
+
+if { [skip_cplus_tests] } { continue }
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
+    return -1
+}
+
+set name "disassemble ctor"
+gdb_test_multiple "disassemble bar::bar,+1" $name {
+    -re "Dump of assembler code.*$gdb_prompt $" {
+	pass "$name"
+    }
+}
+
+set name "disassemble dtor"
+gdb_test_multiple "disassemble bar::~bar,+1" "$name" {
+    -re "Dump of assembler code.*$gdb_prompt $" {
+	pass "$name"
+    }
+}
+
+set name "disassemble namespace ctor"
+gdb_test_multiple "disassemble foo::bar::bar,+1" "$name" {
+    -re "Dump of assembler code.*$gdb_prompt $" {
+	pass "$name"
+    }
+}
+
+set name "disassemble namespace dtor"
+gdb_test_multiple "disassemble foo::bar::~bar,+1" "$name" {
+    -re "Dump of assembler code.*$gdb_prompt $" {
+	pass "$name"
+    }
+}


             reply	other threads:[~2013-02-14  0:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-14  0:14 Doug Evans [this message]
2013-02-21 21:14 ` Tom Tromey
2013-02-21 23:58   ` Keith Seitz
2013-02-22 19:15     ` Tom Tromey
2013-02-22 19:43       ` Keith Seitz
2013-02-22 20:00         ` Tom Tromey

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=yjt2liarg3az.fsf@ruffy.mtv.corp.google.com \
    --to=dje@google.com \
    --cc=gdb-patches@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: link
Be 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