gdb: remove SYMTAB_COMPUNIT macro, add getter/setter

Add a getter and a setter for a symtab's compunit_symtab.  Remove the
corresponding macro and adjust all callers.

For brevity, I chose the name "compunit" instead of "compunit_symtab"
the the field, getter and setter names.  Since we are already in symtab
context, the _symtab suffix seems redundant.

Change-Id: I4b9b731c96e3594f7733e75af1e3d01bc0e4fe92
This commit is contained in:
Simon Marchi 2021-11-19 22:49:01 -05:00 committed by Simon Marchi
parent 10cc645b6a
commit c615965258
13 changed files with 37 additions and 27 deletions

View file

@ -2474,8 +2474,8 @@ amd64_skip_xmm_prologue (CORE_ADDR pc, CORE_ADDR start_pc)
start_pc_sal = find_pc_sect_line (start_pc, NULL, 0); start_pc_sal = find_pc_sect_line (start_pc, NULL, 0);
if (start_pc_sal.symtab == NULL if (start_pc_sal.symtab == NULL
|| producer_is_gcc_ge_4 (SYMTAB_COMPUNIT || producer_is_gcc_ge_4 (start_pc_sal.symtab->compunit ()
(start_pc_sal.symtab)->producer ()) < 6 ->producer ()) < 6
|| start_pc_sal.pc != start_pc || pc >= start_pc_sal.end) || start_pc_sal.pc != start_pc || pc >= start_pc_sal.end)
return pc; return pc;

View file

@ -9230,7 +9230,7 @@ resolve_sal_pc (struct symtab_and_line *sal)
struct symbol *sym; struct symbol *sym;
bv = blockvector_for_pc_sect (sal->pc, 0, &b, bv = blockvector_for_pc_sect (sal->pc, 0, &b,
SYMTAB_COMPUNIT (sal->symtab)); sal->symtab->compunit ());
if (bv != NULL) if (bv != NULL)
{ {
sym = block_linkage_function (b); sym = block_linkage_function (b);

View file

@ -43,7 +43,8 @@ sal_macro_scope (struct symtab_and_line sal)
if (sal.symtab == NULL) if (sal.symtab == NULL)
return NULL; return NULL;
cust = SYMTAB_COMPUNIT (sal.symtab);
cust = sal.symtab->compunit ();
if (cust->macro_table () == NULL) if (cust->macro_table () == NULL)
return NULL; return NULL;

View file

@ -4502,7 +4502,7 @@ add_block (struct block *b, struct symtab *s)
+ BLOCKVECTOR_NBLOCKS (bv) + BLOCKVECTOR_NBLOCKS (bv)
* sizeof (bv->block))); * sizeof (bv->block)));
if (bv != SYMTAB_BLOCKVECTOR (s)) if (bv != SYMTAB_BLOCKVECTOR (s))
SYMTAB_COMPUNIT (s)->set_blockvector (bv); s->compunit ()->set_blockvector (bv);
BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b; BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
} }

View file

@ -59,7 +59,7 @@ mi_cmd_file_list_exec_source_file (const char *command, char **argv, int argc)
uiout->field_string ("fullname", symtab_to_fullname (st.symtab)); uiout->field_string ("fullname", symtab_to_fullname (st.symtab));
uiout->field_signed ("macro-info", uiout->field_signed ("macro-info",
SYMTAB_COMPUNIT (st.symtab)->macro_table () != NULL); st.symtab->compunit ()->macro_table () != NULL);
} }
/* Implement -file-list-exec-source-files command. */ /* Implement -file-list-exec-source-files command. */

View file

