Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Process/Utility/HistoryThread.cpp
39644 views
//===-- HistoryThread.cpp -------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/lldb-private.h"910#include "Plugins/Process/Utility/HistoryThread.h"1112#include "Plugins/Process/Utility/HistoryUnwind.h"13#include "Plugins/Process/Utility/RegisterContextHistory.h"1415#include "lldb/Target/Process.h"16#include "lldb/Target/StackFrameList.h"17#include "lldb/Utility/LLDBLog.h"18#include "lldb/Utility/Log.h"1920#include <memory>2122using namespace lldb;23using namespace lldb_private;2425// Constructor2627HistoryThread::HistoryThread(lldb_private::Process &process, lldb::tid_t tid,28std::vector<lldb::addr_t> pcs,29bool pcs_are_call_addresses)30: Thread(process, tid, true), m_framelist_mutex(), m_framelist(),31m_pcs(pcs), m_extended_unwind_token(LLDB_INVALID_ADDRESS), m_queue_name(),32m_thread_name(), m_originating_unique_thread_id(tid),33m_queue_id(LLDB_INVALID_QUEUE_ID) {34m_unwinder_up =35std::make_unique<HistoryUnwind>(*this, pcs, pcs_are_call_addresses);36Log *log = GetLog(LLDBLog::Object);37LLDB_LOGF(log, "%p HistoryThread::HistoryThread", static_cast<void *>(this));38}3940// Destructor4142HistoryThread::~HistoryThread() {43Log *log = GetLog(LLDBLog::Object);44LLDB_LOGF(log, "%p HistoryThread::~HistoryThread (tid=0x%" PRIx64 ")",45static_cast<void *>(this), GetID());46DestroyThread();47}4849lldb::RegisterContextSP HistoryThread::GetRegisterContext() {50RegisterContextSP rctx;51if (m_pcs.size() > 0) {52rctx = std::make_shared<RegisterContextHistory>(53*this, 0, GetProcess()->GetAddressByteSize(), m_pcs[0]);54}55return rctx;56}5758lldb::RegisterContextSP59HistoryThread::CreateRegisterContextForFrame(StackFrame *frame) {60return m_unwinder_up->CreateRegisterContextForFrame(frame);61}6263lldb::StackFrameListSP HistoryThread::GetStackFrameList() {64// FIXME do not throw away the lock after we acquire it..65std::unique_lock<std::mutex> lock(m_framelist_mutex);66lock.unlock();67if (m_framelist.get() == nullptr) {68m_framelist =69std::make_shared<StackFrameList>(*this, StackFrameListSP(), true);70}7172return m_framelist;73}7475uint32_t HistoryThread::GetExtendedBacktraceOriginatingIndexID() {76if (m_originating_unique_thread_id != LLDB_INVALID_THREAD_ID) {77if (GetProcess()->HasAssignedIndexIDToThread(78m_originating_unique_thread_id)) {79return GetProcess()->AssignIndexIDToThread(80m_originating_unique_thread_id);81}82}83return LLDB_INVALID_THREAD_ID;84}858687