bfd patch for gdb cross-debugging support

Danny Backx danny.backx@scarlet.be
Sun Sep 13 19:40:00 GMT 2009


Hi,

When using gdb as a cross-debugger from e.g. a linux development pc to a
windows ce target (e.g. an embedded system), the source and target can
have different filesystem naming standards.

This causes gdb to have trouble locating the right file on the host, to
match the DLL loaded on the target : a path such as
  \network\x86\libgcc_s_sjlj-1.dll
doesn't get translated into
  /opt/x86mingw32ce/bin/libgcc_s_sjlj-1.dll
so some of the functionality in gdb doesn't work.

The cause lies in macros in include/filenames.h which gdb inherits from
bfd. I'm including a proposed patch that has been created with guidance
from the gdb maintainers. But obviously this is on your territory.

The included patch is spread over three files. I am presenting only the
gdb-diff-dos-3-bfd to you, the others are included for you to understand
what this fits into.

Is this the way to handle this type of change ?

Please comment, I'm prepared to do the extra work necessary to make this
fit into everyone's standards.

Thanks,

	Danny
-- 
Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gdb-diff-dos-3-bfd
Type: text/x-patch
Size: 4598 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20090913/bb629a12/attachment.bin>
-------------- next part --------------
? gdb/i386-wince-tdep.c
? gdb/i386-wince-tdep.h
? gdb/gdbserver/win32-low.c.mine
Index: gdb/completer.c
===================================================================
RCS file: /cvs/src/src/gdb/completer.c,v
retrieving revision 1.34
diff -u -r1.34 completer.c
--- gdb/completer.c	25 Mar 2009 10:50:56 -0000	1.34
+++ gdb/completer.c	13 Sep 2009 19:35:22 -0000
@@ -232,13 +232,12 @@
 	  else
 	    break;		/* Hit the end of text.  */
 	}
-#if HAVE_DOS_BASED_FILE_SYSTEM
       /* If we have a DOS-style absolute file name at the beginning of
 	 TEXT, and the colon after the drive letter is the only colon
 	 we found, pretend the colon is not there.  */
-      else if (p < text + 3 && *p == ':' && p == text + 1 + quoted)
+      else if (have_dos_based_file_system
+            && p < text + 3 && *p == ':' && p == text + 1 + quoted)
 	;
-#endif
       else if (*p == ':' && !colon)
 	{
 	  colon = p;
Index: gdb/configure.tgt
===================================================================
RCS file: /cvs/src/src/gdb/configure.tgt,v
retrieving revision 1.224
diff -u -r1.224 configure.tgt
--- gdb/configure.tgt	6 Aug 2009 10:28:38 -0000	1.224
+++ gdb/configure.tgt	13 Sep 2009 19:35:22 -0000
@@ -220,6 +220,12 @@
 			solib-target.o corelow.o windows-tdep.o"
 	build_gdbserver=yes
 	;;
+i[34567]86-*-mingw32ce)
+	# Target: Intel 386 running Windows CE
+	gdb_target_obs="i386-tdep.o i386-wince-tdep.o i387-tdep.o \
+			solib-target.o corelow.o windows-tdep.o"
+	build_gdbserver=yes
+	;;
 i[34567]86-*-mingw32*)
 	# Target: Intel 386 running win32
 	gdb_target_obs="i386-tdep.o i386-cygwin-tdep.o i387-tdep.o \
Index: gdb/source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.103
diff -u -r1.103 source.c
--- gdb/source.c	23 Jul 2009 23:20:00 -0000	1.103
+++ gdb/source.c	13 Sep 2009 19:35:22 -0000
@@ -474,14 +474,20 @@
       /* name is the start of the directory.
 	 p is the separator (or null) following the end.  */
 
-      while (!(IS_DIR_SEPARATOR (*name) && p <= name + 1)	/* "/" */
-#ifdef HAVE_DOS_BASED_FILE_SYSTEM
-      /* On MS-DOS and MS-Windows, h:\ is different from h: */
-	     && !(p == name + 3 && name[1] == ':')		/* "d:/" */
-#endif
-	     && IS_DIR_SEPARATOR (p[-1]))
-	/* Sigh. "foo/" => "foo" */
-	--p;
+      if (have_dos_based_file_system) {
+        while (!(IS_DIR_SEPARATOR (*name) && p <= name + 1)	/* "/" */
+        /* On MS-DOS and MS-Windows, h:\ is different from h: */
+	       && !(p == name + 3 && name[1] == ':')		/* "d:/" */
+	       && IS_DIR_SEPARATOR (p[-1]))
+	  /* Sigh. "foo/" => "foo" */
+	  --p;
+      } else {
+        while (!(IS_DIR_SEPARATOR (*name) && p <= name + 1)	/* "/" */
+        /* On MS-DOS and MS-Windows, h:\ is different from h: */
+	       && IS_DIR_SEPARATOR (p[-1]))
+	  /* Sigh. "foo/" => "foo" */
+	  --p;
+      }
       *p = '\0';
 
       while (p > name && p[-1] == '.')
