#include "gdb_bfd.h"
#include "cli/cli-utils.h"
#include "common/byte-vector.h"
-#include "selftest.h"
+#include "common/pathstuff.h"
+#include "common/selftest.h"
#include "cli/cli-style.h"
+#include "common/forward-scope-exit.h"
#include <sys/types.h>
#include <fcntl.h>
void (*deprecated_pre_add_symbol_hook) (const char *);
void (*deprecated_post_add_symbol_hook) (void);
-static void clear_symtab_users_cleanup (void *ignore);
+using clear_symtab_users_cleanup
+ = FORWARD_SCOPE_EXIT (clear_symtab_users);
/* Global variables owned by this file. */
int readnow_symbol_files; /* Read full symbols immediately. */
symfile_add_flags add_flags)
{
section_addr_info local_addr;
- struct cleanup *old_chain;
const int mainline = add_flags & SYMFILE_MAINLINE;
objfile_set_sym_fns (objfile, find_sym_fns (objfile->obfd));
/* Make sure that partially constructed symbol tables will be cleaned up
if an error occurs during symbol reading. */
- old_chain = make_cleanup (null_cleanup, NULL);
+ gdb::optional<clear_symtab_users_cleanup> defer_clear_users;
+
std::unique_ptr<struct objfile> objfile_holder (objfile);
/* If ADDRS is NULL, put together a dummy address list.
{
/* We will modify the main symbol table, make sure that all its users
will be cleaned up if an error occurs during symbol reading. */
- make_cleanup (clear_symtab_users_cleanup, 0 /*ignore*/);
+ defer_clear_users.emplace ((symfile_add_flag) 0);
/* Since no error yet, throw away the old symbol table. */
/* Discard cleanups as symbol reading was successful. */
objfile_holder.release ();
- discard_cleanups (old_chain);
+ if (defer_clear_users)
+ defer_clear_users->release ();
}
/* Same as syms_from_objfile_1, but also initializes the objfile
const char *dir_notarget = target_prefix ? dir + strlen ("target:") : dir;
std::vector<gdb::unique_xmalloc_ptr<char>> debugdir_vec
= dirnames_to_char_ptr_vec (debug_file_directory);
+ gdb::unique_xmalloc_ptr<char> canon_sysroot = gdb_realpath (gdb_sysroot);
+
+ /* MS-Windows/MS-DOS don't allow colons in file names; we must
+ convert the drive letter into a one-letter directory, so that the
+ file name resulting from splicing below will be valid.
+
+ FIXME: The below only works when GDB runs on MS-Windows/MS-DOS.
+ There are various remote-debugging scenarios where such a
+ transformation of the drive letter might be required when GDB runs
+ on a Posix host, see
+
+ https://sourceware.org/ml/gdb-patches/2019-04/msg00605.html
+
+ If some of those scenarions need to be supported, we will need to
+ use a different condition for HAS_DRIVE_SPEC and a different macro
+ instead of STRIP_DRIVE_SPEC, which work on Posix systems as well. */
+ std::string drive;
+ if (HAS_DRIVE_SPEC (dir_notarget))
+ {
+ drive = dir_notarget[0];
+ dir_notarget = STRIP_DRIVE_SPEC (dir_notarget);
+ }
for (const gdb::unique_xmalloc_ptr<char> &debugdir : debugdir_vec)
{
debugfile = target_prefix ? "target:" : "";
debugfile += debugdir.get ();
debugfile += "/";
+ debugfile += drive;
debugfile += dir_notarget;
debugfile += debuglink;
if (separate_debug_file_exists (debugfile, crc32, objfile))
return debugfile;
- /* If the file is in the sysroot, try using its base path in the
- global debugfile directory. */
- if (canon_dir != NULL
- && filename_ncmp (canon_dir, gdb_sysroot,
- strlen (gdb_sysroot)) == 0
- && IS_DIR_SEPARATOR (canon_dir[strlen (gdb_sysroot)]))
+ const char *base_path = NULL;
+ if (canon_dir != NULL)
+ {
+ if (canon_sysroot.get () != NULL)
+ base_path = child_path (canon_sysroot.get (), canon_dir);
+ else
+ base_path = child_path (gdb_sysroot, canon_dir);
+ }
+ if (base_path != NULL)
{
+ /* If the file is in the sysroot, try using its base path in
+ the global debugfile directory. */
+ debugfile = target_prefix ? "target:" : "";
+ debugfile += debugdir.get ();
+ debugfile += "/";
+ debugfile += base_path;
+ debugfile += "/";
+ debugfile += debuglink;
+
+ if (separate_debug_file_exists (debugfile, crc32, objfile))
+ return debugfile;
+
+ /* If the file is in the sysroot, try using its base path in
+ the sysroot's global debugfile directory. */
debugfile = target_prefix ? "target:" : "";
+ debugfile += gdb_sysroot;
debugfile += debugdir.get ();
- debugfile += (canon_dir + strlen (gdb_sysroot));
+ debugfile += "/";
+ debugfile += base_path;
debugfile += "/";
debugfile += debuglink;
if (separate_debug_file_exists (debugfile, crc32, objfile))
return debugfile;
}
+
}
return std::string ();
unsigned long write_count,
std::chrono::steady_clock::duration d);
+/* See symfile.h. */
+
void
generic_load (const char *args, int from_tty)
{
/* This function allows the addition of incrementally linked object files.
It does not modify any state in the target, only in the debugger. */
-/* Note: ezannoni 2000-04-13 This function/command used to have a
- special case syntax for the rombug target (Rombug is the boot
- monitor for Microware's OS-9 / OS-9000, see remote-os9k.c). In the
- rombug case, the user doesn't need to supply a text address,
- instead a call to target_link() (in target.c) would supply the
- value to use. We are now discontinuing this type of ad hoc syntax. */
static void
add_symbol_file_command (const char *args, int from_tty)
objf = symbol_file_add (filename.get (), add_flags, §ion_addrs,
flags);
+ if (!objfile_has_symbols (objf) && objf->per_bfd->minimal_symbol_count <= 0)
+ warning (_("newly-added symbol file \"%s\" does not provide any symbols"),
+ filename.get ());
if (seen_offset)
set_objfile_default_section_offset (objf, section_addrs, offset);
addr = parse_and_eval_address (argv[1]);
- for (objfile *objfile : all_objfiles (current_program_space))
+ for (objfile *objfile : current_program_space->objfiles ())
{
if ((objfile->flags & OBJF_USERLOADED) != 0
&& (objfile->flags & OBJF_SHARED) != 0
gdb::unique_xmalloc_ptr<char> filename (tilde_expand (argv[0]));
- for (objfile *objfile : all_objfiles (current_program_space))
+ for (objfile *objfile : current_program_space->objfiles ())
{
if ((objfile->flags & OBJF_USERLOADED) != 0
&& (objfile->flags & OBJF_SHARED) != 0
void
reread_symbols (void)
{
- struct objfile *objfile;
long new_modtime;
struct stat new_statbuf;
int res;
std::vector<struct objfile *> new_objfiles;
- /* With the addition of shared libraries, this should be modified,
- the load time should be saved in the partial symbol tables, since
- different tables may come from different source files. FIXME.
- This routine should then walk down each partial symbol table
- and see if the symbol table that it originates from has been changed. */
-
- for (objfile = object_files; objfile; objfile = objfile->next)
+ for (objfile *objfile : current_program_space->objfiles ())
{
if (objfile->obfd == NULL)
continue;
new_modtime = new_statbuf.st_mtime;
if (new_modtime != objfile->mtime)
{
- struct cleanup *old_cleanups;
struct section_offsets *offsets;
int num_offsets;
std::unique_ptr<struct objfile> objfile_holder (objfile);
/* We need to do this whenever any symbols go away. */
- old_cleanups = make_cleanup (clear_symtab_users_cleanup, 0 /*ignore*/);
+ clear_symtab_users_cleanup defer_clear_users (0);
if (exec_bfd != NULL
&& filename_cmp (bfd_get_filename (objfile->obfd),
memcpy (offsets, objfile->section_offsets,
SIZEOF_N_SECTION_OFFSETS (num_offsets));
- /* FIXME: Do we have to free a whole linked list, or is this
- enough? */
- objfile->partial_symtabs->global_psymbols.clear ();
- objfile->partial_symtabs->static_psymbols.clear ();
-
- /* Free the obstacks for non-reusable objfiles. */
- psymbol_bcache_free (objfile->partial_symtabs->psymbol_cache);
- objfile->partial_symtabs->psymbol_cache = psymbol_bcache_init ();
+ objfile->reset_psymtabs ();
/* NB: after this call to obstack_free, objfiles_changed
will need to be called (see discussion below). */
obstack_free (&objfile->objfile_obstack, 0);
objfile->sections = NULL;
objfile->compunit_symtabs = NULL;
- objfile->partial_symtabs->psymtabs = NULL;
- objfile->partial_symtabs->psymtabs_addrmap = NULL;
- objfile->partial_symtabs->free_psymtabs = NULL;
objfile->template_symbols = NULL;
- objfile->static_links = NULL;
+ objfile->static_links.reset (nullptr);
/* obstack_init also initializes the obstack so it is
empty. We could use obstack_specify_allocation but
objfile_set_sym_fns (objfile, find_sym_fns (objfile->obfd));
build_objfile_section_table (objfile);
- terminate_minimal_symbol_table (objfile);
/* We use the same section offsets as from last time. I'm not
sure whether that is always correct for shared libraries. */
/* Discard cleanups as symbol reading was successful. */
objfile_holder.release ();
- discard_cleanups (old_cleanups);
+ defer_clear_users.release ();
/* If the mtime has changed between the time we set new_modtime
and now, we *want* this to be out of date, so don't call stat
= OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symtab);
symtab->filename
- = (const char *) bcache (filename, strlen (filename) + 1,
- objfile->per_bfd->filename_cache);
+ = ((const char *) objfile->per_bfd->filename_cache.insert
+ (filename, strlen (filename) + 1));
symtab->fullname = NULL;
symtab->language = deduce_language_from_filename (filename);
clear_pc_function_cache ();
gdb::observers::new_objfile.notify (NULL);
- /* Clear globals which might have pointed into a removed objfile.
- FIXME: It's not clear which of these are supposed to persist
- between expressions and which ought to be reset each time. */
- expression_context_block = NULL;
- innermost_block.reset ();
-
/* Varobj may refer to old symbols, perform a cleanup. */
varobj_invalidate ();
if ((add_flags & SYMFILE_DEFER_BP_RESET) == 0)
breakpoint_re_set ();
}
-
-static void
-clear_symtab_users_cleanup (void *ignore)
-{
- clear_symtab_users (0);
-}
\f
/* OVERLAYS:
The following code implements an abstraction for debugging overlay sections.
{
struct obj_section *sect;
- for (objfile *objfile : all_objfiles (current_program_space))
+ for (objfile *objfile : current_program_space->objfiles ())
ALL_OBJFILE_OSECTIONS (objfile, sect)
if (section_is_overlay (sect))
sect->ovly_mapped = -1;
if (overlay_debugging)
{
- for (objfile *objfile : all_objfiles (current_program_space))
+ for (objfile *objfile : current_program_space->objfiles ())
ALL_OBJFILE_OSECTIONS (objfile, osect)
if (section_is_overlay (osect))
{
if (overlay_debugging)
{
- for (objfile *objfile : all_objfiles (current_program_space))
+ for (objfile *objfile : current_program_space->objfiles ())
ALL_OBJFILE_OSECTIONS (objfile, osect)
if (pc_in_mapped_range (pc, osect) && section_is_mapped (osect))
return osect;
if (overlay_debugging)
{
- for (objfile *objfile : all_objfiles (current_program_space))
+ for (objfile *objfile : current_program_space->objfiles ())
ALL_OBJFILE_OSECTIONS (objfile, osect)
if (section_is_mapped (osect))
{
error (_("Argument required: name of an overlay section"));
/* First, find a section matching the user supplied argument. */
- for (objfile *obj_file : all_objfiles (current_program_space))
+ for (objfile *obj_file : current_program_space->objfiles ())
ALL_OBJFILE_OSECTIONS (obj_file, sec)
if (!strcmp (bfd_section_name (obj_file->obfd, sec->the_bfd_section),
args))
/* Next, make a pass and unmap any sections that are
overlapped by this new section: */
- for (objfile *objfile2 : all_objfiles (current_program_space))
+ for (objfile *objfile2 : current_program_space->objfiles ())
ALL_OBJFILE_OSECTIONS (objfile2, sec2)
if (sec2->ovly_mapped && sec != sec2 && sections_overlap (sec,
sec2))
error (_("Argument required: name of an overlay section"));
/* First, find a section matching the user supplied argument. */
- for (objfile *objfile : all_objfiles (current_program_space))
+ for (objfile *objfile : current_program_space->objfiles ())
ALL_OBJFILE_OSECTIONS (objfile, sec)
if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args))
{
return;
/* Now may as well update all sections, even if only one was requested. */
- for (objfile *objfile : all_objfiles (current_program_space))
+ for (objfile *objfile : current_program_space->objfiles ())
ALL_OBJFILE_OSECTIONS (objfile, osect)
if (section_is_overlay (osect))
{
gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
enum search_domain kind)
{
- for (objfile *objfile : all_objfiles (current_program_space))
+ for (objfile *objfile : current_program_space->objfiles ())
{
if (objfile->sf)
objfile->sf->qf->expand_symtabs_matching (objfile, file_matcher,
map_symbol_filenames (symbol_filename_ftype *fun, void *data,
int need_fullname)
{
- for (objfile *objfile : all_objfiles (current_program_space))
+ for (objfile *objfile : current_program_space->objfiles ())
{
if (objfile->sf)
objfile->sf->qf->map_symbol_filenames (objfile, fun, data,
SELF_CHECK (lang == language_unknown);
/* Test adding a new extension using the CLI command. */
- gdb::unique_xmalloc_ptr<char> args_holder (xstrdup (".hello rust"));
+ auto args_holder = make_unique_xstrdup (".hello rust");
ext_args = args_holder.get ();
set_ext_lang_command (NULL, 1, NULL);