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 
27*4e4fbe82SZachary Turner #include "llvm/ADT/STLExtras.h"
28*4e4fbe82SZachary Turner 
2930fdc8d8SChris Lattner using namespace lldb;
3030fdc8d8SChris Lattner using namespace lldb_private;
3130fdc8d8SChris Lattner 
3230fdc8d8SChris Lattner //-------------------------------------------------------------------------
3330fdc8d8SChris Lattner // CommandObjectBreakpointCommandAdd
3430fdc8d8SChris Lattner //-------------------------------------------------------------------------
3530fdc8d8SChris Lattner 
36b9c1b51eSKate Stone class CommandObjectBreakpointCommandAdd : public CommandObjectParsed,
37b9c1b51eSKate Stone                                           public IOHandlerDelegateMultiline {
385a988416SJim Ingham public:
397428a18cSKate Stone   CommandObjectBreakpointCommandAdd(CommandInterpreter &interpreter)
407428a18cSKate Stone       : CommandObjectParsed(interpreter, "add",
41b9c1b51eSKate Stone                             "Add LLDB commands to a breakpoint, to be executed "
42b9c1b51eSKate Stone                             "whenever the breakpoint is hit."
43b9c1b51eSKate Stone                             "  If no breakpoint is specified, adds the "
44b9c1b51eSKate Stone                             "commands to the last created breakpoint.",
45c8ecc2a9SEugene Zelenko                             nullptr),
46b9c1b51eSKate Stone         IOHandlerDelegateMultiline("DONE",
47b9c1b51eSKate Stone                                    IOHandlerDelegate::Completion::LLDBCommand),
48b9c1b51eSKate Stone         m_options() {
4930fdc8d8SChris Lattner     SetHelpLong(
50ea671fbdSKate Stone         R"(
51ea671fbdSKate Stone General information about entering breakpoint commands
52ea671fbdSKate Stone ------------------------------------------------------
53ea671fbdSKate Stone 
54b9c1b51eSKate Stone )"
55b9c1b51eSKate Stone         "This command will prompt for commands to be executed when the specified \
56ea671fbdSKate Stone breakpoint is hit.  Each command is typed on its own line following the '> ' \
57b9c1b51eSKate Stone prompt until 'DONE' is entered."
58b9c1b51eSKate Stone         R"(
59ea671fbdSKate Stone 
60b9c1b51eSKate Stone )"
61b9c1b51eSKate Stone         "Syntactic errors may not be detected when initially entered, and many \
62ea671fbdSKate Stone malformed commands can silently fail when executed.  If your breakpoint commands \
63b9c1b51eSKate Stone do not appear to be executing, double-check the command syntax."
64b9c1b51eSKate Stone         R"(
65ea671fbdSKate Stone 
66b9c1b51eSKate Stone )"
67b9c1b51eSKate Stone         "Note: You may enter any debugger command exactly as you would at the debugger \
68ea671fbdSKate Stone prompt.  There is no limit to the number of commands supplied, but do NOT enter \
69b9c1b51eSKate Stone more than one command per line."
70b9c1b51eSKate Stone         R"(
71ea671fbdSKate Stone 
72ea671fbdSKate Stone Special information about PYTHON breakpoint commands
73ea671fbdSKate Stone ----------------------------------------------------
74ea671fbdSKate Stone 
75b9c1b51eSKate Stone )"
76b9c1b51eSKate Stone         "You may enter either one or more lines of Python, including function \
77ea671fbdSKate Stone definitions or calls to functions that will have been imported by the time \
78ea671fbdSKate Stone the code executes.  Single line breakpoint commands will be interpreted 'as is' \
79ea671fbdSKate Stone when the breakpoint is hit.  Multiple lines of Python will be wrapped in a \
80b9c1b51eSKate Stone generated function, and a call to the function will be attached to the breakpoint."
81b9c1b51eSKate Stone         R"(
82ea671fbdSKate Stone 
83ea671fbdSKate Stone This auto-generated function is passed in three arguments:
84ea671fbdSKate Stone 
85ea671fbdSKate Stone     frame:  an lldb.SBFrame object for the frame which hit breakpoint.
86ea671fbdSKate Stone 
87ea671fbdSKate Stone     bp_loc: an lldb.SBBreakpointLocation object that represents the breakpoint location that was hit.
88ea671fbdSKate Stone 
89ea671fbdSKate Stone     dict:   the python session dictionary hit.
90ea671fbdSKate Stone 
91b9c1b51eSKate Stone )"
92b9c1b51eSKate Stone         "When specifying a python function with the --python-function option, you need \
93b9c1b51eSKate Stone to supply the function name prepended by the module name:"
94b9c1b51eSKate Stone         R"(
95ea671fbdSKate Stone 
96ea671fbdSKate Stone     --python-function myutils.breakpoint_callback
97ea671fbdSKate Stone 
98ea671fbdSKate Stone The function itself must have the following prototype:
99ea671fbdSKate Stone 
100ea671fbdSKate Stone def breakpoint_callback(frame, bp_loc, dict):
101ea671fbdSKate Stone   # Your code goes here
102ea671fbdSKate Stone 
103b9c1b51eSKate Stone )"
104b9c1b51eSKate Stone         "The arguments are the same as the arguments passed to generated functions as \
105ea671fbdSKate Stone described above.  Note that the global variable 'lldb.frame' will NOT be updated when \
106ea671fbdSKate Stone this function is called, so be sure to use the 'frame' argument. The 'frame' argument \
107ea671fbdSKate Stone can get you to the thread via frame.GetThread(), the thread can get you to the \
108ea671fbdSKate Stone process via thread.GetProcess(), and the process can get you back to the target \
109b9c1b51eSKate Stone via process.GetTarget()."
110b9c1b51eSKate Stone         R"(
111ea671fbdSKate Stone 
112b9c1b51eSKate Stone )"
113b9c1b51eSKate Stone         "Important Note: As Python code gets collected into functions, access to global \
114ea671fbdSKate Stone variables requires explicit scoping using the 'global' keyword.  Be sure to use correct \
115b9c1b51eSKate Stone Python syntax, including indentation, when entering Python breakpoint commands."
116b9c1b51eSKate Stone         R"(
117ea671fbdSKate Stone 
118ea671fbdSKate Stone Example Python one-line breakpoint command:
119ea671fbdSKate Stone 
120ea671fbdSKate Stone (lldb) breakpoint command add -s python 1
121ea671fbdSKate Stone Enter your Python command(s). Type 'DONE' to end.
122ea671fbdSKate Stone > print "Hit this breakpoint!"
123ea671fbdSKate Stone > DONE
124ea671fbdSKate Stone 
125ea671fbdSKate Stone As a convenience, this also works for a short Python one-liner:
126ea671fbdSKate Stone 
127ea671fbdSKate Stone (lldb) breakpoint command add -s python 1 -o 'import time; print time.asctime()'
128ea671fbdSKate Stone (lldb) run
129ea671fbdSKate Stone Launching '.../a.out'  (x86_64)
130ea671fbdSKate Stone (lldb) Fri Sep 10 12:17:45 2010
131ea671fbdSKate Stone Process 21778 Stopped
132ea671fbdSKate Stone * thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread
133ea671fbdSKate Stone   36
134ea671fbdSKate Stone   37   	int c(int val)
135ea671fbdSKate Stone   38   	{
136ea671fbdSKate Stone   39 ->	    return val + 3;
137ea671fbdSKate Stone   40   	}
138ea671fbdSKate Stone   41
139ea671fbdSKate Stone   42   	int main (int argc, char const *argv[])
140ea671fbdSKate Stone 
141ea671fbdSKate Stone Example multiple line Python breakpoint command:
142ea671fbdSKate Stone 
143ea671fbdSKate Stone (lldb) breakpoint command add -s p 1
144ea671fbdSKate Stone Enter your Python command(s). Type 'DONE' to end.
145ea671fbdSKate Stone > global bp_count
146ea671fbdSKate Stone > bp_count = bp_count + 1
147ea671fbdSKate Stone > print "Hit this breakpoint " + repr(bp_count) + " times!"
148ea671fbdSKate Stone > DONE
149ea671fbdSKate Stone 
150ea671fbdSKate Stone Example multiple line Python breakpoint command, using function definition:
151ea671fbdSKate Stone 
152ea671fbdSKate Stone (lldb) breakpoint command add -s python 1
153ea671fbdSKate Stone Enter your Python command(s). Type 'DONE' to end.
154ea671fbdSKate Stone > def breakpoint_output (bp_no):
155ea671fbdSKate Stone >     out_string = "Hit breakpoint number " + repr (bp_no)
156ea671fbdSKate Stone >     print out_string
157ea671fbdSKate Stone >     return True
158ea671fbdSKate Stone > breakpoint_output (1)
159ea671fbdSKate Stone > DONE
160ea671fbdSKate Stone 
161b9c1b51eSKate Stone )"
162b9c1b51eSKate Stone         "In this case, since there is a reference to a global variable, \
163ea671fbdSKate Stone 'bp_count', you will also need to make sure 'bp_count' exists and is \
164b9c1b51eSKate Stone initialized:"
165b9c1b51eSKate Stone         R"(
166ea671fbdSKate Stone 
167ea671fbdSKate Stone (lldb) script
168ea671fbdSKate Stone >>> bp_count = 0
169ea671fbdSKate Stone >>> quit()
170ea671fbdSKate Stone 
171b9c1b51eSKate Stone )"
172b9c1b51eSKate Stone         "Your Python code, however organized, can optionally return a value.  \
173ea671fbdSKate Stone If the returned value is False, that tells LLDB not to stop at the breakpoint \
174ea671fbdSKate Stone to which the code is associated. Returning anything other than False, or even \
175ea671fbdSKate Stone returning None, or even omitting a return statement entirely, will cause \
176b9c1b51eSKate Stone LLDB to stop."
177b9c1b51eSKate Stone         R"(
178ea671fbdSKate Stone 
179b9c1b51eSKate Stone )"
180b9c1b51eSKate Stone         "Final Note: A warning that no breakpoint command was generated when there \
181b9c1b51eSKate Stone are no syntax errors may indicate that a function was declared but never called.");
182405fe67fSCaroline Tice 
183405fe67fSCaroline Tice     CommandArgumentEntry arg;
184405fe67fSCaroline Tice     CommandArgumentData bp_id_arg;
185405fe67fSCaroline Tice 
186405fe67fSCaroline Tice     // Define the first (and only) variant of this arg.
187405fe67fSCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
1881bb0750bSJim Ingham     bp_id_arg.arg_repetition = eArgRepeatOptional;
189405fe67fSCaroline Tice 
190b9c1b51eSKate Stone     // There is only one variant this argument could be; put it into the
191b9c1b51eSKate Stone     // argument entry.
192405fe67fSCaroline Tice     arg.push_back(bp_id_arg);
193405fe67fSCaroline Tice 
194405fe67fSCaroline Tice     // Push the data for the first argument into the m_arguments vector.
195405fe67fSCaroline Tice     m_arguments.push_back(arg);
19630fdc8d8SChris Lattner   }
19730fdc8d8SChris Lattner 
198c8ecc2a9SEugene Zelenko   ~CommandObjectBreakpointCommandAdd() override = default;
1995a988416SJim Ingham 
200b9c1b51eSKate Stone   Options *GetOptions() override { return &m_options; }
2015a988416SJim Ingham 
202b9c1b51eSKate Stone   void IOHandlerActivated(IOHandler &io_handler) override {
20344d93782SGreg Clayton     StreamFileSP output_sp(io_handler.GetOutputStreamFile());
204b9c1b51eSKate Stone     if (output_sp) {
20544d93782SGreg Clayton       output_sp->PutCString(g_reader_instructions);
20644d93782SGreg Clayton       output_sp->Flush();
20744d93782SGreg Clayton     }
20844d93782SGreg Clayton   }
20944d93782SGreg Clayton 
210b9c1b51eSKate Stone   void IOHandlerInputComplete(IOHandler &io_handler,
211b9c1b51eSKate Stone                               std::string &line) override {
21244d93782SGreg Clayton     io_handler.SetIsDone(true);
21344d93782SGreg Clayton 
214b9c1b51eSKate Stone     std::vector<BreakpointOptions *> *bp_options_vec =
215b9c1b51eSKate Stone         (std::vector<BreakpointOptions *> *)io_handler.GetUserData();
216b9c1b51eSKate Stone     for (BreakpointOptions *bp_options : *bp_options_vec) {
217b5796cb4SJim Ingham       if (!bp_options)
218b5796cb4SJim Ingham         continue;
219b5796cb4SJim Ingham 
220*4e4fbe82SZachary Turner       auto cmd_data = llvm::make_unique<BreakpointOptions::CommandData>();
221e14dc268SJim Ingham       cmd_data->user_source.SplitIntoLines(line.c_str(), line.size());
222*4e4fbe82SZachary Turner       bp_options->SetCommandDataCallback(std::move(cmd_data));
22344d93782SGreg Clayton     }
22444d93782SGreg Clayton   }
22544d93782SGreg Clayton 
226b9c1b51eSKate Stone   void CollectDataForBreakpointCommandCallback(
227b9c1b51eSKate Stone       std::vector<BreakpointOptions *> &bp_options_vec,
228b9c1b51eSKate Stone       CommandReturnObject &result) {
229b9c1b51eSKate Stone     m_interpreter.GetLLDBCommandsFromIOHandler(
230b9c1b51eSKate Stone         "> ",             // Prompt
23144d93782SGreg Clayton         *this,            // IOHandlerDelegate
23244d93782SGreg Clayton         true,             // Run IOHandler in async mode
233b9c1b51eSKate Stone         &bp_options_vec); // Baton for the "io_handler" that will be passed back
234b9c1b51eSKate Stone                           // into our IOHandlerDelegate functions
2355a988416SJim Ingham   }
2365a988416SJim Ingham 
2375a988416SJim Ingham   /// Set a one-liner as the callback for the breakpoint.
2385a988416SJim Ingham   void
239b5796cb4SJim Ingham   SetBreakpointCommandCallback(std::vector<BreakpointOptions *> &bp_options_vec,
240b9c1b51eSKate Stone                                const char *oneliner) {
241b9c1b51eSKate Stone     for (auto bp_options : bp_options_vec) {
242*4e4fbe82SZachary Turner       auto cmd_data = llvm::make_unique<BreakpointOptions::CommandData>();
2435a988416SJim Ingham 
244b9c1b51eSKate Stone       // It's necessary to set both user_source and script_source to the
245b9c1b51eSKate Stone       // oneliner.
246b9c1b51eSKate Stone       // The former is used to generate callback description (as in breakpoint
247b9c1b51eSKate Stone       // command list)
248b9c1b51eSKate Stone       // while the latter is used for Python to interpret during the actual
249b9c1b51eSKate Stone       // callback.
250e14dc268SJim Ingham       cmd_data->user_source.AppendString(oneliner);
251e14dc268SJim Ingham       cmd_data->script_source.assign(oneliner);
252e14dc268SJim Ingham       cmd_data->stop_on_error = m_options.m_stop_on_error;
2535a988416SJim Ingham 
254*4e4fbe82SZachary Turner       bp_options->SetCommandDataCallback(std::move(cmd_data));
255b5796cb4SJim Ingham     }
2565a988416SJim Ingham   }
2575a988416SJim Ingham 
258b9c1b51eSKate Stone   class CommandOptions : public Options {
2595a988416SJim Ingham   public:
260b9c1b51eSKate Stone     CommandOptions()
261b9c1b51eSKate Stone         : Options(), m_use_commands(false), m_use_script_language(false),
262b9c1b51eSKate Stone           m_script_language(eScriptLanguageNone), m_use_one_liner(false),
263b9c1b51eSKate Stone           m_one_liner(), m_function_name() {}
26430fdc8d8SChris Lattner 
265c8ecc2a9SEugene Zelenko     ~CommandOptions() override = default;
2665a988416SJim Ingham 
267b9c1b51eSKate Stone     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
268b9c1b51eSKate Stone                          ExecutionContext *execution_context) override {
2695a988416SJim Ingham       Error error;
2703bcdfc0eSGreg Clayton       const int short_option = m_getopt_table[option_idx].val;
2715a988416SJim Ingham 
272b9c1b51eSKate Stone       switch (short_option) {
2735a988416SJim Ingham       case 'o':
2745a988416SJim Ingham         m_use_one_liner = true;
2755a988416SJim Ingham         m_one_liner = option_arg;
2765a988416SJim Ingham         break;
2775a988416SJim Ingham 
2785a988416SJim Ingham       case 's':
279b9c1b51eSKate Stone         m_script_language = (lldb::ScriptLanguage)Args::StringToOptionEnum(
280b9c1b51eSKate Stone             option_arg, g_option_table[option_idx].enum_values,
281b9c1b51eSKate Stone             eScriptLanguageNone, error);
2825a988416SJim Ingham 
283b9c1b51eSKate Stone         if (m_script_language == eScriptLanguagePython ||
284b9c1b51eSKate Stone             m_script_language == eScriptLanguageDefault) {
2855a988416SJim Ingham           m_use_script_language = true;
286b9c1b51eSKate Stone         } else {
2875a988416SJim Ingham           m_use_script_language = false;
2885a988416SJim Ingham         }
2895a988416SJim Ingham         break;
2905a988416SJim Ingham 
291b9c1b51eSKate Stone       case 'e': {
2925a988416SJim Ingham         bool success = false;
2935a988416SJim Ingham         m_stop_on_error = Args::StringToBoolean(option_arg, false, &success);
2945a988416SJim Ingham         if (!success)
295b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
296b9c1b51eSKate Stone               "invalid value for stop-on-error: \"%s\"", option_arg);
297b9c1b51eSKate Stone       } break;
2985a988416SJim Ingham 
2995a988416SJim Ingham       case 'F':
3005a988416SJim Ingham         m_use_one_liner = false;
3015a988416SJim Ingham         m_use_script_language = true;
3025a988416SJim Ingham         m_function_name.assign(option_arg);
3035a988416SJim Ingham         break;
3045a988416SJim Ingham 
30533df7cd3SJim Ingham       case 'D':
30633df7cd3SJim Ingham         m_use_dummy = true;
30733df7cd3SJim Ingham         break;
30833df7cd3SJim Ingham 
3095a988416SJim Ingham       default:
3105a988416SJim Ingham         break;
3115a988416SJim Ingham       }
3125a988416SJim Ingham       return error;
3135a988416SJim Ingham     }
314c8ecc2a9SEugene Zelenko 
315b9c1b51eSKate Stone     void OptionParsingStarting(ExecutionContext *execution_context) override {
3165a988416SJim Ingham       m_use_commands = true;
3175a988416SJim Ingham       m_use_script_language = false;
3185a988416SJim Ingham       m_script_language = eScriptLanguageNone;
3195a988416SJim Ingham 
3205a988416SJim Ingham       m_use_one_liner = false;
3215a988416SJim Ingham       m_stop_on_error = true;
3225a988416SJim Ingham       m_one_liner.clear();
3235a988416SJim Ingham       m_function_name.clear();
32433df7cd3SJim Ingham       m_use_dummy = false;
3255a988416SJim Ingham     }
3265a988416SJim Ingham 
327b9c1b51eSKate Stone     const OptionDefinition *GetDefinitions() override { return g_option_table; }
3285a988416SJim Ingham 
3295a988416SJim Ingham     // Options table: Required for subclasses of Options.
3305a988416SJim Ingham 
3315a988416SJim Ingham     static OptionDefinition g_option_table[];
3325a988416SJim Ingham 
3335a988416SJim Ingham     // Instance variables to hold the values for command options.
3345a988416SJim Ingham 
3355a988416SJim Ingham     bool m_use_commands;
3365a988416SJim Ingham     bool m_use_script_language;
3375a988416SJim Ingham     lldb::ScriptLanguage m_script_language;
3385a988416SJim Ingham 
3395a988416SJim Ingham     // Instance variables to hold the values for one_liner options.
3405a988416SJim Ingham     bool m_use_one_liner;
3415a988416SJim Ingham     std::string m_one_liner;
3425a988416SJim Ingham     bool m_stop_on_error;
3435a988416SJim Ingham     std::string m_function_name;
34433df7cd3SJim Ingham     bool m_use_dummy;
3455a988416SJim Ingham   };
3465a988416SJim Ingham 
3475a988416SJim Ingham protected:
348b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
34933df7cd3SJim Ingham     Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
35030fdc8d8SChris Lattner 
351b9c1b51eSKate Stone     if (target == nullptr) {
352b9c1b51eSKate Stone       result.AppendError("There is not a current executable; there are no "
353b9c1b51eSKate Stone                          "breakpoints to which to add commands");
35430fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
35530fdc8d8SChris Lattner       return false;
35630fdc8d8SChris Lattner     }
35730fdc8d8SChris Lattner 
35830fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
35930fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
36030fdc8d8SChris Lattner 
361b9c1b51eSKate Stone     if (num_breakpoints == 0) {
36230fdc8d8SChris Lattner       result.AppendError("No breakpoints exist to have commands added");
36330fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
36430fdc8d8SChris Lattner       return false;
36530fdc8d8SChris Lattner     }
36630fdc8d8SChris Lattner 
367b9c1b51eSKate Stone     if (!m_options.m_use_script_language &&
368b9c1b51eSKate Stone         !m_options.m_function_name.empty()) {
369b9c1b51eSKate Stone       result.AppendError("need to enable scripting to have a function run as a "
370b9c1b51eSKate Stone                          "breakpoint command");
3718d4a8010SEnrico Granata       result.SetStatus(eReturnStatusFailed);
3728d4a8010SEnrico Granata       return false;
3738d4a8010SEnrico Granata     }
3748d4a8010SEnrico Granata 
37530fdc8d8SChris Lattner     BreakpointIDList valid_bp_ids;
376b9c1b51eSKate Stone     CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
377b9c1b51eSKate Stone         command, target, result, &valid_bp_ids);
37830fdc8d8SChris Lattner 
379b5796cb4SJim Ingham     m_bp_options_vec.clear();
380b5796cb4SJim Ingham 
381b9c1b51eSKate Stone     if (result.Succeeded()) {
382c982c768SGreg Clayton       const size_t count = valid_bp_ids.GetSize();
383d9916eaeSJim Ingham 
384b9c1b51eSKate Stone       for (size_t i = 0; i < count; ++i) {
38530fdc8d8SChris Lattner         BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
386b9c1b51eSKate Stone         if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
387b9c1b51eSKate Stone           Breakpoint *bp =
388b9c1b51eSKate Stone               target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
389c8ecc2a9SEugene Zelenko           BreakpointOptions *bp_options = nullptr;
390b9c1b51eSKate Stone           if (cur_bp_id.GetLocationID() == LLDB_INVALID_BREAK_ID) {
39139d7d4f0SJohnny Chen             // This breakpoint does not have an associated location.
39239d7d4f0SJohnny Chen             bp_options = bp->GetOptions();
393b9c1b51eSKate Stone           } else {
394b9c1b51eSKate Stone             BreakpointLocationSP bp_loc_sp(
395b9c1b51eSKate Stone                 bp->FindLocationByID(cur_bp_id.GetLocationID()));
39639d7d4f0SJohnny Chen             // This breakpoint does have an associated location.
39739d7d4f0SJohnny Chen             // Get its breakpoint options.
39830fdc8d8SChris Lattner             if (bp_loc_sp)
39939d7d4f0SJohnny Chen               bp_options = bp_loc_sp->GetLocationOptions();
40039d7d4f0SJohnny Chen           }
401b5796cb4SJim Ingham           if (bp_options)
402b5796cb4SJim Ingham             m_bp_options_vec.push_back(bp_options);
403b5796cb4SJim Ingham         }
404b5796cb4SJim Ingham       }
40539d7d4f0SJohnny Chen 
40639d7d4f0SJohnny Chen       // If we are using script language, get the script interpreter
40739d7d4f0SJohnny Chen       // in order to set or collect command callback.  Otherwise, call
40839d7d4f0SJohnny Chen       // the methods associated with this object.
409b9c1b51eSKate Stone       if (m_options.m_use_script_language) {
410b5796cb4SJim Ingham         ScriptInterpreter *script_interp = m_interpreter.GetScriptInterpreter();
41139d7d4f0SJohnny Chen         // Special handling for one-liner specified inline.
412b9c1b51eSKate Stone         if (m_options.m_use_one_liner) {
413b9c1b51eSKate Stone           script_interp->SetBreakpointCommandCallback(
414b9c1b51eSKate Stone               m_bp_options_vec, m_options.m_one_liner.c_str());
415b9c1b51eSKate Stone         } else if (!m_options.m_function_name.empty()) {
416b9c1b51eSKate Stone           script_interp->SetBreakpointCommandCallbackFunction(
417b9c1b51eSKate Stone               m_bp_options_vec, m_options.m_function_name.c_str());
418b9c1b51eSKate Stone         } else {
419b9c1b51eSKate Stone           script_interp->CollectDataForBreakpointCommandCallback(
420b9c1b51eSKate Stone               m_bp_options_vec, result);
4218d4a8010SEnrico Granata         }
422b9c1b51eSKate Stone       } else {
42339d7d4f0SJohnny Chen         // Special handling for one-liner specified inline.
42439d7d4f0SJohnny Chen         if (m_options.m_use_one_liner)
425b5796cb4SJim Ingham           SetBreakpointCommandCallback(m_bp_options_vec,
42639d7d4f0SJohnny Chen                                        m_options.m_one_liner.c_str());
42739d7d4f0SJohnny Chen         else
428b9c1b51eSKate Stone           CollectDataForBreakpointCommandCallback(m_bp_options_vec, result);
42930fdc8d8SChris Lattner       }
43030fdc8d8SChris Lattner     }
43130fdc8d8SChris Lattner 
43230fdc8d8SChris Lattner     return result.Succeeded();
43330fdc8d8SChris Lattner   }
43430fdc8d8SChris Lattner 
4355a988416SJim Ingham private:
4365a988416SJim Ingham   CommandOptions m_options;
437b9c1b51eSKate Stone   std::vector<BreakpointOptions *> m_bp_options_vec; // This stores the
438b9c1b51eSKate Stone                                                      // breakpoint options that
439b9c1b51eSKate Stone                                                      // we are currently
440b5796cb4SJim Ingham   // collecting commands for.  In the CollectData... calls we need
441b5796cb4SJim Ingham   // to hand this off to the IOHandler, which may run asynchronously.
442b5796cb4SJim Ingham   // So we have to have some way to keep it alive, and not leak it.
443b5796cb4SJim Ingham   // Making it an ivar of the command object, which never goes away
444b5796cb4SJim Ingham   // achieves this.  Note that if we were able to run
445b5796cb4SJim Ingham   // the same command concurrently in one interpreter we'd have to
446b5796cb4SJim Ingham   // make this "per invocation".  But there are many more reasons
447b5796cb4SJim Ingham   // why it is not in general safe to do that in lldb at present,
448b5796cb4SJim Ingham   // so it isn't worthwhile to come up with a more complex mechanism
449b5796cb4SJim Ingham   // to address this particular weakness right now.
4505a988416SJim Ingham   static const char *g_reader_instructions;
4515a988416SJim Ingham };
4525a988416SJim Ingham 
453b9c1b51eSKate Stone const char *CommandObjectBreakpointCommandAdd::g_reader_instructions =
454b9c1b51eSKate Stone     "Enter your debugger command(s).  Type 'DONE' to end.\n";
4555a988416SJim Ingham 
456b9c1b51eSKate Stone // FIXME: "script-type" needs to have its contents determined dynamically, so
457b9c1b51eSKate Stone // somebody can add a new scripting
458b9c1b51eSKate Stone // language to lldb and have it pickable here without having to change this
459b9c1b51eSKate Stone // enumeration by hand and rebuild lldb proper.
4605a988416SJim Ingham 
461b9c1b51eSKate Stone static OptionEnumValueElement g_script_option_enumeration[4] = {
462b9c1b51eSKate Stone     {eScriptLanguageNone, "command",
463b9c1b51eSKate Stone      "Commands are in the lldb command interpreter language"},
4645a988416SJim Ingham     {eScriptLanguagePython, "python", "Commands are in the Python language."},
465b9c1b51eSKate Stone     {eSortOrderByName, "default-script",
466b9c1b51eSKate Stone      "Commands are in the default scripting language."},
467b9c1b51eSKate Stone     {0, nullptr, nullptr}};
46830fdc8d8SChris Lattner 
4695a988416SJim Ingham OptionDefinition
470b9c1b51eSKate Stone     CommandObjectBreakpointCommandAdd::CommandOptions::g_option_table[] = {
471ac9c3a62SKate Stone         // clang-format off
472ac9c3a62SKate Stone   {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." },
473ac9c3a62SKate Stone   {LLDB_OPT_SET_ALL, false, "stop-on-error",     'e', OptionParser::eRequiredArgument, nullptr, nullptr,                     0, eArgTypeBoolean,        "Specify whether breakpoint command execution should terminate on error." },
474ac9c3a62SKate Stone   {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."},
475ac9c3a62SKate Stone   {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."},
476ac9c3a62SKate Stone   {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."},
477c8ecc2a9SEugene Zelenko   {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
478ac9c3a62SKate Stone         // clang-format on
4795a988416SJim Ingham };
48030fdc8d8SChris Lattner 
48130fdc8d8SChris Lattner //-------------------------------------------------------------------------
48293e0f19fSCaroline Tice // CommandObjectBreakpointCommandDelete
48330fdc8d8SChris Lattner //-------------------------------------------------------------------------
48430fdc8d8SChris Lattner 
485b9c1b51eSKate Stone class CommandObjectBreakpointCommandDelete : public CommandObjectParsed {
4865a988416SJim Ingham public:
487b9c1b51eSKate Stone   CommandObjectBreakpointCommandDelete(CommandInterpreter &interpreter)
488b9c1b51eSKate Stone       : CommandObjectParsed(interpreter, "delete",
48993e0f19fSCaroline Tice                             "Delete the set of commands from a breakpoint.",
490c8ecc2a9SEugene Zelenko                             nullptr),
491b9c1b51eSKate Stone         m_options() {
492405fe67fSCaroline Tice     CommandArgumentEntry arg;
493405fe67fSCaroline Tice     CommandArgumentData bp_id_arg;
494405fe67fSCaroline Tice 
495405fe67fSCaroline Tice     // Define the first (and only) variant of this arg.
496405fe67fSCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
497405fe67fSCaroline Tice     bp_id_arg.arg_repetition = eArgRepeatPlain;
498405fe67fSCaroline Tice 
499b9c1b51eSKate Stone     // There is only one variant this argument could be; put it into the
500b9c1b51eSKate Stone     // argument entry.
501405fe67fSCaroline Tice     arg.push_back(bp_id_arg);
502405fe67fSCaroline Tice 
503405fe67fSCaroline Tice     // Push the data for the first argument into the m_arguments vector.
504405fe67fSCaroline Tice     m_arguments.push_back(arg);
50530fdc8d8SChris Lattner   }
50630fdc8d8SChris Lattner 
507c8ecc2a9SEugene Zelenko   ~CommandObjectBreakpointCommandDelete() override = default;
5085a988416SJim Ingham 
509b9c1b51eSKate Stone   Options *GetOptions() override { return &m_options; }
51033df7cd3SJim Ingham 
511b9c1b51eSKate Stone   class CommandOptions : public Options {
51233df7cd3SJim Ingham   public:
513b9c1b51eSKate Stone     CommandOptions() : Options(), m_use_dummy(false) {}
51433df7cd3SJim Ingham 
515c8ecc2a9SEugene Zelenko     ~CommandOptions() override = default;
51633df7cd3SJim Ingham 
517b9c1b51eSKate Stone     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
518b9c1b51eSKate Stone                          ExecutionContext *execution_context) override {
51933df7cd3SJim Ingham       Error error;
52033df7cd3SJim Ingham       const int short_option = m_getopt_table[option_idx].val;
52133df7cd3SJim Ingham 
522b9c1b51eSKate Stone       switch (short_option) {
52333df7cd3SJim Ingham       case 'D':
52433df7cd3SJim Ingham         m_use_dummy = true;
52533df7cd3SJim Ingham         break;
52633df7cd3SJim Ingham 
52733df7cd3SJim Ingham       default:
528b9c1b51eSKate Stone         error.SetErrorStringWithFormat("unrecognized option '%c'",
529b9c1b51eSKate Stone                                        short_option);
53033df7cd3SJim Ingham         break;
53133df7cd3SJim Ingham       }
53233df7cd3SJim Ingham 
53333df7cd3SJim Ingham       return error;
53433df7cd3SJim Ingham     }
53533df7cd3SJim Ingham 
536b9c1b51eSKate Stone     void OptionParsingStarting(ExecutionContext *execution_context) override {
53733df7cd3SJim Ingham       m_use_dummy = false;
53833df7cd3SJim Ingham     }
53933df7cd3SJim Ingham 
540b9c1b51eSKate Stone     const OptionDefinition *GetDefinitions() override { return g_option_table; }
54133df7cd3SJim Ingham 
54233df7cd3SJim Ingham     // Options table: Required for subclasses of Options.
54333df7cd3SJim Ingham 
54433df7cd3SJim Ingham     static OptionDefinition g_option_table[];
54533df7cd3SJim Ingham 
54633df7cd3SJim Ingham     // Instance variables to hold the values for command options.
54733df7cd3SJim Ingham     bool m_use_dummy;
54833df7cd3SJim Ingham   };
54933df7cd3SJim Ingham 
5505a988416SJim Ingham protected:
551b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
55233df7cd3SJim Ingham     Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
55330fdc8d8SChris Lattner 
554b9c1b51eSKate Stone     if (target == nullptr) {
555b9c1b51eSKate Stone       result.AppendError("There is not a current executable; there are no "
556b9c1b51eSKate Stone                          "breakpoints from which to delete commands");
55730fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
55830fdc8d8SChris Lattner       return false;
55930fdc8d8SChris Lattner     }
56030fdc8d8SChris Lattner 
56130fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
56230fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
56330fdc8d8SChris Lattner 
564b9c1b51eSKate Stone     if (num_breakpoints == 0) {
56593e0f19fSCaroline Tice       result.AppendError("No breakpoints exist to have commands deleted");
56630fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
56730fdc8d8SChris Lattner       return false;
56830fdc8d8SChris Lattner     }
56930fdc8d8SChris Lattner 
570b9c1b51eSKate Stone     if (command.GetArgumentCount() == 0) {
571b9c1b51eSKate Stone       result.AppendError(
572b9c1b51eSKate Stone           "No breakpoint specified from which to delete the commands");
57330fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
57430fdc8d8SChris Lattner       return false;
57530fdc8d8SChris Lattner     }
57630fdc8d8SChris Lattner 
57730fdc8d8SChris Lattner     BreakpointIDList valid_bp_ids;
578b9c1b51eSKate Stone     CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
579b9c1b51eSKate Stone         command, target, result, &valid_bp_ids);
58030fdc8d8SChris Lattner 
581b9c1b51eSKate Stone     if (result.Succeeded()) {
582c982c768SGreg Clayton       const size_t count = valid_bp_ids.GetSize();
583b9c1b51eSKate Stone       for (size_t i = 0; i < count; ++i) {
58430fdc8d8SChris Lattner         BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
585b9c1b51eSKate Stone         if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
586b9c1b51eSKate Stone           Breakpoint *bp =
587b9c1b51eSKate Stone               target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
588b9c1b51eSKate Stone           if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
589b9c1b51eSKate Stone             BreakpointLocationSP bp_loc_sp(
590b9c1b51eSKate Stone                 bp->FindLocationByID(cur_bp_id.GetLocationID()));
59130fdc8d8SChris Lattner             if (bp_loc_sp)
59230fdc8d8SChris Lattner               bp_loc_sp->ClearCallback();
593b9c1b51eSKate Stone             else {
59430fdc8d8SChris Lattner               result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n",
59530fdc8d8SChris Lattner                                            cur_bp_id.GetBreakpointID(),
59630fdc8d8SChris Lattner                                            cur_bp_id.GetLocationID());
59730fdc8d8SChris Lattner               result.SetStatus(eReturnStatusFailed);
59830fdc8d8SChris Lattner               return false;
59930fdc8d8SChris Lattner             }
600b9c1b51eSKate Stone           } else {
60130fdc8d8SChris Lattner             bp->ClearCallback();
60230fdc8d8SChris Lattner           }
60330fdc8d8SChris Lattner         }
60430fdc8d8SChris Lattner       }
60530fdc8d8SChris Lattner     }
60630fdc8d8SChris Lattner     return result.Succeeded();
60730fdc8d8SChris Lattner   }
608c8ecc2a9SEugene Zelenko 
60933df7cd3SJim Ingham private:
61033df7cd3SJim Ingham   CommandOptions m_options;
6115a988416SJim Ingham };
61230fdc8d8SChris Lattner 
61333df7cd3SJim Ingham OptionDefinition
614b9c1b51eSKate Stone     CommandObjectBreakpointCommandDelete::CommandOptions::g_option_table[] = {
615ac9c3a62SKate Stone         // clang-format off
616ac9c3a62SKate Stone   {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."},
617c8ecc2a9SEugene Zelenko   {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
618ac9c3a62SKate Stone         // clang-format on
61933df7cd3SJim Ingham };
62033df7cd3SJim Ingham 
62130fdc8d8SChris Lattner //-------------------------------------------------------------------------
62230fdc8d8SChris Lattner // CommandObjectBreakpointCommandList
62330fdc8d8SChris Lattner //-------------------------------------------------------------------------
62430fdc8d8SChris Lattner 
625b9c1b51eSKate Stone class CommandObjectBreakpointCommandList : public CommandObjectParsed {
6265a988416SJim Ingham public:
627b9c1b51eSKate Stone   CommandObjectBreakpointCommandList(CommandInterpreter &interpreter)
628b9c1b51eSKate Stone       : CommandObjectParsed(interpreter, "list", "List the script or set of "
629b9c1b51eSKate Stone                                                  "commands to be executed when "
630b9c1b51eSKate Stone                                                  "the breakpoint is hit.",
631b9c1b51eSKate Stone                             nullptr) {
632405fe67fSCaroline Tice     CommandArgumentEntry arg;
633405fe67fSCaroline Tice     CommandArgumentData bp_id_arg;
634405fe67fSCaroline Tice 
635405fe67fSCaroline Tice     // Define the first (and only) variant of this arg.
636405fe67fSCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
637405fe67fSCaroline Tice     bp_id_arg.arg_repetition = eArgRepeatPlain;
638405fe67fSCaroline Tice 
639b9c1b51eSKate Stone     // There is only one variant this argument could be; put it into the
640b9c1b51eSKate Stone     // argument entry.
641405fe67fSCaroline Tice     arg.push_back(bp_id_arg);
642405fe67fSCaroline Tice 
643405fe67fSCaroline Tice     // Push the data for the first argument into the m_arguments vector.
644405fe67fSCaroline Tice     m_arguments.push_back(arg);
64530fdc8d8SChris Lattner   }
64630fdc8d8SChris Lattner 
647c8ecc2a9SEugene Zelenko   ~CommandObjectBreakpointCommandList() override = default;
64830fdc8d8SChris Lattner 
6495a988416SJim Ingham protected:
650b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
651a7015092SGreg Clayton     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
65230fdc8d8SChris Lattner 
653b9c1b51eSKate Stone     if (target == nullptr) {
654b9c1b51eSKate Stone       result.AppendError("There is not a current executable; there are no "
655b9c1b51eSKate Stone                          "breakpoints for which to list commands");
65630fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
65730fdc8d8SChris Lattner       return false;
65830fdc8d8SChris Lattner     }
65930fdc8d8SChris Lattner 
66030fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
66130fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
66230fdc8d8SChris Lattner 
663b9c1b51eSKate Stone     if (num_breakpoints == 0) {
66430fdc8d8SChris Lattner       result.AppendError("No breakpoints exist for which to list commands");
66530fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
66630fdc8d8SChris Lattner       return false;
66730fdc8d8SChris Lattner     }
66830fdc8d8SChris Lattner 
669b9c1b51eSKate Stone     if (command.GetArgumentCount() == 0) {
670b9c1b51eSKate Stone       result.AppendError(
671b9c1b51eSKate Stone           "No breakpoint specified for which to list the commands");
67230fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
67330fdc8d8SChris Lattner       return false;
67430fdc8d8SChris Lattner     }
67530fdc8d8SChris Lattner 
67630fdc8d8SChris Lattner     BreakpointIDList valid_bp_ids;
677b9c1b51eSKate Stone     CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
678b9c1b51eSKate Stone         command, target, result, &valid_bp_ids);
67930fdc8d8SChris Lattner 
680b9c1b51eSKate Stone     if (result.Succeeded()) {
681c982c768SGreg Clayton       const size_t count = valid_bp_ids.GetSize();
682b9c1b51eSKate Stone       for (size_t i = 0; i < count; ++i) {
68330fdc8d8SChris Lattner         BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
684b9c1b51eSKate Stone         if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
685b9c1b51eSKate Stone           Breakpoint *bp =
686b9c1b51eSKate Stone               target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
68730fdc8d8SChris Lattner 
688b9c1b51eSKate Stone           if (bp) {
689c8ecc2a9SEugene Zelenko             const BreakpointOptions *bp_options = nullptr;
690b9c1b51eSKate Stone             if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
691b9c1b51eSKate Stone               BreakpointLocationSP bp_loc_sp(
692b9c1b51eSKate Stone                   bp->FindLocationByID(cur_bp_id.GetLocationID()));
69330fdc8d8SChris Lattner               if (bp_loc_sp)
69405407f6bSJim Ingham                 bp_options = bp_loc_sp->GetOptionsNoCreate();
695b9c1b51eSKate Stone               else {
69630fdc8d8SChris Lattner                 result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n",
69730fdc8d8SChris Lattner                                              cur_bp_id.GetBreakpointID(),
69830fdc8d8SChris Lattner                                              cur_bp_id.GetLocationID());
69930fdc8d8SChris Lattner                 result.SetStatus(eReturnStatusFailed);
70030fdc8d8SChris Lattner                 return false;
70130fdc8d8SChris Lattner               }
702b9c1b51eSKate Stone             } else {
70330fdc8d8SChris Lattner               bp_options = bp->GetOptions();
70430fdc8d8SChris Lattner             }
70530fdc8d8SChris Lattner 
706b9c1b51eSKate Stone             if (bp_options) {
70730fdc8d8SChris Lattner               StreamString id_str;
708e16c50a1SJim Ingham               BreakpointID::GetCanonicalReference(&id_str,
709e16c50a1SJim Ingham                                                   cur_bp_id.GetBreakpointID(),
710e16c50a1SJim Ingham                                                   cur_bp_id.GetLocationID());
7111b54c88cSJim Ingham               const Baton *baton = bp_options->GetBaton();
712b9c1b51eSKate Stone               if (baton) {
713b9c1b51eSKate Stone                 result.GetOutputStream().Printf("Breakpoint %s:\n",
714b9c1b51eSKate Stone                                                 id_str.GetData());
71530fdc8d8SChris Lattner                 result.GetOutputStream().IndentMore();
716b9c1b51eSKate Stone                 baton->GetDescription(&result.GetOutputStream(),
717b9c1b51eSKate Stone                                       eDescriptionLevelFull);
71830fdc8d8SChris Lattner                 result.GetOutputStream().IndentLess();
719b9c1b51eSKate Stone               } else {
720b9c1b51eSKate Stone                 result.AppendMessageWithFormat(
721b9c1b51eSKate Stone                     "Breakpoint %s does not have an associated command.\n",
722e16c50a1SJim Ingham                     id_str.GetData());
72330fdc8d8SChris Lattner               }
72430fdc8d8SChris Lattner             }
72530fdc8d8SChris Lattner             result.SetStatus(eReturnStatusSuccessFinishResult);
726b9c1b51eSKate Stone           } else {
727b9c1b51eSKate Stone             result.AppendErrorWithFormat("Invalid breakpoint ID: %u.\n",
728b9c1b51eSKate Stone                                          cur_bp_id.GetBreakpointID());
72930fdc8d8SChris Lattner             result.SetStatus(eReturnStatusFailed);
73030fdc8d8SChris Lattner           }
73130fdc8d8SChris Lattner         }
73230fdc8d8SChris Lattner       }
73330fdc8d8SChris Lattner     }
73430fdc8d8SChris Lattner 
73530fdc8d8SChris Lattner     return result.Succeeded();
73630fdc8d8SChris Lattner   }
7375a988416SJim Ingham };
73830fdc8d8SChris Lattner 
73930fdc8d8SChris Lattner //-------------------------------------------------------------------------
74030fdc8d8SChris Lattner // CommandObjectBreakpointCommand
74130fdc8d8SChris Lattner //-------------------------------------------------------------------------
74230fdc8d8SChris Lattner 
743b9c1b51eSKate Stone CommandObjectBreakpointCommand::CommandObjectBreakpointCommand(
744b9c1b51eSKate Stone     CommandInterpreter &interpreter)
7457428a18cSKate Stone     : CommandObjectMultiword(
746b9c1b51eSKate Stone           interpreter, "command", "Commands for adding, removing and listing "
747b9c1b51eSKate Stone                                   "LLDB commands executed when a breakpoint is "
748b9c1b51eSKate Stone                                   "hit.",
749b9c1b51eSKate Stone           "command <sub-command> [<sub-command-options>] <breakpoint-id>") {
750b9c1b51eSKate Stone   CommandObjectSP add_command_object(
751b9c1b51eSKate Stone       new CommandObjectBreakpointCommandAdd(interpreter));
752b9c1b51eSKate Stone   CommandObjectSP delete_command_object(
753b9c1b51eSKate Stone       new CommandObjectBreakpointCommandDelete(interpreter));
754b9c1b51eSKate Stone   CommandObjectSP list_command_object(
755b9c1b51eSKate Stone       new CommandObjectBreakpointCommandList(interpreter));
75630fdc8d8SChris Lattner 
75730fdc8d8SChris Lattner   add_command_object->SetCommandName("breakpoint command add");
75893e0f19fSCaroline Tice   delete_command_object->SetCommandName("breakpoint command delete");
75930fdc8d8SChris Lattner   list_command_object->SetCommandName("breakpoint command list");
76030fdc8d8SChris Lattner 
76123f59509SGreg Clayton   LoadSubCommand("add", add_command_object);
76223f59509SGreg Clayton   LoadSubCommand("delete", delete_command_object);
76323f59509SGreg Clayton   LoadSubCommand("list", list_command_object);
76430fdc8d8SChris Lattner }
76530fdc8d8SChris Lattner 
766c8ecc2a9SEugene Zelenko CommandObjectBreakpointCommand::~CommandObjectBreakpointCommand() = default;
767