130fdc8d8SChris Lattner //===-- CommandObjectBreakpoint.cpp -----------------------------*- C++ -*-===//
230fdc8d8SChris Lattner //
330fdc8d8SChris Lattner //                     The LLVM Compiler Infrastructure
430fdc8d8SChris Lattner //
530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source
630fdc8d8SChris Lattner // License. See LICENSE.TXT for details.
730fdc8d8SChris Lattner //
830fdc8d8SChris Lattner //===----------------------------------------------------------------------===//
930fdc8d8SChris Lattner 
1030fdc8d8SChris Lattner #include "CommandObjectBreakpoint.h"
1130fdc8d8SChris Lattner #include "CommandObjectBreakpointCommand.h"
1230fdc8d8SChris Lattner 
1330fdc8d8SChris Lattner // C Includes
1430fdc8d8SChris Lattner // C++ Includes
1530fdc8d8SChris Lattner // Other libraries and framework includes
1630fdc8d8SChris Lattner // Project includes
1730fdc8d8SChris Lattner #include "lldb/Breakpoint/Breakpoint.h"
1830fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointIDList.h"
1930fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointLocation.h"
2040af72e1SJim Ingham #include "lldb/Interpreter/Options.h"
2130fdc8d8SChris Lattner #include "lldb/Core/RegularExpression.h"
2230fdc8d8SChris Lattner #include "lldb/Core/StreamString.h"
2330fdc8d8SChris Lattner #include "lldb/Interpreter/CommandInterpreter.h"
2430fdc8d8SChris Lattner #include "lldb/Interpreter/CommandReturnObject.h"
2530fdc8d8SChris Lattner #include "lldb/Target/Target.h"
2630fdc8d8SChris Lattner #include "lldb/Interpreter/CommandCompletions.h"
2730fdc8d8SChris Lattner #include "lldb/Target/StackFrame.h"
281b54c88cSJim Ingham #include "lldb/Target/Thread.h"
291b54c88cSJim Ingham #include "lldb/Target/ThreadSpec.h"
3030fdc8d8SChris Lattner 
3130fdc8d8SChris Lattner using namespace lldb;
3230fdc8d8SChris Lattner using namespace lldb_private;
3330fdc8d8SChris Lattner 
3430fdc8d8SChris Lattner static void
35*6611103cSGreg Clayton AddBreakpointDescription (StreamString *s, Breakpoint *bp, lldb::DescriptionLevel level)
3630fdc8d8SChris Lattner {
3730fdc8d8SChris Lattner     s->IndentMore();
3830fdc8d8SChris Lattner     bp->GetDescription (s, level, true);
3930fdc8d8SChris Lattner     s->IndentLess();
4030fdc8d8SChris Lattner     s->EOL();
4130fdc8d8SChris Lattner }
4230fdc8d8SChris Lattner 
4330fdc8d8SChris Lattner //-------------------------------------------------------------------------
4430fdc8d8SChris Lattner // CommandObjectBreakpointSet::CommandOptions
4530fdc8d8SChris Lattner //-------------------------------------------------------------------------
46ae1c4cf5SJim Ingham #pragma mark Set::CommandOptions
4730fdc8d8SChris Lattner 
4830fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::CommandOptions() :
4930fdc8d8SChris Lattner     Options (),
5030fdc8d8SChris Lattner     m_filename (),
5130fdc8d8SChris Lattner     m_line_num (0),
5230fdc8d8SChris Lattner     m_column (0),
5330fdc8d8SChris Lattner     m_ignore_inlines (false),
5430fdc8d8SChris Lattner     m_func_name (),
5530fdc8d8SChris Lattner     m_func_regexp (),
5630fdc8d8SChris Lattner     m_modules (),
571b54c88cSJim Ingham     m_load_addr(),
581b54c88cSJim Ingham     m_thread_id(LLDB_INVALID_THREAD_ID),
591b54c88cSJim Ingham     m_thread_index (-1),
601b54c88cSJim Ingham     m_thread_name(),
611b54c88cSJim Ingham     m_queue_name(),
621b54c88cSJim Ingham     m_ignore_count (-1)
6330fdc8d8SChris Lattner {
6430fdc8d8SChris Lattner }
6530fdc8d8SChris Lattner 
6630fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::~CommandOptions ()
6730fdc8d8SChris Lattner {
6830fdc8d8SChris Lattner }
6930fdc8d8SChris Lattner 
7030fdc8d8SChris Lattner lldb::OptionDefinition
7130fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
7230fdc8d8SChris Lattner {
738651121cSJim Ingham     { LLDB_OPT_SET_ALL, false, "shlib",       's', required_argument, NULL, CommandCompletions::eModuleCompletion, "<shlib-name>",
748651121cSJim Ingham         "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."},
758651121cSJim Ingham 
768651121cSJim Ingham     { LLDB_OPT_SET_ALL, false, "ignore_inlines", 'i', no_argument,   NULL, 0, NULL,
778651121cSJim Ingham         "Ignore inlined subroutines when setting the breakppoint." },
788651121cSJim Ingham 
791b54c88cSJim Ingham     { LLDB_OPT_SET_ALL, false, "ignore_count", 'k', required_argument,   NULL, 0, NULL,
801b54c88cSJim Ingham         "Set the number of times this breakpoint is sKipped before stopping." },
811b54c88cSJim Ingham 
821b54c88cSJim Ingham     { LLDB_OPT_SET_ALL, false, "thread_index",       'x', required_argument, NULL, NULL, "<thread_index>",
831b54c88cSJim Ingham         "The breakpoint stops only for the thread whose indeX matches this argument."},
841b54c88cSJim Ingham 
851b54c88cSJim Ingham     { LLDB_OPT_SET_ALL, false, "thread_id",       't', required_argument, NULL, NULL, "<thread_id>",
861b54c88cSJim Ingham         "The breakpoint stops only for the thread whose TID matches this argument."},
871b54c88cSJim Ingham 
881b54c88cSJim Ingham     { LLDB_OPT_SET_ALL, false, "thread_name",       'T', required_argument, NULL, NULL, "<thread_name>",
891b54c88cSJim Ingham         "The breakpoint stops only for the thread whose thread name matches this argument."},
901b54c88cSJim Ingham 
911b54c88cSJim Ingham     { LLDB_OPT_SET_ALL, false, "queue_name",       'q', required_argument, NULL, NULL, "<queue_name>",
921b54c88cSJim Ingham         "The breakpoint stops only for threads in the queue whose name is given by this argument."},
931b54c88cSJim Ingham 
948651121cSJim Ingham     { LLDB_OPT_SET_1, false, "file",       'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, "<filename>",
9530fdc8d8SChris Lattner         "Set the breakpoint by source location in this particular file."},
9630fdc8d8SChris Lattner 
978651121cSJim Ingham     { LLDB_OPT_SET_1, true, "line",       'l', required_argument, NULL, 0, "<linenum>",
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 
1058651121cSJim Ingham     { LLDB_OPT_SET_2, true, "address",    'a', required_argument, NULL, 0, "<address>",
10630fdc8d8SChris Lattner         "Set the breakpoint by address, at the specified address."},
10730fdc8d8SChris Lattner 
1088651121cSJim Ingham     { LLDB_OPT_SET_3, true, "name",       'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, "<function-name>",
10930fdc8d8SChris Lattner         "Set the breakpoint by function name." },
11030fdc8d8SChris Lattner 
1118651121cSJim Ingham     { LLDB_OPT_SET_4, true, "func_regex", 'r', required_argument, NULL, 0, "<regular-expression>",
11230fdc8d8SChris Lattner         "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
11330fdc8d8SChris Lattner 
11430fdc8d8SChris Lattner     { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL }
11530fdc8d8SChris Lattner };
11630fdc8d8SChris Lattner 
11730fdc8d8SChris Lattner const lldb::OptionDefinition*
11830fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::GetDefinitions ()
11930fdc8d8SChris Lattner {
12030fdc8d8SChris Lattner     return g_option_table;
12130fdc8d8SChris Lattner }
12230fdc8d8SChris Lattner 
12330fdc8d8SChris Lattner Error
12430fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
12530fdc8d8SChris Lattner {
12630fdc8d8SChris Lattner     Error error;
12730fdc8d8SChris Lattner     char short_option = (char) m_getopt_table[option_idx].val;
12830fdc8d8SChris Lattner 
12930fdc8d8SChris Lattner     switch (short_option)
13030fdc8d8SChris Lattner     {
13130fdc8d8SChris Lattner         case 'a':
13230fdc8d8SChris Lattner             m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 0);
13330fdc8d8SChris Lattner             if (m_load_addr == LLDB_INVALID_ADDRESS)
13430fdc8d8SChris Lattner                 m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 16);
13530fdc8d8SChris Lattner 
13630fdc8d8SChris Lattner             if (m_load_addr == LLDB_INVALID_ADDRESS)
13730fdc8d8SChris Lattner                 error.SetErrorStringWithFormat ("Invalid address string '%s'.\n", optarg);
13830fdc8d8SChris Lattner             break;
13930fdc8d8SChris Lattner 
14030fdc8d8SChris Lattner         case 'c':
14130fdc8d8SChris Lattner             m_column = Args::StringToUInt32 (option_arg, 0);
14230fdc8d8SChris Lattner             break;
14330fdc8d8SChris Lattner         case 'f':
14430fdc8d8SChris Lattner             m_filename = option_arg;
14530fdc8d8SChris Lattner             break;
14630fdc8d8SChris Lattner         case 'i':
14730fdc8d8SChris Lattner             m_ignore_inlines = true;
14830fdc8d8SChris Lattner             break;
14930fdc8d8SChris Lattner         case 'l':
15030fdc8d8SChris Lattner             m_line_num = Args::StringToUInt32 (option_arg, 0);
15130fdc8d8SChris Lattner             break;
15230fdc8d8SChris Lattner         case 'n':
15330fdc8d8SChris Lattner             m_func_name = option_arg;
15430fdc8d8SChris Lattner             break;
15530fdc8d8SChris Lattner         case 'r':
15630fdc8d8SChris Lattner             m_func_regexp = option_arg;
15730fdc8d8SChris Lattner             break;
15830fdc8d8SChris Lattner         case 's':
15930fdc8d8SChris Lattner             {
16030fdc8d8SChris Lattner                 m_modules.push_back (std::string (option_arg));
16130fdc8d8SChris Lattner                 break;
16230fdc8d8SChris Lattner             }
1631b54c88cSJim Ingham         case 'k':
1641b54c88cSJim Ingham         {
1651b54c88cSJim Ingham             m_ignore_count = Args::StringToSInt32(optarg, -1, 0);
1661b54c88cSJim Ingham             if (m_ignore_count == -1)
1671b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg);
1681b54c88cSJim Ingham         }
169ae1c4cf5SJim Ingham         break;
1701b54c88cSJim Ingham         case 't' :
1711b54c88cSJim Ingham         {
1721b54c88cSJim Ingham             m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0);
1731b54c88cSJim Ingham             if (m_thread_id == LLDB_INVALID_THREAD_ID)
1741b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg);
1751b54c88cSJim Ingham         }
1761b54c88cSJim Ingham         break;
1771b54c88cSJim Ingham         case 'T':
1781b54c88cSJim Ingham             m_thread_name = option_arg;
1791b54c88cSJim Ingham             break;
1801b54c88cSJim Ingham         case 'q':
1811b54c88cSJim Ingham             m_queue_name = option_arg;
1821b54c88cSJim Ingham             break;
1831b54c88cSJim Ingham         case 'x':
1841b54c88cSJim Ingham         {
1851b54c88cSJim Ingham             m_thread_index = Args::StringToUInt64(optarg, -1, 0);
1861b54c88cSJim Ingham             if (m_thread_id == -1)
1871b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg);
1881b54c88cSJim Ingham 
1891b54c88cSJim Ingham         }
1901b54c88cSJim Ingham         break;
19130fdc8d8SChris Lattner         default:
19230fdc8d8SChris Lattner             error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
19330fdc8d8SChris Lattner             break;
19430fdc8d8SChris Lattner     }
19530fdc8d8SChris Lattner 
19630fdc8d8SChris Lattner     return error;
19730fdc8d8SChris Lattner }
19830fdc8d8SChris Lattner 
19930fdc8d8SChris Lattner void
20030fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::ResetOptionValues ()
20130fdc8d8SChris Lattner {
20230fdc8d8SChris Lattner     Options::ResetOptionValues();
20330fdc8d8SChris Lattner 
20430fdc8d8SChris Lattner     m_filename.clear();
20530fdc8d8SChris Lattner     m_line_num = 0;
20630fdc8d8SChris Lattner     m_column = 0;
20730fdc8d8SChris Lattner     m_ignore_inlines = false;
20830fdc8d8SChris Lattner     m_func_name.clear();
20930fdc8d8SChris Lattner     m_func_regexp.clear();
21030fdc8d8SChris Lattner     m_load_addr = LLDB_INVALID_ADDRESS;
21130fdc8d8SChris Lattner     m_modules.clear();
2121b54c88cSJim Ingham     m_ignore_count = -1;
2131b54c88cSJim Ingham     m_thread_id = LLDB_INVALID_THREAD_ID;
2141b54c88cSJim Ingham     m_thread_index = -1;
2151b54c88cSJim Ingham     m_thread_name.clear();
2161b54c88cSJim Ingham     m_queue_name.clear();
21730fdc8d8SChris Lattner }
21830fdc8d8SChris Lattner 
21930fdc8d8SChris Lattner //-------------------------------------------------------------------------
22030fdc8d8SChris Lattner // CommandObjectBreakpointSet
22130fdc8d8SChris Lattner //-------------------------------------------------------------------------
222ae1c4cf5SJim Ingham #pragma mark Set
22330fdc8d8SChris Lattner 
22430fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandObjectBreakpointSet () :
22530fdc8d8SChris Lattner     CommandObject ("breakpoint set", "Sets a breakpoint or set of breakpoints in the executable.",
22630fdc8d8SChris Lattner                    "breakpoint set <cmd-options>")
22730fdc8d8SChris Lattner {
22830fdc8d8SChris Lattner }
22930fdc8d8SChris Lattner 
23030fdc8d8SChris Lattner CommandObjectBreakpointSet::~CommandObjectBreakpointSet ()
23130fdc8d8SChris Lattner {
23230fdc8d8SChris Lattner }
23330fdc8d8SChris Lattner 
23430fdc8d8SChris Lattner Options *
23530fdc8d8SChris Lattner CommandObjectBreakpointSet::GetOptions ()
23630fdc8d8SChris Lattner {
23730fdc8d8SChris Lattner     return &m_options;
23830fdc8d8SChris Lattner }
23930fdc8d8SChris Lattner 
24030fdc8d8SChris Lattner bool
24130fdc8d8SChris Lattner CommandObjectBreakpointSet::Execute
24230fdc8d8SChris Lattner (
243*6611103cSGreg Clayton     CommandInterpreter &interpreter,
24430fdc8d8SChris Lattner     Args& command,
24530fdc8d8SChris Lattner     CommandReturnObject &result
24630fdc8d8SChris Lattner )
24730fdc8d8SChris Lattner {
248*6611103cSGreg Clayton     Target *target = interpreter.GetDebugger().GetCurrentTarget().get();
24930fdc8d8SChris Lattner     if (target == NULL)
25030fdc8d8SChris Lattner     {
25130fdc8d8SChris Lattner         result.AppendError ("Invalid target, set executable file using 'file' command.");
25230fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
25330fdc8d8SChris Lattner         return false;
25430fdc8d8SChris Lattner     }
25530fdc8d8SChris Lattner 
25630fdc8d8SChris Lattner     // The following are the various types of breakpoints that could be set:
25730fdc8d8SChris Lattner     //   1).  -f -l -p  [-s -g]   (setting breakpoint by source location)
25830fdc8d8SChris Lattner     //   2).  -a  [-s -g]         (setting breakpoint by address)
25930fdc8d8SChris Lattner     //   3).  -n  [-s -g]         (setting breakpoint by function name)
26030fdc8d8SChris Lattner     //   4).  -r  [-s -g]         (setting breakpoint by function name regular expression)
26130fdc8d8SChris Lattner 
26230fdc8d8SChris Lattner     BreakpointSetType break_type = eSetTypeInvalid;
26330fdc8d8SChris Lattner 
26430fdc8d8SChris Lattner     if (m_options.m_line_num != 0)
26530fdc8d8SChris Lattner         break_type = eSetTypeFileAndLine;
26630fdc8d8SChris Lattner     else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
26730fdc8d8SChris Lattner         break_type = eSetTypeAddress;
26830fdc8d8SChris Lattner     else if (!m_options.m_func_name.empty())
26930fdc8d8SChris Lattner         break_type = eSetTypeFunctionName;
27030fdc8d8SChris Lattner     else if  (!m_options.m_func_regexp.empty())
27130fdc8d8SChris Lattner         break_type = eSetTypeFunctionRegexp;
27230fdc8d8SChris Lattner 
27330fdc8d8SChris Lattner     ModuleSP module_sp = target->GetExecutableModule();
27430fdc8d8SChris Lattner     Breakpoint *bp = NULL;
27530fdc8d8SChris Lattner     FileSpec module;
27630fdc8d8SChris Lattner     bool use_module = false;
27730fdc8d8SChris Lattner     int num_modules = m_options.m_modules.size();
27830fdc8d8SChris Lattner 
27930fdc8d8SChris Lattner     if ((num_modules > 0) && (break_type != eSetTypeAddress))
28030fdc8d8SChris Lattner         use_module = true;
28130fdc8d8SChris Lattner 
28230fdc8d8SChris Lattner     switch (break_type)
28330fdc8d8SChris Lattner     {
28430fdc8d8SChris Lattner         case eSetTypeFileAndLine: // Breakpoint by source position
28530fdc8d8SChris Lattner         {
28630fdc8d8SChris Lattner             FileSpec file;
28730fdc8d8SChris Lattner             if (m_options.m_filename.empty())
28830fdc8d8SChris Lattner             {
289*6611103cSGreg Clayton                 StackFrame *cur_frame = interpreter.GetDebugger().GetExecutionContext().frame;
29030fdc8d8SChris Lattner                 if (cur_frame == NULL)
29130fdc8d8SChris Lattner                 {
29230fdc8d8SChris Lattner                     result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame.");
29330fdc8d8SChris Lattner                     result.SetStatus (eReturnStatusFailed);
29430fdc8d8SChris Lattner                     break;
29530fdc8d8SChris Lattner                 }
29630fdc8d8SChris Lattner                 else if (!cur_frame->HasDebugInformation())
29730fdc8d8SChris Lattner                 {
29830fdc8d8SChris Lattner                     result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info.");
29930fdc8d8SChris Lattner                     result.SetStatus (eReturnStatusFailed);
30030fdc8d8SChris Lattner                     break;
30130fdc8d8SChris Lattner                 }
30230fdc8d8SChris Lattner                 else
30330fdc8d8SChris Lattner                 {
30430fdc8d8SChris Lattner                     const SymbolContext &context = cur_frame->GetSymbolContext(true);
30530fdc8d8SChris Lattner                     if (context.line_entry.file)
30630fdc8d8SChris Lattner                     {
30730fdc8d8SChris Lattner                         file = context.line_entry.file;
30830fdc8d8SChris Lattner                     }
30930fdc8d8SChris Lattner                     else if (context.comp_unit != NULL)
31030fdc8d8SChris Lattner                     {    file = context.comp_unit;
31130fdc8d8SChris Lattner                     }
31230fdc8d8SChris Lattner                     else
31330fdc8d8SChris Lattner                     {
31430fdc8d8SChris Lattner                         result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame.");
31530fdc8d8SChris Lattner                         result.SetStatus (eReturnStatusFailed);
31630fdc8d8SChris Lattner                         break;
31730fdc8d8SChris Lattner                     }
31830fdc8d8SChris Lattner                 }
31930fdc8d8SChris Lattner             }
32030fdc8d8SChris Lattner             else
32130fdc8d8SChris Lattner             {
32230fdc8d8SChris Lattner                 file.SetFile(m_options.m_filename.c_str());
32330fdc8d8SChris Lattner             }
32430fdc8d8SChris Lattner 
32530fdc8d8SChris Lattner             if (use_module)
32630fdc8d8SChris Lattner             {
32730fdc8d8SChris Lattner                 for (int i = 0; i < num_modules; ++i)
32830fdc8d8SChris Lattner                 {
32930fdc8d8SChris Lattner                     module.SetFile(m_options.m_modules[i].c_str());
33030fdc8d8SChris Lattner                     bp = target->CreateBreakpoint (&module,
33130fdc8d8SChris Lattner                                                    file,
33230fdc8d8SChris Lattner                                                    m_options.m_line_num,
33330fdc8d8SChris Lattner                                                    m_options.m_ignore_inlines).get();
33430fdc8d8SChris Lattner                     if (bp)
33530fdc8d8SChris Lattner                     {
33630fdc8d8SChris Lattner                         StreamString &output_stream = result.GetOutputStream();
33730fdc8d8SChris Lattner                         output_stream.Printf ("Breakpoint created: ");
33830fdc8d8SChris Lattner                         bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
33930fdc8d8SChris Lattner                         output_stream.EOL();
34030fdc8d8SChris Lattner                         result.SetStatus (eReturnStatusSuccessFinishResult);
34130fdc8d8SChris Lattner                     }
34230fdc8d8SChris Lattner                     else
34330fdc8d8SChris Lattner                     {
34430fdc8d8SChris Lattner                         result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
34530fdc8d8SChris Lattner                                                     m_options.m_modules[i].c_str());
34630fdc8d8SChris Lattner                         result.SetStatus (eReturnStatusFailed);
34730fdc8d8SChris Lattner                     }
34830fdc8d8SChris Lattner                 }
34930fdc8d8SChris Lattner             }
35030fdc8d8SChris Lattner             else
35130fdc8d8SChris Lattner                 bp = target->CreateBreakpoint (NULL,
35230fdc8d8SChris Lattner                                                file,
35330fdc8d8SChris Lattner                                                m_options.m_line_num,
35430fdc8d8SChris Lattner                                                m_options.m_ignore_inlines).get();
35530fdc8d8SChris Lattner         }
35630fdc8d8SChris Lattner         break;
35730fdc8d8SChris Lattner         case eSetTypeAddress: // Breakpoint by address
35830fdc8d8SChris Lattner             bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
35930fdc8d8SChris Lattner             break;
36030fdc8d8SChris Lattner         case eSetTypeFunctionName: // Breakpoint by function name
36130fdc8d8SChris Lattner             if (use_module)
36230fdc8d8SChris Lattner             {
36330fdc8d8SChris Lattner                 for (int i = 0; i < num_modules; ++i)
36430fdc8d8SChris Lattner                 {
36530fdc8d8SChris Lattner                     module.SetFile(m_options.m_modules[i].c_str());
36630fdc8d8SChris Lattner                     bp = target->CreateBreakpoint (&module, m_options.m_func_name.c_str()).get();
36730fdc8d8SChris Lattner                     if (bp)
36830fdc8d8SChris Lattner                     {
36930fdc8d8SChris Lattner                         StreamString &output_stream = result.GetOutputStream();
37030fdc8d8SChris Lattner                         output_stream.Printf ("Breakpoint created: ");
37130fdc8d8SChris Lattner                         bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
37230fdc8d8SChris Lattner                         output_stream.EOL();
37330fdc8d8SChris Lattner                         result.SetStatus (eReturnStatusSuccessFinishResult);
37430fdc8d8SChris Lattner                     }
37530fdc8d8SChris Lattner                     else
37630fdc8d8SChris Lattner                     {
37730fdc8d8SChris Lattner                         result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
37830fdc8d8SChris Lattner                                                     m_options.m_modules[i].c_str());
37930fdc8d8SChris Lattner                         result.SetStatus (eReturnStatusFailed);
38030fdc8d8SChris Lattner                     }
38130fdc8d8SChris Lattner                 }
38230fdc8d8SChris Lattner             }
38330fdc8d8SChris Lattner             else
38430fdc8d8SChris Lattner                 bp = target->CreateBreakpoint (NULL, m_options.m_func_name.c_str()).get();
38530fdc8d8SChris Lattner             break;
38630fdc8d8SChris Lattner         case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
38730fdc8d8SChris Lattner             {
38830fdc8d8SChris Lattner                 RegularExpression regexp(m_options.m_func_regexp.c_str());
38930fdc8d8SChris Lattner                 if (use_module)
39030fdc8d8SChris Lattner                 {
39130fdc8d8SChris Lattner                     for (int i = 0; i < num_modules; ++i)
39230fdc8d8SChris Lattner                     {
39330fdc8d8SChris Lattner                         module.SetFile(m_options.m_modules[i].c_str());
39430fdc8d8SChris Lattner                         bp = target->CreateBreakpoint (&module, regexp).get();
39530fdc8d8SChris Lattner                         if (bp)
39630fdc8d8SChris Lattner                         {
39730fdc8d8SChris Lattner                             StreamString &output_stream = result.GetOutputStream();
39830fdc8d8SChris Lattner                             output_stream.Printf ("Breakpoint created: ");
39930fdc8d8SChris Lattner                             bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
40030fdc8d8SChris Lattner                             output_stream.EOL();
40130fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusSuccessFinishResult);
40230fdc8d8SChris Lattner                         }
40330fdc8d8SChris Lattner                         else
40430fdc8d8SChris Lattner                         {
40530fdc8d8SChris Lattner                             result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
40630fdc8d8SChris Lattner                                                         m_options.m_modules[i].c_str());
40730fdc8d8SChris Lattner                             result.SetStatus (eReturnStatusFailed);
40830fdc8d8SChris Lattner                         }
40930fdc8d8SChris Lattner                     }
41030fdc8d8SChris Lattner                 }
41130fdc8d8SChris Lattner                 else
41230fdc8d8SChris Lattner                     bp = target->CreateBreakpoint (NULL, regexp).get();
41330fdc8d8SChris Lattner             }
41430fdc8d8SChris Lattner             break;
41530fdc8d8SChris Lattner         default:
41630fdc8d8SChris Lattner             break;
41730fdc8d8SChris Lattner     }
41830fdc8d8SChris Lattner 
4191b54c88cSJim Ingham     // Now set the various options that were passed in:
4201b54c88cSJim Ingham     if (bp)
4211b54c88cSJim Ingham     {
4221b54c88cSJim Ingham         if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
4231b54c88cSJim Ingham             bp->SetThreadID (m_options.m_thread_id);
4241b54c88cSJim Ingham 
4251b54c88cSJim Ingham         if (m_options.m_thread_index != -1)
4261b54c88cSJim Ingham             bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
4271b54c88cSJim Ingham 
4281b54c88cSJim Ingham         if (!m_options.m_thread_name.empty())
4291b54c88cSJim Ingham             bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
4301b54c88cSJim Ingham 
4311b54c88cSJim Ingham         if (!m_options.m_queue_name.empty())
4321b54c88cSJim Ingham             bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
4331b54c88cSJim Ingham 
4341b54c88cSJim Ingham         if (m_options.m_ignore_count != -1)
4351b54c88cSJim Ingham             bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
4361b54c88cSJim Ingham     }
4371b54c88cSJim Ingham 
43830fdc8d8SChris Lattner     if (bp && !use_module)
43930fdc8d8SChris Lattner     {
44030fdc8d8SChris Lattner         StreamString &output_stream = result.GetOutputStream();
44130fdc8d8SChris Lattner         output_stream.Printf ("Breakpoint created: ");
44230fdc8d8SChris Lattner         bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
44330fdc8d8SChris Lattner         output_stream.EOL();
44430fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishResult);
44530fdc8d8SChris Lattner     }
44630fdc8d8SChris Lattner     else if (!bp)
44730fdc8d8SChris Lattner     {
44830fdc8d8SChris Lattner         result.AppendError ("Breakpoint creation failed: No breakpoint created.");
44930fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
45030fdc8d8SChris Lattner     }
45130fdc8d8SChris Lattner 
45230fdc8d8SChris Lattner     return result.Succeeded();
45330fdc8d8SChris Lattner }
45430fdc8d8SChris Lattner 
45530fdc8d8SChris Lattner //-------------------------------------------------------------------------
45630fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint
45730fdc8d8SChris Lattner //-------------------------------------------------------------------------
458ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint
45930fdc8d8SChris Lattner 
460*6611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
46130fdc8d8SChris Lattner     CommandObjectMultiword ("breakpoint",
46230fdc8d8SChris Lattner                               "A set of commands for operating on breakpoints.",
46330fdc8d8SChris Lattner                               "breakpoint <command> [<command-options>]")
46430fdc8d8SChris Lattner {
46530fdc8d8SChris Lattner     bool status;
46630fdc8d8SChris Lattner 
46730fdc8d8SChris Lattner     CommandObjectSP list_command_object (new CommandObjectBreakpointList ());
46830fdc8d8SChris Lattner     CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete ());
46930fdc8d8SChris Lattner     CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable ());
47030fdc8d8SChris Lattner     CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable ());
47130fdc8d8SChris Lattner     CommandObjectSP set_command_object (new CommandObjectBreakpointSet ());
47230fdc8d8SChris Lattner     CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
473ae1c4cf5SJim Ingham     CommandObjectSP modify_command_object (new CommandObjectBreakpointModify());
47430fdc8d8SChris Lattner 
475ae1c4cf5SJim Ingham     command_command_object->SetCommandName ("breakpoint command");
47630fdc8d8SChris Lattner     enable_command_object->SetCommandName("breakpoint enable");
47730fdc8d8SChris Lattner     disable_command_object->SetCommandName("breakpoint disable");
47830fdc8d8SChris Lattner     list_command_object->SetCommandName ("breakpoint list");
479ae1c4cf5SJim Ingham     modify_command_object->SetCommandName ("breakpoint modify");
480ae1c4cf5SJim Ingham     set_command_object->SetCommandName("breakpoint set");
48130fdc8d8SChris Lattner 
482*6611103cSGreg Clayton     status = LoadSubCommand (interpreter, "list",       list_command_object);
483*6611103cSGreg Clayton     status = LoadSubCommand (interpreter, "enable",     enable_command_object);
484*6611103cSGreg Clayton     status = LoadSubCommand (interpreter, "disable",    disable_command_object);
485*6611103cSGreg Clayton     status = LoadSubCommand (interpreter, "delete",     delete_command_object);
486*6611103cSGreg Clayton     status = LoadSubCommand (interpreter, "set",        set_command_object);
487*6611103cSGreg Clayton     status = LoadSubCommand (interpreter, "command",    command_command_object);
488*6611103cSGreg Clayton     status = LoadSubCommand (interpreter, "modify",     modify_command_object);
48930fdc8d8SChris Lattner }
49030fdc8d8SChris Lattner 
49130fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
49230fdc8d8SChris Lattner {
49330fdc8d8SChris Lattner }
49430fdc8d8SChris Lattner 
49530fdc8d8SChris Lattner void
49630fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result,
49730fdc8d8SChris Lattner                                                          BreakpointIDList *valid_ids)
49830fdc8d8SChris Lattner {
49930fdc8d8SChris Lattner     // args can be strings representing 1). integers (for breakpoint ids)
50030fdc8d8SChris Lattner     //                                  2). the full breakpoint & location canonical representation
50130fdc8d8SChris Lattner     //                                  3). the word "to" or a hyphen, representing a range (in which case there
50230fdc8d8SChris Lattner     //                                      had *better* be an entry both before & after of one of the first two types.
50330fdc8d8SChris Lattner 
50430fdc8d8SChris Lattner     Args temp_args;
50530fdc8d8SChris Lattner 
50630fdc8d8SChris Lattner     // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
50730fdc8d8SChris Lattner     // the new TEMP_ARGS.  Do not copy breakpoint id range strings over; instead generate a list of strings for
50830fdc8d8SChris Lattner     // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
50930fdc8d8SChris Lattner 
51030fdc8d8SChris Lattner     BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
51130fdc8d8SChris Lattner 
51230fdc8d8SChris Lattner     // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
51330fdc8d8SChris Lattner 
51430fdc8d8SChris Lattner     valid_ids->InsertStringArray ((const char **) temp_args.GetArgumentVector(), temp_args.GetArgumentCount(), result);
51530fdc8d8SChris Lattner 
51630fdc8d8SChris Lattner     // At this point,  all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
51730fdc8d8SChris Lattner     // and put into valid_ids.
51830fdc8d8SChris Lattner 
51930fdc8d8SChris Lattner     if (result.Succeeded())
52030fdc8d8SChris Lattner     {
52130fdc8d8SChris Lattner         // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
52230fdc8d8SChris Lattner         // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
52330fdc8d8SChris Lattner 
52430fdc8d8SChris Lattner         for (int i = 0; i < valid_ids->Size(); ++i)
52530fdc8d8SChris Lattner         {
52630fdc8d8SChris Lattner             BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
52730fdc8d8SChris Lattner             Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
52830fdc8d8SChris Lattner             if (breakpoint != NULL)
52930fdc8d8SChris Lattner             {
53030fdc8d8SChris Lattner                 int num_locations = breakpoint->GetNumLocations();
53130fdc8d8SChris Lattner                 if (cur_bp_id.GetLocationID() > num_locations)
53230fdc8d8SChris Lattner                 {
53330fdc8d8SChris Lattner                     StreamString id_str;
53430fdc8d8SChris Lattner                     BreakpointID::GetCanonicalReference (&id_str, cur_bp_id.GetBreakpointID(),
53530fdc8d8SChris Lattner                                                            cur_bp_id.GetLocationID());
53630fdc8d8SChris Lattner                     i = valid_ids->Size() + 1;
53730fdc8d8SChris Lattner                     result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
53830fdc8d8SChris Lattner                                                  id_str.GetData());
53930fdc8d8SChris Lattner                     result.SetStatus (eReturnStatusFailed);
54030fdc8d8SChris Lattner                 }
54130fdc8d8SChris Lattner             }
54230fdc8d8SChris Lattner             else
54330fdc8d8SChris Lattner             {
54430fdc8d8SChris Lattner                 i = valid_ids->Size() + 1;
54530fdc8d8SChris Lattner                 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
54630fdc8d8SChris Lattner                 result.SetStatus (eReturnStatusFailed);
54730fdc8d8SChris Lattner             }
54830fdc8d8SChris Lattner         }
54930fdc8d8SChris Lattner     }
55030fdc8d8SChris Lattner }
55130fdc8d8SChris Lattner 
55230fdc8d8SChris Lattner //-------------------------------------------------------------------------
55330fdc8d8SChris Lattner // CommandObjectBreakpointList::Options
55430fdc8d8SChris Lattner //-------------------------------------------------------------------------
555ae1c4cf5SJim Ingham #pragma mark List::CommandOptions
55630fdc8d8SChris Lattner 
55730fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::CommandOptions() :
55830fdc8d8SChris Lattner     Options (),
55930fdc8d8SChris Lattner     m_level (lldb::eDescriptionLevelFull)  // Breakpoint List defaults to brief descriptions
56030fdc8d8SChris Lattner {
56130fdc8d8SChris Lattner }
56230fdc8d8SChris Lattner 
56330fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::~CommandOptions ()
56430fdc8d8SChris Lattner {
56530fdc8d8SChris Lattner }
56630fdc8d8SChris Lattner 
56730fdc8d8SChris Lattner lldb::OptionDefinition
56830fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::g_option_table[] =
56930fdc8d8SChris Lattner {
5708651121cSJim Ingham     { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, NULL,
5718651121cSJim Ingham         "Show debugger internal breakpoints" },
5728651121cSJim Ingham 
5738651121cSJim Ingham     { LLDB_OPT_SET_1, false, "brief",    'b', no_argument, NULL, 0, NULL,
57430fdc8d8SChris Lattner         "Give a brief description of the breakpoint (no location info)."},
57530fdc8d8SChris Lattner 
57630fdc8d8SChris Lattner     // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
57730fdc8d8SChris Lattner     // But I need to see it for now, and don't want to wait.
5788651121cSJim Ingham     { LLDB_OPT_SET_2, false, "full",    'f', no_argument, NULL, 0, NULL,
57930fdc8d8SChris Lattner         "Give a full description of the breakpoint and its locations."},
58030fdc8d8SChris Lattner 
5818651121cSJim Ingham     { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, NULL,
58230fdc8d8SChris Lattner         "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
58330fdc8d8SChris Lattner 
58430fdc8d8SChris Lattner     { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL }
58530fdc8d8SChris Lattner };
58630fdc8d8SChris Lattner 
58730fdc8d8SChris Lattner const lldb::OptionDefinition*
58830fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::GetDefinitions ()
58930fdc8d8SChris Lattner {
59030fdc8d8SChris Lattner     return g_option_table;
59130fdc8d8SChris Lattner }
59230fdc8d8SChris Lattner 
59330fdc8d8SChris Lattner Error
59430fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
59530fdc8d8SChris Lattner {
59630fdc8d8SChris Lattner     Error error;
59730fdc8d8SChris Lattner     char short_option = (char) m_getopt_table[option_idx].val;
59830fdc8d8SChris Lattner 
59930fdc8d8SChris Lattner     switch (short_option)
60030fdc8d8SChris Lattner     {
60130fdc8d8SChris Lattner         case 'b':
60230fdc8d8SChris Lattner             m_level = lldb::eDescriptionLevelBrief;
60330fdc8d8SChris Lattner             break;
60430fdc8d8SChris Lattner         case 'f':
60530fdc8d8SChris Lattner             m_level = lldb::eDescriptionLevelFull;
60630fdc8d8SChris Lattner             break;
60730fdc8d8SChris Lattner         case 'v':
60830fdc8d8SChris Lattner             m_level = lldb::eDescriptionLevelVerbose;
60930fdc8d8SChris Lattner             break;
61030fdc8d8SChris Lattner         case 'i':
61130fdc8d8SChris Lattner             m_internal = true;
61230fdc8d8SChris Lattner             break;
61330fdc8d8SChris Lattner         default:
61430fdc8d8SChris Lattner             error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
61530fdc8d8SChris Lattner             break;
61630fdc8d8SChris Lattner     }
61730fdc8d8SChris Lattner 
61830fdc8d8SChris Lattner     return error;
61930fdc8d8SChris Lattner }
62030fdc8d8SChris Lattner 
62130fdc8d8SChris Lattner void
62230fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::ResetOptionValues ()
62330fdc8d8SChris Lattner {
62430fdc8d8SChris Lattner     Options::ResetOptionValues();
62530fdc8d8SChris Lattner 
62630fdc8d8SChris Lattner     m_level = lldb::eDescriptionLevelFull;
62730fdc8d8SChris Lattner     m_internal = false;
62830fdc8d8SChris Lattner }
62930fdc8d8SChris Lattner 
63030fdc8d8SChris Lattner //-------------------------------------------------------------------------
63130fdc8d8SChris Lattner // CommandObjectBreakpointList
63230fdc8d8SChris Lattner //-------------------------------------------------------------------------
633ae1c4cf5SJim Ingham #pragma mark List
63430fdc8d8SChris Lattner 
63530fdc8d8SChris Lattner CommandObjectBreakpointList::CommandObjectBreakpointList () :
63630fdc8d8SChris Lattner     CommandObject ("breakpoint list",
63730fdc8d8SChris Lattner                      "List some or all breakpoints at configurable levels of detail.",
63830fdc8d8SChris Lattner                      "breakpoint list [<breakpoint-id>]")
63930fdc8d8SChris Lattner {
64030fdc8d8SChris Lattner }
64130fdc8d8SChris Lattner 
64230fdc8d8SChris Lattner CommandObjectBreakpointList::~CommandObjectBreakpointList ()
64330fdc8d8SChris Lattner {
64430fdc8d8SChris Lattner }
64530fdc8d8SChris Lattner 
64630fdc8d8SChris Lattner Options *
64730fdc8d8SChris Lattner CommandObjectBreakpointList::GetOptions ()
64830fdc8d8SChris Lattner {
64930fdc8d8SChris Lattner     return &m_options;
65030fdc8d8SChris Lattner }
65130fdc8d8SChris Lattner 
65230fdc8d8SChris Lattner bool
65330fdc8d8SChris Lattner CommandObjectBreakpointList::Execute
65430fdc8d8SChris Lattner (
655*6611103cSGreg Clayton     CommandInterpreter &interpreter,
65630fdc8d8SChris Lattner     Args& args,
65730fdc8d8SChris Lattner     CommandReturnObject &result
65830fdc8d8SChris Lattner )
65930fdc8d8SChris Lattner {
660*6611103cSGreg Clayton     Target *target = interpreter.GetDebugger().GetCurrentTarget().get();
66130fdc8d8SChris Lattner     if (target == NULL)
66230fdc8d8SChris Lattner     {
66330fdc8d8SChris Lattner         result.AppendError ("Invalid target, set executable file using 'file' command.");
66430fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
66530fdc8d8SChris Lattner         return true;
66630fdc8d8SChris Lattner     }
66730fdc8d8SChris Lattner 
66830fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
6691b54c88cSJim Ingham     Mutex::Locker locker;
6701b54c88cSJim Ingham     target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
6711b54c88cSJim Ingham 
67230fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
67330fdc8d8SChris Lattner 
67430fdc8d8SChris Lattner     if (num_breakpoints == 0)
67530fdc8d8SChris Lattner     {
67630fdc8d8SChris Lattner         result.AppendMessage ("No breakpoints currently set.");
67730fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
67830fdc8d8SChris Lattner         return true;
67930fdc8d8SChris Lattner     }
68030fdc8d8SChris Lattner 
68130fdc8d8SChris Lattner     StreamString &output_stream = result.GetOutputStream();
68230fdc8d8SChris Lattner 
68330fdc8d8SChris Lattner     if (args.GetArgumentCount() == 0)
68430fdc8d8SChris Lattner     {
68530fdc8d8SChris Lattner         // No breakpoint selected; show info about all currently set breakpoints.
68630fdc8d8SChris Lattner         result.AppendMessage ("Current breakpoints:");
68730fdc8d8SChris Lattner         for (int i = 0; i < num_breakpoints; ++i)
68830fdc8d8SChris Lattner         {
68930fdc8d8SChris Lattner             Breakpoint *breakpoint = breakpoints.GetBreakpointByIndex (i).get();
690*6611103cSGreg Clayton             AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
69130fdc8d8SChris Lattner         }
69230fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
69330fdc8d8SChris Lattner     }
69430fdc8d8SChris Lattner     else
69530fdc8d8SChris Lattner     {
69630fdc8d8SChris Lattner         // Particular breakpoints selected; show info about that breakpoint.
69730fdc8d8SChris Lattner         BreakpointIDList valid_bp_ids;
69830fdc8d8SChris Lattner         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
69930fdc8d8SChris Lattner 
70030fdc8d8SChris Lattner         if (result.Succeeded())
70130fdc8d8SChris Lattner         {
70230fdc8d8SChris Lattner             for (int i = 0; i < valid_bp_ids.Size(); ++i)
70330fdc8d8SChris Lattner             {
70430fdc8d8SChris Lattner                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
70530fdc8d8SChris Lattner                 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
706*6611103cSGreg Clayton                 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
70730fdc8d8SChris Lattner             }
70830fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishNoResult);
70930fdc8d8SChris Lattner         }
71030fdc8d8SChris Lattner         else
71130fdc8d8SChris Lattner         {
71230fdc8d8SChris Lattner             result.AppendError ("Invalid breakpoint id.");
71330fdc8d8SChris Lattner             result.SetStatus (eReturnStatusFailed);
71430fdc8d8SChris Lattner         }
71530fdc8d8SChris Lattner     }
71630fdc8d8SChris Lattner 
71730fdc8d8SChris Lattner     return result.Succeeded();
71830fdc8d8SChris Lattner }
71930fdc8d8SChris Lattner 
72030fdc8d8SChris Lattner //-------------------------------------------------------------------------
72130fdc8d8SChris Lattner // CommandObjectBreakpointEnable
72230fdc8d8SChris Lattner //-------------------------------------------------------------------------
723ae1c4cf5SJim Ingham #pragma mark Enable
72430fdc8d8SChris Lattner 
72530fdc8d8SChris Lattner CommandObjectBreakpointEnable::CommandObjectBreakpointEnable () :
72630fdc8d8SChris Lattner     CommandObject ("enable",
72730fdc8d8SChris Lattner                      "Enables the specified disabled breakpoint(s).  If no breakpoints are specified, enables all of them.",
72830fdc8d8SChris Lattner                      "breakpoint enable [<breakpoint-id> | <breakpoint-id-list>]")
72930fdc8d8SChris Lattner {
73030fdc8d8SChris Lattner     // This command object can either be called via 'enable' or 'breakpoint enable'.  Because it has two different
73130fdc8d8SChris Lattner     // potential invocation methods, we need to be a little tricky about generating the syntax string.
73230fdc8d8SChris Lattner     //StreamString tmp_string;
73330fdc8d8SChris Lattner     //tmp_string.Printf ("%s <breakpoint-id>", GetCommandName());
73430fdc8d8SChris Lattner     //m_cmd_syntax.assign (tmp_string.GetData(), tmp_string.GetSize());
73530fdc8d8SChris Lattner }
73630fdc8d8SChris Lattner 
73730fdc8d8SChris Lattner 
73830fdc8d8SChris Lattner CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable ()
73930fdc8d8SChris Lattner {
74030fdc8d8SChris Lattner }
74130fdc8d8SChris Lattner 
74230fdc8d8SChris Lattner 
74330fdc8d8SChris Lattner bool
744*6611103cSGreg Clayton CommandObjectBreakpointEnable::Execute
745*6611103cSGreg Clayton (
746*6611103cSGreg Clayton     CommandInterpreter &interpreter,
747*6611103cSGreg Clayton     Args& args,
748*6611103cSGreg Clayton     CommandReturnObject &result
749*6611103cSGreg Clayton )
75030fdc8d8SChris Lattner {
751*6611103cSGreg Clayton     Target *target = interpreter.GetDebugger().GetCurrentTarget().get();
75230fdc8d8SChris Lattner     if (target == NULL)
75330fdc8d8SChris Lattner     {
75430fdc8d8SChris Lattner         result.AppendError ("Invalid target, set executable file using 'file' command.");
75530fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
75630fdc8d8SChris Lattner         return false;
75730fdc8d8SChris Lattner     }
75830fdc8d8SChris Lattner 
7591b54c88cSJim Ingham     Mutex::Locker locker;
7601b54c88cSJim Ingham     target->GetBreakpointList().GetListMutex(locker);
7611b54c88cSJim Ingham 
76230fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
7631b54c88cSJim Ingham 
76430fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
76530fdc8d8SChris Lattner 
76630fdc8d8SChris Lattner     if (num_breakpoints == 0)
76730fdc8d8SChris Lattner     {
76830fdc8d8SChris Lattner         result.AppendError ("No breakpoints exist to be enabled.");
76930fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
77030fdc8d8SChris Lattner         return false;
77130fdc8d8SChris Lattner     }
77230fdc8d8SChris Lattner 
77330fdc8d8SChris Lattner     if (args.GetArgumentCount() == 0)
77430fdc8d8SChris Lattner     {
77530fdc8d8SChris Lattner         // No breakpoint selected; enable all currently set breakpoints.
77630fdc8d8SChris Lattner         target->EnableAllBreakpoints ();
77730fdc8d8SChris Lattner         result.AppendMessageWithFormat ("All breakpoints enabled. (%d breakpoints)\n", num_breakpoints);
77830fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
77930fdc8d8SChris Lattner     }
78030fdc8d8SChris Lattner     else
78130fdc8d8SChris Lattner     {
78230fdc8d8SChris Lattner         // Particular breakpoint selected; enable that breakpoint.
78330fdc8d8SChris Lattner         BreakpointIDList valid_bp_ids;
78430fdc8d8SChris Lattner         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
78530fdc8d8SChris Lattner 
78630fdc8d8SChris Lattner         if (result.Succeeded())
78730fdc8d8SChris Lattner         {
78830fdc8d8SChris Lattner             int enable_count = 0;
78930fdc8d8SChris Lattner             int loc_count = 0;
79030fdc8d8SChris Lattner             for (int i = 0; i < valid_bp_ids.Size(); ++i)
79130fdc8d8SChris Lattner             {
79230fdc8d8SChris Lattner                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
79330fdc8d8SChris Lattner 
79430fdc8d8SChris Lattner                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
79530fdc8d8SChris Lattner                 {
79630fdc8d8SChris Lattner                     Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
79730fdc8d8SChris Lattner                     if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
79830fdc8d8SChris Lattner                     {
79930fdc8d8SChris Lattner                         BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
80030fdc8d8SChris Lattner                         if (location)
80130fdc8d8SChris Lattner                         {
80230fdc8d8SChris Lattner                             location->SetEnabled (true);
80330fdc8d8SChris Lattner                             ++loc_count;
80430fdc8d8SChris Lattner                         }
80530fdc8d8SChris Lattner                     }
80630fdc8d8SChris Lattner                     else
80730fdc8d8SChris Lattner                     {
808ae1c4cf5SJim Ingham                         breakpoint->SetEnabled (true);
80930fdc8d8SChris Lattner                         ++enable_count;
81030fdc8d8SChris Lattner                     }
81130fdc8d8SChris Lattner                 }
81230fdc8d8SChris Lattner             }
81330fdc8d8SChris Lattner             result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
81430fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishNoResult);
81530fdc8d8SChris Lattner         }
81630fdc8d8SChris Lattner     }
81730fdc8d8SChris Lattner 
81830fdc8d8SChris Lattner     return result.Succeeded();
81930fdc8d8SChris Lattner }
82030fdc8d8SChris Lattner 
82130fdc8d8SChris Lattner //-------------------------------------------------------------------------
82230fdc8d8SChris Lattner // CommandObjectBreakpointDisable
82330fdc8d8SChris Lattner //-------------------------------------------------------------------------
824ae1c4cf5SJim Ingham #pragma mark Disable
82530fdc8d8SChris Lattner 
82630fdc8d8SChris Lattner CommandObjectBreakpointDisable::CommandObjectBreakpointDisable () :
82730fdc8d8SChris Lattner     CommandObject ("disable",
82830fdc8d8SChris Lattner                    "Disables the specified breakpoint(s) without removing it/them.  If no breakpoints are specified, disables them all.",
82930fdc8d8SChris Lattner                    "disable [<breakpoint-id> | <breakpoint-id-list>]")
83030fdc8d8SChris Lattner {
83130fdc8d8SChris Lattner     // This command object can either be called via 'enable' or 'breakpoint enable'.  Because it has two different
83230fdc8d8SChris Lattner     // potential invocation methods, we need to be a little tricky about generating the syntax string.
83330fdc8d8SChris Lattner     //StreamString tmp_string;
83430fdc8d8SChris Lattner     //tmp_string.Printf ("%s <breakpoint-id>", GetCommandName());
83530fdc8d8SChris Lattner     //m_cmd_syntax.assign(tmp_string.GetData(), tmp_string.GetSize());
83630fdc8d8SChris Lattner }
83730fdc8d8SChris Lattner 
83830fdc8d8SChris Lattner CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable ()
83930fdc8d8SChris Lattner {
84030fdc8d8SChris Lattner }
84130fdc8d8SChris Lattner 
84230fdc8d8SChris Lattner bool
843*6611103cSGreg Clayton CommandObjectBreakpointDisable::Execute
844*6611103cSGreg Clayton (
845*6611103cSGreg Clayton     CommandInterpreter &interpreter,
846*6611103cSGreg Clayton     Args& args,
847*6611103cSGreg Clayton     CommandReturnObject &result
848*6611103cSGreg Clayton )
84930fdc8d8SChris Lattner {
850*6611103cSGreg Clayton     Target *target = interpreter.GetDebugger().GetCurrentTarget().get();
85130fdc8d8SChris Lattner     if (target == NULL)
85230fdc8d8SChris Lattner     {
85330fdc8d8SChris Lattner         result.AppendError ("Invalid target, set executable file using 'file' command.");
85430fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
85530fdc8d8SChris Lattner         return false;
85630fdc8d8SChris Lattner     }
85730fdc8d8SChris Lattner 
8581b54c88cSJim Ingham     Mutex::Locker locker;
8591b54c88cSJim Ingham     target->GetBreakpointList().GetListMutex(locker);
8601b54c88cSJim Ingham 
86130fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
86230fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
86330fdc8d8SChris Lattner 
86430fdc8d8SChris Lattner     if (num_breakpoints == 0)
86530fdc8d8SChris Lattner     {
86630fdc8d8SChris Lattner         result.AppendError ("No breakpoints exist to be disabled.");
86730fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
86830fdc8d8SChris Lattner         return false;
86930fdc8d8SChris Lattner     }
87030fdc8d8SChris Lattner 
87130fdc8d8SChris Lattner     if (args.GetArgumentCount() == 0)
87230fdc8d8SChris Lattner     {
87330fdc8d8SChris Lattner         // No breakpoint selected; disable all currently set breakpoints.
87430fdc8d8SChris Lattner         target->DisableAllBreakpoints ();
87530fdc8d8SChris Lattner         result.AppendMessageWithFormat ("All breakpoints disabled. (%d breakpoints)\n", num_breakpoints);
87630fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
87730fdc8d8SChris Lattner     }
87830fdc8d8SChris Lattner     else
87930fdc8d8SChris Lattner     {
88030fdc8d8SChris Lattner         // Particular breakpoint selected; disable that breakpoint.
88130fdc8d8SChris Lattner         BreakpointIDList valid_bp_ids;
88230fdc8d8SChris Lattner 
88330fdc8d8SChris Lattner         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
88430fdc8d8SChris Lattner 
88530fdc8d8SChris Lattner         if (result.Succeeded())
88630fdc8d8SChris Lattner         {
88730fdc8d8SChris Lattner             int disable_count = 0;
88830fdc8d8SChris Lattner             int loc_count = 0;
88930fdc8d8SChris Lattner             for (int i = 0; i < valid_bp_ids.Size(); ++i)
89030fdc8d8SChris Lattner             {
89130fdc8d8SChris Lattner                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
89230fdc8d8SChris Lattner 
89330fdc8d8SChris Lattner                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
89430fdc8d8SChris Lattner                 {
89530fdc8d8SChris Lattner                     Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
89630fdc8d8SChris Lattner                     if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
89730fdc8d8SChris Lattner                     {
89830fdc8d8SChris Lattner                         BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
89930fdc8d8SChris Lattner                         if (location)
90030fdc8d8SChris Lattner                         {
90130fdc8d8SChris Lattner                             location->SetEnabled (false);
90230fdc8d8SChris Lattner                             ++loc_count;
90330fdc8d8SChris Lattner                         }
90430fdc8d8SChris Lattner                     }
90530fdc8d8SChris Lattner                     else
90630fdc8d8SChris Lattner                     {
907ae1c4cf5SJim Ingham                         breakpoint->SetEnabled (false);
90830fdc8d8SChris Lattner                         ++disable_count;
90930fdc8d8SChris Lattner                     }
91030fdc8d8SChris Lattner                 }
91130fdc8d8SChris Lattner             }
91230fdc8d8SChris Lattner             result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
91330fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishNoResult);
91430fdc8d8SChris Lattner         }
91530fdc8d8SChris Lattner     }
91630fdc8d8SChris Lattner 
91730fdc8d8SChris Lattner     return result.Succeeded();
91830fdc8d8SChris Lattner }
91930fdc8d8SChris Lattner 
92030fdc8d8SChris Lattner //-------------------------------------------------------------------------
92130fdc8d8SChris Lattner // CommandObjectBreakpointDelete
92230fdc8d8SChris Lattner //-------------------------------------------------------------------------
923ae1c4cf5SJim Ingham #pragma mark Delete
92430fdc8d8SChris Lattner 
92530fdc8d8SChris Lattner CommandObjectBreakpointDelete::CommandObjectBreakpointDelete() :
92630fdc8d8SChris Lattner     CommandObject ("breakpoint delete",
92730fdc8d8SChris Lattner                    "Delete the specified breakpoint(s).  If no breakpoints are specified, deletes them all.",
92830fdc8d8SChris Lattner                    "breakpoint delete [<breakpoint-id> | <breakpoint-id-list>]")
92930fdc8d8SChris Lattner {
93030fdc8d8SChris Lattner }
93130fdc8d8SChris Lattner 
93230fdc8d8SChris Lattner 
93330fdc8d8SChris Lattner CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete ()
93430fdc8d8SChris Lattner {
93530fdc8d8SChris Lattner }
93630fdc8d8SChris Lattner 
93730fdc8d8SChris Lattner bool
938*6611103cSGreg Clayton CommandObjectBreakpointDelete::Execute
939*6611103cSGreg Clayton (
940*6611103cSGreg Clayton     CommandInterpreter &interpreter,
941*6611103cSGreg Clayton     Args& args,
942*6611103cSGreg Clayton     CommandReturnObject &result
943*6611103cSGreg Clayton )
94430fdc8d8SChris Lattner {
945*6611103cSGreg Clayton     Target *target = interpreter.GetDebugger().GetCurrentTarget().get();
94630fdc8d8SChris Lattner     if (target == NULL)
94730fdc8d8SChris Lattner     {
94830fdc8d8SChris Lattner         result.AppendError ("Invalid target, set executable file using 'file' command.");
94930fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
95030fdc8d8SChris Lattner         return false;
95130fdc8d8SChris Lattner     }
95230fdc8d8SChris Lattner 
9531b54c88cSJim Ingham     Mutex::Locker locker;
9541b54c88cSJim Ingham     target->GetBreakpointList().GetListMutex(locker);
9551b54c88cSJim Ingham 
95630fdc8d8SChris Lattner     const BreakpointList &breakpoints = target->GetBreakpointList();
9571b54c88cSJim Ingham 
95830fdc8d8SChris Lattner     size_t num_breakpoints = breakpoints.GetSize();
95930fdc8d8SChris Lattner 
96030fdc8d8SChris Lattner     if (num_breakpoints == 0)
96130fdc8d8SChris Lattner     {
96230fdc8d8SChris Lattner         result.AppendError ("No breakpoints exist to be deleted.");
96330fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
96430fdc8d8SChris Lattner         return false;
96530fdc8d8SChris Lattner     }
96630fdc8d8SChris Lattner 
96730fdc8d8SChris Lattner     if (args.GetArgumentCount() == 0)
96830fdc8d8SChris Lattner     {
96930fdc8d8SChris Lattner         // No breakpoint selected; disable all currently set breakpoints.
97030fdc8d8SChris Lattner         if (args.GetArgumentCount() != 0)
97130fdc8d8SChris Lattner         {
97230fdc8d8SChris Lattner             result.AppendErrorWithFormat ("Specify breakpoints to delete with the -i option.\n");
97330fdc8d8SChris Lattner             result.SetStatus (eReturnStatusFailed);
97430fdc8d8SChris Lattner             return false;
97530fdc8d8SChris Lattner         }
97630fdc8d8SChris Lattner 
97730fdc8d8SChris Lattner         target->RemoveAllBreakpoints ();
97830fdc8d8SChris Lattner         result.AppendMessageWithFormat ("All breakpoints removed. (%d breakpoints)\n", num_breakpoints);
97930fdc8d8SChris Lattner         result.SetStatus (eReturnStatusSuccessFinishNoResult);
98030fdc8d8SChris Lattner     }
98130fdc8d8SChris Lattner     else
98230fdc8d8SChris Lattner     {
98330fdc8d8SChris Lattner         // Particular breakpoint selected; disable that breakpoint.
98430fdc8d8SChris Lattner         BreakpointIDList valid_bp_ids;
98530fdc8d8SChris Lattner         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
98630fdc8d8SChris Lattner 
98730fdc8d8SChris Lattner         if (result.Succeeded())
98830fdc8d8SChris Lattner         {
98930fdc8d8SChris Lattner             int delete_count = 0;
99030fdc8d8SChris Lattner             int disable_count = 0;
99130fdc8d8SChris Lattner             for (int i = 0; i < valid_bp_ids.Size(); ++i)
99230fdc8d8SChris Lattner             {
99330fdc8d8SChris Lattner                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
99430fdc8d8SChris Lattner 
99530fdc8d8SChris Lattner                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
99630fdc8d8SChris Lattner                 {
99730fdc8d8SChris Lattner                     if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
99830fdc8d8SChris Lattner                     {
99930fdc8d8SChris Lattner                         Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
100030fdc8d8SChris Lattner                         BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
100130fdc8d8SChris Lattner                         // It makes no sense to try to delete individual locations, so we disable them instead.
100230fdc8d8SChris Lattner                         if (location)
100330fdc8d8SChris Lattner                         {
100430fdc8d8SChris Lattner                             location->SetEnabled (false);
100530fdc8d8SChris Lattner                             ++disable_count;
100630fdc8d8SChris Lattner                         }
100730fdc8d8SChris Lattner                     }
100830fdc8d8SChris Lattner                     else
100930fdc8d8SChris Lattner                     {
101030fdc8d8SChris Lattner                         target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
101130fdc8d8SChris Lattner                         ++delete_count;
101230fdc8d8SChris Lattner                     }
101330fdc8d8SChris Lattner                 }
101430fdc8d8SChris Lattner             }
101530fdc8d8SChris Lattner             result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
101630fdc8d8SChris Lattner                                            delete_count, disable_count);
101730fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishNoResult);
101830fdc8d8SChris Lattner         }
101930fdc8d8SChris Lattner     }
102030fdc8d8SChris Lattner     return result.Succeeded();
102130fdc8d8SChris Lattner }
10221b54c88cSJim Ingham 
10231b54c88cSJim Ingham //-------------------------------------------------------------------------
1024ae1c4cf5SJim Ingham // CommandObjectBreakpointModify::CommandOptions
10251b54c88cSJim Ingham //-------------------------------------------------------------------------
1026ae1c4cf5SJim Ingham #pragma mark Modify::CommandOptions
10271b54c88cSJim Ingham 
1028ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::CommandOptions() :
10291b54c88cSJim Ingham     Options (),
10301b54c88cSJim Ingham     m_thread_id(LLDB_INVALID_THREAD_ID),
10311b54c88cSJim Ingham     m_thread_index (-1),
10321b54c88cSJim Ingham     m_thread_name(),
10331b54c88cSJim Ingham     m_queue_name(),
1034ae1c4cf5SJim Ingham     m_ignore_count (-1),
1035ae1c4cf5SJim Ingham     m_enable_passed (false)
10361b54c88cSJim Ingham {
10371b54c88cSJim Ingham }
10381b54c88cSJim Ingham 
1039ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::~CommandOptions ()
10401b54c88cSJim Ingham {
10411b54c88cSJim Ingham }
10421b54c88cSJim Ingham 
10431b54c88cSJim Ingham lldb::OptionDefinition
1044ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
10451b54c88cSJim Ingham {
10461b54c88cSJim Ingham     { LLDB_OPT_SET_ALL, false, "ignore_count", 'k', required_argument,   NULL, 0, NULL,
10471b54c88cSJim Ingham         "Set the number of times this breakpoint is sKipped before stopping." },
10481b54c88cSJim Ingham 
10491b54c88cSJim Ingham     { LLDB_OPT_SET_ALL, false, "thread_index",       'x', required_argument, NULL, NULL, "<thread_index>",
10501b54c88cSJim Ingham         "The breakpoint stops only for the thread whose indeX matches this argument."},
10511b54c88cSJim Ingham 
10521b54c88cSJim Ingham     { LLDB_OPT_SET_ALL, false, "thread_id",       't', required_argument, NULL, NULL, "<thread_id>",
10531b54c88cSJim Ingham         "The breakpoint stops only for the thread whose TID matches this argument."},
10541b54c88cSJim Ingham 
10551b54c88cSJim Ingham     { LLDB_OPT_SET_ALL, false, "thread_name",       'T', required_argument, NULL, NULL, "<thread_name>",
10561b54c88cSJim Ingham         "The breakpoint stops only for the thread whose thread name matches this argument."},
10571b54c88cSJim Ingham 
10581b54c88cSJim Ingham     { LLDB_OPT_SET_ALL, false, "queue_name",       'q', required_argument, NULL, NULL, "<queue_name>",
10591b54c88cSJim Ingham         "The breakpoint stops only for threads in the queue whose name is given by this argument."},
10601b54c88cSJim Ingham 
1061ae1c4cf5SJim Ingham     { LLDB_OPT_SET_1, false, "enable",       'e', no_argument, NULL, NULL, NULL,
1062ae1c4cf5SJim Ingham         "Enable the breakpoint."},
1063ae1c4cf5SJim Ingham 
1064ae1c4cf5SJim Ingham     { LLDB_OPT_SET_2, false, "disable",       'd', no_argument, NULL, NULL, NULL,
1065ae1c4cf5SJim Ingham         "Disable the breakpoint."},
1066ae1c4cf5SJim Ingham 
1067ae1c4cf5SJim Ingham 
10681b54c88cSJim Ingham     { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL }
10691b54c88cSJim Ingham };
10701b54c88cSJim Ingham 
10711b54c88cSJim Ingham const lldb::OptionDefinition*
1072ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::GetDefinitions ()
10731b54c88cSJim Ingham {
10741b54c88cSJim Ingham     return g_option_table;
10751b54c88cSJim Ingham }
10761b54c88cSJim Ingham 
10771b54c88cSJim Ingham Error
1078ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
10791b54c88cSJim Ingham {
10801b54c88cSJim Ingham     Error error;
10811b54c88cSJim Ingham     char short_option = (char) m_getopt_table[option_idx].val;
10821b54c88cSJim Ingham 
10831b54c88cSJim Ingham     switch (short_option)
10841b54c88cSJim Ingham     {
1085ae1c4cf5SJim Ingham         case 'd':
1086ae1c4cf5SJim Ingham             m_enable_passed = true;
1087ae1c4cf5SJim Ingham             m_enable_value = false;
1088ae1c4cf5SJim Ingham             break;
1089ae1c4cf5SJim Ingham         case 'e':
1090ae1c4cf5SJim Ingham             m_enable_passed = true;
1091ae1c4cf5SJim Ingham             m_enable_value = true;
1092ae1c4cf5SJim Ingham             break;
10931b54c88cSJim Ingham         case 'k':
10941b54c88cSJim Ingham         {
10951b54c88cSJim Ingham             m_ignore_count = Args::StringToSInt32(optarg, -1, 0);
10961b54c88cSJim Ingham             if (m_ignore_count == -1)
10971b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg);
10981b54c88cSJim Ingham         }
1099ae1c4cf5SJim Ingham         break;
11001b54c88cSJim Ingham         case 't' :
11011b54c88cSJim Ingham         {
11021b54c88cSJim Ingham             m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0);
11031b54c88cSJim Ingham             if (m_thread_id == LLDB_INVALID_THREAD_ID)
11041b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg);
11051b54c88cSJim Ingham         }
11061b54c88cSJim Ingham         break;
11071b54c88cSJim Ingham         case 'T':
1108b2a38a72SJim Ingham             if (option_arg != NULL)
11091b54c88cSJim Ingham                 m_thread_name = option_arg;
1110b2a38a72SJim Ingham             else
1111b2a38a72SJim Ingham                 m_thread_name.clear();
1112b2a38a72SJim Ingham             m_name_passed = true;
11131b54c88cSJim Ingham             break;
11141b54c88cSJim Ingham         case 'q':
1115b2a38a72SJim Ingham             if (option_arg != NULL)
11161b54c88cSJim Ingham                 m_queue_name = option_arg;
1117b2a38a72SJim Ingham             else
1118b2a38a72SJim Ingham                 m_queue_name.clear();
1119b2a38a72SJim Ingham             m_queue_passed = true;
11201b54c88cSJim Ingham             break;
11211b54c88cSJim Ingham         case 'x':
11221b54c88cSJim Ingham         {
11231b54c88cSJim Ingham             m_thread_index = Args::StringToUInt64(optarg, -1, 0);
11241b54c88cSJim Ingham             if (m_thread_id == -1)
11251b54c88cSJim Ingham                error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg);
11261b54c88cSJim Ingham 
11271b54c88cSJim Ingham         }
11281b54c88cSJim Ingham         break;
11291b54c88cSJim Ingham         default:
11301b54c88cSJim Ingham             error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
11311b54c88cSJim Ingham             break;
11321b54c88cSJim Ingham     }
11331b54c88cSJim Ingham 
11341b54c88cSJim Ingham     return error;
11351b54c88cSJim Ingham }
11361b54c88cSJim Ingham 
11371b54c88cSJim Ingham void
1138ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::ResetOptionValues ()
11391b54c88cSJim Ingham {
11401b54c88cSJim Ingham     Options::ResetOptionValues();
11411b54c88cSJim Ingham 
11421b54c88cSJim Ingham     m_ignore_count = -1;
11431b54c88cSJim Ingham     m_thread_id = LLDB_INVALID_THREAD_ID;
11441b54c88cSJim Ingham     m_thread_index = -1;
11451b54c88cSJim Ingham     m_thread_name.clear();
11461b54c88cSJim Ingham     m_queue_name.clear();
1147ae1c4cf5SJim Ingham     m_enable_passed = false;
1148b2a38a72SJim Ingham     m_queue_passed = false;
1149b2a38a72SJim Ingham     m_name_passed = false;
11501b54c88cSJim Ingham }
11511b54c88cSJim Ingham 
11521b54c88cSJim Ingham //-------------------------------------------------------------------------
1153ae1c4cf5SJim Ingham // CommandObjectBreakpointModify
11541b54c88cSJim Ingham //-------------------------------------------------------------------------
1155ae1c4cf5SJim Ingham #pragma mark Modify
11561b54c88cSJim Ingham 
1157ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandObjectBreakpointModify () :
1158ae1c4cf5SJim Ingham     CommandObject ("breakpoint modify", "Modifys the options on a breakpoint or set of breakpoints in the executable.",
1159ae1c4cf5SJim Ingham                    "breakpoint modify <cmd-options> break-id [break-id ...]")
11601b54c88cSJim Ingham {
11611b54c88cSJim Ingham }
11621b54c88cSJim Ingham 
1163ae1c4cf5SJim Ingham CommandObjectBreakpointModify::~CommandObjectBreakpointModify ()
11641b54c88cSJim Ingham {
11651b54c88cSJim Ingham }
11661b54c88cSJim Ingham 
11671b54c88cSJim Ingham Options *
1168ae1c4cf5SJim Ingham CommandObjectBreakpointModify::GetOptions ()
11691b54c88cSJim Ingham {
11701b54c88cSJim Ingham     return &m_options;
11711b54c88cSJim Ingham }
11721b54c88cSJim Ingham 
11731b54c88cSJim Ingham bool
1174ae1c4cf5SJim Ingham CommandObjectBreakpointModify::Execute
11751b54c88cSJim Ingham (
1176*6611103cSGreg Clayton     CommandInterpreter &interpreter,
11771b54c88cSJim Ingham     Args& command,
11781b54c88cSJim Ingham     CommandReturnObject &result
11791b54c88cSJim Ingham )
11801b54c88cSJim Ingham {
11811b54c88cSJim Ingham     if (command.GetArgumentCount() == 0)
11821b54c88cSJim Ingham     {
11831b54c88cSJim Ingham         result.AppendError ("No breakpoints specified.");
11841b54c88cSJim Ingham         result.SetStatus (eReturnStatusFailed);
11851b54c88cSJim Ingham         return false;
11861b54c88cSJim Ingham     }
11871b54c88cSJim Ingham 
1188*6611103cSGreg Clayton     Target *target = interpreter.GetDebugger().GetCurrentTarget().get();
11891b54c88cSJim Ingham     if (target == NULL)
11901b54c88cSJim Ingham     {
11911b54c88cSJim Ingham         result.AppendError ("Invalid target, set executable file using 'file' command.");
11921b54c88cSJim Ingham         result.SetStatus (eReturnStatusFailed);
11931b54c88cSJim Ingham         return false;
11941b54c88cSJim Ingham     }
11951b54c88cSJim Ingham 
11961b54c88cSJim Ingham     Mutex::Locker locker;
11971b54c88cSJim Ingham     target->GetBreakpointList().GetListMutex(locker);
11981b54c88cSJim Ingham 
11991b54c88cSJim Ingham     BreakpointIDList valid_bp_ids;
12001b54c88cSJim Ingham 
12011b54c88cSJim Ingham     CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
12021b54c88cSJim Ingham 
12031b54c88cSJim Ingham     if (result.Succeeded())
12041b54c88cSJim Ingham     {
12051b54c88cSJim Ingham         for (int i = 0; i < valid_bp_ids.Size(); ++i)
12061b54c88cSJim Ingham         {
12071b54c88cSJim Ingham             BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
12081b54c88cSJim Ingham 
12091b54c88cSJim Ingham             if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
12101b54c88cSJim Ingham             {
12111b54c88cSJim Ingham                 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
12121b54c88cSJim Ingham                 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
12131b54c88cSJim Ingham                 {
12141b54c88cSJim Ingham                     BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
12151b54c88cSJim Ingham                     if (location)
12161b54c88cSJim Ingham                     {
12171b54c88cSJim Ingham                         if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
12181b54c88cSJim Ingham                             location->SetThreadID (m_options.m_thread_id);
12191b54c88cSJim Ingham 
12201b54c88cSJim Ingham                         if (m_options.m_thread_index != -1)
12211b54c88cSJim Ingham                             location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
12221b54c88cSJim Ingham 
1223b2a38a72SJim Ingham                         if (m_options.m_name_passed)
12241b54c88cSJim Ingham                             location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
12251b54c88cSJim Ingham 
1226b2a38a72SJim Ingham                         if (m_options.m_queue_passed)
12271b54c88cSJim Ingham                             location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
12281b54c88cSJim Ingham 
12291b54c88cSJim Ingham                         if (m_options.m_ignore_count != -1)
12301b54c88cSJim Ingham                             location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count);
1231ae1c4cf5SJim Ingham 
1232ae1c4cf5SJim Ingham                         if (m_options.m_enable_passed)
1233ae1c4cf5SJim Ingham                             location->SetEnabled (m_options.m_enable_value);
12341b54c88cSJim Ingham                     }
12351b54c88cSJim Ingham                 }
12361b54c88cSJim Ingham                 else
12371b54c88cSJim Ingham                 {
12381b54c88cSJim Ingham                     if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
12391b54c88cSJim Ingham                         bp->SetThreadID (m_options.m_thread_id);
12401b54c88cSJim Ingham 
12411b54c88cSJim Ingham                     if (m_options.m_thread_index != -1)
12421b54c88cSJim Ingham                         bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
12431b54c88cSJim Ingham 
1244b2a38a72SJim Ingham                     if (m_options.m_name_passed)
12451b54c88cSJim Ingham                         bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
12461b54c88cSJim Ingham 
1247b2a38a72SJim Ingham                     if (m_options.m_queue_passed)
12481b54c88cSJim Ingham                         bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
12491b54c88cSJim Ingham 
12501b54c88cSJim Ingham                     if (m_options.m_ignore_count != -1)
12511b54c88cSJim Ingham                         bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
1252ae1c4cf5SJim Ingham 
1253ae1c4cf5SJim Ingham                     if (m_options.m_enable_passed)
1254ae1c4cf5SJim Ingham                         bp->SetEnabled (m_options.m_enable_value);
1255ae1c4cf5SJim Ingham 
12561b54c88cSJim Ingham                 }
12571b54c88cSJim Ingham             }
12581b54c88cSJim Ingham         }
12591b54c88cSJim Ingham     }
12601b54c88cSJim Ingham 
12611b54c88cSJim Ingham     return result.Succeeded();
12621b54c88cSJim Ingham }
12631b54c88cSJim Ingham 
12641b54c88cSJim Ingham 
1265