From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 129439 invoked by alias); 2 May 2019 13:44:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 129423 invoked by uid 89); 2 May 2019 13:44:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-5.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.150.114) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 02 May 2019 13:44:06 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 4D057434D4 for ; Thu, 2 May 2019 08:44:05 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MC0LhUEZk4FKpMC0Lhuauy; Thu, 02 May 2019 08:44:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=VyleUhbCrd8pOShNra9ZEVAkQ20J9wR59L8xwPbEohM=; b=fjuN3LCnXTvapN7v+MmszpQC4d /T9jlB+Uh5eEu7Zll7+BEuQMR6FiS9nuWRlDr3Cq0TFKYF3/zi2ba2xTBK7mPjlof2/yGYtjGyPCD mFg7ExnXCXqcCtHvG0ggGQAqD; Received: from 97-122-168-123.hlrn.qwest.net ([97.122.168.123]:34180 helo=murgatroyd) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hMC0L-0025aC-3M; Thu, 02 May 2019 08:44:05 -0500 From: Tom Tromey To: Andrew Burgess Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] gdb/rust: Handle printing structures containing strings References: <20190501235246.7982-1-andrew.burgess@embecosm.com> Date: Thu, 02 May 2019 13:44:00 -0000 In-Reply-To: <20190501235246.7982-1-andrew.burgess@embecosm.com> (Andrew Burgess's message of "Thu, 2 May 2019 00:52:46 +0100") Message-ID: <875zqtynrv.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2019-05/txt/msg00034.txt.bz2 >>>>> "Andrew" == Andrew Burgess writes: Andrew> When printing a rust structure that contains a string GDB can Andrew> currently fail to read the fields that define the string. This is Andrew> because GDB mistakenly treats a value that is the parent structure as Andrew> though it is the structure that defines the string, and then fails to Andrew> find the fields needed to extract a string. Andrew> The solution is to create a new value to represent the string field of Andrew> the parent value. Thank you for doing this. Andrew> if (rust_slice_type_p (type) && strcmp (TYPE_NAME (type), "&str") == 0) Andrew> { Andrew> + /* If what we are printing here is actually a string within a Andrew> + structure then VAL will be the original parent value, while TYPE Andrew> + will be the type of the structure representing the string we want Andrew> + to print. Andrew> + However, RUST_VAL_PRINT_STR looks up the fields of the string Andrew> + inside VAL, assuming that VAL is the string. Andrew> + So, recreate VAL as a value representing just the string. */ Andrew> + val = value_at_lazy (type, value_address (val) + embedded_offset); Andrew> rust_val_print_str (stream, val, options); Andrew> return; It took me a while to understand this, but I get it now. At first it looked like this code was misplaced, but what's going on is that rust_val_print_str only takes a value, so in a "val_print" context we must reconstruct one. We really ought to get rid of the val_print / value_print distinction someday. It doesn't provide any benefit and it leads to bugs like this. Andrew> +gdb_test "print st" " = simple::StringAtOffset {field1: \"hello\", field2: 1, field3: \"world\"}" I think this line should probably be split after the first argument. Ok with this change. Tom