Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch gdb]: Fix some DOS-path related issues in gdb
       [not found] <AANLkTi=QoOiBg3XmMv+hRNe8DkT2YiVGZ=7NhaQwzCey@mail.gmail.com>
@ 2011-03-03 12:10 ` Kai Tietz
  2011-03-03 13:24   ` Eli Zaretskii
  0 siblings, 1 reply; 37+ messages in thread
From: Kai Tietz @ 2011-03-03 12:10 UTC (permalink / raw)
  To: gdb-patches

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

Hello,

Sorry, first post were sent to wrong list. This patch fixes some
issues related to DOS file-system filenames and paths. I am not sure,
if I hit all places, nevertheless I am sure I hit most.
This patch uses the libiberty functions & macros about
directory-separator checks, absolute-path checks, and the
filename-comparision functions.

ChangeLog gdb/

2011-03-03  Kai Tietz

       * breakpoint.c (clear_command): Use filename_(n)cmp
       for source-file comparision.
       * bsd-kvm.c (bsd_kvm_open): Use IS_ABSOLUTE_PATH check
       for filename.
       (bsd_kvm_files_info): Use filename_cmp for core-file
       comparision.
       * buildsym.c (patch_subfile_names): Use IS_DIR_SEPRARATOR
       for trailing directory-separator check.
       (watch_main_source_file): Use filename_cmp for mainbase
       comparision.
       * dbxread.c (add_old_header_file): Use filename_cmp for file-name
       comparision.
       (read_dbx_symtab): Handle DOS path-separators. And use filename_cmp
       for filename comparision.
       * elfread.c (find_separate_debug_file_by_buildid): Use
       filename_cmp for object-filename comparision.
       (elfstab_offset_sections): Handle DOS path-separators. And use
       filename_cmp for filename comparision.
       * exec.c (exec_set_section_address): Use filename_cmp
       for file-name comparision.
       * macrotab.c (macro_lookup_inclusion): Likewise.
       * mdebugread.c (pase_partial_symbols): Handle DOS
       path-separators. And use filename_cmp for file-name comparision.
       * minsyms.c (lookup_minimal_symbol): Likewise.
       * nto-procfs.c (procfs_open): Likewise.
       * psymtab.c (read_psymtabs_with_filename): Use filename_cmp
       for file-name comparision.
       * remote-fileio.c (remote_fileio_extract_ptr_w_len): Handle
       DOS path-separators.
       (remote_fileio_func_rename): Use IS_DIR_SEPARATOR and filename_ncmp
       for path comparision.
       * rs6000-nat.c (add_vmap): Use filename_cmp for file-name comparision.
       * solib-som.c (match_main): Likewise.
       * solib.c (solib_read_symbols): Likewise.
       (reload_shared_libraries_1): Likewise.
       * source.c (add_path): Use filename_ncmp for path comparision.
       * symfile.c (separate_debug_file_exists): Use filename_(n)cmp for
       filename comparision.
       (separate_debug_file_exists): Likewise.
       (find_separate_debug_file_by_debuglink): Likewise.
       (reread_symbols): Likewise.
       * symmisc.c (maintenance_print_symbols): Likewise.
       * symtab.c (filename_seen): Likewise.
       (file_matches): Likewise.
       (print_symbol_info): Likewise.
       (not_interesting_fname): Likewise.
       (maybe_add_partial_symtab_filename): Likewise.
       (make_source_files_completion_list): Likewise.
       * xcoffread.c (process_linenos): Likewise.
       (scan_xcoff_symtab): Likewise.
       * xml-support.c (fetch_xml_builtin): Likewise.
       * xml-syscall.c (init_sysinfo): Likewise.
       * coffread.c (coff_getfilename): Handle DOS path-separators.
       * dwarf2read.c (find_file_and_directory): Handle DOS absolute
       paths.
       * fbsd-nat.c (fbsd_make_corefile_notes): Handle DOS path-separators.
       * linux-fork.c (info_checkpoints_command): Likewise.
       * linux-nat.c (linux_nat_make_corefile_notes): Likewise.
       * linux-thread-db.c (try_thread_db_load): Likewise.
       * nto-tdep.c (nto_find_and_open_solib): Likewise.
       * windows-nat.c (_initialize_check_for_gdb_ini): Use
       IS_DIR_SEPARATOR for path-separator check.

Patch was tested for x86_64-w64-mingw32, i686-pc-cygwin, and
x86_64-pc-linux-gnu. Ok for apply?

Regards,
Kai

