From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4030 invoked by alias); 18 Sep 2012 20:33:15 -0000 Received: (qmail 4019 invoked by uid 22791); 18 Sep 2012 20:33:14 -0000 X-SWARE-Spam-Status: No, hits=-3.0 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,TW_BJ,TW_JC X-Spam-Check-By: sourceware.org Received: from server-nat-6.cs.umd.edu (HELO bacon.cs.umd.edu) (128.8.127.149) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 18 Sep 2012 20:32:50 +0000 Received: from [10.109.174.174] (129-2-129-155.wireless.umd.edu [129.2.129.155]) (Authenticated sender: khooyp) by bacon.cs.umd.edu (Postfix) with ESMTPSA id A4714B40A0D; Tue, 18 Sep 2012 16:32:45 -0400 (EDT) From: Khoo Yit Phang Content-Type: multipart/mixed; boundary=Apple-Mail-22-325973264 Subject: [PATCH] Try to initialize data-directory by first searching for "data-directory" in the same directory as the gdb binary Date: Tue, 18 Sep 2012 20:33:00 -0000 Message-Id: <21ACC598-F6B4-4117-BA7B-B316414DE9E3@cs.umd.edu> Cc: Khoo Yit Phang To: GDB Patches Mime-Version: 1.0 (Apple Message framework v1084) X-CSD-MailScanner-ID: A4714B40A0D.AE84A X-CSD-MailScanner: Found to be clean X-CSD-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-50, required 5, autolearn=not spam, ALL_TRUSTED -50.00) X-CSD-MailScanner-From: khooyp@cs.umd.edu X-CSD-MailScanner-Watermark: 1348605165.85778@WhPIFHMHdXgE3l0zN1iBYQ 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: 2012-09/txt/msg00382.txt.bz2 --Apple-Mail-22-325973264 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Content-length: 351 Hi, As discussed previously, here a patch that tries to initialize data-directo= ry by first searching for "data-directory" in the same directory as the gdb= binary. Additionally, I've also reverted my previous change to cc-with-twe= aks.sh that added the -data-directory flag, since it is no longer necessary. Thank you, Yit September 18, 2012 --Apple-Mail-22-325973264 Content-Disposition: attachment; filename=gdb-relative-data-directory.txt Content-Type: text/plain; name="gdb-relative-data-directory.txt" Content-Transfer-Encoding: 7bit Content-length: 5685 gdb/ChangeLog 2012-09-18 Khoo Yit Phang Try to initialize data-directory by first searching for "data-directory" in the same directory as the gdb binary. * contrib/cc-with-tweaks.sh (GDB): Revert -data-directory additions that is now unnecessary. * main.c (relocate_path): Add an isdir argument, and check that the relocated file/directory exists. (relocate_gdb_directory): Remove the directory check that is subsumed by relocate_path. (get_init_files): Remove the file check that is subsumed by relocate_path. (relocate_gdb_data_directory): New function similar to relocate_gdb_directory, but specifically for data-directory. (captured_main): Call relocate_gdb_data_directory to initialize gdb_datadir. diff --git a/gdb/contrib/cc-with-tweaks.sh b/gdb/contrib/cc-with-tweaks.sh --- a/gdb/contrib/cc-with-tweaks.sh +++ b/gdb/contrib/cc-with-tweaks.sh @@ -19,8 +19,7 @@ # This program requires gdb and objcopy in addition to gcc. # The default values are gdb from the build tree and objcopy from $PATH. # They may be overridden by setting environment variables GDB and OBJCOPY -# respectively. Note that GDB should contain the gdb binary as well as the -# -data-directory flag, e.g., "foo/gdb -data-directory foo/data-directory". +# respectively. # We assume the current directory is either $obj/gdb or $obj/gdb/testsuite. # # Example usage: @@ -47,13 +46,13 @@ then if [ -f ./gdb ] then - GDB="./gdb -data-directory data-directory" + GDB="./gdb" elif [ -f ../gdb ] then - GDB="../gdb -data-directory ../data-directory" + GDB="../gdb" elif [ -f ../../gdb ] then - GDB="../../gdb -data-directory ../../data-directory" + GDB="../../gdb" else echo "$myname: unable to find usable gdb" >&2 exit 1 diff --git a/gdb/main.c b/gdb/main.c --- a/gdb/main.c +++ b/gdb/main.c @@ -91,17 +91,34 @@ static void print_gdb_help (struct ui_file *); -/* Relocate a file or directory. PROGNAME is the name by which gdb - was invoked (i.e., argv[0]). INITIAL is the default value for the - file or directory. FLAG is true if the value is relocatable, false - otherwise. Returns a newly allocated string; this may return NULL - under the same conditions as make_relative_prefix. */ +/* Relocate a file or directory, checking if it exists. PROGNAME is the + name by which gdb was invoked (i.e., argv[0]). INITIAL is the default + value for the file or directory. ISDIR is true if INITIAL is a + directory. FLAG is true if the value is relocatable, false otherwise. + Returns a newly allocated string; this may return NULL under the same + conditions as make_relative_prefix, or if the relocated path does not + exist. */ static char * -relocate_path (const char *progname, const char *initial, int flag) +relocate_path (const char *progname, const char *initial, int isdir, + int flag) { if (flag) - return make_relative_prefix (progname, BINDIR, initial); + { + char *path; + path = make_relative_prefix (progname, BINDIR, initial); + if (path) + { + struct stat s; + + if (stat (path, &s) != 0 || (isdir && !S_ISDIR (s.st_mode))) + { + xfree (path); + path = NULL; + } + } + return path; + } return xstrdup (initial); } @@ -116,19 +133,52 @@ { char *dir; - dir = relocate_path (gdb_program_name, initial, flag); - if (dir) + dir = relocate_path (gdb_program_name, initial, 1, flag); + if (!dir) + dir = xstrdup (initial); + + /* Canonicalize the directory. */ + if (*dir) { - struct stat s; + char *canon_sysroot = lrealpath (dir); - if (stat (dir, &s) != 0 || !S_ISDIR (s.st_mode)) + if (canon_sysroot) { xfree (dir); - dir = NULL; + dir = canon_sysroot; } } + + return dir; +} + +/* Like relocate_gdb_path, but specifically for data-directory. */ + +static char * +relocate_gdb_data_directory (void) +{ + char *dir; + + /* First try to find "data-directory" in the same directory as gdb. + + Use relocate_path only to resolve the parent directory of + gdb_program_name (i.e., based on PATH if necessary); relocate_path + (gdb_program_name, BINDIR "/data-directory") cannot be used to resolve + data-directory as it returns a path relative to the _grandparent + directory_ of gdb_program_name (munging the parent directory). */ + + dir = relocate_path (gdb_program_name, BINDIR, 1, 1); + if (dir) + dir = reconcat (dir, dir, SLASH_STRING, "data-directory", NULL); + + /* Then try to find GDB_DATADIR relocated relative to gdb. */ if (!dir) - dir = xstrdup (initial); + dir = relocate_path (gdb_program_name, GDB_DATADIR, 1, + GDB_DATADIR_RELOCATABLE); + + /* Otherwise use GDB_DATADIR as is. */ + if (!dir) + dir = xstrdup (GDB_DATADIR); /* Canonicalize the directory. */ if (*dir) @@ -162,15 +212,15 @@ if (!initialized) { - struct stat homebuf, cwdbuf, s; + struct stat homebuf, cwdbuf; char *homedir, *relocated_sysgdbinit; if (SYSTEM_GDBINIT[0]) { relocated_sysgdbinit = relocate_path (gdb_program_name, - SYSTEM_GDBINIT, + SYSTEM_GDBINIT, 0, SYSTEM_GDBINIT_RELOCATABLE); - if (relocated_sysgdbinit && stat (relocated_sysgdbinit, &s) == 0) + if (relocated_sysgdbinit) sysgdbinit = relocated_sysgdbinit; else xfree (relocated_sysgdbinit); @@ -363,8 +413,7 @@ debug_file_directory = relocate_gdb_directory (DEBUGDIR, DEBUGDIR_RELOCATABLE); - gdb_datadir = relocate_gdb_directory (GDB_DATADIR, - GDB_DATADIR_RELOCATABLE); + gdb_datadir = relocate_gdb_data_directory (); #ifdef WITH_PYTHON_PATH { --Apple-Mail-22-325973264--