glog库正在为stacktrace中的某些堆栈帧打印(unknown)
。
我在使用标准18.04
包的Ubuntu libgoogle-glog-dev
上:
$ cat > t.cc
#include <glog/logging.h>
void h() { LOG(FATAL) << "test"; }
void g() { h(); }
void f() { g(); }
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
f();
}
^D
上面的程序在编译的时候...
$ g++ t.cc -lglog
...然后跑...
$ ./a.out
...输出以下内容:
F1219 13:54:46.608317 13408 t.cc:3] test
*** Check failure stack trace: ***
@ 0x7f90ddd970cd google::LogMessage::Fail()
@ 0x7f90ddd98f33 google::LogMessage::SendToLog()
@ 0x7f90ddd96c28 google::LogMessage::Flush()
@ 0x7f90ddd99999 google::LogMessageFatal::~LogMessageFatal()
@ 0x56279a0a7b30 (unknown)
@ 0x56279a0a7b45 (unknown)
@ 0x56279a0a7b51 (unknown)
@ 0x56279a0a7b77 (unknown)
@ 0x7f90dd632b97 __libc_start_main
@ 0x56279a0a79fa (unknown)
Aborted (core dumped)
查看带有
(unknown)
的框架-我希望他们阅读main
,f
,g
,h
我尝试添加
-rdynamic
,但是我仍然观察到相同的行为: $ g++ t.cc -lglog -rdynamic
我尝试添加
-g
,但是我仍然观察到相同的行为: $ g++ t.cc -lglog -o t -g -rdynamic
最佳答案
我只是尝试过,它对我有用。
在堆栈跟踪中显示了可以看到h(),g(),f()的结果。
F1219 16:20:16.171772 20931 main.cpp:2] test
*** Check failure stack trace: ***
@ 0x7f951ee03e6d (unknown)
@ 0x7f951ee05ced (unknown)
@ 0x7f951ee03a5c (unknown)
@ 0x7f951ee0663e (unknown)
@ 0x40089a h()
@ 0x4008af g()
@ 0x4008bb f()
@ 0x4008e1 main
@ 0x7f951e22e3d5 __libc_start_main
@ 0x4007a9 (unknown)
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
这是我的CMakeLists.txt文件
cmake_minimum_required(VERSION 3.13)
project(test_glog)
set(CMAKE_CXX_STANDARD 14)
include_directories(/usr/include)
link_libraries(glog)
add_executable(test_glog main.cpp)
当我编译时扩展为:
我在CentOS 7上并安装了以下库:
yum install glog-devel gflags-devel
这是我的构建方法:
[user@cent1 build]$ make VERBOSE=1
/usr/bin/cmake3 -H/home/user/CLionProjects/test_glog -B/home/user/CLionProjects/test_glog/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake3 -E cmake_progress_start /home/user/CLionProjects/test_glog/build/CMakeFiles /home/user/CLionProjects/test_glog/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/user/CLionProjects/test_glog/build'
make -f CMakeFiles/test_glog.dir/build.make CMakeFiles/test_glog.dir/depend
make[2]: Entering directory `/home/user/CLionProjects/test_glog/build'
cd /home/user/CLionProjects/test_glog/build && /usr/bin/cmake3 -E cmake_depends "Unix Makefiles" /home/user/CLionProjects/test_glog /home/user/CLionProjects/test_glog /home/user/CLionProjects/test_glog/build /home/user/CLionProjects/test_glog/build /home/user/CLionProjects/test_glog/build/CMakeFiles/test_glog.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/user/CLionProjects/test_glog/build'
make -f CMakeFiles/test_glog.dir/build.make CMakeFiles/test_glog.dir/build
make[2]: Entering directory `/home/user/CLionProjects/test_glog/build'
[ 50%] Building CXX object CMakeFiles/test_glog.dir/main.cpp.o
/opt/rh/devtoolset-7/root/usr/bin/c++ -std=gnu++14 -o CMakeFiles/test_glog.dir/main.cpp.o -c /home/user/CLionProjects/test_glog/main.cpp
[100%] Linking CXX executable test_glog
/usr/bin/cmake3 -E cmake_link_script CMakeFiles/test_glog.dir/link.txt --verbose=1
/opt/rh/devtoolset-7/root/usr/bin/c++ CMakeFiles/test_glog.dir/main.cpp.o -o test_glog -lglog
make[2]: Leaving directory `/home/user/CLionProjects/test_glog/build'
[100%] Built target test_glog
make[1]: Leaving directory `/home/user/CLionProjects/test_glog/build'
/usr/bin/cmake3 -E cmake_progress_start /home/user/CLionProjects/test_glog/build/CMakeFiles 0
更新:
我在虚拟机中安装Debian ubuntu-18.04.1-desktop-amd64.iso并从源代码构建glog。您的示例现在显示:
$ ./a.out
F0102 23:54:15.603329 10358 t.cc:2] test
*** Check failure stack trace: ***
@ 0x55c930b28d2c google::LogMessage::Fail()
@ 0x55c930b28c74 google::LogMessage::SendToLog()
@ 0x55c930b285b5 google::LogMessage::Flush()
@ 0x55c930b2be66 google::LogMessageFatal::~LogMessageFatal()
@ 0x55c930b25820 google::thread_msg_data
@ 0x55c930b25835 google::thread_msg_data
@ 0x55c930b25841 google::thread_msg_data
@ 0x55c930b25867 google::thread_msg_data
@ 0x7ff9fbf2eb97 __libc_start_main
@ 0x55c930b256ea google::thread_msg_data
@ (nil) (unknown)
Aborted (core dumped)
我可以看到我们无力解决此问题,因此我建议您打开一个问题
博客。
https://github.com/google/glog/pull/347/commits/26459400f49850bda8e736882c6f22c2ce766761
我还尝试直接从命令链接构建它并显示设置。
不知道glog库的build设置是否会有所作为。
$ g++ t.cc -lglog --verbose
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.3.0-27ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/7/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE t.cc -quiet -dumpbase t.cc -mtune=generic -march=x86-64 -auxbase t -version -fstack-protector-strong -Wformat -Wformat-security -o /tmp/ccoFCYTb.s
GNU C++14 (Ubuntu 7.3.0-27ubuntu1~18.04) version 7.3.0 (x86_64-linux-gnu)
compiled by GNU C version 7.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/7"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/7
/usr/include/x86_64-linux-gnu/c++/7
/usr/include/c++/7/backward
/usr/lib/gcc/x86_64-linux-gnu/7/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C++14 (Ubuntu 7.3.0-27ubuntu1~18.04) version 7.3.0 (x86_64-linux-gnu)
compiled by GNU C version 7.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 1bfae38ae5df64de6196cbd8c3b07d86
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
as -v --64 -o /tmp/ccvUzQBB.o /tmp/ccoFCYTb.s
GNU assembler version 2.30 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.30
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/7/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/7/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper -plugin-opt=-fresolution=/tmp/ccNEOWk1.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --sysroot=/ --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/7 -L/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/7/../../.. /tmp/ccvUzQBB.o -lglog -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
这是我运行它时的输出:
$ ./a.out
F0106 12:07:11.753652 28547 t.cc:2] test
*** Check failure stack trace: ***
@ 0x55c500dedd2c google::LogMessage::Fail()
@ 0x55c500dedc74 google::LogMessage::SendToLog()
@ 0x55c500ded5b5 google::LogMessage::Flush()
@ 0x55c500df0e66 google::LogMessageFatal::~LogMessageFatal()
@ 0x55c500dea820 google::thread_msg_data
@ 0x55c500dea835 google::thread_msg_data
@ 0x55c500dea841 google::thread_msg_data
@ 0x55c500dea867 google::thread_msg_data
@ 0x7f882d938b97 __libc_start_main
@ 0x55c500dea6ea google::thread_msg_data
@ (nil) (unknown)
Aborted (core dumped)
更新2 :
一位博客开发人员Evgeny Prigorodov一直在调查问题,并确定了问题所在。我相信这个问题将很快得到解决。
所以这是a93a451之后src/symbolize.cc中发生的情况:
堆栈跟踪中的每一行都在函数SymbolizeAndDemangle()中准备。
它计算变量start_address/base_address并调用函数GetSymbolFromObjectFile(),该函数尝试查找与给定帧指令指针(pc)相对应的符号。
在v0.3.4中,对GetSymbolFromObjectFile()的调用传递了start_address的值,该值是一个内存区域的起始地址,永远不能为零。 GetSymbolFromObjectFile()不会检查start_address的值,只是将其用于两个符号表中的查找。
在v0.3.5中,对GetSymbolFromObjectFile()的调用开始传递base_address的值。如果在最开始的存储区域中找到了帧程序计数器,并且已将可执行镜像映射为零偏移量,则该值可以变为零。这似乎是一种常见的情况。
GetSymbolFromObjectFile()中的另一个更改添加了用于符号偏移量调整的代码和新的检查:如果在所有调整后symbol_offset等于零,则该函数将返回失败值,表示“未找到符号”。由于然后从base_address计算了symbol_offset变量,因此该条件变得很有可能。
有关详细信息,请访问see。
关于c++ - glog库(Google日志)在stacktrace中打印出 `(unknown)`?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53844443/