Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RFA: ensure binary objects opened in binary mode
@ 2006-02-17 22:02 Charles Wilson
  2006-02-17 23:41 ` Christopher Faylor
  2006-02-18 10:50 ` Eli Zaretskii
  0 siblings, 2 replies; 15+ messages in thread
From: Charles Wilson @ 2006-02-17 22:02 UTC (permalink / raw)
  To: gdb-patches

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

gdb uses solib_open() to open solibs via open(), openp(), or 
ops->find_and_open_solib(), using the O_RDONLY flag.  Later, bfd_open uses
    fdopen(filedescriptor_from_solib_open, "rb")
to change the text/binary mode (to binary) on platforms where that 
matters -- like cygwin and mingw.

Now, cygwin's fdopen implementation does the right thing and does, in 
fact, change the mode to binary.  So, on cygwin, this "bug" has no 
practical effect; this is not true for mingw, where the mode is NOT 
changed to binary (which leads to all sorts of problems parsing the file).

However, even on cygwin, it's still *wrong* for gdb to open a solib 
(which is by definition a binary object) in text mode -- even if it gets 
"fixed" later by bfd_open().  So IMO this patch is "the right thing" for 
both cygwin and mingw, even tho there is no observable change in 
cygwin's behavior -- and it DOES fix a serious bug on mingw.

Oh, and about the #ifndef O_BINARY stuff in this .c file: look at 
gdb/source.c before commenting.  Also, as this patch adds only three 
non-blank lines and modifies only six more (all in exactly the same 
way), I believe it falls under the FSF definition of trivial.

2006-02-17  Charles Wilson  <...>

	* gdb/solib.c(solib_open): ensure solib files are opened in
	binary mode.

--
Chuck


[-- Attachment #2: gdb-6.4.50.20060131-cvs.solib.patch --]
[-- Type: text/plain, Size: 2586 bytes --]

Index: gdb/solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.83
diff -u -r1.83 solib.c
--- gdb/solib.c	21 Jan 2006 22:23:27 -0000	1.83
+++ gdb/solib.c	1 Feb 2006 21:27:52 -0000
@@ -47,6 +47,10 @@
 #include "observer.h"
 #include "readline/readline.h"
 
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
 /* Architecture-specific operations.  */
 
 /* Per-architecture data key.  */
@@ -171,7 +175,7 @@
 	}
 
       /* Now see if we can open it.  */
-      found_file = open (temp_pathname, O_RDONLY, 0);
+      found_file = open (temp_pathname, O_RDONLY|O_BINARY, 0);
     }
 
   /* If the search in solib_absolute_prefix failed, and the path name is
@@ -192,32 +196,32 @@
   /* If not found, search the solib_search_path (if any).  */
   if (found_file < 0 && solib_search_path != NULL)
     found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
-			in_pathname, O_RDONLY, 0, &temp_pathname);
+			in_pathname, O_RDONLY|O_BINARY, 0, &temp_pathname);
   
   /* If not found, next search the solib_search_path (if any) for the basename
      only (ignoring the path).  This is to allow reading solibs from a path
      that differs from the opened path.  */
   if (found_file < 0 && solib_search_path != NULL)
     found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
-                        lbasename (in_pathname), O_RDONLY, 0,
+                        lbasename (in_pathname), O_RDONLY|O_BINARY, 0,
                         &temp_pathname);
 
   /* If not found, try to use target supplied solib search method */
   if (found_file < 0 && ops->find_and_open_solib)
-    found_file = ops->find_and_open_solib (in_pathname, O_RDONLY,
+    found_file = ops->find_and_open_solib (in_pathname, O_RDONLY|O_BINARY,
 					   &temp_pathname);
 
   /* If not found, next search the inferior's $PATH environment variable. */
   if (found_file < 0 && solib_absolute_prefix == NULL)
     found_file = openp (get_in_environ (inferior_environ, "PATH"),
-			OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0,
+			OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY|O_BINARY, 0,
 			&temp_pathname);
 
   /* If not found, next search the inferior's $LD_LIBRARY_PATH 
      environment variable. */
   if (found_file < 0 && solib_absolute_prefix == NULL)
     found_file = openp (get_in_environ (inferior_environ, "LD_LIBRARY_PATH"),
-			OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0,
+			OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY|O_BINARY, 0,
 			&temp_pathname);
 
   /* Done.  If not found, tough luck.  Return found_file and 

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

end of thread, other threads:[~2006-03-01 22:11 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-17 22:02 RFA: ensure binary objects opened in binary mode Charles Wilson
2006-02-17 23:41 ` Christopher Faylor
2006-02-18 10:45   ` Eli Zaretskii
2006-02-18 11:19     ` Mark Kettenis
2006-02-18 11:47       ` Eli Zaretskii
2006-02-18 11:55         ` Mark Kettenis
2006-02-22  5:52         ` Charles Wilson
2006-02-22 17:06           ` Christopher Faylor
2006-02-22 18:50           ` Eli Zaretskii
2006-02-22 21:55             ` Daniel Jacobowitz
2006-02-24 10:37               ` Charles Wilson
2006-02-24 11:44                 ` Eli Zaretskii
2006-02-25  7:29                   ` Charles Wilson
2006-03-01 22:11             ` Michael Snyder
2006-02-18 10:50 ` Eli Zaretskii

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