Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 1 | //===-- HistoryThread.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/HistoryThread.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 13 | #include "Plugins/Process/Utility/HistoryUnwind.h" |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 14 | #include "Plugins/Process/Utility/RegisterContextHistory.h" |
| 15 | |
Jason Molenda | ee87e75 | 2013-11-12 00:09:58 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Log.h" |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 17 | #include "lldb/Target/Process.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 18 | #include "lldb/Target/StackFrameList.h" |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 23 | // Constructor |
| 24 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 25 | HistoryThread::HistoryThread(lldb_private::Process &process, lldb::tid_t tid, |
| 26 | std::vector<lldb::addr_t> pcs, uint32_t stop_id, |
| 27 | bool stop_id_is_valid) |
| 28 | : Thread(process, tid, true), m_framelist_mutex(), m_framelist(), |
| 29 | m_pcs(pcs), m_stop_id(stop_id), m_stop_id_is_valid(stop_id_is_valid), |
| 30 | m_extended_unwind_token(LLDB_INVALID_ADDRESS), m_queue_name(), |
| 31 | m_thread_name(), m_originating_unique_thread_id(tid), |
| 32 | m_queue_id(LLDB_INVALID_QUEUE_ID) { |
| 33 | m_unwinder_ap.reset(new HistoryUnwind(*this, pcs, stop_id_is_valid)); |
| 34 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); |
| 35 | if (log) |
| 36 | log->Printf("%p HistoryThread::HistoryThread", static_cast<void *>(this)); |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 39 | // Destructor |
| 40 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 41 | HistoryThread::~HistoryThread() { |
| 42 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); |
| 43 | if (log) |
| 44 | log->Printf("%p HistoryThread::~HistoryThread (tid=0x%" PRIx64 ")", |
| 45 | static_cast<void *>(this), GetID()); |
| 46 | DestroyThread(); |
| 47 | } |
| 48 | |
| 49 | lldb::RegisterContextSP HistoryThread::GetRegisterContext() { |
| 50 | RegisterContextSP rctx; |
| 51 | if (m_pcs.size() > 0) { |
| 52 | rctx.reset(new RegisterContextHistory( |
| 53 | *this, 0, GetProcess()->GetAddressByteSize(), m_pcs[0])); |
| 54 | } |
| 55 | return rctx; |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | lldb::RegisterContextSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | HistoryThread::CreateRegisterContextForFrame(StackFrame *frame) { |
| 60 | return m_unwinder_ap->CreateRegisterContextForFrame(frame); |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | lldb::StackFrameListSP HistoryThread::GetStackFrameList() { |
| 64 | // FIXME do not throw away the lock after we acquire it.. |
| 65 | std::unique_lock<std::mutex> lock(m_framelist_mutex); |
| 66 | lock.unlock(); |
| 67 | if (m_framelist.get() == NULL) { |
| 68 | m_framelist.reset(new StackFrameList(*this, StackFrameListSP(), true)); |
| 69 | } |
| 70 | |
| 71 | return m_framelist; |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | uint32_t HistoryThread::GetExtendedBacktraceOriginatingIndexID() { |
| 75 | if (m_originating_unique_thread_id != LLDB_INVALID_THREAD_ID) { |
| 76 | if (GetProcess()->HasAssignedIndexIDToThread( |
| 77 | m_originating_unique_thread_id)) { |
| 78 | return GetProcess()->AssignIndexIDToThread( |
| 79 | m_originating_unique_thread_id); |
Jason Molenda | 02706c3 | 2013-11-08 04:59:54 +0000 | [diff] [blame] | 80 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 81 | } |
| 82 | return LLDB_INVALID_THREAD_ID; |
Jason Molenda | 8ee9cb5 | 2013-11-16 01:24:22 +0000 | [diff] [blame] | 83 | } |