[PATCH] [24/45] x86: Introduce frame_pointer() and stack_pointer()

From: Andi Kleen
Date: Fri Sep 21 2007 - 16:52:52 EST



From: jblunck@xxxxxxx
This patch defines frame_pointer() and stack_pointer() similar to the
already defined instruction_pointer(). Thus the oprofile code can be written
in a more readable fashion.

Signed-off-by: Jan Blunck <jblunck@xxxxxxx>
Signed-off-by: Andi Kleen <ak@xxxxxxx>

---
arch/i386/oprofile/backtrace.c | 12 ++----------
include/asm-i386/ptrace.h | 2 ++
include/asm-x86_64/ptrace.h | 2 ++
3 files changed, 6 insertions(+), 10 deletions(-)

Index: linux/arch/i386/oprofile/backtrace.c
===================================================================
--- linux.orig/arch/i386/oprofile/backtrace.c
+++ linux/arch/i386/oprofile/backtrace.c
@@ -76,16 +76,8 @@ dump_user_backtrace(struct frame_head *
void
x86_backtrace(struct pt_regs * const regs, unsigned int depth)
{
- struct frame_head *head;
- unsigned long stack;
-
-#ifdef CONFIG_X86_64
- head = (struct frame_head *)regs->rbp;
- stack = regs->rsp;
-#else
- head = (struct frame_head *)regs->ebp;
- stack = regs->esp;
-#endif
+ struct frame_head *head = (struct frame_head *)frame_pointer(regs);
+ unsigned long stack = stack_pointer(regs);

if (!user_mode_vm(regs)) {
if (depth)
Index: linux/include/asm-i386/ptrace.h
===================================================================
--- linux.orig/include/asm-i386/ptrace.h
+++ linux/include/asm-i386/ptrace.h
@@ -55,6 +55,8 @@ static inline int v8086_mode(struct pt_r
}

#define instruction_pointer(regs) ((regs)->eip)
+#define frame_pointer(regs) ((regs)->ebp)
+#define stack_pointer(regs) ((regs)->esp)
#define regs_return_value(regs) ((regs)->eax)

extern unsigned long profile_pc(struct pt_regs *regs);
Index: linux/include/asm-x86_64/ptrace.h
===================================================================
--- linux.orig/include/asm-x86_64/ptrace.h
+++ linux/include/asm-x86_64/ptrace.h
@@ -40,6 +40,8 @@ struct pt_regs {
#define user_mode(regs) (!!((regs)->cs & 3))
#define user_mode_vm(regs) user_mode(regs)
#define instruction_pointer(regs) ((regs)->rip)
+#define frame_pointer(regs) ((regs)->rbp)
+#define stack_pointer(regs) ((regs)->rsp)
#define regs_return_value(regs) ((regs)->rax)

extern unsigned long profile_pc(struct pt_regs *regs);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/