Bug 264444 - dtrace ustack() cannot decode stack frames in shared libraries opened with dlopen after the program terminates
Summary: dtrace ustack() cannot decode stack frames in shared libraries opened with dl...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-06-04 03:24 UTC by Alan Somers
Modified: 2022-07-23 04:21 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Somers freebsd_committer freebsd_triage 2022-06-04 03:24:53 UTC
dtrace's ustack() function is supposed to unwind a user stack trace.  It usually can.  But it seems that it cannot decode stack frames from a shared library, if that shared library was loaded with dlopen and the program exits before dtrace does.

Steps to Reproduce (admittedly, with difficulty)
1) pkg install rust c-blosc isa-l llvm pkgconf git
2) pkg install fio-3.30    # May not build with other fio versions
3) git clone https://github.com/bfffs/bfffs.git
4) cd bfffs
5) git checkout 6e2c7b16b681d54d239b0f7518e612d5df36d096
6) cargo build -p bfffs-fio
7) truncate -s 1g /tmp/bfffs.img
8) cargo run --bin bfffs -- pool create testpool /tmp/bfffs.img
9) sudo dtrace -x ustackframes=100 -n 'profile-199 /pid == $target && arg1/ {@[ustack()] = count();}' -o fio.stacks -c "fio bfffs-fio/data/ci.fio"
10) Examine fio.stacks.  It will contain frames from fio and libc.so, but none from libbfffs.so.  Where there should be some, it will instead contain hex numbers, like this:

              libc.so.7`memcpy+0xb0
              0xfcdfdc73c
              fio`io_u_queued_complete+0x7a
              fio`wait_for_completions+0x7b
              fio`do_io+0x678
              fio`thread_main+0xbe0
              libthr.so.3`0x822130a7a