diff options
author | Eli Zaretskii <eliz@gnu.org> | 2004-07-30 19:17:20 +0000 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2004-07-30 19:17:20 +0000 |
commit | 014d698b35008f566973fc2fe0d4a0d3e3009a06 (patch) | |
tree | 22e582437f29fe08fbbc4ee270a97a028d19564d | |
parent | be7d7357efe8cad63c8920b7fa69f6d2324d6fa5 (diff) | |
download | gdb-014d698b35008f566973fc2fe0d4a0d3e3009a06.zip gdb-014d698b35008f566973fc2fe0d4a0d3e3009a06.tar.gz gdb-014d698b35008f566973fc2fe0d4a0d3e3009a06.tar.bz2 |
* defs.h (OPF_TRY_CWD_FIRST, OPF_SEARCH_IN_PATH): New macros.
* exec.c (exec_file_attach):
* nto-tdep.c (nto_find_and_open_solib):
* pa64solib.c (pa64_solib_sizeof_symbol_table):
* solib.c (solib_open):
* somsolib.c (som_solib_sizeof_symbol_table):
* source.c (is_regular_file, openp, open_source_file):
* symfile.c (symfile_bfd_open):
* wince.c (upload_to_device): Differentiate between the search for
binary and source files.
-rw-r--r-- | gdb/defs.h | 3 | ||||
-rw-r--r-- | gdb/exec.c | 7 | ||||
-rw-r--r-- | gdb/nto-tdep.c | 2 | ||||
-rw-r--r-- | gdb/pa64solib.c | 4 | ||||
-rw-r--r-- | gdb/solib.c | 14 | ||||
-rw-r--r-- | gdb/somsolib.c | 3 | ||||
-rw-r--r-- | gdb/source.c | 30 | ||||
-rw-r--r-- | gdb/symfile.c | 7 |
8 files changed, 45 insertions, 25 deletions
@@ -611,6 +611,9 @@ extern void print_address (CORE_ADDR, struct ui_file *); /* 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 **); @@ -194,7 +194,7 @@ exec_file_attach (char *filename, int from_tty) 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__) @@ -202,8 +202,9 @@ exec_file_attach (char *filename, int from_tty) { 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 --git a/gdb/nto-tdep.c b/gdb/nto-tdep.c index f562ebd..50b4fc5 100644 --- a/gdb/nto-tdep.c +++ b/gdb/nto-tdep.c @@ -115,7 +115,7 @@ nto_find_and_open_solib (char *solib, unsigned o_flags, char **temp_pathname) 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 --git a/gdb/pa64solib.c b/gdb/pa64solib.c index b74cd5a..35d5559 100644 --- a/gdb/pa64solib.c +++ b/gdb/pa64solib.c @@ -157,8 +157,8 @@ pa64_solib_sizeof_symbol_table (char *filename) /* 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 --git a/gdb/solib.c b/gdb/solib.c index 76d782d..e722b98 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -156,15 +156,15 @@ solib_open (char *in_pathname, char **found_pathname) /* 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 @@ solib_open (char *in_pathname, char **found_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"), - 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 --git a/gdb/somsolib.c b/gdb/somsolib.c index 4db13a9..fd6c00c 100644 --- a/gdb/somsolib.c +++ b/gdb/somsolib.c @@ -216,7 +216,8 @@ som_solib_sizeof_symbol_table (char *filename) /* 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 --git a/gdb/source.c b/gdb/source.c index 443421c..8c6fec1 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -636,12 +636,18 @@ is_regular_file (const char *name) /* 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 @@ -654,7 +660,7 @@ is_regular_file (const char *name) /* >>>> 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) { @@ -672,7 +678,7 @@ openp (const char *path, int try_cwd_first, const char *string, mode |= O_BINARY; #endif - if (try_cwd_first || IS_ABSOLUTE_PATH (string)) + if ((opts & OPF_TRY_CWD_FIRST) || IS_ABSOLUTE_PATH (string)) { int i; @@ -690,11 +696,16 @@ openp (const char *path, int try_cwd_first, const char *string, 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; @@ -793,7 +804,8 @@ source_full_path_of (char *filename, char **full_pathname) { 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; @@ -864,13 +876,13 @@ find_and_open_source (struct objfile *objfile, } } - result = openp (path, 0, filename, OPEN_MODE, 0, fullname); + result = openp (path, OPF_SEARCH_IN_PATH, filename, OPEN_MODE, 0, fullname); if (result < 0) { /* Didn't work. Try using just the basename. */ p = lbasename (filename); if (p != filename) - result = openp (path, 0, p, OPEN_MODE, 0, fullname); + result = openp (path, OPF_SEARCH_IN_PATH, p, OPEN_MODE, 0, fullname); } if (result >= 0) diff --git a/gdb/symfile.c b/gdb/symfile.c index 0e2d42c..f8c7a44 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1222,14 +1222,15 @@ symfile_bfd_open (char *name) 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) |