Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RE: [patch] IS_ABSOLUTE_PATH to handle both DOS and POSIX path st   yles
@ 2008-01-09 16:13 Aleksandar Ristovski
  2008-01-09 19:10 ` Eli Zaretskii
  0 siblings, 1 reply; 21+ messages in thread
From: Aleksandar Ristovski @ 2008-01-09 16:13 UTC (permalink / raw)
  To: Daniel Jacobowitz, Eli Zaretskii
  Cc: dje, gdb-patches, gcc-patches, Ryan Mansfield

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

^ permalink raw reply	[flat|nested] 21+ messages in thread
[parent not found: <2F6320727174C448A52CEB63D85D11F40A58@nova.ott.qnx.com>]
* RE: [patch] IS_ABSOLUTE_PATH to handle both DOS and POSIX path st  yles
@ 2008-01-04 19:26 Aleksandar Ristovski
  2008-01-04 19:33 ` Daniel Jacobowitz
  0 siblings, 1 reply; 21+ messages in thread
From: Aleksandar Ristovski @ 2008-01-04 19:26 UTC (permalink / raw)
  To: Aleksandar Ristovski, gdb-patches
  Cc: Daniel Jacobowitz, Joel Brobecker, Ryan Mansfield

Oops... the patch I submitted has a few typos. Sorry about that. Here is the
correct one.

This patch introduces new IS_DIR_SEPARATOR_? And IS_ABSOLUTE_PATH_? Macros.

Old macros IS_DIR_SEPARATOR and IS_ABSOLUTE_PATH continue to be configured
host dependent.

Please see http://sourceware.org/ml/gdb/2008-01/msg00021.html for details on
why this patch.

---
Aleksandar Ristovski
QNX Software Systems

ChangeLog:
2008-01-04  Aleksandar Ristovski  <aristovski@qnx.com>

        * filenames.h (IS_DIR_SEPARATOR_DOS): New macro.
        (IS_ABSOLUTE_PATH_DOS): New macro.
        (IS_DIR_SEPARATOR_X): New macro.
        (IS_ABSOLUTE_PATH_X): New macro.
        (IS_DIR_SEPARATOR_ANY): New macro.
        (IS_ABSOLUTE_PATH_ANY): New macro.


Index: include/filenames.h
===================================================================
RCS file: /cvs/src/src/include/filenames.h,v
retrieving revision 1.4
diff -u -3 -p -r1.4 filenames.h
--- include/filenames.h	29 Mar 2007 21:03:43 -0000	1.4
+++ include/filenames.h	4 Jan 2008 19:22:02 -0000
@@ -26,6 +26,23 @@ Foundation, Inc., 51 Franklin Street - F
 #ifndef FILENAMES_H
 #define FILENAMES_H
 
+/* For DOS style paths. Note that these macros do not recognize
+  path starting with '/' as an absolute path.  */
+
+#define IS_DIR_SEPARATOR_DOS(c)	  ((c) == '/' || (c) == '\\')
+#define IS_ABSOLUTE_PATH_DOS(f)	  (((f)[0]) && ((f)[1] == ':'))
+
+/* For POSIX style paths.  */
+
+#define IS_DIR_SEPARATOR_X(c)	  ((c) == '/')
+#define IS_ABSOLUTE_PATH_X(f)	  (IS_DIR_SEPARATOR_X((f)[0]))
+
+/* Universal macros, to be used on paths that could be either
+   POSIX or DOS.  */
+
+#define IS_DIR_SEPARATOR_ANY(c)	  (IS_DIR_SEPARATOR_DOS(c))
+#define IS_ABSOLUTE_PATH_ANY(f)	  (IS_ABSOLUTE_PATH_X(f) ||
IS_ABSOLUTE_PATH_DOS(f))
+
 #if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined
(__CYGWIN__)
 
 #ifndef HAVE_DOS_BASED_FILE_SYSTEM


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2008-01-10 14:01 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-09 16:13 [patch] IS_ABSOLUTE_PATH to handle both DOS and POSIX path st yles Aleksandar Ristovski
2008-01-09 19:10 ` Eli Zaretskii
2008-01-09 19:43   ` Daniel Jacobowitz
2008-01-10  4:13     ` Eli Zaretskii
2008-01-10 14:01       ` Daniel Jacobowitz
     [not found] <2F6320727174C448A52CEB63D85D11F40A58@nova.ott.qnx.com>
     [not found] ` <20080106054030.GA10410@caradoc.them.org>
2008-01-06 19:38   ` Eli Zaretskii
2008-01-06 20:03     ` Doug Evans
2008-01-06 20:18       ` Eli Zaretskii
2008-01-06 21:07         ` Doug Evans
2008-01-07  3:40           ` Daniel Jacobowitz
2008-01-07  4:21             ` Eli Zaretskii
2008-01-07 13:17               ` Daniel Jacobowitz
2008-01-07 21:28                 ` Eli Zaretskii
2008-01-07  4:18           ` Eli Zaretskii
2008-01-07 17:36             ` Doug Evans
2008-01-07 21:32               ` Eli Zaretskii
2008-01-07 21:36                 ` Daniel Jacobowitz
2008-01-08  4:25                   ` Eli Zaretskii
2008-01-08 13:47                     ` Daniel Jacobowitz
  -- strict thread matches above, loose matches on Subject: below --
2008-01-04 19:26 Aleksandar Ristovski
2008-01-04 19:33 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox