gdb: remove symtab::objfile

Same idea as previous patch, but for symtab::objfile.  I find
it clearer without this wrapper, as it shows that the objfile is
common to all symtabs of a given compunit.  Otherwise, you could think
that each symtab (of a given compunit) can have a specific objfile.

Change-Id: Ifc0dbc7ec31a06eefa2787c921196949d5a6fcc6
This commit is contained in:
Simon Marchi 2022-03-29 16:14:36 -04:00
parent 44281e6c08
commit 3c86fae3d9
16 changed files with 41 additions and 45 deletions

View file

@ -11862,8 +11862,8 @@ is_known_support_routine (struct frame_info *frame)
re_comp (known_runtime_file_name_patterns[i]); re_comp (known_runtime_file_name_patterns[i]);
if (re_exec (lbasename (sal.symtab->filename))) if (re_exec (lbasename (sal.symtab->filename)))
return 1; return 1;
if (sal.symtab->objfile () != NULL if (sal.symtab->compunit ()->objfile () != NULL
&& re_exec (objfile_name (sal.symtab->objfile ()))) && re_exec (objfile_name (sal.symtab->compunit ()->objfile ())))
return 1; return 1;
} }

View file

@ -448,7 +448,7 @@ annotate_source_line (struct symtab *s, int line, int mid_statement,
return false; return false;
annotate_source (s->fullname, line, (int) (*offsets)[line - 1], annotate_source (s->fullname, line, (int) (*offsets)[line - 1],
mid_statement, s->objfile ()->arch (), mid_statement, s->compunit ()->objfile ()->arch (),
pc); pc);
/* Update the current symtab and line. */ /* Update the current symtab and line. */

View file

@ -7209,7 +7209,7 @@ get_sal_arch (struct symtab_and_line sal)
if (sal.section) if (sal.section)
return sal.section->objfile->arch (); return sal.section->objfile->arch ();
if (sal.symtab) if (sal.symtab)
return sal.symtab->objfile ()->arch (); return sal.symtab->compunit ()->objfile ()->arch ();
return NULL; return NULL;
} }
@ -9251,8 +9251,9 @@ resolve_sal_pc (struct symtab_and_line *sal)
sym = block_linkage_function (b); sym = block_linkage_function (b);
if (sym != NULL) if (sym != NULL)
{ {
fixup_symbol_section (sym, sal->symtab->objfile ()); fixup_symbol_section (sym, sal->symtab->compunit ()->objfile ());
sal->section = sym->obj_section (sal->symtab->objfile ()); sal->section
= sym->obj_section (sal->symtab->compunit ()->objfile ());
} }
else else
{ {
@ -14680,7 +14681,7 @@ void
breakpoint_free_objfile (struct objfile *objfile) breakpoint_free_objfile (struct objfile *objfile)
{ {
for (bp_location *loc : all_bp_locations ()) for (bp_location *loc : all_bp_locations ())
if (loc->symtab != NULL && loc->symtab->objfile () == objfile) if (loc->symtab != NULL && loc->symtab->compunit ()->objfile () == objfile)
loc->symtab = NULL; loc->symtab = NULL;
} }

View file

@ -1007,7 +1007,7 @@ edit_command (const char *arg, int from_tty)
error (_("No source file for address %s."), error (_("No source file for address %s."),
paddress (get_current_arch (), sal.pc)); paddress (get_current_arch (), sal.pc));
gdbarch = sal.symtab->objfile ()->arch (); gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
sym = find_pc_function (sal.pc); sym = find_pc_function (sal.pc);
if (sym) if (sym)
gdb_printf ("%s is in %s (%s:%d).\n", gdb_printf ("%s is in %s (%s:%d).\n",
@ -1346,7 +1346,7 @@ list_command (const char *arg, int from_tty)
error (_("No source file for address %s."), error (_("No source file for address %s."),
paddress (get_current_arch (), sal.pc)); paddress (get_current_arch (), sal.pc));
gdbarch = sal.symtab->objfile ()->arch (); gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
sym = find_pc_function (sal.pc); sym = find_pc_function (sal.pc);
if (sym) if (sym)
gdb_printf ("%s is in %s (%s:%d).\n", gdb_printf ("%s is in %s (%s:%d).\n",

View file

@ -109,7 +109,7 @@ stscm_eq_symtab_smob (const void *ap, const void *bp)
static htab_t static htab_t
stscm_objfile_symtab_map (struct symtab *symtab) stscm_objfile_symtab_map (struct symtab *symtab)
{ {
struct objfile *objfile = symtab->objfile (); struct objfile *objfile = symtab->compunit ()->objfile ();
htab_t htab = (htab_t) objfile_data (objfile, stscm_objfile_data_key); htab_t htab = (htab_t) objfile_data (objfile, stscm_objfile_data_key);
if (htab == NULL) if (htab == NULL)
@ -348,7 +348,7 @@ gdbscm_symtab_objfile (SCM self)
= stscm_get_valid_symtab_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); = stscm_get_valid_symtab_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
const struct symtab *symtab = st_smob->symtab; const struct symtab *symtab = st_smob->symtab;
return ofscm_scm_from_objfile (symtab->objfile ()); return ofscm_scm_from_objfile (symtab->compunit ()->objfile ());
} }
/* (symtab-global-block <gdb:symtab>) -> <gdb:block> /* (symtab-global-block <gdb:symtab>) -> <gdb:block>
@ -366,7 +366,7 @@ gdbscm_symtab_global_block (SCM self)
blockvector = symtab->compunit ()->blockvector (); blockvector = symtab->compunit ()->blockvector ();
block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK); block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
return bkscm_scm_from_block (block, symtab->objfile ()); return bkscm_scm_from_block (block, symtab->compunit ()->objfile ());
} }
/* (symtab-static-block <gdb:symtab>) -> <gdb:block> /* (symtab-static-block <gdb:symtab>) -> <gdb:block>
@ -384,7 +384,7 @@ gdbscm_symtab_static_block (SCM self)
blockvector = symtab->compunit ()->blockvector (); blockvector = symtab->compunit ()->blockvector ();
block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK); block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
return bkscm_scm_from_block (block, symtab->objfile ()); return bkscm_scm_from_block (block, symtab->compunit ()->objfile ());
} }
/* Administrivia for sal (symtab-and-line) smobs. */ /* Administrivia for sal (symtab-and-line) smobs. */

View file

@ -4245,10 +4245,10 @@ search_minsyms_for_name (struct collect_info *info,
{ {
set_current_program_space (symtab->pspace ()); set_current_program_space (symtab->pspace ());
iterate_over_minimal_symbols iterate_over_minimal_symbols
(symtab->objfile (), name, (symtab->compunit ()->objfile (), name,
[&] (struct minimal_symbol *msym) [&] (struct minimal_symbol *msym)
{ {
add_minsym (msym, symtab->objfile (), symtab, add_minsym (msym, symtab->compunit ()->objfile (), symtab,
info->state->list_mode, &minsyms); info->state->list_mode, &minsyms);
return false; return false;
}); });

View file

@ -50,7 +50,7 @@ mi_cmd_symbol_list_lines (const char *command, char **argv, int argc)
already sorted by increasing values in the symbol table, so no already sorted by increasing values in the symbol table, so no
need to perform any other sorting. */ need to perform any other sorting. */
gdbarch = s->objfile ()->arch (); gdbarch = s->compunit ()->objfile ()->arch ();
ui_out_emit_list list_emitter (uiout, "lines"); ui_out_emit_list list_emitter (uiout, "lines");
if (s->linetable () != NULL && s->linetable ()->nitems > 0) if (s->linetable () != NULL && s->linetable ()->nitems > 0)

View file

@ -591,7 +591,7 @@ objfile::~objfile ()
{ {
struct symtab_and_line cursal = get_current_source_symtab_and_line (); struct symtab_and_line cursal = get_current_source_symtab_and_line ();
if (cursal.symtab && cursal.symtab->objfile () == this) if (cursal.symtab && cursal.symtab->compunit ()->objfile () == this)
clear_current_source_symtab_and_line (); clear_current_source_symtab_and_line ();
} }

View file

@ -119,7 +119,7 @@ stpy_get_objfile (PyObject *self, void *closure)
STPY_REQUIRE_VALID (self, symtab); STPY_REQUIRE_VALID (self, symtab);
return objfile_to_objfile_object (symtab->objfile ()).release (); return objfile_to_objfile_object (symtab->compunit ()->objfile ()).release ();
} }
/* Getter function for symtab.producer. */ /* Getter function for symtab.producer. */
@ -183,7 +183,7 @@ stpy_global_block (PyObject *self, PyObject *args)
blockvector = symtab->compunit ()->blockvector (); blockvector = symtab->compunit ()->blockvector ();
block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK); block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
return block_to_block_object (block, symtab->objfile ()); return block_to_block_object (block, symtab->compunit ()->objfile ());
} }
/* Return the STATIC_BLOCK of the underlying symtab. */ /* Return the STATIC_BLOCK of the underlying symtab. */
@ -199,7 +199,7 @@ stpy_static_block (PyObject *self, PyObject *args)
blockvector = symtab->compunit ()->blockvector (); blockvector = symtab->compunit ()->blockvector ();
block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK); block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
return block_to_block_object (block, symtab->objfile ()); return block_to_block_object (block, symtab->compunit ()->objfile ());
} }
/* Implementation of gdb.Symtab.linetable (self) -> gdb.LineTable. /* Implementation of gdb.Symtab.linetable (self) -> gdb.LineTable.
@ -247,7 +247,7 @@ stpy_dealloc (PyObject *obj)
symtab->prev->next = symtab->next; symtab->prev->next = symtab->next;
else if (symtab->symtab) else if (symtab->symtab)
{ {
set_objfile_data (symtab->symtab->objfile (), set_objfile_data (symtab->symtab->compunit ()->objfile (),
stpy_objfile_data_key, symtab->next); stpy_objfile_data_key, symtab->next);
} }
if (symtab->next) if (symtab->next)
@ -330,7 +330,7 @@ salpy_dealloc (PyObject *self)
self_sal->prev->next = self_sal->next; self_sal->prev->next = self_sal->next;
else if (self_sal->symtab != Py_None) else if (self_sal->symtab != Py_None)
set_objfile_data set_objfile_data
(symtab_object_to_symtab (self_sal->symtab)->objfile (), (symtab_object_to_symtab (self_sal->symtab)->compunit ()->objfile (),
salpy_objfile_data_key, self_sal->next); salpy_objfile_data_key, self_sal->next);
if (self_sal->next) if (self_sal->next)
@ -378,12 +378,12 @@ set_sal (sal_object *sal_obj, struct symtab_and_line sal)
symtab *symtab = symtab_object_to_symtab (sal_obj->symtab); symtab *symtab = symtab_object_to_symtab (sal_obj->symtab);
sal_obj->next sal_obj->next
= ((sal_object *) objfile_data (symtab->objfile (), = ((sal_object *) objfile_data (symtab->compunit ()->objfile (),
salpy_objfile_data_key)); salpy_objfile_data_key));
if (sal_obj->next) if (sal_obj->next)
sal_obj->next->prev = sal_obj; sal_obj->next->prev = sal_obj;
set_objfile_data (symtab->objfile (), set_objfile_data (symtab->compunit ()->objfile (),
salpy_objfile_data_key, sal_obj); salpy_objfile_data_key, sal_obj);
} }
else else
@ -406,10 +406,12 @@ set_symtab (symtab_object *obj, struct symtab *symtab)
{ {
obj->next obj->next
= ((symtab_object *) = ((symtab_object *)
objfile_data (symtab->objfile (), stpy_objfile_data_key)); objfile_data (symtab->compunit ()->objfile (),
stpy_objfile_data_key));
if (obj->next) if (obj->next)
obj->next->prev = obj; obj->next->prev = obj;
set_objfile_data (symtab->objfile (), stpy_objfile_data_key, obj); set_objfile_data (symtab->compunit ()->objfile (),
stpy_objfile_data_key, obj);
} }
else else
obj->next = NULL; obj->next = NULL;

View file

@ -107,8 +107,9 @@ source_cache::get_plain_source_lines (struct symtab *s,
perror_with_name (symtab_to_filename_for_display (s)); perror_with_name (symtab_to_filename_for_display (s));
time_t mtime = 0; time_t mtime = 0;
if (s->objfile () != NULL && s->objfile ()->obfd != NULL) if (s->compunit ()->objfile () != NULL
mtime = s->objfile ()->mtime; && s->compunit ()->objfile ()->obfd != NULL)
mtime = s->compunit ()->objfile ()->mtime;
else if (current_program_space->exec_bfd ()) else if (current_program_space->exec_bfd ())
mtime = current_program_space->ebfd_mtime; mtime = current_program_space->ebfd_mtime;

View file

@ -1560,7 +1560,7 @@ info_line_command (const char *arg, int from_tty)
else if (sal.line > 0 else if (sal.line > 0
&& find_line_pc_range (sal, &start_pc, &end_pc)) && find_line_pc_range (sal, &start_pc, &end_pc))
{ {
struct gdbarch *gdbarch = sal.symtab->objfile ()->arch (); gdbarch *gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
if (start_pc == end_pc) if (start_pc == end_pc)
{ {

View file

@ -131,7 +131,7 @@ dump_objfile (struct objfile *objfile)
gdb_printf ("%s at %s", gdb_printf ("%s at %s",
symtab_to_filename_for_display (symtab), symtab_to_filename_for_display (symtab),
host_address_to_string (symtab)); host_address_to_string (symtab));
if (symtab->objfile () != objfile) if (symtab->compunit ()->objfile () != objfile)
gdb_printf (", NOT ON CHAIN!"); gdb_printf (", NOT ON CHAIN!");
gdb_printf ("\n"); gdb_printf ("\n");
} }
@ -234,7 +234,7 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
static void static void
dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile) dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
{ {
struct objfile *objfile = symtab->objfile (); struct objfile *objfile = symtab->compunit ()->objfile ();
struct gdbarch *gdbarch = objfile->arch (); struct gdbarch *gdbarch = objfile->arch ();
int i; int i;
struct mdict_iterator miter; struct mdict_iterator miter;

View file

@ -338,7 +338,7 @@ search_domain_name (enum search_domain e)
program_space * program_space *
symtab::pspace () const symtab::pspace () const
{ {
return this->objfile ()->pspace; return this->compunit ()->objfile ()->pspace;
} }
/* See symtab.h. */ /* See symtab.h. */
@ -3724,7 +3724,7 @@ find_function_start_sal_1 (CORE_ADDR func_addr, obj_section *section,
&& (sal.symtab->compunit ()->locations_valid () && (sal.symtab->compunit ()->locations_valid ()
|| sal.symtab->language () == language_asm)) || sal.symtab->language () == language_asm))
{ {
struct gdbarch *gdbarch = sal.symtab->objfile ()->arch (); struct gdbarch *gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
sal.pc = func_addr; sal.pc = func_addr;
if (gdbarch_skip_entrypoint_p (gdbarch)) if (gdbarch_skip_entrypoint_p (gdbarch))
@ -6593,7 +6593,7 @@ struct objfile *
symbol_objfile (const struct symbol *symbol) symbol_objfile (const struct symbol *symbol)
{ {
gdb_assert (symbol->is_objfile_owned ()); gdb_assert (symbol->is_objfile_owned ());
return symbol->owner.symtab->objfile (); return symbol->owner.symtab->compunit ()->objfile ();
} }
/* See symtab.h. */ /* See symtab.h. */
@ -6603,7 +6603,7 @@ symbol_arch (const struct symbol *symbol)
{ {
if (!symbol->is_objfile_owned ()) if (!symbol->is_objfile_owned ())
return symbol->owner.arch; return symbol->owner.arch;
return symbol->owner.symtab->objfile ()->arch (); return symbol->owner.symtab->compunit ()->objfile ()->arch ();
} }
/* See symtab.h. */ /* See symtab.h. */

View file

@ -1476,8 +1476,6 @@ struct symtab
m_language = language; m_language = language;
} }
struct objfile *objfile () const;
program_space *pspace () const; program_space *pspace () const;
/* Unordered chain of all filetabs in the compunit, with the exception /* Unordered chain of all filetabs in the compunit, with the exception
@ -1753,12 +1751,6 @@ struct compunit_symtab
using compunit_symtab_range = next_range<compunit_symtab>; using compunit_symtab_range = next_range<compunit_symtab>;
inline struct objfile *
symtab::objfile () const
{
return this->compunit ()->objfile ();
}
/* Return the language of CUST. */ /* Return the language of CUST. */
extern enum language compunit_language (const struct compunit_symtab *cust); extern enum language compunit_language (const struct compunit_symtab *cust);

View file

@ -70,7 +70,7 @@ tui_source_window::set_contents (struct gdbarch *arch,
m_fullname = make_unique_xstrdup (symtab_to_fullname (s)); m_fullname = make_unique_xstrdup (symtab_to_fullname (s));
cur_line = 0; cur_line = 0;
m_gdbarch = s->objfile ()->arch (); m_gdbarch = s->compunit ()->objfile ()->arch ();
m_start_line_or_addr.loa = LOA_LINE; m_start_line_or_addr.loa = LOA_LINE;
cur_line_no = m_start_line_or_addr.u.line_no = line_no; cur_line_no = m_start_line_or_addr.u.line_no = line_no;

View file

@ -199,7 +199,7 @@ tui_update_source_windows_with_line (struct symtab_and_line sal)
if (sal.symtab != nullptr) if (sal.symtab != nullptr)
{ {
find_line_pc (sal.symtab, sal.line, &sal.pc); find_line_pc (sal.symtab, sal.line, &sal.pc);
gdbarch = sal.symtab->objfile ()->arch (); gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
} }
for (struct tui_source_window_base *win_info : tui_source_windows ()) for (struct tui_source_window_base *win_info : tui_source_windows ())