Skip to content

Commit 5a07dfe

Browse files
committed
libbpf-tools/profile: add dso info and symbol offset to backtrace
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) Print backtrace of ip if it failed to get syms. Before: # profile -d psiginfo vscanf __snprintf_chk [unknown] [unknown] [unknown] [unknown] [unknown] sd_event_exit sd_event_dispatch sd_event_run [unknown] __libc_start_main [unknown] - systemd-journal (204) 1 xas_load xas_find filemap_map_pages __handle_mm_fault handle_mm_fault do_page_fault do_translation_fault do_mem_abort do_el0_ia_bp_hardening el0_ia xas_load -- failed to get syms - PmLogCtl (138757) 1 After: # profile -d #0 0xffffffc01018b7e8 __arm64_sys_clock_nanosleep+0x0 #1 0xffffffc01009a93c el0_svc_handler+0x34 iovisor#2 0xffffffc010084a08 el0_svc+0x8 iovisor#3 0xffffffc01018b7e8 __arm64_sys_clock_nanosleep+0x0 -- iovisor#4 0x0000007fa0bffd14 clock_nanosleep+0x94 (/usr/lib/libc-2.31.so+0x9ed14) iovisor#5 0x0000007fa0c0530c nanosleep+0x1c (/usr/lib/libc-2.31.so+0xa430c) iovisor#6 0x0000007fa0c051e4 sleep+0x34 (/usr/lib/libc-2.31.so+0xa41e4) iovisor#7 0x000000558a5a9608 flb_loop+0x28 (/usr/bin/fluent-bit+0x52608) iovisor#8 0x000000558a59f1c4 flb_main+0xa84 (/usr/bin/fluent-bit+0x481c4) iovisor#9 0x0000007fa0b85124 __libc_start_main+0xe4 (/usr/lib/libc-2.31.so+0x24124) iovisor#10 0x000000558a59d828 _start+0x34 (/usr/bin/fluent-bit+0x46828) - fluent-bit (1238) 1 #0 0xffffffc01027daa4 generic_copy_file_checks+0x334 #1 0xffffffc0102ba634 __handle_mm_fault+0x8dc iovisor#2 0xffffffc0102baa20 handle_mm_fault+0x168 iovisor#3 0xffffffc010ad23c0 do_page_fault+0x148 iovisor#4 0xffffffc010ad27c0 do_translation_fault+0xb0 iovisor#5 0xffffffc0100816b0 do_mem_abort+0x50 iovisor#6 0xffffffc0100843b0 el0_da+0x1c iovisor#7 0xffffffc01027daa4 generic_copy_file_checks+0x334 -- failed to get syms iovisor#8 0x0000007f8dc12648 iovisor#9 0x0000007f8dc0aef8 iovisor#10 0x0000007f8dc1c990 iovisor#11 0x0000007f8dc08b0c iovisor#12 0x0000007f8dc08e48 iovisor#13 0x0000007f8dc081c8 - PmLogCtl (2412) 1 Signed-off-by: Eunseon Lee <[email protected]>
1 parent c88462c commit 5a07dfe

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

libbpf-tools/profile.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache,
289289
bool has_collision = false;
290290
unsigned int missing_stacks = 0;
291291
struct key_ext_t counts[MAX_ENTRIES];
292+
int nr_kern_elem = 0;
292293

