Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

android - 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...