Linux gdb赢得';加载核心文件时,不要加载共享libs符号,甚至不要加载libc.so(musl)

Linux gdb赢得';加载核心文件时,不要加载共享libs符号,甚至不要加载libc.so(musl),linux,debugging,gdb,mips,musl,Linux,Debugging,Gdb,Mips,Musl,我正在尝试调试一个程序,该程序使用MIPS cpu在一块板上远程运行,并将musl用于其libc。 如果我在主板上启动gdbserver,通过set sysroot/path/to/sysroot设置sysroot并从gdb实时连接,我会得到一个有意义的堆栈跟踪(由于musl在MIPS上缺少CFI指令,我不得不添加它们,这需要花费数小时的努力,但这是一个单独的问题),我可以看到gdb从libc.so从sysroot加载符号 另一方面,如果我让该程序崩溃并生成一个核心转储(我使用kill-6强制一

我正在尝试调试一个程序,该程序使用MIPS cpu在一块板上远程运行,并将musl用于其libc。 如果我在主板上启动gdbserver,通过
set sysroot/path/to/sysroot
设置sysroot并从gdb实时连接,我会得到一个有意义的堆栈跟踪(由于musl在MIPS上缺少CFI指令,我不得不添加它们,这需要花费数小时的努力,但这是一个单独的问题),我可以看到gdb从
libc.so
从sysroot加载符号

另一方面,如果我让该程序崩溃并生成一个核心转储(我使用
kill-6
强制一个进行测试),gdb将从二进制文件加载符号,但不会加载其任何共享库,甚至不会加载
libc.so
。虽然其他共享lib很好,但不是必需的,没有libc.so的调试信息,gdb无法解析堆栈跟踪,它们看起来都像垃圾

成功的实时gdb会话
$mipsel poky linux gdb-iex“设置sysroot/path/to/sysroot”/path/to/testprog
GNU gdb(gdb)8.2.1
版权所有(C)2018免费软件基金会。
许可证GPLv3+:GNU GPL版本3或更高版本
这是自由软件:您可以自由更改和重新发布它。
在法律允许的范围内,不存在任何担保。
有关详细信息,请键入“显示复制”和“显示保修”。
此GDB配置为“-host=x86_64-pokysdk-linux--target=mipsel-poky-linux”。
键入“显示配置”以获取配置详细信息。
有关错误报告说明,请参阅:
.
在线查找GDB手册和其他文档资源,网址为:
.
要获得帮助,请键入“帮助”。
键入“apropos word”以搜索与“word”相关的命令。。。
从/path/to/testprog…读取符号已完成。
(gdb)
(gdb)目标扩展远程主机名:10000
使用远程主机名进行远程调试:10000
从/path/to/sysroot/lib/ld.so.1读取符号…完成。
__位于src/thread/mips/syscall\u cp.s:38处的cp_end()
38贝基7美元,0美元,1楼
(gdb)英国电信
#src/thread/mips/syscall\u cp.s:38处的0\u cp\u end()
#系统调用中的1 0x77eff348(nr=4029,u=,v=,w=,x=0,y=0,z=0)
在src/thread/pthread_cancel.c:33处
#在src/unistd/pause.c:7处暂停()时有2个0x77f0b4b0
#3 0x556ecd3c在/path/to/source文件处的core_运行(argc=1,argv=0x7f7bf4a4)。cpp:461
#libc_start_main_stage2中的4 0x77e93d28(main=0x556b1ac0,argc=1,argv=0x7f7bf4a4)
在src/env/_libc_start_main.c:94
#crt/crt1处的50x556EB890in _start_c(p=)。c:18
#6 0x556eb850在/path/to/header文件的_start()处。hpp:130
回溯已停止:帧未保存电脑
(注意:在上面我用占位符替换了内部路径/文件名/etc)

不成功的核心转储gdb会话
$mipsel poky linux gdb-iex“设置详细”-iex“设置sysroot/path/to/sysroot”/path/to/testprog核心
GNU gdb(gdb)8.2.1
版权所有(C)2018免费软件基金会。
许可证GPLv3+:GNU GPL版本3或更高版本
这是自由软件:您可以自由更改和重新发布它。
在法律允许的范围内,不存在任何担保。
有关详细信息,请键入“显示复制”和“显示保修”。
此GDB配置为“-host=x86_64-pokysdk-linux--target=mipsel-poky-linux”。
键入“显示配置”以获取配置详细信息。
有关错误报告说明,请参阅:
.
在线查找GDB手册和其他文档资源,网址为:
.
要获得帮助,请键入“帮助”。
键入“apropos word”以搜索与“word”相关的命令。。。
从/path/to/testprog…读取符号已完成。
读取/path/to/source/main.cpp的符号…完成。
[新LWP 1285]
[新LWP 1408]
[新LWP 1409]
[新LWP 1410]
[新LWP 1412]
[新LWP 1407]
[新LWP 1401]
[新LWP 1402]
[新LWP 1403]
[新LWP 1404]
为“/path/to/testprog”使用PIE(位置独立可执行文件)位移0x555c4000。
警告:特定于平台的solib_create_Substander_钩子未加载初始共享库。
正在0x7ff2b000处从系统提供的DSO读取符号…(未找到调试符号)…完成。
核心由“/remote/path/to/testprog”生成。
程序以信号SIGABRT终止,中止。
#0 0x77e80204英寸??()
[当前线程为1(LWP 1285)]
(gdb)英国电信
警告:GDB在0x77e80204处找不到函数的开头。
GDB在0x77e80204处找不到函数的开头
因此无法确定该函数堆栈帧的大小。
这意味着GDB可能无法访问该堆栈帧,或者
下面的框架。
此问题很可能是由无效的程序计数器或
堆栈指针。
然而,如果您认为GDB应该只在更远的地方搜索
来自0x77e80204的代码,看起来像
函数,您可以使用`set`增加搜索范围
“篱笆哨所”命令。
#0 0x77e80204英寸??()
(gdb)
(注意:在上面我用占位符替换了内部路径/文件名/etc)

