130fdc8d8SChris Lattner //===-- CommandObjectBreakpoint.cpp -----------------------------*- C++ -*-===// 230fdc8d8SChris Lattner // 330fdc8d8SChris Lattner // The LLVM Compiler Infrastructure 430fdc8d8SChris Lattner // 530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source 630fdc8d8SChris Lattner // License. See LICENSE.TXT for details. 730fdc8d8SChris Lattner // 830fdc8d8SChris Lattner //===----------------------------------------------------------------------===// 930fdc8d8SChris Lattner 1030fdc8d8SChris Lattner #include "CommandObjectBreakpoint.h" 1130fdc8d8SChris Lattner #include "CommandObjectBreakpointCommand.h" 1230fdc8d8SChris Lattner 1330fdc8d8SChris Lattner // C Includes 1430fdc8d8SChris Lattner // C++ Includes 1530fdc8d8SChris Lattner // Other libraries and framework includes 1630fdc8d8SChris Lattner // Project includes 1730fdc8d8SChris Lattner #include "lldb/Breakpoint/Breakpoint.h" 1830fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointIDList.h" 1930fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointLocation.h" 2040af72e1SJim Ingham #include "lldb/Interpreter/Options.h" 2130fdc8d8SChris Lattner #include "lldb/Core/RegularExpression.h" 2230fdc8d8SChris Lattner #include "lldb/Core/StreamString.h" 2330fdc8d8SChris Lattner #include "lldb/Interpreter/CommandInterpreter.h" 2430fdc8d8SChris Lattner #include "lldb/Interpreter/CommandReturnObject.h" 2530fdc8d8SChris Lattner #include "lldb/Target/Target.h" 2630fdc8d8SChris Lattner #include "lldb/Interpreter/CommandCompletions.h" 2730fdc8d8SChris Lattner #include "lldb/Target/StackFrame.h" 281b54c88cSJim Ingham #include "lldb/Target/Thread.h" 291b54c88cSJim Ingham #include "lldb/Target/ThreadSpec.h" 3030fdc8d8SChris Lattner 31b7234e40SJohnny Chen #include <vector> 32b7234e40SJohnny Chen 3330fdc8d8SChris Lattner using namespace lldb; 3430fdc8d8SChris Lattner using namespace lldb_private; 3530fdc8d8SChris Lattner 3630fdc8d8SChris Lattner static void 3785e8b814SJim Ingham AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level) 3830fdc8d8SChris Lattner { 3930fdc8d8SChris Lattner s->IndentMore(); 4030fdc8d8SChris Lattner bp->GetDescription (s, level, true); 4130fdc8d8SChris Lattner s->IndentLess(); 4230fdc8d8SChris Lattner s->EOL(); 4330fdc8d8SChris Lattner } 4430fdc8d8SChris Lattner 4530fdc8d8SChris Lattner //------------------------------------------------------------------------- 4630fdc8d8SChris Lattner // CommandObjectBreakpointSet::CommandOptions 4730fdc8d8SChris Lattner //------------------------------------------------------------------------- 48ae1c4cf5SJim Ingham #pragma mark Set::CommandOptions 4930fdc8d8SChris Lattner 50eb0103f2SGreg Clayton CommandObjectBreakpointSet::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 51eb0103f2SGreg Clayton Options (interpreter), 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 (), 59969795f1SJim Ingham m_source_text_regexp(), 6030fdc8d8SChris Lattner m_modules (), 611b54c88cSJim Ingham m_load_addr(), 62c982c768SGreg Clayton m_ignore_count (0), 631b54c88cSJim Ingham m_thread_id(LLDB_INVALID_THREAD_ID), 64c982c768SGreg Clayton m_thread_index (UINT32_MAX), 651b54c88cSJim Ingham m_thread_name(), 66c982c768SGreg Clayton m_queue_name() 6730fdc8d8SChris Lattner { 6830fdc8d8SChris Lattner } 6930fdc8d8SChris Lattner 7030fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::~CommandOptions () 7130fdc8d8SChris Lattner { 7230fdc8d8SChris Lattner } 7330fdc8d8SChris Lattner 74e0d378b3SGreg Clayton OptionDefinition 7530fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::g_option_table[] = 7630fdc8d8SChris Lattner { 77deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName, 788651121cSJim Ingham "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."}, 798651121cSJim Ingham 80deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount, 81deaab222SCaroline Tice "Set the number of times this breakpoint is skipped before stopping." }, 821b54c88cSJim Ingham 83deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex, 84ed8a705cSGreg Clayton "The breakpoint stops only for the thread whose index matches this argument."}, 851b54c88cSJim Ingham 86deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, eArgTypeThreadID, 871b54c88cSJim Ingham "The breakpoint stops only for the thread whose TID matches this argument."}, 881b54c88cSJim Ingham 89deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, eArgTypeThreadName, 901b54c88cSJim Ingham "The breakpoint stops only for the thread whose thread name matches this argument."}, 911b54c88cSJim Ingham 92deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, eArgTypeQueueName, 931b54c88cSJim Ingham "The breakpoint stops only for threads in the queue whose name is given by this argument."}, 941b54c88cSJim Ingham 95969795f1SJim Ingham { LLDB_OPT_SET_1 | LLDB_OPT_SET_9, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, 9630fdc8d8SChris Lattner "Set the breakpoint by source location in this particular file."}, 9730fdc8d8SChris Lattner 98deaab222SCaroline Tice { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, 9930fdc8d8SChris Lattner "Set the breakpoint by source location at this particular line."}, 10030fdc8d8SChris Lattner 10130fdc8d8SChris Lattner // Comment out this option for the moment, as we don't actually use it, but will in the future. 10230fdc8d8SChris Lattner // This way users won't see it, but the infrastructure is left in place. 10330fdc8d8SChris Lattner // { 0, false, "column", 'c', required_argument, NULL, "<column>", 10430fdc8d8SChris Lattner // "Set the breakpoint by source location at this particular column."}, 10530fdc8d8SChris Lattner 106deaab222SCaroline Tice { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, 10730fdc8d8SChris Lattner "Set the breakpoint by address, at the specified address."}, 10830fdc8d8SChris Lattner 109deaab222SCaroline Tice { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, 110e02b8504SGreg Clayton "Set the breakpoint by function name." }, 11130fdc8d8SChris Lattner 112deaab222SCaroline Tice { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName, 1132561aa61SJim Ingham "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguemnts, and " 1142561aa61SJim Ingham "for Objective C this means a full function prototype with class and selector." }, 1150c5cd90dSGreg Clayton 116deaab222SCaroline Tice { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector, 1172561aa61SJim Ingham "Set the breakpoint by ObjC selector name." }, 1180c5cd90dSGreg Clayton 119deaab222SCaroline Tice { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod, 1202561aa61SJim Ingham "Set the breakpoint by C++ method names." }, 1210c5cd90dSGreg Clayton 122deaab222SCaroline Tice { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression, 12330fdc8d8SChris Lattner "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." }, 12430fdc8d8SChris Lattner 125e02b8504SGreg Clayton { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, 126e02b8504SGreg Clayton "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored)." }, 127e02b8504SGreg Clayton 128969795f1SJim Ingham { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', required_argument, NULL, 0, eArgTypeRegularExpression, 129969795f1SJim Ingham "Set the breakpoint specifying a regular expression to match a pattern in the source text in a given source file." }, 130969795f1SJim Ingham 131969795f1SJim Ingham 132deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 13330fdc8d8SChris Lattner }; 13430fdc8d8SChris Lattner 135e0d378b3SGreg Clayton const OptionDefinition* 13630fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::GetDefinitions () 13730fdc8d8SChris Lattner { 13830fdc8d8SChris Lattner return g_option_table; 13930fdc8d8SChris Lattner } 14030fdc8d8SChris Lattner 14130fdc8d8SChris Lattner Error 142f6b8b581SGreg Clayton CommandObjectBreakpointSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 14330fdc8d8SChris Lattner { 14430fdc8d8SChris Lattner Error error; 14530fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 14630fdc8d8SChris Lattner 14730fdc8d8SChris Lattner switch (short_option) 14830fdc8d8SChris Lattner { 14930fdc8d8SChris Lattner case 'a': 1500292f4a5SJim Ingham m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0); 15130fdc8d8SChris Lattner if (m_load_addr == LLDB_INVALID_ADDRESS) 1520292f4a5SJim Ingham m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16); 15330fdc8d8SChris Lattner 15430fdc8d8SChris Lattner if (m_load_addr == LLDB_INVALID_ADDRESS) 1550292f4a5SJim Ingham error.SetErrorStringWithFormat ("Invalid address string '%s'.\n", option_arg); 15630fdc8d8SChris Lattner break; 15730fdc8d8SChris Lattner 15830fdc8d8SChris Lattner case 'c': 15930fdc8d8SChris Lattner m_column = Args::StringToUInt32 (option_arg, 0); 16030fdc8d8SChris Lattner break; 1610c5cd90dSGreg Clayton 16230fdc8d8SChris Lattner case 'f': 163357132ebSGreg Clayton m_filename.assign (option_arg); 16430fdc8d8SChris Lattner break; 1650c5cd90dSGreg Clayton 16630fdc8d8SChris Lattner case 'l': 16730fdc8d8SChris Lattner m_line_num = Args::StringToUInt32 (option_arg, 0); 16830fdc8d8SChris Lattner break; 1690c5cd90dSGreg Clayton 170e02b8504SGreg Clayton case 'b': 171357132ebSGreg Clayton m_func_name.assign (option_arg); 1720c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeBase; 1730c5cd90dSGreg Clayton break; 1740c5cd90dSGreg Clayton 175e02b8504SGreg Clayton case 'n': 176357132ebSGreg Clayton m_func_name.assign (option_arg); 177e02b8504SGreg Clayton m_func_name_type_mask |= eFunctionNameTypeAuto; 178e02b8504SGreg Clayton break; 179e02b8504SGreg Clayton 1800c5cd90dSGreg Clayton case 'F': 181357132ebSGreg Clayton m_func_name.assign (option_arg); 1820c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeFull; 1830c5cd90dSGreg Clayton break; 1840c5cd90dSGreg Clayton 1850c5cd90dSGreg Clayton case 'S': 186357132ebSGreg Clayton m_func_name.assign (option_arg); 1870c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeSelector; 1880c5cd90dSGreg Clayton break; 1890c5cd90dSGreg Clayton 1902561aa61SJim Ingham case 'M': 191357132ebSGreg Clayton m_func_name.assign (option_arg); 1920c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeMethod; 1930c5cd90dSGreg Clayton break; 1940c5cd90dSGreg Clayton 195969795f1SJim Ingham case 'p': 196969795f1SJim Ingham m_source_text_regexp.assign (option_arg); 197969795f1SJim Ingham break; 198969795f1SJim Ingham 19930fdc8d8SChris Lattner case 'r': 200357132ebSGreg Clayton m_func_regexp.assign (option_arg); 20130fdc8d8SChris Lattner break; 2020c5cd90dSGreg Clayton 20330fdc8d8SChris Lattner case 's': 20430fdc8d8SChris Lattner { 20530fdc8d8SChris Lattner m_modules.push_back (std::string (option_arg)); 20630fdc8d8SChris Lattner break; 20730fdc8d8SChris Lattner } 208ed8a705cSGreg Clayton case 'i': 2091b54c88cSJim Ingham { 2100292f4a5SJim Ingham m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 211c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 2120292f4a5SJim Ingham error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", option_arg); 2131b54c88cSJim Ingham } 214ae1c4cf5SJim Ingham break; 2151b54c88cSJim Ingham case 't' : 2161b54c88cSJim Ingham { 2170292f4a5SJim Ingham m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 2181b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 2190292f4a5SJim Ingham error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", option_arg); 2201b54c88cSJim Ingham } 2211b54c88cSJim Ingham break; 2221b54c88cSJim Ingham case 'T': 223357132ebSGreg Clayton m_thread_name.assign (option_arg); 2241b54c88cSJim Ingham break; 2251b54c88cSJim Ingham case 'q': 226357132ebSGreg Clayton m_queue_name.assign (option_arg); 2271b54c88cSJim Ingham break; 2281b54c88cSJim Ingham case 'x': 2291b54c88cSJim Ingham { 2300292f4a5SJim Ingham m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 231c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 2320292f4a5SJim Ingham error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", option_arg); 2331b54c88cSJim Ingham 2341b54c88cSJim Ingham } 2351b54c88cSJim Ingham break; 23630fdc8d8SChris Lattner default: 23730fdc8d8SChris Lattner error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 23830fdc8d8SChris Lattner break; 23930fdc8d8SChris Lattner } 24030fdc8d8SChris Lattner 24130fdc8d8SChris Lattner return error; 24230fdc8d8SChris Lattner } 24330fdc8d8SChris Lattner 24430fdc8d8SChris Lattner void 245f6b8b581SGreg Clayton CommandObjectBreakpointSet::CommandOptions::OptionParsingStarting () 24630fdc8d8SChris Lattner { 24730fdc8d8SChris Lattner m_filename.clear(); 24830fdc8d8SChris Lattner m_line_num = 0; 24930fdc8d8SChris Lattner m_column = 0; 25030fdc8d8SChris Lattner m_func_name.clear(); 2510c5cd90dSGreg Clayton m_func_name_type_mask = 0; 25230fdc8d8SChris Lattner m_func_regexp.clear(); 25330fdc8d8SChris Lattner m_load_addr = LLDB_INVALID_ADDRESS; 25430fdc8d8SChris Lattner m_modules.clear(); 255c982c768SGreg Clayton m_ignore_count = 0; 2561b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 257c982c768SGreg Clayton m_thread_index = UINT32_MAX; 2581b54c88cSJim Ingham m_thread_name.clear(); 2591b54c88cSJim Ingham m_queue_name.clear(); 26030fdc8d8SChris Lattner } 26130fdc8d8SChris Lattner 26230fdc8d8SChris Lattner //------------------------------------------------------------------------- 26330fdc8d8SChris Lattner // CommandObjectBreakpointSet 26430fdc8d8SChris Lattner //------------------------------------------------------------------------- 265ae1c4cf5SJim Ingham #pragma mark Set 26630fdc8d8SChris Lattner 267a7015092SGreg Clayton CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) : 268a7015092SGreg Clayton CommandObject (interpreter, 269a7015092SGreg Clayton "breakpoint set", 270a7015092SGreg Clayton "Sets a breakpoint or set of breakpoints in the executable.", 271eb0103f2SGreg Clayton "breakpoint set <cmd-options>"), 272eb0103f2SGreg Clayton m_options (interpreter) 27330fdc8d8SChris Lattner { 27430fdc8d8SChris Lattner } 27530fdc8d8SChris Lattner 27630fdc8d8SChris Lattner CommandObjectBreakpointSet::~CommandObjectBreakpointSet () 27730fdc8d8SChris Lattner { 27830fdc8d8SChris Lattner } 27930fdc8d8SChris Lattner 28030fdc8d8SChris Lattner Options * 28130fdc8d8SChris Lattner CommandObjectBreakpointSet::GetOptions () 28230fdc8d8SChris Lattner { 28330fdc8d8SChris Lattner return &m_options; 28430fdc8d8SChris Lattner } 28530fdc8d8SChris Lattner 28630fdc8d8SChris Lattner bool 287969795f1SJim Ingham CommandObjectBreakpointSet::ChooseFile (Target *target, FileSpec &file, CommandReturnObject &result) 288969795f1SJim Ingham { 289969795f1SJim Ingham if (m_options.m_filename.empty()) 290969795f1SJim Ingham { 291969795f1SJim Ingham uint32_t default_line; 292969795f1SJim Ingham // First use the Source Manager's default file. 293969795f1SJim Ingham // Then use the current stack frame's file. 294969795f1SJim Ingham if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) 295969795f1SJim Ingham { 296*c14ee32dSGreg Clayton StackFrame *cur_frame = m_interpreter.GetExecutionContext().GetFramePtr(); 297969795f1SJim Ingham if (cur_frame == NULL) 298969795f1SJim Ingham { 299969795f1SJim Ingham result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame."); 300969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 301969795f1SJim Ingham return false; 302969795f1SJim Ingham } 303969795f1SJim Ingham else if (!cur_frame->HasDebugInformation()) 304969795f1SJim Ingham { 305969795f1SJim Ingham result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info."); 306969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 307969795f1SJim Ingham return false; 308969795f1SJim Ingham } 309969795f1SJim Ingham else 310969795f1SJim Ingham { 311969795f1SJim Ingham const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry); 312969795f1SJim Ingham if (sc.line_entry.file) 313969795f1SJim Ingham { 314969795f1SJim Ingham file = sc.line_entry.file; 315969795f1SJim Ingham } 316969795f1SJim Ingham else 317969795f1SJim Ingham { 318969795f1SJim Ingham result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame."); 319969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 320969795f1SJim Ingham return false; 321969795f1SJim Ingham } 322969795f1SJim Ingham } 323969795f1SJim Ingham } 324969795f1SJim Ingham } 325969795f1SJim Ingham else 326969795f1SJim Ingham { 327969795f1SJim Ingham file.SetFile(m_options.m_filename.c_str(), false); 328969795f1SJim Ingham } 329969795f1SJim Ingham return true; 330969795f1SJim Ingham } 331969795f1SJim Ingham 332969795f1SJim Ingham bool 33330fdc8d8SChris Lattner CommandObjectBreakpointSet::Execute 33430fdc8d8SChris Lattner ( 33530fdc8d8SChris Lattner Args& command, 33630fdc8d8SChris Lattner CommandReturnObject &result 33730fdc8d8SChris Lattner ) 33830fdc8d8SChris Lattner { 339a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 34030fdc8d8SChris Lattner if (target == NULL) 34130fdc8d8SChris Lattner { 342effe5c95SGreg Clayton result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command)."); 34330fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 34430fdc8d8SChris Lattner return false; 34530fdc8d8SChris Lattner } 34630fdc8d8SChris Lattner 34730fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 34830fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 34930fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 35030fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 35130fdc8d8SChris Lattner // 4). -r [-s -g] (setting breakpoint by function name regular expression) 352969795f1SJim Ingham // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text) 35330fdc8d8SChris Lattner 35430fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 35530fdc8d8SChris Lattner 35630fdc8d8SChris Lattner if (m_options.m_line_num != 0) 35730fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 35830fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 35930fdc8d8SChris Lattner break_type = eSetTypeAddress; 36030fdc8d8SChris Lattner else if (!m_options.m_func_name.empty()) 36130fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 36230fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 36330fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 364969795f1SJim Ingham else if (!m_options.m_source_text_regexp.empty()) 365969795f1SJim Ingham break_type = eSetTypeSourceRegexp; 36630fdc8d8SChris Lattner 36730fdc8d8SChris Lattner Breakpoint *bp = NULL; 368274060b6SGreg Clayton FileSpec module_spec; 36930fdc8d8SChris Lattner bool use_module = false; 37030fdc8d8SChris Lattner int num_modules = m_options.m_modules.size(); 37130fdc8d8SChris Lattner 372969795f1SJim Ingham FileSpecList module_spec_list; 373969795f1SJim Ingham FileSpecList *module_spec_list_ptr = NULL; 374969795f1SJim Ingham 37530fdc8d8SChris Lattner if ((num_modules > 0) && (break_type != eSetTypeAddress)) 37630fdc8d8SChris Lattner use_module = true; 37730fdc8d8SChris Lattner 378969795f1SJim Ingham if (use_module) 379969795f1SJim Ingham { 380969795f1SJim Ingham module_spec_list_ptr = &module_spec_list; 381969795f1SJim Ingham for (int i = 0; i < num_modules; ++i) 382969795f1SJim Ingham { 383969795f1SJim Ingham module_spec.SetFile(m_options.m_modules[i].c_str(), false); 384969795f1SJim Ingham module_spec_list.AppendIfUnique (module_spec); 385969795f1SJim Ingham } 386969795f1SJim Ingham } 387969795f1SJim Ingham 38830fdc8d8SChris Lattner switch (break_type) 38930fdc8d8SChris Lattner { 39030fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 39130fdc8d8SChris Lattner { 39230fdc8d8SChris Lattner FileSpec file; 393969795f1SJim Ingham if (!ChooseFile (target, file, result)) 39430fdc8d8SChris Lattner break; 39530fdc8d8SChris Lattner 396969795f1SJim Ingham bp = target->CreateBreakpoint (module_spec_list_ptr, 39730fdc8d8SChris Lattner file, 39830fdc8d8SChris Lattner m_options.m_line_num, 3992856d462SGreg Clayton m_options.m_check_inlines).get(); 40030fdc8d8SChris Lattner } 40130fdc8d8SChris Lattner break; 4026eee5aa0SGreg Clayton 40330fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 40430fdc8d8SChris Lattner bp = target->CreateBreakpoint (m_options.m_load_addr, false).get(); 40530fdc8d8SChris Lattner break; 4060c5cd90dSGreg Clayton 40730fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 4080c5cd90dSGreg Clayton { 4090c5cd90dSGreg Clayton uint32_t name_type_mask = m_options.m_func_name_type_mask; 4100c5cd90dSGreg Clayton 4110c5cd90dSGreg Clayton if (name_type_mask == 0) 412e02b8504SGreg Clayton name_type_mask = eFunctionNameTypeAuto; 4130c5cd90dSGreg Clayton 414969795f1SJim Ingham bp = target->CreateBreakpoint (module_spec_list_ptr, 415274060b6SGreg Clayton m_options.m_func_name.c_str(), 416274060b6SGreg Clayton name_type_mask, 417274060b6SGreg Clayton Breakpoint::Exact).get(); 4180c5cd90dSGreg Clayton } 41930fdc8d8SChris Lattner break; 4200c5cd90dSGreg Clayton 42130fdc8d8SChris Lattner case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name 42230fdc8d8SChris Lattner { 42330fdc8d8SChris Lattner RegularExpression regexp(m_options.m_func_regexp.c_str()); 424969795f1SJim Ingham if (!regexp.IsValid()) 42530fdc8d8SChris Lattner { 426969795f1SJim Ingham char err_str[1024]; 427969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 428969795f1SJim Ingham result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"", 429969795f1SJim Ingham err_str); 43030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 431969795f1SJim Ingham return false; 43230fdc8d8SChris Lattner } 433969795f1SJim Ingham bp = target->CreateBreakpoint (module_spec_list_ptr, regexp).get(); 43430fdc8d8SChris Lattner } 43530fdc8d8SChris Lattner break; 436969795f1SJim Ingham case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. 437969795f1SJim Ingham { 438969795f1SJim Ingham FileSpec file; 439969795f1SJim Ingham if (!ChooseFile (target, file, result)) 440969795f1SJim Ingham break; 4410c5cd90dSGreg Clayton 442969795f1SJim Ingham RegularExpression regexp(m_options.m_source_text_regexp.c_str()); 443969795f1SJim Ingham if (!regexp.IsValid()) 444969795f1SJim Ingham { 445969795f1SJim Ingham char err_str[1024]; 446969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 447969795f1SJim Ingham result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"", 448969795f1SJim Ingham err_str); 449969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 450969795f1SJim Ingham return false; 451969795f1SJim Ingham } 452969795f1SJim Ingham bp = target->CreateBreakpoint (module_spec_list_ptr, file, regexp).get(); 453969795f1SJim Ingham } 454969795f1SJim Ingham break; 45530fdc8d8SChris Lattner default: 45630fdc8d8SChris Lattner break; 45730fdc8d8SChris Lattner } 45830fdc8d8SChris Lattner 4591b54c88cSJim Ingham // Now set the various options that were passed in: 4601b54c88cSJim Ingham if (bp) 4611b54c88cSJim Ingham { 4621b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 4631b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 4641b54c88cSJim Ingham 465c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 4661b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 4671b54c88cSJim Ingham 4681b54c88cSJim Ingham if (!m_options.m_thread_name.empty()) 4691b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 4701b54c88cSJim Ingham 4711b54c88cSJim Ingham if (!m_options.m_queue_name.empty()) 4721b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 4731b54c88cSJim Ingham 474c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 4751b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 4761b54c88cSJim Ingham } 4771b54c88cSJim Ingham 478969795f1SJim Ingham if (bp) 47930fdc8d8SChris Lattner { 48085e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 48130fdc8d8SChris Lattner output_stream.Printf ("Breakpoint created: "); 48230fdc8d8SChris Lattner bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); 48330fdc8d8SChris Lattner output_stream.EOL(); 484be484f41SCaroline Tice if (bp->GetNumLocations() == 0) 485be484f41SCaroline Tice output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n"); 48630fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 48730fdc8d8SChris Lattner } 48830fdc8d8SChris Lattner else if (!bp) 48930fdc8d8SChris Lattner { 49030fdc8d8SChris Lattner result.AppendError ("Breakpoint creation failed: No breakpoint created."); 49130fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 49230fdc8d8SChris Lattner } 49330fdc8d8SChris Lattner 49430fdc8d8SChris Lattner return result.Succeeded(); 49530fdc8d8SChris Lattner } 49630fdc8d8SChris Lattner 49730fdc8d8SChris Lattner //------------------------------------------------------------------------- 49830fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 49930fdc8d8SChris Lattner //------------------------------------------------------------------------- 500ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 50130fdc8d8SChris Lattner 5026611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) : 503a7015092SGreg Clayton CommandObjectMultiword (interpreter, 504a7015092SGreg Clayton "breakpoint", 50546fbc60fSJim Ingham "A set of commands for operating on breakpoints. Also see _regexp-break.", 50630fdc8d8SChris Lattner "breakpoint <command> [<command-options>]") 50730fdc8d8SChris Lattner { 50830fdc8d8SChris Lattner bool status; 50930fdc8d8SChris Lattner 510a7015092SGreg Clayton CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter)); 511a7015092SGreg Clayton CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter)); 512a7015092SGreg Clayton CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter)); 513b7234e40SJohnny Chen CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter)); 514b7234e40SJohnny Chen CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter)); 515a7015092SGreg Clayton CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter)); 51630fdc8d8SChris Lattner CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter)); 517a7015092SGreg Clayton CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter)); 51830fdc8d8SChris Lattner 519b7234e40SJohnny Chen list_command_object->SetCommandName ("breakpoint list"); 52030fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 52130fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 522b7234e40SJohnny Chen clear_command_object->SetCommandName("breakpoint clear"); 523b7234e40SJohnny Chen delete_command_object->SetCommandName("breakpoint delete"); 524ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 525b7234e40SJohnny Chen command_command_object->SetCommandName ("breakpoint command"); 526b7234e40SJohnny Chen modify_command_object->SetCommandName ("breakpoint modify"); 52730fdc8d8SChris Lattner 528a7015092SGreg Clayton status = LoadSubCommand ("list", list_command_object); 529a7015092SGreg Clayton status = LoadSubCommand ("enable", enable_command_object); 530a7015092SGreg Clayton status = LoadSubCommand ("disable", disable_command_object); 531b7234e40SJohnny Chen status = LoadSubCommand ("clear", clear_command_object); 532a7015092SGreg Clayton status = LoadSubCommand ("delete", delete_command_object); 533a7015092SGreg Clayton status = LoadSubCommand ("set", set_command_object); 534a7015092SGreg Clayton status = LoadSubCommand ("command", command_command_object); 535a7015092SGreg Clayton status = LoadSubCommand ("modify", modify_command_object); 53630fdc8d8SChris Lattner } 53730fdc8d8SChris Lattner 53830fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint () 53930fdc8d8SChris Lattner { 54030fdc8d8SChris Lattner } 54130fdc8d8SChris Lattner 54230fdc8d8SChris Lattner void 54330fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result, 54430fdc8d8SChris Lattner BreakpointIDList *valid_ids) 54530fdc8d8SChris Lattner { 54630fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 54730fdc8d8SChris Lattner // 2). the full breakpoint & location canonical representation 54830fdc8d8SChris Lattner // 3). the word "to" or a hyphen, representing a range (in which case there 54930fdc8d8SChris Lattner // had *better* be an entry both before & after of one of the first two types. 55036f3b369SJim Ingham // If args is empty, we will use the last created breakpoint (if there is one.) 55130fdc8d8SChris Lattner 55230fdc8d8SChris Lattner Args temp_args; 55330fdc8d8SChris Lattner 55436f3b369SJim Ingham if (args.GetArgumentCount() == 0) 55536f3b369SJim Ingham { 5564d122c40SGreg Clayton if (target->GetLastCreatedBreakpoint()) 55736f3b369SJim Ingham { 55836f3b369SJim Ingham valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); 55936f3b369SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 56036f3b369SJim Ingham } 56136f3b369SJim Ingham else 56236f3b369SJim Ingham { 56336f3b369SJim Ingham result.AppendError("No breakpoint specified and no last created breakpoint."); 56436f3b369SJim Ingham result.SetStatus (eReturnStatusFailed); 56536f3b369SJim Ingham } 56636f3b369SJim Ingham return; 56736f3b369SJim Ingham } 56836f3b369SJim Ingham 56930fdc8d8SChris Lattner // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to 57030fdc8d8SChris Lattner // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for 57130fdc8d8SChris Lattner // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS. 57230fdc8d8SChris Lattner 57330fdc8d8SChris Lattner BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args); 57430fdc8d8SChris Lattner 57530fdc8d8SChris Lattner // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList: 57630fdc8d8SChris Lattner 577c982c768SGreg Clayton valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result); 57830fdc8d8SChris Lattner 57930fdc8d8SChris Lattner // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs 58030fdc8d8SChris Lattner // and put into valid_ids. 58130fdc8d8SChris Lattner 58230fdc8d8SChris Lattner if (result.Succeeded()) 58330fdc8d8SChris Lattner { 58430fdc8d8SChris Lattner // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list 58530fdc8d8SChris Lattner // of breakpoint id's and verify that they correspond to valid/currently set breakpoints. 58630fdc8d8SChris Lattner 587c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 588c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 58930fdc8d8SChris Lattner { 59030fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i); 59130fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 59230fdc8d8SChris Lattner if (breakpoint != NULL) 59330fdc8d8SChris Lattner { 59430fdc8d8SChris Lattner int num_locations = breakpoint->GetNumLocations(); 59530fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() > num_locations) 59630fdc8d8SChris Lattner { 59730fdc8d8SChris Lattner StreamString id_str; 598c982c768SGreg Clayton BreakpointID::GetCanonicalReference (&id_str, 599c982c768SGreg Clayton cur_bp_id.GetBreakpointID(), 60030fdc8d8SChris Lattner cur_bp_id.GetLocationID()); 601c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 60230fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n", 60330fdc8d8SChris Lattner id_str.GetData()); 60430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 60530fdc8d8SChris Lattner } 60630fdc8d8SChris Lattner } 60730fdc8d8SChris Lattner else 60830fdc8d8SChris Lattner { 609c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 61030fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID()); 61130fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 61230fdc8d8SChris Lattner } 61330fdc8d8SChris Lattner } 61430fdc8d8SChris Lattner } 61530fdc8d8SChris Lattner } 61630fdc8d8SChris Lattner 61730fdc8d8SChris Lattner //------------------------------------------------------------------------- 61830fdc8d8SChris Lattner // CommandObjectBreakpointList::Options 61930fdc8d8SChris Lattner //------------------------------------------------------------------------- 620ae1c4cf5SJim Ingham #pragma mark List::CommandOptions 62130fdc8d8SChris Lattner 622eb0103f2SGreg Clayton CommandObjectBreakpointList::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 623eb0103f2SGreg Clayton Options (interpreter), 62479042b3eSCaroline Tice m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions 62530fdc8d8SChris Lattner { 62630fdc8d8SChris Lattner } 62730fdc8d8SChris Lattner 62830fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::~CommandOptions () 62930fdc8d8SChris Lattner { 63030fdc8d8SChris Lattner } 63130fdc8d8SChris Lattner 632e0d378b3SGreg Clayton OptionDefinition 63330fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::g_option_table[] = 63430fdc8d8SChris Lattner { 635deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone, 6368651121cSJim Ingham "Show debugger internal breakpoints" }, 6378651121cSJim Ingham 638deaab222SCaroline Tice { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone, 63930fdc8d8SChris Lattner "Give a brief description of the breakpoint (no location info)."}, 64030fdc8d8SChris Lattner 64130fdc8d8SChris Lattner // FIXME: We need to add an "internal" command, and then add this sort of thing to it. 64230fdc8d8SChris Lattner // But I need to see it for now, and don't want to wait. 643deaab222SCaroline Tice { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone, 64430fdc8d8SChris Lattner "Give a full description of the breakpoint and its locations."}, 64530fdc8d8SChris Lattner 646deaab222SCaroline Tice { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, 64730fdc8d8SChris Lattner "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, 64830fdc8d8SChris Lattner 649deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 65030fdc8d8SChris Lattner }; 65130fdc8d8SChris Lattner 652e0d378b3SGreg Clayton const OptionDefinition* 65330fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::GetDefinitions () 65430fdc8d8SChris Lattner { 65530fdc8d8SChris Lattner return g_option_table; 65630fdc8d8SChris Lattner } 65730fdc8d8SChris Lattner 65830fdc8d8SChris Lattner Error 659f6b8b581SGreg Clayton CommandObjectBreakpointList::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 66030fdc8d8SChris Lattner { 66130fdc8d8SChris Lattner Error error; 66230fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 66330fdc8d8SChris Lattner 66430fdc8d8SChris Lattner switch (short_option) 66530fdc8d8SChris Lattner { 66630fdc8d8SChris Lattner case 'b': 66730fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelBrief; 66830fdc8d8SChris Lattner break; 66930fdc8d8SChris Lattner case 'f': 67030fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelFull; 67130fdc8d8SChris Lattner break; 67230fdc8d8SChris Lattner case 'v': 67330fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelVerbose; 67430fdc8d8SChris Lattner break; 67530fdc8d8SChris Lattner case 'i': 67630fdc8d8SChris Lattner m_internal = true; 67730fdc8d8SChris Lattner break; 67830fdc8d8SChris Lattner default: 67930fdc8d8SChris Lattner error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 68030fdc8d8SChris Lattner break; 68130fdc8d8SChris Lattner } 68230fdc8d8SChris Lattner 68330fdc8d8SChris Lattner return error; 68430fdc8d8SChris Lattner } 68530fdc8d8SChris Lattner 68630fdc8d8SChris Lattner void 687f6b8b581SGreg Clayton CommandObjectBreakpointList::CommandOptions::OptionParsingStarting () 68830fdc8d8SChris Lattner { 689d915e16fSJim Ingham m_level = lldb::eDescriptionLevelFull; 69030fdc8d8SChris Lattner m_internal = false; 69130fdc8d8SChris Lattner } 69230fdc8d8SChris Lattner 69330fdc8d8SChris Lattner //------------------------------------------------------------------------- 69430fdc8d8SChris Lattner // CommandObjectBreakpointList 69530fdc8d8SChris Lattner //------------------------------------------------------------------------- 696ae1c4cf5SJim Ingham #pragma mark List 69730fdc8d8SChris Lattner 698a7015092SGreg Clayton CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) : 699a7015092SGreg Clayton CommandObject (interpreter, 700a7015092SGreg Clayton "breakpoint list", 70130fdc8d8SChris Lattner "List some or all breakpoints at configurable levels of detail.", 702eb0103f2SGreg Clayton NULL), 703eb0103f2SGreg Clayton m_options (interpreter) 70430fdc8d8SChris Lattner { 705e139cf23SCaroline Tice CommandArgumentEntry arg; 706e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 707e139cf23SCaroline Tice 708e139cf23SCaroline Tice // Define the first (and only) variant of this arg. 709e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 710405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 711e139cf23SCaroline Tice 712e139cf23SCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 713e139cf23SCaroline Tice arg.push_back (bp_id_arg); 714e139cf23SCaroline Tice 715e139cf23SCaroline Tice // Push the data for the first argument into the m_arguments vector. 716e139cf23SCaroline Tice m_arguments.push_back (arg); 71730fdc8d8SChris Lattner } 71830fdc8d8SChris Lattner 71930fdc8d8SChris Lattner CommandObjectBreakpointList::~CommandObjectBreakpointList () 72030fdc8d8SChris Lattner { 72130fdc8d8SChris Lattner } 72230fdc8d8SChris Lattner 72330fdc8d8SChris Lattner Options * 72430fdc8d8SChris Lattner CommandObjectBreakpointList::GetOptions () 72530fdc8d8SChris Lattner { 72630fdc8d8SChris Lattner return &m_options; 72730fdc8d8SChris Lattner } 72830fdc8d8SChris Lattner 72930fdc8d8SChris Lattner bool 73030fdc8d8SChris Lattner CommandObjectBreakpointList::Execute 73130fdc8d8SChris Lattner ( 73230fdc8d8SChris Lattner Args& args, 73330fdc8d8SChris Lattner CommandReturnObject &result 73430fdc8d8SChris Lattner ) 73530fdc8d8SChris Lattner { 736a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 73730fdc8d8SChris Lattner if (target == NULL) 73830fdc8d8SChris Lattner { 7399068d794SCaroline Tice result.AppendError ("Invalid target. No current target or breakpoints."); 74030fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 74130fdc8d8SChris Lattner return true; 74230fdc8d8SChris Lattner } 74330fdc8d8SChris Lattner 74430fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal); 7451b54c88cSJim Ingham Mutex::Locker locker; 7461b54c88cSJim Ingham target->GetBreakpointList(m_options.m_internal).GetListMutex(locker); 7471b54c88cSJim Ingham 74830fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 74930fdc8d8SChris Lattner 75030fdc8d8SChris Lattner if (num_breakpoints == 0) 75130fdc8d8SChris Lattner { 75230fdc8d8SChris Lattner result.AppendMessage ("No breakpoints currently set."); 75330fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 75430fdc8d8SChris Lattner return true; 75530fdc8d8SChris Lattner } 75630fdc8d8SChris Lattner 75785e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 75830fdc8d8SChris Lattner 75930fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 76030fdc8d8SChris Lattner { 76130fdc8d8SChris Lattner // No breakpoint selected; show info about all currently set breakpoints. 76230fdc8d8SChris Lattner result.AppendMessage ("Current breakpoints:"); 763c982c768SGreg Clayton for (size_t i = 0; i < num_breakpoints; ++i) 76430fdc8d8SChris Lattner { 7659fed0d85SGreg Clayton Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get(); 7666611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 76730fdc8d8SChris Lattner } 76830fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 76930fdc8d8SChris Lattner } 77030fdc8d8SChris Lattner else 77130fdc8d8SChris Lattner { 77230fdc8d8SChris Lattner // Particular breakpoints selected; show info about that breakpoint. 77330fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 77430fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 77530fdc8d8SChris Lattner 77630fdc8d8SChris Lattner if (result.Succeeded()) 77730fdc8d8SChris Lattner { 778c982c768SGreg Clayton for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) 77930fdc8d8SChris Lattner { 78030fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 78130fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 7826611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 78330fdc8d8SChris Lattner } 78430fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 78530fdc8d8SChris Lattner } 78630fdc8d8SChris Lattner else 78730fdc8d8SChris Lattner { 78830fdc8d8SChris Lattner result.AppendError ("Invalid breakpoint id."); 78930fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 79030fdc8d8SChris Lattner } 79130fdc8d8SChris Lattner } 79230fdc8d8SChris Lattner 79330fdc8d8SChris Lattner return result.Succeeded(); 79430fdc8d8SChris Lattner } 79530fdc8d8SChris Lattner 79630fdc8d8SChris Lattner //------------------------------------------------------------------------- 79730fdc8d8SChris Lattner // CommandObjectBreakpointEnable 79830fdc8d8SChris Lattner //------------------------------------------------------------------------- 799ae1c4cf5SJim Ingham #pragma mark Enable 80030fdc8d8SChris Lattner 801a7015092SGreg Clayton CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) : 802a7015092SGreg Clayton CommandObject (interpreter, 803a7015092SGreg Clayton "enable", 804e3d26315SCaroline Tice "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.", 805e139cf23SCaroline Tice NULL) 80630fdc8d8SChris Lattner { 807e139cf23SCaroline Tice CommandArgumentEntry arg; 808184d7a72SJohnny Chen CommandObject::AddIDsArgumentData(arg); 809e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 810e139cf23SCaroline Tice m_arguments.push_back (arg); 81130fdc8d8SChris Lattner } 81230fdc8d8SChris Lattner 81330fdc8d8SChris Lattner 81430fdc8d8SChris Lattner CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable () 81530fdc8d8SChris Lattner { 81630fdc8d8SChris Lattner } 81730fdc8d8SChris Lattner 81830fdc8d8SChris Lattner 81930fdc8d8SChris Lattner bool 8206611103cSGreg Clayton CommandObjectBreakpointEnable::Execute 8216611103cSGreg Clayton ( 8226611103cSGreg Clayton Args& args, 8236611103cSGreg Clayton CommandReturnObject &result 8246611103cSGreg Clayton ) 82530fdc8d8SChris Lattner { 826a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 82730fdc8d8SChris Lattner if (target == NULL) 82830fdc8d8SChris Lattner { 8299068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 83030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 83130fdc8d8SChris Lattner return false; 83230fdc8d8SChris Lattner } 83330fdc8d8SChris Lattner 8341b54c88cSJim Ingham Mutex::Locker locker; 8351b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 8361b54c88cSJim Ingham 83730fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 8381b54c88cSJim Ingham 83930fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 84030fdc8d8SChris Lattner 84130fdc8d8SChris Lattner if (num_breakpoints == 0) 84230fdc8d8SChris Lattner { 84330fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be enabled."); 84430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 84530fdc8d8SChris Lattner return false; 84630fdc8d8SChris Lattner } 84730fdc8d8SChris Lattner 84830fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 84930fdc8d8SChris Lattner { 85030fdc8d8SChris Lattner // No breakpoint selected; enable all currently set breakpoints. 85130fdc8d8SChris Lattner target->EnableAllBreakpoints (); 852fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints enabled. (%lu breakpoints)\n", num_breakpoints); 85330fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 85430fdc8d8SChris Lattner } 85530fdc8d8SChris Lattner else 85630fdc8d8SChris Lattner { 85730fdc8d8SChris Lattner // Particular breakpoint selected; enable that breakpoint. 85830fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 85930fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 86030fdc8d8SChris Lattner 86130fdc8d8SChris Lattner if (result.Succeeded()) 86230fdc8d8SChris Lattner { 86330fdc8d8SChris Lattner int enable_count = 0; 86430fdc8d8SChris Lattner int loc_count = 0; 865c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 866c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 86730fdc8d8SChris Lattner { 86830fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 86930fdc8d8SChris Lattner 87030fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 87130fdc8d8SChris Lattner { 87230fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 87330fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 87430fdc8d8SChris Lattner { 87530fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 87630fdc8d8SChris Lattner if (location) 87730fdc8d8SChris Lattner { 87830fdc8d8SChris Lattner location->SetEnabled (true); 87930fdc8d8SChris Lattner ++loc_count; 88030fdc8d8SChris Lattner } 88130fdc8d8SChris Lattner } 88230fdc8d8SChris Lattner else 88330fdc8d8SChris Lattner { 884ae1c4cf5SJim Ingham breakpoint->SetEnabled (true); 88530fdc8d8SChris Lattner ++enable_count; 88630fdc8d8SChris Lattner } 88730fdc8d8SChris Lattner } 88830fdc8d8SChris Lattner } 88930fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count); 89030fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 89130fdc8d8SChris Lattner } 89230fdc8d8SChris Lattner } 89330fdc8d8SChris Lattner 89430fdc8d8SChris Lattner return result.Succeeded(); 89530fdc8d8SChris Lattner } 89630fdc8d8SChris Lattner 89730fdc8d8SChris Lattner //------------------------------------------------------------------------- 89830fdc8d8SChris Lattner // CommandObjectBreakpointDisable 89930fdc8d8SChris Lattner //------------------------------------------------------------------------- 900ae1c4cf5SJim Ingham #pragma mark Disable 90130fdc8d8SChris Lattner 902a7015092SGreg Clayton CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) : 903a7015092SGreg Clayton CommandObject (interpreter, 904e139cf23SCaroline Tice "breakpoint disable", 905e3d26315SCaroline Tice "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.", 906e139cf23SCaroline Tice NULL) 90730fdc8d8SChris Lattner { 908e139cf23SCaroline Tice CommandArgumentEntry arg; 909184d7a72SJohnny Chen CommandObject::AddIDsArgumentData(arg); 910e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 911e139cf23SCaroline Tice m_arguments.push_back (arg); 91230fdc8d8SChris Lattner } 91330fdc8d8SChris Lattner 91430fdc8d8SChris Lattner CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable () 91530fdc8d8SChris Lattner { 91630fdc8d8SChris Lattner } 91730fdc8d8SChris Lattner 91830fdc8d8SChris Lattner bool 9196611103cSGreg Clayton CommandObjectBreakpointDisable::Execute 9206611103cSGreg Clayton ( 9216611103cSGreg Clayton Args& args, 9226611103cSGreg Clayton CommandReturnObject &result 9236611103cSGreg Clayton ) 92430fdc8d8SChris Lattner { 925a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 92630fdc8d8SChris Lattner if (target == NULL) 92730fdc8d8SChris Lattner { 9289068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 92930fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 93030fdc8d8SChris Lattner return false; 93130fdc8d8SChris Lattner } 93230fdc8d8SChris Lattner 9331b54c88cSJim Ingham Mutex::Locker locker; 9341b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 9351b54c88cSJim Ingham 93630fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 93730fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 93830fdc8d8SChris Lattner 93930fdc8d8SChris Lattner if (num_breakpoints == 0) 94030fdc8d8SChris Lattner { 94130fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be disabled."); 94230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 94330fdc8d8SChris Lattner return false; 94430fdc8d8SChris Lattner } 94530fdc8d8SChris Lattner 94630fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 94730fdc8d8SChris Lattner { 94830fdc8d8SChris Lattner // No breakpoint selected; disable all currently set breakpoints. 94930fdc8d8SChris Lattner target->DisableAllBreakpoints (); 950fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints disabled. (%lu breakpoints)\n", num_breakpoints); 95130fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 95230fdc8d8SChris Lattner } 95330fdc8d8SChris Lattner else 95430fdc8d8SChris Lattner { 95530fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 95630fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 95730fdc8d8SChris Lattner 95830fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 95930fdc8d8SChris Lattner 96030fdc8d8SChris Lattner if (result.Succeeded()) 96130fdc8d8SChris Lattner { 96230fdc8d8SChris Lattner int disable_count = 0; 96330fdc8d8SChris Lattner int loc_count = 0; 964c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 965c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 96630fdc8d8SChris Lattner { 96730fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 96830fdc8d8SChris Lattner 96930fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 97030fdc8d8SChris Lattner { 97130fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 97230fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 97330fdc8d8SChris Lattner { 97430fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 97530fdc8d8SChris Lattner if (location) 97630fdc8d8SChris Lattner { 97730fdc8d8SChris Lattner location->SetEnabled (false); 97830fdc8d8SChris Lattner ++loc_count; 97930fdc8d8SChris Lattner } 98030fdc8d8SChris Lattner } 98130fdc8d8SChris Lattner else 98230fdc8d8SChris Lattner { 983ae1c4cf5SJim Ingham breakpoint->SetEnabled (false); 98430fdc8d8SChris Lattner ++disable_count; 98530fdc8d8SChris Lattner } 98630fdc8d8SChris Lattner } 98730fdc8d8SChris Lattner } 98830fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count); 98930fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 99030fdc8d8SChris Lattner } 99130fdc8d8SChris Lattner } 99230fdc8d8SChris Lattner 99330fdc8d8SChris Lattner return result.Succeeded(); 99430fdc8d8SChris Lattner } 99530fdc8d8SChris Lattner 99630fdc8d8SChris Lattner //------------------------------------------------------------------------- 997b7234e40SJohnny Chen // CommandObjectBreakpointClear::CommandOptions 998b7234e40SJohnny Chen //------------------------------------------------------------------------- 999b7234e40SJohnny Chen #pragma mark Clear::CommandOptions 1000b7234e40SJohnny Chen 1001eb0103f2SGreg Clayton CommandObjectBreakpointClear::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 1002eb0103f2SGreg Clayton Options (interpreter), 1003b7234e40SJohnny Chen m_filename (), 1004b7234e40SJohnny Chen m_line_num (0) 1005b7234e40SJohnny Chen { 1006b7234e40SJohnny Chen } 1007b7234e40SJohnny Chen 1008b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::~CommandOptions () 1009b7234e40SJohnny Chen { 1010b7234e40SJohnny Chen } 1011b7234e40SJohnny Chen 1012e0d378b3SGreg Clayton OptionDefinition 1013b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::g_option_table[] = 1014b7234e40SJohnny Chen { 1015b7234e40SJohnny Chen { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, 1016b7234e40SJohnny Chen "Specify the breakpoint by source location in this particular file."}, 1017b7234e40SJohnny Chen 1018b7234e40SJohnny Chen { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, 1019b7234e40SJohnny Chen "Specify the breakpoint by source location at this particular line."}, 1020b7234e40SJohnny Chen 1021b7234e40SJohnny Chen { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 1022b7234e40SJohnny Chen }; 1023b7234e40SJohnny Chen 1024e0d378b3SGreg Clayton const OptionDefinition* 1025b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::GetDefinitions () 1026b7234e40SJohnny Chen { 1027b7234e40SJohnny Chen return g_option_table; 1028b7234e40SJohnny Chen } 1029b7234e40SJohnny Chen 1030b7234e40SJohnny Chen Error 1031f6b8b581SGreg Clayton CommandObjectBreakpointClear::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 1032b7234e40SJohnny Chen { 1033b7234e40SJohnny Chen Error error; 1034b7234e40SJohnny Chen char short_option = (char) m_getopt_table[option_idx].val; 1035b7234e40SJohnny Chen 1036b7234e40SJohnny Chen switch (short_option) 1037b7234e40SJohnny Chen { 1038b7234e40SJohnny Chen case 'f': 1039357132ebSGreg Clayton m_filename.assign (option_arg); 1040b7234e40SJohnny Chen break; 1041b7234e40SJohnny Chen 1042b7234e40SJohnny Chen case 'l': 1043b7234e40SJohnny Chen m_line_num = Args::StringToUInt32 (option_arg, 0); 1044b7234e40SJohnny Chen break; 1045b7234e40SJohnny Chen 1046b7234e40SJohnny Chen default: 1047b7234e40SJohnny Chen error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 1048b7234e40SJohnny Chen break; 1049b7234e40SJohnny Chen } 1050b7234e40SJohnny Chen 1051b7234e40SJohnny Chen return error; 1052b7234e40SJohnny Chen } 1053b7234e40SJohnny Chen 1054b7234e40SJohnny Chen void 1055f6b8b581SGreg Clayton CommandObjectBreakpointClear::CommandOptions::OptionParsingStarting () 1056b7234e40SJohnny Chen { 1057b7234e40SJohnny Chen m_filename.clear(); 1058b7234e40SJohnny Chen m_line_num = 0; 1059b7234e40SJohnny Chen } 1060b7234e40SJohnny Chen 1061b7234e40SJohnny Chen //------------------------------------------------------------------------- 1062b7234e40SJohnny Chen // CommandObjectBreakpointClear 1063b7234e40SJohnny Chen //------------------------------------------------------------------------- 1064b7234e40SJohnny Chen #pragma mark Clear 1065b7234e40SJohnny Chen 1066b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandObjectBreakpointClear (CommandInterpreter &interpreter) : 1067b7234e40SJohnny Chen CommandObject (interpreter, 1068b7234e40SJohnny Chen "breakpoint clear", 1069b7234e40SJohnny Chen "Clears a breakpoint or set of breakpoints in the executable.", 1070eb0103f2SGreg Clayton "breakpoint clear <cmd-options>"), 1071eb0103f2SGreg Clayton m_options (interpreter) 1072b7234e40SJohnny Chen { 1073b7234e40SJohnny Chen } 1074b7234e40SJohnny Chen 1075b7234e40SJohnny Chen CommandObjectBreakpointClear::~CommandObjectBreakpointClear () 1076b7234e40SJohnny Chen { 1077b7234e40SJohnny Chen } 1078b7234e40SJohnny Chen 1079b7234e40SJohnny Chen Options * 1080b7234e40SJohnny Chen CommandObjectBreakpointClear::GetOptions () 1081b7234e40SJohnny Chen { 1082b7234e40SJohnny Chen return &m_options; 1083b7234e40SJohnny Chen } 1084b7234e40SJohnny Chen 1085b7234e40SJohnny Chen bool 1086b7234e40SJohnny Chen CommandObjectBreakpointClear::Execute 1087b7234e40SJohnny Chen ( 1088b7234e40SJohnny Chen Args& command, 1089b7234e40SJohnny Chen CommandReturnObject &result 1090b7234e40SJohnny Chen ) 1091b7234e40SJohnny Chen { 1092b7234e40SJohnny Chen Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 1093b7234e40SJohnny Chen if (target == NULL) 1094b7234e40SJohnny Chen { 1095b7234e40SJohnny Chen result.AppendError ("Invalid target. No existing target or breakpoints."); 1096b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1097b7234e40SJohnny Chen return false; 1098b7234e40SJohnny Chen } 1099b7234e40SJohnny Chen 1100b7234e40SJohnny Chen // The following are the various types of breakpoints that could be cleared: 1101b7234e40SJohnny Chen // 1). -f -l (clearing breakpoint by source location) 1102b7234e40SJohnny Chen 1103b7234e40SJohnny Chen BreakpointClearType break_type = eClearTypeInvalid; 1104b7234e40SJohnny Chen 1105b7234e40SJohnny Chen if (m_options.m_line_num != 0) 1106b7234e40SJohnny Chen break_type = eClearTypeFileAndLine; 1107b7234e40SJohnny Chen 1108b7234e40SJohnny Chen Mutex::Locker locker; 1109b7234e40SJohnny Chen target->GetBreakpointList().GetListMutex(locker); 1110b7234e40SJohnny Chen 1111b7234e40SJohnny Chen BreakpointList &breakpoints = target->GetBreakpointList(); 1112b7234e40SJohnny Chen size_t num_breakpoints = breakpoints.GetSize(); 1113b7234e40SJohnny Chen 1114b7234e40SJohnny Chen // Early return if there's no breakpoint at all. 1115b7234e40SJohnny Chen if (num_breakpoints == 0) 1116b7234e40SJohnny Chen { 1117b7234e40SJohnny Chen result.AppendError ("Breakpoint clear: No breakpoint cleared."); 1118b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1119b7234e40SJohnny Chen return result.Succeeded(); 1120b7234e40SJohnny Chen } 1121b7234e40SJohnny Chen 1122b7234e40SJohnny Chen // Find matching breakpoints and delete them. 1123b7234e40SJohnny Chen 1124b7234e40SJohnny Chen // First create a copy of all the IDs. 1125b7234e40SJohnny Chen std::vector<break_id_t> BreakIDs; 1126b7234e40SJohnny Chen for (size_t i = 0; i < num_breakpoints; ++i) 1127b7234e40SJohnny Chen BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID()); 1128b7234e40SJohnny Chen 1129b7234e40SJohnny Chen int num_cleared = 0; 1130b7234e40SJohnny Chen StreamString ss; 1131b7234e40SJohnny Chen switch (break_type) 1132b7234e40SJohnny Chen { 1133b7234e40SJohnny Chen case eClearTypeFileAndLine: // Breakpoint by source position 1134b7234e40SJohnny Chen { 1135b7234e40SJohnny Chen const ConstString filename(m_options.m_filename.c_str()); 1136b7234e40SJohnny Chen BreakpointLocationCollection loc_coll; 1137b7234e40SJohnny Chen 1138b7234e40SJohnny Chen for (size_t i = 0; i < num_breakpoints; ++i) 1139b7234e40SJohnny Chen { 1140b7234e40SJohnny Chen Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); 1141b7234e40SJohnny Chen 1142b7234e40SJohnny Chen if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) 1143b7234e40SJohnny Chen { 1144b7234e40SJohnny Chen // If the collection size is 0, it's a full match and we can just remove the breakpoint. 1145b7234e40SJohnny Chen if (loc_coll.GetSize() == 0) 1146b7234e40SJohnny Chen { 1147b7234e40SJohnny Chen bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); 1148b7234e40SJohnny Chen ss.EOL(); 1149b7234e40SJohnny Chen target->RemoveBreakpointByID (bp->GetID()); 1150b7234e40SJohnny Chen ++num_cleared; 1151b7234e40SJohnny Chen } 1152b7234e40SJohnny Chen } 1153b7234e40SJohnny Chen } 1154b7234e40SJohnny Chen } 1155b7234e40SJohnny Chen break; 1156b7234e40SJohnny Chen 1157b7234e40SJohnny Chen default: 1158b7234e40SJohnny Chen break; 1159b7234e40SJohnny Chen } 1160b7234e40SJohnny Chen 1161b7234e40SJohnny Chen if (num_cleared > 0) 1162b7234e40SJohnny Chen { 116385e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 1164b7234e40SJohnny Chen output_stream.Printf ("%d breakpoints cleared:\n", num_cleared); 1165b7234e40SJohnny Chen output_stream << ss.GetData(); 1166b7234e40SJohnny Chen output_stream.EOL(); 1167b7234e40SJohnny Chen result.SetStatus (eReturnStatusSuccessFinishNoResult); 1168b7234e40SJohnny Chen } 1169b7234e40SJohnny Chen else 1170b7234e40SJohnny Chen { 1171b7234e40SJohnny Chen result.AppendError ("Breakpoint clear: No breakpoint cleared."); 1172b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1173b7234e40SJohnny Chen } 1174b7234e40SJohnny Chen 1175b7234e40SJohnny Chen return result.Succeeded(); 1176b7234e40SJohnny Chen } 1177b7234e40SJohnny Chen 1178b7234e40SJohnny Chen //------------------------------------------------------------------------- 117930fdc8d8SChris Lattner // CommandObjectBreakpointDelete 118030fdc8d8SChris Lattner //------------------------------------------------------------------------- 1181ae1c4cf5SJim Ingham #pragma mark Delete 118230fdc8d8SChris Lattner 1183a7015092SGreg Clayton CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) : 1184a7015092SGreg Clayton CommandObject (interpreter, 1185a7015092SGreg Clayton "breakpoint delete", 1186e3d26315SCaroline Tice "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.", 1187e139cf23SCaroline Tice NULL) 118830fdc8d8SChris Lattner { 1189e139cf23SCaroline Tice CommandArgumentEntry arg; 1190184d7a72SJohnny Chen CommandObject::AddIDsArgumentData(arg); 1191e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1192e139cf23SCaroline Tice m_arguments.push_back (arg); 119330fdc8d8SChris Lattner } 119430fdc8d8SChris Lattner 119530fdc8d8SChris Lattner 119630fdc8d8SChris Lattner CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete () 119730fdc8d8SChris Lattner { 119830fdc8d8SChris Lattner } 119930fdc8d8SChris Lattner 120030fdc8d8SChris Lattner bool 12016611103cSGreg Clayton CommandObjectBreakpointDelete::Execute 12026611103cSGreg Clayton ( 12036611103cSGreg Clayton Args& args, 12046611103cSGreg Clayton CommandReturnObject &result 12056611103cSGreg Clayton ) 120630fdc8d8SChris Lattner { 1207a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 120830fdc8d8SChris Lattner if (target == NULL) 120930fdc8d8SChris Lattner { 12109068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 121130fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 121230fdc8d8SChris Lattner return false; 121330fdc8d8SChris Lattner } 121430fdc8d8SChris Lattner 12151b54c88cSJim Ingham Mutex::Locker locker; 12161b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 12171b54c88cSJim Ingham 121830fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 12191b54c88cSJim Ingham 122030fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 122130fdc8d8SChris Lattner 122230fdc8d8SChris Lattner if (num_breakpoints == 0) 122330fdc8d8SChris Lattner { 122430fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be deleted."); 122530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 122630fdc8d8SChris Lattner return false; 122730fdc8d8SChris Lattner } 122830fdc8d8SChris Lattner 122930fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 123030fdc8d8SChris Lattner { 123136f3b369SJim Ingham if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true)) 123230fdc8d8SChris Lattner { 123336f3b369SJim Ingham result.AppendMessage("Operation cancelled..."); 123430fdc8d8SChris Lattner } 123536f3b369SJim Ingham else 123636f3b369SJim Ingham { 123730fdc8d8SChris Lattner target->RemoveAllBreakpoints (); 1238fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints removed. (%lu breakpoints)\n", num_breakpoints); 123936f3b369SJim Ingham } 124030fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 124130fdc8d8SChris Lattner } 124230fdc8d8SChris Lattner else 124330fdc8d8SChris Lattner { 124430fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 124530fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 124630fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 124730fdc8d8SChris Lattner 124830fdc8d8SChris Lattner if (result.Succeeded()) 124930fdc8d8SChris Lattner { 125030fdc8d8SChris Lattner int delete_count = 0; 125130fdc8d8SChris Lattner int disable_count = 0; 1252c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1253c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 125430fdc8d8SChris Lattner { 125530fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 125630fdc8d8SChris Lattner 125730fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 125830fdc8d8SChris Lattner { 125930fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 126030fdc8d8SChris Lattner { 126130fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 126230fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 126330fdc8d8SChris Lattner // It makes no sense to try to delete individual locations, so we disable them instead. 126430fdc8d8SChris Lattner if (location) 126530fdc8d8SChris Lattner { 126630fdc8d8SChris Lattner location->SetEnabled (false); 126730fdc8d8SChris Lattner ++disable_count; 126830fdc8d8SChris Lattner } 126930fdc8d8SChris Lattner } 127030fdc8d8SChris Lattner else 127130fdc8d8SChris Lattner { 127230fdc8d8SChris Lattner target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID()); 127330fdc8d8SChris Lattner ++delete_count; 127430fdc8d8SChris Lattner } 127530fdc8d8SChris Lattner } 127630fdc8d8SChris Lattner } 127730fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n", 127830fdc8d8SChris Lattner delete_count, disable_count); 127930fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 128030fdc8d8SChris Lattner } 128130fdc8d8SChris Lattner } 128230fdc8d8SChris Lattner return result.Succeeded(); 128330fdc8d8SChris Lattner } 12841b54c88cSJim Ingham 12851b54c88cSJim Ingham //------------------------------------------------------------------------- 1286ae1c4cf5SJim Ingham // CommandObjectBreakpointModify::CommandOptions 12871b54c88cSJim Ingham //------------------------------------------------------------------------- 1288ae1c4cf5SJim Ingham #pragma mark Modify::CommandOptions 12891b54c88cSJim Ingham 1290eb0103f2SGreg Clayton CommandObjectBreakpointModify::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 1291eb0103f2SGreg Clayton Options (interpreter), 1292c982c768SGreg Clayton m_ignore_count (0), 12931b54c88cSJim Ingham m_thread_id(LLDB_INVALID_THREAD_ID), 1294e0a97848SJim Ingham m_thread_id_passed(false), 1295c982c768SGreg Clayton m_thread_index (UINT32_MAX), 1296e0a97848SJim Ingham m_thread_index_passed(false), 12971b54c88cSJim Ingham m_thread_name(), 12981b54c88cSJim Ingham m_queue_name(), 129936f3b369SJim Ingham m_condition (), 1300c982c768SGreg Clayton m_enable_passed (false), 1301c982c768SGreg Clayton m_enable_value (false), 1302c982c768SGreg Clayton m_name_passed (false), 130336f3b369SJim Ingham m_queue_passed (false), 130436f3b369SJim Ingham m_condition_passed (false) 13051b54c88cSJim Ingham { 13061b54c88cSJim Ingham } 13071b54c88cSJim Ingham 1308ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::~CommandOptions () 13091b54c88cSJim Ingham { 13101b54c88cSJim Ingham } 13111b54c88cSJim Ingham 1312e0d378b3SGreg Clayton OptionDefinition 1313ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] = 13141b54c88cSJim Ingham { 1315deaab222SCaroline 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." }, 1316deaab222SCaroline 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."}, 1317deaab222SCaroline 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."}, 1318deaab222SCaroline 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."}, 1319deaab222SCaroline 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."}, 132036f3b369SJim Ingham { LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, NULL, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."}, 1321deaab222SCaroline Tice { LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, eArgTypeNone, "Enable the breakpoint."}, 1322deaab222SCaroline Tice { LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, eArgTypeNone, "Disable the breakpoint."}, 1323deaab222SCaroline Tice { 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } 13241b54c88cSJim Ingham }; 13251b54c88cSJim Ingham 1326e0d378b3SGreg Clayton const OptionDefinition* 1327ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::GetDefinitions () 13281b54c88cSJim Ingham { 13291b54c88cSJim Ingham return g_option_table; 13301b54c88cSJim Ingham } 13311b54c88cSJim Ingham 13321b54c88cSJim Ingham Error 1333f6b8b581SGreg Clayton CommandObjectBreakpointModify::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 13341b54c88cSJim Ingham { 13351b54c88cSJim Ingham Error error; 13361b54c88cSJim Ingham char short_option = (char) m_getopt_table[option_idx].val; 13371b54c88cSJim Ingham 13381b54c88cSJim Ingham switch (short_option) 13391b54c88cSJim Ingham { 134036f3b369SJim Ingham case 'c': 134136f3b369SJim Ingham if (option_arg != NULL) 1342357132ebSGreg Clayton m_condition.assign (option_arg); 134336f3b369SJim Ingham else 134436f3b369SJim Ingham m_condition.clear(); 134536f3b369SJim Ingham m_condition_passed = true; 134636f3b369SJim Ingham break; 1347ae1c4cf5SJim Ingham case 'd': 1348ae1c4cf5SJim Ingham m_enable_passed = true; 1349ae1c4cf5SJim Ingham m_enable_value = false; 1350ae1c4cf5SJim Ingham break; 1351ae1c4cf5SJim Ingham case 'e': 1352ae1c4cf5SJim Ingham m_enable_passed = true; 1353ae1c4cf5SJim Ingham m_enable_value = true; 1354ae1c4cf5SJim Ingham break; 1355ed8a705cSGreg Clayton case 'i': 13561b54c88cSJim Ingham { 13570292f4a5SJim Ingham m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 1358c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 13590292f4a5SJim Ingham error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", option_arg); 13601b54c88cSJim Ingham } 1361ae1c4cf5SJim Ingham break; 13621b54c88cSJim Ingham case 't' : 13631b54c88cSJim Ingham { 13640292f4a5SJim Ingham if (option_arg[0] == '\0') 1365e0a97848SJim Ingham { 1366e0a97848SJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 1367e0a97848SJim Ingham m_thread_id_passed = true; 1368e0a97848SJim Ingham } 1369e0a97848SJim Ingham else 1370e0a97848SJim Ingham { 13710292f4a5SJim Ingham m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 13721b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 13730292f4a5SJim Ingham error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", option_arg); 1374e0a97848SJim Ingham else 1375e0a97848SJim Ingham m_thread_id_passed = true; 1376e0a97848SJim Ingham } 13771b54c88cSJim Ingham } 13781b54c88cSJim Ingham break; 13791b54c88cSJim Ingham case 'T': 1380b2a38a72SJim Ingham if (option_arg != NULL) 1381357132ebSGreg Clayton m_thread_name.assign (option_arg); 1382b2a38a72SJim Ingham else 1383b2a38a72SJim Ingham m_thread_name.clear(); 1384b2a38a72SJim Ingham m_name_passed = true; 13851b54c88cSJim Ingham break; 13861b54c88cSJim Ingham case 'q': 1387b2a38a72SJim Ingham if (option_arg != NULL) 1388357132ebSGreg Clayton m_queue_name.assign (option_arg); 1389b2a38a72SJim Ingham else 1390b2a38a72SJim Ingham m_queue_name.clear(); 1391b2a38a72SJim Ingham m_queue_passed = true; 13921b54c88cSJim Ingham break; 13931b54c88cSJim Ingham case 'x': 13941b54c88cSJim Ingham { 13950292f4a5SJim Ingham if (option_arg[0] == '\n') 1396e0a97848SJim Ingham { 1397e0a97848SJim Ingham m_thread_index = UINT32_MAX; 1398e0a97848SJim Ingham m_thread_index_passed = true; 1399e0a97848SJim Ingham } 1400e0a97848SJim Ingham else 1401e0a97848SJim Ingham { 14020292f4a5SJim Ingham m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0); 1403c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 14040292f4a5SJim Ingham error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", option_arg); 1405e0a97848SJim Ingham else 1406e0a97848SJim Ingham m_thread_index_passed = true; 1407e0a97848SJim Ingham } 14081b54c88cSJim Ingham } 14091b54c88cSJim Ingham break; 14101b54c88cSJim Ingham default: 14111b54c88cSJim Ingham error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 14121b54c88cSJim Ingham break; 14131b54c88cSJim Ingham } 14141b54c88cSJim Ingham 14151b54c88cSJim Ingham return error; 14161b54c88cSJim Ingham } 14171b54c88cSJim Ingham 14181b54c88cSJim Ingham void 1419f6b8b581SGreg Clayton CommandObjectBreakpointModify::CommandOptions::OptionParsingStarting () 14201b54c88cSJim Ingham { 1421c982c768SGreg Clayton m_ignore_count = 0; 14221b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 1423e0a97848SJim Ingham m_thread_id_passed = false; 1424c982c768SGreg Clayton m_thread_index = UINT32_MAX; 1425e0a97848SJim Ingham m_thread_index_passed = false; 14261b54c88cSJim Ingham m_thread_name.clear(); 14271b54c88cSJim Ingham m_queue_name.clear(); 142836f3b369SJim Ingham m_condition.clear(); 1429ae1c4cf5SJim Ingham m_enable_passed = false; 1430b2a38a72SJim Ingham m_queue_passed = false; 1431b2a38a72SJim Ingham m_name_passed = false; 143236f3b369SJim Ingham m_condition_passed = false; 14331b54c88cSJim Ingham } 14341b54c88cSJim Ingham 14351b54c88cSJim Ingham //------------------------------------------------------------------------- 1436ae1c4cf5SJim Ingham // CommandObjectBreakpointModify 14371b54c88cSJim Ingham //------------------------------------------------------------------------- 1438ae1c4cf5SJim Ingham #pragma mark Modify 14391b54c88cSJim Ingham 1440a7015092SGreg Clayton CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) : 1441a7015092SGreg Clayton CommandObject (interpreter, 1442a7015092SGreg Clayton "breakpoint modify", 1443a571c010SJim Ingham "Modify the options on a breakpoint or set of breakpoints in the executable. " 1444e0a97848SJim Ingham "If no breakpoint is specified, acts on the last created breakpoint. " 1445e0a97848SJim Ingham "With the exception of -e, -d and -i, passing an empty argument clears the modification.", 1446eb0103f2SGreg Clayton NULL), 1447eb0103f2SGreg Clayton m_options (interpreter) 14481b54c88cSJim Ingham { 1449e139cf23SCaroline Tice CommandArgumentEntry arg; 1450184d7a72SJohnny Chen CommandObject::AddIDsArgumentData(arg); 1451e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1452e139cf23SCaroline Tice m_arguments.push_back (arg); 14531b54c88cSJim Ingham } 14541b54c88cSJim Ingham 1455ae1c4cf5SJim Ingham CommandObjectBreakpointModify::~CommandObjectBreakpointModify () 14561b54c88cSJim Ingham { 14571b54c88cSJim Ingham } 14581b54c88cSJim Ingham 14591b54c88cSJim Ingham Options * 1460ae1c4cf5SJim Ingham CommandObjectBreakpointModify::GetOptions () 14611b54c88cSJim Ingham { 14621b54c88cSJim Ingham return &m_options; 14631b54c88cSJim Ingham } 14641b54c88cSJim Ingham 14651b54c88cSJim Ingham bool 1466ae1c4cf5SJim Ingham CommandObjectBreakpointModify::Execute 14671b54c88cSJim Ingham ( 14681b54c88cSJim Ingham Args& command, 14691b54c88cSJim Ingham CommandReturnObject &result 14701b54c88cSJim Ingham ) 14711b54c88cSJim Ingham { 1472a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 14731b54c88cSJim Ingham if (target == NULL) 14741b54c88cSJim Ingham { 14759068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 14761b54c88cSJim Ingham result.SetStatus (eReturnStatusFailed); 14771b54c88cSJim Ingham return false; 14781b54c88cSJim Ingham } 14791b54c88cSJim Ingham 14801b54c88cSJim Ingham Mutex::Locker locker; 14811b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 14821b54c88cSJim Ingham 14831b54c88cSJim Ingham BreakpointIDList valid_bp_ids; 14841b54c88cSJim Ingham 14851b54c88cSJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 14861b54c88cSJim Ingham 14871b54c88cSJim Ingham if (result.Succeeded()) 14881b54c88cSJim Ingham { 1489c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1490c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 14911b54c88cSJim Ingham { 14921b54c88cSJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 14931b54c88cSJim Ingham 14941b54c88cSJim Ingham if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 14951b54c88cSJim Ingham { 14961b54c88cSJim Ingham Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 14971b54c88cSJim Ingham if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 14981b54c88cSJim Ingham { 14991b54c88cSJim Ingham BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get(); 15001b54c88cSJim Ingham if (location) 15011b54c88cSJim Ingham { 1502e0a97848SJim Ingham if (m_options.m_thread_id_passed) 15031b54c88cSJim Ingham location->SetThreadID (m_options.m_thread_id); 15041b54c88cSJim Ingham 1505e0a97848SJim Ingham if (m_options.m_thread_index_passed) 15061b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 15071b54c88cSJim Ingham 1508b2a38a72SJim Ingham if (m_options.m_name_passed) 15091b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 15101b54c88cSJim Ingham 1511b2a38a72SJim Ingham if (m_options.m_queue_passed) 15121b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 15131b54c88cSJim Ingham 1514c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 15151b54c88cSJim Ingham location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count); 1516ae1c4cf5SJim Ingham 1517ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1518ae1c4cf5SJim Ingham location->SetEnabled (m_options.m_enable_value); 151936f3b369SJim Ingham 152036f3b369SJim Ingham if (m_options.m_condition_passed) 152136f3b369SJim Ingham location->SetCondition (m_options.m_condition.c_str()); 15221b54c88cSJim Ingham } 15231b54c88cSJim Ingham } 15241b54c88cSJim Ingham else 15251b54c88cSJim Ingham { 1526e0a97848SJim Ingham if (m_options.m_thread_id_passed) 15271b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 15281b54c88cSJim Ingham 1529e0a97848SJim Ingham if (m_options.m_thread_index_passed) 15301b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 15311b54c88cSJim Ingham 1532b2a38a72SJim Ingham if (m_options.m_name_passed) 15331b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 15341b54c88cSJim Ingham 1535b2a38a72SJim Ingham if (m_options.m_queue_passed) 15361b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 15371b54c88cSJim Ingham 1538c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 15391b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 1540ae1c4cf5SJim Ingham 1541ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1542ae1c4cf5SJim Ingham bp->SetEnabled (m_options.m_enable_value); 1543ae1c4cf5SJim Ingham 154436f3b369SJim Ingham if (m_options.m_condition_passed) 154536f3b369SJim Ingham bp->SetCondition (m_options.m_condition.c_str()); 15461b54c88cSJim Ingham } 15471b54c88cSJim Ingham } 15481b54c88cSJim Ingham } 15491b54c88cSJim Ingham } 15501b54c88cSJim Ingham 15511b54c88cSJim Ingham return result.Succeeded(); 15521b54c88cSJim Ingham } 15531b54c88cSJim Ingham 15541b54c88cSJim Ingham 1555