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), 5287df91b8SJim Ingham m_filenames (), 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 744a6ae0f0SJim Ingham #define LLDB_OPT_FILE (LLDB_OPT_SET_1 | LLDB_OPT_SET_3 | LLDB_OPT_SET_4 | LLDB_OPT_SET_5 | LLDB_OPT_SET_6 | LLDB_OPT_SET_7 | LLDB_OPT_SET_8 | LLDB_OPT_SET_9 ) 7587df91b8SJim Ingham 76e0d378b3SGreg Clayton OptionDefinition 7730fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::g_option_table[] = 7830fdc8d8SChris Lattner { 79deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName, 808651121cSJim Ingham "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."}, 818651121cSJim Ingham 82deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount, 83deaab222SCaroline Tice "Set the number of times this breakpoint is skipped before stopping." }, 841b54c88cSJim Ingham 85deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex, 86ed8a705cSGreg Clayton "The breakpoint stops only for the thread whose index matches this argument."}, 871b54c88cSJim Ingham 88deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, eArgTypeThreadID, 891b54c88cSJim Ingham "The breakpoint stops only for the thread whose TID matches this argument."}, 901b54c88cSJim Ingham 91deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, eArgTypeThreadName, 921b54c88cSJim Ingham "The breakpoint stops only for the thread whose thread name matches this argument."}, 931b54c88cSJim Ingham 94deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, eArgTypeQueueName, 951b54c88cSJim Ingham "The breakpoint stops only for threads in the queue whose name is given by this argument."}, 961b54c88cSJim Ingham 9787df91b8SJim Ingham { LLDB_OPT_FILE, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, 9887df91b8SJim Ingham "Specifies the source file in which to set this breakpoint."}, 9930fdc8d8SChris Lattner 100deaab222SCaroline Tice { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, 10187df91b8SJim Ingham "Specifies the line number on which to set this breakpoint."}, 10230fdc8d8SChris Lattner 10330fdc8d8SChris Lattner // Comment out this option for the moment, as we don't actually use it, but will in the future. 10430fdc8d8SChris Lattner // This way users won't see it, but the infrastructure is left in place. 10530fdc8d8SChris Lattner // { 0, false, "column", 'c', required_argument, NULL, "<column>", 10630fdc8d8SChris Lattner // "Set the breakpoint by source location at this particular column."}, 10730fdc8d8SChris Lattner 108deaab222SCaroline Tice { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, 10930fdc8d8SChris Lattner "Set the breakpoint by address, at the specified address."}, 11030fdc8d8SChris Lattner 111deaab222SCaroline Tice { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, 112e02b8504SGreg Clayton "Set the breakpoint by function name." }, 11330fdc8d8SChris Lattner 114deaab222SCaroline Tice { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName, 1152561aa61SJim Ingham "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguemnts, and " 1162561aa61SJim Ingham "for Objective C this means a full function prototype with class and selector." }, 1170c5cd90dSGreg Clayton 118deaab222SCaroline Tice { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector, 1192561aa61SJim Ingham "Set the breakpoint by ObjC selector name." }, 1200c5cd90dSGreg Clayton 121deaab222SCaroline Tice { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod, 1222561aa61SJim Ingham "Set the breakpoint by C++ method names." }, 1230c5cd90dSGreg Clayton 124deaab222SCaroline Tice { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression, 12530fdc8d8SChris Lattner "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." }, 12630fdc8d8SChris Lattner 127e02b8504SGreg Clayton { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, 128e02b8504SGreg Clayton "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored)." }, 129e02b8504SGreg Clayton 130969795f1SJim Ingham { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', required_argument, NULL, 0, eArgTypeRegularExpression, 131969795f1SJim Ingham "Set the breakpoint specifying a regular expression to match a pattern in the source text in a given source file." }, 132969795f1SJim Ingham 133969795f1SJim Ingham 134deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 13530fdc8d8SChris Lattner }; 13630fdc8d8SChris Lattner 137e0d378b3SGreg Clayton const OptionDefinition* 13830fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::GetDefinitions () 13930fdc8d8SChris Lattner { 14030fdc8d8SChris Lattner return g_option_table; 14130fdc8d8SChris Lattner } 14230fdc8d8SChris Lattner 14330fdc8d8SChris Lattner Error 144f6b8b581SGreg Clayton CommandObjectBreakpointSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 14530fdc8d8SChris Lattner { 14630fdc8d8SChris Lattner Error error; 14730fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 14830fdc8d8SChris Lattner 14930fdc8d8SChris Lattner switch (short_option) 15030fdc8d8SChris Lattner { 15130fdc8d8SChris Lattner case 'a': 1520292f4a5SJim Ingham m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0); 15330fdc8d8SChris Lattner if (m_load_addr == LLDB_INVALID_ADDRESS) 1540292f4a5SJim Ingham m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16); 15530fdc8d8SChris Lattner 15630fdc8d8SChris Lattner if (m_load_addr == LLDB_INVALID_ADDRESS) 157*86edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg); 15830fdc8d8SChris Lattner break; 15930fdc8d8SChris Lattner 16030fdc8d8SChris Lattner case 'c': 16130fdc8d8SChris Lattner m_column = Args::StringToUInt32 (option_arg, 0); 16230fdc8d8SChris Lattner break; 1630c5cd90dSGreg Clayton 16430fdc8d8SChris Lattner case 'f': 16587df91b8SJim Ingham m_filenames.AppendIfUnique (FileSpec(option_arg, false)); 16630fdc8d8SChris Lattner break; 1670c5cd90dSGreg Clayton 16830fdc8d8SChris Lattner case 'l': 16930fdc8d8SChris Lattner m_line_num = Args::StringToUInt32 (option_arg, 0); 17030fdc8d8SChris Lattner break; 1710c5cd90dSGreg Clayton 172e02b8504SGreg Clayton case 'b': 173357132ebSGreg Clayton m_func_name.assign (option_arg); 1740c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeBase; 1750c5cd90dSGreg Clayton break; 1760c5cd90dSGreg Clayton 177e02b8504SGreg Clayton case 'n': 178357132ebSGreg Clayton m_func_name.assign (option_arg); 179e02b8504SGreg Clayton m_func_name_type_mask |= eFunctionNameTypeAuto; 180e02b8504SGreg Clayton break; 181e02b8504SGreg Clayton 1820c5cd90dSGreg Clayton case 'F': 183357132ebSGreg Clayton m_func_name.assign (option_arg); 1840c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeFull; 1850c5cd90dSGreg Clayton break; 1860c5cd90dSGreg Clayton 1870c5cd90dSGreg Clayton case 'S': 188357132ebSGreg Clayton m_func_name.assign (option_arg); 1890c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeSelector; 1900c5cd90dSGreg Clayton break; 1910c5cd90dSGreg Clayton 1922561aa61SJim Ingham case 'M': 193357132ebSGreg Clayton m_func_name.assign (option_arg); 1940c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeMethod; 1950c5cd90dSGreg Clayton break; 1960c5cd90dSGreg Clayton 197969795f1SJim Ingham case 'p': 198969795f1SJim Ingham m_source_text_regexp.assign (option_arg); 199969795f1SJim Ingham break; 200969795f1SJim Ingham 20130fdc8d8SChris Lattner case 'r': 202357132ebSGreg Clayton m_func_regexp.assign (option_arg); 20330fdc8d8SChris Lattner break; 2040c5cd90dSGreg Clayton 20530fdc8d8SChris Lattner case 's': 20630fdc8d8SChris Lattner { 20787df91b8SJim Ingham m_modules.AppendIfUnique (FileSpec (option_arg, false)); 20830fdc8d8SChris Lattner break; 20930fdc8d8SChris Lattner } 210ed8a705cSGreg Clayton case 'i': 2111b54c88cSJim Ingham { 2120292f4a5SJim Ingham m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 213c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 214*86edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); 2151b54c88cSJim Ingham } 216ae1c4cf5SJim Ingham break; 2171b54c88cSJim Ingham case 't' : 2181b54c88cSJim Ingham { 2190292f4a5SJim Ingham m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 2201b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 221*86edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); 2221b54c88cSJim Ingham } 2231b54c88cSJim Ingham break; 2241b54c88cSJim Ingham case 'T': 225357132ebSGreg Clayton m_thread_name.assign (option_arg); 2261b54c88cSJim Ingham break; 2271b54c88cSJim Ingham case 'q': 228357132ebSGreg Clayton m_queue_name.assign (option_arg); 2291b54c88cSJim Ingham break; 2301b54c88cSJim Ingham case 'x': 2311b54c88cSJim Ingham { 2320292f4a5SJim Ingham m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 233c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 234*86edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); 2351b54c88cSJim Ingham 2361b54c88cSJim Ingham } 2371b54c88cSJim Ingham break; 23830fdc8d8SChris Lattner default: 239*86edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 24030fdc8d8SChris Lattner break; 24130fdc8d8SChris Lattner } 24230fdc8d8SChris Lattner 24330fdc8d8SChris Lattner return error; 24430fdc8d8SChris Lattner } 24530fdc8d8SChris Lattner 24630fdc8d8SChris Lattner void 247f6b8b581SGreg Clayton CommandObjectBreakpointSet::CommandOptions::OptionParsingStarting () 24830fdc8d8SChris Lattner { 24987df91b8SJim Ingham m_filenames.Clear(); 25030fdc8d8SChris Lattner m_line_num = 0; 25130fdc8d8SChris Lattner m_column = 0; 25230fdc8d8SChris Lattner m_func_name.clear(); 2530c5cd90dSGreg Clayton m_func_name_type_mask = 0; 25430fdc8d8SChris Lattner m_func_regexp.clear(); 25530fdc8d8SChris Lattner m_load_addr = LLDB_INVALID_ADDRESS; 25687df91b8SJim Ingham m_modules.Clear(); 257c982c768SGreg Clayton m_ignore_count = 0; 2581b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 259c982c768SGreg Clayton m_thread_index = UINT32_MAX; 2601b54c88cSJim Ingham m_thread_name.clear(); 2611b54c88cSJim Ingham m_queue_name.clear(); 26230fdc8d8SChris Lattner } 26330fdc8d8SChris Lattner 26430fdc8d8SChris Lattner //------------------------------------------------------------------------- 26530fdc8d8SChris Lattner // CommandObjectBreakpointSet 26630fdc8d8SChris Lattner //------------------------------------------------------------------------- 267ae1c4cf5SJim Ingham #pragma mark Set 26830fdc8d8SChris Lattner 269a7015092SGreg Clayton CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) : 270a7015092SGreg Clayton CommandObject (interpreter, 271a7015092SGreg Clayton "breakpoint set", 272a7015092SGreg Clayton "Sets a breakpoint or set of breakpoints in the executable.", 273eb0103f2SGreg Clayton "breakpoint set <cmd-options>"), 274eb0103f2SGreg Clayton m_options (interpreter) 27530fdc8d8SChris Lattner { 27630fdc8d8SChris Lattner } 27730fdc8d8SChris Lattner 27830fdc8d8SChris Lattner CommandObjectBreakpointSet::~CommandObjectBreakpointSet () 27930fdc8d8SChris Lattner { 28030fdc8d8SChris Lattner } 28130fdc8d8SChris Lattner 28230fdc8d8SChris Lattner Options * 28330fdc8d8SChris Lattner CommandObjectBreakpointSet::GetOptions () 28430fdc8d8SChris Lattner { 28530fdc8d8SChris Lattner return &m_options; 28630fdc8d8SChris Lattner } 28730fdc8d8SChris Lattner 28830fdc8d8SChris Lattner bool 28987df91b8SJim Ingham CommandObjectBreakpointSet::GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result) 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 { 296c14ee32dSGreg Clayton StackFrame *cur_frame = m_interpreter.GetExecutionContext().GetFramePtr(); 297969795f1SJim Ingham if (cur_frame == NULL) 298969795f1SJim Ingham { 29987df91b8SJim Ingham result.AppendError ("No selected frame to use to find the default file."); 300969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 301969795f1SJim Ingham return false; 302969795f1SJim Ingham } 303969795f1SJim Ingham else if (!cur_frame->HasDebugInformation()) 304969795f1SJim Ingham { 30587df91b8SJim Ingham result.AppendError ("Cannot use the selected frame to find the default file, it 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 { 31887df91b8SJim Ingham result.AppendError ("Can't find the file for the selected frame to use as the default file."); 319969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 320969795f1SJim Ingham return false; 321969795f1SJim Ingham } 322969795f1SJim Ingham } 323969795f1SJim Ingham } 324969795f1SJim Ingham return true; 325969795f1SJim Ingham } 326969795f1SJim Ingham 327969795f1SJim Ingham bool 32830fdc8d8SChris Lattner CommandObjectBreakpointSet::Execute 32930fdc8d8SChris Lattner ( 33030fdc8d8SChris Lattner Args& command, 33130fdc8d8SChris Lattner CommandReturnObject &result 33230fdc8d8SChris Lattner ) 33330fdc8d8SChris Lattner { 334a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 33530fdc8d8SChris Lattner if (target == NULL) 33630fdc8d8SChris Lattner { 337effe5c95SGreg Clayton result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command)."); 33830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 33930fdc8d8SChris Lattner return false; 34030fdc8d8SChris Lattner } 34130fdc8d8SChris Lattner 34230fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 34330fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 34430fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 34530fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 34630fdc8d8SChris Lattner // 4). -r [-s -g] (setting breakpoint by function name regular expression) 347969795f1SJim Ingham // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text) 34830fdc8d8SChris Lattner 34930fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 35030fdc8d8SChris Lattner 35130fdc8d8SChris Lattner if (m_options.m_line_num != 0) 35230fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 35330fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 35430fdc8d8SChris Lattner break_type = eSetTypeAddress; 35530fdc8d8SChris Lattner else if (!m_options.m_func_name.empty()) 35630fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 35730fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 35830fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 359969795f1SJim Ingham else if (!m_options.m_source_text_regexp.empty()) 360969795f1SJim Ingham break_type = eSetTypeSourceRegexp; 36130fdc8d8SChris Lattner 36230fdc8d8SChris Lattner Breakpoint *bp = NULL; 363274060b6SGreg Clayton FileSpec module_spec; 36430fdc8d8SChris Lattner bool use_module = false; 36587df91b8SJim Ingham int num_modules = m_options.m_modules.GetSize(); 366969795f1SJim Ingham 36730fdc8d8SChris Lattner if ((num_modules > 0) && (break_type != eSetTypeAddress)) 36830fdc8d8SChris Lattner use_module = true; 36930fdc8d8SChris Lattner 37030fdc8d8SChris Lattner switch (break_type) 37130fdc8d8SChris Lattner { 37230fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 37330fdc8d8SChris Lattner { 37430fdc8d8SChris Lattner FileSpec file; 37587df91b8SJim Ingham uint32_t num_files = m_options.m_filenames.GetSize(); 37687df91b8SJim Ingham if (num_files == 0) 37787df91b8SJim Ingham { 37887df91b8SJim Ingham if (!GetDefaultFile (target, file, result)) 37987df91b8SJim Ingham { 38087df91b8SJim Ingham result.AppendError("No file supplied and no default file available."); 38187df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 38287df91b8SJim Ingham return false; 38387df91b8SJim Ingham } 38487df91b8SJim Ingham } 38587df91b8SJim Ingham else if (num_files > 1) 38687df91b8SJim Ingham { 38787df91b8SJim Ingham result.AppendError("Only one file at a time is allowed for file and line breakpoints."); 38887df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 38987df91b8SJim Ingham return false; 39087df91b8SJim Ingham } 39187df91b8SJim Ingham else 39287df91b8SJim Ingham file = m_options.m_filenames.GetFileSpecAtIndex(0); 39330fdc8d8SChris Lattner 39487df91b8SJim Ingham bp = target->CreateBreakpoint (&(m_options.m_modules), 39530fdc8d8SChris Lattner file, 39630fdc8d8SChris Lattner m_options.m_line_num, 3972856d462SGreg Clayton m_options.m_check_inlines).get(); 39830fdc8d8SChris Lattner } 39930fdc8d8SChris Lattner break; 4006eee5aa0SGreg Clayton 40130fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 40230fdc8d8SChris Lattner bp = target->CreateBreakpoint (m_options.m_load_addr, false).get(); 40330fdc8d8SChris Lattner break; 4040c5cd90dSGreg Clayton 40530fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 4060c5cd90dSGreg Clayton { 4070c5cd90dSGreg Clayton uint32_t name_type_mask = m_options.m_func_name_type_mask; 4080c5cd90dSGreg Clayton 4090c5cd90dSGreg Clayton if (name_type_mask == 0) 410e02b8504SGreg Clayton name_type_mask = eFunctionNameTypeAuto; 4110c5cd90dSGreg Clayton 41287df91b8SJim Ingham bp = target->CreateBreakpoint (&(m_options.m_modules), 41387df91b8SJim Ingham &(m_options.m_filenames), 414274060b6SGreg Clayton m_options.m_func_name.c_str(), 415274060b6SGreg Clayton name_type_mask, 416274060b6SGreg Clayton Breakpoint::Exact).get(); 4170c5cd90dSGreg Clayton } 41830fdc8d8SChris Lattner break; 4190c5cd90dSGreg Clayton 42030fdc8d8SChris Lattner case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name 42130fdc8d8SChris Lattner { 42230fdc8d8SChris Lattner RegularExpression regexp(m_options.m_func_regexp.c_str()); 423969795f1SJim Ingham if (!regexp.IsValid()) 42430fdc8d8SChris Lattner { 425969795f1SJim Ingham char err_str[1024]; 426969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 427969795f1SJim Ingham result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"", 428969795f1SJim Ingham err_str); 42930fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 430969795f1SJim Ingham return false; 43130fdc8d8SChris Lattner } 43287df91b8SJim Ingham 43387df91b8SJim Ingham bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules), &(m_options.m_filenames), regexp).get(); 43430fdc8d8SChris Lattner } 43530fdc8d8SChris Lattner break; 436969795f1SJim Ingham case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. 437969795f1SJim Ingham { 43887df91b8SJim Ingham int num_files = m_options.m_filenames.GetSize(); 43987df91b8SJim Ingham 44087df91b8SJim Ingham if (num_files == 0) 44187df91b8SJim Ingham { 442969795f1SJim Ingham FileSpec file; 44387df91b8SJim Ingham if (!GetDefaultFile (target, file, result)) 44487df91b8SJim Ingham { 44587df91b8SJim Ingham result.AppendError ("No files provided and could not find default file."); 44687df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 44787df91b8SJim Ingham return false; 44887df91b8SJim Ingham } 44987df91b8SJim Ingham else 45087df91b8SJim Ingham { 45187df91b8SJim Ingham m_options.m_filenames.Append (file); 45287df91b8SJim Ingham } 45387df91b8SJim Ingham } 4540c5cd90dSGreg Clayton 455969795f1SJim Ingham RegularExpression regexp(m_options.m_source_text_regexp.c_str()); 456969795f1SJim Ingham if (!regexp.IsValid()) 457969795f1SJim Ingham { 458969795f1SJim Ingham char err_str[1024]; 459969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 460969795f1SJim Ingham result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"", 461969795f1SJim Ingham err_str); 462969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 463969795f1SJim Ingham return false; 464969795f1SJim Ingham } 46587df91b8SJim Ingham bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules), &(m_options.m_filenames), regexp).get(); 466969795f1SJim Ingham } 467969795f1SJim Ingham break; 46830fdc8d8SChris Lattner default: 46930fdc8d8SChris Lattner break; 47030fdc8d8SChris Lattner } 47130fdc8d8SChris Lattner 4721b54c88cSJim Ingham // Now set the various options that were passed in: 4731b54c88cSJim Ingham if (bp) 4741b54c88cSJim Ingham { 4751b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 4761b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 4771b54c88cSJim Ingham 478c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 4791b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 4801b54c88cSJim Ingham 4811b54c88cSJim Ingham if (!m_options.m_thread_name.empty()) 4821b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 4831b54c88cSJim Ingham 4841b54c88cSJim Ingham if (!m_options.m_queue_name.empty()) 4851b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 4861b54c88cSJim Ingham 487c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 4881b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 4891b54c88cSJim Ingham } 4901b54c88cSJim Ingham 491969795f1SJim Ingham if (bp) 49230fdc8d8SChris Lattner { 49385e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 49430fdc8d8SChris Lattner output_stream.Printf ("Breakpoint created: "); 49530fdc8d8SChris Lattner bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); 49630fdc8d8SChris Lattner output_stream.EOL(); 497be484f41SCaroline Tice if (bp->GetNumLocations() == 0) 498be484f41SCaroline Tice output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n"); 49930fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 50030fdc8d8SChris Lattner } 50130fdc8d8SChris Lattner else if (!bp) 50230fdc8d8SChris Lattner { 50330fdc8d8SChris Lattner result.AppendError ("Breakpoint creation failed: No breakpoint created."); 50430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 50530fdc8d8SChris Lattner } 50630fdc8d8SChris Lattner 50730fdc8d8SChris Lattner return result.Succeeded(); 50830fdc8d8SChris Lattner } 50930fdc8d8SChris Lattner 51030fdc8d8SChris Lattner //------------------------------------------------------------------------- 51130fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 51230fdc8d8SChris Lattner //------------------------------------------------------------------------- 513ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 51430fdc8d8SChris Lattner 5156611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) : 516a7015092SGreg Clayton CommandObjectMultiword (interpreter, 517a7015092SGreg Clayton "breakpoint", 51846fbc60fSJim Ingham "A set of commands for operating on breakpoints. Also see _regexp-break.", 51930fdc8d8SChris Lattner "breakpoint <command> [<command-options>]") 52030fdc8d8SChris Lattner { 52130fdc8d8SChris Lattner bool status; 52230fdc8d8SChris Lattner 523a7015092SGreg Clayton CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter)); 524a7015092SGreg Clayton CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter)); 525a7015092SGreg Clayton CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter)); 526b7234e40SJohnny Chen CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter)); 527b7234e40SJohnny Chen CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter)); 528a7015092SGreg Clayton CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter)); 52930fdc8d8SChris Lattner CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter)); 530a7015092SGreg Clayton CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter)); 53130fdc8d8SChris Lattner 532b7234e40SJohnny Chen list_command_object->SetCommandName ("breakpoint list"); 53330fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 53430fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 535b7234e40SJohnny Chen clear_command_object->SetCommandName("breakpoint clear"); 536b7234e40SJohnny Chen delete_command_object->SetCommandName("breakpoint delete"); 537ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 538b7234e40SJohnny Chen command_command_object->SetCommandName ("breakpoint command"); 539b7234e40SJohnny Chen modify_command_object->SetCommandName ("breakpoint modify"); 54030fdc8d8SChris Lattner 541a7015092SGreg Clayton status = LoadSubCommand ("list", list_command_object); 542a7015092SGreg Clayton status = LoadSubCommand ("enable", enable_command_object); 543a7015092SGreg Clayton status = LoadSubCommand ("disable", disable_command_object); 544b7234e40SJohnny Chen status = LoadSubCommand ("clear", clear_command_object); 545a7015092SGreg Clayton status = LoadSubCommand ("delete", delete_command_object); 546a7015092SGreg Clayton status = LoadSubCommand ("set", set_command_object); 547a7015092SGreg Clayton status = LoadSubCommand ("command", command_command_object); 548a7015092SGreg Clayton status = LoadSubCommand ("modify", modify_command_object); 54930fdc8d8SChris Lattner } 55030fdc8d8SChris Lattner 55130fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint () 55230fdc8d8SChris Lattner { 55330fdc8d8SChris Lattner } 55430fdc8d8SChris Lattner 55530fdc8d8SChris Lattner void 55630fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result, 55730fdc8d8SChris Lattner BreakpointIDList *valid_ids) 55830fdc8d8SChris Lattner { 55930fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 56030fdc8d8SChris Lattner // 2). the full breakpoint & location canonical representation 56130fdc8d8SChris Lattner // 3). the word "to" or a hyphen, representing a range (in which case there 56230fdc8d8SChris Lattner // had *better* be an entry both before & after of one of the first two types. 56336f3b369SJim Ingham // If args is empty, we will use the last created breakpoint (if there is one.) 56430fdc8d8SChris Lattner 56530fdc8d8SChris Lattner Args temp_args; 56630fdc8d8SChris Lattner 56736f3b369SJim Ingham if (args.GetArgumentCount() == 0) 56836f3b369SJim Ingham { 5694d122c40SGreg Clayton if (target->GetLastCreatedBreakpoint()) 57036f3b369SJim Ingham { 57136f3b369SJim Ingham valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); 57236f3b369SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 57336f3b369SJim Ingham } 57436f3b369SJim Ingham else 57536f3b369SJim Ingham { 57636f3b369SJim Ingham result.AppendError("No breakpoint specified and no last created breakpoint."); 57736f3b369SJim Ingham result.SetStatus (eReturnStatusFailed); 57836f3b369SJim Ingham } 57936f3b369SJim Ingham return; 58036f3b369SJim Ingham } 58136f3b369SJim Ingham 58230fdc8d8SChris Lattner // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to 58330fdc8d8SChris Lattner // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for 58430fdc8d8SChris Lattner // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS. 58530fdc8d8SChris Lattner 58630fdc8d8SChris Lattner BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args); 58730fdc8d8SChris Lattner 58830fdc8d8SChris Lattner // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList: 58930fdc8d8SChris Lattner 590c982c768SGreg Clayton valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result); 59130fdc8d8SChris Lattner 59230fdc8d8SChris Lattner // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs 59330fdc8d8SChris Lattner // and put into valid_ids. 59430fdc8d8SChris Lattner 59530fdc8d8SChris Lattner if (result.Succeeded()) 59630fdc8d8SChris Lattner { 59730fdc8d8SChris Lattner // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list 59830fdc8d8SChris Lattner // of breakpoint id's and verify that they correspond to valid/currently set breakpoints. 59930fdc8d8SChris Lattner 600c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 601c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 60230fdc8d8SChris Lattner { 60330fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i); 60430fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 60530fdc8d8SChris Lattner if (breakpoint != NULL) 60630fdc8d8SChris Lattner { 60730fdc8d8SChris Lattner int num_locations = breakpoint->GetNumLocations(); 60830fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() > num_locations) 60930fdc8d8SChris Lattner { 61030fdc8d8SChris Lattner StreamString id_str; 611c982c768SGreg Clayton BreakpointID::GetCanonicalReference (&id_str, 612c982c768SGreg Clayton cur_bp_id.GetBreakpointID(), 61330fdc8d8SChris Lattner cur_bp_id.GetLocationID()); 614c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 61530fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n", 61630fdc8d8SChris Lattner id_str.GetData()); 61730fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 61830fdc8d8SChris Lattner } 61930fdc8d8SChris Lattner } 62030fdc8d8SChris Lattner else 62130fdc8d8SChris Lattner { 622c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 62330fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID()); 62430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 62530fdc8d8SChris Lattner } 62630fdc8d8SChris Lattner } 62730fdc8d8SChris Lattner } 62830fdc8d8SChris Lattner } 62930fdc8d8SChris Lattner 63030fdc8d8SChris Lattner //------------------------------------------------------------------------- 63130fdc8d8SChris Lattner // CommandObjectBreakpointList::Options 63230fdc8d8SChris Lattner //------------------------------------------------------------------------- 633ae1c4cf5SJim Ingham #pragma mark List::CommandOptions 63430fdc8d8SChris Lattner 635eb0103f2SGreg Clayton CommandObjectBreakpointList::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 636eb0103f2SGreg Clayton Options (interpreter), 63779042b3eSCaroline Tice m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions 63830fdc8d8SChris Lattner { 63930fdc8d8SChris Lattner } 64030fdc8d8SChris Lattner 64130fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::~CommandOptions () 64230fdc8d8SChris Lattner { 64330fdc8d8SChris Lattner } 64430fdc8d8SChris Lattner 645e0d378b3SGreg Clayton OptionDefinition 64630fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::g_option_table[] = 64730fdc8d8SChris Lattner { 648deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone, 6498651121cSJim Ingham "Show debugger internal breakpoints" }, 6508651121cSJim Ingham 651deaab222SCaroline Tice { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone, 65230fdc8d8SChris Lattner "Give a brief description of the breakpoint (no location info)."}, 65330fdc8d8SChris Lattner 65430fdc8d8SChris Lattner // FIXME: We need to add an "internal" command, and then add this sort of thing to it. 65530fdc8d8SChris Lattner // But I need to see it for now, and don't want to wait. 656deaab222SCaroline Tice { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone, 65730fdc8d8SChris Lattner "Give a full description of the breakpoint and its locations."}, 65830fdc8d8SChris Lattner 659deaab222SCaroline Tice { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, 66030fdc8d8SChris Lattner "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, 66130fdc8d8SChris Lattner 662deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 66330fdc8d8SChris Lattner }; 66430fdc8d8SChris Lattner 665e0d378b3SGreg Clayton const OptionDefinition* 66630fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::GetDefinitions () 66730fdc8d8SChris Lattner { 66830fdc8d8SChris Lattner return g_option_table; 66930fdc8d8SChris Lattner } 67030fdc8d8SChris Lattner 67130fdc8d8SChris Lattner Error 672f6b8b581SGreg Clayton CommandObjectBreakpointList::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 67330fdc8d8SChris Lattner { 67430fdc8d8SChris Lattner Error error; 67530fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 67630fdc8d8SChris Lattner 67730fdc8d8SChris Lattner switch (short_option) 67830fdc8d8SChris Lattner { 67930fdc8d8SChris Lattner case 'b': 68030fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelBrief; 68130fdc8d8SChris Lattner break; 68230fdc8d8SChris Lattner case 'f': 68330fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelFull; 68430fdc8d8SChris Lattner break; 68530fdc8d8SChris Lattner case 'v': 68630fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelVerbose; 68730fdc8d8SChris Lattner break; 68830fdc8d8SChris Lattner case 'i': 68930fdc8d8SChris Lattner m_internal = true; 69030fdc8d8SChris Lattner break; 69130fdc8d8SChris Lattner default: 692*86edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 69330fdc8d8SChris Lattner break; 69430fdc8d8SChris Lattner } 69530fdc8d8SChris Lattner 69630fdc8d8SChris Lattner return error; 69730fdc8d8SChris Lattner } 69830fdc8d8SChris Lattner 69930fdc8d8SChris Lattner void 700f6b8b581SGreg Clayton CommandObjectBreakpointList::CommandOptions::OptionParsingStarting () 70130fdc8d8SChris Lattner { 702d915e16fSJim Ingham m_level = lldb::eDescriptionLevelFull; 70330fdc8d8SChris Lattner m_internal = false; 70430fdc8d8SChris Lattner } 70530fdc8d8SChris Lattner 70630fdc8d8SChris Lattner //------------------------------------------------------------------------- 70730fdc8d8SChris Lattner // CommandObjectBreakpointList 70830fdc8d8SChris Lattner //------------------------------------------------------------------------- 709ae1c4cf5SJim Ingham #pragma mark List 71030fdc8d8SChris Lattner 711a7015092SGreg Clayton CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) : 712a7015092SGreg Clayton CommandObject (interpreter, 713a7015092SGreg Clayton "breakpoint list", 71430fdc8d8SChris Lattner "List some or all breakpoints at configurable levels of detail.", 715eb0103f2SGreg Clayton NULL), 716eb0103f2SGreg Clayton m_options (interpreter) 71730fdc8d8SChris Lattner { 718e139cf23SCaroline Tice CommandArgumentEntry arg; 719e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 720e139cf23SCaroline Tice 721e139cf23SCaroline Tice // Define the first (and only) variant of this arg. 722e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 723405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 724e139cf23SCaroline Tice 725e139cf23SCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 726e139cf23SCaroline Tice arg.push_back (bp_id_arg); 727e139cf23SCaroline Tice 728e139cf23SCaroline Tice // Push the data for the first argument into the m_arguments vector. 729e139cf23SCaroline Tice m_arguments.push_back (arg); 73030fdc8d8SChris Lattner } 73130fdc8d8SChris Lattner 73230fdc8d8SChris Lattner CommandObjectBreakpointList::~CommandObjectBreakpointList () 73330fdc8d8SChris Lattner { 73430fdc8d8SChris Lattner } 73530fdc8d8SChris Lattner 73630fdc8d8SChris Lattner Options * 73730fdc8d8SChris Lattner CommandObjectBreakpointList::GetOptions () 73830fdc8d8SChris Lattner { 73930fdc8d8SChris Lattner return &m_options; 74030fdc8d8SChris Lattner } 74130fdc8d8SChris Lattner 74230fdc8d8SChris Lattner bool 74330fdc8d8SChris Lattner CommandObjectBreakpointList::Execute 74430fdc8d8SChris Lattner ( 74530fdc8d8SChris Lattner Args& args, 74630fdc8d8SChris Lattner CommandReturnObject &result 74730fdc8d8SChris Lattner ) 74830fdc8d8SChris Lattner { 749a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 75030fdc8d8SChris Lattner if (target == NULL) 75130fdc8d8SChris Lattner { 7529068d794SCaroline Tice result.AppendError ("Invalid target. No current target or breakpoints."); 75330fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 75430fdc8d8SChris Lattner return true; 75530fdc8d8SChris Lattner } 75630fdc8d8SChris Lattner 75730fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal); 7581b54c88cSJim Ingham Mutex::Locker locker; 7591b54c88cSJim Ingham target->GetBreakpointList(m_options.m_internal).GetListMutex(locker); 7601b54c88cSJim Ingham 76130fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 76230fdc8d8SChris Lattner 76330fdc8d8SChris Lattner if (num_breakpoints == 0) 76430fdc8d8SChris Lattner { 76530fdc8d8SChris Lattner result.AppendMessage ("No breakpoints currently set."); 76630fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 76730fdc8d8SChris Lattner return true; 76830fdc8d8SChris Lattner } 76930fdc8d8SChris Lattner 77085e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 77130fdc8d8SChris Lattner 77230fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 77330fdc8d8SChris Lattner { 77430fdc8d8SChris Lattner // No breakpoint selected; show info about all currently set breakpoints. 77530fdc8d8SChris Lattner result.AppendMessage ("Current breakpoints:"); 776c982c768SGreg Clayton for (size_t i = 0; i < num_breakpoints; ++i) 77730fdc8d8SChris Lattner { 7789fed0d85SGreg Clayton Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get(); 7796611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 78030fdc8d8SChris Lattner } 78130fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 78230fdc8d8SChris Lattner } 78330fdc8d8SChris Lattner else 78430fdc8d8SChris Lattner { 78530fdc8d8SChris Lattner // Particular breakpoints selected; show info about that breakpoint. 78630fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 78730fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 78830fdc8d8SChris Lattner 78930fdc8d8SChris Lattner if (result.Succeeded()) 79030fdc8d8SChris Lattner { 791c982c768SGreg Clayton for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) 79230fdc8d8SChris Lattner { 79330fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 79430fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 7956611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 79630fdc8d8SChris Lattner } 79730fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 79830fdc8d8SChris Lattner } 79930fdc8d8SChris Lattner else 80030fdc8d8SChris Lattner { 80130fdc8d8SChris Lattner result.AppendError ("Invalid breakpoint id."); 80230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 80330fdc8d8SChris Lattner } 80430fdc8d8SChris Lattner } 80530fdc8d8SChris Lattner 80630fdc8d8SChris Lattner return result.Succeeded(); 80730fdc8d8SChris Lattner } 80830fdc8d8SChris Lattner 80930fdc8d8SChris Lattner //------------------------------------------------------------------------- 81030fdc8d8SChris Lattner // CommandObjectBreakpointEnable 81130fdc8d8SChris Lattner //------------------------------------------------------------------------- 812ae1c4cf5SJim Ingham #pragma mark Enable 81330fdc8d8SChris Lattner 814a7015092SGreg Clayton CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) : 815a7015092SGreg Clayton CommandObject (interpreter, 816a7015092SGreg Clayton "enable", 817e3d26315SCaroline Tice "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.", 818e139cf23SCaroline Tice NULL) 81930fdc8d8SChris Lattner { 820e139cf23SCaroline Tice CommandArgumentEntry arg; 821de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 822e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 823e139cf23SCaroline Tice m_arguments.push_back (arg); 82430fdc8d8SChris Lattner } 82530fdc8d8SChris Lattner 82630fdc8d8SChris Lattner 82730fdc8d8SChris Lattner CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable () 82830fdc8d8SChris Lattner { 82930fdc8d8SChris Lattner } 83030fdc8d8SChris Lattner 83130fdc8d8SChris Lattner 83230fdc8d8SChris Lattner bool 8336611103cSGreg Clayton CommandObjectBreakpointEnable::Execute 8346611103cSGreg Clayton ( 8356611103cSGreg Clayton Args& args, 8366611103cSGreg Clayton CommandReturnObject &result 8376611103cSGreg Clayton ) 83830fdc8d8SChris Lattner { 839a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 84030fdc8d8SChris Lattner if (target == NULL) 84130fdc8d8SChris Lattner { 8429068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 84330fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 84430fdc8d8SChris Lattner return false; 84530fdc8d8SChris Lattner } 84630fdc8d8SChris Lattner 8471b54c88cSJim Ingham Mutex::Locker locker; 8481b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 8491b54c88cSJim Ingham 85030fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 8511b54c88cSJim Ingham 85230fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 85330fdc8d8SChris Lattner 85430fdc8d8SChris Lattner if (num_breakpoints == 0) 85530fdc8d8SChris Lattner { 85630fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be enabled."); 85730fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 85830fdc8d8SChris Lattner return false; 85930fdc8d8SChris Lattner } 86030fdc8d8SChris Lattner 86130fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 86230fdc8d8SChris Lattner { 86330fdc8d8SChris Lattner // No breakpoint selected; enable all currently set breakpoints. 86430fdc8d8SChris Lattner target->EnableAllBreakpoints (); 865fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints enabled. (%lu breakpoints)\n", num_breakpoints); 86630fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 86730fdc8d8SChris Lattner } 86830fdc8d8SChris Lattner else 86930fdc8d8SChris Lattner { 87030fdc8d8SChris Lattner // Particular breakpoint selected; enable that breakpoint. 87130fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 87230fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 87330fdc8d8SChris Lattner 87430fdc8d8SChris Lattner if (result.Succeeded()) 87530fdc8d8SChris Lattner { 87630fdc8d8SChris Lattner int enable_count = 0; 87730fdc8d8SChris Lattner int loc_count = 0; 878c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 879c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 88030fdc8d8SChris Lattner { 88130fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 88230fdc8d8SChris Lattner 88330fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 88430fdc8d8SChris Lattner { 88530fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 88630fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 88730fdc8d8SChris Lattner { 88830fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 88930fdc8d8SChris Lattner if (location) 89030fdc8d8SChris Lattner { 89130fdc8d8SChris Lattner location->SetEnabled (true); 89230fdc8d8SChris Lattner ++loc_count; 89330fdc8d8SChris Lattner } 89430fdc8d8SChris Lattner } 89530fdc8d8SChris Lattner else 89630fdc8d8SChris Lattner { 897ae1c4cf5SJim Ingham breakpoint->SetEnabled (true); 89830fdc8d8SChris Lattner ++enable_count; 89930fdc8d8SChris Lattner } 90030fdc8d8SChris Lattner } 90130fdc8d8SChris Lattner } 90230fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count); 90330fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 90430fdc8d8SChris Lattner } 90530fdc8d8SChris Lattner } 90630fdc8d8SChris Lattner 90730fdc8d8SChris Lattner return result.Succeeded(); 90830fdc8d8SChris Lattner } 90930fdc8d8SChris Lattner 91030fdc8d8SChris Lattner //------------------------------------------------------------------------- 91130fdc8d8SChris Lattner // CommandObjectBreakpointDisable 91230fdc8d8SChris Lattner //------------------------------------------------------------------------- 913ae1c4cf5SJim Ingham #pragma mark Disable 91430fdc8d8SChris Lattner 915a7015092SGreg Clayton CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) : 916a7015092SGreg Clayton CommandObject (interpreter, 917e139cf23SCaroline Tice "breakpoint disable", 918e3d26315SCaroline Tice "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.", 919e139cf23SCaroline Tice NULL) 92030fdc8d8SChris Lattner { 921e139cf23SCaroline Tice CommandArgumentEntry arg; 922de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 923e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 924e139cf23SCaroline Tice m_arguments.push_back (arg); 92530fdc8d8SChris Lattner } 92630fdc8d8SChris Lattner 92730fdc8d8SChris Lattner CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable () 92830fdc8d8SChris Lattner { 92930fdc8d8SChris Lattner } 93030fdc8d8SChris Lattner 93130fdc8d8SChris Lattner bool 9326611103cSGreg Clayton CommandObjectBreakpointDisable::Execute 9336611103cSGreg Clayton ( 9346611103cSGreg Clayton Args& args, 9356611103cSGreg Clayton CommandReturnObject &result 9366611103cSGreg Clayton ) 93730fdc8d8SChris Lattner { 938a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 93930fdc8d8SChris Lattner if (target == NULL) 94030fdc8d8SChris Lattner { 9419068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 94230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 94330fdc8d8SChris Lattner return false; 94430fdc8d8SChris Lattner } 94530fdc8d8SChris Lattner 9461b54c88cSJim Ingham Mutex::Locker locker; 9471b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 9481b54c88cSJim Ingham 94930fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 95030fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 95130fdc8d8SChris Lattner 95230fdc8d8SChris Lattner if (num_breakpoints == 0) 95330fdc8d8SChris Lattner { 95430fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be disabled."); 95530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 95630fdc8d8SChris Lattner return false; 95730fdc8d8SChris Lattner } 95830fdc8d8SChris Lattner 95930fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 96030fdc8d8SChris Lattner { 96130fdc8d8SChris Lattner // No breakpoint selected; disable all currently set breakpoints. 96230fdc8d8SChris Lattner target->DisableAllBreakpoints (); 963fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints disabled. (%lu breakpoints)\n", num_breakpoints); 96430fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 96530fdc8d8SChris Lattner } 96630fdc8d8SChris Lattner else 96730fdc8d8SChris Lattner { 96830fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 96930fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 97030fdc8d8SChris Lattner 97130fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 97230fdc8d8SChris Lattner 97330fdc8d8SChris Lattner if (result.Succeeded()) 97430fdc8d8SChris Lattner { 97530fdc8d8SChris Lattner int disable_count = 0; 97630fdc8d8SChris Lattner int loc_count = 0; 977c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 978c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 97930fdc8d8SChris Lattner { 98030fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 98130fdc8d8SChris Lattner 98230fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 98330fdc8d8SChris Lattner { 98430fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 98530fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 98630fdc8d8SChris Lattner { 98730fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 98830fdc8d8SChris Lattner if (location) 98930fdc8d8SChris Lattner { 99030fdc8d8SChris Lattner location->SetEnabled (false); 99130fdc8d8SChris Lattner ++loc_count; 99230fdc8d8SChris Lattner } 99330fdc8d8SChris Lattner } 99430fdc8d8SChris Lattner else 99530fdc8d8SChris Lattner { 996ae1c4cf5SJim Ingham breakpoint->SetEnabled (false); 99730fdc8d8SChris Lattner ++disable_count; 99830fdc8d8SChris Lattner } 99930fdc8d8SChris Lattner } 100030fdc8d8SChris Lattner } 100130fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count); 100230fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 100330fdc8d8SChris Lattner } 100430fdc8d8SChris Lattner } 100530fdc8d8SChris Lattner 100630fdc8d8SChris Lattner return result.Succeeded(); 100730fdc8d8SChris Lattner } 100830fdc8d8SChris Lattner 100930fdc8d8SChris Lattner //------------------------------------------------------------------------- 1010b7234e40SJohnny Chen // CommandObjectBreakpointClear::CommandOptions 1011b7234e40SJohnny Chen //------------------------------------------------------------------------- 1012b7234e40SJohnny Chen #pragma mark Clear::CommandOptions 1013b7234e40SJohnny Chen 1014eb0103f2SGreg Clayton CommandObjectBreakpointClear::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 1015eb0103f2SGreg Clayton Options (interpreter), 1016b7234e40SJohnny Chen m_filename (), 1017b7234e40SJohnny Chen m_line_num (0) 1018b7234e40SJohnny Chen { 1019b7234e40SJohnny Chen } 1020b7234e40SJohnny Chen 1021b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::~CommandOptions () 1022b7234e40SJohnny Chen { 1023b7234e40SJohnny Chen } 1024b7234e40SJohnny Chen 1025e0d378b3SGreg Clayton OptionDefinition 1026b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::g_option_table[] = 1027b7234e40SJohnny Chen { 1028b7234e40SJohnny Chen { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, 1029b7234e40SJohnny Chen "Specify the breakpoint by source location in this particular file."}, 1030b7234e40SJohnny Chen 1031b7234e40SJohnny Chen { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, 1032b7234e40SJohnny Chen "Specify the breakpoint by source location at this particular line."}, 1033b7234e40SJohnny Chen 1034b7234e40SJohnny Chen { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 1035b7234e40SJohnny Chen }; 1036b7234e40SJohnny Chen 1037e0d378b3SGreg Clayton const OptionDefinition* 1038b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::GetDefinitions () 1039b7234e40SJohnny Chen { 1040b7234e40SJohnny Chen return g_option_table; 1041b7234e40SJohnny Chen } 1042b7234e40SJohnny Chen 1043b7234e40SJohnny Chen Error 1044f6b8b581SGreg Clayton CommandObjectBreakpointClear::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 1045b7234e40SJohnny Chen { 1046b7234e40SJohnny Chen Error error; 1047b7234e40SJohnny Chen char short_option = (char) m_getopt_table[option_idx].val; 1048b7234e40SJohnny Chen 1049b7234e40SJohnny Chen switch (short_option) 1050b7234e40SJohnny Chen { 1051b7234e40SJohnny Chen case 'f': 1052357132ebSGreg Clayton m_filename.assign (option_arg); 1053b7234e40SJohnny Chen break; 1054b7234e40SJohnny Chen 1055b7234e40SJohnny Chen case 'l': 1056b7234e40SJohnny Chen m_line_num = Args::StringToUInt32 (option_arg, 0); 1057b7234e40SJohnny Chen break; 1058b7234e40SJohnny Chen 1059b7234e40SJohnny Chen default: 1060*86edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 1061b7234e40SJohnny Chen break; 1062b7234e40SJohnny Chen } 1063b7234e40SJohnny Chen 1064b7234e40SJohnny Chen return error; 1065b7234e40SJohnny Chen } 1066b7234e40SJohnny Chen 1067b7234e40SJohnny Chen void 1068f6b8b581SGreg Clayton CommandObjectBreakpointClear::CommandOptions::OptionParsingStarting () 1069b7234e40SJohnny Chen { 1070b7234e40SJohnny Chen m_filename.clear(); 1071b7234e40SJohnny Chen m_line_num = 0; 1072b7234e40SJohnny Chen } 1073b7234e40SJohnny Chen 1074b7234e40SJohnny Chen //------------------------------------------------------------------------- 1075b7234e40SJohnny Chen // CommandObjectBreakpointClear 1076b7234e40SJohnny Chen //------------------------------------------------------------------------- 1077b7234e40SJohnny Chen #pragma mark Clear 1078b7234e40SJohnny Chen 1079b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandObjectBreakpointClear (CommandInterpreter &interpreter) : 1080b7234e40SJohnny Chen CommandObject (interpreter, 1081b7234e40SJohnny Chen "breakpoint clear", 1082b7234e40SJohnny Chen "Clears a breakpoint or set of breakpoints in the executable.", 1083eb0103f2SGreg Clayton "breakpoint clear <cmd-options>"), 1084eb0103f2SGreg Clayton m_options (interpreter) 1085b7234e40SJohnny Chen { 1086b7234e40SJohnny Chen } 1087b7234e40SJohnny Chen 1088b7234e40SJohnny Chen CommandObjectBreakpointClear::~CommandObjectBreakpointClear () 1089b7234e40SJohnny Chen { 1090b7234e40SJohnny Chen } 1091b7234e40SJohnny Chen 1092b7234e40SJohnny Chen Options * 1093b7234e40SJohnny Chen CommandObjectBreakpointClear::GetOptions () 1094b7234e40SJohnny Chen { 1095b7234e40SJohnny Chen return &m_options; 1096b7234e40SJohnny Chen } 1097b7234e40SJohnny Chen 1098b7234e40SJohnny Chen bool 1099b7234e40SJohnny Chen CommandObjectBreakpointClear::Execute 1100b7234e40SJohnny Chen ( 1101b7234e40SJohnny Chen Args& command, 1102b7234e40SJohnny Chen CommandReturnObject &result 1103b7234e40SJohnny Chen ) 1104b7234e40SJohnny Chen { 1105b7234e40SJohnny Chen Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 1106b7234e40SJohnny Chen if (target == NULL) 1107b7234e40SJohnny Chen { 1108b7234e40SJohnny Chen result.AppendError ("Invalid target. No existing target or breakpoints."); 1109b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1110b7234e40SJohnny Chen return false; 1111b7234e40SJohnny Chen } 1112b7234e40SJohnny Chen 1113b7234e40SJohnny Chen // The following are the various types of breakpoints that could be cleared: 1114b7234e40SJohnny Chen // 1). -f -l (clearing breakpoint by source location) 1115b7234e40SJohnny Chen 1116b7234e40SJohnny Chen BreakpointClearType break_type = eClearTypeInvalid; 1117b7234e40SJohnny Chen 1118b7234e40SJohnny Chen if (m_options.m_line_num != 0) 1119b7234e40SJohnny Chen break_type = eClearTypeFileAndLine; 1120b7234e40SJohnny Chen 1121b7234e40SJohnny Chen Mutex::Locker locker; 1122b7234e40SJohnny Chen target->GetBreakpointList().GetListMutex(locker); 1123b7234e40SJohnny Chen 1124b7234e40SJohnny Chen BreakpointList &breakpoints = target->GetBreakpointList(); 1125b7234e40SJohnny Chen size_t num_breakpoints = breakpoints.GetSize(); 1126b7234e40SJohnny Chen 1127b7234e40SJohnny Chen // Early return if there's no breakpoint at all. 1128b7234e40SJohnny Chen if (num_breakpoints == 0) 1129b7234e40SJohnny Chen { 1130b7234e40SJohnny Chen result.AppendError ("Breakpoint clear: No breakpoint cleared."); 1131b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1132b7234e40SJohnny Chen return result.Succeeded(); 1133b7234e40SJohnny Chen } 1134b7234e40SJohnny Chen 1135b7234e40SJohnny Chen // Find matching breakpoints and delete them. 1136b7234e40SJohnny Chen 1137b7234e40SJohnny Chen // First create a copy of all the IDs. 1138b7234e40SJohnny Chen std::vector<break_id_t> BreakIDs; 1139b7234e40SJohnny Chen for (size_t i = 0; i < num_breakpoints; ++i) 1140b7234e40SJohnny Chen BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID()); 1141b7234e40SJohnny Chen 1142b7234e40SJohnny Chen int num_cleared = 0; 1143b7234e40SJohnny Chen StreamString ss; 1144b7234e40SJohnny Chen switch (break_type) 1145b7234e40SJohnny Chen { 1146b7234e40SJohnny Chen case eClearTypeFileAndLine: // Breakpoint by source position 1147b7234e40SJohnny Chen { 1148b7234e40SJohnny Chen const ConstString filename(m_options.m_filename.c_str()); 1149b7234e40SJohnny Chen BreakpointLocationCollection loc_coll; 1150b7234e40SJohnny Chen 1151b7234e40SJohnny Chen for (size_t i = 0; i < num_breakpoints; ++i) 1152b7234e40SJohnny Chen { 1153b7234e40SJohnny Chen Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); 1154b7234e40SJohnny Chen 1155b7234e40SJohnny Chen if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) 1156b7234e40SJohnny Chen { 1157b7234e40SJohnny Chen // If the collection size is 0, it's a full match and we can just remove the breakpoint. 1158b7234e40SJohnny Chen if (loc_coll.GetSize() == 0) 1159b7234e40SJohnny Chen { 1160b7234e40SJohnny Chen bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); 1161b7234e40SJohnny Chen ss.EOL(); 1162b7234e40SJohnny Chen target->RemoveBreakpointByID (bp->GetID()); 1163b7234e40SJohnny Chen ++num_cleared; 1164b7234e40SJohnny Chen } 1165b7234e40SJohnny Chen } 1166b7234e40SJohnny Chen } 1167b7234e40SJohnny Chen } 1168b7234e40SJohnny Chen break; 1169b7234e40SJohnny Chen 1170b7234e40SJohnny Chen default: 1171b7234e40SJohnny Chen break; 1172b7234e40SJohnny Chen } 1173b7234e40SJohnny Chen 1174b7234e40SJohnny Chen if (num_cleared > 0) 1175b7234e40SJohnny Chen { 117685e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 1177b7234e40SJohnny Chen output_stream.Printf ("%d breakpoints cleared:\n", num_cleared); 1178b7234e40SJohnny Chen output_stream << ss.GetData(); 1179b7234e40SJohnny Chen output_stream.EOL(); 1180b7234e40SJohnny Chen result.SetStatus (eReturnStatusSuccessFinishNoResult); 1181b7234e40SJohnny Chen } 1182b7234e40SJohnny Chen else 1183b7234e40SJohnny Chen { 1184b7234e40SJohnny Chen result.AppendError ("Breakpoint clear: No breakpoint cleared."); 1185b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1186b7234e40SJohnny Chen } 1187b7234e40SJohnny Chen 1188b7234e40SJohnny Chen return result.Succeeded(); 1189b7234e40SJohnny Chen } 1190b7234e40SJohnny Chen 1191b7234e40SJohnny Chen //------------------------------------------------------------------------- 119230fdc8d8SChris Lattner // CommandObjectBreakpointDelete 119330fdc8d8SChris Lattner //------------------------------------------------------------------------- 1194ae1c4cf5SJim Ingham #pragma mark Delete 119530fdc8d8SChris Lattner 1196a7015092SGreg Clayton CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) : 1197a7015092SGreg Clayton CommandObject (interpreter, 1198a7015092SGreg Clayton "breakpoint delete", 1199e3d26315SCaroline Tice "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.", 1200e139cf23SCaroline Tice NULL) 120130fdc8d8SChris Lattner { 1202e139cf23SCaroline Tice CommandArgumentEntry arg; 1203de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 1204e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1205e139cf23SCaroline Tice m_arguments.push_back (arg); 120630fdc8d8SChris Lattner } 120730fdc8d8SChris Lattner 120830fdc8d8SChris Lattner 120930fdc8d8SChris Lattner CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete () 121030fdc8d8SChris Lattner { 121130fdc8d8SChris Lattner } 121230fdc8d8SChris Lattner 121330fdc8d8SChris Lattner bool 12146611103cSGreg Clayton CommandObjectBreakpointDelete::Execute 12156611103cSGreg Clayton ( 12166611103cSGreg Clayton Args& args, 12176611103cSGreg Clayton CommandReturnObject &result 12186611103cSGreg Clayton ) 121930fdc8d8SChris Lattner { 1220a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 122130fdc8d8SChris Lattner if (target == NULL) 122230fdc8d8SChris Lattner { 12239068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 122430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 122530fdc8d8SChris Lattner return false; 122630fdc8d8SChris Lattner } 122730fdc8d8SChris Lattner 12281b54c88cSJim Ingham Mutex::Locker locker; 12291b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 12301b54c88cSJim Ingham 123130fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 12321b54c88cSJim Ingham 123330fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 123430fdc8d8SChris Lattner 123530fdc8d8SChris Lattner if (num_breakpoints == 0) 123630fdc8d8SChris Lattner { 123730fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be deleted."); 123830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 123930fdc8d8SChris Lattner return false; 124030fdc8d8SChris Lattner } 124130fdc8d8SChris Lattner 124230fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 124330fdc8d8SChris Lattner { 124436f3b369SJim Ingham if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true)) 124530fdc8d8SChris Lattner { 124636f3b369SJim Ingham result.AppendMessage("Operation cancelled..."); 124730fdc8d8SChris Lattner } 124836f3b369SJim Ingham else 124936f3b369SJim Ingham { 125030fdc8d8SChris Lattner target->RemoveAllBreakpoints (); 1251fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints removed. (%lu breakpoints)\n", num_breakpoints); 125236f3b369SJim Ingham } 125330fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 125430fdc8d8SChris Lattner } 125530fdc8d8SChris Lattner else 125630fdc8d8SChris Lattner { 125730fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 125830fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 125930fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 126030fdc8d8SChris Lattner 126130fdc8d8SChris Lattner if (result.Succeeded()) 126230fdc8d8SChris Lattner { 126330fdc8d8SChris Lattner int delete_count = 0; 126430fdc8d8SChris Lattner int disable_count = 0; 1265c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1266c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 126730fdc8d8SChris Lattner { 126830fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 126930fdc8d8SChris Lattner 127030fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 127130fdc8d8SChris Lattner { 127230fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 127330fdc8d8SChris Lattner { 127430fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 127530fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 127630fdc8d8SChris Lattner // It makes no sense to try to delete individual locations, so we disable them instead. 127730fdc8d8SChris Lattner if (location) 127830fdc8d8SChris Lattner { 127930fdc8d8SChris Lattner location->SetEnabled (false); 128030fdc8d8SChris Lattner ++disable_count; 128130fdc8d8SChris Lattner } 128230fdc8d8SChris Lattner } 128330fdc8d8SChris Lattner else 128430fdc8d8SChris Lattner { 128530fdc8d8SChris Lattner target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID()); 128630fdc8d8SChris Lattner ++delete_count; 128730fdc8d8SChris Lattner } 128830fdc8d8SChris Lattner } 128930fdc8d8SChris Lattner } 129030fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n", 129130fdc8d8SChris Lattner delete_count, disable_count); 129230fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 129330fdc8d8SChris Lattner } 129430fdc8d8SChris Lattner } 129530fdc8d8SChris Lattner return result.Succeeded(); 129630fdc8d8SChris Lattner } 12971b54c88cSJim Ingham 12981b54c88cSJim Ingham //------------------------------------------------------------------------- 1299ae1c4cf5SJim Ingham // CommandObjectBreakpointModify::CommandOptions 13001b54c88cSJim Ingham //------------------------------------------------------------------------- 1301ae1c4cf5SJim Ingham #pragma mark Modify::CommandOptions 13021b54c88cSJim Ingham 1303eb0103f2SGreg Clayton CommandObjectBreakpointModify::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 1304eb0103f2SGreg Clayton Options (interpreter), 1305c982c768SGreg Clayton m_ignore_count (0), 13061b54c88cSJim Ingham m_thread_id(LLDB_INVALID_THREAD_ID), 1307e0a97848SJim Ingham m_thread_id_passed(false), 1308c982c768SGreg Clayton m_thread_index (UINT32_MAX), 1309e0a97848SJim Ingham m_thread_index_passed(false), 13101b54c88cSJim Ingham m_thread_name(), 13111b54c88cSJim Ingham m_queue_name(), 131236f3b369SJim Ingham m_condition (), 1313c982c768SGreg Clayton m_enable_passed (false), 1314c982c768SGreg Clayton m_enable_value (false), 1315c982c768SGreg Clayton m_name_passed (false), 131636f3b369SJim Ingham m_queue_passed (false), 131736f3b369SJim Ingham m_condition_passed (false) 13181b54c88cSJim Ingham { 13191b54c88cSJim Ingham } 13201b54c88cSJim Ingham 1321ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::~CommandOptions () 13221b54c88cSJim Ingham { 13231b54c88cSJim Ingham } 13241b54c88cSJim Ingham 1325e0d378b3SGreg Clayton OptionDefinition 1326ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] = 13271b54c88cSJim Ingham { 1328deaab222SCaroline 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." }, 1329deaab222SCaroline 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."}, 1330deaab222SCaroline 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."}, 1331deaab222SCaroline 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."}, 1332deaab222SCaroline 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."}, 133336f3b369SJim Ingham { LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, NULL, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."}, 1334deaab222SCaroline Tice { LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, eArgTypeNone, "Enable the breakpoint."}, 1335deaab222SCaroline Tice { LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, eArgTypeNone, "Disable the breakpoint."}, 1336deaab222SCaroline Tice { 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } 13371b54c88cSJim Ingham }; 13381b54c88cSJim Ingham 1339e0d378b3SGreg Clayton const OptionDefinition* 1340ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::GetDefinitions () 13411b54c88cSJim Ingham { 13421b54c88cSJim Ingham return g_option_table; 13431b54c88cSJim Ingham } 13441b54c88cSJim Ingham 13451b54c88cSJim Ingham Error 1346f6b8b581SGreg Clayton CommandObjectBreakpointModify::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 13471b54c88cSJim Ingham { 13481b54c88cSJim Ingham Error error; 13491b54c88cSJim Ingham char short_option = (char) m_getopt_table[option_idx].val; 13501b54c88cSJim Ingham 13511b54c88cSJim Ingham switch (short_option) 13521b54c88cSJim Ingham { 135336f3b369SJim Ingham case 'c': 135436f3b369SJim Ingham if (option_arg != NULL) 1355357132ebSGreg Clayton m_condition.assign (option_arg); 135636f3b369SJim Ingham else 135736f3b369SJim Ingham m_condition.clear(); 135836f3b369SJim Ingham m_condition_passed = true; 135936f3b369SJim Ingham break; 1360ae1c4cf5SJim Ingham case 'd': 1361ae1c4cf5SJim Ingham m_enable_passed = true; 1362ae1c4cf5SJim Ingham m_enable_value = false; 1363ae1c4cf5SJim Ingham break; 1364ae1c4cf5SJim Ingham case 'e': 1365ae1c4cf5SJim Ingham m_enable_passed = true; 1366ae1c4cf5SJim Ingham m_enable_value = true; 1367ae1c4cf5SJim Ingham break; 1368ed8a705cSGreg Clayton case 'i': 13691b54c88cSJim Ingham { 13700292f4a5SJim Ingham m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 1371c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 1372*86edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); 13731b54c88cSJim Ingham } 1374ae1c4cf5SJim Ingham break; 13751b54c88cSJim Ingham case 't' : 13761b54c88cSJim Ingham { 13770292f4a5SJim Ingham if (option_arg[0] == '\0') 1378e0a97848SJim Ingham { 1379e0a97848SJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 1380e0a97848SJim Ingham m_thread_id_passed = true; 1381e0a97848SJim Ingham } 1382e0a97848SJim Ingham else 1383e0a97848SJim Ingham { 13840292f4a5SJim Ingham m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 13851b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 1386*86edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); 1387e0a97848SJim Ingham else 1388e0a97848SJim Ingham m_thread_id_passed = true; 1389e0a97848SJim Ingham } 13901b54c88cSJim Ingham } 13911b54c88cSJim Ingham break; 13921b54c88cSJim Ingham case 'T': 1393b2a38a72SJim Ingham if (option_arg != NULL) 1394357132ebSGreg Clayton m_thread_name.assign (option_arg); 1395b2a38a72SJim Ingham else 1396b2a38a72SJim Ingham m_thread_name.clear(); 1397b2a38a72SJim Ingham m_name_passed = true; 13981b54c88cSJim Ingham break; 13991b54c88cSJim Ingham case 'q': 1400b2a38a72SJim Ingham if (option_arg != NULL) 1401357132ebSGreg Clayton m_queue_name.assign (option_arg); 1402b2a38a72SJim Ingham else 1403b2a38a72SJim Ingham m_queue_name.clear(); 1404b2a38a72SJim Ingham m_queue_passed = true; 14051b54c88cSJim Ingham break; 14061b54c88cSJim Ingham case 'x': 14071b54c88cSJim Ingham { 14080292f4a5SJim Ingham if (option_arg[0] == '\n') 1409e0a97848SJim Ingham { 1410e0a97848SJim Ingham m_thread_index = UINT32_MAX; 1411e0a97848SJim Ingham m_thread_index_passed = true; 1412e0a97848SJim Ingham } 1413e0a97848SJim Ingham else 1414e0a97848SJim Ingham { 14150292f4a5SJim Ingham m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0); 1416c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 1417*86edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); 1418e0a97848SJim Ingham else 1419e0a97848SJim Ingham m_thread_index_passed = true; 1420e0a97848SJim Ingham } 14211b54c88cSJim Ingham } 14221b54c88cSJim Ingham break; 14231b54c88cSJim Ingham default: 1424*86edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 14251b54c88cSJim Ingham break; 14261b54c88cSJim Ingham } 14271b54c88cSJim Ingham 14281b54c88cSJim Ingham return error; 14291b54c88cSJim Ingham } 14301b54c88cSJim Ingham 14311b54c88cSJim Ingham void 1432f6b8b581SGreg Clayton CommandObjectBreakpointModify::CommandOptions::OptionParsingStarting () 14331b54c88cSJim Ingham { 1434c982c768SGreg Clayton m_ignore_count = 0; 14351b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 1436e0a97848SJim Ingham m_thread_id_passed = false; 1437c982c768SGreg Clayton m_thread_index = UINT32_MAX; 1438e0a97848SJim Ingham m_thread_index_passed = false; 14391b54c88cSJim Ingham m_thread_name.clear(); 14401b54c88cSJim Ingham m_queue_name.clear(); 144136f3b369SJim Ingham m_condition.clear(); 1442ae1c4cf5SJim Ingham m_enable_passed = false; 1443b2a38a72SJim Ingham m_queue_passed = false; 1444b2a38a72SJim Ingham m_name_passed = false; 144536f3b369SJim Ingham m_condition_passed = false; 14461b54c88cSJim Ingham } 14471b54c88cSJim Ingham 14481b54c88cSJim Ingham //------------------------------------------------------------------------- 1449ae1c4cf5SJim Ingham // CommandObjectBreakpointModify 14501b54c88cSJim Ingham //------------------------------------------------------------------------- 1451ae1c4cf5SJim Ingham #pragma mark Modify 14521b54c88cSJim Ingham 1453a7015092SGreg Clayton CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) : 1454a7015092SGreg Clayton CommandObject (interpreter, 1455a7015092SGreg Clayton "breakpoint modify", 1456a571c010SJim Ingham "Modify the options on a breakpoint or set of breakpoints in the executable. " 1457e0a97848SJim Ingham "If no breakpoint is specified, acts on the last created breakpoint. " 1458e0a97848SJim Ingham "With the exception of -e, -d and -i, passing an empty argument clears the modification.", 1459eb0103f2SGreg Clayton NULL), 1460eb0103f2SGreg Clayton m_options (interpreter) 14611b54c88cSJim Ingham { 1462e139cf23SCaroline Tice CommandArgumentEntry arg; 1463de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 1464e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1465e139cf23SCaroline Tice m_arguments.push_back (arg); 14661b54c88cSJim Ingham } 14671b54c88cSJim Ingham 1468ae1c4cf5SJim Ingham CommandObjectBreakpointModify::~CommandObjectBreakpointModify () 14691b54c88cSJim Ingham { 14701b54c88cSJim Ingham } 14711b54c88cSJim Ingham 14721b54c88cSJim Ingham Options * 1473ae1c4cf5SJim Ingham CommandObjectBreakpointModify::GetOptions () 14741b54c88cSJim Ingham { 14751b54c88cSJim Ingham return &m_options; 14761b54c88cSJim Ingham } 14771b54c88cSJim Ingham 14781b54c88cSJim Ingham bool 1479ae1c4cf5SJim Ingham CommandObjectBreakpointModify::Execute 14801b54c88cSJim Ingham ( 14811b54c88cSJim Ingham Args& command, 14821b54c88cSJim Ingham CommandReturnObject &result 14831b54c88cSJim Ingham ) 14841b54c88cSJim Ingham { 1485a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 14861b54c88cSJim Ingham if (target == NULL) 14871b54c88cSJim Ingham { 14889068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 14891b54c88cSJim Ingham result.SetStatus (eReturnStatusFailed); 14901b54c88cSJim Ingham return false; 14911b54c88cSJim Ingham } 14921b54c88cSJim Ingham 14931b54c88cSJim Ingham Mutex::Locker locker; 14941b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 14951b54c88cSJim Ingham 14961b54c88cSJim Ingham BreakpointIDList valid_bp_ids; 14971b54c88cSJim Ingham 14981b54c88cSJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 14991b54c88cSJim Ingham 15001b54c88cSJim Ingham if (result.Succeeded()) 15011b54c88cSJim Ingham { 1502c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1503c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 15041b54c88cSJim Ingham { 15051b54c88cSJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 15061b54c88cSJim Ingham 15071b54c88cSJim Ingham if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 15081b54c88cSJim Ingham { 15091b54c88cSJim Ingham Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 15101b54c88cSJim Ingham if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 15111b54c88cSJim Ingham { 15121b54c88cSJim Ingham BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get(); 15131b54c88cSJim Ingham if (location) 15141b54c88cSJim Ingham { 1515e0a97848SJim Ingham if (m_options.m_thread_id_passed) 15161b54c88cSJim Ingham location->SetThreadID (m_options.m_thread_id); 15171b54c88cSJim Ingham 1518e0a97848SJim Ingham if (m_options.m_thread_index_passed) 15191b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 15201b54c88cSJim Ingham 1521b2a38a72SJim Ingham if (m_options.m_name_passed) 15221b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 15231b54c88cSJim Ingham 1524b2a38a72SJim Ingham if (m_options.m_queue_passed) 15251b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 15261b54c88cSJim Ingham 1527c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 15281b54c88cSJim Ingham location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count); 1529ae1c4cf5SJim Ingham 1530ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1531ae1c4cf5SJim Ingham location->SetEnabled (m_options.m_enable_value); 153236f3b369SJim Ingham 153336f3b369SJim Ingham if (m_options.m_condition_passed) 153436f3b369SJim Ingham location->SetCondition (m_options.m_condition.c_str()); 15351b54c88cSJim Ingham } 15361b54c88cSJim Ingham } 15371b54c88cSJim Ingham else 15381b54c88cSJim Ingham { 1539e0a97848SJim Ingham if (m_options.m_thread_id_passed) 15401b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 15411b54c88cSJim Ingham 1542e0a97848SJim Ingham if (m_options.m_thread_index_passed) 15431b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 15441b54c88cSJim Ingham 1545b2a38a72SJim Ingham if (m_options.m_name_passed) 15461b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 15471b54c88cSJim Ingham 1548b2a38a72SJim Ingham if (m_options.m_queue_passed) 15491b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 15501b54c88cSJim Ingham 1551c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 15521b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 1553ae1c4cf5SJim Ingham 1554ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1555ae1c4cf5SJim Ingham bp->SetEnabled (m_options.m_enable_value); 1556ae1c4cf5SJim Ingham 155736f3b369SJim Ingham if (m_options.m_condition_passed) 155836f3b369SJim Ingham bp->SetCondition (m_options.m_condition.c_str()); 15591b54c88cSJim Ingham } 15601b54c88cSJim Ingham } 15611b54c88cSJim Ingham } 15621b54c88cSJim Ingham } 15631b54c88cSJim Ingham 15641b54c88cSJim Ingham return result.Succeeded(); 15651b54c88cSJim Ingham } 15661b54c88cSJim Ingham 15671b54c88cSJim Ingham 1568