Possible fix for mingw32 directory relocation problems

Doug Evans dje@google.com
Wed Jan 18 19:01:00 GMT 2012


On Tue, Jan 17, 2012 at 6:49 AM, Pierre Muller
<pierre.muller@ics-cnrs.unistra.fr> wrote:
>
>
>> -----Message d'origine-----
>> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
>> owner@sourceware.org] De la part de Doug Evans
>> Envoyé : mardi 17 janvier 2012 08:00
>> À : Pierre Muller
>> Cc : gdb-patches@sourceware.org; Eli Zaretskii; asmwarrior@gmail.com; Tom
>> Tromey
>> Objet : Re: Possible fix for mingw32 directory relocation problems
>>
>> On Mon, Jan 16, 2012 at 7:03 AM, Pierre Muller
>> <pierre.muller@ics-cnrs.unistra.fr> wrote:
>> >  After some debugging,
>> > we finally managed to find out that
>> > mingw32 specific directory relocations are related
>> > to msys -> mingw32 argument conversions.
>>
>> Thanks for the detective work!
>
>  I always liked to debug GDB with itself!
>
>> > http://sourceware.org/ml/gdb-patches/2012-01/msg00537.html
>> >
>> > This is explained in:
>> >
>> > http://www.mingw.org/wiki/Posix_path_conversion
>> >
>> > This page also allows to understand why
>> > using mingw32 style paths for prefix at configure
>> > level works and avoid the troubles encountered.
>> >
>> > This conversion concerns defines passed by command line arguments
>> > to gcc, which are specific to main.o
>> > compilation, as found in gdb/Makefile.in
>> > 1520-
>> > 1521:# main.o needs an explicit build rule to get TARGET_SYSTEM_ROOT and
>> > BINDIR.
>> > 1522-main.o: $(srcdir)/main.c
>> > 1523:   $(COMPILE) $(TARGET_SYSTEM_ROOT_DEFINE) -DBINDIR=\"$(bindir)\"
>> > $(srcdir)/main.c
>> > 1524-   $(POSTCOMPILE)
>> > 1525-
>> >
>> >  But this leads to a conversion:
>> >  -DBINDIR="/usr/local/bin\"
>> > gets transformed into '-D' 'BINDIR="E:/msys/mingw32/msys/1.0/local/bin"'
>> >
>> >  While other pates used in relocate_gdb_directory calls
>> > are macros defined inside gdb/config.h
>> >
>> > config.h:#define DEBUGDIR "/usr/local/lib/debug"
>> > config.h:#define GDB_DATADIR "/usr/local/share/gdb"
>> > config.h:#define JIT_READER_DIR "/usr/local/lib/gdb"
>> >
>> > Those are of course not affected by msys command-line argument
> conversion.
>> >
>> >  The first question is:
>> > Why do we need to pass BINDIR (and TARGET_SYSTEM_ROOT_DEFINE)
>> > at the command line instead of inside config.h as for other
>> > directories?
>>
>> We don't need to pass them on the command line.
>>
>> >  If the answer to the first question is "we don't",
>> > then I need help about how to convert those
>> > Makefile.in variables into new entries of generated config.h file.
>>
>> Possible patch is attached.
>> Can you try it?  I don't know that it will fix things, but based on
>> what you've said it seems reasonable to try.
>
>  I tried it...
> But got really into troubles to regenerate configure and config.in using
> Cygwin
> installation...
>  I finally discovered gcc-tools-epoch2 cygwin package
> that allowed me to successfully regenerate configure and config.in
>
>  After that I did recompile and install gdb into e:\pas\fpc-2.7.1 directory
> by specifying --prefix=/e/pas/fpc-2.7.1
> (I tested with --preficx=e:/pas/fpc-2.4.4, which worked the same)
>
> E:\pas\fpc-2.7.1\gdb>cd bin
>
> E:\pas\fpc-2.7.1\gdb\bin>.\gdb ./gdb
> GNU gdb (GDB) 7.4.50.20120117-cvs
> Copyright (C) 2012 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later
> <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
> and "show warranty" for details.
> This GDB was configured as "i686-pc-mingw32".
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>...
> Reading symbols from E:\pas\fpc-2.7.1\gdb\bin\gdb.exe...done.
> (gdb) py print gdb.PYTHONDIR
> e:\pas\fpc-2.7.1\gdb\share\gdb/python
> (gdb) py
>>end
> (gdb) q
>
> E:\pas\fpc-2.7.1\gdb\bin>cd ..\..
>
> E:\pas\fpc-2.7.1>cp -Rf gdb ..\fpc-2.6.0
>
> E:\pas\fpc-2.7.1>cd ..\fpc-2.6.0\gdb\bin
>
> E:\pas\fpc-2.6.0\gdb\bin>.\gdb ./gdb
> GNU gdb (GDB) 7.4.50.20120117-cvs
> Copyright (C) 2012 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later
> <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
> and "show warranty" for details.
> This GDB was configured as "i686-pc-mingw32".
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>...
> Reading symbols from E:\pas\fpc-2.6.0\gdb\bin\gdb.exe...done.
> (gdb) py print gdb.PYTHONDIR
> e:\pas\fpc-2.6.0\gdb\share\gdb/python
> (gdb)
>
> So the basic idea of rebasing gdb/python seems to work,
> the next problem is that I never used python scripts
> so that I didn't know what else to do to check that this directory is really
> functional!

