Skip to content

Commit 36e0b7b

Browse files
ekyooodkruces
authored andcommitted
libbpf-tools/capable: Add additional information to backtrace for -v option
Add additional information and change format of backtrace - add symbol base offset, dso name, dso base offset - symbol and dso info is included if it's available in target binary - changed format: INDEX ADDR [SYMBOL+OFFSET] (MODULE+OFFSET) before: # ./capable -UK TIME UID PID COMM CAP NAME AUDIT VER DICT 01:59:17 0 730 irqbalance 21 CAP_SYS_ADMIN 0 deny cap_vm_enough_memory security_vm_enough_memory_mm mmap_region do_mmap vm_mmap_pgoff do_syscall_64 entry_SYSCALL_64_after_hwframe mmap64 - irqbalance (730) After: # ./capable -UKv TIME UID PID COMM CAP NAME AUDIT VERDICT 01:56:37 0 730 irqbalance 21 CAP_SYS_ADMIN 0 deny #0 0xffffffff81447dc6 cap_vm_enough_memory+0x26 iovisor#1 0xffffffff8144a94f security_vm_enough_memory_mm+0x2f iovisor#2 0xffffffff812576e3 mmap_region+0x103 iovisor#3 0xffffffff8125837e do_mmap+0x3de iovisor#4 0xffffffff8122c41c vm_mmap_pgoff+0xdc iovisor#5 0xffffffff81dc3be0 do_syscall_64+0x50 iovisor#6 0xffffffff81e0011b entry_SYSCALL_64_after_hwframe+0x63 iovisor#7 0x00007f3036e9e9ca mmap64+0xa (/lib/x86_64-linux-gnu/libc-2.19.so+0xf49ca) - irqbalance (730)
1 parent 16ef987 commit 36e0b7b

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

libbpf-tools/capable.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache)
195195
const struct ksym *ksym;
196196
const struct syms *syms;
197197
const struct sym *sym;
198+
struct sym_info sinfo;
199+
int idx;
198200
int err, i;
199201
unsigned long *ip;
200202
struct cap_event val;
@@ -206,6 +208,8 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache)
206208
}
207209

208210
while (!bpf_map_get_next_key(ifd, &lookup_key, &next_key)) {
211+
idx = 0;
212+
209213
err = bpf_map_lookup_elem(ifd, &next_key, &val);
210214
if (err < 0) {
211215
fprintf(stderr, "failed to lookup info: %d\n", err);
@@ -218,7 +222,14 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache)
218222
fprintf(stderr, " [Missed Kernel Stack]\n");
219223
for (i = 0; i < env.perf_max_stack_depth && ip[i]; i++) {
220224
ksym = ksyms__map_addr(ksyms, ip[i]);
221-
printf(" %s\n", ksym ? ksym->name : "Unknown");
225+
if (!env.verbose) {
226+
printf(" %s\n", ksym ? ksym->name : "Unknown");
227+
} else {
228+
if (ksym)
229+
printf(" #%-2d 0x%lx %s+0x%lx\n", idx++, ip[i], ksym->name, ip[i] - ksym->addr);
230+
else
231+
printf(" #%-2d 0x%lx [unknown]\n", idx++, ip[i]);
232+
}
222233
}
223234
}
224235

@@ -237,11 +248,22 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache)
237248
goto skip_ustack;
238249
}
239250
for (i = 0; i < env.perf_max_stack_depth && ip[i]; i++) {
240-
sym = syms__map_addr(syms, ip[i]);
241-
if (sym)
242-
printf(" %s\n", sym->name);
243-
else
244-
printf(" [unknown]\n");
251+
if (!env.verbose) {
252+
sym = syms__map_addr(syms, ip[i]);
253+
if (sym)
254+
printf(" %s\n", sym->name);
255+
else
256+
printf(" [unknown]\n");
257+
} else {
258+
err = syms__map_addr_dso(syms, ip[i], &sinfo);
259+
printf(" #%-2d 0x%016lx", idx++, ip[i]);
260+
if (err == 0) {
261+
if (sinfo.sym_name)
262+
printf(" %s+0x%lx", sinfo.sym_name, sinfo.sym_offset);
263+
printf(" (%s+0x%lx)", sinfo.dso_name, sinfo.dso_offset);
264+
}
265+
printf("\n");
266+
}
245267
}
246268
}
247269

0 commit comments

Comments
 (0)