From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 650 invoked by alias); 22 Jul 2004 23:31:43 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 643 invoked from network); 22 Jul 2004 23:31:42 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org with SMTP; 22 Jul 2004 23:31:42 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.10/8.12.10) with ESMTP id i6MNVge1016329 for ; Thu, 22 Jul 2004 19:31:42 -0400 Received: from pobox.toronto.redhat.com (pobox.toronto.redhat.com [172.16.14.4]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id i6MNVfa05354 for ; Thu, 22 Jul 2004 19:31:41 -0400 Received: from [172.16.14.67] (towel.toronto.redhat.com [172.16.14.67]) by pobox.toronto.redhat.com (8.12.8/8.12.8) with ESMTP id i6MNVfXP031879 for ; Thu, 22 Jul 2004 19:31:41 -0400 Message-ID: <41004E5D.5020403@redhat.com> Date: Thu, 22 Jul 2004 23:31:00 -0000 From: Bryce McKinlay User-Agent: Mozilla Thunderbird 0.5 (X11/20040626) MIME-Version: 1.0 To: gdb-patches@sources.redhat.com Subject: Patch: Handle relative paths in .debug_line Content-Type: multipart/mixed; boundary="------------040602070309070109050403" X-SW-Source: 2004-07/txt/msg00316.txt.bz2 This is a multi-part message in MIME format. --------------040602070309070109050403 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1476 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 --------------040602070309070109050403 Content-Type: text/x-patch; name="gdb-subfile-compdir.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="gdb-subfile-compdir.patch" Content-length: 4315 2004-07-22 Bryce McKinlay * 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 --------------040602070309070109050403--