Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Baurjan Ismagulov <ibr@ata.cs.hun.edu.tr>
To: gdb-patches@sources.redhat.com
Subject: Re: handling of absolute source file paths
Date: Sat, 01 May 2004 17:01:00 -0000	[thread overview]
Message-ID: <20040501170312.GA21679@ata.cs.hun.edu.tr> (raw)
In-Reply-To: <ud661962c.fsf@elta.co.il>

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

Hello, Eli!

On Wed, Apr 21, 2004 at 08:51:55AM +0200, Eli Zaretskii wrote:
> The patch looks good to me, and I think I can approve it (Andrew?).
> So, unless someone else objected, it can go in.

Ping?

Attached the uncompressed patch for your convenience.

With kind regards,
Baurjan.

[-- Attachment #2: gdb-6.0-ibr-search_in_path-20040310-1302.diff --]
[-- Type: text/plain, Size: 9675 bytes --]

diff -NaurPX /home/ibr/tmp/root/prg/dontdiff.ibr gdb-6.0.orig/gdb/defs.h gdb-6.0/gdb/defs.h
--- gdb-6.0.orig/gdb/defs.h	Tue Jun 10 16:37:03 2003
+++ gdb-6.0/gdb/defs.h	Thu Mar  4 15:13:51 2004
@@ -570,6 +570,9 @@
 
 /* From source.c */
 
+#define OPF_TRY_CWD_FIRST     0x01
+#define OPF_SEARCH_IN_PATH    0x02
+
 extern int openp (const char *, int, const char *, int, int, char **);
 
 extern int source_full_path_of (char *, char **);
diff -NaurPX /home/ibr/tmp/root/prg/dontdiff.ibr gdb-6.0.orig/gdb/exec.c gdb-6.0/gdb/exec.c
--- gdb-6.0.orig/gdb/exec.c	Tue Jan 21 20:43:47 2003
+++ gdb-6.0/gdb/exec.c	Wed Mar 10 10:41:18 2004
@@ -204,7 +204,7 @@
       char *scratch_pathname;
       int scratch_chan;
 
-      scratch_chan = openp (getenv ("PATH"), 1, filename,
+      scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename,
 		   write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY, 0,
 			    &scratch_pathname);
 #if defined(__GO32__) || defined(_WIN32) || defined(__CYGWIN__)
@@ -212,8 +212,9 @@
 	{
 	  char *exename = alloca (strlen (filename) + 5);
 	  strcat (strcpy (exename, filename), ".exe");
-	  scratch_chan = openp (getenv ("PATH"), 1, exename, write_files ?
-	     O_RDWR | O_BINARY : O_RDONLY | O_BINARY, 0, &scratch_pathname);
+	  scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, exename,
+	     write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY, 0,
+	     &scratch_pathname);
 	}
 #endif
       if (scratch_chan < 0)
diff -NaurPX /home/ibr/tmp/root/prg/dontdiff.ibr gdb-6.0.orig/gdb/nto-tdep.c gdb-6.0/gdb/nto-tdep.c
--- gdb-6.0.orig/gdb/nto-tdep.c	Tue Jun 17 20:30:48 2003
+++ gdb-6.0/gdb/nto-tdep.c	Wed Mar 10 10:46:37 2004
@@ -115,7 +115,7 @@
   sprintf (buf, path_fmt, arch_path, arch_path, arch_path, arch_path,
 	   arch_path);
 
-  return openp (buf, 1, solib, o_flags, 0, temp_pathname);
+  return openp (buf, OPF_TRY_CWD_FIRST, solib, o_flags, 0, temp_pathname);
 }
 
 void
diff -NaurPX /home/ibr/tmp/root/prg/dontdiff.ibr gdb-6.0.orig/gdb/pa64solib.c gdb-6.0/gdb/pa64solib.c
--- gdb-6.0.orig/gdb/pa64solib.c	Sat Jun  7 01:32:59 2003
+++ gdb-6.0/gdb/pa64solib.c	Wed Mar 10 10:47:33 2004
@@ -157,8 +157,8 @@
 
   /* We believe that filename was handed to us by the dynamic linker, and
      is therefore always an absolute path.  */
