+# Parent 99b3052b6ad47045356669b430b8aad3ae978d0a
+Try to initialize data-directory by first searching for "data-directory" in the same directory as the gdb binary.
+diff --git a/gdb/ChangeLog b/gdb/ChangeLog
++2012-09-18 Khoo Yit Phang <firstname.lastname@example.org>
++ Try to initialize data-directory by first searching for
++ "data-directory" in the same directory as the gdb binary.
++ * 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_gdb_data_directory): New function similar to
++ relocate_gdb_directory, but specifically for data-directory.
++ (captured_main): Call relocate_gdb_data_directory to initialize
++ * contrib/cc-with-tweaks.sh (GDB): Revert -data-directory
++ additions that is now unnecessary.
+ 2012-09-18 Joel Brobecker <email@example.com>
+ * linespec.c (iterate_over_all_matching_symtabs): Use the correct
+diff --git a/gdb/contrib/cc-with-tweaks.sh b/gdb/contrib/cc-with-tweaks.sh
+ # 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".
+ # We assume the current directory is either $obj/gdb or $obj/gdb/testsuite.
+- GDB="./gdb -data-directory data-directory"
+- GDB="../gdb -data-directory ../data-directory"
+- GDB="../../gdb -data-directory ../../data-directory"
+ echo "$myname: unable to find usable gdb" >&2
+diff --git a/gdb/main.c b/gdb/main.c
+ 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). 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). 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
+-relocate_path (const char *progname, const char *initial, int flag)
++relocate_path (const char *progname, const char *initial, int isdir,
+- return make_relative_prefix (progname, BINDIR, initial);
++ path = make_relative_prefix (progname, BINDIR, initial);
++ if (stat (path, &s) != 0 || (isdir && !S_ISDIR (s.st_mode)))
+ return xstrdup (initial);
+- dir = relocate_path (gdb_program_name, initial, flag);
++ dir = relocate_path (gdb_program_name, initial, 1, flag);
++ dir = xstrdup (initial);
++ /* Canonicalize the directory. */
++ char *canon_sysroot = lrealpath (dir);
+- if (stat (dir, &s) != 0 || !S_ISDIR (s.st_mode))
++/* Like relocate_gdb_path, but specifically for data-directory. */
++ /* 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);
++ dir = reconcat (dir, dir, SLASH_STRING, "data-directory", NULL);
++ /* Then try to find GDB_DATADIR relocated relative to gdb. */
+- dir = xstrdup (initial);
++ dir = relocate_path (gdb_program_name, GDB_DATADIR, 1,
++ /* Otherwise use GDB_DATADIR as is. */
++ dir = xstrdup (GDB_DATADIR);
+ /* Canonicalize the directory. */
+- struct stat homebuf, cwdbuf, s;
++ struct stat homebuf, cwdbuf;
+ char *homedir, *relocated_sysgdbinit;
+ relocated_sysgdbinit = relocate_path (gdb_program_name,
+- if (relocated_sysgdbinit && stat (relocated_sysgdbinit, &s) == 0)
++ if (relocated_sysgdbinit)
+ sysgdbinit = relocated_sysgdbinit;
+ xfree (relocated_sysgdbinit);
+ debug_file_directory = relocate_gdb_directory (DEBUGDIR,
+- gdb_datadir = relocate_gdb_directory (GDB_DATADIR,
++ gdb_datadir = relocate_gdb_data_directory ();
+ #ifdef WITH_PYTHON_PATH