@ -471,7 +471,7 @@ or1k_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
{ {
struct symtab_and_line prologue_sal = find_pc_line (start_pc, 0); struct symtab_and_line prologue_sal = find_pc_line (start_pc, 0);
struct compunit_symtab *compunit struct compunit_symtab *compunit
= SYMTAB_COMPUNIT (prologue_sal.symtab); = prologue_sal.symtab->compunit ();
const char *debug_format = compunit->debugformat (); const char *debug_format = compunit->debugformat ();
if ((NULL != debug_format) if ((NULL != debug_format)

View file

@ -131,7 +131,7 @@ stpy_get_producer (PyObject *self, void *closure)
struct compunit_symtab *cust; struct compunit_symtab *cust;
STPY_REQUIRE_VALID (self, symtab); STPY_REQUIRE_VALID (self, symtab);
cust = SYMTAB_COMPUNIT (symtab); cust = symtab->compunit ();
if (cust->producer () != nullptr) if (cust->producer () != nullptr)
{ {
const char *producer = cust->producer (); const char *producer = cust->producer ();

View file

@ -711,7 +711,7 @@ info_source_command (const char *ignore, int from_tty)
return; return;
} }
cust = SYMTAB_COMPUNIT (s); cust = s->compunit ();
printf_filtered (_("Current source file is %s\n"), s->filename); printf_filtered (_("Current source file is %s\n"), s->filename);
if (SYMTAB_DIRNAME (s) != NULL) if (SYMTAB_DIRNAME (s) != NULL)
printf_filtered (_("Compilation directory is %s\n"), SYMTAB_DIRNAME (s)); printf_filtered (_("Compilation directory is %s\n"), SYMTAB_DIRNAME (s));
@ -1184,9 +1184,9 @@ open_source_file (struct symtab *s)
if (fd.get () < 0) if (fd.get () < 0)
{ {
if (SYMTAB_COMPUNIT (s) != nullptr) if (s->compunit () != nullptr)
{ {
const objfile *ofp = SYMTAB_COMPUNIT (s)->objfile (); const objfile *ofp = s->compunit ()->objfile ();
std::string srcpath; std::string srcpath;
if (IS_ABSOLUTE_PATH (s->filename)) if (IS_ABSOLUTE_PATH (s->filename))

View file

@ -2807,7 +2807,7 @@ allocate_symtab (struct compunit_symtab *cust, const char *filename)
cust->add_filetab (symtab); cust->add_filetab (symtab);
/* Backlink to the containing compunit symtab. */ /* Backlink to the containing compunit symtab. */
symtab->compunit_symtab = cust; symtab->set_compunit (cust);
return symtab; return symtab;
} }

View file

@ -329,7 +329,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
} }
else else
{ {
compunit_symtab *compunit = SYMTAB_COMPUNIT (symtab); compunit_symtab *compunit = symtab->compunit ();
const char *compunit_filename const char *compunit_filename
= symtab_to_filename_for_display (compunit->primary_filetab ()); = symtab_to_filename_for_display (compunit->primary_filetab ());
@ -342,7 +342,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
compunit_symtabs included by this one. */ compunit_symtabs included by this one. */
if (is_main_symtab_of_compunit_symtab (symtab)) if (is_main_symtab_of_compunit_symtab (symtab))
{ {
struct compunit_symtab *cust = SYMTAB_COMPUNIT (symtab); struct compunit_symtab *cust = symtab->compunit ();
if (cust->user != nullptr) if (cust->user != nullptr)
{ {
@ -956,14 +956,14 @@ maintenance_print_one_line_table (struct symtab *symtab, void *data)
struct linetable *linetable; struct linetable *linetable;
struct objfile *objfile; struct objfile *objfile;
objfile = symtab->compunit_symtab->objfile (); objfile = symtab->compunit ()->objfile ();
printf_filtered (_("objfile: %ps ((struct objfile *) %s)\n"), printf_filtered (_("objfile: %ps ((struct objfile *) %s)\n"),
styled_string (file_name_style.style (), styled_string (file_name_style.style (),
objfile_name (objfile)), objfile_name (objfile)),
host_address_to_string (objfile)); host_address_to_string (objfile));
printf_filtered (_("compunit_symtab: %s ((struct compunit_symtab *) %s)\n"), printf_filtered (_("compunit_symtab: %s ((struct compunit_symtab *) %s)\n"),
symtab->compunit_symtab->name, symtab->compunit ()->name,
host_address_to_string (symtab->compunit_symtab)); host_address_to_string (symtab->compunit ()));
printf_filtered (_("symtab: %ps ((struct symtab *) %s)\n"), printf_filtered (_("symtab: %ps ((struct symtab *) %s)\n"),
styled_string (file_name_style.style (), styled_string (file_name_style.style (),
symtab_to_fullname (symtab)), symtab_to_fullname (symtab)),

View file

@ -3709,7 +3709,7 @@ find_function_start_sal_1 (CORE_ADDR func_addr, obj_section *section,
symtab_and_line sal = find_pc_sect_line (func_addr, section, 0); symtab_and_line sal = find_pc_sect_line (func_addr, section, 0);
if (funfirstline && sal.symtab != NULL if (funfirstline && sal.symtab != NULL
&& (SYMTAB_COMPUNIT (sal.symtab)->locations_valid () && (sal.symtab->compunit ()->locations_valid ()
|| SYMTAB_LANGUAGE (sal.symtab) == language_asm)) || SYMTAB_LANGUAGE (sal.symtab) == language_asm))
{ {
struct gdbarch *gdbarch = SYMTAB_OBJFILE (sal.symtab)->arch (); struct gdbarch *gdbarch = SYMTAB_OBJFILE (sal.symtab)->arch ();
@ -3885,7 +3885,7 @@ skip_prologue_sal (struct symtab_and_line *sal)
have proven the CU (Compilation Unit) supports it. sal->SYMTAB does not have proven the CU (Compilation Unit) supports it. sal->SYMTAB does not
have to be set by the caller so we use SYM instead. */ have to be set by the caller so we use SYM instead. */
if (sym != NULL if (sym != NULL
&& SYMTAB_COMPUNIT (symbol_symtab (sym))->locations_valid ()) && symbol_symtab (sym)->compunit ()->locations_valid ())
force_skip = 0; force_skip = 0;
saved_pc = pc; saved_pc = pc;
@ -6095,7 +6095,7 @@ collect_file_symbol_completion_matches (completion_tracker &tracker,
for symbols which match. */ for symbols which match. */
iterate_over_symtabs (srcfile, [&] (symtab *s) iterate_over_symtabs (srcfile, [&] (symtab *s)
{ {
add_symtab_completions (SYMTAB_COMPUNIT (s), add_symtab_completions (s->compunit (),
tracker, mode, lookup_name, tracker, mode, lookup_name,
sym_text, word, TYPE_CODE_UNDEF); sym_text, word, TYPE_CODE_UNDEF);
return false; return false;

View file

@ -1373,6 +1373,16 @@ typedef std::vector<CORE_ADDR> section_offsets;
struct symtab struct symtab
{ {
struct compunit_symtab *compunit () const
{
return m_compunit;
}
void set_compunit (struct compunit_symtab *compunit)
{
m_compunit = compunit;
}
/* Unordered chain of all filetabs in the compunit, with the exception /* Unordered chain of all filetabs in the compunit, with the exception
that the "main" source file is the first entry in the list. */ that the "main" source file is the first entry in the list. */
@ -1380,7 +1390,7 @@ struct symtab
/* Backlink to containing compunit symtab. */ /* Backlink to containing compunit symtab. */
struct compunit_symtab *compunit_symtab; struct compunit_symtab *m_compunit;
/* Table mapping core addresses to line numbers for this file. /* Table mapping core addresses to line numbers for this file.
Can be NULL if none. Never shared between different symtabs. */ Can be NULL if none. Never shared between different symtabs. */
@ -1405,15 +1415,14 @@ struct symtab
using symtab_range = next_range<symtab>; using symtab_range = next_range<symtab>;
#define SYMTAB_COMPUNIT(symtab) ((symtab)->compunit_symtab)
#define SYMTAB_LINETABLE(symtab) ((symtab)->linetable) #define SYMTAB_LINETABLE(symtab) ((symtab)->linetable)
#define SYMTAB_LANGUAGE(symtab) ((symtab)->language) #define SYMTAB_LANGUAGE(symtab) ((symtab)->language)
#define SYMTAB_BLOCKVECTOR(symtab) \ #define SYMTAB_BLOCKVECTOR(symtab) \
(SYMTAB_COMPUNIT (symtab)->blockvector ()) (symtab->compunit ()->blockvector ())
#define SYMTAB_OBJFILE(symtab) \ #define SYMTAB_OBJFILE(symtab) \
(SYMTAB_COMPUNIT (symtab)->objfile ()) (symtab->compunit ()->objfile ())
#define SYMTAB_PSPACE(symtab) (SYMTAB_OBJFILE (symtab)->pspace) #define SYMTAB_PSPACE(symtab) (SYMTAB_OBJFILE (symtab)->pspace)
#define SYMTAB_DIRNAME(symtab) (SYMTAB_COMPUNIT (symtab)->dirname ()) #define SYMTAB_DIRNAME(symtab) ((symtab)->compunit ()->dirname ())
/* Compunit symtabs contain the actual "symbol table", aka blockvector, as well /* Compunit symtabs contain the actual "symbol table", aka blockvector, as well
as the list of all source files (what gdb has historically associated with as the list of all source files (what gdb has historically associated with
@ -1665,7 +1674,7 @@ extern enum language compunit_language (const struct compunit_symtab *cust);
static inline bool static inline bool
is_main_symtab_of_compunit_symtab (struct symtab *symtab) is_main_symtab_of_compunit_symtab (struct symtab *symtab)
{ {
return symtab == SYMTAB_COMPUNIT (symtab)->primary_filetab (); return symtab == symtab->compunit ()->primary_filetab ();
} }

View file

@ -495,7 +495,7 @@ z80_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
if (prologue_end != 0) if (prologue_end != 0)
{ {
struct symtab_and_line prologue_sal = find_pc_line (func_addr, 0); struct symtab_and_line prologue_sal = find_pc_line (func_addr, 0);
struct compunit_symtab *compunit = SYMTAB_COMPUNIT (prologue_sal.symtab); struct compunit_symtab *compunit = prologue_sal.symtab->compunit ();
const char *debug_format = compunit->debugformat (); const char *debug_format = compunit->debugformat ();
if (debug_format != NULL && if (debug_format != NULL &&