Skip to content

Commit e08227d

Browse files
chleroympe
authored andcommitted
powerpc/ptrace: create ptrace_get_debugreg()
Create ptrace_get_debugreg() to handle PTRACE_GET_DEBUGREG and reduce ifdef mess Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/c1482c41a39cc216f4073a51070d8680f52d5054.1582848567.git.christophe.leroy@c-s.fr
1 parent 323a780 commit e08227d

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

arch/powerpc/kernel/ptrace/ptrace-adv.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ void user_disable_single_step(struct task_struct *task)
5656
clear_tsk_thread_flag(task, TIF_SINGLESTEP);
5757
}
5858

59+
int ptrace_get_debugreg(struct task_struct *child, unsigned long addr,
60+
unsigned long __user *datalp)
61+
{
62+
/* We only support one DABR and no IABRS at the moment */
63+
if (addr > 0)
64+
return -EINVAL;
65+
return put_user(child->thread.debug.dac1, datalp);
66+
}
67+
5968
int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, unsigned long data)
6069
{
6170
#ifdef CONFIG_HAVE_HW_BREAKPOINT

arch/powerpc/kernel/ptrace/ptrace-decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ int tm_cgpr32_set(struct task_struct *target, const struct user_regset *regset,
176176
extern const struct user_regset_view user_ppc_native_view;
177177

178178
/* ptrace-(no)adv */
179+
int ptrace_get_debugreg(struct task_struct *child, unsigned long addr,
180+
unsigned long __user *datalp);
179181
int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, unsigned long data);
180182
long ppc_set_hwdebug(struct task_struct *child, struct ppc_hw_breakpoint *bp_info);
181183
long ppc_del_hwdebug(struct task_struct *child, long data);

arch/powerpc/kernel/ptrace/ptrace-noadv.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ void user_disable_single_step(struct task_struct *task)
3939
clear_tsk_thread_flag(task, TIF_SINGLESTEP);
4040
}
4141

42+
int ptrace_get_debugreg(struct task_struct *child, unsigned long addr,
43+
unsigned long __user *datalp)
44+
{
45+
unsigned long dabr_fake;
46+
47+
/* We only support one DABR and no IABRS at the moment */
48+
if (addr > 0)
49+
return -EINVAL;
50+
dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) |
51+
(child->thread.hw_brk.type & HW_BRK_TYPE_DABR));
52+
return put_user(dabr_fake, datalp);
53+
}
54+
4255
int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, unsigned long data)
4356
{
4457
#ifdef CONFIG_HAVE_HW_BREAKPOINT

arch/powerpc/kernel/ptrace/ptrace.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,23 +191,9 @@ long arch_ptrace(struct task_struct *child, long request,
191191
break;
192192
}
193193

194-
case PTRACE_GET_DEBUGREG: {
195-
#ifndef CONFIG_PPC_ADV_DEBUG_REGS
196-
unsigned long dabr_fake;
197-
#endif
198-
ret = -EINVAL;
199-
/* We only support one DABR and no IABRS at the moment */
200-
if (addr > 0)
201-
break;
202-
#ifdef CONFIG_PPC_ADV_DEBUG_REGS
203-
ret = put_user(child->thread.debug.dac1, datalp);
204-
#else
205-
dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) |
206-
(child->thread.hw_brk.type & HW_BRK_TYPE_DABR));
207-
ret = put_user(dabr_fake, datalp);
208-
#endif
194+
case PTRACE_GET_DEBUGREG:
195+
ret = ptrace_get_debugreg(child, addr, datalp);
209196
break;
210-
}
211197

212198
case PTRACE_SET_DEBUGREG:
213199
ret = ptrace_set_debugreg(child, addr, data);

0 commit comments

Comments
 (0)