【GDB】 command command

GDB command command

grammar

The command command is a very useful debugging command. It is used with breakpoints and can execute preset commands at the specified breakpoints.

The syntax is: command bread_id, which will prompt you to enter the command you want to execute, ending with end. This bread_id is the result printed by info b, which is actually the breakpoint serial number that has been set currently.

.gdbinitThe file contains the following content

layout src

b main
b binary_search if target == 5

# 断点 1 触发执行的命令
command 1
i locals # 显示局部变量
i args # 显示参数
end

# 断点 2 触发执行的命令
comm 2
i locals # 显示局部变量
i args # 显示参数
end

# 自定义一个 print-tyustli 命令
define print-tyustli
    echo hello, world\n
end

# 自定义命令 print-tyustli 的帮助文档
document print-tyustli
    usage: print-list LIST NODE_TYPE NEXT_FIELD [COUNT]
    打印 tyustli

    data:   2023-09-27
    author: tyustli
end

Two breakpoints are set above b mainandb binary_search if target == 5

The command is set at breakpoint 1

command 1
i locals
i args
end

Set the command at breakpoint 2

comm 2
i locals
i args
end

Command commands have been added to both breakpoints. When the breakpoint is triggered, these commands will be executed. The advantage of this is that there is no need to manually type c to continue executing the program, which is convenient for debugging.

Example

Insert image description here
Insert image description here

reference

https://blog.csdn.net/tianyexing2008/article/details/129673247

Guess you like

Origin blog.csdn.net/tyustli/article/details/133414423