[gdb/libiberty] Improve support for cross debugging shared libraries with DOS style pathnames (from Unix hosts)

Pedro Alves
2010-04-22T17:24:49Z

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. */