码迷,mamicode.com
首页 > 数据库 > 详细

gdbserver 远程调试问题:设置文件和so搜索路径

时间:2014-06-17 19:06:18      阅读:710      评论:0      收藏:0      [点我收藏+]

标签:gdb

编写一个必然crash 的程序

#include <stdio.h>

void crash(){
 
    char *a=0;
    *a=0;
}
int main()
 {
        printf("hello world\n");
        crash();
        printf("after crash\n");
 }
执行gdb 远程调试

gdbserver :1234 a.out 


运行 gdb , 运行命令  target remote :1234

必须用 file 指定可执行文件,才能看见调用函数

(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x0000000000400534 in ?? ()
(gdb) bt
#0  0x0000000000400534 in ?? ()
#1  0x00007fffffffe4c0 in ?? ()
#2  0x000000000040054c in ?? ()
#3  0x0000000000000000 in ?? ()
(gdb) file /home/payne/hello/a.out
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from /home/payne/hello/a.out...done.
(gdb) bt
#0  0x0000000000400534 in fun1 () at hello.cpp:6
#1  0x000000000040054c in main () at hello.cpp:12

不用 -g 编译也能看见函数,但不能定位到行

Program received signal SIGSEGV, Segmentation fault.
0x0000000000400534 in crash() ()
(gdb) bt
#0  0x0000000000400534 in crash() ()
#1  0x000000000040054c in main ()

把 crash 放到 so 中会如何?

生成libcrash.so 重新编译 hello.cpp

g++ -o libcrash.so -shared crash.cpp 

export LD_LIBRARY_PATH=`pwd`

g++  hello.cpp  -lcrash


gdb 不能定位到 so 中的函数

rogram received signal SIGSEGV, Segmentation fault.
0x00007ffff7ff65bc in ?? ()
(gdb) bt
#0  0x00007ffff7ff65bc in ?? ()
#1  0x00007fffffffe470 in ?? ()
#2  0x0000000000400657 in ?? ()
#3  0x0000000000000000 in ?? ()
(gdb) file /home/payne/hello/a.out
A program is being debugged already.
Are you sure you want to change the file? (y or n) 
Please answer y or n.
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from /home/payne/hello/a.out...(no debugging symbols found)...done.
(gdb) bty
Undefined command: "bty".  Try "help".
(gdb) bt
#0  0x00007ffff7ff65bc in ?? ()
#1  0x00007fffffffe470 in ?? ()
#2  0x0000000000400657 in main ()

用 set solib-search-path 指定路径, 可以得到 so 中的位置

(gdb) set solib-search-path /home/payne/hello
Reading symbols from /home/payne/hello/libcrash.so...(no debugging symbols found)...done.
Loaded symbols for /home/payne/hello/libcrash.so
Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.15.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/ld-2.15.so...done.
done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
(gdb) bt
#0  0x00007ffff7ff65bc in crash() () from /home/payne/hello/libcrash.so
#1  0x0000000000400657 in main ()



gdbserver 远程调试问题:设置文件和so搜索路径,布布扣,bubuko.com

gdbserver 远程调试问题:设置文件和so搜索路径

标签:gdb

原文地址:http://blog.csdn.net/span76/article/details/31745113

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!