-#ifndef ROS_KERN_KDEBUG_H
-#define ROS_KERN_KDEBUG_H
+#pragma once
#include <ros/common.h>
+#include <ros/trapframe.h>
#include <arch/kdebug.h>
+#include <profiler.h>
+/* for includes */ struct proc;
-// Debug information about a particular instruction pointer
-typedef struct eipdebuginfo {
- const char *eip_file; // Source code filename for EIP
- int eip_line; // Source code linenumber for EIP
+struct symtab_entry {
+ char *name;
+ uintptr_t addr;
+};
- const char *eip_fn_name; // Name of function containing EIP
- // - Note: not null terminated!
- int eip_fn_namelen; // Length of function name
- uintptr_t eip_fn_addr; // Address of start of function
- int eip_fn_narg; // Number of function arguments
-} eipdebuginfo_t;
+/* An alternative here is to have backtrace_list kmalloc an array. The downside
+ * is that we're calling into the allocator in potentially-delicate situations,
+ * such as the NMI handler. */
+#define MAX_BT_DEPTH 20
-int debuginfo_eip(uintptr_t eip, eipdebuginfo_t *NONNULL info);
-void *debug_get_fn_addr(char *fn_name);
+/*** Printk Backtraces, usually used for debugging or from the monitor */
+/* Backtraces the calling kernel context */
void backtrace(void);
+/* Backtraces a PC/FP, with no protections */
+void backtrace_frame(uintptr_t pc, uintptr_t fp);
+/* Backtraces a user PC/FP */
+void backtrace_user_frame(uintptr_t pc, uintptr_t fp);
+/* Backtraces a hardware TF. Can handle user or kernel TFs */
+void backtrace_hwtf(struct hw_trapframe *hw_tf);
+/* Backtraces a user context */
+void backtrace_user_ctx(struct proc *p, struct user_context *ctx);
+
+/*** Programmatic Backtraces */
+/* Backtraces a PC/FP, stores results in *pcs, with no protections */
+size_t backtrace_list(uintptr_t pc, uintptr_t fp, uintptr_t *pcs,
+ size_t nr_slots);
+/* Backtraces a user PC/FP, stores results in *pcs */
+size_t backtrace_user_list(uintptr_t pc, uintptr_t fp, uintptr_t *pcs,
+ size_t nr_slots);
+/* Prints out a backtrace list, using pfunc(opaque, "line") for the printk.
+ * This does a symbol lookup on the kernel binary, so it is less useful for a
+ * user backtrace. */
+void print_backtrace_list(uintptr_t *pcs, size_t nr_pcs,
+ void (*pfunc)(void *, const char *), void *opaque);
+/* Backtraces the calling kernel context, using pfunc for printing */
+void gen_backtrace(void (*pfunc)(void *, const char *), void *opaque);
/* Arch dependent, listed here for ease-of-use */
static inline uintptr_t get_caller_pc(void);
* instruction pointer. kfree() the result. */
char *get_fn_name(uintptr_t pc);
-#endif /* ROS_KERN_KDEBUG_H */
+/* Returns the address of sym, or 0 if it does not exist */
+uintptr_t get_symbol_addr(char *sym);
+
+/* For a poor-mans function tracer (can add these with spatch) */
+void __print_func_entry(const char *func, const char *file);
+void __print_func_exit(const char *func, const char *file);
+#define print_func_entry() __print_func_entry(__FUNCTION__, __FILE__)
+#define print_func_exit() __print_func_exit(__FUNCTION__, __FILE__)
+void hexdump(void *v, int length);
+void pahexdump(uintptr_t pa, int length);
+int printdump(char *buf, int numprint, int buflen, uint8_t *data);
+
+extern bool printx_on;
+void set_printx(int mode);
+#define printx(args...) \
+ do { \
+ if (printx_on) \
+ printk(args); \
+ } while (0)
+#define trace_printx(args...) \
+ do { \
+ if (printx_on) \
+ trace_printk(args); \
+ } while (0)
+
+void debug_addr_proc(struct proc *p, unsigned long addr);
+void debug_addr_pid(int pid, unsigned long addr);
+
+void px_lock(void);
+void px_unlock(void);