From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 448 invoked by alias); 2 Aug 2010 23:11:48 -0000 Received: (qmail 439 invoked by uid 22791); 2 Aug 2010 23:11:48 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 02 Aug 2010 23:11:43 +0000 Received: from hpaq5.eem.corp.google.com (hpaq5.eem.corp.google.com [172.25.149.5]) by smtp-out.google.com with ESMTP id o72NBfLq020975 for ; Mon, 2 Aug 2010 16:11:41 -0700 Received: from vws11 (vws11.prod.google.com [10.241.21.139]) by hpaq5.eem.corp.google.com with ESMTP id o72NB09b017039 for ; Mon, 2 Aug 2010 16:11:40 -0700 Received: by vws11 with SMTP id 11so2344420vws.22 for ; Mon, 02 Aug 2010 16:11:39 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.126.129 with SMTP id c1mr4644359vcs.214.1280790699393; Mon, 02 Aug 2010 16:11:39 -0700 (PDT) Received: by 10.220.186.74 with HTTP; Mon, 2 Aug 2010 16:11:39 -0700 (PDT) In-Reply-To: <20100608172738.GA17570@caradoc.them.org> References: <20100525172715.A9BE38439A@ruffy.mtv.corp.google.com> <20100608172738.GA17570@caradoc.them.org> Date: Mon, 02 Aug 2010 23:11:00 -0000 Message-ID: Subject: Re: [RFA] stdio gdbserver connection From: Doug Evans To: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-08/txt/msg00003.txt.bz2 On Tue, Jun 8, 2010 at 10:27 AM, Daniel Jacobowitz w= rote: > On Tue, May 25, 2010 at 10:27:15AM -0700, Doug Evans wrote: >> Hi. >> >> This patch lets gdbserver communicate via stdio. >> >> E.g. >> >> (gdb) target remote | ssh -T myhost gdbserver stdio hello > > Silly thing to comment about but... "-" instead to mean stdio? Sure. I avoided it but I don't have a strong preference. >> One outstanding issue is what to do with inferior stdio. >> stderr is ok, it'll just get propagated back to gdb which will display i= t. >> But we don't want inferior stdio to interfere with the gdb connection. > > Send it to a pipe, pass it to GDB over semihosting? Does semihosting work with non-stop mode? An alternative, I think, is to redirect the inferior's stdout,stderr to gdbserver's stderr, and redirect stdin to /dev/null (say). That feels like more of a hack than explicitly handling inferior stdio. But it's simpler, or at least should be theoretically ... alas when gdbserver is starting it calls start_inferior before remote_open, and thus unless one makes the chosen kind of connection known before remote_open is called (or passes "port" to start_inferior, blech), it's a non-starter. Sigh. Even when not using stdio, it can be useful to have the inferior's stdio fed back to gdb, so that's probably the way to go (as an option) anyway. Except that it depends on my above question: Does semihosting work with non-stop mode? AIUI, currently it doesn't, but presumably it could be made to. [This feature isn't something that should be all-stop mode only.] >> + =A0 =A0 =A0/* Use stdin as the handle of the connection. >> + =A0 =A0 =A0We only select on reads, for example. =A0*/ >> + =A0 =A0 =A0remote_desc =3D 0; > > 0 -> STDIN_FILENO? =A0That's what you check for. Right, missed that. I think I'll go with fileno(). >> Index: gdbserver/server.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> RCS file: /cvs/src/src/gdb/gdbserver/server.c,v >> retrieving revision 1.120 >> diff -u -p -r1.120 server.c >> --- gdbserver/server.c =A0 =A0 =A0 =A03 May 2010 04:02:20 -0000 =A0 =A0 = =A0 1.120 >> +++ gdbserver/server.c =A0 =A0 =A0 =A025 May 2010 16:48:02 -0000 >> @@ -2502,11 +2502,17 @@ main (int argc, char *argv[]) >> >> =A0 =A0 =A0 =A0/* If an exit was requested (using the "monitor exit" com= mand), >> =A0 =A0 =A0 =A0terminate now. =A0The only other way to get here is for >> - =A0 =A0 =A0getpkt to fail; close the connection and reopen it at the >> + =A0 =A0 =A0getpkt to fail; if the connection is via stdio terminate no= w, >> + =A0 =A0 =A0otherwise close the connection and reopen it at the >> =A0 =A0 =A0 =A0top of the loop. =A0*/ >> >> - =A0 =A0 =A0if (exit_requested) >> + =A0 =A0 =A0if (exit_requested >> + =A0 =A0 =A0 || remote_connection_is_stdio ()) >> =A0 =A0 =A0 { >> + =A0 =A0 =A0 if (debug_threads >> + =A0 =A0 =A0 =A0 =A0 && remote_connection_is_stdio ()) >> + =A0 =A0 =A0 =A0 fprintf (stderr, "Remote side has terminated connectio= n. =A0" >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"Shutting down.\n"); >> =A0 =A0 =A0 =A0 detach_or_kill_for_exit (); >> =A0 =A0 =A0 =A0 exit (0); >> =A0 =A0 =A0 } > > This will print the message if exit_requested && > remote_connection_is_stdio (); was that intended? Not so much intended as not caring as it was just a debugging message. >> +@smallexample >> +(gdb) target remote | ssh -T gdbserver stdio emacs foo.txt >> +@end smallexample >> + >> +The @samp{-T} option to ssh is provided because we don't need a remote = pty, >> +and we don't want escape-character handling. > > Host name is missing. =A0Doesn't ssh default to -T if there's a command? Right. Re: -T: I didn't know whether it did, but at least in openssh's implementation it does. > I've no complaints about the general feature. > > A caveat somewhere about running with a terminal might be in order. > Apps that write directly to the tty are unfortunately not too > uncommon. > > -- > Daniel Jacobowitz > CodeSourcery >