From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTP id B487F386EC45 for ; Thu, 1 Apr 2021 17:58:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B487F386EC45 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 90CB356153; Thu, 1 Apr 2021 13:58:34 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com 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 xliOfRamP0Fv; Thu, 1 Apr 2021 13:58:34 -0400 (EDT) Received: from murgatroyd.Home (71-211-182-15.hlrn.qwest.net [71.211.182.15]) (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 4D95F5612C; Thu, 1 Apr 2021 13:58:34 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/2] Avoid crash in Ada value printing with optimized-out array Date: Thu, 1 Apr 2021 11:58:31 -0600 Message-Id: <20210401175831.3373671-3-tromey@adacore.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210401175831.3373671-1-tromey@adacore.com> References: <20210401175831.3373671-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, 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: Thu, 01 Apr 2021 17:58:36 -0000 The Ada value-printing code could crash when printing an array which had been optimized out. The crash is difficult to reproduce, but I did manage to write a test that at least shows that the previous behavior was incorrect -- before the patch, the array is printed as if it is valid and every value is 0. gdb/ChangeLog 2021-04-01 Tom Tromey * ada-valprint.c (ada_value_print_array): Handle optimized-out arrays. gdb/testsuite/ChangeLog 2021-04-01 Tom Tromey * gdb.dwarf2/arr-stride.exp: Add test. --- gdb/ChangeLog | 5 ++++ gdb/ada-valprint.c | 5 +++- gdb/testsuite/ChangeLog | 4 +++ gdb/testsuite/gdb.dwarf2/arr-stride.exp | 33 ++++++++++++++++++++++++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index 0d5b6d73076..61c903bbed5 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -897,7 +897,10 @@ ada_value_print_array (struct value *val, struct ui_file *stream, int recurse, fprintf_filtered (stream, "("); print_optional_low_bound (stream, type, options); - if (TYPE_FIELD_BITSIZE (type, 0) > 0) + + if (value_entirely_optimized_out (val)) + val_print_optimized_out (val, stream); + else if (TYPE_FIELD_BITSIZE (type, 0) > 0) { const gdb_byte *valaddr = value_contents_for_printing (val); int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr; diff --git a/gdb/testsuite/gdb.dwarf2/arr-stride.exp b/gdb/testsuite/gdb.dwarf2/arr-stride.exp index bf30f10c5c8..f25518f4558 100644 --- a/gdb/testsuite/gdb.dwarf2/arr-stride.exp +++ b/gdb/testsuite/gdb.dwarf2/arr-stride.exp @@ -31,7 +31,7 @@ Dwarf::assemble $asm_file { {DW_AT_comp_dir /tmp} } { declare_labels integer_label array_elt_label array_label \ - big_array_label + big_array_label struct_label integer_label: DW_TAG_base_type { {DW_AT_byte_size 4 DW_FORM_sdata} @@ -79,6 +79,34 @@ Dwarf::assemble $asm_file { {DW_AT_upper_bound 4 DW_FORM_data1} } } + + struct_label: DW_TAG_structure_type { + {name struct_type} + {byte_size 16 DW_FORM_sdata} + } { + member { + {name intfield} + {type :$integer_label} + {data_member_location 0 DW_FORM_sdata} + } + member { + {name arrayfield} + {type :$array_label} + {data_member_location 4 DW_FORM_sdata} + } + } + + DW_TAG_variable { + {name the_struct} + {external 1 DW_FORM_flag} + {location { + DW_OP_const1u 1 + DW_OP_stack_value + DW_OP_piece 4 + DW_OP_piece 12 + } SPECIAL_expr} + {type :$struct_label} + } } } } @@ -95,3 +123,6 @@ gdb_test "ptype pck.table" \ gdb_test "ptype pck.big_table" \ "type = array \\(0 \\.\\. 4\\) of pck\\.item " + +gdb_test "print the_struct" \ + "\\(intfield => 1, arrayfield => \\(0 => \\)\\)" -- 2.26.2