130fdc8d8SChris Lattner //===-- CommandObjectBreakpointCommand.cpp ----------------------*- C++ -*-===// 230fdc8d8SChris Lattner // 330fdc8d8SChris Lattner // The LLVM Compiler Infrastructure 430fdc8d8SChris Lattner // 530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source 630fdc8d8SChris Lattner // License. See LICENSE.TXT for details. 730fdc8d8SChris Lattner // 830fdc8d8SChris Lattner //===----------------------------------------------------------------------===// 930fdc8d8SChris Lattner 1093a64300SDaniel Malea #include "lldb/lldb-python.h" 1193a64300SDaniel Malea 1230fdc8d8SChris Lattner // C Includes 1330fdc8d8SChris Lattner // C++ Includes 1430fdc8d8SChris Lattner 1530fdc8d8SChris Lattner 1630fdc8d8SChris Lattner #include "CommandObjectBreakpointCommand.h" 1730fdc8d8SChris Lattner #include "CommandObjectBreakpoint.h" 1830fdc8d8SChris Lattner 1944d93782SGreg Clayton #include "lldb/Core/IOHandler.h" 2030fdc8d8SChris Lattner #include "lldb/Interpreter/CommandInterpreter.h" 2130fdc8d8SChris Lattner #include "lldb/Interpreter/CommandReturnObject.h" 2230fdc8d8SChris Lattner #include "lldb/Target/Target.h" 2330fdc8d8SChris Lattner #include "lldb/Target/Thread.h" 2430fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointIDList.h" 2530fdc8d8SChris Lattner #include "lldb/Breakpoint/Breakpoint.h" 2630fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointLocation.h" 2730fdc8d8SChris Lattner #include "lldb/Breakpoint/StoppointCallbackContext.h" 2830fdc8d8SChris Lattner #include "lldb/Core/State.h" 2930fdc8d8SChris Lattner 3030fdc8d8SChris Lattner using namespace lldb; 3130fdc8d8SChris Lattner using namespace lldb_private; 3230fdc8d8SChris Lattner 3330fdc8d8SChris Lattner //------------------------------------------------------------------------- 3430fdc8d8SChris Lattner // CommandObjectBreakpointCommandAdd 3530fdc8d8SChris Lattner //------------------------------------------------------------------------- 3630fdc8d8SChris Lattner 3730fdc8d8SChris Lattner 3844d93782SGreg Clayton class CommandObjectBreakpointCommandAdd : 3944d93782SGreg Clayton public CommandObjectParsed, 4044d93782SGreg Clayton public IOHandlerDelegateMultiline 415a988416SJim Ingham { 425a988416SJim Ingham public: 435a988416SJim Ingham 445a988416SJim Ingham CommandObjectBreakpointCommandAdd (CommandInterpreter &interpreter) : 455a988416SJim Ingham CommandObjectParsed (interpreter, 46a7015092SGreg Clayton "add", 471bb0750bSJim Ingham "Add a set of commands to a breakpoint, to be executed whenever the breakpoint is hit." 481bb0750bSJim Ingham " If no breakpoint is specified, adds the commands to the last created breakpoint.", 49eb0103f2SGreg Clayton NULL), 50c3d874a5SGreg Clayton IOHandlerDelegateMultiline ("DONE", IOHandlerDelegate::Completion::LLDBCommand), 51eb0103f2SGreg Clayton m_options (interpreter) 5230fdc8d8SChris Lattner { 5330fdc8d8SChris Lattner SetHelpLong ( 5430fdc8d8SChris Lattner "\nGeneral information about entering breakpoint commands\n\ 5530fdc8d8SChris Lattner ------------------------------------------------------\n\ 5630fdc8d8SChris Lattner \n\ 5713b1213dSGreg Clayton This command will cause you to be prompted to enter the command or set of\n\ 5813b1213dSGreg Clayton commands you wish to be executed when the specified breakpoint is hit. You\n\ 5913b1213dSGreg Clayton will be told to enter your command(s), and will see a '> 'prompt. Because\n\ 6013b1213dSGreg Clayton you can enter one or many commands to be executed when a breakpoint is hit,\n\ 6113b1213dSGreg Clayton you will continue to be prompted after each new-line that you enter, until you\n\ 6213b1213dSGreg Clayton enter the word 'DONE', which will cause the commands you have entered to be\n\ 6313b1213dSGreg Clayton stored with the breakpoint and executed when the breakpoint is hit.\n\ 6430fdc8d8SChris Lattner \n\ 6513b1213dSGreg Clayton Syntax checking is not necessarily done when breakpoint commands are entered.\n\ 6613b1213dSGreg Clayton An improperly written breakpoint command will attempt to get executed when the\n\ 6713b1213dSGreg Clayton breakpoint gets hit, and usually silently fail. If your breakpoint command does\n\ 6813b1213dSGreg Clayton not appear to be getting executed, go back and check your syntax.\n\ 6930fdc8d8SChris Lattner \n\ 7030fdc8d8SChris Lattner Special information about PYTHON breakpoint commands\n\ 7130fdc8d8SChris Lattner ----------------------------------------------------\n\ 7230fdc8d8SChris Lattner \n\ 7313b1213dSGreg Clayton You may enter either one line of Python, multiple lines of Python (including\n\ 7413b1213dSGreg Clayton function definitions), or specify a Python function in a module that has already,\n\ 7513b1213dSGreg Clayton or will be imported. If you enter a single line of Python, that will be passed\n\ 7613b1213dSGreg Clayton to the Python interpreter 'as is' when the breakpoint gets hit. If you enter\n\ 7713b1213dSGreg Clayton function definitions, they will be passed to the Python interpreter as soon as\n\ 7813b1213dSGreg Clayton you finish entering the breakpoint command, and they can be called later (don't\n\ 7913b1213dSGreg Clayton forget to add calls to them, if you want them called when the breakpoint is\n\ 8013b1213dSGreg Clayton hit). If you enter multiple lines of Python that are not function definitions,\n\ 8113b1213dSGreg Clayton they will be collected into a new, automatically generated Python function, and\n\ 8213b1213dSGreg Clayton a call to the newly generated function will be attached to the breakpoint.\n\ 83c9efdbb0SJim Ingham \n\ 84c9efdbb0SJim Ingham \n\ 8513b1213dSGreg Clayton This auto-generated function is passed in three arguments:\n\ 86c9efdbb0SJim Ingham \n\ 8713b1213dSGreg Clayton frame: a lldb.SBFrame object for the frame which hit breakpoint.\n\ 8813b1213dSGreg Clayton bp_loc: a lldb.SBBreakpointLocation object that represents the breakpoint\n\ 8913b1213dSGreg Clayton location that was hit.\n\ 9013b1213dSGreg Clayton dict: the python session dictionary hit.\n\ 9113b1213dSGreg Clayton \n\ 9213b1213dSGreg Clayton When specifying a python function with the --python-function option, you need\n\ 9313b1213dSGreg Clayton to supply the function name prepended by the module name. So if you import a\n\ 9413b1213dSGreg Clayton module named 'myutils' that contains a 'breakpoint_callback' function, you would\n\ 9513b1213dSGreg Clayton specify the option as:\n\ 9613b1213dSGreg Clayton \n\ 9713b1213dSGreg Clayton --python-function myutils.breakpoint_callback\n\ 9813b1213dSGreg Clayton \n\ 9913b1213dSGreg Clayton The function itself must have the following prototype:\n\ 10013b1213dSGreg Clayton \n\ 10113b1213dSGreg Clayton def breakpoint_callback(frame, bp_loc, dict):\n\ 10213b1213dSGreg Clayton # Your code goes here\n\ 10313b1213dSGreg Clayton \n\ 10413b1213dSGreg Clayton The arguments are the same as the 3 auto generation function arguments listed\n\ 10513b1213dSGreg Clayton above. Note that the global variable 'lldb.frame' will NOT be setup when this\n\ 10613b1213dSGreg Clayton function is called, so be sure to use the 'frame' argument. The 'frame' argument\n\ 10713b1213dSGreg Clayton can get you to the thread (frame.GetThread()), the thread can get you to the\n\ 10813b1213dSGreg Clayton process (thread.GetProcess()), and the process can get you back to the target\n\ 10913b1213dSGreg Clayton (process.GetTarget()).\n\ 11013b1213dSGreg Clayton \n\ 11113b1213dSGreg Clayton Important Note: Because loose Python code gets collected into functions, if you\n\ 11213b1213dSGreg Clayton want to access global variables in the 'loose' code, you need to specify that\n\ 11313b1213dSGreg Clayton they are global, using the 'global' keyword. Be sure to use correct Python\n\ 11413b1213dSGreg Clayton syntax, including indentation, when entering Python breakpoint commands.\n\ 115c9efdbb0SJim Ingham \n\ 116c9efdbb0SJim Ingham As a third option, you can pass the name of an already existing Python function\n\ 117c9efdbb0SJim Ingham and that function will be attached to the breakpoint. It will get passed the\n\ 118c9efdbb0SJim Ingham frame and bp_loc arguments mentioned above.\n\ 11930fdc8d8SChris Lattner \n\ 12030fdc8d8SChris Lattner Example Python one-line breakpoint command:\n\ 12130fdc8d8SChris Lattner \n\ 122e16c50a1SJim Ingham (lldb) breakpoint command add -s python 1\n\ 12330fdc8d8SChris Lattner Enter your Python command(s). Type 'DONE' to end.\n\ 12430fdc8d8SChris Lattner > print \"Hit this breakpoint!\"\n\ 12530fdc8d8SChris Lattner > DONE\n\ 12630fdc8d8SChris Lattner \n\ 1273495f25aSJohnny Chen As a convenience, this also works for a short Python one-liner:\n\ 128e16c50a1SJim Ingham (lldb) breakpoint command add -s python 1 -o \"import time; print time.asctime()\"\n\ 1293495f25aSJohnny Chen (lldb) run\n\ 1303495f25aSJohnny Chen Launching '.../a.out' (x86_64)\n\ 1313495f25aSJohnny Chen (lldb) Fri Sep 10 12:17:45 2010\n\ 1323495f25aSJohnny Chen Process 21778 Stopped\n\ 1333495f25aSJohnny Chen * thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread\n\ 1343495f25aSJohnny Chen 36 \n\ 1353495f25aSJohnny Chen 37 int c(int val)\n\ 1363495f25aSJohnny Chen 38 {\n\ 1373495f25aSJohnny Chen 39 -> return val + 3;\n\ 1383495f25aSJohnny Chen 40 }\n\ 1393495f25aSJohnny Chen 41 \n\ 1403495f25aSJohnny Chen 42 int main (int argc, char const *argv[])\n\ 1413495f25aSJohnny Chen (lldb)\n\ 1423495f25aSJohnny Chen \n\ 14330fdc8d8SChris Lattner Example multiple line Python breakpoint command, using function definition:\n\ 14430fdc8d8SChris Lattner \n\ 145e16c50a1SJim Ingham (lldb) breakpoint command add -s python 1\n\ 14630fdc8d8SChris Lattner Enter your Python command(s). Type 'DONE' to end.\n\ 14730fdc8d8SChris Lattner > def breakpoint_output (bp_no):\n\ 14830fdc8d8SChris Lattner > out_string = \"Hit breakpoint number \" + repr (bp_no)\n\ 14930fdc8d8SChris Lattner > print out_string\n\ 15030fdc8d8SChris Lattner > return True\n\ 15130fdc8d8SChris Lattner > breakpoint_output (1)\n\ 15230fdc8d8SChris Lattner > DONE\n\ 15330fdc8d8SChris Lattner \n\ 15430fdc8d8SChris Lattner \n\ 15530fdc8d8SChris Lattner Example multiple line Python breakpoint command, using 'loose' Python:\n\ 15630fdc8d8SChris Lattner \n\ 157e16c50a1SJim Ingham (lldb) breakpoint command add -s p 1\n\ 15830fdc8d8SChris Lattner Enter your Python command(s). Type 'DONE' to end.\n\ 15930fdc8d8SChris Lattner > global bp_count\n\ 16030fdc8d8SChris Lattner > bp_count = bp_count + 1\n\ 16130fdc8d8SChris Lattner > print \"Hit this breakpoint \" + repr(bp_count) + \" times!\"\n\ 16230fdc8d8SChris Lattner > DONE\n\ 16330fdc8d8SChris Lattner \n\ 16430fdc8d8SChris Lattner In this case, since there is a reference to a global variable,\n\ 16530fdc8d8SChris Lattner 'bp_count', you will also need to make sure 'bp_count' exists and is\n\ 16630fdc8d8SChris Lattner initialized:\n\ 16730fdc8d8SChris Lattner \n\ 16830fdc8d8SChris Lattner (lldb) script\n\ 16930fdc8d8SChris Lattner >>> bp_count = 0\n\ 17030fdc8d8SChris Lattner >>> quit()\n\ 17130fdc8d8SChris Lattner \n\ 17230fdc8d8SChris Lattner (lldb)\n\ 17330fdc8d8SChris Lattner \n\ 174650b9268SCaroline Tice \n\ 175f5f560caSEnrico Granata Your Python code, however organized, can optionally return a value.\n\ 176f5f560caSEnrico Granata If the returned value is False, that tells LLDB not to stop at the breakpoint\n\ 177f5f560caSEnrico Granata to which the code is associated. Returning anything other than False, or even\n\ 178f5f560caSEnrico Granata returning None, or even omitting a return statement entirely, will cause\n\ 179f5f560caSEnrico Granata LLDB to stop.\n\ 180f5f560caSEnrico Granata \n\ 18113b1213dSGreg Clayton Final Note: If you get a warning that no breakpoint command was generated, but\n\ 18213b1213dSGreg Clayton you did not get any syntax errors, you probably forgot to add a call to your\n\ 18313b1213dSGreg Clayton functions.\n\ 184650b9268SCaroline Tice \n\ 185e3d26315SCaroline Tice Special information about debugger command breakpoint commands\n\ 186e3d26315SCaroline Tice --------------------------------------------------------------\n\ 18730fdc8d8SChris Lattner \n\ 18813b1213dSGreg Clayton You may enter any debugger command, exactly as you would at the debugger prompt.\n\ 18913b1213dSGreg Clayton You may enter as many debugger commands as you like, but do NOT enter more than\n\ 19013b1213dSGreg Clayton one command per line.\n" ); 191405fe67fSCaroline Tice 192405fe67fSCaroline Tice CommandArgumentEntry arg; 193405fe67fSCaroline Tice CommandArgumentData bp_id_arg; 194405fe67fSCaroline Tice 195405fe67fSCaroline Tice // Define the first (and only) variant of this arg. 196405fe67fSCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 1971bb0750bSJim Ingham bp_id_arg.arg_repetition = eArgRepeatOptional; 198405fe67fSCaroline Tice 199405fe67fSCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 200405fe67fSCaroline Tice arg.push_back (bp_id_arg); 201405fe67fSCaroline Tice 202405fe67fSCaroline Tice // Push the data for the first argument into the m_arguments vector. 203405fe67fSCaroline Tice m_arguments.push_back (arg); 20430fdc8d8SChris Lattner } 20530fdc8d8SChris Lattner 2065a988416SJim Ingham virtual 2075a988416SJim Ingham ~CommandObjectBreakpointCommandAdd () {} 2085a988416SJim Ingham 2095a988416SJim Ingham virtual Options * 2105a988416SJim Ingham GetOptions () 2115a988416SJim Ingham { 2125a988416SJim Ingham return &m_options; 2135a988416SJim Ingham } 2145a988416SJim Ingham 21544d93782SGreg Clayton virtual void 21644d93782SGreg Clayton IOHandlerActivated (IOHandler &io_handler) 21744d93782SGreg Clayton { 21844d93782SGreg Clayton StreamFileSP output_sp(io_handler.GetOutputStreamFile()); 21944d93782SGreg Clayton if (output_sp) 22044d93782SGreg Clayton { 22144d93782SGreg Clayton output_sp->PutCString(g_reader_instructions); 22244d93782SGreg Clayton output_sp->Flush(); 22344d93782SGreg Clayton } 22444d93782SGreg Clayton } 22544d93782SGreg Clayton 22644d93782SGreg Clayton 22744d93782SGreg Clayton virtual void 22844d93782SGreg Clayton IOHandlerInputComplete (IOHandler &io_handler, std::string &line) 22944d93782SGreg Clayton { 23044d93782SGreg Clayton io_handler.SetIsDone(true); 23144d93782SGreg Clayton 232b5796cb4SJim Ingham std::vector<BreakpointOptions *> *bp_options_vec = (std::vector<BreakpointOptions *> *)io_handler.GetUserData(); 233b5796cb4SJim Ingham for (BreakpointOptions *bp_options : *bp_options_vec) 23444d93782SGreg Clayton { 235b5796cb4SJim Ingham if (!bp_options) 236b5796cb4SJim Ingham continue; 237b5796cb4SJim Ingham 23844d93782SGreg Clayton std::unique_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData()); 23944d93782SGreg Clayton if (data_ap.get()) 24044d93782SGreg Clayton { 24144d93782SGreg Clayton data_ap->user_source.SplitIntoLines (line.c_str(), line.size()); 24244d93782SGreg Clayton BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release())); 24344d93782SGreg Clayton bp_options->SetCallback (BreakpointOptionsCallbackFunction, baton_sp); 24444d93782SGreg Clayton } 24544d93782SGreg Clayton } 24644d93782SGreg Clayton } 24744d93782SGreg Clayton 2485a988416SJim Ingham void 249b5796cb4SJim Ingham CollectDataForBreakpointCommandCallback (std::vector<BreakpointOptions *> &bp_options_vec, 2505a988416SJim Ingham CommandReturnObject &result) 2515a988416SJim Ingham { 25244d93782SGreg Clayton m_interpreter.GetLLDBCommandsFromIOHandler ("> ", // Prompt 25344d93782SGreg Clayton *this, // IOHandlerDelegate 25444d93782SGreg Clayton true, // Run IOHandler in async mode 255b5796cb4SJim Ingham &bp_options_vec); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions 2565a988416SJim Ingham } 2575a988416SJim Ingham 2585a988416SJim Ingham /// Set a one-liner as the callback for the breakpoint. 2595a988416SJim Ingham void 260b5796cb4SJim Ingham SetBreakpointCommandCallback (std::vector<BreakpointOptions *> &bp_options_vec, 2615a988416SJim Ingham const char *oneliner) 2625a988416SJim Ingham { 263b5796cb4SJim Ingham for (auto bp_options : bp_options_vec) 264b5796cb4SJim Ingham { 2657b0992d9SGreg Clayton std::unique_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData()); 2665a988416SJim Ingham 2675a988416SJim Ingham // It's necessary to set both user_source and script_source to the oneliner. 2685a988416SJim Ingham // The former is used to generate callback description (as in breakpoint command list) 2695a988416SJim Ingham // while the latter is used for Python to interpret during the actual callback. 2705a988416SJim Ingham data_ap->user_source.AppendString (oneliner); 2715a988416SJim Ingham data_ap->script_source.assign (oneliner); 2725a988416SJim Ingham data_ap->stop_on_error = m_options.m_stop_on_error; 2735a988416SJim Ingham 2745a988416SJim Ingham BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release())); 2755a988416SJim Ingham bp_options->SetCallback (BreakpointOptionsCallbackFunction, baton_sp); 276b5796cb4SJim Ingham } 2775a988416SJim Ingham return; 2785a988416SJim Ingham } 2795a988416SJim Ingham 2805a988416SJim Ingham static bool 2815a988416SJim Ingham BreakpointOptionsCallbackFunction (void *baton, 2825a988416SJim Ingham StoppointCallbackContext *context, 2835a988416SJim Ingham lldb::user_id_t break_id, 2845a988416SJim Ingham lldb::user_id_t break_loc_id) 2855a988416SJim Ingham { 2865a988416SJim Ingham bool ret_value = true; 2875a988416SJim Ingham if (baton == NULL) 2885a988416SJim Ingham return true; 2895a988416SJim Ingham 2905a988416SJim Ingham 2915a988416SJim Ingham BreakpointOptions::CommandData *data = (BreakpointOptions::CommandData *) baton; 2925a988416SJim Ingham StringList &commands = data->user_source; 2935a988416SJim Ingham 2945a988416SJim Ingham if (commands.GetSize() > 0) 2955a988416SJim Ingham { 2965a988416SJim Ingham ExecutionContext exe_ctx (context->exe_ctx_ref); 2975a988416SJim Ingham Target *target = exe_ctx.GetTargetPtr(); 2985a988416SJim Ingham if (target) 2995a988416SJim Ingham { 3005a988416SJim Ingham CommandReturnObject result; 3015a988416SJim Ingham Debugger &debugger = target->GetDebugger(); 3025a988416SJim Ingham // Rig up the results secondary output stream to the debugger's, so the output will come out synchronously 3035a988416SJim Ingham // if the debugger is set up that way. 3045a988416SJim Ingham 3055a988416SJim Ingham StreamSP output_stream (debugger.GetAsyncOutputStream()); 3065a988416SJim Ingham StreamSP error_stream (debugger.GetAsyncErrorStream()); 3075a988416SJim Ingham result.SetImmediateOutputStream (output_stream); 3085a988416SJim Ingham result.SetImmediateErrorStream (error_stream); 3095a988416SJim Ingham 31026c7bf93SJim Ingham CommandInterpreterRunOptions options; 31126c7bf93SJim Ingham options.SetStopOnContinue(true); 31226c7bf93SJim Ingham options.SetStopOnError (data->stop_on_error); 31326c7bf93SJim Ingham options.SetEchoCommands (true); 31426c7bf93SJim Ingham options.SetPrintResults (true); 31526c7bf93SJim Ingham options.SetAddToHistory (false); 3165a988416SJim Ingham 3175a988416SJim Ingham debugger.GetCommandInterpreter().HandleCommands (commands, 3185a988416SJim Ingham &exe_ctx, 31926c7bf93SJim Ingham options, 3205a988416SJim Ingham result); 3215a988416SJim Ingham result.GetImmediateOutputStream()->Flush(); 3225a988416SJim Ingham result.GetImmediateErrorStream()->Flush(); 3235a988416SJim Ingham } 3245a988416SJim Ingham } 3255a988416SJim Ingham return ret_value; 3265a988416SJim Ingham } 3275a988416SJim Ingham 3285a988416SJim Ingham class CommandOptions : public Options 3295a988416SJim Ingham { 3305a988416SJim Ingham public: 3315a988416SJim Ingham 3325a988416SJim Ingham CommandOptions (CommandInterpreter &interpreter) : 3335a988416SJim Ingham Options (interpreter), 3345a988416SJim Ingham m_use_commands (false), 3355a988416SJim Ingham m_use_script_language (false), 3365a988416SJim Ingham m_script_language (eScriptLanguageNone), 3375a988416SJim Ingham m_use_one_liner (false), 3385a988416SJim Ingham m_one_liner(), 3395a988416SJim Ingham m_function_name() 34030fdc8d8SChris Lattner { 34130fdc8d8SChris Lattner } 34230fdc8d8SChris Lattner 3435a988416SJim Ingham virtual 3445a988416SJim Ingham ~CommandOptions () {} 3455a988416SJim Ingham 3465a988416SJim Ingham virtual Error 3475a988416SJim Ingham SetOptionValue (uint32_t option_idx, const char *option_arg) 3485a988416SJim Ingham { 3495a988416SJim Ingham Error error; 3503bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 3515a988416SJim Ingham 3525a988416SJim Ingham switch (short_option) 3535a988416SJim Ingham { 3545a988416SJim Ingham case 'o': 3555a988416SJim Ingham m_use_one_liner = true; 3565a988416SJim Ingham m_one_liner = option_arg; 3575a988416SJim Ingham break; 3585a988416SJim Ingham 3595a988416SJim Ingham case 's': 3605a988416SJim Ingham m_script_language = (lldb::ScriptLanguage) Args::StringToOptionEnum (option_arg, 3615a988416SJim Ingham g_option_table[option_idx].enum_values, 3625a988416SJim Ingham eScriptLanguageNone, 3635a988416SJim Ingham error); 3645a988416SJim Ingham 3655a988416SJim Ingham if (m_script_language == eScriptLanguagePython || m_script_language == eScriptLanguageDefault) 3665a988416SJim Ingham { 3675a988416SJim Ingham m_use_script_language = true; 3685a988416SJim Ingham } 3695a988416SJim Ingham else 3705a988416SJim Ingham { 3715a988416SJim Ingham m_use_script_language = false; 3725a988416SJim Ingham } 3735a988416SJim Ingham break; 3745a988416SJim Ingham 3755a988416SJim Ingham case 'e': 3765a988416SJim Ingham { 3775a988416SJim Ingham bool success = false; 3785a988416SJim Ingham m_stop_on_error = Args::StringToBoolean(option_arg, false, &success); 3795a988416SJim Ingham if (!success) 3805a988416SJim Ingham error.SetErrorStringWithFormat("invalid value for stop-on-error: \"%s\"", option_arg); 3815a988416SJim Ingham } 3825a988416SJim Ingham break; 3835a988416SJim Ingham 3845a988416SJim Ingham case 'F': 3855a988416SJim Ingham { 3865a988416SJim Ingham m_use_one_liner = false; 3875a988416SJim Ingham m_use_script_language = true; 3885a988416SJim Ingham m_function_name.assign(option_arg); 3895a988416SJim Ingham } 3905a988416SJim Ingham break; 3915a988416SJim Ingham 392*33df7cd3SJim Ingham case 'D': 393*33df7cd3SJim Ingham m_use_dummy = true; 394*33df7cd3SJim Ingham break; 395*33df7cd3SJim Ingham 3965a988416SJim Ingham default: 3975a988416SJim Ingham break; 3985a988416SJim Ingham } 3995a988416SJim Ingham return error; 4005a988416SJim Ingham } 4015a988416SJim Ingham void 4025a988416SJim Ingham OptionParsingStarting () 4035a988416SJim Ingham { 4045a988416SJim Ingham m_use_commands = true; 4055a988416SJim Ingham m_use_script_language = false; 4065a988416SJim Ingham m_script_language = eScriptLanguageNone; 4075a988416SJim Ingham 4085a988416SJim Ingham m_use_one_liner = false; 4095a988416SJim Ingham m_stop_on_error = true; 4105a988416SJim Ingham m_one_liner.clear(); 4115a988416SJim Ingham m_function_name.clear(); 412*33df7cd3SJim Ingham m_use_dummy = false; 4135a988416SJim Ingham } 4145a988416SJim Ingham 4155a988416SJim Ingham const OptionDefinition* 4165a988416SJim Ingham GetDefinitions () 4175a988416SJim Ingham { 4185a988416SJim Ingham return g_option_table; 4195a988416SJim Ingham } 4205a988416SJim Ingham 4215a988416SJim Ingham // Options table: Required for subclasses of Options. 4225a988416SJim Ingham 4235a988416SJim Ingham static OptionDefinition g_option_table[]; 4245a988416SJim Ingham 4255a988416SJim Ingham // Instance variables to hold the values for command options. 4265a988416SJim Ingham 4275a988416SJim Ingham bool m_use_commands; 4285a988416SJim Ingham bool m_use_script_language; 4295a988416SJim Ingham lldb::ScriptLanguage m_script_language; 4305a988416SJim Ingham 4315a988416SJim Ingham // Instance variables to hold the values for one_liner options. 4325a988416SJim Ingham bool m_use_one_liner; 4335a988416SJim Ingham std::string m_one_liner; 4345a988416SJim Ingham bool m_stop_on_error; 4355a988416SJim Ingham std::string m_function_name; 436*33df7cd3SJim Ingham bool m_use_dummy; 4375a988416SJim Ingham }; 4385a988416SJim Ingham 4395a988416SJim Ingham protected: 4405a988416SJim Ingham virtual bool 4415a988416SJim Ingham DoExecute (Args& command, CommandReturnObject &result) 44230fdc8d8SChris Lattner { 443*33df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 44430fdc8d8SChris Lattner 44530fdc8d8SChris Lattner if (target == NULL) 44630fdc8d8SChris Lattner { 44730fdc8d8SChris Lattner result.AppendError ("There is not a current executable; there are no breakpoints to which to add commands"); 44830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 44930fdc8d8SChris Lattner return false; 45030fdc8d8SChris Lattner } 45130fdc8d8SChris Lattner 45230fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 45330fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 45430fdc8d8SChris Lattner 45530fdc8d8SChris Lattner if (num_breakpoints == 0) 45630fdc8d8SChris Lattner { 45730fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to have commands added"); 45830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 45930fdc8d8SChris Lattner return false; 46030fdc8d8SChris Lattner } 46130fdc8d8SChris Lattner 4628d4a8010SEnrico Granata if (m_options.m_use_script_language == false && m_options.m_function_name.size()) 4638d4a8010SEnrico Granata { 4648d4a8010SEnrico Granata result.AppendError ("need to enable scripting to have a function run as a breakpoint command"); 4658d4a8010SEnrico Granata result.SetStatus (eReturnStatusFailed); 4668d4a8010SEnrico Granata return false; 4678d4a8010SEnrico Granata } 4688d4a8010SEnrico Granata 46930fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 47030fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 47130fdc8d8SChris Lattner 472b5796cb4SJim Ingham m_bp_options_vec.clear(); 473b5796cb4SJim Ingham 47430fdc8d8SChris Lattner if (result.Succeeded()) 47530fdc8d8SChris Lattner { 476c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 477d9916eaeSJim Ingham 478c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 47930fdc8d8SChris Lattner { 48030fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 48130fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 48230fdc8d8SChris Lattner { 48330fdc8d8SChris Lattner Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 48439d7d4f0SJohnny Chen BreakpointOptions *bp_options = NULL; 48539d7d4f0SJohnny Chen if (cur_bp_id.GetLocationID() == LLDB_INVALID_BREAK_ID) 48639d7d4f0SJohnny Chen { 48739d7d4f0SJohnny Chen // This breakpoint does not have an associated location. 48839d7d4f0SJohnny Chen bp_options = bp->GetOptions(); 48939d7d4f0SJohnny Chen } 49039d7d4f0SJohnny Chen else 49130fdc8d8SChris Lattner { 49230fdc8d8SChris Lattner BreakpointLocationSP bp_loc_sp(bp->FindLocationByID (cur_bp_id.GetLocationID())); 49339d7d4f0SJohnny Chen // This breakpoint does have an associated location. 49439d7d4f0SJohnny Chen // Get its breakpoint options. 49530fdc8d8SChris Lattner if (bp_loc_sp) 49639d7d4f0SJohnny Chen bp_options = bp_loc_sp->GetLocationOptions(); 49739d7d4f0SJohnny Chen } 498b5796cb4SJim Ingham if (bp_options) 499b5796cb4SJim Ingham m_bp_options_vec.push_back (bp_options); 500b5796cb4SJim Ingham } 501b5796cb4SJim Ingham } 50239d7d4f0SJohnny Chen 50339d7d4f0SJohnny Chen // If we are using script language, get the script interpreter 50439d7d4f0SJohnny Chen // in order to set or collect command callback. Otherwise, call 50539d7d4f0SJohnny Chen // the methods associated with this object. 50630fdc8d8SChris Lattner if (m_options.m_use_script_language) 50730fdc8d8SChris Lattner { 508b5796cb4SJim Ingham ScriptInterpreter *script_interp = m_interpreter.GetScriptInterpreter(); 50939d7d4f0SJohnny Chen // Special handling for one-liner specified inline. 51039d7d4f0SJohnny Chen if (m_options.m_use_one_liner) 5118d4a8010SEnrico Granata { 512b5796cb4SJim Ingham script_interp->SetBreakpointCommandCallback (m_bp_options_vec, 51339d7d4f0SJohnny Chen m_options.m_one_liner.c_str()); 5148d4a8010SEnrico Granata } 5158d4a8010SEnrico Granata else if (m_options.m_function_name.size()) 5168d4a8010SEnrico Granata { 517b5796cb4SJim Ingham script_interp->SetBreakpointCommandCallbackFunction (m_bp_options_vec, 518d80102e4SJim Ingham m_options.m_function_name.c_str()); 5198d4a8010SEnrico Granata } 52094de55d5SJohnny Chen else 5218d4a8010SEnrico Granata { 522b5796cb4SJim Ingham script_interp->CollectDataForBreakpointCommandCallback (m_bp_options_vec, 52330fdc8d8SChris Lattner result); 52430fdc8d8SChris Lattner } 5258d4a8010SEnrico Granata } 52630fdc8d8SChris Lattner else 52730fdc8d8SChris Lattner { 52839d7d4f0SJohnny Chen // Special handling for one-liner specified inline. 52939d7d4f0SJohnny Chen if (m_options.m_use_one_liner) 530b5796cb4SJim Ingham SetBreakpointCommandCallback (m_bp_options_vec, 53139d7d4f0SJohnny Chen m_options.m_one_liner.c_str()); 53239d7d4f0SJohnny Chen else 533b5796cb4SJim Ingham CollectDataForBreakpointCommandCallback (m_bp_options_vec, 534b132097bSGreg Clayton result); 53530fdc8d8SChris Lattner } 536b5796cb4SJim Ingham 53730fdc8d8SChris Lattner } 53830fdc8d8SChris Lattner 53930fdc8d8SChris Lattner return result.Succeeded(); 54030fdc8d8SChris Lattner } 54130fdc8d8SChris Lattner 5425a988416SJim Ingham private: 5435a988416SJim Ingham CommandOptions m_options; 544b5796cb4SJim Ingham std::vector<BreakpointOptions *> m_bp_options_vec; // This stores the breakpoint options that we are currently 545b5796cb4SJim Ingham // collecting commands for. In the CollectData... calls we need 546b5796cb4SJim Ingham // to hand this off to the IOHandler, which may run asynchronously. 547b5796cb4SJim Ingham // So we have to have some way to keep it alive, and not leak it. 548b5796cb4SJim Ingham // Making it an ivar of the command object, which never goes away 549b5796cb4SJim Ingham // achieves this. Note that if we were able to run 550b5796cb4SJim Ingham // the same command concurrently in one interpreter we'd have to 551b5796cb4SJim Ingham // make this "per invocation". But there are many more reasons 552b5796cb4SJim Ingham // why it is not in general safe to do that in lldb at present, 553b5796cb4SJim Ingham // so it isn't worthwhile to come up with a more complex mechanism 554b5796cb4SJim Ingham // to address this particular weakness right now. 5555a988416SJim Ingham static const char *g_reader_instructions; 5565a988416SJim Ingham 5575a988416SJim Ingham }; 5585a988416SJim Ingham 5595a988416SJim Ingham const char * 56044d93782SGreg Clayton CommandObjectBreakpointCommandAdd::g_reader_instructions = "Enter your debugger command(s). Type 'DONE' to end.\n"; 5615a988416SJim Ingham 5625a988416SJim Ingham // FIXME: "script-type" needs to have its contents determined dynamically, so somebody can add a new scripting 5635a988416SJim Ingham // language to lldb and have it pickable here without having to change this enumeration by hand and rebuild lldb proper. 5645a988416SJim Ingham 5655a988416SJim Ingham static OptionEnumValueElement 5665a988416SJim Ingham g_script_option_enumeration[4] = 56730fdc8d8SChris Lattner { 5685a988416SJim Ingham { eScriptLanguageNone, "command", "Commands are in the lldb command interpreter language"}, 5695a988416SJim Ingham { eScriptLanguagePython, "python", "Commands are in the Python language."}, 5705a988416SJim Ingham { eSortOrderByName, "default-script", "Commands are in the default scripting language."}, 5715a988416SJim Ingham { 0, NULL, NULL } 5725a988416SJim Ingham }; 57330fdc8d8SChris Lattner 5745a988416SJim Ingham OptionDefinition 5755a988416SJim Ingham CommandObjectBreakpointCommandAdd::CommandOptions::g_option_table[] = 57630fdc8d8SChris Lattner { 577d37221dcSZachary Turner { LLDB_OPT_SET_1, false, "one-liner", 'o', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeOneLiner, 5785a988416SJim Ingham "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." }, 57930fdc8d8SChris Lattner 580d37221dcSZachary Turner { LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, 5815a988416SJim Ingham "Specify whether breakpoint command execution should terminate on error." }, 58230fdc8d8SChris Lattner 583d37221dcSZachary Turner { LLDB_OPT_SET_ALL, false, "script-type", 's', OptionParser::eRequiredArgument, NULL, g_script_option_enumeration, 0, eArgTypeNone, 5845a988416SJim Ingham "Specify the language for the commands - if none is specified, the lldb command interpreter will be used."}, 58530fdc8d8SChris Lattner 586d37221dcSZachary Turner { LLDB_OPT_SET_2, false, "python-function", 'F', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePythonFunction, 5875a988416SJim Ingham "Give the name of a Python function to run as command for this breakpoint. Be sure to give a module name if appropriate."}, 58839d7d4f0SJohnny Chen 589*33df7cd3SJim Ingham { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, 590*33df7cd3SJim Ingham "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, 591*33df7cd3SJim Ingham 592d37221dcSZachary Turner { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } 5935a988416SJim Ingham }; 59430fdc8d8SChris Lattner 59530fdc8d8SChris Lattner //------------------------------------------------------------------------- 59693e0f19fSCaroline Tice // CommandObjectBreakpointCommandDelete 59730fdc8d8SChris Lattner //------------------------------------------------------------------------- 59830fdc8d8SChris Lattner 5995a988416SJim Ingham class CommandObjectBreakpointCommandDelete : public CommandObjectParsed 6005a988416SJim Ingham { 6015a988416SJim Ingham public: 6025a988416SJim Ingham CommandObjectBreakpointCommandDelete (CommandInterpreter &interpreter) : 6035a988416SJim Ingham CommandObjectParsed (interpreter, 60493e0f19fSCaroline Tice "delete", 60593e0f19fSCaroline Tice "Delete the set of commands from a breakpoint.", 606*33df7cd3SJim Ingham NULL), 607*33df7cd3SJim Ingham m_options (interpreter) 60830fdc8d8SChris Lattner { 609405fe67fSCaroline Tice CommandArgumentEntry arg; 610405fe67fSCaroline Tice CommandArgumentData bp_id_arg; 611405fe67fSCaroline Tice 612405fe67fSCaroline Tice // Define the first (and only) variant of this arg. 613405fe67fSCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 614405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatPlain; 615405fe67fSCaroline Tice 616405fe67fSCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 617405fe67fSCaroline Tice arg.push_back (bp_id_arg); 618405fe67fSCaroline Tice 619405fe67fSCaroline Tice // Push the data for the first argument into the m_arguments vector. 620405fe67fSCaroline Tice m_arguments.push_back (arg); 62130fdc8d8SChris Lattner } 62230fdc8d8SChris Lattner 62330fdc8d8SChris Lattner 6245a988416SJim Ingham virtual 6255a988416SJim Ingham ~CommandObjectBreakpointCommandDelete () {} 6265a988416SJim Ingham 627*33df7cd3SJim Ingham virtual Options * 628*33df7cd3SJim Ingham GetOptions () 629*33df7cd3SJim Ingham { 630*33df7cd3SJim Ingham return &m_options; 631*33df7cd3SJim Ingham } 632*33df7cd3SJim Ingham 633*33df7cd3SJim Ingham class CommandOptions : public Options 634*33df7cd3SJim Ingham { 635*33df7cd3SJim Ingham public: 636*33df7cd3SJim Ingham 637*33df7cd3SJim Ingham CommandOptions (CommandInterpreter &interpreter) : 638*33df7cd3SJim Ingham Options (interpreter), 639*33df7cd3SJim Ingham m_use_dummy (false) 640*33df7cd3SJim Ingham { 641*33df7cd3SJim Ingham } 642*33df7cd3SJim Ingham 643*33df7cd3SJim Ingham virtual 644*33df7cd3SJim Ingham ~CommandOptions () {} 645*33df7cd3SJim Ingham 646*33df7cd3SJim Ingham virtual Error 647*33df7cd3SJim Ingham SetOptionValue (uint32_t option_idx, const char *option_arg) 648*33df7cd3SJim Ingham { 649*33df7cd3SJim Ingham Error error; 650*33df7cd3SJim Ingham const int short_option = m_getopt_table[option_idx].val; 651*33df7cd3SJim Ingham 652*33df7cd3SJim Ingham switch (short_option) 653*33df7cd3SJim Ingham { 654*33df7cd3SJim Ingham case 'D': 655*33df7cd3SJim Ingham m_use_dummy = true; 656*33df7cd3SJim Ingham break; 657*33df7cd3SJim Ingham 658*33df7cd3SJim Ingham default: 659*33df7cd3SJim Ingham error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 660*33df7cd3SJim Ingham break; 661*33df7cd3SJim Ingham } 662*33df7cd3SJim Ingham 663*33df7cd3SJim Ingham return error; 664*33df7cd3SJim Ingham } 665*33df7cd3SJim Ingham 666*33df7cd3SJim Ingham void 667*33df7cd3SJim Ingham OptionParsingStarting () 668*33df7cd3SJim Ingham { 669*33df7cd3SJim Ingham m_use_dummy = false; 670*33df7cd3SJim Ingham } 671*33df7cd3SJim Ingham 672*33df7cd3SJim Ingham const OptionDefinition* 673*33df7cd3SJim Ingham GetDefinitions () 674*33df7cd3SJim Ingham { 675*33df7cd3SJim Ingham return g_option_table; 676*33df7cd3SJim Ingham } 677*33df7cd3SJim Ingham 678*33df7cd3SJim Ingham // Options table: Required for subclasses of Options. 679*33df7cd3SJim Ingham 680*33df7cd3SJim Ingham static OptionDefinition g_option_table[]; 681*33df7cd3SJim Ingham 682*33df7cd3SJim Ingham // Instance variables to hold the values for command options. 683*33df7cd3SJim Ingham bool m_use_dummy; 684*33df7cd3SJim Ingham }; 685*33df7cd3SJim Ingham 6865a988416SJim Ingham protected: 6875a988416SJim Ingham virtual bool 6885a988416SJim Ingham DoExecute (Args& command, CommandReturnObject &result) 68930fdc8d8SChris Lattner { 690*33df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 69130fdc8d8SChris Lattner 69230fdc8d8SChris Lattner if (target == NULL) 69330fdc8d8SChris Lattner { 69493e0f19fSCaroline Tice result.AppendError ("There is not a current executable; there are no breakpoints from which to delete commands"); 69530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 69630fdc8d8SChris Lattner return false; 69730fdc8d8SChris Lattner } 69830fdc8d8SChris Lattner 69930fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 70030fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 70130fdc8d8SChris Lattner 70230fdc8d8SChris Lattner if (num_breakpoints == 0) 70330fdc8d8SChris Lattner { 70493e0f19fSCaroline Tice result.AppendError ("No breakpoints exist to have commands deleted"); 70530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 70630fdc8d8SChris Lattner return false; 70730fdc8d8SChris Lattner } 70830fdc8d8SChris Lattner 70930fdc8d8SChris Lattner if (command.GetArgumentCount() == 0) 71030fdc8d8SChris Lattner { 71193e0f19fSCaroline Tice result.AppendError ("No breakpoint specified from which to delete the commands"); 71230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 71330fdc8d8SChris Lattner return false; 71430fdc8d8SChris Lattner } 71530fdc8d8SChris Lattner 71630fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 71730fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 71830fdc8d8SChris Lattner 71930fdc8d8SChris Lattner if (result.Succeeded()) 72030fdc8d8SChris Lattner { 721c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 722c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 72330fdc8d8SChris Lattner { 72430fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 72530fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 72630fdc8d8SChris Lattner { 72730fdc8d8SChris Lattner Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 72830fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 72930fdc8d8SChris Lattner { 73030fdc8d8SChris Lattner BreakpointLocationSP bp_loc_sp (bp->FindLocationByID (cur_bp_id.GetLocationID())); 73130fdc8d8SChris Lattner if (bp_loc_sp) 73230fdc8d8SChris Lattner bp_loc_sp->ClearCallback(); 73330fdc8d8SChris Lattner else 73430fdc8d8SChris Lattner { 73530fdc8d8SChris Lattner result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n", 73630fdc8d8SChris Lattner cur_bp_id.GetBreakpointID(), 73730fdc8d8SChris Lattner cur_bp_id.GetLocationID()); 73830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 73930fdc8d8SChris Lattner return false; 74030fdc8d8SChris Lattner } 74130fdc8d8SChris Lattner } 74230fdc8d8SChris Lattner else 74330fdc8d8SChris Lattner { 74430fdc8d8SChris Lattner bp->ClearCallback(); 74530fdc8d8SChris Lattner } 74630fdc8d8SChris Lattner } 74730fdc8d8SChris Lattner } 74830fdc8d8SChris Lattner } 74930fdc8d8SChris Lattner return result.Succeeded(); 75030fdc8d8SChris Lattner } 751*33df7cd3SJim Ingham private: 752*33df7cd3SJim Ingham CommandOptions m_options; 7535a988416SJim Ingham }; 75430fdc8d8SChris Lattner 755*33df7cd3SJim Ingham OptionDefinition 756*33df7cd3SJim Ingham CommandObjectBreakpointCommandDelete::CommandOptions::g_option_table[] = 757*33df7cd3SJim Ingham { 758*33df7cd3SJim Ingham { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, 759*33df7cd3SJim Ingham "Delete commands from Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, 760*33df7cd3SJim Ingham 761*33df7cd3SJim Ingham { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } 762*33df7cd3SJim Ingham }; 763*33df7cd3SJim Ingham 764*33df7cd3SJim Ingham 76530fdc8d8SChris Lattner //------------------------------------------------------------------------- 76630fdc8d8SChris Lattner // CommandObjectBreakpointCommandList 76730fdc8d8SChris Lattner //------------------------------------------------------------------------- 76830fdc8d8SChris Lattner 7695a988416SJim Ingham class CommandObjectBreakpointCommandList : public CommandObjectParsed 7705a988416SJim Ingham { 7715a988416SJim Ingham public: 7725a988416SJim Ingham CommandObjectBreakpointCommandList (CommandInterpreter &interpreter) : 7735a988416SJim Ingham CommandObjectParsed (interpreter, 774a7015092SGreg Clayton "list", 77530fdc8d8SChris Lattner "List the script or set of commands to be executed when the breakpoint is hit.", 776405fe67fSCaroline Tice NULL) 77730fdc8d8SChris Lattner { 778405fe67fSCaroline Tice CommandArgumentEntry arg; 779405fe67fSCaroline Tice CommandArgumentData bp_id_arg; 780405fe67fSCaroline Tice 781405fe67fSCaroline Tice // Define the first (and only) variant of this arg. 782405fe67fSCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 783405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatPlain; 784405fe67fSCaroline Tice 785405fe67fSCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 786405fe67fSCaroline Tice arg.push_back (bp_id_arg); 787405fe67fSCaroline Tice 788405fe67fSCaroline Tice // Push the data for the first argument into the m_arguments vector. 789405fe67fSCaroline Tice m_arguments.push_back (arg); 79030fdc8d8SChris Lattner } 79130fdc8d8SChris Lattner 7925a988416SJim Ingham virtual 7935a988416SJim Ingham ~CommandObjectBreakpointCommandList () {} 79430fdc8d8SChris Lattner 7955a988416SJim Ingham protected: 7965a988416SJim Ingham virtual bool 7975a988416SJim Ingham DoExecute (Args& command, 7985a988416SJim Ingham CommandReturnObject &result) 79930fdc8d8SChris Lattner { 800a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 80130fdc8d8SChris Lattner 80230fdc8d8SChris Lattner if (target == NULL) 80330fdc8d8SChris Lattner { 80430fdc8d8SChris Lattner result.AppendError ("There is not a current executable; there are no breakpoints for which to list commands"); 80530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 80630fdc8d8SChris Lattner return false; 80730fdc8d8SChris Lattner } 80830fdc8d8SChris Lattner 80930fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 81030fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 81130fdc8d8SChris Lattner 81230fdc8d8SChris Lattner if (num_breakpoints == 0) 81330fdc8d8SChris Lattner { 81430fdc8d8SChris Lattner result.AppendError ("No breakpoints exist for which to list commands"); 81530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 81630fdc8d8SChris Lattner return false; 81730fdc8d8SChris Lattner } 81830fdc8d8SChris Lattner 81930fdc8d8SChris Lattner if (command.GetArgumentCount() == 0) 82030fdc8d8SChris Lattner { 82130fdc8d8SChris Lattner result.AppendError ("No breakpoint specified for which to list the commands"); 82230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 82330fdc8d8SChris Lattner return false; 82430fdc8d8SChris Lattner } 82530fdc8d8SChris Lattner 82630fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 82730fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 82830fdc8d8SChris Lattner 82930fdc8d8SChris Lattner if (result.Succeeded()) 83030fdc8d8SChris Lattner { 831c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 832c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 83330fdc8d8SChris Lattner { 83430fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 83530fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 83630fdc8d8SChris Lattner { 83730fdc8d8SChris Lattner Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 83830fdc8d8SChris Lattner 83930fdc8d8SChris Lattner if (bp) 84030fdc8d8SChris Lattner { 8411b54c88cSJim Ingham const BreakpointOptions *bp_options = NULL; 84230fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 84330fdc8d8SChris Lattner { 84430fdc8d8SChris Lattner BreakpointLocationSP bp_loc_sp(bp->FindLocationByID (cur_bp_id.GetLocationID())); 84530fdc8d8SChris Lattner if (bp_loc_sp) 84605407f6bSJim Ingham bp_options = bp_loc_sp->GetOptionsNoCreate(); 84730fdc8d8SChris Lattner else 84830fdc8d8SChris Lattner { 84930fdc8d8SChris Lattner result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n", 85030fdc8d8SChris Lattner cur_bp_id.GetBreakpointID(), 85130fdc8d8SChris Lattner cur_bp_id.GetLocationID()); 85230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 85330fdc8d8SChris Lattner return false; 85430fdc8d8SChris Lattner } 85530fdc8d8SChris Lattner } 85630fdc8d8SChris Lattner else 85730fdc8d8SChris Lattner { 85830fdc8d8SChris Lattner bp_options = bp->GetOptions(); 85930fdc8d8SChris Lattner } 86030fdc8d8SChris Lattner 86130fdc8d8SChris Lattner if (bp_options) 86230fdc8d8SChris Lattner { 86330fdc8d8SChris Lattner StreamString id_str; 864e16c50a1SJim Ingham BreakpointID::GetCanonicalReference (&id_str, 865e16c50a1SJim Ingham cur_bp_id.GetBreakpointID(), 866e16c50a1SJim Ingham cur_bp_id.GetLocationID()); 8671b54c88cSJim Ingham const Baton *baton = bp_options->GetBaton(); 86830fdc8d8SChris Lattner if (baton) 86930fdc8d8SChris Lattner { 87030fdc8d8SChris Lattner result.GetOutputStream().Printf ("Breakpoint %s:\n", id_str.GetData()); 87130fdc8d8SChris Lattner result.GetOutputStream().IndentMore (); 87230fdc8d8SChris Lattner baton->GetDescription(&result.GetOutputStream(), eDescriptionLevelFull); 87330fdc8d8SChris Lattner result.GetOutputStream().IndentLess (); 87430fdc8d8SChris Lattner } 87530fdc8d8SChris Lattner else 87630fdc8d8SChris Lattner { 877e16c50a1SJim Ingham result.AppendMessageWithFormat ("Breakpoint %s does not have an associated command.\n", 878e16c50a1SJim Ingham id_str.GetData()); 87930fdc8d8SChris Lattner } 88030fdc8d8SChris Lattner } 88130fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 88230fdc8d8SChris Lattner } 88330fdc8d8SChris Lattner else 88430fdc8d8SChris Lattner { 88530fdc8d8SChris Lattner result.AppendErrorWithFormat("Invalid breakpoint ID: %u.\n", cur_bp_id.GetBreakpointID()); 88630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 88730fdc8d8SChris Lattner } 88830fdc8d8SChris Lattner 88930fdc8d8SChris Lattner } 89030fdc8d8SChris Lattner } 89130fdc8d8SChris Lattner } 89230fdc8d8SChris Lattner 89330fdc8d8SChris Lattner return result.Succeeded(); 89430fdc8d8SChris Lattner } 8955a988416SJim Ingham }; 89630fdc8d8SChris Lattner 89730fdc8d8SChris Lattner //------------------------------------------------------------------------- 89830fdc8d8SChris Lattner // CommandObjectBreakpointCommand 89930fdc8d8SChris Lattner //------------------------------------------------------------------------- 90030fdc8d8SChris Lattner 9016611103cSGreg Clayton CommandObjectBreakpointCommand::CommandObjectBreakpointCommand (CommandInterpreter &interpreter) : 902a7015092SGreg Clayton CommandObjectMultiword (interpreter, 903a7015092SGreg Clayton "command", 9047050e0b1SSean Callanan "A set of commands for adding, removing and examining bits of code to be executed when the breakpoint is hit (breakpoint 'commands').", 90530fdc8d8SChris Lattner "command <sub-command> [<sub-command-options>] <breakpoint-id>") 90630fdc8d8SChris Lattner { 907a7015092SGreg Clayton CommandObjectSP add_command_object (new CommandObjectBreakpointCommandAdd (interpreter)); 90893e0f19fSCaroline Tice CommandObjectSP delete_command_object (new CommandObjectBreakpointCommandDelete (interpreter)); 909a7015092SGreg Clayton CommandObjectSP list_command_object (new CommandObjectBreakpointCommandList (interpreter)); 91030fdc8d8SChris Lattner 91130fdc8d8SChris Lattner add_command_object->SetCommandName ("breakpoint command add"); 91293e0f19fSCaroline Tice delete_command_object->SetCommandName ("breakpoint command delete"); 91330fdc8d8SChris Lattner list_command_object->SetCommandName ("breakpoint command list"); 91430fdc8d8SChris Lattner 91523f59509SGreg Clayton LoadSubCommand ("add", add_command_object); 91623f59509SGreg Clayton LoadSubCommand ("delete", delete_command_object); 91723f59509SGreg Clayton LoadSubCommand ("list", list_command_object); 91830fdc8d8SChris Lattner } 91930fdc8d8SChris Lattner 92030fdc8d8SChris Lattner CommandObjectBreakpointCommand::~CommandObjectBreakpointCommand () 92130fdc8d8SChris Lattner { 92230fdc8d8SChris Lattner } 92330fdc8d8SChris Lattner 92430fdc8d8SChris Lattner 925