xref: /llvm-project/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.h (revision bf9f21a28be171dc500cc68b4cb1fcd3fc33f229)
1 //===-- CommandObjectTraceStartIntelPT.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_COMMANDOBJECTTRACESTARTINTELPT_H
10 #define LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTRACESTARTINTELPT_H
11 
12 #include "../../../../source/Commands/CommandObjectTrace.h"
13 #include "TraceIntelPT.h"
14 #include "lldb/Interpreter/CommandInterpreter.h"
15 #include "lldb/Interpreter/CommandReturnObject.h"
16 
17 namespace lldb_private {
18 namespace trace_intel_pt {
19 
20 class CommandObjectThreadTraceStartIntelPT
21     : public CommandObjectMultipleThreads {
22 public:
23   class CommandOptions : public Options {
24   public:
25     CommandOptions() : Options() { OptionParsingStarting(nullptr); }
26 
27     Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
28                           ExecutionContext *execution_context) override;
29 
30     void OptionParsingStarting(ExecutionContext *execution_context) override;
31 
32     llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
33 
34     size_t m_thread_buffer_size;
35   };
36 
37   CommandObjectThreadTraceStartIntelPT(TraceIntelPT &trace,
38                                        CommandInterpreter &interpreter)
39       : CommandObjectMultipleThreads(
40             interpreter, "thread trace start",
41             "Start tracing one or more threads with intel-pt. "
42             "Defaults to the current thread. Thread indices can be "
43             "specified as arguments.\n Use the thread-index \"all\" to trace "
44             "all threads including future threads.",
45             "thread trace start [<thread-index> <thread-index> ...] "
46             "[<intel-pt-options>]",
47             lldb::eCommandRequiresProcess | lldb::eCommandTryTargetAPILock |
48                 lldb::eCommandProcessMustBeLaunched |
49                 lldb::eCommandProcessMustBePaused),
50         m_trace(trace), m_options() {}
51 
52   Options *GetOptions() override { return &m_options; }
53 
54 protected:
55   bool DoExecuteOnThreads(Args &command, CommandReturnObject &result,
56                           llvm::ArrayRef<lldb::tid_t> tids) override;
57 
58   TraceIntelPT &m_trace;
59   CommandOptions m_options;
60 };
61 
62 class CommandObjectProcessTraceStartIntelPT : public CommandObjectParsed {
63 public:
64   class CommandOptions : public Options {
65   public:
66     CommandOptions() : Options() { OptionParsingStarting(nullptr); }
67 
68     Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
69                           ExecutionContext *execution_context) override;
70 
71     void OptionParsingStarting(ExecutionContext *execution_context) override;
72 
73     llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
74 
75     size_t m_thread_buffer_size;
76     size_t m_process_buffer_size_limit;
77   };
78 
79   CommandObjectProcessTraceStartIntelPT(TraceIntelPT &trace,
80                                         CommandInterpreter &interpreter)
81       : CommandObjectParsed(
82             interpreter, "process trace start",
83             "Start tracing this process with intel-pt, including future "
84             "threads. "
85             "This is implemented by tracing each thread independently. "
86             "Threads traced with the \"thread trace start\" command are left "
87             "unaffected ant not retraced.",
88             "process trace start [<intel-pt-options>]",
89             lldb::eCommandRequiresProcess | lldb::eCommandTryTargetAPILock |
90                 lldb::eCommandProcessMustBeLaunched |
91                 lldb::eCommandProcessMustBePaused),
92         m_trace(trace), m_options() {}
93 
94   Options *GetOptions() override { return &m_options; }
95 
96 protected:
97   bool DoExecute(Args &command, CommandReturnObject &result) override;
98 
99   TraceIntelPT &m_trace;
100   CommandOptions m_options;
101 };
102 
103 } // namespace trace_intel_pt
104 } // namespace lldb_private
105 
106 #endif // LLDB_SOURCE_PLUGINS_TRACE_INTEL_PT_COMMANDOBJECTTRACESTARTINTELPT_H
107