Open klaushhp opened 1 year ago
环境
x86_64
4.4.0-19041-Microsoft
commit 55db580faa82ef98882a97dfc9a6424b91733a35
ubuntu 22.04 gcc 12.1.0 出现同样的问题
at /home/robin/.cache/bazel/_bazel_robin/389f81c4c4ae302f3b55a547146dfe65/sandbox/linux-sandbox/20/execroot/gs_map/external/emock/src/JmpOnlyApiHook.cpp:57
at /home/robin/.cache/bazel/_bazel_robin/389f81c4c4ae302f3b55a547146dfe65/sandbox/linux-sandbox/20/execroot/gs_map/external/emock/src/JmpOnlyApiHook.cpp:63
trampoline=0x0, api=0x4a5a6, this=0x55555563ed50)
at /home/robin/.cache/bazel/_bazel_robin/389f81c4c4ae302f3b55a547146dfe65/sandbox/linux-sandbox/20/execroot/gs_map/external/emock/src/JmpOnlyApiHook.cpp:44
stub=stub@entry=0x55555559fa56 <emock::ApiHookFunctor<int (MyUsing*, int, int), 10u>::hook(MyUsing*, int, int)>)
at /home/robin/.cache/bazel/_bazel_robin/389f81c4c4ae302f3b55a547146dfe65/sandbox/linux-sandbox/20/execroot/gs_map/external/emock/src/JmpOnlyApiHook.cpp:91
stub=0x55555559fa56 <emock::ApiHookFunctor<int (MyUsing*, int, int), 10u>::hook(MyUsing*, int, int)>, trampoline=0x0, api=0x4a5a6, this=0x55555563ed30)
at /home/robin/.cache/bazel/_bazel_robin/389f81c4c4ae302f3b55a547146dfe65/sandbox/linux-sandbox/20/execroot/gs_map/external/emock/src/ApiHook.cpp:34
stub=stub@entry=0x55555559fa56 <emock::ApiHookFunctor<int (MyUsing*, int, int), 10u>::hook(MyUsing*, int, int)>)
at /home/robin/.cache/bazel/_bazel_robin/389f81c4c4ae302f3b55a547146dfe65/sandbox/linux-sandbox/20/execroot/gs_map/external/emock/src/ApiHook.cpp:50
isMemFun=isMemFun@entry=true)
at /home/robin/.cache/bazel/_bazel_robin/389f81c4c4ae302f3b55a547146dfe65/sandbox/linux-sandbox/20/execroot/gs_map/external/emock/src/ApiHookKey.cpp:39
ns=0x555555626060 <emock::GlobalMockObject::instance>, ns@entry=0x55555563bed0, isMemFun=<optimized out>)
at /home/robin/.cache/bazel/_bazel_robin/389f81c4c4ae302f3b55a547146dfe65/sandbox/linux-sandbox/20/execroot/gs_map/external/emock/src/HookMockObject.cpp:88
ns=0x55555563bed0, isMemFun=<optimized out>)
at /home/robin/.cache/bazel/_bazel_robin/389f81c4c4ae302f3b55a547146dfe65/sandbox/linux-sandbox/20/execroot/gs_map/external/emock/src/HookMockObject.cpp:110
--Type
代码:
class MyUsing { public: int Add(int a, int b) { return a + b; } };
class MyRunner { public: int Run(int a) { MyUsing my; return my.Add(a, a * a); } };
int add_stub(int a, int b) { return a+b; }
class MyRunnerTest : public testing::Test { public: protected: virtual void SetUp(){}; void TearDown() override{}; };
TEST_F(MyRunnerTest, TestRun) { MyRunner my; EMOCK(&MyUsing::Add) .stubs() .will(returnValue(2)); EXPECT_EQ(2, my.Run(1)); }
int main(int argc, char *argv[]) { printf("Running main() from %s\n", FILE); testing::InitGoogleTest(&argc, argv); // ros::init(argc, argv, "gs_map_test");
return RUN_ALL_TESTS(); }
查了一下, u.p = SymbolRetriever::getMethodAddress(u.p, typeid(api), name);\ 这个函数取得的函数地址只有5五位数,非真正有效的内存地址,所以 memcpy直接挂了。
我也遇到同样的问题,根本不能用啊,这个还没有解决吗?
Program received signal SIGSEGV, Segmentation fault. __memmove_avx_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:312 312 ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S: No such file or directory. (gdb) bt
0 __memmove_avx_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:312
1 0x000000000812ffae in emock::JmpOnlyApiHook::JmpOnlyApiHook(void const, void const, void const*) ()
2 0x000000000812c5b6 in emock::ApiHook::ApiHook(void const, void const, void const*) ()
3 0x000000000812c287 in emock::ApiHookKey::ApiHookKey(void const, emock::ApiHookHolder, bool) ()
4 0x000000000812be27 in emock::HookMockObjectImpl::addMethod(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, void const, emock::ApiHookHolder, emock::InvocationMockerNamespace*, bool) ()
5 0x000000000812c005 in emock::HookMockObject::method(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, void const, emock::ApiHookHolder, bool) ()
6 0x00000000080aaa81 in emock::InvocationMockBuilderGetter emock::mockAPI<void, Foo, int>(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, void (Foo::*)(int)) ()
7 0x00000000080a95f6 in member_func_ut_member_func_Test::TestBody() ()
8 0x00000000080f85b6 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test, void (testing::Test::)(), char const*) ()
9 0x00000000080f0349 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test, void (testing::Test::)(), char const*) ()
10 0x00000000080ca286 in testing::Test::Run() ()
11 0x00000000080cad55 in testing::TestInfo::Run() ()
12 0x00000000080cb72b in testing::TestSuite::Run() ()
13 0x00000000080db6b6 in testing::internal::UnitTestImpl::RunAllTests() ()
14 0x00000000080f9beb in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl, bool (testing::internal::UnitTestImpl::)(), char const*) ()
15 0x00000000080f1657 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl, bool (testing::internal::UnitTestImpl::)(), char const*) ()
16 0x00000000080d9cb0 in testing::UnitTest::Run() ()
17 0x00000000080a9e70 in RUN_ALL_TESTS() ()
18 0x00000000080a9754 in main ()
(gdb)