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 
3130fdc8d8SChris Lattner using namespace lldb;
3230fdc8d8SChris Lattner using namespace lldb_private;
3330fdc8d8SChris Lattner 
3430fdc8d8SChris Lattner static void
356611103cSGreg Clayton AddBreakpointDescription (StreamString *s, Breakpoint *bp, lldb::DescriptionLevel level)
3630fdc8d8SChris Lattner {
3730fdc8d8SChris Lattner     s->IndentMore();
3830fdc8d8SChris Lattner     bp->GetDescription (s, level, true);
3930fdc8d8SChris Lattner     s->IndentLess();
4030fdc8d8SChris Lattner     s->EOL();
4130fdc8d8SChris Lattner }
4230fdc8d8SChris Lattner 
4330fdc8d8SChris Lattner //-------------------------------------------------------------------------
4430fdc8d8SChris Lattner // CommandObjectBreakpointSet::CommandOptions
4530fdc8d8SChris Lattner //-------------------------------------------------------------------------
46ae1c4cf5SJim Ingham #pragma mark Set::CommandOptions
4730fdc8d8SChris Lattner 
4830fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::CommandOptions() :
4930fdc8d8SChris Lattner     Options (),
5030fdc8d8SChris Lattner     m_filename (),
5130fdc8d8SChris Lattner     m_line_num (0),
5230fdc8d8SChris Lattner     m_column (0),
5330fdc8d8SChris Lattner     m_ignore_inlines (false),
5430fdc8d8SChris Lattner     m_func_name (),
550c5cd90dSGreg Clayton     m_func_name_type_mask (0),
5630fdc8d8SChris Lattner     m_func_regexp (),
5730fdc8d8SChris Lattner     m_modules (),
581b54c88cSJim Ingham     m_load_addr(),
59c982c768SGreg Clayton     m_ignore_count (0),
601b54c88cSJim Ingham     m_thread_id(LLDB_INVALID_THREAD_ID),
61c982c768SGreg Clayton     m_thread_index (UINT32_MAX),
621b54c88cSJim Ingham     m_thread_name(),
63c982c768SGreg Clayton     m_queue_name()
6430fdc8d8SChris Lattner {
6530fdc8d8SChris Lattner }
6630fdc8d8SChris Lattner 
6730fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::~CommandOptions ()
6830fdc8d8SChris Lattner {
6930fdc8d8SChris Lattner }
7030fdc8d8SChris Lattner 
7130fdc8d8SChris Lattner lldb::OptionDefinition
7230fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
7330fdc8d8SChris Lattner {
74deaab222SCaroline Tice     { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
758651121cSJim Ingham         "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."},
768651121cSJim Ingham 
77deaab222SCaroline Tice     { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument,   NULL, 0, eArgTypeCount,
78deaab222SCaroline Tice         "Set the number of times this breakpoint is skipped before stopping." },
791b54c88cSJim Ingham 
80deaab222SCaroline Tice     { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex,
81ed8a705cSGreg Clayton         "The breakpoint stops only for the thread whose index matches this argument."},
821b54c88cSJim Ingham 
83deaab222SCaroline Tice     { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, eArgTypeThreadID,
841b54c88cSJim Ingham         "The breakpoint stops only for the thread whose TID matches this argument."},
851b54c88cSJim Ingham 
86deaab222SCaroline Tice     { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, eArgTypeThreadName,
871b54c88cSJim Ingham         "The breakpoint stops only for the thread whose thread name matches this argument."},
881b54c88cSJim Ingham 
89deaab222SCaroline Tice     { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, eArgTypeQueueName,
901b54c88cSJim Ingham         "The breakpoint stops only for threads in the queue whose name is given by this argument."},
911b54c88cSJim Ingham 
92deaab222SCaroline Tice     { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
9330fdc8d8SChris Lattner         "Set the breakpoint by source location in this particular file."},
9430fdc8d8SChris Lattner 
95deaab222SCaroline Tice     { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
9630fdc8d8SChris Lattner         "Set the breakpoint by source location at this particular line."},
9730fdc8d8SChris Lattner 
9830fdc8d8SChris Lattner     // Comment out this option for the moment, as we don't actually use it, but will in the future.
9930fdc8d8SChris Lattner     // This way users won't see it, but the infrastructure is left in place.
10030fdc8d8SChris Lattner     //    { 0, false, "column",     'c', required_argument, NULL, "<column>",
10130fdc8d8SChris Lattner     //    "Set the breakpoint by source location at this particular column."},
10230fdc8d8SChris Lattner 
103deaab222SCaroline Tice     { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress,
10430fdc8d8SChris Lattner         "Set the breakpoint by address, at the specified address."},
10530fdc8d8SChris Lattner 
106deaab222SCaroline Tice     { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
107e02b8504SGreg Clayton         "Set the breakpoint by function name." },
10830fdc8d8SChris Lattner 
109deaab222SCaroline Tice     { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
1102561aa61SJim Ingham         "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguemnts, and "
1112561aa61SJim Ingham         "for Objective C this means a full function prototype with class and selector." },
1120c5cd90dSGreg Clayton 
113deaab222SCaroline Tice     { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector,
1142561aa61SJim Ingham         "Set the breakpoint by ObjC selector name." },
1150c5cd90dSGreg Clayton 
116deaab222SCaroline Tice     { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod,
1172561aa61SJim Ingham         "Set the breakpoint by C++ method names." },
1180c5cd90dSGreg Clayton 
119deaab222SCaroline Tice     { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression,
12030fdc8d8SChris Lattner         "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
12130fdc8d8SChris Lattner 
122e02b8504SGreg Clayton     { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
123e02b8504SGreg Clayton         "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored)." },
124e02b8504SGreg Clayton 
125deaab222SCaroline Tice     { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
12630fdc8d8SChris Lattner };
12730fdc8d8SChris Lattner 
12830fdc8d8SChris Lattner const lldb::OptionDefinition*
12930fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::GetDefinitions ()
13030fdc8d8SChris Lattner {
13130fdc8d8SChris Lattner     return g_option_table;
13230fdc8d8SChris Lattner }
13330fdc8d8SChris Lattner 
13430fdc8d8SChris Lattner Error
13530fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
13630fdc8d8SChris Lattner {
13730fdc8d8SChris Lattner     Error error;
13830fdc8d8SChris Lattner     char short_option = (char) m_getopt_table[option_idx].val;
13930fdc8d8SChris Lattner 
14030fdc8d8SChris Lattner     switch (short_option)
14130fdc8d8SChris Lattner     {
14230fdc8d8SChris Lattner         case 'a':
14330fdc8d8SChris Lattner             m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 0);
14430fdc8d8SChris Lattner             if (m_load_addr == LLDB_INVALID_ADDRESS)
14530fdc8d8SChris Lattner                 m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 16);
14630fdc8d8SChris Lattner 
14730fdc8d8SChris Lattner             if (m_load_addr == LLDB_INVALID_ADDRESS)
14830fdc8d8SChris Lattner                 error.SetErrorStringWithFormat ("Invalid address string '%s'.\n", optarg);
14930fdc8d8SChris Lattner             break;
15030fdc8d8SChris Lattner 
15130fdc8d8SChris Lattner         case 'c':
15230fdc8d8SChris Lattner             m_column = Args::StringToUInt32 (option_arg, 0);
15330fdc8d8SChris Lattner             break;
1540c5cd90dSGreg Clayton 
15530fdc8d8SChris Lattner         case 'f':
15630fdc8d8SChris Lattner             m_filename = option_arg;
15730fdc8d8SChris Lattner             break;
1580c5cd90dSGreg Clayton 
15930fdc8d8SChris Lattner         case 'l':
16030fdc8d8SChris Lattner             m_line_num = Args::StringToUInt32 (option_arg, 0);
16130fdc8d8SChris Lattner             break;
1620c5cd90dSGreg Clayton 
163e02b8504SGreg Clayton         case 'b':
16430fdc8d8SChris Lattner             m_func_name = option_arg;
1650c5cd90dSGreg Clayton             m_func_name_type_mask |= eFunctionNameTypeBase;
1660c5cd90dSGreg Clayton             break;
1670c5cd90dSGreg Clayton 
168e02b8504SGreg Clayton         case 'n':
169e02b8504SGreg Clayton             m_func_name = option_arg;
170e02b8504SGreg Clayton             m_func_name_type_mask |= eFunctionNameTypeAuto;
171e02b8504SGreg Clayton             break;
172e02b8504SGreg Clayton 
1730c5cd90dSGreg Clayton         case 'F':
1742561aa61SJim Ingham             m_func_name = option_arg;
1750c5cd90dSGreg Clayton             m_func_name_type_mask |= eFunctionNameTypeFull;
1760c5cd90dSGreg Clayton             break;
1770c5cd90dSGreg Clayton 
1780c5cd90dSGreg Clayton         case 'S':
1792561aa61SJim Ingham             m_func_name = option_arg;
1800c5cd90dSGreg Clayton             m_func_name_type_mask |= eFunctionNameTypeSelector;
1810c5cd90dSGreg Clayton             break;
1820c5cd90dSGreg Clayton 
1832561aa61SJim Ingham         case 'M':
1842561aa61SJim Ingham             m_func_name = option_arg;
1850c5cd90dSGreg Clayton             m_func_name_type_mask |= eFunctionNameTypeMethod;
1860c5cd90dSGreg Clayton             break;
1870c5cd90dSGreg Clayton 
18830fdc8d8SChris Lattner         case 'r':
18930fdc8d8SChris Lattner             m_func_regexp = option_arg;
19030fdc8d8SChris Lattner             break;
1910c5cd90dSGreg Clayton 
19230fdc8d8SChris Lattner         case 's':
19330fdc8d8SChris Lattner             {
19430fdc8d8SChris Lattner                 m_modules.push_back (std::string (option_arg));
19530fdc8d8SChris Lattner                 break;
19630fdc8d8SChris Lattner             }
197ed8a705cSGreg Clayton         case 'i':
1981b54c88cSJim Ingham         {
199c982c768SGreg Clayton             m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0);
200c982c768SGreg Clayton             if (m_ignore_count == UINT32_MAX)
2011b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg);
2021b54c88cSJim Ingham         }
203ae1c4cf5SJim Ingham         break;
2041b54c88cSJim Ingham         case 't' :
2051b54c88cSJim Ingham         {
2061b54c88cSJim Ingham             m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0);
2071b54c88cSJim Ingham             if (m_thread_id == LLDB_INVALID_THREAD_ID)
2081b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg);
2091b54c88cSJim Ingham         }
2101b54c88cSJim Ingham         break;
2111b54c88cSJim Ingham         case 'T':
2121b54c88cSJim Ingham             m_thread_name = option_arg;
2131b54c88cSJim Ingham             break;
2141b54c88cSJim Ingham         case 'q':
2151b54c88cSJim Ingham             m_queue_name = option_arg;
2161b54c88cSJim Ingham             break;
2171b54c88cSJim Ingham         case 'x':
2181b54c88cSJim Ingham         {
219c982c768SGreg Clayton             m_thread_index = Args::StringToUInt32(optarg, UINT32_MAX, 0);
220c982c768SGreg Clayton             if (m_thread_id == UINT32_MAX)
2211b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg);
2221b54c88cSJim Ingham 
2231b54c88cSJim Ingham         }
2241b54c88cSJim Ingham         break;
22530fdc8d8SChris Lattner         default:
22630fdc8d8SChris Lattner             error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
22730fdc8d8SChris Lattner             break;
22830fdc8d8SChris Lattner     }
22930fdc8d8SChris Lattner 
23030fdc8d8SChris Lattner     return error;
23130fdc8d8SChris Lattner }
23230fdc8d8SChris Lattner 
23330fdc8d8SChris Lattner void
23430fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::ResetOptionValues ()
23530fdc8d8SChris Lattner {
23630fdc8d8SChris Lattner     Options::ResetOptionValues();
23730fdc8d8SChris Lattner 
23830fdc8d8SChris Lattner     m_filename.clear();
23930fdc8d8SChris Lattner     m_line_num = 0;
24030fdc8d8SChris Lattner     m_column = 0;
24130fdc8d8SChris Lattner     m_func_name.clear();
2420c5cd90dSGreg Clayton     m_func_name_type_mask = 0;
24330fdc8d8SChris Lattner     m_func_regexp.clear();
24430fdc8d8SChris Lattner     m_load_addr = LLDB_INVALID_ADDRESS;
24530fdc8d8SChris Lattner     m_modules.clear();
246c982c768SGreg Clayton     m_ignore_count = 0;
2471b54c88cSJim Ingham     m_thread_id = LLDB_INVALID_THREAD_ID;
248c982c768SGreg Clayton     m_thread_index = UINT32_MAX;
2491b54c88cSJim Ingham     m_thread_name.clear();
2501b54c88cSJim Ingham     m_queue_name.clear();
25130fdc8d8SChris Lattner }
25230fdc8d8SChris Lattner 
25330fdc8d8SChris Lattner //-------------------------------------------------------------------------
25430fdc8d8SChris Lattner // CommandObjectBreakpointSet
25530fdc8d8SChris Lattner //-------------------------------------------------------------------------
256ae1c4cf5SJim Ingham #pragma mark Set
25730fdc8d8SChris Lattner 
258a7015092SGreg Clayton CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
259a7015092SGreg Clayton     CommandObject (interpreter,
260a7015092SGreg Clayton                    "breakpoint set",
261a7015092SGreg Clayton                    "Sets a breakpoint or set of breakpoints in the executable.",
26230fdc8d8SChris Lattner                    "breakpoint set <cmd-options>")
26330fdc8d8SChris Lattner {
26430fdc8d8SChris Lattner }
26530fdc8d8SChris Lattner 
26630fdc8d8SChris Lattner CommandObjectBreakpointSet::~CommandObjectBreakpointSet ()
26730fdc8d8SChris Lattner {
26830fdc8d8SChris Lattner }
26930fdc8d8SChris Lattner 
27030fdc8d8SChris Lattner Options *
27130fdc8d8SChris Lattner CommandObjectBreakpointSet::GetOptions ()
27230fdc8d8SChris Lattner {
27330fdc8d8SChris Lattner     return &m_options;
27430fdc8d8SChris Lattner }
27530fdc8d8SChris Lattner 
27630fdc8d8SChris Lattner bool
27730fdc8d8SChris Lattner CommandObjectBreakpointSet::Execute
27830fdc8d8SChris Lattner (
27930fdc8d8SChris Lattner     Args& command,
28030fdc8d8SChris Lattner     CommandReturnObject &result
28130fdc8d8SChris Lattner )
28230fdc8d8SChris Lattner {
283a7015092SGreg Clayton     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
28430fdc8d8SChris Lattner     if (target == NULL)
28530fdc8d8SChris Lattner     {
2869068d794SCaroline Tice         result.AppendError ("Invalid target.  Must set target before setting breakpoints (see 'file' command).");
28730fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
28830fdc8d8SChris Lattner         return false;
28930fdc8d8SChris Lattner     }
29030fdc8d8SChris Lattner 
29130fdc8d8SChris Lattner     // The following are the various types of breakpoints that could be set:
29230fdc8d8SChris Lattner     //   1).  -f -l -p  [-s -g]   (setting breakpoint by source location)
29330fdc8d8SChris Lattner     //   2).  -a  [-s -g]         (setting breakpoint by address)
29430fdc8d8SChris Lattner     //   3).  -n  [-s -g]         (setting breakpoint by function name)
29530fdc8d8SChris Lattner     //   4).  -r  [-s -g]         (setting breakpoint by function name regular expression)
29630fdc8d8SChris Lattner 
29730fdc8d8SChris Lattner     BreakpointSetType break_type = eSetTypeInvalid;
29830fdc8d8SChris Lattner 
29930fdc8d8SChris Lattner     if (m_options.m_line_num != 0)
30030fdc8d8SChris Lattner         break_type = eSetTypeFileAndLine;
30130fdc8d8SChris Lattner     else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
30230fdc8d8SChris Lattner         break_type = eSetTypeAddress;
30330fdc8d8SChris Lattner     else if (!m_options.m_func_name.empty())
30430fdc8d8SChris Lattner         break_type = eSetTypeFunctionName;
30530fdc8d8SChris Lattner     else if  (!m_options.m_func_regexp.empty())
30630fdc8d8SChris Lattner         break_type = eSetTypeFunctionRegexp;
30730fdc8d8SChris Lattner 
30830fdc8d8SChris Lattner     ModuleSP module_sp = target->GetExecutableModule();
30930fdc8d8SChris Lattner     Breakpoint *bp = NULL;
310274060b6SGreg Clayton     FileSpec module_spec;
31130fdc8d8SChris Lattner     bool use_module = false;
31230fdc8d8SChris Lattner     int num_modules = m_options.m_modules.size();
31330fdc8d8SChris Lattner 
31430fdc8d8SChris Lattner     if ((num_modules > 0) && (break_type != eSetTypeAddress))
31530fdc8d8SChris Lattner         use_module = true;
31630fdc8d8SChris Lattner 
31730fdc8d8SChris Lattner     switch (break_type)
31830fdc8d8SChris Lattner     {
31930fdc8d8SChris Lattner         case eSetTypeFileAndLine: // Breakpoint by source position
32030fdc8d8SChris Lattner             {
32130fdc8d8SChris Lattner                 FileSpec file;
32230fdc8d8SChris Lattner                 if (m_options.m_filename.empty())
32330fdc8d8SChris Lattner                 {
324a7015092SGreg Clayton                     StackFrame *cur_frame = m_interpreter.GetDebugger().GetExecutionContext().frame;
32530fdc8d8SChris Lattner                     if (cur_frame == NULL)
32630fdc8d8SChris Lattner                     {
32730fdc8d8SChris Lattner                         result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame.");
32830fdc8d8SChris Lattner                         result.SetStatus (eReturnStatusFailed);
32930fdc8d8SChris Lattner                         break;
33030fdc8d8SChris Lattner                     }
33130fdc8d8SChris Lattner                     else if (!cur_frame->HasDebugInformation())
33230fdc8d8SChris Lattner                     {
33330fdc8d8SChris Lattner                         result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info.");
33430fdc8d8SChris Lattner                         result.SetStatus (eReturnStatusFailed);
33530fdc8d8SChris Lattner                         break;
33630fdc8d8SChris Lattner                     }
33730fdc8d8SChris Lattner                     else
33830fdc8d8SChris Lattner                     {
33930fdc8d8SChris Lattner                         const SymbolContext &context = cur_frame->GetSymbolContext(true);
34030fdc8d8SChris Lattner                         if (context.line_entry.file)
34130fdc8d8SChris Lattner                         {
34230fdc8d8SChris Lattner                             file = context.line_entry.file;
34330fdc8d8SChris Lattner                         }
34430fdc8d8SChris Lattner                         else if (context.comp_unit != NULL)
34530fdc8d8SChris Lattner                         {    file = context.comp_unit;
34630fdc8d8SChris Lattner                         }
34730fdc8d8SChris Lattner                         else
34830fdc8d8SChris Lattner                         {
34930fdc8d8SChris Lattner                             result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame.");
35030fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusFailed);
35130fdc8d8SChris Lattner                             break;
35230fdc8d8SChris Lattner                         }
35330fdc8d8SChris Lattner                     }
35430fdc8d8SChris Lattner                 }
35530fdc8d8SChris Lattner                 else
35630fdc8d8SChris Lattner                 {
357274060b6SGreg Clayton                     file.SetFile(m_options.m_filename.c_str(), false);
35830fdc8d8SChris Lattner                 }
35930fdc8d8SChris Lattner 
36030fdc8d8SChris Lattner                 if (use_module)
36130fdc8d8SChris Lattner                 {
36230fdc8d8SChris Lattner                     for (int i = 0; i < num_modules; ++i)
36330fdc8d8SChris Lattner                     {
364274060b6SGreg Clayton                         module_spec.SetFile(m_options.m_modules[i].c_str(), false);
365274060b6SGreg Clayton                         bp = target->CreateBreakpoint (&module_spec,
36630fdc8d8SChris Lattner                                                        file,
36730fdc8d8SChris Lattner                                                        m_options.m_line_num,
36830fdc8d8SChris Lattner                                                        m_options.m_ignore_inlines).get();
36930fdc8d8SChris Lattner                         if (bp)
37030fdc8d8SChris Lattner                         {
37130fdc8d8SChris Lattner                             StreamString &output_stream = result.GetOutputStream();
37230fdc8d8SChris Lattner                             output_stream.Printf ("Breakpoint created: ");
37330fdc8d8SChris Lattner                             bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
37430fdc8d8SChris Lattner                             output_stream.EOL();
375*be484f41SCaroline Tice                             if (bp->GetNumLocations() == 0)
376*be484f41SCaroline Tice                                 output_stream.Printf ("WARNING:  Unable to resolve breakpoint to any actual"
377*be484f41SCaroline Tice                                                       " locations.\n");
37830fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusSuccessFinishResult);
37930fdc8d8SChris Lattner                         }
38030fdc8d8SChris Lattner                         else
38130fdc8d8SChris Lattner                         {
38230fdc8d8SChris Lattner                             result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
38330fdc8d8SChris Lattner                                                         m_options.m_modules[i].c_str());
38430fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusFailed);
38530fdc8d8SChris Lattner                         }
38630fdc8d8SChris Lattner                     }
38730fdc8d8SChris Lattner                 }
38830fdc8d8SChris Lattner                 else
38930fdc8d8SChris Lattner                     bp = target->CreateBreakpoint (NULL,
39030fdc8d8SChris Lattner                                                    file,
39130fdc8d8SChris Lattner                                                    m_options.m_line_num,
39230fdc8d8SChris Lattner                                                    m_options.m_ignore_inlines).get();
39330fdc8d8SChris Lattner             }
39430fdc8d8SChris Lattner             break;
3956eee5aa0SGreg Clayton 
39630fdc8d8SChris Lattner         case eSetTypeAddress: // Breakpoint by address
39730fdc8d8SChris Lattner             bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
39830fdc8d8SChris Lattner             break;
3990c5cd90dSGreg Clayton 
40030fdc8d8SChris Lattner         case eSetTypeFunctionName: // Breakpoint by function name
4010c5cd90dSGreg Clayton             {
4020c5cd90dSGreg Clayton                 uint32_t name_type_mask = m_options.m_func_name_type_mask;
4030c5cd90dSGreg Clayton 
4040c5cd90dSGreg Clayton                 if (name_type_mask == 0)
405e02b8504SGreg Clayton                     name_type_mask = eFunctionNameTypeAuto;
4060c5cd90dSGreg Clayton 
40730fdc8d8SChris Lattner                 if (use_module)
40830fdc8d8SChris Lattner                 {
40930fdc8d8SChris Lattner                     for (int i = 0; i < num_modules; ++i)
41030fdc8d8SChris Lattner                     {
411274060b6SGreg Clayton                         module_spec.SetFile(m_options.m_modules[i].c_str(), false);
412274060b6SGreg Clayton                         bp = target->CreateBreakpoint (&module_spec,
413274060b6SGreg Clayton                                                        m_options.m_func_name.c_str(),
414274060b6SGreg Clayton                                                        name_type_mask,
415274060b6SGreg Clayton                                                        Breakpoint::Exact).get();
41630fdc8d8SChris Lattner                         if (bp)
41730fdc8d8SChris Lattner                         {
41830fdc8d8SChris Lattner                             StreamString &output_stream = result.GetOutputStream();
41930fdc8d8SChris Lattner                             output_stream.Printf ("Breakpoint created: ");
42030fdc8d8SChris Lattner                             bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
42130fdc8d8SChris Lattner                             output_stream.EOL();
422*be484f41SCaroline Tice                             if (bp->GetNumLocations() == 0)
423*be484f41SCaroline Tice                                 output_stream.Printf ("WARNING:  Unable to resolve breakpoint to any actual"
424*be484f41SCaroline Tice                                                       " locations.\n");
42530fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusSuccessFinishResult);
42630fdc8d8SChris Lattner                         }
42730fdc8d8SChris Lattner                         else
42830fdc8d8SChris Lattner                         {
42930fdc8d8SChris Lattner                             result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
43030fdc8d8SChris Lattner                                                         m_options.m_modules[i].c_str());
43130fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusFailed);
43230fdc8d8SChris Lattner                         }
43330fdc8d8SChris Lattner                     }
43430fdc8d8SChris Lattner                 }
43530fdc8d8SChris Lattner                 else
4360c5cd90dSGreg Clayton                     bp = target->CreateBreakpoint (NULL, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get();
4370c5cd90dSGreg Clayton             }
43830fdc8d8SChris Lattner             break;
4390c5cd90dSGreg Clayton 
44030fdc8d8SChris Lattner         case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
44130fdc8d8SChris Lattner             {
44230fdc8d8SChris Lattner                 RegularExpression regexp(m_options.m_func_regexp.c_str());
44330fdc8d8SChris Lattner                 if (use_module)
44430fdc8d8SChris Lattner                 {
44530fdc8d8SChris Lattner                     for (int i = 0; i < num_modules; ++i)
44630fdc8d8SChris Lattner                     {
447274060b6SGreg Clayton                         module_spec.SetFile(m_options.m_modules[i].c_str(), false);
448274060b6SGreg Clayton                         bp = target->CreateBreakpoint (&module_spec, regexp).get();
44930fdc8d8SChris Lattner                         if (bp)
45030fdc8d8SChris Lattner                         {
45130fdc8d8SChris Lattner                             StreamString &output_stream = result.GetOutputStream();
45230fdc8d8SChris Lattner                             output_stream.Printf ("Breakpoint created: ");
45330fdc8d8SChris Lattner                             bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
45430fdc8d8SChris Lattner                             output_stream.EOL();
455*be484f41SCaroline Tice                             if (bp->GetNumLocations() == 0)
456*be484f41SCaroline Tice                                 output_stream.Printf ("WARNING:  Unable to resolve breakpoint to any actual"
457*be484f41SCaroline Tice                                                       " locations.\n");
45830fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusSuccessFinishResult);
45930fdc8d8SChris Lattner                         }
46030fdc8d8SChris Lattner                         else
46130fdc8d8SChris Lattner                         {
46230fdc8d8SChris Lattner                             result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
46330fdc8d8SChris Lattner                                                         m_options.m_modules[i].c_str());
46430fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusFailed);
46530fdc8d8SChris Lattner                         }
46630fdc8d8SChris Lattner                     }
46730fdc8d8SChris Lattner                 }
46830fdc8d8SChris Lattner                 else
46930fdc8d8SChris Lattner                     bp = target->CreateBreakpoint (NULL, regexp).get();
47030fdc8d8SChris Lattner             }
47130fdc8d8SChris Lattner             break;
4720c5cd90dSGreg Clayton 
47330fdc8d8SChris Lattner         default:
47430fdc8d8SChris Lattner             break;
47530fdc8d8SChris Lattner     }
47630fdc8d8SChris Lattner 
4771b54c88cSJim Ingham     // Now set the various options that were passed in:
4781b54c88cSJim Ingham     if (bp)
4791b54c88cSJim Ingham     {
4801b54c88cSJim Ingham         if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
4811b54c88cSJim Ingham             bp->SetThreadID (m_options.m_thread_id);
4821b54c88cSJim Ingham 
483c982c768SGreg Clayton         if (m_options.m_thread_index != UINT32_MAX)
4841b54c88cSJim Ingham             bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
4851b54c88cSJim Ingham 
4861b54c88cSJim Ingham         if (!m_options.m_thread_name.empty())
4871b54c88cSJim Ingham             bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
4881b54c88cSJim Ingham 
4891b54c88cSJim Ingham         if (!m_options.m_queue_name.empty())
4901b54c88cSJim Ingham             bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
4911b54c88cSJim Ingham 
492c982c768SGreg Clayton         if (m_options.m_ignore_count != 0)
4931b54c88cSJim Ingham             bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
4941b54c88cSJim Ingham     }
4951b54c88cSJim Ingham 
49630fdc8d8SChris Lattner     if (bp && !use_module)
49730fdc8d8SChris Lattner     {
49830fdc8d8SChris Lattner         StreamString &output_stream = result.GetOutputStream();
49930fdc8d8SChris Lattner         output_stream.Printf ("Breakpoint created: ");
50030fdc8d8SChris Lattner         bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
50130fdc8d8SChris Lattner         output_stream.EOL();
502*be484f41SCaroline Tice         if (bp->GetNumLocations() == 0)
503*be484f41SCaroline Tice             output_stream.Printf ("WARNING:  Unable to resolve breakpoint to any actual locations.\n");
50430fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishResult);
50530fdc8d8SChris Lattner     }
50630fdc8d8SChris Lattner     else if (!bp)
50730fdc8d8SChris Lattner     {
50830fdc8d8SChris Lattner         result.AppendError ("Breakpoint creation failed: No breakpoint created.");
50930fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
51030fdc8d8SChris Lattner     }
51130fdc8d8SChris Lattner 
51230fdc8d8SChris Lattner     return result.Succeeded();
51330fdc8d8SChris Lattner }
51430fdc8d8SChris Lattner 
51530fdc8d8SChris Lattner //-------------------------------------------------------------------------
51630fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint
51730fdc8d8SChris Lattner //-------------------------------------------------------------------------
518ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint
51930fdc8d8SChris Lattner 
5206611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
521a7015092SGreg Clayton     CommandObjectMultiword (interpreter,
522a7015092SGreg Clayton                             "breakpoint",
5233f4c09c1SCaroline Tice                             "A set of commands for operating on breakpoints. Also see regexp-break.",
52430fdc8d8SChris Lattner                             "breakpoint <command> [<command-options>]")
52530fdc8d8SChris Lattner {
52630fdc8d8SChris Lattner     bool status;
52730fdc8d8SChris Lattner 
528a7015092SGreg Clayton     CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
529a7015092SGreg Clayton     CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
530a7015092SGreg Clayton     CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
531a7015092SGreg Clayton     CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
532a7015092SGreg Clayton     CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
53330fdc8d8SChris Lattner     CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
534a7015092SGreg Clayton     CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
53530fdc8d8SChris Lattner 
536ae1c4cf5SJim Ingham     command_command_object->SetCommandName ("breakpoint command");
53730fdc8d8SChris Lattner     enable_command_object->SetCommandName("breakpoint enable");
53830fdc8d8SChris Lattner     disable_command_object->SetCommandName("breakpoint disable");
53930fdc8d8SChris Lattner     list_command_object->SetCommandName ("breakpoint list");
540ae1c4cf5SJim Ingham     modify_command_object->SetCommandName ("breakpoint modify");
541ae1c4cf5SJim Ingham     set_command_object->SetCommandName("breakpoint set");
54230fdc8d8SChris Lattner 
543a7015092SGreg Clayton     status = LoadSubCommand ("list",       list_command_object);
544a7015092SGreg Clayton     status = LoadSubCommand ("enable",     enable_command_object);
545a7015092SGreg Clayton     status = LoadSubCommand ("disable",    disable_command_object);
546a7015092SGreg Clayton     status = LoadSubCommand ("delete",     delete_command_object);
547a7015092SGreg Clayton     status = LoadSubCommand ("set",        set_command_object);
548a7015092SGreg Clayton     status = LoadSubCommand ("command",    command_command_object);
549a7015092SGreg Clayton     status = LoadSubCommand ("modify",     modify_command_object);
55030fdc8d8SChris Lattner }
55130fdc8d8SChris Lattner 
55230fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
55330fdc8d8SChris Lattner {
55430fdc8d8SChris Lattner }
55530fdc8d8SChris Lattner 
55630fdc8d8SChris Lattner void
55730fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result,
55830fdc8d8SChris Lattner                                                          BreakpointIDList *valid_ids)
55930fdc8d8SChris Lattner {
56030fdc8d8SChris Lattner     // args can be strings representing 1). integers (for breakpoint ids)
56130fdc8d8SChris Lattner     //                                  2). the full breakpoint & location canonical representation
56230fdc8d8SChris Lattner     //                                  3). the word "to" or a hyphen, representing a range (in which case there
56330fdc8d8SChris Lattner     //                                      had *better* be an entry both before & after of one of the first two types.
56436f3b369SJim Ingham     // If args is empty, we will use the last created breakpoint (if there is one.)
56530fdc8d8SChris Lattner 
56630fdc8d8SChris Lattner     Args temp_args;
56730fdc8d8SChris Lattner 
56836f3b369SJim Ingham     if (args.GetArgumentCount() == 0)
56936f3b369SJim Ingham     {
57036f3b369SJim Ingham         if (target->GetLastCreatedBreakpoint() != NULL)
57136f3b369SJim Ingham         {
57236f3b369SJim Ingham             valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
57336f3b369SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
57436f3b369SJim Ingham         }
57536f3b369SJim Ingham         else
57636f3b369SJim Ingham         {
57736f3b369SJim Ingham             result.AppendError("No breakpoint specified and no last created breakpoint.");
57836f3b369SJim Ingham             result.SetStatus (eReturnStatusFailed);
57936f3b369SJim Ingham         }
58036f3b369SJim Ingham         return;
58136f3b369SJim Ingham     }
58236f3b369SJim Ingham 
58330fdc8d8SChris Lattner     // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
58430fdc8d8SChris Lattner     // the new TEMP_ARGS.  Do not copy breakpoint id range strings over; instead generate a list of strings for
58530fdc8d8SChris Lattner     // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
58630fdc8d8SChris Lattner 
58730fdc8d8SChris Lattner     BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
58830fdc8d8SChris Lattner 
58930fdc8d8SChris Lattner     // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
59030fdc8d8SChris Lattner 
591c982c768SGreg Clayton     valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
59230fdc8d8SChris Lattner 
59330fdc8d8SChris Lattner     // At this point,  all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
59430fdc8d8SChris Lattner     // and put into valid_ids.
59530fdc8d8SChris Lattner 
59630fdc8d8SChris Lattner     if (result.Succeeded())
59730fdc8d8SChris Lattner     {
59830fdc8d8SChris Lattner         // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
59930fdc8d8SChris Lattner         // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
60030fdc8d8SChris Lattner 
601c982c768SGreg Clayton         const size_t count = valid_ids->GetSize();
602c982c768SGreg Clayton         for (size_t i = 0; i < count; ++i)
60330fdc8d8SChris Lattner         {
60430fdc8d8SChris Lattner             BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
60530fdc8d8SChris Lattner             Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
60630fdc8d8SChris Lattner             if (breakpoint != NULL)
60730fdc8d8SChris Lattner             {
60830fdc8d8SChris Lattner                 int num_locations = breakpoint->GetNumLocations();
60930fdc8d8SChris Lattner                 if (cur_bp_id.GetLocationID() > num_locations)
61030fdc8d8SChris Lattner                 {
61130fdc8d8SChris Lattner                     StreamString id_str;
612c982c768SGreg Clayton                     BreakpointID::GetCanonicalReference (&id_str,
613c982c768SGreg Clayton                                                          cur_bp_id.GetBreakpointID(),
61430fdc8d8SChris Lattner                                                          cur_bp_id.GetLocationID());
615c982c768SGreg Clayton                     i = valid_ids->GetSize() + 1;
61630fdc8d8SChris Lattner                     result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
61730fdc8d8SChris Lattner                                                  id_str.GetData());
61830fdc8d8SChris Lattner                     result.SetStatus (eReturnStatusFailed);
61930fdc8d8SChris Lattner                 }
62030fdc8d8SChris Lattner             }
62130fdc8d8SChris Lattner             else
62230fdc8d8SChris Lattner             {
623c982c768SGreg Clayton                 i = valid_ids->GetSize() + 1;
62430fdc8d8SChris Lattner                 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
62530fdc8d8SChris Lattner                 result.SetStatus (eReturnStatusFailed);
62630fdc8d8SChris Lattner             }
62730fdc8d8SChris Lattner         }
62830fdc8d8SChris Lattner     }
62930fdc8d8SChris Lattner }
63030fdc8d8SChris Lattner 
63130fdc8d8SChris Lattner //-------------------------------------------------------------------------
63230fdc8d8SChris Lattner // CommandObjectBreakpointList::Options
63330fdc8d8SChris Lattner //-------------------------------------------------------------------------
634ae1c4cf5SJim Ingham #pragma mark List::CommandOptions
63530fdc8d8SChris Lattner 
63630fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::CommandOptions() :
63730fdc8d8SChris Lattner     Options (),
63830fdc8d8SChris Lattner     m_level (lldb::eDescriptionLevelFull)  // Breakpoint List defaults to brief descriptions
63930fdc8d8SChris Lattner {
64030fdc8d8SChris Lattner }
64130fdc8d8SChris Lattner 
64230fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::~CommandOptions ()
64330fdc8d8SChris Lattner {
64430fdc8d8SChris Lattner }
64530fdc8d8SChris Lattner 
64630fdc8d8SChris Lattner lldb::OptionDefinition
64730fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::g_option_table[] =
64830fdc8d8SChris Lattner {
649deaab222SCaroline Tice     { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone,
6508651121cSJim Ingham         "Show debugger internal breakpoints" },
6518651121cSJim Ingham 
652deaab222SCaroline Tice     { LLDB_OPT_SET_1, false, "brief",    'b', no_argument, NULL, 0, eArgTypeNone,
65330fdc8d8SChris Lattner         "Give a brief description of the breakpoint (no location info)."},
65430fdc8d8SChris Lattner 
65530fdc8d8SChris Lattner     // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
65630fdc8d8SChris Lattner     // But I need to see it for now, and don't want to wait.
657deaab222SCaroline Tice     { LLDB_OPT_SET_2, false, "full",    'f', no_argument, NULL, 0, eArgTypeNone,
65830fdc8d8SChris Lattner         "Give a full description of the breakpoint and its locations."},
65930fdc8d8SChris Lattner 
660deaab222SCaroline Tice     { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone,
66130fdc8d8SChris Lattner         "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
66230fdc8d8SChris Lattner 
663deaab222SCaroline Tice     { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
66430fdc8d8SChris Lattner };
66530fdc8d8SChris Lattner 
66630fdc8d8SChris Lattner const lldb::OptionDefinition*
66730fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::GetDefinitions ()
66830fdc8d8SChris Lattner {
66930fdc8d8SChris Lattner     return g_option_table;
67030fdc8d8SChris Lattner }
67130fdc8d8SChris Lattner 
67230fdc8d8SChris Lattner Error
67330fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
67430fdc8d8SChris Lattner {
67530fdc8d8SChris Lattner     Error error;
67630fdc8d8SChris Lattner     char short_option = (char) m_getopt_table[option_idx].val;
67730fdc8d8SChris Lattner 
67830fdc8d8SChris Lattner     switch (short_option)
67930fdc8d8SChris Lattner     {
68030fdc8d8SChris Lattner         case 'b':
68130fdc8d8SChris Lattner             m_level = lldb::eDescriptionLevelBrief;
68230fdc8d8SChris Lattner             break;
68330fdc8d8SChris Lattner         case 'f':
68430fdc8d8SChris Lattner             m_level = lldb::eDescriptionLevelFull;
68530fdc8d8SChris Lattner             break;
68630fdc8d8SChris Lattner         case 'v':
68730fdc8d8SChris Lattner             m_level = lldb::eDescriptionLevelVerbose;
68830fdc8d8SChris Lattner             break;
68930fdc8d8SChris Lattner         case 'i':
69030fdc8d8SChris Lattner             m_internal = true;
69130fdc8d8SChris Lattner             break;
69230fdc8d8SChris Lattner         default:
69330fdc8d8SChris Lattner             error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
69430fdc8d8SChris Lattner             break;
69530fdc8d8SChris Lattner     }
69630fdc8d8SChris Lattner 
69730fdc8d8SChris Lattner     return error;
69830fdc8d8SChris Lattner }
69930fdc8d8SChris Lattner 
70030fdc8d8SChris Lattner void
70130fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::ResetOptionValues ()
70230fdc8d8SChris Lattner {
70330fdc8d8SChris Lattner     Options::ResetOptionValues();
70430fdc8d8SChris Lattner 
70530fdc8d8SChris Lattner     m_level = lldb::eDescriptionLevelFull;
70630fdc8d8SChris Lattner     m_internal = false;
70730fdc8d8SChris Lattner }
70830fdc8d8SChris Lattner 
70930fdc8d8SChris Lattner //-------------------------------------------------------------------------
71030fdc8d8SChris Lattner // CommandObjectBreakpointList
71130fdc8d8SChris Lattner //-------------------------------------------------------------------------
712ae1c4cf5SJim Ingham #pragma mark List
71330fdc8d8SChris Lattner 
714a7015092SGreg Clayton CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) :
715a7015092SGreg Clayton     CommandObject (interpreter,
716a7015092SGreg Clayton                    "breakpoint list",
71730fdc8d8SChris Lattner                    "List some or all breakpoints at configurable levels of detail.",
718e139cf23SCaroline Tice                    NULL)
71930fdc8d8SChris Lattner {
720e139cf23SCaroline Tice     CommandArgumentEntry arg;
721e139cf23SCaroline Tice     CommandArgumentData bp_id_arg;
722e139cf23SCaroline Tice 
723e139cf23SCaroline Tice     // Define the first (and only) variant of this arg.
724e139cf23SCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
725405fe67fSCaroline Tice     bp_id_arg.arg_repetition = eArgRepeatOptional;
726e139cf23SCaroline Tice 
727e139cf23SCaroline Tice     // There is only one variant this argument could be; put it into the argument entry.
728e139cf23SCaroline Tice     arg.push_back (bp_id_arg);
729e139cf23SCaroline Tice 
730e139cf23SCaroline Tice     // Push the data for the first argument into the m_arguments vector.
731e139cf23SCaroline Tice     m_arguments.push_back (arg);
73230fdc8d8SChris Lattner }
73330fdc8d8SChris Lattner 
73430fdc8d8SChris Lattner CommandObjectBreakpointList::~CommandObjectBreakpointList ()
73530fdc8d8SChris Lattner {
73630fdc8d8SChris Lattner }
73730fdc8d8SChris Lattner 
73830fdc8d8SChris Lattner Options *
73930fdc8d8SChris Lattner CommandObjectBreakpointList::GetOptions ()
74030fdc8d8SChris Lattner {
74130fdc8d8SChris Lattner     return &m_options;
74230fdc8d8SChris Lattner }
74330fdc8d8SChris Lattner 
74430fdc8d8SChris Lattner bool
74530fdc8d8SChris Lattner CommandObjectBreakpointList::Execute
74630fdc8d8SChris Lattner (
74730fdc8d8SChris Lattner     Args& args,
74830fdc8d8SChris Lattner     CommandReturnObject &result
74930fdc8d8SChris Lattner )
75030fdc8d8SChris Lattner {
751a7015092SGreg Clayton     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
75230fdc8d8SChris Lattner     if (target == NULL)
75330fdc8d8SChris Lattner     {
7549068d794SCaroline Tice         result.AppendError ("Invalid target. No current target or breakpoints.");
75530fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
75630fdc8d8SChris Lattner         return true;
75730fdc8d8SChris Lattner     }
75830fdc8d8SChris Lattner 
75930fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
7601b54c88cSJim Ingham     Mutex::Locker locker;
7611b54c88cSJim Ingham     target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
7621b54c88cSJim Ingham 
76330fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
76430fdc8d8SChris Lattner 
76530fdc8d8SChris Lattner     if (num_breakpoints == 0)
76630fdc8d8SChris Lattner     {
76730fdc8d8SChris Lattner         result.AppendMessage ("No breakpoints currently set.");
76830fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
76930fdc8d8SChris Lattner         return true;
77030fdc8d8SChris Lattner     }
77130fdc8d8SChris Lattner 
77230fdc8d8SChris Lattner     StreamString &output_stream = result.GetOutputStream();
77330fdc8d8SChris Lattner 
77430fdc8d8SChris Lattner     if (args.GetArgumentCount() == 0)
77530fdc8d8SChris Lattner     {
77630fdc8d8SChris Lattner         // No breakpoint selected; show info about all currently set breakpoints.
77730fdc8d8SChris Lattner         result.AppendMessage ("Current breakpoints:");
778c982c768SGreg Clayton         for (size_t i = 0; i < num_breakpoints; ++i)
77930fdc8d8SChris Lattner         {
7809fed0d85SGreg Clayton             Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
7816611103cSGreg Clayton             AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
78230fdc8d8SChris Lattner         }
78330fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
78430fdc8d8SChris Lattner     }
78530fdc8d8SChris Lattner     else
78630fdc8d8SChris Lattner     {
78730fdc8d8SChris Lattner         // Particular breakpoints selected; show info about that breakpoint.
78830fdc8d8SChris Lattner         BreakpointIDList valid_bp_ids;
78930fdc8d8SChris Lattner         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
79030fdc8d8SChris Lattner 
79130fdc8d8SChris Lattner         if (result.Succeeded())
79230fdc8d8SChris Lattner         {
793c982c768SGreg Clayton             for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
79430fdc8d8SChris Lattner             {
79530fdc8d8SChris Lattner                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
79630fdc8d8SChris Lattner                 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
7976611103cSGreg Clayton                 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
79830fdc8d8SChris Lattner             }
79930fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishNoResult);
80030fdc8d8SChris Lattner         }
80130fdc8d8SChris Lattner         else
80230fdc8d8SChris Lattner         {
80330fdc8d8SChris Lattner             result.AppendError ("Invalid breakpoint id.");
80430fdc8d8SChris Lattner             result.SetStatus (eReturnStatusFailed);
80530fdc8d8SChris Lattner         }
80630fdc8d8SChris Lattner     }
80730fdc8d8SChris Lattner 
80830fdc8d8SChris Lattner     return result.Succeeded();
80930fdc8d8SChris Lattner }
81030fdc8d8SChris Lattner 
81130fdc8d8SChris Lattner //-------------------------------------------------------------------------
81230fdc8d8SChris Lattner // CommandObjectBreakpointEnable
81330fdc8d8SChris Lattner //-------------------------------------------------------------------------
814ae1c4cf5SJim Ingham #pragma mark Enable
81530fdc8d8SChris Lattner 
816a7015092SGreg Clayton CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
817a7015092SGreg Clayton     CommandObject (interpreter,
818a7015092SGreg Clayton                    "enable",
819e3d26315SCaroline Tice                    "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
820e139cf23SCaroline Tice                    NULL)
82130fdc8d8SChris Lattner {
822e139cf23SCaroline Tice     CommandArgumentEntry arg;
823e139cf23SCaroline Tice     CommandArgumentData bp_id_arg;
824e139cf23SCaroline Tice     CommandArgumentData bp_id_range_arg;
825e139cf23SCaroline Tice 
826e139cf23SCaroline Tice     // Create the first variant for the first (and only) argument for this command.
827e139cf23SCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
828405fe67fSCaroline Tice     bp_id_arg.arg_repetition = eArgRepeatOptional;
829e139cf23SCaroline Tice 
830e139cf23SCaroline Tice     // Create the second variant for the first (and only) argument for this command.
831e139cf23SCaroline Tice     bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
832405fe67fSCaroline Tice     bp_id_range_arg.arg_repetition = eArgRepeatOptional;
833e139cf23SCaroline Tice 
834e139cf23SCaroline Tice     // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
835e139cf23SCaroline Tice     // Push both variants into the entry for the first argument for this command.
836e139cf23SCaroline Tice     arg.push_back (bp_id_arg);
837e139cf23SCaroline Tice     arg.push_back (bp_id_range_arg);
838e139cf23SCaroline Tice 
839e139cf23SCaroline Tice     // Add the entry for the first argument for this command to the object's arguments vector.
840e139cf23SCaroline Tice     m_arguments.push_back (arg);
84130fdc8d8SChris Lattner }
84230fdc8d8SChris Lattner 
84330fdc8d8SChris Lattner 
84430fdc8d8SChris Lattner CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable ()
84530fdc8d8SChris Lattner {
84630fdc8d8SChris Lattner }
84730fdc8d8SChris Lattner 
84830fdc8d8SChris Lattner 
84930fdc8d8SChris Lattner bool
8506611103cSGreg Clayton CommandObjectBreakpointEnable::Execute
8516611103cSGreg Clayton (
8526611103cSGreg Clayton     Args& args,
8536611103cSGreg Clayton     CommandReturnObject &result
8546611103cSGreg Clayton )
85530fdc8d8SChris Lattner {
856a7015092SGreg Clayton     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
85730fdc8d8SChris Lattner     if (target == NULL)
85830fdc8d8SChris Lattner     {
8599068d794SCaroline Tice         result.AppendError ("Invalid target.  No existing target or breakpoints.");
86030fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
86130fdc8d8SChris Lattner         return false;
86230fdc8d8SChris Lattner     }
86330fdc8d8SChris Lattner 
8641b54c88cSJim Ingham     Mutex::Locker locker;
8651b54c88cSJim Ingham     target->GetBreakpointList().GetListMutex(locker);
8661b54c88cSJim Ingham 
86730fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
8681b54c88cSJim Ingham 
86930fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
87030fdc8d8SChris Lattner 
87130fdc8d8SChris Lattner     if (num_breakpoints == 0)
87230fdc8d8SChris Lattner     {
87330fdc8d8SChris Lattner         result.AppendError ("No breakpoints exist to be enabled.");
87430fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
87530fdc8d8SChris Lattner         return false;
87630fdc8d8SChris Lattner     }
87730fdc8d8SChris Lattner 
87830fdc8d8SChris Lattner     if (args.GetArgumentCount() == 0)
87930fdc8d8SChris Lattner     {
88030fdc8d8SChris Lattner         // No breakpoint selected; enable all currently set breakpoints.
88130fdc8d8SChris Lattner         target->EnableAllBreakpoints ();
88230fdc8d8SChris Lattner         result.AppendMessageWithFormat ("All breakpoints enabled. (%d breakpoints)\n", num_breakpoints);
88330fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
88430fdc8d8SChris Lattner     }
88530fdc8d8SChris Lattner     else
88630fdc8d8SChris Lattner     {
88730fdc8d8SChris Lattner         // Particular breakpoint selected; enable that breakpoint.
88830fdc8d8SChris Lattner         BreakpointIDList valid_bp_ids;
88930fdc8d8SChris Lattner         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
89030fdc8d8SChris Lattner 
89130fdc8d8SChris Lattner         if (result.Succeeded())
89230fdc8d8SChris Lattner         {
89330fdc8d8SChris Lattner             int enable_count = 0;
89430fdc8d8SChris Lattner             int loc_count = 0;
895c982c768SGreg Clayton             const size_t count = valid_bp_ids.GetSize();
896c982c768SGreg Clayton             for (size_t i = 0; i < count; ++i)
89730fdc8d8SChris Lattner             {
89830fdc8d8SChris Lattner                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
89930fdc8d8SChris Lattner 
90030fdc8d8SChris Lattner                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
90130fdc8d8SChris Lattner                 {
90230fdc8d8SChris Lattner                     Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
90330fdc8d8SChris Lattner                     if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
90430fdc8d8SChris Lattner                     {
90530fdc8d8SChris Lattner                         BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
90630fdc8d8SChris Lattner                         if (location)
90730fdc8d8SChris Lattner                         {
90830fdc8d8SChris Lattner                             location->SetEnabled (true);
90930fdc8d8SChris Lattner                             ++loc_count;
91030fdc8d8SChris Lattner                         }
91130fdc8d8SChris Lattner                     }
91230fdc8d8SChris Lattner                     else
91330fdc8d8SChris Lattner                     {
914ae1c4cf5SJim Ingham                         breakpoint->SetEnabled (true);
91530fdc8d8SChris Lattner                         ++enable_count;
91630fdc8d8SChris Lattner                     }
91730fdc8d8SChris Lattner                 }
91830fdc8d8SChris Lattner             }
91930fdc8d8SChris Lattner             result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
92030fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishNoResult);
92130fdc8d8SChris Lattner         }
92230fdc8d8SChris Lattner     }
92330fdc8d8SChris Lattner 
92430fdc8d8SChris Lattner     return result.Succeeded();
92530fdc8d8SChris Lattner }
92630fdc8d8SChris Lattner 
92730fdc8d8SChris Lattner //-------------------------------------------------------------------------
92830fdc8d8SChris Lattner // CommandObjectBreakpointDisable
92930fdc8d8SChris Lattner //-------------------------------------------------------------------------
930ae1c4cf5SJim Ingham #pragma mark Disable
93130fdc8d8SChris Lattner 
932a7015092SGreg Clayton CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
933a7015092SGreg Clayton     CommandObject (interpreter,
934e139cf23SCaroline Tice                    "breakpoint disable",
935e3d26315SCaroline Tice                    "Disable the specified breakpoint(s) without removing it/them.  If no breakpoints are specified, disable them all.",
936e139cf23SCaroline Tice                    NULL)
93730fdc8d8SChris Lattner {
938e139cf23SCaroline Tice     CommandArgumentEntry arg;
939e139cf23SCaroline Tice     CommandArgumentData bp_id_arg;
940e139cf23SCaroline Tice     CommandArgumentData bp_id_range_arg;
941e139cf23SCaroline Tice 
942e139cf23SCaroline Tice     // Create the first variant for the first (and only) argument for this command.
943e139cf23SCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
944405fe67fSCaroline Tice     bp_id_arg.arg_repetition = eArgRepeatOptional;
945e139cf23SCaroline Tice 
946e139cf23SCaroline Tice     // Create the second variant for the first (and only) argument for this command.
947e139cf23SCaroline Tice     bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
948405fe67fSCaroline Tice     bp_id_range_arg.arg_repetition = eArgRepeatOptional;
949e139cf23SCaroline Tice 
950e139cf23SCaroline Tice     // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
951e139cf23SCaroline Tice     // Push both variants into the entry for the first argument for this command.
952e139cf23SCaroline Tice     arg.push_back (bp_id_arg);
953e139cf23SCaroline Tice     arg.push_back (bp_id_range_arg);
954e139cf23SCaroline Tice 
955e139cf23SCaroline Tice     // Add the entry for the first argument for this command to the object's arguments vector.
956e139cf23SCaroline Tice     m_arguments.push_back (arg);
95730fdc8d8SChris Lattner }
95830fdc8d8SChris Lattner 
95930fdc8d8SChris Lattner CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable ()
96030fdc8d8SChris Lattner {
96130fdc8d8SChris Lattner }
96230fdc8d8SChris Lattner 
96330fdc8d8SChris Lattner bool
9646611103cSGreg Clayton CommandObjectBreakpointDisable::Execute
9656611103cSGreg Clayton (
9666611103cSGreg Clayton     Args& args,
9676611103cSGreg Clayton     CommandReturnObject &result
9686611103cSGreg Clayton )
96930fdc8d8SChris Lattner {
970a7015092SGreg Clayton     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
97130fdc8d8SChris Lattner     if (target == NULL)
97230fdc8d8SChris Lattner     {
9739068d794SCaroline Tice         result.AppendError ("Invalid target.  No existing target or breakpoints.");
97430fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
97530fdc8d8SChris Lattner         return false;
97630fdc8d8SChris Lattner     }
97730fdc8d8SChris Lattner 
9781b54c88cSJim Ingham     Mutex::Locker locker;
9791b54c88cSJim Ingham     target->GetBreakpointList().GetListMutex(locker);
9801b54c88cSJim Ingham 
98130fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
98230fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
98330fdc8d8SChris Lattner 
98430fdc8d8SChris Lattner     if (num_breakpoints == 0)
98530fdc8d8SChris Lattner     {
98630fdc8d8SChris Lattner         result.AppendError ("No breakpoints exist to be disabled.");
98730fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
98830fdc8d8SChris Lattner         return false;
98930fdc8d8SChris Lattner     }
99030fdc8d8SChris Lattner 
99130fdc8d8SChris Lattner     if (args.GetArgumentCount() == 0)
99230fdc8d8SChris Lattner     {
99330fdc8d8SChris Lattner         // No breakpoint selected; disable all currently set breakpoints.
99430fdc8d8SChris Lattner         target->DisableAllBreakpoints ();
99530fdc8d8SChris Lattner         result.AppendMessageWithFormat ("All breakpoints disabled. (%d breakpoints)\n", num_breakpoints);
99630fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
99730fdc8d8SChris Lattner     }
99830fdc8d8SChris Lattner     else
99930fdc8d8SChris Lattner     {
100030fdc8d8SChris Lattner         // Particular breakpoint selected; disable that breakpoint.
100130fdc8d8SChris Lattner         BreakpointIDList valid_bp_ids;
100230fdc8d8SChris Lattner 
100330fdc8d8SChris Lattner         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
100430fdc8d8SChris Lattner 
100530fdc8d8SChris Lattner         if (result.Succeeded())
100630fdc8d8SChris Lattner         {
100730fdc8d8SChris Lattner             int disable_count = 0;
100830fdc8d8SChris Lattner             int loc_count = 0;
1009c982c768SGreg Clayton             const size_t count = valid_bp_ids.GetSize();
1010c982c768SGreg Clayton             for (size_t i = 0; i < count; ++i)
101130fdc8d8SChris Lattner             {
101230fdc8d8SChris Lattner                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
101330fdc8d8SChris Lattner 
101430fdc8d8SChris Lattner                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
101530fdc8d8SChris Lattner                 {
101630fdc8d8SChris Lattner                     Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
101730fdc8d8SChris Lattner                     if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
101830fdc8d8SChris Lattner                     {
101930fdc8d8SChris Lattner                         BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
102030fdc8d8SChris Lattner                         if (location)
102130fdc8d8SChris Lattner                         {
102230fdc8d8SChris Lattner                             location->SetEnabled (false);
102330fdc8d8SChris Lattner                             ++loc_count;
102430fdc8d8SChris Lattner                         }
102530fdc8d8SChris Lattner                     }
102630fdc8d8SChris Lattner                     else
102730fdc8d8SChris Lattner                     {
1028ae1c4cf5SJim Ingham                         breakpoint->SetEnabled (false);
102930fdc8d8SChris Lattner                         ++disable_count;
103030fdc8d8SChris Lattner                     }
103130fdc8d8SChris Lattner                 }
103230fdc8d8SChris Lattner             }
103330fdc8d8SChris Lattner             result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
103430fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishNoResult);
103530fdc8d8SChris Lattner         }
103630fdc8d8SChris Lattner     }
103730fdc8d8SChris Lattner 
103830fdc8d8SChris Lattner     return result.Succeeded();
103930fdc8d8SChris Lattner }
104030fdc8d8SChris Lattner 
104130fdc8d8SChris Lattner //-------------------------------------------------------------------------
104230fdc8d8SChris Lattner // CommandObjectBreakpointDelete
104330fdc8d8SChris Lattner //-------------------------------------------------------------------------
1044ae1c4cf5SJim Ingham #pragma mark Delete
104530fdc8d8SChris Lattner 
1046a7015092SGreg Clayton CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) :
1047a7015092SGreg Clayton     CommandObject (interpreter,
1048a7015092SGreg Clayton                    "breakpoint delete",
1049e3d26315SCaroline Tice                    "Delete the specified breakpoint(s).  If no breakpoints are specified, delete them all.",
1050e139cf23SCaroline Tice                    NULL)
105130fdc8d8SChris Lattner {
1052e139cf23SCaroline Tice     CommandArgumentEntry arg;
1053e139cf23SCaroline Tice     CommandArgumentData bp_id_arg;
1054e139cf23SCaroline Tice     CommandArgumentData bp_id_range_arg;
1055e139cf23SCaroline Tice 
1056e139cf23SCaroline Tice     // Create the first variant for the first (and only) argument for this command.
1057e139cf23SCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
1058405fe67fSCaroline Tice     bp_id_arg.arg_repetition = eArgRepeatOptional;
1059e139cf23SCaroline Tice 
1060e139cf23SCaroline Tice     // Create the second variant for the first (and only) argument for this command.
1061e139cf23SCaroline Tice     bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
1062405fe67fSCaroline Tice     bp_id_range_arg.arg_repetition = eArgRepeatOptional;
1063e139cf23SCaroline Tice 
1064e139cf23SCaroline Tice     // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1065e139cf23SCaroline Tice     // Push both variants into the entry for the first argument for this command.
1066e139cf23SCaroline Tice     arg.push_back (bp_id_arg);
1067e139cf23SCaroline Tice     arg.push_back (bp_id_range_arg);
1068e139cf23SCaroline Tice 
1069e139cf23SCaroline Tice     // Add the entry for the first argument for this command to the object's arguments vector.
1070e139cf23SCaroline Tice     m_arguments.push_back (arg);
107130fdc8d8SChris Lattner }
107230fdc8d8SChris Lattner 
107330fdc8d8SChris Lattner 
107430fdc8d8SChris Lattner CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete ()
107530fdc8d8SChris Lattner {
107630fdc8d8SChris Lattner }
107730fdc8d8SChris Lattner 
107830fdc8d8SChris Lattner bool
10796611103cSGreg Clayton CommandObjectBreakpointDelete::Execute
10806611103cSGreg Clayton (
10816611103cSGreg Clayton     Args& args,
10826611103cSGreg Clayton     CommandReturnObject &result
10836611103cSGreg Clayton )
108430fdc8d8SChris Lattner {
1085a7015092SGreg Clayton     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
108630fdc8d8SChris Lattner     if (target == NULL)
108730fdc8d8SChris Lattner     {
10889068d794SCaroline Tice         result.AppendError ("Invalid target. No existing target or breakpoints.");
108930fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
109030fdc8d8SChris Lattner         return false;
109130fdc8d8SChris Lattner     }
109230fdc8d8SChris Lattner 
10931b54c88cSJim Ingham     Mutex::Locker locker;
10941b54c88cSJim Ingham     target->GetBreakpointList().GetListMutex(locker);
10951b54c88cSJim Ingham 
109630fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
10971b54c88cSJim Ingham 
109830fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
109930fdc8d8SChris Lattner 
110030fdc8d8SChris Lattner     if (num_breakpoints == 0)
110130fdc8d8SChris Lattner     {
110230fdc8d8SChris Lattner         result.AppendError ("No breakpoints exist to be deleted.");
110330fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
110430fdc8d8SChris Lattner         return false;
110530fdc8d8SChris Lattner     }
110630fdc8d8SChris Lattner 
110730fdc8d8SChris Lattner     if (args.GetArgumentCount() == 0)
110830fdc8d8SChris Lattner     {
110936f3b369SJim Ingham         if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
111030fdc8d8SChris Lattner         {
111136f3b369SJim Ingham             result.AppendMessage("Operation cancelled...");
111230fdc8d8SChris Lattner         }
111336f3b369SJim Ingham         else
111436f3b369SJim Ingham         {
111530fdc8d8SChris Lattner             target->RemoveAllBreakpoints ();
111630fdc8d8SChris Lattner             result.AppendMessageWithFormat ("All breakpoints removed. (%d breakpoints)\n", num_breakpoints);
111736f3b369SJim Ingham         }
111830fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
111930fdc8d8SChris Lattner     }
112030fdc8d8SChris Lattner     else
112130fdc8d8SChris Lattner     {
112230fdc8d8SChris Lattner         // Particular breakpoint selected; disable that breakpoint.
112330fdc8d8SChris Lattner         BreakpointIDList valid_bp_ids;
112430fdc8d8SChris Lattner         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
112530fdc8d8SChris Lattner 
112630fdc8d8SChris Lattner         if (result.Succeeded())
112730fdc8d8SChris Lattner         {
112830fdc8d8SChris Lattner             int delete_count = 0;
112930fdc8d8SChris Lattner             int disable_count = 0;
1130c982c768SGreg Clayton             const size_t count = valid_bp_ids.GetSize();
1131c982c768SGreg Clayton             for (size_t i = 0; i < count; ++i)
113230fdc8d8SChris Lattner             {
113330fdc8d8SChris Lattner                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
113430fdc8d8SChris Lattner 
113530fdc8d8SChris Lattner                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
113630fdc8d8SChris Lattner                 {
113730fdc8d8SChris Lattner                     if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
113830fdc8d8SChris Lattner                     {
113930fdc8d8SChris Lattner                         Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
114030fdc8d8SChris Lattner                         BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
114130fdc8d8SChris Lattner                         // It makes no sense to try to delete individual locations, so we disable them instead.
114230fdc8d8SChris Lattner                         if (location)
114330fdc8d8SChris Lattner                         {
114430fdc8d8SChris Lattner                             location->SetEnabled (false);
114530fdc8d8SChris Lattner                             ++disable_count;
114630fdc8d8SChris Lattner                         }
114730fdc8d8SChris Lattner                     }
114830fdc8d8SChris Lattner                     else
114930fdc8d8SChris Lattner                     {
115030fdc8d8SChris Lattner                         target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
115130fdc8d8SChris Lattner                         ++delete_count;
115230fdc8d8SChris Lattner                     }
115330fdc8d8SChris Lattner                 }
115430fdc8d8SChris Lattner             }
115530fdc8d8SChris Lattner             result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
115630fdc8d8SChris Lattner                                            delete_count, disable_count);
115730fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishNoResult);
115830fdc8d8SChris Lattner         }
115930fdc8d8SChris Lattner     }
116030fdc8d8SChris Lattner     return result.Succeeded();
116130fdc8d8SChris Lattner }
11621b54c88cSJim Ingham 
11631b54c88cSJim Ingham //-------------------------------------------------------------------------
1164ae1c4cf5SJim Ingham // CommandObjectBreakpointModify::CommandOptions
11651b54c88cSJim Ingham //-------------------------------------------------------------------------
1166ae1c4cf5SJim Ingham #pragma mark Modify::CommandOptions
11671b54c88cSJim Ingham 
1168ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::CommandOptions() :
11691b54c88cSJim Ingham     Options (),
1170c982c768SGreg Clayton     m_ignore_count (0),
11711b54c88cSJim Ingham     m_thread_id(LLDB_INVALID_THREAD_ID),
1172c982c768SGreg Clayton     m_thread_index (UINT32_MAX),
11731b54c88cSJim Ingham     m_thread_name(),
11741b54c88cSJim Ingham     m_queue_name(),
117536f3b369SJim Ingham     m_condition (),
1176c982c768SGreg Clayton     m_enable_passed (false),
1177c982c768SGreg Clayton     m_enable_value (false),
1178c982c768SGreg Clayton     m_name_passed (false),
117936f3b369SJim Ingham     m_queue_passed (false),
118036f3b369SJim Ingham     m_condition_passed (false)
11811b54c88cSJim Ingham {
11821b54c88cSJim Ingham }
11831b54c88cSJim Ingham 
1184ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::~CommandOptions ()
11851b54c88cSJim Ingham {
11861b54c88cSJim Ingham }
11871b54c88cSJim Ingham 
11881b54c88cSJim Ingham lldb::OptionDefinition
1189ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
11901b54c88cSJim Ingham {
1191deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, NULL, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." },
1192deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose indeX matches this argument."},
1193deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-id",    't', required_argument, NULL, NULL, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."},
1194deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-name",  'T', required_argument, NULL, NULL, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."},
1195deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "queue-name",   'q', required_argument, NULL, NULL, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."},
119636f3b369SJim Ingham { LLDB_OPT_SET_ALL, false, "condition",    'c', required_argument, NULL, NULL, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."},
1197deaab222SCaroline Tice { LLDB_OPT_SET_1,   false, "enable",       'e', no_argument,       NULL, NULL, eArgTypeNone, "Enable the breakpoint."},
1198deaab222SCaroline Tice { LLDB_OPT_SET_2,   false, "disable",      'd', no_argument,       NULL, NULL, eArgTypeNone, "Disable the breakpoint."},
1199deaab222SCaroline Tice { 0,                false, NULL,            0 , 0,                 NULL, 0,    eArgTypeNone, NULL }
12001b54c88cSJim Ingham };
12011b54c88cSJim Ingham 
12021b54c88cSJim Ingham const lldb::OptionDefinition*
1203ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::GetDefinitions ()
12041b54c88cSJim Ingham {
12051b54c88cSJim Ingham     return g_option_table;
12061b54c88cSJim Ingham }
12071b54c88cSJim Ingham 
12081b54c88cSJim Ingham Error
1209ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
12101b54c88cSJim Ingham {
12111b54c88cSJim Ingham     Error error;
12121b54c88cSJim Ingham     char short_option = (char) m_getopt_table[option_idx].val;
12131b54c88cSJim Ingham 
12141b54c88cSJim Ingham     switch (short_option)
12151b54c88cSJim Ingham     {
121636f3b369SJim Ingham         case 'c':
121736f3b369SJim Ingham             if (option_arg != NULL)
121836f3b369SJim Ingham                 m_condition = option_arg;
121936f3b369SJim Ingham             else
122036f3b369SJim Ingham                 m_condition.clear();
122136f3b369SJim Ingham             m_condition_passed = true;
122236f3b369SJim Ingham             break;
1223ae1c4cf5SJim Ingham         case 'd':
1224ae1c4cf5SJim Ingham             m_enable_passed = true;
1225ae1c4cf5SJim Ingham             m_enable_value = false;
1226ae1c4cf5SJim Ingham             break;
1227ae1c4cf5SJim Ingham         case 'e':
1228ae1c4cf5SJim Ingham             m_enable_passed = true;
1229ae1c4cf5SJim Ingham             m_enable_value = true;
1230ae1c4cf5SJim Ingham             break;
1231ed8a705cSGreg Clayton         case 'i':
12321b54c88cSJim Ingham         {
1233c982c768SGreg Clayton             m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0);
1234c982c768SGreg Clayton             if (m_ignore_count == UINT32_MAX)
12351b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg);
12361b54c88cSJim Ingham         }
1237ae1c4cf5SJim Ingham         break;
12381b54c88cSJim Ingham         case 't' :
12391b54c88cSJim Ingham         {
12401b54c88cSJim Ingham             m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0);
12411b54c88cSJim Ingham             if (m_thread_id == LLDB_INVALID_THREAD_ID)
12421b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg);
12431b54c88cSJim Ingham         }
12441b54c88cSJim Ingham         break;
12451b54c88cSJim Ingham         case 'T':
1246b2a38a72SJim Ingham             if (option_arg != NULL)
12471b54c88cSJim Ingham                 m_thread_name = option_arg;
1248b2a38a72SJim Ingham             else
1249b2a38a72SJim Ingham                 m_thread_name.clear();
1250b2a38a72SJim Ingham             m_name_passed = true;
12511b54c88cSJim Ingham             break;
12521b54c88cSJim Ingham         case 'q':
1253b2a38a72SJim Ingham             if (option_arg != NULL)
12541b54c88cSJim Ingham                 m_queue_name = option_arg;
1255b2a38a72SJim Ingham             else
1256b2a38a72SJim Ingham                 m_queue_name.clear();
1257b2a38a72SJim Ingham             m_queue_passed = true;
12581b54c88cSJim Ingham             break;
12591b54c88cSJim Ingham         case 'x':
12601b54c88cSJim Ingham         {
1261c982c768SGreg Clayton             m_thread_index = Args::StringToUInt32 (optarg, UINT32_MAX, 0);
1262c982c768SGreg Clayton             if (m_thread_id == UINT32_MAX)
12631b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg);
12641b54c88cSJim Ingham 
12651b54c88cSJim Ingham         }
12661b54c88cSJim Ingham         break;
12671b54c88cSJim Ingham         default:
12681b54c88cSJim Ingham             error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
12691b54c88cSJim Ingham             break;
12701b54c88cSJim Ingham     }
12711b54c88cSJim Ingham 
12721b54c88cSJim Ingham     return error;
12731b54c88cSJim Ingham }
12741b54c88cSJim Ingham 
12751b54c88cSJim Ingham void
1276ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::ResetOptionValues ()
12771b54c88cSJim Ingham {
12781b54c88cSJim Ingham     Options::ResetOptionValues();
12791b54c88cSJim Ingham 
1280c982c768SGreg Clayton     m_ignore_count = 0;
12811b54c88cSJim Ingham     m_thread_id = LLDB_INVALID_THREAD_ID;
1282c982c768SGreg Clayton     m_thread_index = UINT32_MAX;
12831b54c88cSJim Ingham     m_thread_name.clear();
12841b54c88cSJim Ingham     m_queue_name.clear();
128536f3b369SJim Ingham     m_condition.clear();
1286ae1c4cf5SJim Ingham     m_enable_passed = false;
1287b2a38a72SJim Ingham     m_queue_passed = false;
1288b2a38a72SJim Ingham     m_name_passed = false;
128936f3b369SJim Ingham     m_condition_passed = false;
12901b54c88cSJim Ingham }
12911b54c88cSJim Ingham 
12921b54c88cSJim Ingham //-------------------------------------------------------------------------
1293ae1c4cf5SJim Ingham // CommandObjectBreakpointModify
12941b54c88cSJim Ingham //-------------------------------------------------------------------------
1295ae1c4cf5SJim Ingham #pragma mark Modify
12961b54c88cSJim Ingham 
1297a7015092SGreg Clayton CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
1298a7015092SGreg Clayton     CommandObject (interpreter,
1299a7015092SGreg Clayton                    "breakpoint modify",
1300a7015092SGreg Clayton                    "Modify the options on a breakpoint or set of breakpoints in the executable.",
1301e139cf23SCaroline Tice                    NULL)
13021b54c88cSJim Ingham {
1303e139cf23SCaroline Tice     CommandArgumentEntry arg;
1304e139cf23SCaroline Tice     CommandArgumentData bp_id_arg;
1305e139cf23SCaroline Tice     CommandArgumentData bp_id_range_arg;
1306e139cf23SCaroline Tice 
1307e139cf23SCaroline Tice     // Create the first variant for the first (and only) argument for this command.
1308e139cf23SCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
1309405fe67fSCaroline Tice     bp_id_arg.arg_repetition = eArgRepeatPlain;
1310e139cf23SCaroline Tice 
1311e139cf23SCaroline Tice     // Create the second variant for the first (and only) argument for this command.
1312e139cf23SCaroline Tice     bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
1313405fe67fSCaroline Tice     bp_id_range_arg.arg_repetition = eArgRepeatPlain;
1314e139cf23SCaroline Tice 
1315e139cf23SCaroline Tice     // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1316e139cf23SCaroline Tice     // Push both variants into the entry for the first argument for this command.
1317e139cf23SCaroline Tice     arg.push_back (bp_id_arg);
1318e139cf23SCaroline Tice     arg.push_back (bp_id_range_arg);
1319e139cf23SCaroline Tice 
1320e139cf23SCaroline Tice     // Add the entry for the first argument for this command to the object's arguments vector.
1321e139cf23SCaroline Tice     m_arguments.push_back (arg);
13221b54c88cSJim Ingham }
13231b54c88cSJim Ingham 
1324ae1c4cf5SJim Ingham CommandObjectBreakpointModify::~CommandObjectBreakpointModify ()
13251b54c88cSJim Ingham {
13261b54c88cSJim Ingham }
13271b54c88cSJim Ingham 
13281b54c88cSJim Ingham Options *
1329ae1c4cf5SJim Ingham CommandObjectBreakpointModify::GetOptions ()
13301b54c88cSJim Ingham {
13311b54c88cSJim Ingham     return &m_options;
13321b54c88cSJim Ingham }
13331b54c88cSJim Ingham 
13341b54c88cSJim Ingham bool
1335ae1c4cf5SJim Ingham CommandObjectBreakpointModify::Execute
13361b54c88cSJim Ingham (
13371b54c88cSJim Ingham     Args& command,
13381b54c88cSJim Ingham     CommandReturnObject &result
13391b54c88cSJim Ingham )
13401b54c88cSJim Ingham {
1341a7015092SGreg Clayton     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
13421b54c88cSJim Ingham     if (target == NULL)
13431b54c88cSJim Ingham     {
13449068d794SCaroline Tice         result.AppendError ("Invalid target.  No existing target or breakpoints.");
13451b54c88cSJim Ingham         result.SetStatus (eReturnStatusFailed);
13461b54c88cSJim Ingham         return false;
13471b54c88cSJim Ingham     }
13481b54c88cSJim Ingham 
13491b54c88cSJim Ingham     Mutex::Locker locker;
13501b54c88cSJim Ingham     target->GetBreakpointList().GetListMutex(locker);
13511b54c88cSJim Ingham 
13521b54c88cSJim Ingham     BreakpointIDList valid_bp_ids;
13531b54c88cSJim Ingham 
13541b54c88cSJim Ingham     CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
13551b54c88cSJim Ingham 
13561b54c88cSJim Ingham     if (result.Succeeded())
13571b54c88cSJim Ingham     {
1358c982c768SGreg Clayton         const size_t count = valid_bp_ids.GetSize();
1359c982c768SGreg Clayton         for (size_t i = 0; i < count; ++i)
13601b54c88cSJim Ingham         {
13611b54c88cSJim Ingham             BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
13621b54c88cSJim Ingham 
13631b54c88cSJim Ingham             if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
13641b54c88cSJim Ingham             {
13651b54c88cSJim Ingham                 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
13661b54c88cSJim Ingham                 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
13671b54c88cSJim Ingham                 {
13681b54c88cSJim Ingham                     BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
13691b54c88cSJim Ingham                     if (location)
13701b54c88cSJim Ingham                     {
13711b54c88cSJim Ingham                         if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
13721b54c88cSJim Ingham                             location->SetThreadID (m_options.m_thread_id);
13731b54c88cSJim Ingham 
1374c982c768SGreg Clayton                         if (m_options.m_thread_index != UINT32_MAX)
13751b54c88cSJim Ingham                             location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
13761b54c88cSJim Ingham 
1377b2a38a72SJim Ingham                         if (m_options.m_name_passed)
13781b54c88cSJim Ingham                             location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
13791b54c88cSJim Ingham 
1380b2a38a72SJim Ingham                         if (m_options.m_queue_passed)
13811b54c88cSJim Ingham                             location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
13821b54c88cSJim Ingham 
1383c982c768SGreg Clayton                         if (m_options.m_ignore_count != 0)
13841b54c88cSJim Ingham                             location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count);
1385ae1c4cf5SJim Ingham 
1386ae1c4cf5SJim Ingham                         if (m_options.m_enable_passed)
1387ae1c4cf5SJim Ingham                             location->SetEnabled (m_options.m_enable_value);
138836f3b369SJim Ingham 
138936f3b369SJim Ingham                         if (m_options.m_condition_passed)
139036f3b369SJim Ingham                             location->SetCondition (m_options.m_condition.c_str());
13911b54c88cSJim Ingham                     }
13921b54c88cSJim Ingham                 }
13931b54c88cSJim Ingham                 else
13941b54c88cSJim Ingham                 {
13951b54c88cSJim Ingham                     if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
13961b54c88cSJim Ingham                         bp->SetThreadID (m_options.m_thread_id);
13971b54c88cSJim Ingham 
1398c982c768SGreg Clayton                     if (m_options.m_thread_index != UINT32_MAX)
13991b54c88cSJim Ingham                         bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
14001b54c88cSJim Ingham 
1401b2a38a72SJim Ingham                     if (m_options.m_name_passed)
14021b54c88cSJim Ingham                         bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
14031b54c88cSJim Ingham 
1404b2a38a72SJim Ingham                     if (m_options.m_queue_passed)
14051b54c88cSJim Ingham                         bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
14061b54c88cSJim Ingham 
1407c982c768SGreg Clayton                     if (m_options.m_ignore_count != 0)
14081b54c88cSJim Ingham                         bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
1409ae1c4cf5SJim Ingham 
1410ae1c4cf5SJim Ingham                     if (m_options.m_enable_passed)
1411ae1c4cf5SJim Ingham                         bp->SetEnabled (m_options.m_enable_value);
1412ae1c4cf5SJim Ingham 
141336f3b369SJim Ingham                     if (m_options.m_condition_passed)
141436f3b369SJim Ingham                         bp->SetCondition (m_options.m_condition.c_str());
14151b54c88cSJim Ingham                 }
14161b54c88cSJim Ingham             }
14171b54c88cSJim Ingham         }
14181b54c88cSJim Ingham     }
14191b54c88cSJim Ingham 
14201b54c88cSJim Ingham     return result.Succeeded();
14211b54c88cSJim Ingham }
14221b54c88cSJim Ingham 
14231b54c88cSJim Ingham 
1424