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), 69fab10e89SJim Ingham m_language (eLanguageTypeUnknown) 7030fdc8d8SChris Lattner { 7130fdc8d8SChris Lattner } 7230fdc8d8SChris Lattner 7330fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::~CommandOptions () 7430fdc8d8SChris Lattner { 7530fdc8d8SChris Lattner } 7630fdc8d8SChris Lattner 77*6943e7c5SJohnny Chen // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to 78*6943e7c5SJohnny Chen // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately. 794ab2e6beSJohnny Chen #define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 ) 804ab2e6beSJohnny Chen #define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 ) 8187df91b8SJim Ingham 82e0d378b3SGreg Clayton OptionDefinition 8330fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::g_option_table[] = 8430fdc8d8SChris Lattner { 85fab10e89SJim Ingham { LLDB_OPT_NOT_10, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName, 8664cc29cbSJim Ingham "Set the breakpoint only in this shared library. " 8764cc29cbSJim Ingham "Can repeat this option multiple times to specify multiple shared libraries."}, 888651121cSJim Ingham 89deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount, 90deaab222SCaroline Tice "Set the number of times this breakpoint is skipped before stopping." }, 911b54c88cSJim Ingham 92a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex, 93ed8a705cSGreg Clayton "The breakpoint stops only for the thread whose index matches this argument."}, 941b54c88cSJim Ingham 95a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID, 961b54c88cSJim Ingham "The breakpoint stops only for the thread whose TID matches this argument."}, 971b54c88cSJim Ingham 98a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName, 991b54c88cSJim Ingham "The breakpoint stops only for the thread whose thread name matches this argument."}, 1001b54c88cSJim Ingham 101a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName, 1021b54c88cSJim Ingham "The breakpoint stops only for threads in the queue whose name is given by this argument."}, 1031b54c88cSJim Ingham 10487df91b8SJim Ingham { LLDB_OPT_FILE, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, 10587df91b8SJim Ingham "Specifies the source file in which to set this breakpoint."}, 10630fdc8d8SChris Lattner 107deaab222SCaroline Tice { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, 10887df91b8SJim Ingham "Specifies the line number on which to set this breakpoint."}, 10930fdc8d8SChris Lattner 11030fdc8d8SChris Lattner // Comment out this option for the moment, as we don't actually use it, but will in the future. 11130fdc8d8SChris Lattner // This way users won't see it, but the infrastructure is left in place. 11230fdc8d8SChris Lattner // { 0, false, "column", 'c', required_argument, NULL, "<column>", 11330fdc8d8SChris Lattner // "Set the breakpoint by source location at this particular column."}, 11430fdc8d8SChris Lattner 115deaab222SCaroline Tice { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, 11630fdc8d8SChris Lattner "Set the breakpoint by address, at the specified address."}, 11730fdc8d8SChris Lattner 118deaab222SCaroline Tice { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, 11964cc29cbSJim Ingham "Set the breakpoint by function name. Can be repeated multiple times to make one breakpoint for multiple snames" }, 12030fdc8d8SChris Lattner 121deaab222SCaroline Tice { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName, 12264cc29cbSJim Ingham "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and " 12364cc29cbSJim Ingham "for Objective C this means a full function prototype with class and selector. " 12464cc29cbSJim Ingham "Can be repeated multiple times to make one breakpoint for multiple names." }, 1250c5cd90dSGreg Clayton 126deaab222SCaroline Tice { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector, 12764cc29cbSJim Ingham "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." }, 1280c5cd90dSGreg Clayton 129deaab222SCaroline Tice { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod, 13064cc29cbSJim Ingham "Set the breakpoint by C++ method names. Can be repeated multiple times to make one breakpoint for multiple methods." }, 1310c5cd90dSGreg Clayton 132deaab222SCaroline Tice { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression, 13330fdc8d8SChris Lattner "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." }, 13430fdc8d8SChris Lattner 135e02b8504SGreg Clayton { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, 13664cc29cbSJim Ingham "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). " 13764cc29cbSJim Ingham "Can be repeated multiple times to make one breakpoint for multiple symbols." }, 138e02b8504SGreg Clayton 139969795f1SJim Ingham { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', required_argument, NULL, 0, eArgTypeRegularExpression, 140969795f1SJim Ingham "Set the breakpoint specifying a regular expression to match a pattern in the source text in a given source file." }, 141969795f1SJim Ingham 142fab10e89SJim Ingham { LLDB_OPT_SET_10, true, "language-exception", 'E', required_argument, NULL, 0, eArgTypeLanguage, 143fab10e89SJim Ingham "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" }, 144fab10e89SJim Ingham 145fab10e89SJim Ingham { LLDB_OPT_SET_10, false, "on-throw", 'w', required_argument, NULL, 0, eArgTypeBoolean, 146fab10e89SJim Ingham "Set the breakpoint on exception throW." }, 147fab10e89SJim Ingham 148fab10e89SJim Ingham { LLDB_OPT_SET_10, false, "on-catch", 'h', required_argument, NULL, 0, eArgTypeBoolean, 149fab10e89SJim Ingham "Set the breakpoint on exception catcH." }, 150969795f1SJim Ingham 151deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 15230fdc8d8SChris Lattner }; 15330fdc8d8SChris Lattner 154e0d378b3SGreg Clayton const OptionDefinition* 15530fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::GetDefinitions () 15630fdc8d8SChris Lattner { 15730fdc8d8SChris Lattner return g_option_table; 15830fdc8d8SChris Lattner } 15930fdc8d8SChris Lattner 16030fdc8d8SChris Lattner Error 161f6b8b581SGreg Clayton CommandObjectBreakpointSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 16230fdc8d8SChris Lattner { 16330fdc8d8SChris Lattner Error error; 16430fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 16530fdc8d8SChris Lattner 16630fdc8d8SChris Lattner switch (short_option) 16730fdc8d8SChris Lattner { 16830fdc8d8SChris Lattner case 'a': 1690292f4a5SJim Ingham m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0); 17030fdc8d8SChris Lattner if (m_load_addr == LLDB_INVALID_ADDRESS) 1710292f4a5SJim Ingham m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16); 17230fdc8d8SChris Lattner 17330fdc8d8SChris Lattner if (m_load_addr == LLDB_INVALID_ADDRESS) 17486edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg); 17530fdc8d8SChris Lattner break; 17630fdc8d8SChris Lattner 17730fdc8d8SChris Lattner case 'c': 17830fdc8d8SChris Lattner m_column = Args::StringToUInt32 (option_arg, 0); 17930fdc8d8SChris Lattner break; 1800c5cd90dSGreg Clayton 18130fdc8d8SChris Lattner case 'f': 18287df91b8SJim Ingham m_filenames.AppendIfUnique (FileSpec(option_arg, false)); 18330fdc8d8SChris Lattner break; 1840c5cd90dSGreg Clayton 18530fdc8d8SChris Lattner case 'l': 18630fdc8d8SChris Lattner m_line_num = Args::StringToUInt32 (option_arg, 0); 18730fdc8d8SChris Lattner break; 1880c5cd90dSGreg Clayton 189e02b8504SGreg Clayton case 'b': 190fab10e89SJim Ingham m_func_names.push_back (option_arg); 1910c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeBase; 1920c5cd90dSGreg Clayton break; 1930c5cd90dSGreg Clayton 194e02b8504SGreg Clayton case 'n': 195fab10e89SJim Ingham m_func_names.push_back (option_arg); 196e02b8504SGreg Clayton m_func_name_type_mask |= eFunctionNameTypeAuto; 197e02b8504SGreg Clayton break; 198e02b8504SGreg Clayton 1990c5cd90dSGreg Clayton case 'F': 200fab10e89SJim Ingham m_func_names.push_back (option_arg); 2010c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeFull; 2020c5cd90dSGreg Clayton break; 2030c5cd90dSGreg Clayton 2040c5cd90dSGreg Clayton case 'S': 205fab10e89SJim Ingham m_func_names.push_back (option_arg); 2060c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeSelector; 2070c5cd90dSGreg Clayton break; 2080c5cd90dSGreg Clayton 2092561aa61SJim Ingham case 'M': 210fab10e89SJim Ingham m_func_names.push_back (option_arg); 2110c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeMethod; 2120c5cd90dSGreg Clayton break; 2130c5cd90dSGreg Clayton 214969795f1SJim Ingham case 'p': 215969795f1SJim Ingham m_source_text_regexp.assign (option_arg); 216969795f1SJim Ingham break; 217969795f1SJim Ingham 21830fdc8d8SChris Lattner case 'r': 219357132ebSGreg Clayton m_func_regexp.assign (option_arg); 22030fdc8d8SChris Lattner break; 2210c5cd90dSGreg Clayton 22230fdc8d8SChris Lattner case 's': 22330fdc8d8SChris Lattner { 22487df91b8SJim Ingham m_modules.AppendIfUnique (FileSpec (option_arg, false)); 22530fdc8d8SChris Lattner break; 22630fdc8d8SChris Lattner } 227ed8a705cSGreg Clayton case 'i': 2281b54c88cSJim Ingham { 2290292f4a5SJim Ingham m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 230c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 23186edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); 2321b54c88cSJim Ingham } 233ae1c4cf5SJim Ingham break; 2341b54c88cSJim Ingham case 't' : 2351b54c88cSJim Ingham { 2360292f4a5SJim Ingham m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 2371b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 23886edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); 2391b54c88cSJim Ingham } 2401b54c88cSJim Ingham break; 2411b54c88cSJim Ingham case 'T': 242357132ebSGreg Clayton m_thread_name.assign (option_arg); 2431b54c88cSJim Ingham break; 2441b54c88cSJim Ingham case 'q': 245357132ebSGreg Clayton m_queue_name.assign (option_arg); 2461b54c88cSJim Ingham break; 2471b54c88cSJim Ingham case 'x': 2481b54c88cSJim Ingham { 2490292f4a5SJim Ingham m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 250c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 25186edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); 2521b54c88cSJim Ingham 2531b54c88cSJim Ingham } 2541b54c88cSJim Ingham break; 255fab10e89SJim Ingham case 'E': 256fab10e89SJim Ingham { 257fab10e89SJim Ingham LanguageType language = LanguageRuntime::GetLanguageTypeFromString (option_arg); 258fab10e89SJim Ingham 259fab10e89SJim Ingham switch (language) 260fab10e89SJim Ingham { 261fab10e89SJim Ingham case eLanguageTypeC89: 262fab10e89SJim Ingham case eLanguageTypeC: 263fab10e89SJim Ingham case eLanguageTypeC99: 264fab10e89SJim Ingham m_language = eLanguageTypeC; 265fab10e89SJim Ingham break; 266fab10e89SJim Ingham case eLanguageTypeC_plus_plus: 267fab10e89SJim Ingham m_language = eLanguageTypeC_plus_plus; 268fab10e89SJim Ingham break; 269fab10e89SJim Ingham case eLanguageTypeObjC: 270fab10e89SJim Ingham m_language = eLanguageTypeObjC; 271fab10e89SJim Ingham break; 272fab10e89SJim Ingham case eLanguageTypeObjC_plus_plus: 273fab10e89SJim Ingham error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c"); 274fab10e89SJim Ingham break; 275fab10e89SJim Ingham case eLanguageTypeUnknown: 276fab10e89SJim Ingham error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg); 277fab10e89SJim Ingham break; 278fab10e89SJim Ingham default: 279fab10e89SJim Ingham error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg); 280fab10e89SJim Ingham } 281fab10e89SJim Ingham } 282fab10e89SJim Ingham break; 283fab10e89SJim Ingham case 'w': 284fab10e89SJim Ingham { 285fab10e89SJim Ingham bool success; 286fab10e89SJim Ingham m_throw_bp = Args::StringToBoolean (option_arg, true, &success); 287fab10e89SJim Ingham if (!success) 288fab10e89SJim Ingham error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg); 289fab10e89SJim Ingham } 290fab10e89SJim Ingham break; 291fab10e89SJim Ingham case 'h': 292fab10e89SJim Ingham { 293fab10e89SJim Ingham bool success; 294fab10e89SJim Ingham m_catch_bp = Args::StringToBoolean (option_arg, true, &success); 295fab10e89SJim Ingham if (!success) 296fab10e89SJim Ingham error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg); 297fab10e89SJim Ingham } 298fab10e89SJim Ingham break; 29930fdc8d8SChris Lattner default: 30086edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 30130fdc8d8SChris Lattner break; 30230fdc8d8SChris Lattner } 30330fdc8d8SChris Lattner 30430fdc8d8SChris Lattner return error; 30530fdc8d8SChris Lattner } 30630fdc8d8SChris Lattner 30730fdc8d8SChris Lattner void 308f6b8b581SGreg Clayton CommandObjectBreakpointSet::CommandOptions::OptionParsingStarting () 30930fdc8d8SChris Lattner { 31087df91b8SJim Ingham m_filenames.Clear(); 31130fdc8d8SChris Lattner m_line_num = 0; 31230fdc8d8SChris Lattner m_column = 0; 313fab10e89SJim Ingham m_func_names.clear(); 3140c5cd90dSGreg Clayton m_func_name_type_mask = 0; 31530fdc8d8SChris Lattner m_func_regexp.clear(); 31630fdc8d8SChris Lattner m_load_addr = LLDB_INVALID_ADDRESS; 31787df91b8SJim Ingham m_modules.Clear(); 318c982c768SGreg Clayton m_ignore_count = 0; 3191b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 320c982c768SGreg Clayton m_thread_index = UINT32_MAX; 3211b54c88cSJim Ingham m_thread_name.clear(); 3221b54c88cSJim Ingham m_queue_name.clear(); 323fab10e89SJim Ingham m_language = eLanguageTypeUnknown; 324fab10e89SJim Ingham m_catch_bp = false; 325fab10e89SJim Ingham m_throw_bp = true; 32630fdc8d8SChris Lattner } 32730fdc8d8SChris Lattner 32830fdc8d8SChris Lattner //------------------------------------------------------------------------- 32930fdc8d8SChris Lattner // CommandObjectBreakpointSet 33030fdc8d8SChris Lattner //------------------------------------------------------------------------- 331ae1c4cf5SJim Ingham #pragma mark Set 33230fdc8d8SChris Lattner 333a7015092SGreg Clayton CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) : 334a7015092SGreg Clayton CommandObject (interpreter, 335a7015092SGreg Clayton "breakpoint set", 336a7015092SGreg Clayton "Sets a breakpoint or set of breakpoints in the executable.", 337eb0103f2SGreg Clayton "breakpoint set <cmd-options>"), 338eb0103f2SGreg Clayton m_options (interpreter) 33930fdc8d8SChris Lattner { 34030fdc8d8SChris Lattner } 34130fdc8d8SChris Lattner 34230fdc8d8SChris Lattner CommandObjectBreakpointSet::~CommandObjectBreakpointSet () 34330fdc8d8SChris Lattner { 34430fdc8d8SChris Lattner } 34530fdc8d8SChris Lattner 34630fdc8d8SChris Lattner Options * 34730fdc8d8SChris Lattner CommandObjectBreakpointSet::GetOptions () 34830fdc8d8SChris Lattner { 34930fdc8d8SChris Lattner return &m_options; 35030fdc8d8SChris Lattner } 35130fdc8d8SChris Lattner 35230fdc8d8SChris Lattner bool 35387df91b8SJim Ingham CommandObjectBreakpointSet::GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result) 354969795f1SJim Ingham { 355969795f1SJim Ingham uint32_t default_line; 356969795f1SJim Ingham // First use the Source Manager's default file. 357969795f1SJim Ingham // Then use the current stack frame's file. 358969795f1SJim Ingham if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) 359969795f1SJim Ingham { 360c14ee32dSGreg Clayton StackFrame *cur_frame = m_interpreter.GetExecutionContext().GetFramePtr(); 361969795f1SJim Ingham if (cur_frame == NULL) 362969795f1SJim Ingham { 36387df91b8SJim Ingham result.AppendError ("No selected frame to use to find the default file."); 364969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 365969795f1SJim Ingham return false; 366969795f1SJim Ingham } 367969795f1SJim Ingham else if (!cur_frame->HasDebugInformation()) 368969795f1SJim Ingham { 36987df91b8SJim Ingham result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info."); 370969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 371969795f1SJim Ingham return false; 372969795f1SJim Ingham } 373969795f1SJim Ingham else 374969795f1SJim Ingham { 375969795f1SJim Ingham const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry); 376969795f1SJim Ingham if (sc.line_entry.file) 377969795f1SJim Ingham { 378969795f1SJim Ingham file = sc.line_entry.file; 379969795f1SJim Ingham } 380969795f1SJim Ingham else 381969795f1SJim Ingham { 38287df91b8SJim Ingham result.AppendError ("Can't find the file for the selected frame to use as the default file."); 383969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 384969795f1SJim Ingham return false; 385969795f1SJim Ingham } 386969795f1SJim Ingham } 387969795f1SJim Ingham } 388969795f1SJim Ingham return true; 389969795f1SJim Ingham } 390969795f1SJim Ingham 391969795f1SJim Ingham bool 39230fdc8d8SChris Lattner CommandObjectBreakpointSet::Execute 39330fdc8d8SChris Lattner ( 39430fdc8d8SChris Lattner Args& command, 39530fdc8d8SChris Lattner CommandReturnObject &result 39630fdc8d8SChris Lattner ) 39730fdc8d8SChris Lattner { 398a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 39930fdc8d8SChris Lattner if (target == NULL) 40030fdc8d8SChris Lattner { 401effe5c95SGreg Clayton result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command)."); 40230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 40330fdc8d8SChris Lattner return false; 40430fdc8d8SChris Lattner } 40530fdc8d8SChris Lattner 40630fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 40730fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 40830fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 40930fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 41030fdc8d8SChris Lattner // 4). -r [-s -g] (setting breakpoint by function name regular expression) 411969795f1SJim Ingham // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text) 412fab10e89SJim Ingham // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.) 41330fdc8d8SChris Lattner 41430fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 41530fdc8d8SChris Lattner 41630fdc8d8SChris Lattner if (m_options.m_line_num != 0) 41730fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 41830fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 41930fdc8d8SChris Lattner break_type = eSetTypeAddress; 420fab10e89SJim Ingham else if (!m_options.m_func_names.empty()) 42130fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 42230fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 42330fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 424969795f1SJim Ingham else if (!m_options.m_source_text_regexp.empty()) 425969795f1SJim Ingham break_type = eSetTypeSourceRegexp; 426fab10e89SJim Ingham else if (m_options.m_language != eLanguageTypeUnknown) 427fab10e89SJim Ingham break_type = eSetTypeException; 42830fdc8d8SChris Lattner 42930fdc8d8SChris Lattner Breakpoint *bp = NULL; 430274060b6SGreg Clayton FileSpec module_spec; 43130fdc8d8SChris Lattner bool use_module = false; 43287df91b8SJim Ingham int num_modules = m_options.m_modules.GetSize(); 433969795f1SJim Ingham 43430fdc8d8SChris Lattner if ((num_modules > 0) && (break_type != eSetTypeAddress)) 43530fdc8d8SChris Lattner use_module = true; 43630fdc8d8SChris Lattner 43730fdc8d8SChris Lattner switch (break_type) 43830fdc8d8SChris Lattner { 43930fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 44030fdc8d8SChris Lattner { 44130fdc8d8SChris Lattner FileSpec file; 44287df91b8SJim Ingham uint32_t num_files = m_options.m_filenames.GetSize(); 44387df91b8SJim Ingham if (num_files == 0) 44487df91b8SJim Ingham { 44587df91b8SJim Ingham if (!GetDefaultFile (target, file, result)) 44687df91b8SJim Ingham { 44787df91b8SJim Ingham result.AppendError("No file supplied and no default file available."); 44887df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 44987df91b8SJim Ingham return false; 45087df91b8SJim Ingham } 45187df91b8SJim Ingham } 45287df91b8SJim Ingham else if (num_files > 1) 45387df91b8SJim Ingham { 45487df91b8SJim Ingham result.AppendError("Only one file at a time is allowed for file and line breakpoints."); 45587df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 45687df91b8SJim Ingham return false; 45787df91b8SJim Ingham } 45887df91b8SJim Ingham else 45987df91b8SJim Ingham file = m_options.m_filenames.GetFileSpecAtIndex(0); 46030fdc8d8SChris Lattner 46187df91b8SJim Ingham bp = target->CreateBreakpoint (&(m_options.m_modules), 46230fdc8d8SChris Lattner file, 46330fdc8d8SChris Lattner m_options.m_line_num, 4642856d462SGreg Clayton m_options.m_check_inlines).get(); 46530fdc8d8SChris Lattner } 46630fdc8d8SChris Lattner break; 4676eee5aa0SGreg Clayton 46830fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 46930fdc8d8SChris Lattner bp = target->CreateBreakpoint (m_options.m_load_addr, false).get(); 47030fdc8d8SChris Lattner break; 4710c5cd90dSGreg Clayton 47230fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 4730c5cd90dSGreg Clayton { 4740c5cd90dSGreg Clayton uint32_t name_type_mask = m_options.m_func_name_type_mask; 4750c5cd90dSGreg Clayton 4760c5cd90dSGreg Clayton if (name_type_mask == 0) 477e02b8504SGreg Clayton name_type_mask = eFunctionNameTypeAuto; 4780c5cd90dSGreg Clayton 47987df91b8SJim Ingham bp = target->CreateBreakpoint (&(m_options.m_modules), 48087df91b8SJim Ingham &(m_options.m_filenames), 481fab10e89SJim Ingham m_options.m_func_names, 482274060b6SGreg Clayton name_type_mask, 483274060b6SGreg Clayton Breakpoint::Exact).get(); 4840c5cd90dSGreg Clayton } 48530fdc8d8SChris Lattner break; 4860c5cd90dSGreg Clayton 48730fdc8d8SChris Lattner case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name 48830fdc8d8SChris Lattner { 48930fdc8d8SChris Lattner RegularExpression regexp(m_options.m_func_regexp.c_str()); 490969795f1SJim Ingham if (!regexp.IsValid()) 49130fdc8d8SChris Lattner { 492969795f1SJim Ingham char err_str[1024]; 493969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 494969795f1SJim Ingham result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"", 495969795f1SJim Ingham err_str); 49630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 497969795f1SJim Ingham return false; 49830fdc8d8SChris Lattner } 49987df91b8SJim Ingham 50087df91b8SJim Ingham bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules), &(m_options.m_filenames), regexp).get(); 50130fdc8d8SChris Lattner } 50230fdc8d8SChris Lattner break; 503969795f1SJim Ingham case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. 504969795f1SJim Ingham { 50587df91b8SJim Ingham int num_files = m_options.m_filenames.GetSize(); 50687df91b8SJim Ingham 50787df91b8SJim Ingham if (num_files == 0) 50887df91b8SJim Ingham { 509969795f1SJim Ingham FileSpec file; 51087df91b8SJim Ingham if (!GetDefaultFile (target, file, result)) 51187df91b8SJim Ingham { 51287df91b8SJim Ingham result.AppendError ("No files provided and could not find default file."); 51387df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 51487df91b8SJim Ingham return false; 51587df91b8SJim Ingham } 51687df91b8SJim Ingham else 51787df91b8SJim Ingham { 51887df91b8SJim Ingham m_options.m_filenames.Append (file); 51987df91b8SJim Ingham } 52087df91b8SJim Ingham } 5210c5cd90dSGreg Clayton 522969795f1SJim Ingham RegularExpression regexp(m_options.m_source_text_regexp.c_str()); 523969795f1SJim Ingham if (!regexp.IsValid()) 524969795f1SJim Ingham { 525969795f1SJim Ingham char err_str[1024]; 526969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 527969795f1SJim Ingham result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"", 528969795f1SJim Ingham err_str); 529969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 530969795f1SJim Ingham return false; 531969795f1SJim Ingham } 53287df91b8SJim Ingham bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules), &(m_options.m_filenames), regexp).get(); 533969795f1SJim Ingham } 534969795f1SJim Ingham break; 535fab10e89SJim Ingham case eSetTypeException: 536fab10e89SJim Ingham { 537fab10e89SJim Ingham bp = target->CreateExceptionBreakpoint (m_options.m_language, m_options.m_catch_bp, m_options.m_throw_bp).get(); 538fab10e89SJim Ingham } 539fab10e89SJim Ingham break; 54030fdc8d8SChris Lattner default: 54130fdc8d8SChris Lattner break; 54230fdc8d8SChris Lattner } 54330fdc8d8SChris Lattner 5441b54c88cSJim Ingham // Now set the various options that were passed in: 5451b54c88cSJim Ingham if (bp) 5461b54c88cSJim Ingham { 5471b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 5481b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 5491b54c88cSJim Ingham 550c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 5511b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 5521b54c88cSJim Ingham 5531b54c88cSJim Ingham if (!m_options.m_thread_name.empty()) 5541b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 5551b54c88cSJim Ingham 5561b54c88cSJim Ingham if (!m_options.m_queue_name.empty()) 5571b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 5581b54c88cSJim Ingham 559c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 5601b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 5611b54c88cSJim Ingham } 5621b54c88cSJim Ingham 563969795f1SJim Ingham if (bp) 56430fdc8d8SChris Lattner { 56585e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 56630fdc8d8SChris Lattner output_stream.Printf ("Breakpoint created: "); 56730fdc8d8SChris Lattner bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); 56830fdc8d8SChris Lattner output_stream.EOL(); 569fab10e89SJim Ingham // Don't print out this warning for exception breakpoints. They can get set before the target 570fab10e89SJim Ingham // is set, but we won't know how to actually set the breakpoint till we run. 571fab10e89SJim Ingham if (bp->GetNumLocations() == 0 && break_type != eSetTypeException) 572be484f41SCaroline Tice output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n"); 57330fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 57430fdc8d8SChris Lattner } 57530fdc8d8SChris Lattner else if (!bp) 57630fdc8d8SChris Lattner { 57730fdc8d8SChris Lattner result.AppendError ("Breakpoint creation failed: No breakpoint created."); 57830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 57930fdc8d8SChris Lattner } 58030fdc8d8SChris Lattner 58130fdc8d8SChris Lattner return result.Succeeded(); 58230fdc8d8SChris Lattner } 58330fdc8d8SChris Lattner 58430fdc8d8SChris Lattner //------------------------------------------------------------------------- 58530fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 58630fdc8d8SChris Lattner //------------------------------------------------------------------------- 587ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 58830fdc8d8SChris Lattner 5896611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) : 590a7015092SGreg Clayton CommandObjectMultiword (interpreter, 591a7015092SGreg Clayton "breakpoint", 59246fbc60fSJim Ingham "A set of commands for operating on breakpoints. Also see _regexp-break.", 59330fdc8d8SChris Lattner "breakpoint <command> [<command-options>]") 59430fdc8d8SChris Lattner { 59530fdc8d8SChris Lattner bool status; 59630fdc8d8SChris Lattner 597a7015092SGreg Clayton CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter)); 598a7015092SGreg Clayton CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter)); 599a7015092SGreg Clayton CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter)); 600b7234e40SJohnny Chen CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter)); 601b7234e40SJohnny Chen CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter)); 602a7015092SGreg Clayton CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter)); 60330fdc8d8SChris Lattner CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter)); 604a7015092SGreg Clayton CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter)); 60530fdc8d8SChris Lattner 606b7234e40SJohnny Chen list_command_object->SetCommandName ("breakpoint list"); 60730fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 60830fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 609b7234e40SJohnny Chen clear_command_object->SetCommandName("breakpoint clear"); 610b7234e40SJohnny Chen delete_command_object->SetCommandName("breakpoint delete"); 611ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 612b7234e40SJohnny Chen command_command_object->SetCommandName ("breakpoint command"); 613b7234e40SJohnny Chen modify_command_object->SetCommandName ("breakpoint modify"); 61430fdc8d8SChris Lattner 615a7015092SGreg Clayton status = LoadSubCommand ("list", list_command_object); 616a7015092SGreg Clayton status = LoadSubCommand ("enable", enable_command_object); 617a7015092SGreg Clayton status = LoadSubCommand ("disable", disable_command_object); 618b7234e40SJohnny Chen status = LoadSubCommand ("clear", clear_command_object); 619a7015092SGreg Clayton status = LoadSubCommand ("delete", delete_command_object); 620a7015092SGreg Clayton status = LoadSubCommand ("set", set_command_object); 621a7015092SGreg Clayton status = LoadSubCommand ("command", command_command_object); 622a7015092SGreg Clayton status = LoadSubCommand ("modify", modify_command_object); 62330fdc8d8SChris Lattner } 62430fdc8d8SChris Lattner 62530fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint () 62630fdc8d8SChris Lattner { 62730fdc8d8SChris Lattner } 62830fdc8d8SChris Lattner 62930fdc8d8SChris Lattner void 63030fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result, 63130fdc8d8SChris Lattner BreakpointIDList *valid_ids) 63230fdc8d8SChris Lattner { 63330fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 63430fdc8d8SChris Lattner // 2). the full breakpoint & location canonical representation 63530fdc8d8SChris Lattner // 3). the word "to" or a hyphen, representing a range (in which case there 63630fdc8d8SChris Lattner // had *better* be an entry both before & after of one of the first two types. 63736f3b369SJim Ingham // If args is empty, we will use the last created breakpoint (if there is one.) 63830fdc8d8SChris Lattner 63930fdc8d8SChris Lattner Args temp_args; 64030fdc8d8SChris Lattner 64136f3b369SJim Ingham if (args.GetArgumentCount() == 0) 64236f3b369SJim Ingham { 6434d122c40SGreg Clayton if (target->GetLastCreatedBreakpoint()) 64436f3b369SJim Ingham { 64536f3b369SJim Ingham valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); 64636f3b369SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 64736f3b369SJim Ingham } 64836f3b369SJim Ingham else 64936f3b369SJim Ingham { 65036f3b369SJim Ingham result.AppendError("No breakpoint specified and no last created breakpoint."); 65136f3b369SJim Ingham result.SetStatus (eReturnStatusFailed); 65236f3b369SJim Ingham } 65336f3b369SJim Ingham return; 65436f3b369SJim Ingham } 65536f3b369SJim Ingham 65630fdc8d8SChris Lattner // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to 65730fdc8d8SChris Lattner // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for 65830fdc8d8SChris Lattner // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS. 65930fdc8d8SChris Lattner 66030fdc8d8SChris Lattner BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args); 66130fdc8d8SChris Lattner 66230fdc8d8SChris Lattner // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList: 66330fdc8d8SChris Lattner 664c982c768SGreg Clayton valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result); 66530fdc8d8SChris Lattner 66630fdc8d8SChris Lattner // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs 66730fdc8d8SChris Lattner // and put into valid_ids. 66830fdc8d8SChris Lattner 66930fdc8d8SChris Lattner if (result.Succeeded()) 67030fdc8d8SChris Lattner { 67130fdc8d8SChris Lattner // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list 67230fdc8d8SChris Lattner // of breakpoint id's and verify that they correspond to valid/currently set breakpoints. 67330fdc8d8SChris Lattner 674c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 675c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 67630fdc8d8SChris Lattner { 67730fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i); 67830fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 67930fdc8d8SChris Lattner if (breakpoint != NULL) 68030fdc8d8SChris Lattner { 68130fdc8d8SChris Lattner int num_locations = breakpoint->GetNumLocations(); 68230fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() > num_locations) 68330fdc8d8SChris Lattner { 68430fdc8d8SChris Lattner StreamString id_str; 685c982c768SGreg Clayton BreakpointID::GetCanonicalReference (&id_str, 686c982c768SGreg Clayton cur_bp_id.GetBreakpointID(), 68730fdc8d8SChris Lattner cur_bp_id.GetLocationID()); 688c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 68930fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n", 69030fdc8d8SChris Lattner id_str.GetData()); 69130fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 69230fdc8d8SChris Lattner } 69330fdc8d8SChris Lattner } 69430fdc8d8SChris Lattner else 69530fdc8d8SChris Lattner { 696c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 69730fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID()); 69830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 69930fdc8d8SChris Lattner } 70030fdc8d8SChris Lattner } 70130fdc8d8SChris Lattner } 70230fdc8d8SChris Lattner } 70330fdc8d8SChris Lattner 70430fdc8d8SChris Lattner //------------------------------------------------------------------------- 70530fdc8d8SChris Lattner // CommandObjectBreakpointList::Options 70630fdc8d8SChris Lattner //------------------------------------------------------------------------- 707ae1c4cf5SJim Ingham #pragma mark List::CommandOptions 70830fdc8d8SChris Lattner 709eb0103f2SGreg Clayton CommandObjectBreakpointList::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 710eb0103f2SGreg Clayton Options (interpreter), 71179042b3eSCaroline Tice m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions 71230fdc8d8SChris Lattner { 71330fdc8d8SChris Lattner } 71430fdc8d8SChris Lattner 71530fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::~CommandOptions () 71630fdc8d8SChris Lattner { 71730fdc8d8SChris Lattner } 71830fdc8d8SChris Lattner 719e0d378b3SGreg Clayton OptionDefinition 72030fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::g_option_table[] = 72130fdc8d8SChris Lattner { 722deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone, 7238651121cSJim Ingham "Show debugger internal breakpoints" }, 7248651121cSJim Ingham 725deaab222SCaroline Tice { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone, 72630fdc8d8SChris Lattner "Give a brief description of the breakpoint (no location info)."}, 72730fdc8d8SChris Lattner 72830fdc8d8SChris Lattner // FIXME: We need to add an "internal" command, and then add this sort of thing to it. 72930fdc8d8SChris Lattner // But I need to see it for now, and don't want to wait. 730deaab222SCaroline Tice { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone, 73130fdc8d8SChris Lattner "Give a full description of the breakpoint and its locations."}, 73230fdc8d8SChris Lattner 733deaab222SCaroline Tice { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, 73430fdc8d8SChris Lattner "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, 73530fdc8d8SChris Lattner 736deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 73730fdc8d8SChris Lattner }; 73830fdc8d8SChris Lattner 739e0d378b3SGreg Clayton const OptionDefinition* 74030fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::GetDefinitions () 74130fdc8d8SChris Lattner { 74230fdc8d8SChris Lattner return g_option_table; 74330fdc8d8SChris Lattner } 74430fdc8d8SChris Lattner 74530fdc8d8SChris Lattner Error 746f6b8b581SGreg Clayton CommandObjectBreakpointList::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 74730fdc8d8SChris Lattner { 74830fdc8d8SChris Lattner Error error; 74930fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 75030fdc8d8SChris Lattner 75130fdc8d8SChris Lattner switch (short_option) 75230fdc8d8SChris Lattner { 75330fdc8d8SChris Lattner case 'b': 75430fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelBrief; 75530fdc8d8SChris Lattner break; 75630fdc8d8SChris Lattner case 'f': 75730fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelFull; 75830fdc8d8SChris Lattner break; 75930fdc8d8SChris Lattner case 'v': 76030fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelVerbose; 76130fdc8d8SChris Lattner break; 76230fdc8d8SChris Lattner case 'i': 76330fdc8d8SChris Lattner m_internal = true; 76430fdc8d8SChris Lattner break; 76530fdc8d8SChris Lattner default: 76686edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 76730fdc8d8SChris Lattner break; 76830fdc8d8SChris Lattner } 76930fdc8d8SChris Lattner 77030fdc8d8SChris Lattner return error; 77130fdc8d8SChris Lattner } 77230fdc8d8SChris Lattner 77330fdc8d8SChris Lattner void 774f6b8b581SGreg Clayton CommandObjectBreakpointList::CommandOptions::OptionParsingStarting () 77530fdc8d8SChris Lattner { 776d915e16fSJim Ingham m_level = lldb::eDescriptionLevelFull; 77730fdc8d8SChris Lattner m_internal = false; 77830fdc8d8SChris Lattner } 77930fdc8d8SChris Lattner 78030fdc8d8SChris Lattner //------------------------------------------------------------------------- 78130fdc8d8SChris Lattner // CommandObjectBreakpointList 78230fdc8d8SChris Lattner //------------------------------------------------------------------------- 783ae1c4cf5SJim Ingham #pragma mark List 78430fdc8d8SChris Lattner 785a7015092SGreg Clayton CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) : 786a7015092SGreg Clayton CommandObject (interpreter, 787a7015092SGreg Clayton "breakpoint list", 78830fdc8d8SChris Lattner "List some or all breakpoints at configurable levels of detail.", 789eb0103f2SGreg Clayton NULL), 790eb0103f2SGreg Clayton m_options (interpreter) 79130fdc8d8SChris Lattner { 792e139cf23SCaroline Tice CommandArgumentEntry arg; 793e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 794e139cf23SCaroline Tice 795e139cf23SCaroline Tice // Define the first (and only) variant of this arg. 796e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 797405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 798e139cf23SCaroline Tice 799e139cf23SCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 800e139cf23SCaroline Tice arg.push_back (bp_id_arg); 801e139cf23SCaroline Tice 802e139cf23SCaroline Tice // Push the data for the first argument into the m_arguments vector. 803e139cf23SCaroline Tice m_arguments.push_back (arg); 80430fdc8d8SChris Lattner } 80530fdc8d8SChris Lattner 80630fdc8d8SChris Lattner CommandObjectBreakpointList::~CommandObjectBreakpointList () 80730fdc8d8SChris Lattner { 80830fdc8d8SChris Lattner } 80930fdc8d8SChris Lattner 81030fdc8d8SChris Lattner Options * 81130fdc8d8SChris Lattner CommandObjectBreakpointList::GetOptions () 81230fdc8d8SChris Lattner { 81330fdc8d8SChris Lattner return &m_options; 81430fdc8d8SChris Lattner } 81530fdc8d8SChris Lattner 81630fdc8d8SChris Lattner bool 81730fdc8d8SChris Lattner CommandObjectBreakpointList::Execute 81830fdc8d8SChris Lattner ( 81930fdc8d8SChris Lattner Args& args, 82030fdc8d8SChris Lattner CommandReturnObject &result 82130fdc8d8SChris Lattner ) 82230fdc8d8SChris Lattner { 823a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 82430fdc8d8SChris Lattner if (target == NULL) 82530fdc8d8SChris Lattner { 8269068d794SCaroline Tice result.AppendError ("Invalid target. No current target or breakpoints."); 82730fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 82830fdc8d8SChris Lattner return true; 82930fdc8d8SChris Lattner } 83030fdc8d8SChris Lattner 83130fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal); 8321b54c88cSJim Ingham Mutex::Locker locker; 8331b54c88cSJim Ingham target->GetBreakpointList(m_options.m_internal).GetListMutex(locker); 8341b54c88cSJim Ingham 83530fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 83630fdc8d8SChris Lattner 83730fdc8d8SChris Lattner if (num_breakpoints == 0) 83830fdc8d8SChris Lattner { 83930fdc8d8SChris Lattner result.AppendMessage ("No breakpoints currently set."); 84030fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 84130fdc8d8SChris Lattner return true; 84230fdc8d8SChris Lattner } 84330fdc8d8SChris Lattner 84485e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 84530fdc8d8SChris Lattner 84630fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 84730fdc8d8SChris Lattner { 84830fdc8d8SChris Lattner // No breakpoint selected; show info about all currently set breakpoints. 84930fdc8d8SChris Lattner result.AppendMessage ("Current breakpoints:"); 850c982c768SGreg Clayton for (size_t i = 0; i < num_breakpoints; ++i) 85130fdc8d8SChris Lattner { 8529fed0d85SGreg Clayton Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get(); 8536611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 85430fdc8d8SChris Lattner } 85530fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 85630fdc8d8SChris Lattner } 85730fdc8d8SChris Lattner else 85830fdc8d8SChris Lattner { 85930fdc8d8SChris Lattner // Particular breakpoints selected; show info about that breakpoint. 86030fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 86130fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 86230fdc8d8SChris Lattner 86330fdc8d8SChris Lattner if (result.Succeeded()) 86430fdc8d8SChris Lattner { 865c982c768SGreg Clayton for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) 86630fdc8d8SChris Lattner { 86730fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 86830fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 8696611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 87030fdc8d8SChris Lattner } 87130fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 87230fdc8d8SChris Lattner } 87330fdc8d8SChris Lattner else 87430fdc8d8SChris Lattner { 87530fdc8d8SChris Lattner result.AppendError ("Invalid breakpoint id."); 87630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 87730fdc8d8SChris Lattner } 87830fdc8d8SChris Lattner } 87930fdc8d8SChris Lattner 88030fdc8d8SChris Lattner return result.Succeeded(); 88130fdc8d8SChris Lattner } 88230fdc8d8SChris Lattner 88330fdc8d8SChris Lattner //------------------------------------------------------------------------- 88430fdc8d8SChris Lattner // CommandObjectBreakpointEnable 88530fdc8d8SChris Lattner //------------------------------------------------------------------------- 886ae1c4cf5SJim Ingham #pragma mark Enable 88730fdc8d8SChris Lattner 888a7015092SGreg Clayton CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) : 889a7015092SGreg Clayton CommandObject (interpreter, 890a7015092SGreg Clayton "enable", 891e3d26315SCaroline Tice "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.", 892e139cf23SCaroline Tice NULL) 89330fdc8d8SChris Lattner { 894e139cf23SCaroline Tice CommandArgumentEntry arg; 895de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 896e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 897e139cf23SCaroline Tice m_arguments.push_back (arg); 89830fdc8d8SChris Lattner } 89930fdc8d8SChris Lattner 90030fdc8d8SChris Lattner 90130fdc8d8SChris Lattner CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable () 90230fdc8d8SChris Lattner { 90330fdc8d8SChris Lattner } 90430fdc8d8SChris Lattner 90530fdc8d8SChris Lattner 90630fdc8d8SChris Lattner bool 9076611103cSGreg Clayton CommandObjectBreakpointEnable::Execute 9086611103cSGreg Clayton ( 9096611103cSGreg Clayton Args& args, 9106611103cSGreg Clayton CommandReturnObject &result 9116611103cSGreg Clayton ) 91230fdc8d8SChris Lattner { 913a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 91430fdc8d8SChris Lattner if (target == NULL) 91530fdc8d8SChris Lattner { 9169068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 91730fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 91830fdc8d8SChris Lattner return false; 91930fdc8d8SChris Lattner } 92030fdc8d8SChris Lattner 9211b54c88cSJim Ingham Mutex::Locker locker; 9221b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 9231b54c88cSJim Ingham 92430fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 9251b54c88cSJim Ingham 92630fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 92730fdc8d8SChris Lattner 92830fdc8d8SChris Lattner if (num_breakpoints == 0) 92930fdc8d8SChris Lattner { 93030fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be enabled."); 93130fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 93230fdc8d8SChris Lattner return false; 93330fdc8d8SChris Lattner } 93430fdc8d8SChris Lattner 93530fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 93630fdc8d8SChris Lattner { 93730fdc8d8SChris Lattner // No breakpoint selected; enable all currently set breakpoints. 93830fdc8d8SChris Lattner target->EnableAllBreakpoints (); 939fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints enabled. (%lu breakpoints)\n", num_breakpoints); 94030fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 94130fdc8d8SChris Lattner } 94230fdc8d8SChris Lattner else 94330fdc8d8SChris Lattner { 94430fdc8d8SChris Lattner // Particular breakpoint selected; enable that breakpoint. 94530fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 94630fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 94730fdc8d8SChris Lattner 94830fdc8d8SChris Lattner if (result.Succeeded()) 94930fdc8d8SChris Lattner { 95030fdc8d8SChris Lattner int enable_count = 0; 95130fdc8d8SChris Lattner int loc_count = 0; 952c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 953c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 95430fdc8d8SChris Lattner { 95530fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 95630fdc8d8SChris Lattner 95730fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 95830fdc8d8SChris Lattner { 95930fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 96030fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 96130fdc8d8SChris Lattner { 96230fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 96330fdc8d8SChris Lattner if (location) 96430fdc8d8SChris Lattner { 96530fdc8d8SChris Lattner location->SetEnabled (true); 96630fdc8d8SChris Lattner ++loc_count; 96730fdc8d8SChris Lattner } 96830fdc8d8SChris Lattner } 96930fdc8d8SChris Lattner else 97030fdc8d8SChris Lattner { 971ae1c4cf5SJim Ingham breakpoint->SetEnabled (true); 97230fdc8d8SChris Lattner ++enable_count; 97330fdc8d8SChris Lattner } 97430fdc8d8SChris Lattner } 97530fdc8d8SChris Lattner } 97630fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count); 97730fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 97830fdc8d8SChris Lattner } 97930fdc8d8SChris Lattner } 98030fdc8d8SChris Lattner 98130fdc8d8SChris Lattner return result.Succeeded(); 98230fdc8d8SChris Lattner } 98330fdc8d8SChris Lattner 98430fdc8d8SChris Lattner //------------------------------------------------------------------------- 98530fdc8d8SChris Lattner // CommandObjectBreakpointDisable 98630fdc8d8SChris Lattner //------------------------------------------------------------------------- 987ae1c4cf5SJim Ingham #pragma mark Disable 98830fdc8d8SChris Lattner 989a7015092SGreg Clayton CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) : 990a7015092SGreg Clayton CommandObject (interpreter, 991e139cf23SCaroline Tice "breakpoint disable", 992e3d26315SCaroline Tice "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.", 993e139cf23SCaroline Tice NULL) 99430fdc8d8SChris Lattner { 995e139cf23SCaroline Tice CommandArgumentEntry arg; 996de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 997e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 998e139cf23SCaroline Tice m_arguments.push_back (arg); 99930fdc8d8SChris Lattner } 100030fdc8d8SChris Lattner 100130fdc8d8SChris Lattner CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable () 100230fdc8d8SChris Lattner { 100330fdc8d8SChris Lattner } 100430fdc8d8SChris Lattner 100530fdc8d8SChris Lattner bool 10066611103cSGreg Clayton CommandObjectBreakpointDisable::Execute 10076611103cSGreg Clayton ( 10086611103cSGreg Clayton Args& args, 10096611103cSGreg Clayton CommandReturnObject &result 10106611103cSGreg Clayton ) 101130fdc8d8SChris Lattner { 1012a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 101330fdc8d8SChris Lattner if (target == NULL) 101430fdc8d8SChris Lattner { 10159068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 101630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 101730fdc8d8SChris Lattner return false; 101830fdc8d8SChris Lattner } 101930fdc8d8SChris Lattner 10201b54c88cSJim Ingham Mutex::Locker locker; 10211b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 10221b54c88cSJim Ingham 102330fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 102430fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 102530fdc8d8SChris Lattner 102630fdc8d8SChris Lattner if (num_breakpoints == 0) 102730fdc8d8SChris Lattner { 102830fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be disabled."); 102930fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 103030fdc8d8SChris Lattner return false; 103130fdc8d8SChris Lattner } 103230fdc8d8SChris Lattner 103330fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 103430fdc8d8SChris Lattner { 103530fdc8d8SChris Lattner // No breakpoint selected; disable all currently set breakpoints. 103630fdc8d8SChris Lattner target->DisableAllBreakpoints (); 1037fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints disabled. (%lu breakpoints)\n", num_breakpoints); 103830fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 103930fdc8d8SChris Lattner } 104030fdc8d8SChris Lattner else 104130fdc8d8SChris Lattner { 104230fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 104330fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 104430fdc8d8SChris Lattner 104530fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 104630fdc8d8SChris Lattner 104730fdc8d8SChris Lattner if (result.Succeeded()) 104830fdc8d8SChris Lattner { 104930fdc8d8SChris Lattner int disable_count = 0; 105030fdc8d8SChris Lattner int loc_count = 0; 1051c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1052c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 105330fdc8d8SChris Lattner { 105430fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 105530fdc8d8SChris Lattner 105630fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 105730fdc8d8SChris Lattner { 105830fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 105930fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 106030fdc8d8SChris Lattner { 106130fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 106230fdc8d8SChris Lattner if (location) 106330fdc8d8SChris Lattner { 106430fdc8d8SChris Lattner location->SetEnabled (false); 106530fdc8d8SChris Lattner ++loc_count; 106630fdc8d8SChris Lattner } 106730fdc8d8SChris Lattner } 106830fdc8d8SChris Lattner else 106930fdc8d8SChris Lattner { 1070ae1c4cf5SJim Ingham breakpoint->SetEnabled (false); 107130fdc8d8SChris Lattner ++disable_count; 107230fdc8d8SChris Lattner } 107330fdc8d8SChris Lattner } 107430fdc8d8SChris Lattner } 107530fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count); 107630fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 107730fdc8d8SChris Lattner } 107830fdc8d8SChris Lattner } 107930fdc8d8SChris Lattner 108030fdc8d8SChris Lattner return result.Succeeded(); 108130fdc8d8SChris Lattner } 108230fdc8d8SChris Lattner 108330fdc8d8SChris Lattner //------------------------------------------------------------------------- 1084b7234e40SJohnny Chen // CommandObjectBreakpointClear::CommandOptions 1085b7234e40SJohnny Chen //------------------------------------------------------------------------- 1086b7234e40SJohnny Chen #pragma mark Clear::CommandOptions 1087b7234e40SJohnny Chen 1088eb0103f2SGreg Clayton CommandObjectBreakpointClear::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 1089eb0103f2SGreg Clayton Options (interpreter), 1090b7234e40SJohnny Chen m_filename (), 1091b7234e40SJohnny Chen m_line_num (0) 1092b7234e40SJohnny Chen { 1093b7234e40SJohnny Chen } 1094b7234e40SJohnny Chen 1095b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::~CommandOptions () 1096b7234e40SJohnny Chen { 1097b7234e40SJohnny Chen } 1098b7234e40SJohnny Chen 1099e0d378b3SGreg Clayton OptionDefinition 1100b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::g_option_table[] = 1101b7234e40SJohnny Chen { 1102b7234e40SJohnny Chen { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, 1103b7234e40SJohnny Chen "Specify the breakpoint by source location in this particular file."}, 1104b7234e40SJohnny Chen 1105b7234e40SJohnny Chen { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, 1106b7234e40SJohnny Chen "Specify the breakpoint by source location at this particular line."}, 1107b7234e40SJohnny Chen 1108b7234e40SJohnny Chen { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 1109b7234e40SJohnny Chen }; 1110b7234e40SJohnny Chen 1111e0d378b3SGreg Clayton const OptionDefinition* 1112b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandOptions::GetDefinitions () 1113b7234e40SJohnny Chen { 1114b7234e40SJohnny Chen return g_option_table; 1115b7234e40SJohnny Chen } 1116b7234e40SJohnny Chen 1117b7234e40SJohnny Chen Error 1118f6b8b581SGreg Clayton CommandObjectBreakpointClear::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 1119b7234e40SJohnny Chen { 1120b7234e40SJohnny Chen Error error; 1121b7234e40SJohnny Chen char short_option = (char) m_getopt_table[option_idx].val; 1122b7234e40SJohnny Chen 1123b7234e40SJohnny Chen switch (short_option) 1124b7234e40SJohnny Chen { 1125b7234e40SJohnny Chen case 'f': 1126357132ebSGreg Clayton m_filename.assign (option_arg); 1127b7234e40SJohnny Chen break; 1128b7234e40SJohnny Chen 1129b7234e40SJohnny Chen case 'l': 1130b7234e40SJohnny Chen m_line_num = Args::StringToUInt32 (option_arg, 0); 1131b7234e40SJohnny Chen break; 1132b7234e40SJohnny Chen 1133b7234e40SJohnny Chen default: 113486edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 1135b7234e40SJohnny Chen break; 1136b7234e40SJohnny Chen } 1137b7234e40SJohnny Chen 1138b7234e40SJohnny Chen return error; 1139b7234e40SJohnny Chen } 1140b7234e40SJohnny Chen 1141b7234e40SJohnny Chen void 1142f6b8b581SGreg Clayton CommandObjectBreakpointClear::CommandOptions::OptionParsingStarting () 1143b7234e40SJohnny Chen { 1144b7234e40SJohnny Chen m_filename.clear(); 1145b7234e40SJohnny Chen m_line_num = 0; 1146b7234e40SJohnny Chen } 1147b7234e40SJohnny Chen 1148b7234e40SJohnny Chen //------------------------------------------------------------------------- 1149b7234e40SJohnny Chen // CommandObjectBreakpointClear 1150b7234e40SJohnny Chen //------------------------------------------------------------------------- 1151b7234e40SJohnny Chen #pragma mark Clear 1152b7234e40SJohnny Chen 1153b7234e40SJohnny Chen CommandObjectBreakpointClear::CommandObjectBreakpointClear (CommandInterpreter &interpreter) : 1154b7234e40SJohnny Chen CommandObject (interpreter, 1155b7234e40SJohnny Chen "breakpoint clear", 1156b7234e40SJohnny Chen "Clears a breakpoint or set of breakpoints in the executable.", 1157eb0103f2SGreg Clayton "breakpoint clear <cmd-options>"), 1158eb0103f2SGreg Clayton m_options (interpreter) 1159b7234e40SJohnny Chen { 1160b7234e40SJohnny Chen } 1161b7234e40SJohnny Chen 1162b7234e40SJohnny Chen CommandObjectBreakpointClear::~CommandObjectBreakpointClear () 1163b7234e40SJohnny Chen { 1164b7234e40SJohnny Chen } 1165b7234e40SJohnny Chen 1166b7234e40SJohnny Chen Options * 1167b7234e40SJohnny Chen CommandObjectBreakpointClear::GetOptions () 1168b7234e40SJohnny Chen { 1169b7234e40SJohnny Chen return &m_options; 1170b7234e40SJohnny Chen } 1171b7234e40SJohnny Chen 1172b7234e40SJohnny Chen bool 1173b7234e40SJohnny Chen CommandObjectBreakpointClear::Execute 1174b7234e40SJohnny Chen ( 1175b7234e40SJohnny Chen Args& command, 1176b7234e40SJohnny Chen CommandReturnObject &result 1177b7234e40SJohnny Chen ) 1178b7234e40SJohnny Chen { 1179b7234e40SJohnny Chen Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 1180b7234e40SJohnny Chen if (target == NULL) 1181b7234e40SJohnny Chen { 1182b7234e40SJohnny Chen result.AppendError ("Invalid target. No existing target or breakpoints."); 1183b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1184b7234e40SJohnny Chen return false; 1185b7234e40SJohnny Chen } 1186b7234e40SJohnny Chen 1187b7234e40SJohnny Chen // The following are the various types of breakpoints that could be cleared: 1188b7234e40SJohnny Chen // 1). -f -l (clearing breakpoint by source location) 1189b7234e40SJohnny Chen 1190b7234e40SJohnny Chen BreakpointClearType break_type = eClearTypeInvalid; 1191b7234e40SJohnny Chen 1192b7234e40SJohnny Chen if (m_options.m_line_num != 0) 1193b7234e40SJohnny Chen break_type = eClearTypeFileAndLine; 1194b7234e40SJohnny Chen 1195b7234e40SJohnny Chen Mutex::Locker locker; 1196b7234e40SJohnny Chen target->GetBreakpointList().GetListMutex(locker); 1197b7234e40SJohnny Chen 1198b7234e40SJohnny Chen BreakpointList &breakpoints = target->GetBreakpointList(); 1199b7234e40SJohnny Chen size_t num_breakpoints = breakpoints.GetSize(); 1200b7234e40SJohnny Chen 1201b7234e40SJohnny Chen // Early return if there's no breakpoint at all. 1202b7234e40SJohnny Chen if (num_breakpoints == 0) 1203b7234e40SJohnny Chen { 1204b7234e40SJohnny Chen result.AppendError ("Breakpoint clear: No breakpoint cleared."); 1205b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1206b7234e40SJohnny Chen return result.Succeeded(); 1207b7234e40SJohnny Chen } 1208b7234e40SJohnny Chen 1209b7234e40SJohnny Chen // Find matching breakpoints and delete them. 1210b7234e40SJohnny Chen 1211b7234e40SJohnny Chen // First create a copy of all the IDs. 1212b7234e40SJohnny Chen std::vector<break_id_t> BreakIDs; 1213b7234e40SJohnny Chen for (size_t i = 0; i < num_breakpoints; ++i) 1214b7234e40SJohnny Chen BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID()); 1215b7234e40SJohnny Chen 1216b7234e40SJohnny Chen int num_cleared = 0; 1217b7234e40SJohnny Chen StreamString ss; 1218b7234e40SJohnny Chen switch (break_type) 1219b7234e40SJohnny Chen { 1220b7234e40SJohnny Chen case eClearTypeFileAndLine: // Breakpoint by source position 1221b7234e40SJohnny Chen { 1222b7234e40SJohnny Chen const ConstString filename(m_options.m_filename.c_str()); 1223b7234e40SJohnny Chen BreakpointLocationCollection loc_coll; 1224b7234e40SJohnny Chen 1225b7234e40SJohnny Chen for (size_t i = 0; i < num_breakpoints; ++i) 1226b7234e40SJohnny Chen { 1227b7234e40SJohnny Chen Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); 1228b7234e40SJohnny Chen 1229b7234e40SJohnny Chen if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) 1230b7234e40SJohnny Chen { 1231b7234e40SJohnny Chen // If the collection size is 0, it's a full match and we can just remove the breakpoint. 1232b7234e40SJohnny Chen if (loc_coll.GetSize() == 0) 1233b7234e40SJohnny Chen { 1234b7234e40SJohnny Chen bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); 1235b7234e40SJohnny Chen ss.EOL(); 1236b7234e40SJohnny Chen target->RemoveBreakpointByID (bp->GetID()); 1237b7234e40SJohnny Chen ++num_cleared; 1238b7234e40SJohnny Chen } 1239b7234e40SJohnny Chen } 1240b7234e40SJohnny Chen } 1241b7234e40SJohnny Chen } 1242b7234e40SJohnny Chen break; 1243b7234e40SJohnny Chen 1244b7234e40SJohnny Chen default: 1245b7234e40SJohnny Chen break; 1246b7234e40SJohnny Chen } 1247b7234e40SJohnny Chen 1248b7234e40SJohnny Chen if (num_cleared > 0) 1249b7234e40SJohnny Chen { 125085e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 1251b7234e40SJohnny Chen output_stream.Printf ("%d breakpoints cleared:\n", num_cleared); 1252b7234e40SJohnny Chen output_stream << ss.GetData(); 1253b7234e40SJohnny Chen output_stream.EOL(); 1254b7234e40SJohnny Chen result.SetStatus (eReturnStatusSuccessFinishNoResult); 1255b7234e40SJohnny Chen } 1256b7234e40SJohnny Chen else 1257b7234e40SJohnny Chen { 1258b7234e40SJohnny Chen result.AppendError ("Breakpoint clear: No breakpoint cleared."); 1259b7234e40SJohnny Chen result.SetStatus (eReturnStatusFailed); 1260b7234e40SJohnny Chen } 1261b7234e40SJohnny Chen 1262b7234e40SJohnny Chen return result.Succeeded(); 1263b7234e40SJohnny Chen } 1264b7234e40SJohnny Chen 1265b7234e40SJohnny Chen //------------------------------------------------------------------------- 126630fdc8d8SChris Lattner // CommandObjectBreakpointDelete 126730fdc8d8SChris Lattner //------------------------------------------------------------------------- 1268ae1c4cf5SJim Ingham #pragma mark Delete 126930fdc8d8SChris Lattner 1270a7015092SGreg Clayton CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) : 1271a7015092SGreg Clayton CommandObject (interpreter, 1272a7015092SGreg Clayton "breakpoint delete", 1273e3d26315SCaroline Tice "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.", 1274e139cf23SCaroline Tice NULL) 127530fdc8d8SChris Lattner { 1276e139cf23SCaroline Tice CommandArgumentEntry arg; 1277de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 1278e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1279e139cf23SCaroline Tice m_arguments.push_back (arg); 128030fdc8d8SChris Lattner } 128130fdc8d8SChris Lattner 128230fdc8d8SChris Lattner 128330fdc8d8SChris Lattner CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete () 128430fdc8d8SChris Lattner { 128530fdc8d8SChris Lattner } 128630fdc8d8SChris Lattner 128730fdc8d8SChris Lattner bool 12886611103cSGreg Clayton CommandObjectBreakpointDelete::Execute 12896611103cSGreg Clayton ( 12906611103cSGreg Clayton Args& args, 12916611103cSGreg Clayton CommandReturnObject &result 12926611103cSGreg Clayton ) 129330fdc8d8SChris Lattner { 1294a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 129530fdc8d8SChris Lattner if (target == NULL) 129630fdc8d8SChris Lattner { 12979068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 129830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 129930fdc8d8SChris Lattner return false; 130030fdc8d8SChris Lattner } 130130fdc8d8SChris Lattner 13021b54c88cSJim Ingham Mutex::Locker locker; 13031b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 13041b54c88cSJim Ingham 130530fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 13061b54c88cSJim Ingham 130730fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 130830fdc8d8SChris Lattner 130930fdc8d8SChris Lattner if (num_breakpoints == 0) 131030fdc8d8SChris Lattner { 131130fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be deleted."); 131230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 131330fdc8d8SChris Lattner return false; 131430fdc8d8SChris Lattner } 131530fdc8d8SChris Lattner 131630fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 131730fdc8d8SChris Lattner { 131836f3b369SJim Ingham if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true)) 131930fdc8d8SChris Lattner { 132036f3b369SJim Ingham result.AppendMessage("Operation cancelled..."); 132130fdc8d8SChris Lattner } 132236f3b369SJim Ingham else 132336f3b369SJim Ingham { 132430fdc8d8SChris Lattner target->RemoveAllBreakpoints (); 1325fd54b368SJason Molenda result.AppendMessageWithFormat ("All breakpoints removed. (%lu breakpoints)\n", num_breakpoints); 132636f3b369SJim Ingham } 132730fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 132830fdc8d8SChris Lattner } 132930fdc8d8SChris Lattner else 133030fdc8d8SChris Lattner { 133130fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 133230fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 133330fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 133430fdc8d8SChris Lattner 133530fdc8d8SChris Lattner if (result.Succeeded()) 133630fdc8d8SChris Lattner { 133730fdc8d8SChris Lattner int delete_count = 0; 133830fdc8d8SChris Lattner int disable_count = 0; 1339c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1340c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 134130fdc8d8SChris Lattner { 134230fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 134330fdc8d8SChris Lattner 134430fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 134530fdc8d8SChris Lattner { 134630fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 134730fdc8d8SChris Lattner { 134830fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 134930fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 135030fdc8d8SChris Lattner // It makes no sense to try to delete individual locations, so we disable them instead. 135130fdc8d8SChris Lattner if (location) 135230fdc8d8SChris Lattner { 135330fdc8d8SChris Lattner location->SetEnabled (false); 135430fdc8d8SChris Lattner ++disable_count; 135530fdc8d8SChris Lattner } 135630fdc8d8SChris Lattner } 135730fdc8d8SChris Lattner else 135830fdc8d8SChris Lattner { 135930fdc8d8SChris Lattner target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID()); 136030fdc8d8SChris Lattner ++delete_count; 136130fdc8d8SChris Lattner } 136230fdc8d8SChris Lattner } 136330fdc8d8SChris Lattner } 136430fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n", 136530fdc8d8SChris Lattner delete_count, disable_count); 136630fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 136730fdc8d8SChris Lattner } 136830fdc8d8SChris Lattner } 136930fdc8d8SChris Lattner return result.Succeeded(); 137030fdc8d8SChris Lattner } 13711b54c88cSJim Ingham 13721b54c88cSJim Ingham //------------------------------------------------------------------------- 1373ae1c4cf5SJim Ingham // CommandObjectBreakpointModify::CommandOptions 13741b54c88cSJim Ingham //------------------------------------------------------------------------- 1375ae1c4cf5SJim Ingham #pragma mark Modify::CommandOptions 13761b54c88cSJim Ingham 1377eb0103f2SGreg Clayton CommandObjectBreakpointModify::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : 1378eb0103f2SGreg Clayton Options (interpreter), 1379c982c768SGreg Clayton m_ignore_count (0), 13801b54c88cSJim Ingham m_thread_id(LLDB_INVALID_THREAD_ID), 1381e0a97848SJim Ingham m_thread_id_passed(false), 1382c982c768SGreg Clayton m_thread_index (UINT32_MAX), 1383e0a97848SJim Ingham m_thread_index_passed(false), 13841b54c88cSJim Ingham m_thread_name(), 13851b54c88cSJim Ingham m_queue_name(), 138636f3b369SJim Ingham m_condition (), 1387c982c768SGreg Clayton m_enable_passed (false), 1388c982c768SGreg Clayton m_enable_value (false), 1389c982c768SGreg Clayton m_name_passed (false), 139036f3b369SJim Ingham m_queue_passed (false), 139136f3b369SJim Ingham m_condition_passed (false) 13921b54c88cSJim Ingham { 13931b54c88cSJim Ingham } 13941b54c88cSJim Ingham 1395ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::~CommandOptions () 13961b54c88cSJim Ingham { 13971b54c88cSJim Ingham } 13981b54c88cSJim Ingham 1399e0d378b3SGreg Clayton OptionDefinition 1400ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] = 14011b54c88cSJim Ingham { 1402a0cd2bcaSBill 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." }, 1403a0cd2bcaSBill 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."}, 1404a0cd2bcaSBill 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."}, 1405a0cd2bcaSBill 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."}, 1406a0cd2bcaSBill 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."}, 1407a0cd2bcaSBill Wendling { LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."}, 1408a0cd2bcaSBill Wendling { LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, 0, eArgTypeNone, "Enable the breakpoint."}, 1409a0cd2bcaSBill Wendling { LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, 0, eArgTypeNone, "Disable the breakpoint."}, 1410deaab222SCaroline Tice { 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } 14111b54c88cSJim Ingham }; 14121b54c88cSJim Ingham 1413e0d378b3SGreg Clayton const OptionDefinition* 1414ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::GetDefinitions () 14151b54c88cSJim Ingham { 14161b54c88cSJim Ingham return g_option_table; 14171b54c88cSJim Ingham } 14181b54c88cSJim Ingham 14191b54c88cSJim Ingham Error 1420f6b8b581SGreg Clayton CommandObjectBreakpointModify::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) 14211b54c88cSJim Ingham { 14221b54c88cSJim Ingham Error error; 14231b54c88cSJim Ingham char short_option = (char) m_getopt_table[option_idx].val; 14241b54c88cSJim Ingham 14251b54c88cSJim Ingham switch (short_option) 14261b54c88cSJim Ingham { 142736f3b369SJim Ingham case 'c': 142836f3b369SJim Ingham if (option_arg != NULL) 1429357132ebSGreg Clayton m_condition.assign (option_arg); 143036f3b369SJim Ingham else 143136f3b369SJim Ingham m_condition.clear(); 143236f3b369SJim Ingham m_condition_passed = true; 143336f3b369SJim Ingham break; 1434ae1c4cf5SJim Ingham case 'd': 1435ae1c4cf5SJim Ingham m_enable_passed = true; 1436ae1c4cf5SJim Ingham m_enable_value = false; 1437ae1c4cf5SJim Ingham break; 1438ae1c4cf5SJim Ingham case 'e': 1439ae1c4cf5SJim Ingham m_enable_passed = true; 1440ae1c4cf5SJim Ingham m_enable_value = true; 1441ae1c4cf5SJim Ingham break; 1442ed8a705cSGreg Clayton case 'i': 14431b54c88cSJim Ingham { 14440292f4a5SJim Ingham m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); 1445c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 144686edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); 14471b54c88cSJim Ingham } 1448ae1c4cf5SJim Ingham break; 14491b54c88cSJim Ingham case 't' : 14501b54c88cSJim Ingham { 14510292f4a5SJim Ingham if (option_arg[0] == '\0') 1452e0a97848SJim Ingham { 1453e0a97848SJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 1454e0a97848SJim Ingham m_thread_id_passed = true; 1455e0a97848SJim Ingham } 1456e0a97848SJim Ingham else 1457e0a97848SJim Ingham { 14580292f4a5SJim Ingham m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 14591b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 146086edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); 1461e0a97848SJim Ingham else 1462e0a97848SJim Ingham m_thread_id_passed = true; 1463e0a97848SJim Ingham } 14641b54c88cSJim Ingham } 14651b54c88cSJim Ingham break; 14661b54c88cSJim Ingham case 'T': 1467b2a38a72SJim Ingham if (option_arg != NULL) 1468357132ebSGreg Clayton m_thread_name.assign (option_arg); 1469b2a38a72SJim Ingham else 1470b2a38a72SJim Ingham m_thread_name.clear(); 1471b2a38a72SJim Ingham m_name_passed = true; 14721b54c88cSJim Ingham break; 14731b54c88cSJim Ingham case 'q': 1474b2a38a72SJim Ingham if (option_arg != NULL) 1475357132ebSGreg Clayton m_queue_name.assign (option_arg); 1476b2a38a72SJim Ingham else 1477b2a38a72SJim Ingham m_queue_name.clear(); 1478b2a38a72SJim Ingham m_queue_passed = true; 14791b54c88cSJim Ingham break; 14801b54c88cSJim Ingham case 'x': 14811b54c88cSJim Ingham { 14820292f4a5SJim Ingham if (option_arg[0] == '\n') 1483e0a97848SJim Ingham { 1484e0a97848SJim Ingham m_thread_index = UINT32_MAX; 1485e0a97848SJim Ingham m_thread_index_passed = true; 1486e0a97848SJim Ingham } 1487e0a97848SJim Ingham else 1488e0a97848SJim Ingham { 14890292f4a5SJim Ingham m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0); 1490c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 149186edbf41SGreg Clayton error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); 1492e0a97848SJim Ingham else 1493e0a97848SJim Ingham m_thread_index_passed = true; 1494e0a97848SJim Ingham } 14951b54c88cSJim Ingham } 14961b54c88cSJim Ingham break; 14971b54c88cSJim Ingham default: 149886edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 14991b54c88cSJim Ingham break; 15001b54c88cSJim Ingham } 15011b54c88cSJim Ingham 15021b54c88cSJim Ingham return error; 15031b54c88cSJim Ingham } 15041b54c88cSJim Ingham 15051b54c88cSJim Ingham void 1506f6b8b581SGreg Clayton CommandObjectBreakpointModify::CommandOptions::OptionParsingStarting () 15071b54c88cSJim Ingham { 1508c982c768SGreg Clayton m_ignore_count = 0; 15091b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 1510e0a97848SJim Ingham m_thread_id_passed = false; 1511c982c768SGreg Clayton m_thread_index = UINT32_MAX; 1512e0a97848SJim Ingham m_thread_index_passed = false; 15131b54c88cSJim Ingham m_thread_name.clear(); 15141b54c88cSJim Ingham m_queue_name.clear(); 151536f3b369SJim Ingham m_condition.clear(); 1516ae1c4cf5SJim Ingham m_enable_passed = false; 1517b2a38a72SJim Ingham m_queue_passed = false; 1518b2a38a72SJim Ingham m_name_passed = false; 151936f3b369SJim Ingham m_condition_passed = false; 15201b54c88cSJim Ingham } 15211b54c88cSJim Ingham 15221b54c88cSJim Ingham //------------------------------------------------------------------------- 1523ae1c4cf5SJim Ingham // CommandObjectBreakpointModify 15241b54c88cSJim Ingham //------------------------------------------------------------------------- 1525ae1c4cf5SJim Ingham #pragma mark Modify 15261b54c88cSJim Ingham 1527a7015092SGreg Clayton CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) : 1528a7015092SGreg Clayton CommandObject (interpreter, 1529a7015092SGreg Clayton "breakpoint modify", 1530a571c010SJim Ingham "Modify the options on a breakpoint or set of breakpoints in the executable. " 1531e0a97848SJim Ingham "If no breakpoint is specified, acts on the last created breakpoint. " 1532e0a97848SJim Ingham "With the exception of -e, -d and -i, passing an empty argument clears the modification.", 1533eb0103f2SGreg Clayton NULL), 1534eb0103f2SGreg Clayton m_options (interpreter) 15351b54c88cSJim Ingham { 1536e139cf23SCaroline Tice CommandArgumentEntry arg; 1537de753464SJohnny Chen CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 1538e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1539e139cf23SCaroline Tice m_arguments.push_back (arg); 15401b54c88cSJim Ingham } 15411b54c88cSJim Ingham 1542ae1c4cf5SJim Ingham CommandObjectBreakpointModify::~CommandObjectBreakpointModify () 15431b54c88cSJim Ingham { 15441b54c88cSJim Ingham } 15451b54c88cSJim Ingham 15461b54c88cSJim Ingham Options * 1547ae1c4cf5SJim Ingham CommandObjectBreakpointModify::GetOptions () 15481b54c88cSJim Ingham { 15491b54c88cSJim Ingham return &m_options; 15501b54c88cSJim Ingham } 15511b54c88cSJim Ingham 15521b54c88cSJim Ingham bool 1553ae1c4cf5SJim Ingham CommandObjectBreakpointModify::Execute 15541b54c88cSJim Ingham ( 15551b54c88cSJim Ingham Args& command, 15561b54c88cSJim Ingham CommandReturnObject &result 15571b54c88cSJim Ingham ) 15581b54c88cSJim Ingham { 1559a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 15601b54c88cSJim Ingham if (target == NULL) 15611b54c88cSJim Ingham { 15629068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 15631b54c88cSJim Ingham result.SetStatus (eReturnStatusFailed); 15641b54c88cSJim Ingham return false; 15651b54c88cSJim Ingham } 15661b54c88cSJim Ingham 15671b54c88cSJim Ingham Mutex::Locker locker; 15681b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 15691b54c88cSJim Ingham 15701b54c88cSJim Ingham BreakpointIDList valid_bp_ids; 15711b54c88cSJim Ingham 15721b54c88cSJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 15731b54c88cSJim Ingham 15741b54c88cSJim Ingham if (result.Succeeded()) 15751b54c88cSJim Ingham { 1576c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1577c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 15781b54c88cSJim Ingham { 15791b54c88cSJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 15801b54c88cSJim Ingham 15811b54c88cSJim Ingham if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 15821b54c88cSJim Ingham { 15831b54c88cSJim Ingham Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 15841b54c88cSJim Ingham if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 15851b54c88cSJim Ingham { 15861b54c88cSJim Ingham BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get(); 15871b54c88cSJim Ingham if (location) 15881b54c88cSJim Ingham { 1589e0a97848SJim Ingham if (m_options.m_thread_id_passed) 15901b54c88cSJim Ingham location->SetThreadID (m_options.m_thread_id); 15911b54c88cSJim Ingham 1592e0a97848SJim Ingham if (m_options.m_thread_index_passed) 1593e6bc6cb9SJim Ingham location->SetThreadIndex(m_options.m_thread_index); 15941b54c88cSJim Ingham 1595b2a38a72SJim Ingham if (m_options.m_name_passed) 1596e6bc6cb9SJim Ingham location->SetThreadName(m_options.m_thread_name.c_str()); 15971b54c88cSJim Ingham 1598b2a38a72SJim Ingham if (m_options.m_queue_passed) 1599e6bc6cb9SJim Ingham location->SetQueueName(m_options.m_queue_name.c_str()); 16001b54c88cSJim Ingham 1601c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 1602e6bc6cb9SJim Ingham location->SetIgnoreCount(m_options.m_ignore_count); 1603ae1c4cf5SJim Ingham 1604ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1605ae1c4cf5SJim Ingham location->SetEnabled (m_options.m_enable_value); 160636f3b369SJim Ingham 160736f3b369SJim Ingham if (m_options.m_condition_passed) 160836f3b369SJim Ingham location->SetCondition (m_options.m_condition.c_str()); 16091b54c88cSJim Ingham } 16101b54c88cSJim Ingham } 16111b54c88cSJim Ingham else 16121b54c88cSJim Ingham { 1613e0a97848SJim Ingham if (m_options.m_thread_id_passed) 16141b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 16151b54c88cSJim Ingham 1616e0a97848SJim Ingham if (m_options.m_thread_index_passed) 1617e6bc6cb9SJim Ingham bp->SetThreadIndex(m_options.m_thread_index); 16181b54c88cSJim Ingham 1619b2a38a72SJim Ingham if (m_options.m_name_passed) 1620e6bc6cb9SJim Ingham bp->SetThreadName(m_options.m_thread_name.c_str()); 16211b54c88cSJim Ingham 1622b2a38a72SJim Ingham if (m_options.m_queue_passed) 1623e6bc6cb9SJim Ingham bp->SetQueueName(m_options.m_queue_name.c_str()); 16241b54c88cSJim Ingham 1625c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 1626e6bc6cb9SJim Ingham bp->SetIgnoreCount(m_options.m_ignore_count); 1627ae1c4cf5SJim Ingham 1628ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1629ae1c4cf5SJim Ingham bp->SetEnabled (m_options.m_enable_value); 1630ae1c4cf5SJim Ingham 163136f3b369SJim Ingham if (m_options.m_condition_passed) 163236f3b369SJim Ingham bp->SetCondition (m_options.m_condition.c_str()); 16331b54c88cSJim Ingham } 16341b54c88cSJim Ingham } 16351b54c88cSJim Ingham } 16361b54c88cSJim Ingham } 16371b54c88cSJim Ingham 16381b54c88cSJim Ingham return result.Succeeded(); 16391b54c88cSJim Ingham } 16401b54c88cSJim Ingham 16411b54c88cSJim Ingham 1642