From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YIJGK4jdt1/maAAAWB0awg (envelope-from ) for ; Fri, 20 Nov 2020 10:15:20 -0500 Received: by simark.ca (Postfix, from userid 112) id A3F4E1F08B; Fri, 20 Nov 2020 10:15:20 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 2904E1E58F for ; Fri, 20 Nov 2020 10:15:19 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 09391386102F; Fri, 20 Nov 2020 15:15:18 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 2DEF0386102F for ; Fri, 20 Nov 2020 15:15:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2DEF0386102F 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 40826AA4F; Fri, 20 Nov 2020 15:15:13 +0000 (UTC) From: Tom de Vries To: Tom Tromey , Gary Benson via Gdb-patches References: <1605547055-25778-1-git-send-email-gbenson@redhat.com> <87mtzek5fv.fsf@tromey.com> <0a3f590c-2a76-e470-136f-e8f88aef1d17@suse.de> Subject: [PATCH][gdb/symtab] Fix gdb.base/vla-optimized-out.exp with clang Message-ID: <3fe3ebd1-835d-b603-5cb1-254364731ec2@suse.de> Date: Fri, 20 Nov 2020 16:15:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <0a3f590c-2a76-e470-136f-e8f88aef1d17@suse.de> Content-Type: multipart/mixed; boundary="------------9EE4607E340F05E0C74EA73A" Content-Language: en-US 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: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" This is a multi-part message in MIME format. --------------9EE4607E340F05E0C74EA73A Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit [ was: Re: [PATCH] KFAIL variable-length array tests which fail with Clang ] On 11/19/20 11:53 PM, Tom de Vries wrote: > On 11/18/20 5:14 PM, Tom Tromey wrote: >>>>>>> "Gary" == Gary Benson via Gdb-patches writes: >> >> Gary> Clang describes the upper bounds of variable length arrays using >> Gary> a DW_AT_count attribute which references the DIE of a synthetic >> Gary> variable whose value is specified using a DW_AT_location. In >> Gary> some cases GDB correctly handles these, but in other cases GDB >> Gary> adds an extra dereference causing the test to fail. This commit >> Gary> marks these failing tests as caused by PR gdb/26905 when the >> Gary> test executable was built using Clang. >> >> Shouldn't we just fix the gdb bug instead? > > This adhoc patch: Here's the complete and tested patch. Any comments? Thanks, - Tom --------------9EE4607E340F05E0C74EA73A Content-Type: text/x-patch; charset=UTF-8; name="0004-gdb-symtab-Fix-gdb.base-vla-optimized-out.exp-with-clang.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename*0="0004-gdb-symtab-Fix-gdb.base-vla-optimized-out.exp-with-clan"; filename*1="g.patch" [gdb/symtab] Fix gdb.base/vla-optimized-out.exp with clang Consider test-case gdb.base/vla-optimized-out.exp, compiled using clang-1= 0. GDB fails to get the size of the vla a: =2E.. (gdb) p sizeof (a)^M Cannot access memory at address 0x6^M (gdb) FAIL: gdb.base/vla-optimized-out.exp: o1: printed size of \ optimized out vla =2E.. The relevant DWARF looks like this: the variable a: =2E.. <2><12b>: Abbrev Number: 5 (DW_TAG_variable) <12c> DW_AT_name : a <132> DW_AT_type : <0x189> =2E.. has type: =2E.. <1><189>: Abbrev Number: 10 (DW_TAG_array_type) <18a> DW_AT_type : <0x198> <2><18e>: Abbrev Number: 11 (DW_TAG_subrange_type) <18f> DW_AT_type : <0x19f> <193> DW_AT_count : <0x117> =2E.. with the count attribute equated to the value of this artificial variable= : =2E.. <2><117>: Abbrev Number: 4 (DW_TAG_variable) <118> DW_AT_location : 10 byte block: 75 1 10 ff ff ff ff f 1a 9= f \ (DW_OP_breg5 (rdi): 1; DW_OP_constu: 4294967295; DW_OP_and; DW_OP_stack_value) <123> DW_AT_name : __vla_expr0 <127> DW_AT_type : <0x182> <12b> DW_AT_artificial : 1 =2E.. The location description of the variable is terminated with DW_OP_stack_v= alue, which according to the DWARF spec means that "the DWARF expression repres= ents the actual value of the object, rather than its location". However, in attr_to_dynamic_prop, we set is_reference to true regardless:= =2E.. baton->locexpr.is_reference =3D true; =2E.. which causes the access to memory at address 0x6. Fix this by detecting that the dwarf expresssion is terminated with DW_OP_stack_value, and if so setting baton->locexpr.is_reference to false= , such that we have instead: =2E.. (gdb) p sizeof (a)^M $2 =3D 6^M (gdb) PASS: gdb.base/vla-optimized-out.exp: o1: printed size of \ optimized out vla =2E.. Add dwarf assembly test-case in gdb.dwarf2/count.exp. Tested on x86_64-linux, with gcc. Tested the following test-cases (the ones mentioned in PR26905) on x86_64-linux with clang-10: - gdb.base/vla-optimized-out.exp - gdb.base/vla-ptr.exp - gdb.mi/mi-vla-c99 This FAIL (with clang) is due to missing debuginfo: =2E.. FAIL: gdb.base/vla-ptr.exp: print td_vla =2E.. so mark it as XFAIL. gdb/ChangeLog: 2020-11-20 Tom de Vries PR symtab/26905 * dwarf2/read.c (attr_to_dynamic_prop): Handle DW_OP_stack_value as end of DW_AT_location expression. gdb/testsuite/ChangeLog: 2020-11-20 Tom de Vries PR symtab/26905 * gdb.base/vla-ptr.exp: Add XFAIL. * gdb.dwarf2/count.exp: Add test-case. --- gdb/dwarf2/read.c | 12 +++++++++++- gdb/testsuite/gdb.base/vla-ptr.exp | 39 ++++++++++++++++++++++++++++++++= +++++- gdb/testsuite/gdb.dwarf2/count.exp | 31 +++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 3c598262913..3782a516a3b 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -18644,7 +18644,17 @@ attr_to_dynamic_prop (const struct attribute *at= tr, struct die_info *die, struct dwarf_block *block =3D target_attr->as_block (); baton->locexpr.size =3D block->size; baton->locexpr.data =3D block->data; - baton->locexpr.is_reference =3D true; + if (block->size > 0 + && block->data[block->size - 1] =3D=3D DW_OP_stack_value) + { + /* A DW_OP_stack_value at the end of a location + description means that the expression represents the + actual value of the object, rather than its + location. */ + baton->locexpr.is_reference =3D false; + } + else + baton->locexpr.is_reference =3D true; prop->set_locexpr (baton); gdb_assert (prop->baton () !=3D NULL); } diff --git a/gdb/testsuite/gdb.base/vla-ptr.exp b/gdb/testsuite/gdb.base/= vla-ptr.exp index 346ff00c524..72d7d36489e 100644 --- a/gdb/testsuite/gdb.base/vla-ptr.exp +++ b/gdb/testsuite/gdb.base/vla-ptr.exp @@ -14,6 +14,7 @@ # along with this program. If not, see . =20 standard_testfile +set using_clang [test_compiler_info clang*] =20 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } = { return -1 @@ -38,4 +39,40 @@ gdb_test "print *vla_ptr" " =3D 2" "print *vla_ptr (ba= r)" =20 gdb_breakpoint [gdb_get_line_number "vla_func_bp"] gdb_continue_to_breakpoint "vla_func_bp" -gdb_test "print td_vla" " =3D \\\{4, 5, 6, 7, 8\\\}" + +gdb_test_multiple "print td_vla" "" { + -re -wrap " =3D \\\{4, 5, 6, 7, 8\\\}" { + pass $gdb_test_name + } + -re -wrap " =3D $hex" { + if { $using_clang } { + # Clang 10.0.1 fails to generate complete type info, see + # note below. + xfail $gdb_test_name + # Verify that despite the incomplete type info, the variable is + # there and has the right value. + gdb_test "p *td_vla@5" " =3D \\\{4, 5, 6, 7, 8\\\}" + } else { + fail $gdb_test_name + } + } +} + +# Clang 10.0.1 generates this DWARF for td_vla: +# +# A variable DIE: +# <2><19f>: Abbrev Number: 6 (DW_TAG_variable) +# <1a0> DW_AT_location : 0x39 (location list) +# <1a4> DW_AT_name : td_vla +# <1aa> DW_AT_type : <0x1ae> +# with type: +# <2><1ae>: Abbrev Number: 7 (DW_TAG_typedef) +# <1af> DW_AT_type : <0x1fc> +# <1b3> DW_AT_name : typedef_vla +# pointing to: +# <1><1fc>: Abbrev Number: 11 (DW_TAG_array_type) +# <1fd> DW_AT_type : <0x1d3> +# <2><201>: Abbrev Number: 14 (DW_TAG_subrange_type) +# <202> DW_AT_type : <0x1f5> +# +# The subrange type is missing the count attribute. diff --git a/gdb/testsuite/gdb.dwarf2/count.exp b/gdb/testsuite/gdb.dwarf= 2/count.exp index 5cefb15da4a..4d44a29331e 100644 --- a/gdb/testsuite/gdb.dwarf2/count.exp +++ b/gdb/testsuite/gdb.dwarf2/count.exp @@ -28,7 +28,10 @@ set asm_file [standard_output_file $srcfile2] Dwarf::assemble $asm_file { cu {} { compile_unit {{language @DW_LANG_C99}} { - declare_labels char_label array_label array_label2 static_array_lab= el + declare_labels char_label \ + array_label array_label2 array_label3 \ + static_array_label \ + len_label =20 char_label: base_type { {name char} @@ -54,6 +57,24 @@ Dwarf::assemble $asm_file { } } =20 + len_label: DW_TAG_variable { + {type :$char_label} + {location { + const1u 6 + stack_value + } SPECIAL_expr} + } + + array_label3: array_type { + {name arraytype3} + {type :$char_label} + } { + subrange_type { + {count :$len_label} + {type :$char_label} + } + } + static_array_label: array_type { {type :$char_label} } { @@ -69,6 +90,11 @@ Dwarf::assemble $asm_file { {const_value 65 DW_FORM_udata} } =20 + DW_TAG_variable { + {name array3} + {type :$array_label3} + } + DW_TAG_variable { {name array} {type :$array_label} @@ -123,3 +149,6 @@ gdb_test "ptype static_array" "type =3D char \\\[5\\\= ]" gdb_test "whatis static_array" "type =3D char \\\[5\\\]" gdb_test "print static_array" " =3D \"world\"" gdb_test "print sizeof static_array" " =3D 5" + +gdb_test "ptype array3" "type =3D char \\\[6\\\]" +gdb_test "p array3" " =3D " --------------9EE4607E340F05E0C74EA73A--