]> granicus.if.org Git - strace/commitdiff
Call get_scno during startup_tcb only for forcibly attached processes
authorEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 3 Jan 2018 16:36:25 +0000 (17:36 +0100)
committerEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 3 Jan 2018 22:56:48 +0000 (23:56 +0100)
Otherwise it makes little sense on most arches to try to get syscall
number.

* defs.h (TCB_GRABBED): New tcb flag.
* strace.c (attach_tcb): Set TCB_GRABBED for the tcb.
(startup_tcb): Call get_scno() only if process is grabbed and its
registers may contain syscall number information.

Reported-by: Dmitry V. Levin <ldv@altlinux.org>
Closes: https://github.com/strace/strace/issues/22
defs.h
strace.c

diff --git a/defs.h b/defs.h
index afb2cb0b3e10c1c2b3d0bf76b22b6b156d58c871..35761290fa6923a0963d1d783f16487727192cdb 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -244,6 +244,8 @@ struct tcb {
 #define TCB_TAMPERED   0x40    /* A syscall has been tampered with */
 #define TCB_HIDE_LOG   0x80    /* We should hide everything (until execve) */
 #define TCB_SKIP_DETACH_ON_FIRST_EXEC  0x100   /* -b execve should skip detach on first execve */
+#define TCB_GRABBED    0x200 /* We grab the process and can catch it
+                              * in the middle of a syscall */
 
 /* qualifier flags */
 #define QUAL_TRACE     0x001   /* this system call should be traced */
index 709062483e58a27dddb856acf0e9ecd480add237..7491a2e994d5c9ae29cad1d18faa60113b048b47 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -1002,7 +1002,8 @@ attach_tcb(struct tcb *const tcp)
                return;
        }
 
-       tcp->flags |= TCB_ATTACHED | TCB_STARTUP | post_attach_sigstop;
+       tcp->flags |= TCB_ATTACHED | TCB_GRABBED | TCB_STARTUP |
+                     post_attach_sigstop;
        newoutf(tcp);
        debug_msg("attach to pid %d (main) succeeded", tcp->pid);
 
@@ -1033,8 +1034,8 @@ attach_tcb(struct tcb *const tcp)
                        debug_msg("attach to pid %d succeeded", tid);
 
                        struct tcb *tid_tcp = alloctcb(tid);
-                       tid_tcp->flags |= TCB_ATTACHED | TCB_STARTUP |
-                                         post_attach_sigstop;
+                       tid_tcp->flags |= TCB_ATTACHED | TCB_GRABBED |
+                                         TCB_STARTUP | post_attach_sigstop;
                        newoutf(tid_tcp);
                }
 
@@ -2149,7 +2150,7 @@ startup_tcb(struct tcb *tcp)
                }
        }
 
-       if (get_scno(tcp) == 1)
+       if ((tcp->flags & TCB_GRABBED) && (get_scno(tcp) == 1))
                tcp->s_prev_ent = tcp->s_ent;
 }