[06/15] Add "maint set dwarf synchronous"

Message ID 20231029173839.471514-7-tom@tromey.com
State New
Headers
Series Index DWARF in the background |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Testing failed
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Testing failed

Commit Message

Tom Tromey Oct. 29, 2023, 5:35 p.m. UTC
  For testing, it's sometimes convenient to be able to request that
DWARF reading be done synchronously.  This patch adds a new "maint"
setting for this purpose.
---
 gdb/NEWS            |  3 +++
 gdb/doc/gdb.texinfo | 14 ++++++++++++++
 gdb/dwarf2/read.c   | 23 +++++++++++++++++++++++
 3 files changed, 40 insertions(+)
  

Comments

Eli Zaretskii Oct. 29, 2023, 5:50 p.m. UTC | #1
> From: Tom Tromey <tom@tromey.com>
> Cc: Tom Tromey <tom@tromey.com>
> Date: Sun, 29 Oct 2023 11:35:25 -0600
> 
> For testing, it's sometimes convenient to be able to request that
> DWARF reading be done synchronously.  This patch adds a new "maint"
> setting for this purpose.
> ---
>  gdb/NEWS            |  3 +++
>  gdb/doc/gdb.texinfo | 14 ++++++++++++++
>  gdb/dwarf2/read.c   | 23 +++++++++++++++++++++++
>  3 files changed, 40 insertions(+)

Thanks.

> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -9,6 +9,9 @@
>  * GDB index now contains information about the main function.  This speeds up
>    startup when it is being used for some large binaries.
>  
> +* DWARF reading is now done in the background, resulting in faster startup.
> +  This can be controlled using "maint set dwarf synchronous".

I'm guessing this isn't supported in all build configurations, and if
so, this text should say so, and should give some indication which
configurations don't support this feature.

> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -41692,6 +41692,20 @@ compilation units will be stored in memory longer, and more total
>  memory will be used.  Setting it to zero disables caching, which will
>  slow down @value{GDBN} startup, but reduce memory consumption.
>  
> +@kindex maint set dwarf synchronous
> +@kindex maint show dwarf synchronous
> +@item maint set dwarf synchronous
> +@itemx maint show dwarf synchronous
> +Control whether DWARF is read asynchronously.
> +
> +By default, the DWARF reader is mostly asynchronous with respect to
> +the rest of @value{GDBN}.  That is, the bulk of the reading is done in
> +the background, and @value{GDBN} will only pause for completion of
> +this task when absolutely necessary.
> +
> +When this setting is enabled, @value{GDBN} will instead wait for DWARF
> +processing to complete before continuing.

Same here.  I'm guessing on platforms where this doesn't work, this
setting doesn't have effect, and the default value is "synchronous"?

> +/* Wait for DWARF reading to be complete.  */
> +static bool dwarf_synchronous = false;
> +static void
> +show_dwarf_synchronous (struct ui_file *file, int from_tty,
> +			struct cmd_list_element *c, const char *value)
> +{
> +  gdb_printf (file, _("Whether DWARF reading is synchronous is %s.\n"),
> +	      value);
> +}

The comment seems to describe a different function?

> +  add_setshow_boolean_cmd ("synchronous", class_obscure,
> +			    &dwarf_synchronous, _("\
> +Set whether DWARF is read synchronously."), _("\
> +Show DWARF is read synchronously."), _("\
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
"Show whether DWARF is read synchronously."

> +By default, DWARF information is read in worker threads,\n\
> +and gdb will not generally wait for this process to complete.\n\
> +Enabling this setting will cause the DWARF reader to always wait\n\
> +for completion before gdb can proceed."),

This could use some clarifications.  The "wait for this process to
complete" and "wait for completion before gdb can proceed" parts are
somewhat mysterious: what exactly does "proceed" mean, and when it is
important to wait for this to complete?

IOW, this doc string leaves unsaid what processing needs DWARF reading
to complete.
  
Eli Zaretskii Nov. 23, 2023, 6:08 a.m. UTC | #2
> From: Tom Tromey <tom@tromey.com>
> Cc: Tom Tromey <tom@tromey.com>,  gdb-patches@sourceware.org
> Date: Wed, 22 Nov 2023 10:59:27 -0700
> 
> >>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:
> 
> Eli> I'm guessing this isn't supported in all build configurations, and if
> Eli> so, this text should say so, and should give some indication which
> Eli> configurations don't support this feature.
> 
> It's somewhat hard to know.  Anybody can disable it at configure time,
> and of course there's the mingw situation -- but even that is
> complicated because I know working setups exist, just not universally.

OK, but at least let's mention that some builds don't support
threading in GDB, and those will always behave synchronously.
  

Patch

diff --git a/gdb/NEWS b/gdb/NEWS
index 95663433f1c..088651a359b 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -9,6 +9,9 @@ 
 * GDB index now contains information about the main function.  This speeds up
   startup when it is being used for some large binaries.
 
+* DWARF reading is now done in the background, resulting in faster startup.
+  This can be controlled using "maint set dwarf synchronous".
+
 * Python API
 
   ** New function gdb.notify_mi(NAME, DATA), that emits custom
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index db1a82ec838..78fe5a27ff5 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -41692,6 +41692,20 @@  compilation units will be stored in memory longer, and more total
 memory will be used.  Setting it to zero disables caching, which will
 slow down @value{GDBN} startup, but reduce memory consumption.
 
+@kindex maint set dwarf synchronous
+@kindex maint show dwarf synchronous
+@item maint set dwarf synchronous
+@itemx maint show dwarf synchronous
+Control whether DWARF is read asynchronously.
+
+By default, the DWARF reader is mostly asynchronous with respect to
+the rest of @value{GDBN}.  That is, the bulk of the reading is done in
+the background, and @value{GDBN} will only pause for completion of
+this task when absolutely necessary.
+
+When this setting is enabled, @value{GDBN} will instead wait for DWARF
+processing to complete before continuing.
+
 @kindex maint set dwarf unwinders
 @kindex maint show dwarf unwinders
 @item maint set dwarf unwinders
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index e8cd4496395..8ee6c6d4762 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -739,6 +739,16 @@  show_dwarf_max_cache_age (struct ui_file *file, int from_tty,
 		      "DWARF compilation units is %s.\n"),
 	      value);
 }
+
+/* Wait for DWARF reading to be complete.  */
+static bool dwarf_synchronous = false;
+static void
+show_dwarf_synchronous (struct ui_file *file, int from_tty,
+			struct cmd_list_element *c, const char *value)
+{
+  gdb_printf (file, _("Whether DWARF reading is synchronous is %s.\n"),
+	      value);
+}
 
 /* local function prototypes */
 
@@ -21899,6 +21909,19 @@  caching, which can slow down startup."),
 			    &set_dwarf_cmdlist,
 			    &show_dwarf_cmdlist);
 
+  add_setshow_boolean_cmd ("synchronous", class_obscure,
+			    &dwarf_synchronous, _("\
+Set whether DWARF is read synchronously."), _("\
+Show DWARF is read synchronously."), _("\
+By default, DWARF information is read in worker threads,\n\
+and gdb will not generally wait for this process to complete.\n\
+Enabling this setting will cause the DWARF reader to always wait\n\
+for completion before gdb can proceed."),
+			    nullptr,
+			    show_dwarf_synchronous,
+			    &set_dwarf_cmdlist,
+			    &show_dwarf_cmdlist);
+
   add_setshow_zuinteger_cmd ("dwarf-read", no_class, &dwarf_read_debug, _("\
 Set debugging of the DWARF reader."), _("\
 Show debugging of the DWARF reader."), _("\