+ struct trace_record tbs[NB_TRACEBACK];
+
+ // Let's get our Stackwalker does his job ;)
+ int n = trace_walkback(tbs, fp, NB_TRACEBACK, &fp);
+
+ if (fp) {
+ DEBUG("...<truncated>");
+ }
+
+ for (int i = 0; i < n; i++) {
+ struct trace_record* tb = &tbs[i];
+ trace_print_code_entry(tb->sym_pc, tb->pc, tb->symbol);
+ }
+}
+
+void
+trace_printstack()
+{
+ trace_printstack_of(cpu_get_fp());
+}
+
+static void
+trace_printswctx(const isr_param* p, char* direction)
+{
+
+ struct ksym_entry* sym = trace_sym_lookup(p->execp->eip);
+
+ DEBUG(">> (sw:%s) iv:%d, errno:%p <<",
+ direction,
+ p->execp->vector,
+ p->execp->err_code);
+
+ ptr_t sym_pc = sym ? sym->pc : p->execp->eip;
+ trace_print_code_entry(sym_pc, p->execp->eip, ksym_getstr(sym));
+}
+
+void
+trace_printstack_isr(const isr_param* isrm)
+{
+ isr_param* p = isrm;
+ ptr_t fp = cpu_get_fp();
+ int prev_fromusr = 0;
+
+ DEBUG("stack trace (pid=%d)\n", __current->pid);
+
+ trace_printstack_of(fp);
+
+ while (p) {
+ if (!prev_fromusr) {
+ if (uspace_context(p)) {
+ trace_printswctx(p, "s/u");
+ } else {
+ trace_printswctx(p, "s/s");
+ }
+ } else {
+ trace_printswctx(p, "u/s");
+ }
+
+ fp = saved_fp(p);
+ trace_printstack_of(fp);
+
+ prev_fromusr = uspace_context(p);
+
+ p = p->execp->saved_prev_ctx;
+ }