1 #include "CommandObjectSession.h" 2 #include "lldb/Interpreter/CommandInterpreter.h" 3 #include "lldb/Interpreter/CommandReturnObject.h" 4 5 using namespace lldb; 6 using namespace lldb_private; 7 8 class CommandObjectSessionSave : public CommandObjectParsed { 9 public: 10 CommandObjectSessionSave(CommandInterpreter &interpreter) 11 : CommandObjectParsed(interpreter, "session save", 12 "Save the current session transcripts to a file.\n" 13 "If no file if specified, transcripts will be " 14 "saved to a temporary file.", 15 "session save [file]") { 16 CommandArgumentEntry arg1; 17 arg1.emplace_back(eArgTypePath, eArgRepeatOptional); 18 m_arguments.push_back(arg1); 19 } 20 21 ~CommandObjectSessionSave() override = default; 22 23 void 24 HandleArgumentCompletion(CompletionRequest &request, 25 OptionElementVector &opt_element_vector) override { 26 CommandCompletions::InvokeCommonCompletionCallbacks( 27 GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion, 28 request, nullptr); 29 } 30 31 protected: 32 bool 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())) 39 result.SetStatus(eReturnStatusSuccessFinishNoResult); 40 else 41 result.SetStatus(eReturnStatusFailed); 42 return result.Succeeded(); 43 } 44 }; 45 46 CommandObjectSession::CommandObjectSession(CommandInterpreter &interpreter) 47 : CommandObjectMultiword(interpreter, "session", 48 "Commands controlling LLDB session.", 49 "session <subcommand> [<command-options>]") { 50 LoadSubCommand("save", 51 CommandObjectSP(new CommandObjectSessionSave(interpreter))); 52 // TODO: Move 'history' subcommand from CommandObjectCommands. 53 } 54