15ffd83dbSDimitry Andric //===-- CommandObjectBreakpointCommand.cpp --------------------------------===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric 9*0b57cec5SDimitry Andric #include "CommandObjectBreakpointCommand.h" 10*0b57cec5SDimitry Andric #include "CommandObjectBreakpoint.h" 11*0b57cec5SDimitry Andric #include "lldb/Breakpoint/Breakpoint.h" 12*0b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointIDList.h" 13*0b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointLocation.h" 14*0b57cec5SDimitry Andric #include "lldb/Core/IOHandler.h" 15*0b57cec5SDimitry Andric #include "lldb/Host/OptionParser.h" 16*0b57cec5SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h" 17fcaf7f86SDimitry Andric #include "lldb/Interpreter/CommandOptionArgumentTable.h" 18*0b57cec5SDimitry Andric #include "lldb/Interpreter/CommandReturnObject.h" 19*0b57cec5SDimitry Andric #include "lldb/Interpreter/OptionArgParser.h" 20480093f4SDimitry Andric #include "lldb/Interpreter/OptionGroupPythonClassWithDict.h" 21*0b57cec5SDimitry Andric #include "lldb/Target/Target.h" 22*0b57cec5SDimitry Andric 23*0b57cec5SDimitry Andric using namespace lldb; 24*0b57cec5SDimitry Andric using namespace lldb_private; 25*0b57cec5SDimitry Andric 269dba64beSDimitry Andric #define LLDB_OPTIONS_breakpoint_command_add 279dba64beSDimitry Andric #include "CommandOptions.inc" 28*0b57cec5SDimitry Andric 29*0b57cec5SDimitry Andric class CommandObjectBreakpointCommandAdd : public CommandObjectParsed, 30*0b57cec5SDimitry Andric public IOHandlerDelegateMultiline { 31*0b57cec5SDimitry Andric public: 32*0b57cec5SDimitry Andric CommandObjectBreakpointCommandAdd(CommandInterpreter &interpreter) 33*0b57cec5SDimitry Andric : CommandObjectParsed(interpreter, "add", 34*0b57cec5SDimitry Andric "Add LLDB commands to a breakpoint, to be executed " 35*0b57cec5SDimitry Andric "whenever the breakpoint is hit. " 36fe6060f1SDimitry Andric "The commands added to the breakpoint replace any " 37fe6060f1SDimitry Andric "commands previously added to it." 38*0b57cec5SDimitry Andric " If no breakpoint is specified, adds the " 39*0b57cec5SDimitry Andric "commands to the last created breakpoint.", 40*0b57cec5SDimitry Andric nullptr), 41*0b57cec5SDimitry Andric IOHandlerDelegateMultiline("DONE", 42*0b57cec5SDimitry Andric IOHandlerDelegate::Completion::LLDBCommand), 4304eeddc0SDimitry Andric m_func_options("breakpoint command", false, 'F') { 44*0b57cec5SDimitry Andric SetHelpLong( 45*0b57cec5SDimitry Andric R"( 46*0b57cec5SDimitry Andric General information about entering breakpoint commands 47*0b57cec5SDimitry Andric ------------------------------------------------------ 48*0b57cec5SDimitry Andric 49*0b57cec5SDimitry Andric )" 50*0b57cec5SDimitry Andric "This command will prompt for commands to be executed when the specified \ 51*0b57cec5SDimitry Andric breakpoint is hit. Each command is typed on its own line following the '> ' \ 52*0b57cec5SDimitry Andric prompt until 'DONE' is entered." 53*0b57cec5SDimitry Andric R"( 54*0b57cec5SDimitry Andric 55*0b57cec5SDimitry Andric )" 56*0b57cec5SDimitry Andric "Syntactic errors may not be detected when initially entered, and many \ 57*0b57cec5SDimitry Andric malformed commands can silently fail when executed. If your breakpoint commands \ 58*0b57cec5SDimitry Andric do not appear to be executing, double-check the command syntax." 59*0b57cec5SDimitry Andric R"( 60*0b57cec5SDimitry Andric 61*0b57cec5SDimitry Andric )" 62*0b57cec5SDimitry Andric "Note: You may enter any debugger command exactly as you would at the debugger \ 63*0b57cec5SDimitry Andric prompt. There is no limit to the number of commands supplied, but do NOT enter \ 64*0b57cec5SDimitry Andric more than one command per line." 65*0b57cec5SDimitry Andric R"( 66*0b57cec5SDimitry Andric 67*0b57cec5SDimitry Andric Special information about PYTHON breakpoint commands 68*0b57cec5SDimitry Andric ---------------------------------------------------- 69*0b57cec5SDimitry Andric 70*0b57cec5SDimitry Andric )" 71*0b57cec5SDimitry Andric "You may enter either one or more lines of Python, including function \ 72*0b57cec5SDimitry Andric definitions or calls to functions that will have been imported by the time \ 73*0b57cec5SDimitry Andric the code executes. Single line breakpoint commands will be interpreted 'as is' \ 74*0b57cec5SDimitry Andric when the breakpoint is hit. Multiple lines of Python will be wrapped in a \ 75*0b57cec5SDimitry Andric generated function, and a call to the function will be attached to the breakpoint." 76*0b57cec5SDimitry Andric R"( 77*0b57cec5SDimitry Andric 78*0b57cec5SDimitry Andric This auto-generated function is passed in three arguments: 79*0b57cec5SDimitry Andric 80*0b57cec5SDimitry Andric frame: an lldb.SBFrame object for the frame which hit breakpoint. 81*0b57cec5SDimitry Andric 82*0b57cec5SDimitry Andric bp_loc: an lldb.SBBreakpointLocation object that represents the breakpoint location that was hit. 83*0b57cec5SDimitry Andric 84*0b57cec5SDimitry Andric dict: the python session dictionary hit. 85*0b57cec5SDimitry Andric 86*0b57cec5SDimitry Andric )" 87*0b57cec5SDimitry Andric "When specifying a python function with the --python-function option, you need \ 88*0b57cec5SDimitry Andric to supply the function name prepended by the module name:" 89*0b57cec5SDimitry Andric R"( 90*0b57cec5SDimitry Andric 91*0b57cec5SDimitry Andric --python-function myutils.breakpoint_callback 92*0b57cec5SDimitry Andric 93fe6060f1SDimitry Andric The function itself must have either of the following prototypes: 94*0b57cec5SDimitry Andric 95fe6060f1SDimitry Andric def breakpoint_callback(frame, bp_loc, internal_dict): 96fe6060f1SDimitry Andric # Your code goes here 97fe6060f1SDimitry Andric 98fe6060f1SDimitry Andric or: 99fe6060f1SDimitry Andric 100fe6060f1SDimitry Andric def breakpoint_callback(frame, bp_loc, extra_args, internal_dict): 101*0b57cec5SDimitry Andric # Your code goes here 102*0b57cec5SDimitry Andric 103*0b57cec5SDimitry Andric )" 104*0b57cec5SDimitry Andric "The arguments are the same as the arguments passed to generated functions as \ 105fe6060f1SDimitry Andric described above. In the second form, any -k and -v pairs provided to the command will \ 106fe6060f1SDimitry Andric be packaged into a SBDictionary in an SBStructuredData and passed as the extra_args parameter. \ 107fe6060f1SDimitry Andric \n\n\ 108fe6060f1SDimitry Andric Note that the global variable 'lldb.frame' will NOT be updated when \ 109*0b57cec5SDimitry Andric this function is called, so be sure to use the 'frame' argument. The 'frame' argument \ 110*0b57cec5SDimitry Andric can get you to the thread via frame.GetThread(), the thread can get you to the \ 111*0b57cec5SDimitry Andric process via thread.GetProcess(), and the process can get you back to the target \ 112*0b57cec5SDimitry Andric via process.GetTarget()." 113*0b57cec5SDimitry Andric R"( 114*0b57cec5SDimitry Andric 115*0b57cec5SDimitry Andric )" 116*0b57cec5SDimitry Andric "Important Note: As Python code gets collected into functions, access to global \ 117*0b57cec5SDimitry Andric variables requires explicit scoping using the 'global' keyword. Be sure to use correct \ 118*0b57cec5SDimitry Andric Python syntax, including indentation, when entering Python breakpoint commands." 119*0b57cec5SDimitry Andric R"( 120*0b57cec5SDimitry Andric 121*0b57cec5SDimitry Andric Example Python one-line breakpoint command: 122*0b57cec5SDimitry Andric 123*0b57cec5SDimitry Andric (lldb) breakpoint command add -s python 1 124*0b57cec5SDimitry Andric Enter your Python command(s). Type 'DONE' to end. 125e8d8bef9SDimitry Andric def function (frame, bp_loc, internal_dict): 126e8d8bef9SDimitry Andric """frame: the lldb.SBFrame for the location at which you stopped 127e8d8bef9SDimitry Andric bp_loc: an lldb.SBBreakpointLocation for the breakpoint location information 128e8d8bef9SDimitry Andric internal_dict: an LLDB support object not to be used""" 129e8d8bef9SDimitry Andric print("Hit this breakpoint!") 130e8d8bef9SDimitry Andric DONE 131*0b57cec5SDimitry Andric 132*0b57cec5SDimitry Andric As a convenience, this also works for a short Python one-liner: 133*0b57cec5SDimitry Andric 134e8d8bef9SDimitry Andric (lldb) breakpoint command add -s python 1 -o 'import time; print(time.asctime())' 135*0b57cec5SDimitry Andric (lldb) run 136*0b57cec5SDimitry Andric Launching '.../a.out' (x86_64) 137*0b57cec5SDimitry Andric (lldb) Fri Sep 10 12:17:45 2010 138*0b57cec5SDimitry Andric Process 21778 Stopped 139*0b57cec5SDimitry Andric * thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread 140*0b57cec5SDimitry Andric 36 141*0b57cec5SDimitry Andric 37 int c(int val) 142*0b57cec5SDimitry Andric 38 { 143*0b57cec5SDimitry Andric 39 -> return val + 3; 144*0b57cec5SDimitry Andric 40 } 145*0b57cec5SDimitry Andric 41 146*0b57cec5SDimitry Andric 42 int main (int argc, char const *argv[]) 147*0b57cec5SDimitry Andric 148*0b57cec5SDimitry Andric Example multiple line Python breakpoint command: 149*0b57cec5SDimitry Andric 150*0b57cec5SDimitry Andric (lldb) breakpoint command add -s p 1 151*0b57cec5SDimitry Andric Enter your Python command(s). Type 'DONE' to end. 152e8d8bef9SDimitry Andric def function (frame, bp_loc, internal_dict): 153e8d8bef9SDimitry Andric """frame: the lldb.SBFrame for the location at which you stopped 154e8d8bef9SDimitry Andric bp_loc: an lldb.SBBreakpointLocation for the breakpoint location information 155e8d8bef9SDimitry Andric internal_dict: an LLDB support object not to be used""" 156e8d8bef9SDimitry Andric global bp_count 157e8d8bef9SDimitry Andric bp_count = bp_count + 1 158e8d8bef9SDimitry Andric print("Hit this breakpoint " + repr(bp_count) + " times!") 159e8d8bef9SDimitry Andric DONE 160*0b57cec5SDimitry Andric 161*0b57cec5SDimitry Andric )" 162*0b57cec5SDimitry Andric "In this case, since there is a reference to a global variable, \ 163*0b57cec5SDimitry Andric 'bp_count', you will also need to make sure 'bp_count' exists and is \ 164*0b57cec5SDimitry Andric initialized:" 165*0b57cec5SDimitry Andric R"( 166*0b57cec5SDimitry Andric 167*0b57cec5SDimitry Andric (lldb) script 168*0b57cec5SDimitry Andric >>> bp_count = 0 169*0b57cec5SDimitry Andric >>> quit() 170*0b57cec5SDimitry Andric 171*0b57cec5SDimitry Andric )" 172*0b57cec5SDimitry Andric "Your Python code, however organized, can optionally return a value. \ 173*0b57cec5SDimitry Andric If the returned value is False, that tells LLDB not to stop at the breakpoint \ 174*0b57cec5SDimitry Andric to which the code is associated. Returning anything other than False, or even \ 175*0b57cec5SDimitry Andric returning None, or even omitting a return statement entirely, will cause \ 176*0b57cec5SDimitry Andric LLDB to stop." 177*0b57cec5SDimitry Andric R"( 178*0b57cec5SDimitry Andric 179*0b57cec5SDimitry Andric )" 180*0b57cec5SDimitry Andric "Final Note: A warning that no breakpoint command was generated when there \ 181*0b57cec5SDimitry Andric are no syntax errors may indicate that a function was declared but never called."); 182*0b57cec5SDimitry Andric 183480093f4SDimitry Andric m_all_options.Append(&m_options); 184480093f4SDimitry Andric m_all_options.Append(&m_func_options, LLDB_OPT_SET_2 | LLDB_OPT_SET_3, 185480093f4SDimitry Andric LLDB_OPT_SET_2); 186480093f4SDimitry Andric m_all_options.Finalize(); 187480093f4SDimitry Andric 188*0b57cec5SDimitry Andric CommandArgumentEntry arg; 189*0b57cec5SDimitry Andric CommandArgumentData bp_id_arg; 190*0b57cec5SDimitry Andric 191*0b57cec5SDimitry Andric // Define the first (and only) variant of this arg. 192*0b57cec5SDimitry Andric bp_id_arg.arg_type = eArgTypeBreakpointID; 193*0b57cec5SDimitry Andric bp_id_arg.arg_repetition = eArgRepeatOptional; 194*0b57cec5SDimitry Andric 195*0b57cec5SDimitry Andric // There is only one variant this argument could be; put it into the 196*0b57cec5SDimitry Andric // argument entry. 197*0b57cec5SDimitry Andric arg.push_back(bp_id_arg); 198*0b57cec5SDimitry Andric 199*0b57cec5SDimitry Andric // Push the data for the first argument into the m_arguments vector. 200*0b57cec5SDimitry Andric m_arguments.push_back(arg); 201*0b57cec5SDimitry Andric } 202*0b57cec5SDimitry Andric 203*0b57cec5SDimitry Andric ~CommandObjectBreakpointCommandAdd() override = default; 204*0b57cec5SDimitry Andric 205480093f4SDimitry Andric Options *GetOptions() override { return &m_all_options; } 206*0b57cec5SDimitry Andric 207*0b57cec5SDimitry Andric void IOHandlerActivated(IOHandler &io_handler, bool interactive) override { 2089dba64beSDimitry Andric StreamFileSP output_sp(io_handler.GetOutputStreamFileSP()); 209*0b57cec5SDimitry Andric if (output_sp && interactive) { 210*0b57cec5SDimitry Andric output_sp->PutCString(g_reader_instructions); 211*0b57cec5SDimitry Andric output_sp->Flush(); 212*0b57cec5SDimitry Andric } 213*0b57cec5SDimitry Andric } 214*0b57cec5SDimitry Andric 215*0b57cec5SDimitry Andric void IOHandlerInputComplete(IOHandler &io_handler, 216*0b57cec5SDimitry Andric std::string &line) override { 217*0b57cec5SDimitry Andric io_handler.SetIsDone(true); 218*0b57cec5SDimitry Andric 219fe6060f1SDimitry Andric std::vector<std::reference_wrapper<BreakpointOptions>> *bp_options_vec = 220fe6060f1SDimitry Andric (std::vector<std::reference_wrapper<BreakpointOptions>> *) 221fe6060f1SDimitry Andric io_handler.GetUserData(); 222fe6060f1SDimitry Andric for (BreakpointOptions &bp_options : *bp_options_vec) { 2239dba64beSDimitry Andric auto cmd_data = std::make_unique<BreakpointOptions::CommandData>(); 224*0b57cec5SDimitry Andric cmd_data->user_source.SplitIntoLines(line.c_str(), line.size()); 225fe6060f1SDimitry Andric bp_options.SetCommandDataCallback(cmd_data); 226*0b57cec5SDimitry Andric } 227*0b57cec5SDimitry Andric } 228*0b57cec5SDimitry Andric 229*0b57cec5SDimitry Andric void CollectDataForBreakpointCommandCallback( 230fe6060f1SDimitry Andric std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec, 231*0b57cec5SDimitry Andric CommandReturnObject &result) { 232*0b57cec5SDimitry Andric m_interpreter.GetLLDBCommandsFromIOHandler( 233*0b57cec5SDimitry Andric "> ", // Prompt 234*0b57cec5SDimitry Andric *this, // IOHandlerDelegate 235*0b57cec5SDimitry Andric &bp_options_vec); // Baton for the "io_handler" that will be passed back 236*0b57cec5SDimitry Andric // into our IOHandlerDelegate functions 237*0b57cec5SDimitry Andric } 238*0b57cec5SDimitry Andric 239*0b57cec5SDimitry Andric /// Set a one-liner as the callback for the breakpoint. 240fe6060f1SDimitry Andric void SetBreakpointCommandCallback( 241fe6060f1SDimitry Andric std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec, 242*0b57cec5SDimitry Andric const char *oneliner) { 243fe6060f1SDimitry Andric for (BreakpointOptions &bp_options : bp_options_vec) { 2449dba64beSDimitry Andric auto cmd_data = std::make_unique<BreakpointOptions::CommandData>(); 245*0b57cec5SDimitry Andric 246*0b57cec5SDimitry Andric cmd_data->user_source.AppendString(oneliner); 247*0b57cec5SDimitry Andric cmd_data->stop_on_error = m_options.m_stop_on_error; 248*0b57cec5SDimitry Andric 249fe6060f1SDimitry Andric bp_options.SetCommandDataCallback(cmd_data); 250*0b57cec5SDimitry Andric } 251*0b57cec5SDimitry Andric } 252*0b57cec5SDimitry Andric 253480093f4SDimitry Andric class CommandOptions : public OptionGroup { 254*0b57cec5SDimitry Andric public: 25581ad6265SDimitry Andric CommandOptions() = default; 256*0b57cec5SDimitry Andric 257*0b57cec5SDimitry Andric ~CommandOptions() override = default; 258*0b57cec5SDimitry Andric 259*0b57cec5SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 260*0b57cec5SDimitry Andric ExecutionContext *execution_context) override { 261*0b57cec5SDimitry Andric Status error; 262480093f4SDimitry Andric const int short_option = 263480093f4SDimitry Andric g_breakpoint_command_add_options[option_idx].short_option; 264*0b57cec5SDimitry Andric 265*0b57cec5SDimitry Andric switch (short_option) { 266*0b57cec5SDimitry Andric case 'o': 267*0b57cec5SDimitry Andric m_use_one_liner = true; 2685ffd83dbSDimitry Andric m_one_liner = std::string(option_arg); 269*0b57cec5SDimitry Andric break; 270*0b57cec5SDimitry Andric 271*0b57cec5SDimitry Andric case 's': 272*0b57cec5SDimitry Andric m_script_language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum( 2739dba64beSDimitry Andric option_arg, 2749dba64beSDimitry Andric g_breakpoint_command_add_options[option_idx].enum_values, 275*0b57cec5SDimitry Andric eScriptLanguageNone, error); 276480093f4SDimitry Andric switch (m_script_language) { 277480093f4SDimitry Andric case eScriptLanguagePython: 278480093f4SDimitry Andric case eScriptLanguageLua: 279*0b57cec5SDimitry Andric m_use_script_language = true; 280480093f4SDimitry Andric break; 281480093f4SDimitry Andric case eScriptLanguageNone: 282480093f4SDimitry Andric case eScriptLanguageUnknown: 283*0b57cec5SDimitry Andric m_use_script_language = false; 284480093f4SDimitry Andric break; 285*0b57cec5SDimitry Andric } 286*0b57cec5SDimitry Andric break; 287*0b57cec5SDimitry Andric 288*0b57cec5SDimitry Andric case 'e': { 289*0b57cec5SDimitry Andric bool success = false; 290*0b57cec5SDimitry Andric m_stop_on_error = 291*0b57cec5SDimitry Andric OptionArgParser::ToBoolean(option_arg, false, &success); 292*0b57cec5SDimitry Andric if (!success) 293*0b57cec5SDimitry Andric error.SetErrorStringWithFormat( 294*0b57cec5SDimitry Andric "invalid value for stop-on-error: \"%s\"", 295*0b57cec5SDimitry Andric option_arg.str().c_str()); 296*0b57cec5SDimitry Andric } break; 297*0b57cec5SDimitry Andric 298*0b57cec5SDimitry Andric case 'D': 299*0b57cec5SDimitry Andric m_use_dummy = true; 300*0b57cec5SDimitry Andric break; 301*0b57cec5SDimitry Andric 302*0b57cec5SDimitry Andric default: 3039dba64beSDimitry Andric llvm_unreachable("Unimplemented option"); 304*0b57cec5SDimitry Andric } 305*0b57cec5SDimitry Andric return error; 306*0b57cec5SDimitry Andric } 307*0b57cec5SDimitry Andric 308*0b57cec5SDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override { 309*0b57cec5SDimitry Andric m_use_commands = true; 310*0b57cec5SDimitry Andric m_use_script_language = false; 311*0b57cec5SDimitry Andric m_script_language = eScriptLanguageNone; 312*0b57cec5SDimitry Andric 313*0b57cec5SDimitry Andric m_use_one_liner = false; 314*0b57cec5SDimitry Andric m_stop_on_error = true; 315*0b57cec5SDimitry Andric m_one_liner.clear(); 316*0b57cec5SDimitry Andric m_use_dummy = false; 317*0b57cec5SDimitry Andric } 318*0b57cec5SDimitry Andric 319*0b57cec5SDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 3209dba64beSDimitry Andric return llvm::makeArrayRef(g_breakpoint_command_add_options); 321*0b57cec5SDimitry Andric } 322*0b57cec5SDimitry Andric 323*0b57cec5SDimitry Andric // Instance variables to hold the values for command options. 324*0b57cec5SDimitry Andric 325fe6060f1SDimitry Andric bool m_use_commands = false; 326fe6060f1SDimitry Andric bool m_use_script_language = false; 327fe6060f1SDimitry Andric lldb::ScriptLanguage m_script_language = eScriptLanguageNone; 328*0b57cec5SDimitry Andric 329*0b57cec5SDimitry Andric // Instance variables to hold the values for one_liner options. 330fe6060f1SDimitry Andric bool m_use_one_liner = false; 331*0b57cec5SDimitry Andric std::string m_one_liner; 332*0b57cec5SDimitry Andric bool m_stop_on_error; 333*0b57cec5SDimitry Andric bool m_use_dummy; 334*0b57cec5SDimitry Andric }; 335*0b57cec5SDimitry Andric 336*0b57cec5SDimitry Andric protected: 337*0b57cec5SDimitry Andric bool DoExecute(Args &command, CommandReturnObject &result) override { 3389dba64beSDimitry Andric Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 339*0b57cec5SDimitry Andric 3409dba64beSDimitry Andric const BreakpointList &breakpoints = target.GetBreakpointList(); 341*0b57cec5SDimitry Andric size_t num_breakpoints = breakpoints.GetSize(); 342*0b57cec5SDimitry Andric 343*0b57cec5SDimitry Andric if (num_breakpoints == 0) { 344*0b57cec5SDimitry Andric result.AppendError("No breakpoints exist to have commands added"); 345*0b57cec5SDimitry Andric return false; 346*0b57cec5SDimitry Andric } 347*0b57cec5SDimitry Andric 348480093f4SDimitry Andric if (!m_func_options.GetName().empty()) { 349480093f4SDimitry Andric m_options.m_use_one_liner = false; 350480093f4SDimitry Andric if (!m_options.m_use_script_language) { 351480093f4SDimitry Andric m_options.m_script_language = GetDebugger().GetScriptLanguage(); 352480093f4SDimitry Andric m_options.m_use_script_language = true; 353480093f4SDimitry Andric } 354*0b57cec5SDimitry Andric } 355*0b57cec5SDimitry Andric 356*0b57cec5SDimitry Andric BreakpointIDList valid_bp_ids; 357*0b57cec5SDimitry Andric CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 3589dba64beSDimitry Andric command, &target, result, &valid_bp_ids, 359*0b57cec5SDimitry Andric BreakpointName::Permissions::PermissionKinds::listPerm); 360*0b57cec5SDimitry Andric 361*0b57cec5SDimitry Andric m_bp_options_vec.clear(); 362*0b57cec5SDimitry Andric 363*0b57cec5SDimitry Andric if (result.Succeeded()) { 364*0b57cec5SDimitry Andric const size_t count = valid_bp_ids.GetSize(); 365*0b57cec5SDimitry Andric 366*0b57cec5SDimitry Andric for (size_t i = 0; i < count; ++i) { 367*0b57cec5SDimitry Andric BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 368*0b57cec5SDimitry Andric if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 369*0b57cec5SDimitry Andric Breakpoint *bp = 3709dba64beSDimitry Andric target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 371*0b57cec5SDimitry Andric if (cur_bp_id.GetLocationID() == LLDB_INVALID_BREAK_ID) { 372*0b57cec5SDimitry Andric // This breakpoint does not have an associated location. 373fe6060f1SDimitry Andric m_bp_options_vec.push_back(bp->GetOptions()); 374*0b57cec5SDimitry Andric } else { 375*0b57cec5SDimitry Andric BreakpointLocationSP bp_loc_sp( 376*0b57cec5SDimitry Andric bp->FindLocationByID(cur_bp_id.GetLocationID())); 377*0b57cec5SDimitry Andric // This breakpoint does have an associated location. Get its 378*0b57cec5SDimitry Andric // breakpoint options. 379*0b57cec5SDimitry Andric if (bp_loc_sp) 380fe6060f1SDimitry Andric m_bp_options_vec.push_back(bp_loc_sp->GetLocationOptions()); 381*0b57cec5SDimitry Andric } 382*0b57cec5SDimitry Andric } 383*0b57cec5SDimitry Andric } 384*0b57cec5SDimitry Andric 385*0b57cec5SDimitry Andric // If we are using script language, get the script interpreter in order 386*0b57cec5SDimitry Andric // to set or collect command callback. Otherwise, call the methods 387*0b57cec5SDimitry Andric // associated with this object. 388*0b57cec5SDimitry Andric if (m_options.m_use_script_language) { 389e8d8bef9SDimitry Andric Status error; 390480093f4SDimitry Andric ScriptInterpreter *script_interp = GetDebugger().GetScriptInterpreter( 391480093f4SDimitry Andric /*can_create=*/true, m_options.m_script_language); 392*0b57cec5SDimitry Andric // Special handling for one-liner specified inline. 393*0b57cec5SDimitry Andric if (m_options.m_use_one_liner) { 394e8d8bef9SDimitry Andric error = script_interp->SetBreakpointCommandCallback( 395*0b57cec5SDimitry Andric m_bp_options_vec, m_options.m_one_liner.c_str()); 396480093f4SDimitry Andric } else if (!m_func_options.GetName().empty()) { 397e8d8bef9SDimitry Andric error = script_interp->SetBreakpointCommandCallbackFunction( 398480093f4SDimitry Andric m_bp_options_vec, m_func_options.GetName().c_str(), 399480093f4SDimitry Andric m_func_options.GetStructuredData()); 400*0b57cec5SDimitry Andric } else { 401*0b57cec5SDimitry Andric script_interp->CollectDataForBreakpointCommandCallback( 402*0b57cec5SDimitry Andric m_bp_options_vec, result); 403*0b57cec5SDimitry Andric } 404e8d8bef9SDimitry Andric if (!error.Success()) 405e8d8bef9SDimitry Andric result.SetError(error); 406*0b57cec5SDimitry Andric } else { 407*0b57cec5SDimitry Andric // Special handling for one-liner specified inline. 408*0b57cec5SDimitry Andric if (m_options.m_use_one_liner) 409*0b57cec5SDimitry Andric SetBreakpointCommandCallback(m_bp_options_vec, 410*0b57cec5SDimitry Andric m_options.m_one_liner.c_str()); 411*0b57cec5SDimitry Andric else 412*0b57cec5SDimitry Andric CollectDataForBreakpointCommandCallback(m_bp_options_vec, result); 413*0b57cec5SDimitry Andric } 414*0b57cec5SDimitry Andric } 415*0b57cec5SDimitry Andric 416*0b57cec5SDimitry Andric return result.Succeeded(); 417*0b57cec5SDimitry Andric } 418*0b57cec5SDimitry Andric 419*0b57cec5SDimitry Andric private: 420*0b57cec5SDimitry Andric CommandOptions m_options; 421480093f4SDimitry Andric OptionGroupPythonClassWithDict m_func_options; 422480093f4SDimitry Andric OptionGroupOptions m_all_options; 423480093f4SDimitry Andric 424fe6060f1SDimitry Andric std::vector<std::reference_wrapper<BreakpointOptions>> 425fe6060f1SDimitry Andric m_bp_options_vec; // This stores the 426*0b57cec5SDimitry Andric // breakpoint options that 427*0b57cec5SDimitry Andric // we are currently 428*0b57cec5SDimitry Andric // collecting commands for. In the CollectData... calls we need to hand this 429*0b57cec5SDimitry Andric // off to the IOHandler, which may run asynchronously. So we have to have 430*0b57cec5SDimitry Andric // some way to keep it alive, and not leak it. Making it an ivar of the 431*0b57cec5SDimitry Andric // command object, which never goes away achieves this. Note that if we were 432*0b57cec5SDimitry Andric // able to run the same command concurrently in one interpreter we'd have to 433*0b57cec5SDimitry Andric // make this "per invocation". But there are many more reasons why it is not 434*0b57cec5SDimitry Andric // in general safe to do that in lldb at present, so it isn't worthwhile to 435*0b57cec5SDimitry Andric // come up with a more complex mechanism to address this particular weakness 436*0b57cec5SDimitry Andric // right now. 437*0b57cec5SDimitry Andric static const char *g_reader_instructions; 438*0b57cec5SDimitry Andric }; 439*0b57cec5SDimitry Andric 440*0b57cec5SDimitry Andric const char *CommandObjectBreakpointCommandAdd::g_reader_instructions = 441*0b57cec5SDimitry Andric "Enter your debugger command(s). Type 'DONE' to end.\n"; 442*0b57cec5SDimitry Andric 443*0b57cec5SDimitry Andric // CommandObjectBreakpointCommandDelete 444*0b57cec5SDimitry Andric 4459dba64beSDimitry Andric #define LLDB_OPTIONS_breakpoint_command_delete 4469dba64beSDimitry Andric #include "CommandOptions.inc" 447*0b57cec5SDimitry Andric 448*0b57cec5SDimitry Andric class CommandObjectBreakpointCommandDelete : public CommandObjectParsed { 449*0b57cec5SDimitry Andric public: 450*0b57cec5SDimitry Andric CommandObjectBreakpointCommandDelete(CommandInterpreter &interpreter) 451*0b57cec5SDimitry Andric : CommandObjectParsed(interpreter, "delete", 452*0b57cec5SDimitry Andric "Delete the set of commands from a breakpoint.", 45304eeddc0SDimitry Andric nullptr) { 454*0b57cec5SDimitry Andric CommandArgumentEntry arg; 455*0b57cec5SDimitry Andric CommandArgumentData bp_id_arg; 456*0b57cec5SDimitry Andric 457*0b57cec5SDimitry Andric // Define the first (and only) variant of this arg. 458*0b57cec5SDimitry Andric bp_id_arg.arg_type = eArgTypeBreakpointID; 459*0b57cec5SDimitry Andric bp_id_arg.arg_repetition = eArgRepeatPlain; 460*0b57cec5SDimitry Andric 461*0b57cec5SDimitry Andric // There is only one variant this argument could be; put it into the 462*0b57cec5SDimitry Andric // argument entry. 463*0b57cec5SDimitry Andric arg.push_back(bp_id_arg); 464*0b57cec5SDimitry Andric 465*0b57cec5SDimitry Andric // Push the data for the first argument into the m_arguments vector. 466*0b57cec5SDimitry Andric m_arguments.push_back(arg); 467*0b57cec5SDimitry Andric } 468*0b57cec5SDimitry Andric 469*0b57cec5SDimitry Andric ~CommandObjectBreakpointCommandDelete() override = default; 470*0b57cec5SDimitry Andric 471*0b57cec5SDimitry Andric Options *GetOptions() override { return &m_options; } 472*0b57cec5SDimitry Andric 473*0b57cec5SDimitry Andric class CommandOptions : public Options { 474*0b57cec5SDimitry Andric public: 47581ad6265SDimitry Andric CommandOptions() = default; 476*0b57cec5SDimitry Andric 477*0b57cec5SDimitry Andric ~CommandOptions() override = default; 478*0b57cec5SDimitry Andric 479*0b57cec5SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 480*0b57cec5SDimitry Andric ExecutionContext *execution_context) override { 481*0b57cec5SDimitry Andric Status error; 482*0b57cec5SDimitry Andric const int short_option = m_getopt_table[option_idx].val; 483*0b57cec5SDimitry Andric 484*0b57cec5SDimitry Andric switch (short_option) { 485*0b57cec5SDimitry Andric case 'D': 486*0b57cec5SDimitry Andric m_use_dummy = true; 487*0b57cec5SDimitry Andric break; 488*0b57cec5SDimitry Andric 489*0b57cec5SDimitry Andric default: 4909dba64beSDimitry Andric llvm_unreachable("Unimplemented option"); 491*0b57cec5SDimitry Andric } 492*0b57cec5SDimitry Andric 493*0b57cec5SDimitry Andric return error; 494*0b57cec5SDimitry Andric } 495*0b57cec5SDimitry Andric 496*0b57cec5SDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override { 497*0b57cec5SDimitry Andric m_use_dummy = false; 498*0b57cec5SDimitry Andric } 499*0b57cec5SDimitry Andric 500*0b57cec5SDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 5019dba64beSDimitry Andric return llvm::makeArrayRef(g_breakpoint_command_delete_options); 502*0b57cec5SDimitry Andric } 503*0b57cec5SDimitry Andric 504*0b57cec5SDimitry Andric // Instance variables to hold the values for command options. 505fe6060f1SDimitry Andric bool m_use_dummy = false; 506*0b57cec5SDimitry Andric }; 507*0b57cec5SDimitry Andric 508*0b57cec5SDimitry Andric protected: 509*0b57cec5SDimitry Andric bool DoExecute(Args &command, CommandReturnObject &result) override { 5109dba64beSDimitry Andric Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 511*0b57cec5SDimitry Andric 5129dba64beSDimitry Andric const BreakpointList &breakpoints = target.GetBreakpointList(); 513*0b57cec5SDimitry Andric size_t num_breakpoints = breakpoints.GetSize(); 514*0b57cec5SDimitry Andric 515*0b57cec5SDimitry Andric if (num_breakpoints == 0) { 516*0b57cec5SDimitry Andric result.AppendError("No breakpoints exist to have commands deleted"); 517*0b57cec5SDimitry Andric return false; 518*0b57cec5SDimitry Andric } 519*0b57cec5SDimitry Andric 520*0b57cec5SDimitry Andric if (command.empty()) { 521*0b57cec5SDimitry Andric result.AppendError( 522*0b57cec5SDimitry Andric "No breakpoint specified from which to delete the commands"); 523*0b57cec5SDimitry Andric return false; 524*0b57cec5SDimitry Andric } 525*0b57cec5SDimitry Andric 526*0b57cec5SDimitry Andric BreakpointIDList valid_bp_ids; 527*0b57cec5SDimitry Andric CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 5289dba64beSDimitry Andric command, &target, result, &valid_bp_ids, 529*0b57cec5SDimitry Andric BreakpointName::Permissions::PermissionKinds::listPerm); 530*0b57cec5SDimitry Andric 531*0b57cec5SDimitry Andric if (result.Succeeded()) { 532*0b57cec5SDimitry Andric const size_t count = valid_bp_ids.GetSize(); 533*0b57cec5SDimitry Andric for (size_t i = 0; i < count; ++i) { 534*0b57cec5SDimitry Andric BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 535*0b57cec5SDimitry Andric if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 536*0b57cec5SDimitry Andric Breakpoint *bp = 5379dba64beSDimitry Andric target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 538*0b57cec5SDimitry Andric if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 539*0b57cec5SDimitry Andric BreakpointLocationSP bp_loc_sp( 540*0b57cec5SDimitry Andric bp->FindLocationByID(cur_bp_id.GetLocationID())); 541*0b57cec5SDimitry Andric if (bp_loc_sp) 542*0b57cec5SDimitry Andric bp_loc_sp->ClearCallback(); 543*0b57cec5SDimitry Andric else { 544*0b57cec5SDimitry Andric result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n", 545*0b57cec5SDimitry Andric cur_bp_id.GetBreakpointID(), 546*0b57cec5SDimitry Andric cur_bp_id.GetLocationID()); 547*0b57cec5SDimitry Andric return false; 548*0b57cec5SDimitry Andric } 549*0b57cec5SDimitry Andric } else { 550*0b57cec5SDimitry Andric bp->ClearCallback(); 551*0b57cec5SDimitry Andric } 552*0b57cec5SDimitry Andric } 553*0b57cec5SDimitry Andric } 554*0b57cec5SDimitry Andric } 555*0b57cec5SDimitry Andric return result.Succeeded(); 556*0b57cec5SDimitry Andric } 557*0b57cec5SDimitry Andric 558*0b57cec5SDimitry Andric private: 559*0b57cec5SDimitry Andric CommandOptions m_options; 560*0b57cec5SDimitry Andric }; 561*0b57cec5SDimitry Andric 562*0b57cec5SDimitry Andric // CommandObjectBreakpointCommandList 563*0b57cec5SDimitry Andric 564*0b57cec5SDimitry Andric class CommandObjectBreakpointCommandList : public CommandObjectParsed { 565*0b57cec5SDimitry Andric public: 566*0b57cec5SDimitry Andric CommandObjectBreakpointCommandList(CommandInterpreter &interpreter) 5679dba64beSDimitry Andric : CommandObjectParsed(interpreter, "list", 5689dba64beSDimitry Andric "List the script or set of commands to be " 5699dba64beSDimitry Andric "executed when the breakpoint is hit.", 5709dba64beSDimitry Andric nullptr, eCommandRequiresTarget) { 571*0b57cec5SDimitry Andric CommandArgumentEntry arg; 572*0b57cec5SDimitry Andric CommandArgumentData bp_id_arg; 573*0b57cec5SDimitry Andric 574*0b57cec5SDimitry Andric // Define the first (and only) variant of this arg. 575*0b57cec5SDimitry Andric bp_id_arg.arg_type = eArgTypeBreakpointID; 576*0b57cec5SDimitry Andric bp_id_arg.arg_repetition = eArgRepeatPlain; 577*0b57cec5SDimitry Andric 578*0b57cec5SDimitry Andric // There is only one variant this argument could be; put it into the 579*0b57cec5SDimitry Andric // argument entry. 580*0b57cec5SDimitry Andric arg.push_back(bp_id_arg); 581*0b57cec5SDimitry Andric 582*0b57cec5SDimitry Andric // Push the data for the first argument into the m_arguments vector. 583*0b57cec5SDimitry Andric m_arguments.push_back(arg); 584*0b57cec5SDimitry Andric } 585*0b57cec5SDimitry Andric 586*0b57cec5SDimitry Andric ~CommandObjectBreakpointCommandList() override = default; 587*0b57cec5SDimitry Andric 588*0b57cec5SDimitry Andric protected: 589*0b57cec5SDimitry Andric bool DoExecute(Args &command, CommandReturnObject &result) override { 5909dba64beSDimitry Andric Target *target = &GetSelectedTarget(); 591*0b57cec5SDimitry Andric 592*0b57cec5SDimitry Andric const BreakpointList &breakpoints = target->GetBreakpointList(); 593*0b57cec5SDimitry Andric size_t num_breakpoints = breakpoints.GetSize(); 594*0b57cec5SDimitry Andric 595*0b57cec5SDimitry Andric if (num_breakpoints == 0) { 596*0b57cec5SDimitry Andric result.AppendError("No breakpoints exist for which to list commands"); 597*0b57cec5SDimitry Andric return false; 598*0b57cec5SDimitry Andric } 599*0b57cec5SDimitry Andric 600*0b57cec5SDimitry Andric if (command.empty()) { 601*0b57cec5SDimitry Andric result.AppendError( 602*0b57cec5SDimitry Andric "No breakpoint specified for which to list the commands"); 603*0b57cec5SDimitry Andric return false; 604*0b57cec5SDimitry Andric } 605*0b57cec5SDimitry Andric 606*0b57cec5SDimitry Andric BreakpointIDList valid_bp_ids; 607*0b57cec5SDimitry Andric CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 608*0b57cec5SDimitry Andric command, target, result, &valid_bp_ids, 609*0b57cec5SDimitry Andric BreakpointName::Permissions::PermissionKinds::listPerm); 610*0b57cec5SDimitry Andric 611*0b57cec5SDimitry Andric if (result.Succeeded()) { 612*0b57cec5SDimitry Andric const size_t count = valid_bp_ids.GetSize(); 613*0b57cec5SDimitry Andric for (size_t i = 0; i < count; ++i) { 614*0b57cec5SDimitry Andric BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 615*0b57cec5SDimitry Andric if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 616*0b57cec5SDimitry Andric Breakpoint *bp = 617*0b57cec5SDimitry Andric target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 618*0b57cec5SDimitry Andric 619*0b57cec5SDimitry Andric if (bp) { 620*0b57cec5SDimitry Andric BreakpointLocationSP bp_loc_sp; 621*0b57cec5SDimitry Andric if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 622*0b57cec5SDimitry Andric bp_loc_sp = bp->FindLocationByID(cur_bp_id.GetLocationID()); 623480093f4SDimitry Andric if (!bp_loc_sp) { 624*0b57cec5SDimitry Andric result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n", 625*0b57cec5SDimitry Andric cur_bp_id.GetBreakpointID(), 626*0b57cec5SDimitry Andric cur_bp_id.GetLocationID()); 627*0b57cec5SDimitry Andric return false; 628*0b57cec5SDimitry Andric } 629*0b57cec5SDimitry Andric } 630*0b57cec5SDimitry Andric 631*0b57cec5SDimitry Andric StreamString id_str; 632*0b57cec5SDimitry Andric BreakpointID::GetCanonicalReference(&id_str, 633*0b57cec5SDimitry Andric cur_bp_id.GetBreakpointID(), 634*0b57cec5SDimitry Andric cur_bp_id.GetLocationID()); 635*0b57cec5SDimitry Andric const Baton *baton = nullptr; 636*0b57cec5SDimitry Andric if (bp_loc_sp) 637480093f4SDimitry Andric baton = 638480093f4SDimitry Andric bp_loc_sp 639*0b57cec5SDimitry Andric ->GetOptionsSpecifyingKind(BreakpointOptions::eCallback) 640fe6060f1SDimitry Andric .GetBaton(); 641*0b57cec5SDimitry Andric else 642fe6060f1SDimitry Andric baton = bp->GetOptions().GetBaton(); 643*0b57cec5SDimitry Andric 644*0b57cec5SDimitry Andric if (baton) { 645*0b57cec5SDimitry Andric result.GetOutputStream().Printf("Breakpoint %s:\n", 646*0b57cec5SDimitry Andric id_str.GetData()); 647480093f4SDimitry Andric baton->GetDescription(result.GetOutputStream().AsRawOstream(), 648480093f4SDimitry Andric eDescriptionLevelFull, 649480093f4SDimitry Andric result.GetOutputStream().GetIndentLevel() + 650480093f4SDimitry Andric 2); 651*0b57cec5SDimitry Andric } else { 652*0b57cec5SDimitry Andric result.AppendMessageWithFormat( 653*0b57cec5SDimitry Andric "Breakpoint %s does not have an associated command.\n", 654*0b57cec5SDimitry Andric id_str.GetData()); 655*0b57cec5SDimitry Andric } 656*0b57cec5SDimitry Andric } 657*0b57cec5SDimitry Andric result.SetStatus(eReturnStatusSuccessFinishResult); 658*0b57cec5SDimitry Andric } else { 659*0b57cec5SDimitry Andric result.AppendErrorWithFormat("Invalid breakpoint ID: %u.\n", 660*0b57cec5SDimitry Andric cur_bp_id.GetBreakpointID()); 661*0b57cec5SDimitry Andric } 662*0b57cec5SDimitry Andric } 663*0b57cec5SDimitry Andric } 664*0b57cec5SDimitry Andric 665*0b57cec5SDimitry Andric return result.Succeeded(); 666*0b57cec5SDimitry Andric } 667*0b57cec5SDimitry Andric }; 668*0b57cec5SDimitry Andric 669*0b57cec5SDimitry Andric // CommandObjectBreakpointCommand 670*0b57cec5SDimitry Andric 671*0b57cec5SDimitry Andric CommandObjectBreakpointCommand::CommandObjectBreakpointCommand( 672*0b57cec5SDimitry Andric CommandInterpreter &interpreter) 673*0b57cec5SDimitry Andric : CommandObjectMultiword( 674480093f4SDimitry Andric interpreter, "command", 675480093f4SDimitry Andric "Commands for adding, removing and listing " 676*0b57cec5SDimitry Andric "LLDB commands executed when a breakpoint is " 677*0b57cec5SDimitry Andric "hit.", 678*0b57cec5SDimitry Andric "command <sub-command> [<sub-command-options>] <breakpoint-id>") { 679*0b57cec5SDimitry Andric CommandObjectSP add_command_object( 680*0b57cec5SDimitry Andric new CommandObjectBreakpointCommandAdd(interpreter)); 681*0b57cec5SDimitry Andric CommandObjectSP delete_command_object( 682*0b57cec5SDimitry Andric new CommandObjectBreakpointCommandDelete(interpreter)); 683*0b57cec5SDimitry Andric CommandObjectSP list_command_object( 684*0b57cec5SDimitry Andric new CommandObjectBreakpointCommandList(interpreter)); 685*0b57cec5SDimitry Andric 686*0b57cec5SDimitry Andric add_command_object->SetCommandName("breakpoint command add"); 687*0b57cec5SDimitry Andric delete_command_object->SetCommandName("breakpoint command delete"); 688*0b57cec5SDimitry Andric list_command_object->SetCommandName("breakpoint command list"); 689*0b57cec5SDimitry Andric 690*0b57cec5SDimitry Andric LoadSubCommand("add", add_command_object); 691*0b57cec5SDimitry Andric LoadSubCommand("delete", delete_command_object); 692*0b57cec5SDimitry Andric LoadSubCommand("list", list_command_object); 693*0b57cec5SDimitry Andric } 694*0b57cec5SDimitry Andric 695*0b57cec5SDimitry Andric CommandObjectBreakpointCommand::~CommandObjectBreakpointCommand() = default; 696