]> Zhao Yanbai Git Server - minix.git/commitdiff
Make stack traces on exceptions possible.
authorBen Gras <ben@minix3.org>
Thu, 29 Jun 2006 13:35:27 +0000 (13:35 +0000)
committerBen Gras <ben@minix3.org>
Thu, 29 Jun 2006 13:35:27 +0000 (13:35 +0000)
kernel/debug.h
kernel/exception.c
kernel/proto.h

index 534ae06a5f2ade62015fdda1fee5bbcc149a5720..7169559a4cbaee01af5f18e6cfb1d09fd35f0d25 100644 (file)
@@ -20,6 +20,7 @@
  * are disabled.
  */
 #define DEBUG_ENABLE_IPC_WARNINGS      0
+#define DEBUG_STACKTRACE               1
 
 /* It's interesting to measure the time spent withing locked regions, because
  * this is the time that the system is deaf to interrupts.
index d269f4af90c3d0c24426bf58bd792523f01f32d2..df6343acebb7e31c7a9b711a1d2adc0ee5a69e09 100755 (executable)
@@ -65,6 +65,10 @@ unsigned vec_nr;
                        saved_proc->p_reg.cs, saved_proc->p_reg.pc,
                        saved_proc->p_reg.ss, saved_proc->p_reg.sp);
                kprintf("edi = 0x%x\n", saved_proc->p_reg.di);
+
+#if DEBUG_STACKTRACE
+               stacktrace(saved_proc);
+#endif
        }
 #endif
 
@@ -85,3 +89,34 @@ unsigned vec_nr;
   panic("exception in a kernel task", NO_NUM);
 }
 
+#if DEBUG_STACKTRACE
+/*===========================================================================*
+ *                             stacktrace                                   *
+ *===========================================================================*/
+PUBLIC void stacktrace(proc)
+struct proc *proc;
+{
+       reg_t bp, v_bp, v_pc, v_hbp;
+
+       v_bp = proc->p_reg.fp;
+
+       kprintf("stacktrace: ");
+       while(v_bp) {
+               phys_bytes p;
+               if(!(p = umap_local(proc, D, v_bp, sizeof(v_bp)))) {
+                       kprintf("(bad bp %lx)", v_bp);
+                       break;
+               }
+               phys_copy(p+sizeof(v_pc), vir2phys(&v_pc), sizeof(v_pc));
+               phys_copy(p, vir2phys(&v_hbp), sizeof(v_hbp));
+               kprintf("0x%lx ", (unsigned long) v_pc);
+               if(v_hbp != 0 && v_hbp <= v_bp) {
+                       kprintf("(bad hbp %lx)", v_hbp);
+                       break;
+               }
+               v_bp = v_hbp;
+       }
+       kprintf("\n");
+}
+#endif
+
index bfaa88e3d8e0c5bba00492e8d6f90459c934e135..f9a68f22640285ca7357ad7164ec96ec5c660064 100755 (executable)
@@ -74,6 +74,9 @@ _PROTOTYPE( int newmap, (struct proc *rp, struct mem_map *map_ptr)    );
 
 /* exception.c */
 _PROTOTYPE( void exception, (unsigned vec_nr)                          );
+#if DEBUG_STACK_TRACE
+_PROTOTYPE( void stacktrace, (struct proc *)                           );
+#endif
 
 /* i8259.c */
 _PROTOTYPE( void intr_init, (int mine)                                 );