zdb/ztest: improve and harmonise crash output
Motivation and Context
The ongoing quest for better insight when things go wrong. And tidying up.
Description
See the commit messages. tl;dr:
- make zdb produce a backtrace on SIGSEGV/SIGABRT, just like ztest
- use the nicer libunwind backtraces from #16140 in this case (adding FreeBSD support)
- make the backtrace and dbgmsg printers (more) signal-safe, by removing allocations and printfs
This started out as just bringing over the SIGSEGV/SIGABRT handling from ztest to zdb, which is very useful if zdb crashes out on some kind of weird thing on disk. But then I saw I could have better backtraces, so I did that. Then I realised the backtrace functions needed to be a bit more general (where to send output), and they need to be safe to call from a signal handler. And the rest is just tidying up. Lots more tidying possible, but that's enough here.
There is a user-facing change here: dbgmsg output from ztest and zdb will now go to stderr, not stdout. It's kind of an incidental change, but I consider it an improvement.
How Has This Been Tested?
By hand, on Linux glibc with/without libunwind, FreeBSD 14 with libunwind, and FreeBSD 13 without libunwind. All looks good.
I'll be curious to see what the test suite makes of it, given zdb is important to some parts of it. I'm not expecting anything though.
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Performance enhancement (non-breaking change which improves efficiency)
- [x] Code cleanup (non-breaking change which makes code smaller or more readable)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
- [ ] Documentation (a change to man pages or other documentation)
Checklist:
- [x] My code follows the OpenZFS code style requirements.
- [ ] I have updated the documentation accordingly.
- [x] I have read the contributing document.
- [ ] I have added tests to cover my changes.
- [ ] I have run the ZFS Test Suite with this change applied.
- [x] All commit messages are properly formatted and contain
Signed-off-by.