aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Biesinger <cbiesinger@google.com>2019-11-04 13:12:09 -0600
committerChristian Biesinger <cbiesinger@google.com>2019-11-12 15:21:35 -0600
commit468c0cbb327fadf28386a989f929fcbed4aed8b9 (patch)
treedf5e63c82ad35603b4fbc8716e72dd417176601e
parentConsolidate setting of current_layout (diff)
downloadbinutils-gdb-468c0cbb327fadf28386a989f929fcbed4aed8b9.tar.gz
binutils-gdb-468c0cbb327fadf28386a989f929fcbed4aed8b9.tar.bz2
binutils-gdb-468c0cbb327fadf28386a989f929fcbed4aed8b9.zip
Make struct symbol inherit from general_symbol_info
Since this is now no longer a POD, also give it a constructor that initializes all fields. (I have considered overloading operator new to zero-initialize the memory instead; let me know if you prefer that) gdb/ChangeLog: 2019-11-12 Christian Biesinger <cbiesinger@google.com> * ada-exp.y (write_ambiguous_var): Update. * buildsym.c (add_symbol_to_list): Update. * dwarf2read.c (read_variable): Update. (new_symbol): Update. * jit.c (finalize_symtab): Update. * language.c (language_alloc_type_symbol): Update. * symtab.c (fixup_symbol_section): Update. (initialize_objfile_symbol_1): Move code to... (initialize_objfile_symbol): ...here. Remove now-unnecessary memset. (allocate_symbol): Update. (allocate_template_symbol): Update. (get_symbol_address): Update. * symtab.h (struct symbol): Inherit from general_symbol_info instead of having as a field, and add a constructor. (SYMBOL_VALUE): Update. (SYMBOL_VALUE_ADDRESS): Update. (SET_SYMBOL_VALUE_ADDRESS): Update. (SYMBOL_VALUE_BYTES): Update. (SYMBOL_VALUE_COMMON_BLOCK): Update. (SYMBOL_BLOCK_VALUE): Update. (SYMBOL_VALUE_CHAIN): Update. (SYMBOL_LANGUAGE): Update. (SYMBOL_SECTION): Update. (SYMBOL_OBJ_SECTION): Update. (SYMBOL_SET_LANGUAGE): Update. (SYMBOL_SET_LINKAGE_NAME): Update. (SYMBOL_SET_NAMES): Update. (SYMBOL_NATURAL_NAME): Update. (SYMBOL_LINKAGE_NAME): Update. (SYMBOL_DEMANGLED_NAME): Update. (SYMBOL_SEARCH_NAME): Update. (SYMBOL_MATCHES_SEARCH_NAME): Update. (struct symbol): Update. (struct template_symbol): Update. (struct rust_vtable_symbol): Update. * xcoffread.c (SYMBOL_DUP): Update. Change-Id: I05b1628455bcce3efaa101e65ef051708d17eb07
-rw-r--r--gdb/ChangeLog39
-rw-r--r--gdb/ada-exp.y3
-rw-r--r--gdb/buildsym.c2
-rw-r--r--gdb/dwarf2read.c7
-rw-r--r--gdb/jit.c4
-rw-r--r--gdb/language.c6
-rw-r--r--gdb/symtab.c27
-rw-r--r--gdb/symtab.h92
-rw-r--r--gdb/xcoffread.c2
9 files changed, 109 insertions, 73 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 23095e0200f..44ace04beb9 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,42 @@
+2019-11-12 Christian Biesinger <cbiesinger@google.com>
+
+ * ada-exp.y (write_ambiguous_var): Update.
+ * buildsym.c (add_symbol_to_list): Update.
+ * dwarf2read.c (read_variable): Update.
+ (new_symbol): Update.
+ * jit.c (finalize_symtab): Update.
+ * language.c (language_alloc_type_symbol): Update.
+ * symtab.c (fixup_symbol_section): Update.
+ (initialize_objfile_symbol_1): Move code to...
+ (initialize_objfile_symbol): ...here. Remove now-unnecessary memset.
+ (allocate_symbol): Update.
+ (allocate_template_symbol): Update.
+ (get_symbol_address): Update.
+ * symtab.h (struct symbol): Inherit from general_symbol_info instead
+ of having as a field, and add a constructor.
+ (SYMBOL_VALUE): Update.
+ (SYMBOL_VALUE_ADDRESS): Update.
+ (SET_SYMBOL_VALUE_ADDRESS): Update.
+ (SYMBOL_VALUE_BYTES): Update.
+ (SYMBOL_VALUE_COMMON_BLOCK): Update.
+ (SYMBOL_BLOCK_VALUE): Update.
+ (SYMBOL_VALUE_CHAIN): Update.
+ (SYMBOL_LANGUAGE): Update.
+ (SYMBOL_SECTION): Update.
+ (SYMBOL_OBJ_SECTION): Update.
+ (SYMBOL_SET_LANGUAGE): Update.
+ (SYMBOL_SET_LINKAGE_NAME): Update.
+ (SYMBOL_SET_NAMES): Update.
+ (SYMBOL_NATURAL_NAME): Update.
+ (SYMBOL_LINKAGE_NAME): Update.
+ (SYMBOL_DEMANGLED_NAME): Update.
+ (SYMBOL_SEARCH_NAME): Update.
+ (SYMBOL_MATCHES_SEARCH_NAME): Update.
+ (struct symbol): Update.
+ (struct template_symbol): Update.
+ (struct rust_vtable_symbol): Update.
+ * xcoffread.c (SYMBOL_DUP): Update.
+
2019-11-12 Tom Tromey <tom@tromey.com>
* tui/tui-layout.c (show_layout): Set current_layout.
diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 160e64bc05b..ff3ce763924 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -1102,9 +1102,8 @@ static void
write_ambiguous_var (struct parser_state *par_state,
const struct block *block, char *name, int len)
{
- struct symbol *sym = XOBNEW (&temp_parse_space, struct symbol);
+ struct symbol *sym = new (&temp_parse_space) symbol ();
- memset (sym, 0, sizeof (struct symbol));
SYMBOL_DOMAIN (sym) = UNDEF_DOMAIN;
SYMBOL_LINKAGE_NAME (sym) = obstack_strndup (&temp_parse_space, name, len);
SYMBOL_LANGUAGE (sym) = language_ada;
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 954a6106c6a..24d1e0f806b 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -135,7 +135,7 @@ add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
struct pending *link;
/* If this is an alias for another symbol, don't add it. */
- if (symbol->ginfo.name && symbol->ginfo.name[0] == '#')
+ if (symbol->name && symbol->name[0] == '#')
return;
/* We keep PENDINGSIZE symbols in each link of the list. If we
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 0a7a0334202..bbfa442d577 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -14320,8 +14320,7 @@ read_variable (struct die_info *die, struct dwarf2_cu *cu)
{
struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
- storage = OBSTACK_ZALLOC (&objfile->objfile_obstack,
- struct rust_vtable_symbol);
+ storage = new (&objfile->objfile_obstack) rust_vtable_symbol ();
initialize_objfile_symbol (storage);
storage->concrete_type = containing_type;
storage->subclass = SYMBOL_RUST_VTABLE;
@@ -21636,8 +21635,8 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
/* Fortran does not have mangling standard and the mangling does differ
between gfortran, iFort etc. */
if (cu->language == language_fortran
- && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
- symbol_set_demangled_name (&(sym->ginfo),
+ && symbol_get_demangled_name (sym) == NULL)
+ symbol_set_demangled_name (sym,
dwarf2_full_name (name, die, cu),
NULL);
diff --git a/gdb/jit.c b/gdb/jit.c
index 08fd8623f9c..85a01ef2c74 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -700,8 +700,8 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
SYMBOL_TYPE (block_name) = lookup_function_type (block_type);
SYMBOL_BLOCK_VALUE (block_name) = new_block;
- block_name->ginfo.name = obstack_strdup (&objfile->objfile_obstack,
- gdb_block_iter->name);
+ block_name->name = obstack_strdup (&objfile->objfile_obstack,
+ gdb_block_iter->name);
BLOCK_FUNCTION (new_block) = block_name;
diff --git a/gdb/language.c b/gdb/language.c
index 0e13c7185b7..6ab0ca323d2 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -1048,10 +1048,10 @@ language_alloc_type_symbol (enum language lang, struct type *type)
gdb_assert (!TYPE_OBJFILE_OWNED (type));
gdbarch = TYPE_OWNER (type).gdbarch;
- symbol = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct symbol);
+ symbol = new (gdbarch_obstack (gdbarch)) struct symbol ();
- symbol->ginfo.name = TYPE_NAME (type);
- symbol->ginfo.language = lang;
+ symbol->name = TYPE_NAME (type);
+ symbol->language = lang;
symbol->owner.arch = gdbarch;
SYMBOL_OBJFILE_OWNED (symbol) = 0;
SYMBOL_TYPE (symbol) = type;
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 2c934b9c22f..0064800313d 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1759,7 +1759,7 @@ fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
return sym;
}
- fixup_section (&sym->ginfo, addr, objfile);
+ fixup_section (sym, addr, objfile);
return sym;
}
@@ -6208,23 +6208,13 @@ initialize_ordinary_address_classes (void)
-/* Helper function to initialize the fields of an objfile-owned symbol.
- It assumed that *SYM is already all zeroes. */
-
-static void
-initialize_objfile_symbol_1 (struct symbol *sym)
-{
- SYMBOL_OBJFILE_OWNED (sym) = 1;
- SYMBOL_SECTION (sym) = -1;
-}
-
/* Initialize the symbol SYM, and mark it as being owned by an objfile. */
void
initialize_objfile_symbol (struct symbol *sym)
{
- memset (sym, 0, sizeof (*sym));
- initialize_objfile_symbol_1 (sym);
+ SYMBOL_OBJFILE_OWNED (sym) = 1;
+ SYMBOL_SECTION (sym) = -1;
}
/* Allocate and initialize a new 'struct symbol' on OBJFILE's
@@ -6233,10 +6223,9 @@ initialize_objfile_symbol (struct symbol *sym)
struct symbol *
allocate_symbol (struct objfile *objfile)
{
- struct symbol *result;
+ struct symbol *result = new (&objfile->objfile_obstack) symbol ();
- result = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
- initialize_objfile_symbol_1 (result);
+ initialize_objfile_symbol (result);
return result;
}
@@ -6249,8 +6238,8 @@ allocate_template_symbol (struct objfile *objfile)
{
struct template_symbol *result;
- result = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct template_symbol);
- initialize_objfile_symbol_1 (result);
+ result = new (&objfile->objfile_obstack) template_symbol ();
+ initialize_objfile_symbol (result);
return result;
}
@@ -6309,7 +6298,7 @@ get_symbol_address (const struct symbol *sym)
if (minsym.minsym != nullptr)
return BMSYMBOL_VALUE_ADDRESS (minsym);
}
- return sym->ginfo.value.address;
+ return sym->value.address;
}
/* See symtab.h. */
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 111a0f924d8..390aee4218b 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -25,6 +25,7 @@
#include <string>
#include "gdbsupport/gdb_vecs.h"
#include "gdbtypes.h"
+#include "gdb_obstack.h"
#include "gdb_regex.h"
#include "gdbsupport/enum-flags.h"
#include "gdbsupport/function-view.h"
@@ -470,35 +471,29 @@ extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
extern CORE_ADDR get_symbol_address (const struct symbol *sym);
-/* Note that all the following SYMBOL_* macros are used with the
- SYMBOL argument being either a partial symbol or
- a full symbol. Both types have a ginfo field. In particular
- the SYMBOL_SET_LANGUAGE, SYMBOL_DEMANGLED_NAME, etc.
- macros cannot be entirely substituted by
- functions, unless the callers are changed to pass in the ginfo
- field only, instead of the SYMBOL parameter. */
+/* Note that these macros only work with symbol, not partial_symbol. */
-#define SYMBOL_VALUE(symbol) (symbol)->ginfo.value.ivalue
+#define SYMBOL_VALUE(symbol) (symbol)->value.ivalue
#define SYMBOL_VALUE_ADDRESS(symbol) \
(((symbol)->maybe_copied) ? get_symbol_address (symbol) \
- : ((symbol)->ginfo.value.address))
+ : ((symbol)->value.address))
#define SET_SYMBOL_VALUE_ADDRESS(symbol, new_value) \
- ((symbol)->ginfo.value.address = (new_value))
-#define SYMBOL_VALUE_BYTES(symbol) (symbol)->ginfo.value.bytes
-#define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->ginfo.value.common_block
-#define SYMBOL_BLOCK_VALUE(symbol) (symbol)->ginfo.value.block
-#define SYMBOL_VALUE_CHAIN(symbol) (symbol)->ginfo.value.chain
-#define SYMBOL_LANGUAGE(symbol) (symbol)->ginfo.language
-#define SYMBOL_SECTION(symbol) (symbol)->ginfo.section
+ ((symbol)->value.address = (new_value))
+#define SYMBOL_VALUE_BYTES(symbol) (symbol)->value.bytes
+#define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->value.common_block
+#define SYMBOL_BLOCK_VALUE(symbol) (symbol)->value.block
+#define SYMBOL_VALUE_CHAIN(symbol) (symbol)->value.chain
+#define SYMBOL_LANGUAGE(symbol) (symbol)->language
+#define SYMBOL_SECTION(symbol) (symbol)->section
#define SYMBOL_OBJ_SECTION(objfile, symbol) \
- (((symbol)->ginfo.section >= 0) \
- ? (&(((objfile)->sections)[(symbol)->ginfo.section])) \
+ (((symbol)->section >= 0) \
+ ? (&(((objfile)->sections)[(symbol)->section])) \
: NULL)
/* Initializes the language dependent portion of a symbol
depending upon the language for the symbol. */
#define SYMBOL_SET_LANGUAGE(symbol,language,obstack) \
- (symbol_set_language (&(symbol)->ginfo, (language), (obstack)))
+ (symbol_set_language ((symbol), (language), (obstack)))
extern void symbol_set_language (struct general_symbol_info *symbol,
enum language language,
struct obstack *obstack);
@@ -509,13 +504,13 @@ extern void symbol_set_language (struct general_symbol_info *symbol,
be terminated and either already on the objfile's obstack or
permanently allocated. */
#define SYMBOL_SET_LINKAGE_NAME(symbol,linkage_name) \
- (symbol)->ginfo.name = (linkage_name)
+ (symbol)->name = (linkage_name)
/* Set the linkage and natural names of a symbol, by demangling
the linkage name. If linkage_name may not be nullterminated,
copy_name must be set to true. */
#define SYMBOL_SET_NAMES(symbol,linkage_name,copy_name,objfile) \
- symbol_set_names (&(symbol)->ginfo, linkage_name, copy_name, \
+ symbol_set_names ((symbol), linkage_name, copy_name, \
(objfile)->per_bfd)
extern void symbol_set_names (struct general_symbol_info *symbol,
gdb::string_view linkage_name, bool copy_name,
@@ -535,7 +530,7 @@ extern void symbol_set_names (struct general_symbol_info *symbol,
demangled name. */
#define SYMBOL_NATURAL_NAME(symbol) \
- (symbol_natural_name (&(symbol)->ginfo))
+ (symbol_natural_name ((symbol)))
extern const char *symbol_natural_name
(const struct general_symbol_info *symbol);
@@ -544,12 +539,12 @@ extern const char *symbol_natural_name
manipulation by the linker, this is the mangled name; otherwise,
it's the same as SYMBOL_NATURAL_NAME. */
-#define SYMBOL_LINKAGE_NAME(symbol) (symbol)->ginfo.name
+#define SYMBOL_LINKAGE_NAME(symbol) (symbol)->name
/* Return the demangled name for a symbol based on the language for
that symbol. If no demangled name exists, return NULL. */
#define SYMBOL_DEMANGLED_NAME(symbol) \
- (symbol_demangled_name (&(symbol)->ginfo))
+ (symbol_demangled_name ((symbol)))
extern const char *symbol_demangled_name
(const struct general_symbol_info *symbol);
@@ -560,7 +555,7 @@ extern const char *symbol_demangled_name
The result should never be NULL. Don't use this for internal
purposes (e.g. storing in a hashtable): it's only suitable for output.
- N.B. symbol may be anything with a ginfo member,
+ N.B. symbol may be anything inheriting from general_symbol_info,
e.g., struct symbol or struct minimal_symbol. */
#define SYMBOL_PRINT_NAME(symbol) \
@@ -573,13 +568,13 @@ extern bool demangle;
name. If there is no distinct demangled name, then SYMBOL_SEARCH_NAME
returns the same value (same pointer) as SYMBOL_LINKAGE_NAME. */
#define SYMBOL_SEARCH_NAME(symbol) \
- (symbol_search_name (&(symbol)->ginfo))
+ (symbol_search_name (symbol))
extern const char *symbol_search_name (const struct general_symbol_info *ginfo);
/* Return true if NAME matches the "search" name of SYMBOL, according
to the symbol's language. */
#define SYMBOL_MATCHES_SEARCH_NAME(symbol, name) \
- symbol_matches_search_name (&(symbol)->ginfo, (name))
+ symbol_matches_search_name ((symbol), (name))
/* Helper for SYMBOL_MATCHES_SEARCH_NAME that works with both symbols
and psymbols. */
@@ -1105,16 +1100,31 @@ enum symbol_subclass_kind
/* This structure is space critical. See space comments at the top. */
-struct symbol
+struct symbol : public general_symbol_info, public allocate_on_obstack
{
-
- /* The general symbol info required for all types of symbols. */
-
- struct general_symbol_info ginfo;
+ symbol ()
+ /* Class-initialization of bitfields is only allowed in C++20. */
+ : domain (UNDEF_DOMAIN),
+ aclass_index (0),
+ is_objfile_owned (0),
+ is_argument (0),
+ is_inlined (0),
+ maybe_copied (0),
+ subclass (SYMBOL_NONE)
+ {
+ /* We can't use an initializer list for members of a base class, and
+ general_symbol_info needs to stay a POD type. */
+ name = nullptr;
+ value.ivalue = 0;
+ language_specific.obstack = nullptr;
+ language = language_unknown;
+ ada_mangled = 0;
+ section = 0;
+ }
/* Data type of value */
- struct type *type;
+ struct type *type = nullptr;
/* The owner of this symbol.
Which one to use is defined by symbol.is_objfile_owned. */
@@ -1124,7 +1134,7 @@ struct symbol
/* The symbol table containing this symbol. This is the file associated
with LINE. It can be NULL during symbols read-in but it is never NULL
during normal operation. */
- struct symtab *symtab;
+ struct symtab *symtab = nullptr;
/* For types defined by the architecture. */
struct gdbarch *arch;
@@ -1141,7 +1151,7 @@ struct symbol
unsigned int aclass_index : SYMBOL_ACLASS_BITS;
/* If non-zero then symbol is objfile-owned, use owner.symtab.
- Otherwise symbol is arch-owned, use owner.arch. */
+ Otherwise symbol is arch-owned, use owner.arch. */
unsigned int is_objfile_owned : 1;
@@ -1175,7 +1185,7 @@ struct symbol
to debug files longer than 64K lines? What about machine
generated programs? */
- unsigned short line;
+ unsigned short line = 0;
/* An arbitrary data pointer, allowing symbol readers to record
additional information on a per-symbol basis. Note that this data
@@ -1189,9 +1199,9 @@ struct symbol
to add a magic symbol to the block containing this information,
or to have a generic debug info annotation slot for symbols. */
- void *aux_value;
+ void *aux_value = nullptr;
- struct symbol *hash_next;
+ struct symbol *hash_next = nullptr;
};
/* This struct is size-critical (see comment at the top), so this assert
@@ -1272,11 +1282,11 @@ extern void symbol_set_symtab (struct symbol *symbol, struct symtab *symtab);
struct template_symbol : public symbol
{
/* The number of template arguments. */
- int n_template_arguments;
+ int n_template_arguments = 0;
/* The template arguments. This is an array with
N_TEMPLATE_ARGUMENTS elements. */
- struct symbol **template_arguments;
+ struct symbol **template_arguments = nullptr;
};
/* A symbol that represents a Rust virtual table object. */
@@ -1285,7 +1295,7 @@ struct rust_vtable_symbol : public symbol
{
/* The concrete type for which this vtable was created; that is, in
"impl Trait for Type", this is "Type". */
- struct type *concrete_type;
+ struct type *concrete_type = nullptr;
};
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 20a21872d1c..4ea9b0b5bdd 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -1522,7 +1522,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst)
}
#define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
- (SYMBOL2) = XOBNEW (&objfile->objfile_obstack, struct symbol); \
+ (SYMBOL2) = new (&objfile->objfile_obstack) symbol (); \
*(SYMBOL2) = *(SYMBOL1);