From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10660 invoked by alias); 21 Sep 2012 18:31:41 -0000 Received: (qmail 10648 invoked by uid 22791); 21 Sep 2012 18:31:40 -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 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; Fri, 21 Sep 2012 18:31:27 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8LIVQEo000584 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 21 Sep 2012 14:31:27 -0400 Received: from host2.jankratochvil.net (ovpn-113-58.phx2.redhat.com [10.3.113.58]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8LIVMIb032646 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 21 Sep 2012 14:31:25 -0400 Date: Fri, 21 Sep 2012 18:31:00 -0000 From: Jan Kratochvil To: Khoo Yit Phang Cc: GDB Patches Subject: Re: [PATCH 2/2] Try to initialize data-directory by first searching for "data-directory" in the same directory as the gdb binary Message-ID: <20120921183122.GB8747@host2.jankratochvil.net> References: <21ACC598-F6B4-4117-BA7B-B316414DE9E3@cs.umd.edu> <20120919130040.GA20442@host2.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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/msg00447.txt.bz2 On Wed, 19 Sep 2012 21:55:28 +0200, Khoo Yit Phang wrote: > + /* Then try to find GDB_DATADIR relocated relative to gdb. */ > + if (!dir) > + 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) > + { > + char *canon_sysroot = lrealpath (dir); > + > + if (canon_sysroot) > + { > + xfree (dir); > + dir = canon_sysroot; > + } > + } I am not happy from the code duplication with existing function: char * relocate_gdb_directory (const char *initial, int flag) { char *dir; dir = relocate_path (gdb_program_name, initial, 1, flag); if (!dir) dir = xstrdup (initial); /* Canonicalize the directory. */ if (*dir) { char *canon_sysroot = lrealpath (dir); if (canon_sysroot) { xfree (dir); dir = canon_sysroot; } } return dir; } Also it could check for /usr/gdb/data-directory which is less likely to be present than /usr/bin/data-directory . Proposing the patch below instead, although I do not like it much either. Thanks, Jan gdb/ 2012-09-21 Jan Kratochvil * main.c: New variables dir and datadir. Change GDB_DATADIR initialization to attempt to find gdb/data-directory/ first. diff --git a/gdb/main.c b/gdb/main.c index bde37f9..635c86b 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -314,6 +314,7 @@ captured_main (void *data) int i; int save_auto_load; struct objfile *objfile; + char *dir, *datadir; struct cleanup *pre_stat_chain; @@ -370,8 +371,23 @@ captured_main (void *data) debug_file_directory = relocate_gdb_directory (DEBUGDIR, DEBUGDIR_RELOCATABLE); - gdb_datadir = relocate_gdb_directory (GDB_DATADIR, - GDB_DATADIR_RELOCATABLE); + /* Attempt first to find gdb/data-directory/ if we are run still from the + build directory. */ + datadir = ldirname (BINDIR); + datadir = reconcat (datadir, datadir, + SLASH_STRING "gdb" SLASH_STRING "data-directory", NULL); + dir = relocate_path (gdb_program_name, datadir, 1, 1); + xfree (datadir); + if (dir) + { + /* DATADIR could never have less components than BINDIR, therefore + we do not need to check it DIR is not "" like + relocate_gdb_directory has to. */ + gdb_datadir = lrealpath (dir); + xfree (dir); + } + if (gdb_datadir == NULL) + gdb_datadir = relocate_gdb_directory (GDB_DATADIR, GDB_DATADIR_RELOCATABLE); #ifdef WITH_PYTHON_PATH {