Page MenuHomePhabricator

Optionally print symbolizer markup backtraces.
Needs ReviewPublic

Authored by mysterymath on Dec 9 2022, 4:47 PM.

Details

Summary

When the environment LLVM_ENABLE_SYMBOLIZER_MARKUP is set, if
llvm-symbolizer fails or is disabled, this change will print a backtrace
in llvm-symbolizer markup instead of falling back to in-process
symbolization mechanisms.

This allows llvm-symbolizer to be run on the output later to produce a
high quality backtrace, even for fully-stripped LLVM utilities.

Diff Detail

Unit TestsFailed

TimeTest
180 msx64 debian > Flang.Driver::target-cpu-features.f90
Script: -- : 'RUN: at line 6'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/flang-new --target=aarch64-linux-gnu -mcpu=cortex-a57 -c /var/lib/buildkite-agent/builds/llvm-project/flang/test/Driver/target-cpu-features.f90 -### 2>&1 | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/flang/test/Driver/target-cpu-features.f90 -check-prefix=CHECK-A57
60,050 msx64 debian > libFuzzer.libFuzzer::minimize_crash.test
Script: -- : 'RUN: at line 1'; /var/lib/buildkite-agent/builds/llvm-project/build/./bin/clang --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/var/lib/buildkite-agent/builds/llvm-project/compiler-rt/lib/fuzzer -m64 /var/lib/buildkite-agent/builds/llvm-project/compiler-rt/test/fuzzer/NullDerefTest.cpp -o /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/test/fuzzer/X86_64DefaultLinuxConfig/Output/minimize_crash.test.tmp-NullDerefTest
60,030 msx64 debian > libFuzzer.libFuzzer::value-profile-load.test
Script: -- : 'RUN: at line 2'; /var/lib/buildkite-agent/builds/llvm-project/build/./bin/clang --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/var/lib/buildkite-agent/builds/llvm-project/compiler-rt/lib/fuzzer -m64 /var/lib/buildkite-agent/builds/llvm-project/compiler-rt/test/fuzzer/LoadTest.cpp -fsanitize-coverage=trace-gep -o /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/test/fuzzer/X86_64DefaultLinuxConfig/Output/value-profile-load.test.tmp-LoadTest

Event Timeline

mysterymath created this revision.Dec 9 2022, 4:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 9 2022, 4:47 PM
mysterymath requested review of this revision.Dec 9 2022, 4:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 9 2022, 4:48 PM

Add negative test.

I thought we agreed that the desirable semantics to keep things simple is that if markup is requested then markup is always printed, period. It shouldn't have anything to do with whether llvm-symbolizer works.

I thought we agreed that the desirable semantics to keep things simple is that if markup is requested then markup is always printed, period. It shouldn't have anything to do with whether llvm-symbolizer works.

I agree, I think it's fine if we keep markup as a fallback in the case when llvm-symbolizer fails or is disabled, but there should also be a way to force the use markup without trying anything else.

I thought we agreed that the desirable semantics to keep things simple is that if markup is requested then markup is always printed, period. It shouldn't have anything to do with whether llvm-symbolizer works.

I agree, I think it's fine if we keep markup as a fallback in the case when llvm-symbolizer fails or is disabled, but there should also be a way to force the use markup without trying anything else.

The idea was to keep LLVM_DISABLE_SYMBOLIZATION and LLVM_ENABLE_SYMBOLIZER_MARKUP orthogonal; it seems prima facie that setting LLVM_ENABLE_SYMBOLIZER_MARKUP shouldn't also have the effect of setting LLVM_DISABLE_SYMBOLIZATION.

But the available options form a priority ordering; at most one method should be used, and some are superior to others. We could reasonable consider the markup workflow to have superior characteristics the others in the scenarios where it applies, so I think it's reasonable for enabling it to implicitly disable the others. Accordingly, I've moved the markup option to the top of the list.

Give markup priority over other symbolization options.

Add Windows version of printMarkupContext.

Apply git clang-format.

phosek added inline comments.Dec 18 2022, 9:30 AM
llvm/lib/Support/Unix/Signals.inc
538

Can you use reinterpret_cast instead of C-style cast?

561

Can you use C++-style instead of C-style cast here and below?

571

What does Amt refer to? Might be better to use something more self-descriptive.

mysterymath marked an inline comment as done.

Address review comments.

llvm/lib/Support/Unix/Signals.inc
538

This is just an array to pointer decay, so static_cast works. format just doesn't like being handed an array type.

561

Done, throughout.

571

Renamed these as the bytes remaining until the next item.

No idea where would the most appropriate place be for this, but should this be added to the docs somewhere?

Add blurb about LLVM_ENABLE_SYMBOLIZER_MARKUP to markup doc.

I'd like to ping this; having symbolizer markup would be boon for debugging crashes in CI environments where the toolchain is stripped. Fuchsia does this to minimize the install image for the toolchain, but it currently means that we must reproduce all crashes locally with a debug build to get a usable stack trace.