1 //===-- SBTrace.h -----------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLDB_SBTrace_h_
11 #define LLDB_SBTrace_h_
12 
13 #include "lldb/API/SBDefines.h"
14 #include "lldb/API/SBError.h"
15 
16 class TraceImpl;
17 
18 namespace lldb {
19 
20 class LLDB_API SBTrace {
21 public:
22   SBTrace();
23   //------------------------------------------------------------------
24   /// Obtain the trace data as raw bytes.
25   ///
26   /// @param[out] error
27   ///     An error explaining what went wrong.
28   ///
29   /// @param[in] buf
30   ///     Buffer to write the trace data to.
31   ///
32   /// @param[in] size
33   ///     The size of the buffer used to read the data. This is
34   ///     also the size of the data intended to read. It is also
35   ///     possible to partially read the trace data for some trace
36   ///     technologies by specifying a smaller buffer.
37   ///
38   /// @param[in] offset
39   ///     The start offset to begin reading the trace data.
40   ///
41   /// @param[in] thread_id
42   ///     Tracing could be started for the complete process or a
43   ///     single thread, in the first case the traceid obtained would
44   ///     map to all the threads existing within the process and the
45   ///     ones spawning later. The thread_id parameter can be used in
46   ///     such a scenario to select the trace data for a specific
47   ///     thread.
48   ///
49   /// @return
50   ///     The size of the trace data effectively read by the API call.
51   //------------------------------------------------------------------
52   size_t GetTraceData(SBError &error, void *buf, size_t size, size_t offset = 0,
53                       lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID);
54 
55   //------------------------------------------------------------------
56   /// Obtain any meta data as raw bytes for the tracing instance.
57   /// The input parameter definition is similar to the previous
58   /// function.
59   //------------------------------------------------------------------
60   size_t GetMetaData(SBError &error, void *buf, size_t size, size_t offset = 0,
61                      lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID);
62 
63   //------------------------------------------------------------------
64   /// Stop the tracing instance. Stopping the trace will also
65   /// lead to deletion of any gathered trace data.
66   ///
67   /// @param[out] error
68   ///     An error explaining what went wrong.
69   ///
70   /// @param[in] thread_id
71   ///     The trace id could map to a tracing instance for a thread
72   ///     or could also map to a group of threads being traced with
73   ///     the same trace options. A thread_id is normally optional
74   ///     except in the case of tracing a complete process and tracing
75   ///     needs to switched off on a particular thread.
76   ///     A situation could occur where initially a thread (lets say
77   ///     thread A) is being individually traced with a particular
78   ///     trace id and then tracing is started on the complete
79   ///     process, in this case thread A will continue without any
80   ///     change. All newly spawned threads would be traced with the
81   ///     trace id of the process.
82   ///     Now if the StopTrace API is called for the whole process,
83   ///     thread A will not be stopped and must be stopped separately.
84   //------------------------------------------------------------------
85   void StopTrace(SBError &error,
86                  lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID);
87 
88   //------------------------------------------------------------------
89   /// Get the trace configuration being used for the trace instance.
90   /// The threadid in the SBTraceOptions needs to be set when the
91   /// configuration used by a specific thread is being requested.
92   ///
93   /// @param[out] options
94   ///     The trace options actually used by the trace instance
95   ///     would be filled by the API.
96   ///
97   /// @param[out] error
98   ///     An error explaining what went wrong.
99   //------------------------------------------------------------------
100   void GetTraceConfig(SBTraceOptions &options, SBError &error);
101 
102   lldb::user_id_t GetTraceUID();
103 
104   bool IsValid();
105 
106 protected:
107   typedef std::shared_ptr<TraceImpl> TraceImplSP;
108 
109   friend class SBProcess;
110 
111   void SetTraceUID(lldb::user_id_t uid);
112 
113   TraceImplSP m_trace_impl_sp;
114 
115   lldb::ProcessSP GetSP() const;
116 
117   void SetSP(const ProcessSP &process_sp);
118 
119   lldb::ProcessWP m_opaque_wp;
120 };
121 } // namespace lldb
122 
123 #endif // LLDB_SBTrace_h_
124