This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Patch: Handle relative paths in .debug_line
- From: Bryce McKinlay <mckinlay at redhat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Thu, 22 Jul 2004 19:31:41 -0400
- Subject: Patch: Handle relative paths in .debug_line
When debugging mainline gcc, GDB has a problem locating source for files
which are only referenced from .debug_line. For example: debugging gcj,
and trying to put a breakpoint on the parse.y file, I get the following:
Breakpoint 1, lookup_method_invoke (lc=1, cl=0xf6dee5f0, class=0xf6def244,
name=0xf6dee550, arg_list=0xf6e574b0) at parse.y:10956
10956 parse.y: No such file or directory.
in parse.y
(gdb) info source
Current source file is parse.y
Compilation directory is ../../gcc/java
Source language is c.
Compiled with unknown debugging format.
Does not include preprocessor macro info.
This is because the contents of the directory table in .debug_line can
be paths relative to the DW_AT_comp_dir:
The Directory Table:
../../gcc/java
java
/usr/include/bits
.
../../gcc
../../gcc/../libcpp/include
../../gcc/config/i386
../../gcc/../include
/local/gcc-clean/lib/gcc/i686-pc-linux-gnu/3.5.0/include
/usr/include
The File Name Table:
Entry Dir Time Size Name
1 1 0 0 keyword.h
2 1 0 0 lex.c
3 2 0 0 parse.c
4 1 0 0 parse.y
... etc...
DW_AT_comp_dir : (indirect string, offset: 0x658c):
/home/mckinlay/cvs/gcc-really-clean/build/gcc
This patch fixes the problem by appending the path from the directory
table, if it is not absolute already, to the DW_AT_comp_dir path when
creating subfiles from the .debug_line info.
OK to commit?
Bryce
2004-07-22 Bryce McKinlay <mckinlay@redhat.com>
* dwarf2read.c (dwarf_decode_lines): Pass comp_dir to
dwarf2_start_subfile.
(dwarf2_start_subfile): New comp_dir parameter. Handle relative paths
in .debug_line by appending them to comp_dir. Use make_cleanup to
free strings used in directory concatenation.
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.156
diff -u -r1.156 dwarf2read.c
--- dwarf2read.c 6 Jul 2004 19:29:30 -0000 1.156
+++ dwarf2read.c 22 Jul 2004 23:07:41 -0000
@@ -762,7 +762,7 @@
static void dwarf_decode_lines (struct line_header *, char *, bfd *,
struct dwarf2_cu *, struct partial_symtab *);
-static void dwarf2_start_subfile (char *, char *);
+static void dwarf2_start_subfile (char *, char *, char *);
static struct symbol *new_symbol (struct die_info *, struct type *,
struct dwarf2_cu *);
@@ -5951,12 +5951,10 @@
directory and file name numbers in the statement program
are 1-based. */
struct file_entry *fe = &lh->file_names[file - 1];
- char *dir;
+ char *dir = NULL;
if (fe->dir_index)
dir = lh->include_dirs[fe->dir_index - 1];
- else
- dir = comp_dir;
- dwarf2_start_subfile (fe->name, dir);
+ dwarf2_start_subfile (fe->name, dir, comp_dir);
}
/* Decode the table. */
@@ -6044,17 +6042,15 @@
but the directory and file name numbers in the
statement program are 1-based. */
struct file_entry *fe;
- char *dir;
+ char *dir = NULL;
file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
line_ptr += bytes_read;
fe = &lh->file_names[file - 1];
fe->included_p = 1;
if (fe->dir_index)
dir = lh->include_dirs[fe->dir_index - 1];
- else
- dir = comp_dir;
if (!decode_for_pst_p)
- dwarf2_start_subfile (fe->name, dir);
+ dwarf2_start_subfile (fe->name, dir, comp_dir);
}
break;
case DW_LNS_set_column:
@@ -6112,7 +6108,8 @@
/* Start a subfile for DWARF. FILENAME is the name of the file and
DIRNAME the name of the source directory which contains FILENAME
- or NULL if not known.
+ or NULL if not known. COMP_DIR is the value of DW_AT_comp_dir. If
+ DIRNAME specifies a relative path, it is appended to COMP_DIR.
This routine tries to keep line numbers from identical absolute and
relative file names in a common subfile.
@@ -6131,28 +6128,44 @@
subfile, so that `break /srcdir/list0.c:1' works as expected. */
static void
-dwarf2_start_subfile (char *filename, char *dirname)
+dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir)
{
+ char *fullname;
+ struct subfile *subfile;
+ struct cleanup *back_to = make_cleanup (null_cleanup, 0);
+
+ /* If we have a relative dirname, append comp_dir to it. */
+ if (dirname != NULL && !IS_ABSOLUTE_PATH (dirname))
+ {
+ dirname = concat (comp_dir, "/", dirname, NULL);
+ make_cleanup (xfree, dirname);
+ }
+ else if (dirname == NULL)
+ dirname = comp_dir;
+
/* If the filename isn't absolute, try to match an existing subfile
with the full pathname. */
- if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
+ if (!IS_ABSOLUTE_PATH (filename))
{
- struct subfile *subfile;
- char *fullname = concat (dirname, "/", filename, NULL);
+ fullname = concat (dirname, "/", filename, NULL);
+ make_cleanup (xfree, fullname);
+ }
+ else
+ fullname = filename;
- for (subfile = subfiles; subfile; subfile = subfile->next)
+ for (subfile = subfiles; subfile; subfile = subfile->next)
+ {
+ if (FILENAME_CMP (subfile->name, fullname) == 0)
{
- if (FILENAME_CMP (subfile->name, fullname) == 0)
- {
- current_subfile = subfile;
- xfree (fullname);
- return;
- }
+ current_subfile = subfile;
+ do_cleanups (back_to);
+ return;
}
- xfree (fullname);
}
+
start_subfile (filename, dirname);
+ do_cleanups (back_to);
}
static void