-  desc = openp (getenv ("PATH"), 1, filename, O_RDONLY | O_BINARY,
-		0, &absolute_name);
+  desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename,
+		O_RDONLY | O_BINARY, 0, &absolute_name);
   if (desc < 0)
     {
       perror_with_name (filename);
diff -NaurPX /home/ibr/tmp/root/prg/dontdiff.ibr gdb-6.0.orig/gdb/solib.c gdb-6.0/gdb/solib.c
--- gdb-6.0.orig/gdb/solib.c	Fri Jun 20 14:23:18 2003
+++ gdb-6.0/gdb/solib.c	Wed Mar 10 10:49:12 2004
@@ -156,15 +156,15 @@
   
   /* If not found, search the solib_search_path (if any).  */
   if (found_file < 0 && solib_search_path != NULL)
-    found_file = openp (solib_search_path,
-			1, in_pathname, O_RDONLY, 0, &temp_pathname);
+    found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
+			in_pathname, O_RDONLY, 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, 
-                        1, lbasename (in_pathname), O_RDONLY, 0,
+    found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
+                        lbasename (in_pathname), O_RDONLY, 0,
                         &temp_pathname);
 
   /* If not found, try to use target supplied solib search method */
@@ -175,13 +175,15 @@
   /* 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"),
-			1, in_pathname, O_RDONLY, 0, &temp_pathname);
+			OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 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"),
-			1, in_pathname, O_RDONLY, 0, &temp_pathname);
+			OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0,
+			&temp_pathname);
 
   /* Done.  If not found, tough luck.  Return found_file and 
      (optionally) found_pathname.  */
diff -NaurPX /home/ibr/tmp/root/prg/dontdiff.ibr gdb-6.0.orig/gdb/somsolib.c gdb-6.0/gdb/somsolib.c
--- gdb-6.0.orig/gdb/somsolib.c	Tue Mar 18 00:25:08 2003
+++ gdb-6.0/gdb/somsolib.c	Wed Mar 10 10:49:42 2004
@@ -221,7 +221,8 @@
   /* We believe that filename was handed to us by the dynamic linker, and
      is therefore always an absolute path.
    */
-  desc = openp (getenv ("PATH"), 1, filename, O_RDONLY | O_BINARY, 0, &absolute_name);
+  desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename,
+		O_RDONLY | O_BINARY, 0, &absolute_name);
   if (desc < 0)
     {
       perror_with_name (filename);
diff -NaurPX /home/ibr/tmp/root/prg/dontdiff.ibr gdb-6.0.orig/gdb/source.c gdb-6.0/gdb/source.c
--- gdb-6.0.orig/gdb/source.c	Wed May 14 19:43:18 2003
+++ gdb-6.0/gdb/source.c	Wed Mar 10 12:57:36 2004
@@ -638,12 +638,18 @@
 /* Open a file named STRING, searching path PATH (dir names sep by some char)
    using mode MODE and protection bits PROT in the calls to open.
 
-   If TRY_CWD_FIRST, try to open ./STRING before searching PATH.
+   OPTS specifies the function behaviour in specific cases.
+
+   If OPF_TRY_CWD_FIRST, try to open ./STRING before searching PATH.
    (ie pretend the first element of PATH is ".").  This also indicates
    that a slash in STRING disables searching of the path (this is
    so that "exec-file ./foo" or "symbol-file ./foo" insures that you
    get that particular version of foo or an error message).
 
+   If OPTS has OPF_SEARCH_IN_PATH set, absolute names will also be
+   searched in path (we usually want this for source files but not for
+   executables).
+
    If FILENAME_OPENED is non-null, set it to a newly allocated string naming
    the actual file opened (this string will always start with a "/").  We
    have to take special pains to avoid doubling the "/" between the directory
@@ -656,7 +662,7 @@
 /*  >>>> This should only allow files of certain types,
     >>>>  eg executable, non-directory */
 int
-openp (const char *path, int try_cwd_first, const char *string,
+openp (const char *path, int opts, const char *string,
        int mode, int prot,
        char **filename_opened)
 {
@@ -674,7 +680,7 @@
   mode |= O_BINARY;
 #endif
 
-  if (try_cwd_first || IS_ABSOLUTE_PATH (string))
+  if ((opts & OPF_TRY_CWD_FIRST) || IS_ABSOLUTE_PATH (string))
     {
       int i;
 
@@ -692,11 +698,16 @@
 	  fd = -1;
 	}
 
-      for (i = 0; string[i]; i++)
-	if (IS_DIR_SEPARATOR (string[i]))
-	  goto done;
+      if (!(opts & OPF_SEARCH_IN_PATH))
+	for (i = 0; string[i]; i++)
+	  if (IS_DIR_SEPARATOR (string[i]))
+	    goto done;
     }
 
+  /* /foo => foo, to avoid multiple slashes that Emacs doesn't like. */
+  while (IS_DIR_SEPARATOR(string[0]))
+    string++;
+
   /* ./foo => foo */
   while (string[0] == '.' && IS_DIR_SEPARATOR (string[1]))
     string += 2;
@@ -796,7 +807,8 @@
 {
   int fd;
 
-  fd = openp (source_path, 1, filename, O_RDONLY, 0, full_pathname);
+  fd = openp (source_path, OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH, filename,
+	      O_RDONLY, 0, full_pathname);
   if (fd < 0)
     {
       *full_pathname = NULL;
@@ -851,13 +863,15 @@
 	}
     }
 
-  result = openp (path, 0, s->filename, OPEN_MODE, 0, &s->fullname);
+  result = openp (path, OPF_SEARCH_IN_PATH, s->filename, OPEN_MODE, 0,
+		  &s->fullname);
   if (result < 0)
     {
       /* Didn't work.  Try using just the basename. */
       p = lbasename (s->filename);
       if (p != s->filename)
-	result = openp (path, 0, p, OPEN_MODE, 0, &s->fullname);
+	result = openp (path, OPF_SEARCH_IN_PATH, p, OPEN_MODE, 0,
+			&s->fullname);
     }
 
   if (result >= 0)
diff -NaurPX /home/ibr/tmp/root/prg/dontdiff.ibr gdb-6.0.orig/gdb/symfile.c gdb-6.0/gdb/symfile.c
--- gdb-6.0.orig/gdb/symfile.c	Thu Aug 14 22:12:31 2003
+++ gdb-6.0/gdb/symfile.c	Wed Mar 10 10:51:32 2004
@@ -1298,14 +1298,15 @@
   name = tilde_expand (name);	/* Returns 1st new malloc'd copy */
 
   /* Look down path for it, allocate 2nd new malloc'd copy.  */
-  desc = openp (getenv ("PATH"), 1, name, O_RDONLY | O_BINARY, 0, &absolute_name);
+  desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, name, O_RDONLY | O_BINARY,
+		0, &absolute_name);
 #if defined(__GO32__) || defined(_WIN32) || defined (__CYGWIN__)
   if (desc < 0)
     {
       char *exename = alloca (strlen (name) + 5);
       strcat (strcpy (exename, name), ".exe");
-      desc = openp (getenv ("PATH"), 1, exename, O_RDONLY | O_BINARY,
-		    0, &absolute_name);
+      desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, exename,
+		    O_RDONLY | O_BINARY, 0, &absolute_name);
     }
 #endif
   if (desc < 0)
