admin管理员组文章数量:1417551
I've added stacktraces to our gtest use.
However with -O2
the TestBody
is disappearing from the stackprinting which often makes this useless as the most important call site is not shown. Any idea why or how to circumvent it?
Example
#include <iostream>
#include <stacktrace>
#include "gtest/gtest.h"
void foo()
{
std::cout << std::stacktrace::current() << '\n';
}
TEST(example, base)
{
foo();
}
int
main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Results in this (desired, with -O0
)
[ RUN ] example.base
0# foo() at /app/example.cpp:7
1# example_base_Test::TestBody() at /app/example.cpp:12
2# void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) at :0
3# void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) at :0
...
But with -O2
the #1 disappears
[ RUN ] example.base
0# foo() at /app/example.cpp:7
1# void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) at :0
2# void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) at :0
3# testing::Test::Run() at :0
...
This example on godbolt
Edit:
I have tried with __attribute__((noinline))
but not succeeded yet:
void ::testing::internal::HandleSehExceptionsInMethodIfSupported<::testing::Test, void>(::testing::Test*, void (::testing::Test::*)(), char const*)
__attribute__((noinline));
I've added stacktraces to our gtest use.
However with -O2
the TestBody
is disappearing from the stackprinting which often makes this useless as the most important call site is not shown. Any idea why or how to circumvent it?
Example
#include <iostream>
#include <stacktrace>
#include "gtest/gtest.h"
void foo()
{
std::cout << std::stacktrace::current() << '\n';
}
TEST(example, base)
{
foo();
}
int
main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Results in this (desired, with -O0
)
[ RUN ] example.base
0# foo() at /app/example.cpp:7
1# example_base_Test::TestBody() at /app/example.cpp:12
2# void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) at :0
3# void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) at :0
...
But with -O2
the #1 disappears
[ RUN ] example.base
0# foo() at /app/example.cpp:7
1# void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) at :0
2# void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) at :0
3# testing::Test::Run() at :0
...
This example on godbolt
Edit:
I have tried with __attribute__((noinline))
but not succeeded yet:
void ::testing::internal::HandleSehExceptionsInMethodIfSupported<::testing::Test, void>(::testing::Test*, void (::testing::Test::*)(), char const*)
__attribute__((noinline));
Share
Improve this question
edited Jan 31 at 10:17
mbschenkel
asked Jan 31 at 8:56
mbschenkelmbschenkel
1,9052 gold badges18 silver badges43 bronze badges
0
1 Answer
Reset to default 1Optimizer has inlined the code, so there is no frame on a stack. So no data to print.
You have to disable some optimizations to see full call-stack.
Try add compiler options: -fno-omit-frame-pointer -fno-inline -fno-optimize-sibling-calls
.
Live demo.
Disclaimer: I didn'ty test if all of this flags are required (most probably all are required).
本文标签: cNo stackframe for googletest TestBodyStack Overflow
版权声明:本文标题:c++ - No stackframe for google-test TestBody - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745273655a2651047.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论