From owner-freebsd-hackers Tue Jun 11 10:55:16 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from security.is (security.is [62.145.149.99]) by hub.freebsd.org (Postfix) with ESMTP id D33D437B40D for ; Tue, 11 Jun 2002 10:55:03 -0700 (PDT) Received: by security.is (Postfix, from userid 1012) id 2AA4B15BD; Tue, 11 Jun 2002 17:59:40 +0000 (GMT) Date: Tue, 11 Jun 2002 17:59:40 +0000 From: silent To: hackers@freebsd.org Subject: ptrace problem Message-ID: <20020611175940.GA22937@security.is> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="VS++wcV0S1rZb1Fb" Content-Disposition: inline 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 --VS++wcV0S1rZb1Fb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi! there is a problem in ptrace code or my understanding of how it should work. man page says taht PT_DETACH acts same way PT_CONTIUNE does, but when i try to detach from process with PT_DETACH delayed? sigstop is delivered, and process becomes suspended. Valid solution/workaround seems to be in calling PT_CONTINUE with sigcont, and PT_DETACH after it. Example is attached. Please cc me a reply:) Thanks --VS++wcV0S1rZb1Fb Content-Type: text/plain; charset=us-ascii Content-Description: pt.c Content-Disposition: attachment; filename="fbsd_ptrace_prob.c" #include #include #include #include #include #include #include #include #include #define SIG(x) [SIG##x] "SIG"#x char *sigtable[] = { SIG(HUP), SIG(INT), SIG(QUIT), SIG(ILL), SIG(ABRT), SIG(FPE), SIG(KILL), SIG(SEGV), SIG(PIPE), SIG(ALRM), SIG(TERM), SIG(USR1), SIG(USR2), SIG(CHLD), SIG(CONT), SIG(STOP), SIG(TSTP), SIG(TTIN), SIG(TTOU), SIG(BUS), SIG(XCPU), SIG(XFSZ) }; void show (int status) { if (WIFEXITED (status)) printf ("ex %d\n", WEXITSTATUS(status)); else if (WIFSIGNALED (status)) printf ("ts %s\n", sigtable[WTERMSIG(status)]); else if (WIFSTOPPED (status)) printf ("ss %s\n", sigtable[WSTOPSIG(status)]); return; } int main (int argc, char *argv[]) { struct reg regs; int status; pid_t pid; if (argc != 2) exit(1); pid = atoi (argv[1]); if (ptrace (PT_ATTACH, pid, 0, SIGCONT)) err (1, "ptrace attach"); while (wait4(-1, &status, WUNTRACED, NULL) != pid); show (status); if (ptrace (PT_GETREGS, pid, ®s, NULL)) err (1, "ptace getregs"); printf ("attach ok, pc: %#lx\n", regs.r_eip); /* uncomment this , it will wokr ptrace (PT_CONTINUE, pid, 1, 17); while (wait4(-1, &status, WUNTRACED, NULL) != pid); show (status); */ if (ptrace (PT_DETACH, pid, 1, 0)) err (1, "ptrace detach"); else printf ("detach ok\n"); exit (1); } --VS++wcV0S1rZb1Fb-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message