www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/06/02:40:28

Date: Mon, 6 May 1996 09:33:51 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: "Charles W. Kann" <ckann AT seas DOT gwu DOT edu>
Cc: djgpp AT delorie DOT com
Subject: Re: gdb and stdout
In-Reply-To: <4mighk$7h1@cronkite.seas.gwu.edu>
Message-Id: <Pine.SUN.3.91.960506091015.13129K-100000@is>
Mime-Version: 1.0
Thread: Frames, NoFrames, TwoWindows

On 5 May 1996, Charles W. Kann wrote:

> I am having a problem with gdb and version 2 of djgpp, redirecting stdout.
> The basic problem is I want stdout from gdb to go to a file, and the 
> user's output to go to the Console (CON).  The rest of this tells what I
> have done, and what I have found does not work.

Under MS-DOS, the gdb and the debuggee share file handles, because it's
essentially a single program from the system's point of view (it is still
a single-task DOS!).  A simple implication of this fact is that you just
can't accomplish what you are trying to do without changing either the way
gdb works on MS-DOS or the way the debuggee prints its output (or both). 
The way things are right now, gdb writes its output to stdout, so anything
you do with stdout in your program immediately affects gdb too:  if your
program calls `dup', gdb's stdout is also redirected; if you close handle
1, you can't see gdb's output at all, etc.  Any trick that works around
this simple fact is IMHO just exploiting specific knowledge about inner
library workings and is subject to stop working without notice.  (I also 
don't think such tricks are possible at all in v2.)

Solutions?  I can think about a few:

	1) Make your program print to another file handle (e.g., to
stderr), or open (not freopen) CON on another file handle and write to
that handle. 

	2) Make your program use console output (cputs, cprintf etc.)

	3) Use a program such as `script' that can save to a file
everything that is written to the screen.  (The FAQ tells you in section
6.9 where to get `script'.)

I suggest the last option, unless it proves to be unsuitable for your 

Personally, I think gdb should be changed to use console output on MS-DOS,
which will solve these problems (and a few others) like a snap.  Somebody
with enough motivation and time should sit down and do it.

- Raw text -

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2014   by DJ Delorie     Updated Aug 2014