Hi all,

I have looked into the directory problem people find when using gdb or Insight built with Cygwin and the other mspgcc tools built with MinGW. In Insight, this shows up as an inability to see a pure source listing or source and assembly listings in separate windows.

A MinGW built binary contains file names like "c:\a\b\c\d.c", while a Cygwin binary contains file names like "/cygdrive/c/a/b/c/d.c". Gdb and Insight do not handle names like "c:\a\b\c\d.c" properly.

The symbol HAVE_DOS_BASED_FILE_SYSTEM should apparently be set for a Cygwin build, but it is not. Also, the code for opening a source file does not even attempt to handle DOS style file names properly. I don't have a deep enough knowledge of gdb to make a truly clean fix for this, but I do have a solution that works.

Unpack gdb or insight. Merge the MSP430 specific files. Run configure. Then add the line:

#define HAVE_DOS_BASED_FILE_SYSTEM 1

to the end of gdb-5.1.1/gdb/config.h and gdb-5.1.1/bfd/config.h. Now use the attached patch to modify gdb-5.1.1/gdb/source.c. If you are using Insight, those file names would begin with insight-5.1.1 instead of gdb-5.1.1. Now build the software, and source level debugging shoudl work OK. It does for me!

Regards,
Steve
--- source.c.orig       Wed Nov 27 20:39:00 2002
+++ source.c    Wed Nov 27 19:57:35 2002
@@ -746,19 +746,46 @@
 
 char *
 symtab_to_filename (struct symtab *s)
 {
   int fd;
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  char *p;
+  char *dir;
+#endif
 
   if (!s)
     return NULL;
 
   /* If we've seen the file before, just return fullname. */
 
   if (s->fullname)
     return s->fullname;
 
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  if (s->dirname)
+    {
+      for (p = s->dirname;  *p;  p++)
+        {
+          if (*p == '\\')
+            *p = DIRNAME_SEPARATOR;
+        }
+      if (s->dirname[0] != '\0'  &&  s->dirname[1] == ':')
+        {
+          dir = (char *) alloca (50 + 1 + strlen (s->dirname) + 1);
+          s->dirname[1] = '\0';
+          strcpy(dir, "/cygdrive/");
+          strcat(dir, s->dirname);
+          if (s->dirname[2] != DIRNAME_SEPARATOR)
+            strcat(dir, "/$cwd/");
+          strcat(dir, s->dirname + 2);
+          free(s->dirname);
+          s->dirname = dir;
+        }
+      }
+#endif
+ 
   /* Try opening the file to setup fullname */
 
   fd = open_source_file (s);
   if (fd < 0)
     return s->filename;                /* File not found.  Just use short name 
*/

Reply via email to