Bug 48045 - dwarf2out emits CU with DW_AT_stmt_list to empty line table
Summary: dwarf2out emits CU with DW_AT_stmt_list to empty line table
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-debug
Depends on:
Blocks:
 
Reported: 2011-03-09 13:58 UTC by Mark Wielaard
Modified: 2021-12-24 14:08 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Wielaard 2011-03-09 13:58:35 UTC
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);
Comment 1 Mark Wielaard 2011-03-09 23:04:09 UTC
The previous patch is wrong, it should depend on either a .loc or a .line output. I had misunderstood when the DW_AT_stmt_list was really necessary. Also there was some debate on whether or not pointing to an empty line number table was actually wrong. We might want to change dwarflint to just allow it. See the discussion here: https://fedorahosted.org/pipermail/elfutils-devel/2011-March/001840.html