gdb MI命令中文
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
GDB MI的命令总共分为以下几个部分:
1.断点(Breakpoint)
2.程序环境(Program Context)
3.线程(Thread)
4.程序执行(Program Execution)
5.栈(Stack)
6.变量(Variable)
7.数据(Data)
8.跟踪点(Tracepoint)
9.符号(Symbol)
10.文件(File)
11.目标数据(Target Manipulation)
12.其它杂项
我们以下面这段代码为例演示各种命令的执行结果:
/*
** demo.c
*/
#include
int swap(int a[], int len)
{
int i;
int temp;
for(i = 0; i < len / 2; i++)
{
temp = a[i];
a[i] = a[len - i - 1];
a[len - i - 1] = temp;
}
return 0;
}
int main()
{
int array[10];
int i;
for(i = 0; i < 10; i++)
array[i] = i;
printf("swap before:");
for(i = 0; i < 10; i++)
printf("%d ", array[i]);
printf(" \n");
swap(array, 10);
printf("swap after:");
for(i = 0; i < 10; i++)
printf("%d ", array[i]);
printf(" \n");
return 0;
}
执行gcc -g demo.c -o demo.exe编译。
具体详细的命令还请大家看gdb手册,下面一一介绍:1.断点
-break-after
用法:-break-after number count
语义:第number个断点在被执行count次后有效
-break-condition
用法:-break-condition number expr
语义:第number个断点在表达式expr为true时有效
-break-delete
用法:-break-delete ( breakpoint number )+
语义:删除指定number 的多个断点
-break-disable
用法:-break-disable ( breakpoint number)+
语义:使指定number的多个断点失效
-break-enable
用法:-break-enable ( breakpoint number)+
语义:使指定number的多个断点起效
-break-info
用法:-break-info breakpoint
语义:得到指定断点的信息
-break-insert
用法:
-break-insert [ -t ] [ -h ] [ -r ]
[ -c condition ] [ -i ignore-count ]
[ -p thread ] [ line | addr ]
语义:-t 插入一个临时断点
-h 插于一个硬件端点
-r 插入一个正则断点,当函数名匹配正则表达式时有效
-c 插入一个条件断点
-i 插入一个指定无效次数的断点
如果指定了line选项,可以使用如下格式:
函数
文件名:行号
文件名:函数
地址
-break-list
用法:-break-list
语义:先是已插入断点的列表
-break-watch
用法:-break-watch [ -a | -r ] variable
语义:创建一个观察点,-a表示对variable读写时有效,-r表示只读时有效运行效果:
(gdb)
-break-insert main
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0040 10f
6",func="main",file="demo.c",line="23",times="0"}
(gdb)
-break-insert 28
^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="0x0040 110
8",func="main",file="demo.c",line="28",times="0"}
(gdb)
-break-list
^done,BreakpointTable={nr_rows="2",nr_cols="6",hdr=[{width="3",alignment="-1", co
l_name="number",colhdr="Num"},{width="14",alignment="-1",col_name="type",col hdr=
"Type"},{width="4",alignment="-1",col_name="disp",colhdr="Disp"},{width="3",ali g
nment="-1",col_name="enabled",colhdr="Enb"},{width="10",alignment="-1",col_na me=
"addr",colhdr="Address"},{width="40",alignment="2",col_name="what",colhdr="W hat"
}],body=[bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0 040
10f6",func="main",file="demo.c",line="23",times="0"},bkpt={number="2",type="br ea
kpoint",disp="keep",enabled="y",addr="0x00401108",func="main",file="demo.c",lin e
="28",times="0"}]}
(gdb)
-exec-run
^running
(gdb)
*stopped,reason="breakpoint-hit",bkptno="1",thread-id="1",frame={addr="0x004010 f
6",func="main",args=[],file="demo.c",line="23"}
(gdb)
-exec-continue
^running
(gdb)
*stopped,reason="breakpoint-hit",bkptno="2",thread-id="1",frame={addr="0x004011 0
8",func="main",args=[],file="demo.c",line="28"}
(gdb)