Remove allocate_symbol et al
authorTom Tromey <tom@tromey.com>
Fri, 15 May 2020 22:11:33 +0000 (16:11 -0600)
committerTom Tromey <tom@tromey.com>
Fri, 15 May 2020 22:11:34 +0000 (16:11 -0600)
This removes allocate_symbol, allocate_template_symbol, and
initialize_objfile_symbol in favor of changing the default values for
symbol members, and updating the one per-arch caller.

gdb/ChangeLog
2020-05-15  Tom Tromey  <tom@tromey.com>

* language.c (language_alloc_type_symbol): Set
SYMBOL_SECTION.
* symtab.c (initialize_objfile_symbol): Remove.
(allocate_symbol): Remove.
(allocate_template_symbol): Remove.
* dwarf2/read.c (fixup_go_packaging): Use "new".
(new_symbol): Use "new".
(read_variable): Don't call initialize_objfile_symbol.  Use
"new".
(read_func_scope): Use "new".
* xcoffread.c (process_xcoff_symbol): Don't call
initialize_objfile_symbol.
(SYMBOL_DUP): Remove.
* coffread.c (process_coff_symbol, coff_read_enum_type): Use
"new".
* symtab.h (allocate_symbol, initialize_objfile_symbol)
(allocate_template_symbol): Don't declare.
(struct symbol): Add copy constructor.  Change defaults.
* jit.c (finalize_symtab): Use "new".
* ctfread.c (ctf_add_enum_member_cb, new_symbol, ctf_add_var_cb):
Use "new".
* stabsread.c (patch_block_stabs, define_symbol, read_enum_type)
(common_block_end): Use "new".
* mdebugread.c (parse_symbol): Use "new".
(new_symbol): Likewise.

gdb/ChangeLog
gdb/coffread.c
gdb/ctfread.c
gdb/dwarf2/read.c
gdb/jit.c
gdb/language.c
gdb/mdebugread.c
gdb/stabsread.c
gdb/symtab.c
gdb/symtab.h
gdb/xcoffread.c

index 86499f9982fdbfb1c0a6c23e4582efe2c1a3aa70..4b6294f4faff146667c24201d832a71e6056cfc2 100644 (file)
@@ -1,3 +1,31 @@
+2020-05-15  Tom Tromey  <tom@tromey.com>
+
+       * language.c (language_alloc_type_symbol): Set
+       SYMBOL_SECTION.
+       * symtab.c (initialize_objfile_symbol): Remove.
+       (allocate_symbol): Remove.
+       (allocate_template_symbol): Remove.
+       * dwarf2/read.c (fixup_go_packaging): Use "new".
+       (new_symbol): Use "new".
+       (read_variable): Don't call initialize_objfile_symbol.  Use
+       "new".
+       (read_func_scope): Use "new".
+       * xcoffread.c (process_xcoff_symbol): Don't call
+       initialize_objfile_symbol.
+       (SYMBOL_DUP): Remove.
+       * coffread.c (process_coff_symbol, coff_read_enum_type): Use
+       "new".
+       * symtab.h (allocate_symbol, initialize_objfile_symbol)
+       (allocate_template_symbol): Don't declare.
+       (struct symbol): Add copy constructor.  Change defaults.
+       * jit.c (finalize_symtab): Use "new".
+       * ctfread.c (ctf_add_enum_member_cb, new_symbol, ctf_add_var_cb):
+       Use "new".
+       * stabsread.c (patch_block_stabs, define_symbol, read_enum_type)
+       (common_block_end): Use "new".
+       * mdebugread.c (parse_symbol): Use "new".
+       (new_symbol): Likewise.
+
 2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 
        * NEWS: Mention changes to help and apropos.
