使用包装器脚本时无法调试应用 [英] Cannot debug app when using wrapper script

查看:211
本文介绍了使用包装器脚本时无法调试应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已为我的应用的本机代码激活了地址清除程序,以检测某些内存泄漏.但是我有一个奇怪的问题.

I have activated address sanitizer for my app's native codes in order to detect some memory leak. But I have a strange problem.

在激活地址清理器之前,应用程序可以正常运行,并且我可以对其进行调试而没有任何问题.但是,在激活地址清理器之后,即使它运行正常,我也无法调试应用程序.这是一个非常奇怪的行为,因为激活地址清理器后,"Waiting for Debugger..."消息不再显示,并且在调试控制台中出现以下错误:

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.

同时,该应用程序运行良好,如果运行adb shell ps -A,我会很容易找到它,而在"attach to process"菜单中看不到它.

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.

有什么问题吗?

推荐答案

最后,在我的bug的线程,我能够为 android 27 + 创建一个工作包装器脚本. 我几乎可以肯定,您现在无法在Internet上找到任何其他有效的包装器脚本,并且这是唯一可以使用的包装器脚本.

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.

以下是完整的脚本:

#!/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

要与ASAN一起使用,只需在包装脚本开始时添加所需的ASAN配置(例如LD_PRELOAD).因此它将变得像这样:

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.

更新:Google更新了 wrap.sh 页面.您也可以在那里看到最终的包装器脚本.

Update: Google updated wrap.sh page in NDK based on this thread. You can see final wrapper script there too.

最好的问候

这篇关于使用包装器脚本时无法调试应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