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.\n"
23 "Note: transcripts will only be saved if "
24 "interpreter.save-transcript is true.\n",
25 "session save [file]") {
27 }
28
29 ~CommandObjectSessionSave() override = default;
30
31protected:
32 void DoExecute(Args &args, CommandReturnObject &result) override {
33 llvm::StringRef file_path;
34
35 if (!args.empty())
36 file_path = args[0].ref();
37
38 if (m_interpreter.SaveTranscript(result, file_path.str()))
40 else
42 }
43};
44
45#define LLDB_OPTIONS_history
46#include "CommandOptions.inc"
47
49public:
51 : CommandObjectParsed(interpreter, "session history",
52 "Dump the history of commands in this session.\n"
53 "Commands in the history list can be run again "
54 "using \"!<INDEX>\". \"!-<OFFSET>\" will re-run "
55 "the command that is <OFFSET> commands from the end"
56 " of the list (counting the current command).",
57 nullptr) {}
58
59 ~CommandObjectSessionHistory() override = default;
60
61 Options *GetOptions() override { return &m_options; }
62
63protected:
64 class CommandOptions : public Options {
65 public:
67 : m_start_idx(0), m_stop_idx(0), m_count(0), m_clear(false) {}
68
69 ~CommandOptions() override = default;
70
71 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
72 ExecutionContext *execution_context) override {
74 const int short_option = m_getopt_table[option_idx].val;
75
76 switch (short_option) {
77 case 'c':
79 break;
80 case 's':
81 if (option_arg == "end") {
84 } else
87 break;
88 case 'e':
89 error =
91 break;
92 case 'C':
95 break;
96 default:
97 llvm_unreachable("Unimplemented option");
98 }
99
100 return error;
101 }
102
103 void OptionParsingStarting(ExecutionContext *execution_context) override {
106 m_count.Clear();
107 m_clear.Clear();
108 }
109
110 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
111 return llvm::ArrayRef(g_history_options);
112 }
113
114 // Instance variables to hold the values for command options.
115
120 };
121
122 void DoExecute(Args &command, CommandReturnObject &result) override {
127 } else {
131 result.AppendError("--count, --start-index and --end-index cannot be "
132 "all specified in the same invocation");
134 } else {
135 std::pair<bool, uint64_t> start_idx(
138 std::pair<bool, uint64_t> stop_idx(
141 std::pair<bool, uint64_t> count(m_options.m_count.OptionWasSet(),
143
145
146 if (start_idx.first && start_idx.second == UINT64_MAX) {
147 if (count.first) {
148 start_idx.second = history.GetSize() - count.second;
149 stop_idx.second = history.GetSize() - 1;
150 } else if (stop_idx.first) {
151 start_idx.second = stop_idx.second;
152 stop_idx.second = history.GetSize() - 1;
153 } else {
154 start_idx.second = 0;
155 stop_idx.second = history.GetSize() - 1;
156 }
157 } else {
158 if (!start_idx.first && !stop_idx.first && !count.first) {
159 start_idx.second = 0;
160 stop_idx.second = history.GetSize() - 1;
161 } else if (start_idx.first) {
162 if (count.first) {
163 stop_idx.second = start_idx.second + count.second - 1;
164 } else if (!stop_idx.first) {
165 stop_idx.second = history.GetSize() - 1;
166 }
167 } else if (stop_idx.first) {
168 if (count.first) {
169 if (stop_idx.second >= count.second)
170 start_idx.second = stop_idx.second - count.second + 1;
171 else
172 start_idx.second = 0;
173 }
174 } else /* if (count.first) */
175 {
176 start_idx.second = 0;
177 stop_idx.second = count.second - 1;
178 }
179 }
180 history.Dump(result.GetOutputStream(), start_idx.second,
181 stop_idx.second);
182 }
183 }
184 }
185
187};
188
190 : CommandObjectMultiword(interpreter, "session",
191 "Commands controlling LLDB session.",
192 "session <subcommand> [<command-options>]") {
193 LoadSubCommand("save",
194 CommandObjectSP(new CommandObjectSessionSave(interpreter)));
195 LoadSubCommand("history",
197}
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:122
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:118
#define UINT64_MAX
Definition: lldb-defines.h:23
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
Definition: lldb-forward.h:333
@ eReturnStatusFailed
@ eReturnStatusSuccessFinishNoResult