@@ -500,7 +500,7 @@ find_and_open_script (const char *script_file, int search_path,
char *file;
int fd;
struct cleanup *old_cleanups;
- enum openp_flags search_flags = OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH;
+ enum openp_flags search_flags = OPF_TRY_CWD_FIRST;
file = tilde_expand (script_file);
old_cleanups = make_cleanup (xfree, file);
@@ -523,6 +523,8 @@ find_and_open_script (const char *script_file, int search_path,
do_cleanups (old_cleanups);
+ *full_pathp = gdb_realpath_and_xfree (*full_pathp);
+
*streamp = fdopen (fd, FOPEN_RT);
if (*streamp == NULL)
{
@@ -323,6 +323,9 @@ extern const char *pc_prefix (CORE_ADDR);
/* See openp function definition for their description. */
enum openp_flags
{
+ /* No options specified, type-compatibile with the enum. */
+ OPF_NONE = 0,
+
/* Try to open ./STRING before searching PATH (ie pretend the first
element of PATH is "."). This also indicates that, unless
OPF_SEARCH_IN_PATH is also specified, a slash in STRING disables
@@ -334,9 +337,6 @@ enum openp_flags
/* Absolute names will also be searched in path (we usually want this
for source files but not for executables). */
OPF_SEARCH_IN_PATH = (1 << 1),
-
- /* See openp, to be removed. */
- OPF_RETURN_REALPATH = (1 << 2),
};
extern int openp (const char *, enum openp_flags, const char *, int, char **);
@@ -10470,7 +10470,7 @@ try_open_dwop_file (const char *file_name, int is_dwp, int search_cwd)
else
search_path = xstrdup (debug_file_directory);
- flags = OPF_RETURN_REALPATH;
+ flags = OPF_NONE;
if (is_dwp)
flags |= OPF_SEARCH_IN_PATH;
desc = openp (search_path, flags, file_name,
@@ -10478,6 +10478,7 @@ try_open_dwop_file (const char *file_name, int is_dwp, int search_cwd)
xfree (search_path);
if (desc < 0)
return NULL;
+ absolute_name = gdb_realpath_and_xfree (absolute_name);
sym_bfd = gdb_bfd_open (absolute_name, gnutarget, desc);
xfree (absolute_name);
@@ -127,7 +127,7 @@ nto_find_and_open_solib (char *solib, unsigned o_flags, char **temp_pathname)
arch_path);
base = lbasename (solib);
- ret = openp (buf, OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, base, o_flags,
+ ret = openp (buf, OPF_TRY_CWD_FIRST, base, o_flags,
temp_pathname);
if (ret < 0 && base != solib)
{
@@ -136,11 +136,13 @@ nto_find_and_open_solib (char *solib, unsigned o_flags, char **temp_pathname)
if (temp_pathname)
{
if (ret >= 0)
- *temp_pathname = gdb_realpath (arch_path);
+ *temp_pathname = xstrdup (arch_path);
else
*temp_pathname = NULL;
}
}
+ if (ret >= 0)
+ *temp_pathname = gdb_realpath_and_xfree (*temp_pathname);
return ret;
}
@@ -158,7 +158,7 @@ solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot)
char *temp_pathname = NULL;
const char *fskind = effective_target_file_system_kind ();
struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
- int prefix_len, orig_prefix_len;
+ int prefix_len, orig_prefix_len, temp_pathname_is_realpath;
/* If the absolute prefix starts with "target:" but the filesystem
accessed by the target_fileio_* methods is the local filesystem
@@ -311,7 +311,12 @@ solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot)
needs to be freed. */
if (found_file < 0)
- temp_pathname = NULL;
+ {
+ temp_pathname = NULL;
+ temp_pathname_is_realpath = 1;
+ }
+ else
+ temp_pathname_is_realpath = 0;
/* If the search in gdb_sysroot failed, and the path name is
absolute at this point, make it relative. (openp will try and open the
@@ -331,8 +336,7 @@ solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot)
/* If not found, and we're looking for a solib, search the
solib_search_path (if any). */
if (is_solib && found_file < 0 && solib_search_path != NULL)
- found_file = openp (solib_search_path,
- OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH,
+ found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
in_pathname, O_RDONLY | O_BINARY, &temp_pathname);
/* If not found, and we're looking for a solib, next search the
@@ -340,8 +344,7 @@ solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot)
path). This is to allow reading solibs from a path that differs
from the opened path. */
if (is_solib && found_file < 0 && solib_search_path != NULL)
- found_file = openp (solib_search_path,
- OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH,
+ found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
target_lbasename (fskind, in_pathname),
O_RDONLY | O_BINARY, &temp_pathname);
@@ -355,7 +358,7 @@ solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot)
if (found_file < 0 && sysroot == NULL)
found_file = openp (get_in_environ (current_inferior ()->environment,
"PATH"),
- OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, in_pathname,
+ OPF_TRY_CWD_FIRST, in_pathname,
O_RDONLY | O_BINARY, &temp_pathname);
/* If not found, and we're looking for a solib, next search the
@@ -363,9 +366,12 @@ solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot)
if (is_solib && found_file < 0 && sysroot == NULL)
found_file = openp (get_in_environ (current_inferior ()->environment,
"LD_LIBRARY_PATH"),
- OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, in_pathname,
+ OPF_TRY_CWD_FIRST, in_pathname,
O_RDONLY | O_BINARY, &temp_pathname);
+ if (found_file >= 0 && temp_pathname_is_realpath)
+ temp_pathname = gdb_realpath_and_xfree (temp_pathname);
+
if (fd == NULL)
{
if (found_file >= 0)
@@ -749,11 +749,6 @@ dirnames_to_char_ptr_vec_target_exc (const char *string)
and the file, sigh! Emacs gets confuzzed by this when we print the
source file name!!!
- If OPTS has OPF_RETURN_REALPATH set return FILENAME_OPENED resolved by
- gdb_realpath. Even without OPF_RETURN_REALPATH this function still returns
- filename starting with "/". If FILENAME_OPENED is NULL this option has no
- effect.
-
If a file is found, return the descriptor.
Otherwise, return -1, with errno set for the last name we tried to open. */
@@ -910,13 +905,10 @@ openp (const char *path, enum openp_flags opts, const char *string,
done:
if (filename_opened)
{
- /* If a file was opened, canonicalize its filename. */
if (fd < 0)
*filename_opened = NULL;
- else if ((opts & OPF_RETURN_REALPATH) != 0)
- *filename_opened = gdb_realpath (filename);
else
- *filename_opened = gdb_abspath (filename);
+ *filename_opened = xstrdup (filename);
}
return fd;
@@ -939,14 +931,15 @@ source_full_path_of (const char *filename, char **full_pathname)
{
int fd;
- fd = openp (source_path,
- OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH,
+ fd = openp (source_path, OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH,
filename, O_RDONLY, full_pathname);
if (fd < 0)
{
*full_pathname = NULL;
return 0;
}
+
+ *full_pathname = gdb_realpath_and_xfree (*full_pathname);
close (fd);
return 1;
@@ -1113,17 +1106,18 @@ find_and_open_source (const char *filename,
}
}
- result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, filename,
- OPEN_MODE, fullname);
+ result = openp (path, OPF_SEARCH_IN_PATH, filename, OPEN_MODE, fullname);
if (result < 0)
{
/* Didn't work. Try using just the basename. */
p = lbasename (filename);
if (p != filename)
- result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, p,
- OPEN_MODE, fullname);
+ result = openp (path, OPF_SEARCH_IN_PATH, p, OPEN_MODE, fullname);
}
+ if (result >= 0)
+ *fullname = gdb_realpath_and_xfree (*fullname);
+
do_cleanups (cleanup);
return result;
}
@@ -1731,8 +1731,7 @@ symfile_bfd_open (const char *name)
expanded_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"),
- OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH,
+ desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST,
expanded_name, O_RDONLY | O_BINARY, &absolute_name);
#if defined(__GO32__) || defined(_WIN32) || defined (__CYGWIN__)
if (desc < 0)
@@ -1740,8 +1739,7 @@ symfile_bfd_open (const char *name)
char *exename = alloca (strlen (expanded_name) + 5);
strcat (strcpy (exename, expanded_name), ".exe");
- desc = openp (getenv ("PATH"),
- OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH,
+ desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST,
exename, O_RDONLY | O_BINARY, &absolute_name);
}
#endif
@@ -1752,6 +1750,7 @@ symfile_bfd_open (const char *name)
}
xfree (expanded_name);
+ absolute_name = gdb_realpath_and_xfree (absolute_name);
make_cleanup (xfree, absolute_name);
name = absolute_name;
}
@@ -2820,6 +2820,17 @@ gdb_realpath (const char *filename)
return xstrdup (filename);
}
+/* Wrap gdb_realpath by also calling xfree for the FILENAME parameter. */
+
+char *
+gdb_realpath_and_xfree (char *filename)
+{
+ char *retval = gdb_realpath (filename);
+
+ xfree (filename);
+ return retval;
+}
+
/* Return a copy of FILENAME, with its directory prefix canonicalized
by gdb_realpath. */
@@ -124,6 +124,8 @@ extern struct cleanup *make_bpstat_clear_actions_cleanup (void);
extern char *gdb_realpath (const char *);
+extern char *gdb_realpath_and_xfree (char *filename);
+
extern char *gdb_realpath_keepfile (const char *);
extern char *gdb_abspath (const char *);