ndk-gdb debugging

3,347 views
Skip to first unread message

faris

unread,
Sep 21, 2011, 7:23:01 PM9/21/11
to android-ndk
*note: I am trying this on an unrooted Droid X device (not emulator,
which I unfortunately cannot use due to no GL ES 2.0 support) with NDK
r6b

When trying to start ndk-gdb I am getting the following output:

$ ndk-gdb --start --verbose
Android NDK installation path: /home/faris/android-ndk-r6b
Using default adb command: /home/faris/android-sdk-linux_x86/platform-
tools/adb
ADB version found: Android Debug Bridge version 1.0.26
Using final ADB command: '/home/faris/android-sdk-linux_x86/platform-
tools/adb'
Using auto-detected project path: .
Found package name: com.game
ABIs targetted by application: armeabi
Device API Level: 8
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi
Found debuggable flag: true
Found device gdbserver: /data/data/com.game/lib/gdbserver
Using gdb setup init: /home/faris/workspace/android/Game/libs/armeabi/
gdb.setup
Using toolchain prefix: /home/faris/android-ndk-r6b/toolchains/arm-
linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-
Using app out directory: /home/faris/workspace/android/Game/obj/local/
armeabi
ERROR: Could not extract package's data directory. Are you sure that
your installed application is debuggable?

Debuggable is set to "true" in the manifest, and my shared library
modules are specifying LOCAL_CFLAGS := -g

Tim Mensch

unread,
Sep 21, 2011, 7:29:55 PM9/21/11
to andro...@googlegroups.com

Does your libs/armeabi folder have a gdbserver in it?

If not, you need to run ndk-build again. You may even need to run
"ndk-build clean" first, and then ndk-build.

ndk-build looks at the "debuggable" attribute in the XML to determine
how to build the binary, and whether to include gdbserver.

Tim

faris

unread,
Sep 21, 2011, 7:37:32 PM9/21/11
to android-ndk
Hey Tim,

Thanks for the quick response. gdbserver does exist in the libs/
armeabi dir... also from this output line "Found device gdbserver: /
data/data/com.game/lib/gdbserver" it also seems like it is being
deployed correctly to the device. This is actually one of the reasons
I am quite confused.

Tim Mensch

unread,
Sep 21, 2011, 7:52:06 PM9/21/11
to andro...@googlegroups.com
I see.

Hmm...I'm going to suggest a clean build from Eclipse AFTER you right
click on the project and select "Refresh" (or however you would do a
clean build the Java side).

It sounds like the project has the data directory locked, which happens
to applications built for release.

The other possibility is that the device is somehow broken wrt debugging
-- have you ever managed to get ndk-gdb to work on this device? Have you
tried another device? What device is it?

Tim

faris

unread,
Sep 21, 2011, 9:01:46 PM9/21/11
to android-ndk
I haven't tried ndk-gdb prior to today... also, I've only tried it on
this device (Droid X running 2.2.1). I think my next step is to try
with an emulator.

David Turner

unread,
Sep 22, 2011, 10:42:18 AM9/22/11
to andro...@googlegroups.com
This message indicates that ndk-gdb couldn't find the location of your installed application.
Can you do the following in a terminal while your device is connected and report the output:

adb shell run-as <your-package-name> /system/bin/sh -c pwd

Replace <your-package-name> with the name of your package (e.g. com.example.hellojni or whatever)

That's essentially what ndk-gdb is trying to do (according to the log, your package name if just 'com.game', but maybe it's really different and that's the problem).

Thanks in advance


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


faris

unread,
Sep 23, 2011, 7:58:34 AM9/23/11
to android-ndk
When trying run-as with my com.game package, I get a 'com.game is
unknown' response. When you mentioned the package name, I thought
about a posted issue on the android svn here:
http://code.google.com/p/android/issues/detail?id=13965 . A few of
these folks had mentioned issues with package names (relating to the
number of levels). To test my application package, I duplicated my
project, and renamed the package to com.game2, rebuilt with the ndk
and compiled, and I was able to attach gdb to my application
correctly. Also... executing run-as with this new package responds
with '/data/data/com.game2', as I'm assuming it should? I refuse to
believe that the issue is related to the number of levels in the
package name, or anything relating to the actual package name, but
more likely some system cached settings on the device.

David Turner

unread,
Sep 23, 2011, 9:29:16 AM9/23/11
to andro...@googlegroups.com
On Fri, Sep 23, 2011 at 1:58 PM, faris <fari...@gmail.com> wrote:
When trying run-as with my com.game package, I get a 'com.game is
unknown' response. When you mentioned the package name, I thought
about a posted issue on the android svn here:
http://code.google.com/p/android/issues/detail?id=13965 . A few of
these folks had mentioned issues with package names (relating to the
number of levels). To test my application package, I duplicated my
project, and renamed the package to com.game2, rebuilt with the ndk
and compiled, and I was able to attach gdb to my application
correctly. Also... executing run-as with this new package responds
with '/data/data/com.game2', as I'm assuming it should? I refuse to
believe that the issue is related to the number of levels in the
package name, or anything relating to the actual package name, but
more likely some system cached settings on the device.


