+/*
+ * Dumps the current stack
+ */
+static void dumpstack(int crop)
+{
+ int idx, count;
+ void *addresses[1000];
+ char **locations;
+
+ count = backtrace(addresses, sizeof addresses / sizeof *addresses);
+ locations = backtrace_symbols(addresses, count);
+ if (locations == NULL)
+ ERROR("can't get the backtrace (returned %d addresses)", count);
+ else {
+ for (idx = crop; idx < count; idx++)
+ ERROR("[BACKTRACE %d/%d] %s", idx - crop + 1, count - crop, locations[idx]);
+ free(locations);
+ }
+}
+