[PATCH 2/2] Try to initialize data-directory by first searching for "data-directory" in the same directory as the gdb binary

Khoo Yit Phang
2012-09-19T19:56:01Z

[-- Attachment #1: Type: text/plain, Size: 245 bytes --]

Hi Jan,

Here's the second of the split patch that actually implements the extra search for data-directory in the same directory as the gdb binary. I've dropped the reverting changes to cc-with-tweaks.sh as well.

Yit
September 19, 2012

[-- Attachment #2: gdb-relative-data-directory.txt --]
[-- Type: text/plain, Size: 2166 bytes --]

gdb/ChangeLog

2012-09-19 Khoo Yit Phang <khooyp@cs.umd.edu>

Try to initialize data-directory by first searching for
"data-directory" in the same directory as the gdb binary.
* main.c (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/main.c b/gdb/main.c
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -152,6 +152,49 @@
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 = 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;
+ }
+ }
+
+ return dir;
+}
+
/* Compute the locations of init files that GDB should source and
return them in SYSTEM_GDBINIT, HOME_GDBINIT, LOCAL_GDBINIT. If
there is no system gdbinit (resp. home gdbinit and local gdbinit)
@@ -370,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
{