Commits

Wez Furlong  committed fc76f96

don't show frames below main and don't go below our own threads created
via pthread_create.

This is for aesthetic reasons; with debug libc installed, we now print
a lot of local variables that, while fascinating, don't help understand
the program being debugged.

  • Participants
  • Parent commits 874a42b
  • Branches onering

Comments (0)

Files changed (1)

   gimli_stack_trace_t trace = calloc(1, sizeof(*trace));
   struct gimli_unwind_cursor cur;
   gimli_stack_frame_t frame;
+  struct {
+    const char *name;
+    int before;
+    struct gimli_symbol *sym;
+  } stopsyms[] = {
+    { "main", 0 },
+#ifdef __linux__
+    { "start_thread", 1 },
+#endif
+  };
+  int i;
+  int stop;
 
   if (!trace) return NULL;
 
     free(trace);
     return NULL;
   }
+
+  for (i = 0; i < sizeof(stopsyms)/sizeof(stopsyms[0]); i++) {
+    stopsyms[i].sym = gimli_sym_lookup(thr->proc, NULL, stopsyms[i].name);
+#if 0
+    printf("Looking up %s %" PRIx64 "-%" PRIx64 "\n",
+        stopsyms[i].name, stopsyms[i].sym->addr,
+        stopsyms[i].sym->addr + stopsyms[i].sym->size);
+#endif
+  }
+
   do {
+    stop = 0;
+
+    for (i = 0; i < sizeof(stopsyms)/sizeof(stopsyms[0]); i++) {
+      if (!stopsyms[i].before) continue;
+      if ((gimli_addr_t)cur.st.pc >= stopsyms[i].sym->addr &&
+          (gimli_addr_t)cur.st.pc <= stopsyms[i].sym->addr + stopsyms[i].sym->size) {
+        stop = 1;
+        break;
+      }
+    }
+    if (stop) {
+      break;
+    }
+
     frame = calloc(1, sizeof(*frame));
 
     STAILQ_INIT(&frame->vars);
     frame->cur = cur;
     STAILQ_INSERT_TAIL(&trace->frames, frame, frames);
 
+    for (i = 0; i < sizeof(stopsyms)/sizeof(stopsyms[0]); i++) {
+      if (stopsyms[i].before) continue;
+      if ((gimli_addr_t)cur.st.pc >= stopsyms[i].sym->addr &&
+          (gimli_addr_t)cur.st.pc <= stopsyms[i].sym->addr + stopsyms[i].sym->size) {
+        stop = 1;
+        break;
+      }
+    }
+    if (stop) {
+      break;
+    }
+
   } while (trace->num_frames < max_frames &&
       cur.st.pc && gimli_unwind_next(&cur) && cur.st.pc);