gmock:googlemock: g_gmock_implicit_sequence;通过名称无法判断其类型

// Points to the implicit sequence introduced by a living InSequence
// object (if any) in the current thread or NULL.
GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence;

这个类型的全局变量,会在get方法里申请heap的内存,以便自己使用,然后将这个内存地址放到thread local的变量。而且是一个全局变量,如果想在运行测试用例的时候加快运行,可以事调用get,提前申请内存。需要注意这个使用规则。

这个名称有些让人联系不上它的类型,所以下面的调用栈,初看的时候有些困扰。看gmock/gtest的时候需要注意。
google这个网站也是不能访问。

  T* GetOrCreateValue() const {
    
    
    ThreadLocalValueHolderBase* const holder =
        static_cast<ThreadLocalValueHolderBase*>(pthread_getspecific(key_));
    if (holder != nullptr) {
    
    
      return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
    }
    ValueHolder* const new_holder = default_factory_->MakeNewHolder(); /// 在这里申请,调用到libgmock里的函数
    ThreadLocalValueHolderBase* const holder_base = new_holder;
    GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));
    return new_holder->pointer();
  }
(gdb) bt
#0  0x00007ffff7bbd0a0 in testing::internal::ThreadLocal<testing::Sequence*>::DefaultValueHolderFactory::MakeNewHolder() const ()
   from /home/charleyc/sbc/obj/linux_x86-64/3rd/lib64/libgmock.so
#1  0x000000001020c11a in testing::internal::ThreadLocal<testing::Sequence*>::GetOrCreateValue (
    this=0x15561260 <testing::internal::g_gmock_implicit_sequence>) at ../obj/linux_x86-64/3rd/include/gtest/internal/gtest-port.h:2213
#2  0x000000001020c1a5 in testing::internal::ThreadLocal<testing::Sequence*>::pointer (this=<optimized out>) at ../obj/linux_x86-64/3rd/include/gtest/internal/gtest-port.h:2186
#3  0x000000001020c1b5 in testing::internal::ThreadLocal<testing::Sequence*>::get (this=<optimized out>)
    at ../obj/linux_x86-64/3rd/include/gtest/internal/gtest-port.h:2187
	
#4  0x000000001219198f in testing::internal::FunctionMockerBase<void (cpICR*, AF_DiamAvpSubscriptionId&)>::AddNewExpectation
(char const*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::tuple<testing::Matcher<cpICR*>, testing::Matcher<AF_DiamAvpSubscriptionId&> > const&)
 (this=0x7fffb3f17e88, file=file@entry=0x13275810 "/hom.cpp", line=line@entry=3964, source_text="EXPECT_CALL(*gmock_gld(_,_))", m=std::tuple containing = {
    
    ...}) at ../obj/linux_x86-64/3rd/include/gmock/gmock-spec-builders.h:1619
(gdb) disass
Dump of assembler code for function testing::internal::FunctionMockerBase<void (cpICR*, AF_DiamAvpSubscriptionId&)>::AddNewExpectation(char const*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::tuple<testing::Matcher<cpICR*>, testing::Matcher<AF_DiamAvpSubscriptionId&> > const&):
   0x0000000012191910 <+0>:     push   %rbp
   0x0000000012191911 <+1>:     mov    %rsp,%rbp
   0x0000000012191914 <+4>:     push   %r15
   0x0000000012191916 <+6>:     mov    %rcx,%r15
   0x0000000012191919 <+9>:     push   %r14
   0x000000001219191b <+11>:    mov    %edx,%r14d
   0x000000001219191e <+14>:    push   %r13
   0x0000000012191920 <+16>:    mov    %rsi,%r13
   0x0000000012191923 <+19>:    push   %r12
   0x0000000012191925 <+21>:    push   %rbx
   0x0000000012191926 <+22>:    mov    %rdi,%rbx
   0x0000000012191929 <+25>:    sub    $0x38,%rsp
   0x000000001219192d <+29>:    mov    %r8,-0x58(%rbp)
   testing::internal::UntypedFunctionMockerBase::MockObject() const
   0x0000000012191931 <+33>:    callq  0x1555dc90 <_ZNK7testing8internal25UntypedFunctionMockerBase10MockObjectEv@plt>
   0x0000000012191936 <+38>:    mov    %r14d,%edx
   0x0000000012191939 <+41>:    mov    %r13,%rsi
   0x000000001219193c <+44>:    mov    %rax,%rdi
   0x000000001219193f <+47>:    callq  0x1555ef70 <_ZN7testing4Mock31RegisterUseByOnCallOrExpectCallEPKvPKci@plt>
   0x0000000012191944 <+52>:    mov    $0x168,%edi
   0x0000000012191949 <+57>:    callq  0x12a2ebd0 <operator new(unsigned long)>
   0x000000001219194e <+62>:    mov    -0x58(%rbp),%r8
   0x0000000012191952 <+66>:    mov    %r14d,%ecx
   0x0000000012191955 <+69>:    mov    %r13,%rdx
   0x0000000012191958 <+72>:    mov    %rbx,%rsi
   0x000000001219195b <+75>:    mov    %rax,%rdi
   0x000000001219195e <+78>:    mov    %rax,%r12
   0x0000000012191961 <+81>:    mov    %r8,%r9
   0x0000000012191964 <+84>:    mov    %r15,%r8
   0x0000000012191967 <+87>:    callq  0x1218aaf0 <testing::internal::TypedExpectation<void (cpICR*, AF_DiamAvpSubscriptionId&)>::TypedExpectation(testing::internal::FunctionMockerBase<void (cpICR*, AF_DiamAvpSubscriptionId&)>*, char const*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::tuple<testing::Matcher<cpICR*>, testing::Matcher<AF_DiamAvpSubscriptionId&> > const&)>
   0x000000001219196c <+92>:    mov    %r12,%rsi
   0x000000001219196f <+95>:    lea    -0x50(%rbp),%rdi
   0x0000000012191973 <+99>:    callq  0x101ffec0 <testing::internal::linked_ptr<testing::internal::ExpectationBase>::linked_ptr(testing::internal::ExpectationBase*)>
   0x0000000012191978 <+104>:   lea    0x30(%rbx),%rdi
   0x000000001219197c <+108>:   lea    -0x50(%rbp),%rsi
   0x0000000012191980 <+112>:   callq  0x10210c80 <std::vector<testing::internal::linked_ptr<testing::internal::ExpectationBase>, std::allocator<testing::internal::linked_ptr<testing::internal::ExpectationBase> > >::push_back(testing::internal::linked_ptr<testing::internal::ExpectationBase> const&)>
   0x0000000012191985 <+117>:   mov    $0x15561260,%edi
   0x000000001219198a <+122>:   callq  0x1020c1b0 <testing::internal::ThreadLocal<testing::Sequence*>::get() const>

这个一个开源项目用的c++,那叫一个复杂。做个比喻,不知合不合适。说美国当年登月,后来过了多半个世纪,后来者还没居上,美国自己都被甩后边,没再重拾月球计划。

猜你喜欢

转载自blog.csdn.net/qq_36428903/article/details/131219429