Alias "e" to monitor's "exit"
[akaros.git] / kern / src / kdebug.c
index c9a4f2c..982fca5 100644 (file)
@@ -59,8 +59,29 @@ static const char *blacklist[] = {
        "calcd",
        "freeroute",
        "genrandom",    /* not noisy, just never returns */
+       "limborexmit",
        "rangecompare",
        "walkadd",
+       "bnx2x_alloc_rx_data",
+       "bnx2x_frag_alloc",
+       "__dma_map_single",
+       "__dma_mapping_error",
+       "__dma_zalloc_coherent",
+       "__dma_alloc_coherent",
+       "bnx2x_ilt_line_mem_op",
+       "bnx2x_ilt_line_init_op",
+       "bnx2x_ilt_line_wr",
+       "bnx2x_wr_64",
+       "pci_write_config_dword",
+       "bnx2x_init_str_wr",
+       "bnx2x_init_fill",
+       "bnx2x_init_block",
+       "bnx2x_write_big_buf",
+       "bnx2x_init_wr_wb",
+       "bnx2x_write_big_buf_wb",
+       "bnx2x_cl45_read",
+       "bnx2x_cl45_write",
+       "bnx2x_set_mdio_clk",
 };
 
 static bool is_blacklisted(const char *s)
@@ -73,48 +94,139 @@ static bool is_blacklisted(const char *s)
 }
 
 static int tab_depth = 0;
-static bool print = TRUE;
 
-/* Call these via kfunc */
+/* Call this via kfunc */
 void reset_print_func_depth(void)
 {
        tab_depth = 0;
 }
 
-void toggle_print_func(void)
+static spinlock_t lock = SPINLOCK_INITIALIZER_IRQSAVE;
+
+static void __print_hdr(void)
 {
-       print = !print;
-       printk("Func entry/exit printing is now %sabled\n", print ? "en" : "dis");
+       struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
+       printd("Core %2d ", core_id()); /* may help with multicore output */
+       if (in_irq_ctx(pcpui)) {
+               printk("IRQ       :");
+       } else {
+               assert(pcpui->cur_kthread);
+               if (pcpui->cur_kthread->is_ktask) {
+                       printk("%10s:", pcpui->cur_kthread->name);
+               } else {
+                       printk("PID %3d   :", pcpui->cur_proc ? pcpui->cur_proc->pid : 0);
+               }
+       }
 }
 
-static spinlock_t lock = SPINLOCK_INITIALIZER_IRQSAVE;
-
 void __print_func_entry(const char *func, const char *file)
 {
-       if (!print)
+       char tentabs[] = "\t\t\t\t\t\t\t\t\t\t"; // ten tabs and a \0
+       char *ourtabs = &tentabs[10 - MIN(tab_depth, 10)];
+       if (!printx_on)
                return;
        if (is_blacklisted(func))
                return;
        spin_lock_irqsave(&lock);
-       printd("Core %2d", core_id());  /* helps with multicore output */
-       for (int i = 0; i < tab_depth; i++)
-               printk("\t");
-       printk("%s() in %s\n", func, file);
+       __print_hdr();
+       printk("%s%s() in %s\n", ourtabs, func, file);
        spin_unlock_irqsave(&lock);
        tab_depth++;
 }
 
 void __print_func_exit(const char *func, const char *file)
 {
-       if (!print)
+       char tentabs[] = "\t\t\t\t\t\t\t\t\t\t"; // ten tabs and a \0
+       char *ourtabs;
+       if (!printx_on)
                return;
        if (is_blacklisted(func))
                return;
        tab_depth--;
+       ourtabs = &tentabs[10 - MIN(tab_depth, 10)];
        spin_lock_irqsave(&lock);
-       printd("Core %2d", core_id());
-       for (int i = 0; i < tab_depth; i++)
-               printk("\t");
-       printk("---- %s()\n", func);
+       __print_hdr();
+       printk("%s---- %s()\n", ourtabs, func);
        spin_unlock_irqsave(&lock);
 }
+
+bool printx_on = FALSE;
+
+void set_printx(int mode)
+{
+       switch (mode) {
+               case 0:
+                       printx_on = FALSE;
+                       break;
+               case 1:
+                       printx_on = TRUE;
+                       break;
+               case 2:
+                       printx_on = !printx_on;
+                       break;
+       }
+}
+
+void debug_addr_proc(struct proc *p, unsigned long addr)
+{
+       struct vm_region *vmr;
+       spin_lock(&p->vmr_lock);
+       TAILQ_FOREACH(vmr, &p->vm_regions, vm_link) {
+               if ((vmr->vm_base <= addr) && (addr < vmr->vm_end))
+                       break;
+       }
+       if (!vmr) {
+               spin_unlock(&p->vmr_lock);
+               printk("Addr %p has no VMR\n", addr);
+               return;
+       }
+       if (!vmr->vm_file) {
+               spin_unlock(&p->vmr_lock);
+               printk("Addr %p's VMR has no file\n", addr);
+               return;
+       }
+       printk("Addr %p is in %s at offset %p\n", addr, file_name(vmr->vm_file),
+              addr - vmr->vm_base + vmr->vm_foff);
+       spin_unlock(&p->vmr_lock);
+}
+
+void debug_addr_pid(int pid, unsigned long addr)
+{
+       struct proc *p;
+       p = pid2proc(pid);
+       if (!p) {
+               printk("No such proc for pid %d\n", pid);
+               return;
+       }
+       debug_addr_proc(p, addr);
+       proc_decref(p);
+}
+
+void backtrace_kframe(struct hw_trapframe *hw_tf)
+{
+       struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
+       pcpui->__lock_checking_enabled--;
+       printk("\nBacktrace of kernel context on Core %d:\n", core_id());
+       backtrace_frame(get_hwtf_pc(hw_tf), get_hwtf_fp(hw_tf));
+       pcpui->__lock_checking_enabled++;
+}
+
+void backtrace_user_ctx(struct proc *p, struct user_context *ctx)
+{
+       #define MAX_BT_DEPTH 20
+       uintptr_t pcs[MAX_BT_DEPTH];
+       size_t nr_pcs;
+
+       if (!ctx) {
+               printk("Null user context!\n");
+               return;
+       }
+       nr_pcs = backtrace_list(get_user_ctx_pc(ctx), get_user_ctx_fp(ctx), pcs,
+                               MAX_BT_DEPTH);
+       printk("User context backtrace:\n");
+       printk("\tOffsets only matter for shared libraries\n");
+       for (int i = 0; i < nr_pcs; i++) {
+               printk("#%02d ", i + 1);
+               debug_addr_proc(p, pcs[i]);
+       }
+}