iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.36k stars 3.86k forks source link

libbpf-tools/offcputime, futexctn: Fix incorrect DSO information in s… #4902

Closed ekyooo closed 7 months ago

ekyooo commented 8 months ago

…tacktrace

offcputime may display inaccurate DSO information in the stacktrace. Here's an example of the issue:

It shows the same DSO offset for different addresses, which is incorrect.

  $ ./offcputime -v
    ..
    #14 0x00007f8b912a8c (/usr/lib/libcbe.so_0x22afa8c)
    #15 0x000044000a3ee0 (/usr/lib/libcbe.so_0x22afa8c)
    #16 0x000044001fc56c (/usr/lib/libcbe.so_0x22afa8c)

This is why symsmap_addr_dso simply returns NULL when symsfind_dso also returns NULL. In that case, the values of dso_name and dso_offset are not changed. If the dso_name and dso_offset variables have a garbage value before calling symsmap_addr_dso, those garbage values are maintained after calling symsmap_addr_dso.

This patch fixes the issue by reinitializing dso_name and dso_offset variables before calling syms__map_addr_dso.

FYI, there is another PR(https://github.com/iovisor/bcc/pull/4862) to fix the issue by changing syms__map_addr_dso API. This PR is to fix the issue in a simple way as the above PR is pending now.