linux看代码调试,linux下gdb调试查看源代码

在linnux下编程,gdb是一个非常重要的**【才不会告诉你是调试利器】

在使用gdb调试前,所调试的文件必须加上-g参数生成调试信息

gcc -g helloworld.c -o hello    #生成可调试的信息以及可执行文件

调试:

下面我们来介绍下gdb的使用方法:

退出 gdb:

(gdb) quit    |(gdb)  q

进入gdb:

$ gdb hello

GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git

Copyright (C) 2018 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law. Type "show copying"

and "show warranty" for details.

This GDB was configured as "x86_64-linux-gnu".

Type "show configuration" for configuration details.

For bug reporting instructions, please see:

.

Find the GDB manual and other documentation resources online at:

.

For help, type "help".

Type "apropos word" to search for commands related to "word"...

Reading symbols from hello...done.

(gdb) list    #显示源码

1 #include

2

3 void main(){

4 printf("Hello,World\n\n\n");

5 }

错误指示:  没有符号表被读取。请使用 "file" 命令。

!!!如果出现以上文字,那么请注意在编译文件时是否使用了-g参数!!!

是不是发现list这样按顺序列出程序源代码是不是有点不太方便?设计师当然 也想到了这个问题,于是乎设计出了搜索特定内容的命令

$ (gdb) search printf

4 printf("Hello,world!");    #search只会显示一个符合条件的行,再次回车找到匹配的下一行代码,并且值得注意的是,search只能向前(朝文件尾)搜索

若是向向后(朝文件头)搜索,可以使用reverse-search

#search和reverse-search支持使用正则达式进行搜索。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值