码迷,mamicode.com
首页 > 数据库 > 详细

gdb调试程序

时间:2014-09-23 14:55:45      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:io   for   sp   on   c   代码   ad   r   bs   

一、准备好内容vim test3.c  输入如下即可

#include <stdio.h>
 int func(int n)
 {
         int sum=0,i;
         for(i=0; i<n; i++)
         {
                 sum+=i;
         }
         return sum;
 }
 main()
 {
         int i;
         long result = 0;
         for(i=1; i<=100; i++)
         {
                 result += i;
         }
        printf("result[1-100] = %d /n", result );
        printf("result[1-250] = %d /n", func(250) );
 }

二、编译成

gcc test3.c -o test3

./test3 可以查看结果

gdb test3 出现错误

gdb list 的时候出现如下错误

No symbol table is loaded.  Use the "file" command.

---------------------------------

解决方案:

list命令后显示No symbol table is loaded. Use the "file" command.
原来编译用:gcc -o filename filename.c
解决办法,编译时加 一定要加-g:gcc -o filename -g filename.c

或者 比如gcc -g -o test3 test3.c 然后 gdb test3

 

gdb list 1 从第一行开始。默认的一次只有10行,直接enter键下10行代码

 

gdb调试程序

标签:io   for   sp   on   c   代码   ad   r   bs   

原文地址:http://www.cnblogs.com/bluewelkin/p/3988032.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!