1 //===-- ThreadDecoder.cpp --======-----------------------------------------===// 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-exception 5 // 6 //===----------------------------------------------------------------------===// 7 8 #include "ThreadDecoder.h" 9 10 #include "llvm/Support/MemoryBuffer.h" 11 12 #include "../common/ThreadPostMortemTrace.h" 13 #include "LibiptDecoder.h" 14 #include "TraceIntelPT.h" 15 16 #include <utility> 17 18 using namespace lldb; 19 using namespace lldb_private; 20 using namespace lldb_private::trace_intel_pt; 21 using namespace llvm; 22 23 ThreadDecoder::ThreadDecoder(const ThreadSP &thread_sp, TraceIntelPT &trace) 24 : m_thread_sp(thread_sp), m_trace(trace) {} 25 26 DecodedThreadSP ThreadDecoder::Decode() { 27 if (!m_decoded_thread.hasValue()) 28 m_decoded_thread = DoDecode(); 29 return *m_decoded_thread; 30 } 31 32 DecodedThreadSP ThreadDecoder::DoDecode() { 33 DecodedThreadSP decoded_thread_sp = 34 std::make_shared<DecodedThread>(m_thread_sp); 35 36 Error err = m_trace.OnThreadBufferRead( 37 m_thread_sp->GetID(), [&](llvm::ArrayRef<uint8_t> data) { 38 DecodeTrace(*decoded_thread_sp, m_trace, data); 39 return Error::success(); 40 }); 41 if (err) 42 decoded_thread_sp->AppendError(std::move(err)); 43 return decoded_thread_sp; 44 } 45