LLDB mainline
CommandObjectSession.cpp
Go to the documentation of this file.
12
13using namespace lldb;
14using namespace lldb_private;
15
17public:
19 : CommandObjectParsed(interpreter, "session save",
20 "Save the current session transcripts to a file.\n"
21 "If no file if specified, transcripts will be "
22 "saved to a temporary file.",
23 "session save [file]") {
25 arg1.emplace_back(eArgTypePath, eArgRepeatOptional);
26 m_arguments.push_back(arg1);
27 }
28
29 ~CommandObjectSessionSave() override = default;
30
31 void
33 OptionElementVector &opt_element_vector) override {
36 request, nullptr);
37 }
38
39protected:
40 bool DoExecute(Args &args, CommandReturnObject &result) override {
41 llvm::StringRef file_path;
42
43 if (!args.empty())
44 file_path = args[0].ref();
45
46 if (m_interpreter.SaveTranscript(result, file_path.str()))
48 else
50 return result.Succeeded();
51 }
52};
53
54#define LLDB_OPTIONS_history
55#include "CommandOptions.inc"
56
58public:
60 : CommandObjectParsed(interpreter, "session history",
61 "Dump the history of commands in this session.\n"
62 "Commands in the history list can be run again "
63 "using \"!<INDEX>\". \"!-<OFFSET>\" will re-run "
64 "the command that is <OFFSET> commands from the end"
65 " of the list (counting the current command).",
66 nullptr) {}
67
68 ~CommandObjectSessionHistory() override = default;
69
70 Options *GetOptions() override { return &m_options; }
71
72protected:
73 class CommandOptions : public Options {
74 public:
76 : m_start_idx(0), m_stop_idx(0), m_count(0), m_clear(false) {}
77
78 ~CommandOptions() override = default;
79
80 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
81 ExecutionContext *execution_context) override {
83 const int short_option = m_getopt_table[option_idx].val;
84
85 switch (short_option) {
86 case 'c':
88 break;
89 case 's':
90 if (option_arg == "end") {
93 } else
96 break;
97 case 'e':
98 error =
100 break;
101 case 'C':
104 break;
105 default:
106 llvm_unreachable("Unimplemented option");
107 }
108
109 return error;
110 }
111
112 void OptionParsingStarting(ExecutionContext *execution_context) override {
115 m_count.Clear();
116 m_clear.Clear();
117 }
118
119 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
120 return llvm::ArrayRef(g_history_options);
121 }
122
123 // Instance variables to hold the values for command options.
124
129 };
130
131 bool DoExecute(Args &command, CommandReturnObject &result) override {
136 } else {
140 result.AppendError("--count, --start-index and --end-index cannot be "
141 "all specified in the same invocation");
143 } else {
144 std::pair<bool, uint64_t> start_idx(
147 std::pair<bool, uint64_t> stop_idx(
150 std::pair<bool, uint64_t> count(m_options.m_count.OptionWasSet(),
152
154
155 if (start_idx.first && start_idx.second == UINT64_MAX) {
156 if (count.first) {
157 start_idx.second = history.GetSize() - count.second;
158 stop_idx.second = history.GetSize() - 1;
159 } else if (stop_idx.first) {
160 start_idx.second = stop_idx.second;
161 stop_idx.second = history.GetSize() - 1;
162 } else {
163 start_idx.second = 0;
164 stop_idx.second = history.GetSize() - 1;
165 }
166 } else {
167 if (!start_idx.first && !stop_idx.first && !count.first) {
168 start_idx.second = 0;
169 stop_idx.second = history.GetSize() - 1;
170 } else if (start_idx.first) {
171 if (count.first) {
172 stop_idx.second = start_idx.second + count.second - 1;
173 } else if (!stop_idx.first) {
174 stop_idx.second = history.GetSize() - 1;
175 }
176 } else if (stop_idx.first) {
177 if (count.first) {
178 if (stop_idx.second >= count.second)
179 start_idx.second = stop_idx.second - count.second + 1;
180 else
181 start_idx.second = 0;
182 }
183 } else /* if (count.first) */
184 {
185 start_idx.second = 0;
186 stop_idx.second = count.second - 1;
187 }
188 }
189 history.Dump(result.GetOutputStream(), start_idx.second,
190 stop_idx.second);
191 }
192 }
193 return result.Succeeded();
194 }
195
197};
198
200 : CommandObjectMultiword(interpreter, "session",
201 "Commands controlling LLDB session.",
202 "session <subcommand> [<command-options>]") {
203 LoadSubCommand("save",
204 CommandObjectSP(new CommandObjectSessionSave(interpreter)));
205 LoadSubCommand("history",
206 CommandObjectSP(new CommandObjectSessionHistory(interpreter)));
207}
static llvm::raw_ostream & error(Stream &strm)
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void OptionParsingStarting(ExecutionContext *execution_context) override
CommandObjectSessionHistory(CommandInterpreter &interpreter)
~CommandObjectSessionHistory() override=default
bool DoExecute(Args &command, CommandReturnObject &result) override
bool DoExecute(Args &args, CommandReturnObject &result) override
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
~CommandObjectSessionSave() override=default
CommandObjectSessionSave(CommandInterpreter &interpreter)
A command line argument class.
Definition: Args.h:33
bool empty() const
Definition: Args.h:118
static bool InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, uint32_t completion_mask, lldb_private::CompletionRequest &request, SearchFilter *searcher)
void Dump(Stream &stream, size_t start_idx=0, size_t stop_idx=SIZE_MAX) const
bool SaveTranscript(CommandReturnObject &result, std::optional< std::string > output_file=std::nullopt)
Save the current debugger session transcript to a file on disk.
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
CommandObjectSession(CommandInterpreter &interpreter)
std::vector< CommandArgumentData > CommandArgumentEntry
std::vector< CommandArgumentEntry > m_arguments
CommandInterpreter & GetCommandInterpreter()
CommandInterpreter & m_interpreter
void void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
"lldb/Utility/ArgCompletionRequest.h"
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
void SetCurrentValue(uint64_t value)
A command line option parsing protocol class.
Definition: Options.h:58
std::vector< Option > m_getopt_table
Definition: Options.h:198
An error handling class.
Definition: Status.h:44
#define UINT64_MAX
Definition: lldb-defines.h:23
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
std::vector< OptionArgElement > OptionElementVector
Definition: Options.h:43
Definition: SBAddress.h:15
@ eReturnStatusFailed
@ eReturnStatusSuccessFinishNoResult