`
deepfuture
  • 浏览: 4332547 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:79402
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:68357
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:101480
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:281131
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:14596
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:65547
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:31310
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:45197
社区版块
存档分类
最新评论

linux-c/c++调试利器gdb、ddd小试

阅读更多

一、gdb,在shell窗口调试

main.c内容:

main.c

#include <stdio.h>

int main() 

{

int y=0;

for (int i=0;i<10;i++){

   y+=i;

}

return 0;

}

深未来技术原创文章,如转载,请注明来源http://deepfuture.iteye.com/ 

编译:

 

deepfuture@deepfuture-desktop:~/test$ gcc -ggdb -std=c99 -o main main.c

 

启动gdb

1、gdb 执行文件名

 

deepfuture@deepfuture-desktop:~/test$ gdb main

GNU gdb (GDB) 7.1-ubuntu

Copyright (C) 2010 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

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 "i486-linux-gnu".

For bug reporting instructions, please see:

<http://www.gnu.org/software/gdb/bugs/>...

Reading symbols from /home/deepfuture/test/main...done.

2、list为列出源代码

(gdb) list

1

2 #include <stdio.h>

3 int main() 

4 {

5 int y=0;

6 for (int i=0;i<10;i++){

7   y+=i;

8 }

9 return 0;

10 }

3、运行
(gdb) run
Starting program: /home/deepfuture/test/main 

Program exited normally.
4、退出gdb
(gdb) quit
5、启动gdb后,再设置要加载的文件
(gdb) file main
Reading symbols from /home/deepfuture/test/main...done.

6、设置断点,,使用break行号

(gdb) list
warning: Source file is more recent than executable.
1
2 #include <stdio.h>
3 int main() 
4 {
5 int y=0;
6 for (int i=0;i<10;i++){
7   y+=i;
8 }
9 return 0;
10 }

(gdb) break 7
Breakpoint 1 at 0x80483ca: file main.c, line 7.

7、运行,run
(gdb) run
Starting program: /home/deepfuture/test/main 

Breakpoint 1, main () at main.c:7
7   y+=i;
8、离开这个断点,继续运行
(gdb) c
Continuing.
9、监视变量
(gdb) watch y
Hardware watchpoint 2: y
10、检查变量变化
(gdb) c
Continuing.
Hardware watchpoint 2: y

Old value = 1
New value = 3
main () at main.c:6
6 for (int i=0;i<10;i++){
(gdb) c
Continuing.

Breakpoint 1, main () at main.c:7
7   y+=i;
(gdb) c
Continuing.
Hardware watchpoint 2: y

Old value = 3
New value = 6
main () at main.c:6
6 for (int i=0;i<10;i++){


二、ddd,使用
可以在选择行或某变量后,watch,break等按钮,很方便
右中部的面板是一些流程调试

 图形方式调试





 


  • 大小: 21.2 KB
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics