From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by sourceware.org (Postfix) with ESMTPS id E0E853858423 for ; Tue, 30 Nov 2021 12:17:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E0E853858423 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f52.google.com with SMTP id q3so21119783wru.5 for ; Tue, 30 Nov 2021 04:17:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=GTIZCj0OpjqO6XvgY4N1OzrnfrZ1OP/YxpBTP5i7ing=; b=fP0Bj6si9cEktVPgwILP+k7gYyhvus0zUEr7J+/aNUJRj2/cmv9CLy9fRlmMJx5nxd EzPJBrUPoyB9A1owBuQFphUB3v7xCe8Ry2YxpkIDO/6e12dU2z1bNyL0jYnQcFpPGq4D JmFXHrcoTiAP9pBJ18LOxa0MaxItoYiV+BYZ8qiDHpd4nwqIsSMcAe1vPu2FnAEX7rlz 9hcjq3LWkUEGb3zf9Oz0fBLBuAlHfi4/AsDL2Zh71HJe4Dl49UrvaPA/amTUhytTkWxA ttpVsrhH44W/IrK1LmeoJaSUrqEsBzAY425nbgcoWjPb1BqTr50WMazSGdTx7/d2PUU1 EKBA== X-Gm-Message-State: AOAM530C6oOGwxBt95K2THhtBDhrXo+JgwxRLoKbvNZppdM6N4qQnjHa YcImGWbwluEt/5o14VxZZHTVCJ+mt3E= X-Google-Smtp-Source: ABdhPJzYlnp7kQ6TD/tqGuZn2iRsmGEbYgzl/731DaETU3UIm/SFtGIhQ2fLk60BIPDdfyFRLiaH3Q== X-Received: by 2002:a5d:69ce:: with SMTP id s14mr40577770wrw.25.1638274657769; Tue, 30 Nov 2021 04:17:37 -0800 (PST) Received: from ?IPV6:2001:8a0:f912:1a00:fb57:3faf:e98:b979? ([2001:8a0:f912:1a00:fb57:3faf:e98:b979]) by smtp.gmail.com with ESMTPSA id r8sm20617251wrz.43.2021.11.30.04.17.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Nov 2021 04:17:36 -0800 (PST) Message-ID: Date: Tue, 30 Nov 2021 12:17:35 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: [PATCH v2 2/2] ppc: recognize all program traps Content-Language: en-US To: Jan Vrany , gdb-patches@sourceware.org Cc: lsix@lancelotsix.com References: <20211123154237.2335848-1-jan.vrany@labware.com> <20211124130926.2412617-1-jan.vrany@labware.com> <20211124130926.2412617-3-jan.vrany@labware.com> From: Pedro Alves In-Reply-To: <20211124130926.2412617-3-jan.vrany@labware.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Tue, 30 Nov 2021 12:17:55 -0000 On 2021-11-24 13:09, Jan Vrany via Gdb-patches wrote: > +# Number of expected SIGTRAP's to get. This needs to be kept in sync > +# with the source file. > +set expected_traps 3 > +set keep_going 1 > +set count 0 > + > +# Make sure we have a lower timeout in case GDB doesn't support a particular > +# instruction. Such instruction will cause GDB to loop infinitely. > +while {$keep_going} { > + # Continue to next program breakpoint instruction. > + gdb_test_multiple "continue" "trap instruction $count causes SIGTRAP" { > + -re "Program received signal SIGTRAP, Trace/breakpoint trap.*$gdb_prompt $" { > + pass $gdb_test_name > + > + # Advance PC to next instruction > + gdb_test "set \$pc = \$pc + 4" "" "advance past trap instruction $count" > + > + incr count > + } > + # We've reached the end of the test. > + -re "exited with code 01.*$gdb_prompt $" { > + set keep_going 0 > + } > + timeout { > + fail $gdb_test_name > + set keep_going 0 > + } > + } > +} > + This while loop will iterate forever if gdb_test_multiple trips on some internal match, like some unexpected text out of gdb that ends with a prompt, or an internal error. The logic of "keep_going" should be reversed so that the loop breaks if anything goes wrong. Also, the last continue to "exited with code 01" doesn't itself issue a pass unlike the other continues, which seems inconsistent. BTW, if we flip the logic, we no longer need the timeout check. Something like this (completely untested): ~~~~~~~~~~~~ # Number of expected SIGTRAP's to get. This needs to be kept in sync # with the source file. set expected_traps 3 set count 0 set keep_going 1 # Make sure we have a lower timeout in case GDB doesn't support a particular # instruction. Such instruction will cause GDB to loop infinitely. while {$keep_going} { set keep_going 0 # Continue to next program breakpoint instruction. gdb_test_multiple "continue" "trap instruction $count causes SIGTRAP" { -re "Program received signal SIGTRAP, Trace/breakpoint trap.*$gdb_prompt $" { pass $gdb_test_name # Advance PC to next instruction gdb_test "set \$pc = \$pc + 4" "" "advance past trap instruction $count" incr count if {$count < $expected_traps} { set keep_going 1 } } } # Verify we stopped at the expected number of SIGTRAP's. gdb_assert {$count == $expected_traps} "all trap instructions triggered" # One last continue to reach the end of the test, to make sure we don't get # another SIGTRAP. gdb_test "continue" "exited with code 01.*" "continue to end" ~~~~~~~~~~~~ Some thing in the other file. Or you could merge the files, and make the exp file set a different .S filename and different "expected_traps" depending on arch, to avoid duplication. BTW, I don't understand what the "Make sure we have a lower timeout" comment is referring to -- I don't see anything changing the timeout. BTW², seems strange to expect that the program exits with exit code 1 instead of 0 on a success run. I can't write PPC assembly to save my life, but I don't see any "1", or writing to r3 in in the assembly, so I guess that is assuming the value is already 1 on entry. I wonder whether that's a good assumption in all environments.