-
Notifications
You must be signed in to change notification settings - Fork 258
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
SIGSEGV or SIGBUS while returning from native method under gdbserver #628
Comments
The instructions weren't completely clear to me. When I set a breakpoint on second.c:27, the app is already loaded, and its activity has already called I managed to reproduce the segfault anyway by moving the call into an |
The I use The |
seems like an ART bug?
|
I managed to call add by rotating the phone :-). And yes, enforcing Thumb before finish helps me to prevent SIGSEGV as well. Nice. |
The Nonetheless, I guess the gdb can not find the proper function name, so it just uses any previous symbol as the reference point. Is there .gnu_debugdata in the ELF file? (that should generally contain the compressed proper symbols) |
base.odex looks stripped:
libtwolib-second.so isn't stripped, but there is no .gnu_debugdata section:
|
When gdb's Maybe gdb should ignore data symbols. If I made that change, I think gdb would fall back to the detected ARM/Thumb mode of the "current frame". That'll work as long as every function is Thumb. If a file has ARM mapping symbols ( I don't see a
I see that LLDB knows about oat files. It looks for the |
I had come up with a hack that worked around this issue: https://android-review.googlesource.com/c/toolchain/gdb/+/602241. I'm not sure it's a good idea. IIRC, gdb seemed to think |
Sounds like the non-hack fix would be a more invasive gdb change. Given that this already works in lldb, I think our answer for a Java interoperable debugger should just be to use lldb. Related to that, @dantipov (and others): would including lldb directly in the NDK and adding ndk-gdb support for it help you? aiui it isn't actually that much work for us to get lldb into the NDK proper now, we're just unsure of the value since we don't have a good idea of how many people use the NDK in absence of the rest of the SDK. |
PS: Is this reproducible in recent aosp builds? (I made the symbol size 0 - aka unknown). |
Thanks for letting me know. When I last looked at this, in this situation, I think the only information gdb had about addresses in the Maybe there's other some other debug/symbol information gdb would or could find, though. I'd have to retest. |
I retested with a recent P build, and the size of the |
An application’s process execution is terminated with SIGBUS or SIGSEGV when control flow returns from a JNI method call that is defined in an ARM v7 ELF module if the application is run under prebuilt/android-arm/gdbserver/gdbserver from NDK r16b.
This behavior is observed on Nexus 6P and Pixel XL devices running Android 8.1 January 5 OTA security update.
The bug seems to be ARMv7-specific, as ARMv8 build of the sample works fine then it’s debugged by the same GDB/gdbserver combo.
On target, gdbserver startup command line is:
$ run-as com.example.twolibs /data/data/com.example.twolibs/gdbserver --attach tcp:9999 [pid]
On host, debugging session is:
$ /home/dantipov/android/android-ndk-r16b/prebuilt/linux-x86_64/bin/gdb -q
(gdb) target extended-remote :9999
Remote debugging using :9999
Reading /system/bin/app_process32 from remote target...
[...a lot of library transfer...]
(gdb) info dll
From To Syms Read Shared Object Library
0xf2647fa0 0xf26bbb40 Yes () target:/system/bin/linker
...
[...a lot of libraries shown...]
0xd53ea698 0xd53eb576 Yes () target:/data/app/com.example.twolibs-vArWzXBjlMD4efey3B7_-w==/lib/arm/libtwolib-second.so
(gdb) add-symbol-file /tmp/libtwolib-second.so 0xd53ea698
add symbol table from file "/tmp/libtwolib-second.so" at
.text_addr = 0xd53ea698
(y or n) y
Reading symbols from /tmp/libtwolib-second.so...done.
(gdb) b second.c:27
Breakpoint 1 at 0xd53ea712: file /home/dantipov/android/twolibs/app/src/main/cpp/second.c, line 27.
(gdb) c
Continuing.
Thread 1 "example.twolibs" hit Breakpoint 1, Java_com_example_twolibs_TwoLibs_add (env=0xeee312a0, this=0xffc7c0ac, x=1000, y=42)
at /home/dantipov/android/twolibs/app/src/main/cpp/second.c:27
27 return first(x, y);
(gdb) finish
Run till exit from #0 Java_com_example_twolibs_TwoLibs_add (env=0xeee312a0, this=0xffc7c0ac, x=1000, y=42) at /home/dantipov/android/twolibs/app/src/main/cpp/second.c:27
Thread 1 "example.twolibs" received signal SIGSEGV, Segmentation fault.
0xd5599052 in oatexec () from target:/data/app/com.example.twolibs-vArWzXBjlMD4efey3B7_-w==/oat/arm/base.odex
(gdb) bt
#0 0xd5599052 in oatexec () from target:/data/app/com.example.twolibs-vArWzXBjlMD4efey3B7_-w==/oat/arm/base.odex
#1 0x00000000 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) set arm force-mode thumb
(gdb) disassemble
Dump of assembler code for function oatexec:
0xd5599000 <+0>: movs r0, r0
0xd5599002 <+2>: movs r0, r0
0xd5599004 <+4>: movs r0, r0
0xd5599006 <+6>: movs r0, r0
0xd5599008 <+8>: lsls r0, r0, #2
0xd559900a <+10>: movs r0, r0
0xd559900c <+12>: ldr r5, [pc, #896] ; (0xd5599390)
0xd559900e <+14>: movs r0, r0
0xd5599010 <+16>: movs r0, r0
0xd5599012 <+18>: vaddl.u<illegal width 64> q8, d31, d4
0xd5599016 <+22>: movs r0, r0
0xd5599018 <+24>: stmdb sp!, {r5, r6, r7, r8, r10, r11, lr}
0xd559901c <+28>: vpush {s16-s31}
0xd5599020 <+32>: sub sp, #36 ; 0x24
0xd5599022 <+34>: str r0, [sp, #0]
0xd5599024 <+36>: str r1, [sp, #132] ; 0x84
0xd5599026 <+38>: str r2, [sp, #136] ; 0x88
0xd5599028 <+40>: str r3, [sp, #140] ; 0x8c
0xd559902a <+42>: mov.w r12, #1
0xd559902e <+46>: str.w r12, [sp, #8]
0xd5599032 <+50>: ldr.w r12, [r9, #204] ; 0xcc
0xd5599036 <+54>: str.w r12, [sp, #4]
0xd559903a <+58>: add.w r12, sp, #4
0xd559903e <+62>: str.w r12, [r9, #204] ; 0xcc
0xd5599042 <+66>: ldr.w r12, [sp, #132] ; 0x84
0xd5599046 <+70>: str.w r12, [sp, #12]
0xd559904a <+74>: str.w sp, [r9, #148] ; 0x94
0xd559904e <+78>: mov r0, r9
0xd5599050 <+80>: ldr.w r12, [r0, #460] ; 0x1cc
0xd5599054 <+84>: blx r12
0xd5599056 <+86>: str r0, [sp, #16]
0xd5599058 <+88>: ldr r3, [sp, #140] ; 0x8c
0xd559905a <+90>: ldr r2, [sp, #136] ; 0x88
0xd559905c <+92>: add r1, sp, #12
0xd559905e <+94>: ldr.w r0, [r9, #164] ; 0xa4
0xd5599062 <+98>: ldr.w r12, [sp]
0xd5599066 <+102>: ldr.w r12, [r12, #24]
0xd559906a <+106>: blx r12
0xd559906c <+108>: str r0, [sp, #20]
0xd559906e <+110>: ldr r0, [sp, #16]
0xd5599070 <+112>: mov r1, r9
0xd5599072 <+114>: ldr.w r12, [r1, #472] ; 0x1d8
0xd5599076 <+118>: blx r12
0xd5599078 <+120>: ldr r0, [sp, #20]
0xd559907a <+122>: ldr.w r12, [r9, #140] ; 0x8c
0xd559907e <+126>: cmp.w r12, #0
0xd5599082 <+130>: bne.n 0xd5599094 <oatexec+148>
0xd5599084 <+132>: add sp, #36 ; 0x24
0xd5599086 <+134>: vpop {s16-s31}
0xd559908a <+138>: ldmia.w sp!, {r5, r6, r7, r8, r10, r11, lr}
0xd559908e <+142>: ldr.w r8, [r9, #52] ; 0x34
0xd5599092 <+146>: bx lr
0xd5599094 <+148>: mov r0, r12
0xd5599096 <+150>: ldr.w r12, [r9, #704] ; 0x2c0
0xd559909a <+2>: blx r12
End of assembler dump.
getprop.txt
twolibs.zip
The text was updated successfully, but these errors were encountered: