[review,v2] Turn off threaded minsym demangling by default

Message ID 20191126215322.10AAD20AF6@gnutoolchain-gerrit.osci.io
State New, archived
Headers

Commit Message

Simon Marchi (Code Review) Nov. 26, 2019, 9:53 p.m. UTC
  Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/687
......................................................................

Turn off threaded minsym demangling by default

Per discussion on gdb-patches with Joel, this patch turns off multihreaded
symbol loading by default. It can be turned on using:
  maint set worker-threads unlimited

To keep the behavior as close as possible to the old code, it still
calls symbol_set_names in the old place if n_worker_threads is 0.

gdb/ChangeLog:

2019-11-18  Christian Biesinger  <cbiesinger@google.com>

	* maint.c (n_worker_threads): Default to 0.
	(worker_threads_disabled): New function.
	* maint.h (worker_threads_disabled): New function.
	* minsyms.c (minimal_symbol_reader::record_full): Call symbol_set_names
	here if worker_threads_disabled () is true.
	(minimal_symbol_reader::install): Skip all threading if
	worker_threads_disabled () is true.

Change-Id: I92ba4f6bbf07363189666327cad452d6b9c8e01d
---
M gdb/maint.c
M gdb/maint.h
M gdb/minsyms.c
3 files changed, 23 insertions(+), 4 deletions(-)
  

Patch

diff --git a/gdb/maint.c b/gdb/maint.c
index 7ab3fdb..dbc949a 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -845,7 +845,12 @@ 
 }
 #endif
 
-static int n_worker_threads = -1;
+static int n_worker_threads = 0;
+
+bool worker_threads_disabled ()
+{
+  return n_worker_threads == 0;
+}
 
 /* Update the thread pool for the desired number of threads.  */
 static void
diff --git a/gdb/maint.h b/gdb/maint.h
index 827964d..cbaf9de 100644
--- a/gdb/maint.h
+++ b/gdb/maint.h
@@ -26,6 +26,8 @@ 
 
 extern void set_per_command_space (int);
 
+extern bool worker_threads_disabled ();
+
 /* Records a run time and space usage to be used as a base for
    reporting elapsed time or change in space.  */
 
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index b752b3a..de8cb78 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -54,6 +54,7 @@ 
 #include <algorithm>
 #include "safe-ctype.h"
 #include "gdbsupport/parallel-for.h"
+#include "maint.h"
 
 #if CXX_STD_THREAD
 #include <mutex>
@@ -1137,6 +1138,15 @@ 
   else
     msymbol->name = name.data ();
 
+  if (worker_threads_disabled ())
+    {
+      /* To keep our behavior as close as possible to the previous non-threaded
+	 behavior for GDB 9.1, we call symbol_set_names here when threads
+	 are disabled.  */
+      symbol_set_names (msymbol, msymbol->name, false, m_objfile->per_bfd);
+      msymbol->name_set = 1;
+    }
+
   SET_MSYMBOL_VALUE_ADDRESS (msymbol, address);
   MSYMBOL_SECTION (msymbol) = section;
 
@@ -1401,10 +1411,12 @@ 
 		     (msym, demangled_name,
 		      &m_objfile->per_bfd->storage_obstack);
 		   msym->name_set = 1;
-
-		   hash_values[idx].mangled_name_hash
-		     = fast_hash (msym->name, hash_values[idx].name_length);
 		 }
+	       /* This mangled_name_hash computation has to be outside of
+		  the name_set check, or symbol_set_names below will
+		  be called with an invalid hash value.  */
+	       hash_values[idx].mangled_name_hash
+		 = fast_hash (msym->name, hash_values[idx].name_length);
 	       hash_values[idx].minsym_hash
 		 = msymbol_hash (msym->linkage_name ());
 	       hash_values[idx].minsym_demangled_hash