From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id C0A413858D37 for ; Mon, 17 Aug 2020 07:55:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C0A413858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 0E9CFABF4 for ; Mon, 17 Aug 2020 07:55:30 +0000 (UTC) Date: Mon, 17 Aug 2020 09:55:03 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [committed][gdb] Fix printing of unresolved dynamic type Message-ID: <20200817075502.GA25567@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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: Mon, 17 Aug 2020 07:55:08 -0000 Hi, When debugging gdb in batch mode with executable mixed-lang-stack and doing a backtrace at breakpt: ... $ gdb --args gdb \ -batch \ outputs/gdb.fortran/mixed-lang-stack/mixed-lang-stack \ -ex "b breakpt" \ -ex r \ -ex bt ... and stopping at resolve_dynamic_type to print the type: ... (gdb) b resolve_dynamic_type Breakpoint 1 at 0x6b020c: file gdbtypes.c, line 2633. (gdb) commands Type commands for breakpoint(s) 1, one per line. End with a line saying just "end". >call recursive_dump_type (type, 0) >continue >end (gdb) run ... we eventually run into an assert for the dynamic type of "str": ... Thread 1 "gdb" hit Breakpoint 1, resolve_dynamic_type (type=0x22204f0, \ valaddr=..., addr=4199408) at gdbtypes.c:2633 2633 = {check_typedef (type), valaddr, addr, NULL}; type node 0x22204f0 name '' (0x0) code 0xd (TYPE_CODE_STRING) length 0 ... nfields 0 0x22204b0 gdbtypes.h:526: internal-error: LONGEST dynamic_prop::const_val() const: \ Assertion `m_kind == PROP_CONST' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. ... when trying to print the high bound of a TYPE_CODE_RANGE, which has m_kind PROP_LOCEXPR, while the code in resolve_dynamic_type assumes PROP_CONST. Fix this by extending the printing of TYPE_CODE_RANGE to allow PROP_LOCEXPR/PROP_LOCLIST as well, such that we have instead: ... nfields 0 0x1fbc020 low 1 high (dynamic) ... Tested on x86_64-linux. Committed to trunk. Thanks, - Tom [gdb] Fix printing of unresolved dynamic type gdb/ChangeLog: 2020-08-17 Tom de Vries PR gdb/26393 * gdbtypes.c (dump_dynamic_prop): New function. (recursive_dump_type): Use dump_dynamic_prop for TYPE_CODE_RANGE. --- gdb/gdbtypes.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index da1c58c65c..c1eb03d898 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -4856,6 +4856,29 @@ print_gnat_stuff (struct type *type, int spaces) static struct obstack dont_print_type_obstack; +/* Print the dynamic_prop PROP. */ + +static void +dump_dynamic_prop (dynamic_prop const& prop) +{ + switch (prop.kind ()) + { + case PROP_CONST: + printf_filtered ("%s", plongest (prop.const_val ())); + break; + case PROP_UNDEFINED: + printf_filtered ("(undefined)"); + break; + case PROP_LOCEXPR: + case PROP_LOCLIST: + printf_filtered ("(dynamic)"); + break; + default: + gdb_assert_not_reached ("unhandled prop kind"); + break; + } +} + void recursive_dump_type (struct type *type, int spaces) { @@ -5115,13 +5138,11 @@ recursive_dump_type (struct type *type, int spaces) } if (type->code () == TYPE_CODE_RANGE) { - printfi_filtered (spaces, "low %s%s high %s%s\n", - plongest (type->bounds ()->low.const_val ()), - (type->bounds ()->low.kind () == PROP_UNDEFINED - ? " (undefined)" : ""), - plongest (type->bounds ()->high.const_val ()), - (type->bounds ()->high.kind () == PROP_UNDEFINED - ? " (undefined)" : "")); + printfi_filtered (spaces, "low "); + dump_dynamic_prop (type->bounds ()->low); + printf_filtered (" high "); + dump_dynamic_prop (type->bounds ()->high); + printf_filtered ("\n"); } switch (TYPE_SPECIFIC_FIELD (type))