/* Read dbx symbol tables and convert to internal format, for GDB.
- Copyright (C) 1986-2020 Free Software Foundation, Inc.
+ Copyright (C) 1986-2022 Free Software Foundation, Inc.
This file is part of GDB.
for real. dbx_psymtab_to_symtab() is the function that does this */
#include "defs.h"
-#if defined(__CYGNUSCLIB__)
-#include <sys/types.h>
-#include <fcntl.h>
-#endif
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
#include <sys/stat.h>
#include "symtab.h"
#include "breakpoint.h"
static void dbx_expand_psymtab (legacy_psymtab *, struct objfile *);
-static void read_dbx_symtab (minimal_symbol_reader &, struct objfile *);
+static void read_dbx_symtab (minimal_symbol_reader &, psymtab_storage *,
+ struct objfile *);
static legacy_psymtab *find_corresponding_bincl_psymtab (const char *,
int);
static void add_this_object_header_file (int);
-static legacy_psymtab *start_psymtab (struct objfile *, const char *,
- CORE_ADDR, int);
+static legacy_psymtab *start_psymtab (psymtab_storage *, struct objfile *,
+ const char *, CORE_ADDR, int);
/* Free up old header file tables. */
/* Read stabs data from executable file and define symbols. */
- read_dbx_symtab (reader, objfile);
+ psymbol_functions *psf = new psymbol_functions ();
+ psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
+ objfile->qf.emplace_front (psf);
+ read_dbx_symtab (reader, partial_symtabs, objfile);
/* Install any minimal symbols that have been collected as the current
minimal symbols for this objfile. */
debugging information is available. */
static void
-read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
+read_dbx_symtab (minimal_symbol_reader &reader,
+ psymtab_storage *partial_symtabs,
+ struct objfile *objfile)
{
struct gdbarch *gdbarch = objfile->arch ();
struct external_nlist *bufp = 0; /* =0 avoids gcc -Wall glitch. */
which are not the address. */
&& nlist.n_value >= pst->raw_text_low ())
{
- dbx_end_psymtab (objfile, pst, psymtab_include_list,
+ dbx_end_psymtab (objfile, partial_symtabs,
+ pst, psymtab_include_list,
includes_used, symnum * symbol_size,
nlist.n_value > pst->raw_text_high ()
? nlist.n_value : pst->raw_text_high (),
if (pst)
{
- dbx_end_psymtab (objfile, pst, psymtab_include_list,
+ dbx_end_psymtab (objfile, partial_symtabs,
+ pst, psymtab_include_list,
includes_used, symnum * symbol_size,
(valu > pst->raw_text_high ()
? valu : pst->raw_text_high ()),
if (!pst)
{
- pst = start_psymtab (objfile,
+ pst = start_psymtab (partial_symtabs, objfile,
namestring, valu,
first_so_symnum * symbol_size);
pst->dirname = dirname_nso;
if (!p)
continue; /* Not a debugging symbol. */
- sym_len = 0;
+ sym_len = 0;
sym_name = NULL; /* pacify "gcc -Werror" */
- if (psymtab_language == language_cplus)
- {
+ if (psymtab_language == language_cplus)
+ {
std::string name (namestring, p - namestring);
gdb::unique_xmalloc_ptr<char> new_name
= cp_canonicalize_string (name.c_str ());
}
}
- if (sym_len == 0)
- {
- sym_name = namestring;
- sym_len = p - namestring;
- }
+ if (sym_len == 0)
+ {
+ sym_name = namestring;
+ sym_len = p - namestring;
+ }
/* Main processing section for debugging symbols which
the initial read through the symbol tables needs to worry
switch (p[1])
{
case 'S':
- pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
- VAR_DOMAIN, LOC_STATIC,
- data_sect_index,
- psymbol_placement::STATIC,
- nlist.n_value, psymtab_language, objfile);
+ if (pst != nullptr)
+ pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
+ VAR_DOMAIN, LOC_STATIC,
+ data_sect_index,
+ psymbol_placement::STATIC,
+ nlist.n_value, psymtab_language,
+ partial_symtabs, objfile);
+ else
+ complaint (_("static `%*s' appears to be defined "
+ "outside of all compilation units"),
+ sym_len, sym_name);
continue;
case 'G':
/* The addresses in these entries are reported to be
wrong. See the code that reads 'G's for symtabs. */
- pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
- VAR_DOMAIN, LOC_STATIC,
- data_sect_index,
- psymbol_placement::GLOBAL,
- nlist.n_value, psymtab_language, objfile);
+ if (pst != nullptr)
+ pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
+ VAR_DOMAIN, LOC_STATIC,
+ data_sect_index,
+ psymbol_placement::GLOBAL,
+ nlist.n_value, psymtab_language,
+ partial_symtabs, objfile);
+ else
+ complaint (_("global `%*s' appears to be defined "
+ "outside of all compilation units"),
+ sym_len, sym_name);
continue;
case 'T':
|| (p == namestring + 1
&& namestring[0] != ' '))
{
- pst->add_psymbol (gdb::string_view (sym_name, sym_len),
- true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
- psymbol_placement::STATIC,
- 0, psymtab_language, objfile);
+ if (pst != nullptr)
+ pst->add_psymbol (gdb::string_view (sym_name, sym_len),
+ true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
+ psymbol_placement::STATIC,
+ 0, psymtab_language,
+ partial_symtabs, objfile);
+ else
+ complaint (_("enum, struct, or union `%*s' appears "
+ "to be defined outside of all "
+ "compilation units"),
+ sym_len, sym_name);
if (p[2] == 't')
{
/* Also a typedef with the same name. */
- pst->add_psymbol (gdb::string_view (sym_name, sym_len),
- true, VAR_DOMAIN, LOC_TYPEDEF, -1,
- psymbol_placement::STATIC,
- 0, psymtab_language, objfile);
+ if (pst != nullptr)
+ pst->add_psymbol (gdb::string_view (sym_name, sym_len),
+ true, VAR_DOMAIN, LOC_TYPEDEF, -1,
+ psymbol_placement::STATIC,
+ 0, psymtab_language,
+ partial_symtabs, objfile);
+ else
+ complaint (_("typedef `%*s' appears to be defined "
+ "outside of all compilation units"),
+ sym_len, sym_name);
p += 1;
}
}
case 't':
if (p != namestring) /* a name is there, not just :T... */
{
- pst->add_psymbol (gdb::string_view (sym_name, sym_len),
- true, VAR_DOMAIN, LOC_TYPEDEF, -1,
- psymbol_placement::STATIC,
- 0, psymtab_language, objfile);
+ if (pst != nullptr)
+ pst->add_psymbol (gdb::string_view (sym_name, sym_len),
+ true, VAR_DOMAIN, LOC_TYPEDEF, -1,
+ psymbol_placement::STATIC,
+ 0, psymtab_language,
+ partial_symtabs, objfile);
+ else
+ complaint (_("typename `%*s' appears to be defined "
+ "outside of all compilation units"),
+ sym_len, sym_name);
}
check_enum:
/* If this is an enumerated type, we need to
;
/* Note that the value doesn't matter for
enum constants in psymtabs, just in symtabs. */
- pst->add_psymbol (gdb::string_view (p, q - p), true,
- VAR_DOMAIN, LOC_CONST, -1,
- psymbol_placement::STATIC, 0,
- psymtab_language, objfile);
+ if (pst != nullptr)
+ pst->add_psymbol (gdb::string_view (p, q - p), true,
+ VAR_DOMAIN, LOC_CONST, -1,
+ psymbol_placement::STATIC, 0,
+ psymtab_language,
+ partial_symtabs, objfile);
+ else
+ complaint (_("enum constant `%*s' appears to be defined "
+ "outside of all compilation units"),
+ ((int) (q - p)), p);
/* Point past the name. */
p = q;
/* Skip over the value. */
case 'c':
/* Constant, e.g. from "const" in Pascal. */
- pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
- VAR_DOMAIN, LOC_CONST, -1,
- psymbol_placement::STATIC, 0,
- psymtab_language, objfile);
+ if (pst != nullptr)
+ pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
+ VAR_DOMAIN, LOC_CONST, -1,
+ psymbol_placement::STATIC, 0,
+ psymtab_language,
+ partial_symtabs, objfile);
+ else
+ complaint (_("constant `%*s' appears to be defined "
+ "outside of all compilation units"),
+ sym_len, sym_name);
+
continue;
case 'f':
if (! pst)
{
- int name_len = p - namestring;
- char *name = (char *) xmalloc (name_len + 1);
-
- memcpy (name, namestring, name_len);
- name[name_len] = '\0';
- function_outside_compilation_unit_complaint (name);
- xfree (name);
+ std::string name (namestring, (p - namestring));
+ function_outside_compilation_unit_complaint (name.c_str ());
}
/* Kludges for ELF/STABS with Sun ACC. */
last_function_name = namestring;
pst->set_text_low (nlist.n_value);
textlow_not_set = 0;
}
- pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
- VAR_DOMAIN, LOC_BLOCK,
- SECT_OFF_TEXT (objfile),
- psymbol_placement::STATIC,
- nlist.n_value, psymtab_language, objfile);
+ if (pst != nullptr)
+ pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
+ VAR_DOMAIN, LOC_BLOCK,
+ SECT_OFF_TEXT (objfile),
+ psymbol_placement::STATIC,
+ nlist.n_value, psymtab_language,
+ partial_symtabs, objfile);
continue;
/* Global functions were ignored here, but now they
case 'F':
if (! pst)
{
- int name_len = p - namestring;
- char *name = (char *) xmalloc (name_len + 1);
-
- memcpy (name, namestring, name_len);
- name[name_len] = '\0';
- function_outside_compilation_unit_complaint (name);
- xfree (name);
+ std::string name (namestring, (p - namestring));
+ function_outside_compilation_unit_complaint (name.c_str ());
}
/* Kludges for ELF/STABS with Sun ACC. */
last_function_name = namestring;
pst->set_text_low (nlist.n_value);
textlow_not_set = 0;
}
- pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
- VAR_DOMAIN, LOC_BLOCK,
- SECT_OFF_TEXT (objfile),
- psymbol_placement::GLOBAL,
- nlist.n_value, psymtab_language, objfile);
+ if (pst != nullptr)
+ pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
+ VAR_DOMAIN, LOC_BLOCK,
+ SECT_OFF_TEXT (objfile),
+ psymbol_placement::GLOBAL,
+ nlist.n_value, psymtab_language,
+ partial_symtabs, objfile);
continue;
/* Two things show up here (hopefully); static symbols of
compiled without debugging info follows this module. */
if (pst && gdbarch_sofun_address_maybe_missing (gdbarch))
{
- dbx_end_psymtab (objfile, pst,
+ dbx_end_psymtab (objfile, partial_symtabs, pst,
psymtab_include_list, includes_used,
symnum * symbol_size,
(CORE_ADDR) 0, dependency_list,
: lowest_text_address)
+ text_size;
- dbx_end_psymtab (objfile, pst, psymtab_include_list, includes_used,
+ dbx_end_psymtab (objfile, partial_symtabs,
+ pst, psymtab_include_list, includes_used,
symnum * symbol_size,
(text_end > pst->raw_text_high ()
? text_end : pst->raw_text_high ()),
(normal). */
static legacy_psymtab *
-start_psymtab (struct objfile *objfile, const char *filename, CORE_ADDR textlow,
- int ldsymoff)
+start_psymtab (psymtab_storage *partial_symtabs, struct objfile *objfile,
+ const char *filename, CORE_ADDR textlow, int ldsymoff)
{
- legacy_psymtab *result = new legacy_psymtab (filename, objfile, textlow);
+ legacy_psymtab *result = new legacy_psymtab (filename, partial_symtabs,
+ objfile->per_bfd, textlow);
result->read_symtab_private =
XOBNEW (&objfile->objfile_obstack, struct symloc);
FIXME: List variables and peculiarities of same. */
legacy_psymtab *
-dbx_end_psymtab (struct objfile *objfile, legacy_psymtab *pst,
+dbx_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
+ legacy_psymtab *pst,
const char **include_list, int num_includes,
int capping_symbol_offset, CORE_ADDR capping_text,
legacy_psymtab **dependency_list,
address, set it to our starting address. Take care to not set our
own ending address to our starting address. */
- for (partial_symtab *p1 : objfile->psymtabs ())
+ for (partial_symtab *p1 : partial_symtabs->range ())
if (!p1->text_high_valid && p1->text_low_valid && p1 != pst)
p1->set_text_high (pst->raw_text_low ());
}
if (number_dependencies)
{
pst->dependencies
- = objfile->partial_symtabs->allocate_dependencies (number_dependencies);
+ = partial_symtabs->allocate_dependencies (number_dependencies);
memcpy (pst->dependencies, dependency_list,
number_dependencies * sizeof (legacy_psymtab *));
}
for (i = 0; i < num_includes; i++)
{
legacy_psymtab *subpst =
- new legacy_psymtab (include_list[i], objfile);
+ new legacy_psymtab (include_list[i], partial_symtabs, objfile->per_bfd);
subpst->read_symtab_private =
XOBNEW (&objfile->objfile_obstack, struct symloc);
/* We could save slight bits of space by only making one of these,
shared by the entire set of include files. FIXME-someday. */
subpst->dependencies =
- objfile->partial_symtabs->allocate_dependencies (1);
+ partial_symtabs->allocate_dependencies (1);
subpst->dependencies[0] = pst;
subpst->number_of_dependencies = 1;
is not empty, but we don't realize that. Fixing that without slowing
things down might be tricky. */
- objfile->partial_symtabs->discard_psymtab (pst);
+ partial_symtabs->discard_psymtab (pst);
/* Indicate that psymtab was thrown away. */
pst = NULL;
struct block *block;
if (outermost_context_p ())
- {
+ {
lbrac_mismatch_complaint (symnum);
- break;
- }
+ break;
+ }
/* The following check is added before recording line 0 at
end of function so as to handle hand-generated stabs
dbx_new_init, /* init anything gbl to entire symtab */
dbx_symfile_init, /* read initial info, setup for sym_read() */
dbx_symfile_read, /* read a symbol file into symtab */
- NULL, /* sym_read_psymbols */
dbx_symfile_finish, /* finished with file, cleanup */
default_symfile_offsets, /* parse user's offsets to internal form */
default_symfile_segments, /* Get segment information from a file. */
NULL,
default_symfile_relocate, /* Relocate a debug section. */
NULL, /* sym_probe_fns */
- &psym_functions
};
void _initialize_dbxread ();