MCPcopy Create free account
hub / github.com/boostorg/stacktrace / test_inplace

Function test_inplace

example/terminate_handler.cpp:145–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143#include <sstream>
144
145int test_inplace() {
146 const bool is_noop = !boost::stacktrace::stacktrace();
147
148 {
149 // This is very dependent on compiler and link flags. No sane way to make it work, because:
150 // * BOOST_NOINLINE could be ignored by MSVC compiler if link-time optimization is enabled.
151 // * BOOST_FORCEINLINE could be ignored by GCC depending on the std::vector default constructor length.
152 const std::size_t frames_ss1 = boost::stacktrace::safe_dump_to("./backtrace2.dump");
153 boost::stacktrace::stacktrace ss2;
154 std::ifstream ifs("./backtrace2.dump");
155 boost::stacktrace::stacktrace ss1 = boost::stacktrace::stacktrace::from_dump(ifs);
156 ifs.close();
157 boost::filesystem::remove("./backtrace2.dump");
158
159 if (ss1.size() + 1 != frames_ss1 || ss2.size() != ss1.size()) {
160 std::cerr << "51: Stacktraces differ. Dumped size == " << frames_ss1 << ".\n" << ss1 << "\n vs \n" << ss2 << '\n';
161 } else if (ss1.size() > 1 && ss1[1].name() != ss2[1].name()) {
162 std::cerr << "52: Stacktraces differ:\n" << ss1 << "\n vs \n" << ss2 << '\n';
163 }
164 }
165
166 {
167 // This is very dependent on compiler and link flags. No sane way to make it work, because:
168 // * BOOST_NOINLINE could be ignored by MSVC compiler if link-time optimization is enabled.
169 // * BOOST_FORCEINLINE could be ignored by GCC depending on the std::vector default constructor length.
170 void* data[1024];
171 const std::size_t frames_ss1 = boost::stacktrace::safe_dump_to(data, sizeof(data));
172 boost::stacktrace::stacktrace ss2;
173 boost::stacktrace::stacktrace ss1 = boost::stacktrace::stacktrace::from_dump(data, sizeof(data));
174
175 if (ss1.size() + 1 != frames_ss1 || ss1.size() != ss2.size()) {
176 std::cerr << "53: Stacktraces differ. Dumped size == " << frames_ss1 << ".\n" << ss1 << "\n vs \n" << ss2 << '\n';
177 } else if (ss1.size() > 1 && ss1[1].name() != ss2[1].name()) {
178 std::cerr << "54: Stacktraces differ:\n" << ss1 << "\n vs \n" << ss2 << '\n';
179 }
180 }
181
182 {
183 void* data[1024];
184 boost::stacktrace::safe_dump_to(1024, data, sizeof(data));
185 if (boost::stacktrace::stacktrace::from_dump(data, sizeof(data))) {
186 std::cerr << "Stacktrace not empty!\n";
187 return 55;
188 }
189 }
190
191 {
192 void* data[1024];
193 boost::stacktrace::safe_dump_to(1, data, sizeof(data));
194 if (!is_noop && !boost::stacktrace::stacktrace::from_dump(data, sizeof(data))) {
195 std::cerr << "Stacktrace empty!\n";
196 return 56;
197 }
198 const std::size_t size_1_skipped = boost::stacktrace::stacktrace::from_dump(data, sizeof(data)).size();
199 boost::stacktrace::safe_dump_to(0, data, sizeof(data));
200 const std::size_t size_0_skipped = boost::stacktrace::stacktrace::from_dump(data, sizeof(data)).size();
201
202 if (!is_noop && (size_1_skipped + 1 != size_0_skipped)) {

Callers 1

mainFunction · 0.85

Calls 3

from_dumpFunction · 0.85
addressMethod · 0.80
nameMethod · 0.45

Tested by

no test coverage detected