Scott
Scott

Reputation: 5263

How to start an android app with valgrind

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.

Upvotes: 24

Views: 18391

Answers (2)

victor
victor

Reputation: 11

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.

Upvotes: 1

jernkuan
jernkuan

Reputation: 630

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

Upvotes: 6

Related Questions