Can't run a Java Android program with Valgrind

匿名 (未验证) 提交于 2019-12-03 02:52:02

问题:

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 

I'm getting:

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

回答1:

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 $*  

that should be copied to the device.

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  

WARNING: Make sure the property name set with setprop i.e. (wrap.com.yourcompany.yourapp) has a length of less than 31 characters.
Otherwise, you'll get the error "could not set property" because you CANNOT set a property name with a length greater than 31, which is the number maximum allowed characters in the property name.
Also the property value should be https://stackoverflow.com/a/5068818/313113


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



回答2:

1) I had Used the Following script to Generate the Inst Folder Android valgrind build fails

2) The Mistake i was Doing is I have not Given write Permission to all the Folders under inst the MemCheck Tool is Under lib/valgrind .

My findings Copy all the Folders Under Generated Inst(bin,share,inclide,lib) Folder to /data/local/Inst Traverse through each folder and set the Permission to CHMOD 777 *

was facing the Issue Like Memcheck Tool Not Found for arm-linux if i didnot copy all the these Folders 1 folder /Inst facing memcheck permission if dont set the permission to chmod 777 to all the Folders in the Hirearchy



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!