Commit 52b8e7f
authored
[android] print backtraces on ds2 crashes/errors
## Purpose
Add support to print ds2 backtraces on Android from the signal handler
to diagnose crashes and fatal errors in DS2 itself.
## Overview
* Reuse the existing backtrace plumbing and implement only the glibc
`backtrace` functionality missing on Android
* Log the module-relative address of each stack frame in addition to the
existing information.
## Problem Details
No backtraces are currently logged when DS2 crashes or encounters a
fatal error on Android because `ds2::utils::PrintBacktrace` function is
stubbed-out on platforms without glibc. Instead of glibc, Android
provides `libunwind` in the NDK exposed in the `unwind.h` header.
## Validation
Manually verified mostly complete backtraces are emitted from signal
handler context during a ds2 crash on a Debug. Verified with ds2 built
for 4 Android ABIs. x86, x86_64, armeabi-v7a, and arm64-v8a.
Example fatal error log (from x86_64):
```
[10853][void ds2::Utils::PrintBacktrace()] ERROR : 0x00005f03b2caed35 <unknown>+0x5f03b2caed35 (/data/local/tmp/ds2+0xa7d35)
[10853][void ds2::Utils::PrintBacktrace()] ERROR : 0x00005f03b2cafb88 <unknown>+0x5f03b2cafb88 (/data/local/tmp/ds2+0xa8b88)
[10853][void ds2::Utils::PrintBacktrace()] ERROR : 0x00005f03b2cc144f <unknown>+0x5f03b2cc144f (/data/local/tmp/ds2+0xba44f)
[10853][void ds2::Utils::PrintBacktrace()] ERROR : 0x00005f03b2c785ed <unknown>+0x5f03b2c785ed (/data/local/tmp/ds2+0x715ed)
[10853][void ds2::Utils::PrintBacktrace()] ERROR : 0x00005f03b2c9c59f <unknown>+0x5f03b2c9c59f (/data/local/tmp/ds2+0x9559f)
[10853][void ds2::Utils::PrintBacktrace()] ERROR : 0x00005f03b2c84bfe <unknown>+0x5f03b2c84bfe (/data/local/tmp/ds2+0x7dbfe)
[10853][void ds2::Utils::PrintBacktrace()] ERROR : 0x00005f03b2c847d2 <unknown>+0x5f03b2c847d2 (/data/local/tmp/ds2+0x7d7d2)
[10853][void ds2::Utils::PrintBacktrace()] ERROR : 0x00005f03b2ca2dc8 <unknown>+0x5f03b2ca2dc8 (/data/local/tmp/ds2+0x9bdc8)
[10853][void ds2::Utils::PrintBacktrace()] ERROR : 0x00005f03b2c646dd <unknown>+0x5f03b2c646dd (/data/local/tmp/ds2+0x5d6dd)
[10853][void ds2::Utils::PrintBacktrace()] ERROR : 0x00005f03b2c60977 <unknown>+0x5f03b2c60977 (/data/local/tmp/ds2+0x59977)
[10853][void ds2::Utils::PrintBacktrace()] ERROR : 0x00007be7296c09f0 __libc_init+0x60 (/apex/com.android.runtime/lib64/bionic/libc.so+0x529f0)
```
Addresses relative to the module can be decoded on the build machine
with `lldb-symbolizer`:
```
$ llvm-symbolizer --obj=./build/ds2 <stack.txt
ds2::Utils::PrintBacktrace()
??:0:0
ds2::Log(int, char const*, char const*, char const*, ...)
??:0:0
ds2::Target::Linux::Process::wait()
??:0:0
ds2::GDBRemote::DebugSessionImplBase::onResume(ds2::GDBRemote::Session&, std::__ndk1::vector<ds2::GDBRemote::ThreadResumeAction, std::__ndk1::allocator<ds2::GDBRemote::ThreadResumeAction>> const&, ds2::GDBRemote::StopInfo&)
??:0:0
ds2::GDBRemote::Session::Handle_vCont(ds2::GDBRemote::ProtocolInterpreter::Handler const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&)
??:0:0
ds2::GDBRemote::ProtocolInterpreter::onCommand(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&)
??:0:0
ds2::GDBRemote::ProtocolInterpreter::onPacketData(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, bool)
??:0:0
ds2::GDBRemote::SessionBase::receive(bool)
??:0:0
RunDebugServer(ds2::Host::Channel*, ds2::GDBRemote::SessionDelegate*)
main.cpp:0:0
main
??:0:0
```
NOTE: file location debug information is also shown if ds2 is compiled
with `-g`.1 parent e492429 commit 52b8e7f
1 file changed
+48
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
28 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
29 | 70 | | |
30 | 71 | | |
31 | 72 | | |
32 | | - | |
33 | 73 | | |
34 | | - | |
35 | 74 | | |
36 | 75 | | |
37 | 76 | | |
38 | | - | |
| 77 | + | |
39 | 78 | | |
40 | 79 | | |
41 | 80 | | |
| |||
60 | 99 | | |
61 | 100 | | |
62 | 101 | | |
63 | | - | |
| 102 | + | |
| 103 | + | |
64 | 104 | | |
65 | 105 | | |
66 | | - | |
| 106 | + | |
| 107 | + | |
67 | 108 | | |
68 | 109 | | |
69 | 110 | | |
| |||
0 commit comments