无法使用 Valgrind 运行 Java Android 程序 [英] Can't run a Java Android program with Valgrind

查看:29
本文介绍了无法使用 Valgrind 运行 Java Android 程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Valgring 下像这样(在 adb shell 中)启动一个 Java 程序:

I'm trying to start a Java program under Valgring like this (in adb shell):

valgrind am start -a android.intent.action.MAIN -n com.me.myapp/.MainActivity

我得到:

==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

推荐答案

你必须创建一个脚本,我们称之为 start_valgrind.sh

You have to create a script, lets call it 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 $* 

应该复制到设备上.

一旦您在本地文件系统上的 start_valgrind.sh 文件中拥有上述脚本,您就可以使用以下脚本(我们称之为 bootstrap_valgrind.sh)来完成所有工作(将 start_valgrind.sh 脚本复制到手机,运行它,通过 Valgrind 启动您的应用).

Once you have the above script in the start_valgrind.sh file somewhere on your local filesystem you can just use the below script (lets call it bootstrap_valgrind.sh) to do the all the work (copies the start_valgrind.sh script to the phone, runs it, starts your app through 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 

警告:确保使用 setprop 设置的属性名称,即 (wrap.com.yourcompany.yourapp) 的长度小于 31 个字符.
否则,您将收到错误无法设置属性",因为您不能设置长度大于 31 的属性名称,这是属性名称中允许的最大字符数.
此外,属性值应为 <= 91 个字符:https://stackoverflow.com/a/5068818/313113

有关如何为 Android (ARM) 构建 Valgrind,请从此处查看我的脚本:https://stackoverflow.com/a/19255251/313113

For how to build Valgrind for Android (ARM) see my script from here: https://stackoverflow.com/a/19255251/313113

这篇关于无法使用 Valgrind 运行 Java Android 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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