Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Trace/intel-pt/ThreadDecoder.cpp
39645 views
//===-- ThreadDecoder.cpp --======-----------------------------------------===//1// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.2// See https://llvm.org/LICENSE.txt for license information.3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception4//5//===----------------------------------------------------------------------===//67#include "ThreadDecoder.h"8#include "../common/ThreadPostMortemTrace.h"9#include "LibiptDecoder.h"10#include "TraceIntelPT.h"11#include "llvm/Support/MemoryBuffer.h"12#include <optional>13#include <utility>1415using namespace lldb;16using namespace lldb_private;17using namespace lldb_private::trace_intel_pt;18using namespace llvm;1920ThreadDecoder::ThreadDecoder(const ThreadSP &thread_sp, TraceIntelPT &trace)21: m_thread_sp(thread_sp), m_trace(trace) {}2223Expected<std::optional<uint64_t>> ThreadDecoder::FindLowestTSC() {24std::optional<uint64_t> lowest_tsc;25Error err = m_trace.OnThreadBufferRead(26m_thread_sp->GetID(), [&](llvm::ArrayRef<uint8_t> data) -> llvm::Error {27Expected<std::optional<uint64_t>> tsc =28FindLowestTSCInTrace(m_trace, data);29if (!tsc)30return tsc.takeError();31lowest_tsc = *tsc;32return Error::success();33});34if (err)35return std::move(err);36return lowest_tsc;37}3839Expected<DecodedThreadSP> ThreadDecoder::Decode() {40if (!m_decoded_thread.has_value()) {41if (Expected<DecodedThreadSP> decoded_thread = DoDecode()) {42m_decoded_thread = *decoded_thread;43} else {44return decoded_thread.takeError();45}46}47return *m_decoded_thread;48}4950llvm::Expected<DecodedThreadSP> ThreadDecoder::DoDecode() {51return m_trace.GetThreadTimer(m_thread_sp->GetID())52.TimeTask("Decoding instructions", [&]() -> Expected<DecodedThreadSP> {53DecodedThreadSP decoded_thread_sp = std::make_shared<DecodedThread>(54m_thread_sp, m_trace.GetPerfZeroTscConversion());5556Error err = m_trace.OnThreadBufferRead(57m_thread_sp->GetID(), [&](llvm::ArrayRef<uint8_t> data) {58return DecodeSingleTraceForThread(*decoded_thread_sp, m_trace,59data);60});6162if (err)63return std::move(err);64return decoded_thread_sp;65});66}676869