You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The easiest way to get symbolized reports from ASan is with on-device llvm-symbolizer binary.
Currently, NDK provides only a host binary.
Both asan_device_setup and wrap.sh-based workflows can automate symbolization setup (with wrap.sh we would add llvm-symbolizer to the apk and set ASAN_OPTIONS or ASAN_SYMBOLIZER_PATH).
It would provide slightly better user experience, because sanitizer reports would come out pre-symbolized. But ndk-stack is enough to get all the same info, just with extra steps.
@hhb is in the middle of refactoring our build and changing the process by which we build many of the device components now. Once that is converted over, we could build and package the extra device binaries for llvm-symbolizer. Then we would need the NDK to properly package these (similar to how the runtime libraries all come from the Linux build, but must be distributed for each host separately).
I just found about this issue. I have a binary that definitely contains symbols and debug information, as tracy on it is able to show perfect stacks without being pointed to any additional symbols file/directory.
Now I'm running it with ASan, and getting ASan stacks on stderr like:
WRITE of size 8 at 0x0065720656c0 thread T0
#0 0x5b09882ac4 (/data/local/tmp/iree-benchmark-module+0x1d7ac4)
#1 0x5b09880f90 (/data/local/tmp/iree-benchmark-module+0x1d5f90)
#2 0x5b09880724 (/data/local/tmp/iree-benchmark-module+0x1d5724)
I've tried feeding that to ndk-stack but it doesn't output anything. My guess is that it doesn't parse the format that ASan stacks are in, since ndk-stack docs suggest examples where the stack is as dumped on logcat, and that's a different format.
Reading closer the doc, I learned that I should try to put a logcat-like marker line like
So, it looks like ndk-stack is at most a satisfactory solution in contexts where stack traces are coming from a log in a particular format. It's not applicable to ASan use cases.
Finally, consider that even if all these issues with ndk-stack were addressed, it would still not be as convenient as outputting readily annotated stacks.
As stated at the beginning, Tracy is able to symbolize all these stacks, so if llvm-symbolizer is any trouble (which it seems to be, seeing how it seems to require being built from the same LLVM version as produced the program being symbolized), maybe just look at what Tracy is doing instead?
ndk-stack should (despite the TODO) cope; @eugenis added support (see the __sanitizer_line_re line):
# See unwindstack::FormatFrame in libunwindstack.
# We're deliberately very loose because NDK users are likely to be
# looking at crashes on ancient OS releases.
# TODO: support asan stacks too?
_line_re = re.compile(r'.* +(#[0-9]+) +pc ([0-9a-f]+) +(([^ ]+).*)')
_sanitizer_line_re = re.compile(r'.* +(#[0-9]+) +0x[0-9a-f]* +\(([^ ]+)\+0x([0-9a-f]+)\)')
_lib_re = re.compile(r'([^\!]+)\!(.+)')
_offset_re = re.compile(r'\(offset\s+(0x[0-9a-f]+)\)')
_build_id_re = re.compile(r'\(BuildId:\s+([0-9a-f]+)\)')
@enh-google I've tried ndk-stack from r22 beta 1 now. Issues:
It still requires the input to start with *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***, which ASan output does not, so I still have to add that manually in a text editor every time.
It still prepends the output with "Crash dump" which could get confusing in case of non-crash stack traces as from non-fatal sanitizer reports.
It still takes a mandatory --sym parameter asking where "the .so files" are stored, which is confusing in case of native executables which may not involve .so's, and this still bakes in an assumption that all the binary code lives in a single directory. In practice, different stack frames may be in different files in different directories; even in my simple use case, I have
which ndk-stack is unable to symbolize because it's not in the directory that I passed in --sym.
It drops input lines that aren't stack frames, so two-stack ASan reports look wrong - it outputs the two stacks back-to-back without any indication anymore of what each of these stacks is.
Here is what a simple script using adb pull to get each file referenced by each stack frame and using the host llvm-symbolize on it, and correctly echo'ing the other lines that aren't stack frames so that the ASan report remains understandable, shows:
Activity
DanAlbert commentedon Apr 14, 2020
Is this still needed, or was the work done by this rolled into ndk-stack? @enh-google
eugenis commentedon Apr 15, 2020
It would provide slightly better user experience, because sanitizer reports would come out pre-symbolized. But ndk-stack is enough to get all the same info, just with extra steps.
enh-google commentedon Apr 15, 2020
would Studio support that workflow? i thought dan said it's hard to get symbols onto the device because Studio (cmake?) doesn't believe in that?
stephenhines commentedon Apr 16, 2020
@hhb is in the middle of refactoring our build and changing the process by which we build many of the device components now. Once that is converted over, we could build and package the extra device binaries for
llvm-symbolizer. Then we would need the NDK to properly package these (similar to how the runtime libraries all come from the Linux build, but must be distributed for each host separately).DanAlbert commentedon Apr 16, 2020
AGP will strip symbols for the APK by default, but you can override it with
or something like that. It's not going to be the common case by any means.
I think I'll close this for now. If we get users asking for it we'll reopen, but I think in practice everyone will need ndk-stack anyway.
bjacob commentedon Oct 30, 2020
I just found about this issue. I have a binary that definitely contains symbols and debug information, as tracy on it is able to show perfect stacks without being pointed to any additional symbols file/directory.
Now I'm running it with ASan, and getting ASan stacks on stderr like:
I've tried feeding that to
ndk-stackbut it doesn't output anything. My guess is that it doesn't parse the format that ASan stacks are in, sincendk-stackdocs suggest examples where the stack is as dumped on logcat, and that's a different format.Reading closer the doc, I learned that I should try to put a logcat-like marker line like
Once I did this,
ndk-buildstarted printing this:But still nothing else.
So, it looks like
ndk-stackis at most a satisfactory solution in contexts where stack traces are coming from a log in a particular format. It's not applicable to ASan use cases.Finally, consider that even if all these issues with
ndk-stackwere addressed, it would still not be as convenient as outputting readily annotated stacks.As stated at the beginning, Tracy is able to symbolize all these stacks, so if
llvm-symbolizeris any trouble (which it seems to be, seeing how it seems to require being built from the same LLVM version as produced the program being symbolized), maybe just look at what Tracy is doing instead?stephenhines commentedon Oct 30, 2020
@bjacob
llvm-symbolizeris in the latest NDK r22 beta 1. Can you give that a try to see if it solves your problem?enh-google commentedon Oct 30, 2020
ndk-stack should (despite the TODO) cope; @eugenis added support (see the
__sanitizer_line_reline):ah, but that was https://android-review.googlesource.com/c/platform/ndk/+/1225302 which will have been too late for r21. r22beta1 should have this though.
bjacob commentedon Oct 30, 2020
@stephenhines :
I just downloaded NDK r22 beta 1 but still can't find any device build of llvm-symbolizer. Only the same host build as in r21:
@enh-google
Thanks for the tip, retrying ndk-stack with r22 beta 1 now ...
bjacob commentedon Oct 30, 2020
@enh-google I've tried ndk-stack from r22 beta 1 now. Issues:
It still requires the input to start with
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***, which ASan output does not, so I still have to add that manually in a text editor every time.It still prepends the output with "Crash dump" which could get confusing in case of non-crash stack traces as from non-fatal sanitizer reports.
It still takes a mandatory
--symparameter asking where "the .so files" are stored, which is confusing in case of native executables which may not involve .so's, and this still bakes in an assumption that all the binary code lives in a single directory. In practice, different stack frames may be in different files in different directories; even in my simple use case, I havewhich ndk-stack is unable to symbolize because it's not in the directory that I passed in
--sym.For reference:
Here is the raw output from ASan:
Here is what ndk-stack shows:
... well, initially it shows nothing, but if I add the
***marker at the start of the input, I get:Here is what a simple script using
adb pullto get each file referenced by each stack frame and using the host llvm-symbolize on it, and correctly echo'ing the other lines that aren't stack frames so that the ASan report remains understandable, shows:Add script to symbolize android stacks, particularly for use with Asan.
Add script to symbolize android stacks, particularly for use with Asa…