Valgrind cannot execute memcheck tool on Android OS? - android

I've compiled Valgrind for ARM using this with minor alterations.
After installing on a phone with the method specified, I get the following error:
# /data/local/Inst/bin/valgrind
valgrind: failed to start tool 'memcheck' for platform 'arm-linux': Permission denied
On closer investigation, it is possible to find what it's trying to do:
# /data/local/Inst/bin/valgrind -d -v
--25068:1:debuglog DebugLog system started by Stage 1, level 1 logging requested
--25068:1:launcher no tool requested, defaulting to 'memcheck'
--25068:1:launcher no client specified, defaulting platform to 'arm-linux'
--25068:1:launcher launching /data/local/Inst/lib/valgrind/memcheck-arm-linux
valgrind: failed to start tool 'memcheck' for platform 'arm-linux': Permission denied
However, the executable is there and has the right permissions:
# ls -l /data/local/Inst/lib/valgrind/memcheck-arm-linux
-rwxrwxrwx root root 9261240 2013-10-28 17:00 memcheck-arm-linux
Furthermore, trying to execute it yields no problem, which eliminates dynamic linking problems as well:
/data/local/Inst/lib/valgrind/memcheck-arm-linux
valgrind: You cannot run '/data/local/Inst/lib/valgrind/memcheck-arm-linux' directly.
valgrind: You should use $prefix/bin/valgrind.
At this point, I'm mostly out of ideas, any help would be greatly appreciated.
I'm aware of this similar post, but I'm sure (based on the output with "-d") the prefix is right.
Potential clue: this worked a few "ROM"-s before, but unfortunately, this current one is the exact same on which it worked previously, with the exact same Valgrind build.
The minor alterations: since the build was done on a 64 bit system, _64 was appended to toolchain paths where appropriate. I can post the full script, but it should be irrelevant. Famous last words, potentially.

I recently ran into the exact same problem.
On my device /data/local/Inst and all of its content is owned by a user named "shell".
Strange enough, when I try to execute valgrind with the root user, I get the above-mentioned error, but as soon as I log in with the unprivileged user, I can run valgrind without any issues.
From the information you posted, I take, that you installed valgrind as the root user, and I assume you also executed it as root.
So here are the steps that got it working for me:
/data/local/Inst is owned by an unprivileged user
Install valgrind with the same unprivileged user
Again, execute valgrind with the same user
Hope this helps.

Normally, this indicates some files (either lib or config files) lack the permission to you. Most likelihood is when you install the Valgrind with root, the umask may exclude the rx for others.
It is easy to solve this by adding the rx permission for others:
find /usr/local -name "*valgrind*" -exec chmod o+rxt {} \;

If you use Valgrind on Android, at least there are three way to solve the problem. (You must root your Android phone first.)
On your PC
cmd
adb shell
$su
#cp /data/local/Inst/bin/valgrind /system/bin/
Note: Remember to chmod. For example chmod 777 valgrind.
On your Android phone
Install an app "Root Explorer". Copy valgrind to /system/bin/ with the app.
Write a shell script
This is a example: Can't run a Java Android program with Valgrind
Chinese Comments:
我本人曾不止一次英语考试不及格。写英文回贴真的很不舒服。不过自我学Android开始,就从http://stackoverflow.com 这里得到过很多帮助。 知恩回报是中华民族的传统美德,所以
就硬首头皮写了这个E文回贴。

Related

Eclipse - Why Errors with Android SDK for normal user but not root?

Why doesn’t this error happening when starting Eclipse as a normal user, but doesn’t when starting as sudo:
I have checked the permission of all directories that I can imagine that might be affected and chowned to my user and group id.
These are the root directories of all areas that I’m familiar with:
Folder Specification
-------------------------------------------------------------
/opt/android/sdk Android SDK
/opt/eclipse/eclipse Eclipse
~/myeclipse Eclipse specific configuration area
~/workspace Source workspace
These are the commands that were issues to ensure that My user and group ID are assigned:
$ sudo chown -R ljames:ljames /opt/android/sdk
$ sudo chown -R ljames:ljames /opt/eclipse/eclipse
$ sudo chown -R ljames:ljames ~/myeclipse
$ sudo chown -R ljames:ljames ~/workspace
Can someone tell me what else might be causing this possible
permission issue?
I also executed this command on all the subdirectories to find any file or directory not belonging to my user ID.
$ sudo find /opt/android/sdk ! -user ljames
$ sudo find /opt/eclipse/eclipse ! -user ljames
$ sudo find ~/myeclipse ! -user ljames
$ sudo find ~/workspace ! -user ljames
Clearly, this is a permissions problem. Root is not troubled by permissions; others are. Actually, there's one exception: at least one execute bit S_IXUSR|S_IXGRP|S_IXOTH in the permissions field ( di_flags & ~(S_IFMT) ) must be on for users--EVEN ROOT--to execute a program. This used to be true for "executing" (viz., searching) a directory, but no longer is. Note that I parenthesized S_IFMT because one should always be ultra-defensive when incorporating macros in expressions: they can be a source of obscure bugs.
I suspect the problem might be something that's superficially subtle but really isn't if you know how directory permissions work. I would be willing to BET MONEY that some directory somewhere is SEARCHABLE to your non-root programmer but is not READABLE. The difference is that "search" enables you to locate an entry of known name within a directory, whereas "read" enables you to browse the directory like an open catalog. In order to discover whole sets of files, say, *.java, that can be scanned sequentially for, say, the body of a given function, the containing directory must be READable as well as SEARCHable.

