From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4D0B23856DCD for ; Thu, 27 Jul 2023 07:41:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4D0B23856DCD Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690443704; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BkowRi3WnnSbhYv3USM2+g79CIjEbW8OrvBMTHDD0II=; b=Lk/QBd/j5Md5j+JeYd1Ts7z5ITyzVcsuTvGkGkBkZ2c51x8LAP3fOHcVcQfvaeJyoD8wT5 3fLNX5bV+mPPwwNtqbGRDaeZVnQJrfrfzoOhqyOtwW5dBevahzW95Cn5po287Q8Od+dFrK XadQsV4hpMoGi8tSoMsKMw6m0MVDlwQ= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-298-Jul8au60Obaa9-e5LWElcA-1; Thu, 27 Jul 2023 03:41:43 -0400 X-MC-Unique: Jul8au60Obaa9-e5LWElcA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ED28B1C4766D for ; Thu, 27 Jul 2023 07:41:42 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7429E4094DC1; Thu, 27 Jul 2023 07:41:42 +0000 (UTC) From: Bruno Larsen To: gdb-patches@sourceware.org Cc: Bruno Larsen Subject: [PATCH v2 3/4] gdb/testsuite: fix testing gdb.reverse/step-reverse.exp with clang Date: Thu, 27 Jul 2023 09:41:17 +0200 Message-ID: <20230727074118.1583199-4-blarsen@redhat.com> In-Reply-To: <20230727074118.1583199-1-blarsen@redhat.com> References: <20230725095833.236804-1-blarsen@redhat.com> <20230727074118.1583199-1-blarsen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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: When testing using reverse-stepi to fully step through a function, the code checks for an infinite loop by seeing if we land on the line that contains the return statement multiple times. This assumption only works if there is only one instruction associated with that line, which is how GCC handles line information, but other compilers may handle it differently. Clang-15, for instance, associates 6. Because of this, the inferior used to get seriously out of sync with the test expectations, and result in 13 spurious failures. The same issue occurs with gdb.reverse/step-precsave.exp. This commit changes the test so that we check for PC instead of line number. The test still only happens when the same line is detected, to simplify the resulting log. With this change, no new failures are emitted when using clang. It also adds a new parameter to get_hexadecimal_valueof, so that we can use it without generating new passes, otherwise we'd get multiple duplicate test names. This change shouldn't affect any other test using this proc. --- gdb/testsuite/gdb.reverse/step-precsave.exp | 18 +++++++++++++++++- gdb/testsuite/gdb.reverse/step-reverse.exp | 20 +++++++++++++++++++- gdb/testsuite/lib/gdb.exp | 6 ++++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/gdb/testsuite/gdb.reverse/step-precsave.exp b/gdb/testsuite/gdb.reverse/step-precsave.exp index 19cd5d9930e..da3a47e07e2 100644 --- a/gdb/testsuite/gdb.reverse/step-precsave.exp +++ b/gdb/testsuite/gdb.reverse/step-precsave.exp @@ -30,6 +30,16 @@ if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { return -1 } +proc get_current_pc {} { + set pc 0 + gdb_test_multiple "print \$pc" "" { + -re -wrap ".*0x(\[0-9a-f\]+).*" { + set pc $expect_out(1,string) + } + } + return $pc +} + runto_main # Activate process record/replay @@ -209,11 +219,17 @@ gdb_test_multiple "stepi" "$test_message" { # stepi backward out of a function call +set start_pc [get_current_pc] set stepi_location [gdb_get_line_number "STEPI TEST" "$srcfile"] set test_message "reverse stepi from a function call" gdb_test_multiple "stepi" "$test_message" { -re "ARRIVED IN CALLEE.*$gdb_prompt $" { - fail "$test_message (start statement)" + if { [get_current_pc] == $start_pc } { + fail "$test_message (start statement)" + } else { + send_gdb "stepi\n" + exp_continue + } } -re "ENTER CALLEE.*$gdb_prompt $" { send_gdb "stepi\n" diff --git a/gdb/testsuite/gdb.reverse/step-reverse.exp b/gdb/testsuite/gdb.reverse/step-reverse.exp index 4b78a8f8fb7..9ff97bfde42 100644 --- a/gdb/testsuite/gdb.reverse/step-reverse.exp +++ b/gdb/testsuite/gdb.reverse/step-reverse.exp @@ -28,6 +28,16 @@ if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { return -1 } +proc get_current_pc {} { + set pc 0 + gdb_test_multiple "print \$pc" "" { + -re -wrap ".*0x(\[0-9a-f\]+).*" { + set pc $expect_out(1,string) + } + } + return $pc +} + runto_main if [supports_process_record] { @@ -174,11 +184,19 @@ gdb_test_multiple "stepi" "$test_message" { # stepi backward out of a function call +# When testing stepi, we dont want to infinitely step if we're not moving +# so we store the starting PC, in case we land on the same line as above +set start_pc [get_hexadecimal_valueof "\$pc" 0 "" "false"] set stepi_location [gdb_get_line_number "STEPI TEST" "$srcfile"] set test_message "reverse stepi from a function call" gdb_test_multiple "stepi" "$test_message" { -re "ARRIVED IN CALLEE.*$gdb_prompt $" { - fail "$test_message (start statement)" + if { [get_hexadecimal_valueof "\$pc" 0 "" "false"] == $start_pc } { + fail "$test_message (start statement)" + } else { + send_gdb "stepi\n" + exp_continue + } } -re "ENTER CALLEE.*$gdb_prompt $" { send_gdb "stepi\n" diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 63b6291fc36..37342583e0a 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -7919,7 +7919,7 @@ proc get_integer_valueof { exp default {test ""} } { # TEST is the test message to use. It can be omitted, in which case # a test message is built from EXP. -proc get_hexadecimal_valueof { exp default {test ""} } { +proc get_hexadecimal_valueof { exp default {test ""} {pass true} } { global gdb_prompt if {$test == ""} { @@ -7930,7 +7930,9 @@ proc get_hexadecimal_valueof { exp default {test ""} } { gdb_test_multiple "print /x ${exp}" $test { -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" { set val $expect_out(1,string) - pass "$test" + if { "$pass" == "true" } { + pass "$test" + } } } return ${val} -- 2.41.0