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; 38430fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 38530fdc8d8SChris Lattner bp = target->CreateBreakpoint (m_options.m_load_addr, false).get(); 38630fdc8d8SChris Lattner break; 3870c5cd90dSGreg Clayton 38830fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 3890c5cd90dSGreg Clayton { 3900c5cd90dSGreg Clayton uint32_t name_type_mask = m_options.m_func_name_type_mask; 3910c5cd90dSGreg Clayton 3920c5cd90dSGreg Clayton if (name_type_mask == 0) 3930c5cd90dSGreg Clayton { 3940c5cd90dSGreg Clayton 3950c5cd90dSGreg Clayton if (m_options.m_func_name.find('(') != std::string::npos || 3960c5cd90dSGreg Clayton m_options.m_func_name.find("-[") == 0 || 3970c5cd90dSGreg Clayton m_options.m_func_name.find("+[") == 0) 3980c5cd90dSGreg Clayton name_type_mask |= eFunctionNameTypeFull; 3990c5cd90dSGreg Clayton else 4000c5cd90dSGreg Clayton name_type_mask |= eFunctionNameTypeBase; 4010c5cd90dSGreg Clayton } 4020c5cd90dSGreg Clayton 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. 55030fdc8d8SChris Lattner 55130fdc8d8SChris Lattner Args temp_args; 55230fdc8d8SChris Lattner 55330fdc8d8SChris Lattner // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to 55430fdc8d8SChris Lattner // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for 55530fdc8d8SChris Lattner // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS. 55630fdc8d8SChris Lattner 55730fdc8d8SChris Lattner BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args); 55830fdc8d8SChris Lattner 55930fdc8d8SChris Lattner // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList: 56030fdc8d8SChris Lattner 561c982c768SGreg Clayton valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result); 56230fdc8d8SChris Lattner 56330fdc8d8SChris Lattner // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs 56430fdc8d8SChris Lattner // and put into valid_ids. 56530fdc8d8SChris Lattner 56630fdc8d8SChris Lattner if (result.Succeeded()) 56730fdc8d8SChris Lattner { 56830fdc8d8SChris Lattner // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list 56930fdc8d8SChris Lattner // of breakpoint id's and verify that they correspond to valid/currently set breakpoints. 57030fdc8d8SChris Lattner 571c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 572c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 57330fdc8d8SChris Lattner { 57430fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i); 57530fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 57630fdc8d8SChris Lattner if (breakpoint != NULL) 57730fdc8d8SChris Lattner { 57830fdc8d8SChris Lattner int num_locations = breakpoint->GetNumLocations(); 57930fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() > num_locations) 58030fdc8d8SChris Lattner { 58130fdc8d8SChris Lattner StreamString id_str; 582c982c768SGreg Clayton BreakpointID::GetCanonicalReference (&id_str, 583c982c768SGreg Clayton cur_bp_id.GetBreakpointID(), 58430fdc8d8SChris Lattner cur_bp_id.GetLocationID()); 585c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 58630fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n", 58730fdc8d8SChris Lattner id_str.GetData()); 58830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 58930fdc8d8SChris Lattner } 59030fdc8d8SChris Lattner } 59130fdc8d8SChris Lattner else 59230fdc8d8SChris Lattner { 593c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 59430fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID()); 59530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 59630fdc8d8SChris Lattner } 59730fdc8d8SChris Lattner } 59830fdc8d8SChris Lattner } 59930fdc8d8SChris Lattner } 60030fdc8d8SChris Lattner 60130fdc8d8SChris Lattner //------------------------------------------------------------------------- 60230fdc8d8SChris Lattner // CommandObjectBreakpointList::Options 60330fdc8d8SChris Lattner //------------------------------------------------------------------------- 604ae1c4cf5SJim Ingham #pragma mark List::CommandOptions 60530fdc8d8SChris Lattner 60630fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::CommandOptions() : 60730fdc8d8SChris Lattner Options (), 60830fdc8d8SChris Lattner m_level (lldb::eDescriptionLevelFull) // Breakpoint List defaults to brief descriptions 60930fdc8d8SChris Lattner { 61030fdc8d8SChris Lattner } 61130fdc8d8SChris Lattner 61230fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::~CommandOptions () 61330fdc8d8SChris Lattner { 61430fdc8d8SChris Lattner } 61530fdc8d8SChris Lattner 61630fdc8d8SChris Lattner lldb::OptionDefinition 61730fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::g_option_table[] = 61830fdc8d8SChris Lattner { 619deaab222SCaroline Tice { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone, 6208651121cSJim Ingham "Show debugger internal breakpoints" }, 6218651121cSJim Ingham 622deaab222SCaroline Tice { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone, 62330fdc8d8SChris Lattner "Give a brief description of the breakpoint (no location info)."}, 62430fdc8d8SChris Lattner 62530fdc8d8SChris Lattner // FIXME: We need to add an "internal" command, and then add this sort of thing to it. 62630fdc8d8SChris Lattner // But I need to see it for now, and don't want to wait. 627deaab222SCaroline Tice { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone, 62830fdc8d8SChris Lattner "Give a full description of the breakpoint and its locations."}, 62930fdc8d8SChris Lattner 630deaab222SCaroline Tice { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, 63130fdc8d8SChris Lattner "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, 63230fdc8d8SChris Lattner 633deaab222SCaroline Tice { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 63430fdc8d8SChris Lattner }; 63530fdc8d8SChris Lattner 63630fdc8d8SChris Lattner const lldb::OptionDefinition* 63730fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::GetDefinitions () 63830fdc8d8SChris Lattner { 63930fdc8d8SChris Lattner return g_option_table; 64030fdc8d8SChris Lattner } 64130fdc8d8SChris Lattner 64230fdc8d8SChris Lattner Error 64330fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) 64430fdc8d8SChris Lattner { 64530fdc8d8SChris Lattner Error error; 64630fdc8d8SChris Lattner char short_option = (char) m_getopt_table[option_idx].val; 64730fdc8d8SChris Lattner 64830fdc8d8SChris Lattner switch (short_option) 64930fdc8d8SChris Lattner { 65030fdc8d8SChris Lattner case 'b': 65130fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelBrief; 65230fdc8d8SChris Lattner break; 65330fdc8d8SChris Lattner case 'f': 65430fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelFull; 65530fdc8d8SChris Lattner break; 65630fdc8d8SChris Lattner case 'v': 65730fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelVerbose; 65830fdc8d8SChris Lattner break; 65930fdc8d8SChris Lattner case 'i': 66030fdc8d8SChris Lattner m_internal = true; 66130fdc8d8SChris Lattner break; 66230fdc8d8SChris Lattner default: 66330fdc8d8SChris Lattner error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 66430fdc8d8SChris Lattner break; 66530fdc8d8SChris Lattner } 66630fdc8d8SChris Lattner 66730fdc8d8SChris Lattner return error; 66830fdc8d8SChris Lattner } 66930fdc8d8SChris Lattner 67030fdc8d8SChris Lattner void 67130fdc8d8SChris Lattner CommandObjectBreakpointList::CommandOptions::ResetOptionValues () 67230fdc8d8SChris Lattner { 67330fdc8d8SChris Lattner Options::ResetOptionValues(); 67430fdc8d8SChris Lattner 67530fdc8d8SChris Lattner m_level = lldb::eDescriptionLevelFull; 67630fdc8d8SChris Lattner m_internal = false; 67730fdc8d8SChris Lattner } 67830fdc8d8SChris Lattner 67930fdc8d8SChris Lattner //------------------------------------------------------------------------- 68030fdc8d8SChris Lattner // CommandObjectBreakpointList 68130fdc8d8SChris Lattner //------------------------------------------------------------------------- 682ae1c4cf5SJim Ingham #pragma mark List 68330fdc8d8SChris Lattner 684a7015092SGreg Clayton CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) : 685a7015092SGreg Clayton CommandObject (interpreter, 686a7015092SGreg Clayton "breakpoint list", 68730fdc8d8SChris Lattner "List some or all breakpoints at configurable levels of detail.", 688e139cf23SCaroline Tice NULL) 68930fdc8d8SChris Lattner { 690e139cf23SCaroline Tice CommandArgumentEntry arg; 691e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 692e139cf23SCaroline Tice 693e139cf23SCaroline Tice // Define the first (and only) variant of this arg. 694e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 695*405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 696e139cf23SCaroline Tice 697e139cf23SCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 698e139cf23SCaroline Tice arg.push_back (bp_id_arg); 699e139cf23SCaroline Tice 700e139cf23SCaroline Tice // Push the data for the first argument into the m_arguments vector. 701e139cf23SCaroline Tice m_arguments.push_back (arg); 70230fdc8d8SChris Lattner } 70330fdc8d8SChris Lattner 70430fdc8d8SChris Lattner CommandObjectBreakpointList::~CommandObjectBreakpointList () 70530fdc8d8SChris Lattner { 70630fdc8d8SChris Lattner } 70730fdc8d8SChris Lattner 70830fdc8d8SChris Lattner Options * 70930fdc8d8SChris Lattner CommandObjectBreakpointList::GetOptions () 71030fdc8d8SChris Lattner { 71130fdc8d8SChris Lattner return &m_options; 71230fdc8d8SChris Lattner } 71330fdc8d8SChris Lattner 71430fdc8d8SChris Lattner bool 71530fdc8d8SChris Lattner CommandObjectBreakpointList::Execute 71630fdc8d8SChris Lattner ( 71730fdc8d8SChris Lattner Args& args, 71830fdc8d8SChris Lattner CommandReturnObject &result 71930fdc8d8SChris Lattner ) 72030fdc8d8SChris Lattner { 721a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 72230fdc8d8SChris Lattner if (target == NULL) 72330fdc8d8SChris Lattner { 7249068d794SCaroline Tice result.AppendError ("Invalid target. No current target or breakpoints."); 72530fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 72630fdc8d8SChris Lattner return true; 72730fdc8d8SChris Lattner } 72830fdc8d8SChris Lattner 72930fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal); 7301b54c88cSJim Ingham Mutex::Locker locker; 7311b54c88cSJim Ingham target->GetBreakpointList(m_options.m_internal).GetListMutex(locker); 7321b54c88cSJim Ingham 73330fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 73430fdc8d8SChris Lattner 73530fdc8d8SChris Lattner if (num_breakpoints == 0) 73630fdc8d8SChris Lattner { 73730fdc8d8SChris Lattner result.AppendMessage ("No breakpoints currently set."); 73830fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 73930fdc8d8SChris Lattner return true; 74030fdc8d8SChris Lattner } 74130fdc8d8SChris Lattner 74230fdc8d8SChris Lattner StreamString &output_stream = result.GetOutputStream(); 74330fdc8d8SChris Lattner 74430fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 74530fdc8d8SChris Lattner { 74630fdc8d8SChris Lattner // No breakpoint selected; show info about all currently set breakpoints. 74730fdc8d8SChris Lattner result.AppendMessage ("Current breakpoints:"); 748c982c768SGreg Clayton for (size_t i = 0; i < num_breakpoints; ++i) 74930fdc8d8SChris Lattner { 7509fed0d85SGreg Clayton Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get(); 7516611103cSGreg Clayton AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 75230fdc8d8SChris Lattner } 75330fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 75430fdc8d8SChris Lattner } 75530fdc8d8SChris Lattner else 75630fdc8d8SChris Lattner { 75730fdc8d8SChris Lattner // Particular breakpoints selected; show info about that breakpoint. 75830fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 75930fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 76030fdc8d8SChris Lattner 76130fdc8d8SChris Lattner if (result.Succeeded()) 76230fdc8d8SChris Lattner { 763c982c768SGreg Clayton for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) 76430fdc8d8SChris Lattner { 76530fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 76630fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).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 result.AppendError ("Invalid breakpoint id."); 77430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 77530fdc8d8SChris Lattner } 77630fdc8d8SChris Lattner } 77730fdc8d8SChris Lattner 77830fdc8d8SChris Lattner return result.Succeeded(); 77930fdc8d8SChris Lattner } 78030fdc8d8SChris Lattner 78130fdc8d8SChris Lattner //------------------------------------------------------------------------- 78230fdc8d8SChris Lattner // CommandObjectBreakpointEnable 78330fdc8d8SChris Lattner //------------------------------------------------------------------------- 784ae1c4cf5SJim Ingham #pragma mark Enable 78530fdc8d8SChris Lattner 786a7015092SGreg Clayton CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) : 787a7015092SGreg Clayton CommandObject (interpreter, 788a7015092SGreg Clayton "enable", 789e3d26315SCaroline Tice "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.", 790e139cf23SCaroline Tice NULL) 79130fdc8d8SChris Lattner { 792e139cf23SCaroline Tice CommandArgumentEntry arg; 793e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 794e139cf23SCaroline Tice CommandArgumentData bp_id_range_arg; 795e139cf23SCaroline Tice 796e139cf23SCaroline Tice // Create the first variant for the first (and only) argument for this command. 797e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 798*405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 799e139cf23SCaroline Tice 800e139cf23SCaroline Tice // Create the second variant for the first (and only) argument for this command. 801e139cf23SCaroline Tice bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange; 802*405fe67fSCaroline Tice bp_id_range_arg.arg_repetition = eArgRepeatOptional; 803e139cf23SCaroline Tice 804e139cf23SCaroline Tice // The first (and only) argument for this command could be either a bp_id or a bp_id_range. 805e139cf23SCaroline Tice // Push both variants into the entry for the first argument for this command. 806e139cf23SCaroline Tice arg.push_back (bp_id_arg); 807e139cf23SCaroline Tice arg.push_back (bp_id_range_arg); 808e139cf23SCaroline Tice 809e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 810e139cf23SCaroline Tice m_arguments.push_back (arg); 81130fdc8d8SChris Lattner } 81230fdc8d8SChris Lattner 81330fdc8d8SChris Lattner 81430fdc8d8SChris Lattner CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable () 81530fdc8d8SChris Lattner { 81630fdc8d8SChris Lattner } 81730fdc8d8SChris Lattner 81830fdc8d8SChris Lattner 81930fdc8d8SChris Lattner bool 8206611103cSGreg Clayton CommandObjectBreakpointEnable::Execute 8216611103cSGreg Clayton ( 8226611103cSGreg Clayton Args& args, 8236611103cSGreg Clayton CommandReturnObject &result 8246611103cSGreg Clayton ) 82530fdc8d8SChris Lattner { 826a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 82730fdc8d8SChris Lattner if (target == NULL) 82830fdc8d8SChris Lattner { 8299068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 83030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 83130fdc8d8SChris Lattner return false; 83230fdc8d8SChris Lattner } 83330fdc8d8SChris Lattner 8341b54c88cSJim Ingham Mutex::Locker locker; 8351b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 8361b54c88cSJim Ingham 83730fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 8381b54c88cSJim Ingham 83930fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 84030fdc8d8SChris Lattner 84130fdc8d8SChris Lattner if (num_breakpoints == 0) 84230fdc8d8SChris Lattner { 84330fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be enabled."); 84430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 84530fdc8d8SChris Lattner return false; 84630fdc8d8SChris Lattner } 84730fdc8d8SChris Lattner 84830fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 84930fdc8d8SChris Lattner { 85030fdc8d8SChris Lattner // No breakpoint selected; enable all currently set breakpoints. 85130fdc8d8SChris Lattner target->EnableAllBreakpoints (); 85230fdc8d8SChris Lattner result.AppendMessageWithFormat ("All breakpoints enabled. (%d breakpoints)\n", num_breakpoints); 85330fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 85430fdc8d8SChris Lattner } 85530fdc8d8SChris Lattner else 85630fdc8d8SChris Lattner { 85730fdc8d8SChris Lattner // Particular breakpoint selected; enable that breakpoint. 85830fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 85930fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 86030fdc8d8SChris Lattner 86130fdc8d8SChris Lattner if (result.Succeeded()) 86230fdc8d8SChris Lattner { 86330fdc8d8SChris Lattner int enable_count = 0; 86430fdc8d8SChris Lattner int loc_count = 0; 865c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 866c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 86730fdc8d8SChris Lattner { 86830fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 86930fdc8d8SChris Lattner 87030fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 87130fdc8d8SChris Lattner { 87230fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 87330fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 87430fdc8d8SChris Lattner { 87530fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 87630fdc8d8SChris Lattner if (location) 87730fdc8d8SChris Lattner { 87830fdc8d8SChris Lattner location->SetEnabled (true); 87930fdc8d8SChris Lattner ++loc_count; 88030fdc8d8SChris Lattner } 88130fdc8d8SChris Lattner } 88230fdc8d8SChris Lattner else 88330fdc8d8SChris Lattner { 884ae1c4cf5SJim Ingham breakpoint->SetEnabled (true); 88530fdc8d8SChris Lattner ++enable_count; 88630fdc8d8SChris Lattner } 88730fdc8d8SChris Lattner } 88830fdc8d8SChris Lattner } 88930fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count); 89030fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 89130fdc8d8SChris Lattner } 89230fdc8d8SChris Lattner } 89330fdc8d8SChris Lattner 89430fdc8d8SChris Lattner return result.Succeeded(); 89530fdc8d8SChris Lattner } 89630fdc8d8SChris Lattner 89730fdc8d8SChris Lattner //------------------------------------------------------------------------- 89830fdc8d8SChris Lattner // CommandObjectBreakpointDisable 89930fdc8d8SChris Lattner //------------------------------------------------------------------------- 900ae1c4cf5SJim Ingham #pragma mark Disable 90130fdc8d8SChris Lattner 902a7015092SGreg Clayton CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) : 903a7015092SGreg Clayton CommandObject (interpreter, 904e139cf23SCaroline Tice "breakpoint disable", 905e3d26315SCaroline Tice "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.", 906e139cf23SCaroline Tice NULL) 90730fdc8d8SChris Lattner { 908e139cf23SCaroline Tice CommandArgumentEntry arg; 909e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 910e139cf23SCaroline Tice CommandArgumentData bp_id_range_arg; 911e139cf23SCaroline Tice 912e139cf23SCaroline Tice // Create the first variant for the first (and only) argument for this command. 913e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 914*405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 915e139cf23SCaroline Tice 916e139cf23SCaroline Tice // Create the second variant for the first (and only) argument for this command. 917e139cf23SCaroline Tice bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange; 918*405fe67fSCaroline Tice bp_id_range_arg.arg_repetition = eArgRepeatOptional; 919e139cf23SCaroline Tice 920e139cf23SCaroline Tice // The first (and only) argument for this command could be either a bp_id or a bp_id_range. 921e139cf23SCaroline Tice // Push both variants into the entry for the first argument for this command. 922e139cf23SCaroline Tice arg.push_back (bp_id_arg); 923e139cf23SCaroline Tice arg.push_back (bp_id_range_arg); 924e139cf23SCaroline Tice 925e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 926e139cf23SCaroline Tice m_arguments.push_back (arg); 92730fdc8d8SChris Lattner } 92830fdc8d8SChris Lattner 92930fdc8d8SChris Lattner CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable () 93030fdc8d8SChris Lattner { 93130fdc8d8SChris Lattner } 93230fdc8d8SChris Lattner 93330fdc8d8SChris Lattner bool 9346611103cSGreg Clayton CommandObjectBreakpointDisable::Execute 9356611103cSGreg Clayton ( 9366611103cSGreg Clayton Args& args, 9376611103cSGreg Clayton CommandReturnObject &result 9386611103cSGreg Clayton ) 93930fdc8d8SChris Lattner { 940a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 94130fdc8d8SChris Lattner if (target == NULL) 94230fdc8d8SChris Lattner { 9439068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 94430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 94530fdc8d8SChris Lattner return false; 94630fdc8d8SChris Lattner } 94730fdc8d8SChris Lattner 9481b54c88cSJim Ingham Mutex::Locker locker; 9491b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 9501b54c88cSJim Ingham 95130fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 95230fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 95330fdc8d8SChris Lattner 95430fdc8d8SChris Lattner if (num_breakpoints == 0) 95530fdc8d8SChris Lattner { 95630fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be disabled."); 95730fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 95830fdc8d8SChris Lattner return false; 95930fdc8d8SChris Lattner } 96030fdc8d8SChris Lattner 96130fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 96230fdc8d8SChris Lattner { 96330fdc8d8SChris Lattner // No breakpoint selected; disable all currently set breakpoints. 96430fdc8d8SChris Lattner target->DisableAllBreakpoints (); 96530fdc8d8SChris Lattner result.AppendMessageWithFormat ("All breakpoints disabled. (%d breakpoints)\n", num_breakpoints); 96630fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 96730fdc8d8SChris Lattner } 96830fdc8d8SChris Lattner else 96930fdc8d8SChris Lattner { 97030fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 97130fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 97230fdc8d8SChris Lattner 97330fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 97430fdc8d8SChris Lattner 97530fdc8d8SChris Lattner if (result.Succeeded()) 97630fdc8d8SChris Lattner { 97730fdc8d8SChris Lattner int disable_count = 0; 97830fdc8d8SChris Lattner int loc_count = 0; 979c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 980c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 98130fdc8d8SChris Lattner { 98230fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 98330fdc8d8SChris Lattner 98430fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 98530fdc8d8SChris Lattner { 98630fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 98730fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 98830fdc8d8SChris Lattner { 98930fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 99030fdc8d8SChris Lattner if (location) 99130fdc8d8SChris Lattner { 99230fdc8d8SChris Lattner location->SetEnabled (false); 99330fdc8d8SChris Lattner ++loc_count; 99430fdc8d8SChris Lattner } 99530fdc8d8SChris Lattner } 99630fdc8d8SChris Lattner else 99730fdc8d8SChris Lattner { 998ae1c4cf5SJim Ingham breakpoint->SetEnabled (false); 99930fdc8d8SChris Lattner ++disable_count; 100030fdc8d8SChris Lattner } 100130fdc8d8SChris Lattner } 100230fdc8d8SChris Lattner } 100330fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count); 100430fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 100530fdc8d8SChris Lattner } 100630fdc8d8SChris Lattner } 100730fdc8d8SChris Lattner 100830fdc8d8SChris Lattner return result.Succeeded(); 100930fdc8d8SChris Lattner } 101030fdc8d8SChris Lattner 101130fdc8d8SChris Lattner //------------------------------------------------------------------------- 101230fdc8d8SChris Lattner // CommandObjectBreakpointDelete 101330fdc8d8SChris Lattner //------------------------------------------------------------------------- 1014ae1c4cf5SJim Ingham #pragma mark Delete 101530fdc8d8SChris Lattner 1016a7015092SGreg Clayton CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) : 1017a7015092SGreg Clayton CommandObject (interpreter, 1018a7015092SGreg Clayton "breakpoint delete", 1019e3d26315SCaroline Tice "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.", 1020e139cf23SCaroline Tice NULL) 102130fdc8d8SChris Lattner { 1022e139cf23SCaroline Tice CommandArgumentEntry arg; 1023e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 1024e139cf23SCaroline Tice CommandArgumentData bp_id_range_arg; 1025e139cf23SCaroline Tice 1026e139cf23SCaroline Tice // Create the first variant for the first (and only) argument for this command. 1027e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 1028*405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatOptional; 1029e139cf23SCaroline Tice 1030e139cf23SCaroline Tice // Create the second variant for the first (and only) argument for this command. 1031e139cf23SCaroline Tice bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange; 1032*405fe67fSCaroline Tice bp_id_range_arg.arg_repetition = eArgRepeatOptional; 1033e139cf23SCaroline Tice 1034e139cf23SCaroline Tice // The first (and only) argument for this command could be either a bp_id or a bp_id_range. 1035e139cf23SCaroline Tice // Push both variants into the entry for the first argument for this command. 1036e139cf23SCaroline Tice arg.push_back (bp_id_arg); 1037e139cf23SCaroline Tice arg.push_back (bp_id_range_arg); 1038e139cf23SCaroline Tice 1039e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1040e139cf23SCaroline Tice m_arguments.push_back (arg); 104130fdc8d8SChris Lattner } 104230fdc8d8SChris Lattner 104330fdc8d8SChris Lattner 104430fdc8d8SChris Lattner CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete () 104530fdc8d8SChris Lattner { 104630fdc8d8SChris Lattner } 104730fdc8d8SChris Lattner 104830fdc8d8SChris Lattner bool 10496611103cSGreg Clayton CommandObjectBreakpointDelete::Execute 10506611103cSGreg Clayton ( 10516611103cSGreg Clayton Args& args, 10526611103cSGreg Clayton CommandReturnObject &result 10536611103cSGreg Clayton ) 105430fdc8d8SChris Lattner { 1055a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 105630fdc8d8SChris Lattner if (target == NULL) 105730fdc8d8SChris Lattner { 10589068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 105930fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 106030fdc8d8SChris Lattner return false; 106130fdc8d8SChris Lattner } 106230fdc8d8SChris Lattner 10631b54c88cSJim Ingham Mutex::Locker locker; 10641b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 10651b54c88cSJim Ingham 106630fdc8d8SChris Lattner const BreakpointList &breakpoints = target->GetBreakpointList(); 10671b54c88cSJim Ingham 106830fdc8d8SChris Lattner size_t num_breakpoints = breakpoints.GetSize(); 106930fdc8d8SChris Lattner 107030fdc8d8SChris Lattner if (num_breakpoints == 0) 107130fdc8d8SChris Lattner { 107230fdc8d8SChris Lattner result.AppendError ("No breakpoints exist to be deleted."); 107330fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 107430fdc8d8SChris Lattner return false; 107530fdc8d8SChris Lattner } 107630fdc8d8SChris Lattner 107730fdc8d8SChris Lattner if (args.GetArgumentCount() == 0) 107830fdc8d8SChris Lattner { 107930fdc8d8SChris Lattner // No breakpoint selected; disable all currently set breakpoints. 108030fdc8d8SChris Lattner if (args.GetArgumentCount() != 0) 108130fdc8d8SChris Lattner { 108230fdc8d8SChris Lattner result.AppendErrorWithFormat ("Specify breakpoints to delete with the -i option.\n"); 108330fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 108430fdc8d8SChris Lattner return false; 108530fdc8d8SChris Lattner } 108630fdc8d8SChris Lattner 108730fdc8d8SChris Lattner target->RemoveAllBreakpoints (); 108830fdc8d8SChris Lattner result.AppendMessageWithFormat ("All breakpoints removed. (%d breakpoints)\n", num_breakpoints); 108930fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 109030fdc8d8SChris Lattner } 109130fdc8d8SChris Lattner else 109230fdc8d8SChris Lattner { 109330fdc8d8SChris Lattner // Particular breakpoint selected; disable that breakpoint. 109430fdc8d8SChris Lattner BreakpointIDList valid_bp_ids; 109530fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); 109630fdc8d8SChris Lattner 109730fdc8d8SChris Lattner if (result.Succeeded()) 109830fdc8d8SChris Lattner { 109930fdc8d8SChris Lattner int delete_count = 0; 110030fdc8d8SChris Lattner int disable_count = 0; 1101c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1102c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 110330fdc8d8SChris Lattner { 110430fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 110530fdc8d8SChris Lattner 110630fdc8d8SChris Lattner if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 110730fdc8d8SChris Lattner { 110830fdc8d8SChris Lattner if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 110930fdc8d8SChris Lattner { 111030fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 111130fdc8d8SChris Lattner BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 111230fdc8d8SChris Lattner // It makes no sense to try to delete individual locations, so we disable them instead. 111330fdc8d8SChris Lattner if (location) 111430fdc8d8SChris Lattner { 111530fdc8d8SChris Lattner location->SetEnabled (false); 111630fdc8d8SChris Lattner ++disable_count; 111730fdc8d8SChris Lattner } 111830fdc8d8SChris Lattner } 111930fdc8d8SChris Lattner else 112030fdc8d8SChris Lattner { 112130fdc8d8SChris Lattner target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID()); 112230fdc8d8SChris Lattner ++delete_count; 112330fdc8d8SChris Lattner } 112430fdc8d8SChris Lattner } 112530fdc8d8SChris Lattner } 112630fdc8d8SChris Lattner result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n", 112730fdc8d8SChris Lattner delete_count, disable_count); 112830fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishNoResult); 112930fdc8d8SChris Lattner } 113030fdc8d8SChris Lattner } 113130fdc8d8SChris Lattner return result.Succeeded(); 113230fdc8d8SChris Lattner } 11331b54c88cSJim Ingham 11341b54c88cSJim Ingham //------------------------------------------------------------------------- 1135ae1c4cf5SJim Ingham // CommandObjectBreakpointModify::CommandOptions 11361b54c88cSJim Ingham //------------------------------------------------------------------------- 1137ae1c4cf5SJim Ingham #pragma mark Modify::CommandOptions 11381b54c88cSJim Ingham 1139ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::CommandOptions() : 11401b54c88cSJim Ingham Options (), 1141c982c768SGreg Clayton m_ignore_count (0), 11421b54c88cSJim Ingham m_thread_id(LLDB_INVALID_THREAD_ID), 1143c982c768SGreg Clayton m_thread_index (UINT32_MAX), 11441b54c88cSJim Ingham m_thread_name(), 11451b54c88cSJim Ingham m_queue_name(), 1146c982c768SGreg Clayton m_enable_passed (false), 1147c982c768SGreg Clayton m_enable_value (false), 1148c982c768SGreg Clayton m_name_passed (false), 1149c982c768SGreg Clayton m_queue_passed (false) 11501b54c88cSJim Ingham { 11511b54c88cSJim Ingham } 11521b54c88cSJim Ingham 1153ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::~CommandOptions () 11541b54c88cSJim Ingham { 11551b54c88cSJim Ingham } 11561b54c88cSJim Ingham 11571b54c88cSJim Ingham lldb::OptionDefinition 1158ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] = 11591b54c88cSJim Ingham { 1160deaab222SCaroline 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." }, 1161deaab222SCaroline 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."}, 1162deaab222SCaroline 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."}, 1163deaab222SCaroline 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."}, 1164deaab222SCaroline 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."}, 1165deaab222SCaroline Tice { LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, eArgTypeNone, "Enable the breakpoint."}, 1166deaab222SCaroline Tice { LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, eArgTypeNone, "Disable the breakpoint."}, 1167deaab222SCaroline Tice { 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } 11681b54c88cSJim Ingham }; 11691b54c88cSJim Ingham 11701b54c88cSJim Ingham const lldb::OptionDefinition* 1171ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::GetDefinitions () 11721b54c88cSJim Ingham { 11731b54c88cSJim Ingham return g_option_table; 11741b54c88cSJim Ingham } 11751b54c88cSJim Ingham 11761b54c88cSJim Ingham Error 1177ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) 11781b54c88cSJim Ingham { 11791b54c88cSJim Ingham Error error; 11801b54c88cSJim Ingham char short_option = (char) m_getopt_table[option_idx].val; 11811b54c88cSJim Ingham 11821b54c88cSJim Ingham switch (short_option) 11831b54c88cSJim Ingham { 1184ae1c4cf5SJim Ingham case 'd': 1185ae1c4cf5SJim Ingham m_enable_passed = true; 1186ae1c4cf5SJim Ingham m_enable_value = false; 1187ae1c4cf5SJim Ingham break; 1188ae1c4cf5SJim Ingham case 'e': 1189ae1c4cf5SJim Ingham m_enable_passed = true; 1190ae1c4cf5SJim Ingham m_enable_value = true; 1191ae1c4cf5SJim Ingham break; 1192ed8a705cSGreg Clayton case 'i': 11931b54c88cSJim Ingham { 1194c982c768SGreg Clayton m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0); 1195c982c768SGreg Clayton if (m_ignore_count == UINT32_MAX) 11961b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg); 11971b54c88cSJim Ingham } 1198ae1c4cf5SJim Ingham break; 11991b54c88cSJim Ingham case 't' : 12001b54c88cSJim Ingham { 12011b54c88cSJim Ingham m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0); 12021b54c88cSJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 12031b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg); 12041b54c88cSJim Ingham } 12051b54c88cSJim Ingham break; 12061b54c88cSJim Ingham case 'T': 1207b2a38a72SJim Ingham if (option_arg != NULL) 12081b54c88cSJim Ingham m_thread_name = option_arg; 1209b2a38a72SJim Ingham else 1210b2a38a72SJim Ingham m_thread_name.clear(); 1211b2a38a72SJim Ingham m_name_passed = true; 12121b54c88cSJim Ingham break; 12131b54c88cSJim Ingham case 'q': 1214b2a38a72SJim Ingham if (option_arg != NULL) 12151b54c88cSJim Ingham m_queue_name = option_arg; 1216b2a38a72SJim Ingham else 1217b2a38a72SJim Ingham m_queue_name.clear(); 1218b2a38a72SJim Ingham m_queue_passed = true; 12191b54c88cSJim Ingham break; 12201b54c88cSJim Ingham case 'x': 12211b54c88cSJim Ingham { 1222c982c768SGreg Clayton m_thread_index = Args::StringToUInt32 (optarg, UINT32_MAX, 0); 1223c982c768SGreg Clayton if (m_thread_id == UINT32_MAX) 12241b54c88cSJim Ingham error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg); 12251b54c88cSJim Ingham 12261b54c88cSJim Ingham } 12271b54c88cSJim Ingham break; 12281b54c88cSJim Ingham default: 12291b54c88cSJim Ingham error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 12301b54c88cSJim Ingham break; 12311b54c88cSJim Ingham } 12321b54c88cSJim Ingham 12331b54c88cSJim Ingham return error; 12341b54c88cSJim Ingham } 12351b54c88cSJim Ingham 12361b54c88cSJim Ingham void 1237ae1c4cf5SJim Ingham CommandObjectBreakpointModify::CommandOptions::ResetOptionValues () 12381b54c88cSJim Ingham { 12391b54c88cSJim Ingham Options::ResetOptionValues(); 12401b54c88cSJim Ingham 1241c982c768SGreg Clayton m_ignore_count = 0; 12421b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 1243c982c768SGreg Clayton m_thread_index = UINT32_MAX; 12441b54c88cSJim Ingham m_thread_name.clear(); 12451b54c88cSJim Ingham m_queue_name.clear(); 1246ae1c4cf5SJim Ingham m_enable_passed = false; 1247b2a38a72SJim Ingham m_queue_passed = false; 1248b2a38a72SJim Ingham m_name_passed = false; 12491b54c88cSJim Ingham } 12501b54c88cSJim Ingham 12511b54c88cSJim Ingham //------------------------------------------------------------------------- 1252ae1c4cf5SJim Ingham // CommandObjectBreakpointModify 12531b54c88cSJim Ingham //------------------------------------------------------------------------- 1254ae1c4cf5SJim Ingham #pragma mark Modify 12551b54c88cSJim Ingham 1256a7015092SGreg Clayton CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) : 1257a7015092SGreg Clayton CommandObject (interpreter, 1258a7015092SGreg Clayton "breakpoint modify", 1259a7015092SGreg Clayton "Modify the options on a breakpoint or set of breakpoints in the executable.", 1260e139cf23SCaroline Tice NULL) 12611b54c88cSJim Ingham { 1262e139cf23SCaroline Tice CommandArgumentEntry arg; 1263e139cf23SCaroline Tice CommandArgumentData bp_id_arg; 1264e139cf23SCaroline Tice CommandArgumentData bp_id_range_arg; 1265e139cf23SCaroline Tice 1266e139cf23SCaroline Tice // Create the first variant for the first (and only) argument for this command. 1267e139cf23SCaroline Tice bp_id_arg.arg_type = eArgTypeBreakpointID; 1268*405fe67fSCaroline Tice bp_id_arg.arg_repetition = eArgRepeatPlain; 1269e139cf23SCaroline Tice 1270e139cf23SCaroline Tice // Create the second variant for the first (and only) argument for this command. 1271e139cf23SCaroline Tice bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange; 1272*405fe67fSCaroline Tice bp_id_range_arg.arg_repetition = eArgRepeatPlain; 1273e139cf23SCaroline Tice 1274e139cf23SCaroline Tice // The first (and only) argument for this command could be either a bp_id or a bp_id_range. 1275e139cf23SCaroline Tice // Push both variants into the entry for the first argument for this command. 1276e139cf23SCaroline Tice arg.push_back (bp_id_arg); 1277e139cf23SCaroline Tice arg.push_back (bp_id_range_arg); 1278e139cf23SCaroline Tice 1279e139cf23SCaroline Tice // Add the entry for the first argument for this command to the object's arguments vector. 1280e139cf23SCaroline Tice m_arguments.push_back (arg); 12811b54c88cSJim Ingham } 12821b54c88cSJim Ingham 1283ae1c4cf5SJim Ingham CommandObjectBreakpointModify::~CommandObjectBreakpointModify () 12841b54c88cSJim Ingham { 12851b54c88cSJim Ingham } 12861b54c88cSJim Ingham 12871b54c88cSJim Ingham Options * 1288ae1c4cf5SJim Ingham CommandObjectBreakpointModify::GetOptions () 12891b54c88cSJim Ingham { 12901b54c88cSJim Ingham return &m_options; 12911b54c88cSJim Ingham } 12921b54c88cSJim Ingham 12931b54c88cSJim Ingham bool 1294ae1c4cf5SJim Ingham CommandObjectBreakpointModify::Execute 12951b54c88cSJim Ingham ( 12961b54c88cSJim Ingham Args& command, 12971b54c88cSJim Ingham CommandReturnObject &result 12981b54c88cSJim Ingham ) 12991b54c88cSJim Ingham { 13001b54c88cSJim Ingham if (command.GetArgumentCount() == 0) 13011b54c88cSJim Ingham { 13021b54c88cSJim Ingham result.AppendError ("No breakpoints specified."); 13031b54c88cSJim Ingham result.SetStatus (eReturnStatusFailed); 13041b54c88cSJim Ingham return false; 13051b54c88cSJim Ingham } 13061b54c88cSJim Ingham 1307a7015092SGreg Clayton Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 13081b54c88cSJim Ingham if (target == NULL) 13091b54c88cSJim Ingham { 13109068d794SCaroline Tice result.AppendError ("Invalid target. No existing target or breakpoints."); 13111b54c88cSJim Ingham result.SetStatus (eReturnStatusFailed); 13121b54c88cSJim Ingham return false; 13131b54c88cSJim Ingham } 13141b54c88cSJim Ingham 13151b54c88cSJim Ingham Mutex::Locker locker; 13161b54c88cSJim Ingham target->GetBreakpointList().GetListMutex(locker); 13171b54c88cSJim Ingham 13181b54c88cSJim Ingham BreakpointIDList valid_bp_ids; 13191b54c88cSJim Ingham 13201b54c88cSJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 13211b54c88cSJim Ingham 13221b54c88cSJim Ingham if (result.Succeeded()) 13231b54c88cSJim Ingham { 1324c982c768SGreg Clayton const size_t count = valid_bp_ids.GetSize(); 1325c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 13261b54c88cSJim Ingham { 13271b54c88cSJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 13281b54c88cSJim Ingham 13291b54c88cSJim Ingham if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 13301b54c88cSJim Ingham { 13311b54c88cSJim Ingham Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 13321b54c88cSJim Ingham if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 13331b54c88cSJim Ingham { 13341b54c88cSJim Ingham BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get(); 13351b54c88cSJim Ingham if (location) 13361b54c88cSJim Ingham { 13371b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 13381b54c88cSJim Ingham location->SetThreadID (m_options.m_thread_id); 13391b54c88cSJim Ingham 1340c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 13411b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 13421b54c88cSJim Ingham 1343b2a38a72SJim Ingham if (m_options.m_name_passed) 13441b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 13451b54c88cSJim Ingham 1346b2a38a72SJim Ingham if (m_options.m_queue_passed) 13471b54c88cSJim Ingham location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 13481b54c88cSJim Ingham 1349c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 13501b54c88cSJim Ingham location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count); 1351ae1c4cf5SJim Ingham 1352ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1353ae1c4cf5SJim Ingham location->SetEnabled (m_options.m_enable_value); 13541b54c88cSJim Ingham } 13551b54c88cSJim Ingham } 13561b54c88cSJim Ingham else 13571b54c88cSJim Ingham { 13581b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 13591b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 13601b54c88cSJim Ingham 1361c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 13621b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 13631b54c88cSJim Ingham 1364b2a38a72SJim Ingham if (m_options.m_name_passed) 13651b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 13661b54c88cSJim Ingham 1367b2a38a72SJim Ingham if (m_options.m_queue_passed) 13681b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 13691b54c88cSJim Ingham 1370c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 13711b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 1372ae1c4cf5SJim Ingham 1373ae1c4cf5SJim Ingham if (m_options.m_enable_passed) 1374ae1c4cf5SJim Ingham bp->SetEnabled (m_options.m_enable_value); 1375ae1c4cf5SJim Ingham 13761b54c88cSJim Ingham } 13771b54c88cSJim Ingham } 13781b54c88cSJim Ingham } 13791b54c88cSJim Ingham } 13801b54c88cSJim Ingham 13811b54c88cSJim Ingham return result.Succeeded(); 13821b54c88cSJim Ingham } 13831b54c88cSJim Ingham 13841b54c88cSJim Ingham 1385