Jason Merrill <ja...@redhat.com> a écrit:

> Why not just call add_linkage_name after add_abstract_origin_attribute?

That is what I first did and it worked for this case.  But then I wasn't
sure if there could be cases where a function DIE would have the
DW_AT_abstract_origin set, but won't have any actual code? For instance
if the function has DECL_EXTERNAL set.  That's why I wanted to call
add_linkage_name only if the function has DW_AT_{low,high}_pc so that I
am sure it contains actual code.

If my concern is not justified then I guess the patch below should be
enough then.

gcc/

        * dwarf2out.c (gen_subprogram_die): Emit linkage name attribute
        for functions containing actual code for public cloned abstract
        functions.

gcc/testsuite/

        * g++.dg/debug/dwarf2/cdtor-1.C: New test.
---
 gcc/dwarf2out.c                             |    7 +++++++
 gcc/testsuite/g++.dg/debug/dwarf2/cdtor-1.C |   17 +++++++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/debug/dwarf2/cdtor-1.C

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 55453a3..0cf782f 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -19636,6 +19636,13 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
 
       subr_die = new_die (DW_TAG_subprogram, context_die, decl);
       add_abstract_origin_attribute (subr_die, origin);
+      if (TREE_PUBLIC (origin))
+       /*  So this is where the actual code for a publicly accessible
+           cloned function is.  Let's emit linkage name attribute for
+           it.  This helps debuggers to e.g, set breakpoints into
+           constructors/destructors when the user asks "break
+           K::K".  */
+       add_linkage_name (subr_die, decl);
     }
   else if (old_die)
     {
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/cdtor-1.C 
b/gcc/testsuite/g++.dg/debug/dwarf2/cdtor-1.C
new file mode 100644
index 0000000..6d39e54
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/cdtor-1.C
@@ -0,0 +1,17 @@
+// origin PR debug/49047
+// { dg-options "-g -dA" }
+// { dg-do compile }
+
+struct K
+{
+  K () { }
+  ~K () { }
+};
+
+int
+main()
+{
+    K k;
+}
+
+// { dg-final {scan-assembler-times "\[^\n\r\]*DW_AT_MIPS_linkage_name:" 2 } }
-- 
1.7.3.4


-- 
                Dodji

Reply via email to