gdb: remove SYMTAB_LINETABLE macro, add getter/setter

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

Change-Id: I159183fc0ccd8e18ab937b3c2f09ef2244ec6e9c
This commit is contained in:
Simon Marchi
2021-11-20 08:40:12 -05:00
committed by Simon Marchi
parent c615965258
commit 5b6074611e
11 changed files with 64 additions and 57 deletions

View File

@ -977,15 +977,13 @@ buildsym_compunit::end_symtab_with_blockvector (struct block *static_block,
if (subfile->line_vector) if (subfile->line_vector)
{ {
/* Reallocate the line table on the symbol obstack. */ /* Reallocate the line table on the symbol obstack. */
SYMTAB_LINETABLE (symtab) = (struct linetable *) symtab->set_linetable
obstack_alloc (&m_objfile->objfile_obstack, linetablesize); ((struct linetable *)
memcpy (SYMTAB_LINETABLE (symtab), subfile->line_vector, obstack_alloc (&m_objfile->objfile_obstack, linetablesize));
linetablesize); memcpy (symtab->linetable (), subfile->line_vector, linetablesize);
} }
else else
{ symtab->set_linetable (nullptr);
SYMTAB_LINETABLE (symtab) = NULL;
}
/* Use whatever language we have been using for this /* Use whatever language we have been using for this
subfile, not the one that was deduced in allocate_symtab subfile, not the one that was deduced in allocate_symtab

View File

@ -393,10 +393,10 @@ do_mixed_source_and_assembly_deprecated
int num_displayed = 0; int num_displayed = 0;
print_source_lines_flags psl_flags = 0; print_source_lines_flags psl_flags = 0;
gdb_assert (symtab != NULL && SYMTAB_LINETABLE (symtab) != NULL); gdb_assert (symtab != nullptr && symtab->linetable () != nullptr);
nlines = SYMTAB_LINETABLE (symtab)->nitems; nlines = symtab->linetable ()->nitems;
le = SYMTAB_LINETABLE (symtab)->item; le = symtab->linetable ()->item;
if (flags & DISASSEMBLY_FILENAME) if (flags & DISASSEMBLY_FILENAME)
psl_flags |= PRINT_SOURCE_LINES_FILENAME; psl_flags |= PRINT_SOURCE_LINES_FILENAME;
@ -535,7 +535,7 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch,
struct symtab *last_symtab; struct symtab *last_symtab;
int last_line; int last_line;
gdb_assert (main_symtab != NULL && SYMTAB_LINETABLE (main_symtab) != NULL); gdb_assert (main_symtab != NULL && main_symtab->linetable () != NULL);
/* First pass: collect the list of all source files and lines. /* First pass: collect the list of all source files and lines.
We do this so that we can only print lines containing code once. We do this so that we can only print lines containing code once.
@ -553,8 +553,8 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch,
line after the opening brace. We still want to print this opening brace. line after the opening brace. We still want to print this opening brace.
first_le is used to implement this. */ first_le is used to implement this. */
nlines = SYMTAB_LINETABLE (main_symtab)->nitems; nlines = main_symtab->linetable ()->nitems;
le = SYMTAB_LINETABLE (main_symtab)->item; le = main_symtab->linetable ()->item;
first_le = NULL; first_le = NULL;
/* Skip all the preceding functions. */ /* Skip all the preceding functions. */
@ -850,8 +850,8 @@ gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
/* Assume symtab is valid for whole PC range. */ /* Assume symtab is valid for whole PC range. */
symtab = find_pc_line_symtab (low); symtab = find_pc_line_symtab (low);
if (symtab != NULL && SYMTAB_LINETABLE (symtab) != NULL) if (symtab != NULL && symtab->linetable () != NULL)
nlines = SYMTAB_LINETABLE (symtab)->nitems; nlines = symtab->linetable ()->nitems;
if (!(flags & (DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_SOURCE)) if (!(flags & (DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_SOURCE))
|| nlines <= 0) || nlines <= 0)

View File

@ -521,10 +521,9 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
size_t size = ((stab->linetable->nitems - 1) size_t size = ((stab->linetable->nitems - 1)
* sizeof (struct linetable_entry) * sizeof (struct linetable_entry)
+ sizeof (struct linetable)); + sizeof (struct linetable));
SYMTAB_LINETABLE (filetab) filetab->set_linetable ((struct linetable *)
= (struct linetable *) obstack_alloc (&objfile->objfile_obstack, size); obstack_alloc (&objfile->objfile_obstack, size));
memcpy (SYMTAB_LINETABLE (filetab), memcpy (filetab->linetable (), stab->linetable.get (), size);
stab->linetable.get (), size);
} }
blockvector_size = (sizeof (struct blockvector) blockvector_size = (sizeof (struct blockvector)

View File

@ -4089,7 +4089,7 @@ mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
psymtab_language = cust->primary_filetab ()->language; psymtab_language = cust->primary_filetab ()->language;
lines = SYMTAB_LINETABLE (cust->primary_filetab ()); lines = cust->primary_filetab ()->linetable ();
/* Get a new lexical context. */ /* Get a new lexical context. */
@ -4173,11 +4173,11 @@ mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
size = lines->nitems; size = lines->nitems;
if (size > 1) if (size > 1)
--size; --size;
SYMTAB_LINETABLE (cust->primary_filetab ()) cust->primary_filetab ()->set_linetable
= ((struct linetable *) ((struct linetable *)
obstack_copy (&mdebugread_objfile->objfile_obstack, obstack_copy (&mdebugread_objfile->objfile_obstack,
lines, (sizeof (struct linetable) lines, (sizeof (struct linetable)
+ size * sizeof (lines->item)))); + size * sizeof (lines->item))));
xfree (lines); xfree (lines);
/* .. and our share of externals. /* .. and our share of externals.
@ -4623,7 +4623,7 @@ new_symtab (const char *name, int maxlines, struct objfile *objfile)
add_compunit_symtab_to_objfile (cust); add_compunit_symtab_to_objfile (cust);
symtab = allocate_symtab (cust, name); symtab = allocate_symtab (cust, name);
SYMTAB_LINETABLE (symtab) = new_linetable (maxlines); symtab->set_linetable (new_linetable (maxlines));
lang = compunit_language (cust); lang = compunit_language (cust);
/* All symtabs must have at least two blocks. */ /* All symtabs must have at least two blocks. */

View File

@ -53,12 +53,12 @@ mi_cmd_symbol_list_lines (const char *command, char **argv, int argc)
gdbarch = SYMTAB_OBJFILE (s)->arch (); gdbarch = SYMTAB_OBJFILE (s)->arch ();
ui_out_emit_list list_emitter (uiout, "lines"); ui_out_emit_list list_emitter (uiout, "lines");
if (SYMTAB_LINETABLE (s) != NULL && SYMTAB_LINETABLE (s)->nitems > 0) if (s->linetable () != NULL && s->linetable ()->nitems > 0)
for (i = 0; i < SYMTAB_LINETABLE (s)->nitems; i++) for (i = 0; i < s->linetable ()->nitems; i++)
{ {
ui_out_emit_tuple tuple_emitter (uiout, NULL); ui_out_emit_tuple tuple_emitter (uiout, NULL);
uiout->field_core_addr ("pc", gdbarch, SYMTAB_LINETABLE (s)->item[i].pc); uiout->field_core_addr ("pc", gdbarch, s->linetable ()->item[i].pc);
uiout->field_signed ("line", SYMTAB_LINETABLE (s)->item[i].line); uiout->field_signed ("line", s->linetable ()->item[i].line);
} }
} }

