From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id cF4lJQ8ouWBoIwAAWB0awg (envelope-from ) for ; Thu, 03 Jun 2021 15:05:51 -0400 Received: by simark.ca (Postfix, from userid 112) id 93E101F165; Thu, 3 Jun 2021 15:05:51 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, 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 4B4001EE74 for ; Thu, 3 Jun 2021 15:05:50 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 13D55383302E for ; Thu, 3 Jun 2021 19:05:50 +0000 (GMT) Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by sourceware.org (Postfix) with ESMTPS id 3A667398FC31 for ; Thu, 3 Jun 2021 19:03:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3A667398FC31 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-wm1-f45.google.com with SMTP id g204so4017509wmf.5 for ; Thu, 03 Jun 2021 12:03:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HucQ4Gu+yzXN7iR3bKdJrU167K2aCfffaJPyx/w5xDg=; b=Z+b9gVbTLX2sh7GX9Kh1M7MsAmWeWi8GVV3xTmGfD77k9nfe0gcY3fj2QaRfiC+2kx alcdYsj0SA5cwSuZPgDLngTLkbIuXRVfrXBgtdZ1rv3sgeae6jBCdeL64TE2YDaenld2 Y0rUI+aEoWzcycuoIQbiJ69BhnBDZxxbqeaz5K9DxVZ8NEwYierQMAFU39C+MXs/eW5J gI8y655VpeBmK73b6HB7ziRPCEePhL1UBqVJ8DqeuCfjT+//kM98SuC6pHwT92ds5GFU zaFk7vktY8SsGhH7nMjVonbfZ/bgk6x3UctGnNw3jJYo85rIHyWWhs6Z0pQ9KVsUCjqJ AN5w== X-Gm-Message-State: AOAM5305xiHRjMxFT9k/wWN+mACDk55wc9OlKKeLnp12KBTmCJhaFycX t4jFHJpgFTgOvKbB2kgBs3cMOtfARlCbpA== X-Google-Smtp-Source: ABdhPJzU6yfLfdQ44VI0UzvzcON1j3HRp7cb+kGbnMTj0Dy+IJ9V+cWjYY4NVgxtzQWcB6csFsnS+A== X-Received: by 2002:a05:600c:2948:: with SMTP id n8mr11451747wmd.95.1622746981569; Thu, 03 Jun 2021 12:03:01 -0700 (PDT) Received: from localhost ([2001:8a0:f932:6a00:6b6e:c7b6:c5a7:aac3]) by smtp.gmail.com with ESMTPSA id r2sm4285316wrv.39.2021.06.03.12.03.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Jun 2021 12:03:00 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 07/17] Special-case "set inferior-tty /dev/tty" Date: Thu, 3 Jun 2021 20:02:33 +0100 Message-Id: <20210603190243.2609886-8-pedro@palves.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210603190243.2609886-1-pedro@palves.net> References: <20210603190243.2609886-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" The following patches will make GDB spawn inferiors in their own session and tty by default. Meaning, GDB will create and manage a pty for the inferior instead of the inferior and GDB sharing the same terminal and GDB having to juggle terminal settings depending on whether the inferior running or gdb showing the prompt. For some use cases however, it will still be useful to be able to tell GDB to spawn the inferior in the same terminal & session as GDB, like today. Setting the inferior tty to "/dev/tty" seems like an obvious way to get that, as /dev/tty is a special file that represents the terminal for the current process. This leaves "tty" with no arguments free for a different behavior. This patch hardcodes "/dev/tty" in is_gdb_terminal for that reason. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * inflow.c (is_gdb_terminal): Hardcode "/dev/tty". (new_tty): Don't create a tty if is_gdb_terminal is true. (new_tty_postfork): Always allocate a run_terminal. (create_tty_session): Don't create a session if sharing the terminal with GDB. Change-Id: I4dc7958f823fa4e30c21a2c3fe4d8434a5d5ed40 --- gdb/inflow.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/gdb/inflow.c b/gdb/inflow.c index d241540c4cd..15f29dcd08e 100644 --- a/gdb/inflow.c +++ b/gdb/inflow.c @@ -222,6 +222,11 @@ is_gdb_terminal (const char *tty) struct stat other_tty; int res; + /* Users can explicitly set the inferior tty to "/dev/tty" to mean + "the GDB terminal". */ + if (strcmp (tty, "/dev/tty") == 0) + return TRIBOOL_TRUE; + res = stat (tty, &other_tty); if (res == -1) return TRIBOOL_UNKNOWN; @@ -796,9 +801,10 @@ check_syscall (const char *msg, int result) #endif void -new_tty (void) +new_tty () { - if (inferior_thisrun_terminal == 0) + if (inferior_thisrun_terminal == nullptr + || is_gdb_terminal (inferior_thisrun_terminal)) return; #if !defined(__GO32__) && !defined(_WIN32) int tty; @@ -862,13 +868,13 @@ new_tty_postfork (void) /* Save the name for later, for determining whether we and the child are sharing a tty. */ - if (inferior_thisrun_terminal) - { - struct inferior *inf = current_inferior (); - struct terminal_info *tinfo = get_inflow_inferior_data (inf); + struct inferior *inf = current_inferior (); + struct terminal_info *tinfo = get_inflow_inferior_data (inf); - tinfo->run_terminal = xstrdup (inferior_thisrun_terminal); - } + if (inferior_thisrun_terminal != nullptr) + tinfo->run_terminal = xstrdup (inferior_thisrun_terminal); + else + tinfo->run_terminal = xstrdup ("/dev/tty"); inferior_thisrun_terminal = NULL; } @@ -927,7 +933,9 @@ create_tty_session (void) #ifdef HAVE_SETSID pid_t ret; - if (!job_control || inferior_thisrun_terminal == 0) + if (!job_control + || inferior_thisrun_terminal == nullptr + || is_gdb_terminal (inferior_thisrun_terminal)) return 0; ret = setsid (); -- 2.26.2