RE: [patch] IS_ABSOLUTE_PATH to handle both DOS and POSIX path st yles

Aleksandar Ristovski
2008-01-09T16:13:38Z

[-- Attachment #1: Type: text/plain, Size: 1645 bytes --]

> -----Original Message-----
> From: Daniel Jacobowitz [mailto:drow@false.org]
> Sent: January 8, 2008 8:47 AM
> To: Eli Zaretskii
> Cc: dje@google.com; gdb-patches@sources.redhat.com; Aleksandar Ristovski;
> gcc-patches@gcc.gnu.org; Ryan Mansfield
> Subject: Re: [patch] IS_ABSOLUTE_PATH to handle both DOS and POSIX path st
> yles
>
> On Tue, Jan 08, 2008 at 06:24:33AM +0200, Eli Zaretskii wrote:
> > Yes, but why does GDB want to know at startup something about start.S
> > and crtn.S?
>
> I believe we need this information when building psymtabs. If not, it
> may be because we need symbol information for the program entry point.
> One or the other.
>
> > Anyway, whatever problems can happen with these calls if we adopt my
> > suggestion of a user option, they already happen today. So there's
> > nothing to lose here.
>
> True.
>
> --
> Daniel Jacobowitz
> CodeSourcery

How about this approach:

We use option "substitute-path" to rewrite paths that we want to check for
IS_ABSOLUTE_PATH. The logic would be: gdb compares paths in a way native to
its configured host system, but user should provide rules for rewriting
non-native paths. For example, when debugging executable that has DOS paths
in debug info, substitute rule could be
C: /c
Users would, therefore, be responsible for providing the substitute rules if
they have a case of debugging binary compiled on a non-native file system.

(This only works for drive letter in DOS paths, doesn't address the dir.
Separator issue).

The attached patch is just to demonstrate the idea, it is not final
implementation.
Thanks,

Aleksandar Ristovski
QNX Software Systems

[-- Attachment #2: IS_ABSOLUTE_PATHpatch.diff --]
[-- Type: application/octet-stream, Size: 4395 bytes --]

Index: gdb/source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.83
diff -u -p -r1.83 source.c
--- gdb/source.c 1 Jan 2008 22:53:13 -0000 1.83
+++ gdb/source.c 9 Jan 2008 16:09:40 -0000
@@ -895,7 +895,7 @@ get_substitute_path_rule (const char *pa
Return NULL if no substitution rule was specified by the user,
or if no rule applied to the given PATH. */

-static char *
+char *
rewrite_source_path (const char *path)
{
const struct substitute_path_rule *rule = get_substitute_path_rule (path);
Index: gdb/source.h
===================================================================
RCS file: /cvs/src/src/gdb/source.h,v
retrieving revision 1.9
diff -u -p -r1.9 source.h
--- gdb/source.h 1 Jan 2008 22:53:13 -0000 1.9
+++ gdb/source.h 9 Jan 2008 16:09:40 -0000
@@ -20,6 +20,7 @@
#define SOURCE_H

struct symtab;
+struct partial_symtab;

/* Open a source file given a symtab S. Returns a file descriptor or
negative number for error. */
@@ -66,4 +67,7 @@ extern struct symtab_and_line set_curren

/* Reset any information stored about a default file and line to print. */
extern void clear_current_source_symtab_and_line (void);
+
+extern char *rewrite_source_path (const char *path);
+
#endif
Index: gdb/utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.184
diff -u -p -r1.184 utils.c
--- gdb/utils.c 1 Jan 2008 22:53:13 -0000 1.184
+++ gdb/utils.c 9 Jan 2008 16:09:40 -0000
@@ -34,6 +34,8 @@
#include <pc.h>
#endif

+#include "source.h"
+
/* SunOS's curses.h has a '#define reg register' in it. Thank you Sun. */
#ifdef reg
#undef reg
@@ -3223,3 +3225,21 @@ ldirname (const char *filename)
dirname[base - filename] = '\0';
return dirname;
}
+
+int
+is_absolute_path (const char *path)
+{
+ char *rwpath = rewrite_source_path (path);
+
+ if (rwpath == NULL)
+ rwpath = (char *) path;
+ else
+ make_cleanup (xfree, rwpath);
+
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ return IS_ABSOLUTE_PATH_DOS (rwpath);
+#else
+ return IS_ABSOLUTE_PATH_POSIX (rwpath);
+#endif
+
+}
Index: include/filenames.h
===================================================================
RCS file: /cvs/src/src/include/filenames.h,v
retrieving revision 1.4
diff -u -p -r1.4 filenames.h
--- include/filenames.h 29 Mar 2007 21:03:43 -0000 1.4
+++ include/filenames.h 9 Jan 2008 16:09:41 -0000
@@ -26,6 +26,22 @@ Foundation, Inc., 51 Franklin Street - F
#ifndef FILENAMES_H
#define FILENAMES_H

+/* For DOS style paths. */
+
+#define IS_DIR_SEPARATOR_DOS(c) ((c) == '/' || (c) == '\\')
+
+/*Note that IS_ABSOLUTE_PATH_DOS macro does not recognize
+ path starting with '/' as an absolute path. Otherwise, it behaves
+ as IS_DIR_SEPARATOR macro when configured for DOS-like
+ file system (see comment for IS_ABSOLUTE_PATH below). */
+
+#define IS_ABSOLUTE_PATH_DOS(f) (IS_DIR_SEPARATOR_DOS((f)[0]) || (((f)[0]) && ((f)[1] == ':')))
+
+/* For POSIX style paths. */
+
+#define IS_DIR_SEPARATOR_POSIX(c) ((c) == '/')
+#define IS_ABSOLUTE_PATH_POSIX(f) (IS_DIR_SEPARATOR_POSIX((f)[0]))
+
#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__)

#ifndef HAVE_DOS_BASED_FILE_SYSTEM
@@ -37,16 +53,19 @@ Foundation, Inc., 51 Franklin Street - F
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]) || (((f)[0]) && ((f)[1] == ':')))
+//#define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]) || (((f)[0]) && ((f)[1] == ':')))

#else /* not DOSish */

#define IS_DIR_SEPARATOR(c) ((c) == '/')
-#define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]))
+// #define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]))
+extern int is_absolute_path (const char *path);

#endif /* not DOSish */

extern int filename_cmp (const char *s1, const char *s2);
#define FILENAME_CMP(s1, s2) filename_cmp(s1, s2)

+extern int is_absolute_path (const char *path);
+#define IS_ABSOLUTE_PATH(f) is_absolute_path(f)
#endif /* FILENAMES_H */