Here is the patch I committed.
Tested on amd64-linux with various values for --with-sysroot.

The test the previous code was using to compute the relocability of
TARGET_SYSTEM_ROOT, is, AFAICT, excessively complex.
main.c treats TARGET_SYSTEM_ROOT no different than other relocatable
dirs, so I went with what GDB_AC_WITH_DIR does.
Alas I can't just use GDB_AC_WITH_DIR as the help output will be
wrong, and I didn't want to add another argument to GDB_AC_WITH_DIR
and update all its callers just for this.  Still, I think this is an
improvement.
Thanks again for the detective work.

2012-01-18  Doug Evans  <dje@sebabeach.org>

        * Makefile.in (TARGET_SYSTEM_ROOT, TARGET_SYSTEM_ROOT_DEFINE): Delete.
        (main.o): Remove rule.
        * configure.ac (BINDIR): Define with AC_DEFINE_DIR.
        (--with-sysroot): Rewrite.
        * configure: Regenerate.
        * config.in: Regenerate.
-------------- next part --------------
2012-01-16  Doug Evans  <dje@sebabeach.org>

	* Makefile.in (TARGET_SYSTEM_ROOT, TARGET_SYSTEM_ROOT_DEFINE): Delete.
	(main.o): Remove rule.
	* configure.ac (BINDIR): Define with AC_DEFINE_DIR.
	(--with-sysroot): Rewrite.
	* configure: Regenerate.
	* config.in: Regenerate.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.1186
diff -u -p -r1.1186 Makefile.in
--- Makefile.in	10 Jan 2012 16:30:43 -0000	1.1186
+++ Makefile.in	18 Jan 2012 18:18:40 -0000
@@ -166,10 +166,6 @@ INTL = @LIBINTL@
 INTL_DEPS = @LIBINTL_DEP@
 INTL_CFLAGS = @INCINTL@
 
-# Did the user give us a --with-sysroot option?
-TARGET_SYSTEM_ROOT = @TARGET_SYSTEM_ROOT@
-TARGET_SYSTEM_ROOT_DEFINE = @TARGET_SYSTEM_ROOT_DEFINE@
-
 # Did the user give us a --with-gdb-datadir option?
 GDB_DATADIR = @GDB_DATADIR@
 
@@ -1518,11 +1514,6 @@ ALLDEPFILES = \
 # Some files need explicit build rules (due to -Werror problems) or due
 # to sub-directory fun 'n' games.
 
-# main.o needs an explicit build rule to get TARGET_SYSTEM_ROOT and BINDIR.
-main.o: $(srcdir)/main.c
-	$(COMPILE) $(TARGET_SYSTEM_ROOT_DEFINE) -DBINDIR=\"$(bindir)\" $(srcdir)/main.c
-	$(POSTCOMPILE)
-
 # FIXME: cagney/2003-08-10: "monitor.c" gets -Wformat-nonliteral
 # errors.  It turns out that that is the least of monitor.c's
 # problems.  The function print_vsprintf appears to be using
Index: config.in
===================================================================
RCS file: /cvs/src/src/gdb/config.in,v
retrieving revision 1.130
diff -u -p -r1.130 config.in
--- config.in	12 Jan 2012 23:38:47 -0000	1.130
+++ config.in	18 Jan 2012 18:18:40 -0000
@@ -7,6 +7,9 @@
 /* Define if building universal (internal helper macro) */
 #undef AC_APPLE_UNIVERSAL_BUILD
 
+/* Directory of programs. */
+#undef BINDIR
+
 /* Define to the number of bits in type 'ptrdiff_t'. */
 #undef BITSIZEOF_PTRDIFF_T
 
@@ -854,6 +857,12 @@
    moved. */
 #undef SYSTEM_GDBINIT_RELOCATABLE
 
