1 /* Copyright (c) 2011 The Regents of the University of California
2 * Barret Rhoden <brho@cs.berkeley.edu>
3 * See LICENSE for details.
5 * x86-specific Kernel debugging headers and static inlines */
7 #ifndef ROS_KERN_ARCH_KDEBUG_H
8 #define ROS_KERN_ARCH_KDEBUG_H
10 #include <ros/common.h>
15 // Debug information about a particular instruction pointer
16 typedef struct eipdebuginfo {
17 const char *eip_file; // Source code filename for EIP
18 int eip_line; // Source code linenumber for EIP
20 const char *eip_fn_name; // Name of function containing EIP
21 // - Note: not null terminated!
22 int eip_fn_namelen; // Length of function name
23 uintptr_t eip_fn_addr; // Address of start of function
24 int eip_fn_narg; // Number of function arguments
27 int debuginfo_eip(uintptr_t eip, eipdebuginfo_t *NONNULL info);
28 void *debug_get_fn_addr(char *fn_name);
30 /* Returns a PC/EIP in the function that called us, preferably near the call
31 * site. Returns 0 when we can't jump back any farther. */
32 static inline uintptr_t get_caller_pc(void)
34 unsigned long *ebp = (unsigned long*)read_bp();
37 /* this is part of the way back into the call() instruction's bytes
38 * eagle-eyed readers should be able to explain why this is good enough, and
39 * retaddr (just *(ebp + 1) is not) */
40 return *(ebp + 1) - 1;
43 #endif /* ROS_KERN_ARCH_KDEBUG_H */