1b952cd58SEd Maste //===-- HistoryThread.cpp ---------------------------------------*- C++ -*-===//
2b952cd58SEd Maste //
3b952cd58SEd Maste // The LLVM Compiler Infrastructure
4b952cd58SEd Maste //
5b952cd58SEd Maste // This file is distributed under the University of Illinois Open Source
6b952cd58SEd Maste // License. See LICENSE.TXT for details.
7b952cd58SEd Maste //
8b952cd58SEd Maste //===----------------------------------------------------------------------===//
9b952cd58SEd Maste
10b952cd58SEd Maste #include "lldb/lldb-private.h"
11b952cd58SEd Maste
12b952cd58SEd Maste #include "Plugins/Process/Utility/HistoryThread.h"
13435933ddSDimitry Andric #include "Plugins/Process/Utility/HistoryUnwind.h"
14b952cd58SEd Maste #include "Plugins/Process/Utility/RegisterContextHistory.h"
15b952cd58SEd Maste
16b952cd58SEd Maste #include "lldb/Target/Process.h"
17435933ddSDimitry Andric #include "lldb/Target/StackFrameList.h"
18*f678e45dSDimitry Andric #include "lldb/Utility/Log.h"
19b952cd58SEd Maste
20b952cd58SEd Maste using namespace lldb;
21b952cd58SEd Maste using namespace lldb_private;
22b952cd58SEd Maste
230127ef0fSEd Maste // Constructor
240127ef0fSEd Maste
HistoryThread(lldb_private::Process & process,lldb::tid_t tid,std::vector<lldb::addr_t> pcs,uint32_t stop_id,bool stop_id_is_valid)25435933ddSDimitry Andric HistoryThread::HistoryThread(lldb_private::Process &process, lldb::tid_t tid,
26435933ddSDimitry Andric std::vector<lldb::addr_t> pcs, uint32_t stop_id,
27435933ddSDimitry Andric bool stop_id_is_valid)
28435933ddSDimitry Andric : Thread(process, tid, true), m_framelist_mutex(), m_framelist(),
29435933ddSDimitry Andric m_pcs(pcs), m_stop_id(stop_id), m_stop_id_is_valid(stop_id_is_valid),
30435933ddSDimitry Andric m_extended_unwind_token(LLDB_INVALID_ADDRESS), m_queue_name(),
31435933ddSDimitry Andric m_thread_name(), m_originating_unique_thread_id(tid),
32435933ddSDimitry Andric m_queue_id(LLDB_INVALID_QUEUE_ID) {
337aa51b79SEd Maste m_unwinder_ap.reset(new HistoryUnwind(*this, pcs, stop_id_is_valid));
34b952cd58SEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
35b952cd58SEd Maste if (log)
364bb0738eSEd Maste log->Printf("%p HistoryThread::HistoryThread", static_cast<void *>(this));
37b952cd58SEd Maste }
38b952cd58SEd Maste
390127ef0fSEd Maste // Destructor
400127ef0fSEd Maste
~HistoryThread()41435933ddSDimitry Andric HistoryThread::~HistoryThread() {
42b952cd58SEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
43b952cd58SEd Maste if (log)
440127ef0fSEd Maste log->Printf("%p HistoryThread::~HistoryThread (tid=0x%" PRIx64 ")",
450127ef0fSEd Maste static_cast<void *>(this), GetID());
46b952cd58SEd Maste DestroyThread();
47b952cd58SEd Maste }
48b952cd58SEd Maste
GetRegisterContext()49435933ddSDimitry Andric lldb::RegisterContextSP HistoryThread::GetRegisterContext() {
50b952cd58SEd Maste RegisterContextSP rctx;
51435933ddSDimitry Andric if (m_pcs.size() > 0) {
52435933ddSDimitry Andric rctx.reset(new RegisterContextHistory(
53435933ddSDimitry Andric *this, 0, GetProcess()->GetAddressByteSize(), m_pcs[0]));
54b952cd58SEd Maste }
55b952cd58SEd Maste return rctx;
56b952cd58SEd Maste }
57b952cd58SEd Maste
58b952cd58SEd Maste lldb::RegisterContextSP
CreateRegisterContextForFrame(StackFrame * frame)59435933ddSDimitry Andric HistoryThread::CreateRegisterContextForFrame(StackFrame *frame) {
60b952cd58SEd Maste return m_unwinder_ap->CreateRegisterContextForFrame(frame);
61b952cd58SEd Maste }
62b952cd58SEd Maste
GetStackFrameList()63435933ddSDimitry Andric lldb::StackFrameListSP HistoryThread::GetStackFrameList() {
644bb0738eSEd Maste // FIXME do not throw away the lock after we acquire it..
654bb0738eSEd Maste std::unique_lock<std::mutex> lock(m_framelist_mutex);
664bb0738eSEd Maste lock.unlock();
67435933ddSDimitry Andric if (m_framelist.get() == NULL) {
68b952cd58SEd Maste m_framelist.reset(new StackFrameList(*this, StackFrameListSP(), true));
69b952cd58SEd Maste }
70b952cd58SEd Maste
71b952cd58SEd Maste return m_framelist;
72b952cd58SEd Maste }
73b952cd58SEd Maste
GetExtendedBacktraceOriginatingIndexID()74435933ddSDimitry Andric uint32_t HistoryThread::GetExtendedBacktraceOriginatingIndexID() {
75435933ddSDimitry Andric if (m_originating_unique_thread_id != LLDB_INVALID_THREAD_ID) {
76435933ddSDimitry Andric if (GetProcess()->HasAssignedIndexIDToThread(
77435933ddSDimitry Andric m_originating_unique_thread_id)) {
78435933ddSDimitry Andric return GetProcess()->AssignIndexIDToThread(
79435933ddSDimitry Andric m_originating_unique_thread_id);
80b952cd58SEd Maste }
81b952cd58SEd Maste }
82b952cd58SEd Maste return LLDB_INVALID_THREAD_ID;
83b952cd58SEd Maste }
84