• gdb 脚本 简单理解


    1. gdb 脚本的语法简介:

    摘录博客:https://blog.csdn.net/hejinjing_tom_com/article/details/50350865

    1]   # 为脚本注释命令

    2]  赋值语句:set, 变量以$开始,以便区分是gdb还是调试程序变量。
         变量可为全局或局部,视声明位置。
        例如:
            set $x = 1;
    3]  函数声明语句:define .. end 语句
         define func
         end
        无行参声明,但可以直接用$arg1,$arg2引用, $argc 为形参个数

        函数语句开头不需要添加空格或tab键

    4]  说明(帮助)语句: document.. end
        为函数书写帮助说明,格式如下。

      define func

      end

    5] 显示语句: printf
        还可以用 echo

    6]  条件语句: if..else..end
    7]  循环语句: while .. end

    8]  常规的gdb 调试命令语句。

    9]  支持shell 命令, 可以实现dump, search 等复杂功能

    注意:

    gdb中使用的变量要加上'$'符号,否则会认为是被调试的程序中的变量

    自定义的gdb命令脚本文件,可以用source 命令来导入。

    上面是 几条简单语句,进一步学习 请参考:http://ifeve.com/gdb-script/

    2. 写一个gdb脚本,可跟踪某个变量为某数值时,执行添加的断点

    term.gdb 的内容如下:

    #fileName : term.gdb
    #define
    a function to set break_point define term if $argc != 2 help term else set $lineNum = $arg0 set $val = $arg1 printf "set b in file.c:%d if ix==%d ", $lineNum, $val break file.c:$lineNum if ix == $val end end document term usage: term lineNum val end

    test.c 文件内容如下

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    
    int main()
    {
        int ix = 0;
        for(ix = 0; ix < 100; ix++)
        {
            printf("ix = %d
    ", ix);
            usleep(1000*1000);
        }
    
        return 0;
    }
  • 相关阅读:
    Serialize&Deserialize
    Async&Await
    Generic
    Enum
    Array
    String
    Nullable
    Collection
    Class&Struct
    Interface
  • 原文地址:https://www.cnblogs.com/jyfyonghu/p/11218006.html
Copyright © 2020-2023  润新知