-/* 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.
solib_find_1 (const char *in_pathname, int *fd, int is_solib)
{
const struct target_so_ops *ops = solib_ops (target_gdbarch ());
int found_file = -1;
solib_find_1 (const char *in_pathname, int *fd, int is_solib)
{
const struct target_so_ops *ops = solib_ops (target_gdbarch ());
int found_file = -1;
int prefix_len, orig_prefix_len;
/* If the absolute prefix starts with "target:" but the filesystem
int prefix_len, orig_prefix_len;
/* If the absolute prefix starts with "target:" but the filesystem
- sysroot = savestring (sysroot, prefix_len);
- make_cleanup (xfree, sysroot);
+ sysroot_holder = std::string (sysroot, prefix_len);
+ sysroot = sysroot_holder.c_str ();
| target:some/dir | | /foo/bar.dll |
IOW, we don't need to add a separator if IN_PATHNAME already
| target:some/dir | | /foo/bar.dll |
IOW, we don't need to add a separator if IN_PATHNAME already
There's no need to check for drive spec explicitly, as we only
get here if IN_PATHNAME is considered an absolute path. */
need_dir_separator = !(IS_DIR_SEPARATOR (in_pathname[0])
|| strcmp (TARGET_SYSROOT_PREFIX, sysroot) == 0);
/* Cat the prefixed pathname together. */
There's no need to check for drive spec explicitly, as we only
get here if IN_PATHNAME is considered an absolute path. */
need_dir_separator = !(IS_DIR_SEPARATOR (in_pathname[0])
|| strcmp (TARGET_SYSROOT_PREFIX, sysroot) == 0);
/* Cat the prefixed pathname together. */
- temp_pathname = concat (sysroot,
- need_dir_separator ? SLASH_STRING : "",
- in_pathname, (char *) NULL);
+ temp_pathname.reset (concat (sysroot,
+ need_dir_separator ? SLASH_STRING : "",
+ in_pathname, (char *) NULL));
/* If the search in gdb_sysroot failed, and the path name has a
drive spec (e.g, c:/foo), try stripping ':' from the drive spec,
/* If the search in gdb_sysroot failed, and the path name has a
drive spec (e.g, c:/foo), try stripping ':' from the drive spec,
&& HAS_TARGET_DRIVE_SPEC (fskind, in_pathname))
{
int need_dir_separator = !IS_DIR_SEPARATOR (in_pathname[2]);
&& HAS_TARGET_DRIVE_SPEC (fskind, in_pathname))
{
int need_dir_separator = !IS_DIR_SEPARATOR (in_pathname[2]);
- temp_pathname = concat (sysroot,
- SLASH_STRING,
- drive,
- need_dir_separator ? SLASH_STRING : "",
- in_pathname + 2, (char *) NULL);
- xfree (drive);
+ temp_pathname.reset (concat (sysroot,
+ SLASH_STRING,
+ drive,
+ need_dir_separator ? SLASH_STRING : "",
+ in_pathname + 2, (char *) NULL));
- found_file = gdb_open_cloexec (temp_pathname, O_RDONLY | O_BINARY, 0);
+ found_file = gdb_open_cloexec (temp_pathname.get (),
+ O_RDONLY | O_BINARY, 0);
/* If the search in gdb_sysroot still failed, try fully
stripping the drive spec, and trying once more in the
sysroot before giving up.
c:/foo/bar.dll ==> /sysroot/foo/bar.dll. */
/* If the search in gdb_sysroot still failed, try fully
stripping the drive spec, and trying once more in the
sysroot before giving up.
c:/foo/bar.dll ==> /sysroot/foo/bar.dll. */
- temp_pathname = concat (sysroot,
- need_dir_separator ? SLASH_STRING : "",
- in_pathname + 2, (char *) NULL);
+ temp_pathname.reset (concat (sysroot,
+ need_dir_separator ? SLASH_STRING : "",
+ in_pathname + 2, (char *) NULL));
- found_file = gdb_open_cloexec (temp_pathname, O_RDONLY | O_BINARY, 0);
- if (found_file < 0)
- xfree (temp_pathname);
+ found_file = gdb_open_cloexec (temp_pathname.get (),
+ O_RDONLY | O_BINARY, 0);
/* We try to find the library in various ways. After each attempt,
either found_file >= 0 and temp_pathname is a malloc'd string, or
found_file < 0 and temp_pathname does not point to storage that
needs to be freed. */
if (found_file < 0)
/* We try to find the library in various ways. After each attempt,
either found_file >= 0 and temp_pathname is a malloc'd string, or
found_file < 0 and temp_pathname does not point to storage that
needs to be freed. */
if (found_file < 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
/* 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
- 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. */
filename. Not much more we can do...) */
if (!source_full_path_of (in_pathname, &result))
filename. Not much more we can do...) */
if (!source_full_path_of (in_pathname, &result))
- 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.
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.
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 ()));
}
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
solib_map_sections (struct so_list *so)
{
const struct target_so_ops *ops = solib_ops (target_gdbarch ());
solib_map_sections (struct so_list *so)
{
const struct target_so_ops *ops = solib_ops (target_gdbarch ());
- filename = tilde_expand (so->so_name);
- old_chain = make_cleanup (xfree, filename);
- gdb_bfd_ref_ptr abfd (ops->bfd_open (filename));
- do_cleanups (old_chain);
+ gdb::unique_xmalloc_ptr<char> filename (tilde_expand (so->so_name));
+ gdb_bfd_ref_ptr abfd (ops->bfd_open (filename.get ()));
- if (filename_cmp (objfile_name (so->objfile), so->so_name) == 0
- && so->objfile->addr_low == so->addr_low)
- break;
+ if (filename_cmp (objfile_name (objfile), so->so_name) == 0
+ && objfile->addr_low == so->addr_low)
+ {
+ so->objfile = objfile;
+ break;
+ }
{
exception_fprintf (gdb_stderr, e, _("Error while reading shared"
" library symbols for %s:\n"),
so->so_name);
}
{
exception_fprintf (gdb_stderr, e, _("Error while reading shared"
" library symbols for %s:\n"),
so->so_name);
}
/* We can reach here due to changing solib-search-path or the
sysroot, before having any inferior. */
/* We can reach here due to changing solib-search-path or the
sysroot, before having any inferior. */
have not opened a symbol file, we may be able to get its
symbols now! */
if (inf->attach_flag && symfile_objfile == NULL)
have not opened a symbol file, we may be able to get its
symbols now! */
if (inf->attach_flag && symfile_objfile == NULL)
- catch_errors (ops->open_symbol_file_object, &from_tty,
- "Error reading attached process's symbol file.\n",
- RETURN_MASK_ALL);
+ {
+ try
+ {
+ ops->open_symbol_file_object (from_tty);
+ }
+ catch (const gdb_exception &ex)
+ {
+ exception_fprintf (gdb_stderr, ex,
+ "Error reading attached "
+ "process's symbol file.\n");
+ }
+ }
{
/* Notify any observer that the shared object has been
unloaded before we remove it from GDB's tables. */
{
/* Notify any observer that the shared object has been
unloaded before we remove it from GDB's tables. */
*gdb_link = gdb->next;
/* Unless the user loaded it explicitly, free SO's objfile. */
if (gdb->objfile && ! (gdb->objfile->flags & OBJF_USERLOADED)
&& !solib_used (gdb))
*gdb_link = gdb->next;
/* Unless the user loaded it explicitly, free SO's objfile. */
if (gdb->objfile && ! (gdb->objfile->flags & OBJF_USERLOADED)
&& !solib_used (gdb))
{
exception_fprintf (gdb_stderr, e,
_("Error while mapping shared "
"library sections:\n"));
}
{
exception_fprintf (gdb_stderr, e,
_("Error while mapping shared "
"library sections:\n"));
}
/* Notify any observer that the shared object has been
loaded now that we've added it to GDB's tables. */
/* Notify any observer that the shared object has been
loaded now that we've added it to GDB's tables. */
{
/* The order of the two routines below is important: clear_solib notifies
the solib_unloaded observers, and some of these observers might need
{
/* The order of the two routines below is important: clear_solib notifies
the solib_unloaded observers, and some of these observers might need
/* Check for any newly added shared libraries if we're supposed to
be adding them automatically. Switch terminal for any messages
produced by breakpoint_re_set. */
/* Check for any newly added shared libraries if we're supposed to
be adding them automatically. Switch terminal for any messages
produced by breakpoint_re_set. */
if (print_symbol_loading_p (from_tty, 0, 0))
printf_unfiltered (_("Loading symbols for shared libraries.\n"));
for (so = so_list_head; so != NULL; so = so->next)
{
if (print_symbol_loading_p (from_tty, 0, 0))
printf_unfiltered (_("Loading symbols for shared libraries.\n"));
for (so = so_list_head; so != NULL; so = so->next)
{
int was_loaded = so->symbols_loaded;
symfile_add_flags add_flags = SYMFILE_DEFER_BP_RESET;
if (from_tty)
add_flags |= SYMFILE_VERBOSE;
int was_loaded = so->symbols_loaded;
symfile_add_flags add_flags = SYMFILE_DEFER_BP_RESET;
if (from_tty)
add_flags |= SYMFILE_VERBOSE;
- filename = tilde_expand (so->so_original_name);
- make_cleanup (xfree, filename);
- gdb_bfd_ref_ptr abfd (solib_bfd_open (filename));
+ gdb::unique_xmalloc_ptr<char> filename
+ (tilde_expand (so->so_original_name));
+ gdb_bfd_ref_ptr abfd (solib_bfd_open (filename.get ()));
/* If this shared library is no longer associated with its previous
symbol file, close that. */
/* If this shared library is no longer associated with its previous
symbol file, close that. */
{
exception_fprintf (gdb_stderr, e,
_("Error while mapping "
"shared library sections:\n"));
got_error = 1;
}
{
exception_fprintf (gdb_stderr, e,
_("Error while mapping "
"shared library sections:\n"));
got_error = 1;
}
if (!got_error
&& (auto_solib_add || was_loaded || libpthread_solib_p (so)))
solib_read_symbols (so, add_flags);
}
}
if (!got_error
&& (auto_solib_add || was_loaded || libpthread_solib_p (so)))
solib_read_symbols (so, add_flags);
}
}
if (ops->lookup_lib_global_symbol != NULL)
return ops->lookup_lib_global_symbol (objfile, name, domain);
if (ops->lookup_lib_global_symbol != NULL)
return ops->lookup_lib_global_symbol (objfile, name, domain);
- asymbol **symbol_table = (asymbol **) xmalloc (storage_needed);
- struct cleanup *back_to = make_cleanup (xfree, symbol_table);
+ gdb::def_vector<asymbol *> storage (storage_needed / sizeof (asymbol *));
+ asymbol **symbol_table = storage.data ();
unsigned int number_of_symbols =
bfd_canonicalize_symtab (abfd, symbol_table);
unsigned int number_of_symbols =
bfd_canonicalize_symtab (abfd, symbol_table);
if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
&& gdbarch_elf_make_msymbol_special_p (gdbarch))
{
if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
&& gdbarch_elf_make_msymbol_special_p (gdbarch))
{
SET_MSYMBOL_VALUE_ADDRESS (&msym, symaddr);
gdbarch_elf_make_msymbol_special (gdbarch, sym, &msym);
symaddr = MSYMBOL_VALUE_RAW_ADDRESS (&msym);
SET_MSYMBOL_VALUE_ADDRESS (&msym, symaddr);
gdbarch_elf_make_msymbol_special (gdbarch, sym, &msym);
symaddr = MSYMBOL_VALUE_RAW_ADDRESS (&msym);
- asymbol **symbol_table = (asymbol **) xmalloc (storage_needed);
- struct cleanup *back_to = make_cleanup (xfree, symbol_table);
+ gdb::def_vector<asymbol *> storage (storage_needed / sizeof (asymbol *));
+ asymbol **symbol_table = storage.data ();
unsigned int number_of_symbols =
bfd_canonicalize_dynamic_symtab (abfd, symbol_table);
unsigned int number_of_symbols =
bfd_canonicalize_dynamic_symtab (abfd, symbol_table);
add_com ("sharedlibrary", class_files, sharedlibrary_command,
_("Load shared object library symbols for files matching REGEXP."));
add_com ("sharedlibrary", class_files, sharedlibrary_command,
_("Load shared object library symbols for files matching REGEXP."));