This is still work in progress to test my ideas. Not ready for review yet.
In this patch, I tried to use CrashRecoveryContext to re-run lldMain with '--reproduce' when the first run crashes. Flag 'reproduce-on-crash' is added to optionally turn on this feature. Flag '--debug-crash' to allow lld crash on purpose to test crash reproducer.
The reason I choose this approach is that it has a few advantages:
- It is quite simple.
- It works with every lld driver which already support '--reproduce'.
However, during testing, I saw a few issues:
- If the crash happens before the driver initialize the TarWriter for reproducer, this implementation will not catch it.
- lldMain is not designed to run twice internally. It will write unexpected errors to stderr. (e.g. I saw 'lld/ELF/InputSection.cpp:1402: void lld::elf::MergeInputSection::splitIntoPieces(): Assertion `pieces.empty()' failed.' error in tests)
Therefore, I am wondering if I should consider another approach: reimplement the reproducer each driver (start with ELF driver) to make it independent from the lld driver. In this case the reproducer can be directly invoked from CrashRecoveryContext in the lld/tools/lld/lld.cpp instead of being invoked from the rerun lld driver.
Discussion thread: https://lists.llvm.org/pipermail/llvm-dev/2021-April/149853.html
clang-tidy: warning: invalid case style for variable 'arg_str' [readability-identifier-naming]
not useful