offset_type n_elements = 0;
std::vector<symtab_index_entry> data;
+
+ /* Temporary storage for Ada names. */
+ auto_obstack m_string_obstack;
};
/* Find a slot in SYMTAB for the symbol NAME. Returns a reference to
for (; count-- > 0; ++psymp)
{
struct partial_symbol *psym = *psymp;
+ const char *name = psym->ginfo.search_name ();
if (psym->ginfo.language () == language_ada)
- error (_("Ada is not currently supported by the index; "
- "use the DWARF 5 index instead"));
+ {
+ /* We want to ensure that the Ada main function's name appears
+ verbatim in the index. However, this name will be of the
+ form "_ada_mumble", and will be rewritten by ada_decode.
+ So, recognize it specially here and add it to the index by
+ hand. */
+ if (strcmp (main_name (), name) == 0)
+ {
+ gdb_index_symbol_kind kind = symbol_kind (psym);
+
+ add_index_entry (symtab, name, is_static, kind, cu_index);
+ }
+
+ /* In order for the index to work when read back into gdb, it
+ has to supply a funny form of the name: it should be the
+ encoded name, with any suffixes stripped. Using the
+ ordinary encoded name will not work properly with the
+ searching logic in find_name_components_bounds; nor will
+ using the decoded name. Furthermore, an Ada "verbatim"
+ name (of the form "<MumBle>") must be entered without the
+ angle brackets. Note that the current index is unusual,
+ see PR symtab/24820 for details. */
+ std::string decoded = ada_decode (name);
+ if (decoded[0] == '<')
+ name = (char *) obstack_copy0 (&symtab->m_string_obstack,
+ decoded.c_str () + 1,
+ decoded.length () - 2);
+ else
+ name = obstack_strdup (&symtab->m_string_obstack,
+ ada_encode (decoded.c_str ()));
+ }
/* Only add a given psymbol once. */
if (psyms_seen.insert (psym).second)
{
gdb_index_symbol_kind kind = symbol_kind (psym);
- add_index_entry (symtab, psym->ginfo.search_name (),
- is_static, kind, cu_index);
+ add_index_entry (symtab, name, is_static, kind, cu_index);
}
}
}
class debug_names
{
public:
- debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile, bool is_dwarf64,
+ debug_names (dwarf2_per_objfile *per_objfile, bool is_dwarf64,
bfd_endian dwarf5_byte_order)
: m_dwarf5_byte_order (dwarf5_byte_order),
m_dwarf32 (dwarf5_byte_order),
: static_cast<dwarf &> (m_dwarf32)),
m_name_table_string_offs (m_dwarf.name_table_string_offs),
m_name_table_entry_offs (m_dwarf.name_table_entry_offs),
- m_debugstrlookup (dwarf2_per_objfile)
+ m_debugstrlookup (per_objfile)
{}
int dwarf5_offset_size () const
/* Object constructor to be called for current DWARF2_PER_OBJFILE.
All .debug_str section strings are automatically stored. */
- debug_str_lookup (struct dwarf2_per_objfile *dwarf2_per_objfile)
- : m_abfd (dwarf2_per_objfile->objfile->obfd),
- m_dwarf2_per_objfile (dwarf2_per_objfile)
+ debug_str_lookup (dwarf2_per_objfile *per_objfile)
+ : m_abfd (per_objfile->objfile->obfd),
+ m_per_objfile (per_objfile)
{
- dwarf2_per_objfile->per_bfd->str.read (dwarf2_per_objfile->objfile);
- if (dwarf2_per_objfile->per_bfd->str.buffer == NULL)
+ per_objfile->per_bfd->str.read (per_objfile->objfile);
+ if (per_objfile->per_bfd->str.buffer == NULL)
return;
- for (const gdb_byte *data = dwarf2_per_objfile->per_bfd->str.buffer;
- data < (dwarf2_per_objfile->per_bfd->str.buffer
- + dwarf2_per_objfile->per_bfd->str.size);)
+ for (const gdb_byte *data = per_objfile->per_bfd->str.buffer;
+ data < (per_objfile->per_bfd->str.buffer
+ + per_objfile->per_bfd->str.size);)
{
const char *const s = reinterpret_cast<const char *> (data);
const auto insertpair
= m_str_table.emplace (c_str_view (s),
- data - dwarf2_per_objfile->per_bfd->str.buffer);
+ data - per_objfile->per_bfd->str.buffer);
if (!insertpair.second)
complaint (_("Duplicate string \"%s\" in "
".debug_str section [in module %s]"),
const auto it = m_str_table.find (c_str_view (s));
if (it != m_str_table.end ())
return it->second;
- const size_t offset = (m_dwarf2_per_objfile->per_bfd->str.size
+ const size_t offset = (m_per_objfile->per_bfd->str.size
+ m_str_add_buf.size ());
m_str_table.emplace (c_str_view (s), offset);
m_str_add_buf.append_cstr0 (s);
private:
std::unordered_map<c_str_view, size_t, c_str_view_hasher> m_str_table;
bfd *const m_abfd;
- struct dwarf2_per_objfile *m_dwarf2_per_objfile;
+ dwarf2_per_objfile *m_per_objfile;
/* Data to add at the end of .debug_str for new needed symbol names. */
data_buf m_str_add_buf;
.debug_names section. */
static bool
-check_dwarf64_offsets (struct dwarf2_per_objfile *dwarf2_per_objfile)
+check_dwarf64_offsets (dwarf2_per_objfile *per_objfile)
{
- for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units)
+ for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
{
if (to_underlying (per_cu->sect_off) >= (static_cast<uint64_t> (1) << 32))
return true;
}
- for (const signatured_type *sigtype : dwarf2_per_objfile->per_bfd->all_type_units)
+ for (const signatured_type *sigtype : per_objfile->per_bfd->all_type_units)
{
const dwarf2_per_cu_data &per_cu = sigtype->per_cu;
malloc/free. */
static size_t
-psyms_seen_size (struct dwarf2_per_objfile *dwarf2_per_objfile)
+psyms_seen_size (dwarf2_per_objfile *per_objfile)
{
size_t psyms_count = 0;
- for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units)
+ for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
{
partial_symtab *psymtab = per_cu->v.psymtab;
associated dwz file, DWZ_OUT_FILE must be NULL. */
static void
-write_gdbindex (struct dwarf2_per_objfile *dwarf2_per_objfile, FILE *out_file,
+write_gdbindex (dwarf2_per_objfile *per_objfile, FILE *out_file,
FILE *dwz_out_file)
{
- struct objfile *objfile = dwarf2_per_objfile->objfile;
+ struct objfile *objfile = per_objfile->objfile;
mapped_symtab symtab;
data_buf objfile_cu_list;
data_buf dwz_cu_list;
in the index file). This will later be needed to write the address
table. */
psym_index_map cu_index_htab;
- cu_index_htab.reserve (dwarf2_per_objfile->per_bfd->all_comp_units.size ());
+ cu_index_htab.reserve (per_objfile->per_bfd->all_comp_units.size ());
/* The CU list is already sorted, so we don't need to do additional
work here. Also, the debug_types entries do not appear in
all_comp_units, but only in their own hash table. */
std::unordered_set<partial_symbol *> psyms_seen
- (psyms_seen_size (dwarf2_per_objfile));
- for (int i = 0; i < dwarf2_per_objfile->per_bfd->all_comp_units.size (); ++i)
+ (psyms_seen_size (per_objfile));
+ for (int i = 0; i < per_objfile->per_bfd->all_comp_units.size (); ++i)
{
- struct dwarf2_per_cu_data *per_cu
- = dwarf2_per_objfile->per_bfd->all_comp_units[i];
+ dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->all_comp_units[i];
partial_symtab *psymtab = per_cu->v.psymtab;
if (psymtab != NULL)
/* Write out the .debug_type entries, if any. */
data_buf types_cu_list;
- if (dwarf2_per_objfile->per_bfd->signatured_types)
+ if (per_objfile->per_bfd->signatured_types)
{
signatured_type_index_data sig_data (types_cu_list,
psyms_seen);
sig_data.objfile = objfile;
sig_data.symtab = &symtab;
- sig_data.cu_index = dwarf2_per_objfile->per_bfd->all_comp_units.size ();
- htab_traverse_noresize (dwarf2_per_objfile->per_bfd->signatured_types.get (),
+ sig_data.cu_index = per_objfile->per_bfd->all_comp_units.size ();
+ htab_traverse_noresize (per_objfile->per_bfd->signatured_types.get (),
write_one_signatured_type, &sig_data);
}
many bytes were expected to be written into OUT_FILE. */
static void
-write_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile,
+write_debug_names (dwarf2_per_objfile *per_objfile,
FILE *out_file, FILE *out_file_str)
{
- const bool dwarf5_is_dwarf64 = check_dwarf64_offsets (dwarf2_per_objfile);
- struct objfile *objfile = dwarf2_per_objfile->objfile;
+ const bool dwarf5_is_dwarf64 = check_dwarf64_offsets (per_objfile);
+ struct objfile *objfile = per_objfile->objfile;
const enum bfd_endian dwarf5_byte_order
= gdbarch_byte_order (objfile->arch ());
work here. Also, the debug_types entries do not appear in
all_comp_units, but only in their own hash table. */
data_buf cu_list;
- debug_names nametable (dwarf2_per_objfile, dwarf5_is_dwarf64,
- dwarf5_byte_order);
+ debug_names nametable (per_objfile, dwarf5_is_dwarf64, dwarf5_byte_order);
std::unordered_set<partial_symbol *>
- psyms_seen (psyms_seen_size (dwarf2_per_objfile));
- for (int i = 0; i < dwarf2_per_objfile->per_bfd->all_comp_units.size (); ++i)
+ psyms_seen (psyms_seen_size (per_objfile));
+ for (int i = 0; i < per_objfile->per_bfd->all_comp_units.size (); ++i)
{
- const dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->per_bfd->all_comp_units[i];
+ const dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->all_comp_units[i];
partial_symtab *psymtab = per_cu->v.psymtab;
/* CU of a shared file from 'dwz -m' may be unused by this main
/* Write out the .debug_type entries, if any. */
data_buf types_cu_list;
- if (dwarf2_per_objfile->per_bfd->signatured_types)
+ if (per_objfile->per_bfd->signatured_types)
{
debug_names::write_one_signatured_type_data sig_data (nametable,
signatured_type_index_data (types_cu_list, psyms_seen));
/* It is used only for gdb_index. */
sig_data.info.symtab = nullptr;
sig_data.info.cu_index = 0;
- htab_traverse_noresize (dwarf2_per_objfile->per_bfd->signatured_types.get (),
+ htab_traverse_noresize (per_objfile->per_bfd->signatured_types.get (),
debug_names::write_one_signatured_type,
&sig_data);
}
/* comp_unit_count - The number of CUs in the CU list. */
header.append_uint (4, dwarf5_byte_order,
- dwarf2_per_objfile->per_bfd->all_comp_units.size ());
+ per_objfile->per_bfd->all_comp_units.size ());
/* local_type_unit_count - The number of TUs in the local TU
list. */
header.append_uint (4, dwarf5_byte_order,
- dwarf2_per_objfile->per_bfd->all_type_units.size ());
+ per_objfile->per_bfd->all_type_units.size ());
/* foreign_type_unit_count - The number of TUs in the foreign TU
list. */
/* See dwarf-index-write.h. */
void
-write_psymtabs_to_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
- const char *dir, const char *basename,
- const char *dwz_basename,
+write_psymtabs_to_index (dwarf2_per_objfile *per_objfile, const char *dir,
+ const char *basename, const char *dwz_basename,
dw_index_kind index_kind)
{
- struct objfile *objfile = dwarf2_per_objfile->objfile;
+ struct objfile *objfile = per_objfile->objfile;
- if (dwarf2_per_objfile->per_bfd->using_index)
+ if (per_objfile->per_bfd->using_index)
error (_("Cannot use an index to create the index"));
- if (dwarf2_per_objfile->per_bfd->types.size () > 1)
+ if (per_objfile->per_bfd->types.size () > 1)
error (_("Cannot make an index when the file has multiple .debug_types sections"));
if (!objfile->partial_symtabs->psymtabs
{
index_wip_file str_wip_file (dir, basename, DEBUG_STR_SUFFIX);
- write_debug_names (dwarf2_per_objfile, objfile_index_wip.out_file.get (),
+ write_debug_names (per_objfile, objfile_index_wip.out_file.get (),
str_wip_file.out_file.get ());
str_wip_file.finalize ();
}
else
- write_gdbindex (dwarf2_per_objfile, objfile_index_wip.out_file.get (),
+ write_gdbindex (per_objfile, objfile_index_wip.out_file.get (),
(dwz_index_wip.has_value ()
? dwz_index_wip->out_file.get () : NULL));
if (stat (objfile_name (objfile), &st) < 0)
continue;
- struct dwarf2_per_objfile *dwarf2_per_objfile
- = get_dwarf2_per_objfile (objfile);
+ dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
- if (dwarf2_per_objfile != NULL)
+ if (per_objfile != NULL)
{
try
{
const char *basename = lbasename (objfile_name (objfile));
- const dwz_file *dwz
- = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
+ const dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
const char *dwz_basename = NULL;
if (dwz != NULL)
dwz_basename = lbasename (dwz->filename ());
- write_psymtabs_to_index (dwarf2_per_objfile, arg, basename,
- dwz_basename, index_kind);
+ write_psymtabs_to_index (per_objfile, arg, basename, dwz_basename,
+ index_kind);
}
catch (const gdb_exception_error &except)
{