天天看點

mockcpp的so加載失敗問題

mockcpp的so加載失敗問題

一、先來看之前已解決的六個so無法加載的問題。

把libmockcpp-ut-TestReturnObjectList.so拿來做例子研究so加載問題。

加載成功時的預處理後的.cpp,編譯産生的.o.sym/asm,最後的.so.sym

加載不成功時的同樣檔案。

指令如下:

擷取預處理檔案:

/usr/bin/c++ -Dmockcpp_ut_TestChainableMockMethod_EXPORTS -DPACKAGE_NAME=\"mockcpp\" -DPACKAGE_STRING=\"mockcpp\" -DPACKAGE_BUGREPORT=\"[email protected]\" -DPACKAGE_URL=\"http://code.google.com/p/mockcpp\" -DPACKAGE=\"mockcpp\" -DVERSION=\"2.4\" -fPIC -I/home/jelly/Programming/mockcpp_svn_r/mockcpp/mockcpp/tests/3rdparty/testngpp/include -I/home/jelly/Programming/mockcpp_svn_r/mockcpp/mockcpp/tests/../3rdparty -I/home/jelly/Programming/mockcpp_svn_r/mockcpp/mockcpp/tests/../include -I/home/jelly/Programming/mockcpp_svn_r/mockcpp/mockcpp/tests/ut/. -o AAAAAA.d -E /home/jelly/Programming/mockcpp_svn_r/mockcpp/mockcpp/tests/ut/TestReturnObjectList.cpp

擷取反彙編檔案:

objdump -D xxxx.o

擷取so的符号表:

nm -D xxx.so

1、預處理檔案差異。

2、nm so檔案差異。

根據上面情況,已經能看出是result符号連結不到所緻。也許編譯器認為extern的一個const變量應該有一個變量實體與它對應。

由此,這個問題可以修改如下:(把有差異的兩行代碼改為下面這樣)

const Any& result2 = Any();

return getResult(result2, resultProvider);

果然編譯連結通過,用例也都運作通過。

二、再來看TestApiHook.so加載不成功的問題。

它從來都沒有被加載成功過,定位難度較大。

查找.o的方法:

jelly@jelly-linux:~/Programming/mockcpp/build_tests/ut/CMakeFiles/TestApiHook.dir$ find .. -name "TestApiHook.cpp.o"

../mockcpp-ut-TestApiHook.dir/TestApiHook.cpp.o

注釋掉兩行,加載成功,運作時段錯誤:

SETUP()

{

MOCKER(func)

.expects(once());

//.with(eq(a), eq(b))

//.will(returnValue(ret));

}

(TestApiHook)

./build.sh: line 18: 9062 段錯誤 ../../build_testngpp/src/runner/testngpp-runner $(ls *.so) -L"../../build_testngpp/src/listeners" -l"testngppstdoutlistener -c -f"

而且,偶然發現,下面有用例也用到with,will,怎麼SETUP中用到就加載失敗呢。

--------------------------------

比較下面一處with/will與上面的差異,隻不過上面用了static const int 變量。

于是,把它們改為普通成員變量,果然加載成功了。但有段錯誤問題:./build.sh: line 18: 10109 段錯誤

--- tests/ut/TestApiHook.h (版本 434)

+++ tests/ut/TestApiHook.h (工作副本)

@@ -36,12 +36,15 @@

FIXTURE(ApiHook)

- static const int a = 3;

- static const int b = 5;

- static const int ret = 10;

+ int a;

+ int b;

+ int ret;

SETUP()

+ a = 3;

+ b = 5;

+ ret = 10;

MOCKER(func)

.expects(once())

.with(eq(a), eq(b))

-------------------------------------

現在就隻是還有段錯誤問題。