GDB Tutorial: Advanced Debugging Tips For C/C++ Programmers

看到一篇GDB 的不错的文章,跟大家分享一下。

GDB Tutorial: Advanced Debugging Tips For C/C++ Programmers

以下是我做的一点笔记。

add debug option -g when compile the source code

basic:

b

c

step

n

list

print

bt

run

where

watch

 

Run A Program With Arguments

There are two ways you can feed arguments to your program

1. gdb --args executablename arg1 arg2 arg3

   --args says thateverything that follows is the command and arguments, just as you'd normallytype them at the commandline prompt

2. gdb programe

   r  arg1 arg2 ....

 

1. breakpoint(断点)

b  linenumber

b  filename:linenumber

b  function

b  filename:function

 

Get information  aboutall breakpoints

info breakpoint 

 

delete an existing breakpoint

delete breakpoints 1

 

set a temporary breakpoint

tbreak powere

 

If you have a program without debug symbols then you can’tuse any of the above option. Instead, the gdb allows you to specify a breakpoint for memory addresses

break upon matching memory address

b *(memory address)

break after a condition

b linenumber if variable==1

 

2.get the information about the arguments passed to afunction  (查看函数传入参数)

info args

 

3. get the information about the local variables

info locals

 

4.how to execute a function to the end after breakpoint, itwill run through the entire function

finsh

 

5.how to print the line number in GDB wihile debugging

frame

 

6.add watchers

Adding watch points is same like telling the debugger togive an dynamic analysis of changes to the variables.And it's easy to add awatch point in your code.

watch variable

 

7.How to skip/ignore breakpoints

while you are  runningthrough a loop in your code and wouldn't want to pause for every break, thenignore command can help.

Here is how you can skip a breakpoint the number of timesyou want.

 

First check the index of the break point which you want toignore. Use the info breakpoints command.

Then run the following command in the gdb debugger, say wewant to ignore the break for 1000 times

ignore 1 10000

 

8.debug dynamic libs need to set

set breakpoint pending on

otherwise it will report the error:forexample

(gdb) b mps_guide_db.c:1699

No source file named mps_guide_db.c.

Make breakpoint pending on future shared library load? (y or[n]) [answered N; input not from terminal]

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值