如何在核心转储文件中更改sharelibrary的硬编码路径进行调试

时间:2016-11-30 10:44:20

标签: gdb

核心转储中的一些sharelibrary路径是硬编码的,如果设置了solib-absolute-prefix,似乎gdb将从solib-absolute-prefix的值+ sharelibrary的硬编码路径中搜索它,如何更改它们调试?

我尝试过solib-absolute-prefix和solib-search-path,但是效果不好

1 个答案:

答案 0 :(得分:0)

solib-search-path 正好你想要的是什么。

  

不会很好用

你必须扩展不起作用的东西。以下示例显示solib-search-path 的工作原理:

mkdir /tmp/foo /tmp/bar
cd /tmp/foo

echo 'void foo() { abort(); }' | gcc -xc - -fPIC -shared -o foo.so -w
echo 'int main() {  foo(); return 0; }' | gcc -xc - -l:./foo.so
./a.out
Aborted (core dumped)

首先,我们在原始位置查看包含所有二进制文件的核心:

gdb -q ./a.out core

Reading symbols from ./a.out...done.
[New LWP 142587]
Core was generated by `./a.out'.
Program terminated with signal SIGABRT, Aborted.
#0  0x00007f9c6f1f9c37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56  ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  0x00007f9c6f1f9c37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007f9c6f1fd028 in __GI_abort () at abort.c:89
#2  0x00007f9c6f5886ce in foo ()
#3  0x000000000040069b in main ()

这看起来不错。现在我们将foo.so移至/tmp/bar

mv foo.so /tmp/bar

分析相同的核心不再有效(至少不是很好):

gdb -q ./a.out core
Reading symbols from ./a.out...done.
[New LWP 142587]

warning: Could not load shared library symbols for ./foo.so.
Do you need "set solib-search-path" or "set sysroot"?
Core was generated by `./a.out'.
Program terminated with signal SIGABRT, Aborted.
#0  0x00007f9c6f1f9c37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56  ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  0x00007f9c6f1f9c37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007f9c6f1fd028 in __GI_abort () at abort.c:89
#2  0x00007f9c6f5886ce in ?? ()
#3  0x00007ffdaa9b74e0 in ?? ()
#4  0x000000000040069b in main ()
Backtrace stopped: frame did not save the PC

最后我们设置了solib-search-path,它再次有效:

(gdb) set solib-search-path /tmp/bar
Reading symbols from /tmp/bar/foo.so...done.
WARNING: no debugging symbols found in /tmp/bar/foo.so.
(gdb) bt
#0  0x00007f9c6f1f9c37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007f9c6f1fd028 in __GI_abort () at abort.c:89
#2  0x00007f9c6f5886ce in foo ()
#3  0x000000000040069b in main ()