编写一个必定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搜索路径的更多相关文章

  1. GDB + gdbserver 远程调试android native code

    原文地址:GDB + gdbserver 远程调试android native code 作者:tq08g2z 以调试模拟器中的native library code为例. Host: ubuntuT ...

  2. 使用gdbserver远程调试

    使用gdbserver远程调试   1.默认crosstool交叉编译器没有自带gdbserver,需要自行编译 到GNU官方FTP下载,目前最新版的是gdb-6.7.1下载地址:http://ftp ...

  3. gdbserver远程调试嵌入式linux应用程序方法

    此处所讲的是基于gdb和gdbsever的远程调试方法.环境为:PC机:win7.虚拟机:10.04.下位机:飞嵌TE2440开发板. 嵌入式linux应用程序的开发一般都是在linux里面编写好代码 ...

  4. Makefile一 头文件及库搜索路径

    头文件及库搜索路径 头文件的搜索路径: 头文件的搜索规则是:找到就使用,停止继续往下寻找 1: #include “mytest.h” 搜索的顺序为: (1)先搜索当前目录 (2)然后搜索编译时 -I ...

  5. GDB + gdbserver 远程调试mediaserver进程

    远程调试步骤 在Android设备上启动gdbserver并attach你想调试的进程,并指定监听调试命令的端口(此端口是TV上的端口) $ adb shell # ps |grep media  # ...

  6. LaTeX自定义宏包、类文件的默认搜索路径设置方法

      对于自定义的LaTeX宏包与类,在调用时可以通过在命令\documentclass{}与\usepackage{}命令中指定完整路径或者相对路径,这样确实可以调用,但是编译时总是有烦人的警告信息, ...

  7. 如何在sublime3项目设置中设置python模块的搜索路径?ImportError: No module named *的解决办法

    问题:之前使用pycharm,用的挺溜,但是电脑配置实在不争气,pycharm启动久了,耗去大量内存,导致运行起来越来越慢,于是转向使用sublime text. 把项目从pycharm切换到subl ...

  8. Eclispe远程调试tomcat设置

    首先在catelina.sh中添加 JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=23787,server=y,su ...

  9. hive,spark的远程调试设置

    spark的远程调试 spark-env.sh文件里面,加上下面配置即可: if [ "$DEBUG_MODE" = "true" ]; then export ...

随机推荐

  1. zgb老师关于java集合的总结

    数组:存多个数据 操作不便集合(Collection ):存多个数据 管理多个数据 提供更为方便的操作Iterator:专门针对集合 进行迭代List:有序的 允许重复的元素ArrayList:底层数 ...

  2. 使用NPOI实现简单的Excel导出功能

    [1]NPOI是啥? NPOI是指构建在POI 3.x版本之上的一个程序,NPOI可以在没有安装Office的情况下对Word或Excel文档进行读写操作. POI是一个开源的Java读写Excel. ...

  3. Super超级ERP系统---(1)总体设计

       1.概述 随着互联网的发展,尤其是电子商务的发展,信息化系统越来显得越重要.在互联网飞速发展的今天,各种网站,软件系统应用而生,特别是随着近几年电子商务的发展,很多企业慢慢开始做大,管理方面暴露 ...

  4. 常用的CSS命名

    头:header 内容:content/container 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制整体佈局宽度:wrapper 左右中:left rig ...

  5. apache出现You don't have permission to access / on this server提示的解决方法

    在apache的配置文件httpd.conf里定义了对网站根默认的访问权限 #<Directory />    Options FollowSymLinks    AllowOverrid ...

  6. Functor、Applicative 和 Monad(重要)

    Functor.Applicative 和 Monad Posted by 雷纯锋Nov 8th, 2015 10:53 am Functor.Applicative 和 Monad 是函数式编程语言 ...

  7. Javase范式

    package Xwxx; import java.util.ArrayList; import java.util.Iterator; import java.util.function.IntBi ...

  8. PHP中调用Soap/WebService

    关于在PHP中如何调用Soap/WebService的描述,网络上有不少帖子.但是主要讲述了如何用PHP开发服务器端.客户端并加以关联,而很少触及在PHP中调用现成的WebService的情况.在本文 ...

  9. Project Euler 11 Largest product in a grid

    题意:在这个20×20方阵中,四个在同一方向(从下至上.从上至下.从右至左.从左至右或者对角线)上相邻的数的乘积最大是多少? 思路:暴力去枚举以 ( x , y ) 为中心拓展的四个方向 /***** ...

  10. leetCode笔记--(1)

    陪朋友刷题,记录下. 1.Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operato ...