Re: [RFC,PATCH] DWARF support for AIX
On Sun, Sep 20, 2015 at 4:25 PM, David Edelsohnwrote: > Appended is an initial implementation of DWARF support for AIX. The > patch emits the correct sections and works with the existing DWARF > support for AIX XCOFF in GDB ... somewhat. > > First, AIX only supports a subset of DWARF sections. AIX does not > support DWARF debug frame sections, although DWARF unwind frame > sections are produced and consumed internally by GCC. I initially > tried bracketing dwarf2out.c:output_call_frame_info() with #ifdef, but > then changed to setting targetm.debug_unwind_info() to UI_NONE. This > change prevents the debug frame info, but the debug location section > newly appeared, which AIX also does not support. So I must bracket > output_location_lists with #ifdef AIX. Setting and checking for > something like a NULL section name specifically for AIX seems more > complicated and cumbersome. > > Second, recent releases of XLC support DWARF debug info. GDB > understands the DWARF information from XLC. GDB xcoffread.c performs > the mostly normal > > if (dwarf2_has_info (objfile, _xcoff_names)) > dwarf2_build_psymtabs (objfile); > > dwarf2_build_frame_info (objfile); > > so I do not see anything unusual in what it expects to parse. > HOWEVER, XLC DWARF sections begin with the DWARF version number, not > the length, e.g., > >.dwsect 0x0002 # section name .dwline > .dwline: > # 0x0400 # section address > # .long 0x0049 # section length > .short 0x0002 # dwarf version > > .dwsect 0x0001 # section name .dwinfo > .dwinfo: > # 0x0500 # section address > # .long 0x013e # section length > .short 0x0002 # dwarf version > > And that is exactly the way the XLC disassembly appears, comments and > everything. The section length is commented out. > > If I manually comment out the section length information in the GCC > DWARF debugging information, trivial tests of GDB on AIX function > correctly, e.g., it shows the correct file, function and line numbers. > > GDB accepts and understands XLC DWARF debug information WITHOUT > section length but does not understand GCC DWARF debug information > WITH section length. DWARF for other ELF targets includes the section > length and does appear to hinder GDB. > > How can I adjust the DWARF produced by GCC or the DWARF consumed by > GDB to address the section length information? You probably need to add a target hook to do that. Note this isn't "section length" but the size of the CU header. At least on all other targets I know of: .section.debug_info,"",@progbits .Ldebug_info0: .long 0x64# Length of Compilation Unit Info .value 0x4 # DWARF version number and the format of that header is specified by the DWARF standard. So I wonder why XLC chose to do sth non-conforming here (again :/) Richard. > Thanks, David > >* dwarf2out.c (dwarf2out_finish): Don't output location > lists on AIX. > * config/rs6000/rs6000.c (rs6000_xcoff_debug_unwind_info): > New. > (rs6000_xcoff_asm_named_section): Emit .dwsect pseudo-op > for SECTION_DEBUG. > (rs6000_xcoff_declare_function_name): Emit different > .function pseudo-op when DWARF2_DEBUG. > * config/rs6000/xcoff.h (TARGET_DEBUG_UNWIND_INFO): > Redefine. > * config/rs6000/aix71.h (DWARF2_DEBUGGING_INFO): Define. > (PREFERRED_DEBUGGING_TYPE): Define. > (DEBUG_INFO_SECTION): Define. > (DEBUG_ABBREV_SECTION): Define. > (DEBUG_ARANGES_SECTION): Define. > (DEBUG_LINE_SECTION): Define. > (DEBUG_PUBNAMES_SECTION): Define. > (DEBUG_PUBTYPES_SECTION): Define. > (DEBUG_STR_SECTION): Define. > (DEBUG_RANGES_SECTION): Define. > > Index: dwarf2out.c > === > --- dwarf2out.c (revision 227937) > +++ dwarf2out.c (working copy) > @@ -25486,6 +25486,7 @@ >output_abbrev_section (); > } > > +#ifndef TARGET_AIX_VERSION >/* Output location list section if necessary. */ >if (have_location_lists) > { > @@ -25494,6 +25495,7 @@ >ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); >output_location_lists (comp_unit_die ()); > } > +#endif > >output_pubtables (); > > Index: config/rs6000/rs6000.c > === > --- config/rs6000/rs6000.c (revision 227937) > +++ config/rs6000/rs6000.c (working copy) > @@ -30684,6 +30684,12 @@ > #endif > > #if TARGET_XCOFF > +static enum unwind_info_type > +rs6000_xcoff_debug_unwind_info (void) > +{ > + return UI_NONE; > +} > + > static void > rs6000_xcoff_asm_output_anchor (rtx symbol) > { > @@ -30805,6 +30811,11 @@ >
[RFC,PATCH] DWARF support for AIX
Appended is an initial implementation of DWARF support for AIX. The patch emits the correct sections and works with the existing DWARF support for AIX XCOFF in GDB ... somewhat. First, AIX only supports a subset of DWARF sections. AIX does not support DWARF debug frame sections, although DWARF unwind frame sections are produced and consumed internally by GCC. I initially tried bracketing dwarf2out.c:output_call_frame_info() with #ifdef, but then changed to setting targetm.debug_unwind_info() to UI_NONE. This change prevents the debug frame info, but the debug location section newly appeared, which AIX also does not support. So I must bracket output_location_lists with #ifdef AIX. Setting and checking for something like a NULL section name specifically for AIX seems more complicated and cumbersome. Second, recent releases of XLC support DWARF debug info. GDB understands the DWARF information from XLC. GDB xcoffread.c performs the mostly normal if (dwarf2_has_info (objfile, _xcoff_names)) dwarf2_build_psymtabs (objfile); dwarf2_build_frame_info (objfile); so I do not see anything unusual in what it expects to parse. HOWEVER, XLC DWARF sections begin with the DWARF version number, not the length, e.g., .dwsect 0x0002 # section name .dwline .dwline: # 0x0400 # section address # .long 0x0049 # section length .short 0x0002 # dwarf version .dwsect 0x0001 # section name .dwinfo .dwinfo: # 0x0500 # section address # .long 0x013e # section length .short 0x0002 # dwarf version And that is exactly the way the XLC disassembly appears, comments and everything. The section length is commented out. If I manually comment out the section length information in the GCC DWARF debugging information, trivial tests of GDB on AIX function correctly, e.g., it shows the correct file, function and line numbers. GDB accepts and understands XLC DWARF debug information WITHOUT section length but does not understand GCC DWARF debug information WITH section length. DWARF for other ELF targets includes the section length and does appear to hinder GDB. How can I adjust the DWARF produced by GCC or the DWARF consumed by GDB to address the section length information? Thanks, David * dwarf2out.c (dwarf2out_finish): Don't output location lists on AIX. * config/rs6000/rs6000.c (rs6000_xcoff_debug_unwind_info): New. (rs6000_xcoff_asm_named_section): Emit .dwsect pseudo-op for SECTION_DEBUG. (rs6000_xcoff_declare_function_name): Emit different .function pseudo-op when DWARF2_DEBUG. * config/rs6000/xcoff.h (TARGET_DEBUG_UNWIND_INFO): Redefine. * config/rs6000/aix71.h (DWARF2_DEBUGGING_INFO): Define. (PREFERRED_DEBUGGING_TYPE): Define. (DEBUG_INFO_SECTION): Define. (DEBUG_ABBREV_SECTION): Define. (DEBUG_ARANGES_SECTION): Define. (DEBUG_LINE_SECTION): Define. (DEBUG_PUBNAMES_SECTION): Define. (DEBUG_PUBTYPES_SECTION): Define. (DEBUG_STR_SECTION): Define. (DEBUG_RANGES_SECTION): Define. Index: dwarf2out.c === --- dwarf2out.c (revision 227937) +++ dwarf2out.c (working copy) @@ -25486,6 +25486,7 @@ output_abbrev_section (); } +#ifndef TARGET_AIX_VERSION /* Output location list section if necessary. */ if (have_location_lists) { @@ -25494,6 +25495,7 @@ ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); output_location_lists (comp_unit_die ()); } +#endif output_pubtables (); Index: config/rs6000/rs6000.c === --- config/rs6000/rs6000.c (revision 227937) +++ config/rs6000/rs6000.c (working copy) @@ -30684,6 +30684,12 @@ #endif #if TARGET_XCOFF +static enum unwind_info_type +rs6000_xcoff_debug_unwind_info (void) +{ + return UI_NONE; +} + static void rs6000_xcoff_asm_output_anchor (rtx symbol) { @@ -30805,6 +30811,11 @@ int smclass; static const char * const suffix[4] = { "PR", "RO", "RW", "TL" }; + if (flags & SECTION_DEBUG) +{ + fprintf (asm_out_file, "\t.dwsect %s\n", name); + return; +} if (flags & SECTION_CODE) smclass = 0; else if (flags & SECTION_TLS) @@ -31140,8 +31151,16 @@ fputs (":\n", file); data.function_descriptor = true; symtab_node::get (decl)->call_for_symbol_and_aliases (rs6000_declare_alias, , true); - if (write_symbols != NO_DEBUG && !DECL_IGNORED_P (decl)) -xcoffout_declare_function (file, decl, buffer); + if (!DECL_IGNORED_P (decl)) +{ + if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) + xcoffout_declare_function (file, decl, buffer); + else if (write_symbols ==