Skip to content

Commit 6a5c573

Browse files
ekyoooyonghong-song
authored andcommitted
libbpf-tools/offcputime: Add dso info and symbol offset 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) Print backtrace of ip if it failed to get syms. Before: # offcputime -v 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: # offcputime -v #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 -- iovisor#8 0x0000007f8dc12648 [unknown] iovisor#9 0x0000007f8dc0aef8 [unknown] iovisor#10 0x0000007f8dc1c990 [unknown] iovisor#11 0x0000007f8dc08b0c [unknown] iovisor#12 0x0000007f8dc08e48 [unknown] iovisor#13 0x0000007f8dc081c8 [unknown] - PmLogCtl (2412) 1 Fixed: iovisor#3884 Signed-off-by: Eunseon Lee <[email protected]>
1 parent 1ad8f4b commit 6a5c573

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

libbpf-tools/offcputime.c

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache,
197197
int err, i, ifd, sfd;
198198
unsigned long *ip;
199199
struct val_t val;
200+
char *dso_name;
201+
unsigned long dso_offset;
202+
int idx;
200203

201204
ip = calloc(env.perf_max_stack_depth, sizeof(*ip));
202205
if (!ip) {
@@ -207,6 +210,8 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache,
207210
ifd = bpf_map__fd(obj->maps.info);
208211
sfd = bpf_map__fd(obj->maps.stackmap);
209212
while (!bpf_map_get_next_key(ifd, &lookup_key, &next_key)) {
213+
idx = 0;
214+
210215
err = bpf_map_lookup_elem(ifd, &next_key, &val);
211216
if (err < 0) {
212217
fprintf(stderr, "failed to lookup info: %d\n", err);
@@ -219,9 +224,17 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache,
219224
fprintf(stderr, " [Missed Kernel Stack]\n");
220225
goto print_ustack;
221226
}
227+
222228
for (i = 0; i < env.perf_max_stack_depth && ip[i]; i++) {
223229
ksym = ksyms__map_addr(ksyms, ip[i]);
224-
printf(" %s\n", ksym ? ksym->name : "Unknown");
230+
if (!env.verbose) {
231+
printf(" %s\n", ksym ? ksym->name : "unknown");
232+
} else {
233+
if (ksym)
234+
printf(" #%-2d 0x%lx %s+0x%lx\n", idx++, ip[i], ksym->name, ip[i] - ksym->addr);
235+
else
236+
printf(" #%-2d 0x%lx [unknown]\n", idx++, ip[i]);
237+
}
225238
}
226239

227240
print_ustack:
@@ -235,15 +248,30 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache,
235248

236249
syms = syms_cache__get_syms(syms_cache, next_key.tgid);
237250
if (!syms) {
238-
fprintf(stderr, "failed to get syms\n");
251+
if (!env.verbose) {
252+
fprintf(stderr, "failed to get syms\n");
253+
} else {
254+
for (i = 0; i < env.perf_max_stack_depth && ip[i]; i++)
255+
printf(" #%-2d 0x%016lx [unknown]\n", idx++, ip[i]);
256+
}
239257
goto skip_ustack;
240258
}
241259
for (i = 0; i < env.perf_max_stack_depth && ip[i]; i++) {
242-
sym = syms__map_addr(syms, ip[i]);
243-
if (sym)
244-
printf(" %s\n", sym->name);
245-
else
246-
printf(" [unknown]\n");
260+
if (!env.verbose) {
261+
sym = syms__map_addr(syms, ip[i]);
262+
if (sym)
263+
printf(" %s\n", sym->name);
264+
else
265+
printf(" [unknown]\n");
266+
} else {
267+
sym = syms__map_addr_dso(syms, ip[i], &dso_name, &dso_offset);
268+
printf(" #%-2d 0x%016lx", idx++, ip[i]);
269+
if (sym)
270+
printf(" %s+0x%lx", sym->name, sym->offset);
271+
if (dso_name)
272+
printf(" (%s+0x%lx)", dso_name, dso_offset);
273+
printf("\n");
274+
}
247275
}
248276

249277
skip_ustack:

libbpf-tools/trace_helpers.c

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

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

638-
if (start == end && dso->syms[start].start <= offset)
639+
if (start == end && dso->syms[start].start <= offset) {
640+
(dso->syms[start]).offset = offset - dso->syms[start].start;
639641
return &dso->syms[start];
642+
}
640643
return NULL;
641644
}
642645

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

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

3639
struct syms_cache;
3740

0 commit comments

Comments
 (0)