[v2,1/3] Add new commands for controlling type signature fallback.

Message ID 926f5f9ee52488362639ba9eb8eda9f9b97cce85.1741792976.git.dominik.mascherbauer@oracle.com
State New
Headers
Series DWARF type signature lookup fallback. |

Checks

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

Commit Message

Dominik Mascherbauer March 12, 2025, 3:37 p.m. UTC
  'set dwarf-type-signature-fallback (off|main|full)':
Enable type signature fallback.
If a type signature is not found in the current objfile, either looks up the 'main' objfile or all objfiles in a progspace to find the type signature.
Usually a type signature is unique, ther should only be one type unit for each type signature.
Therefore, it should be okay to check other objfile for a type signature.
However, whether this is really the case depends on the debug info producer.
This is why its disabled by default.

'set dwarf-type-signature-fallback-jit':
Whether the type signature fallback is enabled for only JIT objfiles.
JIT objfiles are self-contained, but usually share most debug info with some already loaded objfile.
This is why JIT objfiles are a major use case for the type signature fallback.
This option is added to restrict the type signature fallback to match this exact use-case and provides a more granular use of the type signature fallback.
---
 gdb/NEWS            | 21 ++++++++++++++
 gdb/doc/gdb.texinfo | 34 ++++++++++++++++++++++
 gdb/dwarf2/read.c   | 71 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 126 insertions(+)
  

Comments

Eli Zaretskii March 12, 2025, 3:43 p.m. UTC | #1
> From: dominikmascherbauer <dominik.mascherbauer@gmail.com>
> Cc: dominikmascherbauer <dominik.mascherbauer@oracle.com>
> Date: Wed, 12 Mar 2025 16:37:06 +0100
> 
> 'set dwarf-type-signature-fallback (off|main|full)':
> Enable type signature fallback.
> If a type signature is not found in the current objfile, either looks up the 'main' objfile or all objfiles in a progspace to find the type signature.
> Usually a type signature is unique, ther should only be one type unit for each type signature.
> Therefore, it should be okay to check other objfile for a type signature.
> However, whether this is really the case depends on the debug info producer.
> This is why its disabled by default.
> 
> 'set dwarf-type-signature-fallback-jit':
> Whether the type signature fallback is enabled for only JIT objfiles.
> JIT objfiles are self-contained, but usually share most debug info with some already loaded objfile.
> This is why JIT objfiles are a major use case for the type signature fallback.
> This option is added to restrict the type signature fallback to match this exact use-case and provides a more granular use of the type signature fallback.
> ---
>  gdb/NEWS            | 21 ++++++++++++++
>  gdb/doc/gdb.texinfo | 34 ++++++++++++++++++++++
>  gdb/dwarf2/read.c   | 71 +++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 126 insertions(+)

Thanks, the documentation parts are okay.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
  

Patch

diff --git a/gdb/NEWS b/gdb/NEWS
index 2c504a9b603..58b2f6400b5 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -261,6 +261,27 @@  disable missing-objfile-handler LOCUS HANDLER
   or can be a regular expression which is matched against the filename
   of the primary executable in each program space.
 
+set dwarf-type-signature-fallback (off|main|full)
+  New command which enables a type signature look up fallback for DWARF objfiles.
+  If type signatures in DWARF objfile are unique, enabling this option allows
+  to look up type signatures from fallback DWARF objfiles.  Reusing type units
+  from fallback objfiles can be used to avoid duplicating those type units.
+
+  The 'main' setting allows limiting the scope of the lookup to just the main
+  symfile objfile to reduce the overhead of type signature lookup.  The 'full'
+  setting uses all objfiles in a progspace to find as many type signatures as
+  possible.
+  The default value is 'off'.
+
+set dwarf-type-signature-fallback-jit on|off
+  New command that is used in combination with dwarf-type-signature-fallback
+  and is on by default.  If type signature fallback is enabled,
+  this restricts the fallback to objfiles that were loaded with the
+  JIT debug interface.
+  JIT objfiles are produced at run-time and often rely on already available
+  type information.  This allows the debug info producer to skip generating type
+  units that are known to be present in other objfiles.
+
 * Changed commands
 
 remove-symbol-file
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 04719bf65e6..df343f9fdd8 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -42325,6 +42325,40 @@  Symbol "argc" is a complex DWARF expression:
 For more information on these expressions, see
 @uref{http://www.dwarfstd.org/, the DWARF standard}.
 
+@kindex set dwarf-type-signature-fallback
+@kindex show dwarf-type-signature-fallback
+@item set dwarf-type-signature-fallback @samp{full|main|off}
+@itemx show dwarf-type-signature-fallback
+Control the behavior of the type signature look up in DWARF objfiles.  Type
+Signatures in DWARF uniquely identify a type unit.  A type unit contains debug
+info for a type and can be referenced by its type signature.  Type signature
+look up allows @value{GDBN} to look up type signatures not only in objfile
+containing the reference to a type signature, but also other type signatures
+in the progspace.  This allows to avoid duplicating type units, by looking them
+up from other DWARF objfiles.
+
+The default is @code{off}, which means @value{GDBN} will not use other
+objfiles in the progspace to look up missing type signatures.  When
+@code{main}, @value{GDBN} will check the current main symfile objfile for a
+missing signatured type.  If the main symfile objfile contains most of the
+debug info required for debugging, this setting reduces the impact of type
+signature look up.  When @code{full}, all DWARF objfiles in the current
+progspace will be searched for the missing signatured type.
+
+@kindex set dwarf-type-signature-fallback-jit
+@kindex show dwarf-type-signature-fallback-jit
+@item set dwarf-type-signature-fallback-jit
+@itemx show dwarf-type-signature-fallback-jit
+Control whether @code{dwarf-type-signature-fallback} is limited to DWARF
+objfiles originated from the JIT interface (@pxref{JIT Interface})
+or all DWARF objfiles with a missing signatured type.  If only objfiles loaded
+through the JIT interface rely on existing types and type units this
+setting allows limiting type signature look up to avoid undesired behavior.
+
+The default is @code{on}, which limits the type signature fallback to
+only DWARF objfiles from the JIT interface.  When @code{off}, type signature
+look up is performed for missing signatured types in all DWARF objfiles.
+
 @kindex maint set dwarf max-cache-age
 @kindex maint show dwarf max-cache-age
 @item maint set dwarf max-cache-age
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index c5375b68567..3fdaf003fb7 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -737,6 +737,50 @@  show_dwarf_max_cache_age (struct ui_file *file, int from_tty,
 	      value);
 }
 
