我正在尝试从macOS Sierra调试Android上的NDK程序(SDK 24,NDK r12b)。
运行后
ndk-gdb --verbose --force --launch
我明白了:
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
然后我发现此时没有加载任何符号:
(gdb) i locals
No symbol table info available.
然后我加载了我的原生应用程序的lib,设置断点,并尝试继续:
(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)
从这篇文章 GDB Cannot insert breakpoint, Cannot access memory at address XXX?
我知道这种无效的内存访问是因为ndk-gdb无法映射断点的地址。 但为什么?我该如何让断点起作用呢?
我玩了我的libs / arm64-v8a / gdb.setup并在那里使用了绝对路径:
set sysroot
set solib-search-path /Applications/path/to/myproject/obj/local/arm64-v8a /Applications/NVPACK/ndk/platforms/android-21/arch-arm64/usr/lib
没有运气。