http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48045

           Summary: dwarf2out emits CU with DW_AT_stmt_list to empty line
                    table
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: m...@gcc.gnu.org


Found using the elfutils dwarflint tool.

Example:
$ echo "static int empty;" > empty.c
$ gcc -g -c empty.c 
$ readelf --debug-dump=info empty.o | grep DW_AT_stmt
    <29>   DW_AT_stmt_list   : 0x0    
$ readelf --debug-dump=decodedline empty.o
Decoded dump of debug contents of section .debug_line:

CU: empty.c:
File name                            Line number    Starting address


It seems wrong to output a DW_AT_stmt_list if there are no statements at all.

Possible patch:

Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c    (revision 170813)
+++ gcc/dwarf2out.c    (working copy)
@@ -23485,7 +23486,7 @@
     add_ranges (NULL);
     }

-  if (debug_info_level >= DINFO_LEVEL_NORMAL)
+  if (debug_info_level >= DINFO_LEVEL_NORMAL && line_info_table_in_use > 1)
     add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
             debug_line_section_label);

@@ -23512,7 +23513,7 @@
       /* Add a pointer to the line table for the main compilation unit
          so that the debugger can make sense of DW_AT_decl_file
          attributes.  */
-      if (debug_info_level >= DINFO_LEVEL_NORMAL)
+      if (debug_info_level >= DINFO_LEVEL_NORMAL && line_info_table_in_use >
1)
         add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
                 debug_line_section_label);

Reply via email to