[23/24] pdbout: Handle names of ctor and dtor functions.

Message ID 20210320162652.23346-23-mark@harmstone.com
State New
Headers show
Series
  • [01/24] Add -gcodeview debugging option
Related show

Commit Message

Mark Harmstone March 20, 2021, 4:26 p.m.
---
 gcc/pdbout.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

-- 
2.26.2

Patch

diff --git a/gcc/pdbout.c b/gcc/pdbout.c
index d9ad659cd9a..0f5315f7f07 100644
--- a/gcc/pdbout.c
+++ b/gcc/pdbout.c
@@ -2175,7 +2175,33 @@  get_tree_name (tree t)
   static const char anon_ns[] = "<anonymous>";
 
   if (TREE_CODE (t) == FUNCTION_DECL)
-    name = xstrdup (IDENTIFIER_POINTER (DECL_NAME (t)));
+    {
+      if (DECL_CXX_CONSTRUCTOR_P (t) || DECL_CXX_DESTRUCTOR_P (t))
+	{
+	  tree ctx = DECL_CONTEXT (t);
+	  const char *basename;
+
+	  if (!ctx || !TYPE_NAME (ctx)
+	      || TREE_CODE (TYPE_NAME (ctx)) != TYPE_DECL)
+	    return NULL;
+
+	  basename = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (ctx)));
+
+	  if (DECL_CXX_CONSTRUCTOR_P (t))
+	    name = xstrdup (basename);
+	  else
+	    {
+	      name = (char *) xmalloc (strlen (basename) + 2);
+
+	      name[0] = '~';
+	      name[1] = 0;
+
+	      strcat (name, basename);
+	    }
+	}
+      else
+	name = xstrdup (IDENTIFIER_POINTER (DECL_NAME (t)));
+    }
   else if (TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE)
     name = xstrdup (IDENTIFIER_POINTER (TYPE_NAME (t)));
   else if (TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL