xref: /openbsd-src/gnu/llvm/lldb/source/Plugins/Trace/intel-pt/ThreadDecoder.h (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1*f6aab3d8Srobert //===-- ThreadDecoder.h --======---------------------------------*- C++ -*-===//
2*f6aab3d8Srobert //
3*f6aab3d8Srobert // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*f6aab3d8Srobert // See https://llvm.org/LICENSE.txt for license information.
5*f6aab3d8Srobert // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*f6aab3d8Srobert //
7*f6aab3d8Srobert //===----------------------------------------------------------------------===//
8*f6aab3d8Srobert 
9*f6aab3d8Srobert #ifndef LLDB_SOURCE_PLUGINS_TRACE_THREAD_DECODER_H
10*f6aab3d8Srobert #define LLDB_SOURCE_PLUGINS_TRACE_THREAD_DECODER_H
11*f6aab3d8Srobert 
12*f6aab3d8Srobert #include "DecodedThread.h"
13*f6aab3d8Srobert #include "forward-declarations.h"
14*f6aab3d8Srobert #include "intel-pt.h"
15*f6aab3d8Srobert #include "lldb/Target/Process.h"
16*f6aab3d8Srobert #include "lldb/Utility/FileSpec.h"
17*f6aab3d8Srobert #include <optional>
18*f6aab3d8Srobert 
19*f6aab3d8Srobert namespace lldb_private {
20*f6aab3d8Srobert namespace trace_intel_pt {
21*f6aab3d8Srobert 
22*f6aab3d8Srobert /// Class that handles the decoding of a thread and caches the result.
23*f6aab3d8Srobert class ThreadDecoder {
24*f6aab3d8Srobert public:
25*f6aab3d8Srobert   /// \param[in] thread_sp
26*f6aab3d8Srobert   ///     The thread whose intel pt trace buffer will be decoded.
27*f6aab3d8Srobert   ///
28*f6aab3d8Srobert   /// \param[in] trace
29*f6aab3d8Srobert   ///     The main Trace object who owns this decoder and its data.
30*f6aab3d8Srobert   ThreadDecoder(const lldb::ThreadSP &thread_sp, TraceIntelPT &trace);
31*f6aab3d8Srobert 
32*f6aab3d8Srobert   /// Decode the thread and store the result internally, to avoid
33*f6aab3d8Srobert   /// recomputations.
34*f6aab3d8Srobert   ///
35*f6aab3d8Srobert   /// \return
36*f6aab3d8Srobert   ///     A \a DecodedThread instance.
37*f6aab3d8Srobert   llvm::Expected<DecodedThreadSP> Decode();
38*f6aab3d8Srobert 
39*f6aab3d8Srobert   /// \return
40*f6aab3d8Srobert   ///     The lowest TSC value in this trace if available, \a std::nullopt if
41*f6aab3d8Srobert   ///     the trace is empty or the trace contains no timing information, or an
42*f6aab3d8Srobert   ///     \a llvm::Error if it was not possible to set up the decoder.
43*f6aab3d8Srobert   llvm::Expected<std::optional<uint64_t>> FindLowestTSC();
44*f6aab3d8Srobert 
45*f6aab3d8Srobert   ThreadDecoder(const ThreadDecoder &other) = delete;
46*f6aab3d8Srobert   ThreadDecoder &operator=(const ThreadDecoder &other) = delete;
47*f6aab3d8Srobert 
48*f6aab3d8Srobert private:
49*f6aab3d8Srobert   llvm::Expected<DecodedThreadSP> DoDecode();
50*f6aab3d8Srobert 
51*f6aab3d8Srobert   lldb::ThreadSP m_thread_sp;
52*f6aab3d8Srobert   TraceIntelPT &m_trace;
53*f6aab3d8Srobert   std::optional<DecodedThreadSP> m_decoded_thread;
54*f6aab3d8Srobert };
55*f6aab3d8Srobert 
56*f6aab3d8Srobert } // namespace trace_intel_pt
57*f6aab3d8Srobert } // namespace lldb_private
58*f6aab3d8Srobert 
59*f6aab3d8Srobert #endif // LLDB_SOURCE_PLUGINS_TRACE_THREAD_DECODER_H
60