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