From patchwork Wed Mar 12 15:37:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominik Mascherbauer X-Patchwork-Id: 107784 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3BE453857C6D for ; Wed, 12 Mar 2025 15:39:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3BE453857C6D Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ERkMCZgr X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id D01683858C5F for ; Wed, 12 Mar 2025 15:37:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D01683858C5F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D01683858C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::535 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741793838; cv=none; b=FXgDJ0gmjiFxvX0drqIasCtO+2xOh35uCSHWuawdfZHva6y9qxYo41wS9BjwC3FVWwil3vuyudGzKzCQIW6mjIPM7480djtOcGJl+Ze2Rox+ZmO9NQZNG/DKgI8pMPzU91ljw7KJ92qc5tV1odTSRVIEzocPSdFP/ct1yNWSXfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741793838; c=relaxed/simple; bh=vyyi8sjoEmF+hYBMMyUS/uf7/PYlYIgNaz2cyuB7Es4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=UCQB28xsjL0S5GWj70KNpRPy1GvPr+e3Xw7q5jSFddx7gP75qVqSwSUYwKBG7si1PWdEduKiwCl3rkEz8g7dfCBOYl1fYZQpE3VcWzO7Ya65yVXf2ooS1uLZiqJcWTVuIfZZqFwXpMMeuBgjEGb8MNl3v4betdt6LQsUCOVOiNc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D01683858C5F Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5e677f59438so6598717a12.2 for ; Wed, 12 Mar 2025 08:37:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741793836; x=1742398636; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i6NoLaCB1lvfPlLIifq6obvnK+ZtClqItHU3dumTleI=; b=ERkMCZgraJ4ckmUBZgOXfmCBNp9A3in/E9JxZjesNOfatd/s/Rnt3zlTvnJrHquLsd JBVR+kTb94BoQUi791qpr15mIsvN0qZO/ZVKE5Gjw9bYvFhj2fcdxggbTCcA6HLNS9wI YjWNN2Ox2cmWPjsgCxLiSu0NsO2idNjbwarUINrb/t9rh3DT/mgkaR5gn2ynQbRxLQwC uXh+s1t9N9phmAtkzc0hzYi8Q6oSndhS0V+g20OBqGUBjsLn/3YNE+CJSLqPJqmMFZyU OsMO6XBk/7wCzQhWTV4G7/YcqImroYzj5dFqSejg2v8PBnkvxOh+Nj30E17zPN7MTz9T kJAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741793836; x=1742398636; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i6NoLaCB1lvfPlLIifq6obvnK+ZtClqItHU3dumTleI=; b=Y6+DlaX4VjZ46zk4TWJxAH4F+Bu0W3FxcIYoJBPtlqxtO59sU8q0G1n81dd+8kz7j0 Li4YIK/ut+42tj6BZj83B2PSKOmUfPzr3l890d0FxSC0jkbDrfT+T+VwgKzUDJ0B6Uq6 UaD5ia5lZs0sYEgpfHQD4glTJemIKYk4KUEHMBLPZ4P0SEIjQF1bttWxuVTlR0oshwdj d68Jy6VHI8f9/UDxpQtQSpZTuj/BT1POIu2ayGI3elaoEfKI+57U/+twUxdzhaFg9mZm VR+bSmDVUHSQijKTVgn9LKPYyHUTFB3iBSZGXxRgrLsAgIQTg9n5VyK/0+eoIRKoDBbA NM6w== X-Gm-Message-State: AOJu0YzCBH5n9RrcGqSw07A8NGiOCPM36zY5a70LIYLC/PZ42oUtlpHm vRR4CN8Le9Zu8DgISOOsPYiYGEMrcYzOxptT0pWhjZHzaDelzLyAaLjUTCet9U0= X-Gm-Gg: ASbGncuv/8Betk6riJBH9zvbHCyH1mHH4tsavTX8gpH7ZML+qSiYeCVhkmCimeNOuRZ A2/8/LojwajxFGiEz3JmMemOOzZlZxNDluEfmwcNf2Inq64zJ0qn1RXHbaApadhTazxTrKaX5Dl TN4zL8tSv9KTPwEztLCO/lznMylqOLamw9BxydP2rtx7iTcbDr660D4Zi0nReugxLVm2bpPiLuD qLW+MaO9rtaMX6KGAa694R3rHUEjagUsMggb4f7IeaZcUvbBqSxUDgbgZFlY5i3wa1hsWsMQmeF qaQcx2gmwphs1Xq+lKOFT9JNcNebKfFtKj9WvOrEbosaqqzP116791yZWtTWA7XU5O8Z X-Google-Smtp-Source: AGHT+IF/nUBowPab/nHT7jGkFvIaIb2VgFH28591Ji2rK5UUlxYvRga7IP0YCHNxc9IMNYFni6EobA== X-Received: by 2002:a05:6402:270f:b0:5de:cbed:c955 with SMTP id 4fb4d7f45d1cf-5e5e2309644mr27015157a12.17.1741793835260; Wed, 12 Mar 2025 08:37:15 -0700 (PDT) Received: from pop-os.ssw.jku.at ([140.78.145.202]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e5c74a6af7sm9888800a12.33.2025.03.12.08.37.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 08:37:14 -0700 (PDT) From: dominikmascherbauer X-Google-Original-From: dominikmascherbauer To: gdb-patches@sourceware.org Cc: dominikmascherbauer Subject: [PATCH v2 1/3] Add new commands for controlling type signature fallback. Date: Wed, 12 Mar 2025 16:37:06 +0100 Message-Id: <926f5f9ee52488362639ba9eb8eda9f9b97cce85.1741792976.git.dominik.mascherbauer@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org '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. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 21 ++++++++++++++ gdb/doc/gdb.texinfo | 34 ++++++++++++++++++++++ gdb/dwarf2/read.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) 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."), _("\