如何从模拟功能的限制,克服 [英] How to overcome from the limitation of mock functions

查看:128
本文介绍了如何从模拟功能的限制,克服的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以请帮我从下面给出的问题的解决?

Can anyone please help me to overcome from the problem given below?

定义为在同一个文件中的功能的包装(例如foo和bar,都在同一个文件 - foo.c的):

Define a wrapper for functions that are in the same file (e.g. foo and bar, both in the same file – foo.c):

由于2函数foo的()和b​​ar()在同一文件中,
汇编解决呼叫的连接器有机会来包装它__ wrap_bar前()

Since the 2 functions foo() and bar() in the same file, the assembler resolves the call before the linker has a chance to wrap it to __ wrap_bar()

作为--wrap =符号的手册页提
(您可能希望提供一个__real_malloc功能一样,所以,如果没有--wrap选项的链接也能成功。如果你这样做,你不应该把__real_malloc的定义在同一个文件为__wrap_malloc。如果你这样做,汇编器可能会解决呼叫的连接器有机会就换到malloc的前)。

As mention in the man page of --wrap=symbol (You may wish to provide a "__real_malloc" function as well, so that links without the --wrap option will succeed. If you do this, you should not put the definition of "__real_malloc" in the same file as "__wrap_malloc"; if you do, the assembler may resolve the call before the linker has a chance to wrap it to "malloc".)

功能foobar的()在bar.c文件中定义的,它是调用函数包裹__wrap_foo()和__wrap_bar()(包裹由连接器如预期)。

Function foobar() is defined in bar.c file and it is calling the wrapped functions __wrap_foo() and __wrap_bar() (wrapped as expected by the linker).

功能__wrap_foo()调用函数foo()和功能__wrap_bar()调用函数bar()

Function __wrap_foo() calls the function foo() and function __wrap_bar() calls function bar()

功能美孚()和bar()在foo.c的文件中定义。函数foo()调用函数bar()。

Functions foo() and bar() are defined in foo.c file. Function foo() calls the function bar().

这些调用给输出如下:

foobar的调用到foo()===>包装-富===>富打电话吧===>栏

foobar calling to foo() ===> wrap-foo ===> foo calling to bar ===> bar

foorbar打电话吧()===>总结吧===>栏

foorbar calling to bar() ===> wrap-bar ===> bar

虽然预期输出如下:

foobar的调用为foo()===>包装-富===>富打电话吧===>包裹吧===>栏

foobar calling to foo() ===> wrap-foo ===> foo calling to bar ===> wrap-bar ===> bar

foorbar打电话吧()===>总结吧===>栏

foorbar calling to bar() ===> wrap-bar ===> bar

请帮我解决这个问题。

感谢

推荐答案

名言:如果你这样做,汇编器可能会解决呼叫的连接器有机会来包装它之前的m​​alloc

Quote: "if you do, the assembler may resolve the call before the linker has a chance to wrap it to "malloc"

我觉得这个词可能是非常重要的。这并不是说会,但可能。我看这是你无法知道自己是否一件事或其他会发生的。这取决于你所使用的工具(编译器等)。

I think the word "may" is important. It does not say "will" but "may". I read this as "you can't know for sure whether one thing or the other will happen. It depends on the tools (compiler, etc.) you are using.

如果你提供code和工具链的信息,你会站在得到具体答案的一个更好的机会。

If you provide code and tool-chain information, you'll stand a better chance of getting specific answers.

这篇关于如何从模拟功能的限制,克服的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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