I followed this description for debugging native code in an Android app and it works when debugging on the emulator.
When I want to debug on the actual device, at the point where I switch to the C/C++ debug configuration, Eclipse reports "Remote communication error: Bad file descriptor.". Apparently there's a problem reaching GdbServer (I guess). I suppose all that's missing is a small tweak to the debug configuration. Unfortunately, I don't yet really understand how the whole setup works, so I'm unable to pinpoint/solve the problem. Any help would really be appreciated.
Assuming you're on an ARM Android, you may have better luck with the free ARM-supplied Android debugger: http://ds.arm.com/ds-5-community-edition/
You can get that error if you don't run ndk-gdb to start gdbserver on the device. Here a link to an explaination of how the android remote debugging works: http://mhandroid.wordpress.com/2011/01/25/how-cc-debugging-works-on-android/
Related
I'm interested in learning about the Android runtime (ART) and I'd like to be able to put a debugger on it so I can step through the code. I have an AOSP build that I've been running on an emulator.
What's the best way to attach and run source? Should I just use gdbserver on the emulator? Are there any IDEs that people use for native debugging?
Looks like you figured this out, but just for completeness, here's a link to some official documentation which basically covers what you said: http://source.android.com/devices/tech/debug/index.html
If you want to debug native code, you're going to need the source, which of course means getting the AOSP. After you've setup the AOSP, do the following:
In your AOSP directory, run "choosecombo". Select "debug" and pick an "eng" build of your choice.
Build the AOSP
Start the emulator (ie: on Linux, "emulator &")
adb shell into the emulator and run "setprop debug.db.uid 32767". This prevents debuggerd from attaching to a process that it thinks has halted and causing problems. See system/core/debuggerd/debuggerd.cpp in the AOSP for more info.
In the same shell that you built the AOSP, run "gdbclient [process name]". This will attach and load the debugging information for the process you are interested in. You can also attach to a pid, but you will end up having to load the symbol information yourself.
Enjoy debugging native Android platform code
Ok.
So while this isnt a programming question.
I wanted to know how do people debug apps?
How do you view log cat, and where these exceptions are thrown etc?
And do I need to run the app on the emulator to see all the stuff, or is there a way to view this after running the app on my phone(while not being connected to the computer)
Links to plugins and tips would be really helpful, as im gonna start work on my next game, and while the first one works fine, had a lot of problems while debugging.
Setup: download the Android Developer Tools (ADT) plugin for Eclipse from here http://developer.android.com/tools/index.html
To debug:
Connect your phone to PC via USB
Open Eclipse, set breakpoints
wherever you need
Run -> Debug to relaunch your app in debug mode
Use the Debug perspective, see:
http://developer.android.com/tools/debugging/debugging-projects.html
I am trying to debug a mixed code on Android (Java/C/C++). My target device is Vizio 1008. The code runs on the emulator and I can debug it from Eclipse using GDB. However, I cannot do this on the real device.
After days of struggling with this I localized the problem:
When GDBSERVER starts on the device (successfully), it immediately quits with the message:
"Unknown register d0 requested". Therefore, no debugging session is possible. I also tried DS-5 debugger from ARM. GDBSERVER stays connected, but exits on the connection attempt from the remote debugger. I tried GDBSERVER debug output, but it does not provide any useful info.
Even more strange, I tried any version of GDBSERVER I could get, and all of them behave like this. However, I found GDBSERVER from one of old versions of Google NDK (3 or 4 versions back). And this version WORKS!!! But, the debugger (on the host) dies very soon (segmentation fault), even I know that program is OK.
I looked at GDBSERVER source code, and, as it looks like, this error relates to the startup sequence, when GDBSERVER inspects the hardware. Probably, it relates to floating point co-processor, but I am not sure, as this error message is pretty generic.
If it matters, I am devloping on Windows using Google NDK. The code is 99% C/C++ with Java shell and a few functions implemented in Java (threaded HTTP calls). Again, the application works on the device and can be debugged (both Java and C/C++) on the emulator. I also can debug Java portion on the device.
Does anybogy know what it could be? And how to fix that? Is it Vizio?
Thank you in advance.
Sounds similar to a problem i encountered trying to do native debugging. The problem was that the arm processor used in the device supported both the vfp/neon instruction set as well as the iwmmx instruction set and appearantly gdbserver assumes the two are mutually exclusive.
To fix you'll need to mess with the gdbserver source unfortunately. Following is a fix from link. You'll need to edit the file linux-arm-low.c in the gdbserver source tree:
static void
arm_arch_setup (void)
{
arm_hwcap = 0;
if (arm_get_hwcap (&arm_hwcap) == 0)
{
init_registers_arm ();
return;
}
/* gdbserver assumes that only one of VFP or IWMMXT is available, which may
not be true. In that case, gdbserver fails at run-time with "Unknown
register d0 requested". For now, pretend IWMMXT is missing when both are
available. */
if ((arm_hwcap & HWCAP_VFP) && (arm_hwcap & HWCAP_IWMMXT))
arm_hwcap &= ~HWCAP_IWMMXT;
The exact location of where you have to change the code depends on the gdb(server) version though. I know for a fact it is slightly different in the case of gdb 7.7. After you changed it this way you should build it with gcc from the ndk, so it gets linked against bionic and stuff. I do not have exact instructions for that, because I didn't do it myself.
I should stress that this is ultimately more of a workaround than a proper fix. I do not know how gdbserver patched this way behaves when running code that actually contains iwmmx instructions. At least you'll probably not be able to get register dumps of iwmmx registers.
I've managed to build the Debug Configuration that targets remote client using GDB. This was done as per the Android NDK Sequoyah's plugin documentation.
After a few hours of tinkering I was able to get Eclipse to connect to the gdbserver on the device and see its crash through the console (verifying its connected).
But the problem is eclipse doesn't really do anything when it does. No stack trace, no highlighted problem code, nothing!
If anyone has any pointers on this I would greatly appreciate it.
Thanks,
Kevin
I managed to get this working by using OS X instead of Fedora. Probably not a real answer though.
I am in a desperate situation.
I am developing an Android application using the ADT in Eclipse on Ubuntu 10.04 on a netbook.
Unfortunately the netbook is not powerful enough to run the Device Emulator (when I try there are always issues). Then, I tried to debug on-device, but unfortunately my phone (Pulse) seems to have some problem.
It seems I can't debug. I have already spent hours trying to get that working. And I can't afford to upgrade my netbook/mobile now.
The only thing I can do is developing on Eclipse and run the application on the phone.
Is there any way I can debug while the application is running on my phone? Can I create somewhere a log with errors/warnings and even some custom messages I put in the code?
What a situation.
Any help would be appreciated.
Thanks,
Dan
On device debugging should work. Make sure you have android:debuggable="true" in your application manifest. I previously had debugging issues that fixed themselves after rebooting the device.
Alternately, you can use the Log class to print out log messages. These can be seen by running adb logcat or in the logcat view of Eclipse.
Edit:
It seems that on some devices you have to run echo 1 > /sys/kernel/logger/log_main/enable from adb shell to enable logging.
You can debug an android application directly through a tool named DDMS included in the SDK. With Eclipse the plugin intgrates everything for you: just create a breakpoint on the line you want to stop to by double-clicking in the margin, then hit the 'debug' button (the little bug at the top of the window). The program will start on the device and the device will display a message 'waiting for debugger to attach'. The message should disappear within a few seconds and will stop at the line you put the breakpoint on.
As for create logs, you can use the android.util.Log class:
import android.util.Log;
...
Log.e("MYAPPLICATION", "my message");
This should show in the "Logcat" view of eclipse.
I don't understand why you wouldn't be able to debug on the device. Just make sure your device is recognized by Ubuntu by following this article.