View File

@ -656,7 +656,7 @@ objfile_relocate1 (struct objfile *objfile,
struct linetable *l; struct linetable *l;
/* First the line table. */ /* First the line table. */
l = SYMTAB_LINETABLE (s); l = s->linetable ();
if (l) if (l)
{ {
for (int i = 0; i < l->nitems; ++i) for (int i = 0; i < l->nitems; ++i)

View File

@ -192,16 +192,16 @@ ltpy_has_line (PyObject *self, PyObject *args)
if (! PyArg_ParseTuple (args, GDB_PY_LL_ARG, &py_line)) if (! PyArg_ParseTuple (args, GDB_PY_LL_ARG, &py_line))
return NULL; return NULL;
if (SYMTAB_LINETABLE (symtab) == NULL) if (symtab->linetable () == NULL)
{ {
PyErr_SetString (PyExc_RuntimeError, PyErr_SetString (PyExc_RuntimeError,
_("Linetable information not found in symbol table")); _("Linetable information not found in symbol table"));
return NULL; return NULL;
} }
for (index = 0; index < SYMTAB_LINETABLE (symtab)->nitems; index++) for (index = 0; index < symtab->linetable ()->nitems; index++)
{ {
struct linetable_entry *item = &(SYMTAB_LINETABLE (symtab)->item[index]); struct linetable_entry *item = &(symtab->linetable ()->item[index]);
if (item->line == py_line) if (item->line == py_line)
Py_RETURN_TRUE; Py_RETURN_TRUE;
} }
@ -223,7 +223,7 @@ ltpy_get_all_source_lines (PyObject *self, PyObject *args)
LTPY_REQUIRE_VALID (self, symtab); LTPY_REQUIRE_VALID (self, symtab);
if (SYMTAB_LINETABLE (symtab) == NULL) if (symtab->linetable () == NULL)
{ {
PyErr_SetString (PyExc_RuntimeError, PyErr_SetString (PyExc_RuntimeError,
_("Linetable information not found in symbol table")); _("Linetable information not found in symbol table"));
@ -234,9 +234,9 @@ ltpy_get_all_source_lines (PyObject *self, PyObject *args)
if (source_dict == NULL) if (source_dict == NULL)
return NULL; return NULL;
for (index = 0; index < SYMTAB_LINETABLE (symtab)->nitems; index++) for (index = 0; index < symtab->linetable ()->nitems; index++)
{ {
item = &(SYMTAB_LINETABLE (symtab)->item[index]); item = &(symtab->linetable ()->item[index]);
/* 0 is used to signify end of line table information. Do not /* 0 is used to signify end of line table information. Do not
include in the source set. */ include in the source set. */
@ -399,13 +399,13 @@ ltpy_iternext (PyObject *self)
LTPY_REQUIRE_VALID (iter_obj->source, symtab); LTPY_REQUIRE_VALID (iter_obj->source, symtab);
if (iter_obj->current_index >= SYMTAB_LINETABLE (symtab)->nitems) if (iter_obj->current_index >= symtab->linetable ()->nitems)
{ {
PyErr_SetNone (PyExc_StopIteration); PyErr_SetNone (PyExc_StopIteration);
return NULL; return NULL;
} }
item = &(SYMTAB_LINETABLE (symtab)->item[iter_obj->current_index]); item = &(symtab->linetable ()->item[iter_obj->current_index]);
/* Skip over internal entries such as 0. 0 signifies the end of /* Skip over internal entries such as 0. 0 signifies the end of
line table data and is not useful to the API user. */ line table data and is not useful to the API user. */
@ -414,12 +414,12 @@ ltpy_iternext (PyObject *self)
iter_obj->current_index++; iter_obj->current_index++;
/* Exit if the internal value is the last item in the line table. */ /* Exit if the internal value is the last item in the line table. */
if (iter_obj->current_index >= SYMTAB_LINETABLE (symtab)->nitems) if (iter_obj->current_index >= symtab->linetable ()->nitems)
{ {
PyErr_SetNone (PyExc_StopIteration); PyErr_SetNone (PyExc_StopIteration);
return NULL; return NULL;
} }
item = &(SYMTAB_LINETABLE (symtab)->item[iter_obj->current_index]); item = &(symtab->linetable ()->item[iter_obj->current_index]);
} }
obj = build_linetable_entry (item->line, item->pc); obj = build_linetable_entry (item->line, item->pc);

View File

@ -713,7 +713,7 @@ btrace_find_line_range (CORE_ADDR pc)
if (symtab == NULL) if (symtab == NULL)
return btrace_mk_line_range (NULL, 0, 0); return btrace_mk_line_range (NULL, 0, 0);
ltable = SYMTAB_LINETABLE (symtab); ltable = symtab->linetable ();
if (ltable == NULL) if (ltable == NULL)
return btrace_mk_line_range (symtab, 0, 0); return btrace_mk_line_range (symtab, 0, 0);

View File

@ -77,7 +77,7 @@ print_objfile_statistics (void)
for (symtab *s : cu->filetabs ()) for (symtab *s : cu->filetabs ())
{ {
i++; i++;
if (SYMTAB_LINETABLE (s) != NULL) if (s->linetable () != NULL)
linetables++; linetables++;
} }
} }
@ -259,7 +259,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
language_str (symtab->language)); language_str (symtab->language));
/* First print the line table. */ /* First print the line table. */
l = SYMTAB_LINETABLE (symtab); l = symtab->linetable ();
if (l) if (l)
{ {
fprintf_filtered (outfile, "\nLine table:\n\n"); fprintf_filtered (outfile, "\nLine table:\n\n");
@ -824,7 +824,8 @@ maintenance_info_symtabs (const char *regexp, int from_tty)
: "(null)"); : "(null)");
printf_filtered ("\t " printf_filtered ("\t "
"linetable ((struct linetable *) %s)\n", "linetable ((struct linetable *) %s)\n",
host_address_to_string (symtab->linetable)); host_address_to_string
(symtab->linetable ()));
printf_filtered ("\t}\n"); printf_filtered ("\t}\n");
} }
} }
@ -968,7 +969,7 @@ maintenance_print_one_line_table (struct symtab *symtab, void *data)
styled_string (file_name_style.style (), styled_string (file_name_style.style (),
symtab_to_fullname (symtab)), symtab_to_fullname (symtab)),
host_address_to_string (symtab)); host_address_to_string (symtab));
linetable = SYMTAB_LINETABLE (symtab); linetable = symtab->linetable ();
printf_filtered (_("linetable: ((struct linetable *) %s):\n"), printf_filtered (_("linetable: ((struct linetable *) %s):\n"),
host_address_to_string (linetable)); host_address_to_string (linetable));