+/* If the type for a type signature is not found in the CUs objfile
+   fallback to other objfiles for type signature look up */
+const char type_signature_fallback_off[] = "off";
+const char type_signature_fallback_main[] = "main";
+const char type_signature_fallback_full[] = "full";
+static const char *type_signature_fallback_enums[] =
+	{
+		type_signature_fallback_off,
+		type_signature_fallback_main,
+		type_signature_fallback_full,
+		nullptr
+	};
+static const char *type_signature_fallback = type_signature_fallback_off;
+
+static void
+show_type_signature_fallback (struct ui_file *file, int from_tty,
+			      struct cmd_list_element *c, const char *value)
+{
+  gdb_printf (file, _ ("Look up of type signatures with "
+		       "other DWARF objfiles as fallback is %s.\n"),
+	      value);
+}
+
+/* Type signature fallback is by default restricted to only jit objfiles.  */
+static bool type_signature_fallback_jit = true;
+
+static void
+show_type_signature_fallback_jit (struct ui_file *file, int from_tty,
+				  struct cmd_list_element *c, const char *value)
+{
+  gdb_printf (file, _ ("Whether type signature look up with other"
+		       "DWARF objfiles as fallback is restricted to"
+		       "objfiles loaded through the JIT interface is %s.\n"),
+	      value);
+}
+
+/* Check if type signature fallback applies to OBJFILE.  */
+static bool
+use_type_signature_fallback (struct objfile *objfile)
+{
+  return type_signature_fallback != type_signature_fallback_off &&
+	 (!type_signature_fallback_jit || objfile->flags & OBJF_JIT);
+}
+
 /* When true, wait for DWARF reading to be complete.  */
 static bool dwarf_synchronous = false;
 
@@ -20103,6 +20147,33 @@  caching, which can slow down startup."),
 			    &set_dwarf_cmdlist,
 			    &show_dwarf_cmdlist);
 
+  add_setshow_enum_cmd ("dwarf-type-signature-fallback", class_support,
+			type_signature_fallback_enums, &type_signature_fallback,
+			_ ("\
+Set look up of type signatures with other DWARF objfiles as fallback."), _ ("\
+Show look up of type signatures with other DWARF objfiles as fallback."), _ ("\
+This option will only take effect if set before loading symbols.\n\
+main == use the main symbolfile as fallback objfile\n\
+	for type signature look up.\n\
+full == use all DWARF objfiles with type units in the current progspace\n\
+	as fallback objfiles for type signature look up.\n\
+off  == turn type signature fallback off."),
+			NULL, show_type_signature_fallback, &setlist,
+			&showlist);
+
+  add_setshow_boolean_cmd ("dwarf-type-signature-fallback-jit", class_support,
+			&type_signature_fallback_jit,
+			_ ("\
+Set whether look up of type signatures with other DWARF objfiles as fallback\n\
+is restricted to objfiles loaded through the JIT interface."), _ ("\
+Show whether look up of type signatures with other DWARF objfiles as fallback\n\
+is restricted to objfiles loaded through the JIT interface."), _ ("\
+By default, type signature look up with other DWARF objfiles as fallback is\n\
+restricted to objfiles loaded through the JIT interface.\n\
+This option will only take effect if type-signature-fallback is enabled."),
+			NULL, show_type_signature_fallback_jit, &setlist,
+			&showlist);
+
   add_setshow_boolean_cmd ("synchronous", class_obscure,
 			    &dwarf_synchronous, _("\
 Set whether DWARF is read synchronously."), _("\