Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Michael Fischer" <fischermi@t-online.de>
To: <gdb-patches@sourceware.org>
Subject: [PATCH] source.s: Fix problem handling windows like path with MinGW
Date: Sat, 17 Jun 2006 16:23:00 -0000	[thread overview]
Message-ID: <JLEAKDMELBINENLADICFKEFECIAA.fischermi@t-online.de> (raw)

Hello,

the patch below will fix the problem if an application sends path
information like "d:\foo1\foo2" instead of "/d/foo1/foo2"

I has some problem to get Eclipse running with a MinGW based arm toolchain.
The debugger could not find the source information.

I have change the openp function which try to find a file given by string
and searching in path.

Here are some examples how the path could look like:

1. "D:\Projekte\Eclipse\Test:$cwd"
2.
"D:\Projekte\Eclipse\Test:D:\Projekte\Eclipse\Test\src:D:\Projekte\Eclipse\T
est\inc:$cwd"

The problem is, that the DIRNAME_SEPARATOR is used to separate
path part-one from path part-two and so on. In case #1
"D:\Projekte\Eclipse\STR7Test"
from "$cwd". At the same time DIRNAME_SEPARATOR  is used to separate
the drive from the path itself <drive>:<path>.

If the application send only path information like:

3. "/D/Projekte/Eclipse/Test:$cwd"
4.
"/D/Projekte/Eclipse/Test:/D/Projekte/Eclipse/Test/src:/D/Projekte/Eclipse/T
est/inc:$cwd"

the old implementation is working, here we can use the DIRNAME_SEPARATOR
to separate each path from another. But for #1 we got
"\Projekte\Eclipse\Test", the drive
information is missing here. The additional code should handle the problem.

I have done the diff against gdb-6.5.50.20060615.tar.bz2, sorry I do not
know how
can I make a diff against the cvs tree.

Please check it, specially if it is allowed to use alloca more than one
time.

Can someone take it to the CVS if this patch is axactable?

Best regards,

Michael
PS: This is my first patch here, therefore I could use the wrong style for
it.
Please correct me.



diff -Naur gdb-6.5.50.20060615/gdb/source.c
gdb-6.5.50.20060615-arm/gdb/source.c
--- gdb-6.5.50.20060615/gdb/source.c	Mon May 15 15:50:13 2006
+++ gdb-6.5.50.20060615-arm/gdb/source.c	Sat Jun 17 15:56:11 2006
@@ -721,6 +721,109 @@
   /* ./foo => foo */
   while (string[0] == '.' && IS_DIR_SEPARATOR (string[1]))
     string += 2;
+
+#ifdef __MINGW32__
+  alloclen = strlen (path) + strlen (string) + 2;
+  filename = alloca (alloclen);
+  fd = -1;
+
+  /*
+   * Special handling for a windows path.
+   * Here are some examples how the path could look like:
+   *
+   * 1. "D:\Projekte\Eclipse\Test:$cwd"
+   * 2.
"D:\Projekte\Eclipse\Test:D:\Projekte\Eclipse\Test\src:D:\Projekte\Eclipse\T
est\inc:$cwd"
+   *
+   * The problem is, that the DIRNAME_SEPARATOR is used to separate
+   * path one from path two and so on. In case #1
"D:\Projekte\Eclipse\STR7Test"
+   * from "$cwd". At the same time DIRNAME_SEPARATOR  is used to separate
+   * the drive from the path itself <drive>:<path>.
+   *
+   * If the application send only path information like:
+   *
+   * 3. "/D/Projekte/Eclipse/Test:$cwd"
+   * 4.
"/D/Projekte/Eclipse/Test:/D/Projekte/Eclipse/Test/src:/D/Projekte/Eclipse/T
est/inc:$cwd"
+   *
+   * the old implementation is working, here we can use the
DIRNAME_SEPARATOR
+   * to separate each path from another. But for #1 we got
"\Projekte\Eclipse\Test", the drive
+   * information is missing here. The additional code should handle the
problem.
+   */
+  p = path;
+  while (*p != 0)
+  {
+    if (IS_ABSOLUTE_PATH(p))
+    {
+      /* Start to extract the path */
+
+      /* Copy the  <drive> and DIRNAME_SEPARATOR */
+      strncpy(filename, path, 2);
+      p   = p + 2;
+      len = 2;
+
+      /* Copy the rest up to the next DIRNAME_SEPARATOR */
+      while ((*p != DIRNAME_SEPARATOR) && (len < alloclen))
+      {
+        filename[len++] = *p++;
+      }
+      filename[len] = 0;
+
+      /* At this point we have the path
+         information and can add the string */
+      strcat (filename, SLASH_STRING);
+      strcat (filename, string);
+
+      /* Jump over the ":",
+         for the next round */
+      p++;
+    }
+    else
+    {
+      /* No absolute path found, this could be the current dir
+         or a mix of windows style and the other one */
+	    len = strlen (p);
+      if (len == 4 && p[0] == '$' && p[1] == 'c' && p[2] == 'w' && p[3] ==
'd')
+	    {
+	      /* Name is $cwd -- insert current directory name instead.  */
+	      int newlen;
+
+	      /* First, realloc the filename buffer if too short. */
+	      len = strlen (current_directory);
+	      newlen = len + strlen (string) + 2;
+	      if (newlen > alloclen)
+	      {
+	        alloclen = newlen;
+	        filename = alloca (alloclen);
+	      }
+	      strcpy (filename, current_directory);
+        strcat (filename, SLASH_STRING);
+        strcat (filename, string);
+
+        /* Jump over the $cwd, p should no point to the
+           end (*p==0), and we will leave the loop after
+           the last filename check */
+        p += 4;
+      }
+      else
+      {
+        /* It was not the $cwd, we does not handle this
+           situation, leave the loop */
+        break;
+      }
+    } /* end if (IS_ABSOLUTE_PATH(p))*/
+
+    /* We have a filename and can check it */
+    if (is_regular_file (filename))
+	  {
+	    fd = open (filename, mode);
+	    if (fd >= 0)
+      {
+        /* We have found the file */
+	      goto done;
+      }
+	  }
+
+  } /* while (*p != 0) */
+#endif /* __MINGW32__ */

   alloclen = strlen (path) + strlen (string) + 2;
   filename = alloca (alloclen);



             reply	other threads:[~2006-06-17 16:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-17 16:23 Michael Fischer [this message]
2006-06-17 19:45 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=JLEAKDMELBINENLADICFKEFECIAA.fischermi@t-online.de \
    --to=fischermi@t-online.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox