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 3130fdc8d8SChris Lattner using namespace lldb; 3230fdc8d8SChris Lattner using namespace lldb_private; 3330fdc8d8SChris Lattner 3430fdc8d8SChris Lattner static void 356611103cSGreg Clayton AddBreakpointDescription (StreamString *s, Breakpoint *bp, lldb::DescriptionLevel level) 3630fdc8d8SChris Lattner { 3730fdc8d8SChris Lattner s->IndentMore(); 3830fdc8d8SChris Lattner bp->GetDescription (s, level, true); 3930fdc8d8SChris Lattner s->IndentLess(); 4030fdc8d8SChris Lattner s->EOL(); 4130fdc8d8SChris Lattner } 4230fdc8d8SChris Lattner 4330fdc8d8SChris Lattner //------------------------------------------------------------------------- 4430fdc8d8SChris Lattner // CommandObjectBreakpointSet::CommandOptions 4530fdc8d8SChris Lattner //------------------------------------------------------------------------- 46ae1c4cf5SJim Ingham #pragma mark Set::CommandOptions 4730fdc8d8SChris Lattner 4830fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::CommandOptions() : 4930fdc8d8SChris Lattner Options (), 5030fdc8d8SChris Lattner m_filename (), 5130fdc8d8SChris Lattner m_line_num (0), 5230fdc8d8SChris Lattner m_column (0), 5330fdc8d8SChris Lattner m_ignore_inlines (false), 5430fdc8d8SChris Lattner m_func_name (), 550c5cd90dSGreg Clayton m_func_name_type_mask (0), 5630fdc8d8SChris Lattner m_func_regexp (), 5730fdc8d8SChris Lattner m_modules (), 581b54c88cSJim Ingham m_load_addr(), 59c982c768SGreg Clayton m_ignore_count (0), 601b54c88cSJim Ingham m_thread_id(LLDB_INVALID_THREAD_ID), 61c982c768SGreg Clayton m_thread_index (UINT32_MAX), 621b54c88cSJim Ingham m_thread_name(), 63c982c768SGreg Clayton m_queue_name() 6430fdc8d8SChris Lattner { 6530fdc8d8SChris Lattner } 6630fdc8d8SChris Lattner 6730fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::~CommandOptions () 6830fdc8d8SChris Lattner { 6930fdc8d8SChris Lattner } 7030fdc8d8SChris Lattner 7130fdc8d8SChris Lattner lldb::OptionDefinition 7230fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::g_option_table[] = 7330fdc8d8SChris Lattner { 74deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName, 758651121cSJim Ingham "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."}, 768651121cSJim Ingham 77deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount, 78deaab222SCaroline Tice "Set the number of times this breakpoint is skipped before stopping." }, 791b54c88cSJim Ingham 80deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex, 81ed8a705cSGreg Clayton "The breakpoint stops only for the thread whose index matches this argument."}, 821b54c88cSJim Ingham 83deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, eArgTypeThreadID, 841b54c88cSJim Ingham "The breakpoint stops only for the thread whose TID matches this argument."}, 851b54c88cSJim Ingham 86deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, eArgTypeThreadName, 871b54c88cSJim Ingham "The breakpoint stops only for the thread whose thread name matches this argument."}, 881b54c88cSJim Ingham 89deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, eArgTypeQueueName, 901b54c88cSJim Ingham "The breakpoint stops only for threads in the queue whose name is given by this argument."}, 911b54c88cSJim Ingham 92deaab222SCaroline Tice { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, 9330fdc8d8SChris Lattner "Set the breakpoint by source location in this particular file."}, 9430fdc8d8SChris Lattner 95deaab222SCaroline Tice { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, 9630fdc8d8SChris Lattner "Set the breakpoint by source location at this particular line."}, 9730fdc8d8SChris Lattner 9830fdc8d8SChris Lattner // Comment out this option for the moment, as we don't actually use it, but will in the future. 9930fdc8d8SChris Lattner // This way users won't see it, but the infrastructure is left in place. 10030fdc8d8SChris Lattner // { 0, false, "column", 'c', required_argument, NULL, "<column>", 10130fdc8d8SChris Lattner // "Set the breakpoint by source location at this particular column."}, 10230fdc8d8SChris Lattner 103deaab222SCaroline Tice { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, 10430fdc8d8SChris Lattner "Set the breakpoint by address, at the specified address."}, 10530fdc8d8SChris Lattner 106deaab222SCaroline Tice { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, 107e02b8504SGreg Clayton "Set the breakpoint by function name." }, 10830fdc8d8SChris Lattner 109deaab222SCaroline Tice { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName, 1102561aa61SJim Ingham "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguemnts, and " 1112561aa61SJim Ingham "for Objective C this means a full function prototype with class and selector." }, 1120c5cd90dSGreg Clayton 113deaab222SCaroline Tice { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector, 1142561aa61SJim Ingham "Set the breakpoint by ObjC selector name." }, 1150c5cd90dSGreg Clayton 116deaab222SCaroline Tice { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod, 1172561aa61SJim Ingham "Set the breakpoint by C++ method names." }, 1180c5cd90dSGreg Clayton 119deaab222SCaroline Tice { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression, 12030fdc8d8SChris Lattner "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." }, 12130fdc8d8SChris Lattner 122e02b8504SGreg Clayton { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, 123e02b8504SGreg Clayton "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored)." }, 124e02b8504SGreg Clayton 125deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 12630fdc8d8SChris Lattner }; 12730fdc8d8SChris Lattner 12830fdc8d8SChris Lattner const lldb::OptionDefinition* 12930fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::GetDefinitions () 13030fdc8d8SChris Lattner { 13130fdc8d8SChris Lattner return g_option_table; 13230fdc8d8SChris Lattner } 13330fdc8d8SChris Lattner 13430fdc8d8SChris Lattner Error 13530fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) 13630fdc8d8SChris Lattner { 13730fdc8d8SChris Lattner Error error; 13830fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 13930fdc8d8SChris Lattner 14030fdc8d8SChris Lattner switch (short_option) 14130fdc8d8SChris Lattner { 14230fdc8d8SChris Lattner case 'a': 14330fdc8d8SChris Lattner m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 0); 14430fdc8d8SChris Lattner if (m_load_addr == LLDB_INVALID_ADDRESS) 14530fdc8d8SChris Lattner m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 16); 14630fdc8d8SChris Lattner 14730fdc8d8SChris Lattner if (m_load_addr == LLDB_INVALID_ADDRESS) 14830fdc8d8SChris Lattner error.SetErrorStringWithFormat ("Invalid address string '%s'.\n", optarg); 14930fdc8d8SChris Lattner break; 15030fdc8d8SChris Lattner 15130fdc8d8SChris Lattner case 'c': 15230fdc8d8SChris Lattner m_column = Args::StringToUInt32 (option_arg, 0); 15330fdc8d8SChris Lattner break; 1540c5cd90dSGreg Clayton 15530fdc8d8SChris Lattner case 'f': 15630fdc8d8SChris Lattner m_filename = option_arg; 15730fdc8d8SChris Lattner break; 1580c5cd90dSGreg Clayton 15930fdc8d8SChris Lattner case 'l': 16030fdc8d8SChris Lattner m_line_num = Args::StringToUInt32 (option_arg, 0); 16130fdc8d8SChris Lattner break; 1620c5cd90dSGreg Clayton 163e02b8504SGreg Clayton case 'b': 16430fdc8d8SChris Lattner m_func_name = option_arg; 1650c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeBase; 1660c5cd90dSGreg Clayton break; 1670c5cd90dSGreg Clayton 168e02b8504SGreg Clayton case 'n': 169e02b8504SGreg Clayton m_func_name = option_arg; 170e02b8504SGreg Clayton m_func_name_type_mask |= eFunctionNameTypeAuto; 171e02b8504SGreg Clayton break; 172e02b8504SGreg Clayton 1730c5cd90dSGreg Clayton case 'F': 1742561aa61SJim Ingham m_func_name = option_arg; 1750c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeFull; 1760c5cd90dSGreg Clayton break; 1770c5cd90dSGreg Clayton 1780c5cd90dSGreg Clayton case 'S': 1792561aa61SJim Ingham m_func_name = option_arg; 1800c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeSelector; 1810c5cd90dSGreg Clayton break; 1820c5cd90dSGreg Clayton 1832561aa61SJim Ingham case 'M': 1842561aa61SJim Ingham m_func_name = option_arg; 1850c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeMethod; 1860c5cd90dSGreg Clayton break; 1870c5cd90dSGreg Clayton 18830fdc8d8SChris Lattner case 'r': 18930fdc8d8SChris Lattner m_func_regexp = option_arg; 19030fdc8d8SChris Lattner break; 1910c5cd90dSGreg Clayton 19230fdc8d8SChris Lattner case 's': 19330fdc8d8SChris Lattner { 19430fdc8d8SChris Lattner m_modules.push_back (std::string (option_arg)); 19530fdc8d8SChris Lattner break; 19630fdc8d8SChris Lattner } 197ed8a705cSGreg Clayton case 'i': 1981b54c88cSJim Ingham { 199c982c768SGreg Clayton m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0); 200c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 2011b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg); 2021b54c88cSJim Ingham } 203ae1c4cf5SJim Ingham break; 2041b54c88cSJim Ingham case 't' : 2051b54c88cSJim Ingham { 2061b54c88cSJim Ingham m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0); 2071b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 2081b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg); 2091b54c88cSJim Ingham } 2101b54c88cSJim Ingham break; 2111b54c88cSJim Ingham case 'T': 2121b54c88cSJim Ingham m_thread_name = option_arg; 2131b54c88cSJim Ingham break; 2141b54c88cSJim Ingham case 'q': 2151b54c88cSJim Ingham m_queue_name = option_arg; 2161b54c88cSJim Ingham break; 2171b54c88cSJim Ingham case 'x': 2181b54c88cSJim Ingham { 219c982c768SGreg Clayton m_thread_index = Args::StringToUInt32(optarg, UINT32_MAX, 0); 220c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 2211b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg); 2221b54c88cSJim Ingham 2231b54c88cSJim Ingham } 2241b54c88cSJim Ingham break; 22530fdc8d8SChris Lattner default: 22630fdc8d8SChris Lattner error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 22730fdc8d8SChris Lattner break; 22830fdc8d8SChris Lattner } 22930fdc8d8SChris Lattner 23030fdc8d8SChris Lattner return error; 23130fdc8d8SChris Lattner } 23230fdc8d8SChris Lattner 23330fdc8d8SChris Lattner void 23430fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::ResetOptionValues () 23530fdc8d8SChris Lattner { 23630fdc8d8SChris Lattner Options::ResetOptionValues(); 23730fdc8d8SChris Lattner 23830fdc8d8SChris Lattner m_filename.clear(); 23930fdc8d8SChris Lattner m_line_num = 0; 24030fdc8d8SChris Lattner m_column = 0; 24130fdc8d8SChris Lattner m_func_name.clear(); 2420c5cd90dSGreg Clayton m_func_name_type_mask = 0; 24330fdc8d8SChris Lattner m_func_regexp.clear(); 24430fdc8d8SChris Lattner m_load_addr = LLDB_INVALID_ADDRESS; 24530fdc8d8SChris Lattner m_modules.clear(); 246c982c768SGreg Clayton m_ignore_count = 0; 2471b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 248c982c768SGreg Clayton m_thread_index = UINT32_MAX; 2491b54c88cSJim Ingham m_thread_name.clear(); 2501b54c88cSJim Ingham m_queue_name.clear(); 25130fdc8d8SChris Lattner } 25230fdc8d8SChris Lattner 25330fdc8d8SChris Lattner //------------------------------------------------------------------------- 25430fdc8d8SChris Lattner // CommandObjectBreakpointSet 25530fdc8d8SChris Lattner //------------------------------------------------------------------------- 256ae1c4cf5SJim Ingham #pragma mark Set 25730fdc8d8SChris Lattner 258a7015092SGreg Clayton CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) : 259a7015092SGreg Clayton CommandObject (interpreter, 260a7015092SGreg Clayton "breakpoint set", 261a7015092SGreg Clayton "Sets a breakpoint or set of breakpoints in the executable.", 26230fdc8d8SChris Lattner "breakpoint set <cmd-options>") 26330fdc8d8SChris Lattner { 26430fdc8d8SChris Lattner } 26530fdc8d8SChris Lattner 26630fdc8d8SChris Lattner CommandObjectBreakpointSet::~CommandObjectBreakpointSet () 26730fdc8d8SChris Lattner { 26830fdc8d8SChris Lattner } 26930fdc8d8SChris Lattner 27030fdc8d8SChris Lattner Options * 27130fdc8d8SChris Lattner CommandObjectBreakpointSet::GetOptions () 27230fdc8d8SChris Lattner { 27330fdc8d8SChris Lattner return &m_options; 27430fdc8d8SChris Lattner } 27530fdc8d8SChris Lattner 27630fdc8d8SChris Lattner bool 27730fdc8d8SChris Lattner CommandObjectBreakpointSet::Execute 27830fdc8d8SChris Lattner ( 27930fdc8d8SChris Lattner Args& command, 28030fdc8d8SChris Lattner CommandReturnObject &result 28130fdc8d8SChris Lattner ) 28230fdc8d8SChris Lattner { 283a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 28430fdc8d8SChris Lattner if (target == NULL) 28530fdc8d8SChris Lattner { 2869068d794SCaroline Tice result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'file' command)."); 28730fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 28830fdc8d8SChris Lattner return false; 28930fdc8d8SChris Lattner } 29030fdc8d8SChris Lattner 29130fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 29230fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 29330fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 29430fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 29530fdc8d8SChris Lattner // 4). -r [-s -g] (setting breakpoint by function name regular expression) 29630fdc8d8SChris Lattner 29730fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 29830fdc8d8SChris Lattner 29930fdc8d8SChris Lattner if (m_options.m_line_num != 0) 30030fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 30130fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 30230fdc8d8SChris Lattner break_type = eSetTypeAddress; 30330fdc8d8SChris Lattner else if (!m_options.m_func_name.empty()) 30430fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 30530fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 30630fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 30730fdc8d8SChris Lattner 30830fdc8d8SChris Lattner ModuleSP module_sp = target->GetExecutableModule(); 30930fdc8d8SChris Lattner Breakpoint *bp = NULL; 31030fdc8d8SChris Lattner FileSpec module; 31130fdc8d8SChris Lattner bool use_module = false; 31230fdc8d8SChris Lattner int num_modules = m_options.m_modules.size(); 31330fdc8d8SChris Lattner 31430fdc8d8SChris Lattner if ((num_modules > 0) && (break_type != eSetTypeAddress)) 31530fdc8d8SChris Lattner use_module = true; 31630fdc8d8SChris Lattner 31730fdc8d8SChris Lattner switch (break_type) 31830fdc8d8SChris Lattner { 31930fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 32030fdc8d8SChris Lattner { 32130fdc8d8SChris Lattner FileSpec file; 32230fdc8d8SChris Lattner if (m_options.m_filename.empty()) 32330fdc8d8SChris Lattner { 324a7015092SGreg Clayton StackFrame *cur_frame = m_interpreter.GetDebugger().GetExecutionContext().frame; 32530fdc8d8SChris Lattner if (cur_frame == NULL) 32630fdc8d8SChris Lattner { 32730fdc8d8SChris Lattner result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame."); 32830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 32930fdc8d8SChris Lattner break; 33030fdc8d8SChris Lattner } 33130fdc8d8SChris Lattner else if (!cur_frame->HasDebugInformation()) 33230fdc8d8SChris Lattner { 33330fdc8d8SChris Lattner result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info."); 33430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 33530fdc8d8SChris Lattner break; 33630fdc8d8SChris Lattner } 33730fdc8d8SChris Lattner else 33830fdc8d8SChris Lattner { 33930fdc8d8SChris Lattner const SymbolContext &context = cur_frame->GetSymbolContext(true); 34030fdc8d8SChris Lattner if (context.line_entry.file) 34130fdc8d8SChris Lattner { 34230fdc8d8SChris Lattner file = context.line_entry.file; 34330fdc8d8SChris Lattner } 34430fdc8d8SChris Lattner else if (context.comp_unit != NULL) 34530fdc8d8SChris Lattner { file = context.comp_unit; 34630fdc8d8SChris Lattner } 34730fdc8d8SChris Lattner else 34830fdc8d8SChris Lattner { 34930fdc8d8SChris Lattner result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame."); 35030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 35130fdc8d8SChris Lattner break; 35230fdc8d8SChris Lattner } 35330fdc8d8SChris Lattner } 35430fdc8d8SChris Lattner } 35530fdc8d8SChris Lattner else 35630fdc8d8SChris Lattner { 35730fdc8d8SChris Lattner file.SetFile(m_options.m_filename.c_str()); 35830fdc8d8SChris Lattner } 35930fdc8d8SChris Lattner 36030fdc8d8SChris Lattner if (use_module) 36130fdc8d8SChris Lattner { 36230fdc8d8SChris Lattner for (int i = 0; i < num_modules; ++i) 36330fdc8d8SChris Lattner { 36430fdc8d8SChris Lattner module.SetFile(m_options.m_modules[i].c_str()); 36530fdc8d8SChris Lattner bp = target->CreateBreakpoint (&module, 36630fdc8d8SChris Lattner file, 36730fdc8d8SChris Lattner m_options.m_line_num, 36830fdc8d8SChris Lattner m_options.m_ignore_inlines).get(); 36930fdc8d8SChris Lattner if (bp) 37030fdc8d8SChris Lattner { 37130fdc8d8SChris Lattner StreamString &output_stream = result.GetOutputStream(); 37230fdc8d8SChris Lattner output_stream.Printf ("Breakpoint created: "); 37330fdc8d8SChris Lattner bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); 37430fdc8d8SChris Lattner output_stream.EOL(); 37530fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 37630fdc8d8SChris Lattner } 37730fdc8d8SChris Lattner else 37830fdc8d8SChris Lattner { 37930fdc8d8SChris Lattner result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n", 38030fdc8d8SChris Lattner m_options.m_modules[i].c_str()); 38130fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 38230fdc8d8SChris Lattner } 38330fdc8d8SChris Lattner } 38430fdc8d8SChris Lattner } 38530fdc8d8SChris Lattner else 38630fdc8d8SChris Lattner bp = target->CreateBreakpoint (NULL, 38730fdc8d8SChris Lattner file, 38830fdc8d8SChris Lattner m_options.m_line_num, 38930fdc8d8SChris Lattner m_options.m_ignore_inlines).get(); 39030fdc8d8SChris Lattner } 39130fdc8d8SChris Lattner break; 3926eee5aa0SGreg Clayton 39330fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 39430fdc8d8SChris Lattner bp = target->CreateBreakpoint (m_options.m_load_addr, false).get(); 39530fdc8d8SChris Lattner break; 3960c5cd90dSGreg Clayton 39730fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 3980c5cd90dSGreg Clayton { 3990c5cd90dSGreg Clayton uint32_t name_type_mask = m_options.m_func_name_type_mask; 4000c5cd90dSGreg Clayton 4010c5cd90dSGreg Clayton if (name_type_mask == 0) 402e02b8504SGreg Clayton name_type_mask = eFunctionNameTypeAuto; 4030c5cd90dSGreg Clayton 40430fdc8d8SChris Lattner if (use_module) 40530fdc8d8SChris Lattner { 40630fdc8d8SChris Lattner for (int i = 0; i < num_modules; ++i) 40730fdc8d8SChris Lattner { 40830fdc8d8SChris Lattner module.SetFile(m_options.m_modules[i].c_str()); 4090c5cd90dSGreg Clayton bp = target->CreateBreakpoint (&module, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get(); 41030fdc8d8SChris Lattner if (bp) 41130fdc8d8SChris Lattner { 41230fdc8d8SChris Lattner StreamString &output_stream = result.GetOutputStream(); 41330fdc8d8SChris Lattner output_stream.Printf ("Breakpoint created: "); 41430fdc8d8SChris Lattner bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); 41530fdc8d8SChris Lattner output_stream.EOL(); 41630fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 41730fdc8d8SChris Lattner } 41830fdc8d8SChris Lattner else 41930fdc8d8SChris Lattner { 42030fdc8d8SChris Lattner result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n", 42130fdc8d8SChris Lattner m_options.m_modules[i].c_str()); 42230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 42330fdc8d8SChris Lattner } 42430fdc8d8SChris Lattner } 42530fdc8d8SChris Lattner } 42630fdc8d8SChris Lattner else 4270c5cd90dSGreg Clayton bp = target->CreateBreakpoint (NULL, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get(); 4280c5cd90dSGreg Clayton } 42930fdc8d8SChris Lattner break; 4300c5cd90dSGreg Clayton 43130fdc8d8SChris Lattner case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name 43230fdc8d8SChris Lattner { 43330fdc8d8SChris Lattner RegularExpression regexp(m_options.m_func_regexp.c_str()); 43430fdc8d8SChris Lattner if (use_module) 43530fdc8d8SChris Lattner { 43630fdc8d8SChris Lattner for (int i = 0; i < num_modules; ++i) 43730fdc8d8SChris Lattner { 43830fdc8d8SChris Lattner module.SetFile(m_options.m_modules[i].c_str()); 43930fdc8d8SChris Lattner bp = target->CreateBreakpoint (&module, regexp).get(); 44030fdc8d8SChris Lattner if (bp) 44130fdc8d8SChris Lattner { 44230fdc8d8SChris Lattner StreamString &output_stream = result.GetOutputStream(); 44330fdc8d8SChris Lattner output_stream.Printf ("Breakpoint created: "); 44430fdc8d8SChris Lattner bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); 44530fdc8d8SChris Lattner output_stream.EOL(); 44630fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 44730fdc8d8SChris Lattner } 44830fdc8d8SChris Lattner else 44930fdc8d8SChris Lattner { 45030fdc8d8SChris Lattner result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n", 45130fdc8d8SChris Lattner m_options.m_modules[i].c_str()); 45230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 45330fdc8d8SChris Lattner } 45430fdc8d8SChris Lattner } 45530fdc8d8SChris Lattner } 45630fdc8d8SChris Lattner else 45730fdc8d8SChris Lattner bp = target->CreateBreakpoint (NULL, regexp).get(); 45830fdc8d8SChris Lattner } 45930fdc8d8SChris Lattner break; 4600c5cd90dSGreg Clayton 46130fdc8d8SChris Lattner default: 46230fdc8d8SChris Lattner break; 46330fdc8d8SChris Lattner } 46430fdc8d8SChris Lattner 4651b54c88cSJim Ingham // Now set the various options that were passed in: 4661b54c88cSJim Ingham if (bp) 4671b54c88cSJim Ingham { 4681b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 4691b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 4701b54c88cSJim Ingham 471c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 4721b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 4731b54c88cSJim Ingham 4741b54c88cSJim Ingham if (!m_options.m_thread_name.empty()) 4751b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 4761b54c88cSJim Ingham 4771b54c88cSJim Ingham if (!m_options.m_queue_name.empty()) 4781b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 4791b54c88cSJim Ingham 480c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 4811b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 4821b54c88cSJim Ingham } 4831b54c88cSJim Ingham 48430fdc8d8SChris Lattner if (bp && !use_module) 48530fdc8d8SChris Lattner { 48630fdc8d8SChris Lattner StreamString &output_stream = result.GetOutputStream(); 48730fdc8d8SChris Lattner output_stream.Printf ("Breakpoint created: "); 48830fdc8d8SChris Lattner bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); 48930fdc8d8SChris Lattner output_stream.EOL(); 49030fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 49130fdc8d8SChris Lattner } 49230fdc8d8SChris Lattner else if (!bp) 49330fdc8d8SChris Lattner { 49430fdc8d8SChris Lattner result.AppendError ("Breakpoint creation failed: No breakpoint created."); 49530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 49630fdc8d8SChris Lattner } 49730fdc8d8SChris Lattner 49830fdc8d8SChris Lattner return result.Succeeded(); 49930fdc8d8SChris Lattner } 50030fdc8d8SChris Lattner 50130fdc8d8SChris Lattner //------------------------------------------------------------------------- 50230fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 50330fdc8d8SChris Lattner //------------------------------------------------------------------------- 504ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 50530fdc8d8SChris Lattner 5066611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) : 507a7015092SGreg Clayton CommandObjectMultiword (interpreter, 508a7015092SGreg Clayton "breakpoint", 5093f4c09c1SCaroline Tice "A set of commands for operating on breakpoints. Also see regexp-break.", 51030fdc8d8SChris Lattner "breakpoint <command> [<command-options>]") 51130fdc8d8SChris Lattner { 51230fdc8d8SChris Lattner bool status; 51330fdc8d8SChris Lattner 514a7015092SGreg Clayton CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter)); 515a7015092SGreg Clayton CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter)); 516a7015092SGreg Clayton CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter)); 517a7015092SGreg Clayton CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter)); 518a7015092SGreg Clayton CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter)); 51930fdc8d8SChris Lattner CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter)); 520a7015092SGreg Clayton CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter)); 52130fdc8d8SChris Lattner 522ae1c4cf5SJim Ingham command_command_object->SetCommandName ("breakpoint command"); 52330fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 52430fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 52530fdc8d8SChris Lattner list_command_object->SetCommandName ("breakpoint list"); 526ae1c4cf5SJim Ingham modify_command_object->SetCommandName ("breakpoint modify"); 527ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 52830fdc8d8SChris Lattner 529a7015092SGreg Clayton status = LoadSubCommand ("list", list_command_object); 530a7015092SGreg Clayton status = LoadSubCommand ("enable", enable_command_object); 531a7015092SGreg Clayton status = LoadSubCommand ("disable", disable_command_object); 532a7015092SGreg Clayton status = LoadSubCommand ("delete", delete_command_object); 533a7015092SGreg Clayton status = LoadSubCommand ("set", set_command_object); 534a7015092SGreg Clayton status = LoadSubCommand ("command", command_command_object); 535a7015092SGreg Clayton status = LoadSubCommand ("modify", modify_command_object); 53630fdc8d8SChris Lattner } 53730fdc8d8SChris Lattner 53830fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint () 53930fdc8d8SChris Lattner { 54030fdc8d8SChris Lattner } 54130fdc8d8SChris Lattner 54230fdc8d8SChris Lattner void 54330fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result, 54430fdc8d8SChris Lattner BreakpointIDList *valid_ids) 54530fdc8d8SChris Lattner { 54630fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 54730fdc8d8SChris Lattner // 2). the full breakpoint & location canonical representation 54830fdc8d8SChris Lattner // 3). the word "to" or a hyphen, representing a range (in which case there 54930fdc8d8SChris Lattner // had *better* be an entry both before & after of one of the first two types. 550*36f3b369SJim Ingham // If args is empty, we will use the last created breakpoint (if there is one.) 55130fdc8d8SChris Lattner 55230fdc8d8SChris Lattner Args temp_args; 55330fdc8d8SChris Lattner 554*36f3b369SJim Ingham if (args.GetArgumentCount() == 0) 555*36f3b369SJim Ingham { 556*36f3b369SJim Ingham if (target->GetLastCreatedBreakpoint() != NULL) 557*36f3b369SJim Ingham { 558*36f3b369SJim Ingham valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); 559*36f3b369SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 560*36f3b369SJim Ingham } 561*36f3b369SJim Ingham else 562*36f3b369SJim Ingham { 563*36f3b369SJim Ingham result.AppendError("No breakpoint specified and no last created breakpoint."); 564*36f3b369SJim Ingham result.SetStatus (eReturnStatusFailed); 565*36f3b369SJim Ingham } 566*36f3b369SJim Ingham return; 567*36f3b369SJim Ingham } 568*36f3b369SJim Ingham 56930fdc8d8SChris Lattner // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to 57030fdc8d8SChris Lattner // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for 57130fdc8d8SChris Lattner // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS. 57230fdc8d8SChris Lattner 57330fdc8d8SChris Lattner BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args); 57430fdc8d8SChris Lattner 57530fdc8d8SChris Lattner // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList: 57630fdc8d8SChris Lattner 577c982c768SGreg Clayton valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result); 57830fdc8d8SChris Lattner 57930fdc8d8SChris Lattner // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs 58030fdc8d8SChris Lattner // and put into valid_ids. 58130fdc8d8SChris Lattner 58230fdc8d8SChris Lattner if (result.Succeeded()) 58330fdc8d8SChris Lattner { 58430fdc8d8SChris Lattner // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list 58530fdc8d8SChris Lattner // of breakpoint id's and verify that they correspond to valid/currently set breakpoints. 58630fdc8d8SChris Lattner 587c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 588c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 58930fdc8d8SChris Lattner { 59030fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i); 59130fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 59230fdc8d8SChris Lattner if (breakpoint != NULL) 59330fdc8d8SChris Lattner { 59430fdc8d8SChris Lattner int num_locations = breakpoint->GetNumLocations(); 59530fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() > num_locations) 59630fdc8d8SChris Lattner { 59730fdc8d8SChris Lattner StreamString id_str; 598c982c768SGreg Clayton BreakpointID::GetCanonicalReference (&id_str, 599c982c768SGreg Clayton cur_bp_id.GetBreakpointID(), 60030fdc8d8SChris Lattner cur_bp_id.GetLocationID()); 601c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 60230fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n", 60330fdc8d8SChris Lattner id_str.GetData()); 60430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 60530fdc8d8SChris Lattner } 60630fdc8d8SChris Lattner } 60730fdc8d8SChris Lattner else 60830fdc8d8SChris Lattner { 609c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 61030fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID()); 61130fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 61230fdc8d8SChris Lattner } 61330fdc8d8SChris Lattner } 61430fdc8d8SChris Lattner } 61530fdc8d8SChris Lattner } 61630fdc8d8SChris Lattner 61730fdc8d8SChris Lattner //------------------------------------------------------------------------- 61830fdc8d8SChris Lattner // CommandObjectBreakpointList::Options 61930fdc8d8SChris Lattner //------------------------------------------------------------------------- 620ae1c4cf5SJim Ingham #pragma mark List::CommandOptions 62130fdc8d8SChris Lattner 62230fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::CommandOptions() : 62330fdc8d8SChris Lattner Options (), 62430fdc8d8SChris Lattner m_level (lldb::eDescriptionLevelFull) // Breakpoint List defaults to brief descriptions 62530fdc8d8SChris Lattner { 62630fdc8d8SChris Lattner } 62730fdc8d8SChris Lattner 62830fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::~CommandOptions () 62930fdc8d8SChris Lattner { 63030fdc8d8SChris Lattner } 63130fdc8d8SChris Lattner 63230fdc8d8SChris Lattner lldb::OptionDefinition 63330fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::g_option_table[] = 63430fdc8d8SChris Lattner { 635deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone, 6368651121cSJim Ingham "Show debugger internal breakpoints" }, 6378651121cSJim Ingham 638deaab222SCaroline Tice { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone, 63930fdc8d8SChris Lattner "Give a brief description of the breakpoint (no location info)."}, 64030fdc8d8SChris Lattner 64130fdc8d8SChris Lattner // FIXME: We need to add an "internal" command, and then add this sort of thing to it. 64230fdc8d8SChris Lattner // But I need to see it for now, and don't want to wait. 643deaab222SCaroline Tice { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone, 64430fdc8d8SChris Lattner "Give a full description of the breakpoint and its locations."}, 64530fdc8d8SChris Lattner 646deaab222SCaroline Tice { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, 64730fdc8d8SChris Lattner "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, 64830fdc8d8SChris Lattner 649deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 65030fdc8d8SChris Lattner }; 65130fdc8d8SChris Lattner 65230fdc8d8SChris Lattner const lldb::OptionDefinition* 65330fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::GetDefinitions () 65430fdc8d8SChris Lattner { 65530fdc8d8SChris Lattner return g_option_table; 65630fdc8d8SChris Lattner } 65730fdc8d8SChris Lattner 65830fdc8d8SChris Lattner Error 65930fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) 66030fdc8d8SChris Lattner { 66130fdc8d8SChris Lattner Error error; 66230fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 66330fdc8d8SChris Lattner 66430fdc8d8SChris Lattner switch (short_option) 66530fdc8d8SChris Lattner { 66630fdc8d8SChris Lattner case 'b': 66730fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelBrief; 66830fdc8d8SChris Lattner break; 66930fdc8d8SChris Lattner case 'f': 67030fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelFull; 67130fdc8d8SChris Lattner break; 67230fdc8d8SChris Lattner case 'v': 67330fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelVerbose; 67430fdc8d8SChris Lattner break; 67530fdc8d8SChris Lattner case 'i': 67630fdc8d8SChris Lattner m_internal = true; 67730fdc8d8SChris Lattner break; 67830fdc8d8SChris Lattner default: 67930fdc8d8SChris Lattner error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 68030fdc8d8SChris Lattner break; 68130fdc8d8SChris Lattner } 68230fdc8d8SChris Lattner 68330fdc8d8SChris Lattner return error; 68430fdc8d8SChris Lattner } 68530fdc8d8SChris Lattner 68630fdc8d8SChris Lattner void 68730fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::ResetOptionValues () 68830fdc8d8SChris Lattner { 68930fdc8d8SChris Lattner Options::ResetOptionValues(); 69030fdc8d8SChris Lattner 69130fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelFull; 69230fdc8d8SChris Lattner m_internal = false; 69330fdc8d8SChris Lattner } 69430fdc8d8SChris Lattner 69530fdc8d8SChris Lattner //------------------------------------------------------------------------- 69630fdc8d8SChris Lattner // CommandObjectBreakpointList 69730fdc8d8SChris Lattner //------------------------------------------------------------------------- 698ae1c4cf5SJim Ingham #pragma mark List 69930fdc8d8SChris Lattner 700a7015092SGreg Clayton CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) : 701a7015092SGreg Clayton CommandObject (interpreter, 702a7015092SGreg Clayton "breakpoint list", 70330fdc8d8SChris Lattner "List some or all breakpoints at configurable levels of detail.", 704e139cf23SCaroline Tice NULL) 70530fdc8d8SChris Lattner { 706e139cf23SCaroline Tice CommandArgumentEntry arg; 707e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 708e139cf23SCaroline Tice 709e139cf23SCaroline Tice // Define the first (and only) variant of this arg. 710e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 711405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 712e139cf23SCaroline Tice 713e139cf23SCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 714e139cf23SCaroline Tice arg.push_back (bp_id_arg); 715e139cf23SCaroline Tice 716e139cf23SCaroline Tice // Push the data for the first argument into the m_arguments vector. 717e139cf23SCaroline Tice m_arguments.push_back (arg); 71830fdc8d8SChris Lattner } 71930fdc8d8SChris Lattner 72030fdc8d8SChris Lattner CommandObjectBreakpointList::~CommandObjectBreakpointList () 72130fdc8d8SChris Lattner { 72230fdc8d8SChris Lattner } 72330fdc8d8SChris Lattner 72430fdc8d8SChris Lattner Options * 72530fdc8d8SChris Lattner CommandObjectBreakpointList::GetOptions () 72630fdc8d8SChris Lattner { 72730fdc8d8SChris Lattner return &m_options; 72830fdc8d8SChris Lattner } 72930fdc8d8SChris Lattner 73030fdc8d8SChris Lattner bool 73130fdc8d8SChris Lattner CommandObjectBreakpointList::Execute 73230fdc8d8SChris Lattner ( 73330fdc8d8SChris Lattner Args& args, 73430fdc8d8SChris Lattner CommandReturnObject &result 73530fdc8d8SChris Lattner ) 73630fdc8d8SChris Lattner { 737a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 73830fdc8d8SChris Lattner if (target == NULL) 73930fdc8d8SChris Lattner { 7409068d794SCaroline Tice result.AppendError ("Invalid target. No current target or breakpoints."); 74130fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 74230fdc8d8SChris Lattner return true; 74330fdc8d8SChris Lattner } 74430fdc8d8SChris Lattner 74530fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal); 7461b54c88cSJim Ingham Mutex::Locker locker; 7471b54c88cSJim Ingham target->GetBreakpointList(m_options.m_internal).GetListMutex(locker); 7481b54c88cSJim Ingham 74930fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 75030fdc8d8SChris Lattner 75130fdc8d8SChris Lattner if (num_breakpoints == 0) 75230fdc8d8SChris Lattner { 75330fdc8d8SChris Lattner result.AppendMessage ("No breakpoints currently set."); 75430fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 75530fdc8d8SChris Lattner return true; 75630fdc8d8SChris Lattner } 75730fdc8d8SChris Lattner 75830fdc8d8SChris Lattner StreamString &output_stream = result.GetOutputStream(); 75930fdc8d8SChris Lattner 76030fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 76130fdc8d8SChris Lattner { 76230fdc8d8SChris Lattner // No breakpoint selected; show info about all currently set breakpoints. 76330fdc8d8SChris Lattner result.AppendMessage ("Current breakpoints:"); 764c982c768SGreg Clayton for (size_t i = 0; i < num_breakpoints; ++i) 76530fdc8d8SChris Lattner { 7669fed0d85SGreg Clayton Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get(); 7676611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 76830fdc8d8SChris Lattner } 76930fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 77030fdc8d8SChris Lattner } 77130fdc8d8SChris Lattner else 77230fdc8d8SChris Lattner { 77330fdc8d8SChris Lattner // Particular breakpoints selected; show info about that breakpoint. 77430fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 77530fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 77630fdc8d8SChris Lattner 77730fdc8d8SChris Lattner if (result.Succeeded()) 77830fdc8d8SChris Lattner { 779c982c768SGreg Clayton for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) 78030fdc8d8SChris Lattner { 78130fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 78230fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 7836611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 78430fdc8d8SChris Lattner } 78530fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 78630fdc8d8SChris Lattner } 78730fdc8d8SChris Lattner else 78830fdc8d8SChris Lattner { 78930fdc8d8SChris Lattner result.AppendError ("Invalid breakpoint id."); 79030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 79130fdc8d8SChris Lattner } 79230fdc8d8SChris Lattner } 79330fdc8d8SChris Lattner 79430fdc8d8SChris Lattner return result.Succeeded(); 79530fdc8d8SChris Lattner } 79630fdc8d8SChris Lattner 79730fdc8d8SChris Lattner //------------------------------------------------------------------------- 79830fdc8d8SChris Lattner // CommandObjectBreakpointEnable 79930fdc8d8SChris Lattner //------------------------------------------------------------------------- 800ae1c4cf5SJim Ingham #pragma mark Enable 80130fdc8d8SChris Lattner 802a7015092SGreg Clayton CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) : 803a7015092SGreg Clayton CommandObject (interpreter, 804a7015092SGreg Clayton "enable", 805e3d26315SCaroline Tice "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.", 806e139cf23SCaroline Tice NULL) 80730fdc8d8SChris Lattner { 808e139cf23SCaroline Tice CommandArgumentEntry arg; 809e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 810e139cf23SCaroline Tice CommandArgumentData bp_id_range_arg; 811e139cf23SCaroline Tice 812e139cf23SCaroline Tice // Create the first variant for the first (and only) argument for this command. 813e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 814405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 815e139cf23SCaroline Tice 816e139cf23SCaroline Tice // Create the second variant for the first (and only) argument for this command. 817e139cf23SCaroline Tice bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange; 818405fe67fSCaroline Tice bp_id_range_arg.arg_repetition = eArgRepeatOptional; 819e139cf23SCaroline Tice 820e139cf23SCaroline Tice // The first (and only) argument for this command could be either a bp_id or a bp_id_range. 821e139cf23SCaroline Tice // Push both variants into the entry for the first argument for this command. 822e139cf23SCaroline Tice arg.push_back (bp_id_arg); 823e139cf23SCaroline Tice arg.push_back (bp_id_range_arg); 824e139cf23SCaroline Tice 825e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 826e139cf23SCaroline Tice m_arguments.push_back (arg); 82730fdc8d8SChris Lattner } 82830fdc8d8SChris Lattner 82930fdc8d8SChris Lattner 83030fdc8d8SChris Lattner CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable () 83130fdc8d8SChris Lattner { 83230fdc8d8SChris Lattner } 83330fdc8d8SChris Lattner 83430fdc8d8SChris Lattner 83530fdc8d8SChris Lattner bool 8366611103cSGreg Clayton CommandObjectBreakpointEnable::Execute 8376611103cSGreg Clayton ( 8386611103cSGreg Clayton Args& args, 8396611103cSGreg Clayton CommandReturnObject &result 8406611103cSGreg Clayton ) 84130fdc8d8SChris Lattner { 842a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 84330fdc8d8SChris Lattner if (target == NULL) 84430fdc8d8SChris Lattner { 8459068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 84630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 84730fdc8d8SChris Lattner return false; 84830fdc8d8SChris Lattner } 84930fdc8d8SChris Lattner 8501b54c88cSJim Ingham Mutex::Locker locker; 8511b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 8521b54c88cSJim Ingham 85330fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 8541b54c88cSJim Ingham 85530fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 85630fdc8d8SChris Lattner 85730fdc8d8SChris Lattner if (num_breakpoints == 0) 85830fdc8d8SChris Lattner { 85930fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be enabled."); 86030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 86130fdc8d8SChris Lattner return false; 86230fdc8d8SChris Lattner } 86330fdc8d8SChris Lattner 86430fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 86530fdc8d8SChris Lattner { 86630fdc8d8SChris Lattner // No breakpoint selected; enable all currently set breakpoints. 86730fdc8d8SChris Lattner target->EnableAllBreakpoints (); 86830fdc8d8SChris Lattner result.AppendMessageWithFormat ("All breakpoints enabled. (%d breakpoints)\n", num_breakpoints); 86930fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 87030fdc8d8SChris Lattner } 87130fdc8d8SChris Lattner else 87230fdc8d8SChris Lattner { 87330fdc8d8SChris Lattner // Particular breakpoint selected; enable that breakpoint. 87430fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 87530fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 87630fdc8d8SChris Lattner 87730fdc8d8SChris Lattner if (result.Succeeded()) 87830fdc8d8SChris Lattner { 87930fdc8d8SChris Lattner int enable_count = 0; 88030fdc8d8SChris Lattner int loc_count = 0; 881c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 882c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 88330fdc8d8SChris Lattner { 88430fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 88530fdc8d8SChris Lattner 88630fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 88730fdc8d8SChris Lattner { 88830fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 88930fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 89030fdc8d8SChris Lattner { 89130fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 89230fdc8d8SChris Lattner if (location) 89330fdc8d8SChris Lattner { 89430fdc8d8SChris Lattner location->SetEnabled (true); 89530fdc8d8SChris Lattner ++loc_count; 89630fdc8d8SChris Lattner } 89730fdc8d8SChris Lattner } 89830fdc8d8SChris Lattner else 89930fdc8d8SChris Lattner { 900ae1c4cf5SJim Ingham breakpoint->SetEnabled (true); 90130fdc8d8SChris Lattner ++enable_count; 90230fdc8d8SChris Lattner } 90330fdc8d8SChris Lattner } 90430fdc8d8SChris Lattner } 90530fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count); 90630fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 90730fdc8d8SChris Lattner } 90830fdc8d8SChris Lattner } 90930fdc8d8SChris Lattner 91030fdc8d8SChris Lattner return result.Succeeded(); 91130fdc8d8SChris Lattner } 91230fdc8d8SChris Lattner 91330fdc8d8SChris Lattner //------------------------------------------------------------------------- 91430fdc8d8SChris Lattner // CommandObjectBreakpointDisable 91530fdc8d8SChris Lattner //------------------------------------------------------------------------- 916ae1c4cf5SJim Ingham #pragma mark Disable 91730fdc8d8SChris Lattner 918a7015092SGreg Clayton CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) : 919a7015092SGreg Clayton CommandObject (interpreter, 920e139cf23SCaroline Tice "breakpoint disable", 921e3d26315SCaroline Tice "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.", 922e139cf23SCaroline Tice NULL) 92330fdc8d8SChris Lattner { 924e139cf23SCaroline Tice CommandArgumentEntry arg; 925e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 926e139cf23SCaroline Tice CommandArgumentData bp_id_range_arg; 927e139cf23SCaroline Tice 928e139cf23SCaroline Tice // Create the first variant for the first (and only) argument for this command. 929e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 930405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 931e139cf23SCaroline Tice 932e139cf23SCaroline Tice // Create the second variant for the first (and only) argument for this command. 933e139cf23SCaroline Tice bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange; 934405fe67fSCaroline Tice bp_id_range_arg.arg_repetition = eArgRepeatOptional; 935e139cf23SCaroline Tice 936e139cf23SCaroline Tice // The first (and only) argument for this command could be either a bp_id or a bp_id_range. 937e139cf23SCaroline Tice // Push both variants into the entry for the first argument for this command. 938e139cf23SCaroline Tice arg.push_back (bp_id_arg); 939e139cf23SCaroline Tice arg.push_back (bp_id_range_arg); 940e139cf23SCaroline Tice 941e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 942e139cf23SCaroline Tice m_arguments.push_back (arg); 94330fdc8d8SChris Lattner } 94430fdc8d8SChris Lattner 94530fdc8d8SChris Lattner CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable () 94630fdc8d8SChris Lattner { 94730fdc8d8SChris Lattner } 94830fdc8d8SChris Lattner 94930fdc8d8SChris Lattner bool 9506611103cSGreg Clayton CommandObjectBreakpointDisable::Execute 9516611103cSGreg Clayton ( 9526611103cSGreg Clayton Args& args, 9536611103cSGreg Clayton CommandReturnObject &result 9546611103cSGreg Clayton ) 95530fdc8d8SChris Lattner { 956a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 95730fdc8d8SChris Lattner if (target == NULL) 95830fdc8d8SChris Lattner { 9599068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 96030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 96130fdc8d8SChris Lattner return false; 96230fdc8d8SChris Lattner } 96330fdc8d8SChris Lattner 9641b54c88cSJim Ingham Mutex::Locker locker; 9651b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 9661b54c88cSJim Ingham 96730fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 96830fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 96930fdc8d8SChris Lattner 97030fdc8d8SChris Lattner if (num_breakpoints == 0) 97130fdc8d8SChris Lattner { 97230fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be disabled."); 97330fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 97430fdc8d8SChris Lattner return false; 97530fdc8d8SChris Lattner } 97630fdc8d8SChris Lattner 97730fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 97830fdc8d8SChris Lattner { 97930fdc8d8SChris Lattner // No breakpoint selected; disable all currently set breakpoints. 98030fdc8d8SChris Lattner target->DisableAllBreakpoints (); 98130fdc8d8SChris Lattner result.AppendMessageWithFormat ("All breakpoints disabled. (%d breakpoints)\n", num_breakpoints); 98230fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 98330fdc8d8SChris Lattner } 98430fdc8d8SChris Lattner else 98530fdc8d8SChris Lattner { 98630fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 98730fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 98830fdc8d8SChris Lattner 98930fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 99030fdc8d8SChris Lattner 99130fdc8d8SChris Lattner if (result.Succeeded()) 99230fdc8d8SChris Lattner { 99330fdc8d8SChris Lattner int disable_count = 0; 99430fdc8d8SChris Lattner int loc_count = 0; 995c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 996c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 99730fdc8d8SChris Lattner { 99830fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 99930fdc8d8SChris Lattner 100030fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 100130fdc8d8SChris Lattner { 100230fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 100330fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 100430fdc8d8SChris Lattner { 100530fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 100630fdc8d8SChris Lattner if (location) 100730fdc8d8SChris Lattner { 100830fdc8d8SChris Lattner location->SetEnabled (false); 100930fdc8d8SChris Lattner ++loc_count; 101030fdc8d8SChris Lattner } 101130fdc8d8SChris Lattner } 101230fdc8d8SChris Lattner else 101330fdc8d8SChris Lattner { 1014ae1c4cf5SJim Ingham breakpoint->SetEnabled (false); 101530fdc8d8SChris Lattner ++disable_count; 101630fdc8d8SChris Lattner } 101730fdc8d8SChris Lattner } 101830fdc8d8SChris Lattner } 101930fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count); 102030fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 102130fdc8d8SChris Lattner } 102230fdc8d8SChris Lattner } 102330fdc8d8SChris Lattner 102430fdc8d8SChris Lattner return result.Succeeded(); 102530fdc8d8SChris Lattner } 102630fdc8d8SChris Lattner 102730fdc8d8SChris Lattner //------------------------------------------------------------------------- 102830fdc8d8SChris Lattner // CommandObjectBreakpointDelete 102930fdc8d8SChris Lattner //------------------------------------------------------------------------- 1030ae1c4cf5SJim Ingham #pragma mark Delete 103130fdc8d8SChris Lattner 1032a7015092SGreg Clayton CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) : 1033a7015092SGreg Clayton CommandObject (interpreter, 1034a7015092SGreg Clayton "breakpoint delete", 1035e3d26315SCaroline Tice "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.", 1036e139cf23SCaroline Tice NULL) 103730fdc8d8SChris Lattner { 1038e139cf23SCaroline Tice CommandArgumentEntry arg; 1039e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 1040e139cf23SCaroline Tice CommandArgumentData bp_id_range_arg; 1041e139cf23SCaroline Tice 1042e139cf23SCaroline Tice // Create the first variant for the first (and only) argument for this command. 1043e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 1044405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 1045e139cf23SCaroline Tice 1046e139cf23SCaroline Tice // Create the second variant for the first (and only) argument for this command. 1047e139cf23SCaroline Tice bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange; 1048405fe67fSCaroline Tice bp_id_range_arg.arg_repetition = eArgRepeatOptional; 1049e139cf23SCaroline Tice 1050e139cf23SCaroline Tice // The first (and only) argument for this command could be either a bp_id or a bp_id_range. 1051e139cf23SCaroline Tice // Push both variants into the entry for the first argument for this command. 1052e139cf23SCaroline Tice arg.push_back (bp_id_arg); 1053e139cf23SCaroline Tice arg.push_back (bp_id_range_arg); 1054e139cf23SCaroline Tice 1055e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1056e139cf23SCaroline Tice m_arguments.push_back (arg); 105730fdc8d8SChris Lattner } 105830fdc8d8SChris Lattner 105930fdc8d8SChris Lattner 106030fdc8d8SChris Lattner CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete () 106130fdc8d8SChris Lattner { 106230fdc8d8SChris Lattner } 106330fdc8d8SChris Lattner 106430fdc8d8SChris Lattner bool 10656611103cSGreg Clayton CommandObjectBreakpointDelete::Execute 10666611103cSGreg Clayton ( 10676611103cSGreg Clayton Args& args, 10686611103cSGreg Clayton CommandReturnObject &result 10696611103cSGreg Clayton ) 107030fdc8d8SChris Lattner { 1071a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 107230fdc8d8SChris Lattner if (target == NULL) 107330fdc8d8SChris Lattner { 10749068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 107530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 107630fdc8d8SChris Lattner return false; 107730fdc8d8SChris Lattner } 107830fdc8d8SChris Lattner 10791b54c88cSJim Ingham Mutex::Locker locker; 10801b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 10811b54c88cSJim Ingham 108230fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 10831b54c88cSJim Ingham 108430fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 108530fdc8d8SChris Lattner 108630fdc8d8SChris Lattner if (num_breakpoints == 0) 108730fdc8d8SChris Lattner { 108830fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be deleted."); 108930fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 109030fdc8d8SChris Lattner return false; 109130fdc8d8SChris Lattner } 109230fdc8d8SChris Lattner 109330fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 109430fdc8d8SChris Lattner { 1095*36f3b369SJim Ingham if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true)) 109630fdc8d8SChris Lattner { 1097*36f3b369SJim Ingham result.AppendMessage("Operation cancelled..."); 109830fdc8d8SChris Lattner } 1099*36f3b369SJim Ingham else 1100*36f3b369SJim Ingham { 110130fdc8d8SChris Lattner target->RemoveAllBreakpoints (); 110230fdc8d8SChris Lattner result.AppendMessageWithFormat ("All breakpoints removed. (%d breakpoints)\n", num_breakpoints); 1103*36f3b369SJim Ingham } 110430fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 110530fdc8d8SChris Lattner } 110630fdc8d8SChris Lattner else 110730fdc8d8SChris Lattner { 110830fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 110930fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 111030fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 111130fdc8d8SChris Lattner 111230fdc8d8SChris Lattner if (result.Succeeded()) 111330fdc8d8SChris Lattner { 111430fdc8d8SChris Lattner int delete_count = 0; 111530fdc8d8SChris Lattner int disable_count = 0; 1116c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1117c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 111830fdc8d8SChris Lattner { 111930fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 112030fdc8d8SChris Lattner 112130fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 112230fdc8d8SChris Lattner { 112330fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 112430fdc8d8SChris Lattner { 112530fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 112630fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 112730fdc8d8SChris Lattner // It makes no sense to try to delete individual locations, so we disable them instead. 112830fdc8d8SChris Lattner if (location) 112930fdc8d8SChris Lattner { 113030fdc8d8SChris Lattner location->SetEnabled (false); 113130fdc8d8SChris Lattner ++disable_count; 113230fdc8d8SChris Lattner } 113330fdc8d8SChris Lattner } 113430fdc8d8SChris Lattner else 113530fdc8d8SChris Lattner { 113630fdc8d8SChris Lattner target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID()); 113730fdc8d8SChris Lattner ++delete_count; 113830fdc8d8SChris Lattner } 113930fdc8d8SChris Lattner } 114030fdc8d8SChris Lattner } 114130fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n", 114230fdc8d8SChris Lattner delete_count, disable_count); 114330fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 114430fdc8d8SChris Lattner } 114530fdc8d8SChris Lattner } 114630fdc8d8SChris Lattner return result.Succeeded(); 114730fdc8d8SChris Lattner } 11481b54c88cSJim Ingham 11491b54c88cSJim Ingham //------------------------------------------------------------------------- 1150ae1c4cf5SJim Ingham // CommandObjectBreakpointModify::CommandOptions 11511b54c88cSJim Ingham //------------------------------------------------------------------------- 1152ae1c4cf5SJim Ingham #pragma mark Modify::CommandOptions 11531b54c88cSJim Ingham 1154ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::CommandOptions() : 11551b54c88cSJim Ingham Options (), 1156c982c768SGreg Clayton m_ignore_count (0), 11571b54c88cSJim Ingham m_thread_id(LLDB_INVALID_THREAD_ID), 1158c982c768SGreg Clayton m_thread_index (UINT32_MAX), 11591b54c88cSJim Ingham m_thread_name(), 11601b54c88cSJim Ingham m_queue_name(), 1161*36f3b369SJim Ingham m_condition (), 1162c982c768SGreg Clayton m_enable_passed (false), 1163c982c768SGreg Clayton m_enable_value (false), 1164c982c768SGreg Clayton m_name_passed (false), 1165*36f3b369SJim Ingham m_queue_passed (false), 1166*36f3b369SJim Ingham m_condition_passed (false) 11671b54c88cSJim Ingham { 11681b54c88cSJim Ingham } 11691b54c88cSJim Ingham 1170ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::~CommandOptions () 11711b54c88cSJim Ingham { 11721b54c88cSJim Ingham } 11731b54c88cSJim Ingham 11741b54c88cSJim Ingham lldb::OptionDefinition 1175ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] = 11761b54c88cSJim Ingham { 1177deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, NULL, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." }, 1178deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose indeX matches this argument."}, 1179deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."}, 1180deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."}, 1181deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."}, 1182*36f3b369SJim Ingham { LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, NULL, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."}, 1183deaab222SCaroline Tice { LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, eArgTypeNone, "Enable the breakpoint."}, 1184deaab222SCaroline Tice { LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, eArgTypeNone, "Disable the breakpoint."}, 1185deaab222SCaroline Tice { 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } 11861b54c88cSJim Ingham }; 11871b54c88cSJim Ingham 11881b54c88cSJim Ingham const lldb::OptionDefinition* 1189ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::GetDefinitions () 11901b54c88cSJim Ingham { 11911b54c88cSJim Ingham return g_option_table; 11921b54c88cSJim Ingham } 11931b54c88cSJim Ingham 11941b54c88cSJim Ingham Error 1195ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) 11961b54c88cSJim Ingham { 11971b54c88cSJim Ingham Error error; 11981b54c88cSJim Ingham char short_option = (char) m_getopt_table[option_idx].val; 11991b54c88cSJim Ingham 12001b54c88cSJim Ingham switch (short_option) 12011b54c88cSJim Ingham { 1202*36f3b369SJim Ingham case 'c': 1203*36f3b369SJim Ingham if (option_arg != NULL) 1204*36f3b369SJim Ingham m_condition = option_arg; 1205*36f3b369SJim Ingham else 1206*36f3b369SJim Ingham m_condition.clear(); 1207*36f3b369SJim Ingham m_condition_passed = true; 1208*36f3b369SJim Ingham break; 1209ae1c4cf5SJim Ingham case 'd': 1210ae1c4cf5SJim Ingham m_enable_passed = true; 1211ae1c4cf5SJim Ingham m_enable_value = false; 1212ae1c4cf5SJim Ingham break; 1213ae1c4cf5SJim Ingham case 'e': 1214ae1c4cf5SJim Ingham m_enable_passed = true; 1215ae1c4cf5SJim Ingham m_enable_value = true; 1216ae1c4cf5SJim Ingham break; 1217ed8a705cSGreg Clayton case 'i': 12181b54c88cSJim Ingham { 1219c982c768SGreg Clayton m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0); 1220c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 12211b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg); 12221b54c88cSJim Ingham } 1223ae1c4cf5SJim Ingham break; 12241b54c88cSJim Ingham case 't' : 12251b54c88cSJim Ingham { 12261b54c88cSJim Ingham m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0); 12271b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 12281b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg); 12291b54c88cSJim Ingham } 12301b54c88cSJim Ingham break; 12311b54c88cSJim Ingham case 'T': 1232b2a38a72SJim Ingham if (option_arg != NULL) 12331b54c88cSJim Ingham m_thread_name = option_arg; 1234b2a38a72SJim Ingham else 1235b2a38a72SJim Ingham m_thread_name.clear(); 1236b2a38a72SJim Ingham m_name_passed = true; 12371b54c88cSJim Ingham break; 12381b54c88cSJim Ingham case 'q': 1239b2a38a72SJim Ingham if (option_arg != NULL) 12401b54c88cSJim Ingham m_queue_name = option_arg; 1241b2a38a72SJim Ingham else 1242b2a38a72SJim Ingham m_queue_name.clear(); 1243b2a38a72SJim Ingham m_queue_passed = true; 12441b54c88cSJim Ingham break; 12451b54c88cSJim Ingham case 'x': 12461b54c88cSJim Ingham { 1247c982c768SGreg Clayton m_thread_index = Args::StringToUInt32 (optarg, UINT32_MAX, 0); 1248c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 12491b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg); 12501b54c88cSJim Ingham 12511b54c88cSJim Ingham } 12521b54c88cSJim Ingham break; 12531b54c88cSJim Ingham default: 12541b54c88cSJim Ingham error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 12551b54c88cSJim Ingham break; 12561b54c88cSJim Ingham } 12571b54c88cSJim Ingham 12581b54c88cSJim Ingham return error; 12591b54c88cSJim Ingham } 12601b54c88cSJim Ingham 12611b54c88cSJim Ingham void 1262ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::ResetOptionValues () 12631b54c88cSJim Ingham { 12641b54c88cSJim Ingham Options::ResetOptionValues(); 12651b54c88cSJim Ingham 1266c982c768SGreg Clayton m_ignore_count = 0; 12671b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 1268c982c768SGreg Clayton m_thread_index = UINT32_MAX; 12691b54c88cSJim Ingham m_thread_name.clear(); 12701b54c88cSJim Ingham m_queue_name.clear(); 1271*36f3b369SJim Ingham m_condition.clear(); 1272ae1c4cf5SJim Ingham m_enable_passed = false; 1273b2a38a72SJim Ingham m_queue_passed = false; 1274b2a38a72SJim Ingham m_name_passed = false; 1275*36f3b369SJim Ingham m_condition_passed = false; 12761b54c88cSJim Ingham } 12771b54c88cSJim Ingham 12781b54c88cSJim Ingham //------------------------------------------------------------------------- 1279ae1c4cf5SJim Ingham // CommandObjectBreakpointModify 12801b54c88cSJim Ingham //------------------------------------------------------------------------- 1281ae1c4cf5SJim Ingham #pragma mark Modify 12821b54c88cSJim Ingham 1283a7015092SGreg Clayton CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) : 1284a7015092SGreg Clayton CommandObject (interpreter, 1285a7015092SGreg Clayton "breakpoint modify", 1286a7015092SGreg Clayton "Modify the options on a breakpoint or set of breakpoints in the executable.", 1287e139cf23SCaroline Tice NULL) 12881b54c88cSJim Ingham { 1289e139cf23SCaroline Tice CommandArgumentEntry arg; 1290e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 1291e139cf23SCaroline Tice CommandArgumentData bp_id_range_arg; 1292e139cf23SCaroline Tice 1293e139cf23SCaroline Tice // Create the first variant for the first (and only) argument for this command. 1294e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 1295405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatPlain; 1296e139cf23SCaroline Tice 1297e139cf23SCaroline Tice // Create the second variant for the first (and only) argument for this command. 1298e139cf23SCaroline Tice bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange; 1299405fe67fSCaroline Tice bp_id_range_arg.arg_repetition = eArgRepeatPlain; 1300e139cf23SCaroline Tice 1301e139cf23SCaroline Tice // The first (and only) argument for this command could be either a bp_id or a bp_id_range. 1302e139cf23SCaroline Tice // Push both variants into the entry for the first argument for this command. 1303e139cf23SCaroline Tice arg.push_back (bp_id_arg); 1304e139cf23SCaroline Tice arg.push_back (bp_id_range_arg); 1305e139cf23SCaroline Tice 1306e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1307e139cf23SCaroline Tice m_arguments.push_back (arg); 13081b54c88cSJim Ingham } 13091b54c88cSJim Ingham 1310ae1c4cf5SJim Ingham CommandObjectBreakpointModify::~CommandObjectBreakpointModify () 13111b54c88cSJim Ingham { 13121b54c88cSJim Ingham } 13131b54c88cSJim Ingham 13141b54c88cSJim Ingham Options * 1315ae1c4cf5SJim Ingham CommandObjectBreakpointModify::GetOptions () 13161b54c88cSJim Ingham { 13171b54c88cSJim Ingham return &m_options; 13181b54c88cSJim Ingham } 13191b54c88cSJim Ingham 13201b54c88cSJim Ingham bool 1321ae1c4cf5SJim Ingham CommandObjectBreakpointModify::Execute 13221b54c88cSJim Ingham ( 13231b54c88cSJim Ingham Args& command, 13241b54c88cSJim Ingham CommandReturnObject &result 13251b54c88cSJim Ingham ) 13261b54c88cSJim Ingham { 1327a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 13281b54c88cSJim Ingham if (target == NULL) 13291b54c88cSJim Ingham { 13309068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 13311b54c88cSJim Ingham result.SetStatus (eReturnStatusFailed); 13321b54c88cSJim Ingham return false; 13331b54c88cSJim Ingham } 13341b54c88cSJim Ingham 13351b54c88cSJim Ingham Mutex::Locker locker; 13361b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 13371b54c88cSJim Ingham 13381b54c88cSJim Ingham BreakpointIDList valid_bp_ids; 13391b54c88cSJim Ingham 13401b54c88cSJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 13411b54c88cSJim Ingham 13421b54c88cSJim Ingham if (result.Succeeded()) 13431b54c88cSJim Ingham { 1344c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1345c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 13461b54c88cSJim Ingham { 13471b54c88cSJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 13481b54c88cSJim Ingham 13491b54c88cSJim Ingham if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 13501b54c88cSJim Ingham { 13511b54c88cSJim Ingham Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 13521b54c88cSJim Ingham if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 13531b54c88cSJim Ingham { 13541b54c88cSJim Ingham BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get(); 13551b54c88cSJim Ingham if (location) 13561b54c88cSJim Ingham { 13571b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 13581b54c88cSJim Ingham location->SetThreadID (m_options.m_thread_id); 13591b54c88cSJim Ingham 1360c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 13611b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 13621b54c88cSJim Ingham 1363b2a38a72SJim Ingham if (m_options.m_name_passed) 13641b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 13651b54c88cSJim Ingham 1366b2a38a72SJim Ingham if (m_options.m_queue_passed) 13671b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 13681b54c88cSJim Ingham 1369c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 13701b54c88cSJim Ingham location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count); 1371ae1c4cf5SJim Ingham 1372ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1373ae1c4cf5SJim Ingham location->SetEnabled (m_options.m_enable_value); 1374*36f3b369SJim Ingham 1375*36f3b369SJim Ingham if (m_options.m_condition_passed) 1376*36f3b369SJim Ingham location->SetCondition (m_options.m_condition.c_str()); 13771b54c88cSJim Ingham } 13781b54c88cSJim Ingham } 13791b54c88cSJim Ingham else 13801b54c88cSJim Ingham { 13811b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 13821b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 13831b54c88cSJim Ingham 1384c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 13851b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 13861b54c88cSJim Ingham 1387b2a38a72SJim Ingham if (m_options.m_name_passed) 13881b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 13891b54c88cSJim Ingham 1390b2a38a72SJim Ingham if (m_options.m_queue_passed) 13911b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 13921b54c88cSJim Ingham 1393c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 13941b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 1395ae1c4cf5SJim Ingham 1396ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1397ae1c4cf5SJim Ingham bp->SetEnabled (m_options.m_enable_value); 1398ae1c4cf5SJim Ingham 1399*36f3b369SJim Ingham if (m_options.m_condition_passed) 1400*36f3b369SJim Ingham bp->SetCondition (m_options.m_condition.c_str()); 14011b54c88cSJim Ingham } 14021b54c88cSJim Ingham } 14031b54c88cSJim Ingham } 14041b54c88cSJim Ingham } 14051b54c88cSJim Ingham 14061b54c88cSJim Ingham return result.Succeeded(); 14071b54c88cSJim Ingham } 14081b54c88cSJim Ingham 14091b54c88cSJim Ingham 1410