aboutsummaryrefslogtreecommitdiff
path: root/gdb/source.c
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2024-10-26 08:40:07 +0200
committerTom de Vries <tdevries@suse.de>2024-10-26 08:40:07 +0200
commit5a43f7f040d45ca1bc0066019131cf71d7836cb8 (patch)
tree7472785973203b3aba4bf19690e107fd0adc6a30 /gdb/source.c
parentb3ee98cda498bb256411c5bc23cf7fb9b17f10db (diff)
downloadbinutils-5a43f7f040d45ca1bc0066019131cf71d7836cb8.zip
binutils-5a43f7f040d45ca1bc0066019131cf71d7836cb8.tar.gz
binutils-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>
Diffstat (limited to 'gdb/source.c')
-rw-r--r--gdb/source.c20
1 files changed, 19 insertions, 1 deletions
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