Skip to content

Commit

Permalink
libbpf-tools/capable: Add additional information to backtrace for -v …
Browse files Browse the repository at this point in the history
…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
        #1  0xffffffff8144a94f security_vm_enough_memory_mm+0x2f
        #2  0xffffffff812576e3 mmap_region+0x103
        #3  0xffffffff8125837e do_mmap+0x3de
        #4  0xffffffff8122c41c vm_mmap_pgoff+0xdc
        #5  0xffffffff81dc3be0 do_syscall_64+0x50
        #6  0xffffffff81e0011b entry_SYSCALL_64_after_hwframe+0x63
        #7  0x00007f3036e9e9ca mmap64+0xa (/lib/x86_64-linux-gnu/libc-2.19.so+0xf49ca)
        -                irqbalance (730)
  • Loading branch information
ekyooo authored and yonghong-song committed Jun 16, 2024
1 parent 69fd218 commit b3285dc
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions libbpf-tools/capable.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache)
const struct ksym *ksym;
const struct syms *syms;
const struct sym *sym;
struct sym_info sinfo;
int idx;
int err, i;
unsigned long *ip;
struct cap_event val;
Expand All @@ -206,6 +208,8 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache)
}

while (!bpf_map_get_next_key(ifd, &lookup_key, &next_key)) {
idx = 0;

err = bpf_map_lookup_elem(ifd, &next_key, &val);
if (err < 0) {
fprintf(stderr, "failed to lookup info: %d\n", err);
Expand All @@ -218,7 +222,14 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache)
fprintf(stderr, " [Missed Kernel Stack]\n");
for (i = 0; i < env.perf_max_stack_depth && ip[i]; i++) {
ksym = ksyms__map_addr(ksyms, ip[i]);
printf(" %s\n", ksym ? ksym->name : "Unknown");
if (!env.verbose) {
printf(" %s\n", ksym ? ksym->name : "Unknown");
} else {
if (ksym)
printf(" #%-2d 0x%lx %s+0x%lx\n", idx++, ip[i], ksym->name, ip[i] - ksym->addr);
else
printf(" #%-2d 0x%lx [unknown]\n", idx++, ip[i]);
}
}
}

Expand All @@ -237,11 +248,22 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache)
goto skip_ustack;
}
for (i = 0; i < env.perf_max_stack_depth && ip[i]; i++) {
sym = syms__map_addr(syms, ip[i]);
if (sym)
printf(" %s\n", sym->name);
else
printf(" [unknown]\n");
if (!env.verbose) {
sym = syms__map_addr(syms, ip[i]);
if (sym)
printf(" %s\n", sym->name);
else
printf(" [unknown]\n");
} else {
err = syms__map_addr_dso(syms, ip[i], &sinfo);
printf(" #%-2d 0x%016lx", idx++, ip[i]);
if (err == 0) {
if (sinfo.sym_name)
printf(" %s+0x%lx", sinfo.sym_name, sinfo.sym_offset);
printf(" (%s+0x%lx)", sinfo.dso_name, sinfo.dso_offset);
}
printf("\n");
}
}
}

Expand Down

0 comments on commit b3285dc

Please sign in to comment.