gdbserver can't attach: strange pid

712 views
Skip to first unread message

Dmitry Moskalchuk

unread,
Oct 30, 2010, 10:06:31 AM10/30/10
to andro...@googlegroups.com
Hi,

Today I've tried to debug hello-jni application using ndk-gdb from
android-ndk-r4b. Application run on device and in terminal I got gdb
command line. Well, I type 'info threads' there and got error. This is
known problem with gdbserver in latest NDK (it's built without thread
support). Then, I got prebuilt gdbserver binary from AOSP build system
(http://android.git.kernel.org/?p=platform/prebuilt.git;a=blob_plain;f=android-arm/gdbserver/gdbserver;hb=HEAD)
and put it instead of original one. This new gdbserver has thread
support. Then I ran ndk-gdb again and got strange error:

Attached; pid = 604
Listening on sockaddr socket debug-socket
Cannot attach to process 606: Operation not permitted (1)

Look, here 604 is pid of process started. But what is 606? I didn't
found other process with the same pid. Looks like it fork or smth like.
When I modify ndk-gdb in a way not use run-as feature but run gdbserver
directly, all works fine. Can anyone explain what's wrong with run-as?
And, another question, this approach with direct running gdbserver -
will it work on non-rooted devices? I believe no but I can't check. At
least it works fine on emulator and on both my devices (but they're
rooted already).

--
Dmitry Moskalchuk

Dmitry Moskalchuk

unread,
Oct 30, 2010, 2:34:41 PM10/30/10
to andro...@googlegroups.com
Looking further, I've figured out that actual error comes from call
td_ta_thr_iter located in thread-db.c (gdbserver folder). Don't see into
td_ta_thr_iter yet (it is not in toolchain sources, it related to AOSP
itself) but looks like iterating over threads this function take each
thread and try to attach to it (you know, threads and processes don't
actually differ in linux kernel). And yes, it fails on some thread which
has other owner-id. This explain why it work when I modify ndk-gdb in
order to use direct gdbserver instead of run-as - in this case gdbserver
run with root id. 'run-as' run with root id too but first thing which it
do is switch to another user- and group-id.

So that's it - if I fix threading problem, it completely break debugging
on non-rooted devices; but without fix debugging of multi-threaded
application is not possible at all, on all devices (no matter rooted or
no) and emulator.

I don't have idea how to fix it without breaking debugging on non-rooted
devices. If anybody from Google (David? Dianne?) can respond me on that,
it'll be great.


Dmitry Moskalchuk

Reply all
Reply to author
Forward
0 new messages