我试过的东西
我尝试了几种方法,包括使用
set solib search path
而不是
set sysroot
,直接告诉gdb通过
add symbol file/path/to/libc.so
加载库,甚至
添加symbol file/path/to/libc.so 0xdeadbeef
其中0xdeadbeef实际上是加载库的地址,通过readelf获得。在最后一个例子中,gdb最终加载了符号,但显然有些地方不对劲,可能是我传递的地址不正确。问题是,我不应该这样做,gdb应该在核心转储中找到这些信息并加载库!我如何让它做到这一点,为什么它不首先做到呢?

/path/to/libc。那么
gdb
它显示了什么?它可以读取调试符号吗?
$gdb/path/to/libc.so

通常
libc.so
本身不包含调试符号,而是包含指向包含调试符号的文件的链接

在Linux中,调试符号可以是:

/usr/lib/debug

/usr/bin/.debug

查看
gdb
在哪里查找separa
$ mipsel-poky-linux-gdb -iex "set sysroot /path/to/sysroot" /path/to/testprog
GNU gdb (GDB) 8.2.1
Copyright (C) 2018 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 "--host=x86_64-pokysdk-linux --target=mipsel-poky-linux".
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"...
Reading symbols from /path/to/testprog...done.
(gdb) 
(gdb) target extended-remote remote-hostname:10000
Remote debugging using remote-hostname:10000
Reading symbols from /path/to/sysroot/lib/ld.so.1...done.
__cp_end () at src/thread/mips/syscall_cp.s:38
38      beq     $7, $0, 1f
(gdb) bt
#0  __cp_end () at src/thread/mips/syscall_cp.s:38
#1  0x77eff348 in __syscall_cp_c (nr=4029, u=<optimized out>, v=<optimized out>, w=<optimized out>, x=0, y=0, z=0)
    at src/thread/pthread_cancel.c:33
#2  0x77f0b4b0 in pause () at src/unistd/pause.c:7
#3  0x556ecd3c in core_run (argc=1, argv=0x7f7bf4a4) at /path/to/source-file.cpp:461
#4  0x77e93d28 in libc_start_main_stage2 (main=0x556b1ac0 <main(int, char**)>, argc=1, argv=0x7f7bf4a4)
    at src/env/__libc_start_main.c:94
#5  0x556eb890 in _start_c (p=<optimized out>) at crt/crt1.c:18
#6  0x556eb850 in _start () at /path/to/header-file.hpp:130
Backtrace stopped: frame did not save the PC

$ mipsel-poky-linux-gdb -iex "set verbose on" -iex "set sysroot /path/to/sysroot" /path/to/testprog core
GNU gdb (GDB) 8.2.1
Copyright (C) 2018 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 "--host=x86_64-pokysdk-linux --target=mipsel-poky-linux".
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"...
Reading symbols from /path/to/testprog...done.
Reading in symbols for /path/to/source/main.cpp...done.
[New LWP 1285]
[New LWP 1408]
[New LWP 1409]
[New LWP 1410]
[New LWP 1412]
[New LWP 1407]
[New LWP 1401]
[New LWP 1402]
[New LWP 1403]
[New LWP 1404]
Using PIE (Position Independent Executable) displacement 0x555c4000 for "/path/to/testprog".

warning: platform-specific solib_create_inferior_hook did not load initial shared libraries.
Reading symbols from system-supplied DSO at 0x7ff2b000...(no debugging symbols found)...done.
Core was generated by `/remote/path/to/testprog'.
Program terminated with signal SIGABRT, Aborted.
#0  0x77e80204 in ?? ()
[Current thread is 1 (LWP 1285)]
(gdb) bt
warning: GDB can't find the start of the function at 0x77e80204.

    GDB is unable to find the start of the function at 0x77e80204
and thus can't determine the size of that function's stack frame.
This means that GDB may be unable to access that stack frame, or
the frames below it.
    This problem is most likely caused by an invalid program counter or
stack pointer.
    However, if you think GDB should simply search farther back
from 0x77e80204 for code which looks like the beginning of a
function, you can increase the range of the search using the `set
heuristic-fence-post' command.
#0  0x77e80204 in ?? ()
(gdb)
Hex dump of section '.gnu_debuglink':
  0x00000000 6c696263 2d322e32 372e736f 00000000 libc-2.27.so....
  0x00000010 48c02c04                            H.,.