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."), _("\ From patchwork Wed Mar 12 15:37:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominik Mascherbauer X-Patchwork-Id: 107786 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 1E3A63858D21 for ; Wed, 12 Mar 2025 15:41:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E3A63858D21 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=hKzyOlsU X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by sourceware.org (Postfix) with ESMTPS id 7ED833858401 for ; Wed, 12 Mar 2025 15:37:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7ED833858401 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 7ED833858401 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::530 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741793838; cv=none; b=fRz9s1aTtkxOlD8uRC/Hhxe6y3ZgAlO8AS1bvEDNuKiwiRdKjAkVnYEY1QfIshQrWRtbXKwFobd5CBs3nqHpKRlrhwzcpHT+Fh6SqEiTYxjdwol+clDqtB6g5dBcX0yJ7Fri7nChMOv7AKet4js/gmuo+oXWrRbdoLQ4/rcVVvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741793838; c=relaxed/simple; bh=dnqrLnu/21LOgLyDUd+2yrFIFUre7aG4WRIEoG8LLAc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=oJwjUJ77PRPYvxgIDA7vYOO43OjA3yENM3cV4PDNowsRXVNN5gUhpa0V4f4Sd51POPJ6kqUFdFEVKFZ3gcGrmaGxuqPwR0fkPWoiHEaICHRUfWYvBavtbt2Q9Rw3aFOO14coLZlfkb760vw/+FdEIW/9I3MvV0LMygmiz1vRjns= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7ED833858401 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-5e56b229d60so2034817a12.0 for ; Wed, 12 Mar 2025 08:37:18 -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=uyS1MkzXOJ3u6HS3U8wX4MP1Qc/JSFAuGfC8X/8g/pI=; b=hKzyOlsUuy6OON1043x0p2Loqt/XNv62v69Z1M3wOKyXOI/a1+FjnoSWUpaTtLkPI4 jJz9PssXWf34PrU4Mfp60CldhlLcTQ+UiAWW2h9zY6Kz3CiODCx97rDHo/zHG57zVWoI G1FjchCBgxJF4mnYXPJ+8d5UJA5g1a7bgGy3WpDbdsK9uS1Bznq+vBgwwxpPOo143RD7 VoVz7l1GPI+nufFBz3LkQIN+54vhS/eMdtmDZhkgThpOoUXFDS5jzbgR4m9Cpw+oMtl6 DZAt9H6b3pIjl4J/VhqU4v6CUOTN8bKjmgAGjYRBQ7mEgencGs5y5sz5Rh9ZA2VWC/yb +Vig== 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=uyS1MkzXOJ3u6HS3U8wX4MP1Qc/JSFAuGfC8X/8g/pI=; b=Eia62bmXS7GsUX0vL1CG3AQcpEz44R/JOzioIXsWu4MAIkEHJIi0aZSvtPEhFYa06p FYaEK9+zOCDO+HFdVoFP4Rtq+6t+5+NYnCWx349elQMqDyGlBSrbi4vH3V27oCzsmsGS cNNLdkEFoaQ4tAZDzf7oqvQRheaoyhs/3K75h8tSobad8aJNub+OKHt4PU8DXupDgWGW /X3sLNeoJums5lB6WhbvCemu75I+mrZI7j/HoldhjoraIKRa23KKARKQNM9I0pneGLK1 Z4jjGyZbv/WT9MSQVsvLo18DrzmERIwrCzowm6+e/DVaxF1Y9r9uAJ2OobmIltlExqSk RDQA== X-Gm-Message-State: AOJu0YwR23ncIAXe+9qY2fOivDd5GTiBkSQDEX2HPGmyYpUYjxv5Pio2 kfSyDyqYt69eAVyT1dKmW4594JI7sabYSylpsR5rE+2V2cY2uFtvT/4y9NeEQ2k= X-Gm-Gg: ASbGncs/cG1edZ/r0nJ0vAeeGESea9ILgpxOBCWeHuA1t8UfD5SN9MgF9B8UsKTuLbG logV2jnXJFUxVsssfJ+TYQsHnWkROJSkdEdRyCjBS7+BBhqFJv4uB+TZt3KsRoSuyDFkadB1A7D 8i1Y8LFeFpWSEw3NAyJ3hGyI3rn7CctMV6sFQSP+PNoy3vkq5yrRB+CtY2JYFonEUVu+g+vEMY6 lLyQ5n60xmQZC8rPNOktT7g/PCK75OGMOoMsf/HUr0+se0iPJnQO3Pt4wHitmXjQfIpMbhFu+sj Y6a89v45QwTt/2MBtDjNOOLCJMC4Vb7ZQIVkmy0nS/e35u5xsj2RCZWy63s/w0JsQEGc X-Google-Smtp-Source: AGHT+IGvjEcD3lHgPBhq/Si14qH6tXe/yUDkNIlTSHkIAJi5/HxA6tXTeeJY5MAt7zmc1OkoGebh9w== X-Received: by 2002:a05:6402:348e:b0:5e4:d27a:d868 with SMTP id 4fb4d7f45d1cf-5e7f6e65d3dmr253122a12.0.1741793835955; 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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 08:37:15 -0700 (PDT) From: dominikmascherbauer X-Google-Original-From: dominikmascherbauer To: gdb-patches@sourceware.org Cc: dominikmascherbauer Subject: [PATCH v2 2/3] Add type signature fallback and JIT objfile restriction. Date: Wed, 12 Mar 2025 16:37:07 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 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 To support type signature fallback, the lookup_signatured_type method is extended. If no type signature was found in the current objfile or in a dwo file, the dwraf-type-signature-fallback option is checked: 'off': return nullptr 'main': only check the current main objfile for the type signature. This reduces the additional load for a fallback as only one additional objfile is checked. The main objfile often contains major parts of the debug info, thus it is also likely that the requested type signature is found there. If the main objfile is linked to dwo/dwp files, those are also checked for the type signature. This should be the same behavior as if the type signature is lookup up without fallback. 'full': check all objfiles in the current prospace. Requires potentially more time than just checking the main objfile, but it will also find a type signature in a loaded shared library. If a type signature was found in a fallback objfile, the per_objfile after lookup_signatured_type is the fallback per_objfile. This ensures that if the type unit still needs to be read, it is read from the correct objfile. Additionally, a flag is added to objfiles that marks an objfile as a JIT objfile. With this information the type signature fallback can be restricted to only work for JIT objfiles. This is a separate option because JIT objfile are self-contained but usually share debug info (especially type information) with some other already loaded objfile. So this leaves loading other objfiles as is to avoid unexpected behavior if needed. --- gdb/dwarf2/read.c | 184 +++++++++++++++++++++++++++++++++++++------- gdb/jit.c | 6 +- gdb/objfile-flags.h | 3 + 3 files changed, 162 insertions(+), 31 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 3fdaf003fb7..4b86acec772 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2669,12 +2669,12 @@ fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile *per_objfile, to read all the DWOs to build the type unit groups. */ static struct signatured_type * -lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) +lookup_dwo_signatured_type (struct dwo_unit *dwo_unit, ULONGEST sig, + struct dwarf2_per_objfile *per_objfile) { - dwarf2_per_objfile *per_objfile = cu->per_objfile; dwarf2_per_bfd *per_bfd = per_objfile->per_bfd; - gdb_assert (cu->dwo_unit); + gdb_assert (dwo_unit); /* We only ever need to read in one copy of a signatured type. Use the global signatured_types array to do our own comdat-folding @@ -2697,14 +2697,14 @@ lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) && (*sig_type_it)->tu_read) return *sig_type_it; - /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the + /* Note: dwo_unit is the dwo_unit that references this TU, not the dwo_unit of the TU itself. */ - dwo_file *dwo_file = cu->dwo_unit->dwo_file; + dwo_file *dwo_file = dwo_unit->dwo_file; auto it = dwo_file->tus.find (sig); if (it == dwo_file->tus.end ()) return nullptr; - dwo_unit *dwo_entry = *it; + struct dwo_unit *dwo_entry = *it; /* If the global table doesn't have an entry for this TU, add one. */ if (sig_type_it == per_bfd->signatured_types.end ()) @@ -2724,13 +2724,12 @@ lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) it won't be in .gdb_index. */ static struct signatured_type * -lookup_dwp_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) +lookup_dwp_signatured_type (ULONGEST sig, + struct dwarf2_per_objfile *per_objfile) { - dwarf2_per_objfile *per_objfile = cu->per_objfile; dwarf2_per_bfd *per_bfd = per_objfile->per_bfd; struct dwp_file *dwp_file = get_dwp_file (per_objfile); - gdb_assert (cu->dwo_unit); gdb_assert (dwp_file != NULL); auto sig_type_it = per_bfd->signatured_types.find (sig); @@ -2756,34 +2755,133 @@ lookup_dwp_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) return *sig_type_it; } +/* Subroutine of lookup_signatured_type. + Look up the type for signature SIG, from a fallback objfile. + If we don't have a DWO/DWP file or can't find the signature there, check the + fallback object file. + If a signatured type was found, PER_OBJFILE will contain its per_objfile. */ + +static struct signatured_type * +lookup_fallback_signatured_type (struct objfile *fallback_objfile, ULONGEST sig, + struct dwarf2_per_objfile **per_objfile) +{ + struct signatured_type *sig_type = nullptr; + + /* If we have a separate debug objfile, use it for the fallback. */ + if (fallback_objfile->separate_debug_objfile != nullptr) + fallback_objfile = fallback_objfile->separate_debug_objfile; + + struct dwarf2_per_objfile *fallback_per_objfile = get_dwarf2_per_objfile + (fallback_objfile); + + /* The fallback objfile must be different to the current objfile. Otherwise, + this is no fallback so all necessary checks were already performed in + lookup_signatured_type. */ + if (fallback_per_objfile == *per_objfile) + return nullptr; + + /* Do we have a dwp file? */ + if (get_dwp_file (fallback_per_objfile) != nullptr) + { + sig_type = lookup_dwp_signatured_type (sig, fallback_per_objfile); + } + /* Do we have dwo files? */ + else + { + /* Look for dwo_entry that contains the signatured type. */ + for (const dwo_file_up &file : fallback_per_objfile->per_bfd->dwo_files) + { + auto it = file->tus.find (sig); + if (it != file->tus.end ()) + { + /* We found the dwo entry. Check for the signatured type. */ + sig_type = lookup_dwo_signatured_type (*it, sig, + fallback_per_objfile); + break; + } + } + } + + /* Do we still need to check the fallback per_objfile or was the signatured + type found in a DWO/DWP file? */ + if (sig_type == nullptr) + { + auto sig_type_it + = fallback_per_objfile->per_bfd->signatured_types.find (sig); + + if (sig_type_it != fallback_per_objfile->per_bfd->signatured_types.end ()) + sig_type = *sig_type_it; + } + + if (sig_type != nullptr) + /* Ensure we will know where the signature type came from. */ + *per_objfile = fallback_per_objfile; + return sig_type; +} + /* Lookup a signature based type for DW_FORM_ref_sig8. Returns NULL if signature SIG is not present in the table. - It is up to the caller to complain about this. */ + It is up to the caller to complain about this. + If type_signature_fallback is enabled and the signatured type is found, + per_objfile is the objfile where the signatured type was found in. */ static struct signatured_type * -lookup_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) +lookup_signatured_type (struct dwarf2_cu *cu, ULONGEST sig, + struct dwarf2_per_objfile **per_objfile) { - dwarf2_per_objfile *per_objfile = cu->per_objfile; - dwarf2_per_bfd *per_bfd = per_objfile->per_bfd; + struct signatured_type *sig_type = nullptr; + dwarf2_per_bfd *per_bfd = (*per_objfile)->per_bfd; if (cu->dwo_unit) { /* We're in a DWO/DWP file, and we're using .gdb_index. - These cases require special processing. */ - if (get_dwp_file (per_objfile) == NULL) - return lookup_dwo_signatured_type (cu, sig); + These cases require special processing. */ + if (get_dwp_file (*per_objfile) == nullptr) + sig_type = lookup_dwo_signatured_type (cu->dwo_unit, sig, *per_objfile); else - return lookup_dwp_signatured_type (cu, sig); + sig_type = lookup_dwp_signatured_type (sig, *per_objfile); + + /* If we already found the signatured type, return it. */ + if (sig_type != nullptr) + return sig_type; } else { + /* Lookup type signature in the current objfile. */ auto sig_type_it = per_bfd->signatured_types.find (sig); + /* If we already found the signatured type, return it. */ if (sig_type_it != per_bfd->signatured_types.end ()) return *sig_type_it; + } - return nullptr; + /* Handle fallback if type signature lookup fallback is enabled for this + objfile. */ + if (use_type_signature_fallback ((*per_objfile)->objfile)) + { + /* Do a full fallback through all objfiles in the progspace. */ + if (type_signature_fallback == type_signature_fallback_full) + { + for (objfile *objfile: (*per_objfile)->objfile->pspace ()->objfiles ()) + { + sig_type = lookup_fallback_signatured_type (objfile, sig, + per_objfile); + /* If we already found the signatured type, return it. */ + if (sig_type != nullptr) + return sig_type; + } + } + else + { + /* fallback to main symfile objfile. */ + struct objfile *objfile + = (*per_objfile)->objfile->pspace ()->symfile_object_file; + return lookup_fallback_signatured_type (objfile, sig, per_objfile); + } } + + /* We could not find the signatured type. */ + return nullptr; } /* Low level DIE reading support. */ @@ -4333,8 +4431,19 @@ maybe_queue_comp_unit (struct dwarf2_cu *dependent_cu, dwarf2_per_cu *per_cu, bool queued = false; if (!per_objfile->symtab_set_p (per_cu)) { - /* Add it to the queue. */ - queue_comp_unit (per_cu, per_objfile, pretend_language); + if (dependent_cu != nullptr && !per_objfile->queue.has_value () && + type_signature_fallback != type_signature_fallback_off) + { + /* If the signatured type in the fallback objfile references another + signatured type we might end up here with no queue in the fallback + objfile. */ + dw2_instantiate_symtab (per_cu, per_objfile, false); + } + else + { + /* Add it to the queue. */ + queue_comp_unit (per_cu, per_objfile, pretend_language); + } queued = true; dwarf_read_debug_printf ("Queuing CU for expansion: " @@ -8383,7 +8492,7 @@ static int queue_and_load_dwo_tu (dwo_unit *dwo_unit, dwarf2_cu *cu) { ULONGEST signature = dwo_unit->signature; - signatured_type *sig_type = lookup_dwo_signatured_type (cu, signature); + signatured_type *sig_type = lookup_dwo_signatured_type (cu->dwo_unit, signature, cu->per_objfile); if (sig_type != NULL) { @@ -18985,6 +19094,7 @@ dwarf2_get_die_type (cu_offset die_offset, dwarf2_per_cu *per_cu, static struct die_info * follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type, + struct dwarf2_per_objfile *sig_type_per_objfile, struct dwarf2_cu **ref_cu) { struct dwarf2_cu *sig_cu; @@ -19000,12 +19110,14 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type, Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs, it doesn't mean they are currently loaded. Since we require them to be loaded, we must check for ourselves. */ - if (maybe_queue_comp_unit (*ref_cu, sig_type, per_objfile, + if (maybe_queue_comp_unit (*ref_cu, sig_type, sig_type_per_objfile, language_minimal) - || per_objfile->get_cu (sig_type) == nullptr) - read_signatured_type (sig_type, per_objfile); + || sig_type_per_objfile->get_cu (sig_type) == nullptr) + { + read_signatured_type (sig_type, sig_type_per_objfile); + } - sig_cu = per_objfile->get_cu (sig_type); + sig_cu = sig_type_per_objfile->get_cu (sig_type); gdb_assert (sig_cu != NULL); gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0); @@ -19041,7 +19153,8 @@ follow_die_sig (struct die_info *src_die, const struct attribute *attr, gdb_assert (attr->form == DW_FORM_ref_sig8); - sig_type = lookup_signatured_type (*ref_cu, signature); + dwarf2_per_objfile *sig_type_per_objfile = (*ref_cu)->per_objfile; + sig_type = lookup_signatured_type (*ref_cu, signature, &sig_type_per_objfile); /* sig_type will be NULL if the signatured type is missing from the debug info. */ if (sig_type == NULL) @@ -19053,7 +19166,7 @@ follow_die_sig (struct die_info *src_die, const struct attribute *attr, objfile_name ((*ref_cu)->per_objfile->objfile)); } - die = follow_die_sig_1 (src_die, sig_type, ref_cu); + die = follow_die_sig_1 (src_die, sig_type, sig_type_per_objfile, ref_cu); if (die == NULL) { src_die->error_dump (); @@ -19080,7 +19193,8 @@ get_signatured_type (struct die_info *die, ULONGEST signature, struct die_info *type_die; struct type *type; - sig_type = lookup_signatured_type (cu, signature); + dwarf2_per_objfile *sig_type_per_objfile = per_objfile; + sig_type = lookup_signatured_type (cu, signature, &sig_type_per_objfile); /* sig_type will be NULL if the signatured type is missing from the debug info. */ if (sig_type == NULL) @@ -19099,7 +19213,7 @@ get_signatured_type (struct die_info *die, ULONGEST signature, return type; type_cu = cu; - type_die = follow_die_sig_1 (die, sig_type, &type_cu); + type_die = follow_die_sig_1 (die, sig_type, sig_type_per_objfile, &type_cu); if (type_die != NULL) { /* N.B. We need to call get_die_type to ensure only one type for this DIE @@ -19126,6 +19240,18 @@ get_signatured_type (struct die_info *die, ULONGEST signature, type = build_error_marker_type (cu, die); } + if (type_signature_fallback != type_signature_fallback_off) + { + /* We might already have read the required signatured type + after looking for it in a fallback objfile */ + struct type *existing_type = per_objfile->get_type_for_signatured_type + (sig_type); + if (existing_type != nullptr) + { + gdb_assert (type == existing_type); + return type; + } + } per_objfile->set_type_for_signatured_type (sig_type, type); return type; diff --git a/gdb/jit.c b/gdb/jit.c index d55e371b02a..ce19591c378 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -664,7 +664,8 @@ jit_object_close_impl (struct gdb_symbol_callbacks *cb, priv_data->entry.symfile_addr)); objfile *objfile = objfile::make (nullptr, current_program_space, - objfile_name.c_str (), OBJF_NOT_FILENAME); + objfile_name.c_str (), + OBJF_NOT_FILENAME | OBJF_JIT); objfile->section_offsets.push_back (0); objfile->sect_index_text = 0; objfile->per_bfd->gdbarch = priv_data->gdbarch; @@ -801,7 +802,8 @@ JITed symbol file is not an object file, ignoring it.\n")); objfile = symbol_file_add_from_bfd (nbfd, bfd_get_filename (nbfd.get ()), 0, &sai, - OBJF_SHARED | OBJF_NOT_FILENAME, NULL); + OBJF_SHARED | OBJF_NOT_FILENAME | + OBJF_JIT, NULL); add_objfile_entry (objfile, entry_addr, code_entry->symfile_addr, code_entry->symfile_size); diff --git a/gdb/objfile-flags.h b/gdb/objfile-flags.h index e0a84bcdc2e..0ad6e4037dd 100644 --- a/gdb/objfile-flags.h +++ b/gdb/objfile-flags.h @@ -56,6 +56,9 @@ enum objfile_flag : unsigned /* User requested that we do not read this objfile's symbolic information. */ OBJF_READNEVER = 1 << 6, + + /* Set if this objfile originates from a JIT compilation */ + OBJF_JIT = 1 << 7, }; DEF_ENUM_FLAGS_TYPE (enum objfile_flag, objfile_flags); From patchwork Wed Mar 12 15:37:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominik Mascherbauer X-Patchwork-Id: 107783 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 BDFFB385800F for ; Wed, 12 Mar 2025 15:38:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BDFFB385800F 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=MjMcCNRp X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id B53723858402 for ; Wed, 12 Mar 2025 15:37:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B53723858402 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 B53723858402 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::532 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741793840; cv=none; b=PS+3/JE1EXJzAPVUc05Twc4/jP41XDVjtXk66J5Re/OKOKZnBrnKpapZOZviF+jPJ+lLsEx/ply3qq80INf+mLeehK84RmriTixnWzzWd0+9P29hML5rDmODhQaqEg4c/kbsoo/I2UPkhW1Du9W8t/ozPABuDhMwpho5YPISQ74= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741793840; c=relaxed/simple; bh=1Qky8UHlVkfG94X3ApRXl2xk4iQViTL2uj2oM5RhPyU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=v1ekq4LzokImuSPHKxN/RvKzFbyF/FZqrUpkYDLngi4IqBjFICHUkYShKSPw88mpNH6M7bPLX4VdJpbPVJ0IitzyWwca4qNkcDx0bshzzu4KWDVkOOlgqXAei0KTd+TwON7ebDPNiqHeogHtoGzVaeJsCgKkoYKpFxhmfBeAY3A= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B53723858402 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5e66407963fso7507615a12.2 for ; Wed, 12 Mar 2025 08:37:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741793838; x=1742398638; 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=RE3i5sWYOv8n4BAWEnW0gLBro5CA0lNgpSz88RSMC3Q=; b=MjMcCNRpVx0UbCAPOQkjat7gNWcjaocXb3vN4QTwYPsJNjtSPMcdV5zrwQApkPl2gm SNDwKX+vmTnccygwtAeNcQl814dCNgxvE1HXZK5270ZCaZPZ8F9tdHfHQ64rPnxPO6af 72u4ozSjYKdh5l6jcDycewnFut236PTWnAKfN2iV2MHebHko6fF3byH/TB0Nwr2Y5aY8 nScGHnctpi8wu94o9/WuBYTCxEQQXs80zTA13VFC/N5IMdZN+67CZ7XsbkuGQsrkkWoY ocBNDShdYkVkwuntFcMltceoAEwPBXarxTHDCJd0apYKUC9VqZZjWGAZ+8OThTaq/aYX EaiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741793838; x=1742398638; 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=RE3i5sWYOv8n4BAWEnW0gLBro5CA0lNgpSz88RSMC3Q=; b=hZ729Xd81LUZMRX9Pypp1cRoG0TbtAxgGYcnexl56Lb26ebp3OPMAPgahpljzTzI5B qwNO1TcTLrwHq3iwrGhGoPCArMN1kN0eNJG6L71oRa8LUY7bgkfB1BpxqmTuOo5TUfdG LWXgglwg1b3mLjhfquMyLTXYA38nX3txXPreBwOk0aVSRWA5rzWo6KNsubtpgGTeooPl KzTkRj/41K7ZPit9qA/QfzzIZbekGiATEqdzybtvpu13PJsHI9FdFVBy/QGU2InuR5c4 jVaKKLLpITznSatio9/1WYKhkpA22Ra7gTbOTy5nswxbXG8zF3I9GwbkTpHp9wfA/sKR tqCA== X-Gm-Message-State: AOJu0Yy0+7vHrISL2HHBa9+AUiih+/5zLgLNbuPd5m8Yz+CVXwG680Gn cf09+UYYvMK09ycau7xGxlaKfMLKsnGzAAo9EtG0886jjY+UaAlLlSiT5w7xqX4= X-Gm-Gg: ASbGncuKC2QLYIrZgdQ5Fl1P+zWpPHhjXU3OdszbQE5J0OKCcQVjtumCNx7KGKoxSs6 YTXJgGzv8ai6DPM8KnjYkU1+0GCW6mG17iSN4BacrnfSW4W8u7UwSxxXmtLcL67S9fwnt836Jse hafWKJ2iZ+deYbO/yp9ba5KJLjHLR44JPHyu1K8vjTg4IahWZK9biLPuREEOt70Mb1Poq5MqxWz ci/7AmH4H9kKDyz2aspw9VeXZRhC9NpB8/XFfXz4xFOhsZXXbrD2ro1iSxWv0MA+Ce5j4sphsg7 xZyLCqGBp9JfNcmFeifMeLEb+yyQ3wU6lTAnhcxJAokcFGN3LvrxqxeRFYY5Jt18hJOA X-Google-Smtp-Source: AGHT+IEqKB2oBbs1Ed8YwroabcxUt2FKosUmZ5+YklFePZcXgUP3U0cRRDGlDE056UyLOw2pjPIR8w== X-Received: by 2002:a05:6402:5387:b0:5e0:9254:c10e with SMTP id 4fb4d7f45d1cf-5e5e22dbbf6mr27629615a12.11.1741793837811; Wed, 12 Mar 2025 08:37:17 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 08:37:16 -0700 (PDT) From: dominikmascherbauer X-Google-Original-From: dominikmascherbauer To: gdb-patches@sourceware.org Cc: dominikmascherbauer Subject: [PATCH v2 3/3] Add testing for type signature fallback. Date: Wed, 12 Mar 2025 16:37:08 +0100 Message-Id: <86d6c18c10e7d42a687048182dba5982fb59a77c.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=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, 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 Create an executable with a type unit that loads a JIT objfile with a reference its type unit. Then in the context of the JIT objfile the type is checked. This causes a type signature lookup with a fallback to the main objfile. --- .../gdb.dwarf2/sig-type-fallback-jit.c | 62 +++++++++++++++ .../gdb.dwarf2/sig-type-fallback-jit.exp | 75 +++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.c create mode 100644 gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.exp diff --git a/gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.c b/gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.c new file mode 100644 index 00000000000..da83e27ad64 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.c @@ -0,0 +1,62 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2024 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Simulate loading of JIT code. */ + +#include "../gdb.base/jit-elf-util.h" +#include "../gdb.base/jit-protocol.h" + +/* Must be defined by .exp file when compiling to know + what address to map the ELF binary to. */ +#ifndef LIB_ADDRESS +#error "Must define LOAD_ADDRESS" +#endif +#ifndef LIB_NAME_STRING +#error "Must define LIB_NAME_STRING" +#endif + +int +main () +{ + size_t obj_size; + void *load_addr = (void *) (size_t) (LIB_ADDRESS); + void *addr = load_elf (LIB_NAME_STRING, &obj_size, load_addr); + + /* Link entry at the end of the list. */ + struct jit_code_entry *const entry = calloc (1, sizeof (*entry)); + entry->symfile_addr = (const char *) addr; + entry->symfile_size = obj_size; + __jit_debug_descriptor.relevant_entry = entry; + __jit_debug_descriptor.first_entry = entry; + + /* Notify GDB. */ + __jit_debug_descriptor.action_flag = JIT_REGISTER; + __jit_debug_register_code (); + + // breakpoint 1 + + /* Now unregister entry. */ + /* Notify GDB. */ + __jit_debug_descriptor.action_flag = JIT_UNREGISTER; + __jit_debug_register_code (); + + __jit_debug_descriptor.first_entry = NULL; + __jit_debug_descriptor.relevant_entry = NULL; + free (entry); + + return 0; +} diff --git a/gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.exp b/gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.exp new file mode 100644 index 00000000000..91465118c5f --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/sig-type-fallback-jit.exp @@ -0,0 +1,75 @@ +# Copyright 2024 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +load_lib dwarf.exp + +require dwarf2_support allow_shlib_tests + +set lib_address 0x7000000 +set lib_name libfoo.so + +standard_testfile .c .S -lib.S + +# Create fake DWARF TU for the main objfile. +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble ${asm_file} { + tu {version 5} 0x1122334455667788 the_type { + type_unit {} { + the_type: base_type { + {name myType} + {encoding @DW_ATE_signed} + {byte_size 4 sdata} + } + } + } +} + +# Create fake DWARF CU with type reference for the jit object file. +set asm_file_lib [standard_output_file $srcfile3] +Dwarf::assemble ${asm_file_lib} { + cu {} { + compile_unit {} { + declare_labels typedef_label + + typedef_label: typedef { + {name bar} + {type 0x1122334455667788 ref_sig8 } + } + } + } +} + + +set libobj [standard_output_file $lib_name] +if {[build_executable "build shared library" $libobj $asm_file_lib \ + [list debug text_segment=$lib_address shlib]] != 0} { + return -1 +} + +if {[prepare_for_testing "failed to prepare" $testfile [list $srcfile $asm_file] \ + [list debug additional_flags=-DLIB_ADDRESS=$lib_address \ + additional_flags=-DLIB_NAME_STRING=\"$libobj\" ]]} { + return -1 +} + +if {![runto_main]} { + return -1 +} + +gdb_test_no_output "set dwarf-type-signature-fallback main" +gdb_breakpoint [gdb_get_line_number "breakpoint 1"] +gdb_continue_to_breakpoint "first breakpoint" +gdb_test "ptype bar" "type = myType" \ No newline at end of file