Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 1 | //===-- HistoryUnwind.cpp ---------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/lldb-private.h" |
| 11 | |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 12 | #include "Plugins/Process/Utility/HistoryUnwind.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 13 | #include "Plugins/Process/Utility/RegisterContextHistory.h" |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 14 | |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 15 | #include "lldb/Target/Process.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 16 | #include "lldb/Target/StackFrame.h" |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 17 | #include "lldb/Target/Target.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 18 | #include "lldb/Target/Thread.h" |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | // Constructor |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 24 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 25 | HistoryUnwind::HistoryUnwind(Thread &thread, std::vector<lldb::addr_t> pcs, |
| 26 | bool stop_id_is_valid) |
| 27 | : Unwind(thread), m_pcs(pcs), m_stop_id_is_valid(stop_id_is_valid) {} |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 28 | |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 29 | // Destructor |
| 30 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 31 | HistoryUnwind::~HistoryUnwind() {} |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 32 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 33 | void HistoryUnwind::DoClear() { |
| 34 | std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex); |
| 35 | m_pcs.clear(); |
| 36 | m_stop_id_is_valid = false; |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | lldb::RegisterContextSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | HistoryUnwind::DoCreateRegisterContextForFrame(StackFrame *frame) { |
| 41 | RegisterContextSP rctx; |
| 42 | if (frame) { |
| 43 | addr_t pc = frame->GetFrameCodeAddress().GetLoadAddress( |
| 44 | &frame->GetThread()->GetProcess()->GetTarget()); |
| 45 | if (pc != LLDB_INVALID_ADDRESS) { |
| 46 | rctx.reset(new RegisterContextHistory( |
| 47 | *frame->GetThread().get(), frame->GetConcreteFrameIndex(), |
| 48 | frame->GetThread()->GetProcess()->GetAddressByteSize(), pc)); |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 49 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | } |
| 51 | return rctx; |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | bool HistoryUnwind::DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa, |
| 55 | lldb::addr_t &pc) { |
| 56 | // FIXME do not throw away the lock after we acquire it.. |
| 57 | std::unique_lock<std::recursive_mutex> guard(m_unwind_mutex); |
| 58 | guard.unlock(); |
| 59 | if (frame_idx < m_pcs.size()) { |
| 60 | cfa = frame_idx; |
| 61 | pc = m_pcs[frame_idx]; |
| 62 | return true; |
| 63 | } |
| 64 | return false; |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 67 | uint32_t HistoryUnwind::DoGetFrameCount() { return m_pcs.size(); } |