| 102 | } |
| 103 | |
| 104 | char *stackutil_get_stack_str(int id, char **type, int *nframes, int64_t *hits) |
| 105 | { |
| 106 | char *str = NULL; |
| 107 | #ifdef __GLIBC__ |
| 108 | void *frames[MAX_STACK_FRAMES]; |
| 109 | *type = NULL; |
| 110 | if (stackutil_get_stack(id, type, nframes, frames, hits) == 0) { |
| 111 | char **strings = NULL; |
| 112 | strings = backtrace_symbols(frames, *nframes); |
| 113 | strbuf *b = strbuf_new(); |
| 114 | for (int j = 0, pr = 0; j < *nframes; j++) { |
| 115 | char *p = strchr(strings[j], '('), *q = strchr(strings[j], '+'); |
| 116 | if (p && q) { |
| 117 | (*p) = (*q) = '\0'; |
| 118 | p++; |
| 119 | q--; |
| 120 | if ((q - p) > 0) { |
| 121 | if (pr) |
| 122 | strbuf_append(b, " "); |
| 123 | strbuf_appendf(b, "%s", p); |
| 124 | pr = 1; |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | str = strbuf_disown(b); |
| 129 | free(strings); |
| 130 | } |
| 131 | #endif |
| 132 | return str; |
| 133 | } |
| 134 | |
| 135 | int stackutil_get_num_stacks(void) |
| 136 | { |
no test coverage detected