This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Build question
- From: Danny Backx <danny dot backx at scarlet dot be>
- To: Eli Zaretskii <eliz at gnu dot org>
- Cc: gdb at sourceware dot org
- Date: Sat, 05 Sep 2009 11:35:11 +0200
- Subject: Re: Build question
- References: <1250803105.11282.96.camel@pavilion> <m3fxbl2jib.fsf@fleche.redhat.com> <83d46pgjkq.fsf@gnu.org> <1250877901.11282.116.camel@pavilion> <83ab1tgh9h.fsf@gnu.org> <1250880746.11282.128.camel@pavilion> <m3r5v425lu.fsf@fleche.redhat.com> <1250931899.11282.142.camel@pavilion> <83skfkfa4n.fsf@gnu.org> <1251095160.16357.352.camel@pavilion> <1251828295.6106.119.camel@pavilion> <83zl9e8nro.fsf@gnu.org> <1251835928.6106.124.camel@pavilion> <83vdk281xb.fsf@gnu.org>
- Reply-to: danny dot backx at scarlet dot be
On Wed, 2009-09-02 at 06:23 +0300, Eli Zaretskii wrote:
> > From: Danny Backx <danny.backx@scarlet.be>
> > Cc: tromey@redhat.com, gdb@sourceware.org
> > Date: Tue, 01 Sep 2009 22:12:08 +0200
> >
> > Should I then look into :
> > - changing HAVE_DOS_BASED_FILE_SYSTEM into a variable
> > - doing the same thing for FILENAME_PREFIX_LEN and FILENAME_CMPN
>
> HAVE_DOS_BASED_FILE_SYSTEM should be controllable by a variable, and
> should then automatically DTRT with FILENAME_PREFIX_LEN. As for
> FILENAME_CMPN, I don't think it's appropriate for Posix systems to
> compare file names case-insensitively, so if you need that as well, I
> think a separate variable is in order.
ESR said "early and often", right ? Here is a first draft of my work.
Showing this early allows you to steer me in the right direction.
I've changed include/filenames.h and the gdb source files that contained
HAVE_DOS_BASED_FILE_SYSTEM to replace that by a variable.
Some surprises :
- libiberty also includes filenames.h
- filenames.h says it's part of bfd, so basing it on a global variable,
as I did, might have side effects
Otherwise, this code appears to work for me. I hardcoded the variable in
gdb/main.c, set this to both 0 and 1 for testing, and saw the expected
results.
Comments on all this welcome (e.g. I've left all this stuff in the
include file as inline functions, is this a bad idea?).
Also I left all the case sensitive stuff alone, and the also the
filename break characters, so HAVE_DOS_BASED_FILE_SYSTEM is still
present (gdb/symtab.c and gdb/completer.c).
Should I copy code that handles a variable like "solib-search-path" or
"annotate" to set the _have_dos_based_file_system at runtime ?
Danny
--
Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info
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 5 Sep 2009 09:23:13 -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/main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.77
diff -u -r1.77 main.c
--- gdb/main.c 27 Aug 2009 21:56:38 -0000 1.77
+++ gdb/main.c 5 Sep 2009 09:23:13 -0000
@@ -67,6 +67,9 @@
/* GDB datadir, used to store data files. */
char *gdb_datadir = 0;
+/* Filesystem type */
+int _have_dos_based_file_system = 1;
+
struct ui_file *gdb_stdout;
struct ui_file *gdb_stderr;
struct ui_file *gdb_stdlog;
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 5 Sep 2009 09:23:14 -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/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 5 Sep 2009 09:23:14 -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 5 Sep 2009 09:23:14 -0000
@@ -357,24 +357,26 @@
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);
Index: include/filenames.h
===================================================================
RCS file: /cvs/src/src/include/filenames.h,v
retrieving revision 1.5
diff -u -r1.5 filenames.h
--- include/filenames.h 21 Mar 2008 23:40:18 -0000 1.5
+++ include/filenames.h 5 Sep 2009 09:23:15 -0000
@@ -5,7 +5,7 @@
use forward- and back-slash in path names interchangeably, and
some of them have case-insensitive file names.
- Copyright 2000, 2001, 2007 Free Software Foundation, Inc.
+ Copyright 2000, 2001, 2007, 2009 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
@@ -30,25 +30,54 @@
extern "C" {
#endif
-#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__)
-
-#ifndef HAVE_DOS_BASED_FILE_SYSTEM
-#define HAVE_DOS_BASED_FILE_SYSTEM 1
+#ifndef FALSE
+#define FALSE 0
+#endif
+#ifndef TRUE
+#define TRUE 1
#endif
-#define IS_DIR_SEPARATOR(c) ((c) == '/' || (c) == '\\')
-/* Note that IS_ABSOLUTE_PATH accepts d:foo as well, although it is
- 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] == ':')))
-
-#else /* not DOSish */
+/*
+ * Defined in gdb/main.c
+ *
+ * This determines whether we have
+ * as a separator : / or \
+ * a prefix [a-z]: or not
+ * Replaces HAVE_DOS_BASED_FILE_SYSTEM and FILENAME_PREFIX_LEN.
+ *
+ * Case sensitive/insensitive file name comparison is *not* influenced by this.
+ */
+
+extern int _have_dos_based_file_system;
+
+static inline int _isalpha(int c)
+{
+ if (c <= 'Z' && c >= 'A')
+ return TRUE;
+ if (c <= 'z' && c >= 'a')
+ return TRUE;
+ return FALSE;
+}
-#define IS_DIR_SEPARATOR(c) ((c) == '/')
-#define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]))
+static inline int IS_DIR_SEPARATOR(int c)
+{
+ if (_have_dos_based_file_system) {
+ return (c == '/' || c == '\\');
+ } else {
+ return (c == '/');
+ }
+}
-#endif /* not DOSish */
+static inline int IS_ABSOLUTE_PATH(const char *f)
+{
+ if (IS_DIR_SEPARATOR(f[0]))
+ return TRUE;
+ if (_have_dos_based_file_system) {
+ if (_isalpha(f[0]) && f[1] == ':')
+ return TRUE;
+ }
+ return FALSE;
+}
extern int filename_cmp (const char *s1, const char *s2);
#define FILENAME_CMP(s1, s2) filename_cmp(s1, s2)