From: Eli Zaretskii Date: Sat, 6 Apr 2013 06:47:29 +0000 (+0000) Subject: Fix GDB relocation on MinGW. X-Git-Tag: gdb_7_6-2013-04-26-release~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62257b76e8f10a4a5e56fc8dcbc7a8c1446f62cf;p=thirdparty%2Fbinutils-gdb.git Fix GDB relocation on MinGW. * 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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 12b238f9820..7a45be03301 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,16 @@ +2013-03-23 Eli Zaretskii + + * 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 Fix compatibility with Linux kernel 3.8.3. diff --git a/gdb/main.c b/gdb/main.c index 06f3febd290..bcbf33ffd9e 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -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. */ diff --git a/gdb/main.h b/gdb/main.h index 49b64ee2bff..a5260b16bc6 100644 --- a/gdb/main.h +++ b/gdb/main.h @@ -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 diff --git a/gdb/mingw-hdep.c b/gdb/mingw-hdep.c index 2613495a637..efc9848d3a5 100644 --- a/gdb/mingw-hdep.c +++ b/gdb/mingw-hdep.c @@ -18,6 +18,7 @@ along with this program. If not, see . */ #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.