首页 > 数据库技术 > 详细

gdb调试

时间:2019-03-23 17:28:58      阅读:155      评论:0      收藏:0      [点我收藏+]

1. gdb调试

技术分享图片

fun.c

#include <stdio.h>     
#include "head.h"      


int sum(int a, int b)  
{ 
    printf("welcome call %s, %d + %d = %d\n",__FUNCTION__, a, b, a + b);
    return a + b;      
}
 
int mul(int a, int b)
{
    printf("welcome call %s, %d * %d = %d\n", __FUNCTION__, a, b, a * b);
    return a * b;
}

head.h

#include <stdio.h>     
                       
int sum(int a, int b); 

int mul(int a, int b);

main.c

#include <stdio.h>     
#include <string.h>    
#include <stdlib.h>    
#include "head.h"

typedef struct MyfunInfo 
{ 
    int fun_type;           // 函数类型
    int a;                  // 函数的第一个参数     
    int b;                  // 第二个参数           
    char funname[10];       // 函数名称
}MyfunInfo;

int main(int argc, char *argv[])
{
    int a = 2;
    int i = 0;
    int a1 = 10, b1 = 5;    
    MyfunInfo funinfo[2];   
    char *Msg = "I will die !";
    //Msg[0] = ‘1‘;
    if (argc == 3)
    {
        a1 = atoi(argv[1]);     
        b1 = atoi(argv[2]);     
        funinfo[0].a = a1;      
        funinfo[0].b = b1;      
        funinfo[1].a = a1;      
        funinfo[1].b = b1;      
    }

    for (int i = 0; i < 2; i++)
    {
        printf("i===%d, LINE=%d\n", i, __LINE__);
        if (i == 0)
        {
            funinfo[i].fun_type = 1;
            printf("begin call sum\n");
            strcpy(funinfo[i].funname, "sum");
            sum(funinfo[i].a, funinfo[i].b);
        }
        if (i == 1)
        {
            funinfo[i].fun_type = 2;   //call mul
            printf("begin call mul\n");
            strcpy(funinfo[i].funname, "mul");
            mul(funinfo[i].a, funinfo[i].b);
        }
    }

    printf("say bye\n");

    return 0;
}

技术分享图片

(-g是调试选项, 生成的app.out可调试)

2 启动gdb

gdb app.out

技术分享图片

2.1 run (r) 启动

技术分享图片

2.2 start 启动-停留在main函数,分步调试

2.21 next(n):下一步

技术分享图片

2.22 step(s):下一步, 可以进入函数内部, 但是库函数不能进

技术分享图片

2.3 设置启动参数 set args parm1 parm2 ...

 技术分享图片

2.4 设置断点(重要)

2.41 list查看代码

技术分享图片

2.42 设置断点 break lineNum

技术分享图片

技术分享图片

2.43 给函数设置断点

技术分享图片

2.44 给文件行号设置断点

技术分享图片

2.45 list显示指定文件

 技术分享图片

2.46 指定文件行号设置断点

技术分享图片

 

gdb调试

原文:https://www.cnblogs.com/douzujun/p/10584308.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!