From owner-freebsd-hackers Sat Jun 2 20: 9:56 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from ellipse.mcs.drexel.edu (ellipse.mcs.drexel.edu [129.25.7.190]) by hub.freebsd.org (Postfix) with SMTP id 6691B37B423 for ; Sat, 2 Jun 2001 20:09:53 -0700 (PDT) (envelope-from cosine@ellipse.mcs.drexel.edu) Received: (qmail 1296 invoked by uid 1001); 3 Jun 2001 03:09:42 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 3 Jun 2001 03:09:42 -0000 Date: Sat, 2 Jun 2001 23:09:42 -0400 (EDT) From: Patrick Alken To: Subject: ptrace Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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