bramante@matrix:~/test$ gcc -g -o ./test ./test.c
bramante@matrix:~/test$ gdb --batch --command=gdb.cmds --args ./test 3
Breakpoint 1 at 0x40058f: file ./test.c, line 7.
Breakpoint 1, test (arg=0) at ./test.c:7
7 printf("@test(arg:%d)\n",arg);
arg = 0
@test(arg:0)
main (argc=2, argv=0x7fffffffe5b8) at ./test.c:20
20 sleep(1);
Value returned is $1 = 0
Breakpoint 1, test (arg=1) at ./test.c:7
7 printf("@test(arg:%d)\n",arg);
arg = 1
@test(arg:1)
main (argc=2, argv=0x7fffffffe5b8) at ./test.c:20
20 sleep(1);
Value returned is $2 = 1
Breakpoint 1, test (arg=2) at ./test.c:7
7 printf("@test(arg:%d)\n",arg);
arg = 2
@test(arg:2)
main (argc=2, argv=0x7fffffffe5b8) at ./test.c:20
20 sleep(1);
Value returned is $3 = 2
[Inferior 1 (process 2986) exited normally]
bramante@matrix:~/test$
可以看到test()被執行了3次, 它的return value都被gdb給印了出來.
前面所用到的gdb.cmds檔案的內容如下:
gdb.cmds
12345678910111213
b test
define printFuncInfo
info args
finish
continue
end
commands 1
printFuncInfo
end
run