gtest:放置gdb断点的位置
gtest: where to put gdb breakpoint
多年来我一直在使用各种 xunit 测试(从 2000 年代初期的 cppunit 开始)。在所有情况下,在失败时设置断点都非常容易:有一个函数指示检测到的失败:
b 'atf::tests::tc::fail(std::string const&)'
命令
向上 1
结束
gtest好像不太一样,gtest的惯例是什么?
what is the established practice of doing the same with gtest?
阅读 gtest.cc
,我看到的最接近的是 --gunit_break_on_failure
,这应该会导致代码在 x86/Linux 上执行 INT3
陷阱,并调用 DebugBreak
在 Windows.
更新: 在最新的 public 版本中,该标志似乎已重命名为 --gtest_break_on_failure
。
如果您需要在测试开始时中断以观察某些内容,请先 get the symbol names present in the executable,然后 grep 获取感兴趣的测试名称,例如:
nm -C myclass_test | grep MyTest0
如果你想休息:
TEST(MainTest, MyTest0) {
EXPECT_EQ(1, 1);
}
在该 grep 的结果中,最有希望的结果似乎是:
0000000000407c64 T MainTest_MyTest0_Test::TestBody()
等等:
gdb myclass_test
和:
b MainTest_MyTest0_Test::TestBody
r
然后这让我处于所需测试的开始。
在修订版 2 中测试 with this setup。
多年来我一直在使用各种 xunit 测试(从 2000 年代初期的 cppunit 开始)。在所有情况下,在失败时设置断点都非常容易:有一个函数指示检测到的失败:
b 'atf::tests::tc::fail(std::string const&)' 命令 向上 1 结束
gtest好像不太一样,gtest的惯例是什么?
what is the established practice of doing the same with gtest?
阅读 gtest.cc
,我看到的最接近的是 --gunit_break_on_failure
,这应该会导致代码在 x86/Linux 上执行 INT3
陷阱,并调用 DebugBreak
在 Windows.
更新: 在最新的 public 版本中,该标志似乎已重命名为 --gtest_break_on_failure
。
如果您需要在测试开始时中断以观察某些内容,请先 get the symbol names present in the executable,然后 grep 获取感兴趣的测试名称,例如:
nm -C myclass_test | grep MyTest0
如果你想休息:
TEST(MainTest, MyTest0) {
EXPECT_EQ(1, 1);
}
在该 grep 的结果中,最有希望的结果似乎是:
0000000000407c64 T MainTest_MyTest0_Test::TestBody()
等等:
gdb myclass_test
和:
b MainTest_MyTest0_Test::TestBody
r
然后这让我处于所需测试的开始。
在修订版 2 中测试 with this setup。