m32r: use generic ptrace_resume code

Use the generic ptrace_resume code for PTRACE_SYSCALL, PTRACE_CONT,
PTRACE_KILL and PTRACE_SINGLESTEP.  This implies defining
arch_has_single_step in <asm/ptrace.h> and implementing the
user_enable_single_step and user_disable_single_step functions, which also
causes the breakpoint information to be cleared on fork, which could be
considered a bug fix.

Also the TIF_SYSCALL_TRACE thread flag is now cleared on PTRACE_KILL which
it previously wasn't, which is consistent with all architectures using the
modern ptrace code.

The old code only disables the breakpoints on PTRACE_KILL, while after
this patch this also happens for PTRACE_CONT and PTRACE_SYSCALL which
matches the behaviour of the other architetures.  I think this is a
bugfixes, but please double verify this is correct.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Roland McGrath <roland@redhat.com>
Cc: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Christoph Hellwig 2010-03-10 15:23:01 -08:00 committed by Linus Torvalds
parent 290ba3aef5
commit e34112e396
2 changed files with 31 additions and 68 deletions

View file

@ -120,6 +120,8 @@ struct pt_regs {
#include <asm/m32r.h> /* M32R_PSW_BSM, M32R_PSW_BPM */
#define arch_has_single_step() (1)
struct task_struct;
extern void init_debug_traps(struct task_struct *);
#define arch_ptrace_attach(child) \

View file

@ -580,6 +580,35 @@ init_debug_traps(struct task_struct *child)
}
}
void user_enable_single_step(struct task_struct *child)
{
unsigned long next_pc;
unsigned long pc, insn;
clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
/* Compute next pc. */
pc = get_stack_long(child, PT_BPC);
if (access_process_vm(child, pc&~3, &insn, sizeof(insn), 0)
!= sizeof(insn))
break;
compute_next_pc(insn, pc, &next_pc, child);
if (next_pc & 0x80000000)
break;
if (embed_debug_trap(child, next_pc))
break;
invalidate_cache();
}
void user_disable_single_step(struct task_struct *child)
{
unregister_all_debug_traps(child);
invalidate_cache();
}
/*
* Called by kernel/ptrace.c when detaching..
@ -630,74 +659,6 @@ arch_ptrace(struct task_struct *child, long request, long addr, long data)
ret = ptrace_write_user(child, addr, data);
break;
/*
* continue/restart and stop at next (return from) syscall
*/
case PTRACE_SYSCALL:
case PTRACE_CONT:
ret = -EIO;
if (!valid_signal(data))
break;
if (request == PTRACE_SYSCALL)
set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
else
clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
child->exit_code = data;
wake_up_process(child);
ret = 0;
break;
/*
* make the child exit. Best I can do is send it a sigkill.
* perhaps it should be put in the status that it wants to
* exit.
*/
case PTRACE_KILL: {
ret = 0;
unregister_all_debug_traps(child);
invalidate_cache();
if (child->exit_state == EXIT_ZOMBIE) /* already dead */
break;
child->exit_code = SIGKILL;
wake_up_process(child);
break;
}
/*
* execute single instruction.
*/
case PTRACE_SINGLESTEP: {
unsigned long next_pc;
unsigned long pc, insn;
ret = -EIO;
if (!valid_signal(data))
break;
clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
/* Compute next pc. */
pc = get_stack_long(child, PT_BPC);
if (access_process_vm(child, pc&~3, &insn, sizeof(insn), 0)
!= sizeof(insn))
break;
compute_next_pc(insn, pc, &next_pc, child);
if (next_pc & 0x80000000)
break;
if (embed_debug_trap(child, next_pc))
break;
invalidate_cache();
child->exit_code = data;
/* give it a chance to run. */
wake_up_process(child);
ret = 0;
break;
}
case PTRACE_GETREGS:
ret = ptrace_getregs(child, (void __user *)data);
break;