[-- Attachment #2: gdb_filename.txt --]
[-- Type: text/plain, Size: 33348 bytes --]

Index: gdb/breakpoint.c
===================================================================
--- gdb.orig/breakpoint.c	2011-03-01 09:03:20.000000000 +0100
+++ gdb/breakpoint.c	2011-03-02 12:12:40.027913000 +0100
@@ -39,6 +39,7 @@
 #include "language.h"
 #include "gdb_string.h"
 #include "demangle.h"
+#include "filenames.h"
 #include "annotate.h"
 #include "symfile.h"
 #include "objfiles.h"
@@ -9510,8 +9511,8 @@ clear_command (char *arg, int from_tty)
 				    && b->source_file != NULL
 				    && sal.symtab != NULL
 				    && sal.pspace == loc->pspace
-				    && strcmp (b->source_file,
-					       sal.symtab->filename) == 0
+				    && filename_cmp (b->source_file,
+						     sal.symtab->filename) == 0
 				    && b->line_number == sal.line);
 		  if (pc_match || line_match)
 		    {
Index: gdb/bsd-kvm.c
===================================================================
--- gdb.orig/bsd-kvm.c	2011-01-07 20:36:15.000000000 +0100
+++ gdb/bsd-kvm.c	2011-03-03 10:48:54.750280700 +0100
@@ -36,6 +36,7 @@
 #endif
 #include <paths.h>
 #include "readline/readline.h"
+#include "filenames.h"
 #include <sys/param.h>
 #include <sys/proc.h>
 #include <sys/user.h>
@@ -77,7 +78,7 @@ bsd_kvm_open (char *filename, int from_t
       char *temp;
 
       filename = tilde_expand (filename);
-      if (filename[0] != '/')
+      if (!IS_ABSOLUTE_PATH (filename))
 	{
 	  temp = concat (current_directory, "/", filename, (char *)NULL);
 	  xfree (filename);
@@ -151,7 +152,7 @@ bsd_kvm_xfer_partial (struct target_ops
 static void
 bsd_kvm_files_info (struct target_ops *ops)
 {
-  if (bsd_kvm_corefile && strcmp (bsd_kvm_corefile, _PATH_MEM) != 0)
+  if (bsd_kvm_corefile && filename_cmp (bsd_kvm_corefile, _PATH_MEM) != 0)
     printf_filtered (_("\tUsing the kernel crash dump %s.\n"),
 		     bsd_kvm_corefile);
   else
Index: gdb/buildsym.c
===================================================================
--- gdb.orig/buildsym.c	2011-01-05 23:22:47.000000000 +0100
+++ gdb/buildsym.c	2011-03-03 10:45:56.543151200 +0100
@@ -643,7 +643,7 @@ void
 patch_subfile_names (struct subfile *subfile, char *name)
 {
   if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
-      && subfile->name[strlen (subfile->name) - 1] == '/')
+      && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
     {
       subfile->dirname = subfile->name;
       subfile->name = xstrdup (name);
@@ -878,7 +878,7 @@ watch_main_source_file_lossage (void)
 	   subfile->next;
 	   subfile = subfile->next)
 	{
-	  if (strcmp (lbasename (subfile->name), mainbase) == 0)
+	  if (filename_cmp (lbasename (subfile->name), mainbase) == 0)
 	    {
 	      ++nr_matches;
 	      mainsub_alias = subfile;
Index: gdb/dbxread.c
===================================================================
--- gdb.orig/dbxread.c	2011-03-01 09:03:20.000000000 +0100
+++ gdb/dbxread.c	2011-03-03 10:56:14.497121400 +0100
@@ -47,6 +47,7 @@
 #include "target.h"
 #include "gdbcore.h"		/* for bfd stuff */
 #include "libaout.h"		/* FIXME Secret internal BFD stuff for a.out */
+#include "filenames.h"
 #include "objfiles.h"
 #include "buildsym.h"
 #include "stabsread.h"
@@ -346,7 +347,7 @@ add_old_header_file (char *name, int ins
   int i;
 
   for (i = 0; i < N_HEADER_FILES (current_objfile); i++)
-    if (strcmp (p[i].name, name) == 0 && instance == p[i].instance)
+    if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
       {
 	add_this_object_header_file (i);
 	return;
@@ -1531,6 +1532,13 @@ read_dbx_symtab (struct objfile *objfile
 	       we assume the previous N_SO was a directory name.  */
 
 	    p = strrchr (namestring, '/');
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+	    {
+	      char *p2 = strrchr (namestring, '\\');
+	      if (!p || (p2 && p2 > p))
+	        p = p2;
+	    }
+#endif
 	    if (p && *(p + 1) == '\000')
 	      {
 		/* Save the directory name SOs locally, then save it into
@@ -1620,13 +1628,13 @@ read_dbx_symtab (struct objfile *objfile
 	       things like "break c-exp.y:435" need to work (I
 	       suppose the psymtab_include_list could be hashed or put
 	       in a binary tree, if profiling shows this is a major hog).  */
-	    if (pst && strcmp (namestring, pst->filename) == 0)
+	    if (pst && filename_cmp (namestring, pst->filename) == 0)
 	      continue;
 	    {
 	      int i;
 
 	      for (i = 0; i < includes_used; i++)
-		if (strcmp (namestring, psymtab_include_list[i]) == 0)
+		if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
 		  {
 		    i = -1;
 		    break;
Index: gdb/elfread.c
===================================================================
--- gdb.orig/elfread.c	2011-01-07 20:36:16.000000000 +0100
+++ gdb/elfread.c	2011-03-03 11:08:58.354118900 +0100
@@ -37,6 +37,7 @@
 #include "complaints.h"
 #include "demangle.h"
 #include "psympriv.h"
+#include "filenames.h"
 
 extern void _initialize_elfread (void);
 
@@ -704,7 +705,8 @@ find_separate_debug_file_by_buildid (str
       build_id_name = build_id_to_debug_filename (build_id);
       xfree (build_id);
       /* Prevent looping on a stripped .debug file.  */
-      if (build_id_name != NULL && strcmp (build_id_name, objfile->name) == 0)
+      if (build_id_name != NULL
+	  && filename_cmp (build_id_name, objfile->name) == 0)
         {
 	  warning (_("\"%s\": separate debug info file has no debug info"),
 		   build_id_name);
@@ -1005,7 +1007,15 @@ elfstab_offset_sections (struct objfile
 
   /* The ELF symbol info doesn't include path names, so strip the path
      (if any) from the psymtab filename.  */
-  while (0 != (p = strchr (filename, '/')))
+  p = strrchr (filename, '/');
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  {
+    char *p2 = strrchr (filename, '\\');
+    if (!p || (p2 && p2 > p))
+      p = p2;
+  }
+#endif
+  if (p)
     filename = p + 1;
 
   /* FIXME:  This linear search could speed up significantly
@@ -1014,7 +1024,7 @@ elfstab_offset_sections (struct objfile
   for (; maybe; maybe = maybe->next)
     {
       if (filename[0] == maybe->filename[0]
-	  && strcmp (filename, maybe->filename) == 0)
+	  && filename_cmp (filename, maybe->filename) == 0)
 	{
 	  /* We found a match.  But there might be several source files
 	     (from different directories) with the same name.  */
Index: gdb/exec.c
===================================================================
--- gdb.orig/exec.c	2011-02-17 22:19:31.000000000 +0100
+++ gdb/exec.c	2011-03-02 12:16:52.525976200 +0100
@@ -25,6 +25,7 @@
 #include "target.h"
 #include "gdbcmd.h"
 #include "language.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "completer.h"
@@ -845,7 +846,7 @@ exec_set_section_address (const char *fi
   table = current_target_sections;
   for (p = table->sections; p < table->sections_end; p++)
     {
-      if (strcmp (filename, p->bfd->filename) == 0
+      if (filename_cmp (filename, p->bfd->filename) == 0
 	  && index == p->the_bfd_section->index)
 	{
 	  p->endaddr += address - p->addr;
Index: gdb/macrotab.c
===================================================================
--- gdb.orig/macrotab.c	2011-01-09 04:20:33.000000000 +0100
+++ gdb/macrotab.c	2011-03-03 10:41:58.796961300 +0100
@@ -21,6 +21,7 @@
 #include "defs.h"
 #include "gdb_obstack.h"
 #include "splay-tree.h"
+#include "filenames.h"
 #include "symtab.h"
 #include "symfile.h"
 #include "objfiles.h"
@@ -500,7 +501,7 @@ struct macro_source_file *
 macro_lookup_inclusion (struct macro_source_file *source, const char *name)
 {
   /* Is SOURCE itself named NAME?  */
-  if (strcmp (name, source->filename) == 0)
+  if (filename_cmp (name, source->filename) == 0)
     return source;
 
   /* The filename in the source structure is probably a full path, but
@@ -510,11 +511,12 @@ macro_lookup_inclusion (struct macro_sou
     int src_name_len = strlen (source->filename);
 
     /* We do mean < here, and not <=; if the lengths are the same,
-       then the strcmp above should have triggered, and we need to
+       then the filename_cmp above should have triggered, and we need to
        check for a slash here.  */
     if (name_len < src_name_len
-        && source->filename[src_name_len - name_len - 1] == '/'
-        && strcmp (name, source->filename + src_name_len - name_len) == 0)
+        && IS_DIR_SEPARATOR (source->filename[src_name_len - name_len - 1])
+        && filename_cmp (name,
+			 source->filename + src_name_len - name_len) == 0)
       return source;
   }
 
Index: gdb/mdebugread.c
===================================================================
--- gdb.orig/mdebugread.c	2011-03-01 09:03:21.000000000 +0100
+++ gdb/mdebugread.c	2011-03-03 11:45:18.109912800 +0100
@@ -45,6 +45,7 @@
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "gdbcore.h"
+#include "filenames.h"
 #include "objfiles.h"
 #include "gdb_obstack.h"
 #include "buildsym.h"
@@ -3014,6 +3015,13 @@ parse_partial_symbols (struct objfile *o
 			 the previous N_SO was a directory name.  */
 
 		      p = strrchr (namestring, '/');
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+		      {
+			char *p2 = strrchr (namestring, '\\');
+			if (!p || (p2 && p2 > p))
+			  p = p2;
+		      }
+#endif
 		      if (p && *(p + 1) == '\000')
 			continue;		/* Simply ignore directory
 						   name SOs.  */
@@ -3065,15 +3073,15 @@ parse_partial_symbols (struct objfile *o
 			 work (I suppose the psymtab_include_list could be
 			 hashed or put in a binary tree, if profiling shows
 			 this is a major hog).  */
-		      if (pst && strcmp (namestring, pst->filename) == 0)
+		      if (pst && filename_cmp (namestring, pst->filename) == 0)
 			continue;
 
 		      {
 			int i;
 
 			for (i = 0; i < includes_used; i++)
-			  if (strcmp (namestring,
-				      psymtab_include_list[i]) == 0)
+			  if (filename_cmp (namestring,
+					    psymtab_include_list[i]) == 0)
 			    {
 			      i = -1;
 			      break;
Index: gdb/minsyms.c
===================================================================
--- gdb.orig/minsyms.c	2011-01-09 04:20:33.000000000 +0100
+++ gdb/minsyms.c	2011-03-03 10:37:55.989628700 +0100
@@ -43,6 +43,7 @@
 #include "gdb_string.h"
 #include "symtab.h"
 #include "bfd.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "demangle.h"
@@ -200,6 +201,13 @@ lookup_minimal_symbol (const char *name,
   if (sfile != NULL)
     {
       char *p = strrchr (sfile, '/');
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+      {
+	char *p2 = strrchr (sfile, '\\');
+	if (!p || (p2 && p2 > p))
+	  p = p2;
+      }
+#endif
 
       if (p != NULL)
 	sfile = p + 1;
@@ -260,7 +268,7 @@ lookup_minimal_symbol (const char *name,
                       case mst_file_data:
                       case mst_file_bss:
                         if (sfile == NULL
-			    || strcmp (msymbol->filename, sfile) == 0)
+			    || filename_cmp (msymbol->filename, sfile) == 0)
                           found_file_symbol = msymbol;
                         break;
 
Index: gdb/nto-procfs.c
===================================================================
--- gdb.orig/nto-procfs.c	2011-01-11 16:10:01.000000000 +0100
+++ gdb/nto-procfs.c	2011-03-03 10:35:52.861993500 +0100
@@ -37,6 +37,7 @@
 #include "gdbcore.h"
 #include "inferior.h"
 #include "target.h"
+#include "filenames.h"
 #include "objfiles.h"
 #include "gdbthread.h"
 #include "nto-tdep.h"
@@ -149,7 +150,7 @@ procfs_open (char *arg, int from_tty)
 	}
       else if (*endstr)
 	{
-	  if (*(endstr - 1) == '/')
+	  if (IS_DIR_SEPARATOR (*(endstr - 1)))
 	    *(endstr - 1) = 0;
 	  else
 	    *endstr = 0;
@@ -545,7 +546,7 @@ procfs_meminfo (char *args, int from_tty
 	      if (err != EOK)
 		continue;
 
-	      if (strcmp (map.info.path, printme.name))
+	      if (filename_cmp (map.info.path, printme.name))
 		continue;
 
 	      /* Lower debug_vaddr is always text, if nessessary, swap.  */
Index: gdb/psymtab.c
===================================================================
--- gdb.orig/psymtab.c	2011-03-01 09:03:21.000000000 +0100
+++ gdb/psymtab.c	2011-03-02 11:02:58.109876900 +0100
@@ -946,7 +946,7 @@ read_psymtabs_with_filename (struct objf
 
   ALL_OBJFILE_PSYMTABS (objfile, p)
     {
-      if (strcmp (filename, p->filename) == 0)
+      if (filename_cmp (filename, p->filename) == 0)
 	PSYMTAB_TO_SYMTAB (p);
     }
 }
@@ -1614,7 +1614,7 @@ print-psymbols takes an output file name
 
   immediate_quit++;
   ALL_PSYMTABS (objfile, ps)
-    if (symname == NULL || strcmp (symname, ps->filename) == 0)
+    if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
     dump_psymtab (objfile, ps, outfile);
   immediate_quit--;
   do_cleanups (cleanups);
Index: gdb/remote-fileio.c
===================================================================
--- gdb.orig/remote-fileio.c	2011-02-17 22:19:31.000000000 +0100
+++ gdb/remote-fileio.c	2011-03-03 10:24:24.441575200 +0100
@@ -31,6 +31,7 @@
 #include "remote-fileio.h"
 #include "event-loop.h"
 #include "target.h"
+#include "filenames.h"
 
 #include <fcntl.h>
 #include <sys/time.h>
@@ -378,6 +379,15 @@ remote_fileio_extract_ptr_w_len (char **
   if (!buf || !*buf || !**buf || !ptrval || !length)
     return -1;
   c = strchr (*buf, '/');
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  {
+    char *c2 = strchr (*buf, '\\');
+    if (!c)
+      c = c2;
+    else if (c2 && c2 < c)
+      c = c2;
+  }
+#endif
   if (!c)
     return -1;
   *c++ = '\0';
@@ -1020,8 +1030,8 @@ remote_fileio_func_rename (char *buf)
 		  cygwin_conv_path (CCP_WIN_A_TO_POSIX, newpath, newfullpath,
 				    PATH_MAX);
 		  len = strlen (oldfullpath);
-		  if (newfullpath[len] == '/'
-		      && !strncmp (oldfullpath, newfullpath, len))
+		  if (IS_DIR_SEPARATOR (newfullpath[len])
+		      && !filename_ncmp (oldfullpath, newfullpath, len))
 		    errno = EINVAL;
 		  else
 		    errno = EEXIST;
Index: gdb/rs6000-nat.c
===================================================================
--- gdb.orig/rs6000-nat.c	2011-01-11 16:10:01.000000000 +0100
+++ gdb/rs6000-nat.c	2011-03-03 12:04:39.160347400 +0100
@@ -24,6 +24,7 @@
 #include "target.h"
 #include "gdbcore.h"
 #include "xcoffsolib.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "libbfd.h"		/* For bfd_default_set_arch_mach (FIXME) */
@@ -769,7 +770,7 @@ add_vmap (LdInfo *ldi)
       last = 0;
       /* FIXME??? am I tossing BFDs?  bfd?  */
       while ((last = bfd_openr_next_archived_file (abfd, last)))
-	if (strcmp (mem, last->filename) == 0)
+	if (filename_cmp (mem, last->filename) == 0)
 	  break;
 
       if (!last)
@@ -853,8 +854,8 @@ vmap_ldinfo (LdInfo *ldi)
 
 	  /* The filenames are not always sufficient to match on.  */
 
-	  if ((name[0] == '/' && strcmp (name, vp->name) != 0)
-	      || (memb[0] && strcmp (memb, vp->member) != 0))
+	  if ((name[0] == '/' && filename_cmp (name, vp->name) != 0)
+	      || (memb[0] && filename_cmp (memb, vp->member) != 0))
 	    continue;
 
 	  /* See if we are referring to the same file.
Index: gdb/solib-som.c
===================================================================
--- gdb.orig/solib-som.c	2011-01-14 19:39:31.000000000 +0100
+++ gdb/solib-som.c	2011-03-03 12:05:28.243580200 +0100
@@ -21,6 +21,7 @@
 #include "defs.h"
 #include "symtab.h"
 #include "bfd.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "gdbcore.h"
@@ -568,7 +569,7 @@ link_map_start (void)
 static int
 match_main (const char *name)
 {
-  return strcmp (name, symfile_objfile->name) == 0;
+  return filename_cmp (name, symfile_objfile->name) == 0;
 }
 
 static struct so_list *
Index: gdb/solib.c
===================================================================
--- gdb.orig/solib.c	2011-02-17 22:19:32.000000000 +0100
+++ gdb/solib.c	2011-03-02 11:06:29.717747700 +0100
@@ -638,7 +638,7 @@ solib_read_symbols (struct so_list *so,
 	  /* Have we already loaded this shared object?  */
 	  ALL_OBJFILES (so->objfile)
 	    {
-	      if (strcmp (so->objfile->name, so->so_name) == 0
+	      if (filename_cmp (so->objfile->name, so->so_name) == 0
 		  && so->objfile->addr_low == so->addr_low)
 		break;
 	    }
@@ -762,7 +762,7 @@ update_solib_list (int from_tty, struct
 	    }
 	  else
 	    {
-	      if (! strcmp (gdb->so_original_name, i->so_original_name))
+	      if (! filename_cmp (gdb->so_original_name, i->so_original_name))
 		break;	      
 	    }
 
@@ -1338,7 +1338,7 @@ reload_shared_libraries_1 (int from_tty)
 	 symbol file, close that.  */
       if ((found_pathname == NULL && was_loaded)
 	  || (found_pathname != NULL
-	      && strcmp (found_pathname, so->so_name) != 0))
+	      && filename_cmp (found_pathname, so->so_name) != 0))
 	{
 	  if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED))
 	    free_objfile (so->objfile);
@@ -1350,7 +1350,7 @@ reload_shared_libraries_1 (int from_tty)
 	 file, open it.  */
       if (found_pathname != NULL
 	  && (!was_loaded
-	      || strcmp (found_pathname, so->so_name) != 0))
+	      || filename_cmp (found_pathname, so->so_name) != 0))
 	{
 	  volatile struct gdb_exception e;
 
Index: gdb/source.c
===================================================================
--- gdb.orig/source.c	2011-01-11 22:53:24.000000000 +0100
+++ gdb/source.c	2011-03-02 11:08:29.324935900 +0100
@@ -569,15 +569,10 @@ add_path (char *dirname, char **which_pa
 	p = *which_path;
 	while (1)
 	  {
-	    /* FIXME: strncmp loses in interesting ways on MS-DOS and
-	       MS-Windows because of case-insensitivity and two different
-	       but functionally identical slash characters.  We need a
-	       special filesystem-dependent file-name comparison function.
-
-	       Actually, even on Unix I would use realpath() or its work-
+	    /* Actually, even on Unix I would use realpath() or its work-
 	       alike before comparing.  Then all the code above which
 	       removes excess slashes and dots could simply go away.  */
-	    if (!strncmp (p, name, len)
+	    if (!filename_ncmp (p, name, len)
 		&& (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR))
 	      {
 		/* Found it in the search path, remove old copy.  */
Index: gdb/symfile.c
===================================================================
--- gdb.orig/symfile.c	2011-03-01 09:03:22.000000000 +0100
+++ gdb/symfile.c	2011-03-02 09:40:42.156590400 +0100
@@ -1317,7 +1317,7 @@ separate_debug_file_exists (const char *
      ".debug" suffix as "/usr/lib/debug/path/to/file" is a separate tree where
      the separate debug infos with the same basename can exist.  */
 
-  if (strcmp (name, parent_objfile->name) == 0)
+  if (filename_cmp (name, parent_objfile->name) == 0)
     return 0;
 
   abfd = bfd_open_maybe_remote (name);
@@ -1325,7 +1325,7 @@ separate_debug_file_exists (const char *
   if (!abfd)
     return 0;
 
-  /* Verify symlinks were not the cause of strcmp name difference above.
+  /* Verify symlinks were not the cause of filename_cmp name difference above.
 
      Some operating systems, e.g. Windows, do not provide a meaningful
      st_ino; they always set it to zero.  (Windows does provide a
@@ -1463,7 +1463,8 @@ find_separate_debug_file_by_debuglink (s
       /* If the file is in the sysroot, try using its base path in the
 	 global debugfile directory.  */
       if (canon_name
-	  && strncmp (canon_name, gdb_sysroot, strlen (gdb_sysroot)) == 0
+	  && filename_ncmp (canon_name, gdb_sysroot,
+			    strlen (gdb_sysroot)) == 0
 	  && IS_DIR_SEPARATOR (canon_name[strlen (gdb_sysroot)]))
 	{
 	  memcpy (debugfile, debugdir, debugdir_end - debugdir);
@@ -2367,8 +2368,9 @@ reread_symbols (void)
 	  /* We need to do this whenever any symbols go away.  */
 	  make_cleanup (clear_symtab_users_cleanup, 0 /*ignore*/);
 
-	  if (exec_bfd != NULL && strcmp (bfd_get_filename (objfile->obfd),
-					  bfd_get_filename (exec_bfd)) == 0)
+	  if (exec_bfd != NULL
+	      && filename_cmp (bfd_get_filename (objfile->obfd),
+			       bfd_get_filename (exec_bfd)) == 0)
 	    {
 	      /* Reload EXEC_BFD without asking anything.  */
 
Index: gdb/symmisc.c
===================================================================
--- gdb.orig/symmisc.c	2011-01-11 22:53:24.000000000 +0100
+++ gdb/symmisc.c	2011-03-02 12:14:21.768332400 +0100
@@ -23,6 +23,7 @@
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "bfd.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "breakpoint.h"
@@ -475,7 +476,7 @@ maintenance_print_symbols (char *args, i
 
   immediate_quit++;
   ALL_SYMTABS (objfile, s)
-    if (symname == NULL || strcmp (symname, s->filename) == 0)
+    if (symname == NULL || filename_cmp (symname, s->filename) == 0)
     dump_symtab (objfile, s, outfile);
   immediate_quit--;
   do_cleanups (cleanups);
Index: gdb/symtab.c
===================================================================
--- gdb.orig/symtab.c	2011-03-01 09:03:22.000000000 +0100
+++ gdb/symtab.c	2011-03-02 09:48:00.137707000 +0100
@@ -2761,7 +2761,7 @@ filename_seen (const char *file, int add
 
   /* Is FILE in tab?  */
   for (p = tab; p < tab + tab_cur_size; p++)
-    if (strcmp (*p, file) == 0)
+    if (filename_cmp (*p, file) == 0)
       return 1;
 
   /* No; maybe add it to tab.  */
@@ -2862,7 +2862,7 @@ file_matches (const char *file, char *fi
     {
       for (i = 0; i < nfiles; i++)
 	{
-	  if (strcmp (files[i], lbasename (file)) == 0)
+	  if (filename_cmp (files[i], lbasename (file)) == 0)
 	    return 1;
 	}
     }
@@ -3260,7 +3260,7 @@ static void
 print_symbol_info (domain_enum kind, struct symtab *s, struct symbol *sym,
 		   int block, char *last)
 {
-  if (last == NULL || strcmp (last, s->filename) != 0)
+  if (last == NULL || filename_cmp (last, s->filename) != 0)
     {
       fputs_filtered ("\nFile ", gdb_stdout);
       fputs_filtered (s->filename, gdb_stdout);
@@ -4073,7 +4073,7 @@ not_interesting_fname (const char *fname
 
   for (i = 0; illegal_aliens[i]; i++)
     {
-      if (strcmp (fname, illegal_aliens[i]) == 0)
+      if (filename_cmp (fname, illegal_aliens[i]) == 0)
 	return 1;
     }
   return 0;
@@ -4102,12 +4102,7 @@ maybe_add_partial_symtab_filename (const
   if (not_interesting_fname (filename))
     return;
   if (!filename_seen (filename, 1, data->first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-      && strncasecmp (filename, data->text, data->text_len) == 0
-#else
-      && strncmp (filename, data->text, data->text_len) == 0
-#endif
-      )
+      && filename_ncmp (filename, data->text, data->text_len) == 0)
     {
       /* This file matches for a completion; add it to the
 	 current list of matches.  */
@@ -4120,12 +4115,7 @@ maybe_add_partial_symtab_filename (const
 
       if (base_name != filename
 	  && !filename_seen (base_name, 1, data->first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	  && strncasecmp (base_name, data->text, data->text_len) == 0
-#else
-	  && strncmp (base_name, data->text, data->text_len) == 0
-#endif
-	  )
+	  && filename_ncmp (base_name, data->text, data->text_len) == 0)
 	add_filename_to_list (base_name, data->text, data->word,
 			      data->list, data->list_used, data->list_alloced);
     }
@@ -4159,12 +4149,7 @@ make_source_files_completion_list (char
       if (not_interesting_fname (s->filename))
 	continue;
       if (!filename_seen (s->filename, 1, &first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	  && strncasecmp (s->filename, text, text_len) == 0
-#else
-	  && strncmp (s->filename, text, text_len) == 0
-#endif
-	  )
+	  && filename_ncmp (s->filename, text, text_len) == 0)
 	{
 	  /* This file matches for a completion; add it to the current
 	     list of matches.  */
@@ -4180,12 +4165,7 @@ make_source_files_completion_list (char
 	  base_name = lbasename (s->filename);
 	  if (base_name != s->filename
 	      && !filename_seen (base_name, 1, &first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	      && strncasecmp (base_name, text, text_len) == 0
-#else
-	      && strncmp (base_name, text, text_len) == 0
-#endif
-	      )
+	      && filename_ncmp (base_name, text, text_len) == 0)
 	    add_filename_to_list (base_name, text, word,
 				  &list, &list_used, &list_alloced);
 	}
Index: gdb/xcoffread.c
===================================================================
--- gdb.orig/xcoffread.c	2011-01-12 02:23:29.000000000 +0100
+++ gdb/xcoffread.c	2011-03-03 12:06:39.938184300 +0100
@@ -41,6 +41,7 @@
 #include "coff/rs6000.h"
 #include "xcoffread.h"
 
+#include "filenames.h"
 #include "symtab.h"
 #include "gdbtypes.h"
 /* FIXME: ezannoni/2004-02-13 Verify if the include below is really needed.  */
@@ -609,7 +610,7 @@ process_linenos (CORE_ADDR start, CORE_A
 		 start, 0, &main_source_baseline);
 	    }
 
-	  if (strcmp (inclTable[ii].name, last_source_file) == 0)
+	  if (filename_cmp (inclTable[ii].name, last_source_file) == 0)
 	    {
               /* The entry in the include table refers to the main source
                  file.  Add the lines to the main subfile.  */
@@ -2575,14 +2576,14 @@ scan_xcoff_symtab (struct objfile *objfi
 	       things like "break c-exp.y:435" need to work (I
 	       suppose the psymtab_include_list could be hashed or put
 	       in a binary tree, if profiling shows this is a major hog).  */
-	    if (pst && strcmp (namestring, pst->filename) == 0)
+	    if (pst && filename_cmp (namestring, pst->filename) == 0)
 	      continue;
 
 	    {
 	      int i;
 
 	      for (i = 0; i < includes_used; i++)
-		if (strcmp (namestring, psymtab_include_list[i]) == 0)
+		if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
 		  {
 		    i = -1;
 		    break;
Index: gdb/xml-support.c
===================================================================
--- gdb.orig/xml-support.c	2011-02-17 22:19:32.000000000 +0100
+++ gdb/xml-support.c	2011-03-02 09:51:06.587883100 +0100
@@ -25,6 +25,7 @@
 
 #include "gdb_string.h"
 #include "safe-ctype.h"
+#include "filenames.h"
 
 /* Debugging flag.  */
 static int debug_xml;
@@ -946,7 +947,7 @@ fetch_xml_builtin (const char *filename)
   const char *(*p)[2];
 
   for (p = xml_builtin; (*p)[0]; p++)
-    if (strcmp ((*p)[0], filename) == 0)
+    if (filename_cmp ((*p)[0], filename) == 0)
       return (*p)[1];
 
   return NULL;
Index: gdb/xml-syscall.c
===================================================================
--- gdb.orig/xml-syscall.c	2011-02-17 22:19:32.000000000 +0100
+++ gdb/xml-syscall.c	2011-03-02 11:16:02.371965500 +0100
@@ -280,7 +280,7 @@ static void
 init_sysinfo (void)
 {
   /* Should we re-read the XML info for this target?  */
-  if (my_gdb_datadir && strcmp (my_gdb_datadir, gdb_datadir) != 0)
+  if (my_gdb_datadir && filename_cmp (my_gdb_datadir, gdb_datadir) != 0)
     {
       /* The data-directory changed from the last time we used it.
 	 It means that we have to re-read the XML info.  */
Index: gdb/coffread.c
===================================================================
--- gdb.orig/coffread.c	2011-03-01 09:03:20.000000000 +0100
+++ gdb/coffread.c	2011-03-03 10:53:53.676239400 +0100
@@ -33,6 +33,7 @@
 
 #include "coff/internal.h"	/* Internal format of COFF symbols in BFD */
 #include "libcoff.h"		/* FIXME secret internal data from BFD */
+#include "filenames.h"
 #include "objfiles.h"
 #include "buildsym.h"
 #include "gdb-stabs.h"
@@ -1331,8 +1332,18 @@ coff_getfilename (union internal_auxent
   /* FIXME: We should not be throwing away the information about what
      directory.  It should go into dirname of the symtab, or some such
      place.  */
-  if ((temp = strrchr (result, '/')) != NULL)
+  temp = strrchr (result, '/');
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  {
+    char *p2 = strrchr (result, '\\');
+
+    if (!temp || (p2 && p2 > temp))
+      temp = p2;
+  }
+#endif
+  if (temp != NULL)
     result = temp + 1;
+
   return (result);
 }
 \f
Index: gdb/dwarf2read.c
===================================================================
--- gdb.orig/dwarf2read.c	2011-03-01 09:03:21.000000000 +0100
+++ gdb/dwarf2read.c	2011-03-03 11:04:13.022886500 +0100
@@ -5207,7 +5207,8 @@ find_file_and_directory (struct die_info
 	 directory, get rid of it.  */
       char *cp = strchr (*comp_dir, ':');
 
-      if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
+      if (cp && cp != *comp_dir && cp[-1] == '.'
+	  && IS_ABSOLUTE_PATH (&cp[1]))
 	*comp_dir = cp + 1;
     }
 
Index: gdb/fbsd-nat.c
===================================================================
--- gdb.orig/fbsd-nat.c	2011-03-01 09:03:21.000000000 +0100
+++ gdb/fbsd-nat.c	2011-03-03 11:13:47.130288800 +0100
@@ -24,6 +24,7 @@
 #include "regcache.h"
 #include "regset.h"
 #include "gdbthread.h"
+#include "filenames.h"
 
 #include "gdb_assert.h"
 #include "gdb_string.h"
@@ -202,8 +203,16 @@ fbsd_make_corefile_notes (bfd *obfd, int
 
   if (get_exec_file (0))
     {
-      char *fname = strrchr (get_exec_file (0), '/') + 1;
-      char *psargs = xstrdup (fname);
+      char *fname = strrchr (get_exec_file (0), '/');
+      char *psargs;
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+      char *fname2 = strrchr (get_exec_file (0), '\\');
+
+      if (!fname || (fname2 && fname2 > fname))
+        fname = fname2;
+#endif
+      ++fname;
+      psargs = xstrdup (fname);
 
       if (get_inferior_args ())
 	psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
Index: gdb/linux-fork.c
===================================================================
--- gdb.orig/linux-fork.c	2011-01-09 04:08:57.000000000 +0100
+++ gdb/linux-fork.c	2011-03-03 11:16:49.096395600 +0100
@@ -24,6 +24,7 @@
 #include "regcache.h"
 #include "gdbcmd.h"
 #include "infcall.h"
+#include "filenames.h"
 #include "objfiles.h"
 #include "gdb_assert.h"
 #include "gdb_string.h"
@@ -586,7 +587,12 @@ info_checkpoints_command (char *arg, int
       if (sal.symtab)
 	{
 	  char *tmp = strrchr (sal.symtab->filename, '/');
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+	  char *tmp2 = strrchr (sal_symtab->filename, '\\');
 
+	  if (!tmp || (tmp2 && tmp2 > tmp))
+	    tmp = tmp2;
+#endif
 	  if (tmp)
 	    printf_filtered (_(", file %s"), tmp + 1);
 	  else
Index: gdb/linux-nat.c
===================================================================
--- gdb.orig/linux-nat.c	2011-03-01 09:03:21.000000000 +0100
+++ gdb/linux-nat.c	2011-03-03 11:20:00.738231000 +0100
@@ -56,6 +56,7 @@
 #include "terminal.h"
 #include <sys/vfs.h>
 #include "solib.h"
+#include "filenames.h"
 
 #ifndef SPUFS_MAGIC
 #define SPUFS_MAGIC 0x23c9b64e
@@ -4491,7 +4492,14 @@ linux_nat_make_corefile_notes (bfd *obfd
 
   if (get_exec_file (0))
     {
-      strncpy (fname, strrchr (get_exec_file (0), '/') + 1, sizeof (fname));
+      char *tmp = strrchr (get_exec_file (0), '/');
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+      char *tmp2 = strrchr (get_exec_file (0), '\\');
+
+      if (!tmp || (tmp2 && tmp2 > tmp))
+        tmp = tmp2;
+#endif
+      strncpy (fname, tmp + 1, sizeof (fname));
       strncpy (psargs, get_exec_file (0), sizeof (psargs));
       if (get_inferior_args ())
 	{
Index: gdb/linux-thread-db.c
===================================================================
--- gdb.orig/linux-thread-db.c	2011-03-01 09:03:21.000000000 +0100
+++ gdb/linux-thread-db.c	2011-03-03 11:24:28.584743200 +0100
@@ -31,6 +31,7 @@
 #include "gdbcmd.h"
 #include "gdbthread.h"
 #include "inferior.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "target.h"
@@ -777,7 +778,11 @@ try_thread_db_load (const char *library)
       return 0;
     }
 
-  if (libthread_db_debug && strchr (library, '/') == NULL)
+  if (libthread_db_debug && strchr (library, '/') == NULL
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+      && strchr (library, '\\') == NULL
+#endif
+     )
     {
       void *td_init;
 
@@ -901,7 +906,14 @@ thread_db_load (void)
 	gdb_assert (strlen (obj->name) < sizeof (path));
 	strcpy (path, obj->name);
 	cp = strrchr (path, '/');
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+	{
+	  char *cp2 = strrchr (path, '\\');
 
+	  if (!cp || (cp2 && cp2 > cp))
+	    cp = cp2;
+	}
+#endif
 	if (cp == NULL)
 	  {
 	    warning (_("Expected absolute pathname for libpthread in the"
Index: gdb/nto-tdep.c
===================================================================
--- gdb.orig/nto-tdep.c	2011-01-10 21:38:49.000000000 +0100
+++ gdb/nto-tdep.c	2011-03-03 10:33:39.791595700 +0100
@@ -33,6 +33,7 @@
 #include "elf-bfd.h"
 #include "solib-svr4.h"
 #include "gdbcore.h"
+#include "filenames.h"
 #include "objfiles.h"
 
 #include <string.h>
@@ -129,6 +130,13 @@ nto_find_and_open_solib (char *solib, un
 
   /* Don't assume basename() isn't destructive.  */
   base = strrchr (solib, '/');
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  {
+    char *base2 = strrchr (solib, '\\');
+    if (!base || (base2 && base2 > base))
+      base = base2;
+  }
+#endif
   if (!base)
     base = solib;
   else
Index: gdb/windows-nat.c
===================================================================
--- gdb.orig/windows-nat.c	2011-01-12 02:23:29.000000000 +0100
+++ gdb/windows-nat.c	2011-03-03 10:12:52.749241400 +0100
@@ -46,6 +46,7 @@
 #include <signal.h>
 
 #include "buildsym.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "gdb_obstack.h"
@@ -2586,7 +2587,7 @@ _initialize_check_for_gdb_ini (void)
 				      sizeof ("/gdb.ini"));
       strcpy (oldini, homedir);
       p = strchr (oldini, '\0');
-      if (p > oldini && p[-1] != '/')
+      if (p > oldini && !IS_DIR_SEPARATOR (p[-1]))
 	*p++ = '/';
       strcpy (p, "gdb.ini");
       if (access (oldini, 0) == 0)

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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 12:10 ` [patch gdb]: Fix some DOS-path related issues in gdb Kai Tietz
@ 2011-03-03 13:24   ` Eli Zaretskii
  2011-03-03 13:48     ` Kai Tietz
  0 siblings, 1 reply; 37+ messages in thread
From: Eli Zaretskii @ 2011-03-03 13:24 UTC (permalink / raw)
  To: Kai Tietz; +Cc: gdb-patches

> Date: Thu, 3 Mar 2011 13:10:13 +0100
> From: Kai Tietz <ktietz70@googlemail.com>
> 
> Sorry, first post were sent to wrong list. This patch fixes some
> issues related to DOS file-system filenames and paths. I am not sure,
> if I hit all places, nevertheless I am sure I hit most.
> This patch uses the libiberty functions & macros about
> directory-separator checks, absolute-path checks, and the
> filename-comparision functions.

The patch looks okay to me, but please do NOT install the changes for
the following files, which cannot possibly meet with this issue:
bsd-kvm.c, elfread.c, mdebugread.c, nto-procfs.c, rs6000-nat.c,
xcoffread.c, fbsd-nat.c, linux-fork.c linux-nat.c, linux-thread-db,
nto-tdep.c.

Thanks for working on this.


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 13:24   ` Eli Zaretskii
@ 2011-03-03 13:48     ` Kai Tietz
  2011-03-03 14:00       ` Eli Zaretskii
  0 siblings, 1 reply; 37+ messages in thread
From: Kai Tietz @ 2011-03-03 13:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

2011/3/3 Eli Zaretskii <eliz@gnu.org>:
>> Date: Thu, 3 Mar 2011 13:10:13 +0100
>> From: Kai Tietz <ktietz70@googlemail.com>
>>
>> Sorry, first post were sent to wrong list. This patch fixes some
>> issues related to DOS file-system filenames and paths. I am not sure,
>> if I hit all places, nevertheless I am sure I hit most.
>> This patch uses the libiberty functions & macros about
>> directory-separator checks, absolute-path checks, and the
>> filename-comparision functions.
>
> The patch looks okay to me, but please do NOT install the changes for
> the following files, which cannot possibly meet with this issue:
> bsd-kvm.c, elfread.c, mdebugread.c, nto-procfs.c, rs6000-nat.c,
> xcoffread.c, fbsd-nat.c, linux-fork.c linux-nat.c, linux-thread-db,
> nto-tdep.c.
>
> Thanks for working on this.
>

Ok, the obvious native-parts - not using DOS-style file/paths - I
removed. The files elfread.c, mdebugread.c are also used for a x64
windows target, so I think those parts of patch should be kept. They
don't seem to be host-specific to me.

Regards,
Kai


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 13:48     ` Kai Tietz
@ 2011-03-03 14:00       ` Eli Zaretskii
  2011-03-03 14:58         ` Joel Brobecker
  2011-03-03 17:02         ` Mark Kettenis
  0 siblings, 2 replies; 37+ messages in thread
From: Eli Zaretskii @ 2011-03-03 14:00 UTC (permalink / raw)
  To: Kai Tietz; +Cc: gdb-patches

> Date: Thu, 3 Mar 2011 14:48:07 +0100
> From: Kai Tietz <ktietz70@googlemail.com>
> Cc: gdb-patches@sourceware.org
> 
> The files elfread.c, mdebugread.c are also used for a x64
> windows target

I didn't know that the Windows 64bit target can use ELF debug info.
Can it?  With what toolchains?

As for mdebugread.c, I always thought it was MIPS specific.  What
other platforms use it?


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 14:00       ` Eli Zaretskii
@ 2011-03-03 14:58         ` Joel Brobecker
  2011-03-03 15:25           ` Kai Tietz
                             ` (2 more replies)
  2011-03-03 17:02         ` Mark Kettenis
  1 sibling, 3 replies; 37+ messages in thread
From: Joel Brobecker @ 2011-03-03 14:58 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Kai Tietz, gdb-patches

> I didn't know that the Windows 64bit target can use ELF debug info.
> Can it?  With what toolchains?
> 
> As for mdebugread.c, I always thought it was MIPS specific.  What
> other platforms use it?

These would still be pertinent in the case of cross debugging, no?
If the files were cross-compiled on Windows, the debug info would
contain file paths that follow the Windows convention...

-- 
Joel


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 14:58         ` Joel Brobecker
@ 2011-03-03 15:25           ` Kai Tietz
  2011-03-03 15:32           ` Pedro Alves
  2011-03-03 18:09           ` Eli Zaretskii
  2 siblings, 0 replies; 37+ messages in thread
From: Kai Tietz @ 2011-03-03 15:25 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Eli Zaretskii, gdb-patches

2011/3/3 Joel Brobecker <brobecker@adacore.com>:
>> I didn't know that the Windows 64bit target can use ELF debug info.
>> Can it?  With what toolchains?
>>
>> As for mdebugread.c, I always thought it was MIPS specific.  What
>> other platforms use it?
>
> These would still be pertinent in the case of cross debugging, no?
> If the files were cross-compiled on Windows, the debug info would
> contain file paths that follow the Windows convention...

Right, they would.

Kai


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 14:58         ` Joel Brobecker
  2011-03-03 15:25           ` Kai Tietz
@ 2011-03-03 15:32           ` Pedro Alves
  2011-03-03 15:41             ` Kai Tietz
  2011-03-07 19:28             ` Jan Kratochvil
  2011-03-03 18:09           ` Eli Zaretskii
  2 siblings, 2 replies; 37+ messages in thread
From: Pedro Alves @ 2011-03-03 15:32 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker, Eli Zaretskii, Kai Tietz

On Thursday 03 March 2011 14:58:32, Joel Brobecker wrote:
> > I didn't know that the Windows 64bit target can use ELF debug info.
> > Can it?  With what toolchains?
> > 
> > As for mdebugread.c, I always thought it was MIPS specific.  What
> > other platforms use it?
> 
> These would still be pertinent in the case of cross debugging, no?
> If the files were cross-compiled on Windows, the debug info would
> contain file paths that follow the Windows convention...

And then if you try to debug that on GNU/Linux, things still
won't work, because filename_cmp changes behavior depending on host,
not target or context.  That's why I believe there should be a clear
distinction between what's a source path, and a host path.  I think
Kai's bfd changes affect host paths, so they're fine. (haven't really
checked, but that's what I imagine).  For source paths, I'd rather
have this patch resurected...

 <http://sourceware.org/ml/gdb-patches/2010-12/msg00343.html>

I haven't looked at Kai's patch to see if it affects host
paths or source paths.

-- 
Pedro Alves


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 15:32           ` Pedro Alves
@ 2011-03-03 15:41             ` Kai Tietz
  2011-03-03 16:09               ` Pedro Alves
  2011-03-07 19:28             ` Jan Kratochvil
  1 sibling, 1 reply; 37+ messages in thread
From: Kai Tietz @ 2011-03-03 15:41 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Joel Brobecker, Eli Zaretskii

2011/3/3 Pedro Alves <pedro@codesourcery.com>:
> On Thursday 03 March 2011 14:58:32, Joel Brobecker wrote:
>> > I didn't know that the Windows 64bit target can use ELF debug info.
>> > Can it?  With what toolchains?
>> >
>> > As for mdebugread.c, I always thought it was MIPS specific.  What
>> > other platforms use it?
>>
>> These would still be pertinent in the case of cross debugging, no?
>> If the files were cross-compiled on Windows, the debug info would
>> contain file paths that follow the Windows convention...
>
> And then if you try to debug that on GNU/Linux, things still
> won't work, because filename_cmp changes behavior depending on host,
> not target or context.  That's why I believe there should be a clear
> distinction between what's a source path, and a host path.  I think
> Kai's bfd changes affect host paths, so they're fine. (haven't really
> checked, but that's what I imagine).  For source paths, I'd rather
> have this patch resurected...
>
>  <http://sourceware.org/ml/gdb-patches/2010-12/msg00343.html>
>
> I haven't looked at Kai's patch to see if it affects host
> paths or source paths.
>
> --
> Pedro Alves
>

Well Pedro,

this is exactly the point I described in my reply to Eli. The
debugging of cross-compiled binaries via systems with different
filename/path representation was and is still not operating. Here it
would be necessary to provide host<->creator information for doing a
mapping. And this isn't handled by this patch.
But at least this patch takes care that stuff compiled on a host with
host-compiler using DOS-paths is able to operate correct. And ELF is
an object-file format and has in principle nothing to do with unix and
can be used (with loader-support) on any specifc OS.

Kai


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 15:41             ` Kai Tietz
@ 2011-03-03 16:09               ` Pedro Alves
  2011-03-03 16:19                 ` Kai Tietz
  0 siblings, 1 reply; 37+ messages in thread
From: Pedro Alves @ 2011-03-03 16:09 UTC (permalink / raw)
  To: Kai Tietz; +Cc: gdb-patches, Joel Brobecker, Eli Zaretskii

On Thursday 03 March 2011 15:41:27, Kai Tietz wrote:
> 2011/3/3 Pedro Alves <pedro@codesourcery.com>:
> > On Thursday 03 March 2011 14:58:32, Joel Brobecker wrote:
> >> > I didn't know that the Windows 64bit target can use ELF debug info.
> >> > Can it?  With what toolchains?
> >> >
> >> > As for mdebugread.c, I always thought it was MIPS specific.  What
> >> > other platforms use it?
> >>
> >> These would still be pertinent in the case of cross debugging, no?
> >> If the files were cross-compiled on Windows, the debug info would
> >> contain file paths that follow the Windows convention...
> >
> > And then if you try to debug that on GNU/Linux, things still
> > won't work, because filename_cmp changes behavior depending on host,
> > not target or context.  That's why I believe there should be a clear
> > distinction between what's a source path, and a host path.  I think
> > Kai's bfd changes affect host paths, so they're fine. (haven't really
> > checked, but that's what I imagine).  For source paths, I'd rather
> > have this patch resurected...
> >
> >  <http://sourceware.org/ml/gdb-patches/2010-12/msg00343.html>
> >
> > I haven't looked at Kai's patch to see if it affects host
> > paths or source paths.
> >
> > --
> > Pedro Alves
> >
> 
> Well Pedro,
> 
> this is exactly the point I described in my reply to Eli. The
> debugging of cross-compiled binaries via systems with different
> filename/path representation was and is still not operating. Here it
> would be necessary to provide host<->creator information for doing a
> mapping. And this isn't handled by this patch.
> But at least this patch takes care that stuff compiled on a host with
> host-compiler using DOS-paths is able to operate correct. And ELF is
> an object-file format and has in principle nothing to do with unix and
> can be used (with loader-support) on any specifc OS.

It sounds like you didn't follow the url I pointed at?

-- 
Pedro Alves


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 16:09               ` Pedro Alves
@ 2011-03-03 16:19                 ` Kai Tietz
  2011-03-03 16:42                   ` Pedro Alves
  0 siblings, 1 reply; 37+ messages in thread
From: Kai Tietz @ 2011-03-03 16:19 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Joel Brobecker, Eli Zaretskii

2011/3/3 Pedro Alves <pedro@codesourcery.com>:
> On Thursday 03 March 2011 15:41:27, Kai Tietz wrote:
>> 2011/3/3 Pedro Alves <pedro@codesourcery.com>:
>> > On Thursday 03 March 2011 14:58:32, Joel Brobecker wrote:
>> >> > I didn't know that the Windows 64bit target can use ELF debug info.
>> >> > Can it?  With what toolchains?
>> >> >
>> >> > As for mdebugread.c, I always thought it was MIPS specific.  What
>> >> > other platforms use it?
>> >>
>> >> These would still be pertinent in the case of cross debugging, no?
>> >> If the files were cross-compiled on Windows, the debug info would
>> >> contain file paths that follow the Windows convention...
>> >
>> > And then if you try to debug that on GNU/Linux, things still
>> > won't work, because filename_cmp changes behavior depending on host,
>> > not target or context.  That's why I believe there should be a clear
>> > distinction between what's a source path, and a host path.  I think
>> > Kai's bfd changes affect host paths, so they're fine. (haven't really
>> > checked, but that's what I imagine).  For source paths, I'd rather
>> > have this patch resurected...
>> >
>> >  <http://sourceware.org/ml/gdb-patches/2010-12/msg00343.html>
>> >
>> > I haven't looked at Kai's patch to see if it affects host
>> > paths or source paths.
>> >
>> > --
>> > Pedro Alves
>> >
>>
>> Well Pedro,
>>
>> this is exactly the point I described in my reply to Eli. The
>> debugging of cross-compiled binaries via systems with different
>> filename/path representation was and is still not operating. Here it
>> would be necessary to provide host<->creator information for doing a
>> mapping. And this isn't handled by this patch.
>> But at least this patch takes care that stuff compiled on a host with
>> host-compiler using DOS-paths is able to operate correct. And ELF is
>> an object-file format and has in principle nothing to do with unix and
>> can be used (with loader-support) on any specifc OS.
>
> It sounds like you didn't follow the url I pointed at?
>
> --
> Pedro Alves
>

Yes, sorry. I read it now. Well, this flag sounds on first hand
proper, but by rethinking it a bit, it is not working.
If you have compiled your application via cross-compiler on unix for a
target with a different file-system schema (like windows), and then
try to debug it via an native debugger, you will see that filenames
and paths won't work at all.
This is caused by the fact, that debugging information always are
using host's (and not target's) filename schema. So to have here a
command-line switch won't solve anything AFAICS.
IMHO the only valid approach to solve this is:
a) Assume that gbd uses internally always its host-filename-schema
(this is my patch about)
b) Introduce a mapping of foreign file-systems to host's, which can be
setuped by user. Sadly this can't be detected by debugging-information
as AFAIK it lacks this information to tell on what host it was build.

Regards,
Kai

-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 16:19                 ` Kai Tietz
@ 2011-03-03 16:42                   ` Pedro Alves
  2011-03-03 17:32                     ` Kai Tietz
  0 siblings, 1 reply; 37+ messages in thread
From: Pedro Alves @ 2011-03-03 16:42 UTC (permalink / raw)
  To: gdb-patches; +Cc: Kai Tietz, Joel Brobecker, Eli Zaretskii

On Thursday 03 March 2011 16:19:41, Kai Tietz wrote:

> Yes, sorry. I read it now. Well, this flag sounds on first hand
> proper, but by rethinking it a bit, it is not working.
> If you have compiled your application via cross-compiler on unix for a
> target with a different file-system schema (like windows), and then
> try to debug it via an native debugger, you will see that filenames
> and paths won't work at all.

It's supposed to work, because the "dos-based" setting accepts
unix style paths as well.  A Windows build of gdb doesn't have
problems with unix paths.  It's a unix gdb that has trouble with
dos paths.

> This is caused by the fact, that debugging information always are
> using host's (and not target's) filename schema. 

The patch I pointed at is precisely supposed to help with
that scenario.

> So to have here a
> command-line switch won't solve anything AFAICS.

The patches leaves gdb being lax in filename
comparisions by default, even on unix. 

> +/* Handle binaries compiled on DOS-based filesystems (e.g, Windows),
> +   by default, even if GDB itself is not running on such a system.
> +   Such binaries may contain debug info with source paths the native
> +   path handling functions wouldn't understand (e.g., backslash as
> +   directory separator, drive names, and case insensitivity).  The
> +   risk of this going wrong is very minor in practice, so it's more
> +   useful to leave this as default.  */
> +static const char *source_file_names_mode = source_file_names_dos_based;

If you have a bizarre case where you really need strict case-sensitive
filename comparisions, and to handle `\' in filenames,
then you'd need to flip the switch.  99.9999999999% of
the users won't.

> IMHO the only valid approach to solve this is:
> a) Assume that gbd uses internally always its host-filename-schema
> (this is my patch about)
> b) Introduce a mapping of foreign file-systems to host's, which can be
> setuped by user. 

This is likely to be more memory consuming, and likely to
introduce a hit in debug info read time.  (haven't measured, of course).

> Sadly this can't be detected by debugging-information
> as AFAIK it lacks this information to tell on what host it was build.

Yeah.

-- 
Pedro Alves


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 14:00       ` Eli Zaretskii
  2011-03-03 14:58         ` Joel Brobecker
@ 2011-03-03 17:02         ` Mark Kettenis
  1 sibling, 0 replies; 37+ messages in thread
From: Mark Kettenis @ 2011-03-03 17:02 UTC (permalink / raw)
  To: eliz; +Cc: ktietz70, gdb-patches

> Date: Thu, 03 Mar 2011 09:00:00 -0500
> From: Eli Zaretskii <eliz@gnu.org>
> 
> > Date: Thu, 3 Mar 2011 14:48:07 +0100
> > From: Kai Tietz <ktietz70@googlemail.com>
> > Cc: gdb-patches@sourceware.org
> > 
> > The files elfread.c, mdebugread.c are also used for a x64
> > windows target
> 
> I didn't know that the Windows 64bit target can use ELF debug info.
> Can it?  With what toolchains?
> 
> As for mdebugread.c, I always thought it was MIPS specific.  What
> other platforms use it?

Alpha used it as well.  Windows NT ran on Alpha, but I don't think
anybody will seriously consider using GDB in associated with that
platform these days.


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 16:42                   ` Pedro Alves
@ 2011-03-03 17:32                     ` Kai Tietz
  2011-03-04  7:23                       ` Vladimir Simonov
  0 siblings, 1 reply; 37+ messages in thread
From: Kai Tietz @ 2011-03-03 17:32 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Joel Brobecker, Eli Zaretskii

2011/3/3 Pedro Alves <pedro@codesourcery.com>:
> On Thursday 03 March 2011 16:19:41, Kai Tietz wrote:
>
>> Yes, sorry. I read it now. Well, this flag sounds on first hand
>> proper, but by rethinking it a bit, it is not working.
>> If you have compiled your application via cross-compiler on unix for a
>> target with a different file-system schema (like windows), and then
>> try to debug it via an native debugger, you will see that filenames
>> and paths won't work at all.
>
> It's supposed to work, because the "dos-based" setting accepts
> unix style paths as well.  A Windows build of gdb doesn't have
> problems with unix paths.  It's a unix gdb that has trouble with
> dos paths.

That's right from perspective of scanning those file name proper. But
well on windows boxes there is also the concept of those drive-letters
for volumes.

Also (as side-note) the UNC-stuff isn't handled proper for any OS by
binutils/gdb/gcc, but well, this is a different story.

>> This is caused by the fact, that debugging information always are
>> using host's (and not target's) filename schema.
>
> The patch I pointed at is precisely supposed to help with
> that scenario.

Well, it will help just on Windows boxes, which use same
directory-tree on current working drive. But well, it can help. For
unix a D: will be still be unresolveable.

>> So to have here a
>> command-line switch won't solve anything AFAICS.
>
> The patches leaves gdb being lax in filename
> comparisions by default, even on unix.
>
>> +/* Handle binaries compiled on DOS-based filesystems (e.g, Windows),
>> +   by default, even if GDB itself is not running on such a system.
>> +   Such binaries may contain debug info with source paths the native
>> +   path handling functions wouldn't understand (e.g., backslash as
>> +   directory separator, drive names, and case insensitivity).  The
>> +   risk of this going wrong is very minor in practice, so it's more
>> +   useful to leave this as default.  */
>> +static const char *source_file_names_mode = source_file_names_dos_based;
>
> If you have a bizarre case where you really need strict case-sensitive
> filename comparisions, and to handle `\' in filenames,
> then you'd need to flip the switch.  99.9999999999% of
> the users won't.
>
>> IMHO the only valid approach to solve this is:
>> a) Assume that gbd uses internally always its host-filename-schema
>> (this is my patch about)
>> b) Introduce a mapping of foreign file-systems to host's, which can be
>> setuped by user.
>
> This is likely to be more memory consuming, and likely to
> introduce a hit in debug info read time.  (haven't measured, of course).

Well, it is more a matter how and where this filemapping would be
handled. I thought about adding this filename layer into libiberty,
which then provides the basic file-io routines for
filename-conversion.
As for relative paths (which are commonly the main-part to be found in
debugging information) nothing needs to be done AFAICS. The tricky
part are just the absolute paths/filenames. For the case host's and
current path match each other (means on windows drive-letter colon,
for unix path begins with slash) nothing needs to be done, too. Just
the case that absolute-paths don't match needs some actions (and a
mapping).
This would be best handled on trying to operate on filenames
(open,fopen, stat, & co) via a layer provided in libiberty So those
mapping can be done on actual access and don't need to be
special-cased by app itself.
As this issue is present on binutils (bfd), gcc, and gdb, it would be
reasonable IMHO to handle this at one common and shared place.

By doing this (maybe with some small hashing for transformed names), I
wouldn't assume real speed-impact and no serious memory regression.

Regards,
Kai

PS: IA64 PE is another host for which this can occure (wince-arm too, but well).


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 14:58         ` Joel Brobecker
  2011-03-03 15:25           ` Kai Tietz
  2011-03-03 15:32           ` Pedro Alves
@ 2011-03-03 18:09           ` Eli Zaretskii
  2011-03-04  5:12             ` Joel Brobecker
                               ` (2 more replies)
  2 siblings, 3 replies; 37+ messages in thread
From: Eli Zaretskii @ 2011-03-03 18:09 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: ktietz70, gdb-patches

> Date: Thu, 3 Mar 2011 18:58:32 +0400
> From: Joel Brobecker <brobecker@adacore.com>
> Cc: Kai Tietz <ktietz70@googlemail.com>, gdb-patches@sourceware.org
> 
> > I didn't know that the Windows 64bit target can use ELF debug info.
> > Can it?  With what toolchains?
> > 
> > As for mdebugread.c, I always thought it was MIPS specific.  What
> > other platforms use it?
> 
> These would still be pertinent in the case of cross debugging, no?
> If the files were cross-compiled on Windows, the debug info would
> contain file paths that follow the Windows convention...

Is that use-case even practical?  Who would develop on Windows if they
have Linux or Irix?

Anyway, if others don't mind to have DOS-ism in mdebugread.c and
elfread.c, I don't object.


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 18:09           ` Eli Zaretskii
@ 2011-03-04  5:12             ` Joel Brobecker
  2011-03-04 13:05               ` André Pönitz
  2011-03-04  9:48             ` Kai Tietz
  2011-03-23 11:16             ` Kai Tietz
  2 siblings, 1 reply; 37+ messages in thread
From: Joel Brobecker @ 2011-03-04  5:12 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: ktietz70, gdb-patches

> Is that use-case even practical?  Who would develop on Windows if they
> have Linux or Irix?

I really can't say that this is going to happen frequently...
But I've seen situations where developers cross compile from
their Windows desktop and then execute on a server running a Unix-like
system.  It might make less sense for GNU/Linux (I think that people
are less scared of it, these days), but could make more sense for
IRIX - I don't know how easy it is to procure a machine running
IRIX these days...

-- 
Joel


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 17:32                     ` Kai Tietz
@ 2011-03-04  7:23                       ` Vladimir Simonov
  2011-03-04  8:23                         ` Joel Brobecker
  0 siblings, 1 reply; 37+ messages in thread
From: Vladimir Simonov @ 2011-03-04  7:23 UTC (permalink / raw)
  To: Kai Tietz; +Cc: Pedro Alves, gdb-patches, Joel Brobecker, Eli Zaretskii

On 03/03/2011 08:32 PM, Kai Tietz wrote:
> 2011/3/3 Pedro Alves<pedro@codesourcery.com>:
>> On Thursday 03 March 2011 16:19:41, Kai Tietz wrote:
>>
>>> Yes, sorry. I read it now. Well, this flag sounds on first hand
>>> proper, but by rethinking it a bit, it is not working.
>>> If you have compiled your application via cross-compiler on unix for a
>>> target with a different file-system schema (like windows), and then
>>> try to debug it via an native debugger, you will see that filenames
>>> and paths won't work at all.
>>
>> It's supposed to work, because the "dos-based" setting accepts
>> unix style paths as well.  A Windows build of gdb doesn't have
>> problems with unix paths.  It's a unix gdb that has trouble with
>> dos paths.
>
> That's right from perspective of scanning those file name proper. But
> well on windows boxes there is also the concept of those drive-letters
> for volumes.
>
> Also (as side-note) the UNC-stuff isn't handled proper for any OS by
> binutils/gdb/gcc, but well, this is a different story.
>
>>> This is caused by the fact, that debugging information always are
>>> using host's (and not target's) filename schema.
>>
>> The patch I pointed at is precisely supposed to help with
>> that scenario.
>
> Well, it will help just on Windows boxes, which use same
> directory-tree on current working drive. But well, it can help. For
> unix a D: will be still be unresolveable.
>
>>> So to have here a
>>> command-line switch won't solve anything AFAICS.
>>
>> The patches leaves gdb being lax in filename
>> comparisions by default, even on unix.
>>
>>> +/* Handle binaries compiled on DOS-based filesystems (e.g, Windows),
>>> +   by default, even if GDB itself is not running on such a system.
>>> +   Such binaries may contain debug info with source paths the native
>>> +   path handling functions wouldn't understand (e.g., backslash as
>>> +   directory separator, drive names, and case insensitivity).  The
>>> +   risk of this going wrong is very minor in practice, so it's more
>>> +   useful to leave this as default.  */
>>> +static const char *source_file_names_mode = source_file_names_dos_based;
>>
>> If you have a bizarre case where you really need strict case-sensitive
>> filename comparisions, and to handle `\' in filenames,
>> then you'd need to flip the switch.  99.9999999999% of
>> the users won't.
>>
>>> IMHO the only valid approach to solve this is:
>>> a) Assume that gbd uses internally always its host-filename-schema
>>> (this is my patch about)
>>> b) Introduce a mapping of foreign file-systems to host's, which can be
>>> setuped by user.
>>
>> This is likely to be more memory consuming, and likely to
>> introduce a hit in debug info read time.  (haven't measured, of course).
>
> Well, it is more a matter how and where this filemapping would be
> handled. I thought about adding this filename layer into libiberty,
> which then provides the basic file-io routines for
> filename-conversion.
> As for relative paths (which are commonly the main-part to be found in
> debugging information) nothing needs to be done AFAICS. The tricky
> part are just the absolute paths/filenames. For the case host's and
> current path match each other (means on windows drive-letter colon,
> for unix path begins with slash) nothing needs to be done, too. Just
> the case that absolute-paths don't match needs some actions (and a
> mapping).
> This would be best handled on trying to operate on filenames
> (open,fopen, stat,&  co) via a layer provided in libiberty So those
> mapping can be done on actual access and don't need to be
> special-cased by app itself.
> As this issue is present on binutils (bfd), gcc, and gdb, it would be
> reasonable IMHO to handle this at one common and shared place.
>
> By doing this (maybe with some small hashing for transformed names), I
> wouldn't assume real speed-impact and no serious memory regression.
>
> Regards,
> Kai
>
> PS: IA64 PE is another host for which this can occure (wince-arm too, but well).
>
>
Hi all,

If the main problem is in mapping absolute DOS paths to Linux ones then
the simplest solution is creation appropriate symbolic links
on Linux side. I mean that using symlink D: pointed on some directory
you can simulate any DOS path. I'm using this approach for many years...

Regards
Vladimir Simonov


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-04  7:23                       ` Vladimir Simonov
@ 2011-03-04  8:23                         ` Joel Brobecker
  0 siblings, 0 replies; 37+ messages in thread
From: Joel Brobecker @ 2011-03-04  8:23 UTC (permalink / raw)
  To: Vladimir Simonov; +Cc: Kai Tietz, Pedro Alves, gdb-patches, Eli Zaretskii

> If the main problem is in mapping absolute DOS paths to Linux ones then
> the simplest solution is creation appropriate symbolic links
> on Linux side. I mean that using symlink D: pointed on some directory
> you can simulate any DOS path. I'm using this approach for many years...

On my end of things, this is not what I was concerned about
(it sounds like debugging a program on a different system
than the one it was built on - I assumed that build and debug
systems were the same).  For your case, you can perhaps have
a look at "set substitute-path" (or something like that).

-- 
Joel


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 18:09           ` Eli Zaretskii
  2011-03-04  5:12             ` Joel Brobecker
@ 2011-03-04  9:48             ` Kai Tietz
  2011-03-04 10:37               ` Mark Kettenis
  2011-03-23 11:16             ` Kai Tietz
  2 siblings, 1 reply; 37+ messages in thread
From: Kai Tietz @ 2011-03-04  9:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Joel Brobecker, gdb-patches

2011/3/3 Eli Zaretskii <eliz@gnu.org>:
>> Date: Thu, 3 Mar 2011 18:58:32 +0400
>> From: Joel Brobecker <brobecker@adacore.com>
>> Cc: Kai Tietz <ktietz70@googlemail.com>, gdb-patches@sourceware.org
>>
>> > I didn't know that the Windows 64bit target can use ELF debug info.
>> > Can it?  With what toolchains?
>> >
>> > As for mdebugread.c, I always thought it was MIPS specific.  What
>> > other platforms use it?
>>
>> These would still be pertinent in the case of cross debugging, no?
>> If the files were cross-compiled on Windows, the debug info would
>> contain file paths that follow the Windows convention...
>
> Is that use-case even practical?  Who would develop on Windows if they
> have Linux or Irix?
>
> Anyway, if others don't mind to have DOS-ism in mdebugread.c and
> elfread.c, I don't object.
>

I didn't saw here direct objections. So ok for apply?

On a second thought about Pedros's switch for turning on
case-(in)sensitive-ness by switch, it could be helpful. But the
slash/backslash issue is something pretty incompatible. Windows host
don't have issues in general (not for all API) to use slash and
backslash, but on unix filesystem a backslash causes troubles. So we
need here some path/filename normalization.

Regards,
Kai


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-04  9:48             ` Kai Tietz
@ 2011-03-04 10:37               ` Mark Kettenis
  2011-03-05  9:13                 ` Kai Tietz
  0 siblings, 1 reply; 37+ messages in thread
From: Mark Kettenis @ 2011-03-04 10:37 UTC (permalink / raw)
  To: ktietz70; +Cc: eliz, brobecker, gdb-patches

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1751 bytes --]

> Date: Fri, 4 Mar 2011 10:48:35 +0100
> From: Kai Tietz <ktietz70@googlemail.com>
>
> 2011/3/3 Eli Zaretskii <eliz@gnu.org>:
> >> Date: Thu, 3 Mar 2011 18:58:32 +0400
> >> From: Joel Brobecker <brobecker@adacore.com>
> >> Cc: Kai Tietz <ktietz70@googlemail.com>, gdb-patches@sourceware.org
> >>
> >> > I didn't know that the Windows 64bit target can use ELF debug info.
> >> > Can it?  With what toolchains?
> >> >
> >> > As for mdebugread.c, I always thought it was MIPS specific.  What
> >> > other platforms use it?
> >>
> >> These would still be pertinent in the case of cross debugging, no?
> >> If the files were cross-compiled on Windows, the debug info would
> >> contain file paths that follow the Windows convention...
> >
> > Is that use-case even practical?  Who would develop on Windows if they
> > have Linux or Irix?
> >
> > Anyway, if others don't mind to have DOS-ism in mdebugread.c and
> > elfread.c, I don't object.
> >
> 
> I didn't saw here direct objections. So ok for apply?
> 
> On a second thought about Pedros's switch for turning on
> case-(in)sensitive-ness by switch, it could be helpful. But the
> slash/backslash issue is something pretty incompatible. Windows host
> don't have issues in general (not for all API) to use slash and
> backslash, but on unix filesystem a backslash causes troubles. So we
> need here some path/filename normalization.

There is no problem with backslashes in path names on Unix-like
systems.  Backslashes don't have a special meaning; they're just like
normal letters.  That's exactly why a native debugger on a Unix-like
system should not try to be DOS compatible at all.  And if you ask me,
the same is true for a cross-debugger for a Unix-like target running
on a Unix-like host.


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-04  5:12             ` Joel Brobecker
@ 2011-03-04 13:05               ` André Pönitz
  0 siblings, 0 replies; 37+ messages in thread
From: André Pönitz @ 2011-03-04 13:05 UTC (permalink / raw)
  To: gdb-patches

On Friday 04 March 2011 06:12:03 ext Joel Brobecker wrote:
> > Is that use-case even practical?  Who would develop on Windows if they
> > have Linux or Irix?
> 
> I really can't say that this is going to happen frequently...
> But I've seen situations where developers cross compile from
> their Windows desktop and then execute on a server running a Unix-like
> system.  It might make less sense for GNU/Linux (I think that people
> are less scared of it, these days), but could make more sense for
> IRIX - I don't know how easy it is to procure a machine running
> IRIX these days...

Just two data points from an "gdb frontend" perspective:

 - Two weeks ago I had to enable core file handling on Windows which I 
   previously disabled because I assumed it would not be needed. 
   Someone was actually trying to use it. Quote from the bug report:
   (http://bugreports.qt.nokia.com/browse/QTCREATORBUG-3813)
   "I want to use gdb (compiled using Mingw for mips64 target) to 
   debug a machine that dumps core."

 - Today(!) I got a log file containing
    [...]
   GNU gdb (GDB) 7.2
   This GDB was configured as "i686-pc-mingw32".
    [...]
  153-break-insert  -f "\"main.cpp\":47"
  153^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",
    addr="0x004013b8",func="qMain(int, char **)",file="..\\calendar\\main.cpp",
    fullname="C:\\SDK1\\Examples\\4.7\\richtext\\calendar-build-desktop/..\\calendar\\main.cpp",
    line="47",times="0",original-location="\"main.cpp\":47"}
    [...]

  Note the "/.." bit in fullname.

People try to use gdb in a lot of "cross debugging" scenarios nowadays.

Andre'
   


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-04 10:37               ` Mark Kettenis
@ 2011-03-05  9:13                 ` Kai Tietz
  2011-03-05 11:38                   ` Vladimir Simonov
  0 siblings, 1 reply; 37+ messages in thread
From: Kai Tietz @ 2011-03-05  9:13 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: eliz, brobecker, gdb-patches

2011/3/4 Mark Kettenis <mark.kettenis@xs4all.nl>:
>> Date: Fri, 4 Mar 2011 10:48:35 +0100
>> From: Kai Tietz <ktietz70@googlemail.com>
>>
>> 2011/3/3 Eli Zaretskii <eliz@gnu.org>:
>> >> Date: Thu, 3 Mar 2011 18:58:32 +0400
>> >> From: Joel Brobecker <brobecker@adacore.com>
>> >> Cc: Kai Tietz <ktietz70@googlemail.com>, gdb-patches@sourceware.org
>> >>
>> >> > I didn't know that the Windows 64bit target can use ELF debug info.
>> >> > Can it?  With what toolchains?
>> >> >
>> >> > As for mdebugread.c, I always thought it was MIPS specific.  What
>> >> > other platforms use it?
>> >>
>> >> These would still be pertinent in the case of cross debugging, no?
>> >> If the files were cross-compiled on Windows, the debug info would
>> >> contain file paths that follow the Windows convention...
>> >
>> > Is that use-case even practical?  Who would develop on Windows if they
>> > have Linux or Irix?
>> >
>> > Anyway, if others don't mind to have DOS-ism in mdebugread.c and
>> > elfread.c, I don't object.
>> >
>>
>> I didn't saw here direct objections. So ok for apply?
>>
>> On a second thought about Pedros's switch for turning on
>> case-(in)sensitive-ness by switch, it could be helpful. But the
>> slash/backslash issue is something pretty incompatible. Windows host
>> don't have issues in general (not for all API) to use slash and
>> backslash, but on unix filesystem a backslash causes troubles. So we
>> need here some path/filename normalization.
>
> There is no problem with backslashes in path names on Unix-like
> systems.  Backslashes don't have a special meaning; they're just like
> normal letters.  That's exactly why a native debugger on a Unix-like
> system should not try to be DOS compatible at all.  And if you ask me,
> the same is true for a cross-debugger for a Unix-like target running
> on a Unix-like host.

I didn't said that backslashes are forbidden characters in
file/directory names, I just mentioned that they are causing problems.
And well, you provided here the best example. A referenced filename -
eg. 'C:\source\xyz.c" - would be treated on Unix-like filesystem as
one file name and it wouldn't be an absolute path at all. How a user
should be able to match such a thing? Symbolic links (as suggested
before) won't work.
Even worse it gets by the second example provided by André in his
post. As here on a linux based OS the file "..\\calendar\\main.cpp"
directory "C:\\SDK1\\Examples\\4.7\\richtext\\calendar-build-desktop/".
So if gdb should be able to debug a native application, which might be
cross-compiled on a different host with a different file-system, the
is for sure a lot of work.
Nevertheless my patch didn't addressed that.It just fixes the obvious
bug in file-comparision on Windows-like filesystems. It won't change
behavior on Unix-like OS AFAICS.


Kai


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-05  9:13                 ` Kai Tietz
@ 2011-03-05 11:38                   ` Vladimir Simonov
  2011-03-05 12:45                     ` Kai Tietz
  0 siblings, 1 reply; 37+ messages in thread
From: Vladimir Simonov @ 2011-03-05 11:38 UTC (permalink / raw)
  To: Kai Tietz; +Cc: Mark Kettenis, eliz, brobecker, gdb-patches

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

On 03/05/2011 12:13 PM, Kai Tietz wrote:
> 2011/3/4 Mark Kettenis<mark.kettenis@xs4all.nl>:
>>> Date: Fri, 4 Mar 2011 10:48:35 +0100
>>> From: Kai Tietz<ktietz70@googlemail.com>
>>>
>>> 2011/3/3 Eli Zaretskii<eliz@gnu.org>:
>>>>> Date: Thu, 3 Mar 2011 18:58:32 +0400
>>>>> From: Joel Brobecker<brobecker@adacore.com>
>>>>> Cc: Kai Tietz<ktietz70@googlemail.com>, gdb-patches@sourceware.org
>>>>>
>>>>>> I didn't know that the Windows 64bit target can use ELF debug info.
>>>>>> Can it?  With what toolchains?
>>>>>>
>>>>>> As for mdebugread.c, I always thought it was MIPS specific.  What
>>>>>> other platforms use it?
>>>>>
>>>>> These would still be pertinent in the case of cross debugging, no?
>>>>> If the files were cross-compiled on Windows, the debug info would
>>>>> contain file paths that follow the Windows convention...
>>>>
>>>> Is that use-case even practical?  Who would develop on Windows if they
>>>> have Linux or Irix?
>>>>
>>>> Anyway, if others don't mind to have DOS-ism in mdebugread.c and
>>>> elfread.c, I don't object.
>>>>
>>>
>>> I didn't saw here direct objections. So ok for apply?
>>>
>>> On a second thought about Pedros's switch for turning on
>>> case-(in)sensitive-ness by switch, it could be helpful. But the
>>> slash/backslash issue is something pretty incompatible. Windows host
>>> don't have issues in general (not for all API) to use slash and
>>> backslash, but on unix filesystem a backslash causes troubles. So we
>>> need here some path/filename normalization.
>>
>> There is no problem with backslashes in path names on Unix-like
>> systems.  Backslashes don't have a special meaning; they're just like
>> normal letters.  That's exactly why a native debugger on a Unix-like
>> system should not try to be DOS compatible at all.  And if you ask me,
>> the same is true for a cross-debugger for a Unix-like target running
>> on a Unix-like host.
>
> I didn't said that backslashes are forbidden characters in
> file/directory names, I just mentioned that they are causing problems.
> And well, you provided here the best example. A referenced filename -
> eg. 'C:\source\xyz.c" - would be treated on Unix-like filesystem as
> one file name and it wouldn't be an absolute path at all. How a user
> should be able to match such a thing? Symbolic links (as suggested
> before) won't work.
Sorry for confusing about C: link.

Yes, I've met the same problem several
years ago. The solution was - fix original names on Windows side.
For Windows names 'C:\source\xyz.c" and  'C:/source/xyz.c" are absolutely
equivalent. If we replace "\\" with "/" in gcc command line,
debug info will have records like C:/source/xyz.c

Probably gcc-dosbase it is not needed - gcc command may
converted by some external filter...

With this patches all should be ok. I mean C: link or directory
in current WD should work

Best regards
Vladimir Simonov

[-- Attachment #2: gcc-dosbase.patch --]
[-- Type: text/plain, Size: 860 bytes --]

Vladimir Simonov(sv@sw.ru) - mingw support.
Useful if you crossbuild Linux app on Windows.
- Debug info now contains C:/mydir/myfile.c (vs. C:\mydir\myfile.c).
  This permits debug such app on Linux box (just create C: dir or simlink
  and simulate appropriate path.
Index: gcc/gcc/gcc.c
===================================================================
--- gcc.orig/gcc/gcc.c
+++ gcc/gcc/gcc.c
@@ -6207,6 +6207,16 @@ main (int argc, char **argv)
   struct user_specs *uptr;
   char **old_argv = argv;
 
+#if HAVE_DOS_BASED_FILE_SYSTEM
+   if (argc > 0)
+     {
+	   char *pp;
+	   argv[0]=xstrdup (argv[0]);
+	   while ((pp = strchr (argv[0], '\\')) != NULL)
+		 *pp = '/';
+     }
+#endif
+
   /* Initialize here, not in definition.  The IRIX 6 O32 cc sometimes chokes
      on ?: in file-scope variable initializations.  */
   asm_debug = ASM_DEBUG_SPEC;

[-- Attachment #3: gcc-4.4.2-filename-normalize.patch --]
[-- Type: text/plain, Size: 3971 bytes --]

Vladimir Simonov(sv@sw.ru) - normailize filenames.
Useful if you crossbuild Linux app on Windows.
- Make filenames a bit shorter (constractions like ../dir/../ are collapced
  into ../dir). It sometimes helps to avoid Windows ascii-filenames length
  restriction (near to 160 bytes as I remenber).

--- gcc-4.4.2/include/filenames.h.orig	2010-01-28 14:58:49.000000000 +0300
+++ gcc-4.4.2/include/filenames.h	2010-01-28 16:26:23.000000000 +0300
@@ -52,6 +52,8 @@
 
 extern int filename_cmp (const char *s1, const char *s2);
 #define FILENAME_CMP(s1, s2)	filename_cmp(s1, s2)
+extern void filename_normalize (char *f);
+#define FILENAME_NORMALIZE(f)	filename_normalize(f)
 
 #ifdef __cplusplus
 }
--- gcc-4.4.2/libiberty/filename_cmp.c.orig	2010-01-28 14:59:04.000000000 +0300
+++ gcc-4.4.2/libiberty/filename_cmp.c	2010-01-28 16:23:36.000000000 +0300
@@ -76,3 +76,116 @@
 #endif
 }
 
+#ifdef HAVE_MEMMOVE
+#define memmove_left memmove
+#else
+static void *
+memmove_left (void *dest, const void *src, int n)
+{
+   char *d;
+   const char *s;
+   int i;
+   for (d = (char *)dest, s = (const char *)src, i = 0; i < n; i++)
+     *d++ = *s++;
+}
+#endif
+
+/*
+
+@deftypefn Extension void filename_normalize (char *@var{fn})
+
+This function tries to normalize file names inplace.
+
+@end deftypefn
+
+*/
+
+#ifndef HAVE_DOS_BASED_FILE_SYSTEM
+void
+filename_normalize (char *fn)
+#else
+static void
+filename_normalize_unix (char *fn)
+#endif
+{
+  char *p;
+  int rest;
+
+  rest = strlen (fn) + 1;
+  for (p = fn; *p != '\0' ; p++, rest--)
+    {
+      char *next;
+      const char *next2;
+      const char *next3;
+
+      next = p + 1;
+      if (*next == '\0')
+        break;
+      if (!IS_DIR_SEPARATOR( *p))
+          continue;
+      next2 = p + 2;
+      next3 = p + 3;
+      *p = '/';
+      /* don't handle some special cases, i.e. "//C/" on Microsoft Windows */
+      if (IS_DIR_SEPARATOR (*next))
+        {
+          memmove_left (next, next2, rest - 2);
+          p--;
+          continue;
+        }
+      if (*next != '.' || *next2 == '\0' || *next3 == '\0')
+          continue;
+      /* simplify "./" case */
+      if (IS_DIR_SEPARATOR (*next2))
+        {
+          memmove_left (next, next3, rest - 3);
+          rest--;
+          p--;
+          continue;
+        }
+      if (*next2 != '.' || ! IS_DIR_SEPARATOR (*next3))
+        continue;
+      while (--p >= fn)
+        {
+          if (*p == '/')
+            break;
+        }
+      if (p < fn)
+        {
+          if (*fn == '/')
+              memmove_left (p + 2, next3 + 1, rest - 4);
+          else if (*fn != '.')
+              memmove_left (p + 1, next3 + 1, rest - 4);
+          else
+            {
+              p = next - 1;
+              continue;
+            }
+        }
+      else if (*(p + 1) != '.')
+        {
+          memmove_left (p + 1, next3 + 1, rest - 4);
+          p--;
+        }
+      else
+        {
+          p = next - 1;
+          continue;
+        }
+      rest -= 2;
+    }
+}
+
+
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+void
+filename_normalize (char *fn)
+{
+  if (IS_DIR_SEPARATOR (fn[0]) || ! IS_ABSOLUTE_PATH (fn))
+    /* Absolute path in Unix style or relative path */
+    filename_normalize_unix (fn);
+  else if (fn[1] != '\0')
+    filename_normalize_unix (fn + 2);
+}
+#endif
+
--- gcc-4.4.2/libcpp/directives.c.orig	2010-01-28 15:09:00.000000000 +0300
+++ gcc-4.4.2/libcpp/directives.c	2010-01-28 16:28:04.000000000 +0300
@@ -716,6 +716,7 @@
       return NULL;
     }
 
+  FILENAME_NORMALIZE (fname);
   if (pfile->directive == &dtable[T_PRAGMA])
     {
       /* This pragma allows extra tokens after the file name.  */
--- gcc-4.4.2/libcpp/files.c.orig	2010-02-12 11:47:27.886977300 +0300
+++ gcc-4.4.2/libcpp/files.c	2010-02-14 15:38:39.757260300 +0300
@@ -355,6 +355,7 @@
 
   if (path)
     {
+      FILENAME_NORMALIZE (path);
       hashval_t hv = htab_hash_string (path);
       char *copy;
       void **pp;

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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-05 11:38                   ` Vladimir Simonov
@ 2011-03-05 12:45                     ` Kai Tietz
  0 siblings, 0 replies; 37+ messages in thread
From: Kai Tietz @ 2011-03-05 12:45 UTC (permalink / raw)
  To: Vladimir Simonov; +Cc: Mark Kettenis, eliz, brobecker, gdb-patches

2011/3/5 Vladimir Simonov <sv@sw.ru>:
> On 03/05/2011 12:13 PM, Kai Tietz wrote:
>>
>> 2011/3/4 Mark Kettenis<mark.kettenis@xs4all.nl>:
>>>>
>>>> Date: Fri, 4 Mar 2011 10:48:35 +0100
>>>> From: Kai Tietz<ktietz70@googlemail.com>
>>>>
>>>> 2011/3/3 Eli Zaretskii<eliz@gnu.org>:
>>>>>>
>>>>>> Date: Thu, 3 Mar 2011 18:58:32 +0400
>>>>>> From: Joel Brobecker<brobecker@adacore.com>
>>>>>> Cc: Kai Tietz<ktietz70@googlemail.com>, gdb-patches@sourceware.org
>>>>>>
>>>>>>> I didn't know that the Windows 64bit target can use ELF debug info.
>>>>>>> Can it?  With what toolchains?
>>>>>>>
>>>>>>> As for mdebugread.c, I always thought it was MIPS specific.  What
>>>>>>> other platforms use it?
>>>>>>
>>>>>> These would still be pertinent in the case of cross debugging, no?
>>>>>> If the files were cross-compiled on Windows, the debug info would
>>>>>> contain file paths that follow the Windows convention...
>>>>>
>>>>> Is that use-case even practical?  Who would develop on Windows if they
>>>>> have Linux or Irix?
>>>>>
>>>>> Anyway, if others don't mind to have DOS-ism in mdebugread.c and
>>>>> elfread.c, I don't object.
>>>>>
>>>>
>>>> I didn't saw here direct objections. So ok for apply?
>>>>
>>>> On a second thought about Pedros's switch for turning on
>>>> case-(in)sensitive-ness by switch, it could be helpful. But the
>>>> slash/backslash issue is something pretty incompatible. Windows host
>>>> don't have issues in general (not for all API) to use slash and
>>>> backslash, but on unix filesystem a backslash causes troubles. So we
>>>> need here some path/filename normalization.
>>>
>>> There is no problem with backslashes in path names on Unix-like
>>> systems.  Backslashes don't have a special meaning; they're just like
>>> normal letters.  That's exactly why a native debugger on a Unix-like
>>> system should not try to be DOS compatible at all.  And if you ask me,
>>> the same is true for a cross-debugger for a Unix-like target running
>>> on a Unix-like host.
>>
>> I didn't said that backslashes are forbidden characters in
>> file/directory names, I just mentioned that they are causing problems.
>> And well, you provided here the best example. A referenced filename -
>> eg. 'C:\source\xyz.c" - would be treated on Unix-like filesystem as
>> one file name and it wouldn't be an absolute path at all. How a user
>> should be able to match such a thing? Symbolic links (as suggested
>> before) won't work.
>
> Sorry for confusing about C: link.
>
> Yes, I've met the same problem several
> years ago. The solution was - fix original names on Windows side.
> For Windows names 'C:\source\xyz.c" and  'C:/source/xyz.c" are absolutely
> equivalent. If we replace "\\" with "/" in gcc command line,
> debug info will have records like C:/source/xyz.c
>
> Probably gcc-dosbase it is not needed - gcc command may
> converted by some external filter...
>
> With this patches all should be ok. I mean C: link or directory
> in current WD should work
>
> Best regards
> Vladimir Simonov
>

Yes, this patch at least avoids issues about written out
file-information.  But of course it doesn't touch the comparision
problematic itself. There are in gcc still a lot of issues about
file-comparisions and directory separators. Btw your patch looks
suitable for normalization from windows -> unix like file-system, but
not for vice-verse, as you are using here libiberties path-separator
macros, which are itself host dependent.

I prepared for gcc already a patch-set for addressing native-filename
comparision, but well, stage-4 doesn't look suitable for this.

Regards,
Kai


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-07 19:28             ` Jan Kratochvil
@ 2011-03-07 19:28               ` Pedro Alves
  2011-03-07 19:34                 ` Jan Kratochvil
  0 siblings, 1 reply; 37+ messages in thread
From: Pedro Alves @ 2011-03-07 19:28 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, Joel Brobecker, Eli Zaretskii, Kai Tietz

On Monday 07 March 2011 19:07:09, Jan Kratochvil wrote:
> As it (in most cases) contains absolute filenames it cannot be 
> transferred even between two unices.

What's wrong with "set substitute-path" ?

-- 
Pedro Alves


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 15:32           ` Pedro Alves
  2011-03-03 15:41             ` Kai Tietz
@ 2011-03-07 19:28             ` Jan Kratochvil
  2011-03-07 19:28               ` Pedro Alves
  1 sibling, 1 reply; 37+ messages in thread
From: Jan Kratochvil @ 2011-03-07 19:28 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Joel Brobecker, Eli Zaretskii, Kai Tietz

On Thu, 03 Mar 2011 16:32:19 +0100, Pedro Alves wrote:
> On Thursday 03 March 2011 14:58:32, Joel Brobecker wrote:
> > These would still be pertinent in the case of cross debugging, no?
> > If the files were cross-compiled on Windows, the debug info would
> > contain file paths that follow the Windows convention...
> 
> And then if you try to debug that on GNU/Linux, things still
> won't work, because filename_cmp changes behavior depending on host,
> not target or context.  That's why I believe there should be a clear
> distinction between what's a source path, and a host path.  I think
> Kai's bfd changes affect host paths, so they're fine. (haven't really
> checked, but that's what I imagine).  For source paths, I'd rather
> have this patch resurected...
> 
>  <http://sourceware.org/ml/gdb-patches/2010-12/msg00343.html>

debug info is not transferable between hosts.  As it (in most cases) contains
absolute filenames it cannot be transferred even between two unices.

For this purpose Fedora (+other distros different tools) provides
/usr/lib/rpm/debugedit for .debug filenames editing into a generalized form.

Any patches of GDB for target-specific filenames are not on the right place as
other utilities (such as binutils `objdump -dS' etc.) still remain broken.

As the post-link editing has a performance hit there may be some filename
adjustments provided in the producer (gcc) but IMO not in all the consumers.

As /usr/lib/rpm/debugedit (compilable as a general non-rpm utility) has some
limitations (as it does in-place filenames overwriting) with recent elfutils
support for DWARF reading+writing such a utility should be simple I hope.


So the host-only scope of this patchset I find right.  This is not a review of
its contents, just a statement on its scope.


Thanks,
Jan


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-07 19:28               ` Pedro Alves
@ 2011-03-07 19:34                 ` Jan Kratochvil
  0 siblings, 0 replies; 37+ messages in thread
From: Jan Kratochvil @ 2011-03-07 19:34 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Joel Brobecker, Eli Zaretskii, Kai Tietz

On Mon, 07 Mar 2011 20:19:21 +0100, Pedro Alves wrote:
> On Monday 07 March 2011 19:07:09, Jan Kratochvil wrote:
> > As it (in most cases) contains absolute filenames it cannot be 
> > transferred even between two unices.
> 
> What's wrong with "set substitute-path" ?

How do you do objdump --set-substitute-path?
How addr2line --set-substitute-path?  (OK, that one could be post-processed.)

OK, other utilities are more difficult to find but it illustrates that GDB is
not the place to fix this.


Thanks,
Jan


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-03 18:09           ` Eli Zaretskii
  2011-03-04  5:12             ` Joel Brobecker
  2011-03-04  9:48             ` Kai Tietz
@ 2011-03-23 11:16             ` Kai Tietz
  2011-03-23 12:44               ` Mark Kettenis
  2011-03-23 14:16               ` Pedro Alves
  2 siblings, 2 replies; 37+ messages in thread
From: Kai Tietz @ 2011-03-23 11:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Joel Brobecker, gdb-patches

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

2011/3/3 Eli Zaretskii <eliz@gnu.org>:
>> Date: Thu, 3 Mar 2011 18:58:32 +0400
>> From: Joel Brobecker <brobecker@adacore.com>
>> Cc: Kai Tietz <ktietz70@googlemail.com>, gdb-patches@sourceware.org
>>
>> > I didn't know that the Windows 64bit target can use ELF debug info.
>> > Can it?  With what toolchains?
>> >
>> > As for mdebugread.c, I always thought it was MIPS specific.  What
>> > other platforms use it?
>>
>> These would still be pertinent in the case of cross debugging, no?
>> If the files were cross-compiled on Windows, the debug info would
>> contain file paths that follow the Windows convention...
>
> Is that use-case even practical?  Who would develop on Windows if they
> have Linux or Irix?
>
> Anyway, if others don't mind to have DOS-ism in mdebugread.c and
> elfread.c, I don't object.
>

Hello,

I have updated patch against current trunk. Additionally I replaced
the strrchr-patterns by lbasename. As now some time has pasted, I
would like to kindly ask, if this patch is ok, or if there are still
objections?

2011-03-23  Kai Tietz

	* breakpoint.c (clear_command): Use filename_cmp
	instead of strcmp for comparision.
	* buildsym.c (watch_main_source_file_lossage): Likewise.
	(patch_subfile_names): Use IS_DIR_SEPARATOR instead of
	checking just for slash.
	* dbxread.c (read_dbx_symtab): Use lbasename instead of
	strrchr and filename_cmp instead of strcmp for filenames.
	(add_old_header_file): Use filename_cmp
	instead of strcmp for comparision.
	* exec.c (exec_set_section_address): Likewise.
	* macrotab.c (macro_lookup_inclusion): Likewise.
	(macro_lookup_inclusion): Likewise.
	* elfread.c (_initialize_elfread): Likewise.
	(elfstab_offset_sections): Likewise.
	(elfstab_offset_sections): Use lbasename instead of
	strrchr.
	* mdebugread.c (parse_partial_symbols): Likewise.
	(arse_partial_symbols): Use filename_(n)cmp instead of
	str(n)cmp for comparision.
	* minsyms.c (lookup_minimal_symbol): Likewise.
	* psymtab.c (read_psymtabs_with_filename): Likewise.
	* solib-som.c (match_main): Likewise.
	* solib.c (solib_read_symbols): Likewise.
	(reload_shared_libraries_1): Likewise.
	* symmisc.c (maintenance_print_symbols): Likewise.
	* symfile.c (separate_debug_file_exists): Likewise.
	(reread_symbols): Likewise.
	(find_separate_debug_file_by_debuglink): Likewise.
	* remote-fileio.c (remote_fileio_func_rename): Likewise.
	* source.c (add_path): Likewise.
	* symtab.c (filename_seen): Likewise.
	(file_matches): Likewise.
	(print_symbol_info): Likewise.
	(maybe_add_partial_symtab_filename): Likewise.
	(make_source_files_completion_list): Likewise.
	* xml-support.c (fetch_xml_builtin): Likewise.
	* xml-syscall.c (init_sysinfo): Likewise.
	* dwarf2read.c (find_file_and_directory): Use IS_ABSOLUTE_PATH.
	* windows-nat.c (_initialize_check_for_gdb_ini): Use
	IS_DIR_SEPARATOR for checking for trailing path separator.

Regards,
Kai

[-- Attachment #2: gdb_filename.txt --]
[-- Type: text/plain, Size: 23487 bytes --]

Index: gdb/breakpoint.c
===================================================================
--- gdb.orig/breakpoint.c	2011-03-23 10:31:59.635159300 +0100
+++ gdb/breakpoint.c	2011-03-23 10:56:17.014723000 +0100
@@ -39,6 +39,7 @@
 #include "language.h"
 #include "gdb_string.h"
 #include "demangle.h"
+#include "filenames.h"
 #include "annotate.h"
 #include "symfile.h"
 #include "objfiles.h"
@@ -9524,8 +9525,8 @@ clear_command (char *arg, int from_tty)
 				    && b->source_file != NULL
 				    && sal.symtab != NULL
 				    && sal.pspace == loc->pspace
-				    && strcmp (b->source_file,
-					       sal.symtab->filename) == 0
+				    && filename_cmp (b->source_file,
+						     sal.symtab->filename) == 0
 				    && b->line_number == sal.line);
 		  if (pc_match || line_match)
 		    {
Index: gdb/buildsym.c
===================================================================
--- gdb.orig/buildsym.c	2011-03-23 10:30:42.599811600 +0100
+++ gdb/buildsym.c	2011-03-23 10:56:17.059728700 +0100
@@ -643,7 +643,7 @@ void
 patch_subfile_names (struct subfile *subfile, char *name)
 {
   if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
-      && subfile->name[strlen (subfile->name) - 1] == '/')
+      && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
     {
       subfile->dirname = subfile->name;
       subfile->name = xstrdup (name);
@@ -878,7 +878,7 @@ watch_main_source_file_lossage (void)
 	   subfile->next;
 	   subfile = subfile->next)
 	{
-	  if (strcmp (lbasename (subfile->name), mainbase) == 0)
+	  if (filename_cmp (lbasename (subfile->name), mainbase) == 0)
 	    {
 	      ++nr_matches;
 	      mainsub_alias = subfile;
Index: gdb/dbxread.c
===================================================================
--- gdb.orig/dbxread.c	2011-03-23 10:32:00.133222600 +0100
+++ gdb/dbxread.c	2011-03-23 11:04:57.801854600 +0100
@@ -47,6 +47,7 @@
 #include "target.h"
 #include "gdbcore.h"		/* for bfd stuff */
 #include "libaout.h"		/* FIXME Secret internal BFD stuff for a.out */
+#include "filenames.h"
 #include "objfiles.h"
 #include "buildsym.h"
 #include "stabsread.h"
@@ -346,7 +347,7 @@ add_old_header_file (char *name, int ins
   int i;
 
   for (i = 0; i < N_HEADER_FILES (current_objfile); i++)
-    if (strcmp (p[i].name, name) == 0 && instance == p[i].instance)
+    if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
       {
 	add_this_object_header_file (i);
 	return;
@@ -1465,7 +1466,7 @@ read_dbx_symtab (struct objfile *objfile
 	    CORE_ADDR valu;
 	    static int prev_so_symnum = -10;
 	    static int first_so_symnum;
-	    char *p;
+	    const char *p;
 	    static char *dirname_nso;
 	    int prev_textlow_not_set;
 
@@ -1522,8 +1523,8 @@ read_dbx_symtab (struct objfile *objfile
 	       If pst exists, is empty, and has a filename ending in '/',
 	       we assume the previous N_SO was a directory name.  */
 
-	    p = strrchr (namestring, '/');
-	    if (p && *(p + 1) == '\000')
+	    p = lbasename (namestring);
+	    if (p != namestring && *p == '\000')
 	      {
 		/* Save the directory name SOs locally, then save it into
 		   the psymtab when it's created below.  */
@@ -1612,13 +1613,13 @@ read_dbx_symtab (struct objfile *objfile
 	       things like "break c-exp.y:435" need to work (I
 	       suppose the psymtab_include_list could be hashed or put
 	       in a binary tree, if profiling shows this is a major hog).  */
-	    if (pst && strcmp (namestring, pst->filename) == 0)
+	    if (pst && filename_cmp (namestring, pst->filename) == 0)
 	      continue;
 	    {
 	      int i;
 
 	      for (i = 0; i < includes_used; i++)
-		if (strcmp (namestring, psymtab_include_list[i]) == 0)
+		if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
 		  {
 		    i = -1;
 		    break;
Index: gdb/elfread.c
===================================================================
--- gdb.orig/elfread.c	2011-03-23 10:30:42.602811600 +0100
+++ gdb/elfread.c	2011-03-23 11:07:16.982028200 +0100
@@ -37,6 +37,7 @@
 #include "complaints.h"
 #include "demangle.h"
 #include "psympriv.h"
+#include "filenames.h"
 
 extern void _initialize_elfread (void);
 
@@ -707,7 +708,8 @@ find_separate_debug_file_by_buildid (str
       build_id_name = build_id_to_debug_filename (build_id);
       xfree (build_id);
       /* Prevent looping on a stripped .debug file.  */
-      if (build_id_name != NULL && strcmp (build_id_name, objfile->name) == 0)
+      if (build_id_name != NULL
+	  && filename_cmp (build_id_name, objfile->name) == 0)
         {
 	  warning (_("\"%s\": separate debug info file has no debug info"),
 		   build_id_name);
@@ -1023,12 +1025,13 @@ elfstab_offset_sections (struct objfile
   struct stab_section_info *maybe = dbx->stab_section_info;
   struct stab_section_info *questionable = 0;
   int i;
-  char *p;
+  const char *p;
 
   /* The ELF symbol info doesn't include path names, so strip the path
      (if any) from the psymtab filename.  */
-  while (0 != (p = strchr (filename, '/')))
-    filename = p + 1;
+  p = lbasename (filename);
+  if (p != filename)
+    filename = p;
 
   /* FIXME:  This linear search could speed up significantly
      if it was chained in the right order to match how we search it,
@@ -1036,7 +1039,7 @@ elfstab_offset_sections (struct objfile
   for (; maybe; maybe = maybe->next)
     {
       if (filename[0] == maybe->filename[0]
-	  && strcmp (filename, maybe->filename) == 0)
+	  && filename_cmp (filename, maybe->filename) == 0)
 	{
 	  /* We found a match.  But there might be several source files
 	     (from different directories) with the same name.  */
Index: gdb/exec.c
===================================================================
--- gdb.orig/exec.c	2011-03-23 10:32:00.438261300 +0100
+++ gdb/exec.c	2011-03-23 10:56:17.101734100 +0100
@@ -25,6 +25,7 @@
 #include "target.h"
 #include "gdbcmd.h"
 #include "language.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "completer.h"
@@ -845,7 +846,7 @@ exec_set_section_address (const char *fi
   table = current_target_sections;
   for (p = table->sections; p < table->sections_end; p++)
     {
-      if (strcmp (filename, p->bfd->filename) == 0
+      if (filename_cmp (filename, p->bfd->filename) == 0
 	  && index == p->the_bfd_section->index)
 	{
 	  p->endaddr += address - p->addr;
Index: gdb/macrotab.c
===================================================================
--- gdb.orig/macrotab.c	2011-03-23 10:30:42.604811600 +0100
+++ gdb/macrotab.c	2011-03-23 10:56:17.110235100 +0100
@@ -21,6 +21,7 @@
 #include "defs.h"
 #include "gdb_obstack.h"
 #include "splay-tree.h"
+#include "filenames.h"
 #include "symtab.h"
 #include "symfile.h"
 #include "objfiles.h"
@@ -500,7 +501,7 @@ struct macro_source_file *
 macro_lookup_inclusion (struct macro_source_file *source, const char *name)
 {
   /* Is SOURCE itself named NAME?  */
-  if (strcmp (name, source->filename) == 0)
+  if (filename_cmp (name, source->filename) == 0)
     return source;
 
   /* The filename in the source structure is probably a full path, but
@@ -510,11 +511,12 @@ macro_lookup_inclusion (struct macro_sou
     int src_name_len = strlen (source->filename);
 
     /* We do mean < here, and not <=; if the lengths are the same,
-       then the strcmp above should have triggered, and we need to
+       then the filename_cmp above should have triggered, and we need to
        check for a slash here.  */
     if (name_len < src_name_len
-        && source->filename[src_name_len - name_len - 1] == '/'
-        && strcmp (name, source->filename + src_name_len - name_len) == 0)
+        && IS_DIR_SEPARATOR (source->filename[src_name_len - name_len - 1])
+        && filename_cmp (name,
+			 source->filename + src_name_len - name_len) == 0)
       return source;
   }
 
Index: gdb/mdebugread.c
===================================================================
--- gdb.orig/mdebugread.c	2011-03-23 10:30:42.606811600 +0100
+++ gdb/mdebugread.c	2011-03-23 11:10:00.762825700 +0100
@@ -45,6 +45,7 @@
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "gdbcore.h"
+#include "filenames.h"
 #include "objfiles.h"
 #include "gdb_obstack.h"
 #include "buildsym.h"
@@ -2959,7 +2960,7 @@ parse_partial_symbols (struct objfile *o
 		      CORE_ADDR valu;
 		      static int prev_so_symnum = -10;
 		      static int first_so_symnum;
-		      char *p;
+		      const char *p;
 		      int prev_textlow_not_set;
 
 		      valu = sh.value + ANOFFSET (objfile->section_offsets,
@@ -3012,9 +3013,8 @@ parse_partial_symbols (struct objfile *o
 			 the second the file name.  If pst exists, is
 			 empty, and has a filename ending in '/', we assume
 			 the previous N_SO was a directory name.  */
-
-		      p = strrchr (namestring, '/');
-		      if (p && *(p + 1) == '\000')
+		      p = lbasename (namestring);
+		      if (p != namestring && *p == '\000')
 			continue;		/* Simply ignore directory
 						   name SOs.  */
 
@@ -3065,15 +3065,15 @@ parse_partial_symbols (struct objfile *o
 			 work (I suppose the psymtab_include_list could be
 			 hashed or put in a binary tree, if profiling shows
 			 this is a major hog).  */
-		      if (pst && strcmp (namestring, pst->filename) == 0)
+		      if (pst && filename_cmp (namestring, pst->filename) == 0)
 			continue;
 
 		      {
 			int i;
 
 			for (i = 0; i < includes_used; i++)
-			  if (strcmp (namestring,
-				      psymtab_include_list[i]) == 0)
+			  if (filename_cmp (namestring,
+					    psymtab_include_list[i]) == 0)
 			    {
 			      i = -1;
 			      break;
Index: gdb/minsyms.c
===================================================================
--- gdb.orig/minsyms.c	2011-03-23 10:30:42.607811600 +0100
+++ gdb/minsyms.c	2011-03-23 10:56:17.143739400 +0100
@@ -43,6 +43,7 @@
 #include "gdb_string.h"
 #include "symtab.h"
 #include "bfd.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "demangle.h"
@@ -255,7 +256,7 @@ lookup_minimal_symbol (const char *name,
                       case mst_file_data:
                       case mst_file_bss:
                         if (sfile == NULL
-			    || strcmp (msymbol->filename, sfile) == 0)
+			    || filename_cmp (msymbol->filename, sfile) == 0)
                           found_file_symbol = msymbol;
                         break;
 
Index: gdb/psymtab.c
===================================================================
--- gdb.orig/psymtab.c	2011-03-23 10:32:01.750427900 +0100
+++ gdb/psymtab.c	2011-03-23 10:56:17.153740700 +0100
@@ -1067,7 +1067,7 @@ read_psymtabs_with_filename (struct objf
 
   ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
     {
-      if (strcmp (filename, p->filename) == 0)
+      if (filename_cmp (filename, p->filename) == 0)
 	PSYMTAB_TO_SYMTAB (p);
     }
 }
@@ -1735,7 +1735,7 @@ print-psymbols takes an output file name
 
   immediate_quit++;
   ALL_PSYMTABS (objfile, ps)
-    if (symname == NULL || strcmp (symname, ps->filename) == 0)
+    if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
     dump_psymtab (objfile, ps, outfile);
   immediate_quit--;
   do_cleanups (cleanups);
Index: gdb/remote-fileio.c
===================================================================
--- gdb.orig/remote-fileio.c	2011-03-23 10:30:42.610811600 +0100
+++ gdb/remote-fileio.c	2011-03-23 11:26:45.795948700 +0100
@@ -31,6 +31,7 @@
 #include "remote-fileio.h"
 #include "event-loop.h"
 #include "target.h"
+#include "filenames.h"
 
 #include <fcntl.h>
 #include <sys/time.h>
@@ -1020,8 +1021,8 @@ remote_fileio_func_rename (char *buf)
 		  cygwin_conv_path (CCP_WIN_A_TO_POSIX, newpath, newfullpath,
 				    PATH_MAX);
 		  len = strlen (oldfullpath);
-		  if (newfullpath[len] == '/'
-		      && !strncmp (oldfullpath, newfullpath, len))
+		  if (IS_DIR_SEPARATOR (newfullpath[len])
+		      && !filename_ncmp (oldfullpath, newfullpath, len))
 		    errno = EINVAL;
 		  else
 		    errno = EEXIST;
Index: gdb/solib-som.c
===================================================================
--- gdb.orig/solib-som.c	2011-03-23 10:30:42.611811600 +0100
+++ gdb/solib-som.c	2011-03-23 10:56:17.174743300 +0100
@@ -21,6 +21,7 @@
 #include "defs.h"
 #include "symtab.h"
 #include "bfd.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "gdbcore.h"
@@ -568,7 +569,7 @@ link_map_start (void)
 static int
 match_main (const char *name)
 {
-  return strcmp (name, symfile_objfile->name) == 0;
+  return filename_cmp (name, symfile_objfile->name) == 0;
 }
 
 static struct so_list *
Index: gdb/solib.c
===================================================================
--- gdb.orig/solib.c	2011-03-23 10:30:42.612811600 +0100
+++ gdb/solib.c	2011-03-23 10:56:17.182744400 +0100
@@ -638,7 +638,7 @@ solib_read_symbols (struct so_list *so,
 	  /* Have we already loaded this shared object?  */
 	  ALL_OBJFILES (so->objfile)
 	    {
-	      if (strcmp (so->objfile->name, so->so_name) == 0
+	      if (filename_cmp (so->objfile->name, so->so_name) == 0
 		  && so->objfile->addr_low == so->addr_low)
 		break;
 	    }
@@ -762,7 +762,7 @@ update_solib_list (int from_tty, struct
 	    }
 	  else
 	    {
-	      if (! strcmp (gdb->so_original_name, i->so_original_name))
+	      if (! filename_cmp (gdb->so_original_name, i->so_original_name))
 		break;	      
 	    }
 
@@ -1339,7 +1339,7 @@ reload_shared_libraries_1 (int from_tty)
 	 symbol file, close that.  */
       if ((found_pathname == NULL && was_loaded)
 	  || (found_pathname != NULL
-	      && strcmp (found_pathname, so->so_name) != 0))
+	      && filename_cmp (found_pathname, so->so_name) != 0))
 	{
 	  if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED))
 	    free_objfile (so->objfile);
@@ -1351,7 +1351,7 @@ reload_shared_libraries_1 (int from_tty)
 	 file, open it.  */
       if (found_pathname != NULL
 	  && (!was_loaded
-	      || strcmp (found_pathname, so->so_name) != 0))
+	      || filename_cmp (found_pathname, so->so_name) != 0))
 	{
 	  volatile struct gdb_exception e;
 
Index: gdb/source.c
===================================================================
--- gdb.orig/source.c	2011-03-23 10:30:42.614811600 +0100
+++ gdb/source.c	2011-03-23 10:56:17.194745900 +0100
@@ -569,15 +569,10 @@ add_path (char *dirname, char **which_pa
 	p = *which_path;
 	while (1)
 	  {
-	    /* FIXME: strncmp loses in interesting ways on MS-DOS and
-	       MS-Windows because of case-insensitivity and two different
-	       but functionally identical slash characters.  We need a
-	       special filesystem-dependent file-name comparison function.
-
-	       Actually, even on Unix I would use realpath() or its work-
+	    /* Actually, even on Unix I would use realpath() or its work-
 	       alike before comparing.  Then all the code above which
 	       removes excess slashes and dots could simply go away.  */
-	    if (!strncmp (p, name, len)
+	    if (!filename_ncmp (p, name, len)
 		&& (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR))
 	      {
 		/* Found it in the search path, remove old copy.  */
Index: gdb/symfile.c
===================================================================
--- gdb.orig/symfile.c	2011-03-23 10:30:42.615811600 +0100
+++ gdb/symfile.c	2011-03-23 10:56:17.209747800 +0100
@@ -1325,7 +1325,7 @@ separate_debug_file_exists (const char *
      ".debug" suffix as "/usr/lib/debug/path/to/file" is a separate tree where
      the separate debug infos with the same basename can exist.  */
 
-  if (strcmp (name, parent_objfile->name) == 0)
+  if (filename_cmp (name, parent_objfile->name) == 0)
     return 0;
 
   abfd = bfd_open_maybe_remote (name);
@@ -1333,7 +1333,7 @@ separate_debug_file_exists (const char *
   if (!abfd)
     return 0;
 
-  /* Verify symlinks were not the cause of strcmp name difference above.
+  /* Verify symlinks were not the cause of filename_cmp name difference above.
 
      Some operating systems, e.g. Windows, do not provide a meaningful
      st_ino; they always set it to zero.  (Windows does provide a
@@ -1471,7 +1471,8 @@ find_separate_debug_file_by_debuglink (s
       /* If the file is in the sysroot, try using its base path in the
 	 global debugfile directory.  */
       if (canon_name
-	  && strncmp (canon_name, gdb_sysroot, strlen (gdb_sysroot)) == 0
+	  && filename_ncmp (canon_name, gdb_sysroot,
+			    strlen (gdb_sysroot)) == 0
 	  && IS_DIR_SEPARATOR (canon_name[strlen (gdb_sysroot)]))
 	{
 	  memcpy (debugfile, debugdir, debugdir_end - debugdir);
@@ -2375,8 +2376,9 @@ reread_symbols (void)
 	  /* We need to do this whenever any symbols go away.  */
 	  make_cleanup (clear_symtab_users_cleanup, 0 /*ignore*/);
 
-	  if (exec_bfd != NULL && strcmp (bfd_get_filename (objfile->obfd),
-					  bfd_get_filename (exec_bfd)) == 0)
+	  if (exec_bfd != NULL
+	      && filename_cmp (bfd_get_filename (objfile->obfd),
+			       bfd_get_filename (exec_bfd)) == 0)
 	    {
 	      /* Reload EXEC_BFD without asking anything.  */
 
Index: gdb/symmisc.c
===================================================================
--- gdb.orig/symmisc.c	2011-03-23 10:30:42.616811600 +0100
+++ gdb/symmisc.c	2011-03-23 10:56:17.233250800 +0100
@@ -23,6 +23,7 @@
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "bfd.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "breakpoint.h"
@@ -475,7 +476,7 @@ maintenance_print_symbols (char *args, i
 
   immediate_quit++;
   ALL_SYMTABS (objfile, s)
-    if (symname == NULL || strcmp (symname, s->filename) == 0)
+    if (symname == NULL || filename_cmp (symname, s->filename) == 0)
     dump_symtab (objfile, s, outfile);
   immediate_quit--;
   do_cleanups (cleanups);
Index: gdb/symtab.c
===================================================================
--- gdb.orig/symtab.c	2011-03-23 10:30:42.618811600 +0100
+++ gdb/symtab.c	2011-03-23 10:56:17.242251900 +0100
@@ -2761,7 +2761,7 @@ filename_seen (const char *file, int add
 
   /* Is FILE in tab?  */
   for (p = tab; p < tab + tab_cur_size; p++)
-    if (strcmp (*p, file) == 0)
+    if (filename_cmp (*p, file) == 0)
       return 1;
 
   /* No; maybe add it to tab.  */
@@ -2862,7 +2862,7 @@ file_matches (const char *file, char *fi
     {
       for (i = 0; i < nfiles; i++)
 	{
-	  if (strcmp (files[i], lbasename (file)) == 0)
+	  if (filename_cmp (files[i], lbasename (file)) == 0)
 	    return 1;
 	}
     }
@@ -3260,7 +3260,7 @@ static void
 print_symbol_info (domain_enum kind, struct symtab *s, struct symbol *sym,
 		   int block, char *last)
 {
-  if (last == NULL || strcmp (last, s->filename) != 0)
+  if (last == NULL || filename_cmp (last, s->filename) != 0)
     {
       fputs_filtered ("\nFile ", gdb_stdout);
       fputs_filtered (s->filename, gdb_stdout);
@@ -4073,7 +4073,7 @@ not_interesting_fname (const char *fname
 
   for (i = 0; illegal_aliens[i]; i++)
     {
-      if (strcmp (fname, illegal_aliens[i]) == 0)
+      if (filename_cmp (fname, illegal_aliens[i]) == 0)
 	return 1;
     }
   return 0;
@@ -4102,12 +4102,7 @@ maybe_add_partial_symtab_filename (const
   if (not_interesting_fname (filename))
     return;
   if (!filename_seen (filename, 1, data->first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-      && strncasecmp (filename, data->text, data->text_len) == 0
-#else
-      && strncmp (filename, data->text, data->text_len) == 0
-#endif
-      )
+      && filename_ncmp (filename, data->text, data->text_len) == 0)
     {
       /* This file matches for a completion; add it to the
 	 current list of matches.  */
@@ -4120,12 +4115,7 @@ maybe_add_partial_symtab_filename (const
 
       if (base_name != filename
 	  && !filename_seen (base_name, 1, data->first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	  && strncasecmp (base_name, data->text, data->text_len) == 0
-#else
-	  && strncmp (base_name, data->text, data->text_len) == 0
-#endif
-	  )
+	  && filename_ncmp (base_name, data->text, data->text_len) == 0)
 	add_filename_to_list (base_name, data->text, data->word,
 			      data->list, data->list_used, data->list_alloced);
     }
@@ -4159,12 +4149,7 @@ make_source_files_completion_list (char
       if (not_interesting_fname (s->filename))
 	continue;
       if (!filename_seen (s->filename, 1, &first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	  && strncasecmp (s->filename, text, text_len) == 0
-#else
-	  && strncmp (s->filename, text, text_len) == 0
-#endif
-	  )
+	  && filename_ncmp (s->filename, text, text_len) == 0)
 	{
 	  /* This file matches for a completion; add it to the current
 	     list of matches.  */
@@ -4180,12 +4165,7 @@ make_source_files_completion_list (char
 	  base_name = lbasename (s->filename);
 	  if (base_name != s->filename
 	      && !filename_seen (base_name, 1, &first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	      && strncasecmp (base_name, text, text_len) == 0
-#else
-	      && strncmp (base_name, text, text_len) == 0
-#endif
-	      )
+	      && filename_ncmp (base_name, text, text_len) == 0)
 	    add_filename_to_list (base_name, text, word,
 				  &list, &list_used, &list_alloced);
 	}
Index: gdb/xml-support.c
===================================================================
--- gdb.orig/xml-support.c	2011-03-23 10:30:42.620811600 +0100
+++ gdb/xml-support.c	2011-03-23 10:56:17.265754900 +0100
@@ -25,6 +25,7 @@
 
 #include "gdb_string.h"
 #include "safe-ctype.h"
+#include "filenames.h"
 
 /* Debugging flag.  */
 static int debug_xml;
@@ -946,7 +947,7 @@ fetch_xml_builtin (const char *filename)
   const char *(*p)[2];
 
   for (p = xml_builtin; (*p)[0]; p++)
-    if (strcmp ((*p)[0], filename) == 0)
+    if (filename_cmp ((*p)[0], filename) == 0)
       return (*p)[1];
 
   return NULL;
Index: gdb/xml-syscall.c
===================================================================
--- gdb.orig/xml-syscall.c	2011-03-23 10:30:42.649811600 +0100
+++ gdb/xml-syscall.c	2011-03-23 10:56:17.274256000 +0100
@@ -281,7 +281,7 @@ static void
 init_sysinfo (void)
 {
   /* Should we re-read the XML info for this target?  */
-  if (my_gdb_datadir && strcmp (my_gdb_datadir, gdb_datadir) != 0)
+  if (my_gdb_datadir && filename_cmp (my_gdb_datadir, gdb_datadir) != 0)
     {
       /* The data-directory changed from the last time we used it.
 	 It means that we have to re-read the XML info.  */
Index: gdb/dwarf2read.c
===================================================================
--- gdb.orig/dwarf2read.c	2011-03-23 10:32:00.336248300 +0100
+++ gdb/dwarf2read.c	2011-03-23 10:56:17.285257400 +0100
@@ -5211,7 +5211,8 @@ find_file_and_directory (struct die_info
 	 directory, get rid of it.  */
       char *cp = strchr (*comp_dir, ':');
 
-      if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
+      if (cp && cp != *comp_dir && cp[-1] == '.'
+	  && IS_ABSOLUTE_PATH (&cp[1]))
 	*comp_dir = cp + 1;
     }
 
Index: gdb/windows-nat.c
===================================================================
--- gdb.orig/windows-nat.c	2011-03-23 10:32:03.138104100 +0100
+++ gdb/windows-nat.c	2011-03-23 10:56:17.336763900 +0100
@@ -46,6 +46,7 @@
 #include <signal.h>
 
 #include "buildsym.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "gdb_obstack.h"
@@ -2586,7 +2587,7 @@ _initialize_check_for_gdb_ini (void)
 				      sizeof ("/gdb.ini"));
       strcpy (oldini, homedir);
       p = strchr (oldini, '\0');
-      if (p > oldini && p[-1] != '/')
+      if (p > oldini && !IS_DIR_SEPARATOR (p[-1]))
 	*p++ = '/';
       strcpy (p, "gdb.ini");
       if (access (oldini, 0) == 0)

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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-23 11:16             ` Kai Tietz
@ 2011-03-23 12:44               ` Mark Kettenis
  2011-03-23 14:07                 ` Kai Tietz
  2011-03-23 14:16               ` Pedro Alves
  1 sibling, 1 reply; 37+ messages in thread
From: Mark Kettenis @ 2011-03-23 12:44 UTC (permalink / raw)
  To: ktietz70; +Cc: eliz, brobecker, gdb-patches

> Date: Wed, 23 Mar 2011 11:39:33 +0100
> From: Kai Tietz <ktietz70@googlemail.com>
> 
> 2011/3/3 Eli Zaretskii <eliz@gnu.org>:
> >> Date: Thu, 3 Mar 2011 18:58:32 +0400
> >> From: Joel Brobecker <brobecker@adacore.com>
> >> Cc: Kai Tietz <ktietz70@googlemail.com>, gdb-patches@sourceware.org
> >>
> >> > I didn't know that the Windows 64bit target can use ELF debug info.
> >> > Can it? =A0With what toolchains?
> >> >
> >> > As for mdebugread.c, I always thought it was MIPS specific. =A0What
> >> > other platforms use it?
> >>
> >> These would still be pertinent in the case of cross debugging, no?
> >> If the files were cross-compiled on Windows, the debug info would
> >> contain file paths that follow the Windows convention...
> >
> > Is that use-case even practical? =A0Who would develop on Windows if they
> > have Linux or Irix?
> >
> > Anyway, if others don't mind to have DOS-ism in mdebugread.c and
> > elfread.c, I don't object.
> >
> 
> Hello,
> 
> I have updated patch against current trunk. Additionally I replaced
> the strrchr-patterns by lbasename. As now some time has pasted, I
> would like to kindly ask, if this patch is ok, or if there are still
> objections?

You continue to make it hard for me to review your diffs by sending
them as base64-encoded MIME attachments.  But the solib-som.c bit
should be dropped.  It's a HP-UX native-only bit.

> 2011-03-23  Kai Tietz
> 
> 	* breakpoint.c (clear_command): Use filename_cmp
> 	instead of strcmp for comparision.
> 	* buildsym.c (watch_main_source_file_lossage): Likewise.
> 	(patch_subfile_names): Use IS_DIR_SEPARATOR instead of
> 	checking just for slash.
> 	* dbxread.c (read_dbx_symtab): Use lbasename instead of
> 	strrchr and filename_cmp instead of strcmp for filenames.
> 	(add_old_header_file): Use filename_cmp
> 	instead of strcmp for comparision.
> 	* exec.c (exec_set_section_address): Likewise.
> 	* macrotab.c (macro_lookup_inclusion): Likewise.
> 	(macro_lookup_inclusion): Likewise.
> 	* elfread.c (_initialize_elfread): Likewise.
> 	(elfstab_offset_sections): Likewise.
> 	(elfstab_offset_sections): Use lbasename instead of
> 	strrchr.
> 	* mdebugread.c (parse_partial_symbols): Likewise.
> 	(arse_partial_symbols): Use filename_(n)cmp instead of
> 	str(n)cmp for comparision.
> 	* minsyms.c (lookup_minimal_symbol): Likewise.
> 	* psymtab.c (read_psymtabs_with_filename): Likewise.
> 	* solib-som.c (match_main): Likewise.
> 	* solib.c (solib_read_symbols): Likewise.
> 	(reload_shared_libraries_1): Likewise.
> 	* symmisc.c (maintenance_print_symbols): Likewise.
> 	* symfile.c (separate_debug_file_exists): Likewise.
> 	(reread_symbols): Likewise.
> 	(find_separate_debug_file_by_debuglink): Likewise.
> 	* remote-fileio.c (remote_fileio_func_rename): Likewise.
> 	* source.c (add_path): Likewise.
> 	* symtab.c (filename_seen): Likewise.
> 	(file_matches): Likewise.
> 	(print_symbol_info): Likewise.
> 	(maybe_add_partial_symtab_filename): Likewise.
> 	(make_source_files_completion_list): Likewise.
> 	* xml-support.c (fetch_xml_builtin): Likewise.
> 	* xml-syscall.c (init_sysinfo): Likewise.
> 	* dwarf2read.c (find_file_and_directory): Use IS_ABSOLUTE_PATH.
> 	* windows-nat.c (_initialize_check_for_gdb_ini): Use
> 	IS_DIR_SEPARATOR for checking for trailing path separator.
> 
> Regards,
> Kai
> 
> --90e6ba5bb9ddf94d87049f23f904
> Content-Type: text/plain; charset=US-ASCII; name="gdb_filename.txt"
> Content-Disposition: attachment; filename="gdb_filename.txt"
> Content-Transfer-Encoding: base64
> X-Attachment-Id: f_glm4fqsk0
> 
> SW5kZXg6IGdkYi9icmVha3BvaW50LmMKPT09PT09PT09PT09PT09PT09PT09
> PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
> PQotLS0gZ2RiLm9yaWcvYnJlYWtwb2ludC5jCTIwMTEtMDMtMjMgMTA6MzE6
> NTkuNjM1MTU5MzAwICswMTAwCisrKyBnZGIvYnJlYWtwb2ludC5jCTIwMTEt
> MDMtMjMgMTA6NTY6MTcuMDE0NzIzMDAwICswMTAwCkBAIC0zOSw2ICszOSw3


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-23 12:44               ` Mark Kettenis
@ 2011-03-23 14:07                 ` Kai Tietz
  0 siblings, 0 replies; 37+ messages in thread
From: Kai Tietz @ 2011-03-23 14:07 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: eliz, brobecker, gdb-patches

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

2011/3/23 Mark Kettenis <mark.kettenis@xs4all.nl>:
>> Date: Wed, 23 Mar 2011 11:39:33 +0100
>> From: Kai Tietz <ktietz70@googlemail.com>
>>
>> 2011/3/3 Eli Zaretskii <eliz@gnu.org>:
>> >> Date: Thu, 3 Mar 2011 18:58:32 +0400
>> >> From: Joel Brobecker <brobecker@adacore.com>
>> >> Cc: Kai Tietz <ktietz70@googlemail.com>, gdb-patches@sourceware.org
>> >>
>> >> > I didn't know that the Windows 64bit target can use ELF debug info.
>> >> > Can it? =A0With what toolchains?
>> >> >
>> >> > As for mdebugread.c, I always thought it was MIPS specific. =A0What
>> >> > other platforms use it?
>> >>
>> >> These would still be pertinent in the case of cross debugging, no?
>> >> If the files were cross-compiled on Windows, the debug info would
>> >> contain file paths that follow the Windows convention...
>> >
>> > Is that use-case even practical? =A0Who would develop on Windows if they
>> > have Linux or Irix?
>> >
>> > Anyway, if others don't mind to have DOS-ism in mdebugread.c and
>> > elfread.c, I don't object.
>> >
>>
>> Hello,
>>
>> I have updated patch against current trunk. Additionally I replaced
>> the strrchr-patterns by lbasename. As now some time has pasted, I
>> would like to kindly ask, if this patch is ok, or if there are still
>> objections?
>
> You continue to make it hard for me to review your diffs by sending
> them as base64-encoded MIME attachments.  But the solib-som.c bit
> should be dropped.  It's a HP-UX native-only bit.

Sorry for that, but this encoding is controlled by the gmail account.
By naming them .txt at least I get plain/text encoding and not binary
octet-stream.

I removed file from patch. Here is the updated ChangeLog plus patch.

2011-03-23  Kai Tietz

	* breakpoint.c (clear_command): Use filename_cmp
	instead of strcmp for comparision.
	* buildsym.c (watch_main_source_file_lossage): Likewise.
	(patch_subfile_names): Use IS_DIR_SEPARATOR instead of
	checking just for slash.
	* dbxread.c (read_dbx_symtab): Use lbasename instead of
	strrchr and filename_cmp instead of strcmp for filenames.
	(add_old_header_file): Use filename_cmp
	instead of strcmp for comparision.
	* exec.c (exec_set_section_address): Likewise.
	* macrotab.c (macro_lookup_inclusion): Likewise.
	(macro_lookup_inclusion): Likewise.
	* elfread.c (_initialize_elfread): Likewise.
	(elfstab_offset_sections): Likewise.
	(elfstab_offset_sections): Use lbasename instead of
	strrchr.
	* mdebugread.c (parse_partial_symbols): Likewise.
	(arse_partial_symbols): Use filename_(n)cmp instead of
	str(n)cmp for comparision.
	* minsyms.c (lookup_minimal_symbol): Likewise.
	* psymtab.c (read_psymtabs_with_filename): Likewise.
	* solib.c (solib_read_symbols): Likewise.
	(reload_shared_libraries_1): Likewise.
	* symmisc.c (maintenance_print_symbols): Likewise.
	* symfile.c (separate_debug_file_exists): Likewise.
	(reread_symbols): Likewise.
	(find_separate_debug_file_by_debuglink): Likewise.
	* remote-fileio.c (remote_fileio_func_rename): Likewise.
	* source.c (add_path): Likewise.
	* symtab.c (filename_seen): Likewise.
	(file_matches): Likewise.
	(print_symbol_info): Likewise.
	(maybe_add_partial_symtab_filename): Likewise.
	(make_source_files_completion_list): Likewise.
	* xml-support.c (fetch_xml_builtin): Likewise.
	* xml-syscall.c (init_sysinfo): Likewise.
	* dwarf2read.c (find_file_and_directory): Use IS_ABSOLUTE_PATH.
	* windows-nat.c (_initialize_check_for_gdb_ini): Use
	IS_DIR_SEPARATOR for checking for trailing path separator.

Regards,
Kai

[-- Attachment #2: gdb_filename.txt --]
[-- Type: text/plain, Size: 22882 bytes --]

Index: gdb/breakpoint.c
===================================================================
--- gdb.orig/breakpoint.c	2011-03-23 12:10:37.825811600 +0100
+++ gdb/breakpoint.c	2011-03-23 12:12:32.364218600 +0100
@@ -39,6 +39,7 @@
 #include "language.h"
 #include "gdb_string.h"
 #include "demangle.h"
+#include "filenames.h"
 #include "annotate.h"
 #include "symfile.h"
 #include "objfiles.h"
@@ -9524,8 +9525,8 @@ clear_command (char *arg, int from_tty)
 				    && b->source_file != NULL
 				    && sal.symtab != NULL
 				    && sal.pspace == loc->pspace
-				    && strcmp (b->source_file,
-					       sal.symtab->filename) == 0
+				    && filename_cmp (b->source_file,
+						     sal.symtab->filename) == 0
 				    && b->line_number == sal.line);
 		  if (pc_match || line_match)
 		    {
Index: gdb/buildsym.c
===================================================================
--- gdb.orig/buildsym.c	2011-03-23 12:10:37.826811600 +0100
+++ gdb/buildsym.c	2011-03-23 12:12:32.408724300 +0100
@@ -643,7 +643,7 @@ void
 patch_subfile_names (struct subfile *subfile, char *name)
 {
   if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
-      && subfile->name[strlen (subfile->name) - 1] == '/')
+      && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
     {
       subfile->dirname = subfile->name;
       subfile->name = xstrdup (name);
@@ -878,7 +878,7 @@ watch_main_source_file_lossage (void)
 	   subfile->next;
 	   subfile = subfile->next)
 	{
-	  if (strcmp (lbasename (subfile->name), mainbase) == 0)
+	  if (filename_cmp (lbasename (subfile->name), mainbase) == 0)
 	    {
 	      ++nr_matches;
 	      mainsub_alias = subfile;
Index: gdb/dbxread.c
===================================================================
--- gdb.orig/dbxread.c	2011-03-23 12:10:37.827811600 +0100
+++ gdb/dbxread.c	2011-03-23 12:12:32.419725700 +0100
@@ -47,6 +47,7 @@
 #include "target.h"
 #include "gdbcore.h"		/* for bfd stuff */
 #include "libaout.h"		/* FIXME Secret internal BFD stuff for a.out */
+#include "filenames.h"
 #include "objfiles.h"
 #include "buildsym.h"
 #include "stabsread.h"
@@ -346,7 +347,7 @@ add_old_header_file (char *name, int ins
   int i;
 
   for (i = 0; i < N_HEADER_FILES (current_objfile); i++)
-    if (strcmp (p[i].name, name) == 0 && instance == p[i].instance)
+    if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
       {
 	add_this_object_header_file (i);
 	return;
@@ -1465,7 +1466,7 @@ read_dbx_symtab (struct objfile *objfile
 	    CORE_ADDR valu;
 	    static int prev_so_symnum = -10;
 	    static int first_so_symnum;
-	    char *p;
+	    const char *p;
 	    static char *dirname_nso;
 	    int prev_textlow_not_set;
 
@@ -1522,8 +1523,8 @@ read_dbx_symtab (struct objfile *objfile
 	       If pst exists, is empty, and has a filename ending in '/',
 	       we assume the previous N_SO was a directory name.  */
 
-	    p = strrchr (namestring, '/');
-	    if (p && *(p + 1) == '\000')
+	    p = lbasename (namestring);
+	    if (p != namestring && *p == '\000')
 	      {
 		/* Save the directory name SOs locally, then save it into
 		   the psymtab when it's created below.  */
@@ -1612,13 +1613,13 @@ read_dbx_symtab (struct objfile *objfile
 	       things like "break c-exp.y:435" need to work (I
 	       suppose the psymtab_include_list could be hashed or put
 	       in a binary tree, if profiling shows this is a major hog).  */
-	    if (pst && strcmp (namestring, pst->filename) == 0)
+	    if (pst && filename_cmp (namestring, pst->filename) == 0)
 	      continue;
 	    {
 	      int i;
 
 	      for (i = 0; i < includes_used; i++)
-		if (strcmp (namestring, psymtab_include_list[i]) == 0)
+		if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
 		  {
 		    i = -1;
 		    break;
Index: gdb/elfread.c
===================================================================
--- gdb.orig/elfread.c	2011-03-23 12:10:37.829811600 +0100
+++ gdb/elfread.c	2011-03-23 12:12:32.439728200 +0100
@@ -37,6 +37,7 @@
 #include "complaints.h"
 #include "demangle.h"
 #include "psympriv.h"
+#include "filenames.h"
 
 extern void _initialize_elfread (void);
 
@@ -707,7 +708,8 @@ find_separate_debug_file_by_buildid (str
       build_id_name = build_id_to_debug_filename (build_id);
       xfree (build_id);
       /* Prevent looping on a stripped .debug file.  */
-      if (build_id_name != NULL && strcmp (build_id_name, objfile->name) == 0)
+      if (build_id_name != NULL
+	  && filename_cmp (build_id_name, objfile->name) == 0)
         {
 	  warning (_("\"%s\": separate debug info file has no debug info"),
 		   build_id_name);
@@ -1023,12 +1025,13 @@ elfstab_offset_sections (struct objfile
   struct stab_section_info *maybe = dbx->stab_section_info;
   struct stab_section_info *questionable = 0;
   int i;
-  char *p;
+  const char *p;
 
   /* The ELF symbol info doesn't include path names, so strip the path
      (if any) from the psymtab filename.  */
-  while (0 != (p = strchr (filename, '/')))
-    filename = p + 1;
+  p = lbasename (filename);
+  if (p != filename)
+    filename = p;
 
   /* FIXME:  This linear search could speed up significantly
      if it was chained in the right order to match how we search it,
@@ -1036,7 +1039,7 @@ elfstab_offset_sections (struct objfile
   for (; maybe; maybe = maybe->next)
     {
       if (filename[0] == maybe->filename[0]
-	  && strcmp (filename, maybe->filename) == 0)
+	  && filename_cmp (filename, maybe->filename) == 0)
 	{
 	  /* We found a match.  But there might be several source files
 	     (from different directories) with the same name.  */
Index: gdb/exec.c
===================================================================
--- gdb.orig/exec.c	2011-03-23 12:10:37.830811600 +0100
+++ gdb/exec.c	2011-03-23 12:12:32.448729300 +0100
@@ -25,6 +25,7 @@
 #include "target.h"
 #include "gdbcmd.h"
 #include "language.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "completer.h"
@@ -845,7 +846,7 @@ exec_set_section_address (const char *fi
   table = current_target_sections;
   for (p = table->sections; p < table->sections_end; p++)
     {
-      if (strcmp (filename, p->bfd->filename) == 0
+      if (filename_cmp (filename, p->bfd->filename) == 0
 	  && index == p->the_bfd_section->index)
 	{
 	  p->endaddr += address - p->addr;
Index: gdb/macrotab.c
===================================================================
--- gdb.orig/macrotab.c	2011-03-23 12:10:37.831811600 +0100
+++ gdb/macrotab.c	2011-03-23 12:12:32.456230300 +0100
@@ -21,6 +21,7 @@
 #include "defs.h"
 #include "gdb_obstack.h"
 #include "splay-tree.h"
+#include "filenames.h"
 #include "symtab.h"
 #include "symfile.h"
 #include "objfiles.h"
@@ -500,7 +501,7 @@ struct macro_source_file *
 macro_lookup_inclusion (struct macro_source_file *source, const char *name)
 {
   /* Is SOURCE itself named NAME?  */
-  if (strcmp (name, source->filename) == 0)
+  if (filename_cmp (name, source->filename) == 0)
     return source;
 
   /* The filename in the source structure is probably a full path, but
@@ -510,11 +511,12 @@ macro_lookup_inclusion (struct macro_sou
     int src_name_len = strlen (source->filename);
 
     /* We do mean < here, and not <=; if the lengths are the same,
-       then the strcmp above should have triggered, and we need to
+       then the filename_cmp above should have triggered, and we need to
        check for a slash here.  */
     if (name_len < src_name_len
-        && source->filename[src_name_len - name_len - 1] == '/'
-        && strcmp (name, source->filename + src_name_len - name_len) == 0)
+        && IS_DIR_SEPARATOR (source->filename[src_name_len - name_len - 1])
+        && filename_cmp (name,
+			 source->filename + src_name_len - name_len) == 0)
       return source;
   }
 
Index: gdb/mdebugread.c
===================================================================
--- gdb.orig/mdebugread.c	2011-03-23 12:10:37.832811600 +0100
+++ gdb/mdebugread.c	2011-03-23 12:12:32.466231600 +0100
@@ -45,6 +45,7 @@
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "gdbcore.h"
+#include "filenames.h"
 #include "objfiles.h"
 #include "gdb_obstack.h"
 #include "buildsym.h"
@@ -2959,7 +2960,7 @@ parse_partial_symbols (struct objfile *o
 		      CORE_ADDR valu;
 		      static int prev_so_symnum = -10;
 		      static int first_so_symnum;
-		      char *p;
+		      const char *p;
 		      int prev_textlow_not_set;
 
 		      valu = sh.value + ANOFFSET (objfile->section_offsets,
@@ -3012,9 +3013,8 @@ parse_partial_symbols (struct objfile *o
 			 the second the file name.  If pst exists, is
 			 empty, and has a filename ending in '/', we assume
 			 the previous N_SO was a directory name.  */
-
-		      p = strrchr (namestring, '/');
-		      if (p && *(p + 1) == '\000')
+		      p = lbasename (namestring);
+		      if (p != namestring && *p == '\000')
 			continue;		/* Simply ignore directory
 						   name SOs.  */
 
@@ -3065,15 +3065,15 @@ parse_partial_symbols (struct objfile *o
 			 work (I suppose the psymtab_include_list could be
 			 hashed or put in a binary tree, if profiling shows
 			 this is a major hog).  */
-		      if (pst && strcmp (namestring, pst->filename) == 0)
+		      if (pst && filename_cmp (namestring, pst->filename) == 0)
 			continue;
 
 		      {
 			int i;
 
 			for (i = 0; i < includes_used; i++)
-			  if (strcmp (namestring,
-				      psymtab_include_list[i]) == 0)
+			  if (filename_cmp (namestring,
+					    psymtab_include_list[i]) == 0)
 			    {
 			      i = -1;
 			      break;
Index: gdb/minsyms.c
===================================================================
--- gdb.orig/minsyms.c	2011-03-23 12:10:37.833811600 +0100
+++ gdb/minsyms.c	2011-03-23 12:12:32.489234500 +0100
@@ -43,6 +43,7 @@
 #include "gdb_string.h"
 #include "symtab.h"
 #include "bfd.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "demangle.h"
@@ -255,7 +256,7 @@ lookup_minimal_symbol (const char *name,
                       case mst_file_data:
                       case mst_file_bss:
                         if (sfile == NULL
-			    || strcmp (msymbol->filename, sfile) == 0)
+			    || filename_cmp (msymbol->filename, sfile) == 0)
                           found_file_symbol = msymbol;
                         break;
 
Index: gdb/psymtab.c
===================================================================
--- gdb.orig/psymtab.c	2011-03-23 12:10:37.834811600 +0100
+++ gdb/psymtab.c	2011-03-23 12:12:32.498735700 +0100
@@ -1067,7 +1067,7 @@ read_psymtabs_with_filename (struct objf
 
   ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
     {
-      if (strcmp (filename, p->filename) == 0)
+      if (filename_cmp (filename, p->filename) == 0)
 	PSYMTAB_TO_SYMTAB (p);
     }
 }
@@ -1735,7 +1735,7 @@ print-psymbols takes an output file name
 
   immediate_quit++;
   ALL_PSYMTABS (objfile, ps)
-    if (symname == NULL || strcmp (symname, ps->filename) == 0)
+    if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
     dump_psymtab (objfile, ps, outfile);
   immediate_quit--;
   do_cleanups (cleanups);
Index: gdb/remote-fileio.c
===================================================================
--- gdb.orig/remote-fileio.c	2011-03-23 12:10:37.835811600 +0100
+++ gdb/remote-fileio.c	2011-03-23 12:12:32.510237200 +0100
@@ -31,6 +31,7 @@
 #include "remote-fileio.h"
 #include "event-loop.h"
 #include "target.h"
+#include "filenames.h"
 
 #include <fcntl.h>
 #include <sys/time.h>
@@ -1020,8 +1021,8 @@ remote_fileio_func_rename (char *buf)
 		  cygwin_conv_path (CCP_WIN_A_TO_POSIX, newpath, newfullpath,
 				    PATH_MAX);
 		  len = strlen (oldfullpath);
-		  if (newfullpath[len] == '/'
-		      && !strncmp (oldfullpath, newfullpath, len))
+		  if (IS_DIR_SEPARATOR (newfullpath[len])
+		      && !filename_ncmp (oldfullpath, newfullpath, len))
 		    errno = EINVAL;
 		  else
 		    errno = EEXIST;
Index: gdb/solib.c
===================================================================
--- gdb.orig/solib.c	2011-03-23 12:10:37.837811600 +0100
+++ gdb/solib.c	2011-03-23 12:12:32.519238300 +0100
@@ -638,7 +638,7 @@ solib_read_symbols (struct so_list *so,
 	  /* Have we already loaded this shared object?  */
 	  ALL_OBJFILES (so->objfile)
 	    {
-	      if (strcmp (so->objfile->name, so->so_name) == 0
+	      if (filename_cmp (so->objfile->name, so->so_name) == 0
 		  && so->objfile->addr_low == so->addr_low)
 		break;
 	    }
@@ -762,7 +762,7 @@ update_solib_list (int from_tty, struct
 	    }
 	  else
 	    {
-	      if (! strcmp (gdb->so_original_name, i->so_original_name))
+	      if (! filename_cmp (gdb->so_original_name, i->so_original_name))
 		break;	      
 	    }
 
@@ -1339,7 +1339,7 @@ reload_shared_libraries_1 (int from_tty)
 	 symbol file, close that.  */
       if ((found_pathname == NULL && was_loaded)
 	  || (found_pathname != NULL
-	      && strcmp (found_pathname, so->so_name) != 0))
+	      && filename_cmp (found_pathname, so->so_name) != 0))
 	{
 	  if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED))
 	    free_objfile (so->objfile);
@@ -1351,7 +1351,7 @@ reload_shared_libraries_1 (int from_tty)
 	 file, open it.  */
       if (found_pathname != NULL
 	  && (!was_loaded
-	      || strcmp (found_pathname, so->so_name) != 0))
+	      || filename_cmp (found_pathname, so->so_name) != 0))
 	{
 	  volatile struct gdb_exception e;
 
Index: gdb/source.c
===================================================================
--- gdb.orig/source.c	2011-03-23 12:10:37.838811600 +0100
+++ gdb/source.c	2011-03-23 12:12:32.529739600 +0100
@@ -569,15 +569,10 @@ add_path (char *dirname, char **which_pa
 	p = *which_path;
 	while (1)
 	  {
-	    /* FIXME: strncmp loses in interesting ways on MS-DOS and
-	       MS-Windows because of case-insensitivity and two different
-	       but functionally identical slash characters.  We need a
-	       special filesystem-dependent file-name comparison function.
-
-	       Actually, even on Unix I would use realpath() or its work-
+	    /* Actually, even on Unix I would use realpath() or its work-
 	       alike before comparing.  Then all the code above which
 	       removes excess slashes and dots could simply go away.  */
-	    if (!strncmp (p, name, len)
+	    if (!filename_ncmp (p, name, len)
 		&& (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR))
 	      {
 		/* Found it in the search path, remove old copy.  */
Index: gdb/symfile.c
===================================================================
--- gdb.orig/symfile.c	2011-03-23 12:10:37.839811600 +0100
+++ gdb/symfile.c	2011-03-23 12:12:32.543241300 +0100
@@ -1325,7 +1325,7 @@ separate_debug_file_exists (const char *
      ".debug" suffix as "/usr/lib/debug/path/to/file" is a separate tree where
      the separate debug infos with the same basename can exist.  */
 
-  if (strcmp (name, parent_objfile->name) == 0)
+  if (filename_cmp (name, parent_objfile->name) == 0)
     return 0;
 
   abfd = bfd_open_maybe_remote (name);
@@ -1333,7 +1333,7 @@ separate_debug_file_exists (const char *
   if (!abfd)
     return 0;
 
-  /* Verify symlinks were not the cause of strcmp name difference above.
+  /* Verify symlinks were not the cause of filename_cmp name difference above.
 
      Some operating systems, e.g. Windows, do not provide a meaningful
      st_ino; they always set it to zero.  (Windows does provide a
@@ -1471,7 +1471,8 @@ find_separate_debug_file_by_debuglink (s
       /* If the file is in the sysroot, try using its base path in the
 	 global debugfile directory.  */
       if (canon_name
-	  && strncmp (canon_name, gdb_sysroot, strlen (gdb_sysroot)) == 0
+	  && filename_ncmp (canon_name, gdb_sysroot,
+			    strlen (gdb_sysroot)) == 0
 	  && IS_DIR_SEPARATOR (canon_name[strlen (gdb_sysroot)]))
 	{
 	  memcpy (debugfile, debugdir, debugdir_end - debugdir);
@@ -2375,8 +2376,9 @@ reread_symbols (void)
 	  /* We need to do this whenever any symbols go away.  */
 	  make_cleanup (clear_symtab_users_cleanup, 0 /*ignore*/);
 
-	  if (exec_bfd != NULL && strcmp (bfd_get_filename (objfile->obfd),
-					  bfd_get_filename (exec_bfd)) == 0)
+	  if (exec_bfd != NULL
+	      && filename_cmp (bfd_get_filename (objfile->obfd),
+			       bfd_get_filename (exec_bfd)) == 0)
 	    {
 	      /* Reload EXEC_BFD without asking anything.  */
 
Index: gdb/symmisc.c
===================================================================
--- gdb.orig/symmisc.c	2011-03-23 12:10:37.840811600 +0100
+++ gdb/symmisc.c	2011-03-23 12:12:32.566244300 +0100
@@ -23,6 +23,7 @@
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "bfd.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "breakpoint.h"
@@ -475,7 +476,7 @@ maintenance_print_symbols (char *args, i
 
   immediate_quit++;
   ALL_SYMTABS (objfile, s)
-    if (symname == NULL || strcmp (symname, s->filename) == 0)
+    if (symname == NULL || filename_cmp (symname, s->filename) == 0)
     dump_symtab (objfile, s, outfile);
   immediate_quit--;
   do_cleanups (cleanups);
Index: gdb/symtab.c
===================================================================
--- gdb.orig/symtab.c	2011-03-23 12:10:37.841811600 +0100
+++ gdb/symtab.c	2011-03-23 12:12:32.574745300 +0100
@@ -2761,7 +2761,7 @@ filename_seen (const char *file, int add
 
   /* Is FILE in tab?  */
   for (p = tab; p < tab + tab_cur_size; p++)
-    if (strcmp (*p, file) == 0)
+    if (filename_cmp (*p, file) == 0)
       return 1;
 
   /* No; maybe add it to tab.  */
@@ -2862,7 +2862,7 @@ file_matches (const char *file, char *fi
     {
       for (i = 0; i < nfiles; i++)
 	{
-	  if (strcmp (files[i], lbasename (file)) == 0)
+	  if (filename_cmp (files[i], lbasename (file)) == 0)
 	    return 1;
 	}
     }
@@ -3260,7 +3260,7 @@ static void
 print_symbol_info (domain_enum kind, struct symtab *s, struct symbol *sym,
 		   int block, char *last)
 {
-  if (last == NULL || strcmp (last, s->filename) != 0)
+  if (last == NULL || filename_cmp (last, s->filename) != 0)
     {
       fputs_filtered ("\nFile ", gdb_stdout);
       fputs_filtered (s->filename, gdb_stdout);
@@ -4073,7 +4073,7 @@ not_interesting_fname (const char *fname
 
   for (i = 0; illegal_aliens[i]; i++)
     {
-      if (strcmp (fname, illegal_aliens[i]) == 0)
+      if (filename_cmp (fname, illegal_aliens[i]) == 0)
 	return 1;
     }
   return 0;
@@ -4102,12 +4102,7 @@ maybe_add_partial_symtab_filename (const
   if (not_interesting_fname (filename))
     return;
   if (!filename_seen (filename, 1, data->first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-      && strncasecmp (filename, data->text, data->text_len) == 0
-#else
-      && strncmp (filename, data->text, data->text_len) == 0
-#endif
-      )
+      && filename_ncmp (filename, data->text, data->text_len) == 0)
     {
       /* This file matches for a completion; add it to the
 	 current list of matches.  */
@@ -4120,12 +4115,7 @@ maybe_add_partial_symtab_filename (const
 
       if (base_name != filename
 	  && !filename_seen (base_name, 1, data->first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	  && strncasecmp (base_name, data->text, data->text_len) == 0
-#else
-	  && strncmp (base_name, data->text, data->text_len) == 0
-#endif
-	  )
+	  && filename_ncmp (base_name, data->text, data->text_len) == 0)
 	add_filename_to_list (base_name, data->text, data->word,
 			      data->list, data->list_used, data->list_alloced);
     }
@@ -4159,12 +4149,7 @@ make_source_files_completion_list (char
       if (not_interesting_fname (s->filename))
 	continue;
       if (!filename_seen (s->filename, 1, &first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	  && strncasecmp (s->filename, text, text_len) == 0
-#else
-	  && strncmp (s->filename, text, text_len) == 0
-#endif
-	  )
+	  && filename_ncmp (s->filename, text, text_len) == 0)
 	{
 	  /* This file matches for a completion; add it to the current
 	     list of matches.  */
@@ -4180,12 +4165,7 @@ make_source_files_completion_list (char
 	  base_name = lbasename (s->filename);
 	  if (base_name != s->filename
 	      && !filename_seen (base_name, 1, &first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	      && strncasecmp (base_name, text, text_len) == 0
-#else
-	      && strncmp (base_name, text, text_len) == 0
-#endif
-	      )
+	      && filename_ncmp (base_name, text, text_len) == 0)
 	    add_filename_to_list (base_name, text, word,
 				  &list, &list_used, &list_alloced);
 	}
Index: gdb/xml-support.c
===================================================================
--- gdb.orig/xml-support.c	2011-03-23 12:10:37.843811600 +0100
+++ gdb/xml-support.c	2011-03-23 12:12:32.597748300 +0100
@@ -25,6 +25,7 @@
 
 #include "gdb_string.h"
 #include "safe-ctype.h"
+#include "filenames.h"
 
 /* Debugging flag.  */
 static int debug_xml;
@@ -946,7 +947,7 @@ fetch_xml_builtin (const char *filename)
   const char *(*p)[2];
 
   for (p = xml_builtin; (*p)[0]; p++)
-    if (strcmp ((*p)[0], filename) == 0)
+    if (filename_cmp ((*p)[0], filename) == 0)
       return (*p)[1];
 
   return NULL;
Index: gdb/xml-syscall.c
===================================================================
--- gdb.orig/xml-syscall.c	2011-03-23 12:10:37.868811600 +0100
+++ gdb/xml-syscall.c	2011-03-23 12:12:32.605749300 +0100
@@ -281,7 +281,7 @@ static void
 init_sysinfo (void)
 {
   /* Should we re-read the XML info for this target?  */
-  if (my_gdb_datadir && strcmp (my_gdb_datadir, gdb_datadir) != 0)
+  if (my_gdb_datadir && filename_cmp (my_gdb_datadir, gdb_datadir) != 0)
     {
       /* The data-directory changed from the last time we used it.
 	 It means that we have to re-read the XML info.  */
Index: gdb/dwarf2read.c
===================================================================
--- gdb.orig/dwarf2read.c	2011-03-23 12:10:37.828811600 +0100
+++ gdb/dwarf2read.c	2011-03-23 12:12:32.616250600 +0100
@@ -5211,7 +5211,8 @@ find_file_and_directory (struct die_info
 	 directory, get rid of it.  */
       char *cp = strchr (*comp_dir, ':');
 
-      if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
+      if (cp && cp != *comp_dir && cp[-1] == '.'
+	  && IS_ABSOLUTE_PATH (&cp[1]))
 	*comp_dir = cp + 1;
     }
 
Index: gdb/windows-nat.c
===================================================================
--- gdb.orig/windows-nat.c	2011-03-23 12:10:37.842811600 +0100
+++ gdb/windows-nat.c	2011-03-23 12:12:32.665756900 +0100
@@ -46,6 +46,7 @@
 #include <signal.h>
 
 #include "buildsym.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "gdb_obstack.h"
@@ -2586,7 +2587,7 @@ _initialize_check_for_gdb_ini (void)
 				      sizeof ("/gdb.ini"));
       strcpy (oldini, homedir);
       p = strchr (oldini, '\0');
-      if (p > oldini && p[-1] != '/')
+      if (p > oldini && !IS_DIR_SEPARATOR (p[-1]))
 	*p++ = '/';
       strcpy (p, "gdb.ini");
       if (access (oldini, 0) == 0)

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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-23 11:16             ` Kai Tietz
  2011-03-23 12:44               ` Mark Kettenis
@ 2011-03-23 14:16               ` Pedro Alves
  2011-03-23 14:18                 ` Kai Tietz
  1 sibling, 1 reply; 37+ messages in thread
From: Pedro Alves @ 2011-03-23 14:16 UTC (permalink / raw)
  To: gdb-patches; +Cc: Kai Tietz, Eli Zaretskii, Joel Brobecker

On Wednesday 23 March 2011 10:39:33, Kai Tietz wrote:
> --- gdb.orig/source.c   2011-03-23 10:30:42.614811600 +0100
> +++ gdb/source.c        2011-03-23 10:56:17.194745900 +0100
> @@ -569,15 +569,10 @@ add_path (char *dirname, char **which_pa
>         p = *which_path;
>         while (1)
>           {
> -           /* FIXME: strncmp loses in interesting ways on MS-DOS and
> -              MS-Windows because of case-insensitivity and two different
> -              but functionally identical slash characters.  We need a
> -              special filesystem-dependent file-name comparison function.
> -
> -              Actually, even on Unix I would use realpath() or its work-
> +           /* Actually, even on Unix I would use realpath() or its work-
>                alike before comparing.  Then all the code above which
>                removes excess slashes and dots could simply go away.  */
> -           if (!strncmp (p, name, len)
> +           if (!filename_ncmp (p, name, len)
>                 && (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR))

Without the previous paragraph, the comment left now doesn't make
sense on its own as is.  The "Actually, even on Unix" appears out of
the blue.

> --- gdb.orig/xml-support.c      2011-03-23 10:30:42.620811600 +0100
> +++ gdb/xml-support.c   2011-03-23 10:56:17.265754900 +0100
> @@ -25,6 +25,7 @@
>  
>  #include "gdb_string.h"
>  #include "safe-ctype.h"
> +#include "filenames.h"
>  
>  /* Debugging flag.  */
>  static int debug_xml;
> @@ -946,7 +947,7 @@ fetch_xml_builtin (const char *filename)
>    const char *(*p)[2];
>  
>    for (p = xml_builtin; (*p)[0]; p++)
> -    if (strcmp ((*p)[0], filename) == 0)
> +    if (filename_cmp ((*p)[0], filename) == 0)
>        return (*p)[1];
>  
>    return NULL;

I don't think this one makes sense to behave different depending
on host.  These are files that are built into the GDB binary, with
filenames hardcoded, and always basenamed.  No need to do case
insensitive, or path separator style sensitive match.

> --- gdb.orig/dwarf2read.c       2011-03-23 10:32:00.336248300 +0100
> +++ gdb/dwarf2read.c    2011-03-23 10:56:17.285257400 +0100
> @@ -5211,7 +5211,8 @@ find_file_and_directory (struct die_info
>          directory, get rid of it.  */
>        char *cp = strchr (*comp_dir, ':');
>  
> -      if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
> +      if (cp && cp != *comp_dir && cp[-1] == '.'
> +         && IS_ABSOLUTE_PATH (&cp[1]))
>         *comp_dir = cp + 1;
>      }
>  

I've already told you in another thread that this one is wrong.
We do not want to match anything other than '/' here, even
on Windows.  On a Windows x Irix gdb, we'd want to check for '/',
literally.  The Irix native cc compiler is not going to
use '\' or drive names:

  if (*comp_dir != NULL)
    {
      /* Irix 6.2 native cc prepends <machine>.: to the compilation
	 directory, get rid of it.  */
      char *cp = strchr (*comp_dir, ':');

      if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
	*comp_dir = cp + 1;
    }

-- 
Pedro Alves


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-23 14:16               ` Pedro Alves
@ 2011-03-23 14:18                 ` Kai Tietz
  2011-03-23 14:29                   ` Pierre Muller
                                     ` (2 more replies)
  0 siblings, 3 replies; 37+ messages in thread
From: Kai Tietz @ 2011-03-23 14:18 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Eli Zaretskii, Joel Brobecker

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

2011/3/23 Pedro Alves <pedro@codesourcery.com>:
> On Wednesday 23 March 2011 10:39:33, Kai Tietz wrote:
>> --- gdb.orig/source.c   2011-03-23 10:30:42.614811600 +0100
>> +++ gdb/source.c        2011-03-23 10:56:17.194745900 +0100
>> @@ -569,15 +569,10 @@ add_path (char *dirname, char **which_pa
>>         p = *which_path;
>>         while (1)
>>           {
>> -           /* FIXME: strncmp loses in interesting ways on MS-DOS and
>> -              MS-Windows because of case-insensitivity and two different
>> -              but functionally identical slash characters.  We need a
>> -              special filesystem-dependent file-name comparison function.
>> -
>> -              Actually, even on Unix I would use realpath() or its work-
>> +           /* Actually, even on Unix I would use realpath() or its work-
>>                alike before comparing.  Then all the code above which
>>                removes excess slashes and dots could simply go away.  */
>> -           if (!strncmp (p, name, len)
>> +           if (!filename_ncmp (p, name, len)
>>                 && (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR))
>
> Without the previous paragraph, the comment left now doesn't make
> sense on its own as is.  The "Actually, even on Unix" appears out of
> the blue.

Ok, adjusted comment so that it doesn't seems to be falling out of heaven.

>> --- gdb.orig/xml-support.c      2011-03-23 10:30:42.620811600 +0100
>> +++ gdb/xml-support.c   2011-03-23 10:56:17.265754900 +0100
>> @@ -25,6 +25,7 @@
>>
>>  #include "gdb_string.h"
>>  #include "safe-ctype.h"
>> +#include "filenames.h"
>>
>>  /* Debugging flag.  */
>>  static int debug_xml;
>> @@ -946,7 +947,7 @@ fetch_xml_builtin (const char *filename)
>>    const char *(*p)[2];
>>
>>    for (p = xml_builtin; (*p)[0]; p++)
>> -    if (strcmp ((*p)[0], filename) == 0)
>> +    if (filename_cmp ((*p)[0], filename) == 0)
>>        return (*p)[1];
>>
>>    return NULL;
>
> I don't think this one makes sense to behave different depending
> on host.  These are files that are built into the GDB binary, with
> filenames hardcoded, and always basenamed.  No need to do case
> insensitive, or path separator style sensitive match.

Well, as the names are hard-coded it seems to be superflous to do here
case-insensitive compare. I removed this part from patch.

>> --- gdb.orig/dwarf2read.c       2011-03-23 10:32:00.336248300 +0100
>> +++ gdb/dwarf2read.c    2011-03-23 10:56:17.285257400 +0100
>> @@ -5211,7 +5211,8 @@ find_file_and_directory (struct die_info
>>          directory, get rid of it.  */
>>        char *cp = strchr (*comp_dir, ':');
>>
>> -      if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
>> +      if (cp && cp != *comp_dir && cp[-1] == '.'
>> +         && IS_ABSOLUTE_PATH (&cp[1]))
>>         *comp_dir = cp + 1;
>>      }
>>
>
> I've already told you in another thread that this one is wrong.
> We do not want to match anything other than '/' here, even
> on Windows.  On a Windows x Irix gdb, we'd want to check for '/',
> literally.  The Irix native cc compiler is not going to
> use '\' or drive names:
>
>  if (*comp_dir != NULL)
>    {
>      /* Irix 6.2 native cc prepends <machine>.: to the compilation
>         directory, get rid of it.  */
>      char *cp = strchr (*comp_dir, ':');
>
>      if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
>        *comp_dir = cp + 1;
>    }

Ok, removed this part of the patch, too.


2011-03-23  Kai Tietz

	* breakpoint.c (clear_command): Use filename_cmp
	instead of strcmp for comparision.
	* buildsym.c (watch_main_source_file_lossage): Likewise.
	(patch_subfile_names): Use IS_DIR_SEPARATOR instead of
	checking just for slash.
	* dbxread.c (read_dbx_symtab): Use lbasename instead of
	strrchr and filename_cmp instead of strcmp for filenames.
	(add_old_header_file): Use filename_cmp
	instead of strcmp for comparision.
	* exec.c (exec_set_section_address): Likewise.
	* macrotab.c (macro_lookup_inclusion): Likewise.
	(macro_lookup_inclusion): Likewise.
	* elfread.c (_initialize_elfread): Likewise.
	(elfstab_offset_sections): Likewise.
	(elfstab_offset_sections): Use lbasename instead of
	strrchr.
	* mdebugread.c (parse_partial_symbols): Likewise.
	(arse_partial_symbols): Use filename_(n)cmp instead of
	str(n)cmp for comparision.
	* minsyms.c (lookup_minimal_symbol): Likewise.
	* psymtab.c (read_psymtabs_with_filename): Likewise.
	* solib.c (solib_read_symbols): Likewise.
	(reload_shared_libraries_1): Likewise.
	* symmisc.c (maintenance_print_symbols): Likewise.
	* symfile.c (separate_debug_file_exists): Likewise.
	(reread_symbols): Likewise.
	(find_separate_debug_file_by_debuglink): Likewise.
	* remote-fileio.c (remote_fileio_func_rename): Likewise.
	* source.c (add_path): Likewise.
	* symtab.c (filename_seen): Likewise.
	(file_matches): Likewise.
	(print_symbol_info): Likewise.
	(maybe_add_partial_symtab_filename): Likewise.
	(make_source_files_completion_list): Likewise.
	* xml-syscall.c (init_sysinfo): Likewise.
	* windows-nat.c (_initialize_check_for_gdb_ini): Use
	IS_DIR_SEPARATOR for checking for trailing path separator.

Updated patch attached.

Regards,
Kai

[-- Attachment #2: gdb_filename.txt --]
[-- Type: text/plain, Size: 21783 bytes --]

Index: gdb/breakpoint.c
===================================================================
--- gdb.orig/breakpoint.c	2011-03-23 14:03:30.531811600 +0100
+++ gdb/breakpoint.c	2011-03-23 14:08:47.404436200 +0100
@@ -39,6 +39,7 @@
 #include "language.h"
 #include "gdb_string.h"
 #include "demangle.h"
+#include "filenames.h"
 #include "annotate.h"
 #include "symfile.h"
 #include "objfiles.h"
@@ -9524,8 +9525,8 @@ clear_command (char *arg, int from_tty)
 				    && b->source_file != NULL
 				    && sal.symtab != NULL
 				    && sal.pspace == loc->pspace
-				    && strcmp (b->source_file,
-					       sal.symtab->filename) == 0
+				    && filename_cmp (b->source_file,
+						     sal.symtab->filename) == 0
 				    && b->line_number == sal.line);
 		  if (pc_match || line_match)
 		    {
Index: gdb/buildsym.c
===================================================================
--- gdb.orig/buildsym.c	2011-03-23 14:03:30.532811600 +0100
+++ gdb/buildsym.c	2011-03-23 14:08:47.448441800 +0100
@@ -643,7 +643,7 @@ void
 patch_subfile_names (struct subfile *subfile, char *name)
 {
   if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
-      && subfile->name[strlen (subfile->name) - 1] == '/')
+      && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
     {
       subfile->dirname = subfile->name;
       subfile->name = xstrdup (name);
@@ -878,7 +878,7 @@ watch_main_source_file_lossage (void)
 	   subfile->next;
 	   subfile = subfile->next)
 	{
-	  if (strcmp (lbasename (subfile->name), mainbase) == 0)
+	  if (filename_cmp (lbasename (subfile->name), mainbase) == 0)
 	    {
 	      ++nr_matches;
 	      mainsub_alias = subfile;
Index: gdb/dbxread.c
===================================================================
--- gdb.orig/dbxread.c	2011-03-23 14:03:30.533811600 +0100
+++ gdb/dbxread.c	2011-03-23 14:08:47.459443200 +0100
@@ -47,6 +47,7 @@
 #include "target.h"
 #include "gdbcore.h"		/* for bfd stuff */
 #include "libaout.h"		/* FIXME Secret internal BFD stuff for a.out */
+#include "filenames.h"
 #include "objfiles.h"
 #include "buildsym.h"
 #include "stabsread.h"
@@ -346,7 +347,7 @@ add_old_header_file (char *name, int ins
   int i;
 
   for (i = 0; i < N_HEADER_FILES (current_objfile); i++)
-    if (strcmp (p[i].name, name) == 0 && instance == p[i].instance)
+    if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
       {
 	add_this_object_header_file (i);
 	return;
@@ -1465,7 +1466,7 @@ read_dbx_symtab (struct objfile *objfile
 	    CORE_ADDR valu;
 	    static int prev_so_symnum = -10;
 	    static int first_so_symnum;
-	    char *p;
+	    const char *p;
 	    static char *dirname_nso;
 	    int prev_textlow_not_set;
 
@@ -1522,8 +1523,8 @@ read_dbx_symtab (struct objfile *objfile
 	       If pst exists, is empty, and has a filename ending in '/',
 	       we assume the previous N_SO was a directory name.  */
 
-	    p = strrchr (namestring, '/');
-	    if (p && *(p + 1) == '\000')
+	    p = lbasename (namestring);
+	    if (p != namestring && *p == '\000')
 	      {
 		/* Save the directory name SOs locally, then save it into
 		   the psymtab when it's created below.  */
@@ -1612,13 +1613,13 @@ read_dbx_symtab (struct objfile *objfile
 	       things like "break c-exp.y:435" need to work (I
 	       suppose the psymtab_include_list could be hashed or put
 	       in a binary tree, if profiling shows this is a major hog).  */
-	    if (pst && strcmp (namestring, pst->filename) == 0)
+	    if (pst && filename_cmp (namestring, pst->filename) == 0)
 	      continue;
 	    {
 	      int i;
 
 	      for (i = 0; i < includes_used; i++)
-		if (strcmp (namestring, psymtab_include_list[i]) == 0)
+		if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
 		  {
 		    i = -1;
 		    break;
Index: gdb/elfread.c
===================================================================
--- gdb.orig/elfread.c	2011-03-23 14:03:30.535811600 +0100
+++ gdb/elfread.c	2011-03-23 14:08:47.479945800 +0100
@@ -37,6 +37,7 @@
 #include "complaints.h"
 #include "demangle.h"
 #include "psympriv.h"
+#include "filenames.h"
 
 extern void _initialize_elfread (void);
 
@@ -707,7 +708,8 @@ find_separate_debug_file_by_buildid (str
       build_id_name = build_id_to_debug_filename (build_id);
       xfree (build_id);
       /* Prevent looping on a stripped .debug file.  */
-      if (build_id_name != NULL && strcmp (build_id_name, objfile->name) == 0)
+      if (build_id_name != NULL
+	  && filename_cmp (build_id_name, objfile->name) == 0)
         {
 	  warning (_("\"%s\": separate debug info file has no debug info"),
 		   build_id_name);
@@ -1023,12 +1025,13 @@ elfstab_offset_sections (struct objfile
   struct stab_section_info *maybe = dbx->stab_section_info;
   struct stab_section_info *questionable = 0;
   int i;
-  char *p;
+  const char *p;
 
   /* The ELF symbol info doesn't include path names, so strip the path
      (if any) from the psymtab filename.  */
-  while (0 != (p = strchr (filename, '/')))
-    filename = p + 1;
+  p = lbasename (filename);
+  if (p != filename)
+    filename = p;
 
   /* FIXME:  This linear search could speed up significantly
      if it was chained in the right order to match how we search it,
@@ -1036,7 +1039,7 @@ elfstab_offset_sections (struct objfile
   for (; maybe; maybe = maybe->next)
     {
       if (filename[0] == maybe->filename[0]
-	  && strcmp (filename, maybe->filename) == 0)
+	  && filename_cmp (filename, maybe->filename) == 0)
 	{
 	  /* We found a match.  But there might be several source files
 	     (from different directories) with the same name.  */
Index: gdb/exec.c
===================================================================
--- gdb.orig/exec.c	2011-03-23 14:03:30.536811600 +0100
+++ gdb/exec.c	2011-03-23 14:08:47.488947000 +0100
@@ -25,6 +25,7 @@
 #include "target.h"
 #include "gdbcmd.h"
 #include "language.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "completer.h"
@@ -845,7 +846,7 @@ exec_set_section_address (const char *fi
   table = current_target_sections;
   for (p = table->sections; p < table->sections_end; p++)
     {
-      if (strcmp (filename, p->bfd->filename) == 0
+      if (filename_cmp (filename, p->bfd->filename) == 0
 	  && index == p->the_bfd_section->index)
 	{
 	  p->endaddr += address - p->addr;
Index: gdb/macrotab.c
===================================================================
--- gdb.orig/macrotab.c	2011-03-23 14:03:30.537811600 +0100
+++ gdb/macrotab.c	2011-03-23 14:08:47.496447900 +0100
@@ -21,6 +21,7 @@
 #include "defs.h"
 #include "gdb_obstack.h"
 #include "splay-tree.h"
+#include "filenames.h"
 #include "symtab.h"
 #include "symfile.h"
 #include "objfiles.h"
@@ -500,7 +501,7 @@ struct macro_source_file *
 macro_lookup_inclusion (struct macro_source_file *source, const char *name)
 {
   /* Is SOURCE itself named NAME?  */
-  if (strcmp (name, source->filename) == 0)
+  if (filename_cmp (name, source->filename) == 0)
     return source;
 
   /* The filename in the source structure is probably a full path, but
@@ -510,11 +511,12 @@ macro_lookup_inclusion (struct macro_sou
     int src_name_len = strlen (source->filename);
 
     /* We do mean < here, and not <=; if the lengths are the same,
-       then the strcmp above should have triggered, and we need to
+       then the filename_cmp above should have triggered, and we need to
        check for a slash here.  */
     if (name_len < src_name_len
-        && source->filename[src_name_len - name_len - 1] == '/'
-        && strcmp (name, source->filename + src_name_len - name_len) == 0)
+        && IS_DIR_SEPARATOR (source->filename[src_name_len - name_len - 1])
+        && filename_cmp (name,
+			 source->filename + src_name_len - name_len) == 0)
       return source;
   }
 
Index: gdb/mdebugread.c
===================================================================
--- gdb.orig/mdebugread.c	2011-03-23 14:03:30.538811600 +0100
+++ gdb/mdebugread.c	2011-03-23 14:08:47.506449200 +0100
@@ -45,6 +45,7 @@
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "gdbcore.h"
+#include "filenames.h"
 #include "objfiles.h"
 #include "gdb_obstack.h"
 #include "buildsym.h"
@@ -2959,7 +2960,7 @@ parse_partial_symbols (struct objfile *o
 		      CORE_ADDR valu;
 		      static int prev_so_symnum = -10;
 		      static int first_so_symnum;
-		      char *p;
+		      const char *p;
 		      int prev_textlow_not_set;
 
 		      valu = sh.value + ANOFFSET (objfile->section_offsets,
@@ -3012,9 +3013,8 @@ parse_partial_symbols (struct objfile *o
 			 the second the file name.  If pst exists, is
 			 empty, and has a filename ending in '/', we assume
 			 the previous N_SO was a directory name.  */
-
-		      p = strrchr (namestring, '/');
-		      if (p && *(p + 1) == '\000')
+		      p = lbasename (namestring);
+		      if (p != namestring && *p == '\000')
 			continue;		/* Simply ignore directory
 						   name SOs.  */
 
@@ -3065,15 +3065,15 @@ parse_partial_symbols (struct objfile *o
 			 work (I suppose the psymtab_include_list could be
 			 hashed or put in a binary tree, if profiling shows
 			 this is a major hog).  */
-		      if (pst && strcmp (namestring, pst->filename) == 0)
+		      if (pst && filename_cmp (namestring, pst->filename) == 0)
 			continue;
 
 		      {
 			int i;
 
 			for (i = 0; i < includes_used; i++)
-			  if (strcmp (namestring,
-				      psymtab_include_list[i]) == 0)
+			  if (filename_cmp (namestring,
+					    psymtab_include_list[i]) == 0)
 			    {
 			      i = -1;
 			      break;
Index: gdb/minsyms.c
===================================================================
--- gdb.orig/minsyms.c	2011-03-23 14:03:30.539811600 +0100
+++ gdb/minsyms.c	2011-03-23 14:08:47.529452100 +0100
@@ -43,6 +43,7 @@
 #include "gdb_string.h"
 #include "symtab.h"
 #include "bfd.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "demangle.h"
@@ -255,7 +256,7 @@ lookup_minimal_symbol (const char *name,
                       case mst_file_data:
                       case mst_file_bss:
                         if (sfile == NULL
-			    || strcmp (msymbol->filename, sfile) == 0)
+			    || filename_cmp (msymbol->filename, sfile) == 0)
                           found_file_symbol = msymbol;
                         break;
 
Index: gdb/psymtab.c
===================================================================
--- gdb.orig/psymtab.c	2011-03-23 14:03:30.540811600 +0100
+++ gdb/psymtab.c	2011-03-23 14:08:47.538953300 +0100
@@ -1067,7 +1067,7 @@ read_psymtabs_with_filename (struct objf
 
   ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
     {
-      if (strcmp (filename, p->filename) == 0)
+      if (filename_cmp (filename, p->filename) == 0)
 	PSYMTAB_TO_SYMTAB (p);
     }
 }
@@ -1735,7 +1735,7 @@ print-psymbols takes an output file name
 
   immediate_quit++;
   ALL_PSYMTABS (objfile, ps)
-    if (symname == NULL || strcmp (symname, ps->filename) == 0)
+    if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
     dump_psymtab (objfile, ps, outfile);
   immediate_quit--;
   do_cleanups (cleanups);
Index: gdb/remote-fileio.c
===================================================================
--- gdb.orig/remote-fileio.c	2011-03-23 14:03:30.541811600 +0100
+++ gdb/remote-fileio.c	2011-03-23 14:08:47.550454800 +0100
@@ -31,6 +31,7 @@
 #include "remote-fileio.h"
 #include "event-loop.h"
 #include "target.h"
+#include "filenames.h"
 
 #include <fcntl.h>
 #include <sys/time.h>
@@ -1020,8 +1021,8 @@ remote_fileio_func_rename (char *buf)
 		  cygwin_conv_path (CCP_WIN_A_TO_POSIX, newpath, newfullpath,
 				    PATH_MAX);
 		  len = strlen (oldfullpath);
-		  if (newfullpath[len] == '/'
-		      && !strncmp (oldfullpath, newfullpath, len))
+		  if (IS_DIR_SEPARATOR (newfullpath[len])
+		      && !filename_ncmp (oldfullpath, newfullpath, len))
 		    errno = EINVAL;
 		  else
 		    errno = EEXIST;
Index: gdb/solib.c
===================================================================
--- gdb.orig/solib.c	2011-03-23 14:03:30.542811600 +0100
+++ gdb/solib.c	2011-03-23 14:08:47.560456000 +0100
@@ -638,7 +638,7 @@ solib_read_symbols (struct so_list *so,
 	  /* Have we already loaded this shared object?  */
 	  ALL_OBJFILES (so->objfile)
 	    {
-	      if (strcmp (so->objfile->name, so->so_name) == 0
+	      if (filename_cmp (so->objfile->name, so->so_name) == 0
 		  && so->objfile->addr_low == so->addr_low)
 		break;
 	    }
@@ -762,7 +762,7 @@ update_solib_list (int from_tty, struct
 	    }
 	  else
 	    {
-	      if (! strcmp (gdb->so_original_name, i->so_original_name))
+	      if (! filename_cmp (gdb->so_original_name, i->so_original_name))
 		break;	      
 	    }
 
@@ -1339,7 +1339,7 @@ reload_shared_libraries_1 (int from_tty)
 	 symbol file, close that.  */
       if ((found_pathname == NULL && was_loaded)
 	  || (found_pathname != NULL
-	      && strcmp (found_pathname, so->so_name) != 0))
+	      && filename_cmp (found_pathname, so->so_name) != 0))
 	{
 	  if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED))
 	    free_objfile (so->objfile);
@@ -1351,7 +1351,7 @@ reload_shared_libraries_1 (int from_tty)
 	 file, open it.  */
       if (found_pathname != NULL
 	  && (!was_loaded
-	      || strcmp (found_pathname, so->so_name) != 0))
+	      || filename_cmp (found_pathname, so->so_name) != 0))
 	{
 	  volatile struct gdb_exception e;
 
Index: gdb/source.c
===================================================================
--- gdb.orig/source.c	2011-03-23 14:03:30.543811600 +0100
+++ gdb/source.c	2011-03-23 14:59:11.967507000 +0100
@@ -569,15 +569,10 @@ add_path (char *dirname, char **which_pa
 	p = *which_path;
 	while (1)
 	  {
-	    /* FIXME: strncmp loses in interesting ways on MS-DOS and
-	       MS-Windows because of case-insensitivity and two different
-	       but functionally identical slash characters.  We need a
-	       special filesystem-dependent file-name comparison function.
-
-	       Actually, even on Unix I would use realpath() or its work-
-	       alike before comparing.  Then all the code above which
+	    /* FIXME: we should use realpath() or its work-alike
+	       before comparing.  Then all the code above which
 	       removes excess slashes and dots could simply go away.  */
-	    if (!strncmp (p, name, len)
+	    if (!filename_ncmp (p, name, len)
 		&& (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR))
 	      {
 		/* Found it in the search path, remove old copy.  */
Index: gdb/symfile.c
===================================================================
--- gdb.orig/symfile.c	2011-03-23 14:03:30.544811600 +0100
+++ gdb/symfile.c	2011-03-23 14:08:47.584459100 +0100
@@ -1325,7 +1325,7 @@ separate_debug_file_exists (const char *
      ".debug" suffix as "/usr/lib/debug/path/to/file" is a separate tree where
      the separate debug infos with the same basename can exist.  */
 
-  if (strcmp (name, parent_objfile->name) == 0)
+  if (filename_cmp (name, parent_objfile->name) == 0)
     return 0;
 
   abfd = bfd_open_maybe_remote (name);
@@ -1333,7 +1333,7 @@ separate_debug_file_exists (const char *
   if (!abfd)
     return 0;
 
-  /* Verify symlinks were not the cause of strcmp name difference above.
+  /* Verify symlinks were not the cause of filename_cmp name difference above.
 
      Some operating systems, e.g. Windows, do not provide a meaningful
      st_ino; they always set it to zero.  (Windows does provide a
@@ -1471,7 +1471,8 @@ find_separate_debug_file_by_debuglink (s
       /* If the file is in the sysroot, try using its base path in the
 	 global debugfile directory.  */
       if (canon_name
-	  && strncmp (canon_name, gdb_sysroot, strlen (gdb_sysroot)) == 0
+	  && filename_ncmp (canon_name, gdb_sysroot,
+			    strlen (gdb_sysroot)) == 0
 	  && IS_DIR_SEPARATOR (canon_name[strlen (gdb_sysroot)]))
 	{
 	  memcpy (debugfile, debugdir, debugdir_end - debugdir);
@@ -2375,8 +2376,9 @@ reread_symbols (void)
 	  /* We need to do this whenever any symbols go away.  */
 	  make_cleanup (clear_symtab_users_cleanup, 0 /*ignore*/);
 
-	  if (exec_bfd != NULL && strcmp (bfd_get_filename (objfile->obfd),
-					  bfd_get_filename (exec_bfd)) == 0)
+	  if (exec_bfd != NULL
+	      && filename_cmp (bfd_get_filename (objfile->obfd),
+			       bfd_get_filename (exec_bfd)) == 0)
 	    {
 	      /* Reload EXEC_BFD without asking anything.  */
 
Index: gdb/symmisc.c
===================================================================
--- gdb.orig/symmisc.c	2011-03-23 14:03:30.545811600 +0100
+++ gdb/symmisc.c	2011-03-23 14:08:47.605461800 +0100
@@ -23,6 +23,7 @@
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "bfd.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "breakpoint.h"
@@ -475,7 +476,7 @@ maintenance_print_symbols (char *args, i
 
   immediate_quit++;
   ALL_SYMTABS (objfile, s)
-    if (symname == NULL || strcmp (symname, s->filename) == 0)
+    if (symname == NULL || filename_cmp (symname, s->filename) == 0)
     dump_symtab (objfile, s, outfile);
   immediate_quit--;
   do_cleanups (cleanups);
Index: gdb/symtab.c
===================================================================
--- gdb.orig/symtab.c	2011-03-23 14:03:30.546811600 +0100
+++ gdb/symtab.c	2011-03-23 14:08:47.614462900 +0100
@@ -2761,7 +2761,7 @@ filename_seen (const char *file, int add
 
   /* Is FILE in tab?  */
   for (p = tab; p < tab + tab_cur_size; p++)
-    if (strcmp (*p, file) == 0)
+    if (filename_cmp (*p, file) == 0)
       return 1;
 
   /* No; maybe add it to tab.  */
@@ -2862,7 +2862,7 @@ file_matches (const char *file, char *fi
     {
       for (i = 0; i < nfiles; i++)
 	{
-	  if (strcmp (files[i], lbasename (file)) == 0)
+	  if (filename_cmp (files[i], lbasename (file)) == 0)
 	    return 1;
 	}
     }
@@ -3260,7 +3260,7 @@ static void
 print_symbol_info (domain_enum kind, struct symtab *s, struct symbol *sym,
 		   int block, char *last)
 {
-  if (last == NULL || strcmp (last, s->filename) != 0)
+  if (last == NULL || filename_cmp (last, s->filename) != 0)
     {
       fputs_filtered ("\nFile ", gdb_stdout);
       fputs_filtered (s->filename, gdb_stdout);
@@ -4073,7 +4073,7 @@ not_interesting_fname (const char *fname
 
   for (i = 0; illegal_aliens[i]; i++)
     {
-      if (strcmp (fname, illegal_aliens[i]) == 0)
+      if (filename_cmp (fname, illegal_aliens[i]) == 0)
 	return 1;
     }
   return 0;
@@ -4102,12 +4102,7 @@ maybe_add_partial_symtab_filename (const
   if (not_interesting_fname (filename))
     return;
   if (!filename_seen (filename, 1, data->first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-      && strncasecmp (filename, data->text, data->text_len) == 0
-#else
-      && strncmp (filename, data->text, data->text_len) == 0
-#endif
-      )
+      && filename_ncmp (filename, data->text, data->text_len) == 0)
     {
       /* This file matches for a completion; add it to the
 	 current list of matches.  */
@@ -4120,12 +4115,7 @@ maybe_add_partial_symtab_filename (const
 
       if (base_name != filename
 	  && !filename_seen (base_name, 1, data->first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	  && strncasecmp (base_name, data->text, data->text_len) == 0
-#else
-	  && strncmp (base_name, data->text, data->text_len) == 0
-#endif
-	  )
+	  && filename_ncmp (base_name, data->text, data->text_len) == 0)
 	add_filename_to_list (base_name, data->text, data->word,
 			      data->list, data->list_used, data->list_alloced);
     }
@@ -4159,12 +4149,7 @@ make_source_files_completion_list (char
       if (not_interesting_fname (s->filename))
 	continue;
       if (!filename_seen (s->filename, 1, &first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	  && strncasecmp (s->filename, text, text_len) == 0
-#else
-	  && strncmp (s->filename, text, text_len) == 0
-#endif
-	  )
+	  && filename_ncmp (s->filename, text, text_len) == 0)
 	{
 	  /* This file matches for a completion; add it to the current
 	     list of matches.  */
@@ -4180,12 +4165,7 @@ make_source_files_completion_list (char
 	  base_name = lbasename (s->filename);
 	  if (base_name != s->filename
 	      && !filename_seen (base_name, 1, &first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	      && strncasecmp (base_name, text, text_len) == 0
-#else
-	      && strncmp (base_name, text, text_len) == 0
-#endif
-	      )
+	      && filename_ncmp (base_name, text, text_len) == 0)
 	    add_filename_to_list (base_name, text, word,
 				  &list, &list_used, &list_alloced);
 	}
Index: gdb/xml-syscall.c
===================================================================
--- gdb.orig/xml-syscall.c	2011-03-23 14:03:30.583811600 +0100
+++ gdb/xml-syscall.c	2011-03-23 14:08:47.636965800 +0100
@@ -281,7 +281,7 @@ static void
 init_sysinfo (void)
 {
   /* Should we re-read the XML info for this target?  */
-  if (my_gdb_datadir && strcmp (my_gdb_datadir, gdb_datadir) != 0)
+  if (my_gdb_datadir && filename_cmp (my_gdb_datadir, gdb_datadir) != 0)
     {
       /* The data-directory changed from the last time we used it.
 	 It means that we have to re-read the XML info.  */
Index: gdb/windows-nat.c
===================================================================
--- gdb.orig/windows-nat.c	2011-03-23 14:03:30.547811600 +0100
+++ gdb/windows-nat.c	2011-03-23 14:08:47.642966500 +0100
@@ -46,6 +46,7 @@
 #include <signal.h>
 
 #include "buildsym.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "gdb_obstack.h"
@@ -2586,7 +2587,7 @@ _initialize_check_for_gdb_ini (void)
 				      sizeof ("/gdb.ini"));
       strcpy (oldini, homedir);
       p = strchr (oldini, '\0');
-      if (p > oldini && p[-1] != '/')
+      if (p > oldini && !IS_DIR_SEPARATOR (p[-1]))
 	*p++ = '/';
       strcpy (p, "gdb.ini");
       if (access (oldini, 0) == 0)

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

* RE: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-23 14:18                 ` Kai Tietz
@ 2011-03-23 14:29                   ` Pierre Muller
       [not found]                   ` <-544184502231544940@unknownmsgid>
  2011-03-23 15:29                   ` Pedro Alves
  2 siblings, 0 replies; 37+ messages in thread
From: Pierre Muller @ 2011-03-23 14:29 UTC (permalink / raw)
  To: 'Kai Tietz', 'Pedro Alves'
  Cc: gdb-patches, 'Eli Zaretskii', 'Joel Brobecker'

 
> 	* breakpoint.c (clear_command): Use filename_cmp
> 	instead of strcmp for comparision.

  Just a question:
Does this word (comparision) really exist?
  comparison 
seems more correct to me,
but it might be again one of those English/American subtilities?

Pierre


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
       [not found]                   ` <-544184502231544940@unknownmsgid>
@ 2011-03-23 14:44                     ` Kai Tietz
  0 siblings, 0 replies; 37+ messages in thread
From: Kai Tietz @ 2011-03-23 14:44 UTC (permalink / raw)
  To: Pierre Muller; +Cc: Pedro Alves, gdb-patches, Eli Zaretskii, Joel Brobecker

2011/3/23 Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>:
>
>>       * breakpoint.c (clear_command): Use filename_cmp
>>       instead of strcmp for comparision.
>
>  Just a question:
> Does this word (comparision) really exist?
>  comparison
> seems more correct to me,
> but it might be again one of those English/American subtilities?
>
> Pierre
>
>

Yes "comparison" is the correct word. Thanks for catching this typo.

Kai


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-23 14:18                 ` Kai Tietz
  2011-03-23 14:29                   ` Pierre Muller
       [not found]                   ` <-544184502231544940@unknownmsgid>
@ 2011-03-23 15:29                   ` Pedro Alves
  2011-03-23 15:29                     ` Kai Tietz
  2011-03-23 18:24                     ` Eli Zaretskii
  2 siblings, 2 replies; 37+ messages in thread
From: Pedro Alves @ 2011-03-23 15:29 UTC (permalink / raw)
  To: Kai Tietz; +Cc: gdb-patches, Eli Zaretskii, Joel Brobecker

On Wednesday 23 March 2011 14:07:01, Kai Tietz wrote:
> @@ -1023,12 +1025,13 @@ elfstab_offset_sections (struct objfile
>    struct stab_section_info *maybe = dbx->stab_section_info;
>    struct stab_section_info *questionable = 0;
>    int i;
> -  char *p;
> +  const char *p;
>  
>    /* The ELF symbol info doesn't include path names, so strip the path
>       (if any) from the psymtab filename.  */
> -  while (0 != (p = strchr (filename, '/')))
> -    filename = p + 1;
> +  p = lbasename (filename);
> +  if (p != filename)
> +    filename = p;

These three lines are the same as just:

 filename = lbasename (filename);

You can then drop the unnecessary `p' local.

The patch looked good to me with that change.

-- 
Pedro Alves


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-23 15:29                   ` Pedro Alves
@ 2011-03-23 15:29                     ` Kai Tietz
  2011-03-23 18:24                     ` Eli Zaretskii
  1 sibling, 0 replies; 37+ messages in thread
From: Kai Tietz @ 2011-03-23 15:29 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Eli Zaretskii, Joel Brobecker

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

2011/3/23 Pedro Alves <pedro@codesourcery.com>:
> On Wednesday 23 March 2011 14:07:01, Kai Tietz wrote:
>> @@ -1023,12 +1025,13 @@ elfstab_offset_sections (struct objfile
>>    struct stab_section_info *maybe = dbx->stab_section_info;
>>    struct stab_section_info *questionable = 0;
>>    int i;
>> -  char *p;
>> +  const char *p;
>>
>>    /* The ELF symbol info doesn't include path names, so strip the path
>>       (if any) from the psymtab filename.  */
>> -  while (0 != (p = strchr (filename, '/')))
>> -    filename = p + 1;
>> +  p = lbasename (filename);
>> +  if (p != filename)
>> +    filename = p;
>
> These three lines are the same as just:
>
>  filename = lbasename (filename);
>
> You can then drop the unnecessary `p' local.
>
> The patch looked good to me with that change.
>
> --
> Pedro Alves
>

Thanks for the detailed review. Attached updated patch attached.

2011-03-23  Kai Tietz

	* breakpoint.c (clear_command): Use filename_cmp
	instead of strcmp for comparison.
	* buildsym.c (watch_main_source_file_lossage): Likewise.
	(patch_subfile_names): Use IS_DIR_SEPARATOR instead of
	checking just for slash.
	* dbxread.c (read_dbx_symtab): Use lbasename instead of
	strrchr and filename_cmp instead of strcmp for filenames.
	(add_old_header_file): Use filename_cmp
	instead of strcmp for comparison.
	* exec.c (exec_set_section_address): Likewise.
	* macrotab.c (macro_lookup_inclusion): Likewise.
	(macro_lookup_inclusion): Likewise.
	* elfread.c (_initialize_elfread): Likewise.
	(elfstab_offset_sections): Likewise.
	(elfstab_offset_sections): Use lbasename instead of
	strrchr.
	* mdebugread.c (parse_partial_symbols): Likewise.
	(arse_partial_symbols): Use filename_(n)cmp instead of
	str(n)cmp for comparison.
	* minsyms.c (lookup_minimal_symbol): Likewise.
	* psymtab.c (read_psymtabs_with_filename): Likewise.
	* solib.c (solib_read_symbols): Likewise.
	(reload_shared_libraries_1): Likewise.
	* symmisc.c (maintenance_print_symbols): Likewise.
	* symfile.c (separate_debug_file_exists): Likewise.
	(reread_symbols): Likewise.
	(find_separate_debug_file_by_debuglink): Likewise.
	* remote-fileio.c (remote_fileio_func_rename): Likewise.
	* source.c (add_path): Likewise.
	* symtab.c (filename_seen): Likewise.
	(file_matches): Likewise.
	(print_symbol_info): Likewise.
	(maybe_add_partial_symtab_filename): Likewise.
	(make_source_files_completion_list): Likewise.
	* xml-syscall.c (init_sysinfo): Likewise.
	* windows-nat.c (_initialize_check_for_gdb_ini): Use
	IS_DIR_SEPARATOR for checking for trailing path separator.

Regards,
Kai

[-- Attachment #2: gdb_filename.txt --]
[-- Type: text/plain, Size: 21731 bytes --]

Index: gdb/breakpoint.c
===================================================================
--- gdb.orig/breakpoint.c	2011-03-23 14:03:30.531811600 +0100
+++ gdb/breakpoint.c	2011-03-23 14:08:47.404436200 +0100
@@ -39,6 +39,7 @@
 #include "language.h"
 #include "gdb_string.h"
 #include "demangle.h"
+#include "filenames.h"
 #include "annotate.h"
 #include "symfile.h"
 #include "objfiles.h"
@@ -9524,8 +9525,8 @@ clear_command (char *arg, int from_tty)
 				    && b->source_file != NULL
 				    && sal.symtab != NULL
 				    && sal.pspace == loc->pspace
-				    && strcmp (b->source_file,
-					       sal.symtab->filename) == 0
+				    && filename_cmp (b->source_file,
+						     sal.symtab->filename) == 0
 				    && b->line_number == sal.line);
 		  if (pc_match || line_match)
 		    {
Index: gdb/buildsym.c
===================================================================
--- gdb.orig/buildsym.c	2011-03-23 14:03:30.532811600 +0100
+++ gdb/buildsym.c	2011-03-23 14:08:47.448441800 +0100
@@ -643,7 +643,7 @@ void
 patch_subfile_names (struct subfile *subfile, char *name)
 {
   if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
-      && subfile->name[strlen (subfile->name) - 1] == '/')
+      && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
     {
       subfile->dirname = subfile->name;
       subfile->name = xstrdup (name);
@@ -878,7 +878,7 @@ watch_main_source_file_lossage (void)
 	   subfile->next;
 	   subfile = subfile->next)
 	{
-	  if (strcmp (lbasename (subfile->name), mainbase) == 0)
+	  if (filename_cmp (lbasename (subfile->name), mainbase) == 0)
 	    {
 	      ++nr_matches;
 	      mainsub_alias = subfile;
Index: gdb/dbxread.c
===================================================================
--- gdb.orig/dbxread.c	2011-03-23 14:03:30.533811600 +0100
+++ gdb/dbxread.c	2011-03-23 14:08:47.459443200 +0100
@@ -47,6 +47,7 @@
 #include "target.h"
 #include "gdbcore.h"		/* for bfd stuff */
 #include "libaout.h"		/* FIXME Secret internal BFD stuff for a.out */
+#include "filenames.h"
 #include "objfiles.h"
 #include "buildsym.h"
 #include "stabsread.h"
@@ -346,7 +347,7 @@ add_old_header_file (char *name, int ins
   int i;
 
   for (i = 0; i < N_HEADER_FILES (current_objfile); i++)
-    if (strcmp (p[i].name, name) == 0 && instance == p[i].instance)
+    if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
       {
 	add_this_object_header_file (i);
 	return;
@@ -1465,7 +1466,7 @@ read_dbx_symtab (struct objfile *objfile
 	    CORE_ADDR valu;
 	    static int prev_so_symnum = -10;
 	    static int first_so_symnum;
-	    char *p;
+	    const char *p;
 	    static char *dirname_nso;
 	    int prev_textlow_not_set;
 
@@ -1522,8 +1523,8 @@ read_dbx_symtab (struct objfile *objfile
 	       If pst exists, is empty, and has a filename ending in '/',
 	       we assume the previous N_SO was a directory name.  */
 
-	    p = strrchr (namestring, '/');
-	    if (p && *(p + 1) == '\000')
+	    p = lbasename (namestring);
+	    if (p != namestring && *p == '\000')
 	      {
 		/* Save the directory name SOs locally, then save it into
 		   the psymtab when it's created below.  */
@@ -1612,13 +1613,13 @@ read_dbx_symtab (struct objfile *objfile
 	       things like "break c-exp.y:435" need to work (I
 	       suppose the psymtab_include_list could be hashed or put
 	       in a binary tree, if profiling shows this is a major hog).  */
-	    if (pst && strcmp (namestring, pst->filename) == 0)
+	    if (pst && filename_cmp (namestring, pst->filename) == 0)
 	      continue;
 	    {
 	      int i;
 
 	      for (i = 0; i < includes_used; i++)
-		if (strcmp (namestring, psymtab_include_list[i]) == 0)
+		if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
 		  {
 		    i = -1;
 		    break;
Index: gdb/elfread.c
===================================================================
--- gdb.orig/elfread.c	2011-03-23 14:03:30.535811600 +0100
+++ gdb/elfread.c	2011-03-23 15:53:45.836235500 +0100
@@ -37,6 +37,7 @@
 #include "complaints.h"
 #include "demangle.h"
 #include "psympriv.h"
+#include "filenames.h"
 
 extern void _initialize_elfread (void);
 
@@ -707,7 +708,8 @@ find_separate_debug_file_by_buildid (str
       build_id_name = build_id_to_debug_filename (build_id);
       xfree (build_id);
       /* Prevent looping on a stripped .debug file.  */
-      if (build_id_name != NULL && strcmp (build_id_name, objfile->name) == 0)
+      if (build_id_name != NULL
+	  && filename_cmp (build_id_name, objfile->name) == 0)
         {
 	  warning (_("\"%s\": separate debug info file has no debug info"),
 		   build_id_name);
@@ -1023,12 +1025,10 @@ elfstab_offset_sections (struct objfile
   struct stab_section_info *maybe = dbx->stab_section_info;
   struct stab_section_info *questionable = 0;
   int i;
-  char *p;
 
   /* The ELF symbol info doesn't include path names, so strip the path
      (if any) from the psymtab filename.  */
-  while (0 != (p = strchr (filename, '/')))
-    filename = p + 1;
+  filename = lbasename (filename);
 
   /* FIXME:  This linear search could speed up significantly
      if it was chained in the right order to match how we search it,
@@ -1036,7 +1036,7 @@ elfstab_offset_sections (struct objfile
   for (; maybe; maybe = maybe->next)
     {
       if (filename[0] == maybe->filename[0]
-	  && strcmp (filename, maybe->filename) == 0)
+	  && filename_cmp (filename, maybe->filename) == 0)
 	{
 	  /* We found a match.  But there might be several source files
 	     (from different directories) with the same name.  */
Index: gdb/exec.c
===================================================================
--- gdb.orig/exec.c	2011-03-23 14:03:30.536811600 +0100
+++ gdb/exec.c	2011-03-23 14:08:47.488947000 +0100
@@ -25,6 +25,7 @@
 #include "target.h"
 #include "gdbcmd.h"
 #include "language.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "completer.h"
@@ -845,7 +846,7 @@ exec_set_section_address (const char *fi
   table = current_target_sections;
   for (p = table->sections; p < table->sections_end; p++)
     {
-      if (strcmp (filename, p->bfd->filename) == 0
+      if (filename_cmp (filename, p->bfd->filename) == 0
 	  && index == p->the_bfd_section->index)
 	{
 	  p->endaddr += address - p->addr;
Index: gdb/macrotab.c
===================================================================
--- gdb.orig/macrotab.c	2011-03-23 14:03:30.537811600 +0100
+++ gdb/macrotab.c	2011-03-23 14:08:47.496447900 +0100
@@ -21,6 +21,7 @@
 #include "defs.h"
 #include "gdb_obstack.h"
 #include "splay-tree.h"
+#include "filenames.h"
 #include "symtab.h"
 #include "symfile.h"
 #include "objfiles.h"
@@ -500,7 +501,7 @@ struct macro_source_file *
 macro_lookup_inclusion (struct macro_source_file *source, const char *name)
 {
   /* Is SOURCE itself named NAME?  */
-  if (strcmp (name, source->filename) == 0)
+  if (filename_cmp (name, source->filename) == 0)
     return source;
 
   /* The filename in the source structure is probably a full path, but
@@ -510,11 +511,12 @@ macro_lookup_inclusion (struct macro_sou
     int src_name_len = strlen (source->filename);
 
     /* We do mean < here, and not <=; if the lengths are the same,
-       then the strcmp above should have triggered, and we need to
+       then the filename_cmp above should have triggered, and we need to
        check for a slash here.  */
     if (name_len < src_name_len
-        && source->filename[src_name_len - name_len - 1] == '/'
-        && strcmp (name, source->filename + src_name_len - name_len) == 0)
+        && IS_DIR_SEPARATOR (source->filename[src_name_len - name_len - 1])
+        && filename_cmp (name,
+			 source->filename + src_name_len - name_len) == 0)
       return source;
   }
 
Index: gdb/mdebugread.c
===================================================================
--- gdb.orig/mdebugread.c	2011-03-23 14:03:30.538811600 +0100
+++ gdb/mdebugread.c	2011-03-23 14:08:47.506449200 +0100
@@ -45,6 +45,7 @@
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "gdbcore.h"
+#include "filenames.h"
 #include "objfiles.h"
 #include "gdb_obstack.h"
 #include "buildsym.h"
@@ -2959,7 +2960,7 @@ parse_partial_symbols (struct objfile *o
 		      CORE_ADDR valu;
 		      static int prev_so_symnum = -10;
 		      static int first_so_symnum;
-		      char *p;
+		      const char *p;
 		      int prev_textlow_not_set;
 
 		      valu = sh.value + ANOFFSET (objfile->section_offsets,
@@ -3012,9 +3013,8 @@ parse_partial_symbols (struct objfile *o
 			 the second the file name.  If pst exists, is
 			 empty, and has a filename ending in '/', we assume
 			 the previous N_SO was a directory name.  */
-
-		      p = strrchr (namestring, '/');
-		      if (p && *(p + 1) == '\000')
+		      p = lbasename (namestring);
+		      if (p != namestring && *p == '\000')
 			continue;		/* Simply ignore directory
 						   name SOs.  */
 
@@ -3065,15 +3065,15 @@ parse_partial_symbols (struct objfile *o
 			 work (I suppose the psymtab_include_list could be
 			 hashed or put in a binary tree, if profiling shows
 			 this is a major hog).  */
-		      if (pst && strcmp (namestring, pst->filename) == 0)
+		      if (pst && filename_cmp (namestring, pst->filename) == 0)
 			continue;
 
 		      {
 			int i;
 
 			for (i = 0; i < includes_used; i++)
-			  if (strcmp (namestring,
-				      psymtab_include_list[i]) == 0)
+			  if (filename_cmp (namestring,
+					    psymtab_include_list[i]) == 0)
 			    {
 			      i = -1;
 			      break;
Index: gdb/minsyms.c
===================================================================
--- gdb.orig/minsyms.c	2011-03-23 14:03:30.539811600 +0100
+++ gdb/minsyms.c	2011-03-23 14:08:47.529452100 +0100
@@ -43,6 +43,7 @@
 #include "gdb_string.h"
 #include "symtab.h"
 #include "bfd.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "demangle.h"
@@ -255,7 +256,7 @@ lookup_minimal_symbol (const char *name,
                       case mst_file_data:
                       case mst_file_bss:
                         if (sfile == NULL
-			    || strcmp (msymbol->filename, sfile) == 0)
+			    || filename_cmp (msymbol->filename, sfile) == 0)
                           found_file_symbol = msymbol;
                         break;
 
Index: gdb/psymtab.c
===================================================================
--- gdb.orig/psymtab.c	2011-03-23 14:03:30.540811600 +0100
+++ gdb/psymtab.c	2011-03-23 14:08:47.538953300 +0100
@@ -1067,7 +1067,7 @@ read_psymtabs_with_filename (struct objf
 
   ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
     {
-      if (strcmp (filename, p->filename) == 0)
+      if (filename_cmp (filename, p->filename) == 0)
 	PSYMTAB_TO_SYMTAB (p);
     }
 }
@@ -1735,7 +1735,7 @@ print-psymbols takes an output file name
 
   immediate_quit++;
   ALL_PSYMTABS (objfile, ps)
-    if (symname == NULL || strcmp (symname, ps->filename) == 0)
+    if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
     dump_psymtab (objfile, ps, outfile);
   immediate_quit--;
   do_cleanups (cleanups);
Index: gdb/remote-fileio.c
===================================================================
--- gdb.orig/remote-fileio.c	2011-03-23 14:03:30.541811600 +0100
+++ gdb/remote-fileio.c	2011-03-23 14:08:47.550454800 +0100
@@ -31,6 +31,7 @@
 #include "remote-fileio.h"
 #include "event-loop.h"
 #include "target.h"
+#include "filenames.h"
 
 #include <fcntl.h>
 #include <sys/time.h>
@@ -1020,8 +1021,8 @@ remote_fileio_func_rename (char *buf)
 		  cygwin_conv_path (CCP_WIN_A_TO_POSIX, newpath, newfullpath,
 				    PATH_MAX);
 		  len = strlen (oldfullpath);
-		  if (newfullpath[len] == '/'
-		      && !strncmp (oldfullpath, newfullpath, len))
+		  if (IS_DIR_SEPARATOR (newfullpath[len])
+		      && !filename_ncmp (oldfullpath, newfullpath, len))
 		    errno = EINVAL;
 		  else
 		    errno = EEXIST;
Index: gdb/solib.c
===================================================================
--- gdb.orig/solib.c	2011-03-23 14:03:30.542811600 +0100
+++ gdb/solib.c	2011-03-23 14:08:47.560456000 +0100
@@ -638,7 +638,7 @@ solib_read_symbols (struct so_list *so,
 	  /* Have we already loaded this shared object?  */
 	  ALL_OBJFILES (so->objfile)
 	    {
-	      if (strcmp (so->objfile->name, so->so_name) == 0
+	      if (filename_cmp (so->objfile->name, so->so_name) == 0
 		  && so->objfile->addr_low == so->addr_low)
 		break;
 	    }
@@ -762,7 +762,7 @@ update_solib_list (int from_tty, struct
 	    }
 	  else
 	    {
-	      if (! strcmp (gdb->so_original_name, i->so_original_name))
+	      if (! filename_cmp (gdb->so_original_name, i->so_original_name))
 		break;	      
 	    }
 
@@ -1339,7 +1339,7 @@ reload_shared_libraries_1 (int from_tty)
 	 symbol file, close that.  */
       if ((found_pathname == NULL && was_loaded)
 	  || (found_pathname != NULL
-	      && strcmp (found_pathname, so->so_name) != 0))
+	      && filename_cmp (found_pathname, so->so_name) != 0))
 	{
 	  if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED))
 	    free_objfile (so->objfile);
@@ -1351,7 +1351,7 @@ reload_shared_libraries_1 (int from_tty)
 	 file, open it.  */
       if (found_pathname != NULL
 	  && (!was_loaded
-	      || strcmp (found_pathname, so->so_name) != 0))
+	      || filename_cmp (found_pathname, so->so_name) != 0))
 	{
 	  volatile struct gdb_exception e;
 
Index: gdb/source.c
===================================================================
--- gdb.orig/source.c	2011-03-23 14:03:30.543811600 +0100
+++ gdb/source.c	2011-03-23 14:59:11.967507000 +0100
@@ -569,15 +569,10 @@ add_path (char *dirname, char **which_pa
 	p = *which_path;
 	while (1)
 	  {
-	    /* FIXME: strncmp loses in interesting ways on MS-DOS and
-	       MS-Windows because of case-insensitivity and two different
-	       but functionally identical slash characters.  We need a
-	       special filesystem-dependent file-name comparison function.
-
-	       Actually, even on Unix I would use realpath() or its work-
-	       alike before comparing.  Then all the code above which
+	    /* FIXME: we should use realpath() or its work-alike
+	       before comparing.  Then all the code above which
 	       removes excess slashes and dots could simply go away.  */
-	    if (!strncmp (p, name, len)
+	    if (!filename_ncmp (p, name, len)
 		&& (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR))
 	      {
 		/* Found it in the search path, remove old copy.  */
Index: gdb/symfile.c
===================================================================
--- gdb.orig/symfile.c	2011-03-23 14:03:30.544811600 +0100
+++ gdb/symfile.c	2011-03-23 14:08:47.584459100 +0100
@@ -1325,7 +1325,7 @@ separate_debug_file_exists (const char *
      ".debug" suffix as "/usr/lib/debug/path/to/file" is a separate tree where
      the separate debug infos with the same basename can exist.  */
 
-  if (strcmp (name, parent_objfile->name) == 0)
+  if (filename_cmp (name, parent_objfile->name) == 0)
     return 0;
 
   abfd = bfd_open_maybe_remote (name);
@@ -1333,7 +1333,7 @@ separate_debug_file_exists (const char *
   if (!abfd)
     return 0;
 
-  /* Verify symlinks were not the cause of strcmp name difference above.
+  /* Verify symlinks were not the cause of filename_cmp name difference above.
 
      Some operating systems, e.g. Windows, do not provide a meaningful
      st_ino; they always set it to zero.  (Windows does provide a
@@ -1471,7 +1471,8 @@ find_separate_debug_file_by_debuglink (s
       /* If the file is in the sysroot, try using its base path in the
 	 global debugfile directory.  */
       if (canon_name
-	  && strncmp (canon_name, gdb_sysroot, strlen (gdb_sysroot)) == 0
+	  && filename_ncmp (canon_name, gdb_sysroot,
+			    strlen (gdb_sysroot)) == 0
 	  && IS_DIR_SEPARATOR (canon_name[strlen (gdb_sysroot)]))
 	{
 	  memcpy (debugfile, debugdir, debugdir_end - debugdir);
@@ -2375,8 +2376,9 @@ reread_symbols (void)
 	  /* We need to do this whenever any symbols go away.  */
 	  make_cleanup (clear_symtab_users_cleanup, 0 /*ignore*/);
 
-	  if (exec_bfd != NULL && strcmp (bfd_get_filename (objfile->obfd),
-					  bfd_get_filename (exec_bfd)) == 0)
+	  if (exec_bfd != NULL
+	      && filename_cmp (bfd_get_filename (objfile->obfd),
+			       bfd_get_filename (exec_bfd)) == 0)
 	    {
 	      /* Reload EXEC_BFD without asking anything.  */
 
Index: gdb/symmisc.c
===================================================================
--- gdb.orig/symmisc.c	2011-03-23 14:03:30.545811600 +0100
+++ gdb/symmisc.c	2011-03-23 14:08:47.605461800 +0100
@@ -23,6 +23,7 @@
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "bfd.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "breakpoint.h"
@@ -475,7 +476,7 @@ maintenance_print_symbols (char *args, i
 
   immediate_quit++;
   ALL_SYMTABS (objfile, s)
-    if (symname == NULL || strcmp (symname, s->filename) == 0)
+    if (symname == NULL || filename_cmp (symname, s->filename) == 0)
     dump_symtab (objfile, s, outfile);
   immediate_quit--;
   do_cleanups (cleanups);
Index: gdb/symtab.c
===================================================================
--- gdb.orig/symtab.c	2011-03-23 14:03:30.546811600 +0100
+++ gdb/symtab.c	2011-03-23 14:08:47.614462900 +0100
@@ -2761,7 +2761,7 @@ filename_seen (const char *file, int add
 
   /* Is FILE in tab?  */
   for (p = tab; p < tab + tab_cur_size; p++)
-    if (strcmp (*p, file) == 0)
+    if (filename_cmp (*p, file) == 0)
       return 1;
 
   /* No; maybe add it to tab.  */
@@ -2862,7 +2862,7 @@ file_matches (const char *file, char *fi
     {
       for (i = 0; i < nfiles; i++)
 	{
-	  if (strcmp (files[i], lbasename (file)) == 0)
+	  if (filename_cmp (files[i], lbasename (file)) == 0)
 	    return 1;
 	}
     }
@@ -3260,7 +3260,7 @@ static void
 print_symbol_info (domain_enum kind, struct symtab *s, struct symbol *sym,
 		   int block, char *last)
 {
-  if (last == NULL || strcmp (last, s->filename) != 0)
+  if (last == NULL || filename_cmp (last, s->filename) != 0)
     {
       fputs_filtered ("\nFile ", gdb_stdout);
       fputs_filtered (s->filename, gdb_stdout);
@@ -4073,7 +4073,7 @@ not_interesting_fname (const char *fname
 
   for (i = 0; illegal_aliens[i]; i++)
     {
-      if (strcmp (fname, illegal_aliens[i]) == 0)
+      if (filename_cmp (fname, illegal_aliens[i]) == 0)
 	return 1;
     }
   return 0;
@@ -4102,12 +4102,7 @@ maybe_add_partial_symtab_filename (const
   if (not_interesting_fname (filename))
     return;
   if (!filename_seen (filename, 1, data->first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-      && strncasecmp (filename, data->text, data->text_len) == 0
-#else
-      && strncmp (filename, data->text, data->text_len) == 0
-#endif
-      )
+      && filename_ncmp (filename, data->text, data->text_len) == 0)
     {
       /* This file matches for a completion; add it to the
 	 current list of matches.  */
@@ -4120,12 +4115,7 @@ maybe_add_partial_symtab_filename (const
 
       if (base_name != filename
 	  && !filename_seen (base_name, 1, data->first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	  && strncasecmp (base_name, data->text, data->text_len) == 0
-#else
-	  && strncmp (base_name, data->text, data->text_len) == 0
-#endif
-	  )
+	  && filename_ncmp (base_name, data->text, data->text_len) == 0)
 	add_filename_to_list (base_name, data->text, data->word,
 			      data->list, data->list_used, data->list_alloced);
     }
@@ -4159,12 +4149,7 @@ make_source_files_completion_list (char
       if (not_interesting_fname (s->filename))
 	continue;
       if (!filename_seen (s->filename, 1, &first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	  && strncasecmp (s->filename, text, text_len) == 0
-#else
-	  && strncmp (s->filename, text, text_len) == 0
-#endif
-	  )
+	  && filename_ncmp (s->filename, text, text_len) == 0)
 	{
 	  /* This file matches for a completion; add it to the current
 	     list of matches.  */
@@ -4180,12 +4165,7 @@ make_source_files_completion_list (char
 	  base_name = lbasename (s->filename);
 	  if (base_name != s->filename
 	      && !filename_seen (base_name, 1, &first)
-#if HAVE_DOS_BASED_FILE_SYSTEM
-	      && strncasecmp (base_name, text, text_len) == 0
-#else
-	      && strncmp (base_name, text, text_len) == 0
-#endif
-	      )
+	      && filename_ncmp (base_name, text, text_len) == 0)
 	    add_filename_to_list (base_name, text, word,
 				  &list, &list_used, &list_alloced);
 	}
Index: gdb/xml-syscall.c
===================================================================
--- gdb.orig/xml-syscall.c	2011-03-23 14:03:30.583811600 +0100
+++ gdb/xml-syscall.c	2011-03-23 14:08:47.636965800 +0100
@@ -281,7 +281,7 @@ static void
 init_sysinfo (void)
 {
   /* Should we re-read the XML info for this target?  */
-  if (my_gdb_datadir && strcmp (my_gdb_datadir, gdb_datadir) != 0)
+  if (my_gdb_datadir && filename_cmp (my_gdb_datadir, gdb_datadir) != 0)
     {
       /* The data-directory changed from the last time we used it.
 	 It means that we have to re-read the XML info.  */
Index: gdb/windows-nat.c
===================================================================
--- gdb.orig/windows-nat.c	2011-03-23 14:03:30.547811600 +0100
+++ gdb/windows-nat.c	2011-03-23 14:08:47.642966500 +0100
@@ -46,6 +46,7 @@
 #include <signal.h>
 
 #include "buildsym.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "gdb_obstack.h"
@@ -2586,7 +2587,7 @@ _initialize_check_for_gdb_ini (void)
 				      sizeof ("/gdb.ini"));
       strcpy (oldini, homedir);
       p = strchr (oldini, '\0');
-      if (p > oldini && p[-1] != '/')
+      if (p > oldini && !IS_DIR_SEPARATOR (p[-1]))
 	*p++ = '/';
       strcpy (p, "gdb.ini");
       if (access (oldini, 0) == 0)

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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-23 15:29                   ` Pedro Alves
  2011-03-23 15:29                     ` Kai Tietz
@ 2011-03-23 18:24                     ` Eli Zaretskii
  2011-03-23 21:11                       ` Kai Tietz
  1 sibling, 1 reply; 37+ messages in thread
From: Eli Zaretskii @ 2011-03-23 18:24 UTC (permalink / raw)
  To: Pedro Alves; +Cc: ktietz70, gdb-patches, brobecker

> From: Pedro Alves <pedro@codesourcery.com>
> Date: Wed, 23 Mar 2011 14:44:34 +0000
> Cc: gdb-patches@sourceware.org, Eli Zaretskii <eliz@gnu.org>, Joel Brobecker <brobecker@adacore.com>
> 
> The patch looked good to me with that change.

Agreed.


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

* Re: [patch gdb]: Fix some DOS-path related issues in gdb
  2011-03-23 18:24                     ` Eli Zaretskii
@ 2011-03-23 21:11                       ` Kai Tietz
  0 siblings, 0 replies; 37+ messages in thread
From: Kai Tietz @ 2011-03-23 21:11 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Pedro Alves, gdb-patches, brobecker

2011/3/23 Eli Zaretskii <eliz@gnu.org>:
>> From: Pedro Alves <pedro@codesourcery.com>
>> Date: Wed, 23 Mar 2011 14:44:34 +0000
>> Cc: gdb-patches@sourceware.org, Eli Zaretskii <eliz@gnu.org>, Joel Brobecker <brobecker@adacore.com>
>>
>> The patch looked good to me with that change.
>
> Agreed.

Ok, thanks. Applied patch.

Regards,
Kai


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

end of thread, other threads:[~2011-03-23 18:24 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <AANLkTi=QoOiBg3XmMv+hRNe8DkT2YiVGZ=7NhaQwzCey@mail.gmail.com>
2011-03-03 12:10 ` [patch gdb]: Fix some DOS-path related issues in gdb Kai Tietz
2011-03-03 13:24   ` Eli Zaretskii
2011-03-03 13:48     ` Kai Tietz
2011-03-03 14:00       ` Eli Zaretskii
2011-03-03 14:58         ` Joel Brobecker
2011-03-03 15:25           ` Kai Tietz
2011-03-03 15:32           ` Pedro Alves
2011-03-03 15:41             ` Kai Tietz
2011-03-03 16:09               ` Pedro Alves
2011-03-03 16:19                 ` Kai Tietz
2011-03-03 16:42                   ` Pedro Alves
2011-03-03 17:32                     ` Kai Tietz
2011-03-04  7:23                       ` Vladimir Simonov
2011-03-04  8:23                         ` Joel Brobecker
2011-03-07 19:28             ` Jan Kratochvil
2011-03-07 19:28               ` Pedro Alves
2011-03-07 19:34                 ` Jan Kratochvil
2011-03-03 18:09           ` Eli Zaretskii
2011-03-04  5:12             ` Joel Brobecker
2011-03-04 13:05               ` André Pönitz
2011-03-04  9:48             ` Kai Tietz
2011-03-04 10:37               ` Mark Kettenis
2011-03-05  9:13                 ` Kai Tietz
2011-03-05 11:38                   ` Vladimir Simonov
2011-03-05 12:45                     ` Kai Tietz
2011-03-23 11:16             ` Kai Tietz
2011-03-23 12:44               ` Mark Kettenis
2011-03-23 14:07                 ` Kai Tietz
2011-03-23 14:16               ` Pedro Alves
2011-03-23 14:18                 ` Kai Tietz
2011-03-23 14:29                   ` Pierre Muller
     [not found]                   ` <-544184502231544940@unknownmsgid>
2011-03-23 14:44                     ` Kai Tietz
2011-03-23 15:29                   ` Pedro Alves
2011-03-23 15:29                     ` Kai Tietz
2011-03-23 18:24                     ` Eli Zaretskii
2011-03-23 21:11                       ` Kai Tietz
2011-03-03 17:02         ` Mark Kettenis

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