debug —— list调试命令

就以函数之间传递值(嵌套函数),的函数来理解debug调试中的,list命令。

1、test.c源码

     1	#include<stdio.h>
     2	int aaa(int *a){
     3	        int b = 4;
     4	        (*a) = b;
     5	        printf("aaa:a=%d\n",*a);
     6	        printf("aaa:a==%p\n",&(*a));
     7	        return 0;
     8	}
     9	int bbb(int *total){
    10	        aaa(total);
    11	        printf("bbb:total=%d\n",*total);
    12	        printf("bbb:total=%p\n",total);
    13	        return 0;
    14	}
    15	int ddd(void *other){
    16	        int total = 0;
    17	        bbb(&total);
    18	        printf("ddd:total=%d\n",total);
    19	        printf("ddd:total=%p\n",&total);
    20	}
    21	int ccc(){
    22	        int total = 0;
    23	        char other[512] = {'\0'};
    24	
    25	        bbb(&total);
    26	        printf("ccc:total=%d\n",total);
    27	        printf("ccc:total=%p\n",&total);
    28	        ddd(other);
    29	}
    30	int main(){
    31	        ccc();
    32	        return 0;
    33	}

2、把.c文件编译为可执行文件

如果不编译使用gdb ./a.out执行会有,No symbol table is loaded.  Use the "file" command. 的错误出现。 

3、gdb调试 启动命令

4、list 或者  l命令

【1】help l 或者 help list

列出指定的函数或行。
没有参数,在前面的列表之后或前后再列出10行。
“list-”列出前10行列表之前的10行。
一个参数指定一行,并在该行周围列出十行。
指定要列出的起始行和结束行之间带有逗号的两个参数。
可以通过以下方式指定行:
     LINENUM,在当前文件中围绕该行列出,
     文件:LINENUM,在该文件函数中围绕该行列出,在该函数的开头处列出
     文件:函数,区分类似名称的静态函数。
     *地址,在包含该地址的行周围列出。
对于两个arg,如果其中一个为空,则表示与另一个arg相距10行。

【2】(gdb) l   《或者》  (gdb) list  《或者》 (gdb)  空格       ===》列出源码
{会跟前一句的执行结果有关,例如你上一次查看到第10行,执行list命令之后会显示11-20行}

【3】(gdb) l   数字     ===》列出以该数字为中心,包含该局在内的,前后10行代码。
{例如:如果 l 10,显示5-14行;    如果   l  2, 前不够5行,则显示1-10,尽可能多的显示}

【4】(gdb) l   -    ===》列出上一个l命令查看代码之前的10行。
{例如:如果上一个命令 l 15,显示10-19行;    则l - 之后显示1-9行,不够10行了。}

【5】(gdb) l   数字1 , 数字 2  ===》列出列出数字1,数字2之间的代码
{例如:l  20,24}

【6】(gdb) l   函数名  ===》查看该函数周围的10行代码
{例如:l  aaa  注意:函数名后不需要加括号,否则会报错 function "aaa()" not defined}

【7】(gdb) l   文件名:数字  ===》在文件函数中围绕该行列出,从函数的开头列出
{例如:l  test.c:22  注意:文件名}

【8】(gdb) l   文件名:函数名  ===》在该文件中,围绕该函数名,列出周围10行代码
{例如:l  test.c:bbb     注意:文件名:函数名}

猜你喜欢

转载自blog.csdn.net/weixin_42167759/article/details/81147964