在 bash 中捕获线程转储

Capture thread dump in bash

本文关键字:线程 转储 bash      更新时间:2023-10-16

我的命令失败了,我认为是线程转储或其他东西。由于我想检查,我想将输出重定向到文件或更少。但是输出似乎不在标准或标准输出上?!如何捕获此输出?

7f47efcda000-7f47efcdb000 r--p 00000000 fc:00 174138                     /usr/lib/libgtest_main.so.0.0.0
7f47efcdb000-7f47efcdc000 rw-p 00001000 fc:00 174138                     /usr/lib/libgtest_main.so.0.0.0
7f47efcdc000-7f47efd25000 r-xp 00000000 fc:00 174141                     /usr/lib/libgtest.so.0.0.0
7f47efd25000-7f47eff25000 ---p 00049000 fc:00 174141                     /usr/lib/libgtest.so.0.0.0
7f47eff25000-7f47eff26000 r--p 00049000 fc:00 174141                     /usr/lib/libgtest.so.0.0.0
7f47eff26000-7f47eff27000 rw-p 0004a000 fc:00 174141                     /usr/lib/libgtest.so.0.0.0
7f47eff27000-7f47eff28000 rw-p 00000000 00:00 0
7f47eff28000-7f47eff4e000 r-xp 00000000 fc:00 899                        /lib/x86_64-linux-gnu/ld-2.23.so
7f47f00c6000-7f47f00e2000 rw-p 00000000 00:00 0
7f47f00e2000-7f47f0100000 r-xp 00000000 fc:00 422                        /lib/x86_64-linux-gnu/libudev.so.1.6.4
7f47f0100000-7f47f0101000 r--p 0001d000 fc:00 422                        /lib/x86_64-linux-gnu/libudev.so.1.6.4
7f47f0101000-7f47f0102000 rw-p 0001e000 fc:00 422                        /lib/x86_64-linux-gnu/libudev.so.1.6.4
7f47f0102000-7f47f0132000 rw-p 00000000 00:00 0
7f47f014c000-7f47f014d000 rw-p 00000000 00:00 0
7f47f014d000-7f47f014e000 r--p 00025000 fc:00 899                        /lib/x86_64-linux-gnu/ld-2.23.so
7f47f014e000-7f47f014f000 rw-p 00026000 fc:00 899                        /lib/x86_64-linux-gnu/ld-2.23.so
7f47f014f000-7f47f0150000 rw-p 00000000 00:00 0
7ffca7f25000-7ffca7f46000 rw-p 00000000 00:00 0                          [stack]
7ffca7f84000-7ffca7f86000 r--p 00000000 00:00 0                          [vvar]
7ffca7f86000-7ffca7f88000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
2/2 Test #2: subscriberSkeleton_gtest .........***Exception: Other  0.03 sec
0% tests passed, 2 tests failed out of 2
Total Test time (real) =   0.07 sec

我尝试了make test 2> file的变化,make test 2>&1 | less,这些只输出最后一行,而不是转储。

有问题的代码就是这样:

#include <gtest/gtest.h>
int main(int argc, char **argv) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}       

使该程序失败的问题是它与OpenCV链接在一起,OpenCV包含一个与GTest冲突的测试组件opencv_ts。有相同问题的人的博客文章。我知道如何解决这个问题,但为什么我无法捕获错误产生的输出感到困惑。

这可能是glibc产生输出,例如当你有double-free((s时。 设置以下环境变量可能会有所帮助: LIBC_FATAL_STDERR_=1 (然后输出将在 STDERR 中。

但是,对于您粘贴的输出,这也可能是内核输出,它独立于您的程序发生。