View File

@ -3285,7 +3285,7 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent)
for (symtab *iter_s : cust->filetabs ()) for (symtab *iter_s : cust->filetabs ())
{ {
/* Find the best line in this symtab. */ /* Find the best line in this symtab. */
l = SYMTAB_LINETABLE (iter_s); l = iter_s->linetable ();
if (!l) if (!l)
continue; continue;
len = l->nitems; len = l->nitems;
@ -3454,7 +3454,7 @@ find_line_symtab (struct symtab *sym_tab, int line,
struct symtab *best_symtab; struct symtab *best_symtab;
/* First try looking it up in the given symtab. */ /* First try looking it up in the given symtab. */
best_linetable = SYMTAB_LINETABLE (sym_tab); best_linetable = sym_tab->linetable ();
best_symtab = sym_tab; best_symtab = sym_tab;
best_index = find_line_common (best_linetable, line, &exact, 0); best_index = find_line_common (best_linetable, line, &exact, 0);
if (best_index < 0 || !exact) if (best_index < 0 || !exact)
@ -3493,7 +3493,7 @@ find_line_symtab (struct symtab *sym_tab, int line,
if (FILENAME_CMP (symtab_to_fullname (sym_tab), if (FILENAME_CMP (symtab_to_fullname (sym_tab),
symtab_to_fullname (s)) != 0) symtab_to_fullname (s)) != 0)
continue; continue;
l = SYMTAB_LINETABLE (s); l = s->linetable ();
ind = find_line_common (l, line, &exact, 0); ind = find_line_common (l, line, &exact, 0);
if (ind >= 0) if (ind >= 0)
{ {
@ -3545,14 +3545,14 @@ find_pcs_for_symtab_line (struct symtab *symtab, int line,
int was_exact; int was_exact;
int idx; int idx;
idx = find_line_common (SYMTAB_LINETABLE (symtab), line, &was_exact, idx = find_line_common (symtab->linetable (), line, &was_exact,
start); start);
if (idx < 0) if (idx < 0)
break; break;
if (!was_exact) if (!was_exact)
{ {
struct linetable_entry *item = &SYMTAB_LINETABLE (symtab)->item[idx]; struct linetable_entry *item = &symtab->linetable ()->item[idx];
if (*best_item == NULL if (*best_item == NULL
|| (item->line < (*best_item)->line && item->is_stmt)) || (item->line < (*best_item)->line && item->is_stmt))
@ -3561,7 +3561,7 @@ find_pcs_for_symtab_line (struct symtab *symtab, int line,
break; break;
} }
result.push_back (SYMTAB_LINETABLE (symtab)->item[idx].pc); result.push_back (symtab->linetable ()->item[idx].pc);
start = idx + 1; start = idx + 1;
} }
@ -3586,7 +3586,7 @@ find_line_pc (struct symtab *symtab, int line, CORE_ADDR *pc)
symtab = find_line_symtab (symtab, line, &ind, NULL); symtab = find_line_symtab (symtab, line, &ind, NULL);
if (symtab != NULL) if (symtab != NULL)
{ {
l = SYMTAB_LINETABLE (symtab); l = symtab->linetable ();
*pc = l->item[ind].pc; *pc = l->item[ind].pc;
return true; return true;
} }
@ -3783,7 +3783,7 @@ skip_prologue_using_lineinfo (CORE_ADDR func_addr, struct symtab *symtab)
int i; int i;
/* Give up if this symbol has no lineinfo table. */ /* Give up if this symbol has no lineinfo table. */
l = SYMTAB_LINETABLE (symtab); l = symtab->linetable ();
if (l == NULL) if (l == NULL)
return func_addr; return func_addr;
@ -4025,7 +4025,7 @@ skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr)
do this. */ do this. */
if (prologue_sal.symtab->language != language_asm) if (prologue_sal.symtab->language != language_asm)
{ {
struct linetable *linetable = SYMTAB_LINETABLE (prologue_sal.symtab); struct linetable *linetable = prologue_sal.symtab->linetable ();
int idx = 0; int idx = 0;
/* Skip any earlier lines, and any end-of-sequence marker /* Skip any earlier lines, and any end-of-sequence marker

View File

@ -1383,6 +1383,16 @@ struct symtab
m_compunit = compunit; m_compunit = compunit;
} }
struct linetable *linetable () const
{
return m_linetable;
}
void set_linetable (struct linetable *linetable)
{
m_linetable = linetable;
}
/* 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. */
@ -1395,7 +1405,7 @@ struct symtab
/* 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. */
struct linetable *linetable; struct linetable *m_linetable;
/* Name of this source file. This pointer is never NULL. */ /* Name of this source file. This pointer is never NULL. */
@ -1415,7 +1425,6 @@ struct symtab
using symtab_range = next_range<symtab>; using symtab_range = next_range<symtab>;
#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 ()->blockvector ()) (symtab->compunit ()->blockvector ())