brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 93efa2a Raw
85 lines · cpp
1//===-- HistoryThread.cpp -------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "lldb/lldb-private.h"10 11#include "Plugins/Process/Utility/HistoryThread.h"12 13#include "Plugins/Process/Utility/HistoryUnwind.h"14#include "Plugins/Process/Utility/RegisterContextHistory.h"15 16#include "lldb/Target/Process.h"17#include "lldb/Target/StackFrameList.h"18#include "lldb/Utility/LLDBLog.h"19#include "lldb/Utility/Log.h"20 21#include <memory>22 23using namespace lldb;24using namespace lldb_private;25 26//  Constructor27 28HistoryThread::HistoryThread(lldb_private::Process &process, lldb::tid_t tid,29                             std::vector<lldb::addr_t> pcs,30                             HistoryPCType pc_type)31    : Thread(process, tid, true), m_framelist_mutex(), m_framelist(),32      m_pcs(pcs), m_extended_unwind_token(LLDB_INVALID_ADDRESS), m_queue_name(),33      m_thread_name(), m_originating_unique_thread_id(tid),34      m_queue_id(LLDB_INVALID_QUEUE_ID) {35  m_unwinder_up = std::make_unique<HistoryUnwind>(*this, pcs, pc_type);36  Log *log = GetLog(LLDBLog::Object);37  LLDB_LOGF(log, "%p HistoryThread::HistoryThread", static_cast<void *>(this));38}39 40//  Destructor41 42HistoryThread::~HistoryThread() {43  Log *log = GetLog(LLDBLog::Object);44  LLDB_LOGF(log, "%p HistoryThread::~HistoryThread (tid=0x%" PRIx64 ")",45            static_cast<void *>(this), GetID());46  DestroyThread();47}48 49lldb::RegisterContextSP HistoryThread::GetRegisterContext() {50  RegisterContextSP rctx;51  if (m_pcs.size() > 0) {52    rctx = std::make_shared<RegisterContextHistory>(53        *this, 0, GetProcess()->GetAddressByteSize(), m_pcs[0]);54  }55  return rctx;56}57 58lldb::RegisterContextSP59HistoryThread::CreateRegisterContextForFrame(StackFrame *frame) {60  return m_unwinder_up->CreateRegisterContextForFrame(frame);61}62 63lldb::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() == nullptr) {68    m_framelist =69        std::make_shared<StackFrameList>(*this, StackFrameListSP(), true);70  }71 72  return m_framelist;73}74 75uint32_t HistoryThread::GetExtendedBacktraceOriginatingIndexID() {76  if (m_originating_unique_thread_id != LLDB_INVALID_THREAD_ID) {77    if (GetProcess()->HasAssignedIndexIDToThread(78            m_originating_unique_thread_id)) {79      return GetProcess()->AssignIndexIDToThread(80          m_originating_unique_thread_id);81    }82  }83  return LLDB_INVALID_THREAD_ID;84}85