From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16683 invoked by alias); 19 Sep 2012 13:01:14 -0000 Received: (qmail 16650 invoked by uid 22791); 19 Sep 2012 13:01:10 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_BJ,TW_JC X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 19 Sep 2012 13:00:49 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8JD0lSQ031941 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 19 Sep 2012 09:00:47 -0400 Received: from host2.jankratochvil.net (ovpn-113-58.phx2.redhat.com [10.3.113.58]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8JD0fLZ015953 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 19 Sep 2012 09:00:44 -0400 Date: Wed, 19 Sep 2012 13:01:00 -0000 From: Jan Kratochvil To: Khoo Yit Phang Cc: GDB Patches Subject: Re: [PATCH] Try to initialize data-directory by first searching for "data-directory" in the same directory as the gdb binary Message-ID: <20120919130040.GA20442@host2.jankratochvil.net> References: <21ACC598-F6B4-4117-BA7B-B316414DE9E3@cs.umd.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <21ACC598-F6B4-4117-BA7B-B316414DE9E3@cs.umd.edu> User-Agent: Mutt/1.5.21 (2010-09-15) 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: 2012-09/txt/msg00388.txt.bz2 On Tue, 18 Sep 2012 22:32:40 +0200, Khoo Yit Phang wrote: > As discussed previously, here a patch that tries to initialize > data-directory by first searching for "data-directory" in the same directory > as the gdb binary. I do not see how is it related to the 'isdir' addition, IMO 'isdir' is an unrelated patch which should be posted separately. > Additionally, I've also reverted my previous change to cc-with-tweaks.sh > that added the -data-directory flag, since it is no longer necessary. It can be kept there, it does not harm anything and it then does not depend on a bit magic relocate_gdb_directory. Thanks, Jan > 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. */ GDB comments are formatted to textwidth=72 which may explain this excessive reformatting. Try to keep textwidth=72 instead of changes back and forth. > > 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) It can be more clear by replacing this 'if (!dir)' by 'else'. > - dir = xstrdup (initial); > + dir = relocate_path (gdb_program_name, GDB_DATADIR, 1, > + GDB_DATADIR_RELOCATABLE); Why isn't here the original statement? dir = relocate_gdb_directory (GDB_DATADIR, GDB_DATADIR_RELOCATABLE); > + > + /* Otherwise use GDB_DATADIR as is. */ > + if (!dir) > + dir = xstrdup (GDB_DATADIR); This can be moved to the 'else' block suggested above to simplify it. > > /* 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 > {