Message ID | 20231117111840.2040709-1-ahajkova@redhat.com |
---|---|
Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B97CA38582B5 for <patchwork@sourceware.org>; Fri, 17 Nov 2023 11:19:00 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 06F723858D32 for <gdb-patches@sourceware.org>; Fri, 17 Nov 2023 11:18:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 06F723858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 06F723858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700219927; cv=none; b=d+PtBVJYn4R16jPtAX//GN2HR0AnfWiQpmkCD1aEnLN3A3AomNNzf6hKX5FYvbCUgg3Ws+XILYtr4Kzh4P78sAJxMGW5v6DltMRe9py1cH+jjtlNoXG77d7YNqWFRbR2iBMERArZf8BhI2MA4OnhbvJhYRKj8VWkSxaN4IXvBxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700219927; c=relaxed/simple; bh=euHsiYg9u4VmpX0yxp6JWBu2guygqSXpz5OfvBtKuK0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EUkHJIAt8GeijqaU1TBnFbF9TPMX5PxdGoxzHZVloGawZYUyi6LdTcvsSB9MxeQh0BPxp4ofuYnM8HgCharsZx5SNcTXjZ7SW+hq22Dyvby1eapBbjwZR5mOYRnM4omv28YNartgHCLBnJbJdqv4Ub3vidKM4WbzPuOQpJqs4YI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700219925; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/doeyAcw8jFJV61ZusTz/31s9fjvs7QQg3btQ+P9grw=; b=O9JzpTna8xNjlHJ2x3hCSQQWkCJJfy3zVcm4LhBuh839jZPuiLEG77G1d8d86qokKrTS8G LCQ7rmV6JAcX7XxpKoeeIz8pFv5v72L9t7Ll9qi0n//XH/R7DiNpgH+Blzj/JhKOh47WQh hnVTxwf8N6gTrP+seLmAHrpedc/2TJM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-397-ljzTC5JnPs-00W0_-vuOLw-1; Fri, 17 Nov 2023 06:18:44 -0500 X-MC-Unique: ljzTC5JnPs-00W0_-vuOLw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0CF30811E7B for <gdb-patches@sourceware.org>; Fri, 17 Nov 2023 11:18:44 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.242.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B5612026D4C; Fri, 17 Nov 2023 11:18:42 +0000 (UTC) From: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= <ahajkova@redhat.com> To: gdb-patches@sourceware.org Cc: ahajkova@redhat.com Subject: [PATCH 0/6] Add vDefaultInferiorFd feature Date: Fri, 17 Nov 2023 12:18:34 +0100 Message-ID: <20231117111840.2040709-1-ahajkova@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org |
Series |
Add vDefaultInferiorFd feature
|
|
Message
Alexandra Petlanova Hajkova
Nov. 17, 2023, 11:18 a.m. UTC
Currently, when GDBserver is run locally using stdio, the inferior is unable to read from STDIN so we can't give it any input. The main motivation to address this issue is to use GDB together with Valgrind, using vgdb --multi feature which allows to run Valgrind from inside GDB. Valgrind then acts as a locally run GDBserver that uses stdio. Add a new DefaultInferiorFd feature and the corresponding packet. This feature allows GDB to send, to GDBserver, the file descriptor numbers of the terminal to which GDB is connected. The inferior is then started connected to the same terminal as GDB. This allows the inferior run by local GDBserver to read from GDB's STDIN and write its output to GDB's STOUT/ERR the same way as native target. Alexandra Hájková (6): gdb.server/non-existing-program.exp: Use gdbserver_start. gdb/ser-pipe.c: Duplicate the file descriptors Add new vDefaultInferiorFd packet gdbserver/linux-low.cc: Connect the inferior to the terminal remote.c: Add terminal handling functions Add defaultinf.exp test to the testsuite gdb/doc/gdb.texinfo | 32 +++++ gdb/remote.c | 83 +++++++++++ gdb/ser-pipe.c | 25 ++++ gdb/serial.c | 4 + gdb/serial.h | 4 + gdb/testsuite/gdb.server/defaultinf.c | 39 ++++++ gdb/testsuite/gdb.server/defaultinf.exp | 59 ++++++++ .../gdb.server/non-existing-program.exp | 54 ++----- gdb/testsuite/lib/gdbserver-support.exp | 62 +++++--- gdbserver/linux-low.cc | 32 ++++- gdbserver/server.cc | 132 +++++++++++++++++- gdbserver/server.h | 12 ++ 12 files changed, 476 insertions(+), 62 deletions(-) create mode 100644 gdb/testsuite/gdb.server/defaultinf.c create mode 100644 gdb/testsuite/gdb.server/defaultinf.exp
Comments
Ping On Fri, Nov 17, 2023 at 12:18 PM Alexandra Hájková <ahajkova@redhat.com> wrote: > Currently, when GDBserver is run locally using stdio, the inferior > is unable to read from STDIN so we can't give it any input. > The main motivation to address this issue is to use GDB together > with Valgrind, using vgdb --multi feature which allows to run > Valgrind from inside GDB. Valgrind then acts as a locally run > GDBserver that uses stdio. > > Add a new DefaultInferiorFd feature and the corresponding packet. > This feature allows GDB to send, to GDBserver, the file descriptor > numbers of the terminal to which GDB is connected. The inferior is > then started connected to the same terminal as GDB. This allows the > inferior run by local GDBserver to read from GDB's STDIN and write > its output to GDB's STOUT/ERR the same way as native target. > > > > Alexandra Hájková (6): > gdb.server/non-existing-program.exp: Use gdbserver_start. > gdb/ser-pipe.c: Duplicate the file descriptors > Add new vDefaultInferiorFd packet > gdbserver/linux-low.cc: Connect the inferior to the terminal > remote.c: Add terminal handling functions > Add defaultinf.exp test to the testsuite > > gdb/doc/gdb.texinfo | 32 +++++ > gdb/remote.c | 83 +++++++++++ > gdb/ser-pipe.c | 25 ++++ > gdb/serial.c | 4 + > gdb/serial.h | 4 + > gdb/testsuite/gdb.server/defaultinf.c | 39 ++++++ > gdb/testsuite/gdb.server/defaultinf.exp | 59 ++++++++ > .../gdb.server/non-existing-program.exp | 54 ++----- > gdb/testsuite/lib/gdbserver-support.exp | 62 +++++--- > gdbserver/linux-low.cc | 32 ++++- > gdbserver/server.cc | 132 +++++++++++++++++- > gdbserver/server.h | 12 ++ > 12 files changed, 476 insertions(+), 62 deletions(-) > create mode 100644 gdb/testsuite/gdb.server/defaultinf.c > create mode 100644 gdb/testsuite/gdb.server/defaultinf.exp > > -- > 2.41.0 > >
>>>>> "Alexandra" == Alexandra Hájková <ahajkova@redhat.com> writes:
FWIW I tend to think Pedro ought to review this, since he's got the most
up-to-date experience with terminal handling, etc; or at least more so
than I do.
I do have a few comments on the implementation, but before that, I
wanted to ask a bit about the overall approach.
Alexandra> Currently, when GDBserver is run locally using stdio, the inferior
Alexandra> is unable to read from STDIN so we can't give it any input.
This idea in general seems fine to me (pending Pedro's input).
It's also in line with, and probably needed by, the idea of moving gdb
to a "gdbserver-only" model:
https://sourceware.org/gdb/wiki/LocalRemoteFeatureParity
It's never been super clear to me if gdbserver-only is a real goal or
just something we talk about idly. I've been on the fence about it
myself, though more recently I tend to like the idea, simply because it
means less work -- I've written a number of patches now that needed work
on both gdb and gdbserver, and this project would halve that kind of
effort.
Alexandra> Add a new DefaultInferiorFd feature and the corresponding packet.
One question I had is - why a new packet? A new packet seems somewhat
weird, in that it's only valid pretty early during startup, it seems.
Another approach might be to have a different way to specify the
connection fd to the remote, like a command-line option naming the fd to
use for RSP traffic.
Tom
Tom Tromey <tom@tromey.com> writes: >>>>>> "Alexandra" == Alexandra Hájková <ahajkova@redhat.com> writes: > > FWIW I tend to think Pedro ought to review this, since he's got the most > up-to-date experience with terminal handling, etc; or at least more so > than I do. > > I do have a few comments on the implementation, but before that, I > wanted to ask a bit about the overall approach. > > Alexandra> Currently, when GDBserver is run locally using stdio, the inferior > Alexandra> is unable to read from STDIN so we can't give it any input. > > This idea in general seems fine to me (pending Pedro's input). > It's also in line with, and probably needed by, the idea of moving gdb > to a "gdbserver-only" model: > > https://sourceware.org/gdb/wiki/LocalRemoteFeatureParity > > It's never been super clear to me if gdbserver-only is a real goal or > just something we talk about idly. I've been on the fence about it > myself, though more recently I tend to like the idea, simply because it > means less work -- I've written a number of patches now that needed work > on both gdb and gdbserver, and this project would halve that kind of > effort. I wouldn't describe it as the only thing I'm working on, but this is, lets say, my background goal, part of my 10 year plan :) I suspect my motivation is the same as yours -- the code duplication between GDB and gdbserver is annoying. And even if we managed some super code refactor, and managed to share 100% of the native handling code between GDB and gdbserver, I suspect simply having the remote interface in-between would introduce its only differences. Better, I think, to have just one way of doing things. Honestly, I suspect I may never get there, there are just too many distractions, but I'm hoping to work on closing the gap between native and remote over the next couple of years. Then, maybe, who knows... Anyway, I just thought I'd register my very real interest in working towards a remote-only setup. Thanks, Andrew > > Alexandra> Add a new DefaultInferiorFd feature and the corresponding packet. > > One question I had is - why a new packet? A new packet seems somewhat > weird, in that it's only valid pretty early during startup, it seems. > > Another approach might be to have a different way to specify the > connection fd to the remote, like a command-line option naming the fd to > use for RSP traffic. > > Tom
> > Alexandra> Add a new DefaultInferiorFd feature and the corresponding > packet. > > One question I had is - why a new packet? A new packet seems somewhat > weird, in that it's only valid pretty early during startup, it seems. > > Another approach might be to have a different way to specify the > connection fd to the remote, like a command-line option naming the fd to > use for RSP traffic. > Are you imagining something like "target remote | gdbserver --once RSP_FD ...." ? And GDB would replace RSP_FD with the actual file descriptor to use? I agree that's a good idea but both approaches have pros and cons. You are correct that a command line approach is better because it avoids adding a new packet and the whole FD switching business. But adding the new packet approach makes it easier for the users. It's possible to run GDB to then run Valgrind from inside by using simply target extended-remote | vgdb --multi I hope this command will be replaced with an even simpler " target valgrind" at some point. If we wanted to use the feature with GDBserver, I think, it's always more user-friendly when the user does not have to set any additional command-line options. Thanks, Alexandra
>>>>> "Alexandra" == Alexandra Petlanova Hajkova <ahajkova@redhat.com> writes: > Another approach might be to have a different way to specify the > connection fd to the remote, like a command-line option naming the fd to > use for RSP traffic. Alexandra> Are you imagining something like "target remote | gdbserver --once RSP_FD ...." ? Alexandra> And GDB would replace RSP_FD with the actual file descriptor to use? Yeah. Alexandra> avoids adding a new packet and the whole FD switching business. But adding the new Alexandra> packet approach makes it easier for the users. It's possible to run GDB to then run Alexandra> Valgrind from inside by using simply Alexandra> target extended-remote | vgdb --multi Alexandra> I hope this command will be replaced with an even simpler " target valgrind" at Alexandra> some point. Part of the idea would be to hide the new file descriptor handling behind the "target valgrind" facade. That is, the implementation of "target valgrind" would handle setting up the command line arguments to vgdb. Tom
Tom Tromey <tom@tromey.com> writes: >>>>>> "Alexandra" == Alexandra Petlanova Hajkova <ahajkova@redhat.com> writes: > >> Another approach might be to have a different way to specify the >> connection fd to the remote, like a command-line option naming the fd to >> use for RSP traffic. > > Alexandra> Are you imagining something like "target remote | gdbserver --once RSP_FD ...." ? > Alexandra> And GDB would replace RSP_FD with the actual file descriptor to use? > > Yeah. There is one problem I see with this approach, maybe a bit of an edge case, but, what if the application wanted to use the text RSP_FD elsewhere in it's command line. For example, a user does: (gdb) target remote | gdbserver --once RSP_FD /tmp/myprog And everything is great, GDB replaces RSP_FD with the descriptor to use for RSP traffic, and that's fine. Or a user does: (gdb) target remote | gdbserver --once /tmp/myprog And GDB doesn't spot RSP_FD, so doesn't redirect the RSP traffic, and just continues to use stdin/stdout as it does right now. But what about the poor user who needs to do this: (gdb) target remote | gdbserver --once /tmp/myprog RSP_FD that is the 'RSP_FD' is an actual argument string to pass to 'myprog'! Unlikely maybe, but not impossible. Anything that requires GDB to understand the command that appears after the `|` suffers from the possibility that GDB might get it wrong. > > Alexandra> avoids adding a new packet and the whole FD switching business. But adding the new > Alexandra> packet approach makes it easier for the users. It's possible to run GDB to then run > Alexandra> Valgrind from inside by using simply > > Alexandra> target extended-remote | vgdb --multi > > Alexandra> I hope this command will be replaced with an even simpler " target valgrind" at > Alexandra> some point. > > Part of the idea would be to hide the new file descriptor handling > behind the "target valgrind" facade. That is, the implementation of > "target valgrind" would handle setting up the command line arguments to > vgdb. Even writing a Python wrapper doesn't really solve the above problem, it just shifts it from GDB into the Python code. And (I think) ideally we wouldn't rely on users having to write a Python wrapper in order to use this feature with their own tools, so it would be nice if this feature was usable from pure GDB. Maybe it's just enough to add an on/off control setting, and have GDB announce when it's performed the command line replacements. Then (hopefully) users will know that if they don't want this feature they could turn this off... Just my thoughts. Thanks, Andrew
I sent some reviews, but I wanted to reiterate this bit: Tom> FWIW I tend to think Pedro ought to review this, since he's got the most Tom> up-to-date experience with terminal handling, etc; or at least more so Tom> than I do. In particular I wonder if palves/tty-always-separate-session helps solve this in a different way. Tom