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 }
26
27 ~CommandObjectSessionSave() override = default;
28
29protected:
30 void DoExecute(Args &args, CommandReturnObject &result) override {
31 llvm::StringRef file_path;
32
33 if (!args.empty())
34 file_path = args[0].ref();
35
36 if (m_interpreter.SaveTranscript(result, file_path.str()))
38 else
40 }
41};
42
43#define LLDB_OPTIONS_history
44#include "CommandOptions.inc"
45
47public:
49 : CommandObjectParsed(interpreter, "session history",
50 "Dump the history of commands in this session.\n"
51 "Commands in the history list can be run again "
52 "using \"!<INDEX>\". \"!-<OFFSET>\" will re-run "
53 "the command that is <OFFSET> commands from the end"
54 " of the list (counting the current command).",
55 nullptr) {}
56
57 ~CommandObjectSessionHistory() override = default;
58
59 Options *GetOptions() override { return &m_options; }
60
61protected:
62 class CommandOptions : public Options {
63 public:
65 : m_start_idx(0), m_stop_idx(0), m_count(0), m_clear(false) {}
66
67 ~CommandOptions() override = default;
68
69 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
70 ExecutionContext *execution_context) override {
72 const int short_option = m_getopt_table[option_idx].val;
73
74 switch (short_option) {
75 case 'c':
77 break;
78 case 's':
79 if (option_arg == "end") {
82 } else
85 break;
86 case 'e':
87 error =
89 break;
90 case 'C':
93 break;
94 default:
95 llvm_unreachable("Unimplemented option");
96 }
97
98 return error;
99 }
100
101 void OptionParsingStarting(ExecutionContext *execution_context) override {
104 m_count.Clear();
105 m_clear.Clear();
106 }
107
108 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
109 return llvm::ArrayRef(g_history_options);
110 }
111
112 // Instance variables to hold the values for command options.
113
118 };
119
120 void DoExecute(Args &command, CommandReturnObject &result) override {
125 } else {
129 result.AppendError("--count, --start-index and --end-index cannot be "
130 "all specified in the same invocation");
132 } else {
133 std::pair<bool, uint64_t> start_idx(
136 std::pair<bool, uint64_t> stop_idx(
139 std::pair<bool, uint64_t> count(m_options.m_count.OptionWasSet(),
141
143
144 if (start_idx.first && start_idx.second == UINT64_MAX) {
145 if (count.first) {
146 start_idx.second = history.GetSize() - count.second;
147 stop_idx.second = history.GetSize() - 1;
148 } else if (stop_idx.first) {
149 start_idx.second = stop_idx.second;
150 stop_idx.second = history.GetSize() - 1;
151 } else {
152 start_idx.second = 0;
153 stop_idx.second = history.GetSize() - 1;
154 }
155 } else {
156 if (!start_idx.first && !stop_idx.first && !count.first) {
157 start_idx.second = 0;
158 stop_idx.second = history.GetSize() - 1;
159 } else if (start_idx.first) {
160 if (count.first) {
161 stop_idx.second = start_idx.second + count.second - 1;
162 } else if (!stop_idx.first) {
163 stop_idx.second = history.GetSize() - 1;
164 }
165 } else if (stop_idx.first) {
166 if (count.first) {
167 if (stop_idx.second >= count.second)
168 start_idx.second = stop_idx.second - count.second + 1;
169 else
170 start_idx.second = 0;
171 }
172 } else /* if (count.first) */
173 {
174 start_idx.second = 0;
175 stop_idx.second = count.second - 1;
176 }
177 }
178 history.Dump(result.GetOutputStream(), start_idx.second,
179 stop_idx.second);
180 }
181 }
182 }
183
185};
186
188 : CommandObjectMultiword(interpreter, "session",
189 "Commands controlling LLDB session.",
190 "session <subcommand> [<command-options>]") {
191 LoadSubCommand("save",
192 CommandObjectSP(new CommandObjectSessionSave(interpreter)));
193 LoadSubCommand("history",
195}
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
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectSessionSave() override=default
void DoExecute(Args &args, CommandReturnObject &result) override
CommandObjectSessionSave(CommandInterpreter &interpreter)
A command line argument class.
Definition: Args.h:33
bool empty() const
Definition: Args.h:118
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)
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
CommandInterpreter & m_interpreter
void void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool SetCurrentValue(uint64_t value)
Status SetValueFromString(llvm::StringRef value, VarSetOperationType op=eVarSetOperationAssign) override
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
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
Definition: lldb-forward.h:325
@ eReturnStatusFailed
@ eReturnStatusSuccessFinishNoResult