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, &dwarf2_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 0x00020000              # section name .dwline
.dwline:
#               0x00000400              # section address
#       .long   0x00000049              # section length
        .short  0x0002                  # dwarf version

        .dwsect 0x00010000              # section name .dwinfo
.dwinfo:
#               0x00000500              # section address
#       .long   0x0000013e              # 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, &data, 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 == DWARF2_DEBUG)
+       {
+         name = (*targetm.strip_name_encoding) (name);
+         fprintf (file, "\t.function .%s,.%s,2,0\n", name, name);
+       }
+    }
   return;
 }

Index: config/rs6000/xcoff.h
===================================================================
--- config/rs6000/xcoff.h       (revision 227937)
+++ config/rs6000/xcoff.h       (working copy)
@@ -86,6 +86,8 @@
               || (SCALAR_FLOAT_MODE_P (GET_MODE (X))                   \
                   && ! TARGET_NO_FP_IN_TOC)))))

+#undef TARGET_DEBUG_UNWIND_INFO
+#define TARGET_DEBUG_UNWIND_INFO  rs6000_xcoff_debug_unwind_info
 #define TARGET_ASM_OUTPUT_ANCHOR  rs6000_xcoff_asm_output_anchor
 #define TARGET_ASM_GLOBALIZE_LABEL  rs6000_xcoff_asm_globalize_label
 #define TARGET_ASM_INIT_SECTIONS  rs6000_xcoff_asm_init_sections

Index: config/rs6000/aix71.h
===================================================================
+/* AIX 7.1 supports DWARF debugging, but XCOFF remains the default.  */
+#define DWARF2_DEBUGGING_INFO 1
+#define PREFERRED_DEBUGGING_TYPE XCOFF_DEBUG
+#define DEBUG_INFO_SECTION      "0x10000"
+#define DEBUG_ABBREV_SECTION    "0x60000"
+#define DEBUG_ARANGES_SECTION   "0x50000"
+#define DEBUG_LINE_SECTION      "0x20000"
+#define DEBUG_PUBNAMES_SECTION  "0x30000"
+#define DEBUG_PUBTYPES_SECTION  "0x40000"
+#define DEBUG_STR_SECTION       "0x70000"
+#define DEBUG_RANGES_SECTION    "0x80000"

Reply via email to