GDB脚本到MOCK [英] GDB scripting to MOCK

查看:228
本文介绍了GDB脚本到MOCK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用GDB来模拟一个函数(用于单元测试父函数)。一种方法是设置一个你打算使用GDB 返回命令的功能的断点。

I am trying to mock a function (for unit testing parent function) using GDB. One way to do it would be to set a break point in function you intend to mock and use GDB return command.

但是我无法当使用GDB 调用命令时,执行相同操作。

However I am unable to do the same when GDB call command is used.


(gdb) b secret_check
Breakpoint 1 at 0x80483ba: file ut_gdb.c, line 6.
(gdb) start
Temporary breakpoint 2 at 0x804843c: file ut_gdb.c, line 34.
Starting program: ut.bin
Temporary breakpoint 2, main () at ut_gdb.c:34
34          int res = 0;
(gdb) bt
#0  main () at ut_gdb.c:34
(gdb) call fact(3)
Breakpoint 1, secret_check (check_type=1) at ut_gdb.c:6
6               if(check_type == 0){
The program being debugged stopped while in a function called from GDB.
Evaluation of the expression containing the function
(fact) will be abandoned.
When the function is done executing, GDB will silently stop.
(gdb) bt
#0  secret_check (check_type=1) at ut_gdb.c:6
#1  0x080483ff in fact (n=3) at ut_gdb.c:19
#2  
#3  main () at ut_gdb.c:34

GDB中是否有限制?

Is it a limitation in GDB ?

推荐答案

我希望如此。限制可能是GDB不能一次停止(并能够继续)两个断点。 GDB必须保持关于程序停止的当前位置的信息,以便能够继续。为了支持你想要做的事情,它需要保持一堆继续的状态,并且有一些能力来指定你要继续从哪一个。

I would expect so. The limitation is probably that GDB cannot be stopped at (and able to continue from) two breakpoints at once. GDB has to maintain information about the current point where the program stopped in order to be able to continue. In order to support what you're trying to do, it would need to maintain a stack of "continue" states, and have some ability for you to specify which one you want to continue from.

这篇关于GDB脚本到MOCK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