From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id USPxHKWi+WAgVQAAWB0awg (envelope-from ) for ; Thu, 22 Jul 2021 12:53:57 -0400 Received: by simark.ca (Postfix, from userid 112) id 65B6A1EDFB; Thu, 22 Jul 2021 12:53:57 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,T_DKIM_INVALID,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 6A8B81E79C for ; Thu, 22 Jul 2021 12:53:56 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E5AD03982003 for ; Thu, 22 Jul 2021 16:53:55 +0000 (GMT) Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 13319398382C for ; Thu, 22 Jul 2021 16:53:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 13319398382C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x429.google.com with SMTP id f17so6640735wrt.6 for ; Thu, 22 Jul 2021 09:53:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=r/1F+/ScNkKuTLIjWQWaTZ+2/AF7DOEonsdRhDS9nmk=; b=TQkppcsb78oa4rkl6EIhCivEyXXLhGN/aS+VMqj10alDYYaMwwW6p4pR5SvK5xJETq k/QugMqeS/zbpcR/Ml+BseFQvnzZZG5oJhbDal4VNzM6YK1ku5Y/6rtD7ti/xYvTNBBF UJ1FA7tiQkE7SdDF4fyZIGtL3Fk2LU9Ix/Q8pORKX2RlQFVWLjqLXQK6VFp3T56iCGQt xGUQrvq7oq4vj3rNZJ7rsRA7UAax+6UGlozoavioQE4BpMUz3bw4hKyaAULfWzhMtqQK 2DrAnHmP8qwPJaUFIZcAbbXqXMiOjTCH8Wgm9STYG2em0o/Hy3ZLxx0Qt3TvsZIOu0Ao ejmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=r/1F+/ScNkKuTLIjWQWaTZ+2/AF7DOEonsdRhDS9nmk=; b=Qt311umO1uz6Ox09B40SScJdJfn9pBAJ+3gVj3BUOsEqg11KgV5yk2Oc8ffJw9bD/i 7pGR8XC7jcqBSKpk0b5kbZGJjjQ3ZIRgEMBp1uBlzyYXxXat/oqS4wd6JMoFAY1gxfDL dV1yyXc/BqW4fEqbY72ACGPENGOrhhJfHfyovElGCBCEHOEpcddx0Hy33bXQNMPbB41Z RzeFVeB+tc0y7G2E9OIDaYJ9mdt1inGiNGswPSZR9Bt7rwbnLdUlLWN0B01XChEkUDES hFebBzjveuBwoFgMvj4kXBXXyV2n+2bAnwB+SarxfthLYLXTXT9LJcqyv3Lhqe75W7q6 XtaQ== X-Gm-Message-State: AOAM532FDy0fSI3DdH3nsKICE8B9CFXr6uQ0LALoWarlorc8NMi9eN7R l9++NPVlTJj5VCz7OaOwSWJDLg== X-Google-Smtp-Source: ABdhPJx0QEqp8tRz6gWVQyPVyTsTIYAipcdloiace7yGmYDshGNbYgRGCxZ0CiCcuzHYs9nZNFZVfw== X-Received: by 2002:a5d:6304:: with SMTP id i4mr934123wru.406.1626972816200; Thu, 22 Jul 2021 09:53:36 -0700 (PDT) Received: from localhost (host86-161-16-194.range86-161.btcentralplus.com. [86.161.16.194]) by smtp.gmail.com with ESMTPSA id f11sm2944223wmb.14.2021.07.22.09.53.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jul 2021 09:53:35 -0700 (PDT) Date: Thu, 22 Jul 2021 17:53:34 +0100 From: Andrew Burgess To: Bernd Edlinger Subject: [PATCHv2] Fix the crash at the end of the runtest Message-ID: <20210722165334.GE1872618@embecosm.com> References: <20210722124457.GC1872618@embecosm.com> <20210722132020.GD1872618@embecosm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210722132020.GD1872618@embecosm.com> X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 17:52:34 up 6 days, 3:26, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] 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: , Cc: "gdb-patches@sourceware.org" Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Thanks for the feedback. Below is the patch I intend to push first thing tomorrow unless anyone objects. Thanks, Andrew --- commit 41424acf01830d3cafb838a7d865985182edf47a Author: Andrew Burgess Date: Thu Jul 22 14:07:15 2021 +0100 gdb/testsuite: don't error when trying to unset last_spawn_tty_name In spawn_capture_tty_name (lib/gdb.exp) we either set or unset last_spawn_tty_name depending on whether spawn_out(slave,name) exists or not. One situation that might cause spawn_out(slave,name) to not exists is if the spawn function is called with the argument -leaveopen, which is how it is called when processes are created as part of a pipeline, the created process has no tty, instead its output is written to a file descriptor. If a pipeline is created consisting of multiple processes then there will be multiple sequential calls to spawn, all using -leaveopen. The first of these calls is fine, spawn_out(slave,name) is not set, and so in spawn_capture_tty_name we unset last_spawn_tty_name. However, on the second call to spawn, spawn_out(slave,name) is still not set and so in spawn_capture_tty_name we again try to unset last_spawn_tty_name, this now throws an error (as last_spawn_tty_name is already unset). Fix this issue by using -nocomplain with the call to unset in spawn_capture_tty_name. Before this commit I was seeing gdb.base/gnu-debugdata.exp report 1 pass, and 1 unsupported test. After this commit I now see 16 passes from this test script. I have also improved the code that used to do this: if { [info exists spawn_out] } { set ::last_spawn_tty_name $spawn_out(slave,name) } else { ... } The problem here is that we check for the existence of spawn_out, and then unconditionally read spawn_out(slave,name). A situation could arise where some other element of spawn_out is set, e.g. spawn_out(foo), in which case we would enter the if block and try to read a non-existent variable. After this commit we now check specifically for spawn_out(slave,name). Finally, it is worth noting that before this issue was fixed runtest itself, or rather the expect process behind runtest, would segfault while exiting. I haven't looked at all into what the problem is here that caused expect to crash, as fixing the bug in GDB's testing scripts made the segfault go away. diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index e79e0622f9d..aeb8585bab9 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -2029,10 +2029,20 @@ proc gdb_file_cmd { arg } { proc spawn_capture_tty_name { args } { set result [uplevel builtin_spawn $args] upvar spawn_out spawn_out - if { [info exists spawn_out] } { + if { [info exists spawn_out(slave,name)] } { set ::last_spawn_tty_name $spawn_out(slave,name) } else { - unset ::last_spawn_tty_name + # If a process is spawned as part of a pipe line (e.g. passing + # -leaveopen to the spawn proc) then the spawned process is no + # assigned a tty and spawn_out(slave,name) will not be set. + # In that case we want to ensure that last_spawn_tty_name is + # not set. + # + # If the previous process spawned was also not assigned a tty + # (e.g. multiple processed chained in a pipeline) then + # last_spawn_tty_name will already be unset, so, if we don't + # use -nocomplain here we would otherwise get an error. + unset -nocomplain ::last_spawn_tty_name } return $result }