From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id 9527C3857C43 for ; Tue, 28 Jul 2020 01:23:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9527C3857C43 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-469-U2sjGLY0PkeUu4mrMKTFGw-1; Mon, 27 Jul 2020 21:23:22 -0400 X-MC-Unique: U2sjGLY0PkeUu4mrMKTFGw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C022100AA21; Tue, 28 Jul 2020 01:23:21 +0000 (UTC) Received: from f32-m1.lan (ovpn-112-21.phx2.redhat.com [10.3.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4506D712D5; Tue, 28 Jul 2020 01:23:21 +0000 (UTC) Date: Mon, 27 Jul 2020 18:23:20 -0700 From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: Re: [PATCH] Fix bug in DW_OP_GNU_variable_value evaluation Message-ID: <20200727182320.2aa49b7a@f32-m1.lan> In-Reply-To: <20200727204644.2410247-1-tromey@adacore.com> References: <20200727204644.2410247-1-tromey@adacore.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jul 2020 01:23:28 -0000 On Mon, 27 Jul 2020 14:46:44 -0600 Tom Tromey wrote: > A modified version of the gnat compiler (TBH I don't know if the > modifications are relevant to this bug or not, but I figured I'd > mention it) can generate a DWARF location expression like: > > <1><1201>: Abbrev Number: 3 (DW_TAG_dwarf_procedure) > <1202> DW_AT_location : 32 byte block: 12 31 29 28 4 0 30 2f 12 0 14 30 2d 28 4 0 14 2f 1 0 30 34 1e 23 3 9 fc 1a 16 13 16 13 (DW_OP_dup; DW_OP_lit1; DW_OP_eq; DW_OP_bra: 4; DW_OP_lit0; DW_OP_skip: 18; DW_OP_over; DW_OP_lit0; DW_OP_lt; DW_OP_bra: 4; DW_OP_over; DW_OP_skip: 1; DW_OP_lit0; DW_OP_lit4; DW_OP_mul; DW_OP_plus_uconst: 3; DW_OP_const1s: -4; DW_OP_and; DW_OP_swap; DW_OP_drop; DW_OP_swap; DW_OP_drop) > > <2><1279>: Abbrev Number: 9 (DW_TAG_structure_type) > <127a> DW_AT_name : (indirect string, offset: 0x1a5a): p__logical_channel_t > <127e> DW_AT_byte_size : 18 byte block: fd 43 12 0 0 97 94 1 99 34 0 0 0 23 7 9 fc 1a (DW_OP_GNU_variable_value: <0x1243>; DW_OP_push_object_address; DW_OP_deref_size: 1; DW_OP_call4: <0x1201>; DW_OP_plus_uconst: 7; DW_OP_const1s: -4; DW_OP_and) > > When evaluated, this gives: > > Incompatible types on DWARF stack > > In Jakub's original message about DW_OP_GNU_variable_value: > > https://gcc.gnu.org/legacy-ml/gcc-patches/2017-02/msg01499.html > > .. it says: > > The intended behavior is that the debug info consumer computes the > value of that referenced variable at the current PC, and if it can > compute it and pushes the value as a generic type integer into the > DWARF stack > > Instead, gdb is using the variable's type -- but this fails with some > operations, like DW_OP_and, which expect the types to match. > > I believe what was intended was for the value to be cast to the DWARF > "untyped" type, which is what this patch implements. This patch also > updates varval.exp to exhibit the bug. > > gdb/ChangeLog > 2020-07-27 Tom Tromey > > * dwarf2/expr.c (dwarf_expr_context::execute_stack_op) > : Cast to address type. > > gdb/testsuite/ChangeLog > 2020-07-27 Tom Tromey > > * gdb.dwarf2/varval.exp (setup_exec): Add 'or' instruction to > 'varval' location. LGTM. Kevin