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), 56fab10e89SJim Ingham m_func_names (), 57fab10e89SJim Ingham m_func_name_type_mask (eFunctionNameTypeNone), 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(), 66fab10e89SJim Ingham m_queue_name(), 67fab10e89SJim Ingham m_catch_bp (false), 68fab10e89SJim Ingham m_throw_bp (false), 69*a8558b62SJim Ingham m_language (eLanguageTypeUnknown), 70*a8558b62SJim Ingham m_skip_prologue (eLazyBoolCalculate) 7130fdc8d8SChris Lattner { 7230fdc8d8SChris Lattner } 7330fdc8d8SChris Lattner 7430fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::~CommandOptions () 7530fdc8d8SChris Lattner { 7630fdc8d8SChris Lattner } 7730fdc8d8SChris Lattner 786943e7c5SJohnny Chen // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to 796943e7c5SJohnny Chen // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately. 804ab2e6beSJohnny Chen #define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 ) 814ab2e6beSJohnny Chen #define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 ) 82*a8558b62SJim Ingham #define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) ) 8387df91b8SJim Ingham 84e0d378b3SGreg Clayton OptionDefinition 8530fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::g_option_table[] = 8630fdc8d8SChris Lattner { 87fab10e89SJim Ingham { LLDB_OPT_NOT_10, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName, 8864cc29cbSJim Ingham "Set the breakpoint only in this shared library. " 8964cc29cbSJim Ingham "Can repeat this option multiple times to specify multiple shared libraries."}, 908651121cSJim Ingham 91deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount, 92deaab222SCaroline Tice "Set the number of times this breakpoint is skipped before stopping." }, 931b54c88cSJim Ingham 94a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex, 95ed8a705cSGreg Clayton "The breakpoint stops only for the thread whose index matches this argument."}, 961b54c88cSJim Ingham 97a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID, 981b54c88cSJim Ingham "The breakpoint stops only for the thread whose TID matches this argument."}, 991b54c88cSJim Ingham 100a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName, 1011b54c88cSJim Ingham "The breakpoint stops only for the thread whose thread name matches this argument."}, 1021b54c88cSJim Ingham 103a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName, 1041b54c88cSJim Ingham "The breakpoint stops only for threads in the queue whose name is given by this argument."}, 1051b54c88cSJim Ingham 10687df91b8SJim Ingham { LLDB_OPT_FILE, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, 10787df91b8SJim Ingham "Specifies the source file in which to set this breakpoint."}, 10830fdc8d8SChris Lattner 109deaab222SCaroline Tice { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, 11087df91b8SJim Ingham "Specifies the line number on which to set this breakpoint."}, 11130fdc8d8SChris Lattner 11230fdc8d8SChris Lattner // Comment out this option for the moment, as we don't actually use it, but will in the future. 11330fdc8d8SChris Lattner // This way users won't see it, but the infrastructure is left in place. 11430fdc8d8SChris Lattner // { 0, false, "column", 'c', required_argument, NULL, "<column>", 11530fdc8d8SChris Lattner // "Set the breakpoint by source location at this particular column."}, 11630fdc8d8SChris Lattner 117deaab222SCaroline Tice { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, 11830fdc8d8SChris Lattner "Set the breakpoint by address, at the specified address."}, 11930fdc8d8SChris Lattner 120deaab222SCaroline Tice { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, 12164cc29cbSJim Ingham "Set the breakpoint by function name. Can be repeated multiple times to make one breakpoint for multiple snames" }, 12230fdc8d8SChris Lattner 123deaab222SCaroline Tice { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName, 12464cc29cbSJim Ingham "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and " 12564cc29cbSJim Ingham "for Objective C this means a full function prototype with class and selector. " 12664cc29cbSJim Ingham "Can be repeated multiple times to make one breakpoint for multiple names." }, 1270c5cd90dSGreg Clayton 128deaab222SCaroline Tice { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector, 12964cc29cbSJim Ingham "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." }, 1300c5cd90dSGreg Clayton 131deaab222SCaroline Tice { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod, 13264cc29cbSJim Ingham "Set the breakpoint by C++ method names. Can be repeated multiple times to make one breakpoint for multiple methods." }, 1330c5cd90dSGreg Clayton 134deaab222SCaroline Tice { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression, 13530fdc8d8SChris Lattner "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." }, 13630fdc8d8SChris Lattner 137e02b8504SGreg Clayton { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, 13864cc29cbSJim Ingham "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). " 13964cc29cbSJim Ingham "Can be repeated multiple times to make one breakpoint for multiple symbols." }, 140e02b8504SGreg Clayton 141969795f1SJim Ingham { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', required_argument, NULL, 0, eArgTypeRegularExpression, 142969795f1SJim Ingham "Set the breakpoint specifying a regular expression to match a pattern in the source text in a given source file." }, 143969795f1SJim Ingham 144fab10e89SJim Ingham { LLDB_OPT_SET_10, true, "language-exception", 'E', required_argument, NULL, 0, eArgTypeLanguage, 145fab10e89SJim Ingham "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" }, 146fab10e89SJim Ingham 147fab10e89SJim Ingham { LLDB_OPT_SET_10, false, "on-throw", 'w', required_argument, NULL, 0, eArgTypeBoolean, 148fab10e89SJim Ingham "Set the breakpoint on exception throW." }, 149fab10e89SJim Ingham 150fab10e89SJim Ingham { LLDB_OPT_SET_10, false, "on-catch", 'h', required_argument, NULL, 0, eArgTypeBoolean, 151fab10e89SJim Ingham "Set the breakpoint on exception catcH." }, 152969795f1SJim Ingham 153*a8558b62SJim Ingham { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', required_argument, NULL, 0, eArgTypeBoolean, 154*a8558b62SJim Ingham "sKip the prologue if the breakpoint is at the beginning of a function. If not set the target.skip-prologue setting is used." }, 155*a8558b62SJim Ingham 156deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 15730fdc8d8SChris Lattner }; 15830fdc8d8SChris Lattner 159e0d378b3SGreg Clayton const OptionDefinition* 16030fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::GetDefinitions () 16130fdc8d8SChris Lattner { 16230fdc8d8SChris Lattner return g_option_table; 16330fdc8d8SChris Lattner } 16430fdc8d8SChris Lattner 16530fdc8d8SChris Lattner Error 166f6b8b581SGreg Clayton CommandObjectBreakpointSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 16730fdc8d8SChris Lattner { 16830fdc8d8SChris Lattner Error error; 16930fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 17030fdc8d8SChris Lattner 17130fdc8d8SChris Lattner switch (short_option) 17230fdc8d8SChris Lattner { 17330fdc8d8SChris Lattner case 'a': 1740292f4a5SJim Ingham m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0); 17530fdc8d8SChris Lattner if (m_load_addr == LLDB_INVALID_ADDRESS) 1760292f4a5SJim Ingham m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16); 17730fdc8d8SChris Lattner 17830fdc8d8SChris Lattner if (m_load_addr == LLDB_INVALID_ADDRESS) 17986edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg); 18030fdc8d8SChris Lattner break; 18130fdc8d8SChris Lattner 18230fdc8d8SChris Lattner case 'c': 18330fdc8d8SChris Lattner m_column = Args::StringToUInt32 (option_arg, 0); 18430fdc8d8SChris Lattner break; 1850c5cd90dSGreg Clayton 18630fdc8d8SChris Lattner case 'f': 18787df91b8SJim Ingham m_filenames.AppendIfUnique (FileSpec(option_arg, false)); 18830fdc8d8SChris Lattner break; 1890c5cd90dSGreg Clayton 19030fdc8d8SChris Lattner case 'l': 19130fdc8d8SChris Lattner m_line_num = Args::StringToUInt32 (option_arg, 0); 19230fdc8d8SChris Lattner break; 1930c5cd90dSGreg Clayton 194e02b8504SGreg Clayton case 'b': 195fab10e89SJim Ingham m_func_names.push_back (option_arg); 1960c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeBase; 1970c5cd90dSGreg Clayton break; 1980c5cd90dSGreg Clayton 199e02b8504SGreg Clayton case 'n': 200fab10e89SJim Ingham m_func_names.push_back (option_arg); 201e02b8504SGreg Clayton m_func_name_type_mask |= eFunctionNameTypeAuto; 202e02b8504SGreg Clayton break; 203e02b8504SGreg Clayton 2040c5cd90dSGreg Clayton case 'F': 205fab10e89SJim Ingham m_func_names.push_back (option_arg); 2060c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeFull; 2070c5cd90dSGreg Clayton break; 2080c5cd90dSGreg Clayton 2090c5cd90dSGreg Clayton case 'S': 210fab10e89SJim Ingham m_func_names.push_back (option_arg); 2110c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeSelector; 2120c5cd90dSGreg Clayton break; 2130c5cd90dSGreg Clayton 2142561aa61SJim Ingham case 'M': 215fab10e89SJim Ingham m_func_names.push_back (option_arg); 2160c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeMethod; 2170c5cd90dSGreg Clayton break; 2180c5cd90dSGreg Clayton 219969795f1SJim Ingham case 'p': 220969795f1SJim Ingham m_source_text_regexp.assign (option_arg); 221969795f1SJim Ingham break; 222969795f1SJim Ingham 22330fdc8d8SChris Lattner case 'r': 224357132ebSGreg Clayton m_func_regexp.assign (option_arg); 22530fdc8d8SChris Lattner break; 2260c5cd90dSGreg Clayton 22730fdc8d8SChris Lattner case 's': 22830fdc8d8SChris Lattner { 22987df91b8SJim Ingham m_modules.AppendIfUnique (FileSpec (option_arg, false)); 23030fdc8d8SChris Lattner break; 23130fdc8d8SChris Lattner } 232ed8a705cSGreg Clayton case 'i': 2331b54c88cSJim Ingham { 2340292f4a5SJim Ingham m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 235c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 23686edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); 2371b54c88cSJim Ingham } 238ae1c4cf5SJim Ingham break; 2391b54c88cSJim Ingham case 't' : 2401b54c88cSJim Ingham { 2410292f4a5SJim Ingham m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 2421b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 24386edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); 2441b54c88cSJim Ingham } 2451b54c88cSJim Ingham break; 2461b54c88cSJim Ingham case 'T': 247357132ebSGreg Clayton m_thread_name.assign (option_arg); 2481b54c88cSJim Ingham break; 2491b54c88cSJim Ingham case 'q': 250357132ebSGreg Clayton m_queue_name.assign (option_arg); 2511b54c88cSJim Ingham break; 2521b54c88cSJim Ingham case 'x': 2531b54c88cSJim Ingham { 2540292f4a5SJim Ingham m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 255c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 25686edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); 2571b54c88cSJim Ingham 2581b54c88cSJim Ingham } 2591b54c88cSJim Ingham break; 260fab10e89SJim Ingham case 'E': 261fab10e89SJim Ingham { 262fab10e89SJim Ingham LanguageType language = LanguageRuntime::GetLanguageTypeFromString (option_arg); 263fab10e89SJim Ingham 264fab10e89SJim Ingham switch (language) 265fab10e89SJim Ingham { 266fab10e89SJim Ingham case eLanguageTypeC89: 267fab10e89SJim Ingham case eLanguageTypeC: 268fab10e89SJim Ingham case eLanguageTypeC99: 269fab10e89SJim Ingham m_language = eLanguageTypeC; 270fab10e89SJim Ingham break; 271fab10e89SJim Ingham case eLanguageTypeC_plus_plus: 272fab10e89SJim Ingham m_language = eLanguageTypeC_plus_plus; 273fab10e89SJim Ingham break; 274fab10e89SJim Ingham case eLanguageTypeObjC: 275fab10e89SJim Ingham m_language = eLanguageTypeObjC; 276fab10e89SJim Ingham break; 277fab10e89SJim Ingham case eLanguageTypeObjC_plus_plus: 278fab10e89SJim Ingham error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c"); 279fab10e89SJim Ingham break; 280fab10e89SJim Ingham case eLanguageTypeUnknown: 281fab10e89SJim Ingham error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg); 282fab10e89SJim Ingham break; 283fab10e89SJim Ingham default: 284fab10e89SJim Ingham error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg); 285fab10e89SJim Ingham } 286fab10e89SJim Ingham } 287fab10e89SJim Ingham break; 288fab10e89SJim Ingham case 'w': 289fab10e89SJim Ingham { 290fab10e89SJim Ingham bool success; 291fab10e89SJim Ingham m_throw_bp = Args::StringToBoolean (option_arg, true, &success); 292fab10e89SJim Ingham if (!success) 293fab10e89SJim Ingham error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg); 294fab10e89SJim Ingham } 295fab10e89SJim Ingham break; 296fab10e89SJim Ingham case 'h': 297fab10e89SJim Ingham { 298fab10e89SJim Ingham bool success; 299fab10e89SJim Ingham m_catch_bp = Args::StringToBoolean (option_arg, true, &success); 300fab10e89SJim Ingham if (!success) 301fab10e89SJim Ingham error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg); 302fab10e89SJim Ingham } 303*a8558b62SJim Ingham case 'K': 304*a8558b62SJim Ingham { 305*a8558b62SJim Ingham bool success; 306*a8558b62SJim Ingham bool value; 307*a8558b62SJim Ingham value = Args::StringToBoolean (option_arg, true, &success); 308*a8558b62SJim Ingham if (value) 309*a8558b62SJim Ingham m_skip_prologue = eLazyBoolYes; 310*a8558b62SJim Ingham else 311*a8558b62SJim Ingham m_skip_prologue = eLazyBoolNo; 312*a8558b62SJim Ingham 313*a8558b62SJim Ingham if (!success) 314*a8558b62SJim Ingham error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg); 315*a8558b62SJim Ingham } 316fab10e89SJim Ingham break; 31730fdc8d8SChris Lattner default: 31886edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 31930fdc8d8SChris Lattner break; 32030fdc8d8SChris Lattner } 32130fdc8d8SChris Lattner 32230fdc8d8SChris Lattner return error; 32330fdc8d8SChris Lattner } 32430fdc8d8SChris Lattner 32530fdc8d8SChris Lattner void 326f6b8b581SGreg Clayton CommandObjectBreakpointSet::CommandOptions::OptionParsingStarting () 32730fdc8d8SChris Lattner { 32887df91b8SJim Ingham m_filenames.Clear(); 32930fdc8d8SChris Lattner m_line_num = 0; 33030fdc8d8SChris Lattner m_column = 0; 331fab10e89SJim Ingham m_func_names.clear(); 3320c5cd90dSGreg Clayton m_func_name_type_mask = 0; 33330fdc8d8SChris Lattner m_func_regexp.clear(); 33430fdc8d8SChris Lattner m_load_addr = LLDB_INVALID_ADDRESS; 33587df91b8SJim Ingham m_modules.Clear(); 336c982c768SGreg Clayton m_ignore_count = 0; 3371b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 338c982c768SGreg Clayton m_thread_index = UINT32_MAX; 3391b54c88cSJim Ingham m_thread_name.clear(); 3401b54c88cSJim Ingham m_queue_name.clear(); 341fab10e89SJim Ingham m_language = eLanguageTypeUnknown; 342fab10e89SJim Ingham m_catch_bp = false; 343fab10e89SJim Ingham m_throw_bp = true; 344*a8558b62SJim Ingham m_skip_prologue = eLazyBoolCalculate; 34530fdc8d8SChris Lattner } 34630fdc8d8SChris Lattner 34730fdc8d8SChris Lattner //------------------------------------------------------------------------- 34830fdc8d8SChris Lattner // CommandObjectBreakpointSet 34930fdc8d8SChris Lattner //------------------------------------------------------------------------- 350ae1c4cf5SJim Ingham #pragma mark Set 35130fdc8d8SChris Lattner 352a7015092SGreg Clayton CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) : 353a7015092SGreg Clayton CommandObject (interpreter, 354a7015092SGreg Clayton "breakpoint set", 355a7015092SGreg Clayton "Sets a breakpoint or set of breakpoints in the executable.", 356eb0103f2SGreg Clayton "breakpoint set <cmd-options>"), 357eb0103f2SGreg Clayton m_options (interpreter) 35830fdc8d8SChris Lattner { 35930fdc8d8SChris Lattner } 36030fdc8d8SChris Lattner 36130fdc8d8SChris Lattner CommandObjectBreakpointSet::~CommandObjectBreakpointSet () 36230fdc8d8SChris Lattner { 36330fdc8d8SChris Lattner } 36430fdc8d8SChris Lattner 36530fdc8d8SChris Lattner Options * 36630fdc8d8SChris Lattner CommandObjectBreakpointSet::GetOptions () 36730fdc8d8SChris Lattner { 36830fdc8d8SChris Lattner return &m_options; 36930fdc8d8SChris Lattner } 37030fdc8d8SChris Lattner 37130fdc8d8SChris Lattner bool 37287df91b8SJim Ingham CommandObjectBreakpointSet::GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result) 373969795f1SJim Ingham { 374969795f1SJim Ingham uint32_t default_line; 375969795f1SJim Ingham // First use the Source Manager's default file. 376969795f1SJim Ingham // Then use the current stack frame's file. 377969795f1SJim Ingham if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) 378969795f1SJim Ingham { 379c14ee32dSGreg Clayton StackFrame *cur_frame = m_interpreter.GetExecutionContext().GetFramePtr(); 380969795f1SJim Ingham if (cur_frame == NULL) 381969795f1SJim Ingham { 38287df91b8SJim Ingham result.AppendError ("No selected frame to use to find the default file."); 383969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 384969795f1SJim Ingham return false; 385969795f1SJim Ingham } 386969795f1SJim Ingham else if (!cur_frame->HasDebugInformation()) 387969795f1SJim Ingham { 38887df91b8SJim Ingham result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info."); 389969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 390969795f1SJim Ingham return false; 391969795f1SJim Ingham } 392969795f1SJim Ingham else 393969795f1SJim Ingham { 394969795f1SJim Ingham const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry); 395969795f1SJim Ingham if (sc.line_entry.file) 396969795f1SJim Ingham { 397969795f1SJim Ingham file = sc.line_entry.file; 398969795f1SJim Ingham } 399969795f1SJim Ingham else 400969795f1SJim Ingham { 40187df91b8SJim Ingham result.AppendError ("Can't find the file for the selected frame to use as the default file."); 402969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 403969795f1SJim Ingham return false; 404969795f1SJim Ingham } 405969795f1SJim Ingham } 406969795f1SJim Ingham } 407969795f1SJim Ingham return true; 408969795f1SJim Ingham } 409969795f1SJim Ingham 410969795f1SJim Ingham bool 41130fdc8d8SChris Lattner CommandObjectBreakpointSet::Execute 41230fdc8d8SChris Lattner ( 41330fdc8d8SChris Lattner Args& command, 41430fdc8d8SChris Lattner CommandReturnObject &result 41530fdc8d8SChris Lattner ) 41630fdc8d8SChris Lattner { 417a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 41830fdc8d8SChris Lattner if (target == NULL) 41930fdc8d8SChris Lattner { 420effe5c95SGreg Clayton result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command)."); 42130fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 42230fdc8d8SChris Lattner return false; 42330fdc8d8SChris Lattner } 42430fdc8d8SChris Lattner 42530fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 42630fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 42730fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 42830fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 42930fdc8d8SChris Lattner // 4). -r [-s -g] (setting breakpoint by function name regular expression) 430969795f1SJim Ingham // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text) 431fab10e89SJim Ingham // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.) 43230fdc8d8SChris Lattner 43330fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 43430fdc8d8SChris Lattner 43530fdc8d8SChris Lattner if (m_options.m_line_num != 0) 43630fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 43730fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 43830fdc8d8SChris Lattner break_type = eSetTypeAddress; 439fab10e89SJim Ingham else if (!m_options.m_func_names.empty()) 44030fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 44130fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 44230fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 443969795f1SJim Ingham else if (!m_options.m_source_text_regexp.empty()) 444969795f1SJim Ingham break_type = eSetTypeSourceRegexp; 445fab10e89SJim Ingham else if (m_options.m_language != eLanguageTypeUnknown) 446fab10e89SJim Ingham break_type = eSetTypeException; 44730fdc8d8SChris Lattner 44830fdc8d8SChris Lattner Breakpoint *bp = NULL; 449274060b6SGreg Clayton FileSpec module_spec; 45030fdc8d8SChris Lattner bool use_module = false; 45187df91b8SJim Ingham int num_modules = m_options.m_modules.GetSize(); 452969795f1SJim Ingham 453*a8558b62SJim Ingham const bool internal = false; 454*a8558b62SJim Ingham 45530fdc8d8SChris Lattner if ((num_modules > 0) && (break_type != eSetTypeAddress)) 45630fdc8d8SChris Lattner use_module = true; 45730fdc8d8SChris Lattner 45830fdc8d8SChris Lattner switch (break_type) 45930fdc8d8SChris Lattner { 46030fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 46130fdc8d8SChris Lattner { 46230fdc8d8SChris Lattner FileSpec file; 46387df91b8SJim Ingham uint32_t num_files = m_options.m_filenames.GetSize(); 46487df91b8SJim Ingham if (num_files == 0) 46587df91b8SJim Ingham { 46687df91b8SJim Ingham if (!GetDefaultFile (target, file, result)) 46787df91b8SJim Ingham { 46887df91b8SJim Ingham result.AppendError("No file supplied and no default file available."); 46987df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 47087df91b8SJim Ingham return false; 47187df91b8SJim Ingham } 47287df91b8SJim Ingham } 47387df91b8SJim Ingham else if (num_files > 1) 47487df91b8SJim Ingham { 47587df91b8SJim Ingham result.AppendError("Only one file at a time is allowed for file and line breakpoints."); 47687df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 47787df91b8SJim Ingham return false; 47887df91b8SJim Ingham } 47987df91b8SJim Ingham else 48087df91b8SJim Ingham file = m_options.m_filenames.GetFileSpecAtIndex(0); 48130fdc8d8SChris Lattner 48287df91b8SJim Ingham bp = target->CreateBreakpoint (&(m_options.m_modules), 48330fdc8d8SChris Lattner file, 48430fdc8d8SChris Lattner m_options.m_line_num, 485*a8558b62SJim Ingham m_options.m_check_inlines, 486*a8558b62SJim Ingham m_options.m_skip_prologue, 487*a8558b62SJim Ingham internal).get(); 48830fdc8d8SChris Lattner } 48930fdc8d8SChris Lattner break; 4906eee5aa0SGreg Clayton 49130fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 49230fdc8d8SChris Lattner bp = target->CreateBreakpoint (m_options.m_load_addr, false).get(); 49330fdc8d8SChris Lattner break; 4940c5cd90dSGreg Clayton 49530fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 4960c5cd90dSGreg Clayton { 4970c5cd90dSGreg Clayton uint32_t name_type_mask = m_options.m_func_name_type_mask; 4980c5cd90dSGreg Clayton 4990c5cd90dSGreg Clayton if (name_type_mask == 0) 500e02b8504SGreg Clayton name_type_mask = eFunctionNameTypeAuto; 5010c5cd90dSGreg Clayton 50287df91b8SJim Ingham bp = target->CreateBreakpoint (&(m_options.m_modules), 50387df91b8SJim Ingham &(m_options.m_filenames), 504fab10e89SJim Ingham m_options.m_func_names, 505274060b6SGreg Clayton name_type_mask, 506*a8558b62SJim Ingham m_options.m_skip_prologue, 507*a8558b62SJim Ingham internal).get(); 5080c5cd90dSGreg Clayton } 50930fdc8d8SChris Lattner break; 5100c5cd90dSGreg Clayton 51130fdc8d8SChris Lattner case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name 51230fdc8d8SChris Lattner { 51330fdc8d8SChris Lattner RegularExpression regexp(m_options.m_func_regexp.c_str()); 514969795f1SJim Ingham if (!regexp.IsValid()) 51530fdc8d8SChris Lattner { 516969795f1SJim Ingham char err_str[1024]; 517969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 518969795f1SJim Ingham result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"", 519969795f1SJim Ingham err_str); 52030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 521969795f1SJim Ingham return false; 52230fdc8d8SChris Lattner } 52387df91b8SJim Ingham 524*a8558b62SJim Ingham bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules), 525*a8558b62SJim Ingham &(m_options.m_filenames), 526*a8558b62SJim Ingham regexp, 527*a8558b62SJim Ingham m_options.m_skip_prologue, 528*a8558b62SJim Ingham internal).get(); 52930fdc8d8SChris Lattner } 53030fdc8d8SChris Lattner break; 531969795f1SJim Ingham case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. 532969795f1SJim Ingham { 53387df91b8SJim Ingham int num_files = m_options.m_filenames.GetSize(); 53487df91b8SJim Ingham 53587df91b8SJim Ingham if (num_files == 0) 53687df91b8SJim Ingham { 537969795f1SJim Ingham FileSpec file; 53887df91b8SJim Ingham if (!GetDefaultFile (target, file, result)) 53987df91b8SJim Ingham { 54087df91b8SJim Ingham result.AppendError ("No files provided and could not find default file."); 54187df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 54287df91b8SJim Ingham return false; 54387df91b8SJim Ingham } 54487df91b8SJim Ingham else 54587df91b8SJim Ingham { 54687df91b8SJim Ingham m_options.m_filenames.Append (file); 54787df91b8SJim Ingham } 54887df91b8SJim Ingham } 5490c5cd90dSGreg Clayton 550969795f1SJim Ingham RegularExpression regexp(m_options.m_source_text_regexp.c_str()); 551969795f1SJim Ingham if (!regexp.IsValid()) 552969795f1SJim Ingham { 553969795f1SJim Ingham char err_str[1024]; 554969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 555969795f1SJim Ingham result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"", 556969795f1SJim Ingham err_str); 557969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 558969795f1SJim Ingham return false; 559969795f1SJim Ingham } 56087df91b8SJim Ingham bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules), &(m_options.m_filenames), regexp).get(); 561969795f1SJim Ingham } 562969795f1SJim Ingham break; 563fab10e89SJim Ingham case eSetTypeException: 564fab10e89SJim Ingham { 565fab10e89SJim Ingham bp = target->CreateExceptionBreakpoint (m_options.m_language, m_options.m_catch_bp, m_options.m_throw_bp).get(); 566fab10e89SJim Ingham } 567fab10e89SJim Ingham break; 56830fdc8d8SChris Lattner default: 56930fdc8d8SChris Lattner break; 57030fdc8d8SChris Lattner } 57130fdc8d8SChris Lattner 5721b54c88cSJim Ingham // Now set the various options that were passed in: 5731b54c88cSJim Ingham if (bp) 5741b54c88cSJim Ingham { 5751b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 5761b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 5771b54c88cSJim Ingham 578c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 5791b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 5801b54c88cSJim Ingham 5811b54c88cSJim Ingham if (!m_options.m_thread_name.empty()) 5821b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 5831b54c88cSJim Ingham 5841b54c88cSJim Ingham if (!m_options.m_queue_name.empty()) 5851b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 5861b54c88cSJim Ingham 587c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 5881b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 5891b54c88cSJim Ingham } 5901b54c88cSJim Ingham 591969795f1SJim Ingham if (bp) 59230fdc8d8SChris Lattner { 59385e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 59430fdc8d8SChris Lattner output_stream.Printf ("Breakpoint created: "); 59530fdc8d8SChris Lattner bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); 59630fdc8d8SChris Lattner output_stream.EOL(); 597fab10e89SJim Ingham // Don't print out this warning for exception breakpoints. They can get set before the target 598fab10e89SJim Ingham // is set, but we won't know how to actually set the breakpoint till we run. 599fab10e89SJim Ingham if (bp->GetNumLocations() == 0 && break_type != eSetTypeException) 600be484f41SCaroline Tice output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n"); 60130fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 60230fdc8d8SChris Lattner } 60330fdc8d8SChris Lattner else if (!bp) 60430fdc8d8SChris Lattner { 60530fdc8d8SChris Lattner result.AppendError ("Breakpoint creation failed: No breakpoint created."); 60630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 60730fdc8d8SChris Lattner } 60830fdc8d8SChris Lattner 60930fdc8d8SChris Lattner return result.Succeeded(); 61030fdc8d8SChris Lattner } 61130fdc8d8SChris Lattner 61230fdc8d8SChris Lattner //------------------------------------------------------------------------- 61330fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 61430fdc8d8SChris Lattner //------------------------------------------------------------------------- 615ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 61630fdc8d8SChris Lattner 6176611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) : 618a7015092SGreg Clayton CommandObjectMultiword (interpreter, 619a7015092SGreg Clayton "breakpoint", 62046fbc60fSJim Ingham "A set of commands for operating on breakpoints. Also see _regexp-break.", 62130fdc8d8SChris Lattner "breakpoint <command> [<command-options>]") 62230fdc8d8SChris Lattner { 62330fdc8d8SChris Lattner bool status; 62430fdc8d8SChris Lattner 625a7015092SGreg Clayton CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter)); 626a7015092SGreg Clayton CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter)); 627a7015092SGreg Clayton CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter)); 628b7234e40SJohnny Chen CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter)); 629b7234e40SJohnny Chen CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter)); 630a7015092SGreg Clayton CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter)); 63130fdc8d8SChris Lattner CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter)); 632a7015092SGreg Clayton CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter)); 63330fdc8d8SChris Lattner 634b7234e40SJohnny Chen list_command_object->SetCommandName ("breakpoint list"); 63530fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 63630fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 637b7234e40SJohnny Chen clear_command_object->SetCommandName("breakpoint clear"); 638b7234e40SJohnny Chen delete_command_object->SetCommandName("breakpoint delete"); 639ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 640b7234e40SJohnny Chen command_command_object->SetCommandName ("breakpoint command"); 641b7234e40SJohnny Chen modify_command_object->SetCommandName ("breakpoint modify"); 64230fdc8d8SChris Lattner 643a7015092SGreg Clayton status = LoadSubCommand ("list", list_command_object); 644a7015092SGreg Clayton status = LoadSubCommand ("enable", enable_command_object); 645a7015092SGreg Clayton status = LoadSubCommand ("disable", disable_command_object); 646b7234e40SJohnny Chen status = LoadSubCommand ("clear", clear_command_object); 647a7015092SGreg Clayton status = LoadSubCommand ("delete", delete_command_object); 648a7015092SGreg Clayton status = LoadSubCommand ("set", set_command_object); 649a7015092SGreg Clayton status = LoadSubCommand ("command", command_command_object); 650a7015092SGreg Clayton status = LoadSubCommand ("modify", modify_command_object); 65130fdc8d8SChris Lattner } 65230fdc8d8SChris Lattner 65330fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint () 65430fdc8d8SChris Lattner { 65530fdc8d8SChris Lattner } 65630fdc8d8SChris Lattner 65730fdc8d8SChris Lattner void 65830fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result, 65930fdc8d8SChris Lattner BreakpointIDList *valid_ids) 66030fdc8d8SChris Lattner { 66130fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 66230fdc8d8SChris Lattner // 2). the full breakpoint & location canonical representation 66330fdc8d8SChris Lattner // 3). the word "to" or a hyphen, representing a range (in which case there 66430fdc8d8SChris Lattner // had *better* be an entry both before & after of one of the first two types. 66536f3b369SJim Ingham // If args is empty, we will use the last created breakpoint (if there is one.) 66630fdc8d8SChris Lattner 66730fdc8d8SChris Lattner Args temp_args; 66830fdc8d8SChris Lattner 66936f3b369SJim Ingham if (args.GetArgumentCount() == 0) 67036f3b369SJim Ingham { 6714d122c40SGreg Clayton if (target->GetLastCreatedBreakpoint()) 67236f3b369SJim Ingham { 67336f3b369SJim Ingham valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); 67436f3b369SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 67536f3b369SJim Ingham } 67636f3b369SJim Ingham else 67736f3b369SJim Ingham { 67836f3b369SJim Ingham result.AppendError("No breakpoint specified and no last created breakpoint."); 67936f3b369SJim Ingham result.SetStatus (eReturnStatusFailed); 68036f3b369SJim Ingham } 68136f3b369SJim Ingham return; 68236f3b369SJim Ingham } 68336f3b369SJim Ingham 68430fdc8d8SChris Lattner // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to 68530fdc8d8SChris Lattner // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for 68630fdc8d8SChris Lattner // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS. 68730fdc8d8SChris Lattner 68830fdc8d8SChris Lattner BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args); 68930fdc8d8SChris Lattner 69030fdc8d8SChris Lattner // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList: 69130fdc8d8SChris Lattner 692c982c768SGreg Clayton valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result); 69330fdc8d8SChris Lattner 69430fdc8d8SChris Lattner // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs 69530fdc8d8SChris Lattner // and put into valid_ids. 69630fdc8d8SChris Lattner 69730fdc8d8SChris Lattner if (result.Succeeded()) 69830fdc8d8SChris Lattner { 69930fdc8d8SChris Lattner // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list 70030fdc8d8SChris Lattner // of breakpoint id's and verify that they correspond to valid/currently set breakpoints. 70130fdc8d8SChris Lattner 702c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 703c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 70430fdc8d8SChris Lattner { 70530fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i); 70630fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 70730fdc8d8SChris Lattner if (breakpoint != NULL) 70830fdc8d8SChris Lattner { 70930fdc8d8SChris Lattner int num_locations = breakpoint->GetNumLocations(); 71030fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() > num_locations) 71130fdc8d8SChris Lattner { 71230fdc8d8SChris Lattner StreamString id_str; 713c982c768SGreg Clayton BreakpointID::GetCanonicalReference (&id_str, 714c982c768SGreg Clayton cur_bp_id.GetBreakpointID(), 71530fdc8d8SChris Lattner cur_bp_id.GetLocationID()); 716c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 71730fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n", 71830fdc8d8SChris Lattner id_str.GetData()); 71930fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 72030fdc8d8SChris Lattner } 72130fdc8d8SChris Lattner } 72230fdc8d8SChris Lattner else 72330fdc8d8SChris Lattner { 724c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 72530fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID()); 72630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 72730fdc8d8SChris Lattner } 72830fdc8d8SChris Lattner } 72930fdc8d8SChris Lattner } 73030fdc8d8SChris Lattner } 73130fdc8d8SChris Lattner 73230fdc8d8SChris Lattner //------------------------------------------------------------------------- 73330fdc8d8SChris Lattner // CommandObjectBreakpointList::Options 73430fdc8d8SChris Lattner //------------------------------------------------------------------------- 735ae1c4cf5SJim Ingham #pragma mark List::CommandOptions 73630fdc8d8SChris Lattner 737eb0103f2SGreg Clayton CommandObjectBreakpointList::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 738eb0103f2SGreg Clayton Options (interpreter), 73979042b3eSCaroline Tice m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions 74030fdc8d8SChris Lattner { 74130fdc8d8SChris Lattner } 74230fdc8d8SChris Lattner 74330fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::~CommandOptions () 74430fdc8d8SChris Lattner { 74530fdc8d8SChris Lattner } 74630fdc8d8SChris Lattner 747e0d378b3SGreg Clayton OptionDefinition 74830fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::g_option_table[] = 74930fdc8d8SChris Lattner { 750deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone, 7518651121cSJim Ingham "Show debugger internal breakpoints" }, 7528651121cSJim Ingham 753deaab222SCaroline Tice { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone, 75430fdc8d8SChris Lattner "Give a brief description of the breakpoint (no location info)."}, 75530fdc8d8SChris Lattner 75630fdc8d8SChris Lattner // FIXME: We need to add an "internal" command, and then add this sort of thing to it. 75730fdc8d8SChris Lattner // But I need to see it for now, and don't want to wait. 758deaab222SCaroline Tice { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone, 75930fdc8d8SChris Lattner "Give a full description of the breakpoint and its locations."}, 76030fdc8d8SChris Lattner 761deaab222SCaroline Tice { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, 76230fdc8d8SChris Lattner "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, 76330fdc8d8SChris Lattner 764deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 76530fdc8d8SChris Lattner }; 76630fdc8d8SChris Lattner 767e0d378b3SGreg Clayton const OptionDefinition* 76830fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::GetDefinitions () 76930fdc8d8SChris Lattner { 77030fdc8d8SChris Lattner return g_option_table; 77130fdc8d8SChris Lattner } 77230fdc8d8SChris Lattner 77330fdc8d8SChris Lattner Error 774f6b8b581SGreg Clayton CommandObjectBreakpointList::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 77530fdc8d8SChris Lattner { 77630fdc8d8SChris Lattner Error error; 77730fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 77830fdc8d8SChris Lattner 77930fdc8d8SChris Lattner switch (short_option) 78030fdc8d8SChris Lattner { 78130fdc8d8SChris Lattner case 'b': 78230fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelBrief; 78330fdc8d8SChris Lattner break; 78430fdc8d8SChris Lattner case 'f': 78530fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelFull; 78630fdc8d8SChris Lattner break; 78730fdc8d8SChris Lattner case 'v': 78830fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelVerbose; 78930fdc8d8SChris Lattner break; 79030fdc8d8SChris Lattner case 'i': 79130fdc8d8SChris Lattner m_internal = true; 79230fdc8d8SChris Lattner break; 79330fdc8d8SChris Lattner default: 79486edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 79530fdc8d8SChris Lattner break; 79630fdc8d8SChris Lattner } 79730fdc8d8SChris Lattner 79830fdc8d8SChris Lattner return error; 79930fdc8d8SChris Lattner } 80030fdc8d8SChris Lattner 80130fdc8d8SChris Lattner void 802f6b8b581SGreg Clayton CommandObjectBreakpointList::CommandOptions::OptionParsingStarting () 80330fdc8d8SChris Lattner { 804d915e16fSJim Ingham m_level = lldb::eDescriptionLevelFull; 80530fdc8d8SChris Lattner m_internal = false; 80630fdc8d8SChris Lattner } 80730fdc8d8SChris Lattner 80830fdc8d8SChris Lattner //------------------------------------------------------------------------- 80930fdc8d8SChris Lattner // CommandObjectBreakpointList 81030fdc8d8SChris Lattner //------------------------------------------------------------------------- 811ae1c4cf5SJim Ingham #pragma mark List 81230fdc8d8SChris Lattner 813a7015092SGreg Clayton CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) : 814a7015092SGreg Clayton CommandObject (interpreter, 815a7015092SGreg Clayton "breakpoint list", 81630fdc8d8SChris Lattner "List some or all breakpoints at configurable levels of detail.", 817eb0103f2SGreg Clayton NULL), 818eb0103f2SGreg Clayton m_options (interpreter) 81930fdc8d8SChris Lattner { 820e139cf23SCaroline Tice CommandArgumentEntry arg; 821e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 822e139cf23SCaroline Tice 823e139cf23SCaroline Tice // Define the first (and only) variant of this arg. 824e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 825405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 826e139cf23SCaroline Tice 827e139cf23SCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 828e139cf23SCaroline Tice arg.push_back (bp_id_arg); 829e139cf23SCaroline Tice 830e139cf23SCaroline Tice // Push the data for the first argument into the m_arguments vector. 831e139cf23SCaroline Tice m_arguments.push_back (arg); 83230fdc8d8SChris Lattner } 83330fdc8d8SChris Lattner 83430fdc8d8SChris Lattner CommandObjectBreakpointList::~CommandObjectBreakpointList () 83530fdc8d8SChris Lattner { 83630fdc8d8SChris Lattner } 83730fdc8d8SChris Lattner 83830fdc8d8SChris Lattner Options * 83930fdc8d8SChris Lattner CommandObjectBreakpointList::GetOptions () 84030fdc8d8SChris Lattner { 84130fdc8d8SChris Lattner return &m_options; 84230fdc8d8SChris Lattner } 84330fdc8d8SChris Lattner 84430fdc8d8SChris Lattner bool 84530fdc8d8SChris Lattner CommandObjectBreakpointList::Execute 84630fdc8d8SChris Lattner ( 84730fdc8d8SChris Lattner Args& args, 84830fdc8d8SChris Lattner CommandReturnObject &result 84930fdc8d8SChris Lattner ) 85030fdc8d8SChris Lattner { 851a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 85230fdc8d8SChris Lattner if (target == NULL) 85330fdc8d8SChris Lattner { 8549068d794SCaroline Tice result.AppendError ("Invalid target. No current target or breakpoints."); 85530fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 85630fdc8d8SChris Lattner return true; 85730fdc8d8SChris Lattner } 85830fdc8d8SChris Lattner 85930fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal); 8601b54c88cSJim Ingham Mutex::Locker locker; 8611b54c88cSJim Ingham target->GetBreakpointList(m_options.m_internal).GetListMutex(locker); 8621b54c88cSJim Ingham 86330fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 86430fdc8d8SChris Lattner 86530fdc8d8SChris Lattner if (num_breakpoints == 0) 86630fdc8d8SChris Lattner { 86730fdc8d8SChris Lattner result.AppendMessage ("No breakpoints currently set."); 86830fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 86930fdc8d8SChris Lattner return true; 87030fdc8d8SChris Lattner } 87130fdc8d8SChris Lattner 87285e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 87330fdc8d8SChris Lattner 87430fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 87530fdc8d8SChris Lattner { 87630fdc8d8SChris Lattner // No breakpoint selected; show info about all currently set breakpoints. 87730fdc8d8SChris Lattner result.AppendMessage ("Current breakpoints:"); 878c982c768SGreg Clayton for (size_t i = 0; i < num_breakpoints; ++i) 87930fdc8d8SChris Lattner { 8809fed0d85SGreg Clayton Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get(); 8816611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 88230fdc8d8SChris Lattner } 88330fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 88430fdc8d8SChris Lattner } 88530fdc8d8SChris Lattner else 88630fdc8d8SChris Lattner { 88730fdc8d8SChris Lattner // Particular breakpoints selected; show info about that breakpoint. 88830fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 88930fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 89030fdc8d8SChris Lattner 89130fdc8d8SChris Lattner if (result.Succeeded()) 89230fdc8d8SChris Lattner { 893c982c768SGreg Clayton for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) 89430fdc8d8SChris Lattner { 89530fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 89630fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 8976611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 89830fdc8d8SChris Lattner } 89930fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 90030fdc8d8SChris Lattner } 90130fdc8d8SChris Lattner else 90230fdc8d8SChris Lattner { 90330fdc8d8SChris Lattner result.AppendError ("Invalid breakpoint id."); 90430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 90530fdc8d8SChris Lattner } 90630fdc8d8SChris Lattner } 90730fdc8d8SChris Lattner 90830fdc8d8SChris Lattner return result.Succeeded(); 90930fdc8d8SChris Lattner } 91030fdc8d8SChris Lattner 91130fdc8d8SChris Lattner //------------------------------------------------------------------------- 91230fdc8d8SChris Lattner // CommandObjectBreakpointEnable 91330fdc8d8SChris Lattner //------------------------------------------------------------------------- 914ae1c4cf5SJim Ingham #pragma mark Enable 91530fdc8d8SChris Lattner 916a7015092SGreg Clayton CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) : 917a7015092SGreg Clayton CommandObject (interpreter, 918a7015092SGreg Clayton "enable", 919e3d26315SCaroline Tice "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.", 920e139cf23SCaroline Tice NULL) 92130fdc8d8SChris Lattner { 922e139cf23SCaroline Tice CommandArgumentEntry arg; 923de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 924e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 925e139cf23SCaroline Tice m_arguments.push_back (arg); 92630fdc8d8SChris Lattner } 92730fdc8d8SChris Lattner 92830fdc8d8SChris Lattner 92930fdc8d8SChris Lattner CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable () 93030fdc8d8SChris Lattner { 93130fdc8d8SChris Lattner } 93230fdc8d8SChris Lattner 93330fdc8d8SChris Lattner 93430fdc8d8SChris Lattner bool 9356611103cSGreg Clayton CommandObjectBreakpointEnable::Execute 9366611103cSGreg Clayton ( 9376611103cSGreg Clayton Args& args, 9386611103cSGreg Clayton CommandReturnObject &result 9396611103cSGreg Clayton ) 94030fdc8d8SChris Lattner { 941a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 94230fdc8d8SChris Lattner if (target == NULL) 94330fdc8d8SChris Lattner { 9449068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 94530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 94630fdc8d8SChris Lattner return false; 94730fdc8d8SChris Lattner } 94830fdc8d8SChris Lattner 9491b54c88cSJim Ingham Mutex::Locker locker; 9501b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 9511b54c88cSJim Ingham 95230fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 9531b54c88cSJim Ingham 95430fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 95530fdc8d8SChris Lattner 95630fdc8d8SChris Lattner if (num_breakpoints == 0) 95730fdc8d8SChris Lattner { 95830fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be enabled."); 95930fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 96030fdc8d8SChris Lattner return false; 96130fdc8d8SChris Lattner } 96230fdc8d8SChris Lattner 96330fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 96430fdc8d8SChris Lattner { 96530fdc8d8SChris Lattner // No breakpoint selected; enable all currently set breakpoints. 96630fdc8d8SChris Lattner target->EnableAllBreakpoints (); 967fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints enabled. (%lu breakpoints)\n", num_breakpoints); 96830fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 96930fdc8d8SChris Lattner } 97030fdc8d8SChris Lattner else 97130fdc8d8SChris Lattner { 97230fdc8d8SChris Lattner // Particular breakpoint selected; enable that breakpoint. 97330fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 97430fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 97530fdc8d8SChris Lattner 97630fdc8d8SChris Lattner if (result.Succeeded()) 97730fdc8d8SChris Lattner { 97830fdc8d8SChris Lattner int enable_count = 0; 97930fdc8d8SChris Lattner int loc_count = 0; 980c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 981c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 98230fdc8d8SChris Lattner { 98330fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 98430fdc8d8SChris Lattner 98530fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 98630fdc8d8SChris Lattner { 98730fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 98830fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 98930fdc8d8SChris Lattner { 99030fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 99130fdc8d8SChris Lattner if (location) 99230fdc8d8SChris Lattner { 99330fdc8d8SChris Lattner location->SetEnabled (true); 99430fdc8d8SChris Lattner ++loc_count; 99530fdc8d8SChris Lattner } 99630fdc8d8SChris Lattner } 99730fdc8d8SChris Lattner else 99830fdc8d8SChris Lattner { 999ae1c4cf5SJim Ingham breakpoint->SetEnabled (true); 100030fdc8d8SChris Lattner ++enable_count; 100130fdc8d8SChris Lattner } 100230fdc8d8SChris Lattner } 100330fdc8d8SChris Lattner } 100430fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count); 100530fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 100630fdc8d8SChris Lattner } 100730fdc8d8SChris Lattner } 100830fdc8d8SChris Lattner 100930fdc8d8SChris Lattner return result.Succeeded(); 101030fdc8d8SChris Lattner } 101130fdc8d8SChris Lattner 101230fdc8d8SChris Lattner //------------------------------------------------------------------------- 101330fdc8d8SChris Lattner // CommandObjectBreakpointDisable 101430fdc8d8SChris Lattner //------------------------------------------------------------------------- 1015ae1c4cf5SJim Ingham #pragma mark Disable 101630fdc8d8SChris Lattner 1017a7015092SGreg Clayton CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) : 1018a7015092SGreg Clayton CommandObject (interpreter, 1019e139cf23SCaroline Tice "breakpoint disable", 1020e3d26315SCaroline Tice "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.", 1021e139cf23SCaroline Tice NULL) 102230fdc8d8SChris Lattner { 1023e139cf23SCaroline Tice CommandArgumentEntry arg; 1024de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 1025e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1026e139cf23SCaroline Tice m_arguments.push_back (arg); 102730fdc8d8SChris Lattner } 102830fdc8d8SChris Lattner 102930fdc8d8SChris Lattner CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable () 103030fdc8d8SChris Lattner { 103130fdc8d8SChris Lattner } 103230fdc8d8SChris Lattner 103330fdc8d8SChris Lattner bool 10346611103cSGreg Clayton CommandObjectBreakpointDisable::Execute 10356611103cSGreg Clayton ( 10366611103cSGreg Clayton Args& args, 10376611103cSGreg Clayton CommandReturnObject &result 10386611103cSGreg Clayton ) 103930fdc8d8SChris Lattner { 1040a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 104130fdc8d8SChris Lattner if (target == NULL) 104230fdc8d8SChris Lattner { 10439068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 104430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 104530fdc8d8SChris Lattner return false; 104630fdc8d8SChris Lattner } 104730fdc8d8SChris Lattner 10481b54c88cSJim Ingham Mutex::Locker locker; 10491b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 10501b54c88cSJim Ingham 105130fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 105230fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 105330fdc8d8SChris Lattner 105430fdc8d8SChris Lattner if (num_breakpoints == 0) 105530fdc8d8SChris Lattner { 105630fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be disabled."); 105730fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 105830fdc8d8SChris Lattner return false; 105930fdc8d8SChris Lattner } 106030fdc8d8SChris Lattner 106130fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 106230fdc8d8SChris Lattner { 106330fdc8d8SChris Lattner // No breakpoint selected; disable all currently set breakpoints. 106430fdc8d8SChris Lattner target->DisableAllBreakpoints (); 1065fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints disabled. (%lu breakpoints)\n", num_breakpoints); 106630fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 106730fdc8d8SChris Lattner } 106830fdc8d8SChris Lattner else 106930fdc8d8SChris Lattner { 107030fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 107130fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 107230fdc8d8SChris Lattner 107330fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 107430fdc8d8SChris Lattner 107530fdc8d8SChris Lattner if (result.Succeeded()) 107630fdc8d8SChris Lattner { 107730fdc8d8SChris Lattner int disable_count = 0; 107830fdc8d8SChris Lattner int loc_count = 0; 1079c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1080c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 108130fdc8d8SChris Lattner { 108230fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 108330fdc8d8SChris Lattner 108430fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 108530fdc8d8SChris Lattner { 108630fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 108730fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 108830fdc8d8SChris Lattner { 108930fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 109030fdc8d8SChris Lattner if (location) 109130fdc8d8SChris Lattner { 109230fdc8d8SChris Lattner location->SetEnabled (false); 109330fdc8d8SChris Lattner ++loc_count; 109430fdc8d8SChris Lattner } 109530fdc8d8SChris Lattner } 109630fdc8d8SChris Lattner else 109730fdc8d8SChris Lattner { 1098ae1c4cf5SJim Ingham breakpoint->SetEnabled (false); 109930fdc8d8SChris Lattner ++disable_count; 110030fdc8d8SChris Lattner } 110130fdc8d8SChris Lattner } 110230fdc8d8SChris Lattner } 110330fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count); 110430fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 110530fdc8d8SChris Lattner } 110630fdc8d8SChris Lattner } 110730fdc8d8SChris Lattner 110830fdc8d8SChris Lattner return result.Succeeded(); 110930fdc8d8SChris Lattner } 111030fdc8d8SChris Lattner 111130fdc8d8SChris Lattner //------------------------------------------------------------------------- 1112b7234e40SJohnny Chen // CommandObjectBreakpointClear::CommandOptions 1113b7234e40SJohnny Chen //------------------------------------------------------------------------- 1114b7234e40SJohnny Chen #pragma mark Clear::CommandOptions 1115b7234e40SJohnny Chen 1116eb0103f2SGreg Clayton CommandObjectBreakpointClear::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 1117eb0103f2SGreg Clayton Options (interpreter), 1118b7234e40SJohnny Chen m_filename (), 1119b7234e40SJohnny Chen m_line_num (0) 1120b7234e40SJohnny Chen { 1121b7234e40SJohnny Chen } 1122b7234e40SJohnny Chen 1123b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::~CommandOptions () 1124b7234e40SJohnny Chen { 1125b7234e40SJohnny Chen } 1126b7234e40SJohnny Chen 1127e0d378b3SGreg Clayton OptionDefinition 1128b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::g_option_table[] = 1129b7234e40SJohnny Chen { 1130b7234e40SJohnny Chen { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, 1131b7234e40SJohnny Chen "Specify the breakpoint by source location in this particular file."}, 1132b7234e40SJohnny Chen 1133b7234e40SJohnny Chen { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, 1134b7234e40SJohnny Chen "Specify the breakpoint by source location at this particular line."}, 1135b7234e40SJohnny Chen 1136b7234e40SJohnny Chen { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 1137b7234e40SJohnny Chen }; 1138b7234e40SJohnny Chen 1139e0d378b3SGreg Clayton const OptionDefinition* 1140b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::GetDefinitions () 1141b7234e40SJohnny Chen { 1142b7234e40SJohnny Chen return g_option_table; 1143b7234e40SJohnny Chen } 1144b7234e40SJohnny Chen 1145b7234e40SJohnny Chen Error 1146f6b8b581SGreg Clayton CommandObjectBreakpointClear::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 1147b7234e40SJohnny Chen { 1148b7234e40SJohnny Chen Error error; 1149b7234e40SJohnny Chen char short_option = (char) m_getopt_table[option_idx].val; 1150b7234e40SJohnny Chen 1151b7234e40SJohnny Chen switch (short_option) 1152b7234e40SJohnny Chen { 1153b7234e40SJohnny Chen case 'f': 1154357132ebSGreg Clayton m_filename.assign (option_arg); 1155b7234e40SJohnny Chen break; 1156b7234e40SJohnny Chen 1157b7234e40SJohnny Chen case 'l': 1158b7234e40SJohnny Chen m_line_num = Args::StringToUInt32 (option_arg, 0); 1159b7234e40SJohnny Chen break; 1160b7234e40SJohnny Chen 1161b7234e40SJohnny Chen default: 116286edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 1163b7234e40SJohnny Chen break; 1164b7234e40SJohnny Chen } 1165b7234e40SJohnny Chen 1166b7234e40SJohnny Chen return error; 1167b7234e40SJohnny Chen } 1168b7234e40SJohnny Chen 1169b7234e40SJohnny Chen void 1170f6b8b581SGreg Clayton CommandObjectBreakpointClear::CommandOptions::OptionParsingStarting () 1171b7234e40SJohnny Chen { 1172b7234e40SJohnny Chen m_filename.clear(); 1173b7234e40SJohnny Chen m_line_num = 0; 1174b7234e40SJohnny Chen } 1175b7234e40SJohnny Chen 1176b7234e40SJohnny Chen //------------------------------------------------------------------------- 1177b7234e40SJohnny Chen // CommandObjectBreakpointClear 1178b7234e40SJohnny Chen //------------------------------------------------------------------------- 1179b7234e40SJohnny Chen #pragma mark Clear 1180b7234e40SJohnny Chen 1181b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandObjectBreakpointClear (CommandInterpreter &interpreter) : 1182b7234e40SJohnny Chen CommandObject (interpreter, 1183b7234e40SJohnny Chen "breakpoint clear", 1184b7234e40SJohnny Chen "Clears a breakpoint or set of breakpoints in the executable.", 1185eb0103f2SGreg Clayton "breakpoint clear <cmd-options>"), 1186eb0103f2SGreg Clayton m_options (interpreter) 1187b7234e40SJohnny Chen { 1188b7234e40SJohnny Chen } 1189b7234e40SJohnny Chen 1190b7234e40SJohnny Chen CommandObjectBreakpointClear::~CommandObjectBreakpointClear () 1191b7234e40SJohnny Chen { 1192b7234e40SJohnny Chen } 1193b7234e40SJohnny Chen 1194b7234e40SJohnny Chen Options * 1195b7234e40SJohnny Chen CommandObjectBreakpointClear::GetOptions () 1196b7234e40SJohnny Chen { 1197b7234e40SJohnny Chen return &m_options; 1198b7234e40SJohnny Chen } 1199b7234e40SJohnny Chen 1200b7234e40SJohnny Chen bool 1201b7234e40SJohnny Chen CommandObjectBreakpointClear::Execute 1202b7234e40SJohnny Chen ( 1203b7234e40SJohnny Chen Args& command, 1204b7234e40SJohnny Chen CommandReturnObject &result 1205b7234e40SJohnny Chen ) 1206b7234e40SJohnny Chen { 1207b7234e40SJohnny Chen Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 1208b7234e40SJohnny Chen if (target == NULL) 1209b7234e40SJohnny Chen { 1210b7234e40SJohnny Chen result.AppendError ("Invalid target. No existing target or breakpoints."); 1211b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1212b7234e40SJohnny Chen return false; 1213b7234e40SJohnny Chen } 1214b7234e40SJohnny Chen 1215b7234e40SJohnny Chen // The following are the various types of breakpoints that could be cleared: 1216b7234e40SJohnny Chen // 1). -f -l (clearing breakpoint by source location) 1217b7234e40SJohnny Chen 1218b7234e40SJohnny Chen BreakpointClearType break_type = eClearTypeInvalid; 1219b7234e40SJohnny Chen 1220b7234e40SJohnny Chen if (m_options.m_line_num != 0) 1221b7234e40SJohnny Chen break_type = eClearTypeFileAndLine; 1222b7234e40SJohnny Chen 1223b7234e40SJohnny Chen Mutex::Locker locker; 1224b7234e40SJohnny Chen target->GetBreakpointList().GetListMutex(locker); 1225b7234e40SJohnny Chen 1226b7234e40SJohnny Chen BreakpointList &breakpoints = target->GetBreakpointList(); 1227b7234e40SJohnny Chen size_t num_breakpoints = breakpoints.GetSize(); 1228b7234e40SJohnny Chen 1229b7234e40SJohnny Chen // Early return if there's no breakpoint at all. 1230b7234e40SJohnny Chen if (num_breakpoints == 0) 1231b7234e40SJohnny Chen { 1232b7234e40SJohnny Chen result.AppendError ("Breakpoint clear: No breakpoint cleared."); 1233b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1234b7234e40SJohnny Chen return result.Succeeded(); 1235b7234e40SJohnny Chen } 1236b7234e40SJohnny Chen 1237b7234e40SJohnny Chen // Find matching breakpoints and delete them. 1238b7234e40SJohnny Chen 1239b7234e40SJohnny Chen // First create a copy of all the IDs. 1240b7234e40SJohnny Chen std::vector<break_id_t> BreakIDs; 1241b7234e40SJohnny Chen for (size_t i = 0; i < num_breakpoints; ++i) 1242b7234e40SJohnny Chen BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID()); 1243b7234e40SJohnny Chen 1244b7234e40SJohnny Chen int num_cleared = 0; 1245b7234e40SJohnny Chen StreamString ss; 1246b7234e40SJohnny Chen switch (break_type) 1247b7234e40SJohnny Chen { 1248b7234e40SJohnny Chen case eClearTypeFileAndLine: // Breakpoint by source position 1249b7234e40SJohnny Chen { 1250b7234e40SJohnny Chen const ConstString filename(m_options.m_filename.c_str()); 1251b7234e40SJohnny Chen BreakpointLocationCollection loc_coll; 1252b7234e40SJohnny Chen 1253b7234e40SJohnny Chen for (size_t i = 0; i < num_breakpoints; ++i) 1254b7234e40SJohnny Chen { 1255b7234e40SJohnny Chen Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); 1256b7234e40SJohnny Chen 1257b7234e40SJohnny Chen if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) 1258b7234e40SJohnny Chen { 1259b7234e40SJohnny Chen // If the collection size is 0, it's a full match and we can just remove the breakpoint. 1260b7234e40SJohnny Chen if (loc_coll.GetSize() == 0) 1261b7234e40SJohnny Chen { 1262b7234e40SJohnny Chen bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); 1263b7234e40SJohnny Chen ss.EOL(); 1264b7234e40SJohnny Chen target->RemoveBreakpointByID (bp->GetID()); 1265b7234e40SJohnny Chen ++num_cleared; 1266b7234e40SJohnny Chen } 1267b7234e40SJohnny Chen } 1268b7234e40SJohnny Chen } 1269b7234e40SJohnny Chen } 1270b7234e40SJohnny Chen break; 1271b7234e40SJohnny Chen 1272b7234e40SJohnny Chen default: 1273b7234e40SJohnny Chen break; 1274b7234e40SJohnny Chen } 1275b7234e40SJohnny Chen 1276b7234e40SJohnny Chen if (num_cleared > 0) 1277b7234e40SJohnny Chen { 127885e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 1279b7234e40SJohnny Chen output_stream.Printf ("%d breakpoints cleared:\n", num_cleared); 1280b7234e40SJohnny Chen output_stream << ss.GetData(); 1281b7234e40SJohnny Chen output_stream.EOL(); 1282b7234e40SJohnny Chen result.SetStatus (eReturnStatusSuccessFinishNoResult); 1283b7234e40SJohnny Chen } 1284b7234e40SJohnny Chen else 1285b7234e40SJohnny Chen { 1286b7234e40SJohnny Chen result.AppendError ("Breakpoint clear: No breakpoint cleared."); 1287b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1288b7234e40SJohnny Chen } 1289b7234e40SJohnny Chen 1290b7234e40SJohnny Chen return result.Succeeded(); 1291b7234e40SJohnny Chen } 1292b7234e40SJohnny Chen 1293b7234e40SJohnny Chen //------------------------------------------------------------------------- 129430fdc8d8SChris Lattner // CommandObjectBreakpointDelete 129530fdc8d8SChris Lattner //------------------------------------------------------------------------- 1296ae1c4cf5SJim Ingham #pragma mark Delete 129730fdc8d8SChris Lattner 1298a7015092SGreg Clayton CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) : 1299a7015092SGreg Clayton CommandObject (interpreter, 1300a7015092SGreg Clayton "breakpoint delete", 1301e3d26315SCaroline Tice "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.", 1302e139cf23SCaroline Tice NULL) 130330fdc8d8SChris Lattner { 1304e139cf23SCaroline Tice CommandArgumentEntry arg; 1305de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 1306e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1307e139cf23SCaroline Tice m_arguments.push_back (arg); 130830fdc8d8SChris Lattner } 130930fdc8d8SChris Lattner 131030fdc8d8SChris Lattner 131130fdc8d8SChris Lattner CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete () 131230fdc8d8SChris Lattner { 131330fdc8d8SChris Lattner } 131430fdc8d8SChris Lattner 131530fdc8d8SChris Lattner bool 13166611103cSGreg Clayton CommandObjectBreakpointDelete::Execute 13176611103cSGreg Clayton ( 13186611103cSGreg Clayton Args& args, 13196611103cSGreg Clayton CommandReturnObject &result 13206611103cSGreg Clayton ) 132130fdc8d8SChris Lattner { 1322a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 132330fdc8d8SChris Lattner if (target == NULL) 132430fdc8d8SChris Lattner { 13259068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 132630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 132730fdc8d8SChris Lattner return false; 132830fdc8d8SChris Lattner } 132930fdc8d8SChris Lattner 13301b54c88cSJim Ingham Mutex::Locker locker; 13311b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 13321b54c88cSJim Ingham 133330fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 13341b54c88cSJim Ingham 133530fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 133630fdc8d8SChris Lattner 133730fdc8d8SChris Lattner if (num_breakpoints == 0) 133830fdc8d8SChris Lattner { 133930fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be deleted."); 134030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 134130fdc8d8SChris Lattner return false; 134230fdc8d8SChris Lattner } 134330fdc8d8SChris Lattner 134430fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 134530fdc8d8SChris Lattner { 134636f3b369SJim Ingham if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true)) 134730fdc8d8SChris Lattner { 134836f3b369SJim Ingham result.AppendMessage("Operation cancelled..."); 134930fdc8d8SChris Lattner } 135036f3b369SJim Ingham else 135136f3b369SJim Ingham { 135230fdc8d8SChris Lattner target->RemoveAllBreakpoints (); 1353fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints removed. (%lu breakpoints)\n", num_breakpoints); 135436f3b369SJim Ingham } 135530fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 135630fdc8d8SChris Lattner } 135730fdc8d8SChris Lattner else 135830fdc8d8SChris Lattner { 135930fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 136030fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 136130fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 136230fdc8d8SChris Lattner 136330fdc8d8SChris Lattner if (result.Succeeded()) 136430fdc8d8SChris Lattner { 136530fdc8d8SChris Lattner int delete_count = 0; 136630fdc8d8SChris Lattner int disable_count = 0; 1367c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1368c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 136930fdc8d8SChris Lattner { 137030fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 137130fdc8d8SChris Lattner 137230fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 137330fdc8d8SChris Lattner { 137430fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 137530fdc8d8SChris Lattner { 137630fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 137730fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 137830fdc8d8SChris Lattner // It makes no sense to try to delete individual locations, so we disable them instead. 137930fdc8d8SChris Lattner if (location) 138030fdc8d8SChris Lattner { 138130fdc8d8SChris Lattner location->SetEnabled (false); 138230fdc8d8SChris Lattner ++disable_count; 138330fdc8d8SChris Lattner } 138430fdc8d8SChris Lattner } 138530fdc8d8SChris Lattner else 138630fdc8d8SChris Lattner { 138730fdc8d8SChris Lattner target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID()); 138830fdc8d8SChris Lattner ++delete_count; 138930fdc8d8SChris Lattner } 139030fdc8d8SChris Lattner } 139130fdc8d8SChris Lattner } 139230fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n", 139330fdc8d8SChris Lattner delete_count, disable_count); 139430fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 139530fdc8d8SChris Lattner } 139630fdc8d8SChris Lattner } 139730fdc8d8SChris Lattner return result.Succeeded(); 139830fdc8d8SChris Lattner } 13991b54c88cSJim Ingham 14001b54c88cSJim Ingham //------------------------------------------------------------------------- 1401ae1c4cf5SJim Ingham // CommandObjectBreakpointModify::CommandOptions 14021b54c88cSJim Ingham //------------------------------------------------------------------------- 1403ae1c4cf5SJim Ingham #pragma mark Modify::CommandOptions 14041b54c88cSJim Ingham 1405eb0103f2SGreg Clayton CommandObjectBreakpointModify::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 1406eb0103f2SGreg Clayton Options (interpreter), 1407c982c768SGreg Clayton m_ignore_count (0), 14081b54c88cSJim Ingham m_thread_id(LLDB_INVALID_THREAD_ID), 1409e0a97848SJim Ingham m_thread_id_passed(false), 1410c982c768SGreg Clayton m_thread_index (UINT32_MAX), 1411e0a97848SJim Ingham m_thread_index_passed(false), 14121b54c88cSJim Ingham m_thread_name(), 14131b54c88cSJim Ingham m_queue_name(), 141436f3b369SJim Ingham m_condition (), 1415c982c768SGreg Clayton m_enable_passed (false), 1416c982c768SGreg Clayton m_enable_value (false), 1417c982c768SGreg Clayton m_name_passed (false), 141836f3b369SJim Ingham m_queue_passed (false), 141936f3b369SJim Ingham m_condition_passed (false) 14201b54c88cSJim Ingham { 14211b54c88cSJim Ingham } 14221b54c88cSJim Ingham 1423ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::~CommandOptions () 14241b54c88cSJim Ingham { 14251b54c88cSJim Ingham } 14261b54c88cSJim Ingham 1427e0d378b3SGreg Clayton OptionDefinition 1428ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] = 14291b54c88cSJim Ingham { 1430a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." }, 1431a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose indeX matches this argument."}, 1432a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."}, 1433a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."}, 1434a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."}, 1435a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."}, 1436a0cd2bcaSBill Wendling { LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, 0, eArgTypeNone, "Enable the breakpoint."}, 1437a0cd2bcaSBill Wendling { LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, 0, eArgTypeNone, "Disable the breakpoint."}, 1438deaab222SCaroline Tice { 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } 14391b54c88cSJim Ingham }; 14401b54c88cSJim Ingham 1441e0d378b3SGreg Clayton const OptionDefinition* 1442ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::GetDefinitions () 14431b54c88cSJim Ingham { 14441b54c88cSJim Ingham return g_option_table; 14451b54c88cSJim Ingham } 14461b54c88cSJim Ingham 14471b54c88cSJim Ingham Error 1448f6b8b581SGreg Clayton CommandObjectBreakpointModify::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 14491b54c88cSJim Ingham { 14501b54c88cSJim Ingham Error error; 14511b54c88cSJim Ingham char short_option = (char) m_getopt_table[option_idx].val; 14521b54c88cSJim Ingham 14531b54c88cSJim Ingham switch (short_option) 14541b54c88cSJim Ingham { 145536f3b369SJim Ingham case 'c': 145636f3b369SJim Ingham if (option_arg != NULL) 1457357132ebSGreg Clayton m_condition.assign (option_arg); 145836f3b369SJim Ingham else 145936f3b369SJim Ingham m_condition.clear(); 146036f3b369SJim Ingham m_condition_passed = true; 146136f3b369SJim Ingham break; 1462ae1c4cf5SJim Ingham case 'd': 1463ae1c4cf5SJim Ingham m_enable_passed = true; 1464ae1c4cf5SJim Ingham m_enable_value = false; 1465ae1c4cf5SJim Ingham break; 1466ae1c4cf5SJim Ingham case 'e': 1467ae1c4cf5SJim Ingham m_enable_passed = true; 1468ae1c4cf5SJim Ingham m_enable_value = true; 1469ae1c4cf5SJim Ingham break; 1470ed8a705cSGreg Clayton case 'i': 14711b54c88cSJim Ingham { 14720292f4a5SJim Ingham m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 1473c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 147486edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); 14751b54c88cSJim Ingham } 1476ae1c4cf5SJim Ingham break; 14771b54c88cSJim Ingham case 't' : 14781b54c88cSJim Ingham { 14790292f4a5SJim Ingham if (option_arg[0] == '\0') 1480e0a97848SJim Ingham { 1481e0a97848SJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 1482e0a97848SJim Ingham m_thread_id_passed = true; 1483e0a97848SJim Ingham } 1484e0a97848SJim Ingham else 1485e0a97848SJim Ingham { 14860292f4a5SJim Ingham m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 14871b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 148886edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); 1489e0a97848SJim Ingham else 1490e0a97848SJim Ingham m_thread_id_passed = true; 1491e0a97848SJim Ingham } 14921b54c88cSJim Ingham } 14931b54c88cSJim Ingham break; 14941b54c88cSJim Ingham case 'T': 1495b2a38a72SJim Ingham if (option_arg != NULL) 1496357132ebSGreg Clayton m_thread_name.assign (option_arg); 1497b2a38a72SJim Ingham else 1498b2a38a72SJim Ingham m_thread_name.clear(); 1499b2a38a72SJim Ingham m_name_passed = true; 15001b54c88cSJim Ingham break; 15011b54c88cSJim Ingham case 'q': 1502b2a38a72SJim Ingham if (option_arg != NULL) 1503357132ebSGreg Clayton m_queue_name.assign (option_arg); 1504b2a38a72SJim Ingham else 1505b2a38a72SJim Ingham m_queue_name.clear(); 1506b2a38a72SJim Ingham m_queue_passed = true; 15071b54c88cSJim Ingham break; 15081b54c88cSJim Ingham case 'x': 15091b54c88cSJim Ingham { 15100292f4a5SJim Ingham if (option_arg[0] == '\n') 1511e0a97848SJim Ingham { 1512e0a97848SJim Ingham m_thread_index = UINT32_MAX; 1513e0a97848SJim Ingham m_thread_index_passed = true; 1514e0a97848SJim Ingham } 1515e0a97848SJim Ingham else 1516e0a97848SJim Ingham { 15170292f4a5SJim Ingham m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0); 1518c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 151986edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); 1520e0a97848SJim Ingham else 1521e0a97848SJim Ingham m_thread_index_passed = true; 1522e0a97848SJim Ingham } 15231b54c88cSJim Ingham } 15241b54c88cSJim Ingham break; 15251b54c88cSJim Ingham default: 152686edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 15271b54c88cSJim Ingham break; 15281b54c88cSJim Ingham } 15291b54c88cSJim Ingham 15301b54c88cSJim Ingham return error; 15311b54c88cSJim Ingham } 15321b54c88cSJim Ingham 15331b54c88cSJim Ingham void 1534f6b8b581SGreg Clayton CommandObjectBreakpointModify::CommandOptions::OptionParsingStarting () 15351b54c88cSJim Ingham { 1536c982c768SGreg Clayton m_ignore_count = 0; 15371b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 1538e0a97848SJim Ingham m_thread_id_passed = false; 1539c982c768SGreg Clayton m_thread_index = UINT32_MAX; 1540e0a97848SJim Ingham m_thread_index_passed = false; 15411b54c88cSJim Ingham m_thread_name.clear(); 15421b54c88cSJim Ingham m_queue_name.clear(); 154336f3b369SJim Ingham m_condition.clear(); 1544ae1c4cf5SJim Ingham m_enable_passed = false; 1545b2a38a72SJim Ingham m_queue_passed = false; 1546b2a38a72SJim Ingham m_name_passed = false; 154736f3b369SJim Ingham m_condition_passed = false; 15481b54c88cSJim Ingham } 15491b54c88cSJim Ingham 15501b54c88cSJim Ingham //------------------------------------------------------------------------- 1551ae1c4cf5SJim Ingham // CommandObjectBreakpointModify 15521b54c88cSJim Ingham //------------------------------------------------------------------------- 1553ae1c4cf5SJim Ingham #pragma mark Modify 15541b54c88cSJim Ingham 1555a7015092SGreg Clayton CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) : 1556a7015092SGreg Clayton CommandObject (interpreter, 1557a7015092SGreg Clayton "breakpoint modify", 1558a571c010SJim Ingham "Modify the options on a breakpoint or set of breakpoints in the executable. " 1559e0a97848SJim Ingham "If no breakpoint is specified, acts on the last created breakpoint. " 1560e0a97848SJim Ingham "With the exception of -e, -d and -i, passing an empty argument clears the modification.", 1561eb0103f2SGreg Clayton NULL), 1562eb0103f2SGreg Clayton m_options (interpreter) 15631b54c88cSJim Ingham { 1564e139cf23SCaroline Tice CommandArgumentEntry arg; 1565de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 1566e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1567e139cf23SCaroline Tice m_arguments.push_back (arg); 15681b54c88cSJim Ingham } 15691b54c88cSJim Ingham 1570ae1c4cf5SJim Ingham CommandObjectBreakpointModify::~CommandObjectBreakpointModify () 15711b54c88cSJim Ingham { 15721b54c88cSJim Ingham } 15731b54c88cSJim Ingham 15741b54c88cSJim Ingham Options * 1575ae1c4cf5SJim Ingham CommandObjectBreakpointModify::GetOptions () 15761b54c88cSJim Ingham { 15771b54c88cSJim Ingham return &m_options; 15781b54c88cSJim Ingham } 15791b54c88cSJim Ingham 15801b54c88cSJim Ingham bool 1581ae1c4cf5SJim Ingham CommandObjectBreakpointModify::Execute 15821b54c88cSJim Ingham ( 15831b54c88cSJim Ingham Args& command, 15841b54c88cSJim Ingham CommandReturnObject &result 15851b54c88cSJim Ingham ) 15861b54c88cSJim Ingham { 1587a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 15881b54c88cSJim Ingham if (target == NULL) 15891b54c88cSJim Ingham { 15909068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 15911b54c88cSJim Ingham result.SetStatus (eReturnStatusFailed); 15921b54c88cSJim Ingham return false; 15931b54c88cSJim Ingham } 15941b54c88cSJim Ingham 15951b54c88cSJim Ingham Mutex::Locker locker; 15961b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 15971b54c88cSJim Ingham 15981b54c88cSJim Ingham BreakpointIDList valid_bp_ids; 15991b54c88cSJim Ingham 16001b54c88cSJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 16011b54c88cSJim Ingham 16021b54c88cSJim Ingham if (result.Succeeded()) 16031b54c88cSJim Ingham { 1604c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1605c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 16061b54c88cSJim Ingham { 16071b54c88cSJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 16081b54c88cSJim Ingham 16091b54c88cSJim Ingham if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 16101b54c88cSJim Ingham { 16111b54c88cSJim Ingham Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 16121b54c88cSJim Ingham if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 16131b54c88cSJim Ingham { 16141b54c88cSJim Ingham BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get(); 16151b54c88cSJim Ingham if (location) 16161b54c88cSJim Ingham { 1617e0a97848SJim Ingham if (m_options.m_thread_id_passed) 16181b54c88cSJim Ingham location->SetThreadID (m_options.m_thread_id); 16191b54c88cSJim Ingham 1620e0a97848SJim Ingham if (m_options.m_thread_index_passed) 1621e6bc6cb9SJim Ingham location->SetThreadIndex(m_options.m_thread_index); 16221b54c88cSJim Ingham 1623b2a38a72SJim Ingham if (m_options.m_name_passed) 1624e6bc6cb9SJim Ingham location->SetThreadName(m_options.m_thread_name.c_str()); 16251b54c88cSJim Ingham 1626b2a38a72SJim Ingham if (m_options.m_queue_passed) 1627e6bc6cb9SJim Ingham location->SetQueueName(m_options.m_queue_name.c_str()); 16281b54c88cSJim Ingham 1629c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 1630e6bc6cb9SJim Ingham location->SetIgnoreCount(m_options.m_ignore_count); 1631ae1c4cf5SJim Ingham 1632ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1633ae1c4cf5SJim Ingham location->SetEnabled (m_options.m_enable_value); 163436f3b369SJim Ingham 163536f3b369SJim Ingham if (m_options.m_condition_passed) 163636f3b369SJim Ingham location->SetCondition (m_options.m_condition.c_str()); 16371b54c88cSJim Ingham } 16381b54c88cSJim Ingham } 16391b54c88cSJim Ingham else 16401b54c88cSJim Ingham { 1641e0a97848SJim Ingham if (m_options.m_thread_id_passed) 16421b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 16431b54c88cSJim Ingham 1644e0a97848SJim Ingham if (m_options.m_thread_index_passed) 1645e6bc6cb9SJim Ingham bp->SetThreadIndex(m_options.m_thread_index); 16461b54c88cSJim Ingham 1647b2a38a72SJim Ingham if (m_options.m_name_passed) 1648e6bc6cb9SJim Ingham bp->SetThreadName(m_options.m_thread_name.c_str()); 16491b54c88cSJim Ingham 1650b2a38a72SJim Ingham if (m_options.m_queue_passed) 1651e6bc6cb9SJim Ingham bp->SetQueueName(m_options.m_queue_name.c_str()); 16521b54c88cSJim Ingham 1653c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 1654e6bc6cb9SJim Ingham bp->SetIgnoreCount(m_options.m_ignore_count); 1655ae1c4cf5SJim Ingham 1656ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1657ae1c4cf5SJim Ingham bp->SetEnabled (m_options.m_enable_value); 1658ae1c4cf5SJim Ingham 165936f3b369SJim Ingham if (m_options.m_condition_passed) 166036f3b369SJim Ingham bp->SetCondition (m_options.m_condition.c_str()); 16611b54c88cSJim Ingham } 16621b54c88cSJim Ingham } 16631b54c88cSJim Ingham } 16641b54c88cSJim Ingham } 16651b54c88cSJim Ingham 16661b54c88cSJim Ingham return result.Succeeded(); 16671b54c88cSJim Ingham } 16681b54c88cSJim Ingham 16691b54c88cSJim Ingham 1670