* [gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts)
@ 2010-04-22 17:24 Pedro Alves
2010-04-22 17:46 ` Daniel Jacobowitz
2010-04-23 8:54 ` Eli Zaretskii
0 siblings, 2 replies; 11+ messages in thread
From: Pedro Alves @ 2010-04-22 17:24 UTC (permalink / raw)
To: gdb-patches, gcc-patches
Hi,
libiberty maintainers, this is a GDB patch that includes
src/include/ and src/libiberty/ changes to back it up. I'm
cross-posting the patch so you can see the intent of the change,
in case that's helpful, and in case you have a different
implementation strategy suggestion for the libiberty side.
(Though I hope I got it right the first time. :-) )
Are the liberty changes okay? Let me know if you'd prefer
I'd post them isolated.
Currently, with GDB, if you try to cross debug a target
with DOS-like file system semantics (paths that look
like c:\sys\bin\foo.dll), such as Windows or Symbian OS, with a
Unix GDB, you'll stumble on the fact that you won't be able to
point GDB at the host copies of the target's shared libraries
with either "set sysroot" (for absolute paths), or "set
solib-search path" (for relative paths). The problem is that GDB
mixes up host path handling with target path handling --- on a
Unix GDB build, IS_ABSOLUTE_PATH returns false for "c:\sys\bin\foo.dll",
and IS_DIRECTORY_SEPARATOR also doesn't understand `\' as valid
directory separator. As such, a Unix-ish GDB build
understands "c:\sys\bin\foo.dll" as a single filename, with no
directory components.
The fix is to teach GDB about the distintion between host
paths and target paths, and make the target file system
"kind" selectable at run time. See the new target_lbasename,
IS_TARGET_DIR_SEPARATOR, IS_TARGET_ABSOLUTE_PATH,
HAS_TARGET_DRIVE_SPEC in the patch (gdb side).
For that, the patch introduces a new set/show command pair
so the user can tweak the target's file system flavour, in
case GDB gets it wrong:
(gdb) help set target-file-system-kind
Set assumed file system kind for target reported paths
If `unix', target paths (e.g., loaded shared library filenames)
starting the forward slash (`/') character are considered absolute,
and the directory separator character is the forward slash (`/').
If `dos-based', target paths starting with a drive name (e.g.,
`c:'), are also considered absolute, and the backslash (`\') is
also considered a directory separator. Set to `auto' (which is the
default), to let GDB decide, based on its knowledge of the target
operating system.
(Maybe someday this will be extended to other flavours
like handling a remote VMS file system.)
Note that this includes an "auto" setting. Currently, "auto"
checks the target gdbarch for what file system flavour does
the target OS use. At some point, it may also be useful to
add a new RSP qSupported packet to override GDB's internal
OS knowlege, and for embedded targets where GDB uses a
generic/unknown OSABI.
(At some point, this patch also included a new user knob
to make source file name comparision flavour (and
mostly s/FILENAME_CMP/source_filename_cmp/,
s/lbasename/source_lbasename throught the sources/debug info
handling parts of GDB.) depend on build file system. That's because
often you stumble on the fact that cross debugging a Windows/SymbianOS
binary _built_ on non-Unix, includes `\' in debug info, and a Unix
GDB can't grok that. I mention this, in case someone would
suggest this new setting should be more general and cover that
case as well. It shouldn't: the concepts are different --- target
paths, vs source/debug info/build paths, and you'll want to be
able to tweak them independently.)
On the libiberty side, the patch exposes IS_DIR_SEPARATOR,
IS_DIR_SEPARATOR, HAS_DRIVE_SPEC, IS_ABSOLUTE_PATH, variants
with an extra parameter to select DOS-based filesystem or not,
and always exposes both DOS-based and non DOS-based lbasename
variants. There should be no change in behaviour for the regular
IS_DIR_SEPARATOR, IS_DIR_SEPARATOR, HAS_DRIVE_SPEC, IS_ABSOLUTE_PATH
and lbasename: these still depend on host semantics. The Makefile.in
hunk simply fixes lbasename.o's dependencies: lbasename.c is already
including filenames.h.
GDB documentation changes and NEWS entry included. Are those
okay?
In addition of confirming that it's now possible to cross debug
SymbianOS shared libraries, tested on x86_64-linux with GDB's
testsuite.
--
Pedro Alves
2010-04-22 Pedro Alves <pedro@codesourcery.com>
include/
* filenames.h (IS_DIR_SEPARATOR_1): Rename from IS_DIR_SEPARATOR
and add add `dos_based' parameter.
(HAS_DRIVE_SPEC_1): Rename from HAS_DRIVE_SPEC and add `dos_based'
parameter.
(IS_ABSOLUTE_PATH_1): Rename from IS_ABSOLUTE_PATH. Add
`dos_based' parameter, and handle it.
(IS_DOS_DIR_SEPARATOR, IS_DOS_ABSOLUTE_PATH,
IS_UNIX_DIR_SEPARATOR, IS_UNIX_ABSOLUTE_PATH): New.
(HAS_DRIVE_SPEC): Reimplement on top of HAS_DRIVE_SPEC_1.
(IS_DIR_SEPARATOR): Reimplement on top of IS_DIR_SEPARATOR_1.
(IS_ABSOLUTE_PATH): Reimplement on top of IS_ABSOLUTE_PATH_1.
* libiberty.h (dos_lbasename, unix_lbasename): Declare.
libiberty/
* lbasename.c (lbasename): Split into ...
(unix_lbasename, dos_basename): ... these.
(lbasename): ... and reimplement on top of them.
* Makefile.in (lbasename.o): Depends on $(INCDIR)/filenames.h.
gdb/
* defs.h: Adjust comment.
* solib.c (target_file_system_kind_auto)
(target_file_system_kind_unix, target_file_system_kind_dos_based)
(target_file_system_kinds, target_file_system_kind): New.
(effective_target_file_system_kind): New.
(show_target_file_system_kind_command): New.
(target_lbasename): New.
(IS_TARGET_DIR_SEPARATOR, IS_TARGET_ABSOLUTE_PATH)
(HAS_TARGET_DRIVE_SPEC): New.
(DOS_BASED_FILE_SYSTEM): New.
(solib_find): Handle DOS-based filesystems. Distinguish target
and host paths.
(_initialize_solib): New `set/show target-file-system-kind'
commands.
* arm-symbian-tdep.c (arm_symbian_init_abi): Set
has_dos_based_file_system on the gdbarch.
* arm-wince-tdep.c (arm_wince_init_abi): Ditto.
* i386-cygwin-tdep.c (i386_cygwin_init_abi): Ditto.
* gdbarch.sh (has_dos_based_file_system): New.
* gdbarch.h, gdbarch.c: Regenerate.
* NEWS: Mention improved support for remote targets with DOS-based
filesystems. Mention new `set/show target-file-system-kind'
commands.
gdb/doc/
* gdb.texinfo (Commands to specify files): Describe what how GDB
looks up DOS-based filesystem paths on the system root. Document
the new `set/show target-file-system-kind' commands.
---
gdb/NEWS | 15 +++
gdb/arm-symbian-tdep.c | 4
gdb/arm-wince-tdep.c | 4
gdb/defs.h | 6 -
gdb/doc/gdb.texinfo | 79 ++++++++++++++++
gdb/gdbarch.c | 23 ++++
gdb/gdbarch.h | 7 +
gdb/gdbarch.sh | 5 +
gdb/i386-cygwin-tdep.c | 4
gdb/solib.c | 239 +++++++++++++++++++++++++++++++++++++++++++------
include/filenames.h | 47 +++++----
include/libiberty.h | 11 ++
libiberty/Makefile.in | 2
libiberty/lbasename.c | 28 ++++-
14 files changed, 419 insertions(+), 55 deletions(-)
Index: src/include/filenames.h
===================================================================
--- src.orig/include/filenames.h 2010-04-22 17:19:42.000000000 +0100
+++ src/include/filenames.h 2010-04-22 17:22:34.000000000 +0100
@@ -31,34 +31,45 @@ extern "C" {
#endif
#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__)
-
-#ifndef HAVE_DOS_BASED_FILE_SYSTEM
-#define HAVE_DOS_BASED_FILE_SYSTEM 1
+# ifndef HAVE_DOS_BASED_FILE_SYSTEM
+# define HAVE_DOS_BASED_FILE_SYSTEM 1
+# endif
+# define PATH_SEPARATOR ';'
+# define HAS_DRIVE_SPEC(f) HAS_DRIVE_SPEC_1 (1, f)
+# define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c)
+# define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f)
+#else /* not DOSish */
+# define PATH_SEPARATOR ':'
+# define HAS_DRIVE_SPEC(f) (0)
+# define IS_DIR_SEPARATOR(c) IS_UNIX_DIR_SEPARATOR (c)
+# define IS_ABSOLUTE_PATH(f) IS_UNIX_ABSOLUTE_PATH (f)
#endif
-#define IS_DIR_SEPARATOR(c) ((c) == '/' || (c) == '\\')
+#define IS_DIR_SEPARATOR_1(dos_based, c) \
+ (((c) == '/') \
+ || (((c) == '\\') && (dos_based)))
-#define HAS_DRIVE_SPEC(f) (((f)[0]) && ((f)[1] == ':'))
+#define HAS_DRIVE_SPEC_1(dos_based, f) \
+ ((f)[0] && ((f)[1] == ':') && (dos_based))
/* Remove the drive spec from F, assuming HAS_DRIVE_SPEC (f).
The result is a pointer to the remainder of F. */
#define STRIP_DRIVE_SPEC(f) ((f) + 2)
-/* Note that IS_ABSOLUTE_PATH accepts d:foo as well, although it is
- only semi-absolute. This is because the users of IS_ABSOLUTE_PATH
- want to know whether to prepend the current working directory to
- a file name, which should not be done with a name like d:foo. */
-#define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]) || HAS_DRIVE_SPEC(f))
-
-#else /* not DOSish */
-
-#define IS_DIR_SEPARATOR(c) ((c) == '/')
-#define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]))
+#define IS_DOS_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (1, c)
+#define IS_DOS_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (1, f)
-#define HAS_DRIVE_SPEC(f) (0)
-#define STRIP_DRIVE_SPEC(f) (f)
+#define IS_UNIX_DIR_SEPARATOR(c) IS_DIR_SEPARATOR_1 (0, c)
+#define IS_UNIX_ABSOLUTE_PATH(f) IS_ABSOLUTE_PATH_1 (0, f)
-#endif /* not DOSish */
+/* Note that when DOS_BASED is true, IS_ABSOLUTE_PATH accepts d:foo as
+ well, although it is only semi-absolute. This is because the users
+ of IS_ABSOLUTE_PATH want to know whether to prepend the current
+ working directory to a file name, which should not be done with a
+ name like d:foo. */
+#define IS_ABSOLUTE_PATH_1(dos_based, f) \
+ (IS_DIR_SEPARATOR_1 (dos_based, (f)[0]) \
+ || HAS_DRIVE_SPEC_1 (dos_based, f))
extern int filename_cmp (const char *s1, const char *s2);
#define FILENAME_CMP(s1, s2) filename_cmp(s1, s2)
Index: src/include/libiberty.h
===================================================================
--- src.orig/include/libiberty.h 2010-04-22 17:19:42.000000000 +0100
+++ src/include/libiberty.h 2010-04-22 17:22:34.000000000 +0100
@@ -116,6 +116,17 @@ extern char *basename (const char *);
extern const char *lbasename (const char *);
+/* Same, but assumes DOS semantics (drive name, backslash is also a
+ dir separator) regardless of host. */
+
+extern const char *dos_lbasename (const char *);
+
+/* Same, but assumes Unix semantics (absolute paths always start with
+ a slash, only forward slash is accepted as dir separator)
+ regardless of host. */
+
+extern const char *unix_lbasename (const char *);
+
/* A well-defined realpath () that is always compiled in. */
extern char *lrealpath (const char *);
Index: src/libiberty/lbasename.c
===================================================================
--- src.orig/libiberty/lbasename.c 2010-04-22 17:19:42.000000000 +0100
+++ src/libiberty/lbasename.c 2010-04-22 17:22:34.000000000 +0100
@@ -46,19 +46,39 @@ and a path ending in @code{/} returns th
#include "filenames.h"
const char *
-lbasename (const char *name)
+unix_lbasename (const char *name)
+{
+ const char *base;
+
+ for (base = name; *name; name++)
+ if (IS_UNIX_DIR_SEPARATOR (*name))
+ base = name + 1;
+
+ return base;
+}
+
+const char *
+dos_lbasename (const char *name)
{
const char *base;
-#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
/* Skip over a possible disk name. */
if (ISALPHA (name[0]) && name[1] == ':')
name += 2;
-#endif
for (base = name; *name; name++)
- if (IS_DIR_SEPARATOR (*name))
+ if (IS_DOS_DIR_SEPARATOR (*name))
base = name + 1;
return base;
}
+
+const char *
+lbasename (const char *name)
+{
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+ return dos_lbasename (name);
+#else
+ return unix_lbasename (name);
+#endif
+}
Index: src/libiberty/Makefile.in
===================================================================
--- src.orig/libiberty/Makefile.in 2010-04-22 17:19:42.000000000 +0100
+++ src/libiberty/Makefile.in 2010-04-22 17:22:34.000000000 +0100
@@ -724,7 +724,7 @@ $(CONFIGURED_OFILES): stamp-picdir
./lbasename.o: $(srcdir)/lbasename.c config.h $(INCDIR)/ansidecl.h \
$(INCDIR)/filenames.h $(INCDIR)/libiberty.h \
- $(INCDIR)/safe-ctype.h
+ $(INCDIR)/safe-ctype.h $(INCDIR)/filenames.h
if [ x"$(PICFLAG)" != x ]; then \
$(COMPILE.c) $(PICFLAG) $(srcdir)/lbasename.c -o pic/$@; \
else true; fi
Index: src/gdb/defs.h
===================================================================
--- src.orig/gdb/defs.h 2010-04-22 17:19:42.000000000 +0100
+++ src/gdb/defs.h 2010-04-22 17:22:34.000000000 +0100
@@ -1155,9 +1155,9 @@ extern int (*deprecated_ui_load_progress
extern int use_windows;
-/* Symbolic definitions of filename-related things. */
-/* FIXME, this doesn't work very well if host and executable
- filesystems conventions are different. */
+/* Definitions of filename-related things. */
+
+/* Host specific things. */
#ifdef __MSDOS__
# define CANT_FORK
Index: src/gdb/solib.c
===================================================================
--- src.orig/gdb/solib.c 2010-04-22 17:19:42.000000000 +0100
+++ src/gdb/solib.c 2010-04-22 17:22:34.000000000 +0100
@@ -104,6 +104,76 @@ The search path for loading non-absolute
value);
}
+/* Handle DOS-like target reported paths, that is for example, DLL
+ paths like c:\sys\bin\foo.dll (drive name, backslash as dir
+ separator), even if GDB itself is not running on such a system. */
+
+static const char target_file_system_kind_auto[] = "auto";
+static const char target_file_system_kind_unix[] = "unix";
+static const char target_file_system_kind_dos_based[] = "dos-based";
+static const char *target_file_system_kinds[] =
+{
+ target_file_system_kind_auto,
+ target_file_system_kind_unix,
+ target_file_system_kind_dos_based
+};
+static const char *target_file_system_kind = target_file_system_kind_auto;
+
+static const char *
+effective_target_file_system_kind (void)
+{
+ if (target_file_system_kind == target_file_system_kind_auto)
+ {
+ if (gdbarch_has_dos_based_file_system (target_gdbarch))
+ return target_file_system_kind_dos_based;
+ else
+ return target_file_system_kind_unix;
+ }
+ else
+ return target_file_system_kind;
+}
+
+static void
+show_target_file_system_kind_command (struct ui_file *file,
+ int from_tty,
+ struct cmd_list_element *c,
+ const char *value)
+{
+ if (target_file_system_kind == target_file_system_kind_auto)
+ fprintf_filtered (file, _("\
+The target file system kind is \"%s\" (currently \"%s\").\n"),
+ value,
+ effective_target_file_system_kind ());
+ else
+ fprintf_filtered (file, _("The target file system kind is \"%s\".\n"),
+ value);
+}
+
+static const char *
+target_lbasename (const char *kind, const char *name)
+{
+ if (kind == target_file_system_kind_dos_based)
+ return dos_lbasename (name);
+ else
+ return unix_lbasename (name);
+}
+
+#define IS_TARGET_DIR_SEPARATOR(kind, c) \
+ IS_DIR_SEPARATOR_1 ((kind) == target_file_system_kind_dos_based, c)
+
+#define IS_TARGET_ABSOLUTE_PATH(kind, f) \
+ IS_ABSOLUTE_PATH_1 ((kind) == target_file_system_kind_dos_based, f)
+
+#define HAS_TARGET_DRIVE_SPEC(kind, f) \
+ HAS_DRIVE_SPEC_1 ((kind) == target_file_system_kind_dos_based, f)
+
+/* Same as HAVE_DOS_BASED_FILE_SYSTEM, but useable as an rvalue. */
+#if (HAVE_DOS_BASED_FILE_SYSTEM)
+# define DOS_BASED_FILE_SYSTEM 1
+#else
+# define DOS_BASED_FILE_SYSTEM 0
+#endif
+
/*
GLOBAL FUNCTION
@@ -133,7 +203,7 @@ The search path for loading non-absolute
* If gdb_sysroot is NOT set, perform the following two searches:
* Look in inferior's $PATH.
* Look in inferior's $LD_LIBRARY_PATH.
- *
+ *
* The last check avoids doing this search when targetting remote
* machines since gdb_sysroot will almost always be set.
@@ -152,6 +222,9 @@ solib_find (char *in_pathname, int *fd)
int gdb_sysroot_is_empty;
const char *solib_symbols_extension
= gdbarch_solib_symbols_extension (target_gdbarch);
+ const char *fskind = effective_target_file_system_kind ();
+ struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
+ char *sysroot = NULL;
/* If solib_symbols_extension is set, replace the file's
extension. */
@@ -177,9 +250,7 @@ solib_find (char *in_pathname, int *fd)
gdb_sysroot_is_empty = (gdb_sysroot == NULL || *gdb_sysroot == 0);
- if (! IS_ABSOLUTE_PATH (in_pathname) || gdb_sysroot_is_empty)
- temp_pathname = in_pathname;
- else
+ if (!gdb_sysroot_is_empty)
{
int prefix_len = strlen (gdb_sysroot);
@@ -188,61 +259,152 @@ solib_find (char *in_pathname, int *fd)
&& IS_DIR_SEPARATOR (gdb_sysroot[prefix_len - 1]))
prefix_len--;
+ sysroot = savestring (gdb_sysroot, prefix_len);
+ make_cleanup (xfree, sysroot);
+ }
+
+ /* If we're on a non-DOS-based system, backslashes won't be
+ understood as directory separator, so, convert them to forward
+ slashes, iff we're supposed to handle DOS-based file system
+ semantics for target paths. */
+ if (!DOS_BASED_FILE_SYSTEM && fskind == target_file_system_kind_dos_based)
+ {
+ char *p;
+
+ /* Avoid clobbering our input. */
+ p = alloca (strlen (in_pathname) + 1);
+ strcpy (p, in_pathname);
+ in_pathname = p;
+
+ for (; *p; p++)
+ {
+ if (*p == '\\')
+ *p = '/';
+ }
+ }
+
+ /* Note, we're interested in IS_TARGET_ABSOLUTE_PATH, not
+ IS_ABSOLUTE_PATH. The latter is for host paths only, while
+ IN_PATHNAME is a target path. For example, if we're supposed to
+ be handling DOS-like semantics (which we do by default) we want
+ to consider a 'c:/foo/bar.dll' path as an absolute path, even on
+ a Unix box. With such a path, before giving up on the sysroot,
+ (on Unix x Windows) we'll try:
+
+ 1st attempt, c:/foo/bar.dll ==> /sysroot/c:/foo/bar.dll
+ 2nd attempt, c:/foo/bar.dll ==> /sysroot/c/foo/bar.dll
+ 3rd attempt, c:/foo/bar.dll ==> /sysroot/foo/bar.dll
+ */
+
+ if (!IS_TARGET_ABSOLUTE_PATH (fskind, in_pathname) || gdb_sysroot_is_empty)
+ temp_pathname = xstrdup (in_pathname);
+ else
+ {
+ int need_dir_separator;
+
+ need_dir_separator = !IS_DIR_SEPARATOR (in_pathname[0]);
+
/* Cat the prefixed pathname together. */
- temp_pathname = alloca (prefix_len + strlen (in_pathname) + 1);
- strncpy (temp_pathname, gdb_sysroot, prefix_len);
- temp_pathname[prefix_len] = '\0';
- strcat (temp_pathname, in_pathname);
+ temp_pathname = concat (sysroot,
+ need_dir_separator ? SLASH_STRING : "",
+ in_pathname, (char *) NULL);
}
/* Handle remote files. */
if (remote_filename_p (temp_pathname))
{
*fd = -1;
- return xstrdup (temp_pathname);
+ return temp_pathname;
}
/* Now see if we can open it. */
found_file = open (temp_pathname, O_RDONLY | O_BINARY, 0);
+ if (found_file < 0)
+ xfree (temp_pathname);
- /* We try to find the library in various ways. After each attempt
- (except for the one above), either found_file >= 0 and
- temp_pathname is a malloc'd string, or found_file < 0 and
- temp_pathname does not point to storage that needs to be
- freed. */
-
- if (found_file < 0)
- temp_pathname = NULL;
- else
- temp_pathname = xstrdup (temp_pathname);
+ /* If the search in gdb_sysroot failed, and the path name has a
+ drive spec (e.g, c:/foo), try stripping ':' from the drive spec,
+ and retrying in the sysroot:
+ c:/foo/bar.dll ==> /sysroot/c/foo/bar.dll. */
+ if (found_file < 0
+ && !gdb_sysroot_is_empty
+ && HAS_TARGET_DRIVE_SPEC (fskind, in_pathname))
+ {
+ int need_dir_separator = !IS_DIR_SEPARATOR (in_pathname[2]);
+ char *drive = savestring (in_pathname, 1);
+
+ temp_pathname = concat (sysroot,
+ SLASH_STRING,
+ drive,
+ need_dir_separator ? SLASH_STRING : "",
+ in_pathname + 2, (char *) NULL);
+ xfree (drive);
+
+ found_file = open (temp_pathname, O_RDONLY | O_BINARY, 0);
+ if (found_file < 0)
+ {
+ char *p;
+
+ xfree (temp_pathname);
+
+ /* If the search in gdb_sysroot still failed, try fully
+ stripping the drive spec, and trying once more in the
+ sysroot before giving up.
+
+ c:/foo/bar.dll ==> /sysroot/foo/bar.dll. */
+
+ temp_pathname = concat (sysroot,
+ need_dir_separator ? SLASH_STRING : "",
+ in_pathname + 2, (char *) NULL);
+
+ found_file = open (temp_pathname, O_RDONLY | O_BINARY, 0);
+ if (found_file < 0)
+ xfree (temp_pathname);
+ }
+ }
+
+ do_cleanups (old_chain);
+
+ /* We try to find the library in various ways. After each attempt,
+ either found_file >= 0 and temp_pathname is a malloc'd string, or
+ found_file < 0 and temp_pathname does not point to storage that
+ needs to be freed. */
+
+ if (found_file < 0)
+ temp_pathname = NULL;
+
+ /* If not found, search the solib_search_path (if any). */
+ if (found_file < 0 && solib_search_path != NULL)
+ found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
+ in_pathname, O_RDONLY | O_BINARY, &temp_pathname);
/* If the search in gdb_sysroot failed, and the path name is
absolute at this point, make it relative. (openp will try and open the
file according to its absolute path otherwise, which is not what we want.)
Affects subsequent searches for this solib. */
- if (found_file < 0 && IS_ABSOLUTE_PATH (in_pathname))
+ if (found_file < 0 && IS_TARGET_ABSOLUTE_PATH (fskind, in_pathname))
{
/* First, get rid of any drive letters etc. */
- while (!IS_DIR_SEPARATOR (*in_pathname))
- in_pathname++;
+ while (!IS_TARGET_DIR_SEPARATOR (fskind, *in_pathname))
+ in_pathname++;
/* Next, get rid of all leading dir separators. */
- while (IS_DIR_SEPARATOR (*in_pathname))
- in_pathname++;
+ while (IS_TARGET_DIR_SEPARATOR (fskind, *in_pathname))
+ in_pathname++;
}
-
+
/* If not found, search the solib_search_path (if any). */
if (found_file < 0 && solib_search_path != NULL)
found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
in_pathname, O_RDONLY | O_BINARY, &temp_pathname);
-
+
/* If not found, next search the solib_search_path (if any) for the basename
only (ignoring the path). This is to allow reading solibs from a path
that differs from the opened path. */
if (found_file < 0 && solib_search_path != NULL)
found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
- lbasename (in_pathname), O_RDONLY | O_BINARY,
- &temp_pathname);
+ target_lbasename (fskind, in_pathname),
+ O_RDONLY | O_BINARY, &temp_pathname);
/* If not found, try to use target supplied solib search method */
if (found_file < 0 && ops->find_and_open_solib)
@@ -256,7 +418,7 @@ solib_find (char *in_pathname, int *fd)
OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY,
&temp_pathname);
- /* If not found, next search the inferior's $LD_LIBRARY_PATH
+ /* If not found, next search the inferior's $LD_LIBRARY_PATH
environment variable. */
if (found_file < 0 && gdb_sysroot_is_empty)
found_file = openp (get_in_environ (current_inferior ()->environment,
@@ -1401,4 +1563,23 @@ This takes precedence over the environme
reload_shared_libraries,
show_solib_search_path,
&setlist, &showlist);
+
+ add_setshow_enum_cmd ("target-file-system-kind",
+ class_support,
+ target_file_system_kinds,
+ &target_file_system_kind, _("\
+Set assumed file system kind for target reported paths"), _("\
+Show assumed file system kind for target reported paths"),
+ _("\
+If `unix', target paths (e.g., loaded shared library filenames) \n\
+starting the forward slash (`/') character are considered absolute, \n\
+and the directory separator character is the forward slash (`/').\n\
+If `dos-based', target paths starting with a drive name (e.g., \n\
+`c:'), are also considered absolute, and the backslash (`\\') is \n\
+also considered a directory separator. Set to `auto' (which is the \n\
+default), to let GDB decide, based on its knowledge of the target \n\
+operating system."),
+ NULL, /* setfunc */
+ show_target_file_system_kind_command,
+ &setlist, &showlist);
}
Index: src/gdb/arm-symbian-tdep.c
===================================================================
--- src.orig/gdb/arm-symbian-tdep.c 2010-04-22 17:19:42.000000000 +0100
+++ src/gdb/arm-symbian-tdep.c 2010-04-22 17:22:34.000000000 +0100
@@ -78,6 +78,10 @@ arm_symbian_init_abi (struct gdbarch_inf
corresponding ELF files on the host's filesystem. */
set_gdbarch_solib_symbols_extension (gdbarch, "sym");
+ /* Canonical paths on this target look like `c:\sys\bin\bar.dll',
+ for example. */
+ set_gdbarch_has_dos_based_file_system (gdbarch, 1);
+
set_solib_ops (gdbarch, &solib_target_so_ops);
}
Index: src/gdb/arm-wince-tdep.c
===================================================================
--- src.orig/gdb/arm-wince-tdep.c 2010-04-22 17:19:42.000000000 +0100
+++ src/gdb/arm-wince-tdep.c 2010-04-22 17:22:34.000000000 +0100
@@ -139,6 +139,10 @@ arm_wince_init_abi (struct gdbarch_info
/* Skip call to __gccmain that gcc places in main. */
set_gdbarch_skip_main_prologue (gdbarch, arm_wince_skip_main_prologue);
+
+ /* Canonical paths on this target look like `\Windows\coredll.dll',
+ for example. */
+ set_gdbarch_has_dos_based_file_system (gdbarch, 1);
}
static enum gdb_osabi
Index: src/gdb/i386-cygwin-tdep.c
===================================================================
--- src.orig/gdb/i386-cygwin-tdep.c 2010-04-22 17:19:42.000000000 +0100
+++ src/gdb/i386-cygwin-tdep.c 2010-04-22 17:22:34.000000000 +0100
@@ -235,6 +235,10 @@ i386_cygwin_init_abi (struct gdbarch_inf
(gdbarch, windows_core_xfer_shared_libraries);
set_gdbarch_auto_wide_charset (gdbarch, i386_cygwin_auto_wide_charset);
+
+ /* Canonical paths on this target look like `c:\Program Files\Foo App\mydso.dll',
+ for example. */
+ set_gdbarch_has_dos_based_file_system (gdbarch, 1);
}
static enum gdb_osabi
Index: src/gdb/gdbarch.sh
===================================================================
--- src.orig/gdb/gdbarch.sh 2010-04-22 17:19:42.000000000 +0100
+++ src/gdb/gdbarch.sh 2010-04-22 17:22:34.000000000 +0100
@@ -782,6 +782,11 @@ f:const char *:auto_wide_charset:void::d
# where the names of the files run on the target differ in extension
# compared to the names of the files GDB should load for debug info.
v:const char *:solib_symbols_extension:::::::pstring (gdbarch->solib_symbols_extension)
+
+# If true the target OS has DOS-based file system semantics. That is,
+# absolute paths include a drive name, and the backslash is considered
+# a path separator.
+v:int:has_dos_based_file_system:::0:0::0
EOF
}
Index: src/gdb/NEWS
===================================================================
--- src.orig/gdb/NEWS 2010-04-22 17:19:42.000000000 +0100
+++ src/gdb/NEWS 2010-04-22 17:22:34.000000000 +0100
@@ -47,8 +47,23 @@ qGetTIBAddr
single `break' command creates multiple breakpoints (e.g.,
breakpoints on overloaded c++ functions).
+* Support for remote debugging Windows and SymbianOS shared libraries
+ from Unix hosts has been improved. Non Windows GDB builds now can
+ understand target reported paths that follow MS-DOS based file
+ system semantics, such as paths that include drive letters and use
+ the backslash character as directory separator. This makes it
+ possible to transparently use the "set sysroot" and "set
+ solib-search-path" on Unix hosts to point as host copies of the
+ target's shared libraries. See the new command "set
+ target-file-system-kind" described below, and the "Commands to
+ specify files" section in the user manual for more information.
+
* New commands
+set target-file-system-kind unix|dos-based|auto
+show target-file-system-kind
+ Set or show the assumed file system kind for target reported paths.
+
save breakpoints <filename>
Save all current breakpoint definitions to a file suitable for use
in a later debugging session. To read the saved breakpoint
Index: src/gdb/doc/gdb.texinfo
===================================================================
--- src.orig/gdb/doc/gdb.texinfo 2010-04-22 17:20:14.000000000 +0100
+++ src/gdb/doc/gdb.texinfo 2010-04-22 17:22:34.000000000 +0100
@@ -14344,6 +14344,37 @@ libraries, they need to be laid out in t
the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
under @var{path}.
+
+For targets with an MS-DOS based filesystem, such as MS-Windows and
+SymbianOS, @value{GDBN} tries prefixing a few variants of the target
+path with @var{path}. First, on Unix hosts, @value{GDBN} converts all
+backslash directory separators into forward slashes:
+
+@smallexample
+ c:\foo\bar.dll ==> c:/foo/bar.dll
+@end smallexample
+
+Then, it attempts prefixing the pristine target path with @var{path}.
+
+@smallexample
+ c:/foo/bar.dll ==> /path/to/sysroot/c:/foo/bar.dll
+@end smallexample
+
+If that does not find the shared library, it tries removing the
+@samp{:} character from the drive spec:
+
+@smallexample
+ c:/foo/bar.dll ==> /path/to/sysroot/c/foo/bar.dll
+@end smallexample
+
+If that still does not find the shared library, it tries removing the
+whole drive spec from the target path:
+
+@smallexample
+ c:/foo/bar.dll ==> /path/to/sysroot/foo/bar.dll
+@end smallexample
+
+
If @var{path} starts with the sequence @file{remote:}, @value{GDBN} will
retrieve the target libraries from the remote system. This is only
supported when using a remote target that supports the @code{remote get}
@@ -14385,6 +14416,54 @@ of shared library symbols.
@kindex show solib-search-path
@item show solib-search-path
Display the current shared library search path.
+
+@kindex set target-file-system-kind (unix|dos-based|auto)
+@kindex show target-file-system-kind
+@item set target-file-system-kind @var{kind}
+Set assumed file system kind for target reported paths.
+
+Shared library file names as reported by the target system may not
+make sense as is on the system @value{GDBN} is running on. For
+example, when remote debugging a target that has MS-DOS based file
+system semantics, from a Unix host, the target may be reporting to
+@value{GDBN} a list of loaded shared libraries with paths such as
+@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
+drive letters, the @file{c:\} prefix is not normally understood as
+indicating an absolute path, and neither is the backslash normally
+considered a directory separator character. In that case, the native
+filesystem would interpret this whole absolute path as a single file
+name with no directory components. This would make it impractical to
+point @value{GDBN} at a copy of the remote target's shared libraries
+on the host, using @code{set sysroot} or @code{set solib-search-path}.
+Setting @code{target-file-system-kind} to @code{dos-based} tells
+@value{GDBN} to interpret such paths similarly to how the target
+would, and to map them to paths valid on @value{GDBN}'s native
+filesystem semantics. The value of @var{kind} can be @code{"auto"},
+in addition to one of the supported file system kinds. In that case,
+@value{GDBN} tries to determine the appropriate file system variant
+based on the current target's operating system (@pxref{ABI,
+,Configuring the Current ABI}). The supported file system settings
+are:
+
+@table @code
+@item unix
+Instruct @value{GDBN} to assume the target file system is of Unix
+kind. Only paths starting the forward slash (@samp{/}) character are
+considered absolute, and the directory separator character is also the
+forward slash.
+
+@item dos-based
+Instruct @value{GDBN} to assume the target file system is DOS based.
+Paths starting with either a forward slash or a drive letter (e.g.,
+@samp{c:}), are considered absolute, and both the slash (@samp{/}) and
+the backslash (@samp{\\}) characters are considered directory
+separators.
+
+@item auto
+Instruct @value{GDBN} to use the file system kind associated with the
+target operating system (@pxref{ABI, ,Configuring the Current ABI}).
+This is the default.
+@end table
@end table
Index: src/gdb/gdbarch.h
===================================================================
--- src.orig/gdb/gdbarch.h 2010-04-22 17:19:42.000000000 +0100
+++ src/gdb/gdbarch.h 2010-04-22 17:22:34.000000000 +0100
@@ -950,6 +950,13 @@ extern void set_gdbarch_auto_wide_charse
extern const char * gdbarch_solib_symbols_extension (struct gdbarch *gdbarch);
extern void set_gdbarch_solib_symbols_extension (struct gdbarch *gdbarch, const char * solib_symbols_extension);
+/* If true the target OS has DOS-based file system semantics. That is,
+ absolute paths include a drive name, and the backslash is considered
+ a path separator. */
+
+extern int gdbarch_has_dos_based_file_system (struct gdbarch *gdbarch);
+extern void set_gdbarch_has_dos_based_file_system (struct gdbarch *gdbarch, int has_dos_based_file_system);
+
/* Definition for an unknown syscall, used basically in error-cases. */
#define UNKNOWN_SYSCALL (-1)
Index: src/gdb/gdbarch.c
===================================================================
--- src.orig/gdb/gdbarch.c 2010-04-22 17:19:42.000000000 +0100
+++ src/gdb/gdbarch.c 2010-04-22 17:22:34.000000000 +0100
@@ -264,6 +264,7 @@ struct gdbarch
gdbarch_auto_charset_ftype *auto_charset;
gdbarch_auto_wide_charset_ftype *auto_wide_charset;
const char * solib_symbols_extension;
+ int has_dos_based_file_system;
};
@@ -411,6 +412,7 @@ struct gdbarch startup_gdbarch =
default_auto_charset, /* auto_charset */
default_auto_wide_charset, /* auto_wide_charset */
0, /* solib_symbols_extension */
+ 0, /* has_dos_based_file_system */
/* startup_gdbarch() */
};
@@ -682,6 +684,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of qsupported, invalid_p == 0 */
/* Skip verify of auto_charset, invalid_p == 0 */
/* Skip verify of auto_wide_charset, invalid_p == 0 */
+ /* Skip verify of has_dos_based_file_system, invalid_p == 0 */
buf = ui_file_xstrdup (log, &length);
make_cleanup (xfree, buf);
if (length > 0)
@@ -927,6 +930,9 @@ gdbarch_dump (struct gdbarch *gdbarch, s
"gdbarch_dump: get_syscall_number = <%s>\n",
host_address_to_string (gdbarch->get_syscall_number));
fprintf_unfiltered (file,
+ "gdbarch_dump: has_dos_based_file_system = %s\n",
+ plongest (gdbarch->has_dos_based_file_system));
+ fprintf_unfiltered (file,
"gdbarch_dump: has_global_breakpoints = %s\n",
plongest (gdbarch->has_global_breakpoints));
fprintf_unfiltered (file,
@@ -3676,6 +3682,23 @@ set_gdbarch_solib_symbols_extension (str
gdbarch->solib_symbols_extension = solib_symbols_extension;
}
+int
+gdbarch_has_dos_based_file_system (struct gdbarch *gdbarch)
+{
+ gdb_assert (gdbarch != NULL);
+ /* Skip verify of has_dos_based_file_system, invalid_p == 0 */
+ if (gdbarch_debug >= 2)
+ fprintf_unfiltered (gdb_stdlog, "gdbarch_has_dos_based_file_system called\n");
+ return gdbarch->has_dos_based_file_system;
+}
+
+void
+set_gdbarch_has_dos_based_file_system (struct gdbarch *gdbarch,
+ int has_dos_based_file_system)
+{
+ gdbarch->has_dos_based_file_system = has_dos_based_file_system;
+}
+
/* Keep a registry of per-architecture data-pointers required by GDB
modules. */
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts)
2010-04-22 17:24 [gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts) Pedro Alves
@ 2010-04-22 17:46 ` Daniel Jacobowitz
2010-04-23 8:54 ` Eli Zaretskii
1 sibling, 0 replies; 11+ messages in thread
From: Daniel Jacobowitz @ 2010-04-22 17:46 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches, gcc-patches
On Thu, Apr 22, 2010 at 06:24:26PM +0100, Pedro Alves wrote:
> (At some point, this patch also included a new user knob
> to make source file name comparision flavour (and
> mostly s/FILENAME_CMP/source_filename_cmp/,
> s/lbasename/source_lbasename throught the sources/debug info
> handling parts of GDB.) depend on build file system. That's because
> often you stumble on the fact that cross debugging a Windows/SymbianOS
> binary _built_ on non-Unix, includes `\' in debug info, and a Unix
> GDB can't grok that. I mention this, in case someone would
> suggest this new setting should be more general and cover that
> case as well. It shouldn't: the concepts are different --- target
> paths, vs source/debug info/build paths, and you'll want to be
> able to tweak them independently.)
I agree with this patch's approach, and with this separation. One
important way that source paths are different: a host path is clearly
either Unix or DOS. A target path, ditto. A source path, not so
much. It is common to have half and half, e.g. if your toolchain was
built on Linux but ran on Windows.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts)
2010-04-22 17:24 [gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts) Pedro Alves
2010-04-22 17:46 ` Daniel Jacobowitz
@ 2010-04-23 8:54 ` Eli Zaretskii
2010-04-23 10:46 ` Pedro Alves
1 sibling, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2010-04-23 8:54 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches, gcc-patches
> From: Pedro Alves <pedro@codesourcery.com>
> Date: Thu, 22 Apr 2010 18:24:26 +0100
>
> The fix is to teach GDB about the distintion between host
> paths and target paths, and make the target file system
> "kind" selectable at run time. See the new target_lbasename,
> IS_TARGET_DIR_SEPARATOR, IS_TARGET_ABSOLUTE_PATH,
> HAS_TARGET_DRIVE_SPEC in the patch (gdb side).
>
> For that, the patch introduces a new set/show command pair
> so the user can tweak the target's file system flavour, in
> case GDB gets it wrong:
Thanks!
> (gdb) help set target-file-system-kind
> Set assumed file system kind for target reported paths
Please don't use "path" when you really mean "file name". It's
confusing; "path" should be reserved for lists of directories such as
PATH or INFOPATH.
> --- src.orig/gdb/solib.c 2010-04-22 17:19:42.000000000 +0100
> +++ src/gdb/solib.c 2010-04-22 17:22:34.000000000 +0100
> @@ -104,6 +104,76 @@ The search path for loading non-absolute
> value);
> }
>
> +/* Handle DOS-like target reported paths, that is for example, DLL
> + paths like c:\sys\bin\foo.dll (drive name, backslash as dir
> + separator), even if GDB itself is not running on such a system. */
> +
> +static const char target_file_system_kind_auto[] = "auto";
> +static const char target_file_system_kind_unix[] = "unix";
> +static const char target_file_system_kind_dos_based[] = "dos-based";
> +static const char *target_file_system_kinds[] =
> +{
> + target_file_system_kind_auto,
> + target_file_system_kind_unix,
> + target_file_system_kind_dos_based
> +};
Is it wise to define these in solib.c? What about ports that don't
link solib.c into the binary?
I'd suggest to move this (and the related functions) to some more
general source file, even if for now these facilities are used only
for shared library lookup.
> + /* If the search in gdb_sysroot failed, and the path name has a
> + drive spec (e.g, c:/foo), try stripping ':' from the drive spec,
> + and retrying in the sysroot:
> + c:/foo/bar.dll ==> /sysroot/c/foo/bar.dll. */
Why not /sysroot/foo/bar, without the "c" part? What systems are set
up the way this code expects?
> Index: src/gdb/i386-cygwin-tdep.c
> ===================================================================
> --- src.orig/gdb/i386-cygwin-tdep.c 2010-04-22 17:19:42.000000000 +0100
> +++ src/gdb/i386-cygwin-tdep.c 2010-04-22 17:22:34.000000000 +0100
> @@ -235,6 +235,10 @@ i386_cygwin_init_abi (struct gdbarch_inf
> (gdbarch, windows_core_xfer_shared_libraries);
>
> set_gdbarch_auto_wide_charset (gdbarch, i386_cygwin_auto_wide_charset);
> +
> + /* Canonical paths on this target look like `c:\Program Files\Foo App\mydso.dll',
> + for example. */
> + set_gdbarch_has_dos_based_file_system (gdbarch, 1);
> }
Any reasons not to provide similar settings for MinGW and DJGPP?
> +* Support for remote debugging Windows and SymbianOS shared libraries
> + from Unix hosts has been improved.
Is this feature really used only for remote debugging? Doesn't it
affect native debugging as well?
> +@smallexample
> + c:\foo\bar.dll ==> c:/foo/bar.dll
> +@end smallexample
Please use @result{} instead of the ASCII art.
> +@kindex set target-file-system-kind (unix|dos-based|auto)
> +@kindex show target-file-system-kind
> +@item set target-file-system-kind @var{kind}
> +Set assumed file system kind for target reported paths.
This warrants some @cindex entry, preferably including "dos" as its
substring. Something like
@cindex DOS file-name semantics if file names.
Again, please don't use "path" instead of "file name" (here and
elsewhere).
The NEWS entry and the patch for the manual are okay with the above
changes.
Thanks.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts)
2010-04-23 8:54 ` Eli Zaretskii
@ 2010-04-23 10:46 ` Pedro Alves
2010-04-23 11:15 ` Mark Kettenis
2010-04-23 14:35 ` Eli Zaretskii
0 siblings, 2 replies; 11+ messages in thread
From: Pedro Alves @ 2010-04-23 10:46 UTC (permalink / raw)
To: gdb-patches, Eli Zaretskii; +Cc: gcc-patches
On Friday 23 April 2010 09:54:17, Eli Zaretskii wrote:
> > From: Pedro Alves <pedro@codesourcery.com>
>
> > (gdb) help set target-file-system-kind
> > Set assumed file system kind for target reported paths
>
> Please don't use "path" when you really mean "file name". It's
> confusing; "path" should be reserved for lists of directories such as
> PATH or INFOPATH.
Oh. I really meant a "path", as in:
"A path, the general form of a filename or of a directory name, specifies a unique
location in a file system."
(From <http://en.wikipedia.org/wiki/Path_%28computing%29>.)
I suppose that's why we have IS_ABSOLUTE_PATH, and not IS_ABSOLUTE_FILE_NAME,
and such.
IMO, it's the use of singular path or "search path" to mean
"list of directories" that's overloaded.
"Set assumed file system kind for target reported file names"
kind of sounds like it is only talking about the filename "/dir1/dir2/files1"
(or directory and filenames, if you think of a directory a file as well).
Maybe I could just get rid of the mention of paths/file names, and go with:
"Set the assumed file system kind of the target."
Anyway, I'll change it to what you think is clearer.
> > --- src.orig/gdb/solib.c 2010-04-22 17:19:42.000000000 +0100
> > +++ src/gdb/solib.c 2010-04-22 17:22:34.000000000 +0100
...
> > +static const char target_file_system_kind_auto[] = "auto";
...
> Is it wise to define these in solib.c? What about ports that don't
> link solib.c into the binary?
They don't exist. solib.o is always linked in (it's in COMMON_OBS).
>
> I'd suggest to move this (and the related functions) to some more
> general source file, even if for now these facilities are used only
> for shared library lookup.
Will do anyway. Probably a new file.
> > + /* If the search in gdb_sysroot failed, and the path name has a
> > + drive spec (e.g, c:/foo), try stripping ':' from the drive spec,
> > + and retrying in the sysroot:
> > + c:/foo/bar.dll ==> /sysroot/c/foo/bar.dll. */
>
> Why not /sysroot/foo/bar, without the "c" part? What systems are set
> up the way this code expects?
I'm not sure I understood what you're referring to as "systems" here.
The sysroot is a user specified path in the host file system. If you
have a target system with more than one drive, you will want to setup
you local copies of the target system dlls like so:
/path/to/my/sysroot/c/sys/bin/foo.dll
/path/to/my/sysroot/c/sys/bin/bar.dll
/path/to/my/sysroot/z/sys/bin/bar.dll
and point "set sysroot" at "/path/to/my/sysroot", so that
GDB can find the correct copies of both "c:\sys\bin\foo.dll",
and "z:\sys\bin\bar.dll".
If you don't care about multiple drives, you can
leave the "c" out of the sysroot, and gdb will still
find your host copy of the dll. It was described as next
step in the docs:
" If that still does not find the shared library, it tries removing the
whole drive spec from the target path:
c:/foo/bar.dll ==> /path/to/sysroot/foo/bar.dll
"
I'll be happy to clarify this in the docs, if you think it's useful.
>
> > Index: src/gdb/i386-cygwin-tdep.c
> > ===================================================================
> > --- src.orig/gdb/i386-cygwin-tdep.c 2010-04-22 17:19:42.000000000 +0100
> > +++ src/gdb/i386-cygwin-tdep.c 2010-04-22 17:22:34.000000000 +0100
> > @@ -235,6 +235,10 @@ i386_cygwin_init_abi (struct gdbarch_inf
> > (gdbarch, windows_core_xfer_shared_libraries);
> >
> > set_gdbarch_auto_wide_charset (gdbarch, i386_cygwin_auto_wide_charset);
> > +
> > + /* Canonical paths on this target look like `c:\Program Files\Foo App\mydso.dll',
> > + for example. */
> > + set_gdbarch_has_dos_based_file_system (gdbarch, 1);
> > }
>
> Any reasons not to provide similar settings for MinGW and DJGPP?
MinGW is also covered by i386-cygwin-tdep.c. There's no specific
MinGW gdbarch/osabi currently. DJGPP, it just didn't cross my mind,
probably because it doesn't support shared libraries, sorry :-)
I suppose that'll be ... in `i386_go32_init_abi'. (Why are DJGPP
specific things in the generic i386-tdep.c, BTW?)
>
> > +* Support for remote debugging Windows and SymbianOS shared libraries
> > + from Unix hosts has been improved.
>
> Is this feature really used only for remote debugging? Doesn't it
> affect native debugging as well?
>
> > +@smallexample
> > + c:\foo\bar.dll ==> c:/foo/bar.dll
> > +@end smallexample
>
> Please use @result{} instead of the ASCII art.
Eh, cool. Will do.
>
> > +@kindex set target-file-system-kind (unix|dos-based|auto)
> > +@kindex show target-file-system-kind
> > +@item set target-file-system-kind @var{kind}
> > +Set assumed file system kind for target reported paths.
>
> This warrants some @cindex entry, preferably including "dos" as its
> substring. Something like
>
> @cindex DOS file-name semantics if file names.
Will do. I'll assume you meant s/if/of/.
>
> Again, please don't use "path" instead of "file name" (here and
> elsewhere).
>
> The NEWS entry and the patch for the manual are okay with the above
> changes.
>
> Thanks.
Thanks.
--
Pedro Alves
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts)
2010-04-23 10:46 ` Pedro Alves
@ 2010-04-23 11:15 ` Mark Kettenis
2010-04-23 14:30 ` Eli Zaretskii
2010-04-23 14:35 ` Eli Zaretskii
1 sibling, 1 reply; 11+ messages in thread
From: Mark Kettenis @ 2010-04-23 11:15 UTC (permalink / raw)
To: pedro; +Cc: gdb-patches, eliz, gcc-patches
> From: Pedro Alves <pedro@codesourcery.com>
> Date: Fri, 23 Apr 2010 11:46:22 +0100
>
> On Friday 23 April 2010 09:54:17, Eli Zaretskii wrote:
> > > From: Pedro Alves <pedro@codesourcery.com>
> >
> > > (gdb) help set target-file-system-kind
> > > Set assumed file system kind for target reported paths
> >
> > Please don't use "path" when you really mean "file name". It's
> > confusing; "path" should be reserved for lists of directories such as
> > PATH or INFOPATH.
>
> Oh. I really meant a "path", as in:
>
> "A path, the general form of a filename or of a directory name,
> specifies a unique location in a file system."
>
> (From <http://en.wikipedia.org/wiki/Path_%28computing%29>.)
>
> I suppose that's why we have IS_ABSOLUTE_PATH, and not IS_ABSOLUTE_FILE_NAME,
> and such.
>
> IMO, it's the use of singular path or "search path" to mean
> "list of directories" that's overloaded.
> "Set assumed file system kind for target reported file names"
> kind of sounds like it is only talking about the filename "/dir1/dir2/files1"
> (or directory and filenames, if you think of a directory a file as well).
> Maybe I could just get rid of the mention of paths/file names, and go with:
>
> "Set the assumed file system kind of the target."
>
> Anyway, I'll change it to what you think is clearer.
I think that depends on whether you're coming from a UNIX environment
or a DOS environment. To me (not really having used DOS for two
decades) path is perfectly clear and acceptable.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts)
2010-04-23 11:15 ` Mark Kettenis
@ 2010-04-23 14:30 ` Eli Zaretskii
2010-04-23 15:41 ` Mark Kettenis
0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2010-04-23 14:30 UTC (permalink / raw)
To: Mark Kettenis; +Cc: pedro, gdb-patches, gcc-patches
> Date: Fri, 23 Apr 2010 13:13:28 +0200 (CEST)
> From: Mark Kettenis <mark.kettenis@xs4all.nl>
> CC: gdb-patches@sourceware.org, eliz@gnu.org, gcc-patches@gcc.gnu.org
>
> > > Please don't use "path" when you really mean "file name". It's
> > > confusing; "path" should be reserved for lists of directories such as
> > > PATH or INFOPATH.
> >
> > Oh. I really meant a "path", as in:
> >
> > "A path, the general form of a filename or of a directory name,
> > specifies a unique location in a file system."
> >
> > (From <http://en.wikipedia.org/wiki/Path_%28computing%29>.)
> >
> > I suppose that's why we have IS_ABSOLUTE_PATH, and not IS_ABSOLUTE_FILE_NAME,
> > and such.
> >
> > IMO, it's the use of singular path or "search path" to mean
> > "list of directories" that's overloaded.
> > "Set assumed file system kind for target reported file names"
> > kind of sounds like it is only talking about the filename "/dir1/dir2/files1"
> > (or directory and filenames, if you think of a directory a file as well).
> > Maybe I could just get rid of the mention of paths/file names, and go with:
> >
> > "Set the assumed file system kind of the target."
> >
> > Anyway, I'll change it to what you think is clearer.
>
> I think that depends on whether you're coming from a UNIX environment
> or a DOS environment. To me (not really having used DOS for two
> decades) path is perfectly clear and acceptable.
From standards.info, node "GNU Manuals":
Please do not use the term "pathname" that is used in Unix
documentation; use "file name" (two words) instead. We use the term
"path" only for search paths, which are lists of directory names.
You can hardly say that RMS comes from a DOS environment, can you?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts)
2010-04-23 10:46 ` Pedro Alves
2010-04-23 11:15 ` Mark Kettenis
@ 2010-04-23 14:35 ` Eli Zaretskii
2010-04-24 11:18 ` Pedro Alves
1 sibling, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2010-04-23 14:35 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches, gcc-patches
> From: Pedro Alves <pedro@codesourcery.com>
> Date: Fri, 23 Apr 2010 11:46:22 +0100
> Cc: gcc-patches@gcc.gnu.org
>
> Oh. I really meant a "path", as in:
>
> "A path, the general form of a filename or of a directory name, specifies a unique
> location in a file system."
>
> (From <http://en.wikipedia.org/wiki/Path_%28computing%29>.)
>
> I suppose that's why we have IS_ABSOLUTE_PATH, and not IS_ABSOLUTE_FILE_NAME,
> and such.
>
> IMO, it's the use of singular path or "search path" to mean
> "list of directories" that's overloaded.
> "Set assumed file system kind for target reported file names"
> kind of sounds like it is only talking about the filename "/dir1/dir2/files1"
> (or directory and filenames, if you think of a directory a file as well).
> Maybe I could just get rid of the mention of paths/file names, and go with:
>
> "Set the assumed file system kind of the target."
>
> Anyway, I'll change it to what you think is clearer.
Not only is it clearer, it's in GNU coding standards, see my other
mail.
> c:/foo/bar.dll ==> /path/to/sysroot/foo/bar.dll
> "
>
> I'll be happy to clarify this in the docs, if you think it's useful.
No, it's clear enough. I just wondered why you didn't remove the
drive letter right away. I guess that's common practice in some
quarters to mount DOS-ish filesystems that way. I don't really mind
to support that if people are using it.
> I suppose that'll be ... in `i386_go32_init_abi'.
Yep.
> (Why are DJGPP specific things in the generic i386-tdep.c, BTW?)
History, I think. The number of architecture specific bits is quite
small.
> > @cindex DOS file-name semantics if file names.
>
> Will do. I'll assume you meant s/if/of/.
Of course.
Thanks.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts)
2010-04-23 14:30 ` Eli Zaretskii
@ 2010-04-23 15:41 ` Mark Kettenis
0 siblings, 0 replies; 11+ messages in thread
From: Mark Kettenis @ 2010-04-23 15:41 UTC (permalink / raw)
To: eliz; +Cc: pedro, gdb-patches, gcc-patches
> Date: Fri, 23 Apr 2010 17:30:31 +0300
> From: Eli Zaretskii <eliz@gnu.org>
>
> >From standards.info, node "GNU Manuals":
>
> Please do not use the term "pathname" that is used in Unix
> documentation; use "file name" (two words) instead. We use the term
> "path" only for search paths, which are lists of directory names.
>
> You can hardly say that RMS comes from a DOS environment, can you?
Forgot that his holyness passed a verdict on this one ;).
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts)
2010-04-23 14:35 ` Eli Zaretskii
@ 2010-04-24 11:18 ` Pedro Alves
2010-04-24 11:40 ` Eli Zaretskii
0 siblings, 1 reply; 11+ messages in thread
From: Pedro Alves @ 2010-04-24 11:18 UTC (permalink / raw)
To: gdb-patches, Eli Zaretskii; +Cc: gcc-patches
On Friday 23 April 2010 15:35:11, Eli Zaretskii wrote:
> Not only is it clearer, it's in GNU coding standards, see my other
> mail.
Okay, I changed all user visible strings, I think.
>
> > c:/foo/bar.dll ==> /path/to/sysroot/foo/bar.dll
> > "
> >
> > I'll be happy to clarify this in the docs, if you think it's useful.
>
> No, it's clear enough. I just wondered why you didn't remove the
> drive letter right away. I guess that's common practice in some
> quarters to mount DOS-ish filesystems that way. I don't really mind
> to support that if people are using it.
Hope you don't mind, I ended up extending the docs here to
explicitly explain why the lookup algorith is the way it is,
so that users don't wonder the same you did.
I've moved that new target filesystem handling code to a
new file, and, handled DJGPP's gdbarch.
I think this updated patch addresses all your comments. Could
you please take a new quick look at this?
(gdb patch only, the libiberty bits have already been approved
and applied)
--
Pedro Alves
2010-04-24 Pedro Alves <pedro@codesourcery.com>
gdb/
* defs.h: Adjust comment.
* filesystem.h, filesystem.c: New files.
* Makefile.in (SFILES): Add filesystem.c.
(COMMON_OBS): Add filesystem.o.
* solib.c (solib_find): Handle DOS-based filesystems. Handle
different target and host path flavours.
* arm-symbian-tdep.c (arm_symbian_init_abi): Set
has_dos_based_file_system on the gdbarch.
* arm-wince-tdep.c (arm_wince_init_abi): Ditto.
* i386-cygwin-tdep.c (i386_cygwin_init_abi): Ditto.
* i386-tdep.c (i386_go32_init_abi): Ditto.
* gdbarch.sh (has_dos_based_file_system): New.
* gdbarch.h, gdbarch.c: Regenerate.
* NEWS: Mention improved support for remote targets with DOS-based
filesystems. Mention new `set/show target-file-system-kind'
commands.
gdb/doc/
* gdb.texinfo (Commands to specify files): Describe what how GDB
looks up DOS-based filesystem paths on the system root. Document
the new `set/show target-file-system-kind' commands.
---
gdb/Makefile.in | 5 -
gdb/NEWS | 16 ++++
gdb/arm-symbian-tdep.c | 4 +
gdb/arm-wince-tdep.c | 4 +
gdb/defs.h | 6 -
gdb/doc/gdb.texinfo | 101 +++++++++++++++++++++++++++++++
gdb/filesystem.c | 103 +++++++++++++++++++++++++++++++
gdb/filesystem.h | 58 +++++++++++++++++
gdb/gdbarch.c | 23 +++++++
gdb/gdbarch.h | 7 ++
gdb/gdbarch.sh | 5 +
gdb/i386-cygwin-tdep.c | 4 +
gdb/i386-tdep.c | 2
gdb/solib.c | 158 ++++++++++++++++++++++++++++++++++++++++---------
14 files changed, 462 insertions(+), 34 deletions(-)
Index: src/gdb/defs.h
===================================================================
--- src.orig/gdb/defs.h 2010-04-24 11:53:11.000000000 +0100
+++ src/gdb/defs.h 2010-04-24 11:53:13.000000000 +0100
@@ -1155,9 +1155,9 @@ extern int (*deprecated_ui_load_progress
extern int use_windows;
-/* Symbolic definitions of filename-related things. */
-/* FIXME, this doesn't work very well if host and executable
- filesystems conventions are different. */
+/* Definitions of filename-related things. */
+
+/* Host specific things. */
#ifdef __MSDOS__
# define CANT_FORK
Index: src/gdb/filesystem.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/filesystem.h 2010-04-24 11:56:54.000000000 +0100
@@ -0,0 +1,58 @@
+/* Handle different target file systems for GDB, the GNU Debugger.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef FILESYSTEM_H
+#define FILESYSTEM_H
+
+extern const char file_system_kind_auto[];
+extern const char file_system_kind_unix[];
+extern const char file_system_kind_dos_based[];
+
+extern const char *target_file_system_kind;
+
+/* Same as IS_DIR_SEPARATOR but with file system kind KIND's
+ semantics, instead of host semantics. */
+
+#define IS_TARGET_DIR_SEPARATOR(kind, c) \
+ (((kind) == file_system_kind_dos_based) ? IS_DOS_DIR_SEPARATOR (c) \
+ : IS_UNIX_DIR_SEPARATOR (c))
+
+/* Same as IS_ABSOLUTE_PATH but with file system kind KIND's
+ semantics, instead of host semantics. */
+
+#define IS_TARGET_ABSOLUTE_PATH(kind, p) \
+ (((kind) == file_system_kind_dos_based) ? IS_DOS_ABSOLUTE_PATH (p) \
+ : IS_UNIX_ABSOLUTE_PATH (p))
+
+/* Same as HAS_DRIVE_SPEC but with file system kind KIND's semantics,
+ instead of host semantics. */
+
+#define HAS_TARGET_DRIVE_SPEC(kind, p) \
+ (((kind) == file_system_kind_dos_based) ? HAS_DOS_DRIVE_SPEC (p) \
+ : 0)
+
+/* Same as lbasename, but with file system kind KIND's semantics,
+ instead of host semantics. */
+extern const char *target_lbasename (const char *kind, const char *name);
+
+/* The effective setting of "set target-file-system-kind", with "auto"
+ resolved to the real kind. That is, you never see "auto" as a
+ result from this function. */
+extern const char *effective_target_file_system_kind (void);
+
+#endif
Index: src/gdb/filesystem.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/filesystem.c 2010-04-24 12:09:14.000000000 +0100
@@ -0,0 +1,103 @@
+/* Handle different target file systems for GDB, the GNU Debugger.
+
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "defs.h"
+#include "filesystem.h"
+#include "gdbarch.h"
+#include "gdbcmd.h"
+
+const char file_system_kind_auto[] = "auto";
+const char file_system_kind_unix[] = "unix";
+const char file_system_kind_dos_based[] = "dos-based";
+const char *target_file_system_kinds[] =
+{
+ file_system_kind_auto,
+ file_system_kind_unix,
+ file_system_kind_dos_based,
+ NULL
+};
+const char *target_file_system_kind = file_system_kind_auto;
+
+const char *
+effective_target_file_system_kind (void)
+{
+ if (target_file_system_kind == file_system_kind_auto)
+ {
+ if (gdbarch_has_dos_based_file_system (target_gdbarch))
+ return file_system_kind_dos_based;
+ else
+ return file_system_kind_unix;
+ }
+ else
+ return target_file_system_kind;
+}
+
+const char *
+target_lbasename (const char *kind, const char *name)
+{
+ if (kind == file_system_kind_dos_based)
+ return dos_lbasename (name);
+ else
+ return unix_lbasename (name);
+}
+
+static void
+show_target_file_system_kind_command (struct ui_file *file,
+ int from_tty,
+ struct cmd_list_element *c,
+ const char *value)
+{
+ if (target_file_system_kind == file_system_kind_auto)
+ fprintf_filtered (file, _("\
+The assumed file system kind for target reported file names \
+is \"%s\" (currently \"%s\").\n"),
+ value,
+ effective_target_file_system_kind ());
+ else
+ fprintf_filtered (file, _("\
+The assumed file system kind for target reported file names \
+is \"%s\".\n"),
+ value);
+}
+
+/* Provide a prototype to silence -Wmissing-prototypes. */
+extern initialize_file_ftype _initialize_filesystem;
+
+void
+_initialize_filesystem (void)
+{
+ add_setshow_enum_cmd ("target-file-system-kind",
+ class_files,
+ target_file_system_kinds,
+ &target_file_system_kind, _("\
+Set assumed file system kind for target reported file names"), _("\
+Show assumed file system kind for target reported file names"),
+ _("\
+If `unix', target file names (e.g., loaded shared library file names) \n\
+starting the forward slash (`/') character are considered absolute, \n\
+and the directory separator character is the forward slash (`/'). If \n\
+`dos-based', target file names starting with a drive letter followed \n\
+by a colon (e.g., `c:'), are also considered absolute, and the \n\
+backslash (`\\') is also considered a directory separator. Set to \n\
+`auto' (which is the default), to let GDB decide, based on its \n\
+knowledge of the target operating system."),
+ NULL, /* setfunc */
+ show_target_file_system_kind_command,
+ &setlist, &showlist);
+}
Index: src/gdb/Makefile.in
===================================================================
--- src.orig/gdb/Makefile.in 2010-04-24 11:53:11.000000000 +0100
+++ src/gdb/Makefile.in 2010-04-24 11:53:13.000000000 +0100
@@ -663,8 +663,8 @@ SFILES = ada-exp.y ada-lang.c ada-typepr
dwarf2expr.c dwarf2loc.c dwarf2read.c dwarf2-frame.c \
elfread.c environ.c eval.c event-loop.c event-top.c \
exceptions.c expprint.c \
- f-exp.y f-lang.c f-typeprint.c f-valprint.c findcmd.c findvar.c \
- frame.c frame-base.c frame-unwind.c \
+ f-exp.y f-lang.c f-typeprint.c f-valprint.c filesystem.c \
+ findcmd.c findvar.c frame.c frame-base.c frame-unwind.c \
gdbarch.c arch-utils.c gdbtypes.c gnu-v2-abi.c gnu-v3-abi.c \
inf-loop.c \
infcall.c \
@@ -814,6 +814,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $
infcmd.o infrun.o \
expprint.o environ.o stack.o thread.o \
exceptions.o \
+ filesystem.o \
inf-child.o \
interps.o \
main.o \
Index: src/gdb/solib.c
===================================================================
--- src.orig/gdb/solib.c 2010-04-24 11:53:11.000000000 +0100
+++ src/gdb/solib.c 2010-04-24 11:58:27.000000000 +0100
@@ -47,6 +47,7 @@
#include "remote.h"
#include "solib.h"
#include "interps.h"
+#include "filesystem.h"
/* Architecture-specific operations. */
@@ -104,6 +105,13 @@ The search path for loading non-absolute
value);
}
+/* Same as HAVE_DOS_BASED_FILE_SYSTEM, but useable as an rvalue. */
+#if (HAVE_DOS_BASED_FILE_SYSTEM)
+# define DOS_BASED_FILE_SYSTEM 1
+#else
+# define DOS_BASED_FILE_SYSTEM 0
+#endif
+
/*
GLOBAL FUNCTION
@@ -133,7 +141,7 @@ The search path for loading non-absolute
* If gdb_sysroot is NOT set, perform the following two searches:
* Look in inferior's $PATH.
* Look in inferior's $LD_LIBRARY_PATH.
- *
+ *
* The last check avoids doing this search when targetting remote
* machines since gdb_sysroot will almost always be set.
@@ -152,6 +160,9 @@ solib_find (char *in_pathname, int *fd)
int gdb_sysroot_is_empty;
const char *solib_symbols_extension
= gdbarch_solib_symbols_extension (target_gdbarch);
+ const char *fskind = effective_target_file_system_kind ();
+ struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
+ char *sysroot = NULL;
/* If solib_symbols_extension is set, replace the file's
extension. */
@@ -177,9 +188,7 @@ solib_find (char *in_pathname, int *fd)
gdb_sysroot_is_empty = (gdb_sysroot == NULL || *gdb_sysroot == 0);
- if (! IS_ABSOLUTE_PATH (in_pathname) || gdb_sysroot_is_empty)
- temp_pathname = in_pathname;
- else
+ if (!gdb_sysroot_is_empty)
{
int prefix_len = strlen (gdb_sysroot);
@@ -188,61 +197,152 @@ solib_find (char *in_pathname, int *fd)
&& IS_DIR_SEPARATOR (gdb_sysroot[prefix_len - 1]))
prefix_len--;
+ sysroot = savestring (gdb_sysroot, prefix_len);
+ make_cleanup (xfree, sysroot);
+ }
+
+ /* If we're on a non-DOS-based system, backslashes won't be
+ understood as directory separator, so, convert them to forward
+ slashes, iff we're supposed to handle DOS-based file system
+ semantics for target paths. */
+ if (!DOS_BASED_FILE_SYSTEM && fskind == file_system_kind_dos_based)
+ {
+ char *p;
+
+ /* Avoid clobbering our input. */
+ p = alloca (strlen (in_pathname) + 1);
+ strcpy (p, in_pathname);
+ in_pathname = p;
+
+ for (; *p; p++)
+ {
+ if (*p == '\\')
+ *p = '/';
+ }
+ }
+
+ /* Note, we're interested in IS_TARGET_ABSOLUTE_PATH, not
+ IS_ABSOLUTE_PATH. The latter is for host paths only, while
+ IN_PATHNAME is a target path. For example, if we're supposed to
+ be handling DOS-like semantics we want to consider a
+ 'c:/foo/bar.dll' path as an absolute path, even on a Unix box.
+ With such a path, before giving up on the sysroot, we'll try:
+
+ 1st attempt, c:/foo/bar.dll ==> /sysroot/c:/foo/bar.dll
+ 2nd attempt, c:/foo/bar.dll ==> /sysroot/c/foo/bar.dll
+ 3rd attempt, c:/foo/bar.dll ==> /sysroot/foo/bar.dll
+ */
+
+ if (!IS_TARGET_ABSOLUTE_PATH (fskind, in_pathname) || gdb_sysroot_is_empty)
+ temp_pathname = xstrdup (in_pathname);
+ else
+ {
+ int need_dir_separator;
+
+ need_dir_separator = !IS_DIR_SEPARATOR (in_pathname[0]);
+
/* Cat the prefixed pathname together. */
- temp_pathname = alloca (prefix_len + strlen (in_pathname) + 1);
- strncpy (temp_pathname, gdb_sysroot, prefix_len);
- temp_pathname[prefix_len] = '\0';
- strcat (temp_pathname, in_pathname);
+ temp_pathname = concat (sysroot,
+ need_dir_separator ? SLASH_STRING : "",
+ in_pathname, (char *) NULL);
}
/* Handle remote files. */
if (remote_filename_p (temp_pathname))
{
*fd = -1;
- return xstrdup (temp_pathname);
+ return temp_pathname;
}
/* Now see if we can open it. */
found_file = open (temp_pathname, O_RDONLY | O_BINARY, 0);
+ if (found_file < 0)
+ xfree (temp_pathname);
- /* We try to find the library in various ways. After each attempt
- (except for the one above), either found_file >= 0 and
- temp_pathname is a malloc'd string, or found_file < 0 and
- temp_pathname does not point to storage that needs to be
- freed. */
-
- if (found_file < 0)
- temp_pathname = NULL;
- else
- temp_pathname = xstrdup (temp_pathname);
+ /* If the search in gdb_sysroot failed, and the path name has a
+ drive spec (e.g, c:/foo), try stripping ':' from the drive spec,
+ and retrying in the sysroot:
+ c:/foo/bar.dll ==> /sysroot/c/foo/bar.dll. */
+
+ if (found_file < 0
+ && !gdb_sysroot_is_empty
+ && HAS_TARGET_DRIVE_SPEC (fskind, in_pathname))
+ {
+ int need_dir_separator = !IS_DIR_SEPARATOR (in_pathname[2]);
+ char *drive = savestring (in_pathname, 1);
+
+ temp_pathname = concat (sysroot,
+ SLASH_STRING,
+ drive,
+ need_dir_separator ? SLASH_STRING : "",
+ in_pathname + 2, (char *) NULL);
+ xfree (drive);
+
+ found_file = open (temp_pathname, O_RDONLY | O_BINARY, 0);
+ if (found_file < 0)
+ {
+ char *p;
+
+ xfree (temp_pathname);
+
+ /* If the search in gdb_sysroot still failed, try fully
+ stripping the drive spec, and trying once more in the
+ sysroot before giving up.
+
+ c:/foo/bar.dll ==> /sysroot/foo/bar.dll. */
+
+ temp_pathname = concat (sysroot,
+ need_dir_separator ? SLASH_STRING : "",
+ in_pathname + 2, (char *) NULL);
+
+ found_file = open (temp_pathname, O_RDONLY | O_BINARY, 0);
+ if (found_file < 0)
+ xfree (temp_pathname);
+ }
+ }
+
+ do_cleanups (old_chain);
+
+ /* We try to find the library in various ways. After each attempt,
+ either found_file >= 0 and temp_pathname is a malloc'd string, or
+ found_file < 0 and temp_pathname does not point to storage that
+ needs to be freed. */
+
+ if (found_file < 0)
+ temp_pathname = NULL;
+
+ /* If not found, search the solib_search_path (if any). */
+ if (found_file < 0 && solib_search_path != NULL)
+ found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
+ in_pathname, O_RDONLY | O_BINARY, &temp_pathname);
/* If the search in gdb_sysroot failed, and the path name is
absolute at this point, make it relative. (openp will try and open the
file according to its absolute path otherwise, which is not what we want.)
Affects subsequent searches for this solib. */
- if (found_file < 0 && IS_ABSOLUTE_PATH (in_pathname))
+ if (found_file < 0 && IS_TARGET_ABSOLUTE_PATH (fskind, in_pathname))
{
/* First, get rid of any drive letters etc. */
- while (!IS_DIR_SEPARATOR (*in_pathname))
- in_pathname++;
+ while (!IS_TARGET_DIR_SEPARATOR (fskind, *in_pathname))
+ in_pathname++;
/* Next, get rid of all leading dir separators. */
- while (IS_DIR_SEPARATOR (*in_pathname))
- in_pathname++;
+ while (IS_TARGET_DIR_SEPARATOR (fskind, *in_pathname))
+ in_pathname++;
}
-
+
/* If not found, search the solib_search_path (if any). */
if (found_file < 0 && solib_search_path != NULL)
found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
in_pathname, O_RDONLY | O_BINARY, &temp_pathname);
-
+
/* If not found, next search the solib_search_path (if any) for the basename
only (ignoring the path). This is to allow reading solibs from a path
that differs from the opened path. */
if (found_file < 0 && solib_search_path != NULL)
found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
- lbasename (in_pathname), O_RDONLY | O_BINARY,
- &temp_pathname);
+ target_lbasename (fskind, in_pathname),
+ O_RDONLY | O_BINARY, &temp_pathname);
/* If not found, try to use target supplied solib search method */
if (found_file < 0 && ops->find_and_open_solib)
@@ -256,7 +356,7 @@ solib_find (char *in_pathname, int *fd)
OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY,
&temp_pathname);
- /* If not found, next search the inferior's $LD_LIBRARY_PATH
+ /* If not found, next search the inferior's $LD_LIBRARY_PATH
environment variable. */
if (found_file < 0 && gdb_sysroot_is_empty)
found_file = openp (get_in_environ (current_inferior ()->environment,
Index: src/gdb/arm-symbian-tdep.c
===================================================================
--- src.orig/gdb/arm-symbian-tdep.c 2010-04-24 11:53:11.000000000 +0100
+++ src/gdb/arm-symbian-tdep.c 2010-04-24 11:53:13.000000000 +0100
@@ -78,6 +78,10 @@ arm_symbian_init_abi (struct gdbarch_inf
corresponding ELF files on the host's filesystem. */
set_gdbarch_solib_symbols_extension (gdbarch, "sym");
+ /* Canonical paths on this target look like `c:\sys\bin\bar.dll',
+ for example. */
+ set_gdbarch_has_dos_based_file_system (gdbarch, 1);
+
set_solib_ops (gdbarch, &solib_target_so_ops);
}
Index: src/gdb/arm-wince-tdep.c
===================================================================
--- src.orig/gdb/arm-wince-tdep.c 2010-04-24 11:53:11.000000000 +0100
+++ src/gdb/arm-wince-tdep.c 2010-04-24 11:53:13.000000000 +0100
@@ -139,6 +139,10 @@ arm_wince_init_abi (struct gdbarch_info
/* Skip call to __gccmain that gcc places in main. */
set_gdbarch_skip_main_prologue (gdbarch, arm_wince_skip_main_prologue);
+
+ /* Canonical paths on this target look like `\Windows\coredll.dll',
+ for example. */
+ set_gdbarch_has_dos_based_file_system (gdbarch, 1);
}
static enum gdb_osabi
Index: src/gdb/i386-cygwin-tdep.c
===================================================================
--- src.orig/gdb/i386-cygwin-tdep.c 2010-04-24 11:53:11.000000000 +0100
+++ src/gdb/i386-cygwin-tdep.c 2010-04-24 11:53:13.000000000 +0100
@@ -235,6 +235,10 @@ i386_cygwin_init_abi (struct gdbarch_inf
(gdbarch, windows_core_xfer_shared_libraries);
set_gdbarch_auto_wide_charset (gdbarch, i386_cygwin_auto_wide_charset);
+
+ /* Canonical paths on this target look like
+ `c:\Program Files\Foo App\mydll.dll', for example. */
+ set_gdbarch_has_dos_based_file_system (gdbarch, 1);
}
static enum gdb_osabi
Index: src/gdb/i386-tdep.c
===================================================================
--- src.orig/gdb/i386-tdep.c 2010-04-24 11:53:11.000000000 +0100
+++ src/gdb/i386-tdep.c 2010-04-24 11:53:13.000000000 +0100
@@ -2947,6 +2947,8 @@ i386_go32_init_abi (struct gdbarch_info
set_gdbarch_sdb_reg_to_regnum. */
set_gdbarch_stab_reg_to_regnum (gdbarch, i386_svr4_reg_to_regnum);
set_gdbarch_sdb_reg_to_regnum (gdbarch, i386_svr4_reg_to_regnum);
+
+ set_gdbarch_has_dos_based_file_system (gdbarch, 1);
}
\f
Index: src/gdb/gdbarch.sh
===================================================================
--- src.orig/gdb/gdbarch.sh 2010-04-24 11:53:11.000000000 +0100
+++ src/gdb/gdbarch.sh 2010-04-24 11:53:13.000000000 +0100
@@ -782,6 +782,11 @@ f:const char *:auto_wide_charset:void::d
# where the names of the files run on the target differ in extension
# compared to the names of the files GDB should load for debug info.
v:const char *:solib_symbols_extension:::::::pstring (gdbarch->solib_symbols_extension)
+
+# If true, the target OS has DOS-based file system semantics. That
+# is, absolute paths include a drive name, and the backslash is
+# considered a directory separator.
+v:int:has_dos_based_file_system:::0:0::0
EOF
}
Index: src/gdb/NEWS
===================================================================
--- src.orig/gdb/NEWS 2010-04-24 11:53:11.000000000 +0100
+++ src/gdb/NEWS 2010-04-24 11:53:13.000000000 +0100
@@ -51,8 +51,24 @@ qGetTIBAddr
its argument, limiting the functions selected by the regex to those
in the specified file.
+* Support for remote debugging Windows and SymbianOS shared libraries
+ from Unix hosts has been improved. Non Windows GDB builds now can
+ understand target reported file names that follow MS-DOS based file
+ system semantics, such as file names that include drive letters and
+ use the backslash character as directory separator. This makes it
+ possible to transparently use the "set sysroot" and "set
+ solib-search-path" on Unix hosts to point as host copies of the
+ target's shared libraries. See the new command "set
+ target-file-system-kind" described below, and the "Commands to
+ specify files" section in the user manual for more information.
+
* New commands
+set target-file-system-kind unix|dos-based|auto
+show target-file-system-kind
+ Set or show the assumed file system kind for target reported file
+ names.
+
save breakpoints <filename>
Save all current breakpoint definitions to a file suitable for use
in a later debugging session. To read the saved breakpoint
Index: src/gdb/doc/gdb.texinfo
===================================================================
--- src.orig/gdb/doc/gdb.texinfo 2010-04-24 11:53:11.000000000 +0100
+++ src/gdb/doc/gdb.texinfo 2010-04-24 12:04:42.000000000 +0100
@@ -14404,6 +14404,58 @@ The part of @var{path} following the ini
that happens to be named @file{remote:}, you need to use some equivalent
variant of the name like @file{./remote:}.}
+For targets with an MS-DOS based filesystem, such as MS-Windows and
+SymbianOS, @value{GDBN} tries prefixing a few variants of the target
+absolute file name with @var{path}. But first, on Unix hosts,
+@value{GDBN} converts all backslash directory separators into forward
+slashes, because the backslash is not a directory separator on Unix:
+
+@smallexample
+ c:\foo\bar.dll @result{} c:/foo/bar.dll
+@end smallexample
+
+Then, @value{GDBN} attempts prefixing the target file name with
+@var{path}, and look for the resulting file name in the host file
+system:
+
+@smallexample
+ c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
+@end smallexample
+
+If that does not find the shared library, @value{GDBN} tries removing
+the @samp{:} character from the drive spec, both for convenience, and,
+for the case of the host file system not supporting file names with
+colons:
+
+@smallexample
+ c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
+@end smallexample
+
+This makes it possible to have a system root that mirrors a target
+with more than one drive. E.g., you may want to setup your local
+copies of the target system shared libraries like so (note @samp{c} vs
+@samp{z}):
+
+@smallexample
+ @file{/path/to/sysroot/c/sys/bin/foo.dll}
+ @file{/path/to/sysroot/c/sys/bin/bar.dll}
+ @file{/path/to/sysroot/z/sys/bin/bar.dll}
+@end smallexample
+
+and point the system root at @file{/path/to/sysroot}, so that
+@value{GDBN} can find the correct copies of both
+@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
+
+If that still does not find the shared library, @value{GDBN} tries
+removing the whole drive spec from the target file name:
+
+@smallexample
+ c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
+@end smallexample
+
+This last lookup makes it possible to not care about the drive name,
+if you don't want or need to.
+
The @code{set solib-absolute-prefix} command is an alias for @code{set
sysroot}.
@@ -14435,6 +14487,55 @@ of shared library symbols.
@kindex show solib-search-path
@item show solib-search-path
Display the current shared library search path.
+
+@cindex DOS file-name semantics of file names.
+@kindex set target-file-system-kind (unix|dos-based|auto)
+@kindex show target-file-system-kind
+@item set target-file-system-kind @var{kind}
+Set assumed file system kind for target reported file names.
+
+Shared library file names as reported by the target system may not
+make sense as is on the system @value{GDBN} is running on. For
+example, when remote debugging a target that has MS-DOS based file
+system semantics, from a Unix host, the target may be reporting to
+@value{GDBN} a list of loaded shared libraries with file names such as
+@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
+drive letters, so the @samp{c:\} prefix is not normally understood as
+indicating an absolute file name, and neither is the backslash
+normally considered a directory separator character. In that case,
+the native file system would interpret this whole absolute file name
+as a relative file name with no directory components. This would make
+it impossible to point @value{GDBN} at a copy of the remote target's
+shared libraries on the host using @code{set sysroot}, and impractical
+with @code{set solib-search-path}. Setting
+@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
+to interpret such file names similarly to how the target would, and to
+map them to file names valid on @value{GDBN}'s native file system
+semantics. The value of @var{kind} can be @code{"auto"}, in addition
+to one of the supported file system kinds. In that case, @value{GDBN}
+tries to determine the appropriate file system variant based on the
+current target's operating system (@pxref{ABI, ,Configuring the
+Current ABI}). The supported file system settings are:
+
+@table @code
+@item unix
+Instruct @value{GDBN} to assume the target file system is of Unix
+kind. Only file names starting the forward slash (@samp{/}) character
+are considered absolute, and the directory separator character is also
+the forward slash.
+
+@item dos-based
+Instruct @value{GDBN} to assume the target file system is DOS based.
+File names starting with either a forward slash, or a drive letter
+followed by a colon (e.g., @samp{c:}), are considered absolute, and
+both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
+considered directory separators.
+
+@item auto
+Instruct @value{GDBN} to use the file system kind associated with the
+target operating system (@pxref{ABI, ,Configuring the Current ABI}).
+This is the default.
+@end table
@end table
Index: src/gdb/gdbarch.h
===================================================================
--- src.orig/gdb/gdbarch.h 2010-04-24 11:53:11.000000000 +0100
+++ src/gdb/gdbarch.h 2010-04-24 11:53:13.000000000 +0100
@@ -950,6 +950,13 @@ extern void set_gdbarch_auto_wide_charse
extern const char * gdbarch_solib_symbols_extension (struct gdbarch *gdbarch);
extern void set_gdbarch_solib_symbols_extension (struct gdbarch *gdbarch, const char * solib_symbols_extension);
+/* If true the target OS has DOS-based file system semantics. That is,
+ absolute paths include a drive name, and the backslash is considered
+ a path separator. */
+
+extern int gdbarch_has_dos_based_file_system (struct gdbarch *gdbarch);
+extern void set_gdbarch_has_dos_based_file_system (struct gdbarch *gdbarch, int has_dos_based_file_system);
+
/* Definition for an unknown syscall, used basically in error-cases. */
#define UNKNOWN_SYSCALL (-1)
Index: src/gdb/gdbarch.c
===================================================================
--- src.orig/gdb/gdbarch.c 2010-04-24 11:53:11.000000000 +0100
+++ src/gdb/gdbarch.c 2010-04-24 11:53:13.000000000 +0100
@@ -264,6 +264,7 @@ struct gdbarch
gdbarch_auto_charset_ftype *auto_charset;
gdbarch_auto_wide_charset_ftype *auto_wide_charset;
const char * solib_symbols_extension;
+ int has_dos_based_file_system;
};
@@ -411,6 +412,7 @@ struct gdbarch startup_gdbarch =
default_auto_charset, /* auto_charset */
default_auto_wide_charset, /* auto_wide_charset */
0, /* solib_symbols_extension */
+ 0, /* has_dos_based_file_system */
/* startup_gdbarch() */
};
@@ -682,6 +684,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of qsupported, invalid_p == 0 */
/* Skip verify of auto_charset, invalid_p == 0 */
/* Skip verify of auto_wide_charset, invalid_p == 0 */
+ /* Skip verify of has_dos_based_file_system, invalid_p == 0 */
buf = ui_file_xstrdup (log, &length);
make_cleanup (xfree, buf);
if (length > 0)
@@ -927,6 +930,9 @@ gdbarch_dump (struct gdbarch *gdbarch, s
"gdbarch_dump: get_syscall_number = <%s>\n",
host_address_to_string (gdbarch->get_syscall_number));
fprintf_unfiltered (file,
+ "gdbarch_dump: has_dos_based_file_system = %s\n",
+ plongest (gdbarch->has_dos_based_file_system));
+ fprintf_unfiltered (file,
"gdbarch_dump: has_global_breakpoints = %s\n",
plongest (gdbarch->has_global_breakpoints));
fprintf_unfiltered (file,
@@ -3676,6 +3682,23 @@ set_gdbarch_solib_symbols_extension (str
gdbarch->solib_symbols_extension = solib_symbols_extension;
}
+int
+gdbarch_has_dos_based_file_system (struct gdbarch *gdbarch)
+{
+ gdb_assert (gdbarch != NULL);
+ /* Skip verify of has_dos_based_file_system, invalid_p == 0 */
+ if (gdbarch_debug >= 2)
+ fprintf_unfiltered (gdb_stdlog, "gdbarch_has_dos_based_file_system called\n");
+ return gdbarch->has_dos_based_file_system;
+}
+
+void
+set_gdbarch_has_dos_based_file_system (struct gdbarch *gdbarch,
+ int has_dos_based_file_system)
+{
+ gdbarch->has_dos_based_file_system = has_dos_based_file_system;
+}
+
/* Keep a registry of per-architecture data-pointers required by GDB
modules. */
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts)
2010-04-24 11:18 ` Pedro Alves
@ 2010-04-24 11:40 ` Eli Zaretskii
2010-04-24 13:13 ` Pedro Alves
0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2010-04-24 11:40 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches, gcc-patches
> From: Pedro Alves <pedro@codesourcery.com>
> Date: Sat, 24 Apr 2010 12:17:46 +0100
> Cc: gcc-patches@gcc.gnu.org
>
> On Friday 23 April 2010 15:35:11, Eli Zaretskii wrote:
> > Not only is it clearer, it's in GNU coding standards, see my other
> > mail.
>
> Okay, I changed all user visible strings, I think.
Thanks.
> > No, it's clear enough. I just wondered why you didn't remove the
> > drive letter right away. I guess that's common practice in some
> > quarters to mount DOS-ish filesystems that way. I don't really mind
> > to support that if people are using it.
>
> Hope you don't mind, I ended up extending the docs here to
> explicitly explain why the lookup algorith is the way it is,
> so that users don't wonder the same you did.
I don't mind, of course. Thanks for the extra effort.
> I've moved that new target filesystem handling code to a
> new file, and, handled DJGPP's gdbarch.
Again, thanks.
> I think this updated patch addresses all your comments. Could
> you please take a new quick look at this?
It's fine, I have only 2 minor nits to report:
> +Then, @value{GDBN} attempts prefixing the target file name with
> +@var{path}, and look for the resulting file name in the host file
> +system: ^^^^
"looks"
> +@smallexample
> + @file{/path/to/sysroot/c/sys/bin/foo.dll}
> + @file{/path/to/sysroot/c/sys/bin/bar.dll}
> + @file{/path/to/sysroot/z/sys/bin/bar.dll}
> +@end smallexample
> +
> +and point the system root at @file{/path/to/sysroot}, so that
We need @noindent before the last line.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts)
2010-04-24 11:40 ` Eli Zaretskii
@ 2010-04-24 13:13 ` Pedro Alves
0 siblings, 0 replies; 11+ messages in thread
From: Pedro Alves @ 2010-04-24 13:13 UTC (permalink / raw)
To: gcc-patches, Eli Zaretskii; +Cc: gdb-patches
On Saturday 24 April 2010 12:40:38, Eli Zaretskii wrote:
> > +Then, @value{GDBN} attempts prefixing the target file name with
> > +@var{path}, and look for the resulting file name in the host file
> > +system: ^^^^
>
> "looks"
>
> > +@smallexample
> > + @file{/path/to/sysroot/c/sys/bin/foo.dll}
> > + @file{/path/to/sysroot/c/sys/bin/bar.dll}
> > + @file{/path/to/sysroot/z/sys/bin/bar.dll}
> > +@end smallexample
> > +
> > +and point the system root at @file{/path/to/sysroot}, so that
>
> We need @noindent before the last line.
>
Thank you. Applied with those fixes.
--
Pedro Alves
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2010-04-24 13:13 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-22 17:24 [gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts) Pedro Alves
2010-04-22 17:46 ` Daniel Jacobowitz
2010-04-23 8:54 ` Eli Zaretskii
2010-04-23 10:46 ` Pedro Alves
2010-04-23 11:15 ` Mark Kettenis
2010-04-23 14:30 ` Eli Zaretskii
2010-04-23 15:41 ` Mark Kettenis
2010-04-23 14:35 ` Eli Zaretskii
2010-04-24 11:18 ` Pedro Alves
2010-04-24 11:40 ` Eli Zaretskii
2010-04-24 13:13 ` Pedro Alves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox