GDB && Makefile 大法

https://blog.csdn.net/piaopiaopiaopiaopiao/article/details/86060556

https://blog.csdn.net/zhouzhiyuan999/article/details/80247428
https://blog.csdn.net/taolusi/article/details/81175551

https://blog.csdn.net/baidu_38172402/article/details/81152192

 

//GDB大法:

GDB调试

https://blog.csdn.net/V__KING__/article/details/58192272

https://stackoverflow.com/questions/501486/getting-gdb-to-save-a-list-of-breakpoints

 

 

使用gdb调试当前运行的程序
https://blog.csdn.net/wfing/article/details/5890382

gdb 调试利器

https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/gdb.html?highlight=gdb

gdb watch的使用

https://blog.csdn.net/taolusi/article/details/81072124


//NB的飞龙系列;
https://github.com/wizardforcel

https://legacy.gitbook.com/book/wizardforcel/100-gdb-tips/details

C++ gdb调试
https://blog.csdn.net/taolusi/article/details/81074117
https://blog.csdn.net/taolusi/article/category/6380076

gdb图形化调试之insight
https://blog.csdn.net/noWorries/article/details/8888874

 

//Makefile///

Makefile初学记录
https://blog.csdn.net/noWorries/article/details/8879142

Makefile中的函数(二)
https://blog.csdn.net/noworries/article/details/8880123

Makefile和shell脚本的区别
https://blog.csdn.net/noWorries/article/details/8879856

Makefile中的函数
https://blog.csdn.net/noWorries/article/details/8879467

makefile中的call函数
https://blog.csdn.net/ly890700/article/details/52800734

Makefile文件中的MAKEFILE_LIST变量
https://blog.csdn.net/yanlaifan/article/details/83114279

Makefile中的?= := += =的区别
https://blog.csdn.net/m7548352/article/details/49562547

Makefile: Makefile中的-I
https://blog.csdn.net/kangear/article/details/8492604

makefile专题:函数定义及调用

https://blog.csdn.net/jacob__lei/article/details/79289283

【Makefile】自定义函数
https://blog.csdn.net/q_z_r_s/article/details/80781304

makefile 函数调用理解与自定义函数
https://blog.csdn.net/dp__mcu/article/details/70312779

makefile自定义函数
https://blog.csdn.net/joan11_3/article/details/51568844

Makefile 里的 subst 函数
https://blog.csdn.net/mrwangwang/article/details/25738287

Makefile 函数大全
https://blog.csdn.net/Cashey1991/article/details/8603803

nginx反向代理(实践版)
https://www.cnblogs.com/leon2659/p/10185568.html

 

 

 

 

 

GDB的极致运用

 

 

0. 前言

GDB(GNU Debugger)是UNIX及UNIX-like下的强大调试工具,可以调试ada, c, c++, asm, minimal, d, fortran, objective-c, go, java,pascal等语言。本文以C程序为例,介绍GDB启动调试的多种方式。

1.哪类程序可被调试

对于C程序来说,需要在编译时加上-g参数,保留调试信息,否则不能使用GDB进行调试。
但如果不是自己编译的程序,并不知道是否带有-g参数,如何判断一个文件是否带有调试信息呢?

1.1gdb 文件

例如:

$ gdb helloworld
Reading symbols from helloWorld...(no debugging symbols found)...done.

如果没有调试信息,会提示:no debugging symbols found。
如果是下面的提示:

Reading symbols from helloWorld...done.

则可以进行调试。

1.2readelf查看段信息

例如:

$ readelf -S helloWorld|grep debug
  [28] .debug_aranges    PROGBITS         0000000000000000  0000106d
  [29] .debug_info       PROGBITS         0000000000000000  0000109d
  [30] .debug_abbrev     PROGBITS         0000000000000000  0000115b
  [31] .debug_line       PROGBITS         0000000000000000  000011b9
  [32] .debug_str        PROGBITS         0000000000000000  000011fc

helloWorld为文件名,如果没有任何debug信息,则不能被调试。

1.3file查看strip状况

下面的情况也是不可调试的:

file helloWorld
helloWorld: (省略前面内容) stripped

如果最后是stripped,则说明该文件的符号表信息和调试信息已被去除,不能使用gdb调试。但是not stripped的情况并不能说明能够被调试。

2.调试未运行程序

程序还未启动时,可有多种方式启动调试。

2.1调试启动无参程序

例如:

$ gdb helloWorld
(gdb)

输入run命令,即可运行程序

2.2调试启动带参程序

假设有以下程序,启动时需要带参数:

 #include<stdio.h>
 int main(int argc,char *argv[])
 {
     if(1 >= argc){
         printf("usage:hello name\n");
         return 0;
     }
     printf("Hello World %s!\n",argv[1]);
     return 0 ;
 }

编译:

gcc -g -o hello hello.c

这种情况如何启动调试呢?需要设置参数:

$ gdb hello
(gdb)run 编程珠玑
Starting program: /home/shouwang/workspaces/c/hello 编程珠玑
Hello World 编程珠玑!
[Inferior 1 (process 20084) exited normally]
(gdb)

只需要run的时候带上参数即可。
或者使用set args,然后在用run启动:

gdb hello
(gdb) set args 编程珠玑
(gdb) run
Starting program: /home/hyb/workspaces/c/hello 编程珠玑
Hello World 编程珠玑!
[Inferior 1 (process 20201) exited normally]
(gdb) 

2.3调试core文件

当程序core dump时,可能会产生core文件,它能够很大程序帮助我们定位问题。但前提是系统没有限制core文件的产生。可以使用命令limit -c查看:

 $ ulimit -c
 0

如果结果是0,那么恭喜你,即便程序core dump了也不会有core文件留下。我们需要让core文件能够产生:

ulimit -c unlimied  #表示不限制core文件大小
ulimit -c 10        #设置最大大小,单位为块,一块默认为512字节

上面两种方式可选其一。第一种无限制,第二种指定最大产生的大小。
调试core文件也很简单:

gdb 程序文件名 core文件名

具体可参看《linux常用命令-开发调试篇》gdb部分。

3.调试已运行程序

如果程序已经运行了怎么办呢?
首先使用ps命令找到进程id:

ps -ef|grep 进程名

3.1attach方式

假设获取到进程id为20829,则可用下面的方式调试进程:

$ gdb
(gdb) attach 20829

接下来就可以继续你的调试啦。

可能会有下面的错误提示:

Could not attach to process.  If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.

解决方法,切换到root用户:
将/etc/sysctl.d/10-ptrace.conf中的

kernel.yama.ptrace_scope = 1

修改为

kernel.yama.ptrace_scope = 0

3.2直接调试相关id进程

还可以是用这样的方式gdb program pid,例如:

gdb hello 20829  

或者:

gdb hello --pid 20829

3.3已运行程序没有调试信息

为了节省磁盘空间,已经运行的程序通常没有调试信息。但如果又不能停止当前程序重新启动调试,那怎么办呢?还有办法,那就是同样的代码,再编译出一个带调试信息的版本。然后使用和前面提到的方式操作。对于attach方式,在attach之前,使用file命令即可:

$ gdb
(gdb) file hello
Reading symbols from hello...done.
(gdb)attach 20829

总结

本文主要介绍了两种类型的GDB启动调试方式,分别是调试未运行的程序和已经运行的程序。对于什么样的程序能够进行调试也进行了简单说明。



作者:Leon_Geo
链接:https://www.jianshu.com/p/8e7f6bf6df2f
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值