This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Bug in dwarf2out.c:output_file_names()
- To: gcc at gcc dot gnu dot org
- Subject: Bug in dwarf2out.c:output_file_names()
- From: Mark Kettenis <kettenis at wins dot uva dot nl>
- Date: Mon, 22 Jan 2001 22:54:04 +0100
- CC: gdb at sources dot redhat dot com, drepper at redhat dot com, rth at redhat dot com
Hi,
There seems to be a problem with the code that writes the directory
table and file name table for DWARF2.
Suppose you have the file src/hello.c:
#include <stdio.h>
#include <stdlib.h>
int
main (void)
{
printf ("Hello, World!\n");
return EXIT_SUCCESS;
}
And now do (on a system with an assembler that doesn't support the
DWARF2 .file an .loc directives):
$ gcc -g -dA -S src/hello.c
the resulting assembly for the start of the .debug_line section looks
like:
.section .debug_line
.4byte .LTEND-.LTSTART # Length of Source Line Info.
.LTSTART:
.2byte 0x2 # DWARF Version
.4byte 0x94 # Prolog Length
.byte 0x4 # Minimum Instruction Length
.byte 0x1 # Default is_stmt_start flag
.byte -10 # Line Base Value (Special Opcodes)
.byte 245 # Line Range Value (Special Opcodes)
.byte 10 # Special Opcode Base
.byte 0x0 # opcode: 0x1 has 0 args
.byte 0x1 # opcode: 0x2 has 1 args
.byte 0x1 # opcode: 0x3 has 1 args
.byte 0x1 # opcode: 0x4 has 1 args
.byte 0x1 # opcode: 0x5 has 1 args
.byte 0x0 # opcode: 0x6 has 0 args
.byte 0x0 # opcode: 0x7 has 0 args
.byte 0x0 # opcode: 0x8 has 0 args
.byte 0x1 # opcode: 0x9 has 1 args
.byte 0x0 # End directory table
.ascii "hello.c\0" # File Entry: 0x1
.byte 0x0 # ULEB128 0x0
.byte 0x0 # ULEB128 0x0
.byte 0x0 # ULEB128 0x0
.byte 0x0 # End file name table
Note that the directory table is empty, and the only the last
component of the path is stored in the file name table. It's needless
to say that this greatly confuses the GDB, resulting in a lot of
testsuite failures when running the testsuite on a system where DWARF2
is the default debugging format.
The problems stem from the following line in
dwarf2out.c:output_file_names():
idx_offset = dirs[0].path[0] == '/' ? 1 : 0;
the result is that the first directory isn't emitted if it doesn't
start with a slash, presumably to avoid emitting an empty directory
entry when compiling source files from the current directory.
However, as I explained before, this loses for relative path names.
Im not exactly sure how the code is supposed to work, but wouldn't
replacing the line above with:
idx_offset = dirs[0].length > 0 ? 1 : 0;
work? It seems to do so for me, although I didn't run the testsuite.
A patch is attached, feel free to use it.
Thanks,
Mark
2001-01-22 Mark Kettenis <kettenis@gnu.org>
* dwarf2out.c (output_file_names): Set idx_offset to 1 based on
the path length instead of whether it starts with a slash.
Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/dwarf2out.c,v
retrieving revision 1.233
diff -u -p -r1.233 dwarf2out.c
--- dwarf2out.c 2001/01/19 17:11:15 1.233
+++ dwarf2out.c 2001/01/22 21:52:23
@@ -6671,7 +6671,7 @@ output_file_names ()
confuse these indices with the one for the constructed table
(even though most of the time they are identical). */
idx = 1;
- idx_offset = dirs[0].path[0] == '/' ? 1 : 0;
+ idx_offset = dirs[0].length > 0 ? 1 : 0;
for (i = 1 - idx_offset; i < ndirs; ++i)
if (dirs[i].used != 0)
{