]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb] Don't create registry keys in destructor
authorTom de Vries <tdevries@suse.de>
Sat, 26 Oct 2024 06:40:07 +0000 (08:40 +0200)
committerTom de Vries <tdevries@suse.de>
Sat, 26 Oct 2024 06:40:07 +0000 (08:40 +0200)
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>
gdb/ada-tasks.c
gdb/objfiles.c
gdb/solib-svr4.c
gdb/source.c
gdb/source.h
gdb/symtab.c

index d050b269815957749f27f11aeded272f12fe6855..5f4eceb9974c3c1a1a452f62e826f904f1f68731 100644 (file)
@@ -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.  */
index 0e076fe36be2ef1c4074871ce639075cff0db05d..555195dc61f9f88aa456ae473d3102a8a0f6b4a4 100644 (file)
@@ -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;
 }
 
 \f
index 7999a8e6c7ed7303a7b516570d814a501a4c6b2e..8378ecaff40d7de199013578f4b58fe869ba43f8 100644 (file)
@@ -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
index 9c54ff24b3aa56b32f5ac2b49cbd4e50adefd3d0..32099b9ea7d0cbfc6ebf7a476f0837ca7b748d38 100644 (file)
@@ -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
index 33ccda727c67be7e918fac7be2a73a95a26ee07d..f56e7b5eb3d6861a07fbd24952a5693dd7a827c5 100644 (file)
@@ -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 *);
index a479e920c60f5e053a3708857ea4f5df82b0e8e1..7b11d43bd70689e93f59171085111a165d77e0d7 100644 (file)
@@ -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.  */