遠程調試
Alice和Bob應該使用遠程調試。鮑勃開始gdbserver的:
[email protected]:/home/bob$ gdbserver :2345 ./helloworld
還有愛麗絲連接到它:
[email protected]:/home/alice$ gdb
[...]
(gdb) file helloworld
Reading symbols from /home/alice/helloworld...done.
(gdb) target remote :2345
Remote debugging using :2345
[...]
0x00007fbdc6329af0 in _start() from /lib64/ld-linux-x86-64.so.2
使用絕對路徑
這個作品在這個簡單的情況下,遠程調試。然而,當Bob使用絕對路徑,他的共享庫的一些複雜的requried:
[email protected]:/home/bob$ ls
helloworld libmylib.so
[email protected]:/home/bob$ LD_LIBRARY_PATH=/home/bob gdbserver :2345 ./helloworld
現在,愛麗絲無法找到共享庫:
[email protected]:/home/alice$ gdb
[...]
(gdb) file helloworld
Reading symbols from /home/alice/helloworld...done.
(gdb) target remote :2345
Remote debugging using :2345
[...]
(gdb) break helloWorld()
Breakpoint 1 at 0x400480
(gdb) c
Continuing.
Error while mapping shared library sections:
/home/bob/libmylib.so: No such file or directory.
爲了解決這個問題,Alice創建虛擬鏈接到它的根文件夾中的二進制文件:
[email protected]:/home/alice$ mkdir -p gdb-symbols/home/
[email protected]:/home/alice$ ln -s /home/alice gdb-symbols/home/bob
[email protected]:/home/alice$ ln -s /lib gdb-symbols/lib
[email protected]:/home/alice$ ln -s /lib64 gdb-symbols/lib64
[and so forth for every shared library that cannot be found...]
,現在能夠與加載的所有符號調試:
[email protected]:/home/alice$ gdb
[...]
(gdb) file helloworld
Reading symbols from /home/alice/helloworld...done.
(gdb) target remote :2345
Remote debugging using :2345
[...]
Reading symbols from /home/alice/gdb-symbols/home/bob/libmylib.so...done.
Loaded symbols from /home/alice/gdb-symbols/home/bob/libmylib.so
(gdb)
使用Alice-Bob meme來表達這個問題的榮譽,這使得它非常容易理解並且非常容易回答。 – parasietje 2012-01-04 10:47:22