From patchwork Tue May 14 15:12:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 32680 Received: (qmail 60469 invoked by alias); 14 May 2019 15:12:59 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 60388 invoked by uid 89); 14 May 2019 15:12:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, MIME_BASE64_BLANKS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, UNSUBSCRIBE_BODY autolearn=ham version=3.3.1 spammy=Open, Answer X-HELO: EUR01-DB5-obe.outbound.protection.outlook.com Received: from mail-eopbgr150077.outbound.protection.outlook.com (HELO EUR01-DB5-obe.outbound.protection.outlook.com) (40.107.15.77) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 14 May 2019 15:12:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SDKsxxwaXSgOHi4qzwR+2NsglAL/pJtgNUFurzDHaaE=; b=DgaFR+UpvWSUXsZwLwW7iDI5lO5QQvlG0RFWlHtVFtYMnHZbK6Z8WGWBxoXJbBRRsX7WP3yOdiaPFBSm3kLKwAiWglIVXK329GcBKbE62bUXSMKb/Fb3fnDeKKbLzUeUGq76NiV2Jy9lvbkvOf8+MG8G/9HB0UcdXzsN3GE2SS4= Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com (10.172.227.22) by DB6PR0802MB2535.eurprd08.prod.outlook.com (10.172.251.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1878.24; Tue, 14 May 2019 15:12:46 +0000 Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::8c26:bb4b:6c93:9d40]) by DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::8c26:bb4b:6c93:9d40%2]) with mapi id 15.20.1878.024; Tue, 14 May 2019 15:12:46 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd , Alan Hayward Subject: [PATCH 5/9] testsuite: Record all gdb input to gdb.in Date: Tue, 14 May 2019 15:12:46 +0000 Message-ID: <20190514151238.8765-6-alan.hayward@arm.com> References: <20190514151238.8765-1-alan.hayward@arm.com> In-Reply-To: <20190514151238.8765-1-alan.hayward@arm.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; x-ms-oob-tlc-oobclassifiers: OLM:2582; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-IsSubscribed: yes When debugging testsuite failures, it can be awkward parsing gdb.log to obtain all the commands run in order to manually re-run the test. This patch adds the functionality to save all gdb commands to the file gdb.in when the testsuite is run. The file is saved in the directory for the test and if gdb is restarted then .1, .2, .3 etc is added to the filename. Once a test has been run, the .in file can be used to re-run the test in the following way: gdb -x outputs/gdb.store/gdb.in outputs/gdb.store/store The code works by intercepting send_gdb. I've added a TYPE to ensure that any commands that would destroy the playback are kept from the log (for example the Y from an answer to a y/n question). Adds library function standard_output_file_with_gdb_instance to open a file postfixed with count of the gdb instance. Ensure this count is reset when a new .exp script is run. I've re-run a random selection of .in files to check they do not error. Logs with commands such as "attach " will not directly work when re-run. gdb/testsuite/ChangeLog: 2019-05-14 Alan Hayward * lib/gdb.exp (gdb_unload): Mark Y as an answer. (delete_breakpoints): Likewise. (gdb_run_cmd): Likewise. (gdb_start_cmd): Likewise. (gdb_starti_cmd): Likewise. (gdb_internal_error_resync): Likewise. (gdb_test_multiple): Likewise. (gdb_reinitialize_dir): Likewise. (default_gdb_exit): Likewise. (gdb_file_cmd): Mark kill as optional. (default_gdb_start): Call gdb_stdin_log_init. (send_gdb): Call gdb_stdin_log_write. (rerun_to_main): Mark Y as an answer. (gdb_stdin_log_init): New function. (gdb_stdin_log_write): Likewise. --- gdb/testsuite/lib/gdb.exp | 106 +++++++++++++++++++++++++++++++------- 1 file changed, 88 insertions(+), 18 deletions(-) -- 2.20.1 (Apple Git-117) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index ba276ac9297..3815f86ffc8 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -167,11 +167,11 @@ proc gdb_unload {} { -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue } -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue } -re "A program is being debugged already.*Are you sure you want to change the file.*y or n. $" { - send_gdb "y\n" + send_gdb "y\n" answer exp_continue } -re "Discard symbol table from .*y or n.*$" { - send_gdb "y\n" + send_gdb "y\n" answer exp_continue } -re "$gdb_prompt $" {} @@ -201,7 +201,7 @@ proc delete_breakpoints {} { set deleted 0 gdb_test_multiple "delete breakpoints" "$msg" { -re "Delete all breakpoints.*y or n.*$" { - send_gdb "y\n" + send_gdb "y\n" answer exp_continue } -re "$gdb_prompt $" { @@ -307,7 +307,7 @@ proc gdb_run_cmd {args} { set start_attempt 0 } -re "Line.* Jump anyway.*y or n. $" { - send_gdb "y\n" + send_gdb "y\n" answer } -re "The program is not being run.*$gdb_prompt $" { if { [gdb_reload] != 0 } { @@ -335,7 +335,7 @@ proc gdb_run_cmd {args} { # may test for additional start-up messages. gdb_expect 60 { -re "The program .* has been started already.*y or n. $" { - send_gdb "y\n" + send_gdb "y\n" answer exp_continue } -notransfer -re "Starting program: \[^\r\n\]*" {} @@ -374,7 +374,7 @@ proc gdb_start_cmd {args} { # may test for additional start-up messages. gdb_expect 60 { -re "The program .* has been started already.*y or n. $" { - send_gdb "y\n" + send_gdb "y\n" answer exp_continue } -notransfer -re "Starting program: \[^\r\n\]*" { @@ -411,7 +411,7 @@ proc gdb_starti_cmd {args} { send_gdb "starti $args\n" gdb_expect 60 { -re "The program .* has been started already.*y or n. $" { - send_gdb "y\n" + send_gdb "y\n" answer exp_continue } -re "Starting program: \[^\r\n\]*" { @@ -673,11 +673,11 @@ proc gdb_internal_error_resync {} { while {$count < 10} { gdb_expect { -re "Quit this debugging session\\? \\(y or n\\) $" { - send_gdb "n\n" + send_gdb "n\n" answer incr count } -re "Create a core file of GDB\\? \\(y or n\\) $" { - send_gdb "n\n" + send_gdb "n\n" answer incr count } -re "$gdb_prompt $" { @@ -971,7 +971,7 @@ proc gdb_test_multiple { command message user_code } { set result -1 } -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " { - send_gdb "n\n" + send_gdb "n\n" answer gdb_expect -re "$gdb_prompt $" fail "$message (got interactive prompt)" set result -1 @@ -1451,7 +1451,7 @@ proc gdb_reinitialize_dir { subdir } { send_gdb "dir\n" gdb_expect 60 { -re "Reinitialize source path to empty.*y or n. " { - send_gdb "y\n" + send_gdb "y\n" answer gdb_expect 60 { -re "Source directories searched.*$gdb_prompt $" { send_gdb "dir $subdir\n" @@ -1511,7 +1511,7 @@ proc default_gdb_exit {} { send_gdb "quit\n" gdb_expect 10 { -re "y or n" { - send_gdb "y\n" + send_gdb "y\n" answer exp_continue } -re "DOSEXIT code" { } @@ -1568,11 +1568,12 @@ proc gdb_file_cmd { arg } { } # The file command used to kill the remote target. For the benefit - # of the testsuite, preserve this behavior. - send_gdb "kill\n" + # of the testsuite, preserve this behavior. Mark as optional so it doesn't + # get written to the stdin log. + send_gdb "kill\n" optional gdb_expect 120 { -re "Kill the program being debugged. .y or n. $" { - send_gdb "y\n" + send_gdb "y\n" answer verbose "\t\tKilling previous program being debugged" exp_continue } @@ -1599,7 +1600,7 @@ proc gdb_file_cmd { arg } { return 0 } -re "Load new symbol table from \".*\".*y or n. $" { - send_gdb "y\n" + send_gdb "y\n" answer gdb_expect 120 { -re "Reading symbols from.*$gdb_prompt $" { verbose "\t\tLoaded $arg with new symbol table into $GDB" @@ -1695,6 +1696,12 @@ proc default_gdb_start { } { return 0 } + # Keep track of the number of times GDB has been launched. + global gdb_instances + incr gdb_instances + + gdb_stdin_log_init + set res [gdb_spawn] if { $res != 0} { return $res @@ -3965,11 +3972,15 @@ proc gdb_compile_objc {source dest type options} { } } -proc send_gdb { string } { +# Send a command to GDB. +# For options for TYPE see gdb_stdin_log_write + +proc send_gdb { string {type standard}} { global suppress_flag if { $suppress_flag } { return "suppressed" } + gdb_stdin_log_write $string $type return [remote_send host "$string"] } @@ -4635,6 +4646,20 @@ proc standard_output_file {basename} { return [file join $dir $basename] } +# Turn BASENAME into a full file name in the standard output directory. If +# GDB has been launched more than once then append the count, starting with +# a ".1" postfix. + +proc standard_output_file_with_gdb_instance {basename} { + global gdb_instances + set count [expr $gdb_instances - 1 ] + + if {$count == 0} { + return [standard_output_file $basename] + } + return [standard_output_file ${basename}.${count}] +} + # Return the name of a file in our standard temporary directory. proc standard_temp_file {basename} { @@ -4829,6 +4854,10 @@ proc gdb_init { test_file_name } { set gdbserver_reconnect_p 1 unset gdbserver_reconnect_p + # Reset GDB number of instances + global gdb_instances + set gdb_instances 0 + return [default_gdb_init $test_file_name] } @@ -5097,7 +5126,7 @@ proc rerun_to_main {} { send_gdb "run\n" gdb_expect { -re "The program .* has been started already.*y or n. $" { - send_gdb "y\n" + send_gdb "y\n" answer exp_continue } -re "Starting program.*$gdb_prompt $"\ @@ -6470,5 +6499,46 @@ proc gdbserver_debug_enabled { } { return 0 } +# Open the file for logging gdb input + +proc gdb_stdin_log_init { } { + global in_file + + if {[info exists in_file]} { + # Close existing file. + catch "close $in_file" + } + + set logfile [standard_output_file_with_gdb_instance gdb.in] + set in_file [open $logfile w] +} + +# Write to the file for logging gdb input. +# TYPE can be one of the following: +# STANDARD : Default. Standard message written to the log +# ANSWER : Answer to a question (eg "Y"). Not written the log. +# OPTIONAL : Optional message. Not written to the log. + +proc gdb_stdin_log_write { message {type standard} } { + + global in_file + if {![info exists in_file]} { + return + } + + # Check message types. + switch -regexp -- $type { + "answer" { + return + } + "optional" { + return + } + } + + #Write to the log + puts -nonewline $in_file "$message" +} + # Always load compatibility stuff. load_lib future.exp