1 /* Copyright (c) 2011 The Regents of the University of California
2 * Barret Rhoden <brho@cs.berkeley.edu>
3 * See LICENSE for details.
5 * Arch-independent kernel debugging */
13 struct symtab_entry gbl_symtab[1] __attribute__((weak)) = {{0, 0}};
15 /* Returns a null-terminated string with the function name for a given PC /
16 * instruction pointer. kfree() the result. */
17 char *get_fn_name(uintptr_t pc)
19 struct symtab_entry *i, *prev = 0, *found = 0;
22 /* Table is in ascending order. As soon as we get to an entry greater than
23 * us, we were in the previous one. This is only true if we were given a
24 * good PC. Random addresses will just find the previous symbol. */
25 for (i = &gbl_symtab[0]; i->name; i++) {
35 name_len = strlen(found->name) + 1;
36 buf = kmalloc(name_len, 0);
39 strncpy(buf, found->name, name_len);
44 uintptr_t get_symbol_addr(char *sym)
46 struct symtab_entry *i;
47 for (i = &gbl_symtab[0]; i->name; i++) {
48 if (strcmp(i->name, sym) == 0)
54 static const char *blacklist[] = {
61 "genrandom", /* not noisy, just never returns */
67 static bool is_blacklisted(const char *s)
69 for (int i = 0; i < ARRAY_SIZE(blacklist); i++) {
70 if (!strcmp(blacklist[i], s))
76 static int tab_depth = 0;
78 /* Call this via kfunc */
79 void reset_print_func_depth(void)
84 static spinlock_t lock = SPINLOCK_INITIALIZER_IRQSAVE;
86 static void __print_hdr(void)
88 struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
89 printd("Core %2d ", core_id()); /* may help with multicore output */
90 if (in_irq_ctx(pcpui)) {
93 assert(pcpui->cur_kthread);
94 if (pcpui->cur_kthread->is_ktask) {
95 printk("%10s:", pcpui->cur_kthread->name);
97 printk("PID %3d :", pcpui->cur_proc ? pcpui->cur_proc->pid : 0);
102 void __print_func_entry(const char *func, const char *file)
104 char tentabs[] = "\t\t\t\t\t\t\t\t\t\t"; // ten tabs and a \0
105 char *ourtabs = &tentabs[10 - MIN(tab_depth, 10)];
108 if (is_blacklisted(func))
110 spin_lock_irqsave(&lock);
112 printk("%s%s() in %s\n", ourtabs, func, file);
113 spin_unlock_irqsave(&lock);
117 void __print_func_exit(const char *func, const char *file)
119 char tentabs[] = "\t\t\t\t\t\t\t\t\t\t"; // ten tabs and a \0
123 if (is_blacklisted(func))
126 ourtabs = &tentabs[10 - MIN(tab_depth, 10)];
127 spin_lock_irqsave(&lock);
129 printk("%s---- %s()\n", ourtabs, func);
130 spin_unlock_irqsave(&lock);
133 bool printx_on = FALSE;
135 void set_printx(int mode)
145 printx_on = !printx_on;