+/* search for usr/lib et al within DIR */
+#undef TARGET_SYSTEM_ROOT
+
+/* Define if the sysroot directory should be relocated when GDB is moved. */
+#undef TARGET_SYSTEM_ROOT_RELOCATABLE
+
 /* Define if <thread_db.h> has the TD_NOTALLOC error code. */
 #undef THREAD_DB_HAS_TD_NOTALLOC
 
Index: configure
===================================================================
RCS file: /cvs/src/src/gdb/configure,v
retrieving revision 1.337
diff -u -p -r1.337 configure
--- configure	12 Jan 2012 23:38:47 -0000	1.337
+++ configure	18 Jan 2012 18:18:40 -0000
@@ -654,7 +654,6 @@ SER_HARDWIRE
 WERROR_CFLAGS
 WARN_CFLAGS
 SYSTEM_GDBINIT
-TARGET_SYSTEM_ROOT_DEFINE
 TARGET_SYSTEM_ROOT
 CONFIG_LDFLAGS
 RDYNAMIC
@@ -7900,6 +7899,24 @@ _ACEOF
 
 
 
+# We can't pass paths as command line arguments.
+# Mingw32 tries to be clever and will convert the paths for us.
+# For example -DBINDIR="/usr/local/bin" passed on the command line may get
+# converted to -DBINDIR="E:/msys/mingw32/msys/1.0/local/bin".
+# This breaks GDB's relocatable path conversions since paths passed in
+# config.h would not get so translated, the path prefixes no longer match.
+
+  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
+  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+  ac_define_dir=`eval echo $bindir`
+  ac_define_dir=`eval echo $ac_define_dir`
+
+cat >>confdefs.h <<_ACEOF
+#define BINDIR "$ac_define_dir"
+_ACEOF
+
+
+
 # GDB's datadir relocation
 
 
@@ -15043,45 +15060,53 @@ $as_echo "#define HAVE_PERSONALITY 1" >>
 fi
 
 
-target_sysroot_reloc=0
+# Support for --with-sysroot is a copy of GDB_AC_WITH_DIR,
+# except that the argument to --with-sysroot is optional.
+# --with-sysroot (or --with-sysroot=yes) sets the default sysroot path.
+if test "x$with_sysroot" = xyes; then
+  with_sysroot="${exec_prefix}/${target_alias}/sys-root"
+fi
 
 # Check whether --with-sysroot was given.
 if test "${with_sysroot+set}" = set; then :
-  withval=$with_sysroot;
- case ${with_sysroot} in
- yes) TARGET_SYSTEM_ROOT='${exec_prefix}/${target_alias}/sys-root' ;;
- *) TARGET_SYSTEM_ROOT=$with_sysroot ;;
- esac
+  withval=$with_sysroot; TARGET_SYSTEM_ROOT=$withval
+else
+  TARGET_SYSTEM_ROOT=
+fi
 
- TARGET_SYSTEM_ROOT_DEFINE='-DTARGET_SYSTEM_ROOT=\"$(TARGET_SYSTEM_ROOT)\"'
 
- if test "x$prefix" = xNONE; then
-  test_prefix=/usr/local
- else
-  test_prefix=$prefix
- fi
- if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
-  test_exec_prefix=$test_prefix
- else
-  test_exec_prefix=$exec_prefix
- fi
- case ${TARGET_SYSTEM_ROOT} in
- "${test_prefix}"|"${test_prefix}/"*|\
- "${test_exec_prefix}"|"${test_exec_prefix}/"*|\
- '${prefix}'|'${prefix}/'*|\
- '${exec_prefix}'|'${exec_prefix}/'*)
-   target_sysroot_reloc=1
-   ;;
- esac
+  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
+  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+  ac_define_dir=`eval echo $TARGET_SYSTEM_ROOT`
+  ac_define_dir=`eval echo $ac_define_dir`
 
-else
+cat >>confdefs.h <<_ACEOF
+#define TARGET_SYSTEM_ROOT "$ac_define_dir"
+_ACEOF
 
- TARGET_SYSTEM_ROOT=
- TARGET_SYSTEM_ROOT_DEFINE='-DTARGET_SYSTEM_ROOT=\"\"'
 
-fi
 
-TARGET_SYSTEM_ROOT_DEFINE="$TARGET_SYSTEM_ROOT_DEFINE -DTARGET_SYSTEM_ROOT_RELOCATABLE=$target_sysroot_reloc"
+
+  if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
+     if test "x$prefix" = xNONE; then
+     	test_prefix=/usr/local
+     else
+	test_prefix=$prefix
+     fi
+  else
+     test_prefix=$exec_prefix
+  fi
+  value=0
+  case ${ac_define_dir} in
+     "${test_prefix}"|"${test_prefix}/"*|\
+	'${exec_prefix}'|'${exec_prefix}/'*)
+     value=1
+     ;;
+  esac
+
+cat >>confdefs.h <<_ACEOF
+#define TARGET_SYSTEM_ROOT_RELOCATABLE $value
+_ACEOF
 
 
 
