我正在尝试调试流程,我正在尝试使用-finstrument-functions编译器选项。我已成功编写了以下方法并创建了 trace.o 目标文件:
void __cyg_profile_func_enter(void* this_fn, void* call_site)
__attribute__((no_instrument_function));
void __cyg_profile_func_exit(void* this_fn, void* call_site)
__attribute__((no_instrument_function));
它适用于示例代码,我从文件中获取函数地址,从中我可以提取文件:函数名称。
在我们的项目代码中有大约1500个文件,所以我在CMakeLists.txt文件中添加了以下代码:
SET(GCC_COVERAGE_COMPILE_FLAGS "-finstrument-functions")
add_definitions(${GCC_COVERAGE_COMPILE_FLAGS})
以上配置确保我的所有源代码文件都使用-finstrument-functions编译器标志进行编译。
为确保我链接 trace.o 文件,我正在尝试以下方法:
SET(OBJS
/c/work/trace.o #path to trace.o in my system
)
SET_SOURCE_FILES_PROPERTIES(
${OBJS}
PROPERTIES
EXTERNAL_OBJECT true
GENERATED true
)
但在编译我的项目代码时,我得到以下错误:
Test.cpp.obj: In function `cc::cppx::cMethod(int, int*, int&)':
Test.cpp:16: undefined reference to `__cyg_profile_func_enter'
Test.cpp:17: undefined reference to `__cyg_profile_func_exit'
Test.cpp.obj: In function `__gthread_active_p':
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/x86_64-w64-mingw32/bits/gthr-default.h:304: undefined reference to `__cyg_profile_func_enter'
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/x86_64-w64-mingw32/bits/gthr-default.h:304: undefined reference to `__cyg_profile_func_exit'
Test.cpp.obj: In function `__exchange_and_add_single':
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/ext/atomicity.h:66: undefined reference to `__cyg_profile_func_enter'
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/ext/atomicity.h:68: undefined reference to `__cyg_profile_func_exit'
Test.cpp.obj: In function `forward<cc::cppx::TestInvoke_lambda_with_args_byvalue_ptr_ref_Test::TestBody()::<lambda(int, int*, int&)>&>':
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/bits/move.h:76: undefined reference to `__cyg_profile_func_enter'
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/bits/move.h:76: undefined reference to `__cyg_profile_func_exit'
Test.cpp.obj: In function `operator()':
Test.cpp:54: undefined reference to `__cyg_profile_func_enter'
Test.cpp:56: undefined reference to `__cyg_profile_func_exit'
Test.cpp.obj: In function `__exchange_and_add':
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/ext/atomicity.h:49: undefined reference to `__cyg_profile_func_enter'
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/ext/atomicity.h:49: undefined reference to `__cyg_profile_func_exit'
Test.cpp.obj: In function `__tcf_0':
我正在努力寻找如何实现我的目标的方法,但它没有对问题进行排序 - 是否可以设置相同的方法?