Lines Matching defs:backtrace
42 #include <backtrace/Backtrace.h>
43 #include <backtrace/BacktraceMap.h>
76 Backtrace* backtrace;
94 std::string DumpFrames(Backtrace* backtrace) {
95 if (backtrace->NumFrames() == 0) {
100 for (size_t i = 0; i < backtrace->NumFrames(); i++) {
101 frame += " " + backtrace->FormatFrameData(i) + '\n';
119 bool ReadyLevelBacktrace(Backtrace* backtrace) {
120 // See if test_level_four is in the backtrace.
122 for (Backtrace::const_iterator it = backtrace->begin(); it != backtrace->end(); ++it) {
132 void VerifyLevelDump(Backtrace* backtrace) {
133 ASSERT_GT(backtrace->NumFrames(), static_cast<size_t>(0))
134 << DumpFrames(backtrace);
135 ASSERT_LT(backtrace->NumFrames(), static_cast<size_t>(MAX_BACKTRACE_FRAMES))
136 << DumpFrames(backtrace);
141 for (size_t i = backtrace->NumFrames()-1; i > 2; i--) {
142 if (backtrace->GetFrame(i)->func_name == "test_level_one") {
147 ASSERT_LT(static_cast<size_t>(0), frame_num) << DumpFrames(backtrace);
148 ASSERT_LE(static_cast<size_t>(3), frame_num) << DumpFrames(backtrace);
150 ASSERT_EQ(backtrace->GetFrame(frame_num)->func_name, "test_level_one")
151 << DumpFrames(backtrace);
152 ASSERT_EQ(backtrace->GetFrame(frame_num-1)->func_name, "test_level_two")
153 << DumpFrames(backtrace);
154 ASSERT_EQ(backtrace->GetFrame(frame_num-2)->func_name, "test_level_three")
155 << DumpFrames(backtrace);
156 ASSERT_EQ(backtrace->GetFrame(frame_num-3)->func_name, "test_level_four")
157 << DumpFrames(backtrace);
161 std::unique_ptr<Backtrace> backtrace(
162 Backtrace::Create(BACKTRACE_CURRENT_PROCESS, BACKTRACE_CURRENT_THREAD));
163 ASSERT_TRUE(backtrace.get() != nullptr);
164 ASSERT_TRUE(backtrace->Unwind(0));
165 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
167 VerifyLevelDump(backtrace.get());
170 bool ReadyMaxBacktrace(Backtrace* backtrace) {
171 return (backtrace->NumFrames() == MAX_BACKTRACE_FRAMES);
174 void VerifyMaxDump(Backtrace* backtrace) {
175 ASSERT_EQ(backtrace->NumFrames(), static_cast<size_t>(MAX_BACKTRACE_FRAMES))
176 << DumpFrames(backtrace);
178 ASSERT_EQ(backtrace->GetFrame(MAX_BACKTRACE_FRAMES-1)->func_name, "test_recursive_call")
179 << DumpFrames(backtrace);
183 std::unique_ptr<Backtrace> backtrace(
184 Backtrace::Create(BACKTRACE_CURRENT_PROCESS, BACKTRACE_CURRENT_THREAD));
185 ASSERT_TRUE(backtrace.get() != nullptr);
186 ASSERT_TRUE(backtrace->Unwind(0));
187 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
189 VerifyMaxDump(backtrace.get());
201 void VerifyThreadTest(pid_t tid, void (*VerifyFunc)(Backtrace*)) {
202 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(getpid(), tid));
203 ASSERT_TRUE(backtrace.get() != nullptr);
204 ASSERT_TRUE(backtrace->Unwind(0));
205 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
207 VerifyFunc(backtrace.get());
223 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(getpid(), getpid()));
224 ASSERT_TRUE(backtrace.get() != nullptr);
225 ASSERT_TRUE(backtrace->Unwind(0));
226 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
228 ASSERT_TRUE(backtrace->NumFrames() != 0);
229 for (const auto& frame : *backtrace ) {
233 << DumpFrames(backtrace.get());
244 Backtrace* bt_all, Backtrace* bt_ign1,
245 Backtrace* bt_ign2, const char* cur_proc) {
247 << "All backtrace:\n" << DumpFrames(bt_all) << "Ignore 1 backtrace:\n" << DumpFrames(bt_ign1);
249 << "All backtrace:\n" << DumpFrames(bt_all) << "Ignore 2 backtrace:\n" << DumpFrames(bt_ign2);
270 std::unique_ptr<Backtrace> all(
271 Backtrace::Create(BACKTRACE_CURRENT_PROCESS, BACKTRACE_CURRENT_THREAD));
276 std::unique_ptr<Backtrace> ign1(
277 Backtrace::Create(BACKTRACE_CURRENT_PROCESS, BACKTRACE_CURRENT_THREAD));
282 std::unique_ptr<Backtrace> ign2(
283 Backtrace::Create(BACKTRACE_CURRENT_PROCESS, BACKTRACE_CURRENT_THREAD));
300 bool (*ReadyFunc)(Backtrace*),
301 void (*VerifyFunc)(Backtrace*)) {
321 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(pid, tid, map.get()));
322 ASSERT_TRUE(backtrace.get() != nullptr);
323 ASSERT_TRUE(backtrace->Unwind(0));
324 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
325 if (ReadyFunc(backtrace.get())) {
326 VerifyFunc(backtrace.get());
329 last_dump = DumpFrames(backtrace.get());
336 ASSERT_TRUE(verified) << "Last backtrace:\n" << last_dump;
379 void VerifyProcessIgnoreFrames(Backtrace* bt_all) {
380 std::unique_ptr<Backtrace> ign1(Backtrace::Create(bt_all->Pid(), BACKTRACE_CURRENT_THREAD));
385 std::unique_ptr<Backtrace> ign2(Backtrace::Create(bt_all->Pid(), BACKTRACE_CURRENT_THREAD));
473 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(getpid(), gettid()));
474 ASSERT_TRUE(backtrace.get() != nullptr);
475 ASSERT_TRUE(backtrace->Unwind(0));
476 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
478 VerifyLevelDump(backtrace.get());
486 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(getpid(), gettid()));
487 ASSERT_TRUE(backtrace.get() != nullptr);
488 ASSERT_TRUE(backtrace->Unwind(0));
489 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
491 VerifyMaxDump(backtrace.get());
528 std::unique_ptr<Backtrace> backtrace(Backtrace
529 ASSERT_TRUE(backtrace.get() != nullptr);
530 ASSERT_TRUE(backtrace->Unwind(0));
531 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
533 VerifyLevelDump(backtrace.get());
568 std::unique_ptr<Backtrace> all(Backtrace::Create(getpid(), thread_data.tid));
573 std::unique_ptr<Backtrace> ign1(Backtrace::Create(getpid(), thread_data.tid));
578 std::unique_ptr<Backtrace> ign2(Backtrace::Create(getpid(), thread_data.tid));
609 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(getpid(), thread_data.tid));
610 ASSERT_TRUE(backtrace.get() != nullptr);
611 ASSERT_TRUE(backtrace->Unwind(0));
612 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
614 VerifyMaxDump(backtrace.get());
629 dump->backtrace = Backtrace::Create(getpid(), dump->thread.tid);
630 dump->backtrace->Unwind(0);
678 ASSERT_TRUE(dumpers[i].backtrace != nullptr);
679 VerifyMaxDump(dumpers[i].backtrace);
681 delete dumpers[i].backtrace;
682 dumpers[i].backtrace = nullptr;
718 ASSERT_TRUE(dumpers[i].backtrace != nullptr);
719 VerifyMaxDump(dumpers[i].backtrace);
721 delete dumpers[i].backtrace;
722 dumpers[i].backtrace = nullptr;
736 Backtrace* back1 = Backtrace::Create(getpid(), BACKTRACE_CURRENT_THREAD, map1);
743 Backtrace* back2 = Backtrace::Create(getpid(), BACKTRACE_CURRENT_THREAD, map2);
750 Backtrace* back3 = Backtrace::Create(getpid(), BACKTRACE_CURRENT_THREAD, map3);
778 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(getpid(), BACKTRACE_CURRENT_THREAD));
779 ASSERT_TRUE(backtrace.get() != nullptr);
795 backtrace->FormatFrameData(&frame));
807 backtrace->FormatFrameData(&frame));
820 backtrace->FormatFrameData(&frame));
832 backtrace->FormatFrameData(&frame));
841 backtrace->FormatFrameData(&frame));
850 backtrace->FormatFrameData(&frame));
860 backtrace->FormatFrameData(&frame));
869 backtrace->FormatFrameData(&frame));
985 void RunReadTest(Backtrace* backtrace, uintptr_t read_addr) {
994 size_t bytes_read = backtrace->Read(read_addr, data, 2 * pagesize);
1000 bytes_read = backtrace->Read(read_addr + i, data, 2 * sizeof(word_t));
1011 bytes_read = backtrace->Read(read_addr + i, data, j);
1033 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(getpid(), thread_data.tid));
1034 ASSERT_TRUE(backtrace.get() != nullptr);
1036 RunReadTest(backtrace.get(), reinterpret_cast<uintptr_t>(thread_data.data));
1087 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(pid, pid));
1088 ASSERT_TRUE(backtrace.get() != nullptr);
1091 size_t bytes_read = backtrace->Read(reinterpret_cast<uintptr_t>(&g_ready),
1097 bytes_read = backtrace->Read(reinterpret_cast<uintptr_t>(&g_addr),
1102 RunReadTest(backtrace.get(), read_addr);
1185 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(BACKTRACE_CURRENT_PROCESS,
1187 ASSERT_TRUE(backtrace.get() != nullptr);
1190 backtrace->Unwind(0);
1198 std::string func_name = backtrace->GetFunctionName(read_addr, &offset);
1258 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(pid, BACKTRACE_CURRENT_THREAD));
1259 ASSERT_TRUE(backtrace.get() != nullptr);
1262 ASSERT_EQ(sizeof(uintptr_t), backtrace->Read(reinterpret_cast<uintptr_t>(&g_ready), reinterpret_cast<uint8_t*>(&read_addr), sizeof(uintptr_t)));
1264 ASSERT_EQ(sizeof(uintptr_t), backtrace->Read(reinterpret_cast<uintptr_t>(&g_addr), reinterpret_cast<uint8_t*>(&read_addr), sizeof(uintptr_t)));
1267 backtrace->Unwind(0);
1274 std::string func_name = backtrace->GetFunctionName(read_addr, &offset);
1296 bool FindFuncFrameInBacktrace(Backtrace* backtrace, uintptr_t test_func, size_t* frame_num) {
1298 backtrace->FillInMap(test_func, &map);
1305 for (Backtrace::const_iterator it = backtrace->begin(); it != backtrace->end(); ++it) {
1315 void VerifyUnreadableElfFrame(Backtrace* backtrace, uintptr_t test_func, size_t frame_num) {
1316 ASSERT_LT(backtrace->NumFrames(), static_cast<size_t>(MAX_BACKTRACE_FRAMES))
1317 << DumpFrames(backtrace);
1319 ASSERT_TRUE(frame_num != 0) << DumpFrames(backtrace);
1321 ASSERT_LT(frame_num, backtrace->NumFrames()) << DumpFrames(backtrace);
1323 uintptr_t diff = backtrace->GetFrame(frame_num)->pc - test_func;
1324 ASSERT_LT(diff, 200U) << DumpFrames(backtrace);
1328 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(BACKTRACE_CURRENT_PROCESS,
1330 ASSERT_TRUE(backtrace.get() != nullptr);
1331 ASSERT_TRUE(backtrace->Unwind(0));
1332 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
1335 ASSERT_TRUE(FindFuncFrameInBacktrace(backtrace.get(), test_func, &frame_num));
1337 VerifyUnreadableElfFrame(backtrace.get(), test_func, frame_num);
1386 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(pid, BACKTRACE_CURRENT_THREAD));
1387 ASSERT_TRUE(backtrace.get() != nullptr);
1388 ASSERT_TRUE(backtrace->Unwind(0));
1389 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
1392 if (FindFuncFrameInBacktrace(backtrace.get(),
1395 VerifyUnreadableElfFrame(backtrace.get(), reinterpret_cast<uintptr_t>(test_func), frame_num);
1414 std::unique_ptr<Backtrace> backtrace(
1415 Backtrace::Create(BACKTRACE_CURRENT_PROCESS, 99999999));
1416 ASSERT_TRUE(backtrace.get() != nullptr);
1417 ASSERT_FALSE(backtrace->Unwind(0));
1418 ASSERT_EQ(BACKTRACE_UNWIND_ERROR_THREAD_DOESNT_EXIST, backtrace->GetError());
1429 Backtrace* backtrace = Backtrace::Create(pid, tid);
1430 ASSERT_TRUE(backtrace != nullptr);
1431 ASSERT_TRUE(backtrace->Unwind(0));
1432 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
1433 delete backtrace;
1440 Backtrace* backtrace = Backtrace::Create(pid, tid);
1441 ASSERT_TRUE(backtrace != nullptr);
1442 ASSERT_TRUE(backtrace->Unwind(0));
1443 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
1444 delete backtrace;