diff mbox

[1/5] asm-generic/ptrace.h: start a common low level ptrace helper

Message ID 1302760895-13459-2-git-send-email-vapier@gentoo.org (mailing list archive)
State Not Applicable
Headers show

Commit Message

Mike Frysinger April 14, 2011, 6:01 a.m. UTC
This implements a bunch of helper funcs for poking the registers of a
ptrace structure.  Now common code should be able to portably update
specific registers (like kgdb updating the PC).

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 include/asm-generic/ptrace.h |   74 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 74 insertions(+), 0 deletions(-)
 create mode 100644 include/asm-generic/ptrace.h

Comments

Oleg Nesterov April 14, 2011, 6:09 p.m. UTC | #1
On 04/14, Mike Frysinger wrote:
>
> This implements a bunch of helper funcs for poking the registers of a
> ptrace structure.  Now common code should be able to portably update
> specific registers (like kgdb updating the PC).

The whole series looks correct, but I am a bit confused...

> +#ifndef GET_IP
> +#define GET_IP(regs) ((regs)->pc)
> +#endif

Could you explain this ifndef ?

IIUC, this should be included by arch/*/asm/ptrace.h. Isn't it better
to simply require that if you include asm-generic/ptrace.h you should
provide the necessary GET_* macros?

(regs)->pc looks a bit strange in asm-generic. But please feel free
to ignore.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mike Frysinger April 14, 2011, 6:16 p.m. UTC | #2
On Thu, Apr 14, 2011 at 14:09, Oleg Nesterov wrote:
> On 04/14, Mike Frysinger wrote:
>> +#ifndef GET_IP
>> +#define GET_IP(regs) ((regs)->pc)
>> +#endif
>
> Could you explain this ifndef ?
>
> IIUC, this should be included by arch/*/asm/ptrace.h. Isn't it better
> to simply require that if you include asm-generic/ptrace.h you should
> provide the necessary GET_* macros?
>
> (regs)->pc looks a bit strange in asm-generic. But please feel free
> to ignore.

my view of asm-generic is to put as much common/sane-defaults in there
as possible to minimize code duplication in arch code.  when it comes
to the register names, i looked at the arches to see what people used.
while x86 uses "ip", the majority of ports use "pc", thus the
majority of ports wont have to define their own GET_IP helper.
-mike
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/asm-generic/ptrace.h b/include/asm-generic/ptrace.h
new file mode 100644
index 0000000..82e674f
--- /dev/null
+++ b/include/asm-generic/ptrace.h
@@ -0,0 +1,74 @@ 
+/*
+ * Common low level (register) ptrace helpers
+ *
+ * Copyright 2004-2011 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#ifndef __ASM_GENERIC_PTRACE_H__
+#define __ASM_GENERIC_PTRACE_H__
+
+#ifndef __ASSEMBLY__
+
+/* Helpers for working with the instruction pointer */
+#ifndef GET_IP
+#define GET_IP(regs) ((regs)->pc)
+#endif
+#ifndef SET_IP
+#define SET_IP(regs, val) (GET_IP(regs) = (val))
+#endif
+
+static inline unsigned long instruction_pointer(struct pt_regs *regs)
+{
+	return GET_IP(regs);
+}
+static inline void instruction_pointer_set(struct pt_regs *regs,
+                                           unsigned long val)
+{
+	SET_IP(regs, val);
+}
+
+#ifndef profile_pc
+#define profile_pc(regs) instruction_pointer(regs)
+#endif
+
+/* Helpers for working with the user stack pointer */
+#ifndef GET_USP
+#define GET_USP(regs) ((regs)->usp)
+#endif
+#ifndef SET_USP
+#define SET_USP(regs, val) (GET_USP(regs) = (val))
+#endif
+
+static inline unsigned long user_stack_pointer(struct pt_regs *regs)
+{
+	return GET_USP(regs);
+}
+static inline void user_stack_pointer_set(struct pt_regs *regs,
+                                          unsigned long val)
+{
+	SET_USP(regs, val);
+}
+
+/* Helpers for working with the frame pointer */
+#ifndef GET_FP
+#define GET_FP(regs) ((regs)->fp)
+#endif
+#ifndef SET_FP
+#define SET_FP(regs, val) (GET_FP(regs) = (val))
+#endif
+
+static inline unsigned long frame_pointer(struct pt_regs *regs)
+{
+	return GET_FP(regs);
+}
+static inline void frame_pointer_set(struct pt_regs *regs,
+                                     unsigned long val)
+{
+	SET_FP(regs, val);
+}
+
+#endif /* __ASSEMBLY__ */
+
+#endif