Summary: | port vgdb 'ptrace' invoker on android to allow vgdb to connect to a process blocked in a syscall | ||
---|---|---|---|
Product: | [Developer tools] valgrind | Reporter: | Ayberk Özgür <ayberk.ozgur> |
Component: | general | Assignee: | Julian Seward <jseward> |
Status: | REPORTED --- | ||
Severity: | wishlist | CC: | philippe.waroquiers |
Priority: | NOR | ||
Version First Reported In: | 3.9.0 | ||
Target Milestone: | --- | ||
Platform: | Android | ||
OS: | Android 4.x | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: |
Description
Ayberk Özgür
2014-09-10 13:26:35 UTC
Please refer to user manual section http://www.valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.gdbserver-limitations bullet 'Connecting to or interrupting a Valgrind process blocked in a system call.' last paragraph, which is: "Unblocking processes blocked in system calls is not currently implemented on Mac OS X and Android. So you cannot connect to or interrupt a process blocked in a system call on Mac OS X or Android. " See also coregrind/Makefile.am, which contains: if VGCONF_OS_IS_LINUX if VGCONF_PLATVARIANT_IS_ANDROID vgdb_SOURCES += vgdb-invoker-none.c else vgdb_SOURCES += vgdb-invoker-ptrace.c endif endif vgdb should be able to connect to a program that 'executes' something from time to time (as the vgdb FIFO will be polled from time to time). The command option --vgdb-poll=<number> gdbserver poll max every <number> basic blocks [5000] can be used to change the polling frequency. As far as I can see, the test has been done with 'sleep 1000', which means the process is blocked in a syscall. So, this is a known limitation on android. It would be nice to update Valgrind on android so that it uses vgdb-invoker-ptrace.c instead of vgdb-invoker-none.c. Can you conform vgdb can properly connect to a process that executes some basic blocks from time to time ? Assuming this is working ok, keeping this bug as a 'wishbug' to port vgdb-invoker-ptrace.c on android Indeed, I was able to `vgdb instrumentation on` / `vgdb instrumentation off` the following: `valgrind --vgdb=yes --tool=callgrind ping google.com`. However, vgdb still freezes when trying to send a message to an application with native components launched using the wrapping method described here: http://stackoverflow.com/questions/13531496/cant-run-a-java-android-program-with-valgrind/19235439#19235439. I even tried bypassing `logwrapper` and wrapping the app directly with `start_valgrind.sh`. Doesn't help. What's more, the app itself freezes too. I tried leaving it alone for about an hour thinking that it might be a very slow process, still no luck. My `start_valgrind.sh` looks like: ``` #!/system/bin/sh PACKAGE="some.package.name" # Callgrind tool VGPARAMS='-v --instr-atstart=no --error-limit=no --trace-children=yes --log-file=/sdcard/valgrind.log.%p --tool=callgrind --callgrind-out-file=/sdcard/callgrind.out.%p --vgdb=yes' export TMPDIR=/data/data/$PACKAGE export USER=root export HOSTNAME=t0lte exec valgrind $VGPARAMS $* ``` My `start_valgrind_profiling.sh` script looks like the following and I run it to launch the app itself: ``` #!/usr/bin/env bash PACKAGE="some.package.name" adb root adb push start_valgrind.sh /data/local/ adb shell chmod 777 /data/local/start_valgrind.sh adb shell setprop wrap.$PACKAGE "/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/.MainActivityName adb logcat -c adb logcat exit 0 ``` I tried this with three apps, one is https://code.google.com/p/android-native-egl-example/ (with nothing but the WRITE_EXTERNAL_STORAGE permission added). Second is the same app but with a busy loop inserted into its native onStart function: ``` while(true){ for(int i=0;i<9999999;i++){ i += 4; LOG_INFO("%d",i); } } ``` Third is a Qt app with a lot of Qt and OpenCV libraries that regularly gets and processes the camera image, so it does not wait for I/O most of the time. All three apps respond exactly the same to `vgdb instrumentation on` in every point of its lifetime. One strange thing is that the valgrind process belongs to some user named `u0_a77`. Does the valgrind process not belonging to `root` introduce a problem here? It looks that there are 2 different problems: 1. a known limitation of vgdb 2. a problem of having applications freezing (with and without using vgdb IIUC). I do not know much about android so cannot help a lot about that (and before being able to help, I should re-install android SDK and emulator). Probably better to file another bug for the 2nd problem, unless it is really related to vgdb. |