From: Dmitry V. Levin Date: Tue, 11 Apr 2017 04:04:37 +0000 (+0000) Subject: Delay get_regs invocation X-Git-Tag: v4.17~111 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cb46fea4d5dbf3b4cf92cb8f6ce1e691cf28b171;p=strace Delay get_regs invocation strace used to call get_regs on every stop of a tracee, including cases when the result is going to be discarded. Prepare to change this lavish practice by delaying get_regs invocation until its result is actually needed. * defs.h (get_regs): Remove. * strace.c (trace): Do not call get_regs. * syscall.c (get_regs): Add static qualifier. (trace_syscall_exiting, print_pc, get_scno): Call get_regs. --- diff --git a/defs.h b/defs.h index 39d5693d..54f64174 100644 --- a/defs.h +++ b/defs.h @@ -412,7 +412,6 @@ extern void count_syscall(struct tcb *, const struct timeval *); extern void call_summary(FILE *); extern void clear_regs(void); -extern void get_regs(pid_t pid); extern int get_scno(struct tcb *); extern kernel_ulong_t get_rt_sigframe_addr(struct tcb *); diff --git a/strace.c b/strace.c index 6adb2c9f..2933a780 100644 --- a/strace.c +++ b/strace.c @@ -2299,8 +2299,6 @@ trace(void) } clear_regs(); - if (WIFSTOPPED(status)) - get_regs(pid); event = (unsigned int) status >> 16; diff --git a/syscall.c b/syscall.c index 8cfc3852..89491abb 100644 --- a/syscall.c +++ b/syscall.c @@ -559,6 +559,7 @@ clear_regs(void) get_regs_error = -1; } +static void get_regs(pid_t pid); static int get_syscall_args(struct tcb *); static int get_syscall_result(struct tcb *); static int arch_get_scno(struct tcb *tcp); @@ -766,6 +767,7 @@ trace_syscall_exiting(struct tcb *tcp) } #endif + get_regs(tcp->pid); #if SUPPORTED_PERSONALITIES > 1 update_personality(tcp, tcp->currpers); #endif @@ -1065,6 +1067,7 @@ print_pc(struct tcb *tcp) #else # error Neither ARCH_PC_REG nor ARCH_PC_PEEK_ADDR is defined #endif + get_regs(tcp->pid); if (get_regs_error || ARCH_GET_PC) tprints(current_wordsize == 4 ? "[????????] " : "[????????????????] "); @@ -1150,7 +1153,7 @@ ptrace_setregs(pid_t pid) #endif /* ARCH_REGS_FOR_GETREGSET || ARCH_REGS_FOR_GETREGS */ -void +static void get_regs(pid_t pid) { #undef USE_GET_SYSCALL_RESULT_REGS @@ -1225,6 +1228,8 @@ free_sysent_buf(void *ptr) int get_scno(struct tcb *tcp) { + get_regs(tcp->pid); + if (get_regs_error) return -1;