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
376611103cSGreg Clayton AddBreakpointDescription (StreamString *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 //-------------------------------------------------------------------------
4630fdc8d8SChris Lattner // CommandObjectBreakpointSet::CommandOptions
4730fdc8d8SChris Lattner //-------------------------------------------------------------------------
48ae1c4cf5SJim Ingham #pragma mark Set::CommandOptions
4930fdc8d8SChris Lattner 
5030fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::CommandOptions() :
5130fdc8d8SChris Lattner     Options (),
5230fdc8d8SChris Lattner     m_filename (),
5330fdc8d8SChris Lattner     m_line_num (0),
5430fdc8d8SChris Lattner     m_column (0),
552856d462SGreg Clayton     m_check_inlines (true),
5630fdc8d8SChris Lattner     m_func_name (),
570c5cd90dSGreg Clayton     m_func_name_type_mask (0),
5830fdc8d8SChris Lattner     m_func_regexp (),
5930fdc8d8SChris Lattner     m_modules (),
601b54c88cSJim Ingham     m_load_addr(),
61c982c768SGreg Clayton     m_ignore_count (0),
621b54c88cSJim Ingham     m_thread_id(LLDB_INVALID_THREAD_ID),
63c982c768SGreg Clayton     m_thread_index (UINT32_MAX),
641b54c88cSJim Ingham     m_thread_name(),
65c982c768SGreg Clayton     m_queue_name()
6630fdc8d8SChris Lattner {
6730fdc8d8SChris Lattner }
6830fdc8d8SChris Lattner 
6930fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::~CommandOptions ()
7030fdc8d8SChris Lattner {
7130fdc8d8SChris Lattner }
7230fdc8d8SChris Lattner 
7330fdc8d8SChris Lattner lldb::OptionDefinition
7430fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
7530fdc8d8SChris Lattner {
76deaab222SCaroline Tice     { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
778651121cSJim Ingham         "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."},
788651121cSJim Ingham 
79deaab222SCaroline Tice     { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument,   NULL, 0, eArgTypeCount,
80deaab222SCaroline Tice         "Set the number of times this breakpoint is skipped before stopping." },
811b54c88cSJim Ingham 
82deaab222SCaroline Tice     { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex,
83ed8a705cSGreg Clayton         "The breakpoint stops only for the thread whose index matches this argument."},
841b54c88cSJim Ingham 
85deaab222SCaroline Tice     { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, eArgTypeThreadID,
861b54c88cSJim Ingham         "The breakpoint stops only for the thread whose TID matches this argument."},
871b54c88cSJim Ingham 
88deaab222SCaroline Tice     { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, eArgTypeThreadName,
891b54c88cSJim Ingham         "The breakpoint stops only for the thread whose thread name matches this argument."},
901b54c88cSJim Ingham 
91deaab222SCaroline Tice     { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, eArgTypeQueueName,
921b54c88cSJim Ingham         "The breakpoint stops only for threads in the queue whose name is given by this argument."},
931b54c88cSJim Ingham 
94deaab222SCaroline Tice     { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
9530fdc8d8SChris Lattner         "Set the breakpoint by source location in this particular file."},
9630fdc8d8SChris Lattner 
97deaab222SCaroline Tice     { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
9830fdc8d8SChris Lattner         "Set the breakpoint by source location at this particular line."},
9930fdc8d8SChris Lattner 
10030fdc8d8SChris Lattner     // Comment out this option for the moment, as we don't actually use it, but will in the future.
10130fdc8d8SChris Lattner     // This way users won't see it, but the infrastructure is left in place.
10230fdc8d8SChris Lattner     //    { 0, false, "column",     'c', required_argument, NULL, "<column>",
10330fdc8d8SChris Lattner     //    "Set the breakpoint by source location at this particular column."},
10430fdc8d8SChris Lattner 
105deaab222SCaroline Tice     { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress,
10630fdc8d8SChris Lattner         "Set the breakpoint by address, at the specified address."},
10730fdc8d8SChris Lattner 
108deaab222SCaroline Tice     { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
109e02b8504SGreg Clayton         "Set the breakpoint by function name." },
11030fdc8d8SChris Lattner 
111deaab222SCaroline Tice     { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
1122561aa61SJim Ingham         "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguemnts, and "
1132561aa61SJim Ingham         "for Objective C this means a full function prototype with class and selector." },
1140c5cd90dSGreg Clayton 
115deaab222SCaroline Tice     { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector,
1162561aa61SJim Ingham         "Set the breakpoint by ObjC selector name." },
1170c5cd90dSGreg Clayton 
118deaab222SCaroline Tice     { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod,
1192561aa61SJim Ingham         "Set the breakpoint by C++ method names." },
1200c5cd90dSGreg Clayton 
121deaab222SCaroline Tice     { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression,
12230fdc8d8SChris Lattner         "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
12330fdc8d8SChris Lattner 
124e02b8504SGreg Clayton     { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
125e02b8504SGreg Clayton         "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored)." },
126e02b8504SGreg Clayton 
127deaab222SCaroline Tice     { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
12830fdc8d8SChris Lattner };
12930fdc8d8SChris Lattner 
13030fdc8d8SChris Lattner const lldb::OptionDefinition*
13130fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::GetDefinitions ()
13230fdc8d8SChris Lattner {
13330fdc8d8SChris Lattner     return g_option_table;
13430fdc8d8SChris Lattner }
13530fdc8d8SChris Lattner 
13630fdc8d8SChris Lattner Error
13730fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
13830fdc8d8SChris Lattner {
13930fdc8d8SChris Lattner     Error error;
14030fdc8d8SChris Lattner     char short_option = (char) m_getopt_table[option_idx].val;
14130fdc8d8SChris Lattner 
14230fdc8d8SChris Lattner     switch (short_option)
14330fdc8d8SChris Lattner     {
14430fdc8d8SChris Lattner         case 'a':
14530fdc8d8SChris Lattner             m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 0);
14630fdc8d8SChris Lattner             if (m_load_addr == LLDB_INVALID_ADDRESS)
14730fdc8d8SChris Lattner                 m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 16);
14830fdc8d8SChris Lattner 
14930fdc8d8SChris Lattner             if (m_load_addr == LLDB_INVALID_ADDRESS)
15030fdc8d8SChris Lattner                 error.SetErrorStringWithFormat ("Invalid address string '%s'.\n", optarg);
15130fdc8d8SChris Lattner             break;
15230fdc8d8SChris Lattner 
15330fdc8d8SChris Lattner         case 'c':
15430fdc8d8SChris Lattner             m_column = Args::StringToUInt32 (option_arg, 0);
15530fdc8d8SChris Lattner             break;
1560c5cd90dSGreg Clayton 
15730fdc8d8SChris Lattner         case 'f':
15830fdc8d8SChris Lattner             m_filename = option_arg;
15930fdc8d8SChris Lattner             break;
1600c5cd90dSGreg Clayton 
16130fdc8d8SChris Lattner         case 'l':
16230fdc8d8SChris Lattner             m_line_num = Args::StringToUInt32 (option_arg, 0);
16330fdc8d8SChris Lattner             break;
1640c5cd90dSGreg Clayton 
165e02b8504SGreg Clayton         case 'b':
16630fdc8d8SChris Lattner             m_func_name = option_arg;
1670c5cd90dSGreg Clayton             m_func_name_type_mask |= eFunctionNameTypeBase;
1680c5cd90dSGreg Clayton             break;
1690c5cd90dSGreg Clayton 
170e02b8504SGreg Clayton         case 'n':
171e02b8504SGreg Clayton             m_func_name = option_arg;
172e02b8504SGreg Clayton             m_func_name_type_mask |= eFunctionNameTypeAuto;
173e02b8504SGreg Clayton             break;
174e02b8504SGreg Clayton 
1750c5cd90dSGreg Clayton         case 'F':
1762561aa61SJim Ingham             m_func_name = option_arg;
1770c5cd90dSGreg Clayton             m_func_name_type_mask |= eFunctionNameTypeFull;
1780c5cd90dSGreg Clayton             break;
1790c5cd90dSGreg Clayton 
1800c5cd90dSGreg Clayton         case 'S':
1812561aa61SJim Ingham             m_func_name = option_arg;
1820c5cd90dSGreg Clayton             m_func_name_type_mask |= eFunctionNameTypeSelector;
1830c5cd90dSGreg Clayton             break;
1840c5cd90dSGreg Clayton 
1852561aa61SJim Ingham         case 'M':
1862561aa61SJim Ingham             m_func_name = option_arg;
1870c5cd90dSGreg Clayton             m_func_name_type_mask |= eFunctionNameTypeMethod;
1880c5cd90dSGreg Clayton             break;
1890c5cd90dSGreg Clayton 
19030fdc8d8SChris Lattner         case 'r':
19130fdc8d8SChris Lattner             m_func_regexp = option_arg;
19230fdc8d8SChris Lattner             break;
1930c5cd90dSGreg Clayton 
19430fdc8d8SChris Lattner         case 's':
19530fdc8d8SChris Lattner             {
19630fdc8d8SChris Lattner                 m_modules.push_back (std::string (option_arg));
19730fdc8d8SChris Lattner                 break;
19830fdc8d8SChris Lattner             }
199ed8a705cSGreg Clayton         case 'i':
2001b54c88cSJim Ingham         {
201c982c768SGreg Clayton             m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0);
202c982c768SGreg Clayton             if (m_ignore_count == UINT32_MAX)
2031b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg);
2041b54c88cSJim Ingham         }
205ae1c4cf5SJim Ingham         break;
2061b54c88cSJim Ingham         case 't' :
2071b54c88cSJim Ingham         {
2081b54c88cSJim Ingham             m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0);
2091b54c88cSJim Ingham             if (m_thread_id == LLDB_INVALID_THREAD_ID)
2101b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg);
2111b54c88cSJim Ingham         }
2121b54c88cSJim Ingham         break;
2131b54c88cSJim Ingham         case 'T':
2141b54c88cSJim Ingham             m_thread_name = option_arg;
2151b54c88cSJim Ingham             break;
2161b54c88cSJim Ingham         case 'q':
2171b54c88cSJim Ingham             m_queue_name = option_arg;
2181b54c88cSJim Ingham             break;
2191b54c88cSJim Ingham         case 'x':
2201b54c88cSJim Ingham         {
221c982c768SGreg Clayton             m_thread_index = Args::StringToUInt32(optarg, UINT32_MAX, 0);
222c982c768SGreg Clayton             if (m_thread_id == UINT32_MAX)
2231b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg);
2241b54c88cSJim Ingham 
2251b54c88cSJim Ingham         }
2261b54c88cSJim Ingham         break;
22730fdc8d8SChris Lattner         default:
22830fdc8d8SChris Lattner             error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
22930fdc8d8SChris Lattner             break;
23030fdc8d8SChris Lattner     }
23130fdc8d8SChris Lattner 
23230fdc8d8SChris Lattner     return error;
23330fdc8d8SChris Lattner }
23430fdc8d8SChris Lattner 
23530fdc8d8SChris Lattner void
23630fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::ResetOptionValues ()
23730fdc8d8SChris Lattner {
23830fdc8d8SChris Lattner     Options::ResetOptionValues();
23930fdc8d8SChris Lattner 
24030fdc8d8SChris Lattner     m_filename.clear();
24130fdc8d8SChris Lattner     m_line_num = 0;
24230fdc8d8SChris Lattner     m_column = 0;
24330fdc8d8SChris Lattner     m_func_name.clear();
2440c5cd90dSGreg Clayton     m_func_name_type_mask = 0;
24530fdc8d8SChris Lattner     m_func_regexp.clear();
24630fdc8d8SChris Lattner     m_load_addr = LLDB_INVALID_ADDRESS;
24730fdc8d8SChris Lattner     m_modules.clear();
248c982c768SGreg Clayton     m_ignore_count = 0;
2491b54c88cSJim Ingham     m_thread_id = LLDB_INVALID_THREAD_ID;
250c982c768SGreg Clayton     m_thread_index = UINT32_MAX;
2511b54c88cSJim Ingham     m_thread_name.clear();
2521b54c88cSJim Ingham     m_queue_name.clear();
25330fdc8d8SChris Lattner }
25430fdc8d8SChris Lattner 
25530fdc8d8SChris Lattner //-------------------------------------------------------------------------
25630fdc8d8SChris Lattner // CommandObjectBreakpointSet
25730fdc8d8SChris Lattner //-------------------------------------------------------------------------
258ae1c4cf5SJim Ingham #pragma mark Set
25930fdc8d8SChris Lattner 
260a7015092SGreg Clayton CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
261a7015092SGreg Clayton     CommandObject (interpreter,
262a7015092SGreg Clayton                    "breakpoint set",
263a7015092SGreg Clayton                    "Sets a breakpoint or set of breakpoints in the executable.",
26430fdc8d8SChris Lattner                    "breakpoint set <cmd-options>")
26530fdc8d8SChris Lattner {
26630fdc8d8SChris Lattner }
26730fdc8d8SChris Lattner 
26830fdc8d8SChris Lattner CommandObjectBreakpointSet::~CommandObjectBreakpointSet ()
26930fdc8d8SChris Lattner {
27030fdc8d8SChris Lattner }
27130fdc8d8SChris Lattner 
27230fdc8d8SChris Lattner Options *
27330fdc8d8SChris Lattner CommandObjectBreakpointSet::GetOptions ()
27430fdc8d8SChris Lattner {
27530fdc8d8SChris Lattner     return &m_options;
27630fdc8d8SChris Lattner }
27730fdc8d8SChris Lattner 
27830fdc8d8SChris Lattner bool
27930fdc8d8SChris Lattner CommandObjectBreakpointSet::Execute
28030fdc8d8SChris Lattner (
28130fdc8d8SChris Lattner     Args& command,
28230fdc8d8SChris Lattner     CommandReturnObject &result
28330fdc8d8SChris Lattner )
28430fdc8d8SChris Lattner {
285a7015092SGreg Clayton     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
28630fdc8d8SChris Lattner     if (target == NULL)
28730fdc8d8SChris Lattner     {
2889068d794SCaroline Tice         result.AppendError ("Invalid target.  Must set target before setting breakpoints (see 'file' command).");
28930fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
29030fdc8d8SChris Lattner         return false;
29130fdc8d8SChris Lattner     }
29230fdc8d8SChris Lattner 
29330fdc8d8SChris Lattner     // The following are the various types of breakpoints that could be set:
29430fdc8d8SChris Lattner     //   1).  -f -l -p  [-s -g]   (setting breakpoint by source location)
29530fdc8d8SChris Lattner     //   2).  -a  [-s -g]         (setting breakpoint by address)
29630fdc8d8SChris Lattner     //   3).  -n  [-s -g]         (setting breakpoint by function name)
29730fdc8d8SChris Lattner     //   4).  -r  [-s -g]         (setting breakpoint by function name regular expression)
29830fdc8d8SChris Lattner 
29930fdc8d8SChris Lattner     BreakpointSetType break_type = eSetTypeInvalid;
30030fdc8d8SChris Lattner 
30130fdc8d8SChris Lattner     if (m_options.m_line_num != 0)
30230fdc8d8SChris Lattner         break_type = eSetTypeFileAndLine;
30330fdc8d8SChris Lattner     else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
30430fdc8d8SChris Lattner         break_type = eSetTypeAddress;
30530fdc8d8SChris Lattner     else if (!m_options.m_func_name.empty())
30630fdc8d8SChris Lattner         break_type = eSetTypeFunctionName;
30730fdc8d8SChris Lattner     else if  (!m_options.m_func_regexp.empty())
30830fdc8d8SChris Lattner         break_type = eSetTypeFunctionRegexp;
30930fdc8d8SChris Lattner 
31030fdc8d8SChris Lattner     ModuleSP module_sp = target->GetExecutableModule();
31130fdc8d8SChris Lattner     Breakpoint *bp = NULL;
312274060b6SGreg Clayton     FileSpec module_spec;
31330fdc8d8SChris Lattner     bool use_module = false;
31430fdc8d8SChris Lattner     int num_modules = m_options.m_modules.size();
31530fdc8d8SChris Lattner 
31630fdc8d8SChris Lattner     if ((num_modules > 0) && (break_type != eSetTypeAddress))
31730fdc8d8SChris Lattner         use_module = true;
31830fdc8d8SChris Lattner 
31930fdc8d8SChris Lattner     switch (break_type)
32030fdc8d8SChris Lattner     {
32130fdc8d8SChris Lattner         case eSetTypeFileAndLine: // Breakpoint by source position
32230fdc8d8SChris Lattner             {
32330fdc8d8SChris Lattner                 FileSpec file;
32430fdc8d8SChris Lattner                 if (m_options.m_filename.empty())
32530fdc8d8SChris Lattner                 {
326a7015092SGreg Clayton                     StackFrame *cur_frame = m_interpreter.GetDebugger().GetExecutionContext().frame;
32730fdc8d8SChris Lattner                     if (cur_frame == NULL)
32830fdc8d8SChris Lattner                     {
32930fdc8d8SChris Lattner                         result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame.");
33030fdc8d8SChris Lattner                         result.SetStatus (eReturnStatusFailed);
33130fdc8d8SChris Lattner                         break;
33230fdc8d8SChris Lattner                     }
33330fdc8d8SChris Lattner                     else if (!cur_frame->HasDebugInformation())
33430fdc8d8SChris Lattner                     {
33530fdc8d8SChris Lattner                         result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info.");
33630fdc8d8SChris Lattner                         result.SetStatus (eReturnStatusFailed);
33730fdc8d8SChris Lattner                         break;
33830fdc8d8SChris Lattner                     }
33930fdc8d8SChris Lattner                     else
34030fdc8d8SChris Lattner                     {
34130fdc8d8SChris Lattner                         const SymbolContext &context = cur_frame->GetSymbolContext(true);
34230fdc8d8SChris Lattner                         if (context.line_entry.file)
34330fdc8d8SChris Lattner                         {
34430fdc8d8SChris Lattner                             file = context.line_entry.file;
34530fdc8d8SChris Lattner                         }
34630fdc8d8SChris Lattner                         else if (context.comp_unit != NULL)
34730fdc8d8SChris Lattner                         {    file = context.comp_unit;
34830fdc8d8SChris Lattner                         }
34930fdc8d8SChris Lattner                         else
35030fdc8d8SChris Lattner                         {
35130fdc8d8SChris Lattner                             result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame.");
35230fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusFailed);
35330fdc8d8SChris Lattner                             break;
35430fdc8d8SChris Lattner                         }
35530fdc8d8SChris Lattner                     }
35630fdc8d8SChris Lattner                 }
35730fdc8d8SChris Lattner                 else
35830fdc8d8SChris Lattner                 {
359274060b6SGreg Clayton                     file.SetFile(m_options.m_filename.c_str(), false);
36030fdc8d8SChris Lattner                 }
36130fdc8d8SChris Lattner 
36230fdc8d8SChris Lattner                 if (use_module)
36330fdc8d8SChris Lattner                 {
36430fdc8d8SChris Lattner                     for (int i = 0; i < num_modules; ++i)
36530fdc8d8SChris Lattner                     {
366274060b6SGreg Clayton                         module_spec.SetFile(m_options.m_modules[i].c_str(), false);
367274060b6SGreg Clayton                         bp = target->CreateBreakpoint (&module_spec,
36830fdc8d8SChris Lattner                                                        file,
36930fdc8d8SChris Lattner                                                        m_options.m_line_num,
3702856d462SGreg Clayton                                                        m_options.m_check_inlines).get();
37130fdc8d8SChris Lattner                         if (bp)
37230fdc8d8SChris Lattner                         {
37330fdc8d8SChris Lattner                             StreamString &output_stream = result.GetOutputStream();
37430fdc8d8SChris Lattner                             output_stream.Printf ("Breakpoint created: ");
37530fdc8d8SChris Lattner                             bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
37630fdc8d8SChris Lattner                             output_stream.EOL();
377be484f41SCaroline Tice                             if (bp->GetNumLocations() == 0)
378be484f41SCaroline Tice                                 output_stream.Printf ("WARNING:  Unable to resolve breakpoint to any actual"
379be484f41SCaroline Tice                                                       " locations.\n");
38030fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusSuccessFinishResult);
38130fdc8d8SChris Lattner                         }
38230fdc8d8SChris Lattner                         else
38330fdc8d8SChris Lattner                         {
38430fdc8d8SChris Lattner                             result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
38530fdc8d8SChris Lattner                                                         m_options.m_modules[i].c_str());
38630fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusFailed);
38730fdc8d8SChris Lattner                         }
38830fdc8d8SChris Lattner                     }
38930fdc8d8SChris Lattner                 }
39030fdc8d8SChris Lattner                 else
39130fdc8d8SChris Lattner                     bp = target->CreateBreakpoint (NULL,
39230fdc8d8SChris Lattner                                                    file,
39330fdc8d8SChris Lattner                                                    m_options.m_line_num,
3942856d462SGreg Clayton                                                    m_options.m_check_inlines).get();
39530fdc8d8SChris Lattner             }
39630fdc8d8SChris Lattner             break;
3976eee5aa0SGreg Clayton 
39830fdc8d8SChris Lattner         case eSetTypeAddress: // Breakpoint by address
39930fdc8d8SChris Lattner             bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
40030fdc8d8SChris Lattner             break;
4010c5cd90dSGreg Clayton 
40230fdc8d8SChris Lattner         case eSetTypeFunctionName: // Breakpoint by function name
4030c5cd90dSGreg Clayton             {
4040c5cd90dSGreg Clayton                 uint32_t name_type_mask = m_options.m_func_name_type_mask;
4050c5cd90dSGreg Clayton 
4060c5cd90dSGreg Clayton                 if (name_type_mask == 0)
407e02b8504SGreg Clayton                     name_type_mask = eFunctionNameTypeAuto;
4080c5cd90dSGreg Clayton 
40930fdc8d8SChris Lattner                 if (use_module)
41030fdc8d8SChris Lattner                 {
41130fdc8d8SChris Lattner                     for (int i = 0; i < num_modules; ++i)
41230fdc8d8SChris Lattner                     {
413274060b6SGreg Clayton                         module_spec.SetFile(m_options.m_modules[i].c_str(), false);
414274060b6SGreg Clayton                         bp = target->CreateBreakpoint (&module_spec,
415274060b6SGreg Clayton                                                        m_options.m_func_name.c_str(),
416274060b6SGreg Clayton                                                        name_type_mask,
417274060b6SGreg Clayton                                                        Breakpoint::Exact).get();
41830fdc8d8SChris Lattner                         if (bp)
41930fdc8d8SChris Lattner                         {
42030fdc8d8SChris Lattner                             StreamString &output_stream = result.GetOutputStream();
42130fdc8d8SChris Lattner                             output_stream.Printf ("Breakpoint created: ");
42230fdc8d8SChris Lattner                             bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
42330fdc8d8SChris Lattner                             output_stream.EOL();
424be484f41SCaroline Tice                             if (bp->GetNumLocations() == 0)
425be484f41SCaroline Tice                                 output_stream.Printf ("WARNING:  Unable to resolve breakpoint to any actual"
426be484f41SCaroline Tice                                                       " locations.\n");
42730fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusSuccessFinishResult);
42830fdc8d8SChris Lattner                         }
42930fdc8d8SChris Lattner                         else
43030fdc8d8SChris Lattner                         {
43130fdc8d8SChris Lattner                             result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
43230fdc8d8SChris Lattner                                                         m_options.m_modules[i].c_str());
43330fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusFailed);
43430fdc8d8SChris Lattner                         }
43530fdc8d8SChris Lattner                     }
43630fdc8d8SChris Lattner                 }
43730fdc8d8SChris Lattner                 else
4380c5cd90dSGreg Clayton                     bp = target->CreateBreakpoint (NULL, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get();
4390c5cd90dSGreg Clayton             }
44030fdc8d8SChris Lattner             break;
4410c5cd90dSGreg Clayton 
44230fdc8d8SChris Lattner         case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
44330fdc8d8SChris Lattner             {
44430fdc8d8SChris Lattner                 RegularExpression regexp(m_options.m_func_regexp.c_str());
44530fdc8d8SChris Lattner                 if (use_module)
44630fdc8d8SChris Lattner                 {
44730fdc8d8SChris Lattner                     for (int i = 0; i < num_modules; ++i)
44830fdc8d8SChris Lattner                     {
449274060b6SGreg Clayton                         module_spec.SetFile(m_options.m_modules[i].c_str(), false);
450274060b6SGreg Clayton                         bp = target->CreateBreakpoint (&module_spec, regexp).get();
45130fdc8d8SChris Lattner                         if (bp)
45230fdc8d8SChris Lattner                         {
45330fdc8d8SChris Lattner                             StreamString &output_stream = result.GetOutputStream();
45430fdc8d8SChris Lattner                             output_stream.Printf ("Breakpoint created: ");
45530fdc8d8SChris Lattner                             bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
45630fdc8d8SChris Lattner                             output_stream.EOL();
457be484f41SCaroline Tice                             if (bp->GetNumLocations() == 0)
458be484f41SCaroline Tice                                 output_stream.Printf ("WARNING:  Unable to resolve breakpoint to any actual"
459be484f41SCaroline Tice                                                       " locations.\n");
46030fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusSuccessFinishResult);
46130fdc8d8SChris Lattner                         }
46230fdc8d8SChris Lattner                         else
46330fdc8d8SChris Lattner                         {
46430fdc8d8SChris Lattner                             result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
46530fdc8d8SChris Lattner                                                         m_options.m_modules[i].c_str());
46630fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusFailed);
46730fdc8d8SChris Lattner                         }
46830fdc8d8SChris Lattner                     }
46930fdc8d8SChris Lattner                 }
47030fdc8d8SChris Lattner                 else
47130fdc8d8SChris Lattner                     bp = target->CreateBreakpoint (NULL, regexp).get();
47230fdc8d8SChris Lattner             }
47330fdc8d8SChris Lattner             break;
4740c5cd90dSGreg Clayton 
47530fdc8d8SChris Lattner         default:
47630fdc8d8SChris Lattner             break;
47730fdc8d8SChris Lattner     }
47830fdc8d8SChris Lattner 
4791b54c88cSJim Ingham     // Now set the various options that were passed in:
4801b54c88cSJim Ingham     if (bp)
4811b54c88cSJim Ingham     {
4821b54c88cSJim Ingham         if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
4831b54c88cSJim Ingham             bp->SetThreadID (m_options.m_thread_id);
4841b54c88cSJim Ingham 
485c982c768SGreg Clayton         if (m_options.m_thread_index != UINT32_MAX)
4861b54c88cSJim Ingham             bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
4871b54c88cSJim Ingham 
4881b54c88cSJim Ingham         if (!m_options.m_thread_name.empty())
4891b54c88cSJim Ingham             bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
4901b54c88cSJim Ingham 
4911b54c88cSJim Ingham         if (!m_options.m_queue_name.empty())
4921b54c88cSJim Ingham             bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
4931b54c88cSJim Ingham 
494c982c768SGreg Clayton         if (m_options.m_ignore_count != 0)
4951b54c88cSJim Ingham             bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
4961b54c88cSJim Ingham     }
4971b54c88cSJim Ingham 
49830fdc8d8SChris Lattner     if (bp && !use_module)
49930fdc8d8SChris Lattner     {
50030fdc8d8SChris Lattner         StreamString &output_stream = result.GetOutputStream();
50130fdc8d8SChris Lattner         output_stream.Printf ("Breakpoint created: ");
50230fdc8d8SChris Lattner         bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
50330fdc8d8SChris Lattner         output_stream.EOL();
504be484f41SCaroline Tice         if (bp->GetNumLocations() == 0)
505be484f41SCaroline Tice             output_stream.Printf ("WARNING:  Unable to resolve breakpoint to any actual locations.\n");
50630fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishResult);
50730fdc8d8SChris Lattner     }
50830fdc8d8SChris Lattner     else if (!bp)
50930fdc8d8SChris Lattner     {
51030fdc8d8SChris Lattner         result.AppendError ("Breakpoint creation failed: No breakpoint created.");
51130fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
51230fdc8d8SChris Lattner     }
51330fdc8d8SChris Lattner 
51430fdc8d8SChris Lattner     return result.Succeeded();
51530fdc8d8SChris Lattner }
51630fdc8d8SChris Lattner 
51730fdc8d8SChris Lattner //-------------------------------------------------------------------------
51830fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint
51930fdc8d8SChris Lattner //-------------------------------------------------------------------------
520ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint
52130fdc8d8SChris Lattner 
5226611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
523a7015092SGreg Clayton     CommandObjectMultiword (interpreter,
524a7015092SGreg Clayton                             "breakpoint",
5253f4c09c1SCaroline Tice                             "A set of commands for operating on breakpoints. Also see regexp-break.",
52630fdc8d8SChris Lattner                             "breakpoint <command> [<command-options>]")
52730fdc8d8SChris Lattner {
52830fdc8d8SChris Lattner     bool status;
52930fdc8d8SChris Lattner 
530a7015092SGreg Clayton     CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
531a7015092SGreg Clayton     CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
532a7015092SGreg Clayton     CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
533b7234e40SJohnny Chen     CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
534b7234e40SJohnny Chen     CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
535a7015092SGreg Clayton     CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
53630fdc8d8SChris Lattner     CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
537a7015092SGreg Clayton     CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
53830fdc8d8SChris Lattner 
539b7234e40SJohnny Chen     list_command_object->SetCommandName ("breakpoint list");
54030fdc8d8SChris Lattner     enable_command_object->SetCommandName("breakpoint enable");
54130fdc8d8SChris Lattner     disable_command_object->SetCommandName("breakpoint disable");
542b7234e40SJohnny Chen     clear_command_object->SetCommandName("breakpoint clear");
543b7234e40SJohnny Chen     delete_command_object->SetCommandName("breakpoint delete");
544ae1c4cf5SJim Ingham     set_command_object->SetCommandName("breakpoint set");
545b7234e40SJohnny Chen     command_command_object->SetCommandName ("breakpoint command");
546b7234e40SJohnny Chen     modify_command_object->SetCommandName ("breakpoint modify");
54730fdc8d8SChris Lattner 
548a7015092SGreg Clayton     status = LoadSubCommand ("list",       list_command_object);
549a7015092SGreg Clayton     status = LoadSubCommand ("enable",     enable_command_object);
550a7015092SGreg Clayton     status = LoadSubCommand ("disable",    disable_command_object);
551b7234e40SJohnny Chen     status = LoadSubCommand ("clear",      clear_command_object);
552a7015092SGreg Clayton     status = LoadSubCommand ("delete",     delete_command_object);
553a7015092SGreg Clayton     status = LoadSubCommand ("set",        set_command_object);
554a7015092SGreg Clayton     status = LoadSubCommand ("command",    command_command_object);
555a7015092SGreg Clayton     status = LoadSubCommand ("modify",     modify_command_object);
55630fdc8d8SChris Lattner }
55730fdc8d8SChris Lattner 
55830fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
55930fdc8d8SChris Lattner {
56030fdc8d8SChris Lattner }
56130fdc8d8SChris Lattner 
56230fdc8d8SChris Lattner void
56330fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result,
56430fdc8d8SChris Lattner                                                          BreakpointIDList *valid_ids)
56530fdc8d8SChris Lattner {
56630fdc8d8SChris Lattner     // args can be strings representing 1). integers (for breakpoint ids)
56730fdc8d8SChris Lattner     //                                  2). the full breakpoint & location canonical representation
56830fdc8d8SChris Lattner     //                                  3). the word "to" or a hyphen, representing a range (in which case there
56930fdc8d8SChris Lattner     //                                      had *better* be an entry both before & after of one of the first two types.
57036f3b369SJim Ingham     // If args is empty, we will use the last created breakpoint (if there is one.)
57130fdc8d8SChris Lattner 
57230fdc8d8SChris Lattner     Args temp_args;
57330fdc8d8SChris Lattner 
57436f3b369SJim Ingham     if (args.GetArgumentCount() == 0)
57536f3b369SJim Ingham     {
57636f3b369SJim Ingham         if (target->GetLastCreatedBreakpoint() != NULL)
57736f3b369SJim Ingham         {
57836f3b369SJim Ingham             valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
57936f3b369SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
58036f3b369SJim Ingham         }
58136f3b369SJim Ingham         else
58236f3b369SJim Ingham         {
58336f3b369SJim Ingham             result.AppendError("No breakpoint specified and no last created breakpoint.");
58436f3b369SJim Ingham             result.SetStatus (eReturnStatusFailed);
58536f3b369SJim Ingham         }
58636f3b369SJim Ingham         return;
58736f3b369SJim Ingham     }
58836f3b369SJim Ingham 
58930fdc8d8SChris Lattner     // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
59030fdc8d8SChris Lattner     // the new TEMP_ARGS.  Do not copy breakpoint id range strings over; instead generate a list of strings for
59130fdc8d8SChris Lattner     // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
59230fdc8d8SChris Lattner 
59330fdc8d8SChris Lattner     BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
59430fdc8d8SChris Lattner 
59530fdc8d8SChris Lattner     // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
59630fdc8d8SChris Lattner 
597c982c768SGreg Clayton     valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
59830fdc8d8SChris Lattner 
59930fdc8d8SChris Lattner     // At this point,  all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
60030fdc8d8SChris Lattner     // and put into valid_ids.
60130fdc8d8SChris Lattner 
60230fdc8d8SChris Lattner     if (result.Succeeded())
60330fdc8d8SChris Lattner     {
60430fdc8d8SChris Lattner         // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
60530fdc8d8SChris Lattner         // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
60630fdc8d8SChris Lattner 
607c982c768SGreg Clayton         const size_t count = valid_ids->GetSize();
608c982c768SGreg Clayton         for (size_t i = 0; i < count; ++i)
60930fdc8d8SChris Lattner         {
61030fdc8d8SChris Lattner             BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
61130fdc8d8SChris Lattner             Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
61230fdc8d8SChris Lattner             if (breakpoint != NULL)
61330fdc8d8SChris Lattner             {
61430fdc8d8SChris Lattner                 int num_locations = breakpoint->GetNumLocations();
61530fdc8d8SChris Lattner                 if (cur_bp_id.GetLocationID() > num_locations)
61630fdc8d8SChris Lattner                 {
61730fdc8d8SChris Lattner                     StreamString id_str;
618c982c768SGreg Clayton                     BreakpointID::GetCanonicalReference (&id_str,
619c982c768SGreg Clayton                                                          cur_bp_id.GetBreakpointID(),
62030fdc8d8SChris Lattner                                                          cur_bp_id.GetLocationID());
621c982c768SGreg Clayton                     i = valid_ids->GetSize() + 1;
62230fdc8d8SChris Lattner                     result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
62330fdc8d8SChris Lattner                                                  id_str.GetData());
62430fdc8d8SChris Lattner                     result.SetStatus (eReturnStatusFailed);
62530fdc8d8SChris Lattner                 }
62630fdc8d8SChris Lattner             }
62730fdc8d8SChris Lattner             else
62830fdc8d8SChris Lattner             {
629c982c768SGreg Clayton                 i = valid_ids->GetSize() + 1;
63030fdc8d8SChris Lattner                 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
63130fdc8d8SChris Lattner                 result.SetStatus (eReturnStatusFailed);
63230fdc8d8SChris Lattner             }
63330fdc8d8SChris Lattner         }
63430fdc8d8SChris Lattner     }
63530fdc8d8SChris Lattner }
63630fdc8d8SChris Lattner 
63730fdc8d8SChris Lattner //-------------------------------------------------------------------------
63830fdc8d8SChris Lattner // CommandObjectBreakpointList::Options
63930fdc8d8SChris Lattner //-------------------------------------------------------------------------
640ae1c4cf5SJim Ingham #pragma mark List::CommandOptions
64130fdc8d8SChris Lattner 
64230fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::CommandOptions() :
64330fdc8d8SChris Lattner     Options (),
644*79042b3eSCaroline Tice     m_level (lldb::eDescriptionLevelBrief)  // Breakpoint List defaults to brief descriptions
64530fdc8d8SChris Lattner {
64630fdc8d8SChris Lattner }
64730fdc8d8SChris Lattner 
64830fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::~CommandOptions ()
64930fdc8d8SChris Lattner {
65030fdc8d8SChris Lattner }
65130fdc8d8SChris Lattner 
65230fdc8d8SChris Lattner lldb::OptionDefinition
65330fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::g_option_table[] =
65430fdc8d8SChris Lattner {
655deaab222SCaroline Tice     { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone,
6568651121cSJim Ingham         "Show debugger internal breakpoints" },
6578651121cSJim Ingham 
658deaab222SCaroline Tice     { LLDB_OPT_SET_1, false, "brief",    'b', no_argument, NULL, 0, eArgTypeNone,
65930fdc8d8SChris Lattner         "Give a brief description of the breakpoint (no location info)."},
66030fdc8d8SChris Lattner 
66130fdc8d8SChris Lattner     // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
66230fdc8d8SChris Lattner     // But I need to see it for now, and don't want to wait.
663deaab222SCaroline Tice     { LLDB_OPT_SET_2, false, "full",    'f', no_argument, NULL, 0, eArgTypeNone,
66430fdc8d8SChris Lattner         "Give a full description of the breakpoint and its locations."},
66530fdc8d8SChris Lattner 
666deaab222SCaroline Tice     { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone,
66730fdc8d8SChris Lattner         "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
66830fdc8d8SChris Lattner 
669deaab222SCaroline Tice     { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
67030fdc8d8SChris Lattner };
67130fdc8d8SChris Lattner 
67230fdc8d8SChris Lattner const lldb::OptionDefinition*
67330fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::GetDefinitions ()
67430fdc8d8SChris Lattner {
67530fdc8d8SChris Lattner     return g_option_table;
67630fdc8d8SChris Lattner }
67730fdc8d8SChris Lattner 
67830fdc8d8SChris Lattner Error
67930fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
68030fdc8d8SChris Lattner {
68130fdc8d8SChris Lattner     Error error;
68230fdc8d8SChris Lattner     char short_option = (char) m_getopt_table[option_idx].val;
68330fdc8d8SChris Lattner 
68430fdc8d8SChris Lattner     switch (short_option)
68530fdc8d8SChris Lattner     {
68630fdc8d8SChris Lattner         case 'b':
68730fdc8d8SChris Lattner             m_level = lldb::eDescriptionLevelBrief;
68830fdc8d8SChris Lattner             break;
68930fdc8d8SChris Lattner         case 'f':
69030fdc8d8SChris Lattner             m_level = lldb::eDescriptionLevelFull;
69130fdc8d8SChris Lattner             break;
69230fdc8d8SChris Lattner         case 'v':
69330fdc8d8SChris Lattner             m_level = lldb::eDescriptionLevelVerbose;
69430fdc8d8SChris Lattner             break;
69530fdc8d8SChris Lattner         case 'i':
69630fdc8d8SChris Lattner             m_internal = true;
69730fdc8d8SChris Lattner             break;
69830fdc8d8SChris Lattner         default:
69930fdc8d8SChris Lattner             error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
70030fdc8d8SChris Lattner             break;
70130fdc8d8SChris Lattner     }
70230fdc8d8SChris Lattner 
70330fdc8d8SChris Lattner     return error;
70430fdc8d8SChris Lattner }
70530fdc8d8SChris Lattner 
70630fdc8d8SChris Lattner void
70730fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::ResetOptionValues ()
70830fdc8d8SChris Lattner {
70930fdc8d8SChris Lattner     Options::ResetOptionValues();
71030fdc8d8SChris Lattner 
711*79042b3eSCaroline Tice     m_level = lldb::eDescriptionLevelBrief;
71230fdc8d8SChris Lattner     m_internal = false;
71330fdc8d8SChris Lattner }
71430fdc8d8SChris Lattner 
71530fdc8d8SChris Lattner //-------------------------------------------------------------------------
71630fdc8d8SChris Lattner // CommandObjectBreakpointList
71730fdc8d8SChris Lattner //-------------------------------------------------------------------------
718ae1c4cf5SJim Ingham #pragma mark List
71930fdc8d8SChris Lattner 
720a7015092SGreg Clayton CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) :
721a7015092SGreg Clayton     CommandObject (interpreter,
722a7015092SGreg Clayton                    "breakpoint list",
72330fdc8d8SChris Lattner                    "List some or all breakpoints at configurable levels of detail.",
724e139cf23SCaroline Tice                    NULL)
72530fdc8d8SChris Lattner {
726e139cf23SCaroline Tice     CommandArgumentEntry arg;
727e139cf23SCaroline Tice     CommandArgumentData bp_id_arg;
728e139cf23SCaroline Tice 
729e139cf23SCaroline Tice     // Define the first (and only) variant of this arg.
730e139cf23SCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
731405fe67fSCaroline Tice     bp_id_arg.arg_repetition = eArgRepeatOptional;
732e139cf23SCaroline Tice 
733e139cf23SCaroline Tice     // There is only one variant this argument could be; put it into the argument entry.
734e139cf23SCaroline Tice     arg.push_back (bp_id_arg);
735e139cf23SCaroline Tice 
736e139cf23SCaroline Tice     // Push the data for the first argument into the m_arguments vector.
737e139cf23SCaroline Tice     m_arguments.push_back (arg);
73830fdc8d8SChris Lattner }
73930fdc8d8SChris Lattner 
74030fdc8d8SChris Lattner CommandObjectBreakpointList::~CommandObjectBreakpointList ()
74130fdc8d8SChris Lattner {
74230fdc8d8SChris Lattner }
74330fdc8d8SChris Lattner 
74430fdc8d8SChris Lattner Options *
74530fdc8d8SChris Lattner CommandObjectBreakpointList::GetOptions ()
74630fdc8d8SChris Lattner {
74730fdc8d8SChris Lattner     return &m_options;
74830fdc8d8SChris Lattner }
74930fdc8d8SChris Lattner 
75030fdc8d8SChris Lattner bool
75130fdc8d8SChris Lattner CommandObjectBreakpointList::Execute
75230fdc8d8SChris Lattner (
75330fdc8d8SChris Lattner     Args& args,
75430fdc8d8SChris Lattner     CommandReturnObject &result
75530fdc8d8SChris Lattner )
75630fdc8d8SChris Lattner {
757a7015092SGreg Clayton     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
75830fdc8d8SChris Lattner     if (target == NULL)
75930fdc8d8SChris Lattner     {
7609068d794SCaroline Tice         result.AppendError ("Invalid target. No current target or breakpoints.");
76130fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
76230fdc8d8SChris Lattner         return true;
76330fdc8d8SChris Lattner     }
76430fdc8d8SChris Lattner 
76530fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
7661b54c88cSJim Ingham     Mutex::Locker locker;
7671b54c88cSJim Ingham     target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
7681b54c88cSJim Ingham 
76930fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
77030fdc8d8SChris Lattner 
77130fdc8d8SChris Lattner     if (num_breakpoints == 0)
77230fdc8d8SChris Lattner     {
77330fdc8d8SChris Lattner         result.AppendMessage ("No breakpoints currently set.");
77430fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
77530fdc8d8SChris Lattner         return true;
77630fdc8d8SChris Lattner     }
77730fdc8d8SChris Lattner 
77830fdc8d8SChris Lattner     StreamString &output_stream = result.GetOutputStream();
77930fdc8d8SChris Lattner 
78030fdc8d8SChris Lattner     if (args.GetArgumentCount() == 0)
78130fdc8d8SChris Lattner     {
78230fdc8d8SChris Lattner         // No breakpoint selected; show info about all currently set breakpoints.
78330fdc8d8SChris Lattner         result.AppendMessage ("Current breakpoints:");
784c982c768SGreg Clayton         for (size_t i = 0; i < num_breakpoints; ++i)
78530fdc8d8SChris Lattner         {
7869fed0d85SGreg Clayton             Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
7876611103cSGreg Clayton             AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
78830fdc8d8SChris Lattner         }
78930fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
79030fdc8d8SChris Lattner     }
79130fdc8d8SChris Lattner     else
79230fdc8d8SChris Lattner     {
79330fdc8d8SChris Lattner         // Particular breakpoints selected; show info about that breakpoint.
79430fdc8d8SChris Lattner         BreakpointIDList valid_bp_ids;
79530fdc8d8SChris Lattner         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
79630fdc8d8SChris Lattner 
79730fdc8d8SChris Lattner         if (result.Succeeded())
79830fdc8d8SChris Lattner         {
799c982c768SGreg Clayton             for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
80030fdc8d8SChris Lattner             {
80130fdc8d8SChris Lattner                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
80230fdc8d8SChris Lattner                 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
8036611103cSGreg Clayton                 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
80430fdc8d8SChris Lattner             }
80530fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishNoResult);
80630fdc8d8SChris Lattner         }
80730fdc8d8SChris Lattner         else
80830fdc8d8SChris Lattner         {
80930fdc8d8SChris Lattner             result.AppendError ("Invalid breakpoint id.");
81030fdc8d8SChris Lattner             result.SetStatus (eReturnStatusFailed);
81130fdc8d8SChris Lattner         }
81230fdc8d8SChris Lattner     }
81330fdc8d8SChris Lattner 
81430fdc8d8SChris Lattner     return result.Succeeded();
81530fdc8d8SChris Lattner }
81630fdc8d8SChris Lattner 
81730fdc8d8SChris Lattner //-------------------------------------------------------------------------
81830fdc8d8SChris Lattner // CommandObjectBreakpointEnable
81930fdc8d8SChris Lattner //-------------------------------------------------------------------------
820ae1c4cf5SJim Ingham #pragma mark Enable
82130fdc8d8SChris Lattner 
822a7015092SGreg Clayton CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
823a7015092SGreg Clayton     CommandObject (interpreter,
824a7015092SGreg Clayton                    "enable",
825e3d26315SCaroline Tice                    "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
826e139cf23SCaroline Tice                    NULL)
82730fdc8d8SChris Lattner {
828e139cf23SCaroline Tice     CommandArgumentEntry arg;
829e139cf23SCaroline Tice     CommandArgumentData bp_id_arg;
830e139cf23SCaroline Tice     CommandArgumentData bp_id_range_arg;
831e139cf23SCaroline Tice 
832e139cf23SCaroline Tice     // Create the first variant for the first (and only) argument for this command.
833e139cf23SCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
834405fe67fSCaroline Tice     bp_id_arg.arg_repetition = eArgRepeatOptional;
835e139cf23SCaroline Tice 
836e139cf23SCaroline Tice     // Create the second variant for the first (and only) argument for this command.
837e139cf23SCaroline Tice     bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
838405fe67fSCaroline Tice     bp_id_range_arg.arg_repetition = eArgRepeatOptional;
839e139cf23SCaroline Tice 
840e139cf23SCaroline Tice     // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
841e139cf23SCaroline Tice     // Push both variants into the entry for the first argument for this command.
842e139cf23SCaroline Tice     arg.push_back (bp_id_arg);
843e139cf23SCaroline Tice     arg.push_back (bp_id_range_arg);
844e139cf23SCaroline Tice 
845e139cf23SCaroline Tice     // Add the entry for the first argument for this command to the object's arguments vector.
846e139cf23SCaroline Tice     m_arguments.push_back (arg);
84730fdc8d8SChris Lattner }
84830fdc8d8SChris Lattner 
84930fdc8d8SChris Lattner 
85030fdc8d8SChris Lattner CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable ()
85130fdc8d8SChris Lattner {
85230fdc8d8SChris Lattner }
85330fdc8d8SChris Lattner 
85430fdc8d8SChris Lattner 
85530fdc8d8SChris Lattner bool
8566611103cSGreg Clayton CommandObjectBreakpointEnable::Execute
8576611103cSGreg Clayton (
8586611103cSGreg Clayton     Args& args,
8596611103cSGreg Clayton     CommandReturnObject &result
8606611103cSGreg Clayton )
86130fdc8d8SChris Lattner {
862a7015092SGreg Clayton     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
86330fdc8d8SChris Lattner     if (target == NULL)
86430fdc8d8SChris Lattner     {
8659068d794SCaroline Tice         result.AppendError ("Invalid target.  No existing target or breakpoints.");
86630fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
86730fdc8d8SChris Lattner         return false;
86830fdc8d8SChris Lattner     }
86930fdc8d8SChris Lattner 
8701b54c88cSJim Ingham     Mutex::Locker locker;
8711b54c88cSJim Ingham     target->GetBreakpointList().GetListMutex(locker);
8721b54c88cSJim Ingham 
87330fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
8741b54c88cSJim Ingham 
87530fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
87630fdc8d8SChris Lattner 
87730fdc8d8SChris Lattner     if (num_breakpoints == 0)
87830fdc8d8SChris Lattner     {
87930fdc8d8SChris Lattner         result.AppendError ("No breakpoints exist to be enabled.");
88030fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
88130fdc8d8SChris Lattner         return false;
88230fdc8d8SChris Lattner     }
88330fdc8d8SChris Lattner 
88430fdc8d8SChris Lattner     if (args.GetArgumentCount() == 0)
88530fdc8d8SChris Lattner     {
88630fdc8d8SChris Lattner         // No breakpoint selected; enable all currently set breakpoints.
88730fdc8d8SChris Lattner         target->EnableAllBreakpoints ();
88830fdc8d8SChris Lattner         result.AppendMessageWithFormat ("All breakpoints enabled. (%d breakpoints)\n", num_breakpoints);
88930fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
89030fdc8d8SChris Lattner     }
89130fdc8d8SChris Lattner     else
89230fdc8d8SChris Lattner     {
89330fdc8d8SChris Lattner         // Particular breakpoint selected; enable that breakpoint.
89430fdc8d8SChris Lattner         BreakpointIDList valid_bp_ids;
89530fdc8d8SChris Lattner         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
89630fdc8d8SChris Lattner 
89730fdc8d8SChris Lattner         if (result.Succeeded())
89830fdc8d8SChris Lattner         {
89930fdc8d8SChris Lattner             int enable_count = 0;
90030fdc8d8SChris Lattner             int loc_count = 0;
901c982c768SGreg Clayton             const size_t count = valid_bp_ids.GetSize();
902c982c768SGreg Clayton             for (size_t i = 0; i < count; ++i)
90330fdc8d8SChris Lattner             {
90430fdc8d8SChris Lattner                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
90530fdc8d8SChris Lattner 
90630fdc8d8SChris Lattner                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
90730fdc8d8SChris Lattner                 {
90830fdc8d8SChris Lattner                     Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
90930fdc8d8SChris Lattner                     if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
91030fdc8d8SChris Lattner                     {
91130fdc8d8SChris Lattner                         BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
91230fdc8d8SChris Lattner                         if (location)
91330fdc8d8SChris Lattner                         {
91430fdc8d8SChris Lattner                             location->SetEnabled (true);
91530fdc8d8SChris Lattner                             ++loc_count;
91630fdc8d8SChris Lattner                         }
91730fdc8d8SChris Lattner                     }
91830fdc8d8SChris Lattner                     else
91930fdc8d8SChris Lattner                     {
920ae1c4cf5SJim Ingham                         breakpoint->SetEnabled (true);
92130fdc8d8SChris Lattner                         ++enable_count;
92230fdc8d8SChris Lattner                     }
92330fdc8d8SChris Lattner                 }
92430fdc8d8SChris Lattner             }
92530fdc8d8SChris Lattner             result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
92630fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishNoResult);
92730fdc8d8SChris Lattner         }
92830fdc8d8SChris Lattner     }
92930fdc8d8SChris Lattner 
93030fdc8d8SChris Lattner     return result.Succeeded();
93130fdc8d8SChris Lattner }
93230fdc8d8SChris Lattner 
93330fdc8d8SChris Lattner //-------------------------------------------------------------------------
93430fdc8d8SChris Lattner // CommandObjectBreakpointDisable
93530fdc8d8SChris Lattner //-------------------------------------------------------------------------
936ae1c4cf5SJim Ingham #pragma mark Disable
93730fdc8d8SChris Lattner 
938a7015092SGreg Clayton CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
939a7015092SGreg Clayton     CommandObject (interpreter,
940e139cf23SCaroline Tice                    "breakpoint disable",
941e3d26315SCaroline Tice                    "Disable the specified breakpoint(s) without removing it/them.  If no breakpoints are specified, disable them all.",
942e139cf23SCaroline Tice                    NULL)
94330fdc8d8SChris Lattner {
944e139cf23SCaroline Tice     CommandArgumentEntry arg;
945e139cf23SCaroline Tice     CommandArgumentData bp_id_arg;
946e139cf23SCaroline Tice     CommandArgumentData bp_id_range_arg;
947e139cf23SCaroline Tice 
948e139cf23SCaroline Tice     // Create the first variant for the first (and only) argument for this command.
949e139cf23SCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
950405fe67fSCaroline Tice     bp_id_arg.arg_repetition = eArgRepeatOptional;
951e139cf23SCaroline Tice 
952e139cf23SCaroline Tice     // Create the second variant for the first (and only) argument for this command.
953e139cf23SCaroline Tice     bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
954405fe67fSCaroline Tice     bp_id_range_arg.arg_repetition = eArgRepeatOptional;
955e139cf23SCaroline Tice 
956e139cf23SCaroline Tice     // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
957e139cf23SCaroline Tice     // Push both variants into the entry for the first argument for this command.
958e139cf23SCaroline Tice     arg.push_back (bp_id_arg);
959e139cf23SCaroline Tice     arg.push_back (bp_id_range_arg);
960e139cf23SCaroline Tice 
961e139cf23SCaroline Tice     // Add the entry for the first argument for this command to the object's arguments vector.
962e139cf23SCaroline Tice     m_arguments.push_back (arg);
96330fdc8d8SChris Lattner }
96430fdc8d8SChris Lattner 
96530fdc8d8SChris Lattner CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable ()
96630fdc8d8SChris Lattner {
96730fdc8d8SChris Lattner }
96830fdc8d8SChris Lattner 
96930fdc8d8SChris Lattner bool
9706611103cSGreg Clayton CommandObjectBreakpointDisable::Execute
9716611103cSGreg Clayton (
9726611103cSGreg Clayton     Args& args,
9736611103cSGreg Clayton     CommandReturnObject &result
9746611103cSGreg Clayton )
97530fdc8d8SChris Lattner {
976a7015092SGreg Clayton     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
97730fdc8d8SChris Lattner     if (target == NULL)
97830fdc8d8SChris Lattner     {
9799068d794SCaroline Tice         result.AppendError ("Invalid target.  No existing target or breakpoints.");
98030fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
98130fdc8d8SChris Lattner         return false;
98230fdc8d8SChris Lattner     }
98330fdc8d8SChris Lattner 
9841b54c88cSJim Ingham     Mutex::Locker locker;
9851b54c88cSJim Ingham     target->GetBreakpointList().GetListMutex(locker);
9861b54c88cSJim Ingham 
98730fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
98830fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
98930fdc8d8SChris Lattner 
99030fdc8d8SChris Lattner     if (num_breakpoints == 0)
99130fdc8d8SChris Lattner     {
99230fdc8d8SChris Lattner         result.AppendError ("No breakpoints exist to be disabled.");
99330fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
99430fdc8d8SChris Lattner         return false;
99530fdc8d8SChris Lattner     }
99630fdc8d8SChris Lattner 
99730fdc8d8SChris Lattner     if (args.GetArgumentCount() == 0)
99830fdc8d8SChris Lattner     {
99930fdc8d8SChris Lattner         // No breakpoint selected; disable all currently set breakpoints.
100030fdc8d8SChris Lattner         target->DisableAllBreakpoints ();
100130fdc8d8SChris Lattner         result.AppendMessageWithFormat ("All breakpoints disabled. (%d breakpoints)\n", num_breakpoints);
100230fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
100330fdc8d8SChris Lattner     }
100430fdc8d8SChris Lattner     else
100530fdc8d8SChris Lattner     {
100630fdc8d8SChris Lattner         // Particular breakpoint selected; disable that breakpoint.
100730fdc8d8SChris Lattner         BreakpointIDList valid_bp_ids;
100830fdc8d8SChris Lattner 
100930fdc8d8SChris Lattner         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
101030fdc8d8SChris Lattner 
101130fdc8d8SChris Lattner         if (result.Succeeded())
101230fdc8d8SChris Lattner         {
101330fdc8d8SChris Lattner             int disable_count = 0;
101430fdc8d8SChris Lattner             int loc_count = 0;
1015c982c768SGreg Clayton             const size_t count = valid_bp_ids.GetSize();
1016c982c768SGreg Clayton             for (size_t i = 0; i < count; ++i)
101730fdc8d8SChris Lattner             {
101830fdc8d8SChris Lattner                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
101930fdc8d8SChris Lattner 
102030fdc8d8SChris Lattner                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
102130fdc8d8SChris Lattner                 {
102230fdc8d8SChris Lattner                     Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
102330fdc8d8SChris Lattner                     if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
102430fdc8d8SChris Lattner                     {
102530fdc8d8SChris Lattner                         BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
102630fdc8d8SChris Lattner                         if (location)
102730fdc8d8SChris Lattner                         {
102830fdc8d8SChris Lattner                             location->SetEnabled (false);
102930fdc8d8SChris Lattner                             ++loc_count;
103030fdc8d8SChris Lattner                         }
103130fdc8d8SChris Lattner                     }
103230fdc8d8SChris Lattner                     else
103330fdc8d8SChris Lattner                     {
1034ae1c4cf5SJim Ingham                         breakpoint->SetEnabled (false);
103530fdc8d8SChris Lattner                         ++disable_count;
103630fdc8d8SChris Lattner                     }
103730fdc8d8SChris Lattner                 }
103830fdc8d8SChris Lattner             }
103930fdc8d8SChris Lattner             result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
104030fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishNoResult);
104130fdc8d8SChris Lattner         }
104230fdc8d8SChris Lattner     }
104330fdc8d8SChris Lattner 
104430fdc8d8SChris Lattner     return result.Succeeded();
104530fdc8d8SChris Lattner }
104630fdc8d8SChris Lattner 
104730fdc8d8SChris Lattner //-------------------------------------------------------------------------
1048b7234e40SJohnny Chen // CommandObjectBreakpointClear::CommandOptions
1049b7234e40SJohnny Chen //-------------------------------------------------------------------------
1050b7234e40SJohnny Chen #pragma mark Clear::CommandOptions
1051b7234e40SJohnny Chen 
1052b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::CommandOptions() :
1053b7234e40SJohnny Chen     Options (),
1054b7234e40SJohnny Chen     m_filename (),
1055b7234e40SJohnny Chen     m_line_num (0)
1056b7234e40SJohnny Chen {
1057b7234e40SJohnny Chen }
1058b7234e40SJohnny Chen 
1059b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::~CommandOptions ()
1060b7234e40SJohnny Chen {
1061b7234e40SJohnny Chen }
1062b7234e40SJohnny Chen 
1063b7234e40SJohnny Chen lldb::OptionDefinition
1064b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
1065b7234e40SJohnny Chen {
1066b7234e40SJohnny Chen     { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
1067b7234e40SJohnny Chen         "Specify the breakpoint by source location in this particular file."},
1068b7234e40SJohnny Chen 
1069b7234e40SJohnny Chen     { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
1070b7234e40SJohnny Chen         "Specify the breakpoint by source location at this particular line."},
1071b7234e40SJohnny Chen 
1072b7234e40SJohnny Chen     { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1073b7234e40SJohnny Chen };
1074b7234e40SJohnny Chen 
1075b7234e40SJohnny Chen const lldb::OptionDefinition*
1076b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::GetDefinitions ()
1077b7234e40SJohnny Chen {
1078b7234e40SJohnny Chen     return g_option_table;
1079b7234e40SJohnny Chen }
1080b7234e40SJohnny Chen 
1081b7234e40SJohnny Chen Error
1082b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
1083b7234e40SJohnny Chen {
1084b7234e40SJohnny Chen     Error error;
1085b7234e40SJohnny Chen     char short_option = (char) m_getopt_table[option_idx].val;
1086b7234e40SJohnny Chen 
1087b7234e40SJohnny Chen     switch (short_option)
1088b7234e40SJohnny Chen     {
1089b7234e40SJohnny Chen         case 'f':
1090b7234e40SJohnny Chen             m_filename = option_arg;
1091b7234e40SJohnny Chen             break;
1092b7234e40SJohnny Chen 
1093b7234e40SJohnny Chen         case 'l':
1094b7234e40SJohnny Chen             m_line_num = Args::StringToUInt32 (option_arg, 0);
1095b7234e40SJohnny Chen             break;
1096b7234e40SJohnny Chen 
1097b7234e40SJohnny Chen         default:
1098b7234e40SJohnny Chen             error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1099b7234e40SJohnny Chen             break;
1100b7234e40SJohnny Chen     }
1101b7234e40SJohnny Chen 
1102b7234e40SJohnny Chen     return error;
1103b7234e40SJohnny Chen }
1104b7234e40SJohnny Chen 
1105b7234e40SJohnny Chen void
1106b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::ResetOptionValues ()
1107b7234e40SJohnny Chen {
1108b7234e40SJohnny Chen     Options::ResetOptionValues();
1109b7234e40SJohnny Chen 
1110b7234e40SJohnny Chen     m_filename.clear();
1111b7234e40SJohnny Chen     m_line_num = 0;
1112b7234e40SJohnny Chen }
1113b7234e40SJohnny Chen 
1114b7234e40SJohnny Chen //-------------------------------------------------------------------------
1115b7234e40SJohnny Chen // CommandObjectBreakpointClear
1116b7234e40SJohnny Chen //-------------------------------------------------------------------------
1117b7234e40SJohnny Chen #pragma mark Clear
1118b7234e40SJohnny Chen 
1119b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
1120b7234e40SJohnny Chen     CommandObject (interpreter,
1121b7234e40SJohnny Chen                    "breakpoint clear",
1122b7234e40SJohnny Chen                    "Clears a breakpoint or set of breakpoints in the executable.",
1123b7234e40SJohnny Chen                    "breakpoint clear <cmd-options>")
1124b7234e40SJohnny Chen {
1125b7234e40SJohnny Chen }
1126b7234e40SJohnny Chen 
1127b7234e40SJohnny Chen CommandObjectBreakpointClear::~CommandObjectBreakpointClear ()
1128b7234e40SJohnny Chen {
1129b7234e40SJohnny Chen }
1130b7234e40SJohnny Chen 
1131b7234e40SJohnny Chen Options *
1132b7234e40SJohnny Chen CommandObjectBreakpointClear::GetOptions ()
1133b7234e40SJohnny Chen {
1134b7234e40SJohnny Chen     return &m_options;
1135b7234e40SJohnny Chen }
1136b7234e40SJohnny Chen 
1137b7234e40SJohnny Chen bool
1138b7234e40SJohnny Chen CommandObjectBreakpointClear::Execute
1139b7234e40SJohnny Chen (
1140b7234e40SJohnny Chen     Args& command,
1141b7234e40SJohnny Chen     CommandReturnObject &result
1142b7234e40SJohnny Chen )
1143b7234e40SJohnny Chen {
1144b7234e40SJohnny Chen     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1145b7234e40SJohnny Chen     if (target == NULL)
1146b7234e40SJohnny Chen     {
1147b7234e40SJohnny Chen         result.AppendError ("Invalid target. No existing target or breakpoints.");
1148b7234e40SJohnny Chen         result.SetStatus (eReturnStatusFailed);
1149b7234e40SJohnny Chen         return false;
1150b7234e40SJohnny Chen     }
1151b7234e40SJohnny Chen 
1152b7234e40SJohnny Chen     // The following are the various types of breakpoints that could be cleared:
1153b7234e40SJohnny Chen     //   1). -f -l (clearing breakpoint by source location)
1154b7234e40SJohnny Chen 
1155b7234e40SJohnny Chen     BreakpointClearType break_type = eClearTypeInvalid;
1156b7234e40SJohnny Chen 
1157b7234e40SJohnny Chen     if (m_options.m_line_num != 0)
1158b7234e40SJohnny Chen         break_type = eClearTypeFileAndLine;
1159b7234e40SJohnny Chen 
1160b7234e40SJohnny Chen     Mutex::Locker locker;
1161b7234e40SJohnny Chen     target->GetBreakpointList().GetListMutex(locker);
1162b7234e40SJohnny Chen 
1163b7234e40SJohnny Chen     BreakpointList &breakpoints = target->GetBreakpointList();
1164b7234e40SJohnny Chen     size_t num_breakpoints = breakpoints.GetSize();
1165b7234e40SJohnny Chen 
1166b7234e40SJohnny Chen     // Early return if there's no breakpoint at all.
1167b7234e40SJohnny Chen     if (num_breakpoints == 0)
1168b7234e40SJohnny Chen     {
1169b7234e40SJohnny Chen         result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1170b7234e40SJohnny Chen         result.SetStatus (eReturnStatusFailed);
1171b7234e40SJohnny Chen         return result.Succeeded();
1172b7234e40SJohnny Chen     }
1173b7234e40SJohnny Chen 
1174b7234e40SJohnny Chen     // Find matching breakpoints and delete them.
1175b7234e40SJohnny Chen 
1176b7234e40SJohnny Chen     // First create a copy of all the IDs.
1177b7234e40SJohnny Chen     std::vector<break_id_t> BreakIDs;
1178b7234e40SJohnny Chen     for (size_t i = 0; i < num_breakpoints; ++i)
1179b7234e40SJohnny Chen         BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID());
1180b7234e40SJohnny Chen 
1181b7234e40SJohnny Chen     int num_cleared = 0;
1182b7234e40SJohnny Chen     StreamString ss;
1183b7234e40SJohnny Chen     switch (break_type)
1184b7234e40SJohnny Chen     {
1185b7234e40SJohnny Chen         case eClearTypeFileAndLine: // Breakpoint by source position
1186b7234e40SJohnny Chen             {
1187b7234e40SJohnny Chen                 const ConstString filename(m_options.m_filename.c_str());
1188b7234e40SJohnny Chen                 BreakpointLocationCollection loc_coll;
1189b7234e40SJohnny Chen 
1190b7234e40SJohnny Chen                 for (size_t i = 0; i < num_breakpoints; ++i)
1191b7234e40SJohnny Chen                 {
1192b7234e40SJohnny Chen                     Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
1193b7234e40SJohnny Chen 
1194b7234e40SJohnny Chen                     if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
1195b7234e40SJohnny Chen                     {
1196b7234e40SJohnny Chen                         // If the collection size is 0, it's a full match and we can just remove the breakpoint.
1197b7234e40SJohnny Chen                         if (loc_coll.GetSize() == 0)
1198b7234e40SJohnny Chen                         {
1199b7234e40SJohnny Chen                             bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
1200b7234e40SJohnny Chen                             ss.EOL();
1201b7234e40SJohnny Chen                             target->RemoveBreakpointByID (bp->GetID());
1202b7234e40SJohnny Chen                             ++num_cleared;
1203b7234e40SJohnny Chen                         }
1204b7234e40SJohnny Chen                     }
1205b7234e40SJohnny Chen                 }
1206b7234e40SJohnny Chen             }
1207b7234e40SJohnny Chen             break;
1208b7234e40SJohnny Chen 
1209b7234e40SJohnny Chen         default:
1210b7234e40SJohnny Chen             break;
1211b7234e40SJohnny Chen     }
1212b7234e40SJohnny Chen 
1213b7234e40SJohnny Chen     if (num_cleared > 0)
1214b7234e40SJohnny Chen     {
1215b7234e40SJohnny Chen         StreamString &output_stream = result.GetOutputStream();
1216b7234e40SJohnny Chen         output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
1217b7234e40SJohnny Chen         output_stream << ss.GetData();
1218b7234e40SJohnny Chen         output_stream.EOL();
1219b7234e40SJohnny Chen         result.SetStatus (eReturnStatusSuccessFinishNoResult);
1220b7234e40SJohnny Chen     }
1221b7234e40SJohnny Chen     else
1222b7234e40SJohnny Chen     {
1223b7234e40SJohnny Chen         result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1224b7234e40SJohnny Chen         result.SetStatus (eReturnStatusFailed);
1225b7234e40SJohnny Chen     }
1226b7234e40SJohnny Chen 
1227b7234e40SJohnny Chen     return result.Succeeded();
1228b7234e40SJohnny Chen }
1229b7234e40SJohnny Chen 
1230b7234e40SJohnny Chen //-------------------------------------------------------------------------
123130fdc8d8SChris Lattner // CommandObjectBreakpointDelete
123230fdc8d8SChris Lattner //-------------------------------------------------------------------------
1233ae1c4cf5SJim Ingham #pragma mark Delete
123430fdc8d8SChris Lattner 
1235a7015092SGreg Clayton CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) :
1236a7015092SGreg Clayton     CommandObject (interpreter,
1237a7015092SGreg Clayton                    "breakpoint delete",
1238e3d26315SCaroline Tice                    "Delete the specified breakpoint(s).  If no breakpoints are specified, delete them all.",
1239e139cf23SCaroline Tice                    NULL)
124030fdc8d8SChris Lattner {
1241e139cf23SCaroline Tice     CommandArgumentEntry arg;
1242e139cf23SCaroline Tice     CommandArgumentData bp_id_arg;
1243e139cf23SCaroline Tice     CommandArgumentData bp_id_range_arg;
1244e139cf23SCaroline Tice 
1245e139cf23SCaroline Tice     // Create the first variant for the first (and only) argument for this command.
1246e139cf23SCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
1247405fe67fSCaroline Tice     bp_id_arg.arg_repetition = eArgRepeatOptional;
1248e139cf23SCaroline Tice 
1249e139cf23SCaroline Tice     // Create the second variant for the first (and only) argument for this command.
1250e139cf23SCaroline Tice     bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
1251405fe67fSCaroline Tice     bp_id_range_arg.arg_repetition = eArgRepeatOptional;
1252e139cf23SCaroline Tice 
1253e139cf23SCaroline Tice     // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1254e139cf23SCaroline Tice     // Push both variants into the entry for the first argument for this command.
1255e139cf23SCaroline Tice     arg.push_back (bp_id_arg);
1256e139cf23SCaroline Tice     arg.push_back (bp_id_range_arg);
1257e139cf23SCaroline Tice 
1258e139cf23SCaroline Tice     // Add the entry for the first argument for this command to the object's arguments vector.
1259e139cf23SCaroline Tice     m_arguments.push_back (arg);
126030fdc8d8SChris Lattner }
126130fdc8d8SChris Lattner 
126230fdc8d8SChris Lattner 
126330fdc8d8SChris Lattner CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete ()
126430fdc8d8SChris Lattner {
126530fdc8d8SChris Lattner }
126630fdc8d8SChris Lattner 
126730fdc8d8SChris Lattner bool
12686611103cSGreg Clayton CommandObjectBreakpointDelete::Execute
12696611103cSGreg Clayton (
12706611103cSGreg Clayton     Args& args,
12716611103cSGreg Clayton     CommandReturnObject &result
12726611103cSGreg Clayton )
127330fdc8d8SChris Lattner {
1274a7015092SGreg Clayton     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
127530fdc8d8SChris Lattner     if (target == NULL)
127630fdc8d8SChris Lattner     {
12779068d794SCaroline Tice         result.AppendError ("Invalid target. No existing target or breakpoints.");
127830fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
127930fdc8d8SChris Lattner         return false;
128030fdc8d8SChris Lattner     }
128130fdc8d8SChris Lattner 
12821b54c88cSJim Ingham     Mutex::Locker locker;
12831b54c88cSJim Ingham     target->GetBreakpointList().GetListMutex(locker);
12841b54c88cSJim Ingham 
128530fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
12861b54c88cSJim Ingham 
128730fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
128830fdc8d8SChris Lattner 
128930fdc8d8SChris Lattner     if (num_breakpoints == 0)
129030fdc8d8SChris Lattner     {
129130fdc8d8SChris Lattner         result.AppendError ("No breakpoints exist to be deleted.");
129230fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
129330fdc8d8SChris Lattner         return false;
129430fdc8d8SChris Lattner     }
129530fdc8d8SChris Lattner 
129630fdc8d8SChris Lattner     if (args.GetArgumentCount() == 0)
129730fdc8d8SChris Lattner     {
129836f3b369SJim Ingham         if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
129930fdc8d8SChris Lattner         {
130036f3b369SJim Ingham             result.AppendMessage("Operation cancelled...");
130130fdc8d8SChris Lattner         }
130236f3b369SJim Ingham         else
130336f3b369SJim Ingham         {
130430fdc8d8SChris Lattner             target->RemoveAllBreakpoints ();
130530fdc8d8SChris Lattner             result.AppendMessageWithFormat ("All breakpoints removed. (%d breakpoints)\n", num_breakpoints);
130636f3b369SJim Ingham         }
130730fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
130830fdc8d8SChris Lattner     }
130930fdc8d8SChris Lattner     else
131030fdc8d8SChris Lattner     {
131130fdc8d8SChris Lattner         // Particular breakpoint selected; disable that breakpoint.
131230fdc8d8SChris Lattner         BreakpointIDList valid_bp_ids;
131330fdc8d8SChris Lattner         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
131430fdc8d8SChris Lattner 
131530fdc8d8SChris Lattner         if (result.Succeeded())
131630fdc8d8SChris Lattner         {
131730fdc8d8SChris Lattner             int delete_count = 0;
131830fdc8d8SChris Lattner             int disable_count = 0;
1319c982c768SGreg Clayton             const size_t count = valid_bp_ids.GetSize();
1320c982c768SGreg Clayton             for (size_t i = 0; i < count; ++i)
132130fdc8d8SChris Lattner             {
132230fdc8d8SChris Lattner                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
132330fdc8d8SChris Lattner 
132430fdc8d8SChris Lattner                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
132530fdc8d8SChris Lattner                 {
132630fdc8d8SChris Lattner                     if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
132730fdc8d8SChris Lattner                     {
132830fdc8d8SChris Lattner                         Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
132930fdc8d8SChris Lattner                         BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
133030fdc8d8SChris Lattner                         // It makes no sense to try to delete individual locations, so we disable them instead.
133130fdc8d8SChris Lattner                         if (location)
133230fdc8d8SChris Lattner                         {
133330fdc8d8SChris Lattner                             location->SetEnabled (false);
133430fdc8d8SChris Lattner                             ++disable_count;
133530fdc8d8SChris Lattner                         }
133630fdc8d8SChris Lattner                     }
133730fdc8d8SChris Lattner                     else
133830fdc8d8SChris Lattner                     {
133930fdc8d8SChris Lattner                         target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
134030fdc8d8SChris Lattner                         ++delete_count;
134130fdc8d8SChris Lattner                     }
134230fdc8d8SChris Lattner                 }
134330fdc8d8SChris Lattner             }
134430fdc8d8SChris Lattner             result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
134530fdc8d8SChris Lattner                                            delete_count, disable_count);
134630fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishNoResult);
134730fdc8d8SChris Lattner         }
134830fdc8d8SChris Lattner     }
134930fdc8d8SChris Lattner     return result.Succeeded();
135030fdc8d8SChris Lattner }
13511b54c88cSJim Ingham 
13521b54c88cSJim Ingham //-------------------------------------------------------------------------
1353ae1c4cf5SJim Ingham // CommandObjectBreakpointModify::CommandOptions
13541b54c88cSJim Ingham //-------------------------------------------------------------------------
1355ae1c4cf5SJim Ingham #pragma mark Modify::CommandOptions
13561b54c88cSJim Ingham 
1357ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::CommandOptions() :
13581b54c88cSJim Ingham     Options (),
1359c982c768SGreg Clayton     m_ignore_count (0),
13601b54c88cSJim Ingham     m_thread_id(LLDB_INVALID_THREAD_ID),
1361e0a97848SJim Ingham     m_thread_id_passed(false),
1362c982c768SGreg Clayton     m_thread_index (UINT32_MAX),
1363e0a97848SJim Ingham     m_thread_index_passed(false),
13641b54c88cSJim Ingham     m_thread_name(),
13651b54c88cSJim Ingham     m_queue_name(),
136636f3b369SJim Ingham     m_condition (),
1367c982c768SGreg Clayton     m_enable_passed (false),
1368c982c768SGreg Clayton     m_enable_value (false),
1369c982c768SGreg Clayton     m_name_passed (false),
137036f3b369SJim Ingham     m_queue_passed (false),
137136f3b369SJim Ingham     m_condition_passed (false)
13721b54c88cSJim Ingham {
13731b54c88cSJim Ingham }
13741b54c88cSJim Ingham 
1375ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::~CommandOptions ()
13761b54c88cSJim Ingham {
13771b54c88cSJim Ingham }
13781b54c88cSJim Ingham 
13791b54c88cSJim Ingham lldb::OptionDefinition
1380ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
13811b54c88cSJim Ingham {
1382deaab222SCaroline 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." },
1383deaab222SCaroline 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."},
1384deaab222SCaroline 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."},
1385deaab222SCaroline 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."},
1386deaab222SCaroline 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."},
138736f3b369SJim Ingham { LLDB_OPT_SET_ALL, false, "condition",    'c', required_argument, NULL, NULL, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."},
1388deaab222SCaroline Tice { LLDB_OPT_SET_1,   false, "enable",       'e', no_argument,       NULL, NULL, eArgTypeNone, "Enable the breakpoint."},
1389deaab222SCaroline Tice { LLDB_OPT_SET_2,   false, "disable",      'd', no_argument,       NULL, NULL, eArgTypeNone, "Disable the breakpoint."},
1390deaab222SCaroline Tice { 0,                false, NULL,            0 , 0,                 NULL, 0,    eArgTypeNone, NULL }
13911b54c88cSJim Ingham };
13921b54c88cSJim Ingham 
13931b54c88cSJim Ingham const lldb::OptionDefinition*
1394ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::GetDefinitions ()
13951b54c88cSJim Ingham {
13961b54c88cSJim Ingham     return g_option_table;
13971b54c88cSJim Ingham }
13981b54c88cSJim Ingham 
13991b54c88cSJim Ingham Error
1400ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
14011b54c88cSJim Ingham {
14021b54c88cSJim Ingham     Error error;
14031b54c88cSJim Ingham     char short_option = (char) m_getopt_table[option_idx].val;
14041b54c88cSJim Ingham 
14051b54c88cSJim Ingham     switch (short_option)
14061b54c88cSJim Ingham     {
140736f3b369SJim Ingham         case 'c':
140836f3b369SJim Ingham             if (option_arg != NULL)
140936f3b369SJim Ingham                 m_condition = option_arg;
141036f3b369SJim Ingham             else
141136f3b369SJim Ingham                 m_condition.clear();
141236f3b369SJim Ingham             m_condition_passed = true;
141336f3b369SJim Ingham             break;
1414ae1c4cf5SJim Ingham         case 'd':
1415ae1c4cf5SJim Ingham             m_enable_passed = true;
1416ae1c4cf5SJim Ingham             m_enable_value = false;
1417ae1c4cf5SJim Ingham             break;
1418ae1c4cf5SJim Ingham         case 'e':
1419ae1c4cf5SJim Ingham             m_enable_passed = true;
1420ae1c4cf5SJim Ingham             m_enable_value = true;
1421ae1c4cf5SJim Ingham             break;
1422ed8a705cSGreg Clayton         case 'i':
14231b54c88cSJim Ingham         {
1424c982c768SGreg Clayton             m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0);
1425c982c768SGreg Clayton             if (m_ignore_count == UINT32_MAX)
14261b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg);
14271b54c88cSJim Ingham         }
1428ae1c4cf5SJim Ingham         break;
14291b54c88cSJim Ingham         case 't' :
14301b54c88cSJim Ingham         {
1431e0a97848SJim Ingham             if (optarg[0] == '\0')
1432e0a97848SJim Ingham             {
1433e0a97848SJim Ingham                 m_thread_id = LLDB_INVALID_THREAD_ID;
1434e0a97848SJim Ingham                 m_thread_id_passed = true;
1435e0a97848SJim Ingham             }
1436e0a97848SJim Ingham             else
1437e0a97848SJim Ingham             {
14381b54c88cSJim Ingham                 m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0);
14391b54c88cSJim Ingham                 if (m_thread_id == LLDB_INVALID_THREAD_ID)
14401b54c88cSJim Ingham                    error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg);
1441e0a97848SJim Ingham                 else
1442e0a97848SJim Ingham                     m_thread_id_passed = true;
1443e0a97848SJim Ingham             }
14441b54c88cSJim Ingham         }
14451b54c88cSJim Ingham         break;
14461b54c88cSJim Ingham         case 'T':
1447b2a38a72SJim Ingham             if (option_arg != NULL)
14481b54c88cSJim Ingham                 m_thread_name = option_arg;
1449b2a38a72SJim Ingham             else
1450b2a38a72SJim Ingham                 m_thread_name.clear();
1451b2a38a72SJim Ingham             m_name_passed = true;
14521b54c88cSJim Ingham             break;
14531b54c88cSJim Ingham         case 'q':
1454b2a38a72SJim Ingham             if (option_arg != NULL)
14551b54c88cSJim Ingham                 m_queue_name = option_arg;
1456b2a38a72SJim Ingham             else
1457b2a38a72SJim Ingham                 m_queue_name.clear();
1458b2a38a72SJim Ingham             m_queue_passed = true;
14591b54c88cSJim Ingham             break;
14601b54c88cSJim Ingham         case 'x':
14611b54c88cSJim Ingham         {
1462e0a97848SJim Ingham             if (optarg[0] == '\n')
1463e0a97848SJim Ingham             {
1464e0a97848SJim Ingham                 m_thread_index = UINT32_MAX;
1465e0a97848SJim Ingham                 m_thread_index_passed = true;
1466e0a97848SJim Ingham             }
1467e0a97848SJim Ingham             else
1468e0a97848SJim Ingham             {
1469c982c768SGreg Clayton                 m_thread_index = Args::StringToUInt32 (optarg, UINT32_MAX, 0);
1470c982c768SGreg Clayton                 if (m_thread_id == UINT32_MAX)
14711b54c88cSJim Ingham                    error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg);
1472e0a97848SJim Ingham                 else
1473e0a97848SJim Ingham                     m_thread_index_passed = true;
1474e0a97848SJim Ingham             }
14751b54c88cSJim Ingham         }
14761b54c88cSJim Ingham         break;
14771b54c88cSJim Ingham         default:
14781b54c88cSJim Ingham             error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
14791b54c88cSJim Ingham             break;
14801b54c88cSJim Ingham     }
14811b54c88cSJim Ingham 
14821b54c88cSJim Ingham     return error;
14831b54c88cSJim Ingham }
14841b54c88cSJim Ingham 
14851b54c88cSJim Ingham void
1486ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::ResetOptionValues ()
14871b54c88cSJim Ingham {
14881b54c88cSJim Ingham     Options::ResetOptionValues();
14891b54c88cSJim Ingham 
1490c982c768SGreg Clayton     m_ignore_count = 0;
14911b54c88cSJim Ingham     m_thread_id = LLDB_INVALID_THREAD_ID;
1492e0a97848SJim Ingham     m_thread_id_passed = false;
1493c982c768SGreg Clayton     m_thread_index = UINT32_MAX;
1494e0a97848SJim Ingham     m_thread_index_passed = false;
14951b54c88cSJim Ingham     m_thread_name.clear();
14961b54c88cSJim Ingham     m_queue_name.clear();
149736f3b369SJim Ingham     m_condition.clear();
1498ae1c4cf5SJim Ingham     m_enable_passed = false;
1499b2a38a72SJim Ingham     m_queue_passed = false;
1500b2a38a72SJim Ingham     m_name_passed = false;
150136f3b369SJim Ingham     m_condition_passed = false;
15021b54c88cSJim Ingham }
15031b54c88cSJim Ingham 
15041b54c88cSJim Ingham //-------------------------------------------------------------------------
1505ae1c4cf5SJim Ingham // CommandObjectBreakpointModify
15061b54c88cSJim Ingham //-------------------------------------------------------------------------
1507ae1c4cf5SJim Ingham #pragma mark Modify
15081b54c88cSJim Ingham 
1509a7015092SGreg Clayton CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
1510a7015092SGreg Clayton     CommandObject (interpreter,
1511a7015092SGreg Clayton                    "breakpoint modify",
1512a571c010SJim Ingham                    "Modify the options on a breakpoint or set of breakpoints in the executable.  "
1513e0a97848SJim Ingham                    "If no breakpoint is specified, acts on the last created breakpoint.  "
1514e0a97848SJim Ingham                    "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
1515e139cf23SCaroline Tice                    NULL)
15161b54c88cSJim Ingham {
1517e139cf23SCaroline Tice     CommandArgumentEntry arg;
1518e139cf23SCaroline Tice     CommandArgumentData bp_id_arg;
1519e139cf23SCaroline Tice     CommandArgumentData bp_id_range_arg;
1520e139cf23SCaroline Tice 
1521e139cf23SCaroline Tice     // Create the first variant for the first (and only) argument for this command.
1522e139cf23SCaroline Tice     bp_id_arg.arg_type = eArgTypeBreakpointID;
1523405fe67fSCaroline Tice     bp_id_arg.arg_repetition = eArgRepeatPlain;
1524e139cf23SCaroline Tice 
1525e139cf23SCaroline Tice     // Create the second variant for the first (and only) argument for this command.
1526e139cf23SCaroline Tice     bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
1527405fe67fSCaroline Tice     bp_id_range_arg.arg_repetition = eArgRepeatPlain;
1528e139cf23SCaroline Tice 
1529e139cf23SCaroline Tice     // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1530e139cf23SCaroline Tice     // Push both variants into the entry for the first argument for this command.
1531e139cf23SCaroline Tice     arg.push_back (bp_id_arg);
1532e139cf23SCaroline Tice     arg.push_back (bp_id_range_arg);
1533e139cf23SCaroline Tice 
1534e139cf23SCaroline Tice     // Add the entry for the first argument for this command to the object's arguments vector.
1535e139cf23SCaroline Tice     m_arguments.push_back (arg);
15361b54c88cSJim Ingham }
15371b54c88cSJim Ingham 
1538ae1c4cf5SJim Ingham CommandObjectBreakpointModify::~CommandObjectBreakpointModify ()
15391b54c88cSJim Ingham {
15401b54c88cSJim Ingham }
15411b54c88cSJim Ingham 
15421b54c88cSJim Ingham Options *
1543ae1c4cf5SJim Ingham CommandObjectBreakpointModify::GetOptions ()
15441b54c88cSJim Ingham {
15451b54c88cSJim Ingham     return &m_options;
15461b54c88cSJim Ingham }
15471b54c88cSJim Ingham 
15481b54c88cSJim Ingham bool
1549ae1c4cf5SJim Ingham CommandObjectBreakpointModify::Execute
15501b54c88cSJim Ingham (
15511b54c88cSJim Ingham     Args& command,
15521b54c88cSJim Ingham     CommandReturnObject &result
15531b54c88cSJim Ingham )
15541b54c88cSJim Ingham {
1555a7015092SGreg Clayton     Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
15561b54c88cSJim Ingham     if (target == NULL)
15571b54c88cSJim Ingham     {
15589068d794SCaroline Tice         result.AppendError ("Invalid target.  No existing target or breakpoints.");
15591b54c88cSJim Ingham         result.SetStatus (eReturnStatusFailed);
15601b54c88cSJim Ingham         return false;
15611b54c88cSJim Ingham     }
15621b54c88cSJim Ingham 
15631b54c88cSJim Ingham     Mutex::Locker locker;
15641b54c88cSJim Ingham     target->GetBreakpointList().GetListMutex(locker);
15651b54c88cSJim Ingham 
15661b54c88cSJim Ingham     BreakpointIDList valid_bp_ids;
15671b54c88cSJim Ingham 
15681b54c88cSJim Ingham     CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
15691b54c88cSJim Ingham 
15701b54c88cSJim Ingham     if (result.Succeeded())
15711b54c88cSJim Ingham     {
1572c982c768SGreg Clayton         const size_t count = valid_bp_ids.GetSize();
1573c982c768SGreg Clayton         for (size_t i = 0; i < count; ++i)
15741b54c88cSJim Ingham         {
15751b54c88cSJim Ingham             BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
15761b54c88cSJim Ingham 
15771b54c88cSJim Ingham             if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
15781b54c88cSJim Ingham             {
15791b54c88cSJim Ingham                 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
15801b54c88cSJim Ingham                 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
15811b54c88cSJim Ingham                 {
15821b54c88cSJim Ingham                     BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
15831b54c88cSJim Ingham                     if (location)
15841b54c88cSJim Ingham                     {
1585e0a97848SJim Ingham                         if (m_options.m_thread_id_passed)
15861b54c88cSJim Ingham                             location->SetThreadID (m_options.m_thread_id);
15871b54c88cSJim Ingham 
1588e0a97848SJim Ingham                         if (m_options.m_thread_index_passed)
15891b54c88cSJim Ingham                             location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
15901b54c88cSJim Ingham 
1591b2a38a72SJim Ingham                         if (m_options.m_name_passed)
15921b54c88cSJim Ingham                             location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
15931b54c88cSJim Ingham 
1594b2a38a72SJim Ingham                         if (m_options.m_queue_passed)
15951b54c88cSJim Ingham                             location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
15961b54c88cSJim Ingham 
1597c982c768SGreg Clayton                         if (m_options.m_ignore_count != 0)
15981b54c88cSJim Ingham                             location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count);
1599ae1c4cf5SJim Ingham 
1600ae1c4cf5SJim Ingham                         if (m_options.m_enable_passed)
1601ae1c4cf5SJim Ingham                             location->SetEnabled (m_options.m_enable_value);
160236f3b369SJim Ingham 
160336f3b369SJim Ingham                         if (m_options.m_condition_passed)
160436f3b369SJim Ingham                             location->SetCondition (m_options.m_condition.c_str());
16051b54c88cSJim Ingham                     }
16061b54c88cSJim Ingham                 }
16071b54c88cSJim Ingham                 else
16081b54c88cSJim Ingham                 {
1609e0a97848SJim Ingham                     if (m_options.m_thread_id_passed)
16101b54c88cSJim Ingham                         bp->SetThreadID (m_options.m_thread_id);
16111b54c88cSJim Ingham 
1612e0a97848SJim Ingham                     if (m_options.m_thread_index_passed)
16131b54c88cSJim Ingham                         bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
16141b54c88cSJim Ingham 
1615b2a38a72SJim Ingham                     if (m_options.m_name_passed)
16161b54c88cSJim Ingham                         bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
16171b54c88cSJim Ingham 
1618b2a38a72SJim Ingham                     if (m_options.m_queue_passed)
16191b54c88cSJim Ingham                         bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
16201b54c88cSJim Ingham 
1621c982c768SGreg Clayton                     if (m_options.m_ignore_count != 0)
16221b54c88cSJim Ingham                         bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
1623ae1c4cf5SJim Ingham 
1624ae1c4cf5SJim Ingham                     if (m_options.m_enable_passed)
1625ae1c4cf5SJim Ingham                         bp->SetEnabled (m_options.m_enable_value);
1626ae1c4cf5SJim Ingham 
162736f3b369SJim Ingham                     if (m_options.m_condition_passed)
162836f3b369SJim Ingham                         bp->SetCondition (m_options.m_condition.c_str());
16291b54c88cSJim Ingham                 }
16301b54c88cSJim Ingham             }
16311b54c88cSJim Ingham         }
16321b54c88cSJim Ingham     }
16331b54c88cSJim Ingham 
16341b54c88cSJim Ingham     return result.Succeeded();
16351b54c88cSJim Ingham }
16361b54c88cSJim Ingham 
16371b54c88cSJim Ingham 
1638