From: Tom de Vries Date: Sat, 26 Oct 2024 06:40:07 +0000 (+0200) Subject: [gdb] Don't create registry keys in destructor X-Git-Tag: gdb-16-branchpoint~593 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5a43f7f040d45ca1bc0066019131cf71d7836cb8;p=thirdparty%2Fbinutils-gdb.git [gdb] Don't create registry keys in destructor Creating a registry key using emplace calls new: ... DATA *result = new DATA (std::forward (args)...); ... which can throw a bad alloc, which will terminate gdb if called from a destructor. Fix this in a few places. Tested on aarch64-linux. Approved-By: Tom Tromey --- diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c index d050b269815..5f4eceb9974 100644 --- a/gdb/ada-tasks.c +++ b/gdb/ada-tasks.c @@ -1447,7 +1447,7 @@ ada_task_list_changed (struct inferior *inf) static void ada_tasks_invalidate_pspace_data (struct program_space *pspace) { - get_ada_tasks_pspace_data (pspace)->initialized_p = 0; + ada_tasks_pspace_data_handle.clear (pspace); } /* Invalidate the per-inferior data. */ @@ -1455,10 +1455,7 @@ ada_tasks_invalidate_pspace_data (struct program_space *pspace) static void ada_tasks_invalidate_inferior_data (struct inferior *inf) { - struct ada_tasks_inferior_data *data = get_ada_tasks_inferior_data (inf); - - data->known_tasks_kind = ADA_TASKS_UNKNOWN; - data->task_list_valid_p = false; + ada_tasks_inferior_data_handle.clear (inf); } /* The 'normal_stop' observer notification callback. */ diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 0e076fe36be..555195dc61f 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -560,17 +560,12 @@ objfile::~objfile () /* Check to see if the current_source_symtab belongs to this objfile, and if so, call clear_current_source_symtab_and_line. */ - - { - symtab_and_line cursal - = get_current_source_symtab_and_line (this->pspace ()); - - if (cursal.symtab && cursal.symtab->compunit ()->objfile () == this) - clear_current_source_symtab_and_line (this->pspace ()); - } + clear_current_source_symtab_and_line (this); /* Rebuild section map next time we need it. */ - get_objfile_pspace_data (m_pspace)->section_map_dirty = 1; + auto info = objfiles_pspace_data.get (pspace ()); + if (info != nullptr) + info->section_map_dirty = 1; } diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 7999a8e6c7e..8378ecaff40 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -1631,10 +1631,12 @@ probes_table_htab_remove_objfile_probes (void **slot, void *info) static void probes_table_remove_objfile_probes (struct objfile *objfile) { - svr4_info *info = get_svr4_info (objfile->pspace ()); - if (info->probes_table != nullptr) - htab_traverse_noresize (info->probes_table.get (), - probes_table_htab_remove_objfile_probes, objfile); + svr4_info *info = solib_svr4_pspace_data.get (objfile->pspace ()); + if (info == nullptr || info->probes_table == nullptr) + return; + + htab_traverse_noresize (info->probes_table.get (), + probes_table_htab_remove_objfile_probes, objfile); } /* Register a solib event probe and its associated action in the diff --git a/gdb/source.c b/gdb/source.c index 9c54ff24b3a..32099b9ea7d 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -300,10 +300,28 @@ set_current_source_symtab_and_line (const symtab_and_line &sal) void clear_current_source_symtab_and_line (program_space *pspace) { - current_source_location *loc = get_source_location (pspace); + current_source_location *loc = current_source_key.get (pspace); + if (loc == nullptr) + return; + loc->set (nullptr, 0); } +/* Reset any information stored about a default file and line to print, if it's + owned by OBJFILE. */ + +void +clear_current_source_symtab_and_line (objfile *objfile) +{ + current_source_location *loc = current_source_key.get (objfile->pspace ()); + if (loc == nullptr) + return; + + if (loc->symtab () != nullptr + && loc->symtab ()->compunit ()->objfile () == objfile) + clear_current_source_symtab_and_line (objfile->pspace ()); +} + /* See source.h. */ void diff --git a/gdb/source.h b/gdb/source.h index 33ccda727c6..f56e7b5eb3d 100644 --- a/gdb/source.h +++ b/gdb/source.h @@ -25,6 +25,7 @@ struct program_space; struct symtab; struct symtab_and_line; +struct objfile; /* See openp function definition for their description. */ @@ -132,6 +133,7 @@ extern symtab_and_line set_current_source_symtab_and_line /* Reset any information stored about a default file and line to print. */ extern void clear_current_source_symtab_and_line (program_space *pspace); +extern void clear_current_source_symtab_and_line (objfile *objfile); /* Add a source path substitution rule. */ extern void add_substitute_path_rule (const char *, const char *); diff --git a/gdb/symtab.c b/gdb/symtab.c index a479e920c60..7b11d43bd70 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -1756,7 +1756,7 @@ symtab_all_objfiles_removed (program_space *pspace) symbol_cache_flush (pspace); /* Forget everything we know about the main function. */ - set_main_name (pspace, nullptr, language_unknown); + main_progspace_key.clear (pspace); } /* This module's 'free_objfile' observer. */