This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Fix openp() if the file doesn't exist


Sometime last April, when Joel committed a patch to not try to open
directories as programs, we started always searching the given path in
openp ().  Try it:
% gdb ./ls
will open /bin/ls if there is no ls in the current directory.

Anyone see a problem with this patch?  If not I'll commit it in a day or
two; also to 5.3 on the off chance we have another release.  This is one of
my two big annoyances at 5.3 (and HEAD).  The other is that backtrace
changes the current source location:

(gdb) list
1       in __libc_read
(gdb) bt
#0  0x400c98f4 in __libc_read () at __libc_read:-1
#1  0x0804bc40 in ?? ()
#2  0x08048e29 in __fxstat64 ()
#3  0x08049631 in __fxstat64 ()
#4  0x400279f1 in __libc_start_main (main=0x804915c <__fxstat64+1588>, argc=1, ubp_av=0x804bc40,
    init=0x80488d0, fini=0x804a44c <__fxstat64+6436>, rtld_fini=0x400, stack_end=0x400)
    at ../sysdeps/generic/libc-start.c:147
(gdb) list
147           result = main (argc, argv, __environ);
148         }
149     #ifdef HAVE_CANCELBUF
150       else
151         /* Not much left to do but to exit the thread, not the process.  */
152         __exit_thread (0);
153     #endif
154
155       exit (result);
156     }

Anyone know when that started happening?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2003-01-09  Daniel Jacobowitz  <drow@mvista.com>

	* source.c (openp): If the file does not exist don't necessarily
	search the path.

Index: source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.38
diff -u -p -r1.38 source.c
--- source.c	13 Dec 2002 17:55:49 -0000	1.38
+++ source.c	9 Jan 2003 22:33:43 -0000
@@ -674,14 +674,21 @@ openp (const char *path, int try_cwd_fir
   mode |= O_BINARY;
 #endif
 
-  if ((try_cwd_first || IS_ABSOLUTE_PATH (string)) && is_regular_file (string))
+  if (try_cwd_first || IS_ABSOLUTE_PATH (string))
     {
       int i;
-      filename = alloca (strlen (string) + 1);
-      strcpy (filename, string);
-      fd = open (filename, mode, prot);
-      if (fd >= 0)
-	goto done;
+
+      if (is_regular_file (string))
+	{
+	  filename = alloca (strlen (string) + 1);
+	  strcpy (filename, string);
+	  fd = open (filename, mode, prot);
+	  if (fd >= 0)
+	    goto done;
+	}
+      else
+	fd = -1;
+
       for (i = 0; string[i]; i++)
 	if (IS_DIR_SEPARATOR (string[i]))
 	  goto done;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]