Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Jun 2001 23:09:42 -0400 (EDT)
From:      Patrick Alken <cosine@ellipse.mcs.drexel.edu>
To:        <freebsd-hackers@freebsd.org>
Subject:   ptrace
Message-ID:  <Pine.BSF.4.30.0106022306300.1294-100000@ellipse.mcs.drexel.edu>

next in thread | raw e-mail | index | archive | help
  I am coding a simple debugger, and I need to know the proper way to
save and restore the state of the debugger's terminal when the child
process is not executing. For example, if the debugger ptraces a process
which gets a signal and returns control to the debugger, the debugger
needs to restore the original terminal settings, in case the ptraced
process messed with them. I am currently using a setup like this:

if (isatty(STDIN_FILENO))
  tcgetattr(STDIN_FILENO, &termin);
if (isatty(STDOUT_FILENO))
  tcgetattr(STDOUT_FILENO, &termout);
if (isatty(STDERR_FILENO))
  tcgetattr(STDERR_FILENO, &termerr);

PtraceProcessUntilSignal();

if (isatty(...)) {
  tcsetattr(STDIN_FILENO, TCSANOW, &termin);
  tcsetattr(STDOUT_FILENO, TCSANOW, &termout);
  tcsetattr(STDERR_FILENO, TCSANOW, &termerr);
}

For simplicity I did not show the error checking above, but the terminal
calls never return -1.. The above code does not work - if I hit CONTROL-C
or give the ptraced process another signal, it returns control to the
debugger, but the debugger's terminal does not get restored properly.
ie: the debugger will still accept input but does not output stuff
correctly. The terminal sometimes doesn't scroll up properly when you type
newlines etc..
 If anyone has any info which could help me out here I would greatly
appreciate it as I am not very familiar with the tcgetattr/tcsetattr
stuff. Thanks in advance.

Patrick Alken



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.30.0106022306300.1294-100000>