From patchwork Thu Apr 25 18:17:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32417 Received: (qmail 54578 invoked by alias); 25 Apr 2019 18:17:45 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 54570 invoked by uid 89); 25 Apr 2019 18:17:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=Changing X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 25 Apr 2019 18:17:44 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D6E321172B5; Thu, 25 Apr 2019 14:17:42 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id wDfYO0mUce4a; Thu, 25 Apr 2019 14:17:42 -0400 (EDT) Received: from murgatroyd.Home (97-122-168-123.hlrn.qwest.net [97.122.168.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 80DFC1172B8; Thu, 25 Apr 2019 14:17:42 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Force array coercion in c_get_string Date: Thu, 25 Apr 2019 12:17:40 -0600 Message-Id: <20190425181740.18062-1-tromey@adacore.com> MIME-Version: 1.0 A user here noticed that the Python Value.string method did not work for Ada arrays. I tracked this down to an oddity in value_as_address -- namely, it calls coerce_array, but that function will not force array coercion when the language has c_style_arrays=false, as Ada does. This patch fixes the problem by forcing array coercion in c_get_string. Changing either value_as_address or coerce_array seemed iffy to me. Initially here I tried making arrays take the "in GDB's memory" branch of the if near the top of c_get_string; but this fails the C struct hack test case added for PR 16196. Tested on x86-64 Fedora 29. gdb/ChangeLog 2019-04-25 Tom Tromey * c-lang.c (c_get_string): Call value_coerce_array. gdb/testsuite/ChangeLog 2019-04-25 Tom Tromey * gdb.python/py-value.exp (test_value_in_inferior): Add Ada test. --- gdb/ChangeLog | 4 ++++ gdb/c-lang.c | 7 +++++++ gdb/testsuite/ChangeLog | 4 ++++ gdb/testsuite/gdb.python/py-value.exp | 7 +++++++ 4 files changed, 22 insertions(+) diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 33506f1d1ed..2084134c36d 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -306,6 +306,13 @@ c_get_string (struct value *value, gdb::unique_xmalloc_ptr *buffer, } else { + /* value_as_address calls coerce_array, but that won't actually + coerce the array if c_style_arrays is false. However, in + this particular case, we do want to always force array + coercion. So, check this case here. */ + if (TYPE_CODE (type) == TYPE_CODE_ARRAY) + value = value_coerce_array (value); + CORE_ADDR addr = value_as_address (value); /* Prior to the fix for PR 16196 read_string would ignore fetchlimit diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index b3d90b52272..7f42d31572a 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -315,6 +315,13 @@ proc test_value_in_inferior {} { gdb_test "python print (\"---\"+st.string (length = 0)+\"---\")" "------" "test string (length = 0) is empty" gdb_test "python print (len(st.string (length = 0)))" "0" "test length is 0" + # We choose Ada here to test a language where c_style_arrays is + # false. + gdb_test "set lang ada" \ + "Warning: the current language does not match this frame." + gdb_test "python print (st.string ())" "divide et impera" \ + "Test string with no length in ada" + gdb_test_no_output "set lang auto" # Fetch a string that has embedded nulls. gdb_test "print nullst" "\"divide\\\\000et\\\\000impera\".*"