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), 52*7d49c9c8SJohnny Chen m_condition (), 5387df91b8SJim Ingham m_filenames (), 5430fdc8d8SChris Lattner m_line_num (0), 5530fdc8d8SChris Lattner m_column (0), 562856d462SGreg Clayton m_check_inlines (true), 57fab10e89SJim Ingham m_func_names (), 58fab10e89SJim Ingham m_func_name_type_mask (eFunctionNameTypeNone), 5930fdc8d8SChris Lattner m_func_regexp (), 60969795f1SJim Ingham m_source_text_regexp(), 6130fdc8d8SChris Lattner m_modules (), 621b54c88cSJim Ingham m_load_addr(), 63c982c768SGreg Clayton m_ignore_count (0), 641b54c88cSJim Ingham m_thread_id(LLDB_INVALID_THREAD_ID), 65c982c768SGreg Clayton m_thread_index (UINT32_MAX), 661b54c88cSJim Ingham m_thread_name(), 67fab10e89SJim Ingham m_queue_name(), 68fab10e89SJim Ingham m_catch_bp (false), 69fab10e89SJim Ingham m_throw_bp (false), 70a8558b62SJim Ingham m_language (eLanguageTypeUnknown), 71a8558b62SJim Ingham m_skip_prologue (eLazyBoolCalculate) 7230fdc8d8SChris Lattner { 7330fdc8d8SChris Lattner } 7430fdc8d8SChris Lattner 7530fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::~CommandOptions () 7630fdc8d8SChris Lattner { 7730fdc8d8SChris Lattner } 7830fdc8d8SChris Lattner 796943e7c5SJohnny Chen // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to 806943e7c5SJohnny Chen // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately. 814ab2e6beSJohnny Chen #define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 ) 824ab2e6beSJohnny Chen #define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 ) 83a8558b62SJim Ingham #define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) ) 8487df91b8SJim Ingham 85e0d378b3SGreg Clayton OptionDefinition 8630fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::g_option_table[] = 8730fdc8d8SChris Lattner { 88fab10e89SJim Ingham { LLDB_OPT_NOT_10, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName, 8964cc29cbSJim Ingham "Set the breakpoint only in this shared library. " 9064cc29cbSJim Ingham "Can repeat this option multiple times to specify multiple shared libraries."}, 918651121cSJim Ingham 92deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount, 93deaab222SCaroline Tice "Set the number of times this breakpoint is skipped before stopping." }, 941b54c88cSJim Ingham 95*7d49c9c8SJohnny Chen { LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, 0, eArgTypeExpression, 96*7d49c9c8SJohnny Chen "The breakpoint stops only if this condition expression evaluates to true."}, 97*7d49c9c8SJohnny Chen 98a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex, 99ed8a705cSGreg Clayton "The breakpoint stops only for the thread whose index matches this argument."}, 1001b54c88cSJim Ingham 101a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID, 1021b54c88cSJim Ingham "The breakpoint stops only for the thread whose TID matches this argument."}, 1031b54c88cSJim Ingham 104a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName, 1051b54c88cSJim Ingham "The breakpoint stops only for the thread whose thread name matches this argument."}, 1061b54c88cSJim Ingham 107a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName, 1081b54c88cSJim Ingham "The breakpoint stops only for threads in the queue whose name is given by this argument."}, 1091b54c88cSJim Ingham 11087df91b8SJim Ingham { LLDB_OPT_FILE, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, 11187df91b8SJim Ingham "Specifies the source file in which to set this breakpoint."}, 11230fdc8d8SChris Lattner 113deaab222SCaroline Tice { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, 11487df91b8SJim Ingham "Specifies the line number on which to set this breakpoint."}, 11530fdc8d8SChris Lattner 11630fdc8d8SChris Lattner // Comment out this option for the moment, as we don't actually use it, but will in the future. 11730fdc8d8SChris Lattner // This way users won't see it, but the infrastructure is left in place. 118*7d49c9c8SJohnny Chen // { 0, false, "column", 'C', required_argument, NULL, "<column>", 11930fdc8d8SChris Lattner // "Set the breakpoint by source location at this particular column."}, 12030fdc8d8SChris Lattner 121deaab222SCaroline Tice { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, 12230fdc8d8SChris Lattner "Set the breakpoint by address, at the specified address."}, 12330fdc8d8SChris Lattner 124deaab222SCaroline Tice { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, 12564cc29cbSJim Ingham "Set the breakpoint by function name. Can be repeated multiple times to make one breakpoint for multiple snames" }, 12630fdc8d8SChris Lattner 127deaab222SCaroline Tice { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName, 12864cc29cbSJim Ingham "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and " 12964cc29cbSJim Ingham "for Objective C this means a full function prototype with class and selector. " 13064cc29cbSJim Ingham "Can be repeated multiple times to make one breakpoint for multiple names." }, 1310c5cd90dSGreg Clayton 132deaab222SCaroline Tice { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector, 13364cc29cbSJim Ingham "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." }, 1340c5cd90dSGreg Clayton 135deaab222SCaroline Tice { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod, 13664cc29cbSJim Ingham "Set the breakpoint by C++ method names. Can be repeated multiple times to make one breakpoint for multiple methods." }, 1370c5cd90dSGreg Clayton 138deaab222SCaroline Tice { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression, 13930fdc8d8SChris Lattner "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." }, 14030fdc8d8SChris Lattner 141e02b8504SGreg Clayton { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, 14264cc29cbSJim Ingham "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). " 14364cc29cbSJim Ingham "Can be repeated multiple times to make one breakpoint for multiple symbols." }, 144e02b8504SGreg Clayton 145969795f1SJim Ingham { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', required_argument, NULL, 0, eArgTypeRegularExpression, 146969795f1SJim Ingham "Set the breakpoint specifying a regular expression to match a pattern in the source text in a given source file." }, 147969795f1SJim Ingham 148fab10e89SJim Ingham { LLDB_OPT_SET_10, true, "language-exception", 'E', required_argument, NULL, 0, eArgTypeLanguage, 149fab10e89SJim Ingham "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" }, 150fab10e89SJim Ingham 151fab10e89SJim Ingham { LLDB_OPT_SET_10, false, "on-throw", 'w', required_argument, NULL, 0, eArgTypeBoolean, 152fab10e89SJim Ingham "Set the breakpoint on exception throW." }, 153fab10e89SJim Ingham 154fab10e89SJim Ingham { LLDB_OPT_SET_10, false, "on-catch", 'h', required_argument, NULL, 0, eArgTypeBoolean, 155fab10e89SJim Ingham "Set the breakpoint on exception catcH." }, 156969795f1SJim Ingham 157a8558b62SJim Ingham { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', required_argument, NULL, 0, eArgTypeBoolean, 158a8558b62SJim Ingham "sKip the prologue if the breakpoint is at the beginning of a function. If not set the target.skip-prologue setting is used." }, 159a8558b62SJim Ingham 160deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 16130fdc8d8SChris Lattner }; 16230fdc8d8SChris Lattner 163e0d378b3SGreg Clayton const OptionDefinition* 16430fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::GetDefinitions () 16530fdc8d8SChris Lattner { 16630fdc8d8SChris Lattner return g_option_table; 16730fdc8d8SChris Lattner } 16830fdc8d8SChris Lattner 16930fdc8d8SChris Lattner Error 170f6b8b581SGreg Clayton CommandObjectBreakpointSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 17130fdc8d8SChris Lattner { 17230fdc8d8SChris Lattner Error error; 17330fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 17430fdc8d8SChris Lattner 17530fdc8d8SChris Lattner switch (short_option) 17630fdc8d8SChris Lattner { 17730fdc8d8SChris Lattner case 'a': 1780292f4a5SJim Ingham m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0); 17930fdc8d8SChris Lattner if (m_load_addr == LLDB_INVALID_ADDRESS) 1800292f4a5SJim Ingham m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16); 18130fdc8d8SChris Lattner 18230fdc8d8SChris Lattner if (m_load_addr == LLDB_INVALID_ADDRESS) 18386edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg); 18430fdc8d8SChris Lattner break; 18530fdc8d8SChris Lattner 186*7d49c9c8SJohnny Chen case 'C': 18730fdc8d8SChris Lattner m_column = Args::StringToUInt32 (option_arg, 0); 18830fdc8d8SChris Lattner break; 1890c5cd90dSGreg Clayton 190*7d49c9c8SJohnny Chen case 'c': 191*7d49c9c8SJohnny Chen m_condition.assign(option_arg); 192*7d49c9c8SJohnny Chen break; 193*7d49c9c8SJohnny Chen 19430fdc8d8SChris Lattner case 'f': 19587df91b8SJim Ingham m_filenames.AppendIfUnique (FileSpec(option_arg, false)); 19630fdc8d8SChris Lattner break; 1970c5cd90dSGreg Clayton 19830fdc8d8SChris Lattner case 'l': 19930fdc8d8SChris Lattner m_line_num = Args::StringToUInt32 (option_arg, 0); 20030fdc8d8SChris Lattner break; 2010c5cd90dSGreg Clayton 202e02b8504SGreg Clayton case 'b': 203fab10e89SJim Ingham m_func_names.push_back (option_arg); 2040c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeBase; 2050c5cd90dSGreg Clayton break; 2060c5cd90dSGreg Clayton 207e02b8504SGreg Clayton case 'n': 208fab10e89SJim Ingham m_func_names.push_back (option_arg); 209e02b8504SGreg Clayton m_func_name_type_mask |= eFunctionNameTypeAuto; 210e02b8504SGreg Clayton break; 211e02b8504SGreg Clayton 2120c5cd90dSGreg Clayton case 'F': 213fab10e89SJim Ingham m_func_names.push_back (option_arg); 2140c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeFull; 2150c5cd90dSGreg Clayton break; 2160c5cd90dSGreg Clayton 2170c5cd90dSGreg Clayton case 'S': 218fab10e89SJim Ingham m_func_names.push_back (option_arg); 2190c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeSelector; 2200c5cd90dSGreg Clayton break; 2210c5cd90dSGreg Clayton 2222561aa61SJim Ingham case 'M': 223fab10e89SJim Ingham m_func_names.push_back (option_arg); 2240c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeMethod; 2250c5cd90dSGreg Clayton break; 2260c5cd90dSGreg Clayton 227969795f1SJim Ingham case 'p': 228969795f1SJim Ingham m_source_text_regexp.assign (option_arg); 229969795f1SJim Ingham break; 230969795f1SJim Ingham 23130fdc8d8SChris Lattner case 'r': 232357132ebSGreg Clayton m_func_regexp.assign (option_arg); 23330fdc8d8SChris Lattner break; 2340c5cd90dSGreg Clayton 23530fdc8d8SChris Lattner case 's': 23630fdc8d8SChris Lattner { 23787df91b8SJim Ingham m_modules.AppendIfUnique (FileSpec (option_arg, false)); 23830fdc8d8SChris Lattner break; 23930fdc8d8SChris Lattner } 240ed8a705cSGreg Clayton case 'i': 2411b54c88cSJim Ingham { 2420292f4a5SJim Ingham m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 243c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 24486edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); 2451b54c88cSJim Ingham } 246ae1c4cf5SJim Ingham break; 2471b54c88cSJim Ingham case 't' : 2481b54c88cSJim Ingham { 2490292f4a5SJim Ingham m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 2501b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 25186edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); 2521b54c88cSJim Ingham } 2531b54c88cSJim Ingham break; 2541b54c88cSJim Ingham case 'T': 255357132ebSGreg Clayton m_thread_name.assign (option_arg); 2561b54c88cSJim Ingham break; 2571b54c88cSJim Ingham case 'q': 258357132ebSGreg Clayton m_queue_name.assign (option_arg); 2591b54c88cSJim Ingham break; 2601b54c88cSJim Ingham case 'x': 2611b54c88cSJim Ingham { 2620292f4a5SJim Ingham m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 263c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 26486edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); 2651b54c88cSJim Ingham 2661b54c88cSJim Ingham } 2671b54c88cSJim Ingham break; 268fab10e89SJim Ingham case 'E': 269fab10e89SJim Ingham { 270fab10e89SJim Ingham LanguageType language = LanguageRuntime::GetLanguageTypeFromString (option_arg); 271fab10e89SJim Ingham 272fab10e89SJim Ingham switch (language) 273fab10e89SJim Ingham { 274fab10e89SJim Ingham case eLanguageTypeC89: 275fab10e89SJim Ingham case eLanguageTypeC: 276fab10e89SJim Ingham case eLanguageTypeC99: 277fab10e89SJim Ingham m_language = eLanguageTypeC; 278fab10e89SJim Ingham break; 279fab10e89SJim Ingham case eLanguageTypeC_plus_plus: 280fab10e89SJim Ingham m_language = eLanguageTypeC_plus_plus; 281fab10e89SJim Ingham break; 282fab10e89SJim Ingham case eLanguageTypeObjC: 283fab10e89SJim Ingham m_language = eLanguageTypeObjC; 284fab10e89SJim Ingham break; 285fab10e89SJim Ingham case eLanguageTypeObjC_plus_plus: 286fab10e89SJim Ingham error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c"); 287fab10e89SJim Ingham break; 288fab10e89SJim Ingham case eLanguageTypeUnknown: 289fab10e89SJim Ingham error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg); 290fab10e89SJim Ingham break; 291fab10e89SJim Ingham default: 292fab10e89SJim Ingham error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg); 293fab10e89SJim Ingham } 294fab10e89SJim Ingham } 295fab10e89SJim Ingham break; 296fab10e89SJim Ingham case 'w': 297fab10e89SJim Ingham { 298fab10e89SJim Ingham bool success; 299fab10e89SJim Ingham m_throw_bp = Args::StringToBoolean (option_arg, true, &success); 300fab10e89SJim Ingham if (!success) 301fab10e89SJim Ingham error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg); 302fab10e89SJim Ingham } 303fab10e89SJim Ingham break; 304fab10e89SJim Ingham case 'h': 305fab10e89SJim Ingham { 306fab10e89SJim Ingham bool success; 307fab10e89SJim Ingham m_catch_bp = Args::StringToBoolean (option_arg, true, &success); 308fab10e89SJim Ingham if (!success) 309fab10e89SJim Ingham error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg); 310fab10e89SJim Ingham } 311a8558b62SJim Ingham case 'K': 312a8558b62SJim Ingham { 313a8558b62SJim Ingham bool success; 314a8558b62SJim Ingham bool value; 315a8558b62SJim Ingham value = Args::StringToBoolean (option_arg, true, &success); 316a8558b62SJim Ingham if (value) 317a8558b62SJim Ingham m_skip_prologue = eLazyBoolYes; 318a8558b62SJim Ingham else 319a8558b62SJim Ingham m_skip_prologue = eLazyBoolNo; 320a8558b62SJim Ingham 321a8558b62SJim Ingham if (!success) 322a8558b62SJim Ingham error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg); 323a8558b62SJim Ingham } 324fab10e89SJim Ingham break; 32530fdc8d8SChris Lattner default: 32686edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 32730fdc8d8SChris Lattner break; 32830fdc8d8SChris Lattner } 32930fdc8d8SChris Lattner 33030fdc8d8SChris Lattner return error; 33130fdc8d8SChris Lattner } 33230fdc8d8SChris Lattner 33330fdc8d8SChris Lattner void 334f6b8b581SGreg Clayton CommandObjectBreakpointSet::CommandOptions::OptionParsingStarting () 33530fdc8d8SChris Lattner { 336*7d49c9c8SJohnny Chen m_condition.clear(); 33787df91b8SJim Ingham m_filenames.Clear(); 33830fdc8d8SChris Lattner m_line_num = 0; 33930fdc8d8SChris Lattner m_column = 0; 340fab10e89SJim Ingham m_func_names.clear(); 3410c5cd90dSGreg Clayton m_func_name_type_mask = 0; 34230fdc8d8SChris Lattner m_func_regexp.clear(); 34330fdc8d8SChris Lattner m_load_addr = LLDB_INVALID_ADDRESS; 34487df91b8SJim Ingham m_modules.Clear(); 345c982c768SGreg Clayton m_ignore_count = 0; 3461b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 347c982c768SGreg Clayton m_thread_index = UINT32_MAX; 3481b54c88cSJim Ingham m_thread_name.clear(); 3491b54c88cSJim Ingham m_queue_name.clear(); 350fab10e89SJim Ingham m_language = eLanguageTypeUnknown; 351fab10e89SJim Ingham m_catch_bp = false; 352fab10e89SJim Ingham m_throw_bp = true; 353a8558b62SJim Ingham m_skip_prologue = eLazyBoolCalculate; 35430fdc8d8SChris Lattner } 35530fdc8d8SChris Lattner 35630fdc8d8SChris Lattner //------------------------------------------------------------------------- 35730fdc8d8SChris Lattner // CommandObjectBreakpointSet 35830fdc8d8SChris Lattner //------------------------------------------------------------------------- 359ae1c4cf5SJim Ingham #pragma mark Set 36030fdc8d8SChris Lattner 361a7015092SGreg Clayton CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) : 362a7015092SGreg Clayton CommandObject (interpreter, 363a7015092SGreg Clayton "breakpoint set", 364a7015092SGreg Clayton "Sets a breakpoint or set of breakpoints in the executable.", 365eb0103f2SGreg Clayton "breakpoint set <cmd-options>"), 366eb0103f2SGreg Clayton m_options (interpreter) 36730fdc8d8SChris Lattner { 36830fdc8d8SChris Lattner } 36930fdc8d8SChris Lattner 37030fdc8d8SChris Lattner CommandObjectBreakpointSet::~CommandObjectBreakpointSet () 37130fdc8d8SChris Lattner { 37230fdc8d8SChris Lattner } 37330fdc8d8SChris Lattner 37430fdc8d8SChris Lattner Options * 37530fdc8d8SChris Lattner CommandObjectBreakpointSet::GetOptions () 37630fdc8d8SChris Lattner { 37730fdc8d8SChris Lattner return &m_options; 37830fdc8d8SChris Lattner } 37930fdc8d8SChris Lattner 38030fdc8d8SChris Lattner bool 38187df91b8SJim Ingham CommandObjectBreakpointSet::GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result) 382969795f1SJim Ingham { 383969795f1SJim Ingham uint32_t default_line; 384969795f1SJim Ingham // First use the Source Manager's default file. 385969795f1SJim Ingham // Then use the current stack frame's file. 386969795f1SJim Ingham if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) 387969795f1SJim Ingham { 388c14ee32dSGreg Clayton StackFrame *cur_frame = m_interpreter.GetExecutionContext().GetFramePtr(); 389969795f1SJim Ingham if (cur_frame == NULL) 390969795f1SJim Ingham { 39187df91b8SJim Ingham result.AppendError ("No selected frame to use to find the default file."); 392969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 393969795f1SJim Ingham return false; 394969795f1SJim Ingham } 395969795f1SJim Ingham else if (!cur_frame->HasDebugInformation()) 396969795f1SJim Ingham { 39787df91b8SJim Ingham result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info."); 398969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 399969795f1SJim Ingham return false; 400969795f1SJim Ingham } 401969795f1SJim Ingham else 402969795f1SJim Ingham { 403969795f1SJim Ingham const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry); 404969795f1SJim Ingham if (sc.line_entry.file) 405969795f1SJim Ingham { 406969795f1SJim Ingham file = sc.line_entry.file; 407969795f1SJim Ingham } 408969795f1SJim Ingham else 409969795f1SJim Ingham { 41087df91b8SJim Ingham result.AppendError ("Can't find the file for the selected frame to use as the default file."); 411969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 412969795f1SJim Ingham return false; 413969795f1SJim Ingham } 414969795f1SJim Ingham } 415969795f1SJim Ingham } 416969795f1SJim Ingham return true; 417969795f1SJim Ingham } 418969795f1SJim Ingham 419969795f1SJim Ingham bool 42030fdc8d8SChris Lattner CommandObjectBreakpointSet::Execute 42130fdc8d8SChris Lattner ( 42230fdc8d8SChris Lattner Args& command, 42330fdc8d8SChris Lattner CommandReturnObject &result 42430fdc8d8SChris Lattner ) 42530fdc8d8SChris Lattner { 426a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 42730fdc8d8SChris Lattner if (target == NULL) 42830fdc8d8SChris Lattner { 429effe5c95SGreg Clayton result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command)."); 43030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 43130fdc8d8SChris Lattner return false; 43230fdc8d8SChris Lattner } 43330fdc8d8SChris Lattner 43430fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 43530fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 43630fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 43730fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 43830fdc8d8SChris Lattner // 4). -r [-s -g] (setting breakpoint by function name regular expression) 439969795f1SJim Ingham // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text) 440fab10e89SJim Ingham // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.) 44130fdc8d8SChris Lattner 44230fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 44330fdc8d8SChris Lattner 44430fdc8d8SChris Lattner if (m_options.m_line_num != 0) 44530fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 44630fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 44730fdc8d8SChris Lattner break_type = eSetTypeAddress; 448fab10e89SJim Ingham else if (!m_options.m_func_names.empty()) 44930fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 45030fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 45130fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 452969795f1SJim Ingham else if (!m_options.m_source_text_regexp.empty()) 453969795f1SJim Ingham break_type = eSetTypeSourceRegexp; 454fab10e89SJim Ingham else if (m_options.m_language != eLanguageTypeUnknown) 455fab10e89SJim Ingham break_type = eSetTypeException; 45630fdc8d8SChris Lattner 45730fdc8d8SChris Lattner Breakpoint *bp = NULL; 458274060b6SGreg Clayton FileSpec module_spec; 45930fdc8d8SChris Lattner bool use_module = false; 46087df91b8SJim Ingham int num_modules = m_options.m_modules.GetSize(); 461969795f1SJim Ingham 462a8558b62SJim Ingham const bool internal = false; 463a8558b62SJim Ingham 46430fdc8d8SChris Lattner if ((num_modules > 0) && (break_type != eSetTypeAddress)) 46530fdc8d8SChris Lattner use_module = true; 46630fdc8d8SChris Lattner 46730fdc8d8SChris Lattner switch (break_type) 46830fdc8d8SChris Lattner { 46930fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 47030fdc8d8SChris Lattner { 47130fdc8d8SChris Lattner FileSpec file; 47287df91b8SJim Ingham uint32_t num_files = m_options.m_filenames.GetSize(); 47387df91b8SJim Ingham if (num_files == 0) 47487df91b8SJim Ingham { 47587df91b8SJim Ingham if (!GetDefaultFile (target, file, result)) 47687df91b8SJim Ingham { 47787df91b8SJim Ingham result.AppendError("No file supplied and no default file available."); 47887df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 47987df91b8SJim Ingham return false; 48087df91b8SJim Ingham } 48187df91b8SJim Ingham } 48287df91b8SJim Ingham else if (num_files > 1) 48387df91b8SJim Ingham { 48487df91b8SJim Ingham result.AppendError("Only one file at a time is allowed for file and line breakpoints."); 48587df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 48687df91b8SJim Ingham return false; 48787df91b8SJim Ingham } 48887df91b8SJim Ingham else 48987df91b8SJim Ingham file = m_options.m_filenames.GetFileSpecAtIndex(0); 49030fdc8d8SChris Lattner 49187df91b8SJim Ingham bp = target->CreateBreakpoint (&(m_options.m_modules), 49230fdc8d8SChris Lattner file, 49330fdc8d8SChris Lattner m_options.m_line_num, 494a8558b62SJim Ingham m_options.m_check_inlines, 495a8558b62SJim Ingham m_options.m_skip_prologue, 496a8558b62SJim Ingham internal).get(); 49730fdc8d8SChris Lattner } 49830fdc8d8SChris Lattner break; 4996eee5aa0SGreg Clayton 50030fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 50130fdc8d8SChris Lattner bp = target->CreateBreakpoint (m_options.m_load_addr, false).get(); 50230fdc8d8SChris Lattner break; 5030c5cd90dSGreg Clayton 50430fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 5050c5cd90dSGreg Clayton { 5060c5cd90dSGreg Clayton uint32_t name_type_mask = m_options.m_func_name_type_mask; 5070c5cd90dSGreg Clayton 5080c5cd90dSGreg Clayton if (name_type_mask == 0) 509e02b8504SGreg Clayton name_type_mask = eFunctionNameTypeAuto; 5100c5cd90dSGreg Clayton 51187df91b8SJim Ingham bp = target->CreateBreakpoint (&(m_options.m_modules), 51287df91b8SJim Ingham &(m_options.m_filenames), 513fab10e89SJim Ingham m_options.m_func_names, 514274060b6SGreg Clayton name_type_mask, 515a8558b62SJim Ingham m_options.m_skip_prologue, 516a8558b62SJim Ingham internal).get(); 5170c5cd90dSGreg Clayton } 51830fdc8d8SChris Lattner break; 5190c5cd90dSGreg Clayton 52030fdc8d8SChris Lattner case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name 52130fdc8d8SChris Lattner { 52230fdc8d8SChris Lattner RegularExpression regexp(m_options.m_func_regexp.c_str()); 523969795f1SJim Ingham if (!regexp.IsValid()) 52430fdc8d8SChris Lattner { 525969795f1SJim Ingham char err_str[1024]; 526969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 527969795f1SJim Ingham result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"", 528969795f1SJim Ingham err_str); 52930fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 530969795f1SJim Ingham return false; 53130fdc8d8SChris Lattner } 53287df91b8SJim Ingham 533a8558b62SJim Ingham bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules), 534a8558b62SJim Ingham &(m_options.m_filenames), 535a8558b62SJim Ingham regexp, 536a8558b62SJim Ingham m_options.m_skip_prologue, 537a8558b62SJim Ingham internal).get(); 53830fdc8d8SChris Lattner } 53930fdc8d8SChris Lattner break; 540969795f1SJim Ingham case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. 541969795f1SJim Ingham { 54287df91b8SJim Ingham int num_files = m_options.m_filenames.GetSize(); 54387df91b8SJim Ingham 54487df91b8SJim Ingham if (num_files == 0) 54587df91b8SJim Ingham { 546969795f1SJim Ingham FileSpec file; 54787df91b8SJim Ingham if (!GetDefaultFile (target, file, result)) 54887df91b8SJim Ingham { 54987df91b8SJim Ingham result.AppendError ("No files provided and could not find default file."); 55087df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 55187df91b8SJim Ingham return false; 55287df91b8SJim Ingham } 55387df91b8SJim Ingham else 55487df91b8SJim Ingham { 55587df91b8SJim Ingham m_options.m_filenames.Append (file); 55687df91b8SJim Ingham } 55787df91b8SJim Ingham } 5580c5cd90dSGreg Clayton 559969795f1SJim Ingham RegularExpression regexp(m_options.m_source_text_regexp.c_str()); 560969795f1SJim Ingham if (!regexp.IsValid()) 561969795f1SJim Ingham { 562969795f1SJim Ingham char err_str[1024]; 563969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 564969795f1SJim Ingham result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"", 565969795f1SJim Ingham err_str); 566969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 567969795f1SJim Ingham return false; 568969795f1SJim Ingham } 56987df91b8SJim Ingham bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules), &(m_options.m_filenames), regexp).get(); 570969795f1SJim Ingham } 571969795f1SJim Ingham break; 572fab10e89SJim Ingham case eSetTypeException: 573fab10e89SJim Ingham { 574fab10e89SJim Ingham bp = target->CreateExceptionBreakpoint (m_options.m_language, m_options.m_catch_bp, m_options.m_throw_bp).get(); 575fab10e89SJim Ingham } 576fab10e89SJim Ingham break; 57730fdc8d8SChris Lattner default: 57830fdc8d8SChris Lattner break; 57930fdc8d8SChris Lattner } 58030fdc8d8SChris Lattner 5811b54c88cSJim Ingham // Now set the various options that were passed in: 5821b54c88cSJim Ingham if (bp) 5831b54c88cSJim Ingham { 5841b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 5851b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 5861b54c88cSJim Ingham 587c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 5881b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 5891b54c88cSJim Ingham 5901b54c88cSJim Ingham if (!m_options.m_thread_name.empty()) 5911b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 5921b54c88cSJim Ingham 5931b54c88cSJim Ingham if (!m_options.m_queue_name.empty()) 5941b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 5951b54c88cSJim Ingham 596c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 5971b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 598*7d49c9c8SJohnny Chen 599*7d49c9c8SJohnny Chen if (!m_options.m_condition.empty()) 600*7d49c9c8SJohnny Chen bp->GetOptions()->SetCondition(m_options.m_condition.c_str()); 6011b54c88cSJim Ingham } 6021b54c88cSJim Ingham 603969795f1SJim Ingham if (bp) 60430fdc8d8SChris Lattner { 60585e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 60630fdc8d8SChris Lattner output_stream.Printf ("Breakpoint created: "); 60730fdc8d8SChris Lattner bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); 60830fdc8d8SChris Lattner output_stream.EOL(); 609fab10e89SJim Ingham // Don't print out this warning for exception breakpoints. They can get set before the target 610fab10e89SJim Ingham // is set, but we won't know how to actually set the breakpoint till we run. 611fab10e89SJim Ingham if (bp->GetNumLocations() == 0 && break_type != eSetTypeException) 612be484f41SCaroline Tice output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n"); 61330fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 61430fdc8d8SChris Lattner } 61530fdc8d8SChris Lattner else if (!bp) 61630fdc8d8SChris Lattner { 61730fdc8d8SChris Lattner result.AppendError ("Breakpoint creation failed: No breakpoint created."); 61830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 61930fdc8d8SChris Lattner } 62030fdc8d8SChris Lattner 62130fdc8d8SChris Lattner return result.Succeeded(); 62230fdc8d8SChris Lattner } 62330fdc8d8SChris Lattner 62430fdc8d8SChris Lattner //------------------------------------------------------------------------- 62530fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 62630fdc8d8SChris Lattner //------------------------------------------------------------------------- 627ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 62830fdc8d8SChris Lattner 6296611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) : 630a7015092SGreg Clayton CommandObjectMultiword (interpreter, 631a7015092SGreg Clayton "breakpoint", 63246fbc60fSJim Ingham "A set of commands for operating on breakpoints. Also see _regexp-break.", 63330fdc8d8SChris Lattner "breakpoint <command> [<command-options>]") 63430fdc8d8SChris Lattner { 63530fdc8d8SChris Lattner bool status; 63630fdc8d8SChris Lattner 637a7015092SGreg Clayton CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter)); 638a7015092SGreg Clayton CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter)); 639a7015092SGreg Clayton CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter)); 640b7234e40SJohnny Chen CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter)); 641b7234e40SJohnny Chen CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter)); 642a7015092SGreg Clayton CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter)); 64330fdc8d8SChris Lattner CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter)); 644a7015092SGreg Clayton CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter)); 64530fdc8d8SChris Lattner 646b7234e40SJohnny Chen list_command_object->SetCommandName ("breakpoint list"); 64730fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 64830fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 649b7234e40SJohnny Chen clear_command_object->SetCommandName("breakpoint clear"); 650b7234e40SJohnny Chen delete_command_object->SetCommandName("breakpoint delete"); 651ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 652b7234e40SJohnny Chen command_command_object->SetCommandName ("breakpoint command"); 653b7234e40SJohnny Chen modify_command_object->SetCommandName ("breakpoint modify"); 65430fdc8d8SChris Lattner 655a7015092SGreg Clayton status = LoadSubCommand ("list", list_command_object); 656a7015092SGreg Clayton status = LoadSubCommand ("enable", enable_command_object); 657a7015092SGreg Clayton status = LoadSubCommand ("disable", disable_command_object); 658b7234e40SJohnny Chen status = LoadSubCommand ("clear", clear_command_object); 659a7015092SGreg Clayton status = LoadSubCommand ("delete", delete_command_object); 660a7015092SGreg Clayton status = LoadSubCommand ("set", set_command_object); 661a7015092SGreg Clayton status = LoadSubCommand ("command", command_command_object); 662a7015092SGreg Clayton status = LoadSubCommand ("modify", modify_command_object); 66330fdc8d8SChris Lattner } 66430fdc8d8SChris Lattner 66530fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint () 66630fdc8d8SChris Lattner { 66730fdc8d8SChris Lattner } 66830fdc8d8SChris Lattner 66930fdc8d8SChris Lattner void 67030fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result, 67130fdc8d8SChris Lattner BreakpointIDList *valid_ids) 67230fdc8d8SChris Lattner { 67330fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 67430fdc8d8SChris Lattner // 2). the full breakpoint & location canonical representation 67530fdc8d8SChris Lattner // 3). the word "to" or a hyphen, representing a range (in which case there 67630fdc8d8SChris Lattner // had *better* be an entry both before & after of one of the first two types. 67736f3b369SJim Ingham // If args is empty, we will use the last created breakpoint (if there is one.) 67830fdc8d8SChris Lattner 67930fdc8d8SChris Lattner Args temp_args; 68030fdc8d8SChris Lattner 68136f3b369SJim Ingham if (args.GetArgumentCount() == 0) 68236f3b369SJim Ingham { 6834d122c40SGreg Clayton if (target->GetLastCreatedBreakpoint()) 68436f3b369SJim Ingham { 68536f3b369SJim Ingham valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); 68636f3b369SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 68736f3b369SJim Ingham } 68836f3b369SJim Ingham else 68936f3b369SJim Ingham { 69036f3b369SJim Ingham result.AppendError("No breakpoint specified and no last created breakpoint."); 69136f3b369SJim Ingham result.SetStatus (eReturnStatusFailed); 69236f3b369SJim Ingham } 69336f3b369SJim Ingham return; 69436f3b369SJim Ingham } 69536f3b369SJim Ingham 69630fdc8d8SChris Lattner // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to 69730fdc8d8SChris Lattner // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for 69830fdc8d8SChris Lattner // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS. 69930fdc8d8SChris Lattner 70030fdc8d8SChris Lattner BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args); 70130fdc8d8SChris Lattner 70230fdc8d8SChris Lattner // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList: 70330fdc8d8SChris Lattner 704c982c768SGreg Clayton valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result); 70530fdc8d8SChris Lattner 70630fdc8d8SChris Lattner // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs 70730fdc8d8SChris Lattner // and put into valid_ids. 70830fdc8d8SChris Lattner 70930fdc8d8SChris Lattner if (result.Succeeded()) 71030fdc8d8SChris Lattner { 71130fdc8d8SChris Lattner // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list 71230fdc8d8SChris Lattner // of breakpoint id's and verify that they correspond to valid/currently set breakpoints. 71330fdc8d8SChris Lattner 714c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 715c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 71630fdc8d8SChris Lattner { 71730fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i); 71830fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 71930fdc8d8SChris Lattner if (breakpoint != NULL) 72030fdc8d8SChris Lattner { 72130fdc8d8SChris Lattner int num_locations = breakpoint->GetNumLocations(); 72230fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() > num_locations) 72330fdc8d8SChris Lattner { 72430fdc8d8SChris Lattner StreamString id_str; 725c982c768SGreg Clayton BreakpointID::GetCanonicalReference (&id_str, 726c982c768SGreg Clayton cur_bp_id.GetBreakpointID(), 72730fdc8d8SChris Lattner cur_bp_id.GetLocationID()); 728c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 72930fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n", 73030fdc8d8SChris Lattner id_str.GetData()); 73130fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 73230fdc8d8SChris Lattner } 73330fdc8d8SChris Lattner } 73430fdc8d8SChris Lattner else 73530fdc8d8SChris Lattner { 736c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 73730fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID()); 73830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 73930fdc8d8SChris Lattner } 74030fdc8d8SChris Lattner } 74130fdc8d8SChris Lattner } 74230fdc8d8SChris Lattner } 74330fdc8d8SChris Lattner 74430fdc8d8SChris Lattner //------------------------------------------------------------------------- 74530fdc8d8SChris Lattner // CommandObjectBreakpointList::Options 74630fdc8d8SChris Lattner //------------------------------------------------------------------------- 747ae1c4cf5SJim Ingham #pragma mark List::CommandOptions 74830fdc8d8SChris Lattner 749eb0103f2SGreg Clayton CommandObjectBreakpointList::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 750eb0103f2SGreg Clayton Options (interpreter), 75179042b3eSCaroline Tice m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions 75230fdc8d8SChris Lattner { 75330fdc8d8SChris Lattner } 75430fdc8d8SChris Lattner 75530fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::~CommandOptions () 75630fdc8d8SChris Lattner { 75730fdc8d8SChris Lattner } 75830fdc8d8SChris Lattner 759e0d378b3SGreg Clayton OptionDefinition 76030fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::g_option_table[] = 76130fdc8d8SChris Lattner { 762deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone, 7638651121cSJim Ingham "Show debugger internal breakpoints" }, 7648651121cSJim Ingham 765deaab222SCaroline Tice { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone, 76630fdc8d8SChris Lattner "Give a brief description of the breakpoint (no location info)."}, 76730fdc8d8SChris Lattner 76830fdc8d8SChris Lattner // FIXME: We need to add an "internal" command, and then add this sort of thing to it. 76930fdc8d8SChris Lattner // But I need to see it for now, and don't want to wait. 770deaab222SCaroline Tice { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone, 77130fdc8d8SChris Lattner "Give a full description of the breakpoint and its locations."}, 77230fdc8d8SChris Lattner 773deaab222SCaroline Tice { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, 77430fdc8d8SChris Lattner "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, 77530fdc8d8SChris Lattner 776deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 77730fdc8d8SChris Lattner }; 77830fdc8d8SChris Lattner 779e0d378b3SGreg Clayton const OptionDefinition* 78030fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::GetDefinitions () 78130fdc8d8SChris Lattner { 78230fdc8d8SChris Lattner return g_option_table; 78330fdc8d8SChris Lattner } 78430fdc8d8SChris Lattner 78530fdc8d8SChris Lattner Error 786f6b8b581SGreg Clayton CommandObjectBreakpointList::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 78730fdc8d8SChris Lattner { 78830fdc8d8SChris Lattner Error error; 78930fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 79030fdc8d8SChris Lattner 79130fdc8d8SChris Lattner switch (short_option) 79230fdc8d8SChris Lattner { 79330fdc8d8SChris Lattner case 'b': 79430fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelBrief; 79530fdc8d8SChris Lattner break; 79630fdc8d8SChris Lattner case 'f': 79730fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelFull; 79830fdc8d8SChris Lattner break; 79930fdc8d8SChris Lattner case 'v': 80030fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelVerbose; 80130fdc8d8SChris Lattner break; 80230fdc8d8SChris Lattner case 'i': 80330fdc8d8SChris Lattner m_internal = true; 80430fdc8d8SChris Lattner break; 80530fdc8d8SChris Lattner default: 80686edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 80730fdc8d8SChris Lattner break; 80830fdc8d8SChris Lattner } 80930fdc8d8SChris Lattner 81030fdc8d8SChris Lattner return error; 81130fdc8d8SChris Lattner } 81230fdc8d8SChris Lattner 81330fdc8d8SChris Lattner void 814f6b8b581SGreg Clayton CommandObjectBreakpointList::CommandOptions::OptionParsingStarting () 81530fdc8d8SChris Lattner { 816d915e16fSJim Ingham m_level = lldb::eDescriptionLevelFull; 81730fdc8d8SChris Lattner m_internal = false; 81830fdc8d8SChris Lattner } 81930fdc8d8SChris Lattner 82030fdc8d8SChris Lattner //------------------------------------------------------------------------- 82130fdc8d8SChris Lattner // CommandObjectBreakpointList 82230fdc8d8SChris Lattner //------------------------------------------------------------------------- 823ae1c4cf5SJim Ingham #pragma mark List 82430fdc8d8SChris Lattner 825a7015092SGreg Clayton CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) : 826a7015092SGreg Clayton CommandObject (interpreter, 827a7015092SGreg Clayton "breakpoint list", 82830fdc8d8SChris Lattner "List some or all breakpoints at configurable levels of detail.", 829eb0103f2SGreg Clayton NULL), 830eb0103f2SGreg Clayton m_options (interpreter) 83130fdc8d8SChris Lattner { 832e139cf23SCaroline Tice CommandArgumentEntry arg; 833e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 834e139cf23SCaroline Tice 835e139cf23SCaroline Tice // Define the first (and only) variant of this arg. 836e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 837405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 838e139cf23SCaroline Tice 839e139cf23SCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 840e139cf23SCaroline Tice arg.push_back (bp_id_arg); 841e139cf23SCaroline Tice 842e139cf23SCaroline Tice // Push the data for the first argument into the m_arguments vector. 843e139cf23SCaroline Tice m_arguments.push_back (arg); 84430fdc8d8SChris Lattner } 84530fdc8d8SChris Lattner 84630fdc8d8SChris Lattner CommandObjectBreakpointList::~CommandObjectBreakpointList () 84730fdc8d8SChris Lattner { 84830fdc8d8SChris Lattner } 84930fdc8d8SChris Lattner 85030fdc8d8SChris Lattner Options * 85130fdc8d8SChris Lattner CommandObjectBreakpointList::GetOptions () 85230fdc8d8SChris Lattner { 85330fdc8d8SChris Lattner return &m_options; 85430fdc8d8SChris Lattner } 85530fdc8d8SChris Lattner 85630fdc8d8SChris Lattner bool 85730fdc8d8SChris Lattner CommandObjectBreakpointList::Execute 85830fdc8d8SChris Lattner ( 85930fdc8d8SChris Lattner Args& args, 86030fdc8d8SChris Lattner CommandReturnObject &result 86130fdc8d8SChris Lattner ) 86230fdc8d8SChris Lattner { 863a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 86430fdc8d8SChris Lattner if (target == NULL) 86530fdc8d8SChris Lattner { 8669068d794SCaroline Tice result.AppendError ("Invalid target. No current target or breakpoints."); 86730fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 86830fdc8d8SChris Lattner return true; 86930fdc8d8SChris Lattner } 87030fdc8d8SChris Lattner 87130fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal); 8721b54c88cSJim Ingham Mutex::Locker locker; 8731b54c88cSJim Ingham target->GetBreakpointList(m_options.m_internal).GetListMutex(locker); 8741b54c88cSJim Ingham 87530fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 87630fdc8d8SChris Lattner 87730fdc8d8SChris Lattner if (num_breakpoints == 0) 87830fdc8d8SChris Lattner { 87930fdc8d8SChris Lattner result.AppendMessage ("No breakpoints currently set."); 88030fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 88130fdc8d8SChris Lattner return true; 88230fdc8d8SChris Lattner } 88330fdc8d8SChris Lattner 88485e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 88530fdc8d8SChris Lattner 88630fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 88730fdc8d8SChris Lattner { 88830fdc8d8SChris Lattner // No breakpoint selected; show info about all currently set breakpoints. 88930fdc8d8SChris Lattner result.AppendMessage ("Current breakpoints:"); 890c982c768SGreg Clayton for (size_t i = 0; i < num_breakpoints; ++i) 89130fdc8d8SChris Lattner { 8929fed0d85SGreg Clayton Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get(); 8936611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 89430fdc8d8SChris Lattner } 89530fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 89630fdc8d8SChris Lattner } 89730fdc8d8SChris Lattner else 89830fdc8d8SChris Lattner { 89930fdc8d8SChris Lattner // Particular breakpoints selected; show info about that breakpoint. 90030fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 90130fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 90230fdc8d8SChris Lattner 90330fdc8d8SChris Lattner if (result.Succeeded()) 90430fdc8d8SChris Lattner { 905c982c768SGreg Clayton for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) 90630fdc8d8SChris Lattner { 90730fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 90830fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 9096611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 91030fdc8d8SChris Lattner } 91130fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 91230fdc8d8SChris Lattner } 91330fdc8d8SChris Lattner else 91430fdc8d8SChris Lattner { 91530fdc8d8SChris Lattner result.AppendError ("Invalid breakpoint id."); 91630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 91730fdc8d8SChris Lattner } 91830fdc8d8SChris Lattner } 91930fdc8d8SChris Lattner 92030fdc8d8SChris Lattner return result.Succeeded(); 92130fdc8d8SChris Lattner } 92230fdc8d8SChris Lattner 92330fdc8d8SChris Lattner //------------------------------------------------------------------------- 92430fdc8d8SChris Lattner // CommandObjectBreakpointEnable 92530fdc8d8SChris Lattner //------------------------------------------------------------------------- 926ae1c4cf5SJim Ingham #pragma mark Enable 92730fdc8d8SChris Lattner 928a7015092SGreg Clayton CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) : 929a7015092SGreg Clayton CommandObject (interpreter, 930a7015092SGreg Clayton "enable", 931e3d26315SCaroline Tice "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.", 932e139cf23SCaroline Tice NULL) 93330fdc8d8SChris Lattner { 934e139cf23SCaroline Tice CommandArgumentEntry arg; 935de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 936e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 937e139cf23SCaroline Tice m_arguments.push_back (arg); 93830fdc8d8SChris Lattner } 93930fdc8d8SChris Lattner 94030fdc8d8SChris Lattner 94130fdc8d8SChris Lattner CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable () 94230fdc8d8SChris Lattner { 94330fdc8d8SChris Lattner } 94430fdc8d8SChris Lattner 94530fdc8d8SChris Lattner 94630fdc8d8SChris Lattner bool 9476611103cSGreg Clayton CommandObjectBreakpointEnable::Execute 9486611103cSGreg Clayton ( 9496611103cSGreg Clayton Args& args, 9506611103cSGreg Clayton CommandReturnObject &result 9516611103cSGreg Clayton ) 95230fdc8d8SChris Lattner { 953a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 95430fdc8d8SChris Lattner if (target == NULL) 95530fdc8d8SChris Lattner { 9569068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 95730fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 95830fdc8d8SChris Lattner return false; 95930fdc8d8SChris Lattner } 96030fdc8d8SChris Lattner 9611b54c88cSJim Ingham Mutex::Locker locker; 9621b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 9631b54c88cSJim Ingham 96430fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 9651b54c88cSJim Ingham 96630fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 96730fdc8d8SChris Lattner 96830fdc8d8SChris Lattner if (num_breakpoints == 0) 96930fdc8d8SChris Lattner { 97030fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be enabled."); 97130fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 97230fdc8d8SChris Lattner return false; 97330fdc8d8SChris Lattner } 97430fdc8d8SChris Lattner 97530fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 97630fdc8d8SChris Lattner { 97730fdc8d8SChris Lattner // No breakpoint selected; enable all currently set breakpoints. 97830fdc8d8SChris Lattner target->EnableAllBreakpoints (); 979fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints enabled. (%lu breakpoints)\n", num_breakpoints); 98030fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 98130fdc8d8SChris Lattner } 98230fdc8d8SChris Lattner else 98330fdc8d8SChris Lattner { 98430fdc8d8SChris Lattner // Particular breakpoint selected; enable that breakpoint. 98530fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 98630fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 98730fdc8d8SChris Lattner 98830fdc8d8SChris Lattner if (result.Succeeded()) 98930fdc8d8SChris Lattner { 99030fdc8d8SChris Lattner int enable_count = 0; 99130fdc8d8SChris Lattner int loc_count = 0; 992c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 993c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 99430fdc8d8SChris Lattner { 99530fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 99630fdc8d8SChris Lattner 99730fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 99830fdc8d8SChris Lattner { 99930fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 100030fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 100130fdc8d8SChris Lattner { 100230fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 100330fdc8d8SChris Lattner if (location) 100430fdc8d8SChris Lattner { 100530fdc8d8SChris Lattner location->SetEnabled (true); 100630fdc8d8SChris Lattner ++loc_count; 100730fdc8d8SChris Lattner } 100830fdc8d8SChris Lattner } 100930fdc8d8SChris Lattner else 101030fdc8d8SChris Lattner { 1011ae1c4cf5SJim Ingham breakpoint->SetEnabled (true); 101230fdc8d8SChris Lattner ++enable_count; 101330fdc8d8SChris Lattner } 101430fdc8d8SChris Lattner } 101530fdc8d8SChris Lattner } 101630fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count); 101730fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 101830fdc8d8SChris Lattner } 101930fdc8d8SChris Lattner } 102030fdc8d8SChris Lattner 102130fdc8d8SChris Lattner return result.Succeeded(); 102230fdc8d8SChris Lattner } 102330fdc8d8SChris Lattner 102430fdc8d8SChris Lattner //------------------------------------------------------------------------- 102530fdc8d8SChris Lattner // CommandObjectBreakpointDisable 102630fdc8d8SChris Lattner //------------------------------------------------------------------------- 1027ae1c4cf5SJim Ingham #pragma mark Disable 102830fdc8d8SChris Lattner 1029a7015092SGreg Clayton CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) : 1030a7015092SGreg Clayton CommandObject (interpreter, 1031e139cf23SCaroline Tice "breakpoint disable", 1032e3d26315SCaroline Tice "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.", 1033e139cf23SCaroline Tice NULL) 103430fdc8d8SChris Lattner { 1035e139cf23SCaroline Tice CommandArgumentEntry arg; 1036de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 1037e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1038e139cf23SCaroline Tice m_arguments.push_back (arg); 103930fdc8d8SChris Lattner } 104030fdc8d8SChris Lattner 104130fdc8d8SChris Lattner CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable () 104230fdc8d8SChris Lattner { 104330fdc8d8SChris Lattner } 104430fdc8d8SChris Lattner 104530fdc8d8SChris Lattner bool 10466611103cSGreg Clayton CommandObjectBreakpointDisable::Execute 10476611103cSGreg Clayton ( 10486611103cSGreg Clayton Args& args, 10496611103cSGreg Clayton CommandReturnObject &result 10506611103cSGreg Clayton ) 105130fdc8d8SChris Lattner { 1052a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 105330fdc8d8SChris Lattner if (target == NULL) 105430fdc8d8SChris Lattner { 10559068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 105630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 105730fdc8d8SChris Lattner return false; 105830fdc8d8SChris Lattner } 105930fdc8d8SChris Lattner 10601b54c88cSJim Ingham Mutex::Locker locker; 10611b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 10621b54c88cSJim Ingham 106330fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 106430fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 106530fdc8d8SChris Lattner 106630fdc8d8SChris Lattner if (num_breakpoints == 0) 106730fdc8d8SChris Lattner { 106830fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be disabled."); 106930fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 107030fdc8d8SChris Lattner return false; 107130fdc8d8SChris Lattner } 107230fdc8d8SChris Lattner 107330fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 107430fdc8d8SChris Lattner { 107530fdc8d8SChris Lattner // No breakpoint selected; disable all currently set breakpoints. 107630fdc8d8SChris Lattner target->DisableAllBreakpoints (); 1077fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints disabled. (%lu breakpoints)\n", num_breakpoints); 107830fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 107930fdc8d8SChris Lattner } 108030fdc8d8SChris Lattner else 108130fdc8d8SChris Lattner { 108230fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 108330fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 108430fdc8d8SChris Lattner 108530fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 108630fdc8d8SChris Lattner 108730fdc8d8SChris Lattner if (result.Succeeded()) 108830fdc8d8SChris Lattner { 108930fdc8d8SChris Lattner int disable_count = 0; 109030fdc8d8SChris Lattner int loc_count = 0; 1091c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1092c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 109330fdc8d8SChris Lattner { 109430fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 109530fdc8d8SChris Lattner 109630fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 109730fdc8d8SChris Lattner { 109830fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 109930fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 110030fdc8d8SChris Lattner { 110130fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 110230fdc8d8SChris Lattner if (location) 110330fdc8d8SChris Lattner { 110430fdc8d8SChris Lattner location->SetEnabled (false); 110530fdc8d8SChris Lattner ++loc_count; 110630fdc8d8SChris Lattner } 110730fdc8d8SChris Lattner } 110830fdc8d8SChris Lattner else 110930fdc8d8SChris Lattner { 1110ae1c4cf5SJim Ingham breakpoint->SetEnabled (false); 111130fdc8d8SChris Lattner ++disable_count; 111230fdc8d8SChris Lattner } 111330fdc8d8SChris Lattner } 111430fdc8d8SChris Lattner } 111530fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count); 111630fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 111730fdc8d8SChris Lattner } 111830fdc8d8SChris Lattner } 111930fdc8d8SChris Lattner 112030fdc8d8SChris Lattner return result.Succeeded(); 112130fdc8d8SChris Lattner } 112230fdc8d8SChris Lattner 112330fdc8d8SChris Lattner //------------------------------------------------------------------------- 1124b7234e40SJohnny Chen // CommandObjectBreakpointClear::CommandOptions 1125b7234e40SJohnny Chen //------------------------------------------------------------------------- 1126b7234e40SJohnny Chen #pragma mark Clear::CommandOptions 1127b7234e40SJohnny Chen 1128eb0103f2SGreg Clayton CommandObjectBreakpointClear::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 1129eb0103f2SGreg Clayton Options (interpreter), 1130b7234e40SJohnny Chen m_filename (), 1131b7234e40SJohnny Chen m_line_num (0) 1132b7234e40SJohnny Chen { 1133b7234e40SJohnny Chen } 1134b7234e40SJohnny Chen 1135b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::~CommandOptions () 1136b7234e40SJohnny Chen { 1137b7234e40SJohnny Chen } 1138b7234e40SJohnny Chen 1139e0d378b3SGreg Clayton OptionDefinition 1140b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::g_option_table[] = 1141b7234e40SJohnny Chen { 1142b7234e40SJohnny Chen { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, 1143b7234e40SJohnny Chen "Specify the breakpoint by source location in this particular file."}, 1144b7234e40SJohnny Chen 1145b7234e40SJohnny Chen { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, 1146b7234e40SJohnny Chen "Specify the breakpoint by source location at this particular line."}, 1147b7234e40SJohnny Chen 1148b7234e40SJohnny Chen { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 1149b7234e40SJohnny Chen }; 1150b7234e40SJohnny Chen 1151e0d378b3SGreg Clayton const OptionDefinition* 1152b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::GetDefinitions () 1153b7234e40SJohnny Chen { 1154b7234e40SJohnny Chen return g_option_table; 1155b7234e40SJohnny Chen } 1156b7234e40SJohnny Chen 1157b7234e40SJohnny Chen Error 1158f6b8b581SGreg Clayton CommandObjectBreakpointClear::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 1159b7234e40SJohnny Chen { 1160b7234e40SJohnny Chen Error error; 1161b7234e40SJohnny Chen char short_option = (char) m_getopt_table[option_idx].val; 1162b7234e40SJohnny Chen 1163b7234e40SJohnny Chen switch (short_option) 1164b7234e40SJohnny Chen { 1165b7234e40SJohnny Chen case 'f': 1166357132ebSGreg Clayton m_filename.assign (option_arg); 1167b7234e40SJohnny Chen break; 1168b7234e40SJohnny Chen 1169b7234e40SJohnny Chen case 'l': 1170b7234e40SJohnny Chen m_line_num = Args::StringToUInt32 (option_arg, 0); 1171b7234e40SJohnny Chen break; 1172b7234e40SJohnny Chen 1173b7234e40SJohnny Chen default: 117486edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 1175b7234e40SJohnny Chen break; 1176b7234e40SJohnny Chen } 1177b7234e40SJohnny Chen 1178b7234e40SJohnny Chen return error; 1179b7234e40SJohnny Chen } 1180b7234e40SJohnny Chen 1181b7234e40SJohnny Chen void 1182f6b8b581SGreg Clayton CommandObjectBreakpointClear::CommandOptions::OptionParsingStarting () 1183b7234e40SJohnny Chen { 1184b7234e40SJohnny Chen m_filename.clear(); 1185b7234e40SJohnny Chen m_line_num = 0; 1186b7234e40SJohnny Chen } 1187b7234e40SJohnny Chen 1188b7234e40SJohnny Chen //------------------------------------------------------------------------- 1189b7234e40SJohnny Chen // CommandObjectBreakpointClear 1190b7234e40SJohnny Chen //------------------------------------------------------------------------- 1191b7234e40SJohnny Chen #pragma mark Clear 1192b7234e40SJohnny Chen 1193b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandObjectBreakpointClear (CommandInterpreter &interpreter) : 1194b7234e40SJohnny Chen CommandObject (interpreter, 1195b7234e40SJohnny Chen "breakpoint clear", 1196b7234e40SJohnny Chen "Clears a breakpoint or set of breakpoints in the executable.", 1197eb0103f2SGreg Clayton "breakpoint clear <cmd-options>"), 1198eb0103f2SGreg Clayton m_options (interpreter) 1199b7234e40SJohnny Chen { 1200b7234e40SJohnny Chen } 1201b7234e40SJohnny Chen 1202b7234e40SJohnny Chen CommandObjectBreakpointClear::~CommandObjectBreakpointClear () 1203b7234e40SJohnny Chen { 1204b7234e40SJohnny Chen } 1205b7234e40SJohnny Chen 1206b7234e40SJohnny Chen Options * 1207b7234e40SJohnny Chen CommandObjectBreakpointClear::GetOptions () 1208b7234e40SJohnny Chen { 1209b7234e40SJohnny Chen return &m_options; 1210b7234e40SJohnny Chen } 1211b7234e40SJohnny Chen 1212b7234e40SJohnny Chen bool 1213b7234e40SJohnny Chen CommandObjectBreakpointClear::Execute 1214b7234e40SJohnny Chen ( 1215b7234e40SJohnny Chen Args& command, 1216b7234e40SJohnny Chen CommandReturnObject &result 1217b7234e40SJohnny Chen ) 1218b7234e40SJohnny Chen { 1219b7234e40SJohnny Chen Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 1220b7234e40SJohnny Chen if (target == NULL) 1221b7234e40SJohnny Chen { 1222b7234e40SJohnny Chen result.AppendError ("Invalid target. No existing target or breakpoints."); 1223b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1224b7234e40SJohnny Chen return false; 1225b7234e40SJohnny Chen } 1226b7234e40SJohnny Chen 1227b7234e40SJohnny Chen // The following are the various types of breakpoints that could be cleared: 1228b7234e40SJohnny Chen // 1). -f -l (clearing breakpoint by source location) 1229b7234e40SJohnny Chen 1230b7234e40SJohnny Chen BreakpointClearType break_type = eClearTypeInvalid; 1231b7234e40SJohnny Chen 1232b7234e40SJohnny Chen if (m_options.m_line_num != 0) 1233b7234e40SJohnny Chen break_type = eClearTypeFileAndLine; 1234b7234e40SJohnny Chen 1235b7234e40SJohnny Chen Mutex::Locker locker; 1236b7234e40SJohnny Chen target->GetBreakpointList().GetListMutex(locker); 1237b7234e40SJohnny Chen 1238b7234e40SJohnny Chen BreakpointList &breakpoints = target->GetBreakpointList(); 1239b7234e40SJohnny Chen size_t num_breakpoints = breakpoints.GetSize(); 1240b7234e40SJohnny Chen 1241b7234e40SJohnny Chen // Early return if there's no breakpoint at all. 1242b7234e40SJohnny Chen if (num_breakpoints == 0) 1243b7234e40SJohnny Chen { 1244b7234e40SJohnny Chen result.AppendError ("Breakpoint clear: No breakpoint cleared."); 1245b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1246b7234e40SJohnny Chen return result.Succeeded(); 1247b7234e40SJohnny Chen } 1248b7234e40SJohnny Chen 1249b7234e40SJohnny Chen // Find matching breakpoints and delete them. 1250b7234e40SJohnny Chen 1251b7234e40SJohnny Chen // First create a copy of all the IDs. 1252b7234e40SJohnny Chen std::vector<break_id_t> BreakIDs; 1253b7234e40SJohnny Chen for (size_t i = 0; i < num_breakpoints; ++i) 1254b7234e40SJohnny Chen BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID()); 1255b7234e40SJohnny Chen 1256b7234e40SJohnny Chen int num_cleared = 0; 1257b7234e40SJohnny Chen StreamString ss; 1258b7234e40SJohnny Chen switch (break_type) 1259b7234e40SJohnny Chen { 1260b7234e40SJohnny Chen case eClearTypeFileAndLine: // Breakpoint by source position 1261b7234e40SJohnny Chen { 1262b7234e40SJohnny Chen const ConstString filename(m_options.m_filename.c_str()); 1263b7234e40SJohnny Chen BreakpointLocationCollection loc_coll; 1264b7234e40SJohnny Chen 1265b7234e40SJohnny Chen for (size_t i = 0; i < num_breakpoints; ++i) 1266b7234e40SJohnny Chen { 1267b7234e40SJohnny Chen Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); 1268b7234e40SJohnny Chen 1269b7234e40SJohnny Chen if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) 1270b7234e40SJohnny Chen { 1271b7234e40SJohnny Chen // If the collection size is 0, it's a full match and we can just remove the breakpoint. 1272b7234e40SJohnny Chen if (loc_coll.GetSize() == 0) 1273b7234e40SJohnny Chen { 1274b7234e40SJohnny Chen bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); 1275b7234e40SJohnny Chen ss.EOL(); 1276b7234e40SJohnny Chen target->RemoveBreakpointByID (bp->GetID()); 1277b7234e40SJohnny Chen ++num_cleared; 1278b7234e40SJohnny Chen } 1279b7234e40SJohnny Chen } 1280b7234e40SJohnny Chen } 1281b7234e40SJohnny Chen } 1282b7234e40SJohnny Chen break; 1283b7234e40SJohnny Chen 1284b7234e40SJohnny Chen default: 1285b7234e40SJohnny Chen break; 1286b7234e40SJohnny Chen } 1287b7234e40SJohnny Chen 1288b7234e40SJohnny Chen if (num_cleared > 0) 1289b7234e40SJohnny Chen { 129085e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 1291b7234e40SJohnny Chen output_stream.Printf ("%d breakpoints cleared:\n", num_cleared); 1292b7234e40SJohnny Chen output_stream << ss.GetData(); 1293b7234e40SJohnny Chen output_stream.EOL(); 1294b7234e40SJohnny Chen result.SetStatus (eReturnStatusSuccessFinishNoResult); 1295b7234e40SJohnny Chen } 1296b7234e40SJohnny Chen else 1297b7234e40SJohnny Chen { 1298b7234e40SJohnny Chen result.AppendError ("Breakpoint clear: No breakpoint cleared."); 1299b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1300b7234e40SJohnny Chen } 1301b7234e40SJohnny Chen 1302b7234e40SJohnny Chen return result.Succeeded(); 1303b7234e40SJohnny Chen } 1304b7234e40SJohnny Chen 1305b7234e40SJohnny Chen //------------------------------------------------------------------------- 130630fdc8d8SChris Lattner // CommandObjectBreakpointDelete 130730fdc8d8SChris Lattner //------------------------------------------------------------------------- 1308ae1c4cf5SJim Ingham #pragma mark Delete 130930fdc8d8SChris Lattner 1310a7015092SGreg Clayton CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) : 1311a7015092SGreg Clayton CommandObject (interpreter, 1312a7015092SGreg Clayton "breakpoint delete", 1313e3d26315SCaroline Tice "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.", 1314e139cf23SCaroline Tice NULL) 131530fdc8d8SChris Lattner { 1316e139cf23SCaroline Tice CommandArgumentEntry arg; 1317de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 1318e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1319e139cf23SCaroline Tice m_arguments.push_back (arg); 132030fdc8d8SChris Lattner } 132130fdc8d8SChris Lattner 132230fdc8d8SChris Lattner 132330fdc8d8SChris Lattner CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete () 132430fdc8d8SChris Lattner { 132530fdc8d8SChris Lattner } 132630fdc8d8SChris Lattner 132730fdc8d8SChris Lattner bool 13286611103cSGreg Clayton CommandObjectBreakpointDelete::Execute 13296611103cSGreg Clayton ( 13306611103cSGreg Clayton Args& args, 13316611103cSGreg Clayton CommandReturnObject &result 13326611103cSGreg Clayton ) 133330fdc8d8SChris Lattner { 1334a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 133530fdc8d8SChris Lattner if (target == NULL) 133630fdc8d8SChris Lattner { 13379068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 133830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 133930fdc8d8SChris Lattner return false; 134030fdc8d8SChris Lattner } 134130fdc8d8SChris Lattner 13421b54c88cSJim Ingham Mutex::Locker locker; 13431b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 13441b54c88cSJim Ingham 134530fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 13461b54c88cSJim Ingham 134730fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 134830fdc8d8SChris Lattner 134930fdc8d8SChris Lattner if (num_breakpoints == 0) 135030fdc8d8SChris Lattner { 135130fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be deleted."); 135230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 135330fdc8d8SChris Lattner return false; 135430fdc8d8SChris Lattner } 135530fdc8d8SChris Lattner 135630fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 135730fdc8d8SChris Lattner { 135836f3b369SJim Ingham if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true)) 135930fdc8d8SChris Lattner { 136036f3b369SJim Ingham result.AppendMessage("Operation cancelled..."); 136130fdc8d8SChris Lattner } 136236f3b369SJim Ingham else 136336f3b369SJim Ingham { 136430fdc8d8SChris Lattner target->RemoveAllBreakpoints (); 1365fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints removed. (%lu breakpoints)\n", num_breakpoints); 136636f3b369SJim Ingham } 136730fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 136830fdc8d8SChris Lattner } 136930fdc8d8SChris Lattner else 137030fdc8d8SChris Lattner { 137130fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 137230fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 137330fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 137430fdc8d8SChris Lattner 137530fdc8d8SChris Lattner if (result.Succeeded()) 137630fdc8d8SChris Lattner { 137730fdc8d8SChris Lattner int delete_count = 0; 137830fdc8d8SChris Lattner int disable_count = 0; 1379c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1380c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 138130fdc8d8SChris Lattner { 138230fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 138330fdc8d8SChris Lattner 138430fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 138530fdc8d8SChris Lattner { 138630fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 138730fdc8d8SChris Lattner { 138830fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 138930fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 139030fdc8d8SChris Lattner // It makes no sense to try to delete individual locations, so we disable them instead. 139130fdc8d8SChris Lattner if (location) 139230fdc8d8SChris Lattner { 139330fdc8d8SChris Lattner location->SetEnabled (false); 139430fdc8d8SChris Lattner ++disable_count; 139530fdc8d8SChris Lattner } 139630fdc8d8SChris Lattner } 139730fdc8d8SChris Lattner else 139830fdc8d8SChris Lattner { 139930fdc8d8SChris Lattner target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID()); 140030fdc8d8SChris Lattner ++delete_count; 140130fdc8d8SChris Lattner } 140230fdc8d8SChris Lattner } 140330fdc8d8SChris Lattner } 140430fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n", 140530fdc8d8SChris Lattner delete_count, disable_count); 140630fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 140730fdc8d8SChris Lattner } 140830fdc8d8SChris Lattner } 140930fdc8d8SChris Lattner return result.Succeeded(); 141030fdc8d8SChris Lattner } 14111b54c88cSJim Ingham 14121b54c88cSJim Ingham //------------------------------------------------------------------------- 1413ae1c4cf5SJim Ingham // CommandObjectBreakpointModify::CommandOptions 14141b54c88cSJim Ingham //------------------------------------------------------------------------- 1415ae1c4cf5SJim Ingham #pragma mark Modify::CommandOptions 14161b54c88cSJim Ingham 1417eb0103f2SGreg Clayton CommandObjectBreakpointModify::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 1418eb0103f2SGreg Clayton Options (interpreter), 1419c982c768SGreg Clayton m_ignore_count (0), 14201b54c88cSJim Ingham m_thread_id(LLDB_INVALID_THREAD_ID), 1421e0a97848SJim Ingham m_thread_id_passed(false), 1422c982c768SGreg Clayton m_thread_index (UINT32_MAX), 1423e0a97848SJim Ingham m_thread_index_passed(false), 14241b54c88cSJim Ingham m_thread_name(), 14251b54c88cSJim Ingham m_queue_name(), 142636f3b369SJim Ingham m_condition (), 1427c982c768SGreg Clayton m_enable_passed (false), 1428c982c768SGreg Clayton m_enable_value (false), 1429c982c768SGreg Clayton m_name_passed (false), 143036f3b369SJim Ingham m_queue_passed (false), 143136f3b369SJim Ingham m_condition_passed (false) 14321b54c88cSJim Ingham { 14331b54c88cSJim Ingham } 14341b54c88cSJim Ingham 1435ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::~CommandOptions () 14361b54c88cSJim Ingham { 14371b54c88cSJim Ingham } 14381b54c88cSJim Ingham 1439e0d378b3SGreg Clayton OptionDefinition 1440ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] = 14411b54c88cSJim Ingham { 1442a0cd2bcaSBill 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." }, 1443a0cd2bcaSBill 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."}, 1444a0cd2bcaSBill 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."}, 1445a0cd2bcaSBill 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."}, 1446a0cd2bcaSBill 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."}, 1447a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."}, 1448a0cd2bcaSBill Wendling { LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, 0, eArgTypeNone, "Enable the breakpoint."}, 1449a0cd2bcaSBill Wendling { LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, 0, eArgTypeNone, "Disable the breakpoint."}, 1450deaab222SCaroline Tice { 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } 14511b54c88cSJim Ingham }; 14521b54c88cSJim Ingham 1453e0d378b3SGreg Clayton const OptionDefinition* 1454ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::GetDefinitions () 14551b54c88cSJim Ingham { 14561b54c88cSJim Ingham return g_option_table; 14571b54c88cSJim Ingham } 14581b54c88cSJim Ingham 14591b54c88cSJim Ingham Error 1460f6b8b581SGreg Clayton CommandObjectBreakpointModify::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 14611b54c88cSJim Ingham { 14621b54c88cSJim Ingham Error error; 14631b54c88cSJim Ingham char short_option = (char) m_getopt_table[option_idx].val; 14641b54c88cSJim Ingham 14651b54c88cSJim Ingham switch (short_option) 14661b54c88cSJim Ingham { 146736f3b369SJim Ingham case 'c': 146836f3b369SJim Ingham if (option_arg != NULL) 1469357132ebSGreg Clayton m_condition.assign (option_arg); 147036f3b369SJim Ingham else 147136f3b369SJim Ingham m_condition.clear(); 147236f3b369SJim Ingham m_condition_passed = true; 147336f3b369SJim Ingham break; 1474ae1c4cf5SJim Ingham case 'd': 1475ae1c4cf5SJim Ingham m_enable_passed = true; 1476ae1c4cf5SJim Ingham m_enable_value = false; 1477ae1c4cf5SJim Ingham break; 1478ae1c4cf5SJim Ingham case 'e': 1479ae1c4cf5SJim Ingham m_enable_passed = true; 1480ae1c4cf5SJim Ingham m_enable_value = true; 1481ae1c4cf5SJim Ingham break; 1482ed8a705cSGreg Clayton case 'i': 14831b54c88cSJim Ingham { 14840292f4a5SJim Ingham m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 1485c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 148686edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); 14871b54c88cSJim Ingham } 1488ae1c4cf5SJim Ingham break; 14891b54c88cSJim Ingham case 't' : 14901b54c88cSJim Ingham { 14910292f4a5SJim Ingham if (option_arg[0] == '\0') 1492e0a97848SJim Ingham { 1493e0a97848SJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 1494e0a97848SJim Ingham m_thread_id_passed = true; 1495e0a97848SJim Ingham } 1496e0a97848SJim Ingham else 1497e0a97848SJim Ingham { 14980292f4a5SJim Ingham m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 14991b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 150086edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); 1501e0a97848SJim Ingham else 1502e0a97848SJim Ingham m_thread_id_passed = true; 1503e0a97848SJim Ingham } 15041b54c88cSJim Ingham } 15051b54c88cSJim Ingham break; 15061b54c88cSJim Ingham case 'T': 1507b2a38a72SJim Ingham if (option_arg != NULL) 1508357132ebSGreg Clayton m_thread_name.assign (option_arg); 1509b2a38a72SJim Ingham else 1510b2a38a72SJim Ingham m_thread_name.clear(); 1511b2a38a72SJim Ingham m_name_passed = true; 15121b54c88cSJim Ingham break; 15131b54c88cSJim Ingham case 'q': 1514b2a38a72SJim Ingham if (option_arg != NULL) 1515357132ebSGreg Clayton m_queue_name.assign (option_arg); 1516b2a38a72SJim Ingham else 1517b2a38a72SJim Ingham m_queue_name.clear(); 1518b2a38a72SJim Ingham m_queue_passed = true; 15191b54c88cSJim Ingham break; 15201b54c88cSJim Ingham case 'x': 15211b54c88cSJim Ingham { 15220292f4a5SJim Ingham if (option_arg[0] == '\n') 1523e0a97848SJim Ingham { 1524e0a97848SJim Ingham m_thread_index = UINT32_MAX; 1525e0a97848SJim Ingham m_thread_index_passed = true; 1526e0a97848SJim Ingham } 1527e0a97848SJim Ingham else 1528e0a97848SJim Ingham { 15290292f4a5SJim Ingham m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0); 1530c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 153186edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); 1532e0a97848SJim Ingham else 1533e0a97848SJim Ingham m_thread_index_passed = true; 1534e0a97848SJim Ingham } 15351b54c88cSJim Ingham } 15361b54c88cSJim Ingham break; 15371b54c88cSJim Ingham default: 153886edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 15391b54c88cSJim Ingham break; 15401b54c88cSJim Ingham } 15411b54c88cSJim Ingham 15421b54c88cSJim Ingham return error; 15431b54c88cSJim Ingham } 15441b54c88cSJim Ingham 15451b54c88cSJim Ingham void 1546f6b8b581SGreg Clayton CommandObjectBreakpointModify::CommandOptions::OptionParsingStarting () 15471b54c88cSJim Ingham { 1548c982c768SGreg Clayton m_ignore_count = 0; 15491b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 1550e0a97848SJim Ingham m_thread_id_passed = false; 1551c982c768SGreg Clayton m_thread_index = UINT32_MAX; 1552e0a97848SJim Ingham m_thread_index_passed = false; 15531b54c88cSJim Ingham m_thread_name.clear(); 15541b54c88cSJim Ingham m_queue_name.clear(); 155536f3b369SJim Ingham m_condition.clear(); 1556ae1c4cf5SJim Ingham m_enable_passed = false; 1557b2a38a72SJim Ingham m_queue_passed = false; 1558b2a38a72SJim Ingham m_name_passed = false; 155936f3b369SJim Ingham m_condition_passed = false; 15601b54c88cSJim Ingham } 15611b54c88cSJim Ingham 15621b54c88cSJim Ingham //------------------------------------------------------------------------- 1563ae1c4cf5SJim Ingham // CommandObjectBreakpointModify 15641b54c88cSJim Ingham //------------------------------------------------------------------------- 1565ae1c4cf5SJim Ingham #pragma mark Modify 15661b54c88cSJim Ingham 1567a7015092SGreg Clayton CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) : 1568a7015092SGreg Clayton CommandObject (interpreter, 1569a7015092SGreg Clayton "breakpoint modify", 1570a571c010SJim Ingham "Modify the options on a breakpoint or set of breakpoints in the executable. " 1571e0a97848SJim Ingham "If no breakpoint is specified, acts on the last created breakpoint. " 1572e0a97848SJim Ingham "With the exception of -e, -d and -i, passing an empty argument clears the modification.", 1573eb0103f2SGreg Clayton NULL), 1574eb0103f2SGreg Clayton m_options (interpreter) 15751b54c88cSJim Ingham { 1576e139cf23SCaroline Tice CommandArgumentEntry arg; 1577de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 1578e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1579e139cf23SCaroline Tice m_arguments.push_back (arg); 15801b54c88cSJim Ingham } 15811b54c88cSJim Ingham 1582ae1c4cf5SJim Ingham CommandObjectBreakpointModify::~CommandObjectBreakpointModify () 15831b54c88cSJim Ingham { 15841b54c88cSJim Ingham } 15851b54c88cSJim Ingham 15861b54c88cSJim Ingham Options * 1587ae1c4cf5SJim Ingham CommandObjectBreakpointModify::GetOptions () 15881b54c88cSJim Ingham { 15891b54c88cSJim Ingham return &m_options; 15901b54c88cSJim Ingham } 15911b54c88cSJim Ingham 15921b54c88cSJim Ingham bool 1593ae1c4cf5SJim Ingham CommandObjectBreakpointModify::Execute 15941b54c88cSJim Ingham ( 15951b54c88cSJim Ingham Args& command, 15961b54c88cSJim Ingham CommandReturnObject &result 15971b54c88cSJim Ingham ) 15981b54c88cSJim Ingham { 1599a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 16001b54c88cSJim Ingham if (target == NULL) 16011b54c88cSJim Ingham { 16029068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 16031b54c88cSJim Ingham result.SetStatus (eReturnStatusFailed); 16041b54c88cSJim Ingham return false; 16051b54c88cSJim Ingham } 16061b54c88cSJim Ingham 16071b54c88cSJim Ingham Mutex::Locker locker; 16081b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 16091b54c88cSJim Ingham 16101b54c88cSJim Ingham BreakpointIDList valid_bp_ids; 16111b54c88cSJim Ingham 16121b54c88cSJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 16131b54c88cSJim Ingham 16141b54c88cSJim Ingham if (result.Succeeded()) 16151b54c88cSJim Ingham { 1616c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1617c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 16181b54c88cSJim Ingham { 16191b54c88cSJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 16201b54c88cSJim Ingham 16211b54c88cSJim Ingham if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 16221b54c88cSJim Ingham { 16231b54c88cSJim Ingham Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 16241b54c88cSJim Ingham if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 16251b54c88cSJim Ingham { 16261b54c88cSJim Ingham BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get(); 16271b54c88cSJim Ingham if (location) 16281b54c88cSJim Ingham { 1629e0a97848SJim Ingham if (m_options.m_thread_id_passed) 16301b54c88cSJim Ingham location->SetThreadID (m_options.m_thread_id); 16311b54c88cSJim Ingham 1632e0a97848SJim Ingham if (m_options.m_thread_index_passed) 1633e6bc6cb9SJim Ingham location->SetThreadIndex(m_options.m_thread_index); 16341b54c88cSJim Ingham 1635b2a38a72SJim Ingham if (m_options.m_name_passed) 1636e6bc6cb9SJim Ingham location->SetThreadName(m_options.m_thread_name.c_str()); 16371b54c88cSJim Ingham 1638b2a38a72SJim Ingham if (m_options.m_queue_passed) 1639e6bc6cb9SJim Ingham location->SetQueueName(m_options.m_queue_name.c_str()); 16401b54c88cSJim Ingham 1641c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 1642e6bc6cb9SJim Ingham location->SetIgnoreCount(m_options.m_ignore_count); 1643ae1c4cf5SJim Ingham 1644ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1645ae1c4cf5SJim Ingham location->SetEnabled (m_options.m_enable_value); 164636f3b369SJim Ingham 164736f3b369SJim Ingham if (m_options.m_condition_passed) 164836f3b369SJim Ingham location->SetCondition (m_options.m_condition.c_str()); 16491b54c88cSJim Ingham } 16501b54c88cSJim Ingham } 16511b54c88cSJim Ingham else 16521b54c88cSJim Ingham { 1653e0a97848SJim Ingham if (m_options.m_thread_id_passed) 16541b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 16551b54c88cSJim Ingham 1656e0a97848SJim Ingham if (m_options.m_thread_index_passed) 1657e6bc6cb9SJim Ingham bp->SetThreadIndex(m_options.m_thread_index); 16581b54c88cSJim Ingham 1659b2a38a72SJim Ingham if (m_options.m_name_passed) 1660e6bc6cb9SJim Ingham bp->SetThreadName(m_options.m_thread_name.c_str()); 16611b54c88cSJim Ingham 1662b2a38a72SJim Ingham if (m_options.m_queue_passed) 1663e6bc6cb9SJim Ingham bp->SetQueueName(m_options.m_queue_name.c_str()); 16641b54c88cSJim Ingham 1665c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 1666e6bc6cb9SJim Ingham bp->SetIgnoreCount(m_options.m_ignore_count); 1667ae1c4cf5SJim Ingham 1668ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1669ae1c4cf5SJim Ingham bp->SetEnabled (m_options.m_enable_value); 1670ae1c4cf5SJim Ingham 167136f3b369SJim Ingham if (m_options.m_condition_passed) 167236f3b369SJim Ingham bp->SetCondition (m_options.m_condition.c_str()); 16731b54c88cSJim Ingham } 16741b54c88cSJim Ingham } 16751b54c88cSJim Ingham } 16761b54c88cSJim Ingham } 16771b54c88cSJim Ingham 16781b54c88cSJim Ingham return result.Succeeded(); 16791b54c88cSJim Ingham } 16801b54c88cSJim Ingham 16811b54c88cSJim Ingham 1682