Hello, The constructors (resp. destructors) of a given class K are cloned. For each constructor (resp. destructor) There is thus an abstract version of the function and (at least) a concrete version that actually contains the code of the abstract version.
The debug info generated for a constructor (resp. destructor) lacks linkage name (DWARF attribute DW_AT_MIPS_linkage_name), making the job of GDB slow and difficult when it tries to get the actual concrete function that contains the constructor's code to, e.g, set a breakpoint. The patch below emits that linkage name for those concrete versions of cloned public functions. Tested on x86-64-unknown-linux-gnu against trunk. 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 | 11 +++++++++++ gcc/testsuite/g++.dg/debug/dwarf2/cdtor-1.C | 17 +++++++++++++++++ 2 files changed, 28 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..85c01b1 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -19601,6 +19601,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die) dw_die_ref old_die = lookup_decl_die (decl); int declaration = (current_function_decl != decl || class_or_namespace_scope_p (context_die)); + bool fn_has_code_addr_p = false; premark_used_types (); @@ -19769,6 +19770,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die) /* We have already generated the labels. */ add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin); add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end); + fn_has_code_addr_p = true; } else { @@ -19780,6 +19782,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die) ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, current_function_funcdef_no); add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); + fn_has_code_addr_p = true; } #if VMS_DEBUGGING_INFO @@ -19929,6 +19932,14 @@ gen_subprogram_die (tree decl, dw_die_ref context_die) if (cfun->static_chain_decl) add_AT_location_description (subr_die, DW_AT_static_link, loc_list_from_tree (cfun->static_chain_decl, 2)); + + if (fn_has_code_addr_p && origin && 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); } /* Generate child dies for template paramaters. */ 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