1 //===-- IntelPTDecoder.h --======--------------------------------*- C++ -*-===// 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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_DECODER_H 10 #define LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_DECODER_H 11 12 #include "intel-pt.h" 13 14 #include "DecodedThread.h" 15 #include "forward-declarations.h" 16 #include "lldb/Target/Process.h" 17 #include "lldb/Utility/FileSpec.h" 18 19 namespace lldb_private { 20 namespace trace_intel_pt { 21 22 /// Base class that handles the decoding of a thread and caches the result. 23 class ThreadDecoder { 24 public: 25 virtual ~ThreadDecoder() = default; 26 27 ThreadDecoder() = default; 28 29 /// Decode the thread and store the result internally, to avoid 30 /// recomputations. 31 /// 32 /// \return 33 /// A \a DecodedThread instance. 34 DecodedThreadSP Decode(); 35 36 ThreadDecoder(const ThreadDecoder &other) = delete; 37 ThreadDecoder &operator=(const ThreadDecoder &other) = delete; 38 39 protected: 40 /// Decode the thread. 41 /// 42 /// \return 43 /// A \a DecodedThread instance. 44 virtual DecodedThreadSP DoDecode() = 0; 45 46 llvm::Optional<DecodedThreadSP> m_decoded_thread; 47 }; 48 49 /// Decoder implementation for \a lldb_private::ThreadPostMortemTrace, which are 50 /// non-live processes that come trace session files. 51 class PostMortemThreadDecoder : public ThreadDecoder { 52 public: 53 /// \param[in] trace_thread 54 /// The thread whose trace file will be decoded. 55 /// 56 /// \param[in] trace 57 /// The main Trace object who owns this decoder and its data. 58 PostMortemThreadDecoder(const lldb::ThreadPostMortemTraceSP &trace_thread, 59 TraceIntelPT &trace); 60 61 private: 62 DecodedThreadSP DoDecode() override; 63 64 lldb::ThreadPostMortemTraceSP m_trace_thread; 65 TraceIntelPT &m_trace; 66 }; 67 68 class LiveThreadDecoder : public ThreadDecoder { 69 public: 70 /// \param[in] thread 71 /// The thread whose traces will be decoded. 72 /// 73 /// \param[in] trace 74 /// The main Trace object who owns this decoder and its data. 75 LiveThreadDecoder(Thread &thread, TraceIntelPT &trace); 76 77 private: 78 DecodedThreadSP DoDecode() override; 79 80 lldb::ThreadSP m_thread_sp; 81 TraceIntelPT &m_trace; 82 }; 83 84 } // namespace trace_intel_pt 85 } // namespace lldb_private 86 87 #endif // LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_DECODER_H 88