From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 0369C3858D35 for ; Fri, 15 Sep 2023 15:03:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0369C3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-il1-x12a.google.com with SMTP id e9e14a558f8ab-34e1ddc38c6so7735765ab.3 for ; Fri, 15 Sep 2023 08:03:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1694790193; x=1695394993; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=a1qlYXd7upoBiyiDMWCR4nSzb//Gjh03qRuzKvZTfxY=; b=FcZv8V6V11eEYqhriZJsQwiv46HVA78oLohMY372Wbt1muItIF4b5+Nivm43UGDpCC 8nylyhDyJfbstPlkef1Udjxs8VQGroWTigO27nDUbr0jEZt6Vdoc91ZNvMHS9qjtuKo8 yGWIrnpjoEf41mnsCe6eU1gRa8xv4OWlHBO2coz+XCkhtMNQo/fPFLEzF+qQF1DE1E1v w1hl6x7cPruKXVTJV20NbEGpXF3TBUpkyT7Ffcb+tdMwUBnvVpx10jy0zmmq+mnckJ+S v5uq7A8coHMcmB6J8OojdeU1dr8WUwUsAOU5l4YiIcDP5KHm8gNvf1QCjaHXxQ/AWvHn BE3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694790193; x=1695394993; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=a1qlYXd7upoBiyiDMWCR4nSzb//Gjh03qRuzKvZTfxY=; b=X5Cl5MvukEeJpIEn1PiB1l0HL7vOtR2EFMvx4WPf8zmdWqGeeT4yirEpVjbSWvRs0W xampfqe8z+tuPbKl8jUabHMOG+AOtv7QK3OXn3CffqSlvUvVDUCo3HAWjF94+Z/fcwaw zdRtBh3Atpvyb3oVmJIJq2nn9m1iJNFpiS2DckquqrdDZPtL4L4TdqVb/1j6uENMxs1q dZFIyXTxaQ0emN7kEVRbkaM6mSM/KlPdSteAEnE/Z0M4EZHTECPiLliyINPWcokA8Q4D RZJo52Ka4r00EdBlHmhtuwAEHgGjOZMuuniTzYrjDmSYw7XEcub0rVVss6Xjv4t+/x+F qOwg== X-Gm-Message-State: AOJu0Yy99XYGsOj/NVkQcwGQP+gVf2VP8bI9wUxeiDU8JbyHlG0MMRM2 EuGGFVmA+kr2JVaBrluRU9HPa9MClpspNaqPwwE91w== X-Google-Smtp-Source: AGHT+IHkejC0EGURghGdtudYjZF37r2KQdZxhoTv3kmTGVpJ19BZJdaC2xBNg36+tEEIcpALw//Eqg== X-Received: by 2002:a05:6e02:106b:b0:349:865d:a06 with SMTP id q11-20020a056e02106b00b00349865d0a06mr2146168ilj.4.1694790193026; Fri, 15 Sep 2023 08:03:13 -0700 (PDT) Received: from localhost.localdomain (71-211-130-31.hlrn.qwest.net. [71.211.130.31]) by smtp.gmail.com with ESMTPSA id a14-20020a92ce4e000000b003460b697bc0sm1161643ilr.59.2023.09.15.08.03.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 08:03:12 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Clean up intermediate values in val_print_packed_array_elements Date: Fri, 15 Sep 2023 09:03:02 -0600 Message-Id: <20230915150302.2138965-1-tromey@adacore.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Following on Tom de Vries' work in the other array-printers, this patch changes val_print_packed_array_elements to also avoid allocating too many values when printing an Ada packed array. --- gdb/ada-valprint.c | 8 ++++ gdb/testsuite/gdb.ada/huge.exp | 72 +++++++++++++++--------------- gdb/testsuite/gdb.ada/huge/pck.adb | 6 +++ 3 files changed, 51 insertions(+), 35 deletions(-) diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index eaeca0f6516..b32f1e506d1 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -150,6 +150,11 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, while (i < len && things_printed < options->print_max) { + /* Both this outer loop and the inner loop that checks for + duplicates may allocate many values. To avoid using too much + memory, both spots release values as they work. */ + scoped_value_mark outer_free_values; + struct value *v0, *v1; int i0; @@ -180,6 +185,9 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, bitsize, elttype); while (1) { + /* Make sure to free any values in the inner loop. */ + scoped_value_mark free_values; + i += 1; if (i >= len) break; diff --git a/gdb/testsuite/gdb.ada/huge.exp b/gdb/testsuite/gdb.ada/huge.exp index 71b440e8c59..7a2037af0d0 100644 --- a/gdb/testsuite/gdb.ada/huge.exp +++ b/gdb/testsuite/gdb.ada/huge.exp @@ -48,45 +48,47 @@ for { set size $max } { $size >= $min } { set size [expr $size / 2] } { } require {expr $compilation_succeeded} -clean_restart ${testfile} +foreach_with_prefix varname {Arr Packed_Arr} { + clean_restart ${testfile} -save_vars { timeout } { - set timeout 30 + save_vars { timeout } { + set timeout 30 - if {![runto "foo"]} { - return - } + if {![runto "foo"]} { + return + } - gdb_test_no_output "set max-value-size unlimited" - gdb_test_no_output "maint set per-command space on" - set re1 \ - [list \ - [string_to_regexp $] \ - $decimal \ - " = " \ - [string_to_regexp "(0 )"]] - set re2 \ - [list \ - "Space used: $decimal" \ - [string_to_regexp " (+"] \ - "($decimal) for this command" \ - [string_to_regexp ")"]] - set re [multi_line [join $re1 ""] [join $re2 ""]] - set space_used -1 - gdb_test_multiple "print Arr" "print a very large data object" { - -re -wrap $re { - set space_used $expect_out(1,string) - pass $gdb_test_name + gdb_test_no_output "set max-value-size unlimited" + gdb_test_no_output "maint set per-command space on" + set re1 \ + [list \ + [string_to_regexp $] \ + $decimal \ + " = " \ + [string_to_regexp "(0 )"]] + set re2 \ + [list \ + "Space used: $decimal" \ + [string_to_regexp " (+"] \ + "($decimal) for this command" \ + [string_to_regexp ")"]] + set re [multi_line [join $re1 ""] [join $re2 ""]] + set space_used -1 + gdb_test_multiple "print $varname" "print a very large data object" { + -re -wrap $re { + set space_used $expect_out(1,string) + pass $gdb_test_name + } } - } - set test "not too much space used" - if { $space_used == -1 } { - unsupported $test - } else { - # At 56 passes with and without the fix, so use 55. - gdb_assert {$space_used < [expr 55 * 4 * $size] } $test + set test "not too much space used" + if { $space_used == -1 } { + unsupported $test + } else { + # At 56 passes with and without the fix, so use 55. + gdb_assert {$space_used < [expr 55 * 4 * $size] } $test + } } } diff --git a/gdb/testsuite/gdb.ada/huge/pck.adb b/gdb/testsuite/gdb.ada/huge/pck.adb index 09988fbeb25..47e6e928ca2 100644 --- a/gdb/testsuite/gdb.ada/huge/pck.adb +++ b/gdb/testsuite/gdb.ada/huge/pck.adb @@ -14,6 +14,7 @@ -- along with this program. If not, see . package body Pck is + subtype Small_Int is Integer range 0 .. 7; type My_Int is range -2147483648 .. 2147483647; #if CRASHGDB = 16 @@ -75,6 +76,11 @@ package body Pck is array (Index) of My_Int; Arr : My_Int_Array := (others => 0); + type My_Packed_Array is array (Index) of Small_Int; + pragma Pack (My_Packed_Array); + + Packed_Arr : My_Packed_Array := (others => 0); + procedure Foo is begin null; -- 2.40.1