Skip to content

Commit f2a4357

Browse files
authored
Fix unwinding on Android (#4894)
* Fix unwinding on Android Android isn't able to unwind the CHIP native stack, which interferes with debugging. Turn on unwind tables to fix this. Unclear if we want this in optimized builds, but Android OS seems to be able to unwind all of its frameworks and native libraries, so for now assume we do. There's only a space cost, and we can revisit that later. This is the difference between this: backtrace: 02-16 20:49:34.628 3872 3872 F DEBUG : backtrace: 02-16 20:49:34.628 3872 3872 F DEBUG : #00 pc 000000000008246c /apex/com.android.runtime/lib64/bionic/libc.so (abort+160) (BuildId: 5812256023147338b8a9538321d4c456) 02-16 20:49:34.628 3872 3872 F DEBUG : #1 pc 00000000000a836c /data/app/com.google.chip.chiptool-rPVLWEFRvE413khV9YptWg==/base.apk (offset 0x97a000) (chip::NetworkProvisioning::SendNetworkCredentials(char const*, char const*)+96) and this: 02-16 20:56:04.323 5040 5040 F DEBUG : backtrace: 02-16 20:56:04.323 5040 5040 F DEBUG : #00 pc 000000000008246c /apex/com.android.runtime/lib64/bionic/libc.so (abort+160) (BuildId: 5812256023147338b8a9538321d4c456) 02-16 20:56:04.323 5040 5040 F DEBUG : #1 pc 00000000000a839c /data/app/com.google.chip.chiptool-dz3iwqwmItgQDBBaEcevJw==/base.apk (offset 0x97a000) (chip::NetworkProvisioning::SendNetworkCredentials(char const*, char const*)+96) 02-16 20:56:04.323 5040 5040 F DEBUG : #2 pc 000000000009bb58 /data/app/com.google.chip.chiptool-dz3iwqwmItgQDBBaEcevJw==/base.apk (offset 0x97a000) (chip::RendezvousSession::SendNetworkCredentials(char const*, char const*)+44) 02-16 20:56:04.323 5040 5040 F DEBUG : #3 pc 000000000009bb94 /data/app/com.google.chip.chiptool-dz3iwqwmItgQDBBaEcevJw==/base.apk (offset 0x97a000) (non-virtual thunk to chip::RendezvousSession::SendNetworkCredentials(char const*, char const*)+44) 02-16 20:56:04.323 5040 5040 F DEBUG : #4 pc 0000000000051488 /data/app/com.google.chip.chiptool-dz3iwqwmItgQDBBaEcevJw==/base.apk (offset 0x97a000) (AndroidDeviceControllerWrapper::SendNetworkCredentials(char const*, char const*)+128) 02-16 20:56:04.323 5040 5040 F DEBUG : #5 pc 0000000000054188 /data/app/com.google.chip.chiptool-dz3iwqwmItgQDBBaEcevJw==/base.apk (offset 0x97a000) (Java_chip_devicecontroller_ChipDeviceController_sendWiFiCredentials+188) 02-16 20:56:04.323 5040 5040 F DEBUG : #6 pc 000000000013f350 /apex/com.android.runtime/lib64/libart.so (art_quick_generic_jni_trampoline+144) (BuildId: ccd73e8ae9b59d5596b3b8aeef234d43) <snip> 02-16 20:56:04.327 5040 5040 F DEBUG : #75 pc 00000000000be560 /system/lib64/libandroid_runtime.so (_JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...)+116) (BuildId: e5b25f8fb9f6bb45ccbeca8c07061dad) 02-16 20:56:04.327 5040 5040 F DEBUG : #76 pc 00000000000c13d0 /system/lib64/libandroid_runtime.so (android::AndroidRuntime::start(char const*, android::Vector<android::String8> const&, bool)+776) (BuildId: e5b25f8fb9f6bb45ccbeca8c07061dad) 02-16 20:56:04.327 5040 5040 F DEBUG : #77 pc 00000000000034e0 /system/bin/app_process64 (main+1168) (BuildId: ade4367f7cc82a88f668180d34ce79fe) 02-16 20:56:04.327 5040 5040 F DEBUG : #78 pc 000000000007dc24 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+108) (BuildId: 5812256023147338b8a9538321d4c456) * Make it an argument
1 parent 1e136a1 commit f2a4357

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

build/config/compiler/BUILD.gn

+13-1
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,25 @@ config("exceptions_default") {
318318
configs = [ ":no_exceptions" ]
319319
}
320320

321-
config("unwind_tables_default") {
321+
config("unwind_tables") {
322+
cflags = [ "-funwind-tables" ]
323+
}
324+
325+
config("no_unwind_tables") {
322326
cflags = [
323327
"-fno-unwind-tables",
324328
"-fno-asynchronous-unwind-tables",
325329
]
326330
}
327331

332+
config("unwind_tables_default") {
333+
if (exclude_unwind_tables) {
334+
configs = [ ":no_unwind_tables" ]
335+
} else {
336+
configs = [ ":unwind_tables" ]
337+
}
338+
}
339+
328340
config("size_default") {
329341
cflags = [
330342
"-fno-common",

build/config/compiler/compiler.gni

+3
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ declare_args() {
3131

3232
# Enable position independent executables (-pie).
3333
enable_pie = current_os == "linux"
34+
35+
# Remove unwind tables from the binary to save space.
36+
exclude_unwind_tables = current_os != "android"
3437
}

build/config/defaults.gni

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ declare_args() {
4848
default_configs_exceptions =
4949
[ "${build_root}/config/compiler:exceptions_default" ]
5050

51+
# Default configs for unwind tables.
52+
default_configs_unwind_tables =
53+
[ "${build_root}/config/compiler:unwind_tables_default" ]
54+
5155
# Defaults configs for rtti.
5256
default_configs_rtti = [ "${build_root}/config/compiler:rtti_default" ]
5357

@@ -91,6 +95,7 @@ default_configs += default_configs_symbols
9195
default_configs += default_configs_size
9296
default_configs += default_configs_specs
9397
default_configs += default_configs_exceptions
98+
default_configs += default_configs_unwind_tables
9499
default_configs += default_configs_pic
95100
default_configs += default_configs_rtti
96101
default_configs += default_configs_warnings

0 commit comments

Comments
 (0)