Can I start an executable in an approved application?

I've noticed that it is possible on Android to change the permissions on a file with chmod, which means we can easily execute anything from an application:
var runtime = Runtime.GetRuntime();
runtime.Exec("chmod 0755 /my/file").WaitFor();
// Then ProcessBuilder to execute it.
Would Google Play Store accept an application that takes advantage of this flaw? I can't find any documentation about it, but I confirm that it works.
Actually, I want to include ffmpeg for tasks that are too slow to be executed using MediaCodec.
(I've also noticed that the Android framework sometimes directly access to a native version of ffmpeg, so maybe I could access it directly from the phone?)
I don't know for sure if it is ok for Google Play.
However i don't think it is security issue. You will exec process with the autorisation of your app.
I hope the following example will help you.
You can try the following command line with your device connect.
adb shell
To have a shell on your devices
Then you can try to look what is inside the files for an app (replace com.your.package by the name of a debbugable apk)
ls /data/data/com.your.package
This command will failde because you have not the good permission.
Now run the following command.
run-as com.your.package
You will now exec your command line with the same permission as your app.
You can now retry the previous ls command. It will work. However it will not work for another package.
So, i think the command you will exec with your code, will be exec with the privilege of your app. So i don't think you can elevate the privilege of you app on a file with this method.

Android Terminal-IDE: terminal-gcc error: arm-eabi-gcc not found

I'm using Terminal-IDE as my development environment. (Google code site here.)
I'm running Terminal-IDE v 2.02 - the very latest. My Android versions are:
Android 4.0.3
Software version 2.14.531.3 71ORD
(the rest aren't likely pertinent, but more on request)
I'm in a suitable development directory with a simple enough c source code file ready and run 'make'.
I have never yet gotten any compilation to work successfully. Most likely, there's a version mis-match with regard to what executable is available versus what the software is looking for.
Here's the command and error message:
terminal-gcc -c -Wall -I/data/data/com.spartacusrex.spartacuside/files/local/include tester.c -o tester.o
/data/data/com.spartacusrex.spartacuside/files/system/bin/terminal-gcc[43]: arm-eabi-gcc: not found
make: *** [tester.o] Error 127
Snafu, of course. I'm not at all sure how to find out what the right compiler file name(s) should be because, on this non-rooted phone, I don't have permissions to hunt through the PATH and find the actual executables.
It may also be that PATH is set wrong. All input appreciated.
...I'm not sure what's supposed to happen, but I found in the Terminal-IDE directory tree the file:
$IDESYSTEM/android-gcc-4.4.0.tar.gz
I also found that terminal-gcc is a bash script. Looking inside it seemed to say that a gcc tree should exist in "$HOME", which is the installation directory. So, I unzipped, then un-tarred the file identified above and put the resulting directory tree as a top-level subdirectory.
Well well, what do you know? Success.
I went a little further and created soft links to the actual compiler in ~/bin for both gcc and just cc, and suddenly all my previously created "Makefile" scripts used in other projects I wanted to move over started working perfectly.
Apparently, even though I thought I'd done it right, I overlooked running this script:
./system/bin/install_gcc
It extracts the tar, like I did, but does not create the links you may need.
Hey, if you're glad I got here before you, give it a thumbs up!
A credit goes to #Richard T for his enthusiasm regarding Terminal IDE. The answer is intended to enumerate the steps needed for running a C code.
To run a C code
Run Terminal IDE and extract the gcc package by executing
install_gcc
Create a directory for your projects within the Terminal IDE directory tree. Then in the directory create a source .c file with some code (filename.c here). Compile it
terminal-gcc -c filename.c
Create the executable file
terminal-gcc filename.o -o filename.out
Run the output file
./filename.out
If you'd like to use the PC (laptop) keyboard you can telnet Terminal IDE.
To Telnet Terminal IDE
From Terminal IDE start the telnetd deamon by executing
telnetd
Connect the Android device to the PC (laptop) and type
adb forward tcp:[port] tcp:8080
telnet 127.0.0.1 [port]
P.S. Telnet's default port is 23.

NO such file or directory error when doing insmod in Android Kernel

I followed the steps in the forum (http://www.schaeuffelhut.de/wordpress/?p=237&cpage=1#comment-384) to get the linux kernel source and and cross compile my module. The kernel version of the google nexus one is exactly the same as in the forum. I initially tested with my test module hello-1.ko which got installed on the android device successfully. But when I am installing my module ec.ko on the android device using insmod, I get the following error.
apurva#apurva-Inspiron-1464:~/$ adb shell
$ cd sdcard/data/ec
$ ls
ec.ko
$ su
# insmod ec.ko
insmod: init_module 'ec.ko' failed (No such file or directory)
#
It is clear that the file ec.ko is present. But I am not sure why it is not picking the file. I did the same thing for hello-1.ko and it gets insmod pretty fine. There is no permission issue, and ec.ko gets the same permission as was obtained by hello-1.ko.
Now this bring me to the question, Are there certain limitations of a kernel module in an android device because this module gets insmod in Ubuntu. Next action for me is to go for a hit and trial method and check what lines in ec.c is causing the problem. Meanwhile if you some suggestion, please let me know.
You can check the dmesg log to see something can help you.I have also encountered the same problem.Following is how I solved this problem.
I installed my module on the android device by using insmod command,but I got the same error message like you.I checked the dmesg at that time,and I got this:Unknown symbol "XXX"(I have forgotten the function name.).I used the command —— cat /proc/kallsyms |grep "XXX" to find this symbol,but I found nothing.The reason for this problem is the function have been deprecated in AndroidM.Finally,I fixed this problem by annotating the function.

Running ndk-gdb with package not found error on motorola phone

I have a C++ Android application that I'm trying to debug with ndk-gdb. The application does use multiple threads, but supposedly r5 of the ndk supports multiple threads. Also, I'm not even getting to the point where gdb starts up. I run the command:
ndk-gdb --start --force --verbose
It then finds the proper path for the ndk and sdk (or at least adb), and the needed ABIs and whatnot.
$ ndk-gdb --start --force --verbose
Android NDK installation path: /home/leif/eclipse/android-ndk-r5b
Using default adb command: /home/leif/eclipse/android-sdk-linux_86/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.26
Using final ADB command: '/home/leif/eclipse/android-sdk-linux_86/platform-tools/adb'
Using auto-detected project path: .
Found package name: net.leifandersen.mobile.android.marblemachine
ABIs targetted by application: armeabi
Device API Level: 10
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi
It then looks for gdb server, and finds it, including the proper PID, followed by starting the activity.
But then, it tells me that the the package cannot be found:
Setup network redirection
## COMMAND: /home/leif/eclipse/android-sdk-linux_86/platform-tools/adb shell run-as <package name> lib/gdbserver +debug-socket --attach 16040
## COMMAND: /home/leif/eclipse/android-sdk-linux_86/platform-tools/adb forward tcp:5039 localfilesystem:run-as: Package '<package name>' is unknown/debug-socket
It then spits out what you would get if you improperly use adb (the help file), followed by:
ERROR: Could not setup network redirection to gdbserver?
Maybe using --port=<port> to use a different TCP port might help?
run-as: Package '<package name>' is unknown
I looked into /data/system/packages.list, and yes, my apk is most certainly in there, and the location it's pointing to is correct on the file system. So that's not the problem.
This tutorial: http://vilimpoc.org/blog/2010/09/23/hello-gdbserver-a-debuggable-jni-example-for-android/ recommends deleting and reinstalling, as well as cleaning your eclipse build.
I didn't use eclipse to build the package, but I did clean everything out and compile from scratch, deleted, and reinstalled to no luck.
Has anyone had similar problems, and how did you resolve them? Thank you.
Edit: Oh, and I have tried a different port to no avail, there does not appear to be anything on 5039 (the default port) anyway. And afaik, I don't have any firewalls blocking that connection. I'm developing on Ubuntu 11.04 as well.
Edit2: Hmm...it looks like with the new ndk (r5c), the error message has now changed too:
ERROR: Could not extract package's data directory. Are you sure that
your installed application is debuggable?
And yes, debuggable is set to true in the manifest, and all of the native code is built with:
LOCAL_CFLAGS := -Wall -g
LOCAL_LDFLAGS := -Wl,-Map,xxx.map
run-as: Package 'net.leifandersen.mobile.android.marblemachine' is unknown
Thus, unfortunately, your device is not able to be used with ndk-gdb, because run-as doesn't work. If you want to use that device, you must have root privilege.
EDITED:
Modify ndk-gdb script to get rid of the dependency of run-as. It works only on root privilege ('adb shell whoami' should be 'root').
--- ndk-gdb 2011-02-24 16:55:07.000000000 +0900
+++ ndk-gdb-root 2011-06-09 08:35:04.000000000 +0900
## -465,7 +465,7 ##
log "Using app out directory: $APP_OUT"
# Find the <dataDir> of the package on the device
-DATA_DIR=`adb_shell run-as $PACKAGE_NAME /system/bin/sh -c pwd`
+DATA_DIR="/data/data/$PACKAGE_NAME"
log "Found data directory: '$DATA_DIR'"
if [ $? != 0 -o -z "$DATA_DIR" ] ; then
echo "ERROR: Could not extract package's data directory. Are you sure that"
## -543,7 +543,7 ##
# Launch gdbserver now
DEBUG_SOCKET=debug-socket
-run $ADB_CMD shell run-as $PACKAGE_NAME lib/gdbserver +$DEBUG_SOCKET --attach $PID &
+run $ADB_CMD shell "(cd $DATA_DIR; lib/gdbserver +$DEBUG_SOCKET --attach $PID)" &
if [ $? != 0 ] ; then
echo "ERROR: Could not launch gdbserver on the device?"
exit 1
There is a bug with run-as, it will fail if you have too many apps installed. I was able to work around this problem by removing some apps from my Evo 4G. I found this in the NDK discussion groups - http://groups.google.com/group/android-ndk/browse_thread/thread/ae9e8d5fe2716ae6?pli=1
I had the same issue today with Samsung Galaxy S running MIUI rom. ndk-gdb always reported "Could not extract package's data directory. Are you sure that your installed application is debuggable?"
It turned out the reason is that run-as not working due to /data/data symlink. Cyanogen is used in the customized ROM. Removing the symbolic link and move all files from /datadata to /data/data solved the problem.
Cyanogen 2.3 fix:
ndk-gdb relies on the 'run-as' command, which itself makes a number of checks on the /data/data directory. In Cyanogen 2.3, it's a symlink, and run-as fails with a cryptic message, and ndk-gdb fails in return with [2]:
ERROR: Could not extract package's data directory. Are you sure that
your installed application is debuggable?
A work-around is to recreate /data/data with symlink :
cd /data/data /datadata.break-run-as
mkdir -m 771 /data/data/
chown system: v
mv /datadata/* /data/data/
http://en.wikibooks.org/wiki/OpenGL_Programming/Installation/Android_NDK
http://forum.cyanogenmod.com/topic/27657-run-as-not-working-due-to-datadata-symlink/
Hope it helps others with similar issue. Check to see if run-as works as expected or not. It's not because your binary is not debuggable. ndk-gdb's error message is very misleading.
Had a similar problem and running:
adb shell run-as com.mypackagename /system/bin/sh -c pwd
would output:
run-as: Package 'com.mypackagename' has corrupt installation
fix was to uninstall on device then reinstall from command line via:
adb install MyApkFile.apk
I also experienced this problem and discovered that it can be caused by short package names!
When testing on an Android 2.2 system with an application that had a package with 3 levels (e.g: a.b.c) ndk-gdb would not work. Changing the package to have 4 or more levels (e.g. a.b.c.d) or running on Android 2.3 or later resolved the issue.
see http://code.google.com/p/android/issues/detail?id=13965 for more information.
There is still another posibility for this problem to occur: if you have previously installed your application as a system app (in /system/app), uninstalled it and then installed it once again as a normal application. In that case it is posible that there is still some files remaining that your application cannot access because it has no permissions.
I solved it by uninstalling my application and manually removing every piece of information related to it (with adb shell and root privileges). As far as I know, that comprises:
Everything under /data/data/<your app package>
The file named /data/dalvik-cache/* <your app package>*
After installing it again, I was able to debug the application again.
In case anyone is using Samsung Galaxy S4/... and got 4.4.2 (latest stock rom - by now at all countries) - you got screwed! Samsung bug. So root as explained in one of the answers above, or get another device...
Another solution is to revert to Android 4.2.2 (not 4.4.2) - pre 4.3 version which started this issue.

Categories

Resources