mian.c
tom@ubuntu:~/dvp$ cat -n main.c
1 #include <stdio.h>
2
3 typedef struct
4 {
5 int iW;
6 int iH;
7 int iX;
8 int iY;
9 }BOX_ST;
10
11 int main()
12 {
13 BOX_ST stBox;
14
15 stBox.iW = 1;
16 stBox.iH = 2;
17 stBox.iX = 3;
18 stBox.iY = 4;
19
20 return 0;
21 }
tom@ubuntu:~/dvp$
gdb腳本(使用arg0 arg1,.....)
使用arg0 arg1 arg2, ....等可變參數來代表輸入的任意名稱的數據結構對象
tom@ubuntu:~/dvp$ cat -n gdbcmd_printBOX_ST.txt
1 define print_stBox
2 print $arg0
3 end
tom@ubuntu:~/dvp$
使用gdb腳本
(gdb) file ./a.out
Reading symbols from ./a.out...done.
(gdb) list main
7 int iX;
8 int iY;
9 }BOX_ST;
10
11 int main()
12 {
13 BOX_ST stBox;
14
15 stBox.iW = 1;
16 stBox.iH = 2;
(gdb) l
17 stBox.iX = 3;
18 stBox.iY = 4;
19
20 return 0;
21 }
(gdb) break 20
Breakpoint 1 at 0x4004f6: file main.c, line 20.
(gdb) source gdbcmd_printBOX_ST.txt
(gdb) print
print print-object print_stbox printf
(gdb) run
Starting program: /home/tom/dvp/a.out
Breakpoint 1, main () at main.c:20
20 return 0;
(gdb) print_stbox stBox
$1 = {iW = 1, iH = 2, iX = 3, iY = 4}
(gdb)
《完》