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
12c8ecc2a9SEugene Zelenko // Other libraries and framework includes
13c8ecc2a9SEugene Zelenko // Project includes
1430fdc8d8SChris Lattner #include "CommandObjectBreakpointCommand.h"
1530fdc8d8SChris Lattner #include "CommandObjectBreakpoint.h"
16b9c1b51eSKate Stone #include "lldb/Breakpoint/Breakpoint.h"
17b9c1b51eSKate Stone #include "lldb/Breakpoint/BreakpointIDList.h"
18b9c1b51eSKate Stone #include "lldb/Breakpoint/BreakpointLocation.h"
19b9c1b51eSKate Stone #include "lldb/Breakpoint/StoppointCallbackContext.h"
2044d93782SGreg Clayton #include "lldb/Core/IOHandler.h"
21b9c1b51eSKate Stone #include "lldb/Core/State.h"
2230fdc8d8SChris Lattner #include "lldb/Interpreter/CommandInterpreter.h"
2330fdc8d8SChris Lattner #include "lldb/Interpreter/CommandReturnObject.h"
2430fdc8d8SChris Lattner #include "lldb/Target/Target.h"
2530fdc8d8SChris Lattner #include "lldb/Target/Thread.h"
2630fdc8d8SChris Lattner 
274e4fbe82SZachary Turner #include "llvm/ADT/STLExtras.h"
284e4fbe82SZachary Turner 
2930fdc8d8SChris Lattner using namespace lldb;
3030fdc8d8SChris Lattner using namespace lldb_private;
3130fdc8d8SChris Lattner 
3230fdc8d8SChris Lattner //-------------------------------------------------------------------------
3330fdc8d8SChris Lattner // CommandObjectBreakpointCommandAdd
3430fdc8d8SChris Lattner //-------------------------------------------------------------------------
3530fdc8d8SChris Lattner 
361f0f5b5bSZachary Turner // FIXME: "script-type" needs to have its contents determined dynamically, so
371f0f5b5bSZachary Turner // somebody can add a new scripting
381f0f5b5bSZachary Turner // language to lldb and have it pickable here without having to change this
391f0f5b5bSZachary Turner // enumeration by hand and rebuild lldb proper.
401f0f5b5bSZachary Turner 
411f0f5b5bSZachary Turner static OptionEnumValueElement g_script_option_enumeration[4] = {
421f0f5b5bSZachary Turner     {eScriptLanguageNone, "command",
431f0f5b5bSZachary Turner      "Commands are in the lldb command interpreter language"},
441f0f5b5bSZachary Turner     {eScriptLanguagePython, "python", "Commands are in the Python language."},
451f0f5b5bSZachary Turner     {eSortOrderByName, "default-script",
461f0f5b5bSZachary Turner      "Commands are in the default scripting language."},
471f0f5b5bSZachary Turner     {0, nullptr, nullptr}};
481f0f5b5bSZachary Turner 
491f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_add_options[] = {
501f0f5b5bSZachary Turner     // clang-format off
511f0f5b5bSZachary Turner   { LLDB_OPT_SET_1,   false, "one-liner",         'o', OptionParser::eRequiredArgument, nullptr, nullptr,                     0, eArgTypeOneLiner,       "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." },
521f0f5b5bSZachary Turner   { LLDB_OPT_SET_ALL, false, "stop-on-error",     'e', OptionParser::eRequiredArgument, nullptr, nullptr,                     0, eArgTypeBoolean,        "Specify whether breakpoint command execution should terminate on error." },
531f0f5b5bSZachary Turner   { LLDB_OPT_SET_ALL, false, "script-type",       's', OptionParser::eRequiredArgument, nullptr, g_script_option_enumeration, 0, eArgTypeNone,           "Specify the language for the commands - if none is specified, the lldb command interpreter will be used." },
541f0f5b5bSZachary Turner   { LLDB_OPT_SET_2,   false, "python-function",   'F', OptionParser::eRequiredArgument, nullptr, nullptr,                     0, eArgTypePythonFunction, "Give the name of a Python function to run as command for this breakpoint. Be sure to give a module name if appropriate." },
551f0f5b5bSZachary Turner   { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument,       nullptr, nullptr,                     0, eArgTypeNone,           "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets." },
561f0f5b5bSZachary Turner     // clang-format on
571f0f5b5bSZachary Turner };
581f0f5b5bSZachary Turner 
59b9c1b51eSKate Stone class CommandObjectBreakpointCommandAdd : public CommandObjectParsed,
60b9c1b51eSKate Stone                                           public IOHandlerDelegateMultiline {
615a988416SJim Ingham public:
627428a18cSKate Stone   CommandObjectBreakpointCommandAdd(CommandInterpreter &interpreter)
637428a18cSKate Stone       : CommandObjectParsed(interpreter, "add",
64b9c1b51eSKate Stone                             "Add LLDB commands to a breakpoint, to be executed "
65b9c1b51eSKate Stone                             "whenever the breakpoint is hit."
66b9c1b51eSKate Stone                             "  If no breakpoint is specified, adds the "
67b9c1b51eSKate Stone                             "commands to the last created breakpoint.",
68c8ecc2a9SEugene Zelenko                             nullptr),
69b9c1b51eSKate Stone         IOHandlerDelegateMultiline("DONE",
70b9c1b51eSKate Stone                                    IOHandlerDelegate::Completion::LLDBCommand),
71b9c1b51eSKate Stone         m_options() {
7230fdc8d8SChris Lattner     SetHelpLong(
73ea671fbdSKate Stone         R"(
74ea671fbdSKate Stone General information about entering breakpoint commands
75ea671fbdSKate Stone ------------------------------------------------------
76ea671fbdSKate Stone 
77b9c1b51eSKate Stone )"
78b9c1b51eSKate Stone         "This command will prompt for commands to be executed when the specified \
79ea671fbdSKate Stone breakpoint is hit.  Each command is typed on its own line following the '> ' \
80b9c1b51eSKate Stone prompt until 'DONE' is entered."
81b9c1b51eSKate Stone         R"(
82ea671fbdSKate Stone 
83b9c1b51eSKate Stone )"
84b9c1b51eSKate Stone         "Syntactic errors may not be detected when initially entered, and many \
85ea671fbdSKate Stone malformed commands can silently fail when executed.  If your breakpoint commands \
86b9c1b51eSKate Stone do not appear to be executing, double-check the command syntax."
87b9c1b51eSKate Stone         R"(
88ea671fbdSKate Stone 
89b9c1b51eSKate Stone )"
90b9c1b51eSKate Stone         "Note: You may enter any debugger command exactly as you would at the debugger \
91ea671fbdSKate Stone prompt.  There is no limit to the number of commands supplied, but do NOT enter \
92b9c1b51eSKate Stone more than one command per line."
93b9c1b51eSKate Stone         R"(
94ea671fbdSKate Stone 
95ea671fbdSKate Stone Special information about PYTHON breakpoint commands
96ea671fbdSKate Stone ----------------------------------------------------
97ea671fbdSKate Stone 
98b9c1b51eSKate Stone )"
99b9c1b51eSKate Stone         "You may enter either one or more lines of Python, including function \
100ea671fbdSKate Stone definitions or calls to functions that will have been imported by the time \
101ea671fbdSKate Stone the code executes.  Single line breakpoint commands will be interpreted 'as is' \
102ea671fbdSKate Stone when the breakpoint is hit.  Multiple lines of Python will be wrapped in a \
103b9c1b51eSKate Stone generated function, and a call to the function will be attached to the breakpoint."
104b9c1b51eSKate Stone         R"(
105ea671fbdSKate Stone 
106ea671fbdSKate Stone This auto-generated function is passed in three arguments:
107ea671fbdSKate Stone 
108ea671fbdSKate Stone     frame:  an lldb.SBFrame object for the frame which hit breakpoint.
109ea671fbdSKate Stone 
110ea671fbdSKate Stone     bp_loc: an lldb.SBBreakpointLocation object that represents the breakpoint location that was hit.
111ea671fbdSKate Stone 
112ea671fbdSKate Stone     dict:   the python session dictionary hit.
113ea671fbdSKate Stone 
114b9c1b51eSKate Stone )"
115b9c1b51eSKate Stone         "When specifying a python function with the --python-function option, you need \
116b9c1b51eSKate Stone to supply the function name prepended by the module name:"
117b9c1b51eSKate Stone         R"(
118ea671fbdSKate Stone 
119ea671fbdSKate Stone     --python-function myutils.breakpoint_callback
120ea671fbdSKate Stone 
121ea671fbdSKate Stone The function itself must have the following prototype:
122ea671fbdSKate Stone 
123ea671fbdSKate Stone def breakpoint_callback(frame, bp_loc, dict):
124ea671fbdSKate Stone   # Your code goes here
125ea671fbdSKate Stone 
126b9c1b51eSKate Stone )"
127b9c1b51eSKate Stone         "The arguments are the same as the arguments passed to generated functions as \
128ea671fbdSKate Stone described above.  Note that the global variable 'lldb.frame' will NOT be updated when \
129ea671fbdSKate Stone this function is called, so be sure to use the 'frame' argument. The 'frame' argument \
130ea671fbdSKate Stone can get you to the thread via frame.GetThread(), the thread can get you to the \
131ea671fbdSKate Stone process via thread.GetProcess(), and the process can get you back to the target \
132b9c1b51eSKate Stone via process.GetTarget()."
133b9c1b51eSKate Stone         R"(
134ea671fbdSKate Stone 
135b9c1b51eSKate Stone )"
136b9c1b51eSKate Stone         "Important Note: As Python code gets collected into functions, access to global \
137ea671fbdSKate Stone variables requires explicit scoping using the 'global' keyword.  Be sure to use correct \
138b9c1b51eSKate Stone Python syntax, including indentation, when entering Python breakpoint commands."
139b9c1b51eSKate Stone         R"(
140ea671fbdSKate Stone 
141ea671fbdSKate Stone Example Python one-line breakpoint command:
142ea671fbdSKate Stone 
143ea671fbdSKate Stone (lldb) breakpoint command add -s python 1
144ea671fbdSKate Stone Enter your Python command(s). Type 'DONE' to end.
145ea671fbdSKate Stone > print "Hit this breakpoint!"
146ea671fbdSKate Stone > DONE
147ea671fbdSKate Stone 
148ea671fbdSKate Stone As a convenience, this also works for a short Python one-liner:
149ea671fbdSKate Stone 
150ea671fbdSKate Stone (lldb) breakpoint command add -s python 1 -o 'import time; print time.asctime()'
151ea671fbdSKate Stone (lldb) run
152ea671fbdSKate Stone Launching '.../a.out'  (x86_64)
153ea671fbdSKate Stone (lldb) Fri Sep 10 12:17:45 2010
154ea671fbdSKate Stone Process 21778 Stopped
155ea671fbdSKate Stone * thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread
156ea671fbdSKate Stone   36
157ea671fbdSKate Stone   37   	int c(int val)
158ea671fbdSKate Stone   38   	{
159ea671fbdSKate Stone   39 ->	    return val + 3;
160ea671fbdSKate Stone   40   	}
161ea671fbdSKate Stone   41
162ea671fbdSKate Stone   42   	int main (int argc, char const *argv[])
163ea671fbdSKate Stone 
164ea671fbdSKate Stone Example multiple line Python breakpoint command:
165ea671fbdSKate Stone 
166ea671fbdSKate Stone (lldb) breakpoint command add -s p 1
167ea671fbdSKate Stone Enter your Python command(s). Type 'DONE' to end.
168ea671fbdSKate Stone > global bp_count
169ea671fbdSKate Stone > bp_count = bp_count + 1
170ea671fbdSKate Stone > print "Hit this breakpoint " + repr(bp_count) + " times!"
171ea671fbdSKate Stone > DONE
172ea671fbdSKate Stone 
173ea671fbdSKate Stone Example multiple line Python breakpoint command, using function definition:
174ea671fbdSKate Stone 
175ea671fbdSKate Stone (lldb) breakpoint command add -s python 1
176ea671fbdSKate Stone Enter your Python command(s). Type 'DONE' to end.
177ea671fbdSKate Stone > def breakpoint_output (bp_no):
178ea671fbdSKate Stone >     out_string = "Hit breakpoint number " + repr (bp_no)
179ea671fbdSKate Stone >     print out_string
180ea671fbdSKate Stone >     return True
181ea671fbdSKate Stone > breakpoint_output (1)
182ea671fbdSKate Stone > DONE
183ea671fbdSKate Stone 
184b9c1b51eSKate Stone )"
185b9c1b51eSKate Stone         "In this case, since there is a reference to a global variable, \
186ea671fbdSKate Stone 'bp_count', you will also need to make sure 'bp_count' exists and is \
187b9c1b51eSKate Stone initialized:"
188b9c1b51eSKate Stone         R"(
189ea671fbdSKate Stone 
190ea671fbdSKate Stone (lldb) script
191ea671fbdSKate Stone >>> bp_count = 0
192ea671fbdSKate Stone >>> quit()
193ea671fbdSKate Stone 
194b9c1b51eSKate Stone )"
195b9c1b51eSKate Stone         "Your Python code, however organized, can optionally return a value.  \
196ea671fbdSKate Stone If the returned value is False, that tells LLDB not to stop at the breakpoint \
197ea671fbdSKate Stone to which the code is associated. Returning anything other than False, or even \
198ea671fbdSKate Stone returning None, or even omitting a return statement entirely, will cause \
199b9c1b51eSKate Stone LLDB to stop."
200b9c1b51eSKate Stone         R"(
201ea671fbdSKate Stone 
202b9c1b51eSKate Stone )"
203b9c1b51eSKate Stone         "Final Note: A warning that no breakpoint command was generated when there \
204b9c1b51eSKate Stone are no syntax errors may indicate that a function was declared but never called.");
205405fe67fSCaroline Tice 
206405fe67fSCaroline Tice     CommandArgumentEntry arg;
207405fe67fSCaroline Tice     CommandArgumentData bp_id_arg;
208405fe67fSCaroline Tice 
209405fe67fSCaroline Tice     // Define the first (and only) variant of this arg.
210405fe67fSCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
2111bb0750bSJim Ingham     bp_id_arg.arg_repetition = eArgRepeatOptional;
212405fe67fSCaroline Tice 
213b9c1b51eSKate Stone     // There is only one variant this argument could be; put it into the
214b9c1b51eSKate Stone     // argument entry.
215405fe67fSCaroline Tice     arg.push_back(bp_id_arg);
216405fe67fSCaroline Tice 
217405fe67fSCaroline Tice     // Push the data for the first argument into the m_arguments vector.
218405fe67fSCaroline Tice     m_arguments.push_back(arg);
21930fdc8d8SChris Lattner   }
22030fdc8d8SChris Lattner 
221c8ecc2a9SEugene Zelenko   ~CommandObjectBreakpointCommandAdd() override = default;
2225a988416SJim Ingham 
223b9c1b51eSKate Stone   Options *GetOptions() override { return &m_options; }
2245a988416SJim Ingham 
225b9c1b51eSKate Stone   void IOHandlerActivated(IOHandler &io_handler) override {
22644d93782SGreg Clayton     StreamFileSP output_sp(io_handler.GetOutputStreamFile());
227b9c1b51eSKate Stone     if (output_sp) {
22844d93782SGreg Clayton       output_sp->PutCString(g_reader_instructions);
22944d93782SGreg Clayton       output_sp->Flush();
23044d93782SGreg Clayton     }
23144d93782SGreg Clayton   }
23244d93782SGreg Clayton 
233b9c1b51eSKate Stone   void IOHandlerInputComplete(IOHandler &io_handler,
234b9c1b51eSKate Stone                               std::string &line) override {
23544d93782SGreg Clayton     io_handler.SetIsDone(true);
23644d93782SGreg Clayton 
237b9c1b51eSKate Stone     std::vector<BreakpointOptions *> *bp_options_vec =
238b9c1b51eSKate Stone         (std::vector<BreakpointOptions *> *)io_handler.GetUserData();
239b9c1b51eSKate Stone     for (BreakpointOptions *bp_options : *bp_options_vec) {
240b5796cb4SJim Ingham       if (!bp_options)
241b5796cb4SJim Ingham         continue;
242b5796cb4SJim Ingham 
2434e4fbe82SZachary Turner       auto cmd_data = llvm::make_unique<BreakpointOptions::CommandData>();
244e14dc268SJim Ingham       cmd_data->user_source.SplitIntoLines(line.c_str(), line.size());
24592d1960eSJim Ingham       bp_options->SetCommandDataCallback(cmd_data);
24644d93782SGreg Clayton     }
24744d93782SGreg Clayton   }
24844d93782SGreg Clayton 
249b9c1b51eSKate Stone   void CollectDataForBreakpointCommandCallback(
250b9c1b51eSKate Stone       std::vector<BreakpointOptions *> &bp_options_vec,
251b9c1b51eSKate Stone       CommandReturnObject &result) {
252b9c1b51eSKate Stone     m_interpreter.GetLLDBCommandsFromIOHandler(
253b9c1b51eSKate Stone         "> ",             // Prompt
25444d93782SGreg Clayton         *this,            // IOHandlerDelegate
25544d93782SGreg Clayton         true,             // Run IOHandler in async mode
256b9c1b51eSKate Stone         &bp_options_vec); // Baton for the "io_handler" that will be passed back
257b9c1b51eSKate Stone                           // into our IOHandlerDelegate functions
2585a988416SJim Ingham   }
2595a988416SJim Ingham 
2605a988416SJim Ingham   /// Set a one-liner as the callback for the breakpoint.
2615a988416SJim Ingham   void
262b5796cb4SJim Ingham   SetBreakpointCommandCallback(std::vector<BreakpointOptions *> &bp_options_vec,
263b9c1b51eSKate Stone                                const char *oneliner) {
264b9c1b51eSKate Stone     for (auto bp_options : bp_options_vec) {
2654e4fbe82SZachary Turner       auto cmd_data = llvm::make_unique<BreakpointOptions::CommandData>();
2665a988416SJim Ingham 
267b9c1b51eSKate Stone       // It's necessary to set both user_source and script_source to the
268b9c1b51eSKate Stone       // oneliner.
269b9c1b51eSKate Stone       // The former is used to generate callback description (as in breakpoint
270b9c1b51eSKate Stone       // command list)
271b9c1b51eSKate Stone       // while the latter is used for Python to interpret during the actual
272b9c1b51eSKate Stone       // callback.
273e14dc268SJim Ingham       cmd_data->user_source.AppendString(oneliner);
274e14dc268SJim Ingham       cmd_data->script_source.assign(oneliner);
275e14dc268SJim Ingham       cmd_data->stop_on_error = m_options.m_stop_on_error;
2765a988416SJim Ingham 
27792d1960eSJim Ingham       bp_options->SetCommandDataCallback(cmd_data);
278b5796cb4SJim Ingham     }
2795a988416SJim Ingham   }
2805a988416SJim Ingham 
281b9c1b51eSKate Stone   class CommandOptions : public Options {
2825a988416SJim Ingham   public:
283b9c1b51eSKate Stone     CommandOptions()
284b9c1b51eSKate Stone         : Options(), m_use_commands(false), m_use_script_language(false),
285b9c1b51eSKate Stone           m_script_language(eScriptLanguageNone), m_use_one_liner(false),
286b9c1b51eSKate Stone           m_one_liner(), m_function_name() {}
28730fdc8d8SChris Lattner 
288c8ecc2a9SEugene Zelenko     ~CommandOptions() override = default;
2895a988416SJim Ingham 
290b9c1b51eSKate Stone     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
291b9c1b51eSKate Stone                          ExecutionContext *execution_context) override {
2925a988416SJim Ingham       Error error;
2933bcdfc0eSGreg Clayton       const int short_option = m_getopt_table[option_idx].val;
294ecbb0bb1SZachary Turner       auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg);
2955a988416SJim Ingham 
296b9c1b51eSKate Stone       switch (short_option) {
2975a988416SJim Ingham       case 'o':
2985a988416SJim Ingham         m_use_one_liner = true;
2995a988416SJim Ingham         m_one_liner = option_arg;
3005a988416SJim Ingham         break;
3015a988416SJim Ingham 
3025a988416SJim Ingham       case 's':
303b9c1b51eSKate Stone         m_script_language = (lldb::ScriptLanguage)Args::StringToOptionEnum(
304*8cef4b0bSZachary Turner             llvm::StringRef::withNullAsEmpty(option_arg),
305*8cef4b0bSZachary Turner             g_breakpoint_add_options[option_idx].enum_values,
306b9c1b51eSKate Stone             eScriptLanguageNone, error);
3075a988416SJim Ingham 
308b9c1b51eSKate Stone         if (m_script_language == eScriptLanguagePython ||
309b9c1b51eSKate Stone             m_script_language == eScriptLanguageDefault) {
3105a988416SJim Ingham           m_use_script_language = true;
311b9c1b51eSKate Stone         } else {
3125a988416SJim Ingham           m_use_script_language = false;
3135a988416SJim Ingham         }
3145a988416SJim Ingham         break;
3155a988416SJim Ingham 
316b9c1b51eSKate Stone       case 'e': {
3175a988416SJim Ingham         bool success = false;
318ecbb0bb1SZachary Turner         m_stop_on_error = Args::StringToBoolean(option_strref, false, &success);
3195a988416SJim Ingham         if (!success)
320b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
321b9c1b51eSKate Stone               "invalid value for stop-on-error: \"%s\"", option_arg);
322b9c1b51eSKate Stone       } break;
3235a988416SJim Ingham 
3245a988416SJim Ingham       case 'F':
3255a988416SJim Ingham         m_use_one_liner = false;
3265a988416SJim Ingham         m_use_script_language = true;
3275a988416SJim Ingham         m_function_name.assign(option_arg);
3285a988416SJim Ingham         break;
3295a988416SJim Ingham 
33033df7cd3SJim Ingham       case 'D':
33133df7cd3SJim Ingham         m_use_dummy = true;
33233df7cd3SJim Ingham         break;
33333df7cd3SJim Ingham 
3345a988416SJim Ingham       default:
3355a988416SJim Ingham         break;
3365a988416SJim Ingham       }
3375a988416SJim Ingham       return error;
3385a988416SJim Ingham     }
339c8ecc2a9SEugene Zelenko 
340b9c1b51eSKate Stone     void OptionParsingStarting(ExecutionContext *execution_context) override {
3415a988416SJim Ingham       m_use_commands = true;
3425a988416SJim Ingham       m_use_script_language = false;
3435a988416SJim Ingham       m_script_language = eScriptLanguageNone;
3445a988416SJim Ingham 
3455a988416SJim Ingham       m_use_one_liner = false;
3465a988416SJim Ingham       m_stop_on_error = true;
3475a988416SJim Ingham       m_one_liner.clear();
3485a988416SJim Ingham       m_function_name.clear();
34933df7cd3SJim Ingham       m_use_dummy = false;
3505a988416SJim Ingham     }
3515a988416SJim Ingham 
3521f0f5b5bSZachary Turner     llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
35370602439SZachary Turner       return llvm::makeArrayRef(g_breakpoint_add_options);
3541f0f5b5bSZachary Turner     }
3555a988416SJim Ingham 
3565a988416SJim Ingham     // Instance variables to hold the values for command options.
3575a988416SJim Ingham 
3585a988416SJim Ingham     bool m_use_commands;
3595a988416SJim Ingham     bool m_use_script_language;
3605a988416SJim Ingham     lldb::ScriptLanguage m_script_language;
3615a988416SJim Ingham 
3625a988416SJim Ingham     // Instance variables to hold the values for one_liner options.
3635a988416SJim Ingham     bool m_use_one_liner;
3645a988416SJim Ingham     std::string m_one_liner;
3655a988416SJim Ingham     bool m_stop_on_error;
3665a988416SJim Ingham     std::string m_function_name;
36733df7cd3SJim Ingham     bool m_use_dummy;
3685a988416SJim Ingham   };
3695a988416SJim Ingham 
3705a988416SJim Ingham protected:
371b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
37233df7cd3SJim Ingham     Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
37330fdc8d8SChris Lattner 
374b9c1b51eSKate Stone     if (target == nullptr) {
375b9c1b51eSKate Stone       result.AppendError("There is not a current executable; there are no "
376b9c1b51eSKate Stone                          "breakpoints to which to add commands");
37730fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
37830fdc8d8SChris Lattner       return false;
37930fdc8d8SChris Lattner     }
38030fdc8d8SChris Lattner 
38130fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
38230fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
38330fdc8d8SChris Lattner 
384b9c1b51eSKate Stone     if (num_breakpoints == 0) {
38530fdc8d8SChris Lattner       result.AppendError("No breakpoints exist to have commands added");
38630fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
38730fdc8d8SChris Lattner       return false;
38830fdc8d8SChris Lattner     }
38930fdc8d8SChris Lattner 
390b9c1b51eSKate Stone     if (!m_options.m_use_script_language &&
391b9c1b51eSKate Stone         !m_options.m_function_name.empty()) {
392b9c1b51eSKate Stone       result.AppendError("need to enable scripting to have a function run as a "
393b9c1b51eSKate Stone                          "breakpoint command");
3948d4a8010SEnrico Granata       result.SetStatus(eReturnStatusFailed);
3958d4a8010SEnrico Granata       return false;
3968d4a8010SEnrico Granata     }
3978d4a8010SEnrico Granata 
39830fdc8d8SChris Lattner     BreakpointIDList valid_bp_ids;
399b9c1b51eSKate Stone     CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
400b9c1b51eSKate Stone         command, target, result, &valid_bp_ids);
40130fdc8d8SChris Lattner 
402b5796cb4SJim Ingham     m_bp_options_vec.clear();
403b5796cb4SJim Ingham 
404b9c1b51eSKate Stone     if (result.Succeeded()) {
405c982c768SGreg Clayton       const size_t count = valid_bp_ids.GetSize();
406d9916eaeSJim Ingham 
407b9c1b51eSKate Stone       for (size_t i = 0; i < count; ++i) {
40830fdc8d8SChris Lattner         BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
409b9c1b51eSKate Stone         if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
410b9c1b51eSKate Stone           Breakpoint *bp =
411b9c1b51eSKate Stone               target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
412c8ecc2a9SEugene Zelenko           BreakpointOptions *bp_options = nullptr;
413b9c1b51eSKate Stone           if (cur_bp_id.GetLocationID() == LLDB_INVALID_BREAK_ID) {
41439d7d4f0SJohnny Chen             // This breakpoint does not have an associated location.
41539d7d4f0SJohnny Chen             bp_options = bp->GetOptions();
416b9c1b51eSKate Stone           } else {
417b9c1b51eSKate Stone             BreakpointLocationSP bp_loc_sp(
418b9c1b51eSKate Stone                 bp->FindLocationByID(cur_bp_id.GetLocationID()));
41939d7d4f0SJohnny Chen             // This breakpoint does have an associated location.
42039d7d4f0SJohnny Chen             // Get its breakpoint options.
42130fdc8d8SChris Lattner             if (bp_loc_sp)
42239d7d4f0SJohnny Chen               bp_options = bp_loc_sp->GetLocationOptions();
42339d7d4f0SJohnny Chen           }
424b5796cb4SJim Ingham           if (bp_options)
425b5796cb4SJim Ingham             m_bp_options_vec.push_back(bp_options);
426b5796cb4SJim Ingham         }
427b5796cb4SJim Ingham       }
42839d7d4f0SJohnny Chen 
42939d7d4f0SJohnny Chen       // If we are using script language, get the script interpreter
43039d7d4f0SJohnny Chen       // in order to set or collect command callback.  Otherwise, call
43139d7d4f0SJohnny Chen       // the methods associated with this object.
432b9c1b51eSKate Stone       if (m_options.m_use_script_language) {
433b5796cb4SJim Ingham         ScriptInterpreter *script_interp = m_interpreter.GetScriptInterpreter();
43439d7d4f0SJohnny Chen         // Special handling for one-liner specified inline.
435b9c1b51eSKate Stone         if (m_options.m_use_one_liner) {
436b9c1b51eSKate Stone           script_interp->SetBreakpointCommandCallback(
437b9c1b51eSKate Stone               m_bp_options_vec, m_options.m_one_liner.c_str());
438b9c1b51eSKate Stone         } else if (!m_options.m_function_name.empty()) {
439b9c1b51eSKate Stone           script_interp->SetBreakpointCommandCallbackFunction(
440b9c1b51eSKate Stone               m_bp_options_vec, m_options.m_function_name.c_str());
441b9c1b51eSKate Stone         } else {
442b9c1b51eSKate Stone           script_interp->CollectDataForBreakpointCommandCallback(
443b9c1b51eSKate Stone               m_bp_options_vec, result);
4448d4a8010SEnrico Granata         }
445b9c1b51eSKate Stone       } else {
44639d7d4f0SJohnny Chen         // Special handling for one-liner specified inline.
44739d7d4f0SJohnny Chen         if (m_options.m_use_one_liner)
448b5796cb4SJim Ingham           SetBreakpointCommandCallback(m_bp_options_vec,
44939d7d4f0SJohnny Chen                                        m_options.m_one_liner.c_str());
45039d7d4f0SJohnny Chen         else
451b9c1b51eSKate Stone           CollectDataForBreakpointCommandCallback(m_bp_options_vec, result);
45230fdc8d8SChris Lattner       }
45330fdc8d8SChris Lattner     }
45430fdc8d8SChris Lattner 
45530fdc8d8SChris Lattner     return result.Succeeded();
45630fdc8d8SChris Lattner   }
45730fdc8d8SChris Lattner 
4585a988416SJim Ingham private:
4595a988416SJim Ingham   CommandOptions m_options;
460b9c1b51eSKate Stone   std::vector<BreakpointOptions *> m_bp_options_vec; // This stores the
461b9c1b51eSKate Stone                                                      // breakpoint options that
462b9c1b51eSKate Stone                                                      // we are currently
463b5796cb4SJim Ingham   // collecting commands for.  In the CollectData... calls we need
464b5796cb4SJim Ingham   // to hand this off to the IOHandler, which may run asynchronously.
465b5796cb4SJim Ingham   // So we have to have some way to keep it alive, and not leak it.
466b5796cb4SJim Ingham   // Making it an ivar of the command object, which never goes away
467b5796cb4SJim Ingham   // achieves this.  Note that if we were able to run
468b5796cb4SJim Ingham   // the same command concurrently in one interpreter we'd have to
469b5796cb4SJim Ingham   // make this "per invocation".  But there are many more reasons
470b5796cb4SJim Ingham   // why it is not in general safe to do that in lldb at present,
471b5796cb4SJim Ingham   // so it isn't worthwhile to come up with a more complex mechanism
472b5796cb4SJim Ingham   // to address this particular weakness right now.
4735a988416SJim Ingham   static const char *g_reader_instructions;
4745a988416SJim Ingham };
4755a988416SJim Ingham 
476b9c1b51eSKate Stone const char *CommandObjectBreakpointCommandAdd::g_reader_instructions =
477b9c1b51eSKate Stone     "Enter your debugger command(s).  Type 'DONE' to end.\n";
4785a988416SJim Ingham 
47930fdc8d8SChris Lattner //-------------------------------------------------------------------------
48093e0f19fSCaroline Tice // CommandObjectBreakpointCommandDelete
48130fdc8d8SChris Lattner //-------------------------------------------------------------------------
48230fdc8d8SChris Lattner 
4831f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_delete_options[] = {
4841f0f5b5bSZachary Turner     // clang-format off
4851f0f5b5bSZachary Turner   { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete commands from Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets." },
4861f0f5b5bSZachary Turner     // clang-format on
4871f0f5b5bSZachary Turner };
4881f0f5b5bSZachary Turner 
489b9c1b51eSKate Stone class CommandObjectBreakpointCommandDelete : public CommandObjectParsed {
4905a988416SJim Ingham public:
491b9c1b51eSKate Stone   CommandObjectBreakpointCommandDelete(CommandInterpreter &interpreter)
492b9c1b51eSKate Stone       : CommandObjectParsed(interpreter, "delete",
49393e0f19fSCaroline Tice                             "Delete the set of commands from a breakpoint.",
494c8ecc2a9SEugene Zelenko                             nullptr),
495b9c1b51eSKate Stone         m_options() {
496405fe67fSCaroline Tice     CommandArgumentEntry arg;
497405fe67fSCaroline Tice     CommandArgumentData bp_id_arg;
498405fe67fSCaroline Tice 
499405fe67fSCaroline Tice     // Define the first (and only) variant of this arg.
500405fe67fSCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
501405fe67fSCaroline Tice     bp_id_arg.arg_repetition = eArgRepeatPlain;
502405fe67fSCaroline Tice 
503b9c1b51eSKate Stone     // There is only one variant this argument could be; put it into the
504b9c1b51eSKate Stone     // argument entry.
505405fe67fSCaroline Tice     arg.push_back(bp_id_arg);
506405fe67fSCaroline Tice 
507405fe67fSCaroline Tice     // Push the data for the first argument into the m_arguments vector.
508405fe67fSCaroline Tice     m_arguments.push_back(arg);
50930fdc8d8SChris Lattner   }
51030fdc8d8SChris Lattner 
511c8ecc2a9SEugene Zelenko   ~CommandObjectBreakpointCommandDelete() override = default;
5125a988416SJim Ingham 
513b9c1b51eSKate Stone   Options *GetOptions() override { return &m_options; }
51433df7cd3SJim Ingham 
515b9c1b51eSKate Stone   class CommandOptions : public Options {
51633df7cd3SJim Ingham   public:
517b9c1b51eSKate Stone     CommandOptions() : Options(), m_use_dummy(false) {}
51833df7cd3SJim Ingham 
519c8ecc2a9SEugene Zelenko     ~CommandOptions() override = default;
52033df7cd3SJim Ingham 
521b9c1b51eSKate Stone     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
522b9c1b51eSKate Stone                          ExecutionContext *execution_context) override {
52333df7cd3SJim Ingham       Error error;
52433df7cd3SJim Ingham       const int short_option = m_getopt_table[option_idx].val;
52533df7cd3SJim Ingham 
526b9c1b51eSKate Stone       switch (short_option) {
52733df7cd3SJim Ingham       case 'D':
52833df7cd3SJim Ingham         m_use_dummy = true;
52933df7cd3SJim Ingham         break;
53033df7cd3SJim Ingham 
53133df7cd3SJim Ingham       default:
532b9c1b51eSKate Stone         error.SetErrorStringWithFormat("unrecognized option '%c'",
533b9c1b51eSKate Stone                                        short_option);
53433df7cd3SJim Ingham         break;
53533df7cd3SJim Ingham       }
53633df7cd3SJim Ingham 
53733df7cd3SJim Ingham       return error;
53833df7cd3SJim Ingham     }
53933df7cd3SJim Ingham 
540b9c1b51eSKate Stone     void OptionParsingStarting(ExecutionContext *execution_context) override {
54133df7cd3SJim Ingham       m_use_dummy = false;
54233df7cd3SJim Ingham     }
54333df7cd3SJim Ingham 
5441f0f5b5bSZachary Turner     llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
54570602439SZachary Turner       return llvm::makeArrayRef(g_breakpoint_delete_options);
5461f0f5b5bSZachary Turner     }
54733df7cd3SJim Ingham 
54833df7cd3SJim Ingham     // Instance variables to hold the values for command options.
54933df7cd3SJim Ingham     bool m_use_dummy;
55033df7cd3SJim Ingham   };
55133df7cd3SJim Ingham 
5525a988416SJim Ingham protected:
553b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
55433df7cd3SJim Ingham     Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
55530fdc8d8SChris Lattner 
556b9c1b51eSKate Stone     if (target == nullptr) {
557b9c1b51eSKate Stone       result.AppendError("There is not a current executable; there are no "
558b9c1b51eSKate Stone                          "breakpoints from which to delete commands");
55930fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
56030fdc8d8SChris Lattner       return false;
56130fdc8d8SChris Lattner     }
56230fdc8d8SChris Lattner 
56330fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
56430fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
56530fdc8d8SChris Lattner 
566b9c1b51eSKate Stone     if (num_breakpoints == 0) {
56793e0f19fSCaroline Tice       result.AppendError("No breakpoints exist to have commands deleted");
56830fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
56930fdc8d8SChris Lattner       return false;
57030fdc8d8SChris Lattner     }
57130fdc8d8SChris Lattner 
572b9c1b51eSKate Stone     if (command.GetArgumentCount() == 0) {
573b9c1b51eSKate Stone       result.AppendError(
574b9c1b51eSKate Stone           "No breakpoint specified from which to delete the commands");
57530fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
57630fdc8d8SChris Lattner       return false;
57730fdc8d8SChris Lattner     }
57830fdc8d8SChris Lattner 
57930fdc8d8SChris Lattner     BreakpointIDList valid_bp_ids;
580b9c1b51eSKate Stone     CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
581b9c1b51eSKate Stone         command, target, result, &valid_bp_ids);
58230fdc8d8SChris Lattner 
583b9c1b51eSKate Stone     if (result.Succeeded()) {
584c982c768SGreg Clayton       const size_t count = valid_bp_ids.GetSize();
585b9c1b51eSKate Stone       for (size_t i = 0; i < count; ++i) {
58630fdc8d8SChris Lattner         BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
587b9c1b51eSKate Stone         if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
588b9c1b51eSKate Stone           Breakpoint *bp =
589b9c1b51eSKate Stone               target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
590b9c1b51eSKate Stone           if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
591b9c1b51eSKate Stone             BreakpointLocationSP bp_loc_sp(
592b9c1b51eSKate Stone                 bp->FindLocationByID(cur_bp_id.GetLocationID()));
59330fdc8d8SChris Lattner             if (bp_loc_sp)
59430fdc8d8SChris Lattner               bp_loc_sp->ClearCallback();
595b9c1b51eSKate Stone             else {
59630fdc8d8SChris Lattner               result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n",
59730fdc8d8SChris Lattner                                            cur_bp_id.GetBreakpointID(),
59830fdc8d8SChris Lattner                                            cur_bp_id.GetLocationID());
59930fdc8d8SChris Lattner               result.SetStatus(eReturnStatusFailed);
60030fdc8d8SChris Lattner               return false;
60130fdc8d8SChris Lattner             }
602b9c1b51eSKate Stone           } else {
60330fdc8d8SChris Lattner             bp->ClearCallback();
60430fdc8d8SChris Lattner           }
60530fdc8d8SChris Lattner         }
60630fdc8d8SChris Lattner       }
60730fdc8d8SChris Lattner     }
60830fdc8d8SChris Lattner     return result.Succeeded();
60930fdc8d8SChris Lattner   }
610c8ecc2a9SEugene Zelenko 
61133df7cd3SJim Ingham private:
61233df7cd3SJim Ingham   CommandOptions m_options;
6135a988416SJim Ingham };
61430fdc8d8SChris Lattner 
61530fdc8d8SChris Lattner //-------------------------------------------------------------------------
61630fdc8d8SChris Lattner // CommandObjectBreakpointCommandList
61730fdc8d8SChris Lattner //-------------------------------------------------------------------------
61830fdc8d8SChris Lattner 
619b9c1b51eSKate Stone class CommandObjectBreakpointCommandList : public CommandObjectParsed {
6205a988416SJim Ingham public:
621b9c1b51eSKate Stone   CommandObjectBreakpointCommandList(CommandInterpreter &interpreter)
622b9c1b51eSKate Stone       : CommandObjectParsed(interpreter, "list", "List the script or set of "
623b9c1b51eSKate Stone                                                  "commands to be executed when "
624b9c1b51eSKate Stone                                                  "the breakpoint is hit.",
625b9c1b51eSKate Stone                             nullptr) {
626405fe67fSCaroline Tice     CommandArgumentEntry arg;
627405fe67fSCaroline Tice     CommandArgumentData bp_id_arg;
628405fe67fSCaroline Tice 
629405fe67fSCaroline Tice     // Define the first (and only) variant of this arg.
630405fe67fSCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
631405fe67fSCaroline Tice     bp_id_arg.arg_repetition = eArgRepeatPlain;
632405fe67fSCaroline Tice 
633b9c1b51eSKate Stone     // There is only one variant this argument could be; put it into the
634b9c1b51eSKate Stone     // argument entry.
635405fe67fSCaroline Tice     arg.push_back(bp_id_arg);
636405fe67fSCaroline Tice 
637405fe67fSCaroline Tice     // Push the data for the first argument into the m_arguments vector.
638405fe67fSCaroline Tice     m_arguments.push_back(arg);
63930fdc8d8SChris Lattner   }
64030fdc8d8SChris Lattner 
641c8ecc2a9SEugene Zelenko   ~CommandObjectBreakpointCommandList() override = default;
64230fdc8d8SChris Lattner 
6435a988416SJim Ingham protected:
644b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
645a7015092SGreg Clayton     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
64630fdc8d8SChris Lattner 
647b9c1b51eSKate Stone     if (target == nullptr) {
648b9c1b51eSKate Stone       result.AppendError("There is not a current executable; there are no "
649b9c1b51eSKate Stone                          "breakpoints for which to list commands");
65030fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
65130fdc8d8SChris Lattner       return false;
65230fdc8d8SChris Lattner     }
65330fdc8d8SChris Lattner 
65430fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
65530fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
65630fdc8d8SChris Lattner 
657b9c1b51eSKate Stone     if (num_breakpoints == 0) {
65830fdc8d8SChris Lattner       result.AppendError("No breakpoints exist for which to list commands");
65930fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
66030fdc8d8SChris Lattner       return false;
66130fdc8d8SChris Lattner     }
66230fdc8d8SChris Lattner 
663b9c1b51eSKate Stone     if (command.GetArgumentCount() == 0) {
664b9c1b51eSKate Stone       result.AppendError(
665b9c1b51eSKate Stone           "No breakpoint specified for which to list the commands");
66630fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
66730fdc8d8SChris Lattner       return false;
66830fdc8d8SChris Lattner     }
66930fdc8d8SChris Lattner 
67030fdc8d8SChris Lattner     BreakpointIDList valid_bp_ids;
671b9c1b51eSKate Stone     CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
672b9c1b51eSKate Stone         command, target, result, &valid_bp_ids);
67330fdc8d8SChris Lattner 
674b9c1b51eSKate Stone     if (result.Succeeded()) {
675c982c768SGreg Clayton       const size_t count = valid_bp_ids.GetSize();
676b9c1b51eSKate Stone       for (size_t i = 0; i < count; ++i) {
67730fdc8d8SChris Lattner         BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
678b9c1b51eSKate Stone         if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
679b9c1b51eSKate Stone           Breakpoint *bp =
680b9c1b51eSKate Stone               target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
68130fdc8d8SChris Lattner 
682b9c1b51eSKate Stone           if (bp) {
683c8ecc2a9SEugene Zelenko             const BreakpointOptions *bp_options = nullptr;
684b9c1b51eSKate Stone             if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
685b9c1b51eSKate Stone               BreakpointLocationSP bp_loc_sp(
686b9c1b51eSKate Stone                   bp->FindLocationByID(cur_bp_id.GetLocationID()));
68730fdc8d8SChris Lattner               if (bp_loc_sp)
68805407f6bSJim Ingham                 bp_options = bp_loc_sp->GetOptionsNoCreate();
689b9c1b51eSKate Stone               else {
69030fdc8d8SChris Lattner                 result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n",
69130fdc8d8SChris Lattner                                              cur_bp_id.GetBreakpointID(),
69230fdc8d8SChris Lattner                                              cur_bp_id.GetLocationID());
69330fdc8d8SChris Lattner                 result.SetStatus(eReturnStatusFailed);
69430fdc8d8SChris Lattner                 return false;
69530fdc8d8SChris Lattner               }
696b9c1b51eSKate Stone             } else {
69730fdc8d8SChris Lattner               bp_options = bp->GetOptions();
69830fdc8d8SChris Lattner             }
69930fdc8d8SChris Lattner 
700b9c1b51eSKate Stone             if (bp_options) {
70130fdc8d8SChris Lattner               StreamString id_str;
702e16c50a1SJim Ingham               BreakpointID::GetCanonicalReference(&id_str,
703e16c50a1SJim Ingham                                                   cur_bp_id.GetBreakpointID(),
704e16c50a1SJim Ingham                                                   cur_bp_id.GetLocationID());
7051b54c88cSJim Ingham               const Baton *baton = bp_options->GetBaton();
706b9c1b51eSKate Stone               if (baton) {
707b9c1b51eSKate Stone                 result.GetOutputStream().Printf("Breakpoint %s:\n",
708b9c1b51eSKate Stone                                                 id_str.GetData());
70930fdc8d8SChris Lattner                 result.GetOutputStream().IndentMore();
710b9c1b51eSKate Stone                 baton->GetDescription(&result.GetOutputStream(),
711b9c1b51eSKate Stone                                       eDescriptionLevelFull);
71230fdc8d8SChris Lattner                 result.GetOutputStream().IndentLess();
713b9c1b51eSKate Stone               } else {
714b9c1b51eSKate Stone                 result.AppendMessageWithFormat(
715b9c1b51eSKate Stone                     "Breakpoint %s does not have an associated command.\n",
716e16c50a1SJim Ingham                     id_str.GetData());
71730fdc8d8SChris Lattner               }
71830fdc8d8SChris Lattner             }
71930fdc8d8SChris Lattner             result.SetStatus(eReturnStatusSuccessFinishResult);
720b9c1b51eSKate Stone           } else {
721b9c1b51eSKate Stone             result.AppendErrorWithFormat("Invalid breakpoint ID: %u.\n",
722b9c1b51eSKate Stone                                          cur_bp_id.GetBreakpointID());
72330fdc8d8SChris Lattner             result.SetStatus(eReturnStatusFailed);
72430fdc8d8SChris Lattner           }
72530fdc8d8SChris Lattner         }
72630fdc8d8SChris Lattner       }
72730fdc8d8SChris Lattner     }
72830fdc8d8SChris Lattner 
72930fdc8d8SChris Lattner     return result.Succeeded();
73030fdc8d8SChris Lattner   }
7315a988416SJim Ingham };
73230fdc8d8SChris Lattner 
73330fdc8d8SChris Lattner //-------------------------------------------------------------------------
73430fdc8d8SChris Lattner // CommandObjectBreakpointCommand
73530fdc8d8SChris Lattner //-------------------------------------------------------------------------
73630fdc8d8SChris Lattner 
737b9c1b51eSKate Stone CommandObjectBreakpointCommand::CommandObjectBreakpointCommand(
738b9c1b51eSKate Stone     CommandInterpreter &interpreter)
7397428a18cSKate Stone     : CommandObjectMultiword(
740b9c1b51eSKate Stone           interpreter, "command", "Commands for adding, removing and listing "
741b9c1b51eSKate Stone                                   "LLDB commands executed when a breakpoint is "
742b9c1b51eSKate Stone                                   "hit.",
743b9c1b51eSKate Stone           "command <sub-command> [<sub-command-options>] <breakpoint-id>") {
744b9c1b51eSKate Stone   CommandObjectSP add_command_object(
745b9c1b51eSKate Stone       new CommandObjectBreakpointCommandAdd(interpreter));
746b9c1b51eSKate Stone   CommandObjectSP delete_command_object(
747b9c1b51eSKate Stone       new CommandObjectBreakpointCommandDelete(interpreter));
748b9c1b51eSKate Stone   CommandObjectSP list_command_object(
749b9c1b51eSKate Stone       new CommandObjectBreakpointCommandList(interpreter));
75030fdc8d8SChris Lattner 
75130fdc8d8SChris Lattner   add_command_object->SetCommandName("breakpoint command add");
75293e0f19fSCaroline Tice   delete_command_object->SetCommandName("breakpoint command delete");
75330fdc8d8SChris Lattner   list_command_object->SetCommandName("breakpoint command list");
75430fdc8d8SChris Lattner 
75523f59509SGreg Clayton   LoadSubCommand("add", add_command_object);
75623f59509SGreg Clayton   LoadSubCommand("delete", delete_command_object);
75723f59509SGreg Clayton   LoadSubCommand("list", list_command_object);
75830fdc8d8SChris Lattner }
75930fdc8d8SChris Lattner 
760c8ecc2a9SEugene Zelenko CommandObjectBreakpointCommand::~CommandObjectBreakpointCommand() = default;
761