From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CJlWFE1zBWs2LTIAWB0awg (envelope-from ) for ; Tue, 24 Nov 2026 06:21:49 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=CFM/FJgt; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 370971E167; Tue, 24 Nov 2026 06:21:49 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7DC571E09B for ; Tue, 24 Nov 2026 06:21:48 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 388B8462F21F for ; Tue, 24 Nov 2026 11:21:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 388B8462F21F Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=CFM/FJgt Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 3EE9E46A12DC for ; Tue, 24 Nov 2026 11:21:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3EE9E46A12DC Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3EE9E46A12DC Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795519280; cv=none; b=tB/BWoqnqBoBEAjfjl3YCyXMyfvXvp8pwX5GqN23/hYNcRxcaLM6dO/nANI+u3NIyDVLixZS/V6y4i5y5m1RDganqqb4gjeb/XnbV31Ep7PA7a5Lt5fkhtQ4L4lMXjFpmyNOttVWgX1JmBpsoTX/yGD4NGoB/MAw8gPbKK9Sc5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795519280; c=relaxed/simple; bh=JDxyliKp8Bwat2axGdq/8+VSw16ZBulmurrj/vHc8to=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wsfqiwkfHePrvH2xihaUlFUUlaRZM/Nxp8IJT8FsjHcenw8OZjMbMW72MjoxF2FLMkg7e22VEZ0k9AITtzFYJYgge/H5vr2oJIUZHNMsRTWziEoDBwUL6I4gkDl4UxAaNp4PR1/6We0Cq1VKrEG/yBpdr/5DwpkzHI3pJtiYhr8= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=CFM/FJgt DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3EE9E46A12DC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795519279; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UXBgiCPAMwEGk5Y/Oq8yOkZK/49LLaJqxQtRcwtRbDM=; b=CFM/FJgtTrZkW+eccIh0odAMoBFVp7C/xtpWYZaHEfv7Z7kr6whR1Toq+gfQb0FkEHs9cG vRRln2EllAypHIwduatV7NdIdMKrZKC8KI6Vc9UG2THQpGtUCeDRYUCUZwYbW6uoIJkZmc JqPZoVNFEnJjvi6pB7k9GRmAER8qcyU= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-XZRT1ykLPje_HiRgGI5big-1; Tue, 24 Nov 2026 11:21:18 +0000 X-MC-Unique: XZRT1ykLPje_HiRgGI5big-1 X-Mimecast-MFC-AGG-ID: XZRT1ykLPje_HiRgGI5big_1795519277 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4bb6bac1e84so28294635e9.0 for ; Tue, 24 Nov 2026 03:21:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795519277; x=1796124077; h=content-type:mime-version:message-id:date:references:in-reply-to :subject:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=UXBgiCPAMwEGk5Y/Oq8yOkZK/49LLaJqxQtRcwtRbDM=; b=i15QkiMIdsrXoX+Tq68CMxs7+btAW2NM/zHehTPqqqLE/T9FJavC09ZAwORWDftHaY XbUZnP7evSyX6G5rUMvuXKbRJ7zBidd7mjKL56yBt8oGPLARVbKf2je0UgurbvVVULYC kyPSUfloymxp1/lQp0B1iFZacRvm8aivJ45aXdAyF9grGe3UB2XneYjJMa1ZCYG4hr8p 2wcxNnMq4IkQT47Nwz2iT7WAyb6P2zO1H4Wies7kWr6lj7ub5GjyW3Fy2OBY3bc0zhdZ +QjuYYenvz2Kr2PE74X+o1mm4gd2e0OaAZ5Wl5tSBAHCxAmdEfsHuvZmxMicXPzeThuu x6Gw== X-Gm-Message-State: APuU4Z8tO/xm+vfLuTfwF+zW6zpsv/CBVpyeX1pGUPT5Yf39/bHDrrVZ EA+Z2O+eeyjpn1udZOtU8hWK9fYgZ5Vx1h2fYTJa5UKcJLSAb5LAwXhB+Dw6e0/hBvkzcy0vl6U aqiIKRdVuf21Lgk409cgMNbohtkolcoKfKumgVtOiYSjpsi5PVi0RZ34N6YR8ealhvKeFbD7/J/ W7Q2pVue1h3rlspAS/Spzluk2+16IpW4+pcNGrCYhKc+e8opo= X-Gm-Gg: AZFdTZc33qO9EIsVhzcfWZkYIR1xFVGtQkuId1w23PJNKdhtJQVDtNsxhtmrcGWemEP uEUkiBl928kgkweMDORceiuY3E6TquHvU6Lkyr+zPpaqB8nSSEaN9I13terRO9fqFBMFHETeXNA aFZgQk0ROeLK26AvyihuOkktXlERZk/QeA60yllrr9DHom6CdbblKfOVRUaBwXb4HMaf0H5EsJT HYVMZNoWfgSt8/ncUnOiwb690tPj2qycB6SQM5Y1wsIN+6VXlyuCGHUmFW3V6VKjUsTWdISup7a PI1b3RgYKqDJnm73g85w1HBDTflgyuEItvu1gatbU2p2Fe78K6o/MS0LI0d10SjZsnNs8JOOA4W Hrognn83rXVO6IliIaQ4EYqBixQCboPH1rS1eqrbOkH6yPg== X-Received: by 2002:a05:600c:c8c:b0:4b7:6942:39bd with SMTP id 5b1f17b1804b1-4bb88820e06mr286384045e9.26.1795519276871; Tue, 24 Nov 2026 03:21:16 -0800 (PST) X-Received: by 2002:a05:600c:c8c:b0:4b7:6942:39bd with SMTP id 5b1f17b1804b1-4bb88820e06mr286383005e9.26.1795519276211; Tue, 24 Nov 2026 03:21:16 -0800 (PST) Received: from localhost ([83.216.138.189]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6a67fe48sm25189693f8f.23.2026.11.24.03.21.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 03:21:15 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: Re: [PATCHv2] gdb: unify trivial_entry_value handling in DW_OP_entry_value In-Reply-To: References: Date: Tue, 24 Nov 2026 11:21:14 +0000 Message-ID: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: oFe2tEruPXd8WDQkB0WTdbe2H73nrRkmAAGXukVEIXo_1795519277 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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~public-inbox=simark.ca@sourceware.org Andrew Burgess writes: > In V2: > > - Rebase and retest. > > - Spelling / grammar fixes in comments and commit messages > > - Reworded the commit message for increased clarity. > > - No code changes. > > Thanks, > Andrew > > ~~~~~ > > This commit simplifies the DW_OP_entry_value handling in dwarf2/expr.c > for the case where trivial_entry_value is true, as a consequence I hit > a bug in dwarf_expr_context::fetch_result which I have also fixed. > > Currently GDB can handle two different DW_OP_entry_value DWARF > expressions, DW_OP_reg or DW_OP_breg/DW_OP_deref, and the current > trivial_entry_value is also split in two to mirror these two cases. > > The trivial_entry_value function returns true when the inferior is > stopped at the first instruction of a function. This means that the > value of the DW_OP_entry_value expression is just the current value of > that DWARF expression. > > This commit moves the trivial_entry_value handling to earlier in the > DW_OP_entry_value case statement block, and unifies the existing two > cases. > > The new code performs a recursive evaluation of the DW_OP_entry_value > DWARF expression. > > I took the m_stack save and restore idea from how DW_OP_fbreg is > handled, though I used SCOPE_EXIT for the restore so that the restore > happens even on the exception case. > > Also, unlike the fbreg case I also save and restore m_location as > DW_OP_entry_value could be in the middle of a complex DWARF expression > which has already set m_location, and m_pieces as we could also be in > the middle of building a composite value. > > Finally, the result is pulled from m_stack by a call to fetch_result. > > The DWARF 5 spec says this about DW_OP_entry_value: > > The DW_OP_entry_value operation pushes the value that the described > location held upon entering the current subprogram. It has two > operands: an unsigned LEB128 length, followed by a block containing > a DWARF expression or a register location description (see Section > 2.6.1.1.3 on page 39). The length operand specifies the length in > bytes of the block. If the block contains a DWARF expression, the > DWARF expression is evaluated as if it had been evaluated upon > entering the current subprogram. The DWARF expression assumes no > values are present on the DWARF stack initially and results in > exactly one value being pushed on the DWARF stack when completed. If > the block contains a register location description, > DW_OP_entry_value pushes the value that register had upon entering > the current subprogram. > > From this, and from how GDB currently handles DW_OP_breg/DW_OP_deref > within the DW_OP_entry_value case, I believe that this means there are > two possible results from a DW_OP_entry_value expression: > > (1) The result is left on the DWARF expression stack. > > (2) The result is a register location description, in which case the > result is read from the register. > > Based on #1 I initially wanted to pass as_lval=false to fetch_result, > passing as_lval=false means that m_location is forced to be > DWARF_VALUE_STACK. However, this causes a problem when m_location is > initially DWARF_VALUE_REGISTER, changing to DWARF_VALUE_STACK means > that GDB reads the register number from the stack, which is never what > we want. > > This got me looking at how as_lval is handled in fetch_result, and I'm > not convinced that the current handling makes much sense. Converting > from DWARF_VALUE_MEMORY to DWARF_VALUE_STACK is fine, this causes GDB > to read the result from the expression stack rather than treating the > value on the stack as a memory location, but for DWARF_VALUE_REGISTER, > DWARF_VALUE_LITERAL, DWARF_VALUE_OPTIMIZED_OUT, and > DWARF_VALUE_IMPLICIT_POINTER converting to DWARF_VALUE_STACK doesn't > really work as there either isn't a value on the stack, or the value > on the stack is an internal detail, e.g. the DWARF register number for > DWARF_VALUE_REGISTER. > > I did consider changing this existing code block: > > if (!as_lval) > this->m_location = DWARF_VALUE_STACK; > > to this: > > if (!as_lval && this->m_location == DWARF_VALUE_MEMORY) > this->m_location = DWARF_VALUE_STACK; > > But I figured it would actually be neater if I pushed the as_lval > handling down into the switch statement. The switch is now structured > like this: > > switch (this->m_location) > { > ... > case DWARF_VALUE_MEMORY: > if (as_lval) > { > ... > break; > } > [[fallthrough]]; > case DWARF_VALUE_STACK: > ... > } > > So when as_lval is false we treat it as DWARF_VALUE_STACK just like > before, but for any other location type we leave things unchanged. > This makes more sense to me, this is the bug fix to which I referred > at the top of this commit message. > > Back in the DW_OP_entry_value handling we can now pass as_lval=false > to the fetch_result call, and we will correctly handle the two cases I > identified above, a value on the stack will be treated as an actual > value, while a register location description will result in the value > being read from the register. > > I don't think this issue with fetch_result ever bit us before as the > only place where fetch_result could be called with as_lval=false would > only ever pass DWARF_VALUE_MEMORY or DWARF_VALUE_STACK, in which case > the old behaviour was fine. > > There are no new tests added here. The changes in > dwarf_expr_context::execute_stack_op are a refactor, and the bug in > dwarf_expr_context::fetch_result could not previously be reached in a > way that would cause incorrect behaviour. The fetch_result fix is > covered by the existing gdb.dwarf2/dw2-entry-value*.exp tests after > the refactor though. I've gone ahead and checked this in. Let me know if any issues are spotted. Thanks, Andrew