官网文档介绍了如何使能Address Sanitizer和运行时控制它的行为
https://developer.android.google.cn/ndk/guides/asan?hl=zh-cn
https://source.android.google.cn/devices/tech/debug/asan?hl=zh_cn
https://github.com/google/sanitizers/wiki
本文接下来主要是对官网的补充:
1、Android.bp构建Native代码时如何使能Address Sanitizer功能
cc_library_shared {
name: "libnative_test",
cflags: [
"-fno-omit-frame-pointer",
"-O0",
],
sanitize: {
address: true;//使能Address Sanitizer
hwaddress: true;//使能HW Address Sanitizer
},
}
cflags增加"-fno-omit-frame-pointer"和"-O0"选项,为了让打印的栈信息更清晰
address和hwaddress字段不能一起使能,
2、AndroidManifest.xml中android:extractNativeLibs=true如果不配置采用默认值可能会出现APK