Visual studio调试和在linux gdb调试的尝试

                                    Visual studio调试: 定位代码    缩小调试范围    打断点     不断继续run    查看需要变量值与自己预期结果  判断哪里问题

#include "stdafx.h"
#include <stdio.h>
#include <string.h>

const char* str[] = { "Hello","abc","applef","man","C程序设计","指针数组","1","2","3" };
const char* pdest = "指针数组";


int main()
{
    int i;
    int ret = -1;
    const char * * p = str;
    for (i = 0; i < sizeof(str) / sizeof(char*); i++)
    {

#if 0 
        if (strcmp(*p++, pdest) == 0)
        {
            printf("we are found dest
");
            break;
        }
#endif 


        p = p + i;  // 这样是错误的   p的变化太大 指针越界   应该是p++ 



    }
    printf("
");        
    printf("i = %d
", sizeof(str) / sizeof(char*));

    while (1);

    return 0;
}
// 上面这个 我开始没有想明白 后来采用gdb 查看变量的值 我才找到原因 是p++



  查看变量的值是:     添加监视  就知道变量的值什么回事     

                                                                                    GDB调试

参考文章:

https://blog.csdn.net/niyaozuozuihao/article/details/91802994

-S 编译-s 

gdb xxx 

b xx(行)   b xxx(行)             在某个区间打断点

r(run)

s 单步调试

多次重复操作 按Enter键  

一勤天下无难事。
原文地址:https://www.cnblogs.com/nowroot/p/12642838.html