@@ -514,10 +520,9 @@
 
       if (name[0] == '~')
 	name = tilde_expand (name);
-#ifdef HAVE_DOS_BASED_FILE_SYSTEM
-      else if (IS_ABSOLUTE_PATH (name) && p == name + 2) /* "d:" => "d:." */
+      else if (have_dos_based_file_system
+	    && IS_ABSOLUTE_PATH (name) && p == name + 2) /* "d:" => "d:." */
 	name = concat (name, ".", (char *)NULL);
-#endif
       else if (!IS_ABSOLUTE_PATH (name) && name[0] != '$')
 	name = concat (current_directory, SLASH_STRING, name, (char *)NULL);
       else
Index: gdb/top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.170
diff -u -r1.170 top.c
--- gdb/top.c	31 Aug 2009 20:18:45 -0000	1.170
+++ gdb/top.c	13 Sep 2009 19:35:23 -0000
@@ -52,6 +52,9 @@
 #include "readline/readline.h"
 #include "readline/history.h"
 
+/* libiberty include, for have_dos_based_file_system */
+#include "filenames.h"
+
 /* readline defines this.  */
 #undef savestring
 
@@ -676,6 +679,15 @@
 		    value);
 }
 
+static void
+show_dos_based_file_system (struct ui_file *file, int from_tty,
+		       struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("\
+Whether the target has a DOS based file system is \"%s\".\n"),
+		    value);
+}
+
 /* This is like readline(), but it has some gdb-specific behavior.
    gdb may want readline in both the synchronous and async modes during
    a single gdb invocation.  At the ordinary top-level prompt we might
@@ -1630,6 +1642,16 @@
 			    show_history_filename,
 			    &sethistlist, &showhistlist);
 
+  add_setshow_boolean_cmd ("dos_based_file_system", class_support,
+			    &have_dos_based_file_system, _("\
+Set whether the target has a DOS based file system"), _("\
+Show whether the target has a DOS based file system"), _("\
+whether the target has a DOS based file system"), NULL,
+			    show_dos_based_file_system,
+			    &setlist, &showlist);
+
+  have_dos_based_file_system = 1;	/* FIX ME */
+
   add_setshow_boolean_cmd ("confirm", class_support, &caution, _("\
 Set whether to confirm potentially dangerous operations."), _("\
 Show whether to confirm potentially dangerous operations."), NULL,
Index: gdb/utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.219
diff -u -r1.219 utils.c
--- gdb/utils.c	18 Aug 2009 16:17:16 -0000	1.219
+++ gdb/utils.c	13 Sep 2009 19:35:23 -0000
@@ -3280,15 +3280,14 @@
   strncpy (dir_name, filename, base_name - filename);
   dir_name[base_name - filename] = '\000';
 
-#ifdef HAVE_DOS_BASED_FILE_SYSTEM
   /* We need to be careful when filename is of the form 'd:foo', which
      is equivalent of d:./foo, which is totally different from d:/foo.  */
-  if (strlen (dir_name) == 2 && isalpha (dir_name[0]) && dir_name[1] == ':')
+  if (have_dos_based_file_system
+   && strlen (dir_name) == 2 && isalpha (dir_name[0]) && dir_name[1] == ':')
     {
       dir_name[2] = '.';
       dir_name[3] = '\000';
     }
-#endif
 
   /* Canonicalize the directory prefix, and build the resulting
      filename. If the dirname realpath already contains an ending
Index: gdb/cli/cli-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-cmds.c,v
retrieving revision 1.92
diff -u -r1.92 cli-cmds.c
--- gdb/cli/cli-cmds.c	11 Jul 2009 14:04:23 -0000	1.92
+++ gdb/cli/cli-cmds.c	13 Sep 2009 19:35:24 -0000
@@ -357,24 +357,27 @@
   if (chdir (dir) < 0)
     perror_with_name (dir);
 
-#ifdef HAVE_DOS_BASED_FILE_SYSTEM
   /* There's too much mess with DOSish names like "d:", "d:.",
      "d:./foo" etc.  Instead of having lots of special #ifdef'ed code,
      simply get the canonicalized name of the current directory.  */
-  dir = getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
-#endif
+  if (have_dos_based_file_system)
+    dir = getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
 
   len = strlen (dir);
   if (IS_DIR_SEPARATOR (dir[len - 1]))
     {
       /* Remove the trailing slash unless this is a root directory
          (including a drive letter on non-Unix systems).  */
-      if (!(len == 1)		/* "/" */
-#ifdef HAVE_DOS_BASED_FILE_SYSTEM
-	  && !(len == 3 && dir[1] == ':') /* "d:/" */
-#endif
-	  )
-	len--;
+      if (have_dos_based_file_system)
+        {
+          if (!(len == 1) /* "/" */ && !(len == 3 && dir[1] == ':') /* "d:/" */)
+	    len--;
+        }
+      else
+        {
+          if (!(len == 1))		/* "/" */
+	    len--;
+        }
     }
 
   dir = savestring (dir, len);


More information about the Binutils mailing list