From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 705 invoked by alias); 1 May 2004 17:01:40 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 689 invoked from network); 1 May 2004 17:01:39 -0000 Received: from unknown (HELO burundai.radix50.net) (82.83.204.57) by sources.redhat.com with SMTP; 1 May 2004 17:01:39 -0000 Received: from burundai.radix50.net (localhost [127.0.0.1]) by burundai.radix50.net (8.12.3/8.12.3/Debian -4) with ESMTP id i41H3CLx021853 for ; Sat, 1 May 2004 19:03:13 +0200 Received: (from ibr@localhost) by burundai.radix50.net (8.12.3/8.12.3/Debian -4) id i41H3C1w021851 for gdb-patches@sources.redhat.com; Sat, 1 May 2004 19:03:12 +0200 Date: Sat, 01 May 2004 17:01:00 -0000 From: Baurjan Ismagulov To: gdb-patches@sources.redhat.com Subject: Re: handling of absolute source file paths Message-ID: <20040501170312.GA21679@ata.cs.hun.edu.tr> Mail-Followup-To: gdb-patches@sources.redhat.com References: <20040420154855.GD9020@ata.cs.hacettepe.edu.tr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="gKMricLos+KVdGMg" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.4i X-SW-Source: 2004-05/txt/msg00034.txt.bz2 --gKMricLos+KVdGMg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 287 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. --gKMricLos+KVdGMg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gdb-6.0-ibr-search_in_path-20040310-1302.diff" Content-length: 9675 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. */ --gKMricLos+KVdGMg--