backtrace.h 1.4 KB

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