Index: configure.ac
===================================================================
RCS file: /cvs/src/src/gdb/configure.ac,v
retrieving revision 1.152
diff -u -p -r1.152 configure.ac
--- configure.ac	4 Jan 2012 08:17:00 -0000	1.152
+++ configure.ac	18 Jan 2012 18:18:40 -0000
@@ -125,6 +125,14 @@ GDB_AC_WITH_DIR(DEBUGDIR, separate-debug
     [look for global separate debug info in this path @<:@LIBDIR/debug@:>@],
     [${libdir}/debug])
 
+# We can't pass paths as command line arguments.
+# Mingw32 tries to be clever and will convert the paths for us.
+# For example -DBINDIR="/usr/local/bin" passed on the command line may get
+# converted to -DBINDIR="E:/msys/mingw32/msys/1.0/local/bin".
+# This breaks GDB's relocatable path conversions since paths passed in
+# config.h would not get so translated, the path prefixes no longer match.
+AC_DEFINE_DIR(BINDIR, bindir, [Directory of programs.])
+
 # GDB's datadir relocation
 
 GDB_AC_WITH_DIR(GDB_DATADIR, gdb-datadir,
@@ -1753,42 +1761,20 @@ fi
 
 dnl Handle optional features that can be enabled.
 
-target_sysroot_reloc=0
+# Support for --with-sysroot is a copy of GDB_AC_WITH_DIR,
+# except that the argument to --with-sysroot is optional.
+# --with-sysroot (or --with-sysroot=yes) sets the default sysroot path.
+if test "x$with_sysroot" = xyes; then
+  with_sysroot="${exec_prefix}/${target_alias}/sys-root"
+fi
 AC_ARG_WITH(sysroot,
-AS_HELP_STRING([--with-sysroot@<:@=DIR@:>@], [search for usr/lib et al within DIR]),
-[
- case ${with_sysroot} in
- yes) TARGET_SYSTEM_ROOT='${exec_prefix}/${target_alias}/sys-root' ;;
- *) TARGET_SYSTEM_ROOT=$with_sysroot ;;
- esac
-
- TARGET_SYSTEM_ROOT_DEFINE='-DTARGET_SYSTEM_ROOT=\"$(TARGET_SYSTEM_ROOT)\"'
-
- if test "x$prefix" = xNONE; then
-  test_prefix=/usr/local
- else
-  test_prefix=$prefix
- fi
- if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
-  test_exec_prefix=$test_prefix
- else
-  test_exec_prefix=$exec_prefix
- fi
- case ${TARGET_SYSTEM_ROOT} in
- "${test_prefix}"|"${test_prefix}/"*|\
- "${test_exec_prefix}"|"${test_exec_prefix}/"*|\
- '${prefix}'|'${prefix}/'*|\
- '${exec_prefix}'|'${exec_prefix}/'*)
-   target_sysroot_reloc=1
-   ;;
- esac
-], [
- TARGET_SYSTEM_ROOT=
- TARGET_SYSTEM_ROOT_DEFINE='-DTARGET_SYSTEM_ROOT=\"\"'
-])
-TARGET_SYSTEM_ROOT_DEFINE="$TARGET_SYSTEM_ROOT_DEFINE -DTARGET_SYSTEM_ROOT_RELOCATABLE=$target_sysroot_reloc"
+  AS_HELP_STRING([--with-sysroot@<:@=DIR@:>@],
+                 [search for usr/lib et al within DIR]),
+  [TARGET_SYSTEM_ROOT=$withval], [TARGET_SYSTEM_ROOT=])
+AC_DEFINE_DIR(TARGET_SYSTEM_ROOT, TARGET_SYSTEM_ROOT,
+              [search for usr/lib et al within DIR])
 AC_SUBST(TARGET_SYSTEM_ROOT)
-AC_SUBST(TARGET_SYSTEM_ROOT_DEFINE)
+GDB_AC_DEFINE_RELOCATABLE(TARGET_SYSTEM_ROOT, sysroot, ${ac_define_dir})
 
 GDB_AC_WITH_DIR(SYSTEM_GDBINIT, system-gdbinit,
     [automatically load a system-wide gdbinit file],


More information about the Gdb-patches mailing list