From patchwork Fri Feb 22 12:36:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 31553 Received: (qmail 82999 invoked by alias); 22 Feb 2019 12:36:35 -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 82976 invoked by uid 89); 22 Feb 2019 12:36:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, KAM_TK, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=UD:tk, gross X-HELO: EUR02-AM5-obe.outbound.protection.outlook.com Received: from mail-eopbgr00052.outbound.protection.outlook.com (HELO EUR02-AM5-obe.outbound.protection.outlook.com) (40.107.0.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 22 Feb 2019 12:36:33 +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=9DCG/viI5889+Ehv2mNGKugPUuYb8jR6YFCVOQsmu7g=; b=ky60Zbj2HXj8JnpZBMTVApp3ZUlP/HruY/HBHzEn7RY62y5D9ByFZBekeuL5Vx3xQwzsP4ahuXk1Ok1fF8eSK+BgvM7R2Eg9WZMLdwsz0FDFv0hQDMh41s0NUUihisumilUFDT57bV4kx5gkR0yXBF+MIyn/mj25S9zNrazRuOc= Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com (10.172.227.22) by DB6PR0802MB2584.eurprd08.prod.outlook.com (10.172.247.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1622.19; Fri, 22 Feb 2019 12:36:30 +0000 Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::e974:35a7:c83c:e5b7]) by DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::e974:35a7:c83c:e5b7%3]) with mapi id 15.20.1622.020; Fri, 22 Feb 2019 12:36:30 +0000 From: Alan Hayward To: Tom Tromey CC: "gdb-patches@sourceware.org" , nd Subject: Re: [PATCH] Testsuite: Ensure changing directory does not break the log file Date: Fri, 22 Feb 2019 12:36:30 +0000 Message-ID: References: <20190221103420.18162-1-alan.hayward@arm.com> <878sy8bwa5.fsf@tromey.com> In-Reply-To: <878sy8bwa5.fsf@tromey.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; x-ms-exchange-purlcount: 1 received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 Content-ID: MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-IsSubscribed: yes > On 21 Feb 2019, at 22:40, Tom Tromey wrote: > >>>>>> "Alan" == Alan Hayward writes: > > Alan> get_compiler_info switches to a new log file before checking the compiler > Alan> to ensure the checks are not logged. > > Haha, that seems pretty gross. It was quite a fun issue to track down :) > > Alan> The simpler and safer solution is to override the builtin cd function. The > Alan> new function checks the current log file and if the path is relative, then > Alan> it resets the logging using an absolute path. Finally it calls the builtin > Alan> cd. This ensures get_compiler_info (and any other code) can correctly > Alan> backup and restore the current log file. > > Makes sense to me. > > Alan> + if { [regexp "^-a \[^/\]" $saved_log match] } { > > It may be better here to just extract the file name and either use "file normalize" > (could be done unconditionally) or look at it with "file pathtype". > See https://www.tcl.tk/man/tcl8.4/TclCmd/file.htm > > Tom Re-written using normalize and I also made the checking better. With this version it will be safe regardless of the arguments used for log_file. This version ok? diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index d05854329d..f052bd2f3d 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -6284,5 +6284,37 @@ proc gdb_define_cmd {command command_list} { } } +# Safe version of cd that ensures the log file is not stopped. + +rename cd builtin_cd + +proc cd { dir } { + + # Get the existing log file flags. + set log_file_info [log_file -info] + + # Split the flags into args and file name. + set log_file_flags "" + set log_file_file "" + foreach arg [ split "$log_file_info" " "] { + if [string match "-*" $arg] { + lappend log_file_flags $arg + } else { + lappend log_file_file $arg + } + } + + # If there was an existing file, ensure it is an absolute path, and then + # reset logging. + if { $log_file_file != "" } { + set log_file_file [file normalize $log_file_file] + log_file + log_file $log_file_flags "$log_file_file" + } + + # Call the builtin version of cd. + builtin_cd $dir +} + # Always load compatibility stuff. load_lib future.exp