diff options
-rw-r--r-- | gdb/ChangeLog | 19 | ||||
-rw-r--r-- | gdb/compile/compile-object-run.c | 2 | ||||
-rw-r--r-- | gdb/jit.c | 6 | ||||
-rw-r--r-- | gdb/objfiles.c | 141 | ||||
-rw-r--r-- | gdb/objfiles.h | 80 | ||||
-rw-r--r-- | gdb/solib.c | 4 | ||||
-rw-r--r-- | gdb/symfile.c | 10 |
7 files changed, 131 insertions, 131 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 032d8d3..b868a1d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,22 @@ +2017-10-13 Tom Tromey <tom@tromey.com> + + * compile/compile-object-run.c (do_module_cleanup): Use delete. + * solib.c (update_solib_list, reload_shared_libraries_1): Use + delete. + * symfile.c (symbol_file_add_with_addrs): Use new. + (symbol_file_add_separate): Update comment. + (syms_from_objfile_1, remove_symbol_file_command): Use delete. + * jit.c (jit_object_close_impl): Use new. + (jit_unregister_code): Use delete. + * objfiles.c (objfile::objfile): Rename from allocate_objfile. + (~objfile): Rename from free_objfile. + (free_objfile_separate_debug, do_free_objfile_cleanup) + (free_all_objfiles, objfile_purge_solibs): Use delete. + * objfiles.h (struct objfile): Add constructor and destructor. + Use DISABLE_COPY_AND_ASSIGN. Add initializers to data members. + (allocate_objfile, free_objfile): Don't declare. + (struct objstats): Add initializers. + 2017-10-12 Simon Marchi <simon.marchi@ericsson.com> * arch-utils.h (simple_displaced_step_copy_insn): Remove. diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c index 43da59f..9c36779 100644 --- a/gdb/compile/compile-object-run.c +++ b/gdb/compile/compile-object-run.c @@ -87,7 +87,7 @@ do_module_cleanup (void *arg, int registers_valid) if ((objfile->flags & OBJF_USERLOADED) == 0 && (strcmp (objfile_name (objfile), data->objfile_name_string) == 0)) { - free_objfile (objfile); + delete objfile; /* It may be a bit too pervasive in this dummy_frame dtor callback. */ clear_symtab_users (0); @@ -801,8 +801,8 @@ jit_object_close_impl (struct gdb_symbol_callbacks *cb, priv_data = (jit_dbg_reader_data *) cb->priv_data; - objfile = allocate_objfile (NULL, "<< JIT compiled code >>", - OBJF_NOT_FILENAME); + objfile = new struct objfile (NULL, "<< JIT compiled code >>", + OBJF_NOT_FILENAME); objfile->per_bfd->gdbarch = target_gdbarch (); terminate_minimal_symbol_table (objfile); @@ -983,7 +983,7 @@ jit_register_code (struct gdbarch *gdbarch, static void jit_unregister_code (struct objfile *objfile) { - free_objfile (objfile); + delete objfile; } /* Look up the objfile with this code entry address. */ diff --git a/gdb/objfiles.c b/gdb/objfiles.c index e743834..bf0515a 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -357,10 +357,9 @@ build_objfile_section_table (struct objfile *objfile) add_to_objfile_sections_full (objfile->obfd, bfd_ind_section_ptr, objfile, 1); } -/* Given a pointer to an initialized bfd (ABFD) and some flag bits - allocate a new objfile struct, fill it in as best we can, link it - into the list of all known objfiles, and return a pointer to the - new objfile struct. +/* Given a pointer to an initialized bfd (ABFD) and some flag bits, + initialize the new objfile as best we can and link it into the list + of all known objfiles. NAME should contain original non-canonicalized filename or other identifier as entered by user. If there is no better source use @@ -371,19 +370,19 @@ build_objfile_section_table (struct objfile *objfile) requests for specific operations. Other bits like OBJF_SHARED are simply copied through to the new objfile flags member. */ -struct objfile * -allocate_objfile (bfd *abfd, const char *name, objfile_flags flags) +objfile::objfile (bfd *abfd, const char *name, objfile_flags flags_) + : flags (flags_), + pspace (current_program_space), + obfd (abfd), + psymbol_cache (psymbol_bcache_init ()) { - struct objfile *objfile; const char *expanded_name; - objfile = XCNEW (struct objfile); - objfile->psymbol_cache = psymbol_bcache_init (); /* We could use obstack_specify_allocation here instead, but gdb_obstack.h specifies the alloc/dealloc functions. */ - obstack_init (&objfile->objfile_obstack); + obstack_init (&objfile_obstack); - objfile_alloc_data (objfile); + objfile_alloc_data (this); gdb::unique_xmalloc_ptr<char> name_holder; if (name == NULL) @@ -400,8 +399,8 @@ allocate_objfile (bfd *abfd, const char *name, objfile_flags flags) name_holder = gdb_abspath (name); expanded_name = name_holder.get (); } - objfile->original_name - = (char *) obstack_copy0 (&objfile->objfile_obstack, + original_name + = (char *) obstack_copy0 (&objfile_obstack, expanded_name, strlen (expanded_name)); @@ -409,34 +408,23 @@ allocate_objfile (bfd *abfd, const char *name, objfile_flags flags) that any data that is reference is saved in the per-objfile data region. */ - objfile->obfd = abfd; gdb_bfd_ref (abfd); if (abfd != NULL) { - objfile->mtime = bfd_get_mtime (abfd); + mtime = bfd_get_mtime (abfd); /* Build section table. */ - build_objfile_section_table (objfile); + build_objfile_section_table (this); } - objfile->per_bfd = get_objfile_bfd_data (objfile, abfd); - objfile->pspace = current_program_space; - - terminate_minimal_symbol_table (objfile); - - /* Initialize the section indexes for this objfile, so that we can - later detect if they are used w/o being properly assigned to. */ + per_bfd = get_objfile_bfd_data (this, abfd); - objfile->sect_index_text = -1; - objfile->sect_index_data = -1; - objfile->sect_index_bss = -1; - objfile->sect_index_rodata = -1; + terminate_minimal_symbol_table (this); /* Add this file onto the tail of the linked list of other such files. */ - objfile->next = NULL; if (object_files == NULL) - object_files = objfile; + object_files = this; else { struct objfile *last_one; @@ -444,16 +432,11 @@ allocate_objfile (bfd *abfd, const char *name, objfile_flags flags) for (last_one = object_files; last_one->next; last_one = last_one->next); - last_one->next = objfile; + last_one->next = this; } - /* Save passed in flag bits. */ - objfile->flags |= flags; - /* Rebuild section map next time we need it. */ - get_objfile_pspace_data (objfile->pspace)->new_objfiles_available = 1; - - return objfile; + get_objfile_pspace_data (pspace)->new_objfiles_available = 1; } /* Retrieve the gdbarch associated with OBJFILE. */ @@ -623,45 +606,44 @@ free_objfile_separate_debug (struct objfile *objfile) for (child = objfile->separate_debug_objfile; child;) { struct objfile *next_child = child->separate_debug_objfile_link; - free_objfile (child); + delete child; child = next_child; } } /* Destroy an objfile and all the symtabs and psymtabs under it. */ -void -free_objfile (struct objfile *objfile) +objfile::~objfile () { /* First notify observers that this objfile is about to be freed. */ - observer_notify_free_objfile (objfile); + observer_notify_free_objfile (this); /* Free all separate debug objfiles. */ - free_objfile_separate_debug (objfile); + free_objfile_separate_debug (this); - if (objfile->separate_debug_objfile_backlink) + if (separate_debug_objfile_backlink) { /* We freed the separate debug file, make sure the base objfile doesn't reference it. */ struct objfile *child; - child = objfile->separate_debug_objfile_backlink->separate_debug_objfile; + child = separate_debug_objfile_backlink->separate_debug_objfile; - if (child == objfile) + if (child == this) { - /* OBJFILE is the first child. */ - objfile->separate_debug_objfile_backlink->separate_debug_objfile = - objfile->separate_debug_objfile_link; + /* THIS is the first child. */ + separate_debug_objfile_backlink->separate_debug_objfile = + separate_debug_objfile_link; } else { - /* Find OBJFILE in the list. */ + /* Find THIS in the list. */ while (1) { - if (child->separate_debug_objfile_link == objfile) + if (child->separate_debug_objfile_link == this) { child->separate_debug_objfile_link = - objfile->separate_debug_objfile_link; + separate_debug_objfile_link; break; } child = child->separate_debug_objfile_link; @@ -669,17 +651,17 @@ free_objfile (struct objfile *objfile) } } } - + /* Remove any references to this objfile in the global value lists. */ - preserve_values (objfile); + preserve_values (this); /* It still may reference data modules have associated with the objfile and the symbol file data. */ - forget_cached_source_info_for_objfile (objfile); + forget_cached_source_info_for_objfile (this); - breakpoint_free_objfile (objfile); - btrace_free_objfile (objfile); + breakpoint_free_objfile (this); + btrace_free_objfile (this); /* First do any symbol file specific actions required when we are finished with a particular symbol file. Note that if the objfile @@ -688,25 +670,23 @@ free_objfile (struct objfile *objfile) freeing things which are valid only during this particular gdb execution, or leaving them to be reused during the next one. */ - if (objfile->sf != NULL) - { - (*objfile->sf->sym_finish) (objfile); - } + if (sf != NULL) + (*sf->sym_finish) (this); /* Discard any data modules have associated with the objfile. The function - still may reference objfile->obfd. */ - objfile_free_data (objfile); + still may reference obfd. */ + objfile_free_data (this); - if (objfile->obfd) - gdb_bfd_unref (objfile->obfd); + if (obfd) + gdb_bfd_unref (obfd); else - free_objfile_per_bfd_storage (objfile->per_bfd); + free_objfile_per_bfd_storage (per_bfd); /* Remove it from the chain of all objfiles. */ - unlink_objfile (objfile); + unlink_objfile (this); - if (objfile == symfile_objfile) + if (this == symfile_objfile) symfile_objfile = NULL; /* Before the symbol table code was redone to make it easier to @@ -732,34 +712,31 @@ free_objfile (struct objfile *objfile) { struct symtab_and_line cursal = get_current_source_symtab_and_line (); - if (cursal.symtab && SYMTAB_OBJFILE (cursal.symtab) == objfile) + if (cursal.symtab && SYMTAB_OBJFILE (cursal.symtab) == this) clear_current_source_symtab_and_line (); } - if (objfile->global_psymbols.list) - xfree (objfile->global_psymbols.list); - if (objfile->static_psymbols.list) - xfree (objfile->static_psymbols.list); + if (global_psymbols.list) + xfree (global_psymbols.list); + if (static_psymbols.list) + xfree (static_psymbols.list); /* Free the obstacks for non-reusable objfiles. */ - psymbol_bcache_free (objfile->psymbol_cache); - obstack_free (&objfile->objfile_obstack, 0); + psymbol_bcache_free (psymbol_cache); + obstack_free (&objfile_obstack, 0); /* Rebuild section map next time we need it. */ - get_objfile_pspace_data (objfile->pspace)->section_map_dirty = 1; + get_objfile_pspace_data (pspace)->section_map_dirty = 1; /* Free the map for static links. There's no need to free static link themselves since they were allocated on the objstack. */ - if (objfile->static_links != NULL) - htab_delete (objfile->static_links); - - /* The last thing we do is free the objfile struct itself. */ - xfree (objfile); + if (static_links != NULL) + htab_delete (static_links); } static void do_free_objfile_cleanup (void *obj) { - free_objfile ((struct objfile *) obj); + delete (struct objfile *) obj; } struct cleanup * @@ -782,7 +759,7 @@ free_all_objfiles (void) ALL_OBJFILES_SAFE (objfile, temp) { - free_objfile (objfile); + delete objfile; } clear_symtab_users (0); } @@ -1105,7 +1082,7 @@ objfile_purge_solibs (void) be soon. */ if (!(objf->flags & OBJF_USERLOADED) && (objf->flags & OBJF_SHARED)) - free_objfile (objf); + delete objf; } } diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 3260425..7e2beee 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -154,19 +154,19 @@ struct obj_section struct objstats { /* Number of partial symbols read. */ - int n_psyms; + int n_psyms = 0; /* Number of full symbols read. */ - int n_syms; + int n_syms = 0; /* Number of ".stabs" read (if applicable). */ - int n_stabs; + int n_stabs = 0; /* Number of types. */ - int n_types; + int n_types = 0; /* Size of stringtable, (if applicable). */ - int sz_strtab; + int sz_strtab = 0; }; #define OBJSTAT(objfile, expr) (objfile -> stats.expr) @@ -277,11 +277,16 @@ struct objfile_per_bfd_storage struct objfile { + objfile (bfd *, const char *, objfile_flags); + ~objfile (); + + DISABLE_COPY_AND_ASSIGN (objfile); + /* All struct objfile's are chained together by their next pointers. The program space field "objfiles" (frequently referenced via the macro "object_files") points to the first link in this chain. */ - struct objfile *next; + struct objfile *next = nullptr; /* The object file's original name as specified by the user, made absolute, and tilde-expanded. However, it is not canonicalized @@ -289,9 +294,9 @@ struct objfile This pointer is never NULL. This does not have to be freed; it is guaranteed to have a lifetime at least as long as the objfile. */ - char *original_name; + char *original_name = nullptr; - CORE_ADDR addr_low; + CORE_ADDR addr_low = 0; /* Some flag bits for this objfile. */ @@ -304,24 +309,24 @@ struct objfile /* List of compunits. These are used to do symbol lookups and file/line-number lookups. */ - struct compunit_symtab *compunit_symtabs; + struct compunit_symtab *compunit_symtabs = nullptr; /* Each objfile points to a linked list of partial symtabs derived from this file, one partial symtab structure for each compilation unit (source file). */ - struct partial_symtab *psymtabs; + struct partial_symtab *psymtabs = nullptr; /* Map addresses to the entries of PSYMTABS. It would be more efficient to have a map per the whole process but ADDRMAP cannot selectively remove its items during FREE_OBJFILE. This mapping is already present even for PARTIAL_SYMTABs which still have no corresponding full SYMTABs read. */ - struct addrmap *psymtabs_addrmap; + struct addrmap *psymtabs_addrmap = nullptr; /* List of freed partial symtabs, available for re-use. */ - struct partial_symtab *free_psymtabs; + struct partial_symtab *free_psymtabs = nullptr; /* The object file's BFD. Can be null if the objfile contains only minimal symbols, e.g. the run time common symbols for SunOS4. */ @@ -331,28 +336,28 @@ struct objfile /* The per-BFD data. Note that this is treated specially if OBFD is NULL. */ - struct objfile_per_bfd_storage *per_bfd; + struct objfile_per_bfd_storage *per_bfd = nullptr; /* The modification timestamp of the object file, as of the last time we read its symbols. */ - long mtime; + long mtime = 0; /* Obstack to hold objects that should be freed when we load a new symbol table from this object file. */ - struct obstack objfile_obstack; + struct obstack objfile_obstack {}; /* A byte cache where we can stash arbitrary "chunks" of bytes that will not change. */ - struct psymbol_bcache *psymbol_cache; /* Byte cache for partial syms. */ + struct psymbol_bcache *psymbol_cache; /* Vectors of all partial symbols read in from file. The actual data is stored in the objfile_obstack. */ - struct psymbol_allocation_list global_psymbols; - struct psymbol_allocation_list static_psymbols; + struct psymbol_allocation_list global_psymbols {}; + struct psymbol_allocation_list static_psymbols {}; /* Structure which keeps track of functions that manipulate objfile's of the same type as this objfile. I.e. the function to read partial @@ -360,11 +365,11 @@ struct objfile allocated memory, and is shared by all objfiles that use the object module reader of this type. */ - const struct sym_fns *sf; + const struct sym_fns *sf = nullptr; /* Per objfile data-pointers required by other GDB modules. */ - REGISTRY_FIELDS; + REGISTRY_FIELDS {}; /* Set of relocation offsets to apply to each section. The table is indexed by the_bfd_section->index, thus it is generally @@ -375,20 +380,23 @@ struct objfile minimal symbols) which have been read have been relocated by this much. Symbols which are yet to be read need to be relocated by it. */ - struct section_offsets *section_offsets; - int num_sections; + struct section_offsets *section_offsets = nullptr; + int num_sections = 0; /* Indexes in the section_offsets array. These are initialized by the *_symfile_offsets() family of functions (som_symfile_offsets, xcoff_symfile_offsets, default_symfile_offsets). In theory they should correspond to the section indexes used by bfd for the current objfile. The exception to this for the time being is the - SOM version. */ + SOM version. + + These are initialized to -1 so that we can later detect if they + are used w/o being properly assigned to. */ - int sect_index_text; - int sect_index_data; - int sect_index_bss; - int sect_index_rodata; + int sect_index_text = -1; + int sect_index_data = -1; + int sect_index_bss = -1; + int sect_index_rodata = -1; /* These pointers are used to locate the section table, which among other things, is used to map pc addresses into sections. @@ -399,7 +407,8 @@ struct objfile structure data is only valid for certain sections (e.g. non-empty, SEC_ALLOC). */ - struct obj_section *sections, *sections_end; + struct obj_section *sections = nullptr; + struct obj_section *sections_end = nullptr; /* GDB allows to have debug symbols in separate object files. This is used by .gnu_debuglink, ELF build id note and Mach-O OSO. @@ -411,17 +420,17 @@ struct objfile /* Link to the first separate debug object, if any. */ - struct objfile *separate_debug_objfile; + struct objfile *separate_debug_objfile = nullptr; /* If this is a separate debug object, this is used as a link to the actual executable objfile. */ - struct objfile *separate_debug_objfile_backlink; + struct objfile *separate_debug_objfile_backlink = nullptr; /* If this is a separate debug object, this is a link to the next one for the same executable objfile. */ - struct objfile *separate_debug_objfile_link; + struct objfile *separate_debug_objfile_link = nullptr; /* Place to stash various statistics about this objfile. */ @@ -432,7 +441,7 @@ struct objfile table, so we have to keep them here to relocate them properly. */ - struct symbol *template_symbols; + struct symbol *template_symbols = nullptr; /* Associate a static link (struct dynamic_prop *) to all blocks (struct block *) that have one. @@ -445,14 +454,11 @@ struct objfile Very few blocks have a static link, so it's more memory efficient to store these here rather than in struct block. Static links must be allocated on the objfile's obstack. */ - htab_t static_links; + htab_t static_links {}; }; /* Declarations for functions defined in objfiles.c */ -extern struct objfile *allocate_objfile (bfd *, const char *name, - objfile_flags); - extern struct gdbarch *get_objfile_arch (const struct objfile *); extern int entry_point_address_query (CORE_ADDR *entry_p); @@ -470,8 +476,6 @@ extern void add_separate_debug_objfile (struct objfile *, struct objfile *); extern void unlink_objfile (struct objfile *); -extern void free_objfile (struct objfile *); - extern void free_objfile_separate_debug (struct objfile *); extern struct cleanup *make_cleanup_free_objfile (struct objfile *); diff --git a/gdb/solib.c b/gdb/solib.c index e605e6b..f9f7217 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -851,7 +851,7 @@ update_solib_list (int from_tty) /* Unless the user loaded it explicitly, free SO's objfile. */ if (gdb->objfile && ! (gdb->objfile->flags & OBJF_USERLOADED) && !solib_used (gdb)) - free_objfile (gdb->objfile); + delete gdb->objfile; /* Some targets' section tables might be referring to sections from so->abfd; remove them. */ @@ -1334,7 +1334,7 @@ reload_shared_libraries_1 (int from_tty) { if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED) && !solib_used (so)) - free_objfile (so->objfile); + delete so->objfile; remove_target_sections (so); clear_so (so); } diff --git a/gdb/symfile.c b/gdb/symfile.c index c69a474..07d867c 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1018,7 +1018,7 @@ syms_from_objfile_1 (struct objfile *objfile, if (symfile_objfile != NULL) { - free_objfile (symfile_objfile); + delete symfile_objfile; gdb_assert (symfile_objfile == NULL); } @@ -1100,7 +1100,7 @@ finish_new_objfile (struct objfile *objfile, symfile_add_flags add_flags) ABFD is a BFD already open on the file, as from symfile_bfd_open. A new reference is acquired by this function. - For NAME description see allocate_objfile's definition. + For NAME description see the objfile constructor. ADD_FLAGS encodes verbosity, whether this is main symbol file or extra, such as dynamically loaded code, and what to do with breakpoins. @@ -1144,7 +1144,7 @@ symbol_file_add_with_addrs (bfd *abfd, const char *name, if (mainline) flags |= OBJF_MAINLINE; - objfile = allocate_objfile (abfd, name, flags); + objfile = new struct objfile (abfd, name, flags); if (parent) add_separate_debug_objfile (objfile, parent); @@ -1218,7 +1218,7 @@ symbol_file_add_with_addrs (bfd *abfd, const char *name, } /* Add BFD as a separate debug file for OBJFILE. For NAME description - see allocate_objfile's definition. */ + see the objfile constructor. */ void symbol_file_add_separate (bfd *bfd, const char *name, @@ -2377,7 +2377,7 @@ remove_symbol_file_command (const char *args, int from_tty) objfile_name (objf))) error (_("Not confirmed.")); - free_objfile (objf); + delete objf; clear_symtab_users (0); } |