index d320332f3af0384a59e640dc13fc4b0a9553b968..7e3cb4a6fdac6bea698c5a13083eaaf391fd7bca 100644 (file)
@@ -1556,7 +1556,7 @@ process_coff_symbol (struct coff_symbol *cs,
                     union internal_auxent *aux,
                     struct objfile *objfile)
 {
-  struct symbol *sym = allocate_symbol (objfile);
+  struct symbol *sym = new (&objfile->objfile_obstack) symbol;
   char *name;
 
   name = cs->c_name;
@@ -2095,7 +2095,7 @@ coff_read_enum_type (int index, int length, int lastsym,
       switch (ms->c_sclass)
        {
        case C_MOE:
-         sym = allocate_symbol (objfile);
+         sym = new (&objfile->objfile_obstack) symbol;
 
          name = obstack_strdup (&objfile->objfile_obstack, name);
          sym->set_linkage_name (name);
index 1efa47b2f4c7609fcf793e4fb8d5096e98c4f492..74355a019b95afd485b4bc5a349cf9bb973db426 100644 (file)
@@ -407,7 +407,7 @@ ctf_add_enum_member_cb (const char *name, int enum_value, void *arg)
 
   if (name != NULL)
     {
-      struct symbol *sym = allocate_symbol (ccp->of);
+      struct symbol *sym = new (&ccp->of->objfile_obstack) symbol;
       OBJSTAT (ccp->of, n_syms++);
 
       sym->set_language (language_c, &ccp->of->objfile_obstack);
@@ -436,7 +436,7 @@ new_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid)
   gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
   if (name != NULL)
     {
-      sym = allocate_symbol (objfile);
+      sym = new (&objfile->objfile_obstack) symbol;
       OBJSTAT (objfile, n_syms++);
 
       sym->set_language (language_c, &objfile->objfile_obstack);
@@ -1071,7 +1071,7 @@ ctf_add_var_cb (const char *name, ctf_id_t id, void *arg)
          complaint (_("ctf_add_var_cb: %s has NO type (%ld)"), name, id);
          type = objfile_type (ccp->of)->builtin_error;
        }
-       sym = allocate_symbol (ccp->of);
+       sym = new (&ccp->of->objfile_obstack) symbol;
        OBJSTAT (ccp->of, n_syms++);
        SYMBOL_TYPE (sym) = type;
        SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
index ab21ab0d13a960c581f001a2c0370a8621a88856..245ce07de748b55754f4502f7e250e46ea311ea7 100644 (file)
@@ -9172,7 +9172,7 @@ fixup_go_packaging (struct dwarf2_cu *cu)
                                     saved_package_name);
       struct symbol *sym;
 
-      sym = allocate_symbol (objfile);
+      sym = new (&objfile->objfile_obstack) symbol;
       sym->set_language (language_go, &objfile->objfile_obstack);
       sym->compute_and_set_names (saved_package_name, false, objfile->per_bfd);
       /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
@@ -12983,7 +12983,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
       if (child_die->tag == DW_TAG_template_type_param
          || child_die->tag == DW_TAG_template_value_param)
        {
-         templ_func = allocate_template_symbol (objfile);
+         templ_func = new (&objfile->objfile_obstack) template_symbol;
          templ_func->subclass = SYMBOL_TEMPLATE;
          break;
        }
@@ -13546,8 +13546,7 @@ read_variable (struct die_info *die, struct dwarf2_cu *cu)
        {
          struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
 
-         storage = new (&objfile->objfile_obstack) rust_vtable_symbol ();
-         initialize_objfile_symbol (storage);
+         storage = new (&objfile->objfile_obstack) rust_vtable_symbol;
          storage->concrete_type = containing_type;
          storage->subclass = SYMBOL_RUST_VTABLE;
        }
@@ -20606,7 +20605,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
       if (space)
        sym = space;
       else
-       sym = allocate_symbol (objfile);
+       sym = new (&objfile->objfile_obstack) symbol;
       OBJSTAT (objfile, n_syms++);
 
       /* Cache this symbol's name and the name's demangled form (if any).  */
index 07e9ce7ae245539ab3cc08601abc34ba380bb700..1b5ef46469e0ccd41709f74e03b153d02026f24c 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -655,7 +655,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
   for (gdb_block &gdb_block_iter : stab->blocks)
     {
       struct block *new_block = allocate_block (&objfile->objfile_obstack);
-      struct symbol *block_name = allocate_symbol (objfile);
+      struct symbol *block_name = new (&objfile->objfile_obstack) symbol;
       struct type *block_type = arch_type (objfile->arch (),
                                           TYPE_CODE_VOID,
                                           TARGET_CHAR_BIT,
index a7ecb7963ba85aa0ae6ca44d45f0f47ffcf6f590..3dc22a7a4798ddae67eef5d278ef87dec54f98b3 100644 (file)
@@ -1041,6 +1041,7 @@ language_alloc_type_symbol (enum language lang, struct type *type)
   symbol->set_language (lang, nullptr);
   symbol->owner.arch = gdbarch;
   SYMBOL_OBJFILE_OWNED (symbol) = 0;
+  SYMBOL_SECTION (symbol) = 0;
   SYMBOL_TYPE (symbol) = type;
   SYMBOL_DOMAIN (symbol) = VAR_DOMAIN;
   SYMBOL_ACLASS_INDEX (symbol) = LOC_TYPEDEF;
index eab52c70f17ea057c90756f3f62f7e36dad0e7aa..ba53512636e417dadfb581cf126d1a3a191c67f3 100644 (file)
@@ -1056,7 +1056,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
                FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss;
                FIELD_BITSIZE (*f) = 0;
 
-               enum_sym = allocate_symbol (mdebugread_objfile);
+               enum_sym = new (&mdebugread_objfile->objfile_obstack) symbol;
                enum_sym->set_linkage_name
                  (obstack_strdup (&mdebugread_objfile->objfile_obstack,
                                   f->name));
@@ -4721,7 +4721,7 @@ new_block (enum block_type type, enum language language)
 static struct symbol *
 new_symbol (const char *name)
 {
-  struct symbol *s = allocate_symbol (mdebugread_objfile);
+  struct symbol *s = new (&mdebugread_objfile->objfile_obstack) symbol;
 
   s->set_language (psymtab_language, &mdebugread_objfile->objfile_obstack);
   s->compute_and_set_names (name, true, mdebugread_objfile->per_bfd);
index 77f105d07b359cbf426ed1ea2ec69d1b188d236a..716b5f3f531d891e303c25c7d095f7be9629f816 100644 (file)
@@ -423,7 +423,7 @@ patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
              /* On xcoff, if a global is defined and never referenced,
                 ld will remove it from the executable.  There is then
                 a N_GSYM stab for it, but no regular (C_EXT) symbol.  */
-             sym = allocate_symbol (objfile);
+             sym = new (&objfile->objfile_obstack) symbol;
              SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
              SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
              sym->set_linkage_name
@@ -687,7 +687,7 @@ define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
      e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
   nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
 
-  current_symbol = sym = allocate_symbol (objfile);
+  current_symbol = sym = new (&objfile->objfile_obstack) symbol;
 
   if (processing_gcc_compilation)
     {
@@ -1307,7 +1307,7 @@ define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
       if (synonym)
         {
           /* Create the STRUCT_DOMAIN clone.  */
-          struct symbol *struct_sym = allocate_symbol (objfile);
+          struct symbol *struct_sym = new (&objfile->objfile_obstack) symbol;
 
           *struct_sym = *sym;
           SYMBOL_ACLASS_INDEX (struct_sym) = LOC_TYPEDEF;
@@ -1349,7 +1349,7 @@ define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
       if (synonym)
        {
          /* Clone the sym and then modify it.  */
-         struct symbol *typedef_sym = allocate_symbol (objfile);
+         struct symbol *typedef_sym = new (&objfile->objfile_obstack) symbol;
 
          *typedef_sym = *sym;
          SYMBOL_ACLASS_INDEX (typedef_sym) = LOC_TYPEDEF;
@@ -3632,7 +3632,7 @@ read_enum_type (const char **pp, struct type *type,
       if (nbits != 0)
        return error_type (pp, objfile);
 
-      sym = allocate_symbol (objfile);
+      sym = new (&objfile->objfile_obstack) symbol;
       sym->set_linkage_name (name);
       sym->set_language (get_current_subfile ()->language,
                         &objfile->objfile_obstack);
@@ -4299,7 +4299,7 @@ common_block_end (struct objfile *objfile)
       return;
     }
 
-  sym = allocate_symbol (objfile);
+  sym = new (&objfile->objfile_obstack) symbol;
   /* Note: common_block_name already saved on objfile_obstack.  */
   sym->set_linkage_name (common_block_name);
   SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
index 2043d084140ca68ab7e7e8eab30e515bf1820a5e..16ebe4d39f41d7c3cf84e8d131078c014ede174d 100644 (file)
@@ -6355,42 +6355,6 @@ initialize_ordinary_address_classes (void)
 
 \f
 
-/* Initialize the symbol SYM, and mark it as being owned by an objfile.  */
-
-void
-initialize_objfile_symbol (struct symbol *sym)
-{
-  SYMBOL_OBJFILE_OWNED (sym) = 1;
-  SYMBOL_SECTION (sym) = -1;
-}
-
-/* Allocate and initialize a new 'struct symbol' on OBJFILE's
-   obstack.  */
-
-struct symbol *
-allocate_symbol (struct objfile *objfile)
-{
-  struct symbol *result = new (&objfile->objfile_obstack) symbol ();
-
-  initialize_objfile_symbol (result);
-
-  return result;
-}
-
-/* Allocate and initialize a new 'struct template_symbol' on OBJFILE's
-   obstack.  */
-
-struct template_symbol *
-allocate_template_symbol (struct objfile *objfile)
-{
-  struct template_symbol *result;
-
-  result = new (&objfile->objfile_obstack) template_symbol ();
-  initialize_objfile_symbol (result);
-
-  return result;
-}
-
 /* See symtab.h.  */
 
 struct objfile *
index 764c567a90bb9dd1ca176625f9267861517b2c67..aaf42a576a41630405741737b9b4f0e8b5c48df5 100644 (file)
@@ -1107,7 +1107,7 @@ struct symbol : public general_symbol_info, public allocate_on_obstack
     /* Class-initialization of bitfields is only allowed in C++20.  */
     : domain (UNDEF_DOMAIN),
       aclass_index (0),
-      is_objfile_owned (0),
+      is_objfile_owned (1),
       is_argument (0),
       is_inlined (0),
       maybe_copied (0),
@@ -1120,12 +1120,14 @@ struct symbol : public general_symbol_info, public allocate_on_obstack
       language_specific.obstack = nullptr;
       m_language = language_unknown;
       ada_mangled = 0;
-      section = 0;
+      section = -1;
       /* GCC 4.8.5 (on CentOS 7) does not correctly compile class-
          initialization of unions, so we initialize it manually here.  */
       owner.symtab = nullptr;
     }
 
+  symbol (const symbol &) = default;
+
   /* Data type of value */
 
   struct type *type = nullptr;
@@ -2331,12 +2333,6 @@ const char *
   demangle_for_lookup (const char *name, enum language lang,
                       demangle_result_storage &storage);
 
-struct symbol *allocate_symbol (struct objfile *);
-
-void initialize_objfile_symbol (struct symbol *);
-
-struct template_symbol *allocate_template_symbol (struct objfile *);
-
 /* Test to see if the symbol of language SYMBOL_LANGUAGE specified by
    SYMNAME (which is already demangled for C++ symbols) matches
    SYM_TEXT in the first SYM_TEXT_LEN characters.  If so, add it to
index 2c19dc8c8226c0075b4b963b5042efec0b20ed13..93bdb9b6a6567827205b2a1dfa7d376b2ec40371 100644 (file)
@@ -1521,11 +1521,6 @@ read_xcoff_symtab (struct objfile *objfile, legacy_psymtab *pst)
     }
 }
 
-#define        SYMBOL_DUP(SYMBOL1, SYMBOL2)    \
-  (SYMBOL2) = new (&objfile->objfile_obstack) symbol (); \
-  *(SYMBOL2) = *(SYMBOL1);
-
-
 #define        SYMNAME_ALLOC(NAME, ALLOCED)    \
   ((ALLOCED) ? (NAME) : obstack_strdup (&objfile->objfile_obstack, \
                                        (NAME)))
@@ -1561,8 +1556,6 @@ process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile)
   if (name[0] == '.')
     ++name;
 
-  initialize_objfile_symbol (sym);
-
   /* default assumptions */
   SET_SYMBOL_VALUE_ADDRESS (sym, cs->c_value + off);
   SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
@@ -1578,7 +1571,7 @@ process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile)
       SYMBOL_TYPE (sym) = objfile_type (objfile)->nodebug_text_symbol;
 
       SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
-      SYMBOL_DUP (sym, sym2);
+      sym2 = new (&objfile->objfile_obstack) symbol (*sym);
 
       if (cs->c_sclass == C_EXT || C_WEAKEXT)
        add_symbol_to_list (sym2, get_global_symbols ());
This page took 0.039751 seconds and 4 git commands to generate.