如何使用 valgrind 启动 Android 应用程序
上周我一直在寻找这个问题的答案。
如何使用 valgrind 启动 Android 应用程序?我知道我可以使用“am”命令启动应用程序,但它会启动应用程序并退出。
我正在编写一个使用 NDK 执行本机 C 代码的应用程序,我需要检查它是否存在可疑的内存错误。
编辑:
我又学到了一点。您可以使用 shell 脚本“包装”应用程序。
这是我正在使用的 shell 脚本:
#!/system/bin/sh
VGPARAMS='--error-limit=no'
export TMPDIR=/data/data/com.starlon.froyvisuals
exec /data/local/Inst/bin/valgrind $VGPARAMS $*
这是 setprop:
adb shell setprop wrap.com.starlon.froyvisuals "logwrapper valgrind"
这是我启动应用程序的方式:
adb shell am start -n com.starlon.froyvisuals/.FroyVisuals
我认为这是不对的,因为我不确定 shell 脚本适合哪里,而且我没有看到任何内容日志猫。有什么提示吗?
编辑2: 哦,shell 脚本是用上面的“setprop”命令指示的。所以
adb shell setprop wrap.com.starlon.froyvisuals "logwrapper /data/local/val.sh"
我在 logcat 中仍然没有看到任何内容。
I've been searching for the last week trying to find an answer to this question.
How do I start an Android app with valgrind? I know I can start an app with the 'am' command, but it starts the app and exits.
I'm writing an app that uses the NDK for native C code, and I need to check it for suspected memory errors.
Edit:
I've learned a little more. You can "wrap" an app with a shell script.
Here's the shell script I'm using:
#!/system/bin/sh
VGPARAMS='--error-limit=no'
export TMPDIR=/data/data/com.starlon.froyvisuals
exec /data/local/Inst/bin/valgrind $VGPARAMS $*
And here's setprop:
adb shell setprop wrap.com.starlon.froyvisuals "logwrapper valgrind"
And here's how I start the app:
adb shell am start -n com.starlon.froyvisuals/.FroyVisuals
I don't think this is right, because I'm not sure where the shell script fits in and I'm not seeing anything in logcat. Any hints?
Edit2:
Oh the shell script is indicated with "setprop" command above. So
adb shell setprop wrap.com.starlon.froyvisuals "logwrapper /data/local/val.sh"
I'm still not seeing anything in logcat.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试先清除 logcat。
触发应用程序后,您应该能够看到传入的日志。
我的 shell 脚本有问题,所以我用了这个。
您应该能够在 valgrind 之后立即传入参数
You can try to clear the logcat first
You should be able to see the logs coming in once you triggered your application.
I had problems with my shell script and i used this instead.
You should be able to pass in the parameter right after valgrind
我也遇到了这个问题。在我的情况下,我在 Windows 和 Windows 中编辑“val.sh”。 adb推送到模拟器上,但是shell脚本无法正确执行。然后我使用 echo "*" > val.sh 样式来制作“val.sh”并且效果很好。
因此,您应该首先确保“val.sh”可以被正确解释。
I encountered this problem too. In my situation, I edit the "val.sh" in windows & adb push it to the emulator, but the shell script could not be executed correctly. Then I use a echo "*" > val.sh style to make the "val.sh" and It works well.
So you should first make sure the "val.sh" could be interpreted correctly.