问题
I have activated address sanitizer for my app's native codes in order to detect some memory leak. But I have a strange problem.
Before activating address sanitizer, app just runs normally and I can debug it without any problems. But after activating address sanitizer, I cannot debug app anymore, even though it runs just fine. It is a really strange behavior because after activating address sanitizer, "Waiting for Debugger..."
message does not show anymore and I get following error in debug console:
Could not connect to remote process. Aborting debug session.
At same time, app just works fine and I can find it easily if I run adb shell ps -A
while I won't see it in "attach to process"
menu.
Any idea what the problem is?
回答1:
Finally with help of people in my bug's thread, I were able to create a working wrapper script for android 27+. I'm almost sure you cannot find any other working wrapper script in internet right now and this is the only working one.
Here is full script:
#!/system/bin/sh
processname=$1
shift
sdkversion=$(getprop ro.build.version.sdk)
if [ "$sdkversion" -gt "28" ]; then
fullpath="$processname -XjdwpProvider:adbconnection $@"
elif [ "$sdkversion" -eq "28" ]; then
fullpath="$processname -XjdwpProvider:adbconnection -XjdwpOptions:suspend=n,server=y -Xcompiler-option --debuggable $@"
elif [ "$sdkversion" -eq "27" ]; then
fullpath="$processname -Xrunjdwp:transport=dt_android_adb,suspend=n,server=y -Xcompiler-option --debuggable -Xcompiler-option --generate-mini-debug-info $@"
else
log -p e -t "WRAPPER" "Wrapper script only works starting API level 27!"
exit 1
fi
$fullpath
For using with ASAN, just add your required ASAN configs(e.g. LD_PRELOAD
) at start of wrapper script. So it will become somethign like this:
#!/system/bin/sh
HERE="$(cd "$(dirname "$0")" && pwd)"
export ASAN_OPTIONS=log_to_syslog=false,allow_user_segv_handler=1
export LD_PRELOAD=$HERE/libclang_rt.asan-${arch}-android.so
processname=$1
shift
sdkversion=$(getprop ro.build.version.sdk)
if [ "$sdkversion" -gt "28" ]; then
fullpath="$processname -XjdwpProvider:adbconnection $@"
elif [ "$sdkversion" -eq "28" ]; then
fullpath="$processname -XjdwpProvider:adbconnection -XjdwpOptions:suspend=n,server=y -Xcompiler-option --debuggable $@"
elif [ "$sdkversion" -eq "27" ]; then
fullpath="$processname -Xrunjdwp:transport=dt_android_adb,suspend=n,server=y -Xcompiler-option --debuggable -Xcompiler-option --generate-mini-debug-info $@"
else
log -p e -t "WRAPPER" "Wrapper script only works starting API level 27!"
exit 1
fi
$fullpath
I wish this script will be useful for everyone.
Update: Google updated wrap.sh page in NDK based on this thread. You can see final wrapper script there too.
Best Regards
来源:https://stackoverflow.com/questions/54550668/cannot-debug-app-when-using-wrapper-script