From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5088 invoked by alias); 29 Mar 2010 03:22:07 -0000 Received: (qmail 5079 invoked by uid 22791); 29 Mar 2010 03:22:06 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 29 Mar 2010 03:22:00 +0000 Received: (qmail 26845 invoked from network); 29 Mar 2010 03:21:58 -0000 Received: from unknown (HELO ?117.131.21.13?) (jie@127.0.0.2) by mail.codesourcery.com with ESMTPA; 29 Mar 2010 03:21:58 -0000 Message-ID: <4BB01CC6.3090402@codesourcery.com> Date: Mon, 29 Mar 2010 03:22:00 -0000 From: Jie Zhang User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [RFC] Fix a bug in source file searching Content-Type: multipart/mixed; boundary="------------020202080804080408090800" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-03/txt/msg00978.txt.bz2 This is a multi-part message in MIME format. --------------020202080804080408090800 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1987 I found this bug when debugging GCC. (Actually I don't know if this is a bug in GDB code or documentation.) I prepared a patch so you can easily comment. When I was trying to set a breakpoint on a function in GCC generated options.c, like cl_optimization_restore, GDB always thought it's the options.c in gcc/fortran/ . The related DWARF looks like: <4c5ddc> DW_AT_name : (indirect string, offset: 0x58826): options.c <4c5de0> DW_AT_comp_dir : (indirect string, offset: 0x5383): /home/jie/sources/gcc/builds/build.svn-trunk/gcc and The File Name Table: Entry Dir Time Size Name 1 0 0 0 options.c According to DWARF, Dir = 0 means the current directory of the compilation, which "is understood to be the zeroth entry and is not explicitly represented." So the full name of options.c should be "/home/jie/sources/gcc/builds/build.svn-trunk/gcc/options.c". And .gdbinit file in GCC build directory has dir ../../../svn/trunk/gcc/fortran So it looked GDB searched pathes added by dir command first. But the GDB documentation says in "9.5 Specifying Source Directories": [quote] For example, suppose an executable references the file /usr/src/foo-1.0/lib/foo.c, and our source path is /mnt/cross. The file is first looked up literally; if this fails, /mnt/cross/usr/src/foo-1.0/lib/foo.c is tried; if this fails, /mnt/cross/foo.c is opened; if this fails, an error message is printed. [/quote] From this words, it seems the current GDB behavior doesn't conforms to the documentation. This patch makes GDB first look up the file literally. Only one new FAIL found when doing regression testing on i686-pc-linux-gnu: FAIL: gdb.reverse/i387-env-reverse.exp: record to end of main (timeout) I think it's not an error caused by the patch. Currently I have no reduced test case. If the idea is good, I can write up a test case. Any comments? -- Jie Zhang CodeSourcery (650) 331-3385 x735 --------------020202080804080408090800 Content-Type: text/x-patch; name="gdb-fix-find-and-open-source.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gdb-fix-find-and-open-source.diff" Content-length: 1071 * source.c (find_and_open_source): Search file in compilation directory first. Index: source.c =================================================================== RCS file: /cvs/src/src/gdb/source.c,v retrieving revision 1.108 diff -u -p -r1.108 source.c --- source.c 10 Mar 2010 18:20:06 -0000 1.108 +++ source.c 28 Mar 2010 15:54:07 -0000 @@ -971,6 +971,27 @@ find_and_open_source (const char *filena if (dirname != NULL) { + char *name, *rewritten_fullname; + + name = concat (dirname, SLASH_STRING, filename, (char *)NULL); + rewritten_fullname = rewrite_source_path (name); + + if (rewritten_fullname != NULL) + { + *fullname = rewritten_fullname; + xfree (name); + } + else + *fullname = name; + result = open (*fullname, OPEN_MODE); + if (result >= 0) + return result; + xfree (*fullname); + *fullname = NULL; + } + + if (dirname != NULL) + { /* If necessary, rewrite the compilation directory name according to the source path substitution rules specified by the user. */ --------------020202080804080408090800--