Lines Matching full:backtrace
43 #include <backtrace/Backtrace.h>
44 #include <backtrace/BacktraceMap.h>
80 Backtrace* backtrace;
91 static std::string DumpFrames(Backtrace* backtrace) {
92 if (backtrace->NumFrames() == 0) {
97 for (size_t i = 0; i < backtrace->NumFrames(); i++) {
98 frame += " " + backtrace->FormatFrameData(i) + '\n';
137 static bool ReadyLevelBacktrace(Backtrace* backtrace) {
138 // See if test_level_four is in the backtrace.
140 for (Backtrace::const_iterator it = backtrace->begin(); it != backtrace->end(); ++it) {
150 static void VerifyLevelDump(Backtrace* backtrace) {
151 ASSERT_GT(backtrace->NumFrames(), static_cast<size_t>(0))
152 << DumpFrames(backtrace);
153 ASSERT_LT(backtrace->NumFrames(), static_cast<size_t>(MAX_BACKTRACE_FRAMES))
154 << DumpFrames(backtrace);
159 for (size_t i = backtrace->NumFrames()-1; i > 2; i--) {
160 if (backtrace->GetFrame(i)->func_name == "test_level_one") {
165 ASSERT_LT(static_cast<size_t>(0), frame_num) << DumpFrames(backtrace);
166 ASSERT_LE(static_cast<size_t>(3), frame_num) << DumpFrames(backtrace);
168 ASSERT_EQ(backtrace->GetFrame(frame_num)->func_name, "test_level_one")
169 << DumpFrames(backtrace);
170 ASSERT_EQ(backtrace->GetFrame(frame_num-1)->func_name, "test_level_two")
171 << DumpFrames(backtrace);
172 ASSERT_EQ(backtrace->GetFrame(frame_num-2)->func_name, "test_level_three")
173 << DumpFrames(backtrace);
174 ASSERT_EQ(backtrace->GetFrame(frame_num-3)->func_name, "test_level_four")
175 << DumpFrames(backtrace);
179 std::unique_ptr<Backtrace> backtrace(
180 Backtrace::Create(BACKTRACE_CURRENT_PROCESS, BACKTRACE_CURRENT_THREAD));
181 ASSERT_TRUE(backtrace.get() != nullptr);
182 ASSERT_TRUE(backtrace->Unwind(0));
183 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
185 VerifyLevelDump(backtrace.get());
188 static bool ReadyMaxBacktrace(Backtrace* backtrace) {
189 return (backtrace->NumFrames() == MAX_BACKTRACE_FRAMES);
192 static void VerifyMaxDump(Backtrace* backtrace) {
193 ASSERT_EQ(backtrace->NumFrames(), static_cast<size_t>(MAX_BACKTRACE_FRAMES))
194 << DumpFrames(backtrace);
196 ASSERT_EQ(backtrace->GetFrame(MAX_BACKTRACE_FRAMES-1)->func_name, "test_recursive_call")
197 << DumpFrames(backtrace);
201 std::unique_ptr<Backtrace> backtrace(
202 Backtrace::Create(BACKTRACE_CURRENT_PROCESS, BACKTRACE_CURRENT_THREAD));
203 ASSERT_TRUE(backtrace.get() != nullptr);
204 ASSERT_TRUE(backtrace->Unwind(0));
205 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
207 VerifyMaxDump(backtrace.get());
232 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(getpid(), getpid()));
233 ASSERT_TRUE(backtrace.get() != nullptr);
234 ASSERT_TRUE(backtrace->Unwind(0));
235 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
237 ASSERT_TRUE(backtrace->NumFrames() != 0);
238 for (const auto& frame : *backtrace ) {
242 << DumpFrames(backtrace.get());
252 static void VerifyIgnoreFrames(Backtrace* bt_all, Backtrace* bt_ign1, Backtrace* bt_ign2,
255 << "All backtrace:\n" << DumpFrames(bt_all) << "Ignore 1 backtrace:\n" << DumpFrames(bt_ign1);
257 << "All backtrace:\n" << DumpFrames(bt_all) << "Ignore 2 backtrace:\n" << DumpFrames(bt_ign2);
278 std::unique_ptr<Backtrace> all(
279 Backtrace::Create(BACKTRACE_CURRENT_PROCESS, BACKTRACE_CURRENT_THREAD));
284 std::unique_ptr<Backtrace> ign1(
285 Backtrace::Create(BACKTRACE_CURRENT_PROCESS, BACKTRACE_CURRENT_THREAD));
290 std::unique_ptr<Backtrace> ign2(
291 Backtrace::Create(BACKTRACE_CURRENT_PROCESS, BACKTRACE_CURRENT_THREAD));
307 static void VerifyProcTest(pid_t pid, pid_t tid, bool share_map, bool (*ReadyFunc)(Backtrace*),
308 void (*VerifyFunc)(Backtrace*)) {
328 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(pid, tid, map.get()));
329 ASSERT_TRUE(backtrace.get() != nullptr);
330 ASSERT_TRUE(backtrace->Unwind(0));
331 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
332 if (ReadyFunc(backtrace.get())) {
333 VerifyFunc(backtrace.get());
336 last_dump = DumpFrames(backtrace.get());
343 ASSERT_TRUE(verified) << "Last backtrace:\n" << last_dump;
386 static void VerifyProcessIgnoreFrames(Backtrace* bt_all) {
387 std::unique_ptr<Backtrace> ign1(Backtrace::Create(bt_all->Pid(), BACKTRACE_CURRENT_THREAD));
392 std::unique_ptr<Backtrace> ign2(Backtrace::Create(bt_all->Pid(), BACKTRACE_CURRENT_THREAD));
476 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(getpid(), gettid()));
477 ASSERT_TRUE(backtrace.get() != nullptr);
478 ASSERT_TRUE(backtrace->Unwind(0));
479 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
481 VerifyLevelDump(backtrace.get());
489 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(getpid(), gettid()));
490 ASSERT_TRUE(backtrace.get() != nullptr);
491 ASSERT_TRUE(backtrace->Unwind(0));
492 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
494 VerifyMaxDump(backtrace.get());
531 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(getpid(), thread_data.tid));
532 ASSERT_TRUE(backtrace.get() != nullptr);
533 ASSERT_TRUE(backtrace->Unwind(0));
534 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
536 VerifyLevelDump(backtrace.get());
571 std::unique_ptr<Backtrace> all(Backtrace::Create(getpid(), thread_data.tid));
576 std::unique_ptr<Backtrace> ign1(Backtrace::Create(getpid(), thread_data.tid));
581 std::unique_ptr<Backtrace> ign2(Backtrace::Create(getpid(), thread_data.tid));
612 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(getpid(), thread_data.tid));
613 ASSERT_TRUE(backtrace.get() != nullptr);
614 ASSERT_TRUE(backtrace->Unwind(0));
615 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
617 VerifyMaxDump(backtrace.get());
632 dump->backtrace = Backtrace::Create(getpid(), dump->thread.tid);
633 dump->backtrace->Unwind(0);
681 ASSERT_TRUE(dumpers[i].backtrace != nullptr);
682 VerifyMaxDump(dumpers[i].backtrace);
684 delete dumpers[i].backtrace;
685 dumpers[i].backtrace = nullptr;
721 ASSERT_TRUE(dumpers[i].backtrace != nullptr);
722 VerifyMaxDump(dumpers[i].backtrace);
724 delete dumpers[i].backtrace;
725 dumpers[i].backtrace = nullptr;
739 Backtrace* back1 = Backtrace::Create(getpid(), BACKTRACE_CURRENT_THREAD, map1);
746 Backtrace* back2 = Backtrace::Create(getpid(), BACKTRACE_CURRENT_THREAD, map2);
753 Backtrace* back3 = Backtrace::Create(getpid(), BACKTRACE_CURRENT_THREAD, map3);
781 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(getpid(), BACKTRACE_CURRENT_THREAD));
782 ASSERT_TRUE(backtrace.get() != nullptr);
798 backtrace->FormatFrameData(&frame));
810 backtrace->FormatFrameData(&frame));
823 backtrace->FormatFrameData(&frame));
835 backtrace->FormatFrameData(&frame));
844 backtrace->FormatFrameData(&frame));
853 backtrace->FormatFrameData(&frame));
863 backtrace->FormatFrameData(&frame));
872 backtrace->FormatFrameData(&frame));
973 static void RunReadTest(Backtrace* backtrace, uintptr_t read_addr) {
982 size_t bytes_read = backtrace->Read(read_addr, data, 2 * pagesize);
988 bytes_read = backtrace->Read(read_addr + i, data, 2 * sizeof(word_t));
999 bytes_read = backtrace->Read(read_addr + i, data, j);
1021 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(getpid(), thread_data.tid));
1022 ASSERT_TRUE(backtrace.get() != nullptr);
1024 RunReadTest(backtrace.get(), reinterpret_cast<uintptr_t>(thread_data.data));
1075 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(pid, pid));
1076 ASSERT_TRUE(backtrace.get() != nullptr);
1079 size_t bytes_read = backtrace->Read(reinterpret_cast<uintptr_t>(&g_ready),
1085 bytes_read = backtrace->Read(reinterpret_cast<uintptr_t>(&g_addr),
1090 RunReadTest(backtrace.get(), read_addr);
1173 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(BACKTRACE_CURRENT_PROCESS,
1175 ASSERT_TRUE(backtrace.get() != nullptr);
1178 backtrace->Unwind(0);
1186 std::string func_name = backtrace->GetFunctionName(read_addr, &offset);
1246 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(pid, BACKTRACE_CURRENT_THREAD));
1247 ASSERT_TRUE(backtrace.get() != nullptr);
1250 ASSERT_EQ(sizeof(uintptr_t), backtrace->Read(reinterpret_cast<uintptr_t>(&g_ready), reinterpret_cast<uint8_t*>(&read_addr), sizeof(uintptr_t)));
1252 ASSERT_EQ(sizeof(uintptr_t), backtrace->Read(reinterpret_cast<uintptr_t>(&g_addr), reinterpret_cast<uint8_t*>(&read_addr), sizeof(uintptr_t)));
1255 backtrace->Unwind(0);
1262 std::string func_name = backtrace->GetFunctionName(read_addr, &offset);
1284 static bool FindFuncFrameInBacktrace(Backtrace* backtrace, uintptr_t test_func, size_t* frame_num) {
1286 backtrace->FillInMap(test_func, &map);
1293 for (Backtrace::const_iterator it = backtrace->begin(); it != backtrace->end(); ++it) {
1303 static void VerifyUnreadableElfFrame(Backtrace* backtrace, uintptr_t test_func, size_t frame_num) {
1304 ASSERT_LT(backtrace->NumFrames(), static_cast<size_t>(MAX_BACKTRACE_FRAMES))
1305 << DumpFrames(backtrace);
1307 ASSERT_TRUE(frame_num != 0) << DumpFrames(backtrace);
1309 ASSERT_LT(frame_num, backtrace->NumFrames()) << DumpFrames(backtrace);
1311 uintptr_t diff = backtrace->GetFrame(frame_num)->pc - test_func;
1312 ASSERT_LT(diff, 200U) << DumpFrames(backtrace);
1316 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(BACKTRACE_CURRENT_PROCESS,
1318 ASSERT_TRUE(backtrace.get() != nullptr);
1319 ASSERT_TRUE(backtrace->Unwind(0));
1320 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
1323 ASSERT_TRUE(FindFuncFrameInBacktrace(backtrace.get(), test_func, &frame_num));
1325 VerifyUnreadableElfFrame(backtrace.get(), test_func, frame_num);
1374 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(pid, BACKTRACE_CURRENT_THREAD));
1375 ASSERT_TRUE(backtrace.get() != nullptr);
1376 ASSERT_TRUE(backtrace->Unwind(0));
1377 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
1380 if (FindFuncFrameInBacktrace(backtrace.get(),
1383 VerifyUnreadableElfFrame(backtrace.get(), reinterpret_cast<uintptr_t>(test_func), frame_num);
1402 std::unique_ptr<Backtrace> backtrace(
1403 Backtrace::Create(BACKTRACE_CURRENT_PROCESS, 99999999));
1404 ASSERT_TRUE(backtrace.get() != nullptr);
1405 ASSERT_FALSE(backtrace->Unwind(0));
1406 ASSERT_EQ(BACKTRACE_UNWIND_ERROR_THREAD_DOESNT_EXIST, backtrace->GetError());
1410 std::unique_ptr<Backtrace> backtrace(
1411 Backtrace::Create(BACKTRACE_CURRENT_PROCESS, BACKTRACE_CURRENT_THREAD));
1412 ASSERT_TRUE(backtrace.get() != nullptr);
1417 ASSERT_NE(std::string(""), backtrace->GetFunctionName(cur_func_offset, &offset));
1425 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(pid, pid));
1430 ASSERT_NE(std::string(""), backtrace->GetFunctionName(cur_func_offset, &offset));
1501 static void UnwindFromDevice(Backtrace* backtrace, void* device_map) {
1505 backtrace->FillInMap(device_map_uint, &map);
1511 ASSERT_EQ(std::string(""), backtrace->GetFunctionName(device_map_uint, &offset));
1512 ASSERT_EQ(std::string(""), backtrace->GetFunctionName(device_map_uint, &offset, &map));
1513 ASSERT_EQ(std::string(""), backtrace->GetFunctionName(0, &offset));
1517 backtrace->FillInMap(cur_func_offset, &map);
1519 ASSERT_NE(std::string(""), backtrace->GetFunctionName(cur_func_offset, &offset, &map));
1521 ASSERT_EQ(std::string(""), backtrace->GetFunctionName(cur_func_offset, &offset, &map));
1532 ASSERT_TRUE(backtrace->Unwind(0, &ucontext));
1535 ASSERT_EQ(1U, backtrace->NumFrames());
1536 backtrace->GetFrame(0);
1541 ASSERT_TRUE(backtrace->Unwind(1, &ucontext));
1542 ASSERT_EQ(0U, backtrace->NumFrames());
1551 ASSERT_TRUE(backtrace->Unwind(0, &ucontext));
1554 ASSERT_EQ(1U, backtrace->NumFrames());
1555 frame = backtrace->GetFrame(0);
1560 ASSERT_TRUE(backtrace->Unwind(1, &ucontext));
1561 ASSERT_EQ(0U, backtrace->NumFrames());
1569 std::unique_ptr<Backtrace> backtrace(
1570 Backtrace::Create(BACKTRACE_CURRENT_PROCESS, BACKTRACE_CURRENT_THREAD));
1571 ASSERT_TRUE(backtrace);
1573 UnwindFromDevice(backtrace.get(), device_map);
1582 // Fork a process to do a remote backtrace.
1587 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(pid, pid));
1593 // UnwindFromDevice(backtrace.get(), device_map);
1658 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(pid, pid));
1660 size_t bytes_read = backtrace->Read(reinterpret_cast<uintptr_t>(const_cast<int*>(&value)),
1674 Backtrace::const_iterator frame_iter;
1676 std::unique_ptr<Backtrace> backtrace;
1684 backtrace.reset(Backtrace::Create(pid, pid));
1685 ASSERT_TRUE(backtrace->Unwind(0));
1687 for (frame_iter = backtrace->begin(); frame_iter != backtrace->end(); ++frame_iter) {
1702 << DumpFrames(backtrace.get());
1708 for (; frame_iter != backtrace->end(); ++frame_iter) {
1714 ASSERT_NE(0U, frame) << "Unable to find test_level_four in backtrace" << std::endl
1715 << DumpFrames(backtrace.get());
1726 ASSERT_LE(frame + 2, names.size()) << DumpFrames(backtrace.get());
1727 ASSERT_LE(2U, frame) << DumpFrames(backtrace.get());
1729 ASSERT_EQ("test_signal_action", names[0]) << DumpFrames(backtrace.get());
1731 ASSERT_EQ("test_signal_handler", names[0]) << DumpFrames(backtrace.get());
1733 ASSERT_EQ("test_level_three", names[frame]) << DumpFrames(backtrace.get());
1734 ASSERT_EQ("test_level_two", names[frame + 1]) << DumpFrames(backtrace.get());
1735 ASSERT_EQ("test_level_one", names[frame + 2]) << DumpFrames(backtrace.get());
1752 Backtrace* backtrace = Backtrace::Create(pid, tid);
1753 ASSERT_TRUE(backtrace != nullptr);
1754 ASSERT_TRUE(backtrace->Unwind(0));
1755 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
1756 delete backtrace;
1763 Backtrace* backtrace = Backtrace::Create(pid, tid);
1764 ASSERT_TRUE(backtrace != nullptr);
1765 ASSERT_TRUE(backtrace->Unwind(0));
1766 ASSERT_EQ(BACKTRACE_UNWIND_NO_ERROR, backtrace->GetError());
1767 delete backtrace;