293294
ip = calloc(env.perf_max_stack_depth, sizeof(*ip));
294295
if (!ip) {
@@ -360,18 +361,29 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache,
360361
printf(" %lld\n", v);
361362
} else {
362363
// print default multi-line stack output
364+
nr_kern_elem = 0;
365+
363366
if (!env.user_stacks_only) {
364367
if (stack_id_err(k->kern_stack_id))
365368
printf(" [Missed Kernel Stack]\n");
366369
else if (k->kern_stack_id >= 0 &&
367370
bpf_map_lookup_elem(sfd, &k->kern_stack_id, ip) == 0) {
368371
for (j = 0; j < env.perf_max_stack_depth && ip[j]; j++) {
369372
ksym = ksyms__map_addr(ksyms, ip[j]);
370-
printf(" %s\n", ksym ? ksym->name : "[unknown]");
373+
if (ksym)
374+
printf(" #%-2d 0x%lx %s+0x%lx\n", j, ip[j], ksym->name, ip[j] - ksym->addr);
375+
else
376+
printf(" #%-2d 0x%lx [unknown]\n", j, ip[j]);
371377
}
378+
nr_kern_elem = j;
379+
372380
if (k->kernel_ip) {
373381
ksym = ksyms__map_addr(ksyms, k->kernel_ip);
374-
printf(" %s\n", ksym ? ksym->name : "[unknown]");
382+
if (ksym)
383+
printf(" #%-2d 0x%llx %s+0x%llx\n", j, k->kernel_ip, ksym->name, k->kernel_ip - ksym->addr);
384+
else
385+
printf(" #%-2d 0x%llx [unknown]\n", j, k->kernel_ip);
386+
nr_kern_elem++;
375387
}
376388
}
377389
}
@@ -387,10 +399,20 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache,
387399
syms = syms_cache__get_syms(syms_cache, k->pid);
388400
if (!syms) {
389401
fprintf(stderr, "failed to get syms\n");
402+
for (j = 0; j < env.perf_max_stack_depth && ip[j]; j++)
403+
printf(" #%-2d 0x%016lx\n", j + nr_kern_elem, ip[j]);
390404
} else {
391405
for (j = 0; j < env.perf_max_stack_depth && ip[j]; j++) {
392-
sym = syms__map_addr(syms, ip[j]);
393-
printf(" %s\n", sym ? sym->name : "[unknown]");
406+
char *dso_name;
407+
uint64_t dso_offset;
408+
sym = syms__map_addr_dso(syms, ip[j], &dso_name, &dso_offset);
409+
410+
printf(" #%-2d 0x%016lx", j + nr_kern_elem, ip[j]);
411+
if (sym)
412+
printf(" %s+0x%lx", sym->name, sym->offset);
413+
if (dso_name)
414+
printf(" (%s+0x%lx)", dso_name, dso_offset);
415+
printf("\n");
394416
}
395417
}
396418
}

libbpf-tools/trace_helpers.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ static int dso__add_sym(struct dso *dso, const char *name, uint64_t start,
422422
sym->name = (void*)(unsigned long)off;
423423
sym->start = start;
424424
sym->size = size;
425+
sym->offset = 0;
425426

426427
return 0;
427428
}
@@ -634,8 +635,10 @@ static struct sym *dso__find_sym(struct dso *dso, uint64_t offset)
634635
end = mid - 1;
635636
}
636637

637-
if (start == end && dso->syms[start].start <= offset)
638+
if (start == end && dso->syms[start].start <= offset) {
639+
(dso->syms[start]).offset = offset - dso->syms[start].start;
638640
return &dso->syms[start];
641+
}
639642
return NULL;
640643
}
641644

@@ -720,6 +723,22 @@ const struct sym *syms__map_addr(const struct syms *syms, unsigned long addr)
720723
return dso__find_sym(dso, offset);
721724
}
722725

726+
const struct sym *syms__map_addr_dso(const struct syms *syms, unsigned long addr,
727+
char **dso_name, uint64_t *dso_offset)
728+
{
729+
struct dso *dso;
730+
uint64_t offset;
731+
732+
dso = syms__find_dso(syms, addr, &offset);
733+
if (!dso)
734+
return NULL;
735+
736+
*dso_name = dso->name;
737+
*dso_offset = offset;
738+
739+
return dso__find_sym(dso, offset);
740+
}
741+
723742
struct syms_cache {
724743
struct {
725744
struct syms *syms;

libbpf-tools/trace_helpers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct sym {
2424
const char *name;
2525
unsigned long start;
2626
unsigned long size;
27+
unsigned long offset;
2728
};
2829

2930
struct syms;
@@ -32,6 +33,8 @@ struct syms *syms__load_pid(int tgid);
3233
struct syms *syms__load_file(const char *fname);
3334
void syms__free(struct syms *syms);
3435
const struct sym *syms__map_addr(const struct syms *syms, unsigned long addr);
36+
const struct sym *syms__map_addr_dso(const struct syms *syms, unsigned long addr,
37+
char **dso_name, uint64_t *dso_offset);
3538

3639
struct syms_cache;
3740

0 commit comments

Comments
 (0)