public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: fent@in.tum.de
To: gdb-patches@sourceware.org
Cc: tom@tromey.com, simon.marchi@polymtl.ca, Philipp Fent <fent@in.tum.de>
Subject: [PATCH] gdb: fix disas of destructors in nested namespaces
Date: Wed, 17 Aug 2022 09:14:18 +0200	[thread overview]
Message-ID: <20220817071417.349625-1-fent@in.tum.de> (raw)

From: Philipp Fent <fent@in.tum.de>

Remove the destructor name validity check. The check did not properly
handle nested namespaces or complex templates with nested angle
brackets. Overload resolution already checks the name and reports any
mismatches, so this check seems unnecessary.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27045
Signed-off-by: Philipp Fent <fent@in.tum.de>
---
 gdb/c-exp.y                      |  2 --
 gdb/testsuite/gdb.cp/classes.cc  |  8 ++++++++
 gdb/testsuite/gdb.cp/classes.exp |  4 ++++
 gdb/valops.c                     | 27 ---------------------------
 gdb/value.h                      |  2 --
 5 files changed, 12 insertions(+), 31 deletions(-)

diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 61a61fcba09..7ef557bd38f 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1151,8 +1151,6 @@ qualified_name:	TYPENAME COLONCOLON name
 			  std::string name = "~" + std::string ($4.ptr,
 								$4.length);
 
-			  /* Check for valid destructor name.  */
-			  destructor_name_p (name.c_str (), $1.type);
 			  pstate->push_new<scope_operation> (type,
 							     std::move (name));
 			}
diff --git a/gdb/testsuite/gdb.cp/classes.cc b/gdb/testsuite/gdb.cp/classes.cc
index 3bb52d2433c..c59413cddbd 100644
--- a/gdb/testsuite/gdb.cp/classes.cc
+++ b/gdb/testsuite/gdb.cp/classes.cc
@@ -401,6 +401,13 @@ class Base1 {
   ~Base1 () { }
 };
 
+namespace nested {
+class Base {
+public:
+  ~Base () {}
+};
+}
+
 typedef Base1 base1;
 
 class Foo
@@ -627,6 +634,7 @@ void use_methods ()
   i = class_param.Aval_x (g_A);
 
   base1 b (3);
+  nested::Base nb;
 }
 
 struct Inner
diff --git a/gdb/testsuite/gdb.cp/classes.exp b/gdb/testsuite/gdb.cp/classes.exp
index 7b8b315ac1f..14c2e04e492 100644
--- a/gdb/testsuite/gdb.cp/classes.exp
+++ b/gdb/testsuite/gdb.cp/classes.exp
@@ -654,6 +654,10 @@ proc do_tests {} {
 	"print dtor of typedef class"
 
     gdb_test "list ByAnyOtherName::times" ".*int Foo::times.*"
+
+    gdb_test "disassemble nested::Base::~Base" \
+    "Dump of assembler code for function.*Base.*" \
+    "disassemble dtor in nested namespace"
 }
 
 do_tests
diff --git a/gdb/valops.c b/gdb/valops.c
index 27e84d9f6b3..59b8cf04fbf 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3315,33 +3315,6 @@ classify_oload_match (const badness_vector &oload_champ_bv,
   return worst;
 }
 
-/* C++: return 1 is NAME is a legitimate name for the destructor of
-   type TYPE.  If TYPE does not have a destructor, or if NAME is
-   inappropriate for TYPE, an error is signaled.  Parameter TYPE should not yet
-   have CHECK_TYPEDEF applied, this function will apply it itself.  */
-
-int
-destructor_name_p (const char *name, struct type *type)
-{
-  if (name[0] == '~')
-    {
-      const char *dname = type_name_or_error (type);
-      const char *cp = strchr (dname, '<');
-      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)
-	error (_("name of destructor must equal name of class"));
-      else
-	return 1;
-    }
-  return 0;
-}
-
 /* Find an enum constant named NAME in TYPE.  TYPE must be an "enum
    class".  If the name is found, return a value representing it;
    otherwise throw an exception.  */
diff --git a/gdb/value.h b/gdb/value.h
index 7e1eec22413..4f2bf9d4c99 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1062,8 +1062,6 @@ extern int binop_user_defined_p (enum exp_opcode op, struct value *arg1,
 
 extern int unop_user_defined_p (enum exp_opcode op, struct value *arg1);
 
-extern int destructor_name_p (const char *name, struct type *type);
-
 extern value_ref_ptr release_value (struct value *val);
 
 extern int record_latest_value (struct value *val);
-- 
2.37.2


                 reply	other threads:[~2022-08-17  7:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220817071417.349625-1-fent@in.tum.de \
    --to=fent@in.tum.de \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    --cc=tom@tromey.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).