Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDB 7.10 from NDK r11b is not working on OS X/Windows #53

Closed
dosvidos opened this issue Mar 29, 2016 · 12 comments
Closed

GDB 7.10 from NDK r11b is not working on OS X/Windows #53

dosvidos opened this issue Mar 29, 2016 · 12 comments
Assignees
Milestone

Comments

@dosvidos
Copy link

I've tried to use the GDB 7.10 directly without ndk-gdb.py helper script, but it's not working as expected.
My test device is Nexus 5 running API 23 with latest OTA updates.
Here's the reproduction steps:

  1. Download NDK sample 'native-activity' from 'android-mk' branch at revision android/ndk-samples@b4700b9
  2. Build it with android-ndk-r11b/ndk-build V=1 NDK_DEBUG=1 -B
  3. Set android:debuggable attribute in AndroidManifest.xml
    <application android:debuggable="true" android:label="@string/app_name" android:hasCode="false">
  4. Build APK
  5. adb pull /system/bin local_sysroot && adb pull /system/lib local_sysroot
  6. Copy android-ndk-r11b/prebuilt/android-arm/gdbserver/ to /data/data/com.example.native_activity/gdbserver
  7. chmod 750 /data/data/com.example.native_activity/gdbserver
  8. Launch the com.example.native_activity sample
  9. adb forward tcp:5678 tcp:5678
  10. attach the gdbserver to the sample's PID
  11. run gdb
    $ANDROID_NDK_ROOT/prebuilt/darwin-x86_64/bin/gdb
    OR
    $ANDROID_NDK_ROOT/prebuilt/windows/bin/gdb
  12. set sysroot AND attach to remote target

Here's GDB 7.10 output:
OS X 10.11
(gdb) set sysroot /Users/mike/wrk/ub1404/nexus5/
(gdb) show sysroot
The current system root is "/Users/mike/wrk/ub1404/nexus5/".
(gdb) target remote :5678
Remote debugging using :5678
0xb6c93894 in ?? ()
(gdb) bt
#0 0xb6c93894 in ?? ()
#1 0xb6c6ce72 in ?? ()

Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) info thread
Id Target Id Frame
19 Thread 32420 0xb6c939bc in ?? ()
18 Thread 32076 0xb6c939bc in ?? ()
17 Thread 32044 0xb6c939bc in ?? ()
16 Thread 31805 0xb6c939bc in ?? ()
15 Thread 31784 0xb6c939bc in ?? ()
14 Thread 31525 0xb6c939bc in ?? ()
13 Thread 29778 0xb6c939bc in ?? ()
12 Thread 29770 0xb6c939bc in ?? ()
11 Thread 28441 0xb6c939bc in ?? ()
10 Thread 28440 0xb6c939bc in ?? ()
9 Thread 28433 0xb6c939bc in ?? ()
8 Thread 28432 0xb6c939bc in ?? ()
7 Thread 28431 0xb6c6a5e4 in ?? ()
6 Thread 28429 0xb6c6a5e4 in ?? ()
5 Thread 28428 0xb6c6a5e4 in ?? ()
4 Thread 28427 0xb6c6a5e4 in ?? ()
3 Thread 28426 0xb6c94948 in ?? ()
2 Thread 28417 0xb6c93b68 in ?? ()
** 1 Thread 28412 0xb6c93894 in ?? ()
(gdb) c
Continuing.
^C[New Thread 353]

