This changes a couple of solib.c functions -- exec_file_find and
solib_find -- to return a unique_xmalloc_ptr, and then fixes up the
users. This allows the removal of some cleanups.
This also changes solib_bfd_open to not take ownership of its
argument. I think this change is somewhat cleaner.
gdb/ChangeLog
2018-02-14 Tom Tromey <tom@tromey.com>
* solist.h (exec_file_find, solib_find): Return
unique_xmalloc_ptr.
(solib_bfd_fopen): Take a const char *.
* solib.c (solib_find_1): Return unique_xmalloc_ptr.
(exec_file_find, solib_find): Likewise.
(solib_bfd_fopen): Do not take ownership of "pathname".
(solib_bfd_open): Use unique_xmalloc_ptr.
* solib-darwin.c (darwin_bfd_open): Use unique_xmalloc_ptr.
* solib-aix.c (solib_aix_bfd_open): Use unique_xmalloc_ptr.
* infrun.c (follow_exec): Use unique_xmalloc_ptr.
* exec.c (exec_file_locate_attach): Use unique_xmalloc_ptr.
+2018-02-14 Tom Tromey <tom@tromey.com>
+
+ * solist.h (exec_file_find, solib_find): Return
+ unique_xmalloc_ptr.
+ (solib_bfd_fopen): Take a const char *.
+ * solib.c (solib_find_1): Return unique_xmalloc_ptr.
+ (exec_file_find, solib_find): Likewise.
+ (solib_bfd_fopen): Do not take ownership of "pathname".
+ (solib_bfd_open): Use unique_xmalloc_ptr.
+ * solib-darwin.c (darwin_bfd_open): Use unique_xmalloc_ptr.
+ * solib-aix.c (solib_aix_bfd_open): Use unique_xmalloc_ptr.
+ * infrun.c (follow_exec): Use unique_xmalloc_ptr.
+ * exec.c (exec_file_locate_attach): Use unique_xmalloc_ptr.
+
2018-02-14 Joel Brobecker <brobecker@adacore.com>
* ada-lang.c (name_match_type_from_name): Remove reference to
2018-02-14 Joel Brobecker <brobecker@adacore.com>
* ada-lang.c (name_match_type_from_name): Remove reference to
void
exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty)
{
void
exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty)
{
- char *exec_file_target, *exec_file_host;
- struct cleanup *old_chain;
+ char *exec_file_target;
symfile_add_flags add_flags = 0;
/* Do nothing if we already have an executable filename. */
symfile_add_flags add_flags = 0;
/* Do nothing if we already have an executable filename. */
- exec_file_host = exec_file_find (exec_file_target, NULL);
- old_chain = make_cleanup (xfree, exec_file_host);
+ gdb::unique_xmalloc_ptr<char> exec_file_host
+ = exec_file_find (exec_file_target, NULL);
if (defer_bp_reset)
add_flags |= SYMFILE_DEFER_BP_RESET;
if (defer_bp_reset)
add_flags |= SYMFILE_DEFER_BP_RESET;
add_flags |= SYMFILE_VERBOSE;
/* Attempt to open the exec file. */
add_flags |= SYMFILE_VERBOSE;
/* Attempt to open the exec file. */
- try_open_exec_file (exec_file_host, current_inferior (), add_flags);
- do_cleanups (old_chain);
+ try_open_exec_file (exec_file_host.get (), current_inferior (), add_flags);
}
/* Set FILENAME as the new exec file.
}
/* Set FILENAME as the new exec file.
struct inferior *inf = current_inferior ();
int pid = ptid_get_pid (ptid);
ptid_t process_ptid;
struct inferior *inf = current_inferior ();
int pid = ptid_get_pid (ptid);
ptid_t process_ptid;
- char *exec_file_host;
- struct cleanup *old_chain;
/* This is an exec event that we actually wish to pay attention to.
Refresh our symbol table to the newly exec'd program, remove any
/* This is an exec event that we actually wish to pay attention to.
Refresh our symbol table to the newly exec'd program, remove any
breakpoint_init_inferior (inf_execd);
breakpoint_init_inferior (inf_execd);
- exec_file_host = exec_file_find (exec_file_target, NULL);
- old_chain = make_cleanup (xfree, exec_file_host);
+ gdb::unique_xmalloc_ptr<char> exec_file_host
+ = exec_file_find (exec_file_target, NULL);
/* If we were unable to map the executable target pathname onto a host
pathname, tell the user that. Otherwise GDB's subsequent behavior
/* If we were unable to map the executable target pathname onto a host
pathname, tell the user that. Otherwise GDB's subsequent behavior
Executable) main symbol file will only be computed by
solib_create_inferior_hook below. breakpoint_re_set would fail
to insert the breakpoints with the zero displacement. */
Executable) main symbol file will only be computed by
solib_create_inferior_hook below. breakpoint_re_set would fail
to insert the breakpoints with the zero displacement. */
- try_open_exec_file (exec_file_host, inf, SYMFILE_DEFER_BP_RESET);
-
- do_cleanups (old_chain);
+ try_open_exec_file (exec_file_host.get (), inf, SYMFILE_DEFER_BP_RESET);
/* If the target can specify a description, read it. Must do this
after flipping to the new executable (because the target supplied
/* If the target can specify a description, read it. Must do this
after flipping to the new executable (because the target supplied
char *sep;
int filename_len;
int found_file;
char *sep;
int filename_len;
int found_file;
if (pathname[path_len - 1] != ')')
return solib_bfd_open (pathname);
if (pathname[path_len - 1] != ')')
return solib_bfd_open (pathname);
/* Calling solib_find makes certain that sysroot path is set properly
if program has a dependency on .a archive and sysroot is set via
set sysroot command. */
/* Calling solib_find makes certain that sysroot path is set properly
if program has a dependency on .a archive and sysroot is set via
set sysroot command. */
- found_pathname = solib_find (filename.c_str (), &found_file);
+ gdb::unique_xmalloc_ptr<char> found_pathname
+ = solib_find (filename.c_str (), &found_file);
if (found_pathname == NULL)
perror_with_name (pathname);
if (found_pathname == NULL)
perror_with_name (pathname);
- gdb_bfd_ref_ptr archive_bfd (solib_bfd_fopen (found_pathname, found_file));
+ gdb_bfd_ref_ptr archive_bfd (solib_bfd_fopen (found_pathname.get (),
+ found_file));
if (archive_bfd == NULL)
{
warning (_("Could not open `%s' as an executable file: %s"),
if (archive_bfd == NULL)
{
warning (_("Could not open `%s' as an executable file: %s"),
static gdb_bfd_ref_ptr
darwin_bfd_open (char *pathname)
{
static gdb_bfd_ref_ptr
darwin_bfd_open (char *pathname)
{
int found_file;
/* Search for shared library file. */
int found_file;
/* Search for shared library file. */
- found_pathname = solib_find (pathname, &found_file);
+ gdb::unique_xmalloc_ptr<char> found_pathname
+ = solib_find (pathname, &found_file);
if (found_pathname == NULL)
perror_with_name (pathname);
/* Open bfd for shared library. */
if (found_pathname == NULL)
perror_with_name (pathname);
/* Open bfd for shared library. */
- gdb_bfd_ref_ptr abfd (solib_bfd_fopen (found_pathname, found_file));
+ gdb_bfd_ref_ptr abfd (solib_bfd_fopen (found_pathname.get (), found_file));
gdb_bfd_ref_ptr res
(gdb_bfd_mach_o_fat_extract (abfd.get (), bfd_object,
gdb_bfd_ref_ptr res
(gdb_bfd_mach_o_fat_extract (abfd.get (), bfd_object,
# define DOS_BASED_FILE_SYSTEM 0
#endif
# define DOS_BASED_FILE_SYSTEM 0
#endif
-/* Return the full pathname of a binary file (the main executable
- or a shared library file), or NULL if not found. The returned
- pathname is malloc'ed and must be freed by the caller. If FD
- is non-NULL, *FD is set to either -1 or an open file handle for
- the binary file.
+/* Return the full pathname of a binary file (the main executable or a
+ shared library file), or NULL if not found. If FD is non-NULL, *FD
+ is set to either -1 or an open file handle for the binary file.
Global variable GDB_SYSROOT is used as a prefix directory
to search for binary files if they have an absolute path.
Global variable GDB_SYSROOT is used as a prefix directory
to search for binary files if they have an absolute path.
* machines since a sysroot will almost always be set.
*/
* machines since a sysroot will almost always be set.
*/
+static gdb::unique_xmalloc_ptr<char>
solib_find_1 (const char *in_pathname, int *fd, int is_solib)
{
const struct target_so_ops *ops = solib_ops (target_gdbarch ());
solib_find_1 (const char *in_pathname, int *fd, int is_solib)
{
const struct target_so_ops *ops = solib_ops (target_gdbarch ());
{
if (fd != NULL)
*fd = -1;
{
if (fd != NULL)
*fd = -1;
+ return gdb::unique_xmalloc_ptr<char> (temp_pathname);
}
/* Now see if we can open it. */
}
/* Now see if we can open it. */
+ return gdb::unique_xmalloc_ptr<char> (temp_pathname);
}
/* Return the full pathname of the main executable, or NULL if not
}
/* Return the full pathname of the main executable, or NULL if not
- found. The returned pathname is malloc'ed and must be freed by
- the caller. If FD is non-NULL, *FD is set to either -1 or an open
- file handle for the main executable. */
+ found. If FD is non-NULL, *FD is set to either -1 or an open file
+ handle for the main executable. */
+gdb::unique_xmalloc_ptr<char>
exec_file_find (const char *in_pathname, int *fd)
{
exec_file_find (const char *in_pathname, int *fd)
{
+ gdb::unique_xmalloc_ptr<char> result;
const char *fskind = effective_target_file_system_kind ();
if (in_pathname == NULL)
const char *fskind = effective_target_file_system_kind ();
if (in_pathname == NULL)
(If that fails, we'll just fall back on the original
filename. Not much more we can do...) */
(If that fails, we'll just fall back on the original
filename. Not much more we can do...) */
- if (!source_full_path_of (in_pathname, &result))
- result = xstrdup (in_pathname);
+ char *full_path = NULL;
+ if (source_full_path_of (in_pathname, &full_path))
+ result.reset (full_path);
+ else
+ result.reset (xstrdup (in_pathname));
if (fd != NULL)
*fd = -1;
}
if (fd != NULL)
*fd = -1;
}
}
/* Return the full pathname of a shared library file, or NULL if not
}
/* Return the full pathname of a shared library file, or NULL if not
- found. The returned pathname is malloc'ed and must be freed by
- the caller. If FD is non-NULL, *FD is set to either -1 or an open
- file handle for the shared library.
+ found. If FD is non-NULL, *FD is set to either -1 or an open file
+ handle for the shared library.
The search algorithm used is described in solib_find_1's comment
above. */
The search algorithm used is described in solib_find_1's comment
above. */
+gdb::unique_xmalloc_ptr<char>
solib_find (const char *in_pathname, int *fd)
{
const char *solib_symbols_extension
solib_find (const char *in_pathname, int *fd)
{
const char *solib_symbols_extension
it is used as file handle to open the file. Throws an error if the file
could not be opened. Handles both local and remote file access.
it is used as file handle to open the file. Throws an error if the file
could not be opened. Handles both local and remote file access.
- PATHNAME must be malloc'ed by the caller. It will be freed by this
- function. If unsuccessful, the FD will be closed (unless FD was
- -1). */
+ If unsuccessful, the FD will be closed (unless FD was -1). */
-solib_bfd_fopen (char *pathname, int fd)
+solib_bfd_fopen (const char *pathname, int fd)
{
gdb_bfd_ref_ptr abfd (gdb_bfd_open (pathname, gnutarget, fd));
{
gdb_bfd_ref_ptr abfd (gdb_bfd_open (pathname, gnutarget, fd));
if (abfd == NULL)
{
/* Arrange to free PATHNAME when the error is thrown. */
if (abfd == NULL)
{
/* Arrange to free PATHNAME when the error is thrown. */
- gdb::unique_xmalloc_ptr<char> free_pathname (pathname);
error (_("Could not open `%s' as an executable file: %s"),
pathname, bfd_errmsg (bfd_get_error ()));
}
error (_("Could not open `%s' as an executable file: %s"),
pathname, bfd_errmsg (bfd_get_error ()));
}
gdb_bfd_ref_ptr
solib_bfd_open (char *pathname)
{
gdb_bfd_ref_ptr
solib_bfd_open (char *pathname)
{
int found_file;
const struct bfd_arch_info *b;
/* Search for shared library file. */
int found_file;
const struct bfd_arch_info *b;
/* Search for shared library file. */
- found_pathname = solib_find (pathname, &found_file);
+ gdb::unique_xmalloc_ptr<char> found_pathname
+ = solib_find (pathname, &found_file);
if (found_pathname == NULL)
{
/* Return failure if the file could not be found, so that we can
if (found_pathname == NULL)
{
/* Return failure if the file could not be found, so that we can
}
/* Open bfd for shared library. */
}
/* Open bfd for shared library. */
- gdb_bfd_ref_ptr abfd (solib_bfd_fopen (found_pathname, found_file));
+ gdb_bfd_ref_ptr abfd (solib_bfd_fopen (found_pathname.get (), found_file));
/* Check bfd format. */
if (!bfd_check_format (abfd.get (), bfd_object))
/* Check bfd format. */
if (!bfd_check_format (abfd.get (), bfd_object))
struct so_list *master_so_list (void);
/* Find main executable binary file. */
struct so_list *master_so_list (void);
/* Find main executable binary file. */
-extern char *exec_file_find (const char *in_pathname, int *fd);
+extern gdb::unique_xmalloc_ptr<char> exec_file_find (const char *in_pathname,
+ int *fd);
/* Find shared library binary file. */
/* Find shared library binary file. */
-extern char *solib_find (const char *in_pathname, int *fd);
+extern gdb::unique_xmalloc_ptr<char> solib_find (const char *in_pathname,
+ int *fd);
/* Open BFD for shared library file. */
/* Open BFD for shared library file. */
-extern gdb_bfd_ref_ptr solib_bfd_fopen (char *pathname, int fd);
+extern gdb_bfd_ref_ptr solib_bfd_fopen (const char *pathname, int fd);
/* Find solib binary file and open it. */
extern gdb_bfd_ref_ptr solib_bfd_open (char *in_pathname);
/* Find solib binary file and open it. */
extern gdb_bfd_ref_ptr solib_bfd_open (char *in_pathname);