diff -NaurPX /home/ibr/tmp/root/prg/dontdiff.ibr gdb-6.0.orig/gdb/wince.c gdb-6.0/gdb/wince.c
--- gdb-6.0.orig/gdb/wince.c	Thu Jun 12 20:01:28 2003
+++ gdb-6.0/gdb/wince.c	Wed Mar 10 10:52:03 2004
@@ -1590,7 +1590,8 @@
     return remotefile;		/* Don't bother uploading. */
 
   /* Open the source. */
-  if ((fd = openp (getenv ("PATH"), TRUE, (char *) from, O_RDONLY, 0, NULL)) < 0)
+  if ((fd = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, (char *) from, O_RDONLY,
+		   0, NULL)) < 0)
     error ("couldn't open %s", from);
 
   /* Get the time for later comparison. */

  parent reply	other threads:[~2004-05-01 17:01 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-20 15:49 Baurjan Ismagulov
2004-04-21  5:51 ` Eli Zaretskii
2004-04-21 11:10   ` Baurjan Ismagulov
2004-05-01 17:01   ` Baurjan Ismagulov [this message]
2004-05-02 13:15     ` Eli Zaretskii
2004-05-01 17:12   ` Baurjan Ismagulov
2004-05-01 18:11     ` Eli Zaretskii
2004-05-08 21:20       ` Baurjan Ismagulov
2004-05-09 14:33         ` Eli Zaretskii
2004-05-09 13:53           ` Baurjan Ismagulov
2004-05-11 16:08         ` Eli Zaretskii
2004-07-17 18:20           ` Baurjan Ismagulov
2004-07-23 19:55             ` ping: " Baurjan Ismagulov
2004-07-24  7:21               ` Eli Zaretskii
2004-07-26 14:57                 ` Andrew Cagney
2004-07-26 15:20                   ` Baurjan Ismagulov
2004-07-26 17:48                     ` Eli Zaretskii
2004-07-26 18:15                     ` Andrew Cagney
2004-07-26 17:47                   ` Eli Zaretskii
2004-07-30 19:19             ` Eli Zaretskii
2004-07-31  7:57               ` Baurjan Ismagulov
2004-07-31  8:25                 ` Eli Zaretskii
2004-08-01 19:31                   ` Andrew Cagney
2004-08-03 16:59                     ` Baurjan Ismagulov
2004-08-03 19:12                       ` Eli Zaretskii
2004-08-04  7:02                         ` Baurjan Ismagulov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040501170312.GA21679@ata.cs.hun.edu.tr \
    --to=ibr@ata.cs.hun.edu.tr \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox