文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>GDB调试

GDB调试

时间:2006-03-19  来源:shangguanyun

程序如下:
#include <stdio.h>
 int main()
 {  
      int i;
      long result = 0;  
      for(i=1; i<=5; i++)
      {  
            result += i; 
      } 
      printf("result = %d \n", result ); 
      getchar();
      return 0;  
 }
选用-g选项添加调试信息
gcc -g gdbtest.c -o gdbtest
        
[root@localhost sgy]# gdb                                                     
GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)                               
Copyright 2003 Free Software Foundation, Inc.                                 
GDB is free software, covered by the GNU General Public License, and you are  
welcome to change it and/or distribute copies of it under certain conditions. 
Type "show copying" to see the conditions.                                    
There is absolutely no warranty for GDB.  Type "show warranty" for details.   
This GDB was configured as "i386-redhat-linux-gnu".                           
(gdb) file gdbtest    //加载文件 或开始用gdb gdbtest加载                        
Reading symbols from gdbtest...done.                                          
(gdb) l       //列出源代码                      
1       int main()                                                           
2       {                                                                    
3            int i;                                                          
4            long result = 0;                                                            
5            for(i=1; i<=5; i++)                                             
6            {                                                               
7                  result += i;                                              
8            }                                                               
9            printf("result = %d \n", result );                       
10            getchar();                                                      
11            return 0;                                                       
12       }   
(gdb) break 4        //将断点加在4行    
Breakpoint 1 at 0x804839e: file gdbtest.c, line 4.                           
(gdb) r        //开始执行       
Starting program: /usr/sgy/gdbtest                                            
                                                                              
Breakpoint 1, main () at gdbtest.c:4                                         
14            long result = 0;                                                
(gdb) watch result   //观察变量result     
Hardware watchpoint 2: result                                                 
(gdb) n             //n表示单步执行  
15            for(i=1; i<=5; i++)                                             
(gdb) n                                                                       
Hardware watchpoint 2: result                                                 
                                                                              
Old value = 1108544020                                                        
New value = 0                                                                 
0x080483ac in main () at gdbtest.c:5                                         
15            for(i=1; i<=5; i++)                                             
                                                         
(gdb) kill        //杀掉正在调试项目                            
Kill the program being debugged? (y or n) y
(gdb) q         //退出
[root@localhost sgy]#
相关阅读 更多 +
排行榜 更多 +
Event Horizon

Event Horizon

飞行射击 下载
Counter Terrorist Sniper Shoot

Counter Terrorist Sniper Shoot

飞行射击 下载
Special Agent

Special Agent

飞行射击 下载