any good approaches to debug the service in system_server?

2,125 views
Skip to first unread message

Chen Yang

unread,
Apr 3, 2009, 8:29:40 AM4/3/09
to android-...@googlegroups.com
I don't know whether this is the right forum for this thread. I am
interested to know how to debug those services in system server, are
there some known good approaches? Thanks.
--
Chen

Freepine

unread,
Apr 3, 2009, 10:38:06 AM4/3/09
to android-...@googlegroups.com
You can use gdb to debug it as for other native processes:
1. connect to the device or emulator with adb shell
2. launch gdbserver to listen on a port and attach to system_server's PID
3. setup gdb from your workstation to debug the target process on device remotely, like setting up port forwarding, specifying target executable, loading symbol files, etc. You can leverage gdbclient defined in build/envsetup.sh or use arm-eabi-gdb directly, note that system server's exe is not system/bin/system_server, but system/bin/app_process.
4. switch to the corresponding thread which holds your interested service with system server process.
(gdb) info threads
(gdb) thread <thread_id>
(gdb) bt
(gdb) ...

Chen Yang

unread,
Apr 3, 2009, 7:55:32 PM4/3/09
to android-...@googlegroups.com
Thanks a lot, for service in native, it works.
Since a lot of services are in managed code, is it possible to use
Eclipse to debug?
Thanks.
--
Chen

Dianne Hackborn

unread,
Apr 3, 2009, 7:59:42 PM4/3/09
to android-...@googlegroups.com
Just select the process in ddms, and connect eclipse's debugger to the port ddms tells you it is using.
--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Chen Yang

unread,
Apr 3, 2009, 10:49:51 PM4/3/09
to android-...@googlegroups.com
I am using kvm with x86 port, thus I guess that there may be some
issues with current prebuilt toolchain.
Can the prebuilt arm gdb show correct results with info threads?
On x86, it shows only the attached main thread, no other threads,
neither switchable.
Thanks.
--
Chen

On Fri, Apr 3, 2009 at 10:38 PM, Freepine <free...@gmail.com> wrote:

Chen Yang

unread,
Apr 3, 2009, 11:02:43 PM4/3/09
to android-...@googlegroups.com
Dianne:
Thanks a lot for your helpful information.
I am new to use Eclipse, thus I don't know whether i have followed
your suggestion correctly. I can see that the system_server in the
ddms as 8700, and then i chose remote java application and specify
that port in it, by associating it to one active project, ddms does
show system_server is being debugged. But I am not so sure of whether
it is the right step. Meanwhile, in order to use the most updated
code, I assume that I may need to recompile the android.jar and those
images. Am I right?
In eclipse's DDMS pane, when i click on the system_server to be
debugged, it say, "no opened project found for system_process", what's
the right project for that particular process?
Thanks.
--
Chen

Freepine

unread,
Apr 4, 2009, 12:18:05 AM4/4/09
to android-...@googlegroups.com
Yes, it works with the prebuilt arm gdb, but I didn't have the experience of porting it to x86.

BTW, did you specify the correct executable of system server? It's not system/bin/system_server, though it looks like to be. 
You can try ls -l /proc/<pid>/exe to double check it.

Dianne Hackborn

unread,
Apr 4, 2009, 12:36:09 AM4/4/09
to android-...@googlegroups.com
That sounds correct.  Sorry I am not an eclipse effort so can't help you much there more than that.  You should be able to put breakpoints at that point -- for example you could put a breakpoint in the WindowManagerService add window function and see it stopped when an application displays a window.

You definitely want to have source the matches the build you are running.

Chen Yang

unread,
Apr 4, 2009, 3:37:35 AM4/4/09
to android-...@googlegroups.com
Thanks. It seems that the problem is from the gdbserver.
Is there some explanation on compiling a working gdbserver for android
target? Thanks.
--
Chen

fadden

unread,
Apr 6, 2009, 4:38:36 PM4/6/09
to android-platform
On Apr 4, 12:37 am, Chen Yang <sunsety...@gmail.com> wrote:
> Thanks. It seems that the problem is from the gdbserver.
> Is there some explanation on compiling a working gdbserver for android
> target? Thanks.

An ARM gdbserver is part of the prebuilt binaries. It was omitted
from 1.0, but is now part of the open-source tree:

http://android.git.kernel.org/?p=platform/prebuilt.git;a=tree;f=android-arm/gdbserver;h=275503d08f4d2c759f41480cd2d34b946a699ff6;hb=HEAD

Chen Yang

unread,
Apr 6, 2009, 8:39:16 PM4/6/09
to android-...@googlegroups.com
fadden:
Thanks a lot!
But it only contains the prebuilt binary, no source and explanation
on how to build it. I am interested to build a working gdbserver for
x86. Thanks.
--
Chen

fadden

unread,
Apr 7, 2009, 2:29:32 PM4/7/09
to android-platform
On Apr 6, 5:39 pm, Chen Yang <sunsety...@gmail.com> wrote:
>   But it only contains the prebuilt binary, no source and explanation
> on how to build it. I am interested to build a working gdbserver for
> x86. Thanks.

The README there refers to another README, which refers to an
android_setup.sh, which does all sorts of stuff to set up the ARM
cross-compile environment. The instructions are:

$ . android_setup.sh
$ cd gdb-6.6/gdb/gdbserver
$ ./configure --target=arm-elf-linux --host=i386
$ make
$ arm-eabi-strip gdbserver

If you're building for x86 on x86, you shouldn't need the cross-build
stuff.

Chen Yang

unread,
Apr 8, 2009, 2:52:24 AM4/8/09
to android-...@googlegroups.com
fadden:
Thanks a lot!
It seems that android_setup.sh doesn't exist in android open source project.
I may be wrong, but from the prebuilt arm gdbserver, it is
statcally linked, your description doesn't reflect that.
I may have made some progress, i have tried to static linked with
the libthread_db in bionic, but it reports issues during runtime:
gdb: Unable to get location for thread creation breakpoint:
requested event is not supported
Thanks.
--
Chen

Androidphan

unread,
Apr 10, 2009, 8:12:54 AM4/10/09
to android-platform
I have got the same problem with debugging in Eclipse. If I try to
attach ddms inside Eclipse to a process, I'm getting the error: No
opened project found for com.android.browser. Debug session failed!

How can I open that project to debug it? Or what other can I use to
debug for example the Browser?

Chen Yang

unread,
Apr 15, 2009, 9:37:59 AM4/15/09
to android-...@googlegroups.com
Some one can help? Thanks.
--
Chen

joel

unread,
May 20, 2009, 1:10:55 PM5/20/09
to android-platform
You need to create an Android project (if you don't have one already),
and in your AndroidManifest.xml, change the package name to
"com.android.browser" or "system_process" or whatever as the case may
be.
Reply all
Reply to author
Forward
0 new messages