]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix GDB relocation on MinGW.
authorEli Zaretskii <eliz@gnu.org>
Sat, 6 Apr 2013 06:47:29 +0000 (06:47 +0000)
committerEli Zaretskii <eliz@gnu.org>
Sat, 6 Apr 2013 06:47:29 +0000 (06:47 +0000)
* mingw-hdep.c (windows_get_absolute_argv0): New function.
Include main.h.

* main.h (windows_get_absolute_argv0): Add 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.

gdb/ChangeLog
gdb/main.c
gdb/main.h
gdb/mingw-hdep.c

index 12b238f9820e9f31f8426acaaebdf17be5f6caf1..7a45be0330183f984af72a8beeaf9b869ba57c90 100644 (file)
@@ -1,3 +1,16 @@
+2013-03-23  Eli Zaretskii  <eliz@gnu.org>
+
+       * mingw-hdep.c (windows_get_absolute_argv0): New function.
+       Include main.h.
+
+       * main.h (windows_get_absolute_argv0): Add 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.
+
 2013-04-05  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        Fix compatibility with Linux kernel 3.8.3.
index 06f3febd2903151af6f77fd3515fc1a140dcb705..bcbf33ffd9e8d3c1ac9ebcde1ad2dd7e78952a93 100644 (file)
@@ -43,6 +43,8 @@
 #include "objfiles.h"
 #include "auto-load.h"
 
+#include "filenames.h"
+
 /* 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.  */
@@ -180,15 +182,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);
@@ -377,7 +379,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
@@ -411,7 +419,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
 
@@ -729,7 +737,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 49b64ee2bff0af685288f68bce12d011c1b05645..a5260b16bc6b4ed21092a25509a2310d616ab7f0 100644 (file)
@@ -36,4 +36,10 @@ extern int return_child_result_value;
 extern int batch_silent;
 extern int batch_flag;
 
+/* From mingw-hdep.c, used by main.c.  */
+
+/* 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
index 2613495a637514587fb1e922bcffd3ee939d6daf..efc9848d3a5f689fca5078e7243f28a64381c24a 100644 (file)
@@ -18,6 +18,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "main.h"
 #include "serial.h"
 #include "event-loop.h"
 
@@ -80,6 +81,19 @@ safe_strerror (int errnum)
   return buffer;
 }
 
+/* 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);
+}
+
 /* Wrapper for select.  On Windows systems, where the select interface
    only works for sockets, this uses the GDB serial abstraction to
    handle sockets, consoles, pipes, and serial ports.