130fdc8d8SChris Lattner //===-- CommandObjectBreakpoint.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 #include "CommandObjectBreakpoint.h"
1130fdc8d8SChris Lattner #include "CommandObjectBreakpointCommand.h"
1230fdc8d8SChris Lattner 
1330fdc8d8SChris Lattner // C Includes
1430fdc8d8SChris Lattner // C++ Includes
1530fdc8d8SChris Lattner // Other libraries and framework includes
1630fdc8d8SChris Lattner // Project includes
1730fdc8d8SChris Lattner #include "lldb/Breakpoint/Breakpoint.h"
1830fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointIDList.h"
1930fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointLocation.h"
2040af72e1SJim Ingham #include "lldb/Interpreter/Options.h"
2130fdc8d8SChris Lattner #include "lldb/Core/RegularExpression.h"
2230fdc8d8SChris Lattner #include "lldb/Core/StreamString.h"
2330fdc8d8SChris Lattner #include "lldb/Interpreter/CommandInterpreter.h"
2430fdc8d8SChris Lattner #include "lldb/Interpreter/CommandReturnObject.h"
2530fdc8d8SChris Lattner #include "lldb/Target/Target.h"
2630fdc8d8SChris Lattner #include "lldb/Interpreter/CommandCompletions.h"
2730fdc8d8SChris Lattner #include "lldb/Target/StackFrame.h"
281b54c88cSJim Ingham #include "lldb/Target/Thread.h"
291b54c88cSJim Ingham #include "lldb/Target/ThreadSpec.h"
3030fdc8d8SChris Lattner 
31b7234e40SJohnny Chen #include <vector>
32b7234e40SJohnny Chen 
3330fdc8d8SChris Lattner using namespace lldb;
3430fdc8d8SChris Lattner using namespace lldb_private;
3530fdc8d8SChris Lattner 
3630fdc8d8SChris Lattner static void
3785e8b814SJim Ingham AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level)
3830fdc8d8SChris Lattner {
3930fdc8d8SChris Lattner     s->IndentMore();
4030fdc8d8SChris Lattner     bp->GetDescription (s, level, true);
4130fdc8d8SChris Lattner     s->IndentLess();
4230fdc8d8SChris Lattner     s->EOL();
4330fdc8d8SChris Lattner }
4430fdc8d8SChris Lattner 
4530fdc8d8SChris Lattner //-------------------------------------------------------------------------
465a988416SJim Ingham // CommandObjectBreakpointSet
4730fdc8d8SChris Lattner //-------------------------------------------------------------------------
4830fdc8d8SChris Lattner 
495a988416SJim Ingham 
505a988416SJim Ingham class CommandObjectBreakpointSet : public CommandObjectParsed
515a988416SJim Ingham {
525a988416SJim Ingham public:
535a988416SJim Ingham 
545a988416SJim Ingham     typedef enum BreakpointSetType
555a988416SJim Ingham     {
565a988416SJim Ingham         eSetTypeInvalid,
575a988416SJim Ingham         eSetTypeFileAndLine,
585a988416SJim Ingham         eSetTypeAddress,
595a988416SJim Ingham         eSetTypeFunctionName,
605a988416SJim Ingham         eSetTypeFunctionRegexp,
615a988416SJim Ingham         eSetTypeSourceRegexp,
625a988416SJim Ingham         eSetTypeException
635a988416SJim Ingham     } BreakpointSetType;
645a988416SJim Ingham 
655a988416SJim Ingham     CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
665a988416SJim Ingham         CommandObjectParsed (interpreter,
675a988416SJim Ingham                              "breakpoint set",
685a988416SJim Ingham                              "Sets a breakpoint or set of breakpoints in the executable.",
695a988416SJim Ingham                              "breakpoint set <cmd-options>"),
705a988416SJim Ingham         m_options (interpreter)
715a988416SJim Ingham     {
725a988416SJim Ingham     }
735a988416SJim Ingham 
745a988416SJim Ingham 
755a988416SJim Ingham     virtual
765a988416SJim Ingham     ~CommandObjectBreakpointSet () {}
775a988416SJim Ingham 
785a988416SJim Ingham     virtual Options *
795a988416SJim Ingham     GetOptions ()
805a988416SJim Ingham     {
815a988416SJim Ingham         return &m_options;
825a988416SJim Ingham     }
835a988416SJim Ingham 
845a988416SJim Ingham     class CommandOptions : public Options
855a988416SJim Ingham     {
865a988416SJim Ingham     public:
875a988416SJim Ingham 
885a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
89eb0103f2SGreg Clayton             Options (interpreter),
907d49c9c8SJohnny Chen             m_condition (),
9187df91b8SJim Ingham             m_filenames (),
9230fdc8d8SChris Lattner             m_line_num (0),
9330fdc8d8SChris Lattner             m_column (0),
942856d462SGreg Clayton             m_check_inlines (true),
95fab10e89SJim Ingham             m_func_names (),
96fab10e89SJim Ingham             m_func_name_type_mask (eFunctionNameTypeNone),
9730fdc8d8SChris Lattner             m_func_regexp (),
98969795f1SJim Ingham             m_source_text_regexp(),
9930fdc8d8SChris Lattner             m_modules (),
1001b54c88cSJim Ingham             m_load_addr(),
101c982c768SGreg Clayton             m_ignore_count (0),
1021b54c88cSJim Ingham             m_thread_id(LLDB_INVALID_THREAD_ID),
103c982c768SGreg Clayton             m_thread_index (UINT32_MAX),
1041b54c88cSJim Ingham             m_thread_name(),
105fab10e89SJim Ingham             m_queue_name(),
106fab10e89SJim Ingham             m_catch_bp (false),
107fab10e89SJim Ingham             m_throw_bp (false),
108a8558b62SJim Ingham             m_language (eLanguageTypeUnknown),
109a8558b62SJim Ingham             m_skip_prologue (eLazyBoolCalculate)
11030fdc8d8SChris Lattner         {
11130fdc8d8SChris Lattner         }
11230fdc8d8SChris Lattner 
11330fdc8d8SChris Lattner 
1145a988416SJim Ingham         virtual
1155a988416SJim Ingham         ~CommandOptions () {}
11687df91b8SJim Ingham 
1175a988416SJim Ingham         virtual Error
1185a988416SJim Ingham         SetOptionValue (uint32_t option_idx, const char *option_arg)
11930fdc8d8SChris Lattner         {
12030fdc8d8SChris Lattner             Error error;
12130fdc8d8SChris Lattner             char short_option = (char) m_getopt_table[option_idx].val;
12230fdc8d8SChris Lattner 
12330fdc8d8SChris Lattner             switch (short_option)
12430fdc8d8SChris Lattner             {
12530fdc8d8SChris Lattner                 case 'a':
1260292f4a5SJim Ingham                     m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0);
12730fdc8d8SChris Lattner                     if (m_load_addr == LLDB_INVALID_ADDRESS)
1280292f4a5SJim Ingham                         m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16);
12930fdc8d8SChris Lattner 
13030fdc8d8SChris Lattner                     if (m_load_addr == LLDB_INVALID_ADDRESS)
13186edbf41SGreg Clayton                         error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg);
13230fdc8d8SChris Lattner                     break;
13330fdc8d8SChris Lattner 
1347d49c9c8SJohnny Chen                 case 'C':
13530fdc8d8SChris Lattner                     m_column = Args::StringToUInt32 (option_arg, 0);
13630fdc8d8SChris Lattner                     break;
1370c5cd90dSGreg Clayton 
1387d49c9c8SJohnny Chen                 case 'c':
1397d49c9c8SJohnny Chen                     m_condition.assign(option_arg);
1407d49c9c8SJohnny Chen                     break;
1417d49c9c8SJohnny Chen 
14230fdc8d8SChris Lattner                 case 'f':
14387df91b8SJim Ingham                     m_filenames.AppendIfUnique (FileSpec(option_arg, false));
14430fdc8d8SChris Lattner                     break;
1450c5cd90dSGreg Clayton 
14630fdc8d8SChris Lattner                 case 'l':
14730fdc8d8SChris Lattner                     m_line_num = Args::StringToUInt32 (option_arg, 0);
14830fdc8d8SChris Lattner                     break;
1490c5cd90dSGreg Clayton 
150e02b8504SGreg Clayton                 case 'b':
151fab10e89SJim Ingham                     m_func_names.push_back (option_arg);
1520c5cd90dSGreg Clayton                     m_func_name_type_mask |= eFunctionNameTypeBase;
1530c5cd90dSGreg Clayton                     break;
1540c5cd90dSGreg Clayton 
155e02b8504SGreg Clayton                 case 'n':
156fab10e89SJim Ingham                     m_func_names.push_back (option_arg);
157e02b8504SGreg Clayton                     m_func_name_type_mask |= eFunctionNameTypeAuto;
158e02b8504SGreg Clayton                     break;
159e02b8504SGreg Clayton 
1600c5cd90dSGreg Clayton                 case 'F':
161fab10e89SJim Ingham                     m_func_names.push_back (option_arg);
1620c5cd90dSGreg Clayton                     m_func_name_type_mask |= eFunctionNameTypeFull;
1630c5cd90dSGreg Clayton                     break;
1640c5cd90dSGreg Clayton 
1650c5cd90dSGreg Clayton                 case 'S':
166fab10e89SJim Ingham                     m_func_names.push_back (option_arg);
1670c5cd90dSGreg Clayton                     m_func_name_type_mask |= eFunctionNameTypeSelector;
1680c5cd90dSGreg Clayton                     break;
1690c5cd90dSGreg Clayton 
1702561aa61SJim Ingham                 case 'M':
171fab10e89SJim Ingham                     m_func_names.push_back (option_arg);
1720c5cd90dSGreg Clayton                     m_func_name_type_mask |= eFunctionNameTypeMethod;
1730c5cd90dSGreg Clayton                     break;
1740c5cd90dSGreg Clayton 
175969795f1SJim Ingham                 case 'p':
176969795f1SJim Ingham                     m_source_text_regexp.assign (option_arg);
177969795f1SJim Ingham                     break;
178969795f1SJim Ingham 
17930fdc8d8SChris Lattner                 case 'r':
180357132ebSGreg Clayton                     m_func_regexp.assign (option_arg);
18130fdc8d8SChris Lattner                     break;
1820c5cd90dSGreg Clayton 
18330fdc8d8SChris Lattner                 case 's':
18430fdc8d8SChris Lattner                     {
18587df91b8SJim Ingham                         m_modules.AppendIfUnique (FileSpec (option_arg, false));
18630fdc8d8SChris Lattner                         break;
18730fdc8d8SChris Lattner                     }
188ed8a705cSGreg Clayton                 case 'i':
1891b54c88cSJim Ingham                 {
1900292f4a5SJim Ingham                     m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
191c982c768SGreg Clayton                     if (m_ignore_count == UINT32_MAX)
19286edbf41SGreg Clayton                        error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
1931b54c88cSJim Ingham                 }
194ae1c4cf5SJim Ingham                 break;
1951b54c88cSJim Ingham                 case 't' :
1961b54c88cSJim Ingham                 {
1970292f4a5SJim Ingham                     m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
1981b54c88cSJim Ingham                     if (m_thread_id == LLDB_INVALID_THREAD_ID)
19986edbf41SGreg Clayton                        error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
2001b54c88cSJim Ingham                 }
2011b54c88cSJim Ingham                 break;
2021b54c88cSJim Ingham                 case 'T':
203357132ebSGreg Clayton                     m_thread_name.assign (option_arg);
2041b54c88cSJim Ingham                     break;
2051b54c88cSJim Ingham                 case 'q':
206357132ebSGreg Clayton                     m_queue_name.assign (option_arg);
2071b54c88cSJim Ingham                     break;
2081b54c88cSJim Ingham                 case 'x':
2091b54c88cSJim Ingham                 {
2100292f4a5SJim Ingham                     m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
211c982c768SGreg Clayton                     if (m_thread_id == UINT32_MAX)
21286edbf41SGreg Clayton                        error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
2131b54c88cSJim Ingham 
2141b54c88cSJim Ingham                 }
2151b54c88cSJim Ingham                 break;
216fab10e89SJim Ingham                 case 'E':
217fab10e89SJim Ingham                 {
218fab10e89SJim Ingham                     LanguageType language = LanguageRuntime::GetLanguageTypeFromString (option_arg);
219fab10e89SJim Ingham 
220fab10e89SJim Ingham                     switch (language)
221fab10e89SJim Ingham                     {
222fab10e89SJim Ingham                         case eLanguageTypeC89:
223fab10e89SJim Ingham                         case eLanguageTypeC:
224fab10e89SJim Ingham                         case eLanguageTypeC99:
225fab10e89SJim Ingham                             m_language = eLanguageTypeC;
226fab10e89SJim Ingham                             break;
227fab10e89SJim Ingham                         case eLanguageTypeC_plus_plus:
228fab10e89SJim Ingham                             m_language = eLanguageTypeC_plus_plus;
229fab10e89SJim Ingham                             break;
230fab10e89SJim Ingham                         case eLanguageTypeObjC:
231fab10e89SJim Ingham                             m_language = eLanguageTypeObjC;
232fab10e89SJim Ingham                             break;
233fab10e89SJim Ingham                         case eLanguageTypeObjC_plus_plus:
234fab10e89SJim Ingham                             error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c");
235fab10e89SJim Ingham                             break;
236fab10e89SJim Ingham                         case eLanguageTypeUnknown:
237fab10e89SJim Ingham                             error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg);
238fab10e89SJim Ingham                             break;
239fab10e89SJim Ingham                         default:
240fab10e89SJim Ingham                             error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg);
241fab10e89SJim Ingham                     }
242fab10e89SJim Ingham                 }
243fab10e89SJim Ingham                 break;
244fab10e89SJim Ingham                 case 'w':
245fab10e89SJim Ingham                 {
246fab10e89SJim Ingham                     bool success;
247fab10e89SJim Ingham                     m_throw_bp = Args::StringToBoolean (option_arg, true, &success);
248fab10e89SJim Ingham                     if (!success)
249fab10e89SJim Ingham                         error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg);
250fab10e89SJim Ingham                 }
251fab10e89SJim Ingham                 break;
252fab10e89SJim Ingham                 case 'h':
253fab10e89SJim Ingham                 {
254fab10e89SJim Ingham                     bool success;
255fab10e89SJim Ingham                     m_catch_bp = Args::StringToBoolean (option_arg, true, &success);
256fab10e89SJim Ingham                     if (!success)
257fab10e89SJim Ingham                         error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg);
258fab10e89SJim Ingham                 }
259a8558b62SJim Ingham                 case 'K':
260a8558b62SJim Ingham                 {
261a8558b62SJim Ingham                     bool success;
262a8558b62SJim Ingham                     bool value;
263a8558b62SJim Ingham                     value = Args::StringToBoolean (option_arg, true, &success);
264a8558b62SJim Ingham                     if (value)
265a8558b62SJim Ingham                         m_skip_prologue = eLazyBoolYes;
266a8558b62SJim Ingham                     else
267a8558b62SJim Ingham                         m_skip_prologue = eLazyBoolNo;
268a8558b62SJim Ingham 
269a8558b62SJim Ingham                     if (!success)
270a8558b62SJim Ingham                         error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg);
271a8558b62SJim Ingham                 }
272fab10e89SJim Ingham                 break;
27330fdc8d8SChris Lattner                 default:
27486edbf41SGreg Clayton                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
27530fdc8d8SChris Lattner                     break;
27630fdc8d8SChris Lattner             }
27730fdc8d8SChris Lattner 
27830fdc8d8SChris Lattner             return error;
27930fdc8d8SChris Lattner         }
28030fdc8d8SChris Lattner         void
2815a988416SJim Ingham         OptionParsingStarting ()
28230fdc8d8SChris Lattner         {
2837d49c9c8SJohnny Chen             m_condition.clear();
28487df91b8SJim Ingham             m_filenames.Clear();
28530fdc8d8SChris Lattner             m_line_num = 0;
28630fdc8d8SChris Lattner             m_column = 0;
287fab10e89SJim Ingham             m_func_names.clear();
2880c5cd90dSGreg Clayton             m_func_name_type_mask = 0;
28930fdc8d8SChris Lattner             m_func_regexp.clear();
29030fdc8d8SChris Lattner             m_load_addr = LLDB_INVALID_ADDRESS;
29187df91b8SJim Ingham             m_modules.Clear();
292c982c768SGreg Clayton             m_ignore_count = 0;
2931b54c88cSJim Ingham             m_thread_id = LLDB_INVALID_THREAD_ID;
294c982c768SGreg Clayton             m_thread_index = UINT32_MAX;
2951b54c88cSJim Ingham             m_thread_name.clear();
2961b54c88cSJim Ingham             m_queue_name.clear();
297fab10e89SJim Ingham             m_language = eLanguageTypeUnknown;
298fab10e89SJim Ingham             m_catch_bp = false;
299fab10e89SJim Ingham             m_throw_bp = true;
300a8558b62SJim Ingham             m_skip_prologue = eLazyBoolCalculate;
30130fdc8d8SChris Lattner         }
30230fdc8d8SChris Lattner 
3035a988416SJim Ingham         const OptionDefinition*
3045a988416SJim Ingham         GetDefinitions ()
30530fdc8d8SChris Lattner         {
3065a988416SJim Ingham             return g_option_table;
30730fdc8d8SChris Lattner         }
30830fdc8d8SChris Lattner 
3095a988416SJim Ingham         // Options table: Required for subclasses of Options.
31030fdc8d8SChris Lattner 
3115a988416SJim Ingham         static OptionDefinition g_option_table[];
31230fdc8d8SChris Lattner 
3135a988416SJim Ingham         // Instance variables to hold the values for command options.
314969795f1SJim Ingham 
3155a988416SJim Ingham         std::string m_condition;
3165a988416SJim Ingham         FileSpecList m_filenames;
3175a988416SJim Ingham         uint32_t m_line_num;
3185a988416SJim Ingham         uint32_t m_column;
3195a988416SJim Ingham         bool m_check_inlines;
3205a988416SJim Ingham         std::vector<std::string> m_func_names;
3215a988416SJim Ingham         uint32_t m_func_name_type_mask;
3225a988416SJim Ingham         std::string m_func_regexp;
3235a988416SJim Ingham         std::string m_source_text_regexp;
3245a988416SJim Ingham         FileSpecList m_modules;
3255a988416SJim Ingham         lldb::addr_t m_load_addr;
3265a988416SJim Ingham         uint32_t m_ignore_count;
3275a988416SJim Ingham         lldb::tid_t m_thread_id;
3285a988416SJim Ingham         uint32_t m_thread_index;
3295a988416SJim Ingham         std::string m_thread_name;
3305a988416SJim Ingham         std::string m_queue_name;
3315a988416SJim Ingham         bool m_catch_bp;
3325a988416SJim Ingham         bool m_throw_bp;
3335a988416SJim Ingham         lldb::LanguageType m_language;
3345a988416SJim Ingham         LazyBool m_skip_prologue;
3355a988416SJim Ingham 
3365a988416SJim Ingham     };
3375a988416SJim Ingham 
3385a988416SJim Ingham protected:
3395a988416SJim Ingham     virtual bool
3405a988416SJim Ingham     DoExecute (Args& command,
3415a988416SJim Ingham              CommandReturnObject &result)
34230fdc8d8SChris Lattner     {
343a7015092SGreg Clayton         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
34430fdc8d8SChris Lattner         if (target == NULL)
34530fdc8d8SChris Lattner         {
346effe5c95SGreg Clayton             result.AppendError ("Invalid target.  Must set target before setting breakpoints (see 'target create' command).");
34730fdc8d8SChris Lattner             result.SetStatus (eReturnStatusFailed);
34830fdc8d8SChris Lattner             return false;
34930fdc8d8SChris Lattner         }
35030fdc8d8SChris Lattner 
35130fdc8d8SChris Lattner         // The following are the various types of breakpoints that could be set:
35230fdc8d8SChris Lattner         //   1).  -f -l -p  [-s -g]   (setting breakpoint by source location)
35330fdc8d8SChris Lattner         //   2).  -a  [-s -g]         (setting breakpoint by address)
35430fdc8d8SChris Lattner         //   3).  -n  [-s -g]         (setting breakpoint by function name)
35530fdc8d8SChris Lattner         //   4).  -r  [-s -g]         (setting breakpoint by function name regular expression)
356969795f1SJim Ingham         //   5).  -p -f               (setting a breakpoint by comparing a reg-exp to source text)
357fab10e89SJim Ingham         //   6).  -E [-w -h]          (setting a breakpoint for exceptions for a given language.)
35830fdc8d8SChris Lattner 
35930fdc8d8SChris Lattner         BreakpointSetType break_type = eSetTypeInvalid;
36030fdc8d8SChris Lattner 
36130fdc8d8SChris Lattner         if (m_options.m_line_num != 0)
36230fdc8d8SChris Lattner             break_type = eSetTypeFileAndLine;
36330fdc8d8SChris Lattner         else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
36430fdc8d8SChris Lattner             break_type = eSetTypeAddress;
365fab10e89SJim Ingham         else if (!m_options.m_func_names.empty())
36630fdc8d8SChris Lattner             break_type = eSetTypeFunctionName;
36730fdc8d8SChris Lattner         else if  (!m_options.m_func_regexp.empty())
36830fdc8d8SChris Lattner             break_type = eSetTypeFunctionRegexp;
369969795f1SJim Ingham         else if (!m_options.m_source_text_regexp.empty())
370969795f1SJim Ingham             break_type = eSetTypeSourceRegexp;
371fab10e89SJim Ingham         else if (m_options.m_language != eLanguageTypeUnknown)
372fab10e89SJim Ingham             break_type = eSetTypeException;
37330fdc8d8SChris Lattner 
37430fdc8d8SChris Lattner         Breakpoint *bp = NULL;
375274060b6SGreg Clayton         FileSpec module_spec;
376a8558b62SJim Ingham         const bool internal = false;
377a8558b62SJim Ingham 
37830fdc8d8SChris Lattner         switch (break_type)
37930fdc8d8SChris Lattner         {
38030fdc8d8SChris Lattner             case eSetTypeFileAndLine: // Breakpoint by source position
38130fdc8d8SChris Lattner                 {
38230fdc8d8SChris Lattner                     FileSpec file;
38387df91b8SJim Ingham                     uint32_t num_files = m_options.m_filenames.GetSize();
38487df91b8SJim Ingham                     if (num_files == 0)
38587df91b8SJim Ingham                     {
38687df91b8SJim Ingham                         if (!GetDefaultFile (target, file, result))
38787df91b8SJim Ingham                         {
38887df91b8SJim Ingham                             result.AppendError("No file supplied and no default file available.");
38987df91b8SJim Ingham                             result.SetStatus (eReturnStatusFailed);
39087df91b8SJim Ingham                             return false;
39187df91b8SJim Ingham                         }
39287df91b8SJim Ingham                     }
39387df91b8SJim Ingham                     else if (num_files > 1)
39487df91b8SJim Ingham                     {
39587df91b8SJim Ingham                         result.AppendError("Only one file at a time is allowed for file and line breakpoints.");
39687df91b8SJim Ingham                         result.SetStatus (eReturnStatusFailed);
39787df91b8SJim Ingham                         return false;
39887df91b8SJim Ingham                     }
39987df91b8SJim Ingham                     else
40087df91b8SJim Ingham                         file = m_options.m_filenames.GetFileSpecAtIndex(0);
40130fdc8d8SChris Lattner 
40287df91b8SJim Ingham                     bp = target->CreateBreakpoint (&(m_options.m_modules),
40330fdc8d8SChris Lattner                                                    file,
40430fdc8d8SChris Lattner                                                    m_options.m_line_num,
405a8558b62SJim Ingham                                                    m_options.m_check_inlines,
406a8558b62SJim Ingham                                                    m_options.m_skip_prologue,
407a8558b62SJim Ingham                                                    internal).get();
40830fdc8d8SChris Lattner                 }
40930fdc8d8SChris Lattner                 break;
4106eee5aa0SGreg Clayton 
41130fdc8d8SChris Lattner             case eSetTypeAddress: // Breakpoint by address
41230fdc8d8SChris Lattner                 bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
41330fdc8d8SChris Lattner                 break;
4140c5cd90dSGreg Clayton 
41530fdc8d8SChris Lattner             case eSetTypeFunctionName: // Breakpoint by function name
4160c5cd90dSGreg Clayton                 {
4170c5cd90dSGreg Clayton                     uint32_t name_type_mask = m_options.m_func_name_type_mask;
4180c5cd90dSGreg Clayton 
4190c5cd90dSGreg Clayton                     if (name_type_mask == 0)
420e02b8504SGreg Clayton                         name_type_mask = eFunctionNameTypeAuto;
4210c5cd90dSGreg Clayton 
42287df91b8SJim Ingham                     bp = target->CreateBreakpoint (&(m_options.m_modules),
42387df91b8SJim Ingham                                                    &(m_options.m_filenames),
424fab10e89SJim Ingham                                                    m_options.m_func_names,
425274060b6SGreg Clayton                                                    name_type_mask,
426a8558b62SJim Ingham                                                    m_options.m_skip_prologue,
427a8558b62SJim Ingham                                                    internal).get();
4280c5cd90dSGreg Clayton                 }
42930fdc8d8SChris Lattner                 break;
4300c5cd90dSGreg Clayton 
43130fdc8d8SChris Lattner             case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
43230fdc8d8SChris Lattner                 {
43330fdc8d8SChris Lattner                     RegularExpression regexp(m_options.m_func_regexp.c_str());
434969795f1SJim Ingham                     if (!regexp.IsValid())
43530fdc8d8SChris Lattner                     {
436969795f1SJim Ingham                         char err_str[1024];
437969795f1SJim Ingham                         regexp.GetErrorAsCString(err_str, sizeof(err_str));
438969795f1SJim Ingham                         result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"",
439969795f1SJim Ingham                                                      err_str);
44030fdc8d8SChris Lattner                         result.SetStatus (eReturnStatusFailed);
441969795f1SJim Ingham                         return false;
44230fdc8d8SChris Lattner                     }
44387df91b8SJim Ingham 
444a8558b62SJim Ingham                     bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules),
445a8558b62SJim Ingham                                                             &(m_options.m_filenames),
446a8558b62SJim Ingham                                                             regexp,
447a8558b62SJim Ingham                                                             m_options.m_skip_prologue,
448a8558b62SJim Ingham                                                             internal).get();
44930fdc8d8SChris Lattner                 }
45030fdc8d8SChris Lattner                 break;
451969795f1SJim Ingham             case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
452969795f1SJim Ingham                 {
45387df91b8SJim Ingham                     int num_files = m_options.m_filenames.GetSize();
45487df91b8SJim Ingham 
45587df91b8SJim Ingham                     if (num_files == 0)
45687df91b8SJim Ingham                     {
457969795f1SJim Ingham                         FileSpec file;
45887df91b8SJim Ingham                         if (!GetDefaultFile (target, file, result))
45987df91b8SJim Ingham                         {
46087df91b8SJim Ingham                             result.AppendError ("No files provided and could not find default file.");
46187df91b8SJim Ingham                             result.SetStatus (eReturnStatusFailed);
46287df91b8SJim Ingham                             return false;
46387df91b8SJim Ingham                         }
46487df91b8SJim Ingham                         else
46587df91b8SJim Ingham                         {
46687df91b8SJim Ingham                             m_options.m_filenames.Append (file);
46787df91b8SJim Ingham                         }
46887df91b8SJim Ingham                     }
4690c5cd90dSGreg Clayton 
470969795f1SJim Ingham                     RegularExpression regexp(m_options.m_source_text_regexp.c_str());
471969795f1SJim Ingham                     if (!regexp.IsValid())
472969795f1SJim Ingham                     {
473969795f1SJim Ingham                         char err_str[1024];
474969795f1SJim Ingham                         regexp.GetErrorAsCString(err_str, sizeof(err_str));
475969795f1SJim Ingham                         result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"",
476969795f1SJim Ingham                                                      err_str);
477969795f1SJim Ingham                         result.SetStatus (eReturnStatusFailed);
478969795f1SJim Ingham                         return false;
479969795f1SJim Ingham                     }
48087df91b8SJim Ingham                     bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules), &(m_options.m_filenames), regexp).get();
481969795f1SJim Ingham                 }
482969795f1SJim Ingham                 break;
483fab10e89SJim Ingham             case eSetTypeException:
484fab10e89SJim Ingham                 {
485fab10e89SJim Ingham                     bp = target->CreateExceptionBreakpoint (m_options.m_language, m_options.m_catch_bp, m_options.m_throw_bp).get();
486fab10e89SJim Ingham                 }
487fab10e89SJim Ingham                 break;
48830fdc8d8SChris Lattner             default:
48930fdc8d8SChris Lattner                 break;
49030fdc8d8SChris Lattner         }
49130fdc8d8SChris Lattner 
4921b54c88cSJim Ingham         // Now set the various options that were passed in:
4931b54c88cSJim Ingham         if (bp)
4941b54c88cSJim Ingham         {
4951b54c88cSJim Ingham             if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
4961b54c88cSJim Ingham                 bp->SetThreadID (m_options.m_thread_id);
4971b54c88cSJim Ingham 
498c982c768SGreg Clayton             if (m_options.m_thread_index != UINT32_MAX)
4991b54c88cSJim Ingham                 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
5001b54c88cSJim Ingham 
5011b54c88cSJim Ingham             if (!m_options.m_thread_name.empty())
5021b54c88cSJim Ingham                 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
5031b54c88cSJim Ingham 
5041b54c88cSJim Ingham             if (!m_options.m_queue_name.empty())
5051b54c88cSJim Ingham                 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
5061b54c88cSJim Ingham 
507c982c768SGreg Clayton             if (m_options.m_ignore_count != 0)
5081b54c88cSJim Ingham                 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
5097d49c9c8SJohnny Chen 
5107d49c9c8SJohnny Chen             if (!m_options.m_condition.empty())
5117d49c9c8SJohnny Chen                 bp->GetOptions()->SetCondition(m_options.m_condition.c_str());
5121b54c88cSJim Ingham         }
5131b54c88cSJim Ingham 
514969795f1SJim Ingham         if (bp)
51530fdc8d8SChris Lattner         {
51685e8b814SJim Ingham             Stream &output_stream = result.GetOutputStream();
51730fdc8d8SChris Lattner             output_stream.Printf ("Breakpoint created: ");
51830fdc8d8SChris Lattner             bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
51930fdc8d8SChris Lattner             output_stream.EOL();
520fab10e89SJim Ingham             // Don't print out this warning for exception breakpoints.  They can get set before the target
521fab10e89SJim Ingham             // is set, but we won't know how to actually set the breakpoint till we run.
522fab10e89SJim Ingham             if (bp->GetNumLocations() == 0 && break_type != eSetTypeException)
523be484f41SCaroline Tice                 output_stream.Printf ("WARNING:  Unable to resolve breakpoint to any actual locations.\n");
52430fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishResult);
52530fdc8d8SChris Lattner         }
52630fdc8d8SChris Lattner         else if (!bp)
52730fdc8d8SChris Lattner         {
52830fdc8d8SChris Lattner             result.AppendError ("Breakpoint creation failed: No breakpoint created.");
52930fdc8d8SChris Lattner             result.SetStatus (eReturnStatusFailed);
53030fdc8d8SChris Lattner         }
53130fdc8d8SChris Lattner 
53230fdc8d8SChris Lattner         return result.Succeeded();
53330fdc8d8SChris Lattner     }
53430fdc8d8SChris Lattner 
5355a988416SJim Ingham private:
5365a988416SJim Ingham     bool
5375a988416SJim Ingham     GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result)
5385a988416SJim Ingham     {
5395a988416SJim Ingham         uint32_t default_line;
5405a988416SJim Ingham         // First use the Source Manager's default file.
5415a988416SJim Ingham         // Then use the current stack frame's file.
5425a988416SJim Ingham         if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line))
5435a988416SJim Ingham         {
5445a988416SJim Ingham             StackFrame *cur_frame = m_interpreter.GetExecutionContext().GetFramePtr();
5455a988416SJim Ingham             if (cur_frame == NULL)
5465a988416SJim Ingham             {
5475a988416SJim Ingham                 result.AppendError ("No selected frame to use to find the default file.");
5485a988416SJim Ingham                 result.SetStatus (eReturnStatusFailed);
5495a988416SJim Ingham                 return false;
5505a988416SJim Ingham             }
5515a988416SJim Ingham             else if (!cur_frame->HasDebugInformation())
5525a988416SJim Ingham             {
5535a988416SJim Ingham                 result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info.");
5545a988416SJim Ingham                 result.SetStatus (eReturnStatusFailed);
5555a988416SJim Ingham                 return false;
5565a988416SJim Ingham             }
5575a988416SJim Ingham             else
5585a988416SJim Ingham             {
5595a988416SJim Ingham                 const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
5605a988416SJim Ingham                 if (sc.line_entry.file)
5615a988416SJim Ingham                 {
5625a988416SJim Ingham                     file = sc.line_entry.file;
5635a988416SJim Ingham                 }
5645a988416SJim Ingham                 else
5655a988416SJim Ingham                 {
5665a988416SJim Ingham                     result.AppendError ("Can't find the file for the selected frame to use as the default file.");
5675a988416SJim Ingham                     result.SetStatus (eReturnStatusFailed);
5685a988416SJim Ingham                     return false;
5695a988416SJim Ingham                 }
5705a988416SJim Ingham             }
5715a988416SJim Ingham         }
5725a988416SJim Ingham         return true;
5735a988416SJim Ingham     }
5745a988416SJim Ingham 
5755a988416SJim Ingham     CommandOptions m_options;
5765a988416SJim Ingham };
5775a988416SJim Ingham // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to
5785a988416SJim Ingham // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately.
5795a988416SJim Ingham #define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 )
5805a988416SJim Ingham #define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 )
5815a988416SJim Ingham #define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) )
5825a988416SJim Ingham 
5835a988416SJim Ingham OptionDefinition
5845a988416SJim Ingham CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
5855a988416SJim Ingham {
5865a988416SJim Ingham     { LLDB_OPT_NOT_10, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
5875a988416SJim Ingham         "Set the breakpoint only in this shared library.  "
5885a988416SJim Ingham         "Can repeat this option multiple times to specify multiple shared libraries."},
5895a988416SJim Ingham 
5905a988416SJim Ingham     { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument,   NULL, 0, eArgTypeCount,
5915a988416SJim Ingham         "Set the number of times this breakpoint is skipped before stopping." },
5925a988416SJim Ingham 
5935a988416SJim Ingham     { LLDB_OPT_SET_ALL, false, "condition",    'c', required_argument, NULL, 0, eArgTypeExpression,
5945a988416SJim Ingham         "The breakpoint stops only if this condition expression evaluates to true."},
5955a988416SJim Ingham 
5965a988416SJim Ingham     { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex,
5975a988416SJim Ingham         "The breakpoint stops only for the thread whose index matches this argument."},
5985a988416SJim Ingham 
5995a988416SJim Ingham     { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID,
6005a988416SJim Ingham         "The breakpoint stops only for the thread whose TID matches this argument."},
6015a988416SJim Ingham 
6025a988416SJim Ingham     { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName,
6035a988416SJim Ingham         "The breakpoint stops only for the thread whose thread name matches this argument."},
6045a988416SJim Ingham 
6055a988416SJim Ingham     { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName,
6065a988416SJim Ingham         "The breakpoint stops only for threads in the queue whose name is given by this argument."},
6075a988416SJim Ingham 
6085a988416SJim Ingham     { LLDB_OPT_FILE, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
6095a988416SJim Ingham         "Specifies the source file in which to set this breakpoint."},
6105a988416SJim Ingham 
6115a988416SJim Ingham     { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
6125a988416SJim Ingham         "Specifies the line number on which to set this breakpoint."},
6135a988416SJim Ingham 
6145a988416SJim Ingham     // Comment out this option for the moment, as we don't actually use it, but will in the future.
6155a988416SJim Ingham     // This way users won't see it, but the infrastructure is left in place.
6165a988416SJim Ingham     //    { 0, false, "column",     'C', required_argument, NULL, "<column>",
6175a988416SJim Ingham     //    "Set the breakpoint by source location at this particular column."},
6185a988416SJim Ingham 
6195a988416SJim Ingham     { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress,
6205a988416SJim Ingham         "Set the breakpoint by address, at the specified address."},
6215a988416SJim Ingham 
6225a988416SJim Ingham     { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
6235a988416SJim Ingham         "Set the breakpoint by function name.  Can be repeated multiple times to make one breakpoint for multiple snames" },
6245a988416SJim Ingham 
6255a988416SJim Ingham     { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
6265a988416SJim Ingham         "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and "
6275a988416SJim Ingham         "for Objective C this means a full function prototype with class and selector.   "
6285a988416SJim Ingham         "Can be repeated multiple times to make one breakpoint for multiple names." },
6295a988416SJim Ingham 
6305a988416SJim Ingham     { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector,
6315a988416SJim Ingham         "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." },
6325a988416SJim Ingham 
6335a988416SJim Ingham     { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod,
6345a988416SJim Ingham         "Set the breakpoint by C++ method names.  Can be repeated multiple times to make one breakpoint for multiple methods." },
6355a988416SJim Ingham 
6365a988416SJim Ingham     { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression,
6375a988416SJim Ingham         "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
6385a988416SJim Ingham 
6395a988416SJim Ingham     { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
6405a988416SJim Ingham         "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). "
6415a988416SJim Ingham         "Can be repeated multiple times to make one breakpoint for multiple symbols." },
6425a988416SJim Ingham 
6435a988416SJim Ingham     { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', required_argument, NULL, 0, eArgTypeRegularExpression,
6445a988416SJim Ingham         "Set the breakpoint specifying a regular expression to match a pattern in the source text in a given source file." },
6455a988416SJim Ingham 
6465a988416SJim Ingham     { LLDB_OPT_SET_10, true, "language-exception", 'E', required_argument, NULL, 0, eArgTypeLanguage,
6475a988416SJim Ingham         "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" },
6485a988416SJim Ingham 
6495a988416SJim Ingham     { LLDB_OPT_SET_10, false, "on-throw", 'w', required_argument, NULL, 0, eArgTypeBoolean,
6505a988416SJim Ingham         "Set the breakpoint on exception throW." },
6515a988416SJim Ingham 
6525a988416SJim Ingham     { LLDB_OPT_SET_10, false, "on-catch", 'h', required_argument, NULL, 0, eArgTypeBoolean,
6535a988416SJim Ingham         "Set the breakpoint on exception catcH." },
6545a988416SJim Ingham 
6555a988416SJim Ingham     { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', required_argument, NULL, 0, eArgTypeBoolean,
6565a988416SJim Ingham         "sKip the prologue if the breakpoint is at the beginning of a function.  If not set the target.skip-prologue setting is used." },
6575a988416SJim Ingham 
6585a988416SJim Ingham     { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
6595a988416SJim Ingham };
6605a988416SJim Ingham 
6615a988416SJim Ingham //-------------------------------------------------------------------------
6625a988416SJim Ingham // CommandObjectBreakpointModify
6635a988416SJim Ingham //-------------------------------------------------------------------------
6645a988416SJim Ingham #pragma mark Modify
6655a988416SJim Ingham 
6665a988416SJim Ingham class CommandObjectBreakpointModify : public CommandObjectParsed
6675a988416SJim Ingham {
6685a988416SJim Ingham public:
6695a988416SJim Ingham 
6705a988416SJim Ingham     CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
6715a988416SJim Ingham         CommandObjectParsed (interpreter,
6725a988416SJim Ingham                              "breakpoint modify",
6735a988416SJim Ingham                              "Modify the options on a breakpoint or set of breakpoints in the executable.  "
6745a988416SJim Ingham                              "If no breakpoint is specified, acts on the last created breakpoint.  "
6755a988416SJim Ingham                              "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
6765a988416SJim Ingham                              NULL),
6775a988416SJim Ingham         m_options (interpreter)
6785a988416SJim Ingham     {
6795a988416SJim Ingham         CommandArgumentEntry arg;
6805a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
6815a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
6825a988416SJim Ingham         m_arguments.push_back (arg);
6835a988416SJim Ingham     }
6845a988416SJim Ingham 
6855a988416SJim Ingham 
6865a988416SJim Ingham     virtual
6875a988416SJim Ingham     ~CommandObjectBreakpointModify () {}
6885a988416SJim Ingham 
6895a988416SJim Ingham     virtual Options *
6905a988416SJim Ingham     GetOptions ()
6915a988416SJim Ingham     {
6925a988416SJim Ingham         return &m_options;
6935a988416SJim Ingham     }
6945a988416SJim Ingham 
6955a988416SJim Ingham     class CommandOptions : public Options
6965a988416SJim Ingham     {
6975a988416SJim Ingham     public:
6985a988416SJim Ingham 
6995a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
7005a988416SJim Ingham             Options (interpreter),
7015a988416SJim Ingham             m_ignore_count (0),
7025a988416SJim Ingham             m_thread_id(LLDB_INVALID_THREAD_ID),
7035a988416SJim Ingham             m_thread_id_passed(false),
7045a988416SJim Ingham             m_thread_index (UINT32_MAX),
7055a988416SJim Ingham             m_thread_index_passed(false),
7065a988416SJim Ingham             m_thread_name(),
7075a988416SJim Ingham             m_queue_name(),
7085a988416SJim Ingham             m_condition (),
7095a988416SJim Ingham             m_enable_passed (false),
7105a988416SJim Ingham             m_enable_value (false),
7115a988416SJim Ingham             m_name_passed (false),
7125a988416SJim Ingham             m_queue_passed (false),
7135a988416SJim Ingham             m_condition_passed (false)
7145a988416SJim Ingham         {
7155a988416SJim Ingham         }
7165a988416SJim Ingham 
7175a988416SJim Ingham         virtual
7185a988416SJim Ingham         ~CommandOptions () {}
7195a988416SJim Ingham 
7205a988416SJim Ingham         virtual Error
7215a988416SJim Ingham         SetOptionValue (uint32_t option_idx, const char *option_arg)
7225a988416SJim Ingham         {
7235a988416SJim Ingham             Error error;
7245a988416SJim Ingham             char short_option = (char) m_getopt_table[option_idx].val;
7255a988416SJim Ingham 
7265a988416SJim Ingham             switch (short_option)
7275a988416SJim Ingham             {
7285a988416SJim Ingham                 case 'c':
7295a988416SJim Ingham                     if (option_arg != NULL)
7305a988416SJim Ingham                         m_condition.assign (option_arg);
7315a988416SJim Ingham                     else
7325a988416SJim Ingham                         m_condition.clear();
7335a988416SJim Ingham                     m_condition_passed = true;
7345a988416SJim Ingham                     break;
7355a988416SJim Ingham                 case 'd':
7365a988416SJim Ingham                     m_enable_passed = true;
7375a988416SJim Ingham                     m_enable_value = false;
7385a988416SJim Ingham                     break;
7395a988416SJim Ingham                 case 'e':
7405a988416SJim Ingham                     m_enable_passed = true;
7415a988416SJim Ingham                     m_enable_value = true;
7425a988416SJim Ingham                     break;
7435a988416SJim Ingham                 case 'i':
7445a988416SJim Ingham                 {
7455a988416SJim Ingham                     m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
7465a988416SJim Ingham                     if (m_ignore_count == UINT32_MAX)
7475a988416SJim Ingham                        error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
7485a988416SJim Ingham                 }
7495a988416SJim Ingham                 break;
7505a988416SJim Ingham                 case 't' :
7515a988416SJim Ingham                 {
7525a988416SJim Ingham                     if (option_arg[0] == '\0')
7535a988416SJim Ingham                     {
7545a988416SJim Ingham                         m_thread_id = LLDB_INVALID_THREAD_ID;
7555a988416SJim Ingham                         m_thread_id_passed = true;
7565a988416SJim Ingham                     }
7575a988416SJim Ingham                     else
7585a988416SJim Ingham                     {
7595a988416SJim Ingham                         m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
7605a988416SJim Ingham                         if (m_thread_id == LLDB_INVALID_THREAD_ID)
7615a988416SJim Ingham                            error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
7625a988416SJim Ingham                         else
7635a988416SJim Ingham                             m_thread_id_passed = true;
7645a988416SJim Ingham                     }
7655a988416SJim Ingham                 }
7665a988416SJim Ingham                 break;
7675a988416SJim Ingham                 case 'T':
7685a988416SJim Ingham                     if (option_arg != NULL)
7695a988416SJim Ingham                         m_thread_name.assign (option_arg);
7705a988416SJim Ingham                     else
7715a988416SJim Ingham                         m_thread_name.clear();
7725a988416SJim Ingham                     m_name_passed = true;
7735a988416SJim Ingham                     break;
7745a988416SJim Ingham                 case 'q':
7755a988416SJim Ingham                     if (option_arg != NULL)
7765a988416SJim Ingham                         m_queue_name.assign (option_arg);
7775a988416SJim Ingham                     else
7785a988416SJim Ingham                         m_queue_name.clear();
7795a988416SJim Ingham                     m_queue_passed = true;
7805a988416SJim Ingham                     break;
7815a988416SJim Ingham                 case 'x':
7825a988416SJim Ingham                 {
7835a988416SJim Ingham                     if (option_arg[0] == '\n')
7845a988416SJim Ingham                     {
7855a988416SJim Ingham                         m_thread_index = UINT32_MAX;
7865a988416SJim Ingham                         m_thread_index_passed = true;
7875a988416SJim Ingham                     }
7885a988416SJim Ingham                     else
7895a988416SJim Ingham                     {
7905a988416SJim Ingham                         m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0);
7915a988416SJim Ingham                         if (m_thread_id == UINT32_MAX)
7925a988416SJim Ingham                            error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
7935a988416SJim Ingham                         else
7945a988416SJim Ingham                             m_thread_index_passed = true;
7955a988416SJim Ingham                     }
7965a988416SJim Ingham                 }
7975a988416SJim Ingham                 break;
7985a988416SJim Ingham                 default:
7995a988416SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
8005a988416SJim Ingham                     break;
8015a988416SJim Ingham             }
8025a988416SJim Ingham 
8035a988416SJim Ingham             return error;
8045a988416SJim Ingham         }
8055a988416SJim Ingham         void
8065a988416SJim Ingham         OptionParsingStarting ()
8075a988416SJim Ingham         {
8085a988416SJim Ingham             m_ignore_count = 0;
8095a988416SJim Ingham             m_thread_id = LLDB_INVALID_THREAD_ID;
8105a988416SJim Ingham             m_thread_id_passed = false;
8115a988416SJim Ingham             m_thread_index = UINT32_MAX;
8125a988416SJim Ingham             m_thread_index_passed = false;
8135a988416SJim Ingham             m_thread_name.clear();
8145a988416SJim Ingham             m_queue_name.clear();
8155a988416SJim Ingham             m_condition.clear();
8165a988416SJim Ingham             m_enable_passed = false;
8175a988416SJim Ingham             m_queue_passed = false;
8185a988416SJim Ingham             m_name_passed = false;
8195a988416SJim Ingham             m_condition_passed = false;
8205a988416SJim Ingham         }
8215a988416SJim Ingham 
8225a988416SJim Ingham         const OptionDefinition*
8235a988416SJim Ingham         GetDefinitions ()
8245a988416SJim Ingham         {
8255a988416SJim Ingham             return g_option_table;
8265a988416SJim Ingham         }
8275a988416SJim Ingham 
8285a988416SJim Ingham 
8295a988416SJim Ingham         // Options table: Required for subclasses of Options.
8305a988416SJim Ingham 
8315a988416SJim Ingham         static OptionDefinition g_option_table[];
8325a988416SJim Ingham 
8335a988416SJim Ingham         // Instance variables to hold the values for command options.
8345a988416SJim Ingham 
8355a988416SJim Ingham         uint32_t m_ignore_count;
8365a988416SJim Ingham         lldb::tid_t m_thread_id;
8375a988416SJim Ingham         bool m_thread_id_passed;
8385a988416SJim Ingham         uint32_t m_thread_index;
8395a988416SJim Ingham         bool m_thread_index_passed;
8405a988416SJim Ingham         std::string m_thread_name;
8415a988416SJim Ingham         std::string m_queue_name;
8425a988416SJim Ingham         std::string m_condition;
8435a988416SJim Ingham         bool m_enable_passed;
8445a988416SJim Ingham         bool m_enable_value;
8455a988416SJim Ingham         bool m_name_passed;
8465a988416SJim Ingham         bool m_queue_passed;
8475a988416SJim Ingham         bool m_condition_passed;
8485a988416SJim Ingham 
8495a988416SJim Ingham     };
8505a988416SJim Ingham 
8515a988416SJim Ingham protected:
8525a988416SJim Ingham     virtual bool
8535a988416SJim Ingham     DoExecute (Args& command, CommandReturnObject &result)
8545a988416SJim Ingham     {
8555a988416SJim Ingham         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
8565a988416SJim Ingham         if (target == NULL)
8575a988416SJim Ingham         {
8585a988416SJim Ingham             result.AppendError ("Invalid target.  No existing target or breakpoints.");
8595a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
8605a988416SJim Ingham             return false;
8615a988416SJim Ingham         }
8625a988416SJim Ingham 
8635a988416SJim Ingham         Mutex::Locker locker;
8645a988416SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
8655a988416SJim Ingham 
8665a988416SJim Ingham         BreakpointIDList valid_bp_ids;
8675a988416SJim Ingham 
8685a988416SJim Ingham         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
8695a988416SJim Ingham 
8705a988416SJim Ingham         if (result.Succeeded())
8715a988416SJim Ingham         {
8725a988416SJim Ingham             const size_t count = valid_bp_ids.GetSize();
8735a988416SJim Ingham             for (size_t i = 0; i < count; ++i)
8745a988416SJim Ingham             {
8755a988416SJim Ingham                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
8765a988416SJim Ingham 
8775a988416SJim Ingham                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
8785a988416SJim Ingham                 {
8795a988416SJim Ingham                     Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
8805a988416SJim Ingham                     if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
8815a988416SJim Ingham                     {
8825a988416SJim Ingham                         BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
8835a988416SJim Ingham                         if (location)
8845a988416SJim Ingham                         {
8855a988416SJim Ingham                             if (m_options.m_thread_id_passed)
8865a988416SJim Ingham                                 location->SetThreadID (m_options.m_thread_id);
8875a988416SJim Ingham 
8885a988416SJim Ingham                             if (m_options.m_thread_index_passed)
8895a988416SJim Ingham                                 location->SetThreadIndex(m_options.m_thread_index);
8905a988416SJim Ingham 
8915a988416SJim Ingham                             if (m_options.m_name_passed)
8925a988416SJim Ingham                                 location->SetThreadName(m_options.m_thread_name.c_str());
8935a988416SJim Ingham 
8945a988416SJim Ingham                             if (m_options.m_queue_passed)
8955a988416SJim Ingham                                 location->SetQueueName(m_options.m_queue_name.c_str());
8965a988416SJim Ingham 
8975a988416SJim Ingham                             if (m_options.m_ignore_count != 0)
8985a988416SJim Ingham                                 location->SetIgnoreCount(m_options.m_ignore_count);
8995a988416SJim Ingham 
9005a988416SJim Ingham                             if (m_options.m_enable_passed)
9015a988416SJim Ingham                                 location->SetEnabled (m_options.m_enable_value);
9025a988416SJim Ingham 
9035a988416SJim Ingham                             if (m_options.m_condition_passed)
9045a988416SJim Ingham                                 location->SetCondition (m_options.m_condition.c_str());
9055a988416SJim Ingham                         }
9065a988416SJim Ingham                     }
9075a988416SJim Ingham                     else
9085a988416SJim Ingham                     {
9095a988416SJim Ingham                         if (m_options.m_thread_id_passed)
9105a988416SJim Ingham                             bp->SetThreadID (m_options.m_thread_id);
9115a988416SJim Ingham 
9125a988416SJim Ingham                         if (m_options.m_thread_index_passed)
9135a988416SJim Ingham                             bp->SetThreadIndex(m_options.m_thread_index);
9145a988416SJim Ingham 
9155a988416SJim Ingham                         if (m_options.m_name_passed)
9165a988416SJim Ingham                             bp->SetThreadName(m_options.m_thread_name.c_str());
9175a988416SJim Ingham 
9185a988416SJim Ingham                         if (m_options.m_queue_passed)
9195a988416SJim Ingham                             bp->SetQueueName(m_options.m_queue_name.c_str());
9205a988416SJim Ingham 
9215a988416SJim Ingham                         if (m_options.m_ignore_count != 0)
9225a988416SJim Ingham                             bp->SetIgnoreCount(m_options.m_ignore_count);
9235a988416SJim Ingham 
9245a988416SJim Ingham                         if (m_options.m_enable_passed)
9255a988416SJim Ingham                             bp->SetEnabled (m_options.m_enable_value);
9265a988416SJim Ingham 
9275a988416SJim Ingham                         if (m_options.m_condition_passed)
9285a988416SJim Ingham                             bp->SetCondition (m_options.m_condition.c_str());
9295a988416SJim Ingham                     }
9305a988416SJim Ingham                 }
9315a988416SJim Ingham             }
9325a988416SJim Ingham         }
9335a988416SJim Ingham 
9345a988416SJim Ingham         return result.Succeeded();
9355a988416SJim Ingham     }
9365a988416SJim Ingham 
9375a988416SJim Ingham private:
9385a988416SJim Ingham     CommandOptions m_options;
9395a988416SJim Ingham };
9405a988416SJim Ingham 
9415a988416SJim Ingham #pragma mark Modify::CommandOptions
9425a988416SJim Ingham OptionDefinition
9435a988416SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
9445a988416SJim Ingham {
9455a988416SJim Ingham { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." },
9465a988416SJim Ingham { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose indeX matches this argument."},
9475a988416SJim Ingham { LLDB_OPT_SET_ALL, false, "thread-id",    't', required_argument, NULL, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."},
9485a988416SJim Ingham { LLDB_OPT_SET_ALL, false, "thread-name",  'T', required_argument, NULL, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."},
9495a988416SJim Ingham { LLDB_OPT_SET_ALL, false, "queue-name",   'q', required_argument, NULL, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."},
9505a988416SJim Ingham { LLDB_OPT_SET_ALL, false, "condition",    'c', required_argument, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."},
9515a988416SJim Ingham { LLDB_OPT_SET_1,   false, "enable",       'e', no_argument,       NULL, 0, eArgTypeNone, "Enable the breakpoint."},
9525a988416SJim Ingham { LLDB_OPT_SET_2,   false, "disable",      'd', no_argument,       NULL, 0, eArgTypeNone, "Disable the breakpoint."},
9535a988416SJim Ingham { 0,                false, NULL,            0 , 0,                 NULL, 0,    eArgTypeNone, NULL }
9545a988416SJim Ingham };
9555a988416SJim Ingham 
9565a988416SJim Ingham //-------------------------------------------------------------------------
9575a988416SJim Ingham // CommandObjectBreakpointEnable
9585a988416SJim Ingham //-------------------------------------------------------------------------
9595a988416SJim Ingham #pragma mark Enable
9605a988416SJim Ingham 
9615a988416SJim Ingham class CommandObjectBreakpointEnable : public CommandObjectParsed
9625a988416SJim Ingham {
9635a988416SJim Ingham public:
9645a988416SJim Ingham     CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
9655a988416SJim Ingham         CommandObjectParsed (interpreter,
9665a988416SJim Ingham                              "enable",
9675a988416SJim Ingham                              "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
9685a988416SJim Ingham                              NULL)
9695a988416SJim Ingham     {
9705a988416SJim Ingham         CommandArgumentEntry arg;
9715a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
9725a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
9735a988416SJim Ingham         m_arguments.push_back (arg);
9745a988416SJim Ingham     }
9755a988416SJim Ingham 
9765a988416SJim Ingham 
9775a988416SJim Ingham     virtual
9785a988416SJim Ingham     ~CommandObjectBreakpointEnable () {}
9795a988416SJim Ingham 
9805a988416SJim Ingham protected:
9815a988416SJim Ingham     virtual bool
9825a988416SJim Ingham     DoExecute (Args& command, CommandReturnObject &result)
9835a988416SJim Ingham     {
9845a988416SJim Ingham         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
9855a988416SJim Ingham         if (target == NULL)
9865a988416SJim Ingham         {
9875a988416SJim Ingham             result.AppendError ("Invalid target.  No existing target or breakpoints.");
9885a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
9895a988416SJim Ingham             return false;
9905a988416SJim Ingham         }
9915a988416SJim Ingham 
9925a988416SJim Ingham         Mutex::Locker locker;
9935a988416SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
9945a988416SJim Ingham 
9955a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
9965a988416SJim Ingham 
9975a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
9985a988416SJim Ingham 
9995a988416SJim Ingham         if (num_breakpoints == 0)
10005a988416SJim Ingham         {
10015a988416SJim Ingham             result.AppendError ("No breakpoints exist to be enabled.");
10025a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
10035a988416SJim Ingham             return false;
10045a988416SJim Ingham         }
10055a988416SJim Ingham 
10065a988416SJim Ingham         if (command.GetArgumentCount() == 0)
10075a988416SJim Ingham         {
10085a988416SJim Ingham             // No breakpoint selected; enable all currently set breakpoints.
10095a988416SJim Ingham             target->EnableAllBreakpoints ();
10105a988416SJim Ingham             result.AppendMessageWithFormat ("All breakpoints enabled. (%lu breakpoints)\n", num_breakpoints);
10115a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
10125a988416SJim Ingham         }
10135a988416SJim Ingham         else
10145a988416SJim Ingham         {
10155a988416SJim Ingham             // Particular breakpoint selected; enable that breakpoint.
10165a988416SJim Ingham             BreakpointIDList valid_bp_ids;
10175a988416SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
10185a988416SJim Ingham 
10195a988416SJim Ingham             if (result.Succeeded())
10205a988416SJim Ingham             {
10215a988416SJim Ingham                 int enable_count = 0;
10225a988416SJim Ingham                 int loc_count = 0;
10235a988416SJim Ingham                 const size_t count = valid_bp_ids.GetSize();
10245a988416SJim Ingham                 for (size_t i = 0; i < count; ++i)
10255a988416SJim Ingham                 {
10265a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
10275a988416SJim Ingham 
10285a988416SJim Ingham                     if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
10295a988416SJim Ingham                     {
10305a988416SJim Ingham                         Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
10315a988416SJim Ingham                         if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
10325a988416SJim Ingham                         {
10335a988416SJim Ingham                             BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
10345a988416SJim Ingham                             if (location)
10355a988416SJim Ingham                             {
10365a988416SJim Ingham                                 location->SetEnabled (true);
10375a988416SJim Ingham                                 ++loc_count;
10385a988416SJim Ingham                             }
10395a988416SJim Ingham                         }
10405a988416SJim Ingham                         else
10415a988416SJim Ingham                         {
10425a988416SJim Ingham                             breakpoint->SetEnabled (true);
10435a988416SJim Ingham                             ++enable_count;
10445a988416SJim Ingham                         }
10455a988416SJim Ingham                     }
10465a988416SJim Ingham                 }
10475a988416SJim Ingham                 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
10485a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
10495a988416SJim Ingham             }
10505a988416SJim Ingham         }
10515a988416SJim Ingham 
10525a988416SJim Ingham         return result.Succeeded();
10535a988416SJim Ingham     }
10545a988416SJim Ingham };
10555a988416SJim Ingham 
10565a988416SJim Ingham //-------------------------------------------------------------------------
10575a988416SJim Ingham // CommandObjectBreakpointDisable
10585a988416SJim Ingham //-------------------------------------------------------------------------
10595a988416SJim Ingham #pragma mark Disable
10605a988416SJim Ingham 
10615a988416SJim Ingham class CommandObjectBreakpointDisable : public CommandObjectParsed
10625a988416SJim Ingham {
10635a988416SJim Ingham public:
10645a988416SJim Ingham     CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
10655a988416SJim Ingham         CommandObjectParsed (interpreter,
10665a988416SJim Ingham                              "breakpoint disable",
10675a988416SJim Ingham                              "Disable the specified breakpoint(s) without removing it/them.  If no breakpoints are specified, disable them all.",
10685a988416SJim Ingham                              NULL)
10695a988416SJim Ingham     {
10705a988416SJim Ingham         CommandArgumentEntry arg;
10715a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
10725a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
10735a988416SJim Ingham         m_arguments.push_back (arg);
10745a988416SJim Ingham     }
10755a988416SJim Ingham 
10765a988416SJim Ingham 
10775a988416SJim Ingham     virtual
10785a988416SJim Ingham     ~CommandObjectBreakpointDisable () {}
10795a988416SJim Ingham 
10805a988416SJim Ingham protected:
10815a988416SJim Ingham     virtual bool
10825a988416SJim Ingham     DoExecute (Args& command, CommandReturnObject &result)
10835a988416SJim Ingham     {
10845a988416SJim Ingham         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
10855a988416SJim Ingham         if (target == NULL)
10865a988416SJim Ingham         {
10875a988416SJim Ingham             result.AppendError ("Invalid target.  No existing target or breakpoints.");
10885a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
10895a988416SJim Ingham             return false;
10905a988416SJim Ingham         }
10915a988416SJim Ingham 
10925a988416SJim Ingham         Mutex::Locker locker;
10935a988416SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
10945a988416SJim Ingham 
10955a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
10965a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
10975a988416SJim Ingham 
10985a988416SJim Ingham         if (num_breakpoints == 0)
10995a988416SJim Ingham         {
11005a988416SJim Ingham             result.AppendError ("No breakpoints exist to be disabled.");
11015a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
11025a988416SJim Ingham             return false;
11035a988416SJim Ingham         }
11045a988416SJim Ingham 
11055a988416SJim Ingham         if (command.GetArgumentCount() == 0)
11065a988416SJim Ingham         {
11075a988416SJim Ingham             // No breakpoint selected; disable all currently set breakpoints.
11085a988416SJim Ingham             target->DisableAllBreakpoints ();
11095a988416SJim Ingham             result.AppendMessageWithFormat ("All breakpoints disabled. (%lu breakpoints)\n", num_breakpoints);
11105a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
11115a988416SJim Ingham         }
11125a988416SJim Ingham         else
11135a988416SJim Ingham         {
11145a988416SJim Ingham             // Particular breakpoint selected; disable that breakpoint.
11155a988416SJim Ingham             BreakpointIDList valid_bp_ids;
11165a988416SJim Ingham 
11175a988416SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
11185a988416SJim Ingham 
11195a988416SJim Ingham             if (result.Succeeded())
11205a988416SJim Ingham             {
11215a988416SJim Ingham                 int disable_count = 0;
11225a988416SJim Ingham                 int loc_count = 0;
11235a988416SJim Ingham                 const size_t count = valid_bp_ids.GetSize();
11245a988416SJim Ingham                 for (size_t i = 0; i < count; ++i)
11255a988416SJim Ingham                 {
11265a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
11275a988416SJim Ingham 
11285a988416SJim Ingham                     if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
11295a988416SJim Ingham                     {
11305a988416SJim Ingham                         Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
11315a988416SJim Ingham                         if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
11325a988416SJim Ingham                         {
11335a988416SJim Ingham                             BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
11345a988416SJim Ingham                             if (location)
11355a988416SJim Ingham                             {
11365a988416SJim Ingham                                 location->SetEnabled (false);
11375a988416SJim Ingham                                 ++loc_count;
11385a988416SJim Ingham                             }
11395a988416SJim Ingham                         }
11405a988416SJim Ingham                         else
11415a988416SJim Ingham                         {
11425a988416SJim Ingham                             breakpoint->SetEnabled (false);
11435a988416SJim Ingham                             ++disable_count;
11445a988416SJim Ingham                         }
11455a988416SJim Ingham                     }
11465a988416SJim Ingham                 }
11475a988416SJim Ingham                 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
11485a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
11495a988416SJim Ingham             }
11505a988416SJim Ingham         }
11515a988416SJim Ingham 
11525a988416SJim Ingham         return result.Succeeded();
11535a988416SJim Ingham     }
11545a988416SJim Ingham 
11555a988416SJim Ingham };
11565a988416SJim Ingham 
11575a988416SJim Ingham //-------------------------------------------------------------------------
11585a988416SJim Ingham // CommandObjectBreakpointList
11595a988416SJim Ingham //-------------------------------------------------------------------------
11605a988416SJim Ingham #pragma mark List
11615a988416SJim Ingham 
11625a988416SJim Ingham class CommandObjectBreakpointList : public CommandObjectParsed
11635a988416SJim Ingham {
11645a988416SJim Ingham public:
11655a988416SJim Ingham     CommandObjectBreakpointList (CommandInterpreter &interpreter) :
11665a988416SJim Ingham         CommandObjectParsed (interpreter,
11675a988416SJim Ingham                              "breakpoint list",
11685a988416SJim Ingham                              "List some or all breakpoints at configurable levels of detail.",
11695a988416SJim Ingham                              NULL),
11705a988416SJim Ingham         m_options (interpreter)
11715a988416SJim Ingham     {
11725a988416SJim Ingham         CommandArgumentEntry arg;
11735a988416SJim Ingham         CommandArgumentData bp_id_arg;
11745a988416SJim Ingham 
11755a988416SJim Ingham         // Define the first (and only) variant of this arg.
11765a988416SJim Ingham         bp_id_arg.arg_type = eArgTypeBreakpointID;
11775a988416SJim Ingham         bp_id_arg.arg_repetition = eArgRepeatOptional;
11785a988416SJim Ingham 
11795a988416SJim Ingham         // There is only one variant this argument could be; put it into the argument entry.
11805a988416SJim Ingham         arg.push_back (bp_id_arg);
11815a988416SJim Ingham 
11825a988416SJim Ingham         // Push the data for the first argument into the m_arguments vector.
11835a988416SJim Ingham         m_arguments.push_back (arg);
11845a988416SJim Ingham     }
11855a988416SJim Ingham 
11865a988416SJim Ingham 
11875a988416SJim Ingham     virtual
11885a988416SJim Ingham     ~CommandObjectBreakpointList () {}
11895a988416SJim Ingham 
11905a988416SJim Ingham     virtual Options *
11915a988416SJim Ingham     GetOptions ()
11925a988416SJim Ingham     {
11935a988416SJim Ingham         return &m_options;
11945a988416SJim Ingham     }
11955a988416SJim Ingham 
11965a988416SJim Ingham     class CommandOptions : public Options
11975a988416SJim Ingham     {
11985a988416SJim Ingham     public:
11995a988416SJim Ingham 
12005a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
12015a988416SJim Ingham             Options (interpreter),
12025a988416SJim Ingham             m_level (lldb::eDescriptionLevelBrief)  // Breakpoint List defaults to brief descriptions
12035a988416SJim Ingham         {
12045a988416SJim Ingham         }
12055a988416SJim Ingham 
12065a988416SJim Ingham         virtual
12075a988416SJim Ingham         ~CommandOptions () {}
12085a988416SJim Ingham 
12095a988416SJim Ingham         virtual Error
12105a988416SJim Ingham         SetOptionValue (uint32_t option_idx, const char *option_arg)
12115a988416SJim Ingham         {
12125a988416SJim Ingham             Error error;
12135a988416SJim Ingham             char short_option = (char) m_getopt_table[option_idx].val;
12145a988416SJim Ingham 
12155a988416SJim Ingham             switch (short_option)
12165a988416SJim Ingham             {
12175a988416SJim Ingham                 case 'b':
12185a988416SJim Ingham                     m_level = lldb::eDescriptionLevelBrief;
12195a988416SJim Ingham                     break;
12205a988416SJim Ingham                 case 'f':
12215a988416SJim Ingham                     m_level = lldb::eDescriptionLevelFull;
12225a988416SJim Ingham                     break;
12235a988416SJim Ingham                 case 'v':
12245a988416SJim Ingham                     m_level = lldb::eDescriptionLevelVerbose;
12255a988416SJim Ingham                     break;
12265a988416SJim Ingham                 case 'i':
12275a988416SJim Ingham                     m_internal = true;
12285a988416SJim Ingham                     break;
12295a988416SJim Ingham                 default:
12305a988416SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
12315a988416SJim Ingham                     break;
12325a988416SJim Ingham             }
12335a988416SJim Ingham 
12345a988416SJim Ingham             return error;
12355a988416SJim Ingham         }
12365a988416SJim Ingham 
12375a988416SJim Ingham         void
12385a988416SJim Ingham         OptionParsingStarting ()
12395a988416SJim Ingham         {
12405a988416SJim Ingham             m_level = lldb::eDescriptionLevelFull;
12415a988416SJim Ingham             m_internal = false;
12425a988416SJim Ingham         }
12435a988416SJim Ingham 
12445a988416SJim Ingham         const OptionDefinition *
12455a988416SJim Ingham         GetDefinitions ()
12465a988416SJim Ingham         {
12475a988416SJim Ingham             return g_option_table;
12485a988416SJim Ingham         }
12495a988416SJim Ingham 
12505a988416SJim Ingham         // Options table: Required for subclasses of Options.
12515a988416SJim Ingham 
12525a988416SJim Ingham         static OptionDefinition g_option_table[];
12535a988416SJim Ingham 
12545a988416SJim Ingham         // Instance variables to hold the values for command options.
12555a988416SJim Ingham 
12565a988416SJim Ingham         lldb::DescriptionLevel m_level;
12575a988416SJim Ingham 
12585a988416SJim Ingham         bool m_internal;
12595a988416SJim Ingham     };
12605a988416SJim Ingham 
12615a988416SJim Ingham protected:
12625a988416SJim Ingham     virtual bool
12635a988416SJim Ingham     DoExecute (Args& command, CommandReturnObject &result)
12645a988416SJim Ingham     {
12655a988416SJim Ingham         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
12665a988416SJim Ingham         if (target == NULL)
12675a988416SJim Ingham         {
12685a988416SJim Ingham             result.AppendError ("Invalid target. No current target or breakpoints.");
12695a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
12705a988416SJim Ingham             return true;
12715a988416SJim Ingham         }
12725a988416SJim Ingham 
12735a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
12745a988416SJim Ingham         Mutex::Locker locker;
12755a988416SJim Ingham         target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
12765a988416SJim Ingham 
12775a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
12785a988416SJim Ingham 
12795a988416SJim Ingham         if (num_breakpoints == 0)
12805a988416SJim Ingham         {
12815a988416SJim Ingham             result.AppendMessage ("No breakpoints currently set.");
12825a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
12835a988416SJim Ingham             return true;
12845a988416SJim Ingham         }
12855a988416SJim Ingham 
12865a988416SJim Ingham         Stream &output_stream = result.GetOutputStream();
12875a988416SJim Ingham 
12885a988416SJim Ingham         if (command.GetArgumentCount() == 0)
12895a988416SJim Ingham         {
12905a988416SJim Ingham             // No breakpoint selected; show info about all currently set breakpoints.
12915a988416SJim Ingham             result.AppendMessage ("Current breakpoints:");
12925a988416SJim Ingham             for (size_t i = 0; i < num_breakpoints; ++i)
12935a988416SJim Ingham             {
12945a988416SJim Ingham                 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
12955a988416SJim Ingham                 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
12965a988416SJim Ingham             }
12975a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
12985a988416SJim Ingham         }
12995a988416SJim Ingham         else
13005a988416SJim Ingham         {
13015a988416SJim Ingham             // Particular breakpoints selected; show info about that breakpoint.
13025a988416SJim Ingham             BreakpointIDList valid_bp_ids;
13035a988416SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
13045a988416SJim Ingham 
13055a988416SJim Ingham             if (result.Succeeded())
13065a988416SJim Ingham             {
13075a988416SJim Ingham                 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
13085a988416SJim Ingham                 {
13095a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
13105a988416SJim Ingham                     Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
13115a988416SJim Ingham                     AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
13125a988416SJim Ingham                 }
13135a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
13145a988416SJim Ingham             }
13155a988416SJim Ingham             else
13165a988416SJim Ingham             {
13175a988416SJim Ingham                 result.AppendError ("Invalid breakpoint id.");
13185a988416SJim Ingham                 result.SetStatus (eReturnStatusFailed);
13195a988416SJim Ingham             }
13205a988416SJim Ingham         }
13215a988416SJim Ingham 
13225a988416SJim Ingham         return result.Succeeded();
13235a988416SJim Ingham     }
13245a988416SJim Ingham 
13255a988416SJim Ingham private:
13265a988416SJim Ingham     CommandOptions m_options;
13275a988416SJim Ingham };
13285a988416SJim Ingham 
13295a988416SJim Ingham #pragma mark List::CommandOptions
13305a988416SJim Ingham OptionDefinition
13315a988416SJim Ingham CommandObjectBreakpointList::CommandOptions::g_option_table[] =
13325a988416SJim Ingham {
13335a988416SJim Ingham     { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone,
13345a988416SJim Ingham         "Show debugger internal breakpoints" },
13355a988416SJim Ingham 
13365a988416SJim Ingham     { LLDB_OPT_SET_1, false, "brief",    'b', no_argument, NULL, 0, eArgTypeNone,
13375a988416SJim Ingham         "Give a brief description of the breakpoint (no location info)."},
13385a988416SJim Ingham 
13395a988416SJim Ingham     // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
13405a988416SJim Ingham     // But I need to see it for now, and don't want to wait.
13415a988416SJim Ingham     { LLDB_OPT_SET_2, false, "full",    'f', no_argument, NULL, 0, eArgTypeNone,
13425a988416SJim Ingham         "Give a full description of the breakpoint and its locations."},
13435a988416SJim Ingham 
13445a988416SJim Ingham     { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone,
13455a988416SJim Ingham         "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
13465a988416SJim Ingham 
13475a988416SJim Ingham     { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
13485a988416SJim Ingham };
13495a988416SJim Ingham 
13505a988416SJim Ingham //-------------------------------------------------------------------------
13515a988416SJim Ingham // CommandObjectBreakpointClear
13525a988416SJim Ingham //-------------------------------------------------------------------------
13535a988416SJim Ingham #pragma mark Clear
13545a988416SJim Ingham 
13555a988416SJim Ingham class CommandObjectBreakpointClear : public CommandObjectParsed
13565a988416SJim Ingham {
13575a988416SJim Ingham public:
13585a988416SJim Ingham 
13595a988416SJim Ingham     typedef enum BreakpointClearType
13605a988416SJim Ingham     {
13615a988416SJim Ingham         eClearTypeInvalid,
13625a988416SJim Ingham         eClearTypeFileAndLine
13635a988416SJim Ingham     } BreakpointClearType;
13645a988416SJim Ingham 
13655a988416SJim Ingham     CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
13665a988416SJim Ingham         CommandObjectParsed (interpreter,
13675a988416SJim Ingham                              "breakpoint clear",
13685a988416SJim Ingham                              "Clears a breakpoint or set of breakpoints in the executable.",
13695a988416SJim Ingham                              "breakpoint clear <cmd-options>"),
13705a988416SJim Ingham         m_options (interpreter)
13715a988416SJim Ingham     {
13725a988416SJim Ingham     }
13735a988416SJim Ingham 
13745a988416SJim Ingham     virtual
13755a988416SJim Ingham     ~CommandObjectBreakpointClear () {}
13765a988416SJim Ingham 
13775a988416SJim Ingham     virtual Options *
13785a988416SJim Ingham     GetOptions ()
13795a988416SJim Ingham     {
13805a988416SJim Ingham         return &m_options;
13815a988416SJim Ingham     }
13825a988416SJim Ingham 
13835a988416SJim Ingham     class CommandOptions : public Options
13845a988416SJim Ingham     {
13855a988416SJim Ingham     public:
13865a988416SJim Ingham 
13875a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
13885a988416SJim Ingham             Options (interpreter),
13895a988416SJim Ingham             m_filename (),
13905a988416SJim Ingham             m_line_num (0)
13915a988416SJim Ingham         {
13925a988416SJim Ingham         }
13935a988416SJim Ingham 
13945a988416SJim Ingham         virtual
13955a988416SJim Ingham         ~CommandOptions () {}
13965a988416SJim Ingham 
13975a988416SJim Ingham         virtual Error
13985a988416SJim Ingham         SetOptionValue (uint32_t option_idx, const char *option_arg)
13995a988416SJim Ingham         {
14005a988416SJim Ingham             Error error;
14015a988416SJim Ingham             char short_option = (char) m_getopt_table[option_idx].val;
14025a988416SJim Ingham 
14035a988416SJim Ingham             switch (short_option)
14045a988416SJim Ingham             {
14055a988416SJim Ingham                 case 'f':
14065a988416SJim Ingham                     m_filename.assign (option_arg);
14075a988416SJim Ingham                     break;
14085a988416SJim Ingham 
14095a988416SJim Ingham                 case 'l':
14105a988416SJim Ingham                     m_line_num = Args::StringToUInt32 (option_arg, 0);
14115a988416SJim Ingham                     break;
14125a988416SJim Ingham 
14135a988416SJim Ingham                 default:
14145a988416SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
14155a988416SJim Ingham                     break;
14165a988416SJim Ingham             }
14175a988416SJim Ingham 
14185a988416SJim Ingham             return error;
14195a988416SJim Ingham         }
14205a988416SJim Ingham 
14215a988416SJim Ingham         void
14225a988416SJim Ingham         OptionParsingStarting ()
14235a988416SJim Ingham         {
14245a988416SJim Ingham             m_filename.clear();
14255a988416SJim Ingham             m_line_num = 0;
14265a988416SJim Ingham         }
14275a988416SJim Ingham 
14285a988416SJim Ingham         const OptionDefinition*
14295a988416SJim Ingham         GetDefinitions ()
14305a988416SJim Ingham         {
14315a988416SJim Ingham             return g_option_table;
14325a988416SJim Ingham         }
14335a988416SJim Ingham 
14345a988416SJim Ingham         // Options table: Required for subclasses of Options.
14355a988416SJim Ingham 
14365a988416SJim Ingham         static OptionDefinition g_option_table[];
14375a988416SJim Ingham 
14385a988416SJim Ingham         // Instance variables to hold the values for command options.
14395a988416SJim Ingham 
14405a988416SJim Ingham         std::string m_filename;
14415a988416SJim Ingham         uint32_t m_line_num;
14425a988416SJim Ingham 
14435a988416SJim Ingham     };
14445a988416SJim Ingham 
14455a988416SJim Ingham protected:
14465a988416SJim Ingham     virtual bool
14475a988416SJim Ingham     DoExecute (Args& command, CommandReturnObject &result)
14485a988416SJim Ingham     {
14495a988416SJim Ingham         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
14505a988416SJim Ingham         if (target == NULL)
14515a988416SJim Ingham         {
14525a988416SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
14535a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
14545a988416SJim Ingham             return false;
14555a988416SJim Ingham         }
14565a988416SJim Ingham 
14575a988416SJim Ingham         // The following are the various types of breakpoints that could be cleared:
14585a988416SJim Ingham         //   1). -f -l (clearing breakpoint by source location)
14595a988416SJim Ingham 
14605a988416SJim Ingham         BreakpointClearType break_type = eClearTypeInvalid;
14615a988416SJim Ingham 
14625a988416SJim Ingham         if (m_options.m_line_num != 0)
14635a988416SJim Ingham             break_type = eClearTypeFileAndLine;
14645a988416SJim Ingham 
14655a988416SJim Ingham         Mutex::Locker locker;
14665a988416SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
14675a988416SJim Ingham 
14685a988416SJim Ingham         BreakpointList &breakpoints = target->GetBreakpointList();
14695a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
14705a988416SJim Ingham 
14715a988416SJim Ingham         // Early return if there's no breakpoint at all.
14725a988416SJim Ingham         if (num_breakpoints == 0)
14735a988416SJim Ingham         {
14745a988416SJim Ingham             result.AppendError ("Breakpoint clear: No breakpoint cleared.");
14755a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
14765a988416SJim Ingham             return result.Succeeded();
14775a988416SJim Ingham         }
14785a988416SJim Ingham 
14795a988416SJim Ingham         // Find matching breakpoints and delete them.
14805a988416SJim Ingham 
14815a988416SJim Ingham         // First create a copy of all the IDs.
14825a988416SJim Ingham         std::vector<break_id_t> BreakIDs;
14835a988416SJim Ingham         for (size_t i = 0; i < num_breakpoints; ++i)
14845a988416SJim Ingham             BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID());
14855a988416SJim Ingham 
14865a988416SJim Ingham         int num_cleared = 0;
14875a988416SJim Ingham         StreamString ss;
14885a988416SJim Ingham         switch (break_type)
14895a988416SJim Ingham         {
14905a988416SJim Ingham             case eClearTypeFileAndLine: // Breakpoint by source position
14915a988416SJim Ingham                 {
14925a988416SJim Ingham                     const ConstString filename(m_options.m_filename.c_str());
14935a988416SJim Ingham                     BreakpointLocationCollection loc_coll;
14945a988416SJim Ingham 
14955a988416SJim Ingham                     for (size_t i = 0; i < num_breakpoints; ++i)
14965a988416SJim Ingham                     {
14975a988416SJim Ingham                         Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
14985a988416SJim Ingham 
14995a988416SJim Ingham                         if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
15005a988416SJim Ingham                         {
15015a988416SJim Ingham                             // If the collection size is 0, it's a full match and we can just remove the breakpoint.
15025a988416SJim Ingham                             if (loc_coll.GetSize() == 0)
15035a988416SJim Ingham                             {
15045a988416SJim Ingham                                 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
15055a988416SJim Ingham                                 ss.EOL();
15065a988416SJim Ingham                                 target->RemoveBreakpointByID (bp->GetID());
15075a988416SJim Ingham                                 ++num_cleared;
15085a988416SJim Ingham                             }
15095a988416SJim Ingham                         }
15105a988416SJim Ingham                     }
15115a988416SJim Ingham                 }
15125a988416SJim Ingham                 break;
15135a988416SJim Ingham 
15145a988416SJim Ingham             default:
15155a988416SJim Ingham                 break;
15165a988416SJim Ingham         }
15175a988416SJim Ingham 
15185a988416SJim Ingham         if (num_cleared > 0)
15195a988416SJim Ingham         {
15205a988416SJim Ingham             Stream &output_stream = result.GetOutputStream();
15215a988416SJim Ingham             output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
15225a988416SJim Ingham             output_stream << ss.GetData();
15235a988416SJim Ingham             output_stream.EOL();
15245a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
15255a988416SJim Ingham         }
15265a988416SJim Ingham         else
15275a988416SJim Ingham         {
15285a988416SJim Ingham             result.AppendError ("Breakpoint clear: No breakpoint cleared.");
15295a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
15305a988416SJim Ingham         }
15315a988416SJim Ingham 
15325a988416SJim Ingham         return result.Succeeded();
15335a988416SJim Ingham     }
15345a988416SJim Ingham 
15355a988416SJim Ingham private:
15365a988416SJim Ingham     CommandOptions m_options;
15375a988416SJim Ingham };
15385a988416SJim Ingham 
15395a988416SJim Ingham #pragma mark Clear::CommandOptions
15405a988416SJim Ingham 
15415a988416SJim Ingham OptionDefinition
15425a988416SJim Ingham CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
15435a988416SJim Ingham {
15445a988416SJim Ingham     { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
15455a988416SJim Ingham         "Specify the breakpoint by source location in this particular file."},
15465a988416SJim Ingham 
15475a988416SJim Ingham     { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
15485a988416SJim Ingham         "Specify the breakpoint by source location at this particular line."},
15495a988416SJim Ingham 
15505a988416SJim Ingham     { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
15515a988416SJim Ingham };
15525a988416SJim Ingham 
15535a988416SJim Ingham //-------------------------------------------------------------------------
15545a988416SJim Ingham // CommandObjectBreakpointDelete
15555a988416SJim Ingham //-------------------------------------------------------------------------
15565a988416SJim Ingham #pragma mark Delete
15575a988416SJim Ingham 
15585a988416SJim Ingham class CommandObjectBreakpointDelete : public CommandObjectParsed
15595a988416SJim Ingham {
15605a988416SJim Ingham public:
15615a988416SJim Ingham     CommandObjectBreakpointDelete (CommandInterpreter &interpreter) :
15625a988416SJim Ingham         CommandObjectParsed (interpreter,
15635a988416SJim Ingham                              "breakpoint delete",
15645a988416SJim Ingham                              "Delete the specified breakpoint(s).  If no breakpoints are specified, delete them all.",
15655a988416SJim Ingham                              NULL)
15665a988416SJim Ingham     {
15675a988416SJim Ingham         CommandArgumentEntry arg;
15685a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
15695a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
15705a988416SJim Ingham         m_arguments.push_back (arg);
15715a988416SJim Ingham     }
15725a988416SJim Ingham 
15735a988416SJim Ingham     virtual
15745a988416SJim Ingham     ~CommandObjectBreakpointDelete () {}
15755a988416SJim Ingham 
15765a988416SJim Ingham protected:
15775a988416SJim Ingham     virtual bool
15785a988416SJim Ingham     DoExecute (Args& command, CommandReturnObject &result)
15795a988416SJim Ingham     {
15805a988416SJim Ingham         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
15815a988416SJim Ingham         if (target == NULL)
15825a988416SJim Ingham         {
15835a988416SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
15845a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
15855a988416SJim Ingham             return false;
15865a988416SJim Ingham         }
15875a988416SJim Ingham 
15885a988416SJim Ingham         Mutex::Locker locker;
15895a988416SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
15905a988416SJim Ingham 
15915a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
15925a988416SJim Ingham 
15935a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
15945a988416SJim Ingham 
15955a988416SJim Ingham         if (num_breakpoints == 0)
15965a988416SJim Ingham         {
15975a988416SJim Ingham             result.AppendError ("No breakpoints exist to be deleted.");
15985a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
15995a988416SJim Ingham             return false;
16005a988416SJim Ingham         }
16015a988416SJim Ingham 
16025a988416SJim Ingham         if (command.GetArgumentCount() == 0)
16035a988416SJim Ingham         {
16045a988416SJim Ingham             if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
16055a988416SJim Ingham             {
16065a988416SJim Ingham                 result.AppendMessage("Operation cancelled...");
16075a988416SJim Ingham             }
16085a988416SJim Ingham             else
16095a988416SJim Ingham             {
16105a988416SJim Ingham                 target->RemoveAllBreakpoints ();
16115a988416SJim Ingham                 result.AppendMessageWithFormat ("All breakpoints removed. (%lu breakpoints)\n", num_breakpoints);
16125a988416SJim Ingham             }
16135a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
16145a988416SJim Ingham         }
16155a988416SJim Ingham         else
16165a988416SJim Ingham         {
16175a988416SJim Ingham             // Particular breakpoint selected; disable that breakpoint.
16185a988416SJim Ingham             BreakpointIDList valid_bp_ids;
16195a988416SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
16205a988416SJim Ingham 
16215a988416SJim Ingham             if (result.Succeeded())
16225a988416SJim Ingham             {
16235a988416SJim Ingham                 int delete_count = 0;
16245a988416SJim Ingham                 int disable_count = 0;
16255a988416SJim Ingham                 const size_t count = valid_bp_ids.GetSize();
16265a988416SJim Ingham                 for (size_t i = 0; i < count; ++i)
16275a988416SJim Ingham                 {
16285a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
16295a988416SJim Ingham 
16305a988416SJim Ingham                     if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
16315a988416SJim Ingham                     {
16325a988416SJim Ingham                         if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
16335a988416SJim Ingham                         {
16345a988416SJim Ingham                             Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
16355a988416SJim Ingham                             BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
16365a988416SJim Ingham                             // It makes no sense to try to delete individual locations, so we disable them instead.
16375a988416SJim Ingham                             if (location)
16385a988416SJim Ingham                             {
16395a988416SJim Ingham                                 location->SetEnabled (false);
16405a988416SJim Ingham                                 ++disable_count;
16415a988416SJim Ingham                             }
16425a988416SJim Ingham                         }
16435a988416SJim Ingham                         else
16445a988416SJim Ingham                         {
16455a988416SJim Ingham                             target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
16465a988416SJim Ingham                             ++delete_count;
16475a988416SJim Ingham                         }
16485a988416SJim Ingham                     }
16495a988416SJim Ingham                 }
16505a988416SJim Ingham                 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
16515a988416SJim Ingham                                                delete_count, disable_count);
16525a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
16535a988416SJim Ingham             }
16545a988416SJim Ingham         }
16555a988416SJim Ingham         return result.Succeeded();
16565a988416SJim Ingham     }
16575a988416SJim Ingham };
16585a988416SJim Ingham 
165930fdc8d8SChris Lattner //-------------------------------------------------------------------------
166030fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint
166130fdc8d8SChris Lattner //-------------------------------------------------------------------------
1662ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint
166330fdc8d8SChris Lattner 
16646611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
1665a7015092SGreg Clayton     CommandObjectMultiword (interpreter,
1666a7015092SGreg Clayton                             "breakpoint",
166746fbc60fSJim Ingham                             "A set of commands for operating on breakpoints. Also see _regexp-break.",
166830fdc8d8SChris Lattner                             "breakpoint <command> [<command-options>]")
166930fdc8d8SChris Lattner {
1670a7015092SGreg Clayton     CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
1671a7015092SGreg Clayton     CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
1672a7015092SGreg Clayton     CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
1673b7234e40SJohnny Chen     CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
1674b7234e40SJohnny Chen     CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
1675a7015092SGreg Clayton     CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
167630fdc8d8SChris Lattner     CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
1677a7015092SGreg Clayton     CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
167830fdc8d8SChris Lattner 
1679b7234e40SJohnny Chen     list_command_object->SetCommandName ("breakpoint list");
168030fdc8d8SChris Lattner     enable_command_object->SetCommandName("breakpoint enable");
168130fdc8d8SChris Lattner     disable_command_object->SetCommandName("breakpoint disable");
1682b7234e40SJohnny Chen     clear_command_object->SetCommandName("breakpoint clear");
1683b7234e40SJohnny Chen     delete_command_object->SetCommandName("breakpoint delete");
1684ae1c4cf5SJim Ingham     set_command_object->SetCommandName("breakpoint set");
1685b7234e40SJohnny Chen     command_command_object->SetCommandName ("breakpoint command");
1686b7234e40SJohnny Chen     modify_command_object->SetCommandName ("breakpoint modify");
168730fdc8d8SChris Lattner 
1688*23f59509SGreg Clayton     LoadSubCommand ("list",       list_command_object);
1689*23f59509SGreg Clayton     LoadSubCommand ("enable",     enable_command_object);
1690*23f59509SGreg Clayton     LoadSubCommand ("disable",    disable_command_object);
1691*23f59509SGreg Clayton     LoadSubCommand ("clear",      clear_command_object);
1692*23f59509SGreg Clayton     LoadSubCommand ("delete",     delete_command_object);
1693*23f59509SGreg Clayton     LoadSubCommand ("set",        set_command_object);
1694*23f59509SGreg Clayton     LoadSubCommand ("command",    command_command_object);
1695*23f59509SGreg Clayton     LoadSubCommand ("modify",     modify_command_object);
169630fdc8d8SChris Lattner }
169730fdc8d8SChris Lattner 
169830fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
169930fdc8d8SChris Lattner {
170030fdc8d8SChris Lattner }
170130fdc8d8SChris Lattner 
170230fdc8d8SChris Lattner void
170330fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result,
170430fdc8d8SChris Lattner                                                          BreakpointIDList *valid_ids)
170530fdc8d8SChris Lattner {
170630fdc8d8SChris Lattner     // args can be strings representing 1). integers (for breakpoint ids)
170730fdc8d8SChris Lattner     //                                  2). the full breakpoint & location canonical representation
170830fdc8d8SChris Lattner     //                                  3). the word "to" or a hyphen, representing a range (in which case there
170930fdc8d8SChris Lattner     //                                      had *better* be an entry both before & after of one of the first two types.
171036f3b369SJim Ingham     // If args is empty, we will use the last created breakpoint (if there is one.)
171130fdc8d8SChris Lattner 
171230fdc8d8SChris Lattner     Args temp_args;
171330fdc8d8SChris Lattner 
171436f3b369SJim Ingham     if (args.GetArgumentCount() == 0)
171536f3b369SJim Ingham     {
17164d122c40SGreg Clayton         if (target->GetLastCreatedBreakpoint())
171736f3b369SJim Ingham         {
171836f3b369SJim Ingham             valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
171936f3b369SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
172036f3b369SJim Ingham         }
172136f3b369SJim Ingham         else
172236f3b369SJim Ingham         {
172336f3b369SJim Ingham             result.AppendError("No breakpoint specified and no last created breakpoint.");
172436f3b369SJim Ingham             result.SetStatus (eReturnStatusFailed);
172536f3b369SJim Ingham         }
172636f3b369SJim Ingham         return;
172736f3b369SJim Ingham     }
172836f3b369SJim Ingham 
172930fdc8d8SChris Lattner     // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
173030fdc8d8SChris Lattner     // the new TEMP_ARGS.  Do not copy breakpoint id range strings over; instead generate a list of strings for
173130fdc8d8SChris Lattner     // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
173230fdc8d8SChris Lattner 
173330fdc8d8SChris Lattner     BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
173430fdc8d8SChris Lattner 
173530fdc8d8SChris Lattner     // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
173630fdc8d8SChris Lattner 
1737c982c768SGreg Clayton     valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
173830fdc8d8SChris Lattner 
173930fdc8d8SChris Lattner     // At this point,  all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
174030fdc8d8SChris Lattner     // and put into valid_ids.
174130fdc8d8SChris Lattner 
174230fdc8d8SChris Lattner     if (result.Succeeded())
174330fdc8d8SChris Lattner     {
174430fdc8d8SChris Lattner         // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
174530fdc8d8SChris Lattner         // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
174630fdc8d8SChris Lattner 
1747c982c768SGreg Clayton         const size_t count = valid_ids->GetSize();
1748c982c768SGreg Clayton         for (size_t i = 0; i < count; ++i)
174930fdc8d8SChris Lattner         {
175030fdc8d8SChris Lattner             BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
175130fdc8d8SChris Lattner             Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
175230fdc8d8SChris Lattner             if (breakpoint != NULL)
175330fdc8d8SChris Lattner             {
175430fdc8d8SChris Lattner                 int num_locations = breakpoint->GetNumLocations();
175530fdc8d8SChris Lattner                 if (cur_bp_id.GetLocationID() > num_locations)
175630fdc8d8SChris Lattner                 {
175730fdc8d8SChris Lattner                     StreamString id_str;
1758c982c768SGreg Clayton                     BreakpointID::GetCanonicalReference (&id_str,
1759c982c768SGreg Clayton                                                          cur_bp_id.GetBreakpointID(),
176030fdc8d8SChris Lattner                                                          cur_bp_id.GetLocationID());
1761c982c768SGreg Clayton                     i = valid_ids->GetSize() + 1;
176230fdc8d8SChris Lattner                     result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
176330fdc8d8SChris Lattner                                                  id_str.GetData());
176430fdc8d8SChris Lattner                     result.SetStatus (eReturnStatusFailed);
176530fdc8d8SChris Lattner                 }
176630fdc8d8SChris Lattner             }
176730fdc8d8SChris Lattner             else
176830fdc8d8SChris Lattner             {
1769c982c768SGreg Clayton                 i = valid_ids->GetSize() + 1;
177030fdc8d8SChris Lattner                 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
177130fdc8d8SChris Lattner                 result.SetStatus (eReturnStatusFailed);
177230fdc8d8SChris Lattner             }
177330fdc8d8SChris Lattner         }
177430fdc8d8SChris Lattner     }
177530fdc8d8SChris Lattner }
1776