]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix relocation of directories in the MinGW build.
authorEli Zaretskii <eliz@gnu.org>
Sat, 23 Mar 2013 10:48:23 +0000 (10:48 +0000)
committerEli Zaretskii <eliz@gnu.org>
Sat, 23 Mar 2013 10:48:23 +0000 (10:48 +0000)
 windows-nat.c (windows_get_absolute_argv0): New function.
 windows-nat.h: Add its prototype.
 main.c (get_init_files): Use filename_ncmp instead of strncmp.
 Use IS_DIR_SEPARATOR instead of looking for a character inside
 SLASH_STRING.  Include filenames.h.
 (captured_main) [__MINGW32__]: Make argv[0] absolute, so that
 relocate_gdb_directory works when passed gdb_program_name.
 Include windows-nat.h.

gdb/ChangeLog
gdb/main.c
gdb/windows-nat.c
gdb/windows-nat.h

index b446bd53a04d562e8594e1e26f09082df892216f..15e169ca301e145622c53122600166f73f7a9cb9 100644 (file)
@@ -1,3 +1,15 @@
+2013-03-23  Eli Zaretskii  <eliz@gnu.org>
+
+       * windows-nat.c (windows_get_absolute_argv0): New function.
+       * windows-nat.h: Add its prototype.
+
+       * main.c (get_init_files): Use filename_ncmp instead of strncmp.
+       Use IS_DIR_SEPARATOR instead of looking for a character inside
+       SLASH_STRING.  Include filenames.h.
+       (captured_main) [__MINGW32__]: Make argv[0] absolute, so that
+       relocate_gdb_directory works when passed gdb_program_name.
+       Include windows-nat.h.
+
 2013-03-22  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        * exceptions.h (enum errors): New entry TARGET_CLOSE_ERROR.
index 08a27697745eef72dcf0660b0d6b95d5dec29673..5bbfe833539975ec00df2607cb051a6a116697a7 100644 (file)
 #include "auto-load.h"
 #include "maint.h"
 
+#include "filenames.h"
+#ifdef __MINGW32__
+# include "windows-nat.h"
+#endif
+
 /* The selected interpreter.  This will be used as a set command
    variable, so it should always be malloc'ed - since
    do_setshow_command will free it.  */
@@ -181,15 +186,15 @@ get_init_files (char **system_gdbinit,
             has been provided, search for SYSTEM_GDBINIT there.  */
          if (gdb_datadir_provided
              && datadir_len < sys_gdbinit_len
-             && strncmp (SYSTEM_GDBINIT, GDB_DATADIR, datadir_len) == 0
-             && strchr (SLASH_STRING, SYSTEM_GDBINIT[datadir_len]) != NULL)
+             && filename_ncmp (SYSTEM_GDBINIT, GDB_DATADIR, datadir_len) == 0
+             && IS_DIR_SEPARATOR (SYSTEM_GDBINIT[datadir_len]))
            {
              /* Append the part of SYSTEM_GDBINIT that follows GDB_DATADIR
                 to gdb_datadir.  */
              char *tmp_sys_gdbinit = xstrdup (SYSTEM_GDBINIT + datadir_len);
              char *p;
 
-             for (p = tmp_sys_gdbinit; strchr (SLASH_STRING, *p); ++p)
+             for (p = tmp_sys_gdbinit; IS_DIR_SEPARATOR (*p); ++p)
                continue;
              relocated_sysgdbinit = concat (gdb_datadir, SLASH_STRING, p,
                                             NULL);
@@ -378,7 +383,13 @@ captured_main (void *data)
   gdb_stdtargerr = gdb_stderr; /* for moment */
   gdb_stdtargin = gdb_stdin;   /* for moment */
 
+#ifdef __MINGW32__
+  /* On Windows, argv[0] is not necessarily set to absolute form when
+     GDB is found along PATH, without which relocation doesn't work.  */
+  gdb_program_name = windows_get_absolute_argv0 (argv[0]);
+#else
   gdb_program_name = xstrdup (argv[0]);
+#endif
 
   if (! getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)))
     /* Don't use *_filtered or warning() (which relies on
@@ -412,7 +423,7 @@ captured_main (void *data)
 
 #ifdef RELOC_SRCDIR
   add_substitute_path_rule (RELOC_SRCDIR,
-                           make_relative_prefix (argv[0], BINDIR,
+                           make_relative_prefix (gdb_program_name, BINDIR,
                                                  RELOC_SRCDIR));
 #endif
 
@@ -730,7 +741,7 @@ captured_main (void *data)
 
   /* Initialize all files.  Give the interpreter a chance to take
      control of the console via the deprecated_init_ui_hook ().  */
-  gdb_init (argv[0]);
+  gdb_init (gdb_program_name);
 
   /* Now that gdb_init has created the initial inferior, we're in
      position to set args for that inferior.  */
index f61bb79fcafaec40dd4fe105cebfac9cd294b504..34e3cc04a2b76988c11c7a91697971cb30b3afd3 100644 (file)
@@ -597,6 +597,18 @@ failed:
   return 0;            /* failure */
 }
 
+/* Return an absolute file name of the running GDB, if possible, or
+   ARGV0 if not.  The return value is in malloc'ed storage.  */
+char *
+windows_get_absolute_argv0 (const char *argv0)
+{
+  char full_name[PATH_MAX];
+
+  if (GetModuleFileName (NULL, full_name, PATH_MAX))
+    return xstrdup (full_name);
+  return xstrdup (argv0);
+}
+
 /* Encapsulate the information required in a call to
    symbol_file_add_args.  */
 struct safe_symbol_file_add_args
index 55624eed081e34f2a30e0ce5eb84b8d6fb8e4e15..0691e9ec89659166751a44ebabfd80996e5bb2a4 100644 (file)
@@ -28,5 +28,9 @@ typedef int (segment_register_p_ftype) (int regnum);
    whether a given register is a segment register or not.  */
 extern void windows_set_segment_register_p (segment_register_p_ftype *fun);
 
+/* Return argv[0] in absolute form, if possible, or ARGV0 if not.  The
+   return value is in malloc'ed storage.  */
+extern char *windows_get_absolute_argv0 (const char *argv0);
+
 #endif