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, 1072561aa61SJim Ingham "Set the breakpoint by function name - for C++ this means namespaces and arguments will be ignored." }, 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 122deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 12330fdc8d8SChris Lattner }; 12430fdc8d8SChris Lattner 12530fdc8d8SChris Lattner const lldb::OptionDefinition* 12630fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::GetDefinitions () 12730fdc8d8SChris Lattner { 12830fdc8d8SChris Lattner return g_option_table; 12930fdc8d8SChris Lattner } 13030fdc8d8SChris Lattner 13130fdc8d8SChris Lattner Error 13230fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) 13330fdc8d8SChris Lattner { 13430fdc8d8SChris Lattner Error error; 13530fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 13630fdc8d8SChris Lattner 13730fdc8d8SChris Lattner switch (short_option) 13830fdc8d8SChris Lattner { 13930fdc8d8SChris Lattner case 'a': 14030fdc8d8SChris Lattner m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 0); 14130fdc8d8SChris Lattner if (m_load_addr == LLDB_INVALID_ADDRESS) 14230fdc8d8SChris Lattner m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 16); 14330fdc8d8SChris Lattner 14430fdc8d8SChris Lattner if (m_load_addr == LLDB_INVALID_ADDRESS) 14530fdc8d8SChris Lattner error.SetErrorStringWithFormat ("Invalid address string '%s'.\n", optarg); 14630fdc8d8SChris Lattner break; 14730fdc8d8SChris Lattner 14830fdc8d8SChris Lattner case 'c': 14930fdc8d8SChris Lattner m_column = Args::StringToUInt32 (option_arg, 0); 15030fdc8d8SChris Lattner break; 1510c5cd90dSGreg Clayton 15230fdc8d8SChris Lattner case 'f': 15330fdc8d8SChris Lattner m_filename = option_arg; 15430fdc8d8SChris Lattner break; 1550c5cd90dSGreg Clayton 15630fdc8d8SChris Lattner case 'l': 15730fdc8d8SChris Lattner m_line_num = Args::StringToUInt32 (option_arg, 0); 15830fdc8d8SChris Lattner break; 1590c5cd90dSGreg Clayton 16030fdc8d8SChris Lattner case 'n': 16130fdc8d8SChris Lattner m_func_name = option_arg; 1620c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeBase; 1630c5cd90dSGreg Clayton break; 1640c5cd90dSGreg Clayton 1650c5cd90dSGreg Clayton case 'F': 1662561aa61SJim Ingham m_func_name = option_arg; 1670c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeFull; 1680c5cd90dSGreg Clayton break; 1690c5cd90dSGreg Clayton 1700c5cd90dSGreg Clayton case 'S': 1712561aa61SJim Ingham m_func_name = option_arg; 1720c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeSelector; 1730c5cd90dSGreg Clayton break; 1740c5cd90dSGreg Clayton 1752561aa61SJim Ingham case 'M': 1762561aa61SJim Ingham m_func_name = option_arg; 1770c5cd90dSGreg Clayton m_func_name_type_mask |= eFunctionNameTypeMethod; 1780c5cd90dSGreg Clayton break; 1790c5cd90dSGreg Clayton 18030fdc8d8SChris Lattner case 'r': 18130fdc8d8SChris Lattner m_func_regexp = option_arg; 18230fdc8d8SChris Lattner break; 1830c5cd90dSGreg Clayton 18430fdc8d8SChris Lattner case 's': 18530fdc8d8SChris Lattner { 18630fdc8d8SChris Lattner m_modules.push_back (std::string (option_arg)); 18730fdc8d8SChris Lattner break; 18830fdc8d8SChris Lattner } 189ed8a705cSGreg Clayton case 'i': 1901b54c88cSJim Ingham { 191c982c768SGreg Clayton m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0); 192c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 1931b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg); 1941b54c88cSJim Ingham } 195ae1c4cf5SJim Ingham break; 1961b54c88cSJim Ingham case 't' : 1971b54c88cSJim Ingham { 1981b54c88cSJim Ingham m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0); 1991b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 2001b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg); 2011b54c88cSJim Ingham } 2021b54c88cSJim Ingham break; 2031b54c88cSJim Ingham case 'T': 2041b54c88cSJim Ingham m_thread_name = option_arg; 2051b54c88cSJim Ingham break; 2061b54c88cSJim Ingham case 'q': 2071b54c88cSJim Ingham m_queue_name = option_arg; 2081b54c88cSJim Ingham break; 2091b54c88cSJim Ingham case 'x': 2101b54c88cSJim Ingham { 211c982c768SGreg Clayton m_thread_index = Args::StringToUInt32(optarg, UINT32_MAX, 0); 212c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 2131b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg); 2141b54c88cSJim Ingham 2151b54c88cSJim Ingham } 2161b54c88cSJim Ingham break; 21730fdc8d8SChris Lattner default: 21830fdc8d8SChris Lattner error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 21930fdc8d8SChris Lattner break; 22030fdc8d8SChris Lattner } 22130fdc8d8SChris Lattner 22230fdc8d8SChris Lattner return error; 22330fdc8d8SChris Lattner } 22430fdc8d8SChris Lattner 22530fdc8d8SChris Lattner void 22630fdc8d8SChris Lattner CommandObjectBreakpointSet::CommandOptions::ResetOptionValues () 22730fdc8d8SChris Lattner { 22830fdc8d8SChris Lattner Options::ResetOptionValues(); 22930fdc8d8SChris Lattner 23030fdc8d8SChris Lattner m_filename.clear(); 23130fdc8d8SChris Lattner m_line_num = 0; 23230fdc8d8SChris Lattner m_column = 0; 23330fdc8d8SChris Lattner m_func_name.clear(); 2340c5cd90dSGreg Clayton m_func_name_type_mask = 0; 23530fdc8d8SChris Lattner m_func_regexp.clear(); 23630fdc8d8SChris Lattner m_load_addr = LLDB_INVALID_ADDRESS; 23730fdc8d8SChris Lattner m_modules.clear(); 238c982c768SGreg Clayton m_ignore_count = 0; 2391b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 240c982c768SGreg Clayton m_thread_index = UINT32_MAX; 2411b54c88cSJim Ingham m_thread_name.clear(); 2421b54c88cSJim Ingham m_queue_name.clear(); 24330fdc8d8SChris Lattner } 24430fdc8d8SChris Lattner 24530fdc8d8SChris Lattner //------------------------------------------------------------------------- 24630fdc8d8SChris Lattner // CommandObjectBreakpointSet 24730fdc8d8SChris Lattner //------------------------------------------------------------------------- 248ae1c4cf5SJim Ingham #pragma mark Set 24930fdc8d8SChris Lattner 250a7015092SGreg Clayton CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) : 251a7015092SGreg Clayton CommandObject (interpreter, 252a7015092SGreg Clayton "breakpoint set", 253a7015092SGreg Clayton "Sets a breakpoint or set of breakpoints in the executable.", 25430fdc8d8SChris Lattner "breakpoint set <cmd-options>") 25530fdc8d8SChris Lattner { 25630fdc8d8SChris Lattner } 25730fdc8d8SChris Lattner 25830fdc8d8SChris Lattner CommandObjectBreakpointSet::~CommandObjectBreakpointSet () 25930fdc8d8SChris Lattner { 26030fdc8d8SChris Lattner } 26130fdc8d8SChris Lattner 26230fdc8d8SChris Lattner Options * 26330fdc8d8SChris Lattner CommandObjectBreakpointSet::GetOptions () 26430fdc8d8SChris Lattner { 26530fdc8d8SChris Lattner return &m_options; 26630fdc8d8SChris Lattner } 26730fdc8d8SChris Lattner 26830fdc8d8SChris Lattner bool 26930fdc8d8SChris Lattner CommandObjectBreakpointSet::Execute 27030fdc8d8SChris Lattner ( 27130fdc8d8SChris Lattner Args& command, 27230fdc8d8SChris Lattner CommandReturnObject &result 27330fdc8d8SChris Lattner ) 27430fdc8d8SChris Lattner { 275a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 27630fdc8d8SChris Lattner if (target == NULL) 27730fdc8d8SChris Lattner { 2789068d794SCaroline Tice result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'file' command)."); 27930fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 28030fdc8d8SChris Lattner return false; 28130fdc8d8SChris Lattner } 28230fdc8d8SChris Lattner 28330fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 28430fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 28530fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 28630fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 28730fdc8d8SChris Lattner // 4). -r [-s -g] (setting breakpoint by function name regular expression) 28830fdc8d8SChris Lattner 28930fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 29030fdc8d8SChris Lattner 29130fdc8d8SChris Lattner if (m_options.m_line_num != 0) 29230fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 29330fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 29430fdc8d8SChris Lattner break_type = eSetTypeAddress; 29530fdc8d8SChris Lattner else if (!m_options.m_func_name.empty()) 29630fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 29730fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 29830fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 29930fdc8d8SChris Lattner 30030fdc8d8SChris Lattner ModuleSP module_sp = target->GetExecutableModule(); 30130fdc8d8SChris Lattner Breakpoint *bp = NULL; 30230fdc8d8SChris Lattner FileSpec module; 30330fdc8d8SChris Lattner bool use_module = false; 30430fdc8d8SChris Lattner int num_modules = m_options.m_modules.size(); 30530fdc8d8SChris Lattner 30630fdc8d8SChris Lattner if ((num_modules > 0) && (break_type != eSetTypeAddress)) 30730fdc8d8SChris Lattner use_module = true; 30830fdc8d8SChris Lattner 30930fdc8d8SChris Lattner switch (break_type) 31030fdc8d8SChris Lattner { 31130fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 31230fdc8d8SChris Lattner { 31330fdc8d8SChris Lattner FileSpec file; 31430fdc8d8SChris Lattner if (m_options.m_filename.empty()) 31530fdc8d8SChris Lattner { 316a7015092SGreg Clayton StackFrame *cur_frame = m_interpreter.GetDebugger().GetExecutionContext().frame; 31730fdc8d8SChris Lattner if (cur_frame == NULL) 31830fdc8d8SChris Lattner { 31930fdc8d8SChris Lattner result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame."); 32030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 32130fdc8d8SChris Lattner break; 32230fdc8d8SChris Lattner } 32330fdc8d8SChris Lattner else if (!cur_frame->HasDebugInformation()) 32430fdc8d8SChris Lattner { 32530fdc8d8SChris Lattner result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info."); 32630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 32730fdc8d8SChris Lattner break; 32830fdc8d8SChris Lattner } 32930fdc8d8SChris Lattner else 33030fdc8d8SChris Lattner { 33130fdc8d8SChris Lattner const SymbolContext &context = cur_frame->GetSymbolContext(true); 33230fdc8d8SChris Lattner if (context.line_entry.file) 33330fdc8d8SChris Lattner { 33430fdc8d8SChris Lattner file = context.line_entry.file; 33530fdc8d8SChris Lattner } 33630fdc8d8SChris Lattner else if (context.comp_unit != NULL) 33730fdc8d8SChris Lattner { file = context.comp_unit; 33830fdc8d8SChris Lattner } 33930fdc8d8SChris Lattner else 34030fdc8d8SChris Lattner { 34130fdc8d8SChris Lattner result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame."); 34230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 34330fdc8d8SChris Lattner break; 34430fdc8d8SChris Lattner } 34530fdc8d8SChris Lattner } 34630fdc8d8SChris Lattner } 34730fdc8d8SChris Lattner else 34830fdc8d8SChris Lattner { 34930fdc8d8SChris Lattner file.SetFile(m_options.m_filename.c_str()); 35030fdc8d8SChris Lattner } 35130fdc8d8SChris Lattner 35230fdc8d8SChris Lattner if (use_module) 35330fdc8d8SChris Lattner { 35430fdc8d8SChris Lattner for (int i = 0; i < num_modules; ++i) 35530fdc8d8SChris Lattner { 35630fdc8d8SChris Lattner module.SetFile(m_options.m_modules[i].c_str()); 35730fdc8d8SChris Lattner bp = target->CreateBreakpoint (&module, 35830fdc8d8SChris Lattner file, 35930fdc8d8SChris Lattner m_options.m_line_num, 36030fdc8d8SChris Lattner m_options.m_ignore_inlines).get(); 36130fdc8d8SChris Lattner if (bp) 36230fdc8d8SChris Lattner { 36330fdc8d8SChris Lattner StreamString &output_stream = result.GetOutputStream(); 36430fdc8d8SChris Lattner output_stream.Printf ("Breakpoint created: "); 36530fdc8d8SChris Lattner bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); 36630fdc8d8SChris Lattner output_stream.EOL(); 36730fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 36830fdc8d8SChris Lattner } 36930fdc8d8SChris Lattner else 37030fdc8d8SChris Lattner { 37130fdc8d8SChris Lattner result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n", 37230fdc8d8SChris Lattner m_options.m_modules[i].c_str()); 37330fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 37430fdc8d8SChris Lattner } 37530fdc8d8SChris Lattner } 37630fdc8d8SChris Lattner } 37730fdc8d8SChris Lattner else 37830fdc8d8SChris Lattner bp = target->CreateBreakpoint (NULL, 37930fdc8d8SChris Lattner file, 38030fdc8d8SChris Lattner m_options.m_line_num, 38130fdc8d8SChris Lattner m_options.m_ignore_inlines).get(); 38230fdc8d8SChris Lattner } 38330fdc8d8SChris Lattner break; 384*6eee5aa0SGreg Clayton 38530fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 38630fdc8d8SChris Lattner bp = target->CreateBreakpoint (m_options.m_load_addr, false).get(); 38730fdc8d8SChris Lattner break; 3880c5cd90dSGreg Clayton 38930fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 3900c5cd90dSGreg Clayton { 3910c5cd90dSGreg Clayton uint32_t name_type_mask = m_options.m_func_name_type_mask; 3920c5cd90dSGreg Clayton 3930c5cd90dSGreg Clayton if (name_type_mask == 0) 3940c5cd90dSGreg Clayton { 3950c5cd90dSGreg Clayton 3960c5cd90dSGreg Clayton if (m_options.m_func_name.find('(') != std::string::npos || 3970c5cd90dSGreg Clayton m_options.m_func_name.find("-[") == 0 || 3980c5cd90dSGreg Clayton m_options.m_func_name.find("+[") == 0) 3990c5cd90dSGreg Clayton name_type_mask |= eFunctionNameTypeFull; 4000c5cd90dSGreg Clayton else 4010c5cd90dSGreg Clayton name_type_mask |= eFunctionNameTypeBase; 4020c5cd90dSGreg Clayton } 4030c5cd90dSGreg Clayton 4040c5cd90dSGreg Clayton 40530fdc8d8SChris Lattner if (use_module) 40630fdc8d8SChris Lattner { 40730fdc8d8SChris Lattner for (int i = 0; i < num_modules; ++i) 40830fdc8d8SChris Lattner { 40930fdc8d8SChris Lattner module.SetFile(m_options.m_modules[i].c_str()); 4100c5cd90dSGreg Clayton bp = target->CreateBreakpoint (&module, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get(); 41130fdc8d8SChris Lattner if (bp) 41230fdc8d8SChris Lattner { 41330fdc8d8SChris Lattner StreamString &output_stream = result.GetOutputStream(); 41430fdc8d8SChris Lattner output_stream.Printf ("Breakpoint created: "); 41530fdc8d8SChris Lattner bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); 41630fdc8d8SChris Lattner output_stream.EOL(); 41730fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 41830fdc8d8SChris Lattner } 41930fdc8d8SChris Lattner else 42030fdc8d8SChris Lattner { 42130fdc8d8SChris Lattner result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n", 42230fdc8d8SChris Lattner m_options.m_modules[i].c_str()); 42330fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 42430fdc8d8SChris Lattner } 42530fdc8d8SChris Lattner } 42630fdc8d8SChris Lattner } 42730fdc8d8SChris Lattner else 4280c5cd90dSGreg Clayton bp = target->CreateBreakpoint (NULL, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get(); 4290c5cd90dSGreg Clayton } 43030fdc8d8SChris Lattner break; 4310c5cd90dSGreg Clayton 43230fdc8d8SChris Lattner case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name 43330fdc8d8SChris Lattner { 43430fdc8d8SChris Lattner RegularExpression regexp(m_options.m_func_regexp.c_str()); 43530fdc8d8SChris Lattner if (use_module) 43630fdc8d8SChris Lattner { 43730fdc8d8SChris Lattner for (int i = 0; i < num_modules; ++i) 43830fdc8d8SChris Lattner { 43930fdc8d8SChris Lattner module.SetFile(m_options.m_modules[i].c_str()); 44030fdc8d8SChris Lattner bp = target->CreateBreakpoint (&module, regexp).get(); 44130fdc8d8SChris Lattner if (bp) 44230fdc8d8SChris Lattner { 44330fdc8d8SChris Lattner StreamString &output_stream = result.GetOutputStream(); 44430fdc8d8SChris Lattner output_stream.Printf ("Breakpoint created: "); 44530fdc8d8SChris Lattner bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); 44630fdc8d8SChris Lattner output_stream.EOL(); 44730fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 44830fdc8d8SChris Lattner } 44930fdc8d8SChris Lattner else 45030fdc8d8SChris Lattner { 45130fdc8d8SChris Lattner result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n", 45230fdc8d8SChris Lattner m_options.m_modules[i].c_str()); 45330fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 45430fdc8d8SChris Lattner } 45530fdc8d8SChris Lattner } 45630fdc8d8SChris Lattner } 45730fdc8d8SChris Lattner else 45830fdc8d8SChris Lattner bp = target->CreateBreakpoint (NULL, regexp).get(); 45930fdc8d8SChris Lattner } 46030fdc8d8SChris Lattner break; 4610c5cd90dSGreg Clayton 46230fdc8d8SChris Lattner default: 46330fdc8d8SChris Lattner break; 46430fdc8d8SChris Lattner } 46530fdc8d8SChris Lattner 4661b54c88cSJim Ingham // Now set the various options that were passed in: 4671b54c88cSJim Ingham if (bp) 4681b54c88cSJim Ingham { 4691b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 4701b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 4711b54c88cSJim Ingham 472c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 4731b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 4741b54c88cSJim Ingham 4751b54c88cSJim Ingham if (!m_options.m_thread_name.empty()) 4761b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 4771b54c88cSJim Ingham 4781b54c88cSJim Ingham if (!m_options.m_queue_name.empty()) 4791b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 4801b54c88cSJim Ingham 481c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 4821b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 4831b54c88cSJim Ingham } 4841b54c88cSJim Ingham 48530fdc8d8SChris Lattner if (bp && !use_module) 48630fdc8d8SChris Lattner { 48730fdc8d8SChris Lattner StreamString &output_stream = result.GetOutputStream(); 48830fdc8d8SChris Lattner output_stream.Printf ("Breakpoint created: "); 48930fdc8d8SChris Lattner bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); 49030fdc8d8SChris Lattner output_stream.EOL(); 49130fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 49230fdc8d8SChris Lattner } 49330fdc8d8SChris Lattner else if (!bp) 49430fdc8d8SChris Lattner { 49530fdc8d8SChris Lattner result.AppendError ("Breakpoint creation failed: No breakpoint created."); 49630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 49730fdc8d8SChris Lattner } 49830fdc8d8SChris Lattner 49930fdc8d8SChris Lattner return result.Succeeded(); 50030fdc8d8SChris Lattner } 50130fdc8d8SChris Lattner 50230fdc8d8SChris Lattner //------------------------------------------------------------------------- 50330fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 50430fdc8d8SChris Lattner //------------------------------------------------------------------------- 505ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 50630fdc8d8SChris Lattner 5076611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) : 508a7015092SGreg Clayton CommandObjectMultiword (interpreter, 509a7015092SGreg Clayton "breakpoint", 5103f4c09c1SCaroline Tice "A set of commands for operating on breakpoints. Also see regexp-break.", 51130fdc8d8SChris Lattner "breakpoint <command> [<command-options>]") 51230fdc8d8SChris Lattner { 51330fdc8d8SChris Lattner bool status; 51430fdc8d8SChris Lattner 515a7015092SGreg Clayton CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter)); 516a7015092SGreg Clayton CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter)); 517a7015092SGreg Clayton CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter)); 518a7015092SGreg Clayton CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter)); 519a7015092SGreg Clayton CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter)); 52030fdc8d8SChris Lattner CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter)); 521a7015092SGreg Clayton CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter)); 52230fdc8d8SChris Lattner 523ae1c4cf5SJim Ingham command_command_object->SetCommandName ("breakpoint command"); 52430fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 52530fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 52630fdc8d8SChris Lattner list_command_object->SetCommandName ("breakpoint list"); 527ae1c4cf5SJim Ingham modify_command_object->SetCommandName ("breakpoint modify"); 528ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 52930fdc8d8SChris Lattner 530a7015092SGreg Clayton status = LoadSubCommand ("list", list_command_object); 531a7015092SGreg Clayton status = LoadSubCommand ("enable", enable_command_object); 532a7015092SGreg Clayton status = LoadSubCommand ("disable", disable_command_object); 533a7015092SGreg Clayton status = LoadSubCommand ("delete", delete_command_object); 534a7015092SGreg Clayton status = LoadSubCommand ("set", set_command_object); 535a7015092SGreg Clayton status = LoadSubCommand ("command", command_command_object); 536a7015092SGreg Clayton status = LoadSubCommand ("modify", modify_command_object); 53730fdc8d8SChris Lattner } 53830fdc8d8SChris Lattner 53930fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint () 54030fdc8d8SChris Lattner { 54130fdc8d8SChris Lattner } 54230fdc8d8SChris Lattner 54330fdc8d8SChris Lattner void 54430fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result, 54530fdc8d8SChris Lattner BreakpointIDList *valid_ids) 54630fdc8d8SChris Lattner { 54730fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 54830fdc8d8SChris Lattner // 2). the full breakpoint & location canonical representation 54930fdc8d8SChris Lattner // 3). the word "to" or a hyphen, representing a range (in which case there 55030fdc8d8SChris Lattner // had *better* be an entry both before & after of one of the first two types. 55130fdc8d8SChris Lattner 55230fdc8d8SChris Lattner Args temp_args; 55330fdc8d8SChris Lattner 55430fdc8d8SChris Lattner // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to 55530fdc8d8SChris Lattner // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for 55630fdc8d8SChris Lattner // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS. 55730fdc8d8SChris Lattner 55830fdc8d8SChris Lattner BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args); 55930fdc8d8SChris Lattner 56030fdc8d8SChris Lattner // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList: 56130fdc8d8SChris Lattner 562c982c768SGreg Clayton valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result); 56330fdc8d8SChris Lattner 56430fdc8d8SChris Lattner // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs 56530fdc8d8SChris Lattner // and put into valid_ids. 56630fdc8d8SChris Lattner 56730fdc8d8SChris Lattner if (result.Succeeded()) 56830fdc8d8SChris Lattner { 56930fdc8d8SChris Lattner // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list 57030fdc8d8SChris Lattner // of breakpoint id's and verify that they correspond to valid/currently set breakpoints. 57130fdc8d8SChris Lattner 572c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 573c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 57430fdc8d8SChris Lattner { 57530fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i); 57630fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 57730fdc8d8SChris Lattner if (breakpoint != NULL) 57830fdc8d8SChris Lattner { 57930fdc8d8SChris Lattner int num_locations = breakpoint->GetNumLocations(); 58030fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() > num_locations) 58130fdc8d8SChris Lattner { 58230fdc8d8SChris Lattner StreamString id_str; 583c982c768SGreg Clayton BreakpointID::GetCanonicalReference (&id_str, 584c982c768SGreg Clayton cur_bp_id.GetBreakpointID(), 58530fdc8d8SChris Lattner cur_bp_id.GetLocationID()); 586c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 58730fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n", 58830fdc8d8SChris Lattner id_str.GetData()); 58930fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 59030fdc8d8SChris Lattner } 59130fdc8d8SChris Lattner } 59230fdc8d8SChris Lattner else 59330fdc8d8SChris Lattner { 594c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 59530fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID()); 59630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 59730fdc8d8SChris Lattner } 59830fdc8d8SChris Lattner } 59930fdc8d8SChris Lattner } 60030fdc8d8SChris Lattner } 60130fdc8d8SChris Lattner 60230fdc8d8SChris Lattner //------------------------------------------------------------------------- 60330fdc8d8SChris Lattner // CommandObjectBreakpointList::Options 60430fdc8d8SChris Lattner //------------------------------------------------------------------------- 605ae1c4cf5SJim Ingham #pragma mark List::CommandOptions 60630fdc8d8SChris Lattner 60730fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::CommandOptions() : 60830fdc8d8SChris Lattner Options (), 60930fdc8d8SChris Lattner m_level (lldb::eDescriptionLevelFull) // Breakpoint List defaults to brief descriptions 61030fdc8d8SChris Lattner { 61130fdc8d8SChris Lattner } 61230fdc8d8SChris Lattner 61330fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::~CommandOptions () 61430fdc8d8SChris Lattner { 61530fdc8d8SChris Lattner } 61630fdc8d8SChris Lattner 61730fdc8d8SChris Lattner lldb::OptionDefinition 61830fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::g_option_table[] = 61930fdc8d8SChris Lattner { 620deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone, 6218651121cSJim Ingham "Show debugger internal breakpoints" }, 6228651121cSJim Ingham 623deaab222SCaroline Tice { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone, 62430fdc8d8SChris Lattner "Give a brief description of the breakpoint (no location info)."}, 62530fdc8d8SChris Lattner 62630fdc8d8SChris Lattner // FIXME: We need to add an "internal" command, and then add this sort of thing to it. 62730fdc8d8SChris Lattner // But I need to see it for now, and don't want to wait. 628deaab222SCaroline Tice { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone, 62930fdc8d8SChris Lattner "Give a full description of the breakpoint and its locations."}, 63030fdc8d8SChris Lattner 631deaab222SCaroline Tice { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, 63230fdc8d8SChris Lattner "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, 63330fdc8d8SChris Lattner 634deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 63530fdc8d8SChris Lattner }; 63630fdc8d8SChris Lattner 63730fdc8d8SChris Lattner const lldb::OptionDefinition* 63830fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::GetDefinitions () 63930fdc8d8SChris Lattner { 64030fdc8d8SChris Lattner return g_option_table; 64130fdc8d8SChris Lattner } 64230fdc8d8SChris Lattner 64330fdc8d8SChris Lattner Error 64430fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) 64530fdc8d8SChris Lattner { 64630fdc8d8SChris Lattner Error error; 64730fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 64830fdc8d8SChris Lattner 64930fdc8d8SChris Lattner switch (short_option) 65030fdc8d8SChris Lattner { 65130fdc8d8SChris Lattner case 'b': 65230fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelBrief; 65330fdc8d8SChris Lattner break; 65430fdc8d8SChris Lattner case 'f': 65530fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelFull; 65630fdc8d8SChris Lattner break; 65730fdc8d8SChris Lattner case 'v': 65830fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelVerbose; 65930fdc8d8SChris Lattner break; 66030fdc8d8SChris Lattner case 'i': 66130fdc8d8SChris Lattner m_internal = true; 66230fdc8d8SChris Lattner break; 66330fdc8d8SChris Lattner default: 66430fdc8d8SChris Lattner error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 66530fdc8d8SChris Lattner break; 66630fdc8d8SChris Lattner } 66730fdc8d8SChris Lattner 66830fdc8d8SChris Lattner return error; 66930fdc8d8SChris Lattner } 67030fdc8d8SChris Lattner 67130fdc8d8SChris Lattner void 67230fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::ResetOptionValues () 67330fdc8d8SChris Lattner { 67430fdc8d8SChris Lattner Options::ResetOptionValues(); 67530fdc8d8SChris Lattner 67630fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelFull; 67730fdc8d8SChris Lattner m_internal = false; 67830fdc8d8SChris Lattner } 67930fdc8d8SChris Lattner 68030fdc8d8SChris Lattner //------------------------------------------------------------------------- 68130fdc8d8SChris Lattner // CommandObjectBreakpointList 68230fdc8d8SChris Lattner //------------------------------------------------------------------------- 683ae1c4cf5SJim Ingham #pragma mark List 68430fdc8d8SChris Lattner 685a7015092SGreg Clayton CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) : 686a7015092SGreg Clayton CommandObject (interpreter, 687a7015092SGreg Clayton "breakpoint list", 68830fdc8d8SChris Lattner "List some or all breakpoints at configurable levels of detail.", 689e139cf23SCaroline Tice NULL) 69030fdc8d8SChris Lattner { 691e139cf23SCaroline Tice CommandArgumentEntry arg; 692e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 693e139cf23SCaroline Tice 694e139cf23SCaroline Tice // Define the first (and only) variant of this arg. 695e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 696405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 697e139cf23SCaroline Tice 698e139cf23SCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 699e139cf23SCaroline Tice arg.push_back (bp_id_arg); 700e139cf23SCaroline Tice 701e139cf23SCaroline Tice // Push the data for the first argument into the m_arguments vector. 702e139cf23SCaroline Tice m_arguments.push_back (arg); 70330fdc8d8SChris Lattner } 70430fdc8d8SChris Lattner 70530fdc8d8SChris Lattner CommandObjectBreakpointList::~CommandObjectBreakpointList () 70630fdc8d8SChris Lattner { 70730fdc8d8SChris Lattner } 70830fdc8d8SChris Lattner 70930fdc8d8SChris Lattner Options * 71030fdc8d8SChris Lattner CommandObjectBreakpointList::GetOptions () 71130fdc8d8SChris Lattner { 71230fdc8d8SChris Lattner return &m_options; 71330fdc8d8SChris Lattner } 71430fdc8d8SChris Lattner 71530fdc8d8SChris Lattner bool 71630fdc8d8SChris Lattner CommandObjectBreakpointList::Execute 71730fdc8d8SChris Lattner ( 71830fdc8d8SChris Lattner Args& args, 71930fdc8d8SChris Lattner CommandReturnObject &result 72030fdc8d8SChris Lattner ) 72130fdc8d8SChris Lattner { 722a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 72330fdc8d8SChris Lattner if (target == NULL) 72430fdc8d8SChris Lattner { 7259068d794SCaroline Tice result.AppendError ("Invalid target. No current target or breakpoints."); 72630fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 72730fdc8d8SChris Lattner return true; 72830fdc8d8SChris Lattner } 72930fdc8d8SChris Lattner 73030fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal); 7311b54c88cSJim Ingham Mutex::Locker locker; 7321b54c88cSJim Ingham target->GetBreakpointList(m_options.m_internal).GetListMutex(locker); 7331b54c88cSJim Ingham 73430fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 73530fdc8d8SChris Lattner 73630fdc8d8SChris Lattner if (num_breakpoints == 0) 73730fdc8d8SChris Lattner { 73830fdc8d8SChris Lattner result.AppendMessage ("No breakpoints currently set."); 73930fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 74030fdc8d8SChris Lattner return true; 74130fdc8d8SChris Lattner } 74230fdc8d8SChris Lattner 74330fdc8d8SChris Lattner StreamString &output_stream = result.GetOutputStream(); 74430fdc8d8SChris Lattner 74530fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 74630fdc8d8SChris Lattner { 74730fdc8d8SChris Lattner // No breakpoint selected; show info about all currently set breakpoints. 74830fdc8d8SChris Lattner result.AppendMessage ("Current breakpoints:"); 749c982c768SGreg Clayton for (size_t i = 0; i < num_breakpoints; ++i) 75030fdc8d8SChris Lattner { 7519fed0d85SGreg Clayton Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get(); 7526611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 75330fdc8d8SChris Lattner } 75430fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 75530fdc8d8SChris Lattner } 75630fdc8d8SChris Lattner else 75730fdc8d8SChris Lattner { 75830fdc8d8SChris Lattner // Particular breakpoints selected; show info about that breakpoint. 75930fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 76030fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 76130fdc8d8SChris Lattner 76230fdc8d8SChris Lattner if (result.Succeeded()) 76330fdc8d8SChris Lattner { 764c982c768SGreg Clayton for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) 76530fdc8d8SChris Lattner { 76630fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 76730fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 7686611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 76930fdc8d8SChris Lattner } 77030fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 77130fdc8d8SChris Lattner } 77230fdc8d8SChris Lattner else 77330fdc8d8SChris Lattner { 77430fdc8d8SChris Lattner result.AppendError ("Invalid breakpoint id."); 77530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 77630fdc8d8SChris Lattner } 77730fdc8d8SChris Lattner } 77830fdc8d8SChris Lattner 77930fdc8d8SChris Lattner return result.Succeeded(); 78030fdc8d8SChris Lattner } 78130fdc8d8SChris Lattner 78230fdc8d8SChris Lattner //------------------------------------------------------------------------- 78330fdc8d8SChris Lattner // CommandObjectBreakpointEnable 78430fdc8d8SChris Lattner //------------------------------------------------------------------------- 785ae1c4cf5SJim Ingham #pragma mark Enable 78630fdc8d8SChris Lattner 787a7015092SGreg Clayton CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) : 788a7015092SGreg Clayton CommandObject (interpreter, 789a7015092SGreg Clayton "enable", 790e3d26315SCaroline Tice "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.", 791e139cf23SCaroline Tice NULL) 79230fdc8d8SChris Lattner { 793e139cf23SCaroline Tice CommandArgumentEntry arg; 794e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 795e139cf23SCaroline Tice CommandArgumentData bp_id_range_arg; 796e139cf23SCaroline Tice 797e139cf23SCaroline Tice // Create the first variant for the first (and only) argument for this command. 798e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 799405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 800e139cf23SCaroline Tice 801e139cf23SCaroline Tice // Create the second variant for the first (and only) argument for this command. 802e139cf23SCaroline Tice bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange; 803405fe67fSCaroline Tice bp_id_range_arg.arg_repetition = eArgRepeatOptional; 804e139cf23SCaroline Tice 805e139cf23SCaroline Tice // The first (and only) argument for this command could be either a bp_id or a bp_id_range. 806e139cf23SCaroline Tice // Push both variants into the entry for the first argument for this command. 807e139cf23SCaroline Tice arg.push_back (bp_id_arg); 808e139cf23SCaroline Tice arg.push_back (bp_id_range_arg); 809e139cf23SCaroline Tice 810e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 811e139cf23SCaroline Tice m_arguments.push_back (arg); 81230fdc8d8SChris Lattner } 81330fdc8d8SChris Lattner 81430fdc8d8SChris Lattner 81530fdc8d8SChris Lattner CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable () 81630fdc8d8SChris Lattner { 81730fdc8d8SChris Lattner } 81830fdc8d8SChris Lattner 81930fdc8d8SChris Lattner 82030fdc8d8SChris Lattner bool 8216611103cSGreg Clayton CommandObjectBreakpointEnable::Execute 8226611103cSGreg Clayton ( 8236611103cSGreg Clayton Args& args, 8246611103cSGreg Clayton CommandReturnObject &result 8256611103cSGreg Clayton ) 82630fdc8d8SChris Lattner { 827a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 82830fdc8d8SChris Lattner if (target == NULL) 82930fdc8d8SChris Lattner { 8309068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 83130fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 83230fdc8d8SChris Lattner return false; 83330fdc8d8SChris Lattner } 83430fdc8d8SChris Lattner 8351b54c88cSJim Ingham Mutex::Locker locker; 8361b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 8371b54c88cSJim Ingham 83830fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 8391b54c88cSJim Ingham 84030fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 84130fdc8d8SChris Lattner 84230fdc8d8SChris Lattner if (num_breakpoints == 0) 84330fdc8d8SChris Lattner { 84430fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be enabled."); 84530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 84630fdc8d8SChris Lattner return false; 84730fdc8d8SChris Lattner } 84830fdc8d8SChris Lattner 84930fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 85030fdc8d8SChris Lattner { 85130fdc8d8SChris Lattner // No breakpoint selected; enable all currently set breakpoints. 85230fdc8d8SChris Lattner target->EnableAllBreakpoints (); 85330fdc8d8SChris Lattner result.AppendMessageWithFormat ("All breakpoints enabled. (%d breakpoints)\n", num_breakpoints); 85430fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 85530fdc8d8SChris Lattner } 85630fdc8d8SChris Lattner else 85730fdc8d8SChris Lattner { 85830fdc8d8SChris Lattner // Particular breakpoint selected; enable that breakpoint. 85930fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 86030fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 86130fdc8d8SChris Lattner 86230fdc8d8SChris Lattner if (result.Succeeded()) 86330fdc8d8SChris Lattner { 86430fdc8d8SChris Lattner int enable_count = 0; 86530fdc8d8SChris Lattner int loc_count = 0; 866c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 867c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 86830fdc8d8SChris Lattner { 86930fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 87030fdc8d8SChris Lattner 87130fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 87230fdc8d8SChris Lattner { 87330fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 87430fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 87530fdc8d8SChris Lattner { 87630fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 87730fdc8d8SChris Lattner if (location) 87830fdc8d8SChris Lattner { 87930fdc8d8SChris Lattner location->SetEnabled (true); 88030fdc8d8SChris Lattner ++loc_count; 88130fdc8d8SChris Lattner } 88230fdc8d8SChris Lattner } 88330fdc8d8SChris Lattner else 88430fdc8d8SChris Lattner { 885ae1c4cf5SJim Ingham breakpoint->SetEnabled (true); 88630fdc8d8SChris Lattner ++enable_count; 88730fdc8d8SChris Lattner } 88830fdc8d8SChris Lattner } 88930fdc8d8SChris Lattner } 89030fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count); 89130fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 89230fdc8d8SChris Lattner } 89330fdc8d8SChris Lattner } 89430fdc8d8SChris Lattner 89530fdc8d8SChris Lattner return result.Succeeded(); 89630fdc8d8SChris Lattner } 89730fdc8d8SChris Lattner 89830fdc8d8SChris Lattner //------------------------------------------------------------------------- 89930fdc8d8SChris Lattner // CommandObjectBreakpointDisable 90030fdc8d8SChris Lattner //------------------------------------------------------------------------- 901ae1c4cf5SJim Ingham #pragma mark Disable 90230fdc8d8SChris Lattner 903a7015092SGreg Clayton CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) : 904a7015092SGreg Clayton CommandObject (interpreter, 905e139cf23SCaroline Tice "breakpoint disable", 906e3d26315SCaroline Tice "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.", 907e139cf23SCaroline Tice NULL) 90830fdc8d8SChris Lattner { 909e139cf23SCaroline Tice CommandArgumentEntry arg; 910e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 911e139cf23SCaroline Tice CommandArgumentData bp_id_range_arg; 912e139cf23SCaroline Tice 913e139cf23SCaroline Tice // Create the first variant for the first (and only) argument for this command. 914e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 915405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 916e139cf23SCaroline Tice 917e139cf23SCaroline Tice // Create the second variant for the first (and only) argument for this command. 918e139cf23SCaroline Tice bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange; 919405fe67fSCaroline Tice bp_id_range_arg.arg_repetition = eArgRepeatOptional; 920e139cf23SCaroline Tice 921e139cf23SCaroline Tice // The first (and only) argument for this command could be either a bp_id or a bp_id_range. 922e139cf23SCaroline Tice // Push both variants into the entry for the first argument for this command. 923e139cf23SCaroline Tice arg.push_back (bp_id_arg); 924e139cf23SCaroline Tice arg.push_back (bp_id_range_arg); 925e139cf23SCaroline Tice 926e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 927e139cf23SCaroline Tice m_arguments.push_back (arg); 92830fdc8d8SChris Lattner } 92930fdc8d8SChris Lattner 93030fdc8d8SChris Lattner CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable () 93130fdc8d8SChris Lattner { 93230fdc8d8SChris Lattner } 93330fdc8d8SChris Lattner 93430fdc8d8SChris Lattner bool 9356611103cSGreg Clayton CommandObjectBreakpointDisable::Execute 9366611103cSGreg Clayton ( 9376611103cSGreg Clayton Args& args, 9386611103cSGreg Clayton CommandReturnObject &result 9396611103cSGreg Clayton ) 94030fdc8d8SChris Lattner { 941a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 94230fdc8d8SChris Lattner if (target == NULL) 94330fdc8d8SChris Lattner { 9449068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 94530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 94630fdc8d8SChris Lattner return false; 94730fdc8d8SChris Lattner } 94830fdc8d8SChris Lattner 9491b54c88cSJim Ingham Mutex::Locker locker; 9501b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 9511b54c88cSJim Ingham 95230fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 95330fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 95430fdc8d8SChris Lattner 95530fdc8d8SChris Lattner if (num_breakpoints == 0) 95630fdc8d8SChris Lattner { 95730fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be disabled."); 95830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 95930fdc8d8SChris Lattner return false; 96030fdc8d8SChris Lattner } 96130fdc8d8SChris Lattner 96230fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 96330fdc8d8SChris Lattner { 96430fdc8d8SChris Lattner // No breakpoint selected; disable all currently set breakpoints. 96530fdc8d8SChris Lattner target->DisableAllBreakpoints (); 96630fdc8d8SChris Lattner result.AppendMessageWithFormat ("All breakpoints disabled. (%d breakpoints)\n", num_breakpoints); 96730fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 96830fdc8d8SChris Lattner } 96930fdc8d8SChris Lattner else 97030fdc8d8SChris Lattner { 97130fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 97230fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 97330fdc8d8SChris Lattner 97430fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 97530fdc8d8SChris Lattner 97630fdc8d8SChris Lattner if (result.Succeeded()) 97730fdc8d8SChris Lattner { 97830fdc8d8SChris Lattner int disable_count = 0; 97930fdc8d8SChris Lattner int loc_count = 0; 980c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 981c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 98230fdc8d8SChris Lattner { 98330fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 98430fdc8d8SChris Lattner 98530fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 98630fdc8d8SChris Lattner { 98730fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 98830fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 98930fdc8d8SChris Lattner { 99030fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 99130fdc8d8SChris Lattner if (location) 99230fdc8d8SChris Lattner { 99330fdc8d8SChris Lattner location->SetEnabled (false); 99430fdc8d8SChris Lattner ++loc_count; 99530fdc8d8SChris Lattner } 99630fdc8d8SChris Lattner } 99730fdc8d8SChris Lattner else 99830fdc8d8SChris Lattner { 999ae1c4cf5SJim Ingham breakpoint->SetEnabled (false); 100030fdc8d8SChris Lattner ++disable_count; 100130fdc8d8SChris Lattner } 100230fdc8d8SChris Lattner } 100330fdc8d8SChris Lattner } 100430fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count); 100530fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 100630fdc8d8SChris Lattner } 100730fdc8d8SChris Lattner } 100830fdc8d8SChris Lattner 100930fdc8d8SChris Lattner return result.Succeeded(); 101030fdc8d8SChris Lattner } 101130fdc8d8SChris Lattner 101230fdc8d8SChris Lattner //------------------------------------------------------------------------- 101330fdc8d8SChris Lattner // CommandObjectBreakpointDelete 101430fdc8d8SChris Lattner //------------------------------------------------------------------------- 1015ae1c4cf5SJim Ingham #pragma mark Delete 101630fdc8d8SChris Lattner 1017a7015092SGreg Clayton CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) : 1018a7015092SGreg Clayton CommandObject (interpreter, 1019a7015092SGreg Clayton "breakpoint delete", 1020e3d26315SCaroline Tice "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.", 1021e139cf23SCaroline Tice NULL) 102230fdc8d8SChris Lattner { 1023e139cf23SCaroline Tice CommandArgumentEntry arg; 1024e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 1025e139cf23SCaroline Tice CommandArgumentData bp_id_range_arg; 1026e139cf23SCaroline Tice 1027e139cf23SCaroline Tice // Create the first variant for the first (and only) argument for this command. 1028e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 1029405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 1030e139cf23SCaroline Tice 1031e139cf23SCaroline Tice // Create the second variant for the first (and only) argument for this command. 1032e139cf23SCaroline Tice bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange; 1033405fe67fSCaroline Tice bp_id_range_arg.arg_repetition = eArgRepeatOptional; 1034e139cf23SCaroline Tice 1035e139cf23SCaroline Tice // The first (and only) argument for this command could be either a bp_id or a bp_id_range. 1036e139cf23SCaroline Tice // Push both variants into the entry for the first argument for this command. 1037e139cf23SCaroline Tice arg.push_back (bp_id_arg); 1038e139cf23SCaroline Tice arg.push_back (bp_id_range_arg); 1039e139cf23SCaroline Tice 1040e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1041e139cf23SCaroline Tice m_arguments.push_back (arg); 104230fdc8d8SChris Lattner } 104330fdc8d8SChris Lattner 104430fdc8d8SChris Lattner 104530fdc8d8SChris Lattner CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete () 104630fdc8d8SChris Lattner { 104730fdc8d8SChris Lattner } 104830fdc8d8SChris Lattner 104930fdc8d8SChris Lattner bool 10506611103cSGreg Clayton CommandObjectBreakpointDelete::Execute 10516611103cSGreg Clayton ( 10526611103cSGreg Clayton Args& args, 10536611103cSGreg Clayton CommandReturnObject &result 10546611103cSGreg Clayton ) 105530fdc8d8SChris Lattner { 1056a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 105730fdc8d8SChris Lattner if (target == NULL) 105830fdc8d8SChris Lattner { 10599068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 106030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 106130fdc8d8SChris Lattner return false; 106230fdc8d8SChris Lattner } 106330fdc8d8SChris Lattner 10641b54c88cSJim Ingham Mutex::Locker locker; 10651b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 10661b54c88cSJim Ingham 106730fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 10681b54c88cSJim Ingham 106930fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 107030fdc8d8SChris Lattner 107130fdc8d8SChris Lattner if (num_breakpoints == 0) 107230fdc8d8SChris Lattner { 107330fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be deleted."); 107430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 107530fdc8d8SChris Lattner return false; 107630fdc8d8SChris Lattner } 107730fdc8d8SChris Lattner 107830fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 107930fdc8d8SChris Lattner { 108030fdc8d8SChris Lattner // No breakpoint selected; disable all currently set breakpoints. 108130fdc8d8SChris Lattner if (args.GetArgumentCount() != 0) 108230fdc8d8SChris Lattner { 108330fdc8d8SChris Lattner result.AppendErrorWithFormat ("Specify breakpoints to delete with the -i option.\n"); 108430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 108530fdc8d8SChris Lattner return false; 108630fdc8d8SChris Lattner } 108730fdc8d8SChris Lattner 108830fdc8d8SChris Lattner target->RemoveAllBreakpoints (); 108930fdc8d8SChris Lattner result.AppendMessageWithFormat ("All breakpoints removed. (%d breakpoints)\n", num_breakpoints); 109030fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 109130fdc8d8SChris Lattner } 109230fdc8d8SChris Lattner else 109330fdc8d8SChris Lattner { 109430fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 109530fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 109630fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 109730fdc8d8SChris Lattner 109830fdc8d8SChris Lattner if (result.Succeeded()) 109930fdc8d8SChris Lattner { 110030fdc8d8SChris Lattner int delete_count = 0; 110130fdc8d8SChris Lattner int disable_count = 0; 1102c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1103c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 110430fdc8d8SChris Lattner { 110530fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 110630fdc8d8SChris Lattner 110730fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 110830fdc8d8SChris Lattner { 110930fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 111030fdc8d8SChris Lattner { 111130fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 111230fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 111330fdc8d8SChris Lattner // It makes no sense to try to delete individual locations, so we disable them instead. 111430fdc8d8SChris Lattner if (location) 111530fdc8d8SChris Lattner { 111630fdc8d8SChris Lattner location->SetEnabled (false); 111730fdc8d8SChris Lattner ++disable_count; 111830fdc8d8SChris Lattner } 111930fdc8d8SChris Lattner } 112030fdc8d8SChris Lattner else 112130fdc8d8SChris Lattner { 112230fdc8d8SChris Lattner target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID()); 112330fdc8d8SChris Lattner ++delete_count; 112430fdc8d8SChris Lattner } 112530fdc8d8SChris Lattner } 112630fdc8d8SChris Lattner } 112730fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n", 112830fdc8d8SChris Lattner delete_count, disable_count); 112930fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 113030fdc8d8SChris Lattner } 113130fdc8d8SChris Lattner } 113230fdc8d8SChris Lattner return result.Succeeded(); 113330fdc8d8SChris Lattner } 11341b54c88cSJim Ingham 11351b54c88cSJim Ingham //------------------------------------------------------------------------- 1136ae1c4cf5SJim Ingham // CommandObjectBreakpointModify::CommandOptions 11371b54c88cSJim Ingham //------------------------------------------------------------------------- 1138ae1c4cf5SJim Ingham #pragma mark Modify::CommandOptions 11391b54c88cSJim Ingham 1140ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::CommandOptions() : 11411b54c88cSJim Ingham Options (), 1142c982c768SGreg Clayton m_ignore_count (0), 11431b54c88cSJim Ingham m_thread_id(LLDB_INVALID_THREAD_ID), 1144c982c768SGreg Clayton m_thread_index (UINT32_MAX), 11451b54c88cSJim Ingham m_thread_name(), 11461b54c88cSJim Ingham m_queue_name(), 1147c982c768SGreg Clayton m_enable_passed (false), 1148c982c768SGreg Clayton m_enable_value (false), 1149c982c768SGreg Clayton m_name_passed (false), 1150c982c768SGreg Clayton m_queue_passed (false) 11511b54c88cSJim Ingham { 11521b54c88cSJim Ingham } 11531b54c88cSJim Ingham 1154ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::~CommandOptions () 11551b54c88cSJim Ingham { 11561b54c88cSJim Ingham } 11571b54c88cSJim Ingham 11581b54c88cSJim Ingham lldb::OptionDefinition 1159ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] = 11601b54c88cSJim Ingham { 1161deaab222SCaroline 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." }, 1162deaab222SCaroline 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."}, 1163deaab222SCaroline 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."}, 1164deaab222SCaroline 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."}, 1165deaab222SCaroline 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."}, 1166deaab222SCaroline Tice { LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, eArgTypeNone, "Enable the breakpoint."}, 1167deaab222SCaroline Tice { LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, eArgTypeNone, "Disable the breakpoint."}, 1168deaab222SCaroline Tice { 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } 11691b54c88cSJim Ingham }; 11701b54c88cSJim Ingham 11711b54c88cSJim Ingham const lldb::OptionDefinition* 1172ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::GetDefinitions () 11731b54c88cSJim Ingham { 11741b54c88cSJim Ingham return g_option_table; 11751b54c88cSJim Ingham } 11761b54c88cSJim Ingham 11771b54c88cSJim Ingham Error 1178ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) 11791b54c88cSJim Ingham { 11801b54c88cSJim Ingham Error error; 11811b54c88cSJim Ingham char short_option = (char) m_getopt_table[option_idx].val; 11821b54c88cSJim Ingham 11831b54c88cSJim Ingham switch (short_option) 11841b54c88cSJim Ingham { 1185ae1c4cf5SJim Ingham case 'd': 1186ae1c4cf5SJim Ingham m_enable_passed = true; 1187ae1c4cf5SJim Ingham m_enable_value = false; 1188ae1c4cf5SJim Ingham break; 1189ae1c4cf5SJim Ingham case 'e': 1190ae1c4cf5SJim Ingham m_enable_passed = true; 1191ae1c4cf5SJim Ingham m_enable_value = true; 1192ae1c4cf5SJim Ingham break; 1193ed8a705cSGreg Clayton case 'i': 11941b54c88cSJim Ingham { 1195c982c768SGreg Clayton m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0); 1196c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 11971b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg); 11981b54c88cSJim Ingham } 1199ae1c4cf5SJim Ingham break; 12001b54c88cSJim Ingham case 't' : 12011b54c88cSJim Ingham { 12021b54c88cSJim Ingham m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0); 12031b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 12041b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg); 12051b54c88cSJim Ingham } 12061b54c88cSJim Ingham break; 12071b54c88cSJim Ingham case 'T': 1208b2a38a72SJim Ingham if (option_arg != NULL) 12091b54c88cSJim Ingham m_thread_name = option_arg; 1210b2a38a72SJim Ingham else 1211b2a38a72SJim Ingham m_thread_name.clear(); 1212b2a38a72SJim Ingham m_name_passed = true; 12131b54c88cSJim Ingham break; 12141b54c88cSJim Ingham case 'q': 1215b2a38a72SJim Ingham if (option_arg != NULL) 12161b54c88cSJim Ingham m_queue_name = option_arg; 1217b2a38a72SJim Ingham else 1218b2a38a72SJim Ingham m_queue_name.clear(); 1219b2a38a72SJim Ingham m_queue_passed = true; 12201b54c88cSJim Ingham break; 12211b54c88cSJim Ingham case 'x': 12221b54c88cSJim Ingham { 1223c982c768SGreg Clayton m_thread_index = Args::StringToUInt32 (optarg, UINT32_MAX, 0); 1224c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 12251b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg); 12261b54c88cSJim Ingham 12271b54c88cSJim Ingham } 12281b54c88cSJim Ingham break; 12291b54c88cSJim Ingham default: 12301b54c88cSJim Ingham error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 12311b54c88cSJim Ingham break; 12321b54c88cSJim Ingham } 12331b54c88cSJim Ingham 12341b54c88cSJim Ingham return error; 12351b54c88cSJim Ingham } 12361b54c88cSJim Ingham 12371b54c88cSJim Ingham void 1238ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::ResetOptionValues () 12391b54c88cSJim Ingham { 12401b54c88cSJim Ingham Options::ResetOptionValues(); 12411b54c88cSJim Ingham 1242c982c768SGreg Clayton m_ignore_count = 0; 12431b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 1244c982c768SGreg Clayton m_thread_index = UINT32_MAX; 12451b54c88cSJim Ingham m_thread_name.clear(); 12461b54c88cSJim Ingham m_queue_name.clear(); 1247ae1c4cf5SJim Ingham m_enable_passed = false; 1248b2a38a72SJim Ingham m_queue_passed = false; 1249b2a38a72SJim Ingham m_name_passed = false; 12501b54c88cSJim Ingham } 12511b54c88cSJim Ingham 12521b54c88cSJim Ingham //------------------------------------------------------------------------- 1253ae1c4cf5SJim Ingham // CommandObjectBreakpointModify 12541b54c88cSJim Ingham //------------------------------------------------------------------------- 1255ae1c4cf5SJim Ingham #pragma mark Modify 12561b54c88cSJim Ingham 1257a7015092SGreg Clayton CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) : 1258a7015092SGreg Clayton CommandObject (interpreter, 1259a7015092SGreg Clayton "breakpoint modify", 1260a7015092SGreg Clayton "Modify the options on a breakpoint or set of breakpoints in the executable.", 1261e139cf23SCaroline Tice NULL) 12621b54c88cSJim Ingham { 1263e139cf23SCaroline Tice CommandArgumentEntry arg; 1264e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 1265e139cf23SCaroline Tice CommandArgumentData bp_id_range_arg; 1266e139cf23SCaroline Tice 1267e139cf23SCaroline Tice // Create the first variant for the first (and only) argument for this command. 1268e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 1269405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatPlain; 1270e139cf23SCaroline Tice 1271e139cf23SCaroline Tice // Create the second variant for the first (and only) argument for this command. 1272e139cf23SCaroline Tice bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange; 1273405fe67fSCaroline Tice bp_id_range_arg.arg_repetition = eArgRepeatPlain; 1274e139cf23SCaroline Tice 1275e139cf23SCaroline Tice // The first (and only) argument for this command could be either a bp_id or a bp_id_range. 1276e139cf23SCaroline Tice // Push both variants into the entry for the first argument for this command. 1277e139cf23SCaroline Tice arg.push_back (bp_id_arg); 1278e139cf23SCaroline Tice arg.push_back (bp_id_range_arg); 1279e139cf23SCaroline Tice 1280e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1281e139cf23SCaroline Tice m_arguments.push_back (arg); 12821b54c88cSJim Ingham } 12831b54c88cSJim Ingham 1284ae1c4cf5SJim Ingham CommandObjectBreakpointModify::~CommandObjectBreakpointModify () 12851b54c88cSJim Ingham { 12861b54c88cSJim Ingham } 12871b54c88cSJim Ingham 12881b54c88cSJim Ingham Options * 1289ae1c4cf5SJim Ingham CommandObjectBreakpointModify::GetOptions () 12901b54c88cSJim Ingham { 12911b54c88cSJim Ingham return &m_options; 12921b54c88cSJim Ingham } 12931b54c88cSJim Ingham 12941b54c88cSJim Ingham bool 1295ae1c4cf5SJim Ingham CommandObjectBreakpointModify::Execute 12961b54c88cSJim Ingham ( 12971b54c88cSJim Ingham Args& command, 12981b54c88cSJim Ingham CommandReturnObject &result 12991b54c88cSJim Ingham ) 13001b54c88cSJim Ingham { 13011b54c88cSJim Ingham if (command.GetArgumentCount() == 0) 13021b54c88cSJim Ingham { 13031b54c88cSJim Ingham result.AppendError ("No breakpoints specified."); 13041b54c88cSJim Ingham result.SetStatus (eReturnStatusFailed); 13051b54c88cSJim Ingham return false; 13061b54c88cSJim Ingham } 13071b54c88cSJim Ingham 1308a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 13091b54c88cSJim Ingham if (target == NULL) 13101b54c88cSJim Ingham { 13119068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 13121b54c88cSJim Ingham result.SetStatus (eReturnStatusFailed); 13131b54c88cSJim Ingham return false; 13141b54c88cSJim Ingham } 13151b54c88cSJim Ingham 13161b54c88cSJim Ingham Mutex::Locker locker; 13171b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 13181b54c88cSJim Ingham 13191b54c88cSJim Ingham BreakpointIDList valid_bp_ids; 13201b54c88cSJim Ingham 13211b54c88cSJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 13221b54c88cSJim Ingham 13231b54c88cSJim Ingham if (result.Succeeded()) 13241b54c88cSJim Ingham { 1325c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1326c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 13271b54c88cSJim Ingham { 13281b54c88cSJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 13291b54c88cSJim Ingham 13301b54c88cSJim Ingham if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 13311b54c88cSJim Ingham { 13321b54c88cSJim Ingham Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 13331b54c88cSJim Ingham if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 13341b54c88cSJim Ingham { 13351b54c88cSJim Ingham BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get(); 13361b54c88cSJim Ingham if (location) 13371b54c88cSJim Ingham { 13381b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 13391b54c88cSJim Ingham location->SetThreadID (m_options.m_thread_id); 13401b54c88cSJim Ingham 1341c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 13421b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 13431b54c88cSJim Ingham 1344b2a38a72SJim Ingham if (m_options.m_name_passed) 13451b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 13461b54c88cSJim Ingham 1347b2a38a72SJim Ingham if (m_options.m_queue_passed) 13481b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 13491b54c88cSJim Ingham 1350c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 13511b54c88cSJim Ingham location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count); 1352ae1c4cf5SJim Ingham 1353ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1354ae1c4cf5SJim Ingham location->SetEnabled (m_options.m_enable_value); 13551b54c88cSJim Ingham } 13561b54c88cSJim Ingham } 13571b54c88cSJim Ingham else 13581b54c88cSJim Ingham { 13591b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 13601b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 13611b54c88cSJim Ingham 1362c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 13631b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 13641b54c88cSJim Ingham 1365b2a38a72SJim Ingham if (m_options.m_name_passed) 13661b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 13671b54c88cSJim Ingham 1368b2a38a72SJim Ingham if (m_options.m_queue_passed) 13691b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 13701b54c88cSJim Ingham 1371c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 13721b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 1373ae1c4cf5SJim Ingham 1374ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1375ae1c4cf5SJim Ingham bp->SetEnabled (m_options.m_enable_value); 1376ae1c4cf5SJim Ingham 13771b54c88cSJim Ingham } 13781b54c88cSJim Ingham } 13791b54c88cSJim Ingham } 13801b54c88cSJim Ingham } 13811b54c88cSJim Ingham 13821b54c88cSJim Ingham return result.Succeeded(); 13831b54c88cSJim Ingham } 13841b54c88cSJim Ingham 13851b54c88cSJim Ingham 1386