I'm trying to debug an NDK program on Android (SDK 24, NDK r12b) from macOS Sierra.
After running
ndk-gdb --verbose --force --launch
I get:
GNU gdb (GDB) 7.11
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin14.5.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
warning: Could not load shared library symbols for 142 libraries, e.g. /system/lib64/libcutils.so.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
0x0000007f93f84a20 in syscall ()
from /Applications/path/to/myproject/obj/local/arm64-v8a/system/lib64/libc.so
Then I found that no symbols are loaded at this point:
(gdb) i locals
No symbol table info available.
Then I loaded my native app's lib, set a breakpoint, and tried to continue:
(gdb) symbol-file /Applications/path/to/myproject/obj/local/arm64-v8a/libDemo.so
Reading symbols from /Applications/path/to/myproject/obj/local/arm64-v8a/libDemo.so...done.
(gdb) b MyClass::MyMethod
Breakpoint 1 at 0x158354: file jni/../../MyClasses/MyClass.cpp, line 45.
(gdb) c
Continuing.
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x158354
Command aborted.
(gdb)
From this post GDB Cannot insert breakpoint, Cannot access memory at address XXX?
I knew that this invalid memory access is because ndk-gdb cannot map the breakpoint's address. But Why? And how should I make breakpoints work?
I played around with my libs/arm64-v8a/gdb.setup and used absolute paths in there:
set sysroot
set solib-search-path /Applications/path/to/myproject/obj/local/arm64-v8a /Applications/NVPACK/ndk/platforms/android-21/arch-arm64/usr/lib
without luck.