/* Support routines for building symbol tables in GDB's internal format.
- Copyright (C) 1986-2022 Free Software Foundation, Inc.
+ Copyright (C) 1986-2024 Free Software Foundation, Inc.
This file is part of GDB.
#include "objfiles.h"
#include "gdbtypes.h"
#include "complaints.h"
-#include "expression.h" /* For "enum exp_opcode" used by... */
-#include "filenames.h" /* For DOSish file names. */
+#include "expression.h"
+#include "filenames.h"
#include "macrotab.h"
-#include "demangle.h" /* Needed by SYMBOL_INIT_DEMANGLED_NAME. */
+#include "demangle.h"
#include "block.h"
#include "cp-support.h"
#include "dictionary.h"
buildsym_compunit::buildsym_compunit (struct objfile *objfile_,
const char *name,
const char *comp_dir_,
+ const char *name_for_id,
enum language language_,
CORE_ADDR last_addr)
: m_objfile (objfile_),
It can happen that the debug info provides a different path to NAME than
DIRNAME,NAME. We cope with this in watch_main_source_file_lossage but
that only works if the main_subfile doesn't have a symtab yet. */
- start_subfile (name);
+ start_subfile (name, name_for_id);
/* Save this so that we don't have to go looking for it at the end
of the subfiles list. */
m_main_subfile = m_current_subfile;
struct pending_block *pblock;
struct pending_block *opblock;
- block = (is_global
- ? allocate_global_block (&m_objfile->objfile_obstack)
- : allocate_block (&m_objfile->objfile_obstack));
+ if (is_global)
+ block = new (&m_objfile->objfile_obstack) global_block;
+ else
+ block = new (&m_objfile->objfile_obstack) struct block;
if (symbol)
{
if (symbol)
{
struct type *ftype = symbol->type ();
- struct mdict_iterator miter;
symbol->set_value_block (block);
+ symbol->set_section_index (SECT_OFF_TEXT (m_objfile));
block->set_function (symbol);
if (ftype->num_fields () <= 0)
function's type. Set that from the type of the
parameter symbols. */
int nparams = 0, iparams;
- struct symbol *sym;
/* Here we want to directly access the dictionary, because
we haven't fully initialized the block yet. */
- ALL_DICT_SYMBOLS (block->multidict (), miter, sym)
+ for (struct symbol *sym : block->multidict_symbols ())
{
if (sym->is_argument ())
nparams++;
}
if (nparams > 0)
{
- ftype->set_num_fields (nparams);
- ftype->set_fields
- ((struct field *)
- TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
+ ftype->alloc_fields (nparams);
iparams = 0;
/* Here we want to directly access the dictionary, because
we haven't fully initialized the block yet. */
- ALL_DICT_SYMBOLS (block->multidict (), miter, sym)
+ for (struct symbol *sym : block->multidict_symbols ())
{
if (iparams == nparams)
break;
if (sym->is_argument ())
{
ftype->field (iparams).set_type (sym->type ());
- TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
+ ftype->field (iparams).set_is_artificial (false);
iparams++;
}
}
opblock = pblock;
}
- block_set_using (block,
- (is_global
- ? m_global_using_directives
- : m_local_using_directives),
- &m_objfile->objfile_obstack);
+ block->set_using ((is_global
+ ? m_global_using_directives
+ : m_local_using_directives),
+ &m_objfile->objfile_obstack);
if (is_global)
m_global_using_directives = NULL;
else
return (blockvector);
}
-\f
-/* Start recording information about source code that came from an
- included (or otherwise merged-in) source file with a different
- name. NAME is the name of the file (cannot be NULL). */
+
+/* See buildsym.h. */
void
-buildsym_compunit::start_subfile (const char *name)
+buildsym_compunit::start_subfile (const char *name, const char *name_for_id)
{
/* See if this subfile is already registered. */
- symtab_create_debug_printf ("name = %s", name);
+ symtab_create_debug_printf ("name = %s, name_for_id = %s", name, name_for_id);
for (subfile *subfile = m_subfiles; subfile; subfile = subfile->next)
- {
- std::string subfile_name_holder;
- const char *subfile_name;
-
- /* If NAME is an absolute path, and this subfile is not, then
- attempt to create an absolute path to compare. */
- if (IS_ABSOLUTE_PATH (name)
- && !IS_ABSOLUTE_PATH (subfile->name)
- && !m_comp_dir.empty ())
- {
- subfile_name_holder = path_join (m_comp_dir.c_str (),
- subfile->name.c_str ());
- subfile_name = subfile_name_holder.c_str ();
- }
- else
- subfile_name = subfile->name.c_str ();
-
- if (FILENAME_CMP (subfile_name, name) == 0)
- {
- symtab_create_debug_printf ("found existing symtab with name %s (%s)",
- subfile->name.c_str (), subfile_name);
- m_current_subfile = subfile;
- return;
- }
- }
+ if (FILENAME_CMP (subfile->name_for_id.c_str (), name_for_id) == 0)
+ {
+ symtab_create_debug_printf ("found existing symtab with name_for_id %s",
+ subfile->name_for_id.c_str ());
+ m_current_subfile = subfile;
+ return;
+ }
/* This subfile is not known. Add an entry for it. */
subfile_up subfile (new struct subfile);
subfile->name = name;
+ subfile->name_for_id = name_for_id;
m_current_subfile = subfile.get ();
{
m_comp_dir = std::move (subfile->name);
subfile->name = name;
+ subfile->name_for_id = name;
set_last_source_file (name);
/* Default the source language to whatever can be deduced from
void
buildsym_compunit::record_line (struct subfile *subfile, int line,
- CORE_ADDR pc, linetable_entry_flags flags)
+ unrelocated_addr pc, linetable_entry_flags flags)
{
m_have_line_numbers = true;
anyway. */
if (line == 0)
{
- gdb::optional<int> last_line;
+ std::optional<int> last_line;
while (!subfile->line_vector_entries.empty ())
{
linetable_entry *last = &subfile->line_vector_entries.back ();
last_line = last->line;
- if (last->pc != pc)
+ if (last->unrelocated_pc () != pc)
break;
subfile->line_vector_entries.pop_back ();
linetable_entry &e = subfile->line_vector_entries.back ();
e.line = line;
e.is_stmt = (flags & LEF_IS_STMT) != 0;
- e.pc = pc;
+ e.set_unrelocated_pc (pc);
e.prologue_end = (flags & LEF_PROLOGUE_END) != 0;
+ e.epilogue_begin = (flags & LEF_EPILOGUE_BEGIN) != 0;
}
\f
}
}
- /* Reordered executables may have out of order pending blocks; if
- OBJF_REORDERED is true, then sort the pending blocks. */
-
- if ((m_objfile->flags & OBJF_REORDERED) && m_pending_blocks)
+ /* Executables may have out of order pending blocks; sort the
+ pending blocks. */
+ if (m_pending_blocks != nullptr)
{
struct pending_block *pb;
struct compunit_symtab *
buildsym_compunit::end_compunit_symtab_with_blockvector
- (struct block *static_block, int section, int expandable)
+ (struct block *static_block, int expandable)
{
struct compunit_symtab *cu = m_compunit_symtab;
struct blockvector *blockvector;
{
if (!subfile->line_vector_entries.empty ())
{
- const auto lte_is_less_than
- = [] (const linetable_entry &ln1,
- const linetable_entry &ln2) -> bool
- {
- if (ln1.pc == ln2.pc
- && ((ln1.line == 0) != (ln2.line == 0)))
- return ln1.line == 0;
-
- return (ln1.pc < ln2.pc);
- };
-
- /* Like the pending blocks, the line table may be scrambled in
- reordered executables. Sort it if OBJF_REORDERED is true. It
- is important to preserve the order of lines at the same
- address, as this maintains the inline function caller/callee
+ /* Like the pending blocks, the line table may be scrambled
+ in reordered executables. Sort it. It is important to
+ preserve the order of lines at the same address, as this
+ maintains the inline function caller/callee
relationships, this is why std::stable_sort is used. */
- if (m_objfile->flags & OBJF_REORDERED)
- std::stable_sort (subfile->line_vector_entries.begin (),
- subfile->line_vector_entries.end (),
- lte_is_less_than);
+ std::stable_sort (subfile->line_vector_entries.begin (),
+ subfile->line_vector_entries.end ());
}
/* Allocate a symbol table if necessary. */
if (subfile->symtab == NULL)
- subfile->symtab = allocate_symtab (cu, subfile->name.c_str ());
+ subfile->symtab = allocate_symtab (cu, subfile->name.c_str (),
+ subfile->name_for_id.c_str ());
struct symtab *symtab = subfile->symtab;
size_t entry_array_size = n_entries * sizeof (struct linetable_entry);
int linetablesize = sizeof (struct linetable) + entry_array_size;
- symtab->set_linetable
- (XOBNEWVAR (&m_objfile->objfile_obstack, struct linetable,
- linetablesize));
+ struct linetable *new_table
+ = XOBNEWVAR (&m_objfile->objfile_obstack, struct linetable,
+ linetablesize);
- symtab->linetable ()->nitems = n_entries;
- memcpy (symtab->linetable ()->item,
+ new_table->nitems = n_entries;
+ memcpy (new_table->item,
subfile->line_vector_entries.data (), entry_array_size);
+
+ symtab->set_linetable (new_table);
}
else
symtab->set_linetable (nullptr);
{
struct block *b = blockvector->global_block ();
- set_block_compunit_symtab (b, cu);
+ b->set_compunit_symtab (cu);
}
- cu->set_block_line_section (section);
-
cu->set_macro_table (release_macros ());
/* Default any symbols without a specified symtab to the primary symtab. */
for (block_i = 0; block_i < blockvector->num_blocks (); block_i++)
{
struct block *block = blockvector->block (block_i);
- struct symbol *sym;
- struct mdict_iterator miter;
/* Inlined functions may have symbols not in the global or
static symbol lists. */
block->function ()->set_symtab (symtab);
/* Note that we only want to fix up symbols from the local
- blocks, not blocks coming from included symtabs. That is why
- we use ALL_DICT_SYMBOLS here and not ALL_BLOCK_SYMBOLS. */
- ALL_DICT_SYMBOLS (block->multidict (), miter, sym)
+ blocks, not blocks coming from included symtabs. That is
+ why we use an mdict iterator here and not a block
+ iterator. */
+ for (struct symbol *sym : block->multidict_symbols ())
if (sym->symtab () == NULL)
sym->set_symtab (symtab);
}
/* Implementation of the second part of end_compunit_symtab. Pass STATIC_BLOCK
as value returned by end_compunit_symtab_get_static_block.
- SECTION is the same as for end_compunit_symtab: the section number
- (in objfile->section_offsets) of the blockvector and linetable.
-
If EXPANDABLE is non-zero the GLOBAL_BLOCK dictionary is made
expandable. */
struct compunit_symtab *
buildsym_compunit::end_compunit_symtab_from_static_block
- (struct block *static_block, int section, int expandable)
+ (struct block *static_block, int expandable)
{
struct compunit_symtab *cu;
cu = NULL;
}
else
- cu = end_compunit_symtab_with_blockvector (static_block, section, expandable);
+ cu = end_compunit_symtab_with_blockvector (static_block, expandable);
return cu;
}
them), then make the struct symtab for that file and put it in the
list of all such.
- END_ADDR is the address of the end of the file's text. SECTION is
- the section number (in objfile->section_offsets) of the blockvector
- and linetable.
+ END_ADDR is the address of the end of the file's text.
Note that it is possible for end_compunit_symtab() to return NULL. In
particular, for the DWARF case at least, it will return NULL when
end_compunit_symtab_from_static_block yourself. */
struct compunit_symtab *
-buildsym_compunit::end_compunit_symtab (CORE_ADDR end_addr, int section)
+buildsym_compunit::end_compunit_symtab (CORE_ADDR end_addr)
{
struct block *static_block;
static_block = end_compunit_symtab_get_static_block (end_addr, 0, 0);
- return end_compunit_symtab_from_static_block (static_block, section, 0);
+ return end_compunit_symtab_from_static_block (static_block, 0);
}
/* Same as end_compunit_symtab except create a symtab that can be later added
to. */
struct compunit_symtab *
-buildsym_compunit::end_expandable_symtab (CORE_ADDR end_addr, int section)
+buildsym_compunit::end_expandable_symtab (CORE_ADDR end_addr)
{
struct block *static_block;
static_block = end_compunit_symtab_get_static_block (end_addr, 1, 0);
- return end_compunit_symtab_from_static_block (static_block, section, 1);
+ return end_compunit_symtab_from_static_block (static_block, 1);
}
/* Subroutine of augment_type_symtab to simplify it.