From: Roland McGrath This patch makes x86-64's 32-bit support behave consistently with the native i386 behavior achieved in Davide Libenzi's patch: http://www.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.7/2.6.7-mm7/broken-out/really-ptrace-single-step-2.patch I hope these both can go into 2.6.8 or 2.6.9, since they make life better for gdb. Signed-off-by: Roland McGrath Signed-off-by: Andrew Morton --- 25-akpm/arch/x86_64/kernel/entry.S | 2 +- 25-akpm/arch/x86_64/kernel/ptrace.c | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff -puN arch/x86_64/kernel/entry.S~x86-64-support-for-singlestep-into-32-bit-system-calls arch/x86_64/kernel/entry.S --- 25/arch/x86_64/kernel/entry.S~x86-64-support-for-singlestep-into-32-bit-system-calls 2004-07-12 17:03:27.012691128 -0700 +++ 25-akpm/arch/x86_64/kernel/entry.S 2004-07-12 17:03:27.018690216 -0700 @@ -297,7 +297,7 @@ int_very_careful: sti SAVE_REST /* Check for syscall exit trace */ - testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),%edx + testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP),%edx jz int_signal pushq %rdi leaq 8(%rsp),%rdi # &ptregs -> arg1 diff -puN arch/x86_64/kernel/ptrace.c~x86-64-support-for-singlestep-into-32-bit-system-calls arch/x86_64/kernel/ptrace.c --- 25/arch/x86_64/kernel/ptrace.c~x86-64-support-for-singlestep-into-32-bit-system-calls 2004-07-12 17:03:27.013690976 -0700 +++ 25-akpm/arch/x86_64/kernel/ptrace.c 2004-07-12 17:03:27.018690216 -0700 @@ -88,6 +88,9 @@ void ptrace_disable(struct task_struct * { long tmp; +#ifdef CONFIG_IA32_EMULATION + clear_tsk_thread_flag(child, TIF_SINGLESTEP); +#endif tmp = get_stack_long(child, EFL_OFFSET) & ~TRAP_FLAG; put_stack_long(child, EFL_OFFSET, tmp); } @@ -344,6 +347,9 @@ asmlinkage long sys_ptrace(long request, set_tsk_thread_flag(child,TIF_SYSCALL_TRACE); else clear_tsk_thread_flag(child,TIF_SYSCALL_TRACE); +#ifdef CONFIG_IA32_EMULATION + clear_tsk_thread_flag(child, TIF_SINGLESTEP); +#endif child->exit_code = data; /* make sure the single step bit is not set. */ tmp = get_stack_long(child, EFL_OFFSET); @@ -395,6 +401,9 @@ asmlinkage long sys_ptrace(long request, ret = 0; if (child->state == TASK_ZOMBIE) /* already dead */ break; +#ifdef CONFIG_IA32_EMULATION + clear_tsk_thread_flag(child, TIF_SINGLESTEP); +#endif child->exit_code = SIGKILL; /* make sure the single step bit is not set. */ tmp = get_stack_long(child, EFL_OFFSET) & ~TRAP_FLAG; @@ -416,6 +425,10 @@ asmlinkage long sys_ptrace(long request, } tmp = get_stack_long(child, EFL_OFFSET) | TRAP_FLAG; put_stack_long(child, EFL_OFFSET, tmp); +#ifdef CONFIG_IA32_EMULATION + if (test_tsk_thread_flag(child, TIF_IA32)) + set_tsk_thread_flag(child, TIF_SINGLESTEP); +#endif child->exit_code = data; /* give it a chance to run. */ wake_up_process(child); @@ -528,7 +541,10 @@ asmlinkage void syscall_trace_leave(stru if (unlikely(current->audit_context)) audit_syscall_exit(current, regs->rax); - if (test_thread_flag(TIF_SYSCALL_TRACE) - && (current->ptrace & PT_PTRACED)) + if ((test_thread_flag(TIF_SYSCALL_TRACE) +#ifdef CONFIG_IA32_EMULATION + || test_thread_flag(TIF_SINGLESTEP) +#endif + ) && (current->ptrace & PT_PTRACED)) syscall_trace(regs); } _