Replace GET_FRAME_START with get_caller_fp()
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 9 Oct 2018 20:07:28 +0000 (16:07 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 9 Oct 2018 21:45:56 +0000 (17:45 -0400)
We already had get_caller_pc() and just needed to get the caller's frame
pointer for backtraces.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/arch/riscv/kdebug.h
kern/arch/x86/kdebug.c
kern/arch/x86/kdebug.h

index dca1932..04c69ec 100644 (file)
@@ -18,3 +18,9 @@ static inline uintptr_t get_caller_pc(void)
 #warning Returning PC instead of caller pc
        return read_pc();
 }
+
+static inline uintptr_t get_caller_fp(void)
+{
+#warning Returning FP instead of caller fp
+       return read_ebp();
+}
index 3b740f8..c55a52c 100644 (file)
@@ -9,19 +9,6 @@
 
 #include <ros/memlayout.h>
 
-/* The return address is right above ebp on the stack.  We subtract an
- * additional 1 to make sure the eip we get is actually in the function
- * that called us.  I had a couple cases early on where call was the last
- * instruction in a function, and simply reading the retaddr would point
- * into another function (the next one in the object).
- */
-#define GET_FRAME_START(ebp, eip)                                                      \
-       do {                                                                                                    \
-               ebp = read_bp();                                                                        \
-               eip = *(uintptr_t *) (ebp + sizeof(uintptr_t)) - 1; \
-               ebp = *(uintptr_t *) ebp;                                                       \
-       } while (0)
-
 // Beginning of stabs table
 extern const stab_t __STAB_BEGIN__[];
 
@@ -318,12 +305,11 @@ void *debug_get_fn_addr(char *fn_name)
 
 void gen_backtrace(void (*pfunc)(void *, const char *), void *opaque)
 {
-       uintptr_t ebp, eip;
        uintptr_t pcs[MAX_BT_DEPTH];
        size_t nr_pcs;
 
-       GET_FRAME_START(ebp, eip);
-       nr_pcs = backtrace_list(eip, ebp, pcs, MAX_BT_DEPTH);
+       nr_pcs = backtrace_list(get_caller_pc(), get_caller_fp(), pcs,
+                               MAX_BT_DEPTH);
        print_backtrace_list(pcs, nr_pcs, pfunc, opaque);
 }
 
index d9983df..187740f 100644 (file)
@@ -38,3 +38,12 @@ static inline uintptr_t get_caller_pc(void)
         * retaddr (just *(ebp + 1) is not) */
        return *(ebp + 1) - 1;
 }
+
+static inline uintptr_t get_caller_fp(void)
+{
+       unsigned long *ebp = (unsigned long*)read_bp();
+
+       if (!ebp)
+               return 0;
+       return *ebp;
+}