1258882Semaste//===-- HistoryThread.cpp ---------------------------------------*- C++ -*-===// 2258882Semaste// 3258882Semaste// The LLVM Compiler Infrastructure 4258882Semaste// 5258882Semaste// This file is distributed under the University of Illinois Open Source 6258882Semaste// License. See LICENSE.TXT for details. 7258882Semaste// 8258882Semaste//===----------------------------------------------------------------------===// 9258882Semaste 10258882Semaste#include "lldb/lldb-private.h" 11258882Semaste 12258882Semaste#include "Plugins/Process/Utility/HistoryUnwind.h" 13258882Semaste#include "Plugins/Process/Utility/HistoryThread.h" 14258882Semaste#include "Plugins/Process/Utility/RegisterContextHistory.h" 15258882Semaste 16258882Semaste#include "lldb/Core/Log.h" 17258882Semaste#include "lldb/Target/StackFrameList.h" 18258882Semaste#include "lldb/Target/Process.h" 19258882Semaste 20258882Semasteusing namespace lldb; 21258882Semasteusing namespace lldb_private; 22258882Semaste 23258882SemasteHistoryThread::HistoryThread (lldb_private::Process &process, 24258882Semaste lldb::tid_t tid, 25258882Semaste std::vector<lldb::addr_t> pcs, 26258882Semaste uint32_t stop_id, 27258882Semaste bool stop_id_is_valid) : 28269024Semaste Thread (process, tid), 29258882Semaste m_framelist_mutex(), 30258882Semaste m_framelist(), 31258882Semaste m_pcs (pcs), 32258882Semaste m_stop_id (stop_id), 33258882Semaste m_stop_id_is_valid (stop_id_is_valid), 34258882Semaste m_extended_unwind_token (LLDB_INVALID_ADDRESS), 35258882Semaste m_queue_name (), 36258882Semaste m_thread_name (), 37258882Semaste m_originating_unique_thread_id (tid), 38258882Semaste m_queue_id (LLDB_INVALID_QUEUE_ID) 39258882Semaste{ 40258882Semaste m_unwinder_ap.reset (new HistoryUnwind (*this, pcs, stop_id, stop_id_is_valid)); 41258882Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); 42258882Semaste if (log) 43258882Semaste log->Printf ("%p HistoryThread::HistoryThread", this); 44258882Semaste} 45258882Semaste 46258882SemasteHistoryThread::~HistoryThread () 47258882Semaste{ 48258882Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); 49258882Semaste if (log) 50258882Semaste log->Printf ("%p HistoryThread::~HistoryThread (tid=0x%" PRIx64 ")", this, GetID()); 51258882Semaste DestroyThread(); 52258882Semaste} 53258882Semaste 54258882Semastelldb::RegisterContextSP 55258882SemasteHistoryThread::GetRegisterContext () 56258882Semaste{ 57258882Semaste RegisterContextSP rctx ; 58258882Semaste if (m_pcs.size() > 0) 59258882Semaste { 60258882Semaste rctx.reset (new RegisterContextHistory (*this, 0, GetProcess()->GetAddressByteSize(), m_pcs[0])); 61258882Semaste } 62258882Semaste return rctx; 63258882Semaste 64258882Semaste} 65258882Semaste 66258882Semastelldb::RegisterContextSP 67258882SemasteHistoryThread::CreateRegisterContextForFrame (StackFrame *frame) 68258882Semaste{ 69258882Semaste return m_unwinder_ap->CreateRegisterContextForFrame (frame); 70258882Semaste} 71258882Semaste 72258882Semastelldb::StackFrameListSP 73258882SemasteHistoryThread::GetStackFrameList () 74258882Semaste{ 75258882Semaste Mutex::Locker (m_framelist_mutex); 76258882Semaste if (m_framelist.get() == NULL) 77258882Semaste { 78258882Semaste m_framelist.reset (new StackFrameList (*this, StackFrameListSP(), true)); 79258882Semaste } 80258882Semaste 81258882Semaste return m_framelist; 82258882Semaste} 83258882Semaste 84258882Semasteuint32_t 85258882SemasteHistoryThread::GetExtendedBacktraceOriginatingIndexID () 86258882Semaste{ 87258882Semaste if (m_originating_unique_thread_id != LLDB_INVALID_THREAD_ID) 88258882Semaste { 89258882Semaste if (GetProcess()->HasAssignedIndexIDToThread (m_originating_unique_thread_id)) 90258882Semaste { 91258882Semaste return GetProcess()->AssignIndexIDToThread (m_originating_unique_thread_id); 92258882Semaste } 93258882Semaste } 94258882Semaste return LLDB_INVALID_THREAD_ID; 95258882Semaste} 96