I'm happy that this issue is resolved for you. I believe the bug has nothing to do with the number of levels in the package name.
It's more likely the fact that run-as uses an 8KB buffer to read the /system/data/packages.list file, and that on devices with a lot of installed applications/packages, this size is too smal and you end up reading a truncated file.
 
The bug has been fixed in AOSP by using mmap() instead (so no more size restrictions). Sorry about that though.

Brad Larson

unread,
Nov 12, 2011, 11:17:31 PM11/12/11
to android-ndk


On Sep 23, 8:29 am, David Turner <di...@android.com> wrote:
> On Fri, Sep 23, 2011 at 1:58 PM, faris <faris...@gmail.com> wrote:
> > When trying run-as with my com.game package, I get a 'com.game is
> > unknown' response. When you mentioned the package name, I thought
> > about a posted issue on the android svn here:
> >http://code.google.com/p/android/issues/detail?id=13965. A few of
> > these folks had mentioned issues with package names (relating to the
> > number of levels). To test my application package, I duplicated my
> > project, and renamed the package to com.game2, rebuilt with the ndk
> > and compiled, and I was able to attach gdb to my application
> > correctly. Also... executing run-as with this new package responds
> > with '/data/data/com.game2', as I'm assuming it should? I refuse to
> > believe that the issue is related to the number of levels in the
> > package name, or anything relating to the actual package name, but
> > more likely some system cached settings on the device.
>
> I'm happy that this issue is resolved for you. I believe the bug has nothing
> to do with the number of levels in the package name.
> It's more likely the fact that run-as uses an 8KB buffer to read the
> /system/data/packages.list file, and that on devices with a lot of installed
> applications/packages, this size is too smal and you end up reading a
> truncated file.
>
> The bug has been fixed in AOSP by using mmap() instead (so no more size
> restrictions). Sorry about that though.

I just ran into this on my Evo 4G. Removing some apps fixed the
problem. David, thanks so much for mentioning this bug!

Brad

yostane

unread,
Nov 13, 2011, 4:41:55 PM11/13/11
to android-ndk
Hi, I am getting the same bug using android ndk-r7
Yassine

David Turner

unread,
Nov 14, 2011, 6:06:19 AM11/14/11
to andro...@googlegroups.com
On Sun, Nov 13, 2011 at 10:41 PM, yostane <yassine....@gmail.com> wrote:
Hi, I am getting the same bug using android ndk-r7
Yassine

That's because the fix is in the platform, not the NDK. As Brad said, uninstalling applications can solve the problem.

barney williams

unread,
Feb 2, 2012, 4:01:43 PM2/2/12
to andro...@googlegroups.com
Hi All,

I am having the same problem (package is unknown) but so far I have had no luck with above fixes. I have tried with a 4 level and 3 level package name. Regarding the buffer bug when I run:

adb -d shell pm list packages -f

My package shows up so presumably all is well there? (Or is the problem when this file is being read further down the line?).

One thing that struck me as odd was that when I called the above it seems there had been a "-1" appended to my apk filename that I didn't expect i.e.

package:/data/app/<PackageName>-1.apk=<PackageName>

I get this whether package name is 3 or 4 levels deep.  I have no idea where it is coming from and more importantly if it should or shouldn't be there (i'm guessing it is fine because other apps seem to have it).

I am running this using ARM DS-5 but I get the same error running the following in cygwin (after installing just fine):

adb shell run-as <your-package-name> /system/bin/sh -c pwd 

I guess it is maybe worth pointing out that when I run through eclipse with ARM DS-5 the game actually runs but the debugger still returns the unknown package error.

My one final observation was that the apk on my local machine was name differently to the one that showed up in the package list, again this seemd a bit odd e.g.

The result of printing the package list:

package:/data/app/com.mygames.firstgame-1.apk=com.mygames.firstgame

package on local machine:

FirstGame.apk

Sorry if that is a bit garbled, I have been banging my head against this for ages - any help would be much appreciated.

Barney

barney williams

unread,
Feb 14, 2012, 4:25:29 AM2/14/12
to android-ndk
For the benefit of anyone else stumbling upon this my problem was
indeed the truncation of packages.list. I had to root the phone so
that I could pull packages.list, move my package to the top of the
file and then push it back onto the phone (this is where I needed to
su so that I could give myself write access to the file).
Unfortunately the adb install command will rewrite this list and reset
the file permissions on packages.list* although I am assuming that
once you have done it once and your apk is added to packages.list an
adb push would work (I haven't got round to it yet) - I don't know if
adb install does anything more than copy the files and write to
packages.list?


*The ADT plugin will do the same if you are running through Eclipse.

gadget

unread,
Oct 24, 2012, 7:19:17 PM10/24/12
to andro...@googlegroups.com
barney williams -- big thanks, worked perfectly
Reply all
Reply to author
Forward
0 new messages