xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/Trace/intel-pt/ThreadDecoder.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
181ad6265SDimitry Andric //===-- ThreadDecoder.h --======---------------------------------*- C++ -*-===//
281ad6265SDimitry Andric //
381ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
481ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
581ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
681ad6265SDimitry Andric //
781ad6265SDimitry Andric //===----------------------------------------------------------------------===//
881ad6265SDimitry Andric 
981ad6265SDimitry Andric #ifndef LLDB_SOURCE_PLUGINS_TRACE_THREAD_DECODER_H
1081ad6265SDimitry Andric #define LLDB_SOURCE_PLUGINS_TRACE_THREAD_DECODER_H
1181ad6265SDimitry Andric 
1281ad6265SDimitry Andric #include "DecodedThread.h"
1381ad6265SDimitry Andric #include "forward-declarations.h"
14*bdd1243dSDimitry Andric #include "intel-pt.h"
1581ad6265SDimitry Andric #include "lldb/Target/Process.h"
1681ad6265SDimitry Andric #include "lldb/Utility/FileSpec.h"
17*bdd1243dSDimitry Andric #include <optional>
1881ad6265SDimitry Andric 
1981ad6265SDimitry Andric namespace lldb_private {
2081ad6265SDimitry Andric namespace trace_intel_pt {
2181ad6265SDimitry Andric 
2281ad6265SDimitry Andric /// Class that handles the decoding of a thread and caches the result.
2381ad6265SDimitry Andric class ThreadDecoder {
2481ad6265SDimitry Andric public:
2581ad6265SDimitry Andric   /// \param[in] thread_sp
2681ad6265SDimitry Andric   ///     The thread whose intel pt trace buffer will be decoded.
2781ad6265SDimitry Andric   ///
2881ad6265SDimitry Andric   /// \param[in] trace
2981ad6265SDimitry Andric   ///     The main Trace object who owns this decoder and its data.
3081ad6265SDimitry Andric   ThreadDecoder(const lldb::ThreadSP &thread_sp, TraceIntelPT &trace);
3181ad6265SDimitry Andric 
3281ad6265SDimitry Andric   /// Decode the thread and store the result internally, to avoid
3381ad6265SDimitry Andric   /// recomputations.
3481ad6265SDimitry Andric   ///
3581ad6265SDimitry Andric   /// \return
3681ad6265SDimitry Andric   ///     A \a DecodedThread instance.
3781ad6265SDimitry Andric   llvm::Expected<DecodedThreadSP> Decode();
3881ad6265SDimitry Andric 
39972a253aSDimitry Andric   /// \return
40*bdd1243dSDimitry Andric   ///     The lowest TSC value in this trace if available, \a std::nullopt if
41*bdd1243dSDimitry Andric   ///     the trace is empty or the trace contains no timing information, or an
42*bdd1243dSDimitry Andric   ///     \a llvm::Error if it was not possible to set up the decoder.
43*bdd1243dSDimitry Andric   llvm::Expected<std::optional<uint64_t>> FindLowestTSC();
44972a253aSDimitry Andric 
4581ad6265SDimitry Andric   ThreadDecoder(const ThreadDecoder &other) = delete;
4681ad6265SDimitry Andric   ThreadDecoder &operator=(const ThreadDecoder &other) = delete;
4781ad6265SDimitry Andric 
4881ad6265SDimitry Andric private:
4981ad6265SDimitry Andric   llvm::Expected<DecodedThreadSP> DoDecode();
5081ad6265SDimitry Andric 
5181ad6265SDimitry Andric   lldb::ThreadSP m_thread_sp;
5281ad6265SDimitry Andric   TraceIntelPT &m_trace;
53*bdd1243dSDimitry Andric   std::optional<DecodedThreadSP> m_decoded_thread;
5481ad6265SDimitry Andric };
5581ad6265SDimitry Andric 
5681ad6265SDimitry Andric } // namespace trace_intel_pt
5781ad6265SDimitry Andric } // namespace lldb_private
5881ad6265SDimitry Andric 
5981ad6265SDimitry Andric #endif // LLDB_SOURCE_PLUGINS_TRACE_THREAD_DECODER_H
60