]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/lldb/source/Commands/CommandObjectBreakpointCommand.cpp
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / lldb / source / Commands / CommandObjectBreakpointCommand.cpp
1 //===-- CommandObjectBreakpointCommand.cpp ----------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/lldb-python.h"
11
12 // C Includes
13 // C++ Includes
14
15
16 #include "CommandObjectBreakpointCommand.h"
17 #include "CommandObjectBreakpoint.h"
18
19 #include "lldb/Core/IOHandler.h"
20 #include "lldb/Interpreter/CommandInterpreter.h"
21 #include "lldb/Interpreter/CommandReturnObject.h"
22 #include "lldb/Target/Target.h"
23 #include "lldb/Target/Thread.h"
24 #include "lldb/Breakpoint/BreakpointIDList.h"
25 #include "lldb/Breakpoint/Breakpoint.h"
26 #include "lldb/Breakpoint/BreakpointLocation.h"
27 #include "lldb/Breakpoint/StoppointCallbackContext.h"
28 #include "lldb/Core/State.h"
29
30 using namespace lldb;
31 using namespace lldb_private;
32
33 //-------------------------------------------------------------------------
34 // CommandObjectBreakpointCommandAdd
35 //-------------------------------------------------------------------------
36
37
38 class CommandObjectBreakpointCommandAdd :
39     public CommandObjectParsed,
40     public IOHandlerDelegateMultiline
41 {
42 public:
43
44     CommandObjectBreakpointCommandAdd (CommandInterpreter &interpreter) :
45         CommandObjectParsed (interpreter,
46                              "add",
47                              "Add a set of commands to a breakpoint, to be executed whenever the breakpoint is hit.",
48                              NULL),
49     IOHandlerDelegateMultiline ("DONE", IOHandlerDelegate::Completion::LLDBCommand),
50         m_options (interpreter)
51     {
52         SetHelpLong (
53 "\nGeneral information about entering breakpoint commands\n\
54 ------------------------------------------------------\n\
55 \n\
56 This command will cause you to be prompted to enter the command or set of\n\
57 commands you wish to be executed when the specified breakpoint is hit. You\n\
58 will be told to enter your command(s), and will see a '> 'prompt. Because\n\
59 you can enter one or many commands to be executed when a breakpoint is hit,\n\
60 you will continue to be prompted after each new-line that you enter, until you\n\
61 enter the word 'DONE', which will cause the commands you have entered to be\n\
62 stored with the breakpoint and executed when the breakpoint is hit.\n\
63 \n\
64 Syntax checking is not necessarily done when breakpoint commands are entered.\n\
65 An improperly written breakpoint command will attempt to get executed when the\n\
66 breakpoint gets hit, and usually silently fail.  If your breakpoint command does\n\
67 not appear to be getting executed, go back and check your syntax.\n\
68 \n\
69 Special information about PYTHON breakpoint commands\n\
70 ----------------------------------------------------\n\
71 \n\
72 You may enter either one line of Python, multiple lines of Python (including\n\
73 function definitions), or specify a Python function in a module that has already,\n\
74 or will be imported.  If you enter a single line of Python, that will be passed\n\
75 to the Python interpreter 'as is' when the breakpoint gets hit.  If you enter\n\
76 function definitions, they will be passed to the Python interpreter as soon as\n\
77 you finish entering the breakpoint command, and they can be called later (don't\n\
78 forget to add calls to them, if you want them called when the breakpoint is\n\
79 hit).  If you enter multiple lines of Python that are not function definitions,\n\
80 they will be collected into a new, automatically generated Python function, and\n\
81 a call to the newly generated function will be attached to the breakpoint.\n\
82 \n\
83 \n\
84 This auto-generated function is passed in three arguments:\n\
85 \n\
86     frame:  a lldb.SBFrame object for the frame which hit breakpoint.\n\
87     bp_loc: a lldb.SBBreakpointLocation object that represents the breakpoint\n\
88             location that was hit.\n\
89     dict:   the python session dictionary hit.\n\
90 \n\
91 When specifying a python function with the --python-function option, you need\n\
92 to supply the function name prepended by the module name. So if you import a\n\
93 module named 'myutils' that contains a 'breakpoint_callback' function, you would\n\
94 specify the option as:\n\
95 \n\
96     --python-function myutils.breakpoint_callback\n\
97 \n\
98 The function itself must have the following prototype:\n\
99 \n\
100 def breakpoint_callback(frame, bp_loc, dict):\n\
101   # Your code goes here\n\
102 \n\
103 The arguments are the same as the 3 auto generation function arguments listed\n\
104 above. Note that the global variable 'lldb.frame' will NOT be setup when this\n\
105 function is called, so be sure to use the 'frame' argument. The 'frame' argument\n\
106 can get you to the thread (frame.GetThread()), the thread can get you to the\n\
107 process (thread.GetProcess()), and the process can get you back to the target\n\
108 (process.GetTarget()).\n\
109 \n\
110 Important Note: Because loose Python code gets collected into functions, if you\n\
111 want to access global variables in the 'loose' code, you need to specify that\n\
112 they are global, using the 'global' keyword.  Be sure to use correct Python\n\
113 syntax, including indentation, when entering Python breakpoint commands.\n\
114 \n\
115 As a third option, you can pass the name of an already existing Python function\n\
116 and that function will be attached to the breakpoint. It will get passed the\n\
117 frame and bp_loc arguments mentioned above.\n\
118 \n\
119 Example Python one-line breakpoint command:\n\
120 \n\
121 (lldb) breakpoint command add -s python 1\n\
122 Enter your Python command(s). Type 'DONE' to end.\n\
123 > print \"Hit this breakpoint!\"\n\
124 > DONE\n\
125 \n\
126 As a convenience, this also works for a short Python one-liner:\n\
127 (lldb) breakpoint command add -s python 1 -o \"import time; print time.asctime()\"\n\
128 (lldb) run\n\
129 Launching '.../a.out'  (x86_64)\n\
130 (lldb) Fri Sep 10 12:17:45 2010\n\
131 Process 21778 Stopped\n\
132 * thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread\n\
133   36    \n\
134   37    int c(int val)\n\
135   38    {\n\
136   39 ->     return val + 3;\n\
137   40    }\n\
138   41    \n\
139   42    int main (int argc, char const *argv[])\n\
140 (lldb)\n\
141 \n\
142 Example multiple line Python breakpoint command, using function definition:\n\
143 \n\
144 (lldb) breakpoint command add -s python 1\n\
145 Enter your Python command(s). Type 'DONE' to end.\n\
146 > def breakpoint_output (bp_no):\n\
147 >     out_string = \"Hit breakpoint number \" + repr (bp_no)\n\
148 >     print out_string\n\
149 >     return True\n\
150 > breakpoint_output (1)\n\
151 > DONE\n\
152 \n\
153 \n\
154 Example multiple line Python breakpoint command, using 'loose' Python:\n\
155 \n\
156 (lldb) breakpoint command add -s p 1\n\
157 Enter your Python command(s). Type 'DONE' to end.\n\
158 > global bp_count\n\
159 > bp_count = bp_count + 1\n\
160 > print \"Hit this breakpoint \" + repr(bp_count) + \" times!\"\n\
161 > DONE\n\
162 \n\
163 In this case, since there is a reference to a global variable,\n\
164 'bp_count', you will also need to make sure 'bp_count' exists and is\n\
165 initialized:\n\
166 \n\
167 (lldb) script\n\
168 >>> bp_count = 0\n\
169 >>> quit()\n\
170 \n\
171 (lldb)\n\
172 \n\
173 \n\
174 Your Python code, however organized, can optionally return a value.\n\
175 If the returned value is False, that tells LLDB not to stop at the breakpoint\n\
176 to which the code is associated. Returning anything other than False, or even\n\
177 returning None, or even omitting a return statement entirely, will cause\n\
178 LLDB to stop.\n\
179 \n\
180 Final Note:  If you get a warning that no breakpoint command was generated, but\n\
181 you did not get any syntax errors, you probably forgot to add a call to your\n\
182 functions.\n\
183 \n\
184 Special information about debugger command breakpoint commands\n\
185 --------------------------------------------------------------\n\
186 \n\
187 You may enter any debugger command, exactly as you would at the debugger prompt.\n\
188 You may enter as many debugger commands as you like, but do NOT enter more than\n\
189 one command per line.\n" );
190
191         CommandArgumentEntry arg;
192         CommandArgumentData bp_id_arg;
193
194         // Define the first (and only) variant of this arg.
195         bp_id_arg.arg_type = eArgTypeBreakpointID;
196         bp_id_arg.arg_repetition = eArgRepeatPlain;
197
198         // There is only one variant this argument could be; put it into the argument entry.
199         arg.push_back (bp_id_arg);
200
201         // Push the data for the first argument into the m_arguments vector.
202         m_arguments.push_back (arg);
203     }
204
205     virtual
206     ~CommandObjectBreakpointCommandAdd () {}
207
208     virtual Options *
209     GetOptions ()
210     {
211         return &m_options;
212     }
213
214     virtual void
215     IOHandlerActivated (IOHandler &io_handler)
216     {
217         StreamFileSP output_sp(io_handler.GetOutputStreamFile());
218         if (output_sp)
219         {
220             output_sp->PutCString(g_reader_instructions);
221             output_sp->Flush();
222         }
223     }
224     
225     
226     virtual void
227     IOHandlerInputComplete (IOHandler &io_handler, std::string &line)
228     {
229         io_handler.SetIsDone(true);
230         
231         BreakpointOptions *bp_options = (BreakpointOptions *) io_handler.GetUserData();
232         if (bp_options)
233         {
234             std::unique_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData());
235             if (data_ap.get())
236             {
237                 data_ap->user_source.SplitIntoLines (line.c_str(), line.size());
238                 BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release()));
239                 bp_options->SetCallback (BreakpointOptionsCallbackFunction, baton_sp);
240             }
241         }
242
243     }
244     
245     void
246     CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options, 
247                                              CommandReturnObject &result)
248     {
249         m_interpreter.GetLLDBCommandsFromIOHandler ("> ",           // Prompt
250                                                     *this,          // IOHandlerDelegate
251                                                     true,           // Run IOHandler in async mode
252                                                     bp_options);    // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
253     }
254     
255     /// Set a one-liner as the callback for the breakpoint.
256     void 
257     SetBreakpointCommandCallback (BreakpointOptions *bp_options,
258                                   const char *oneliner)
259     {
260         std::unique_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData());
261
262         // It's necessary to set both user_source and script_source to the oneliner.
263         // The former is used to generate callback description (as in breakpoint command list)
264         // while the latter is used for Python to interpret during the actual callback.
265         data_ap->user_source.AppendString (oneliner);
266         data_ap->script_source.assign (oneliner);
267         data_ap->stop_on_error = m_options.m_stop_on_error;
268
269         BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release()));
270         bp_options->SetCallback (BreakpointOptionsCallbackFunction, baton_sp);
271
272         return;
273     }
274     
275     static bool
276     BreakpointOptionsCallbackFunction (void *baton,
277                                        StoppointCallbackContext *context, 
278                                        lldb::user_id_t break_id,
279                                        lldb::user_id_t break_loc_id)
280     {
281         bool ret_value = true;
282         if (baton == NULL)
283             return true;
284         
285         
286         BreakpointOptions::CommandData *data = (BreakpointOptions::CommandData *) baton;
287         StringList &commands = data->user_source;
288         
289         if (commands.GetSize() > 0)
290         {
291             ExecutionContext exe_ctx (context->exe_ctx_ref);
292             Target *target = exe_ctx.GetTargetPtr();
293             if (target)
294             {
295                 CommandReturnObject result;
296                 Debugger &debugger = target->GetDebugger();
297                 // Rig up the results secondary output stream to the debugger's, so the output will come out synchronously
298                 // if the debugger is set up that way.
299                     
300                 StreamSP output_stream (debugger.GetAsyncOutputStream());
301                 StreamSP error_stream (debugger.GetAsyncErrorStream());
302                 result.SetImmediateOutputStream (output_stream);
303                 result.SetImmediateErrorStream (error_stream);
304         
305                 bool stop_on_continue = true;
306                 bool echo_commands    = false;
307                 bool print_results    = true;
308
309                 debugger.GetCommandInterpreter().HandleCommands (commands, 
310                                                                  &exe_ctx,
311                                                                  stop_on_continue, 
312                                                                  data->stop_on_error, 
313                                                                  echo_commands, 
314                                                                  print_results,
315                                                                  eLazyBoolNo,
316                                                                  result);
317                 result.GetImmediateOutputStream()->Flush();
318                 result.GetImmediateErrorStream()->Flush();
319            }
320         }
321         return ret_value;
322     }    
323
324     class CommandOptions : public Options
325     {
326     public:
327
328         CommandOptions (CommandInterpreter &interpreter) :
329             Options (interpreter),
330             m_use_commands (false),
331             m_use_script_language (false),
332             m_script_language (eScriptLanguageNone),
333             m_use_one_liner (false),
334             m_one_liner(),
335             m_function_name()
336         {
337         }
338
339         virtual
340         ~CommandOptions () {}
341
342         virtual Error
343         SetOptionValue (uint32_t option_idx, const char *option_arg)
344         {
345             Error error;
346             const int short_option = m_getopt_table[option_idx].val;
347
348             switch (short_option)
349             {
350             case 'o':
351                 m_use_one_liner = true;
352                 m_one_liner = option_arg;
353                 break;
354
355             case 's':
356                 m_script_language = (lldb::ScriptLanguage) Args::StringToOptionEnum (option_arg, 
357                                                                                      g_option_table[option_idx].enum_values, 
358                                                                                      eScriptLanguageNone,
359                                                                                      error);
360
361                 if (m_script_language == eScriptLanguagePython || m_script_language == eScriptLanguageDefault)
362                 {
363                     m_use_script_language = true;
364                 }
365                 else
366                 {
367                     m_use_script_language = false;
368                 }          
369                 break;
370
371             case 'e':
372                 {
373                     bool success = false;
374                     m_stop_on_error = Args::StringToBoolean(option_arg, false, &success);
375                     if (!success)
376                         error.SetErrorStringWithFormat("invalid value for stop-on-error: \"%s\"", option_arg);
377                 }
378                 break;
379                     
380             case 'F':
381                 {
382                     m_use_one_liner = false;
383                     m_use_script_language = true;
384                     m_function_name.assign(option_arg);
385                 }
386                 break;
387
388             default:
389                 break;
390             }
391             return error;
392         }
393         void
394         OptionParsingStarting ()
395         {
396             m_use_commands = true;
397             m_use_script_language = false;
398             m_script_language = eScriptLanguageNone;
399
400             m_use_one_liner = false;
401             m_stop_on_error = true;
402             m_one_liner.clear();
403             m_function_name.clear();
404         }
405
406         const OptionDefinition*
407         GetDefinitions ()
408         {
409             return g_option_table;
410         }
411
412         // Options table: Required for subclasses of Options.
413
414         static OptionDefinition g_option_table[];
415
416         // Instance variables to hold the values for command options.
417
418         bool m_use_commands;
419         bool m_use_script_language;
420         lldb::ScriptLanguage m_script_language;
421
422         // Instance variables to hold the values for one_liner options.
423         bool m_use_one_liner;
424         std::string m_one_liner;
425         bool m_stop_on_error;
426         std::string m_function_name;
427     };
428
429 protected:
430     virtual bool
431     DoExecute (Args& command, CommandReturnObject &result)
432     {
433         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
434
435         if (target == NULL)
436         {
437             result.AppendError ("There is not a current executable; there are no breakpoints to which to add commands");
438             result.SetStatus (eReturnStatusFailed);
439             return false;
440         }
441
442         const BreakpointList &breakpoints = target->GetBreakpointList();
443         size_t num_breakpoints = breakpoints.GetSize();
444
445         if (num_breakpoints == 0)
446         {
447             result.AppendError ("No breakpoints exist to have commands added");
448             result.SetStatus (eReturnStatusFailed);
449             return false;
450         }
451
452         if (m_options.m_use_script_language == false && m_options.m_function_name.size())
453         {
454             result.AppendError ("need to enable scripting to have a function run as a breakpoint command");
455             result.SetStatus (eReturnStatusFailed);
456             return false;
457         }
458         
459         BreakpointIDList valid_bp_ids;
460         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
461
462         if (result.Succeeded())
463         {
464             const size_t count = valid_bp_ids.GetSize();
465             if (count > 1)
466             {
467                 result.AppendError ("can only add commands to one breakpoint at a time.");
468                 result.SetStatus (eReturnStatusFailed);
469                 return false;
470             }
471             
472             for (size_t i = 0; i < count; ++i)
473             {
474                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
475                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
476                 {
477                     Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
478                     BreakpointOptions *bp_options = NULL;
479                     if (cur_bp_id.GetLocationID() == LLDB_INVALID_BREAK_ID)
480                     {
481                         // This breakpoint does not have an associated location.
482                         bp_options = bp->GetOptions();
483                     }
484                     else                    
485                     {
486                         BreakpointLocationSP bp_loc_sp(bp->FindLocationByID (cur_bp_id.GetLocationID()));
487                         // This breakpoint does have an associated location.
488                         // Get its breakpoint options.
489                         if (bp_loc_sp)
490                             bp_options = bp_loc_sp->GetLocationOptions();
491                     }
492
493                     // Skip this breakpoint if bp_options is not good.
494                     if (bp_options == NULL) continue;
495
496                     // If we are using script language, get the script interpreter
497                     // in order to set or collect command callback.  Otherwise, call
498                     // the methods associated with this object.
499                     if (m_options.m_use_script_language)
500                     {
501                         // Special handling for one-liner specified inline.
502                         if (m_options.m_use_one_liner)
503                         {
504                             m_interpreter.GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options,
505                                                                                                 m_options.m_one_liner.c_str());
506                         }
507                         // Special handling for using a Python function by name
508                         // instead of extending the breakpoint callback data structures, we just automatize
509                         // what the user would do manually: make their breakpoint command be a function call
510                         else if (m_options.m_function_name.size())
511                         {
512                             std::string oneliner("return ");
513                             oneliner += m_options.m_function_name;
514                             oneliner += "(frame, bp_loc, internal_dict)";
515                             m_interpreter.GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options,
516                                                                                                 oneliner.c_str());
517                         }
518                         else
519                         {
520                             m_interpreter.GetScriptInterpreter()->CollectDataForBreakpointCommandCallback (bp_options,
521                                                                                                            result);
522                         }
523                     }
524                     else
525                     {
526                         // Special handling for one-liner specified inline.
527                         if (m_options.m_use_one_liner)
528                             SetBreakpointCommandCallback (bp_options,
529                                                           m_options.m_one_liner.c_str());
530                         else
531                             CollectDataForBreakpointCommandCallback (bp_options, 
532                                                                      result);
533                     }
534                 }
535             }
536         }
537
538         return result.Succeeded();
539     }
540
541 private:
542     CommandOptions m_options;
543     static const char *g_reader_instructions;
544
545 };
546
547 const char *
548 CommandObjectBreakpointCommandAdd::g_reader_instructions = "Enter your debugger command(s).  Type 'DONE' to end.\n";
549
550 // FIXME: "script-type" needs to have its contents determined dynamically, so somebody can add a new scripting
551 // language to lldb and have it pickable here without having to change this enumeration by hand and rebuild lldb proper.
552
553 static OptionEnumValueElement
554 g_script_option_enumeration[4] =
555 {
556     { eScriptLanguageNone,    "command",         "Commands are in the lldb command interpreter language"},
557     { eScriptLanguagePython,  "python",          "Commands are in the Python language."},
558     { eSortOrderByName,       "default-script",  "Commands are in the default scripting language."},
559     { 0,                      NULL,              NULL }
560 };
561
562 OptionDefinition
563 CommandObjectBreakpointCommandAdd::CommandOptions::g_option_table[] =
564 {
565     { LLDB_OPT_SET_1, false, "one-liner", 'o', OptionParser::eRequiredArgument, NULL, 0, eArgTypeOneLiner,
566         "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." },
567
568     { LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean,
569         "Specify whether breakpoint command execution should terminate on error." },
570
571     { LLDB_OPT_SET_ALL,   false, "script-type",     's', OptionParser::eRequiredArgument, g_script_option_enumeration, 0, eArgTypeNone,
572         "Specify the language for the commands - if none is specified, the lldb command interpreter will be used."},
573
574     { LLDB_OPT_SET_2,   false, "python-function",     'F', OptionParser::eRequiredArgument, NULL, 0, eArgTypePythonFunction,
575         "Give the name of a Python function to run as command for this breakpoint. Be sure to give a module name if appropriate."},
576     
577     { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
578 };
579
580 //-------------------------------------------------------------------------
581 // CommandObjectBreakpointCommandDelete
582 //-------------------------------------------------------------------------
583
584 class CommandObjectBreakpointCommandDelete : public CommandObjectParsed
585 {
586 public:
587     CommandObjectBreakpointCommandDelete (CommandInterpreter &interpreter) :
588         CommandObjectParsed (interpreter, 
589                              "delete",
590                              "Delete the set of commands from a breakpoint.",
591                              NULL)
592     {
593         CommandArgumentEntry arg;
594         CommandArgumentData bp_id_arg;
595
596         // Define the first (and only) variant of this arg.
597         bp_id_arg.arg_type = eArgTypeBreakpointID;
598         bp_id_arg.arg_repetition = eArgRepeatPlain;
599
600         // There is only one variant this argument could be; put it into the argument entry.
601         arg.push_back (bp_id_arg);
602
603         // Push the data for the first argument into the m_arguments vector.
604         m_arguments.push_back (arg);
605     }
606
607
608     virtual
609     ~CommandObjectBreakpointCommandDelete () {}
610
611 protected:
612     virtual bool
613     DoExecute (Args& command, CommandReturnObject &result)
614     {
615         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
616
617         if (target == NULL)
618         {
619             result.AppendError ("There is not a current executable; there are no breakpoints from which to delete commands");
620             result.SetStatus (eReturnStatusFailed);
621             return false;
622         }
623
624         const BreakpointList &breakpoints = target->GetBreakpointList();
625         size_t num_breakpoints = breakpoints.GetSize();
626
627         if (num_breakpoints == 0)
628         {
629             result.AppendError ("No breakpoints exist to have commands deleted");
630             result.SetStatus (eReturnStatusFailed);
631             return false;
632         }
633
634         if (command.GetArgumentCount() == 0)
635         {
636             result.AppendError ("No breakpoint specified from which to delete the commands");
637             result.SetStatus (eReturnStatusFailed);
638             return false;
639         }
640
641         BreakpointIDList valid_bp_ids;
642         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
643
644         if (result.Succeeded())
645         {
646             const size_t count = valid_bp_ids.GetSize();
647             for (size_t i = 0; i < count; ++i)
648             {
649                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
650                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
651                 {
652                     Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
653                     if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
654                     {
655                         BreakpointLocationSP bp_loc_sp (bp->FindLocationByID (cur_bp_id.GetLocationID()));
656                         if (bp_loc_sp)
657                             bp_loc_sp->ClearCallback();
658                         else
659                         {
660                             result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n", 
661                                                          cur_bp_id.GetBreakpointID(),
662                                                          cur_bp_id.GetLocationID());
663                             result.SetStatus (eReturnStatusFailed);
664                             return false;
665                         }
666                     }
667                     else
668                     {
669                         bp->ClearCallback();
670                     }
671                 }
672             }
673         }
674         return result.Succeeded();
675     }
676 };
677
678 //-------------------------------------------------------------------------
679 // CommandObjectBreakpointCommandList
680 //-------------------------------------------------------------------------
681
682 class CommandObjectBreakpointCommandList : public CommandObjectParsed
683 {
684 public:
685     CommandObjectBreakpointCommandList (CommandInterpreter &interpreter) :
686         CommandObjectParsed (interpreter,
687                              "list",
688                              "List the script or set of commands to be executed when the breakpoint is hit.",
689                               NULL)
690     {
691         CommandArgumentEntry arg;
692         CommandArgumentData bp_id_arg;
693
694         // Define the first (and only) variant of this arg.
695         bp_id_arg.arg_type = eArgTypeBreakpointID;
696         bp_id_arg.arg_repetition = eArgRepeatPlain;
697
698         // There is only one variant this argument could be; put it into the argument entry.
699         arg.push_back (bp_id_arg);
700
701         // Push the data for the first argument into the m_arguments vector.
702         m_arguments.push_back (arg);
703     }
704
705     virtual
706     ~CommandObjectBreakpointCommandList () {}
707
708 protected:
709     virtual bool
710     DoExecute (Args& command,
711              CommandReturnObject &result)
712     {
713         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
714
715         if (target == NULL)
716         {
717             result.AppendError ("There is not a current executable; there are no breakpoints for which to list commands");
718             result.SetStatus (eReturnStatusFailed);
719             return false;
720         }
721
722         const BreakpointList &breakpoints = target->GetBreakpointList();
723         size_t num_breakpoints = breakpoints.GetSize();
724
725         if (num_breakpoints == 0)
726         {
727             result.AppendError ("No breakpoints exist for which to list commands");
728             result.SetStatus (eReturnStatusFailed);
729             return false;
730         }
731
732         if (command.GetArgumentCount() == 0)
733         {
734             result.AppendError ("No breakpoint specified for which to list the commands");
735             result.SetStatus (eReturnStatusFailed);
736             return false;
737         }
738
739         BreakpointIDList valid_bp_ids;
740         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
741
742         if (result.Succeeded())
743         {
744             const size_t count = valid_bp_ids.GetSize();
745             for (size_t i = 0; i < count; ++i)
746             {
747                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
748                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
749                 {
750                     Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
751                     
752                     if (bp)
753                     {
754                         const BreakpointOptions *bp_options = NULL;
755                         if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
756                         {
757                             BreakpointLocationSP bp_loc_sp(bp->FindLocationByID (cur_bp_id.GetLocationID()));
758                             if (bp_loc_sp)
759                                 bp_options = bp_loc_sp->GetOptionsNoCreate();
760                             else
761                             {
762                                 result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n", 
763                                                              cur_bp_id.GetBreakpointID(),
764                                                              cur_bp_id.GetLocationID());
765                                 result.SetStatus (eReturnStatusFailed);
766                                 return false;
767                             }
768                         }
769                         else
770                         {
771                             bp_options = bp->GetOptions();
772                         }
773
774                         if (bp_options)
775                         {
776                             StreamString id_str;
777                             BreakpointID::GetCanonicalReference (&id_str, 
778                                                                  cur_bp_id.GetBreakpointID(), 
779                                                                  cur_bp_id.GetLocationID());
780                             const Baton *baton = bp_options->GetBaton();
781                             if (baton)
782                             {
783                                 result.GetOutputStream().Printf ("Breakpoint %s:\n", id_str.GetData());
784                                 result.GetOutputStream().IndentMore ();
785                                 baton->GetDescription(&result.GetOutputStream(), eDescriptionLevelFull);
786                                 result.GetOutputStream().IndentLess ();
787                             }
788                             else
789                             {
790                                 result.AppendMessageWithFormat ("Breakpoint %s does not have an associated command.\n", 
791                                                                 id_str.GetData());
792                             }
793                         }
794                         result.SetStatus (eReturnStatusSuccessFinishResult);
795                     }
796                     else
797                     {
798                         result.AppendErrorWithFormat("Invalid breakpoint ID: %u.\n", cur_bp_id.GetBreakpointID());
799                         result.SetStatus (eReturnStatusFailed);
800                     }
801
802                 }
803             }
804         }
805
806         return result.Succeeded();
807     }
808 };
809
810 //-------------------------------------------------------------------------
811 // CommandObjectBreakpointCommand
812 //-------------------------------------------------------------------------
813
814 CommandObjectBreakpointCommand::CommandObjectBreakpointCommand (CommandInterpreter &interpreter) :
815     CommandObjectMultiword (interpreter,
816                             "command",
817                             "A set of commands for adding, removing and examining bits of code to be executed when the breakpoint is hit (breakpoint 'commmands').",
818                             "command <sub-command> [<sub-command-options>] <breakpoint-id>")
819 {
820     CommandObjectSP add_command_object (new CommandObjectBreakpointCommandAdd (interpreter));
821     CommandObjectSP delete_command_object (new CommandObjectBreakpointCommandDelete (interpreter));
822     CommandObjectSP list_command_object (new CommandObjectBreakpointCommandList (interpreter));
823
824     add_command_object->SetCommandName ("breakpoint command add");
825     delete_command_object->SetCommandName ("breakpoint command delete");
826     list_command_object->SetCommandName ("breakpoint command list");
827
828     LoadSubCommand ("add",    add_command_object);
829     LoadSubCommand ("delete", delete_command_object);
830     LoadSubCommand ("list",   list_command_object);
831 }
832
833 CommandObjectBreakpointCommand::~CommandObjectBreakpointCommand ()
834 {
835 }
836
837