Ale*_*tin 11 android valgrind android-ndk
我正试图在这样的Valgring下启动一个Java程序(在adb shell中):
valgrind am start -a android.intent.action.MAIN -n com.me.myapp/.MainActivity
Run Code Online (Sandbox Code Playgroud)
我越来越:
==2362== Memcheck, a memory error detector
==2362== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==2362== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==2362== Command: am
==2362==
/system/bin/sh: am: No such file or directory
Run Code Online (Sandbox Code Playgroud)
bit*_*tek 17
你必须创建一个脚本,我们称之为start_valgrind.sh
#!/system/bin/sh
PACKAGE="com.example.hellojni"
# Callgrind tool
#VGPARAMS='-v --error-limit=no --trace-children=yes --log-file=/sdcard/valgrind.log.%p --tool=callgrind --callgrind-out-file=/sdcard/callgrind.out.%p'
# Memcheck tool
VGPARAMS='-v --error-limit=no --trace-children=yes --log-file=/sdcard/valgrind.log.%p --tool=memcheck --leak-check=full --show-reachable=yes'
export TMPDIR=/data/data/$PACKAGE
exec /data/local/Inst/bin/valgrind $VGPARAMS $*
Run Code Online (Sandbox Code Playgroud)
应该复制到设备.
一旦在本地文件系统的某个地方的start_valgrind.sh文件中有上述脚本,您就可以使用下面的脚本(让我们称之为bootstrap_valgrind.sh)来完成所有工作(将start_valgrind.sh脚本复制到手机上,运行它,通过Valgrind启动你的应用程序).
#!/usr/bin/env bash
PACKAGE="com.example.hellojni"
adb push start_valgrind.sh /data/local/
adb shell chmod 777 /data/local/start_valgrind.sh
adb root
adb shell setprop wrap.$PACKAGE "logwrapper /data/local/start_valgrind.sh"
echo "wrap.$PACKAGE: $(adb shell getprop wrap.$PACKAGE)"
adb shell am force-stop $PACKAGE
adb shell am start -a android.intent.action.MAIN -n $PACKAGE/.HelloJni
adb logcat -c
adb logcat
exit 0
Run Code Online (Sandbox Code Playgroud)
警告:确保使用setprop ie(wrap.com.yourcompany.yourapp)设置的属性名称的长度小于31个字符.
否则,您将收到错误"无法设置属性",因为您无法设置长度大于31的属性名称,这是属性名称中允许的最大字符数.
此属性值应<= 91个字符:https://stackoverflow.com/a/5068818/313113
有关如何构建Valgrind for Android(ARM)的信息,请参阅我的脚本:https://stackoverflow.com/a/19255251/313113