diff options
author | Tom de Vries <tdevries@suse.de> | 2024-10-26 08:40:07 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2024-10-26 08:40:07 +0200 |
commit | 5a43f7f040d45ca1bc0066019131cf71d7836cb8 (patch) | |
tree | 7472785973203b3aba4bf19690e107fd0adc6a30 | |
parent | b3ee98cda498bb256411c5bc23cf7fb9b17f10db (diff) | |
download | gdb-5a43f7f040d45ca1bc0066019131cf71d7836cb8.zip gdb-5a43f7f040d45ca1bc0066019131cf71d7836cb8.tar.gz gdb-5a43f7f040d45ca1bc0066019131cf71d7836cb8.tar.bz2 |
[gdb] Don't create registry keys in destructor
Creating a registry key using emplace calls new:
...
DATA *result = new DATA (std::forward<Args> (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 <tom@tromey.com>
-rw-r--r-- | gdb/ada-tasks.c | 7 | ||||
-rw-r--r-- | gdb/objfiles.c | 13 | ||||
-rw-r--r-- | gdb/solib-svr4.c | 10 | ||||
-rw-r--r-- | gdb/source.c | 20 | ||||
-rw-r--r-- | gdb/source.h | 2 | ||||
-rw-r--r-- | gdb/symtab.c | 2 |
6 files changed, 34 insertions, 20 deletions
diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c index d050b26..5f4eceb 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 0e076fe..555195d 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 7999a8e..8378eca 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 9c54ff2..32099b9 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 33ccda7..f56e7b5 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 a479e92..7b11d43 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. */ |