Program received signal SIGINT, Interrupt.
0xb6c93894 in ?? ()
(gdb) info dll
No shared libraries loaded at this time.
Windows 7
(gdb) set sysroot /z/wrk/ub1404/nexus5/
(gdb) target remote :5678
Remote debugging using :5678
0xb6c93894 in ?? ()
(gdb) info thread
Id Target Id Frame
22 Thread 1202 0xb6c939bc in ?? ()
21 Thread 459 0xb6c939bc in ?? ()
20 Thread 353 0xb6c939bc in ?? ()
19 Thread 32420 0xb6c939bc in ?? ()
18 Thread 32076 0xb6c939bc in ?? ()
17 Thread 32044 0xb6c939bc in ?? ()
16 Thread 31805 0xb6c939bc in ?? ()
15 Thread 31784 0xb6c939bc in ?? ()
14 Thread 31525 0xb6c939bc in ?? ()
13 Thread 29778 0xb6c6a5e4 in ?? ()
12 Thread 29770 0xb6c939bc in ?? ()
11 Thread 28441 0xb6c6a5e4 in ?? ()
10 Thread 28440 0xb6c939bc in ?? ()
9 Thread 28433 0xb6c939bc in ?? ()
8 Thread 28432 0xb6c939bc in ?? ()
7 Thread 28431 0xb6c6a5e4 in ?? ()
6 Thread 28429 0xb6c6a5e4 in ?? ()
5 Thread 28428 0xb6c6a5e4 in ?? ()
4 Thread 28427 0xb6c6a5e4 in ?? ()
3 Thread 28426 0xb6c94948 in ?? ()
2 Thread 28417 0xb6c93b68 in ?? ()
** 1 Thread 28412 0xb6c93894 in ?? ()
(gdb) info dll
No shared libraries loaded at this time.
(gdb) info target
Symbols from "Z:\wrk\ub1404\nexus5\system\bin\app_process32".
Remote serial target in gdb-specific protocol:
Debugging a target over a serial line.
While running this, GDB does not access memory from...
Local exec file:
`Z:\wrk\ub1404\nexus5\system\bin\app_process32',
file type elf32-littlearm.
Entry point: 0x1808
0x00000154 - 0x00000167 is .interp
0x00000168 - 0x00000180 is .note.android.ident
0x00000180 - 0x000001a0 is .note.gnu.build-id
0x000001a0 - 0x00000670 is .dynsym
0x00000670 - 0x00000ce8 is .dynstr
0x00000ce8 - 0x00000d44 is .gnu.hash
0x00000d44 - 0x00000dde is .gnu.version
0x00000de0 - 0x00000e30 is .gnu.version_r
0x00000e30 - 0x00000f80 is .rel.dyn
0x00000f80 - 0x00001170 is .rel.plt
0x00001170 - 0x0000146c is .plt
0x0000146c - 0x0000388c is .text
0x0000388c - 0x00003a64 is .ARM.exidx
0x00003a64 - 0x00003aac is .ARM.extab
0x00003ab0 - 0x00004590 is .rodata
0x00005cd8 - 0x00005d40 is .data.rel.ro.local
0x00005d40 - 0x00005d48 is .preinit_array
0x00005d48 - 0x00005d54 is .init_array
0x00005d54 - 0x00005d5c is .fini_array
0x00005d60 - 0x00005d88 is .data.rel.ro
0x00005d88 - 0x00005ed0 is .dynamic
0x00005ed0 - 0x00006000 is .got
0x00006000 - 0x00006629 is .bss
(gdb) c
Continuing.
[New Thread 1578]
Program received signal SIGINT, Interrupt.
0xb6c93894 in ?? ()
(gdb) bt
#0 0xb6c93894 in ?? ()
#1 0xb6c6ce72 in ?? ()

Backtrace stopped: previous frame identical to this frame (corrupt stack?)

On Linux GDB 7.10 is able to load the symbols for the shared libraries and display the correct thread stacks:
(gdb) bt
#0 0xb6c93894 in epoll_pwait () from /vagrant/nexus5/system/lib/libc.so
#1 0xb6c6ce72 in epoll_pwait () from /vagrant/nexus5/system/lib/libc.so
#2 0xb6c6ce80 in epoll_wait () from /vagrant/nexus5/system/lib/libc.so
#3 0xb6ebfc5a in android::Looper::pollInner(int) () from /vagrant/nexus5/system/lib/libutils.so
#4 0xb6ebfed6 in android::Looper::pollOnce(int, int
, int
, void**) () from /vagrant/nexus5/system/lib/libutils.so
#5 0xb6e04ce4 in android::NativeMessageQueue::pollOnce(JNIEnv, jobject, int) ()

from /vagrant/nexus5/system/lib/libandroid_runtime.so
#6 0x7389656e in ?? ()

Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) c
Continuing.
[New Thread 32044]
^C
Program received signal SIGINT, Interrupt.
0xb6c93894 in __epoll_pwait () from /vagrant/nexus5/system/lib/libc.so

@DanAlbert
Copy link
Member

@jmgao: is this one of the issues you've already fixed for r11c?

@jmgao
Copy link
Contributor

jmgao commented Mar 29, 2016

@jmgao: is this one of the issues you've already fixed for r11c?

No, because they're not using ndk-gdb.py, but it might be related:

I've tried to use the GDB 7.10 directly without ndk-gdb.py helper script, but it's not working as expected.

Do you see warning messages similar to the following?

warning: A handler for the OS ABI "Cygwin" is not built into this configuration
of GDB. Attempting to continue with the default aarch64 settings.

If so, the problem is probably that gdbserver isn't sending the GNU/Linux osabi to gdb. Try using set osabi GNU/Linux before target remote.

@jmgao jmgao added this to the r12 milestone Mar 29, 2016
@jmgao
Copy link
Contributor

jmgao commented Mar 29, 2016

Marking as r12 for the gdb fix (assuming that that's the problem)

@DanAlbert
Copy link
Member

Oh, I read that as the opposite of what it said. Never mind :)

@dosvidos
Copy link
Author

@jmgao Thanks a lot, set osabi GNU/Linux command solved the problem for OS X\Windows.
On Windows, gdb outputs the following:

warning: Architecture rejected target-supplied description
warning: A handler for the OS ABI "Cygwin" is not built into this configuration
of GDB. Attempting to continue with the default arm settings.

@alessandro-micaglio
Copy link

Hi all,

I follow the official NDK link [ e.g. for MacOs http://dl.google.com/android/repository/android-ndk-r11b-darwin-x86_64.zip ]. Unzip the package. In toolchains sub-folders arm-linux-androideabi-4.9 (the same thing for the other toolchains), the file arm-linux-androideabi-gdb does not exist. The complete path of this tool should be something like: [ NDK_DIR/android-ndk-r11b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gdb ]

Obviously this raises the big issue that is impossible to debug native apps for example via QtCreator that by default tries to load arm-linux-androideabi-gdb when debugging started.

I verify this issue on MacOs, Win8 and Linux.

@jmgao
Copy link
Contributor

jmgao commented Mar 30, 2016

On Windows, gdb outputs the following:

Did you run it before connecting?

Unzip the package. In toolchains sub-folders arm-linux-androideabi-4.9 (the same thing for the other toolchains), the file arm-linux-androideabi-gdb does not exist.

http://stackoverflow.com/questions/36182528/android-ndk-why-arm-linux-androideabi-gdb-exe-disappeared/36203063#36203063

@DanAlbert
Copy link
Member

Unzip the package. In toolchains sub-folders arm-linux-androideabi-4.9 (the same thing for the other toolchains), the file arm-linux-androideabi-gdb does not exist.

http://stackoverflow.com/questions/36182528/android-ndk-why-arm-linux-androideabi-gdb-exe-disappeared/36203063#36203063

Also #35

@dosvidos
Copy link
Author

@jmgao

Did you run it before connecting?

Sure, I've launched the main activity from com.example.native_activity on a target device, then attached to PID via gdbserver and connected from a host GDB by target remote :port

@jmgao
Copy link
Contributor

jmgao commented Mar 30, 2016

Sorry, I meant did you use set osabi GNU/Linux before connecting?

On Wed, Mar 30, 2016, 12:10 PM Mikhail [email protected] wrote:

@jmgao https://github.com/jmgao

Did you run it before connecting?

Sure, I've launched the main activity from com.example.native_activity on
a target device, then attached to PID via gdbserver and connected from a
host GDB by target remote :port


You are receiving this because you were mentioned.

Reply to this email directly or view it on GitHub
#53 (comment)

@dosvidos
Copy link
Author

@jmgao

Sorry, I meant did you use set osabi GNU/Linux before connecting?

I did that, and after connecting to remote target GDB works like it should.

@jmgao
Copy link
Contributor

jmgao commented Apr 11, 2016

Fixed in r11c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants