int backtrace_snapshot(int pid, int *tids, int *index, int nr_tids) { int i, rc = 0; struct snapshot *snap; if ((snap = get_snapshot(pid, tids, index, nr_tids)) == NULL) return -1; for (i = 0; i < snap->num_threads; ++i) { int x; char comm[16]; char end_pad[25] = "------------------------"; x = get_thread_comm(snap->tids[i], comm, sizeof(comm)); if (x > 0 && x <= sizeof(end_pad)) { end_pad[sizeof(end_pad) - x] = '\0'; printf("-------------- thread %d (%d) (%s) %s\n", (index != NULL ? index[i] : i+1), snap->tids[i], comm, end_pad); } snap->cur_thr = i; if (backtrace_thread(&snapshot_addr_space_accessors, snap) < 0) rc = -1; } snapshot_destroy(snap); return rc; }
int backtrace_ptrace(int pid, int *tids, int *index, int nr_tids) { #if !defined (NO_LIBUNWIND_PTRACE) int i, count, rc = 0; int *threads = NULL; count = get_threads(pid, &threads); if (!count || threads == NULL) return -1; if (tids != NULL) { if (adjust_threads(threads, count, tids, index, nr_tids) < 0) return -1; free(threads); count = nr_tids; threads = tids; } if (attach_process(pid) < 0) return -1; for (i = 0; i < count; ++i) { void *upt_info; printf("-------------------- thread %d (%d) --------------------\n", (index != NULL ? index[i] : i+1), threads[i]); if (threads[i] != pid && attach_thread(threads[i]) < 0) { rc = -1; break; } upt_info = _UPT_create(threads[i]); if (backtrace_thread(&_UPT_accessors, upt_info) < 0) rc = -1; _UPT_destroy(upt_info); if (threads[i] != pid && detach_thread(threads[i])) rc = -1; if (rc < 0) break; } free(threads); if (detach_process(pid) < 0) return -1; return rc; #else return -1; #endif /* NO_LIBUNWIND_PTRACE */ }
int backtrace_snapshot(int pid, int *tids, int *index, int nr_tids) { int i, rc = 0; struct snapshot *snap; if ((snap = get_snapshot(pid, tids, index, nr_tids)) == NULL) return -1; for (i = 0; i < snap->num_threads; ++i) { printf("-------------------- thread %d (%d) --------------------\n", (index != NULL ? index[i] : i+1), snap->tids[i]); snap->cur_thr = i; if (backtrace_thread(&snapshot_addr_space_accessors, snap) < 0) rc = -1; } snapshot_destroy(snap); return rc; }
int backtrace_ptrace(int pid, int *tids, int *index, int nr_tids) { #if !defined (NO_LIBUNWIND_PTRACE) int i, count, rc = 0; int *threads = NULL; count = get_threads(pid, &threads); if (!count || threads == NULL) return -1; if (tids != NULL) { if (adjust_threads(threads, count, tids, index, nr_tids) < 0) return -1; free(threads); count = nr_tids; threads = tids; } if (attach_process(pid) < 0) return -1; for (i = 0; i < count; ++i) { void *upt_info; int x; char comm[16]; char end_pad[25] = "------------------------"; x = get_thread_comm(threads[i], comm, sizeof(comm)); if (x > 0 && x <= sizeof(end_pad)) { end_pad[sizeof(end_pad) - x] = '\0'; printf("-------------- thread %d (%d) (%s) %s\n", (index != NULL ? index[i] : i + 1), threads[i], comm, end_pad); } if (threads[i] != pid && attach_thread(threads[i]) < 0) { rc = -1; break; } upt_info = _UPT_create(threads[i]); if (backtrace_thread(&_UPT_accessors, upt_info) < 0) rc = -1; _UPT_destroy(upt_info); if (threads[i] != pid && detach_thread(threads[i])) rc = -1; if (rc < 0) break; } free(threads); if (detach_process(pid) < 0) return -1; return rc; #else return -1; #endif /* NO_LIBUNWIND_PTRACE */ }