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 1030fdc8d8SChris Lattner // C Includes 1130fdc8d8SChris Lattner // C++ Includes 1230fdc8d8SChris Lattner 1330fdc8d8SChris Lattner 1430fdc8d8SChris Lattner #include "CommandObjectBreakpointCommand.h" 1530fdc8d8SChris Lattner #include "CommandObjectBreakpoint.h" 1630fdc8d8SChris Lattner 1730fdc8d8SChris Lattner #include "lldb/Interpreter/CommandInterpreter.h" 1830fdc8d8SChris Lattner #include "lldb/Interpreter/CommandReturnObject.h" 1930fdc8d8SChris Lattner #include "lldb/Target/Target.h" 2030fdc8d8SChris Lattner #include "lldb/Target/Thread.h" 2130fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointIDList.h" 2230fdc8d8SChris Lattner #include "lldb/Breakpoint/Breakpoint.h" 2330fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointLocation.h" 2430fdc8d8SChris Lattner #include "lldb/Breakpoint/StoppointCallbackContext.h" 2530fdc8d8SChris Lattner #include "lldb/Core/State.h" 2630fdc8d8SChris Lattner 2730fdc8d8SChris Lattner using namespace lldb; 2830fdc8d8SChris Lattner using namespace lldb_private; 2930fdc8d8SChris Lattner 3030fdc8d8SChris Lattner //------------------------------------------------------------------------- 3130fdc8d8SChris Lattner // CommandObjectBreakpointCommandAdd 3230fdc8d8SChris Lattner //------------------------------------------------------------------------- 3330fdc8d8SChris Lattner 3430fdc8d8SChris Lattner 355a988416SJim Ingham class CommandObjectBreakpointCommandAdd : public CommandObjectParsed 365a988416SJim Ingham { 375a988416SJim Ingham public: 385a988416SJim Ingham 395a988416SJim Ingham CommandObjectBreakpointCommandAdd (CommandInterpreter &interpreter) : 405a988416SJim Ingham CommandObjectParsed (interpreter, 41a7015092SGreg Clayton "add", 42e3d26315SCaroline Tice "Add a set of commands to a breakpoint, to be executed whenever the breakpoint is hit.", 43eb0103f2SGreg Clayton NULL), 44eb0103f2SGreg Clayton m_options (interpreter) 4530fdc8d8SChris Lattner { 4630fdc8d8SChris Lattner SetHelpLong ( 4730fdc8d8SChris Lattner "\nGeneral information about entering breakpoint commands \n\ 4830fdc8d8SChris Lattner ------------------------------------------------------ \n\ 4930fdc8d8SChris Lattner \n\ 5030fdc8d8SChris Lattner This command will cause you to be prompted to enter the command or set \n\ 5130fdc8d8SChris Lattner of commands you wish to be executed when the specified breakpoint is \n\ 5230fdc8d8SChris Lattner hit. You will be told to enter your command(s), and will see a '> ' \n\ 5330fdc8d8SChris Lattner prompt. Because you can enter one or many commands to be executed when \n\ 5430fdc8d8SChris Lattner a breakpoint is hit, you will continue to be prompted after each \n\ 5530fdc8d8SChris Lattner new-line that you enter, until you enter the word 'DONE', which will \n\ 5630fdc8d8SChris Lattner cause the commands you have entered to be stored with the breakpoint \n\ 5730fdc8d8SChris Lattner and executed when the breakpoint is hit. \n\ 5830fdc8d8SChris Lattner \n\ 5930fdc8d8SChris Lattner Syntax checking is not necessarily done when breakpoint commands are \n\ 6030fdc8d8SChris Lattner entered. An improperly written breakpoint command will attempt to get \n\ 6130fdc8d8SChris Lattner executed when the breakpoint gets hit, and usually silently fail. If \n\ 6230fdc8d8SChris Lattner your breakpoint command does not appear to be getting executed, go \n\ 6330fdc8d8SChris Lattner back and check your syntax. \n\ 6430fdc8d8SChris Lattner \n\ 6530fdc8d8SChris Lattner \n\ 6630fdc8d8SChris Lattner Special information about PYTHON breakpoint commands \n\ 6730fdc8d8SChris Lattner ---------------------------------------------------- \n\ 6830fdc8d8SChris Lattner \n\ 6930fdc8d8SChris Lattner You may enter either one line of Python or multiple lines of Python \n\ 7030fdc8d8SChris Lattner (including defining whole functions, if desired). If you enter a \n\ 7130fdc8d8SChris Lattner single line of Python, that will be passed to the Python interpreter \n\ 7230fdc8d8SChris Lattner 'as is' when the breakpoint gets hit. If you enter function \n\ 7330fdc8d8SChris Lattner definitions, they will be passed to the Python interpreter as soon as \n\ 7430fdc8d8SChris Lattner you finish entering the breakpoint command, and they can be called \n\ 7530fdc8d8SChris Lattner later (don't forget to add calls to them, if you want them called when \n\ 7630fdc8d8SChris Lattner the breakpoint is hit). If you enter multiple lines of Python that \n\ 7730fdc8d8SChris Lattner are not function definitions, they will be collected into a new, \n\ 7830fdc8d8SChris Lattner automatically generated Python function, and a call to the newly \n\ 79c9efdbb0SJim Ingham generated function will be attached to the breakpoint. \n\ 80c9efdbb0SJim Ingham \n\ 81c9efdbb0SJim Ingham This auto-generated function is passed in two arguments: \n\ 82c9efdbb0SJim Ingham \n\ 83c9efdbb0SJim Ingham frame: an SBFrame object representing the frame which hit the breakpoint. \n\ 84c9efdbb0SJim Ingham From the frame you can get back to the thread and process. \n\ 85c9efdbb0SJim Ingham bp_loc: the number of the breakpoint location that was hit. \n\ 86c9efdbb0SJim Ingham This is useful since one breakpoint can have many locations. \n\ 87c9efdbb0SJim Ingham \n\ 88c9efdbb0SJim Ingham Important Note: Because loose Python code gets collected into functions, \n\ 89c9efdbb0SJim Ingham if you want to access global variables in the 'loose' code, you need to \n\ 9030fdc8d8SChris Lattner specify that they are global, using the 'global' keyword. Be sure to \n\ 9130fdc8d8SChris Lattner use correct Python syntax, including indentation, when entering Python \n\ 92c9efdbb0SJim Ingham breakpoint commands. \n\ 93c9efdbb0SJim Ingham \n\ 94c9efdbb0SJim Ingham As a third option, you can pass the name of an already existing Python function \n\ 95c9efdbb0SJim Ingham and that function will be attached to the breakpoint. It will get passed the \n\ 96c9efdbb0SJim Ingham frame and bp_loc arguments mentioned above. \n\ 9730fdc8d8SChris Lattner \n\ 9830fdc8d8SChris Lattner Example Python one-line breakpoint command: \n\ 9930fdc8d8SChris Lattner \n\ 100e16c50a1SJim Ingham (lldb) breakpoint command add -s python 1 \n\ 10130fdc8d8SChris Lattner Enter your Python command(s). Type 'DONE' to end. \n\ 10230fdc8d8SChris Lattner > print \"Hit this breakpoint!\" \n\ 10330fdc8d8SChris Lattner > DONE \n\ 10430fdc8d8SChris Lattner \n\ 1053495f25aSJohnny Chen As a convenience, this also works for a short Python one-liner: \n\ 106e16c50a1SJim Ingham (lldb) breakpoint command add -s python 1 -o \"import time; print time.asctime()\" \n\ 1073495f25aSJohnny Chen (lldb) run \n\ 1083495f25aSJohnny Chen Launching '.../a.out' (x86_64) \n\ 1093495f25aSJohnny Chen (lldb) Fri Sep 10 12:17:45 2010 \n\ 1103495f25aSJohnny Chen Process 21778 Stopped \n\ 1113495f25aSJohnny 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\ 1123495f25aSJohnny Chen 36 \n\ 1133495f25aSJohnny Chen 37 int c(int val)\n\ 1143495f25aSJohnny Chen 38 {\n\ 1153495f25aSJohnny Chen 39 -> return val + 3;\n\ 1163495f25aSJohnny Chen 40 }\n\ 1173495f25aSJohnny Chen 41 \n\ 1183495f25aSJohnny Chen 42 int main (int argc, char const *argv[])\n\ 1193495f25aSJohnny Chen (lldb) \n\ 1203495f25aSJohnny Chen \n\ 12130fdc8d8SChris Lattner Example multiple line Python breakpoint command, using function definition: \n\ 12230fdc8d8SChris Lattner \n\ 123e16c50a1SJim Ingham (lldb) breakpoint command add -s python 1 \n\ 12430fdc8d8SChris Lattner Enter your Python command(s). Type 'DONE' to end. \n\ 12530fdc8d8SChris Lattner > def breakpoint_output (bp_no): \n\ 12630fdc8d8SChris Lattner > out_string = \"Hit breakpoint number \" + repr (bp_no) \n\ 12730fdc8d8SChris Lattner > print out_string \n\ 12830fdc8d8SChris Lattner > return True \n\ 12930fdc8d8SChris Lattner > breakpoint_output (1) \n\ 13030fdc8d8SChris Lattner > DONE \n\ 13130fdc8d8SChris Lattner \n\ 13230fdc8d8SChris Lattner \n\ 13330fdc8d8SChris Lattner Example multiple line Python breakpoint command, using 'loose' Python: \n\ 13430fdc8d8SChris Lattner \n\ 135e16c50a1SJim Ingham (lldb) breakpoint command add -s p 1 \n\ 13630fdc8d8SChris Lattner Enter your Python command(s). Type 'DONE' to end. \n\ 13730fdc8d8SChris Lattner > global bp_count \n\ 13830fdc8d8SChris Lattner > bp_count = bp_count + 1 \n\ 13930fdc8d8SChris Lattner > print \"Hit this breakpoint \" + repr(bp_count) + \" times!\" \n\ 14030fdc8d8SChris Lattner > DONE \n\ 14130fdc8d8SChris Lattner \n\ 14230fdc8d8SChris Lattner In this case, since there is a reference to a global variable, \n\ 14330fdc8d8SChris Lattner 'bp_count', you will also need to make sure 'bp_count' exists and is \n\ 14430fdc8d8SChris Lattner initialized: \n\ 14530fdc8d8SChris Lattner \n\ 14630fdc8d8SChris Lattner (lldb) script \n\ 14730fdc8d8SChris Lattner >>> bp_count = 0 \n\ 14830fdc8d8SChris Lattner >>> quit() \n\ 14930fdc8d8SChris Lattner \n\ 15030fdc8d8SChris Lattner (lldb) \n\ 15130fdc8d8SChris Lattner \n\ 152650b9268SCaroline Tice \n\ 153650b9268SCaroline Tice Final Note: If you get a warning that no breakpoint command was generated, \n\ 154650b9268SCaroline Tice but you did not get any syntax errors, you probably forgot to add a call \n\ 155650b9268SCaroline Tice to your functions. \n\ 156650b9268SCaroline Tice \n\ 157e3d26315SCaroline Tice Special information about debugger command breakpoint commands \n\ 158e3d26315SCaroline Tice -------------------------------------------------------------- \n\ 15930fdc8d8SChris Lattner \n\ 16030fdc8d8SChris Lattner You may enter any debugger command, exactly as you would at the \n\ 16130fdc8d8SChris Lattner debugger prompt. You may enter as many debugger commands as you like, \n\ 16230fdc8d8SChris Lattner but do NOT enter more than one command per line. \n" ); 163405fe67fSCaroline Tice 164405fe67fSCaroline Tice CommandArgumentEntry arg; 165405fe67fSCaroline Tice CommandArgumentData bp_id_arg; 166405fe67fSCaroline Tice 167405fe67fSCaroline Tice // Define the first (and only) variant of this arg. 168405fe67fSCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 169405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatPlain; 170405fe67fSCaroline Tice 171405fe67fSCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 172405fe67fSCaroline Tice arg.push_back (bp_id_arg); 173405fe67fSCaroline Tice 174405fe67fSCaroline Tice // Push the data for the first argument into the m_arguments vector. 175405fe67fSCaroline Tice m_arguments.push_back (arg); 17630fdc8d8SChris Lattner } 17730fdc8d8SChris Lattner 1785a988416SJim Ingham virtual 1795a988416SJim Ingham ~CommandObjectBreakpointCommandAdd () {} 1805a988416SJim Ingham 1815a988416SJim Ingham virtual Options * 1825a988416SJim Ingham GetOptions () 1835a988416SJim Ingham { 1845a988416SJim Ingham return &m_options; 1855a988416SJim Ingham } 1865a988416SJim Ingham 1875a988416SJim Ingham void 1885a988416SJim Ingham CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, 1895a988416SJim Ingham CommandReturnObject &result) 1905a988416SJim Ingham { 1915a988416SJim Ingham InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger())); 1925a988416SJim Ingham std::auto_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData()); 1935a988416SJim Ingham if (reader_sp && data_ap.get()) 1945a988416SJim Ingham { 1955a988416SJim Ingham BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release())); 1965a988416SJim Ingham bp_options->SetCallback (BreakpointOptionsCallbackFunction, baton_sp); 1975a988416SJim Ingham 1985a988416SJim Ingham Error err (reader_sp->Initialize (CommandObjectBreakpointCommandAdd::GenerateBreakpointCommandCallback, 1995a988416SJim Ingham bp_options, // baton 2005a988416SJim Ingham eInputReaderGranularityLine, // token size, to pass to callback function 2015a988416SJim Ingham "DONE", // end token 2025a988416SJim Ingham "> ", // prompt 2035a988416SJim Ingham true)); // echo input 2045a988416SJim Ingham if (err.Success()) 2055a988416SJim Ingham { 2065a988416SJim Ingham m_interpreter.GetDebugger().PushInputReader (reader_sp); 2075a988416SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 2085a988416SJim Ingham } 2095a988416SJim Ingham else 2105a988416SJim Ingham { 2115a988416SJim Ingham result.AppendError (err.AsCString()); 2125a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 2135a988416SJim Ingham } 2145a988416SJim Ingham } 2155a988416SJim Ingham else 2165a988416SJim Ingham { 2175a988416SJim Ingham result.AppendError("out of memory"); 2185a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 2195a988416SJim Ingham } 2205a988416SJim Ingham 2215a988416SJim Ingham } 2225a988416SJim Ingham 2235a988416SJim Ingham /// Set a one-liner as the callback for the breakpoint. 2245a988416SJim Ingham void 2255a988416SJim Ingham SetBreakpointCommandCallback (BreakpointOptions *bp_options, 2265a988416SJim Ingham const char *oneliner) 2275a988416SJim Ingham { 2285a988416SJim Ingham std::auto_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData()); 2295a988416SJim Ingham 2305a988416SJim Ingham // It's necessary to set both user_source and script_source to the oneliner. 2315a988416SJim Ingham // The former is used to generate callback description (as in breakpoint command list) 2325a988416SJim Ingham // while the latter is used for Python to interpret during the actual callback. 2335a988416SJim Ingham data_ap->user_source.AppendString (oneliner); 2345a988416SJim Ingham data_ap->script_source.assign (oneliner); 2355a988416SJim Ingham data_ap->stop_on_error = m_options.m_stop_on_error; 2365a988416SJim Ingham 2375a988416SJim Ingham BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release())); 2385a988416SJim Ingham bp_options->SetCallback (BreakpointOptionsCallbackFunction, baton_sp); 2395a988416SJim Ingham 2405a988416SJim Ingham return; 2415a988416SJim Ingham } 2425a988416SJim Ingham 2435a988416SJim Ingham static size_t 2445a988416SJim Ingham GenerateBreakpointCommandCallback (void *baton, 2455a988416SJim Ingham InputReader &reader, 2465a988416SJim Ingham lldb::InputReaderAction notification, 2475a988416SJim Ingham const char *bytes, 2485a988416SJim Ingham size_t bytes_len) 2495a988416SJim Ingham { 2505a988416SJim Ingham StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream(); 2515a988416SJim Ingham bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode(); 2525a988416SJim Ingham 2535a988416SJim Ingham switch (notification) 2545a988416SJim Ingham { 2555a988416SJim Ingham case eInputReaderActivate: 2565a988416SJim Ingham if (!batch_mode) 2575a988416SJim Ingham { 2585a988416SJim Ingham out_stream->Printf ("%s\n", g_reader_instructions); 2595a988416SJim Ingham if (reader.GetPrompt()) 2605a988416SJim Ingham out_stream->Printf ("%s", reader.GetPrompt()); 2615a988416SJim Ingham out_stream->Flush(); 2625a988416SJim Ingham } 2635a988416SJim Ingham break; 2645a988416SJim Ingham 2655a988416SJim Ingham case eInputReaderDeactivate: 2665a988416SJim Ingham break; 2675a988416SJim Ingham 2685a988416SJim Ingham case eInputReaderReactivate: 2695a988416SJim Ingham if (reader.GetPrompt() && !batch_mode) 2705a988416SJim Ingham { 2715a988416SJim Ingham out_stream->Printf ("%s", reader.GetPrompt()); 2725a988416SJim Ingham out_stream->Flush(); 2735a988416SJim Ingham } 2745a988416SJim Ingham break; 2755a988416SJim Ingham 2765a988416SJim Ingham case eInputReaderAsynchronousOutputWritten: 2775a988416SJim Ingham break; 2785a988416SJim Ingham 2795a988416SJim Ingham case eInputReaderGotToken: 2805a988416SJim Ingham if (bytes && bytes_len && baton) 2815a988416SJim Ingham { 2825a988416SJim Ingham BreakpointOptions *bp_options = (BreakpointOptions *) baton; 2835a988416SJim Ingham if (bp_options) 2845a988416SJim Ingham { 2855a988416SJim Ingham Baton *bp_options_baton = bp_options->GetBaton(); 2865a988416SJim Ingham if (bp_options_baton) 2875a988416SJim Ingham ((BreakpointOptions::CommandData *)bp_options_baton->m_data)->user_source.AppendString (bytes, bytes_len); 2885a988416SJim Ingham } 2895a988416SJim Ingham } 2905a988416SJim Ingham if (!reader.IsDone() && reader.GetPrompt() && !batch_mode) 2915a988416SJim Ingham { 2925a988416SJim Ingham out_stream->Printf ("%s", reader.GetPrompt()); 2935a988416SJim Ingham out_stream->Flush(); 2945a988416SJim Ingham } 2955a988416SJim Ingham break; 2965a988416SJim Ingham 2975a988416SJim Ingham case eInputReaderInterrupt: 2985a988416SJim Ingham { 2995a988416SJim Ingham // Finish, and cancel the breakpoint command. 3005a988416SJim Ingham reader.SetIsDone (true); 3015a988416SJim Ingham BreakpointOptions *bp_options = (BreakpointOptions *) baton; 3025a988416SJim Ingham if (bp_options) 3035a988416SJim Ingham { 3045a988416SJim Ingham Baton *bp_options_baton = bp_options->GetBaton (); 3055a988416SJim Ingham if (bp_options_baton) 3065a988416SJim Ingham { 3075a988416SJim Ingham ((BreakpointOptions::CommandData *) bp_options_baton->m_data)->user_source.Clear(); 3085a988416SJim Ingham ((BreakpointOptions::CommandData *) bp_options_baton->m_data)->script_source.clear(); 3095a988416SJim Ingham } 3105a988416SJim Ingham } 3115a988416SJim Ingham if (!batch_mode) 3125a988416SJim Ingham { 3135a988416SJim Ingham out_stream->Printf ("Warning: No command attached to breakpoint.\n"); 3145a988416SJim Ingham out_stream->Flush(); 3155a988416SJim Ingham } 3165a988416SJim Ingham } 3175a988416SJim Ingham break; 3185a988416SJim Ingham 3195a988416SJim Ingham case eInputReaderEndOfFile: 3205a988416SJim Ingham reader.SetIsDone (true); 3215a988416SJim Ingham break; 3225a988416SJim Ingham 3235a988416SJim Ingham case eInputReaderDone: 3245a988416SJim Ingham break; 3255a988416SJim Ingham } 3265a988416SJim Ingham 3275a988416SJim Ingham return bytes_len; 3285a988416SJim Ingham } 3295a988416SJim Ingham 3305a988416SJim Ingham static bool 3315a988416SJim Ingham BreakpointOptionsCallbackFunction (void *baton, 3325a988416SJim Ingham StoppointCallbackContext *context, 3335a988416SJim Ingham lldb::user_id_t break_id, 3345a988416SJim Ingham lldb::user_id_t break_loc_id) 3355a988416SJim Ingham { 3365a988416SJim Ingham bool ret_value = true; 3375a988416SJim Ingham if (baton == NULL) 3385a988416SJim Ingham return true; 3395a988416SJim Ingham 3405a988416SJim Ingham 3415a988416SJim Ingham BreakpointOptions::CommandData *data = (BreakpointOptions::CommandData *) baton; 3425a988416SJim Ingham StringList &commands = data->user_source; 3435a988416SJim Ingham 3445a988416SJim Ingham if (commands.GetSize() > 0) 3455a988416SJim Ingham { 3465a988416SJim Ingham ExecutionContext exe_ctx (context->exe_ctx_ref); 3475a988416SJim Ingham Target *target = exe_ctx.GetTargetPtr(); 3485a988416SJim Ingham if (target) 3495a988416SJim Ingham { 3505a988416SJim Ingham CommandReturnObject result; 3515a988416SJim Ingham Debugger &debugger = target->GetDebugger(); 3525a988416SJim Ingham // Rig up the results secondary output stream to the debugger's, so the output will come out synchronously 3535a988416SJim Ingham // if the debugger is set up that way. 3545a988416SJim Ingham 3555a988416SJim Ingham StreamSP output_stream (debugger.GetAsyncOutputStream()); 3565a988416SJim Ingham StreamSP error_stream (debugger.GetAsyncErrorStream()); 3575a988416SJim Ingham result.SetImmediateOutputStream (output_stream); 3585a988416SJim Ingham result.SetImmediateErrorStream (error_stream); 3595a988416SJim Ingham 3605a988416SJim Ingham bool stop_on_continue = true; 3615a988416SJim Ingham bool echo_commands = false; 3625a988416SJim Ingham bool print_results = true; 3635a988416SJim Ingham 3645a988416SJim Ingham debugger.GetCommandInterpreter().HandleCommands (commands, 3655a988416SJim Ingham &exe_ctx, 3665a988416SJim Ingham stop_on_continue, 3675a988416SJim Ingham data->stop_on_error, 3685a988416SJim Ingham echo_commands, 3695a988416SJim Ingham print_results, 3705a988416SJim Ingham eLazyBoolNo, 3715a988416SJim Ingham result); 3725a988416SJim Ingham result.GetImmediateOutputStream()->Flush(); 3735a988416SJim Ingham result.GetImmediateErrorStream()->Flush(); 3745a988416SJim Ingham } 3755a988416SJim Ingham } 3765a988416SJim Ingham return ret_value; 3775a988416SJim Ingham } 3785a988416SJim Ingham 3795a988416SJim Ingham class CommandOptions : public Options 3805a988416SJim Ingham { 3815a988416SJim Ingham public: 3825a988416SJim Ingham 3835a988416SJim Ingham CommandOptions (CommandInterpreter &interpreter) : 3845a988416SJim Ingham Options (interpreter), 3855a988416SJim Ingham m_use_commands (false), 3865a988416SJim Ingham m_use_script_language (false), 3875a988416SJim Ingham m_script_language (eScriptLanguageNone), 3885a988416SJim Ingham m_use_one_liner (false), 3895a988416SJim Ingham m_one_liner(), 3905a988416SJim Ingham m_function_name() 39130fdc8d8SChris Lattner { 39230fdc8d8SChris Lattner } 39330fdc8d8SChris Lattner 3945a988416SJim Ingham virtual 3955a988416SJim Ingham ~CommandOptions () {} 3965a988416SJim Ingham 3975a988416SJim Ingham virtual Error 3985a988416SJim Ingham SetOptionValue (uint32_t option_idx, const char *option_arg) 3995a988416SJim Ingham { 4005a988416SJim Ingham Error error; 4015a988416SJim Ingham char short_option = (char) m_getopt_table[option_idx].val; 4025a988416SJim Ingham 4035a988416SJim Ingham switch (short_option) 4045a988416SJim Ingham { 4055a988416SJim Ingham case 'o': 4065a988416SJim Ingham m_use_one_liner = true; 4075a988416SJim Ingham m_one_liner = option_arg; 4085a988416SJim Ingham break; 4095a988416SJim Ingham 4105a988416SJim Ingham case 's': 4115a988416SJim Ingham m_script_language = (lldb::ScriptLanguage) Args::StringToOptionEnum (option_arg, 4125a988416SJim Ingham g_option_table[option_idx].enum_values, 4135a988416SJim Ingham eScriptLanguageNone, 4145a988416SJim Ingham error); 4155a988416SJim Ingham 4165a988416SJim Ingham if (m_script_language == eScriptLanguagePython || m_script_language == eScriptLanguageDefault) 4175a988416SJim Ingham { 4185a988416SJim Ingham m_use_script_language = true; 4195a988416SJim Ingham } 4205a988416SJim Ingham else 4215a988416SJim Ingham { 4225a988416SJim Ingham m_use_script_language = false; 4235a988416SJim Ingham } 4245a988416SJim Ingham break; 4255a988416SJim Ingham 4265a988416SJim Ingham case 'e': 4275a988416SJim Ingham { 4285a988416SJim Ingham bool success = false; 4295a988416SJim Ingham m_stop_on_error = Args::StringToBoolean(option_arg, false, &success); 4305a988416SJim Ingham if (!success) 4315a988416SJim Ingham error.SetErrorStringWithFormat("invalid value for stop-on-error: \"%s\"", option_arg); 4325a988416SJim Ingham } 4335a988416SJim Ingham break; 4345a988416SJim Ingham 4355a988416SJim Ingham case 'F': 4365a988416SJim Ingham { 4375a988416SJim Ingham m_use_one_liner = false; 4385a988416SJim Ingham m_use_script_language = true; 4395a988416SJim Ingham m_function_name.assign(option_arg); 4405a988416SJim Ingham } 4415a988416SJim Ingham break; 4425a988416SJim Ingham 4435a988416SJim Ingham default: 4445a988416SJim Ingham break; 4455a988416SJim Ingham } 4465a988416SJim Ingham return error; 4475a988416SJim Ingham } 4485a988416SJim Ingham void 4495a988416SJim Ingham OptionParsingStarting () 4505a988416SJim Ingham { 4515a988416SJim Ingham m_use_commands = true; 4525a988416SJim Ingham m_use_script_language = false; 4535a988416SJim Ingham m_script_language = eScriptLanguageNone; 4545a988416SJim Ingham 4555a988416SJim Ingham m_use_one_liner = false; 4565a988416SJim Ingham m_stop_on_error = true; 4575a988416SJim Ingham m_one_liner.clear(); 4585a988416SJim Ingham m_function_name.clear(); 4595a988416SJim Ingham } 4605a988416SJim Ingham 4615a988416SJim Ingham const OptionDefinition* 4625a988416SJim Ingham GetDefinitions () 4635a988416SJim Ingham { 4645a988416SJim Ingham return g_option_table; 4655a988416SJim Ingham } 4665a988416SJim Ingham 4675a988416SJim Ingham // Options table: Required for subclasses of Options. 4685a988416SJim Ingham 4695a988416SJim Ingham static OptionDefinition g_option_table[]; 4705a988416SJim Ingham 4715a988416SJim Ingham // Instance variables to hold the values for command options. 4725a988416SJim Ingham 4735a988416SJim Ingham bool m_use_commands; 4745a988416SJim Ingham bool m_use_script_language; 4755a988416SJim Ingham lldb::ScriptLanguage m_script_language; 4765a988416SJim Ingham 4775a988416SJim Ingham // Instance variables to hold the values for one_liner options. 4785a988416SJim Ingham bool m_use_one_liner; 4795a988416SJim Ingham std::string m_one_liner; 4805a988416SJim Ingham bool m_stop_on_error; 4815a988416SJim Ingham std::string m_function_name; 4825a988416SJim Ingham }; 4835a988416SJim Ingham 4845a988416SJim Ingham protected: 4855a988416SJim Ingham virtual bool 4865a988416SJim Ingham DoExecute (Args& command, CommandReturnObject &result) 48730fdc8d8SChris Lattner { 488a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 48930fdc8d8SChris Lattner 49030fdc8d8SChris Lattner if (target == NULL) 49130fdc8d8SChris Lattner { 49230fdc8d8SChris Lattner result.AppendError ("There is not a current executable; there are no breakpoints to which to add commands"); 49330fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 49430fdc8d8SChris Lattner return false; 49530fdc8d8SChris Lattner } 49630fdc8d8SChris Lattner 49730fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 49830fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 49930fdc8d8SChris Lattner 50030fdc8d8SChris Lattner if (num_breakpoints == 0) 50130fdc8d8SChris Lattner { 50230fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to have commands added"); 50330fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 50430fdc8d8SChris Lattner return false; 50530fdc8d8SChris Lattner } 50630fdc8d8SChris Lattner 5078d4a8010SEnrico Granata if (m_options.m_use_script_language == false && m_options.m_function_name.size()) 5088d4a8010SEnrico Granata { 5098d4a8010SEnrico Granata result.AppendError ("need to enable scripting to have a function run as a breakpoint command"); 5108d4a8010SEnrico Granata result.SetStatus (eReturnStatusFailed); 5118d4a8010SEnrico Granata return false; 5128d4a8010SEnrico Granata } 5138d4a8010SEnrico Granata 51430fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 51530fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 51630fdc8d8SChris Lattner 51730fdc8d8SChris Lattner if (result.Succeeded()) 51830fdc8d8SChris Lattner { 519c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 520c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 52130fdc8d8SChris Lattner { 52230fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 52330fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 52430fdc8d8SChris Lattner { 52530fdc8d8SChris Lattner Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 52639d7d4f0SJohnny Chen BreakpointOptions *bp_options = NULL; 52739d7d4f0SJohnny Chen if (cur_bp_id.GetLocationID() == LLDB_INVALID_BREAK_ID) 52839d7d4f0SJohnny Chen { 52939d7d4f0SJohnny Chen // This breakpoint does not have an associated location. 53039d7d4f0SJohnny Chen bp_options = bp->GetOptions(); 53139d7d4f0SJohnny Chen } 53239d7d4f0SJohnny Chen else 53330fdc8d8SChris Lattner { 53430fdc8d8SChris Lattner BreakpointLocationSP bp_loc_sp(bp->FindLocationByID (cur_bp_id.GetLocationID())); 53539d7d4f0SJohnny Chen // This breakpoint does have an associated location. 53639d7d4f0SJohnny Chen // Get its breakpoint options. 53730fdc8d8SChris Lattner if (bp_loc_sp) 53839d7d4f0SJohnny Chen bp_options = bp_loc_sp->GetLocationOptions(); 53939d7d4f0SJohnny Chen } 54039d7d4f0SJohnny Chen 541e16c50a1SJim Ingham // Skip this breakpoint if bp_options is not good. 54239d7d4f0SJohnny Chen if (bp_options == NULL) continue; 54339d7d4f0SJohnny Chen 54439d7d4f0SJohnny Chen // If we are using script language, get the script interpreter 54539d7d4f0SJohnny Chen // in order to set or collect command callback. Otherwise, call 54639d7d4f0SJohnny Chen // the methods associated with this object. 54730fdc8d8SChris Lattner if (m_options.m_use_script_language) 54830fdc8d8SChris Lattner { 54939d7d4f0SJohnny Chen // Special handling for one-liner specified inline. 55039d7d4f0SJohnny Chen if (m_options.m_use_one_liner) 5518d4a8010SEnrico Granata { 552a7015092SGreg Clayton m_interpreter.GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options, 55339d7d4f0SJohnny Chen m_options.m_one_liner.c_str()); 5548d4a8010SEnrico Granata } 5558d4a8010SEnrico Granata // Special handling for using a Python function by name 5568d4a8010SEnrico Granata // instead of extending the breakpoint callback data structures, we just automatize 5578d4a8010SEnrico Granata // what the user would do manually: make their breakpoint command be a function call 5588d4a8010SEnrico Granata else if (m_options.m_function_name.size()) 5598d4a8010SEnrico Granata { 5608d4a8010SEnrico Granata std::string oneliner(m_options.m_function_name); 56140d55710SEnrico Granata oneliner += "(frame, bp_loc, internal_dict)"; 5628d4a8010SEnrico Granata m_interpreter.GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options, 5638d4a8010SEnrico Granata oneliner.c_str()); 5648d4a8010SEnrico Granata } 56594de55d5SJohnny Chen else 5668d4a8010SEnrico Granata { 567a7015092SGreg Clayton m_interpreter.GetScriptInterpreter()->CollectDataForBreakpointCommandCallback (bp_options, 56830fdc8d8SChris Lattner result); 56930fdc8d8SChris Lattner } 5708d4a8010SEnrico Granata } 57130fdc8d8SChris Lattner else 57230fdc8d8SChris Lattner { 57339d7d4f0SJohnny Chen // Special handling for one-liner specified inline. 57439d7d4f0SJohnny Chen if (m_options.m_use_one_liner) 575a7015092SGreg Clayton SetBreakpointCommandCallback (bp_options, 57639d7d4f0SJohnny Chen m_options.m_one_liner.c_str()); 57739d7d4f0SJohnny Chen else 578a7015092SGreg Clayton CollectDataForBreakpointCommandCallback (bp_options, 579b132097bSGreg Clayton result); 58030fdc8d8SChris Lattner } 58130fdc8d8SChris Lattner } 58230fdc8d8SChris Lattner } 58330fdc8d8SChris Lattner } 58430fdc8d8SChris Lattner 58530fdc8d8SChris Lattner return result.Succeeded(); 58630fdc8d8SChris Lattner } 58730fdc8d8SChris Lattner 5885a988416SJim Ingham private: 5895a988416SJim Ingham CommandOptions m_options; 5905a988416SJim Ingham static const char *g_reader_instructions; 5915a988416SJim Ingham 5925a988416SJim Ingham }; 5935a988416SJim Ingham 5945a988416SJim Ingham const char * 5955a988416SJim Ingham CommandObjectBreakpointCommandAdd::g_reader_instructions = "Enter your debugger command(s). Type 'DONE' to end."; 5965a988416SJim Ingham 5975a988416SJim Ingham // FIXME: "script-type" needs to have its contents determined dynamically, so somebody can add a new scripting 5985a988416SJim Ingham // language to lldb and have it pickable here without having to change this enumeration by hand and rebuild lldb proper. 5995a988416SJim Ingham 6005a988416SJim Ingham static OptionEnumValueElement 6015a988416SJim Ingham g_script_option_enumeration[4] = 60230fdc8d8SChris Lattner { 6035a988416SJim Ingham { eScriptLanguageNone, "command", "Commands are in the lldb command interpreter language"}, 6045a988416SJim Ingham { eScriptLanguagePython, "python", "Commands are in the Python language."}, 6055a988416SJim Ingham { eSortOrderByName, "default-script", "Commands are in the default scripting language."}, 6065a988416SJim Ingham { 0, NULL, NULL } 6075a988416SJim Ingham }; 60830fdc8d8SChris Lattner 6095a988416SJim Ingham OptionDefinition 6105a988416SJim Ingham CommandObjectBreakpointCommandAdd::CommandOptions::g_option_table[] = 61130fdc8d8SChris Lattner { 612*bc6e85cbSFilipe Cabecinhas { LLDB_OPT_SET_1, false, "one-liner", 'o', required_argument, NULL, 0, eArgTypeOneLiner, 6135a988416SJim Ingham "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." }, 61430fdc8d8SChris Lattner 615*bc6e85cbSFilipe Cabecinhas { LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', required_argument, NULL, 0, eArgTypeBoolean, 6165a988416SJim Ingham "Specify whether breakpoint command execution should terminate on error." }, 61730fdc8d8SChris Lattner 618*bc6e85cbSFilipe Cabecinhas { LLDB_OPT_SET_ALL, false, "script-type", 's', required_argument, g_script_option_enumeration, 0, eArgTypeNone, 6195a988416SJim Ingham "Specify the language for the commands - if none is specified, the lldb command interpreter will be used."}, 62030fdc8d8SChris Lattner 621*bc6e85cbSFilipe Cabecinhas { LLDB_OPT_SET_2, false, "python-function", 'F', required_argument, NULL, 0, eArgTypePythonFunction, 6225a988416SJim Ingham "Give the name of a Python function to run as command for this breakpoint. Be sure to give a module name if appropriate."}, 62339d7d4f0SJohnny Chen 6245a988416SJim Ingham { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 6255a988416SJim Ingham }; 62630fdc8d8SChris Lattner 62730fdc8d8SChris Lattner //------------------------------------------------------------------------- 62893e0f19fSCaroline Tice // CommandObjectBreakpointCommandDelete 62930fdc8d8SChris Lattner //------------------------------------------------------------------------- 63030fdc8d8SChris Lattner 6315a988416SJim Ingham class CommandObjectBreakpointCommandDelete : public CommandObjectParsed 6325a988416SJim Ingham { 6335a988416SJim Ingham public: 6345a988416SJim Ingham CommandObjectBreakpointCommandDelete (CommandInterpreter &interpreter) : 6355a988416SJim Ingham CommandObjectParsed (interpreter, 63693e0f19fSCaroline Tice "delete", 63793e0f19fSCaroline Tice "Delete the set of commands from a breakpoint.", 638405fe67fSCaroline Tice NULL) 63930fdc8d8SChris Lattner { 640405fe67fSCaroline Tice CommandArgumentEntry arg; 641405fe67fSCaroline Tice CommandArgumentData bp_id_arg; 642405fe67fSCaroline Tice 643405fe67fSCaroline Tice // Define the first (and only) variant of this arg. 644405fe67fSCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 645405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatPlain; 646405fe67fSCaroline Tice 647405fe67fSCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 648405fe67fSCaroline Tice arg.push_back (bp_id_arg); 649405fe67fSCaroline Tice 650405fe67fSCaroline Tice // Push the data for the first argument into the m_arguments vector. 651405fe67fSCaroline Tice m_arguments.push_back (arg); 65230fdc8d8SChris Lattner } 65330fdc8d8SChris Lattner 65430fdc8d8SChris Lattner 6555a988416SJim Ingham virtual 6565a988416SJim Ingham ~CommandObjectBreakpointCommandDelete () {} 6575a988416SJim Ingham 6585a988416SJim Ingham protected: 6595a988416SJim Ingham virtual bool 6605a988416SJim Ingham DoExecute (Args& command, CommandReturnObject &result) 66130fdc8d8SChris Lattner { 662a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 66330fdc8d8SChris Lattner 66430fdc8d8SChris Lattner if (target == NULL) 66530fdc8d8SChris Lattner { 66693e0f19fSCaroline Tice result.AppendError ("There is not a current executable; there are no breakpoints from which to delete commands"); 66730fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 66830fdc8d8SChris Lattner return false; 66930fdc8d8SChris Lattner } 67030fdc8d8SChris Lattner 67130fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 67230fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 67330fdc8d8SChris Lattner 67430fdc8d8SChris Lattner if (num_breakpoints == 0) 67530fdc8d8SChris Lattner { 67693e0f19fSCaroline Tice result.AppendError ("No breakpoints exist to have commands deleted"); 67730fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 67830fdc8d8SChris Lattner return false; 67930fdc8d8SChris Lattner } 68030fdc8d8SChris Lattner 68130fdc8d8SChris Lattner if (command.GetArgumentCount() == 0) 68230fdc8d8SChris Lattner { 68393e0f19fSCaroline Tice result.AppendError ("No breakpoint specified from which to delete the commands"); 68430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 68530fdc8d8SChris Lattner return false; 68630fdc8d8SChris Lattner } 68730fdc8d8SChris Lattner 68830fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 68930fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 69030fdc8d8SChris Lattner 69130fdc8d8SChris Lattner if (result.Succeeded()) 69230fdc8d8SChris Lattner { 693c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 694c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 69530fdc8d8SChris Lattner { 69630fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 69730fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 69830fdc8d8SChris Lattner { 69930fdc8d8SChris Lattner Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 70030fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 70130fdc8d8SChris Lattner { 70230fdc8d8SChris Lattner BreakpointLocationSP bp_loc_sp (bp->FindLocationByID (cur_bp_id.GetLocationID())); 70330fdc8d8SChris Lattner if (bp_loc_sp) 70430fdc8d8SChris Lattner bp_loc_sp->ClearCallback(); 70530fdc8d8SChris Lattner else 70630fdc8d8SChris Lattner { 70730fdc8d8SChris Lattner result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n", 70830fdc8d8SChris Lattner cur_bp_id.GetBreakpointID(), 70930fdc8d8SChris Lattner cur_bp_id.GetLocationID()); 71030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 71130fdc8d8SChris Lattner return false; 71230fdc8d8SChris Lattner } 71330fdc8d8SChris Lattner } 71430fdc8d8SChris Lattner else 71530fdc8d8SChris Lattner { 71630fdc8d8SChris Lattner bp->ClearCallback(); 71730fdc8d8SChris Lattner } 71830fdc8d8SChris Lattner } 71930fdc8d8SChris Lattner } 72030fdc8d8SChris Lattner } 72130fdc8d8SChris Lattner return result.Succeeded(); 72230fdc8d8SChris Lattner } 7235a988416SJim Ingham }; 72430fdc8d8SChris Lattner 72530fdc8d8SChris Lattner //------------------------------------------------------------------------- 72630fdc8d8SChris Lattner // CommandObjectBreakpointCommandList 72730fdc8d8SChris Lattner //------------------------------------------------------------------------- 72830fdc8d8SChris Lattner 7295a988416SJim Ingham class CommandObjectBreakpointCommandList : public CommandObjectParsed 7305a988416SJim Ingham { 7315a988416SJim Ingham public: 7325a988416SJim Ingham CommandObjectBreakpointCommandList (CommandInterpreter &interpreter) : 7335a988416SJim Ingham CommandObjectParsed (interpreter, 734a7015092SGreg Clayton "list", 73530fdc8d8SChris Lattner "List the script or set of commands to be executed when the breakpoint is hit.", 736405fe67fSCaroline Tice NULL) 73730fdc8d8SChris Lattner { 738405fe67fSCaroline Tice CommandArgumentEntry arg; 739405fe67fSCaroline Tice CommandArgumentData bp_id_arg; 740405fe67fSCaroline Tice 741405fe67fSCaroline Tice // Define the first (and only) variant of this arg. 742405fe67fSCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 743405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatPlain; 744405fe67fSCaroline Tice 745405fe67fSCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 746405fe67fSCaroline Tice arg.push_back (bp_id_arg); 747405fe67fSCaroline Tice 748405fe67fSCaroline Tice // Push the data for the first argument into the m_arguments vector. 749405fe67fSCaroline Tice m_arguments.push_back (arg); 75030fdc8d8SChris Lattner } 75130fdc8d8SChris Lattner 7525a988416SJim Ingham virtual 7535a988416SJim Ingham ~CommandObjectBreakpointCommandList () {} 75430fdc8d8SChris Lattner 7555a988416SJim Ingham protected: 7565a988416SJim Ingham virtual bool 7575a988416SJim Ingham DoExecute (Args& command, 7585a988416SJim Ingham CommandReturnObject &result) 75930fdc8d8SChris Lattner { 760a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 76130fdc8d8SChris Lattner 76230fdc8d8SChris Lattner if (target == NULL) 76330fdc8d8SChris Lattner { 76430fdc8d8SChris Lattner result.AppendError ("There is not a current executable; there are no breakpoints for which to list commands"); 76530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 76630fdc8d8SChris Lattner return false; 76730fdc8d8SChris Lattner } 76830fdc8d8SChris Lattner 76930fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 77030fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 77130fdc8d8SChris Lattner 77230fdc8d8SChris Lattner if (num_breakpoints == 0) 77330fdc8d8SChris Lattner { 77430fdc8d8SChris Lattner result.AppendError ("No breakpoints exist for which to list commands"); 77530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 77630fdc8d8SChris Lattner return false; 77730fdc8d8SChris Lattner } 77830fdc8d8SChris Lattner 77930fdc8d8SChris Lattner if (command.GetArgumentCount() == 0) 78030fdc8d8SChris Lattner { 78130fdc8d8SChris Lattner result.AppendError ("No breakpoint specified for which to list the commands"); 78230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 78330fdc8d8SChris Lattner return false; 78430fdc8d8SChris Lattner } 78530fdc8d8SChris Lattner 78630fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 78730fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 78830fdc8d8SChris Lattner 78930fdc8d8SChris Lattner if (result.Succeeded()) 79030fdc8d8SChris Lattner { 791c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 792c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 79330fdc8d8SChris Lattner { 79430fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 79530fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 79630fdc8d8SChris Lattner { 79730fdc8d8SChris Lattner Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 79830fdc8d8SChris Lattner 79930fdc8d8SChris Lattner if (bp) 80030fdc8d8SChris Lattner { 8011b54c88cSJim Ingham const BreakpointOptions *bp_options = NULL; 80230fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 80330fdc8d8SChris Lattner { 80430fdc8d8SChris Lattner BreakpointLocationSP bp_loc_sp(bp->FindLocationByID (cur_bp_id.GetLocationID())); 80530fdc8d8SChris Lattner if (bp_loc_sp) 80605407f6bSJim Ingham bp_options = bp_loc_sp->GetOptionsNoCreate(); 80730fdc8d8SChris Lattner else 80830fdc8d8SChris Lattner { 80930fdc8d8SChris Lattner result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n", 81030fdc8d8SChris Lattner cur_bp_id.GetBreakpointID(), 81130fdc8d8SChris Lattner cur_bp_id.GetLocationID()); 81230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 81330fdc8d8SChris Lattner return false; 81430fdc8d8SChris Lattner } 81530fdc8d8SChris Lattner } 81630fdc8d8SChris Lattner else 81730fdc8d8SChris Lattner { 81830fdc8d8SChris Lattner bp_options = bp->GetOptions(); 81930fdc8d8SChris Lattner } 82030fdc8d8SChris Lattner 82130fdc8d8SChris Lattner if (bp_options) 82230fdc8d8SChris Lattner { 82330fdc8d8SChris Lattner StreamString id_str; 824e16c50a1SJim Ingham BreakpointID::GetCanonicalReference (&id_str, 825e16c50a1SJim Ingham cur_bp_id.GetBreakpointID(), 826e16c50a1SJim Ingham cur_bp_id.GetLocationID()); 8271b54c88cSJim Ingham const Baton *baton = bp_options->GetBaton(); 82830fdc8d8SChris Lattner if (baton) 82930fdc8d8SChris Lattner { 83030fdc8d8SChris Lattner result.GetOutputStream().Printf ("Breakpoint %s:\n", id_str.GetData()); 83130fdc8d8SChris Lattner result.GetOutputStream().IndentMore (); 83230fdc8d8SChris Lattner baton->GetDescription(&result.GetOutputStream(), eDescriptionLevelFull); 83330fdc8d8SChris Lattner result.GetOutputStream().IndentLess (); 83430fdc8d8SChris Lattner } 83530fdc8d8SChris Lattner else 83630fdc8d8SChris Lattner { 837e16c50a1SJim Ingham result.AppendMessageWithFormat ("Breakpoint %s does not have an associated command.\n", 838e16c50a1SJim Ingham id_str.GetData()); 83930fdc8d8SChris Lattner } 84030fdc8d8SChris Lattner } 84130fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 84230fdc8d8SChris Lattner } 84330fdc8d8SChris Lattner else 84430fdc8d8SChris Lattner { 84530fdc8d8SChris Lattner result.AppendErrorWithFormat("Invalid breakpoint ID: %u.\n", cur_bp_id.GetBreakpointID()); 84630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 84730fdc8d8SChris Lattner } 84830fdc8d8SChris Lattner 84930fdc8d8SChris Lattner } 85030fdc8d8SChris Lattner } 85130fdc8d8SChris Lattner } 85230fdc8d8SChris Lattner 85330fdc8d8SChris Lattner return result.Succeeded(); 85430fdc8d8SChris Lattner } 8555a988416SJim Ingham }; 85630fdc8d8SChris Lattner 85730fdc8d8SChris Lattner //------------------------------------------------------------------------- 85830fdc8d8SChris Lattner // CommandObjectBreakpointCommand 85930fdc8d8SChris Lattner //------------------------------------------------------------------------- 86030fdc8d8SChris Lattner 8616611103cSGreg Clayton CommandObjectBreakpointCommand::CommandObjectBreakpointCommand (CommandInterpreter &interpreter) : 862a7015092SGreg Clayton CommandObjectMultiword (interpreter, 863a7015092SGreg Clayton "command", 86430fdc8d8SChris Lattner "A set of commands for adding, removing and examining bits of code to be executed when the breakpoint is hit (breakpoint 'commmands').", 86530fdc8d8SChris Lattner "command <sub-command> [<sub-command-options>] <breakpoint-id>") 86630fdc8d8SChris Lattner { 867a7015092SGreg Clayton CommandObjectSP add_command_object (new CommandObjectBreakpointCommandAdd (interpreter)); 86893e0f19fSCaroline Tice CommandObjectSP delete_command_object (new CommandObjectBreakpointCommandDelete (interpreter)); 869a7015092SGreg Clayton CommandObjectSP list_command_object (new CommandObjectBreakpointCommandList (interpreter)); 87030fdc8d8SChris Lattner 87130fdc8d8SChris Lattner add_command_object->SetCommandName ("breakpoint command add"); 87293e0f19fSCaroline Tice delete_command_object->SetCommandName ("breakpoint command delete"); 87330fdc8d8SChris Lattner list_command_object->SetCommandName ("breakpoint command list"); 87430fdc8d8SChris Lattner 87523f59509SGreg Clayton LoadSubCommand ("add", add_command_object); 87623f59509SGreg Clayton LoadSubCommand ("delete", delete_command_object); 87723f59509SGreg Clayton LoadSubCommand ("list", list_command_object); 87830fdc8d8SChris Lattner } 87930fdc8d8SChris Lattner 88030fdc8d8SChris Lattner CommandObjectBreakpointCommand::~CommandObjectBreakpointCommand () 88130fdc8d8SChris Lattner { 88230fdc8d8SChris Lattner } 88330fdc8d8SChris Lattner 88430fdc8d8SChris Lattner 885