如何使用 valgrind 启动 Android 应用程序

发布于 2025-01-01 13:34:50 字数 864 浏览 4 评论 0原文

上周我一直在寻找这个问题的答案。

如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神仙妹妹 2025-01-08 13:34:50

您可以尝试先清除 logcat。

prompt# adb logcat -c
prompt# adb logcat

触发应用程序后,您应该能够看到传入的日志。

am start -a android.intent.action.MAIN -n com.example.hellojni/.HelloJni

我的 shell 脚本有问题,所以我用了这个。

adb shell setprop wrap.com.example.hellojni "logwrapper /data/local/Inst/bin/valgrind"

您应该能够在 valgrind 之后立即传入参数

You can try to clear the logcat first

prompt# adb logcat -c
prompt# adb logcat

You should be able to see the logs coming in once you triggered your application.

am start -a android.intent.action.MAIN -n com.example.hellojni/.HelloJni

I had problems with my shell script and i used this instead.

adb shell setprop wrap.com.example.hellojni "logwrapper /data/local/Inst/bin/valgrind"

You should be able to pass in the parameter right after valgrind

山有枢 2025-01-08 13:34:50

我也遇到了这个问题。在我的情况下,我在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文