[comp.windows.x] How do you use an Xterm with a debugger

jtc@motcad.portal.com (J.T. Conklin) (03/13/91)

I would like to be able to open an Xterm so I can redirect terminal output
to it from within gdb.  This would allow me to debug tty based programs
from my workstation without me having to connect an ascii terminal to a 
serial port.  Can this be done?

-- 
J.T. Conklin    jtc@motcad.portal.com, ...!portal!motcad!jtc

jtc@motcad.portal.com (J.T. Conklin) (03/14/91)

In article <1991Mar13.011536.17184@motcad.portal.com> jtc@motcad.portal.com (J.T. Conklin) writes:
>I would like to be able to open an Xterm so I can redirect terminal output
>to it from within gdb.  This would allow me to debug tty based programs
>from my workstation without me having to connect an ascii terminal to a 
>serial port.  Can this be done?

Sorry to followup my own posting, but my query was missing the fact that I
also need to redirect terminal _Input_ from the "debugging window"  The 
problem I am having stems from the fact that the shell in the xterm competes
with my program for terminal input.

    --jtc

-- 
J.T. Conklin    jtc@motcad.portal.com, ...!portal!motcad!jtc

barmar@think.com (Barry Margolin) (03/14/91)

In article <1991Mar13.011536.17184@motcad.portal.com> jtc@motcad.portal.com (J.T. Conklin) writes:
>I would like to be able to open an Xterm so I can redirect terminal output
>to it from within gdb.

Why don't you just run gdb from the xterm window?
--
Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

mikeo@sae.UUCP (Michael Ovington) (03/14/91)

In article <1991Mar13.220110.21768@motcad.portal.com> jtc@motcad.portal.com (J.T. Conklin) writes:
>In article <1991Mar13.011536.17184@motcad.portal.com> jtc@motcad.portal.com (J.T. Conklin) writes:
>>I would like to be able to open an Xterm so I can redirect terminal output
>>to it from within gdb.  This would allow me to debug tty based programs
>>from my workstation without me having to connect an ascii terminal to a 
>>serial port.  Can this be done?
>
>Sorry to followup my own posting, but my query was missing the fact that I
>also need to redirect terminal _Input_ from the "debugging window"  The 
>problem I am having stems from the fact that the shell in the xterm competes
>with my program for terminal input.
>
>    --jtc
>
>-- 
>J.T. Conklin    jtc@motcad.portal.com, ...!portal!motcad!jtc

In the xterm that actually runs the aplication, do a sleep 100000 on the
command line to stop it from processing input.
Then in your debugging window run you application and redirect input from
the other xterm and ouput to it.
On a sun running dbx the command would look something like:
(dbx) run </dev/ttyp7 >/dev/ttyp7
different debuggers will certainly have different syntax, but should support
something like this.
________________________________________________________________________________
      Michael S. Ovington               Software A&E
      (703) 276-7910                    1600 Wilson Blvd, Suite 500
      uunet!sae!mikeo                   Arlington, VA 22209
      mikeo@sae.com
________________________________________________________________________________

rmtodd@servalan.uucp (Richard Todd) (03/15/91)

barmar@think.com (Barry Margolin) writes:

>In article <1991Mar13.011536.17184@motcad.portal.com> jtc@motcad.portal.com (J.T. Conklin) writes:
>>I would like to be able to open an Xterm so I can redirect terminal output
>>to it from within gdb.

>Why don't you just run gdb from the xterm window?

Uh, I think you've misinterpreted slightly what the original poster's
after.  You see, gdb has a command that allows the target program to do all
its I/O on a different tty (or pseudo-tty) than the one that gdb is running
on.  This is very useful if you're debugging curses applications, where
otherwise the gdb output would mess up your fancy display and make it hard
to figure out what's going on.  So what the guy wants is to run gdb in one
xterm window and have the target program's I/O go thru *another* xterm
window.  But, by default xterm puts a shell on its pseudo-tty, and when
both your target program and the shell try to read from the same tty, Bad
Things happen.  There are a couple of ways to work around this.  The cheap
and sleazy way (the one I used :-) was to simply type "sleep 10000" in the
target xterm window and let gdb attatch the target program to that tty.
Obviously, this will run into problems if your program expects to receive
signals from the keyboard (i.e. the default signal-causing behaviour of ^C
etc isn't disabled)--the ^C will kill the sleep and the shell will return
to try and grab your input.  (It also runs into problems if it takes more
than 10000 seconds==2.7 hours to debug your program...) The more elegant
solution is to write a special purpose program to just sit there, turn off
all keyboard signals, and do nothing.  It's a fairly straighforward 
exercise in C coding.  
--
Richard Todd	rmtodd@uokmax.ecn.uoknor.edu  rmtodd@chinet.chi.il.us
	rmtodd@servalan.uucp
"Try looking in the Yellow Pages under 'Psychotics'." -- Michael Santana

n025fc@tamuts.tamu.edu (Kevin Weller) (03/16/91)

Have you tried xterm's -S option?  The online manual entry will tell
you how to use it.

--
------------------------------------------------------------------------------
Kevin L. Weller                                 /-------+--------------------\
internet: n025fc@tamuts.tamu.edu                |  aTm  |  GIG 'EM, AGGIES!  |
CIS:      73327,1447  (but I rarely log on)     \-------+--------------------/
------------------------------------------------------------------------------
%SYS-E-BADOPSYS, Fatal system error, DEC VMS halting  / "And now for something
-SYS-I-GETUNIX, Replace with UNIX immediately!       /  completely different."
----------------------------------------------------------------- Monty Python

barmar@think.com (Barry Margolin) (03/17/91)

In article <1991Mar15.074424.857@servalan.uucp> rmtodd@servalan.uucp (Richard Todd) writes:
>barmar@think.com (Barry Margolin) writes:
>>In article <1991Mar13.011536.17184@motcad.portal.com> jtc@motcad.portal.com (J.T. Conklin) writes:
>>>I would like to be able to open an Xterm so I can redirect terminal output
>>>to it from within gdb.
>>Why don't you just run gdb from the xterm window?
>Uh, I think you've misinterpreted slightly what the original poster's
>after.

Yes, I did.  However, a variant on my response is still applicable.

Gdb has an "attach" command that allows it to be used to debug a process
that is already running, rather than running the application in a
subprocess.  So, you could start up the application in one xterm, run gdb
in another xterm, and then attach gdb to the application process.

The only problem with this approach is that you can't set breakpoints
before starting the application, so if the buggy area of the program is run
early you may not be able to attach quickly enough.
--
Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

tro@adiron.uucp (Tom Olin) (03/19/91)

In article <1991Mar17.072157.19385@Think.COM> barmar@think.com (Barry Margolin)
writes:

   Gdb has an "attach" command that allows it to be used to debug a process
   that is already running....  The only problem with this approach is that ...
   if the buggy area of the program is run early you may not be able to attach
   quickly enough.

The way around this is to put a sleep(30) or so at the beginning of main().
That gives you plenty of time to attach.
--
	Tom Olin	uunet!adiron!tro	(315) 738-0600 Ext 638
 PAR Technology Corporation * 220 Seneca Turnpike * New Hartford NY 13413-1191