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 // C Includes 1130fdc8d8SChris Lattner // C++ Includes 129e85e5a8SEugene Zelenko #include <vector> 139e85e5a8SEugene Zelenko 1430fdc8d8SChris Lattner // Other libraries and framework includes 1530fdc8d8SChris Lattner // Project includes 169e85e5a8SEugene Zelenko #include "CommandObjectBreakpoint.h" 179e85e5a8SEugene Zelenko #include "CommandObjectBreakpointCommand.h" 1830fdc8d8SChris Lattner #include "lldb/Breakpoint/Breakpoint.h" 1930fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointIDList.h" 2030fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointLocation.h" 213eb2b44dSZachary Turner #include "lldb/Host/OptionParser.h" 22b9c1b51eSKate Stone #include "lldb/Interpreter/CommandCompletions.h" 23b9c1b51eSKate Stone #include "lldb/Interpreter/CommandInterpreter.h" 24b9c1b51eSKate Stone #include "lldb/Interpreter/CommandReturnObject.h" 25*47cbf4a0SPavel Labath #include "lldb/Interpreter/OptionArgParser.h" 2632abc6edSZachary Turner #include "lldb/Interpreter/OptionValueBoolean.h" 275e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueString.h" 285e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueUInt64.h" 29b9c1b51eSKate Stone #include "lldb/Interpreter/Options.h" 300e0984eeSJim Ingham #include "lldb/Target/Language.h" 31b57e4a1bSJason Molenda #include "lldb/Target/StackFrame.h" 32b9c1b51eSKate Stone #include "lldb/Target/Target.h" 331b54c88cSJim Ingham #include "lldb/Target/Thread.h" 341b54c88cSJim Ingham #include "lldb/Target/ThreadSpec.h" 35bf9a7730SZachary Turner #include "lldb/Utility/RegularExpression.h" 36bf9a7730SZachary Turner #include "lldb/Utility/StreamString.h" 3730fdc8d8SChris Lattner 3830fdc8d8SChris Lattner using namespace lldb; 3930fdc8d8SChris Lattner using namespace lldb_private; 4030fdc8d8SChris Lattner 41b9c1b51eSKate Stone static void AddBreakpointDescription(Stream *s, Breakpoint *bp, 42b9c1b51eSKate Stone lldb::DescriptionLevel level) { 4330fdc8d8SChris Lattner s->IndentMore(); 4430fdc8d8SChris Lattner bp->GetDescription(s, level, true); 4530fdc8d8SChris Lattner s->IndentLess(); 4630fdc8d8SChris Lattner s->EOL(); 4730fdc8d8SChris Lattner } 4830fdc8d8SChris Lattner 49b842f2ecSJim Ingham //------------------------------------------------------------------------- 50b842f2ecSJim Ingham // Modifiable Breakpoint Options 51b842f2ecSJim Ingham //------------------------------------------------------------------------- 52b842f2ecSJim Ingham #pragma mark Modify::CommandOptions 53b842f2ecSJim Ingham static OptionDefinition g_breakpoint_modify_options[] = { 54b842f2ecSJim Ingham // clang-format off 55b842f2ecSJim Ingham { LLDB_OPT_SET_1, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." }, 56b842f2ecSJim Ingham { LLDB_OPT_SET_1, false, "one-shot", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "The breakpoint is deleted the first time it stop causes a stop." }, 57b842f2ecSJim Ingham { LLDB_OPT_SET_1, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose index matches this argument." }, 58b842f2ecSJim Ingham { LLDB_OPT_SET_1, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument." }, 59b842f2ecSJim Ingham { LLDB_OPT_SET_1, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument." }, 60b842f2ecSJim Ingham { LLDB_OPT_SET_1, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument." }, 61b842f2ecSJim Ingham { LLDB_OPT_SET_1, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true." }, 62b842f2ecSJim Ingham { LLDB_OPT_SET_1, false, "auto-continue",'G', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "The breakpoint will auto-continue after running its commands." }, 63b842f2ecSJim Ingham { LLDB_OPT_SET_2, false, "enable", 'e', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable the breakpoint." }, 64b842f2ecSJim Ingham { LLDB_OPT_SET_3, false, "disable", 'd', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Disable the breakpoint." }, 65b842f2ecSJim Ingham { LLDB_OPT_SET_4, false, "command", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCommand, "A command to run when the breakpoint is hit, can be provided more than once, the commands will get run in order left to right." }, 66b842f2ecSJim Ingham // clang-format on 67b842f2ecSJim Ingham }; 68b842f2ecSJim Ingham class lldb_private::BreakpointOptionGroup : public OptionGroup 69b842f2ecSJim Ingham { 70b842f2ecSJim Ingham public: 71b842f2ecSJim Ingham BreakpointOptionGroup() : 72b842f2ecSJim Ingham OptionGroup(), 73b842f2ecSJim Ingham m_bp_opts(false) {} 74b842f2ecSJim Ingham 75b842f2ecSJim Ingham ~BreakpointOptionGroup() override = default; 76b842f2ecSJim Ingham 77b842f2ecSJim Ingham llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 78b842f2ecSJim Ingham return llvm::makeArrayRef(g_breakpoint_modify_options); 79b842f2ecSJim Ingham } 80b842f2ecSJim Ingham 81b842f2ecSJim Ingham Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 82b842f2ecSJim Ingham ExecutionContext *execution_context) override { 83b842f2ecSJim Ingham Status error; 84b842f2ecSJim Ingham const int short_option = g_breakpoint_modify_options[option_idx].short_option; 85b842f2ecSJim Ingham 86b842f2ecSJim Ingham switch (short_option) { 87b842f2ecSJim Ingham case 'c': 88b842f2ecSJim Ingham // Normally an empty breakpoint condition marks is as unset. 89b842f2ecSJim Ingham // But we need to say it was passed in. 90b842f2ecSJim Ingham m_bp_opts.SetCondition(option_arg.str().c_str()); 91b842f2ecSJim Ingham m_bp_opts.m_set_flags.Set(BreakpointOptions::eCondition); 92b842f2ecSJim Ingham break; 93b842f2ecSJim Ingham case 'C': 94b842f2ecSJim Ingham m_commands.push_back(option_arg); 95b842f2ecSJim Ingham break; 96b842f2ecSJim Ingham case 'd': 97b842f2ecSJim Ingham m_bp_opts.SetEnabled(false); 98b842f2ecSJim Ingham break; 99b842f2ecSJim Ingham case 'e': 100b842f2ecSJim Ingham m_bp_opts.SetEnabled(true); 101b842f2ecSJim Ingham break; 102b842f2ecSJim Ingham case 'G': { 103b842f2ecSJim Ingham bool value, success; 104*47cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 105b842f2ecSJim Ingham if (success) { 106b842f2ecSJim Ingham m_bp_opts.SetAutoContinue(value); 107b842f2ecSJim Ingham } else 108b842f2ecSJim Ingham error.SetErrorStringWithFormat( 109b842f2ecSJim Ingham "invalid boolean value '%s' passed for -G option", 110b842f2ecSJim Ingham option_arg.str().c_str()); 111b842f2ecSJim Ingham } 112b842f2ecSJim Ingham break; 113b842f2ecSJim Ingham case 'i': 114b842f2ecSJim Ingham { 115b842f2ecSJim Ingham uint32_t ignore_count; 116b842f2ecSJim Ingham if (option_arg.getAsInteger(0, ignore_count)) 117b842f2ecSJim Ingham error.SetErrorStringWithFormat("invalid ignore count '%s'", 118b842f2ecSJim Ingham option_arg.str().c_str()); 119b842f2ecSJim Ingham else 120b842f2ecSJim Ingham m_bp_opts.SetIgnoreCount(ignore_count); 121b842f2ecSJim Ingham } 122b842f2ecSJim Ingham break; 123b842f2ecSJim Ingham case 'o': { 124b842f2ecSJim Ingham bool value, success; 125*47cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 126b842f2ecSJim Ingham if (success) { 127b842f2ecSJim Ingham m_bp_opts.SetOneShot(value); 128b842f2ecSJim Ingham } else 129b842f2ecSJim Ingham error.SetErrorStringWithFormat( 130b842f2ecSJim Ingham "invalid boolean value '%s' passed for -o option", 131b842f2ecSJim Ingham option_arg.str().c_str()); 132b842f2ecSJim Ingham } break; 133b842f2ecSJim Ingham case 't': 134b842f2ecSJim Ingham { 135b842f2ecSJim Ingham lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID; 136b842f2ecSJim Ingham if (option_arg[0] != '\0') { 137b842f2ecSJim Ingham if (option_arg.getAsInteger(0, thread_id)) 138b842f2ecSJim Ingham error.SetErrorStringWithFormat("invalid thread id string '%s'", 139b842f2ecSJim Ingham option_arg.str().c_str()); 140b842f2ecSJim Ingham } 141b842f2ecSJim Ingham m_bp_opts.SetThreadID(thread_id); 142b842f2ecSJim Ingham } 143b842f2ecSJim Ingham break; 144b842f2ecSJim Ingham case 'T': 145b842f2ecSJim Ingham m_bp_opts.GetThreadSpec()->SetName(option_arg.str().c_str()); 146b842f2ecSJim Ingham break; 147b842f2ecSJim Ingham case 'q': 148b842f2ecSJim Ingham m_bp_opts.GetThreadSpec()->SetQueueName(option_arg.str().c_str()); 149b842f2ecSJim Ingham break; 150b842f2ecSJim Ingham case 'x': 151b842f2ecSJim Ingham { 152b842f2ecSJim Ingham uint32_t thread_index = UINT32_MAX; 153b842f2ecSJim Ingham if (option_arg[0] != '\n') { 154b842f2ecSJim Ingham if (option_arg.getAsInteger(0, thread_index)) 155b842f2ecSJim Ingham error.SetErrorStringWithFormat("invalid thread index string '%s'", 156b842f2ecSJim Ingham option_arg.str().c_str()); 157b842f2ecSJim Ingham } 158b842f2ecSJim Ingham m_bp_opts.GetThreadSpec()->SetIndex(thread_index); 159b842f2ecSJim Ingham } 160b842f2ecSJim Ingham break; 161b842f2ecSJim Ingham default: 162b842f2ecSJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 163b842f2ecSJim Ingham short_option); 164b842f2ecSJim Ingham break; 165b842f2ecSJim Ingham } 166b842f2ecSJim Ingham 167b842f2ecSJim Ingham return error; 168b842f2ecSJim Ingham } 169b842f2ecSJim Ingham 170b842f2ecSJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 171b842f2ecSJim Ingham m_bp_opts.Clear(); 172b842f2ecSJim Ingham m_commands.clear(); 173b842f2ecSJim Ingham } 174b842f2ecSJim Ingham 175b842f2ecSJim Ingham Status OptionParsingFinished(ExecutionContext *execution_context) override { 176b842f2ecSJim Ingham if (!m_commands.empty()) 177b842f2ecSJim Ingham { 178b842f2ecSJim Ingham if (!m_commands.empty()) 179b842f2ecSJim Ingham { 180b842f2ecSJim Ingham auto cmd_data = llvm::make_unique<BreakpointOptions::CommandData>(); 181b842f2ecSJim Ingham 182b842f2ecSJim Ingham for (std::string &str : m_commands) 183b842f2ecSJim Ingham cmd_data->user_source.AppendString(str); 184b842f2ecSJim Ingham 185b842f2ecSJim Ingham cmd_data->stop_on_error = true; 186b842f2ecSJim Ingham m_bp_opts.SetCommandDataCallback(cmd_data); 187b842f2ecSJim Ingham } 188b842f2ecSJim Ingham } 189b842f2ecSJim Ingham return Status(); 190b842f2ecSJim Ingham } 191b842f2ecSJim Ingham 192b842f2ecSJim Ingham const BreakpointOptions &GetBreakpointOptions() 193b842f2ecSJim Ingham { 194b842f2ecSJim Ingham return m_bp_opts; 195b842f2ecSJim Ingham } 196b842f2ecSJim Ingham 197b842f2ecSJim Ingham std::vector<std::string> m_commands; 198b842f2ecSJim Ingham BreakpointOptions m_bp_opts; 199b842f2ecSJim Ingham 200b842f2ecSJim Ingham }; 201b842f2ecSJim Ingham static OptionDefinition g_breakpoint_dummy_options[] = { 202b842f2ecSJim Ingham // clang-format off 203b842f2ecSJim Ingham { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Act on Dummy breakpoints - i.e. breakpoints set before a file is provided, " 204b842f2ecSJim Ingham "which prime new targets." }, 205b842f2ecSJim Ingham // clang-format on 206b842f2ecSJim Ingham }; 207b842f2ecSJim Ingham 208b842f2ecSJim Ingham class BreakpointDummyOptionGroup : public OptionGroup 209b842f2ecSJim Ingham { 210b842f2ecSJim Ingham public: 211b842f2ecSJim Ingham BreakpointDummyOptionGroup() : 212b842f2ecSJim Ingham OptionGroup() {} 213b842f2ecSJim Ingham 214b842f2ecSJim Ingham ~BreakpointDummyOptionGroup() override = default; 215b842f2ecSJim Ingham 216b842f2ecSJim Ingham llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 217b842f2ecSJim Ingham return llvm::makeArrayRef(g_breakpoint_dummy_options); 218b842f2ecSJim Ingham } 219b842f2ecSJim Ingham 220b842f2ecSJim Ingham Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 221b842f2ecSJim Ingham ExecutionContext *execution_context) override { 222b842f2ecSJim Ingham Status error; 223b842f2ecSJim Ingham const int short_option = g_breakpoint_modify_options[option_idx].short_option; 224b842f2ecSJim Ingham 225b842f2ecSJim Ingham switch (short_option) { 226b842f2ecSJim Ingham case 'D': 227b842f2ecSJim Ingham m_use_dummy = true; 228b842f2ecSJim Ingham break; 229b842f2ecSJim Ingham default: 230b842f2ecSJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 231b842f2ecSJim Ingham short_option); 232b842f2ecSJim Ingham break; 233b842f2ecSJim Ingham } 234b842f2ecSJim Ingham 235b842f2ecSJim Ingham return error; 236b842f2ecSJim Ingham } 237b842f2ecSJim Ingham 238b842f2ecSJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 239b842f2ecSJim Ingham m_use_dummy = false; 240b842f2ecSJim Ingham } 241b842f2ecSJim Ingham 242b842f2ecSJim Ingham bool m_use_dummy; 243b842f2ecSJim Ingham 244b842f2ecSJim Ingham }; 245b842f2ecSJim Ingham 2461f0f5b5bSZachary Turner // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to 2471f0f5b5bSZachary Turner // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately. 2481f0f5b5bSZachary Turner #define LLDB_OPT_FILE (LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2) 2491f0f5b5bSZachary Turner #define LLDB_OPT_NOT_10 (LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10) 2501f0f5b5bSZachary Turner #define LLDB_OPT_SKIP_PROLOGUE (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8)) 2511f0f5b5bSZachary Turner #define LLDB_OPT_OFFSET_APPLIES (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8)) 2521f0f5b5bSZachary Turner #define LLDB_OPT_MOVE_TO_NEAREST_CODE (LLDB_OPT_SET_1 | LLDB_OPT_SET_9) 2531f0f5b5bSZachary Turner #define LLDB_OPT_EXPR_LANGUAGE (LLDB_OPT_SET_FROM_TO(3, 8)) 2541f0f5b5bSZachary Turner 2551f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_set_options[] = { 2561f0f5b5bSZachary Turner // clang-format off 2571f0f5b5bSZachary Turner { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Set the breakpoint only in this shared library. Can repeat this option " 2581f0f5b5bSZachary Turner "multiple times to specify multiple shared libraries." }, 2591f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Require the breakpoint to use hardware breakpoints." }, 2601f0f5b5bSZachary Turner { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specifies the source file in which to set this breakpoint. Note, by default " 2611f0f5b5bSZachary Turner "lldb only looks for files that are #included if they use the standard include " 2621f0f5b5bSZachary Turner "file extensions. To set breakpoints on .c/.cpp/.m/.mm files that are " 2631f0f5b5bSZachary Turner "#included, set target.inline-breakpoint-strategy to \"always\"." }, 2641f0f5b5bSZachary Turner { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Specifies the line number on which to set this breakpoint." }, 2651f0f5b5bSZachary Turner 2661f0f5b5bSZachary Turner // Comment out this option for the moment, as we don't actually use it, but will in the future. 2671f0f5b5bSZachary Turner // This way users won't see it, but the infrastructure is left in place. 2681f0f5b5bSZachary Turner // { 0, false, "column", 'C', OptionParser::eRequiredArgument, nullptr, "<column>", 2691f0f5b5bSZachary Turner // "Set the breakpoint by source location at this particular column."}, 2701f0f5b5bSZachary Turner 2711f0f5b5bSZachary Turner { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Set the breakpoint at the specified address. If the address maps uniquely to " 2721f0f5b5bSZachary Turner "a particular binary, then the address will be converted to a \"file\" " 2731f0f5b5bSZachary Turner "address, so that the breakpoint will track that binary+offset no matter where " 2741f0f5b5bSZachary Turner "the binary eventually loads. Alternately, if you also specify the module - " 2751f0f5b5bSZachary Turner "with the -s option - then the address will be treated as a file address in " 2761f0f5b5bSZachary Turner "that module, and resolved accordingly. Again, this will allow lldb to track " 2771f0f5b5bSZachary Turner "that offset on subsequent reloads. The module need not have been loaded at " 2781f0f5b5bSZachary Turner "the time you specify this breakpoint, and will get resolved when the module " 2791f0f5b5bSZachary Turner "is loaded." }, 2801f0f5b5bSZachary Turner { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the breakpoint by function name. Can be repeated multiple times to make " 2811f0f5b5bSZachary Turner "one breakpoint for multiple names" }, 2821f0f5b5bSZachary Turner { LLDB_OPT_SET_9, false, "source-regexp-function", 'X', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "When used with '-p' limits the source regex to source contained in the named " 2831f0f5b5bSZachary Turner "functions. Can be repeated multiple times." }, 2841f0f5b5bSZachary Turner { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFullName, "Set the breakpoint by fully qualified function names. For C++ this means " 2851f0f5b5bSZachary Turner "namespaces and all arguments, and for Objective C this means a full function " 2861f0f5b5bSZachary Turner "prototype with class and selector. Can be repeated multiple times to make " 2871f0f5b5bSZachary Turner "one breakpoint for multiple names." }, 2881f0f5b5bSZachary Turner { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSelector, "Set the breakpoint by ObjC selector name. Can be repeated multiple times to " 2891f0f5b5bSZachary Turner "make one breakpoint for multiple Selectors." }, 2901f0f5b5bSZachary Turner { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeMethod, "Set the breakpoint by C++ method names. Can be repeated multiple times to " 2911f0f5b5bSZachary Turner "make one breakpoint for multiple methods." }, 2921f0f5b5bSZachary Turner { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "Set the breakpoint by function name, evaluating a regular-expression to find " 2931f0f5b5bSZachary Turner "the function name(s)." }, 2941f0f5b5bSZachary Turner { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the breakpoint by function basename (C++ namespaces and arguments will be " 2951f0f5b5bSZachary Turner "ignored). Can be repeated multiple times to make one breakpoint for multiple " 2961f0f5b5bSZachary Turner "symbols." }, 2971f0f5b5bSZachary Turner { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "Set the breakpoint by specifying a regular expression which is matched " 2981f0f5b5bSZachary Turner "against the source text in a source file or files specified with the -f " 2991f0f5b5bSZachary Turner "option. The -f option can be specified more than once. If no source files " 3001f0f5b5bSZachary Turner "are specified, uses the current \"default source file\". If you want to " 3011f0f5b5bSZachary Turner "match against all source files, pass the \"--all-files\" option." }, 3021f0f5b5bSZachary Turner { LLDB_OPT_SET_9, false, "all-files", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "All files are searched for source pattern matches." }, 3031f0f5b5bSZachary Turner { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Set the breakpoint on exceptions thrown by the specified language (without " 3041f0f5b5bSZachary Turner "options, on throw but not catch.)" }, 3051f0f5b5bSZachary Turner { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Set the breakpoint on exception throW." }, 3061f0f5b5bSZachary Turner { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Set the breakpoint on exception catcH." }, 3071f0f5b5bSZachary Turner 3081f0f5b5bSZachary Turner // Don't add this option till it actually does something useful... 3091f0f5b5bSZachary Turner // { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName, 3101f0f5b5bSZachary Turner // "The breakpoint will only stop if an exception Object of this type is thrown. Can be repeated multiple times to stop for multiple object types" }, 3111f0f5b5bSZachary Turner 3121f0f5b5bSZachary Turner { LLDB_OPT_EXPR_LANGUAGE, false, "language", 'L', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Specifies the Language to use when interpreting the breakpoint's expression " 3131f0f5b5bSZachary Turner "(note: currently only implemented for setting breakpoints on identifiers). " 3141f0f5b5bSZachary Turner "If not set the target.language setting is used." }, 3151f0f5b5bSZachary Turner { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "sKip the prologue if the breakpoint is at the beginning of a function. " 3161f0f5b5bSZachary Turner "If not set the target.skip-prologue setting is used." }, 3171f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Adds this to the list of names for this breakpoint." }, 3181f0f5b5bSZachary Turner { LLDB_OPT_OFFSET_APPLIES, false, "address-slide", 'R', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddress, "Add the specified offset to whatever address(es) the breakpoint resolves to. " 3191f0f5b5bSZachary Turner "At present this applies the offset directly as given, and doesn't try to align it to instruction boundaries." }, 3201f0f5b5bSZachary Turner { LLDB_OPT_MOVE_TO_NEAREST_CODE, false, "move-to-nearest-code", 'm', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Move breakpoints to nearest code. If not set the target.move-to-nearest-code " 3211f0f5b5bSZachary Turner "setting is used." }, 3221f0f5b5bSZachary Turner // clang-format on 3231f0f5b5bSZachary Turner }; 3241f0f5b5bSZachary Turner 32530fdc8d8SChris Lattner //------------------------------------------------------------------------- 3265a988416SJim Ingham // CommandObjectBreakpointSet 32730fdc8d8SChris Lattner //------------------------------------------------------------------------- 32830fdc8d8SChris Lattner 329b9c1b51eSKate Stone class CommandObjectBreakpointSet : public CommandObjectParsed { 3305a988416SJim Ingham public: 331b9c1b51eSKate Stone typedef enum BreakpointSetType { 3325a988416SJim Ingham eSetTypeInvalid, 3335a988416SJim Ingham eSetTypeFileAndLine, 3345a988416SJim Ingham eSetTypeAddress, 3355a988416SJim Ingham eSetTypeFunctionName, 3365a988416SJim Ingham eSetTypeFunctionRegexp, 3375a988416SJim Ingham eSetTypeSourceRegexp, 3385a988416SJim Ingham eSetTypeException 3395a988416SJim Ingham } BreakpointSetType; 3405a988416SJim Ingham 341b9c1b51eSKate Stone CommandObjectBreakpointSet(CommandInterpreter &interpreter) 342b9c1b51eSKate Stone : CommandObjectParsed( 343b9c1b51eSKate Stone interpreter, "breakpoint set", 3445a988416SJim Ingham "Sets a breakpoint or set of breakpoints in the executable.", 3455a988416SJim Ingham "breakpoint set <cmd-options>"), 346b842f2ecSJim Ingham m_bp_opts(), m_options() { 347b842f2ecSJim Ingham // We're picking up all the normal options, commands and disable. 348b842f2ecSJim Ingham m_all_options.Append(&m_bp_opts, 349b842f2ecSJim Ingham LLDB_OPT_SET_1 | LLDB_OPT_SET_3 | LLDB_OPT_SET_4, 350b842f2ecSJim Ingham LLDB_OPT_SET_ALL); 351b842f2ecSJim Ingham m_all_options.Append(&m_dummy_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 352b842f2ecSJim Ingham m_all_options.Append(&m_options); 353b842f2ecSJim Ingham m_all_options.Finalize(); 354b842f2ecSJim Ingham } 3555a988416SJim Ingham 3569e85e5a8SEugene Zelenko ~CommandObjectBreakpointSet() override = default; 3575a988416SJim Ingham 358b842f2ecSJim Ingham Options *GetOptions() override { return &m_all_options; } 3595a988416SJim Ingham 360b842f2ecSJim Ingham class CommandOptions : public OptionGroup { 3615a988416SJim Ingham public: 362b9c1b51eSKate Stone CommandOptions() 363b842f2ecSJim Ingham : OptionGroup(), m_condition(), m_filenames(), m_line_num(0), m_column(0), 364b9c1b51eSKate Stone m_func_names(), m_func_name_type_mask(eFunctionNameTypeNone), 365b9c1b51eSKate Stone m_func_regexp(), m_source_text_regexp(), m_modules(), m_load_addr(), 366b9c1b51eSKate Stone m_catch_bp(false), m_throw_bp(true), m_hardware(false), 367a72b31c7SJim Ingham m_exception_language(eLanguageTypeUnknown), 36823b1decbSDawn Perchik m_language(lldb::eLanguageTypeUnknown), 369b842f2ecSJim Ingham m_skip_prologue(eLazyBoolCalculate), 370b9c1b51eSKate Stone m_all_files(false), m_move_to_nearest_code(eLazyBoolCalculate) {} 37130fdc8d8SChris Lattner 3729e85e5a8SEugene Zelenko ~CommandOptions() override = default; 37387df91b8SJim Ingham 37497206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 375b9c1b51eSKate Stone ExecutionContext *execution_context) override { 37697206d57SZachary Turner Status error; 377b842f2ecSJim Ingham const int short_option = g_breakpoint_set_options[option_idx].short_option; 37830fdc8d8SChris Lattner 379b9c1b51eSKate Stone switch (short_option) { 380b9c1b51eSKate Stone case 'a': { 381*47cbf4a0SPavel Labath m_load_addr = OptionArgParser::ToAddress(execution_context, option_arg, 382e1cfbc79STodd Fiala LLDB_INVALID_ADDRESS, &error); 383b9c1b51eSKate Stone } break; 38430fdc8d8SChris Lattner 385e732052fSJim Ingham case 'A': 386e732052fSJim Ingham m_all_files = true; 387e732052fSJim Ingham break; 388e732052fSJim Ingham 389ca36cd16SJim Ingham case 'b': 390ca36cd16SJim Ingham m_func_names.push_back(option_arg); 391ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeBase; 392ca36cd16SJim Ingham break; 393ca36cd16SJim Ingham 394fe11483bSZachary Turner case 'C': 395fe11483bSZachary Turner if (option_arg.getAsInteger(0, m_column)) 396b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid column number: %s", 397fe11483bSZachary Turner option_arg.str().c_str()); 39830fdc8d8SChris Lattner break; 3999e85e5a8SEugene Zelenko 400b9c1b51eSKate Stone case 'E': { 401fe11483bSZachary Turner LanguageType language = Language::GetLanguageTypeFromString(option_arg); 402fab10e89SJim Ingham 403b9c1b51eSKate Stone switch (language) { 404fab10e89SJim Ingham case eLanguageTypeC89: 405fab10e89SJim Ingham case eLanguageTypeC: 406fab10e89SJim Ingham case eLanguageTypeC99: 4071d0089faSBruce Mitchener case eLanguageTypeC11: 408a72b31c7SJim Ingham m_exception_language = eLanguageTypeC; 409fab10e89SJim Ingham break; 410fab10e89SJim Ingham case eLanguageTypeC_plus_plus: 4111d0089faSBruce Mitchener case eLanguageTypeC_plus_plus_03: 4121d0089faSBruce Mitchener case eLanguageTypeC_plus_plus_11: 4132ba84a6aSBruce Mitchener case eLanguageTypeC_plus_plus_14: 414a72b31c7SJim Ingham m_exception_language = eLanguageTypeC_plus_plus; 415fab10e89SJim Ingham break; 416fab10e89SJim Ingham case eLanguageTypeObjC: 417a72b31c7SJim Ingham m_exception_language = eLanguageTypeObjC; 418fab10e89SJim Ingham break; 419fab10e89SJim Ingham case eLanguageTypeObjC_plus_plus: 420b9c1b51eSKate Stone error.SetErrorStringWithFormat( 421b9c1b51eSKate Stone "Set exception breakpoints separately for c++ and objective-c"); 422fab10e89SJim Ingham break; 423fab10e89SJim Ingham case eLanguageTypeUnknown: 424b9c1b51eSKate Stone error.SetErrorStringWithFormat( 425b9c1b51eSKate Stone "Unknown language type: '%s' for exception breakpoint", 426fe11483bSZachary Turner option_arg.str().c_str()); 427fab10e89SJim Ingham break; 428fab10e89SJim Ingham default: 429b9c1b51eSKate Stone error.SetErrorStringWithFormat( 430b9c1b51eSKate Stone "Unsupported language type: '%s' for exception breakpoint", 431fe11483bSZachary Turner option_arg.str().c_str()); 432fab10e89SJim Ingham } 433b9c1b51eSKate Stone } break; 434ca36cd16SJim Ingham 435ca36cd16SJim Ingham case 'f': 436ca36cd16SJim Ingham m_filenames.AppendIfUnique(FileSpec(option_arg, false)); 437fab10e89SJim Ingham break; 438ca36cd16SJim Ingham 439ca36cd16SJim Ingham case 'F': 440ca36cd16SJim Ingham m_func_names.push_back(option_arg); 441ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeFull; 442ca36cd16SJim Ingham break; 443ca36cd16SJim Ingham 444b9c1b51eSKate Stone case 'h': { 445fab10e89SJim Ingham bool success; 446*47cbf4a0SPavel Labath m_catch_bp = OptionArgParser::ToBoolean(option_arg, true, &success); 447fab10e89SJim Ingham if (!success) 448b9c1b51eSKate Stone error.SetErrorStringWithFormat( 449fe11483bSZachary Turner "Invalid boolean value for on-catch option: '%s'", 450fe11483bSZachary Turner option_arg.str().c_str()); 451b9c1b51eSKate Stone } break; 452eb023e75SGreg Clayton 453eb023e75SGreg Clayton case 'H': 454eb023e75SGreg Clayton m_hardware = true; 455eb023e75SGreg Clayton break; 456eb023e75SGreg Clayton 457b9c1b51eSKate Stone case 'K': { 458a8558b62SJim Ingham bool success; 459a8558b62SJim Ingham bool value; 460*47cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, true, &success); 461a8558b62SJim Ingham if (value) 462a8558b62SJim Ingham m_skip_prologue = eLazyBoolYes; 463a8558b62SJim Ingham else 464a8558b62SJim Ingham m_skip_prologue = eLazyBoolNo; 465a8558b62SJim Ingham 466a8558b62SJim Ingham if (!success) 467b9c1b51eSKate Stone error.SetErrorStringWithFormat( 468b9c1b51eSKate Stone "Invalid boolean value for skip prologue option: '%s'", 469fe11483bSZachary Turner option_arg.str().c_str()); 470b9c1b51eSKate Stone } break; 471ca36cd16SJim Ingham 472fe11483bSZachary Turner case 'l': 473fe11483bSZachary Turner if (option_arg.getAsInteger(0, m_line_num)) 474b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid line number: %s.", 475fe11483bSZachary Turner option_arg.str().c_str()); 476ca36cd16SJim Ingham break; 477055ad9beSIlia K 47823b1decbSDawn Perchik case 'L': 479fe11483bSZachary Turner m_language = Language::GetLanguageTypeFromString(option_arg); 48023b1decbSDawn Perchik if (m_language == eLanguageTypeUnknown) 481b9c1b51eSKate Stone error.SetErrorStringWithFormat( 482fe11483bSZachary Turner "Unknown language type: '%s' for breakpoint", 483fe11483bSZachary Turner option_arg.str().c_str()); 48423b1decbSDawn Perchik break; 48523b1decbSDawn Perchik 486b9c1b51eSKate Stone case 'm': { 487055ad9beSIlia K bool success; 488055ad9beSIlia K bool value; 489*47cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, true, &success); 490055ad9beSIlia K if (value) 491055ad9beSIlia K m_move_to_nearest_code = eLazyBoolYes; 492055ad9beSIlia K else 493055ad9beSIlia K m_move_to_nearest_code = eLazyBoolNo; 494055ad9beSIlia K 495055ad9beSIlia K if (!success) 496b9c1b51eSKate Stone error.SetErrorStringWithFormat( 497b9c1b51eSKate Stone "Invalid boolean value for move-to-nearest-code option: '%s'", 498fe11483bSZachary Turner option_arg.str().c_str()); 499055ad9beSIlia K break; 500055ad9beSIlia K } 501055ad9beSIlia K 502ca36cd16SJim Ingham case 'M': 503ca36cd16SJim Ingham m_func_names.push_back(option_arg); 504ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeMethod; 505ca36cd16SJim Ingham break; 506ca36cd16SJim Ingham 507ca36cd16SJim Ingham case 'n': 508ca36cd16SJim Ingham m_func_names.push_back(option_arg); 509ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeAuto; 510ca36cd16SJim Ingham break; 511ca36cd16SJim Ingham 5126fa7681bSZachary Turner case 'N': { 513fe11483bSZachary Turner if (BreakpointID::StringIsBreakpointName(option_arg, error)) 5145e09c8c3SJim Ingham m_breakpoint_names.push_back(option_arg); 515ff9a91eaSJim Ingham else 516ff9a91eaSJim Ingham error.SetErrorStringWithFormat("Invalid breakpoint name: %s", 517fe11483bSZachary Turner option_arg.str().c_str()); 5185e09c8c3SJim Ingham break; 5196fa7681bSZachary Turner } 5205e09c8c3SJim Ingham 521b9c1b51eSKate Stone case 'R': { 5222411167fSJim Ingham lldb::addr_t tmp_offset_addr; 523*47cbf4a0SPavel Labath tmp_offset_addr = OptionArgParser::ToAddress(execution_context, 524*47cbf4a0SPavel Labath option_arg, 0, &error); 5252411167fSJim Ingham if (error.Success()) 5262411167fSJim Ingham m_offset_addr = tmp_offset_addr; 527b9c1b51eSKate Stone } break; 5282411167fSJim Ingham 529a72b31c7SJim Ingham case 'O': 530fe11483bSZachary Turner m_exception_extra_args.AppendArgument("-O"); 531fe11483bSZachary Turner m_exception_extra_args.AppendArgument(option_arg); 532a72b31c7SJim Ingham break; 533a72b31c7SJim Ingham 534ca36cd16SJim Ingham case 'p': 535ca36cd16SJim Ingham m_source_text_regexp.assign(option_arg); 536ca36cd16SJim Ingham break; 537ca36cd16SJim Ingham 538ca36cd16SJim Ingham case 'r': 539ca36cd16SJim Ingham m_func_regexp.assign(option_arg); 540ca36cd16SJim Ingham break; 541ca36cd16SJim Ingham 542ca36cd16SJim Ingham case 's': 543ca36cd16SJim Ingham m_modules.AppendIfUnique(FileSpec(option_arg, false)); 544ca36cd16SJim Ingham break; 545ca36cd16SJim Ingham 546ca36cd16SJim Ingham case 'S': 547ca36cd16SJim Ingham m_func_names.push_back(option_arg); 548ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeSelector; 549ca36cd16SJim Ingham break; 550ca36cd16SJim Ingham 551b9c1b51eSKate Stone case 'w': { 552ca36cd16SJim Ingham bool success; 553*47cbf4a0SPavel Labath m_throw_bp = OptionArgParser::ToBoolean(option_arg, true, &success); 554ca36cd16SJim Ingham if (!success) 555b9c1b51eSKate Stone error.SetErrorStringWithFormat( 556fe11483bSZachary Turner "Invalid boolean value for on-throw option: '%s'", 557fe11483bSZachary Turner option_arg.str().c_str()); 558b9c1b51eSKate Stone } break; 559ca36cd16SJim Ingham 56076bb8d67SJim Ingham case 'X': 56176bb8d67SJim Ingham m_source_regex_func_names.insert(option_arg); 56276bb8d67SJim Ingham break; 56376bb8d67SJim Ingham 56430fdc8d8SChris Lattner default: 565b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 566b9c1b51eSKate Stone short_option); 56730fdc8d8SChris Lattner break; 56830fdc8d8SChris Lattner } 56930fdc8d8SChris Lattner 57030fdc8d8SChris Lattner return error; 57130fdc8d8SChris Lattner } 5729e85e5a8SEugene Zelenko 573b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 57487df91b8SJim Ingham m_filenames.Clear(); 57530fdc8d8SChris Lattner m_line_num = 0; 57630fdc8d8SChris Lattner m_column = 0; 577fab10e89SJim Ingham m_func_names.clear(); 5781f746071SGreg Clayton m_func_name_type_mask = eFunctionNameTypeNone; 57930fdc8d8SChris Lattner m_func_regexp.clear(); 5801f746071SGreg Clayton m_source_text_regexp.clear(); 58187df91b8SJim Ingham m_modules.Clear(); 5821f746071SGreg Clayton m_load_addr = LLDB_INVALID_ADDRESS; 5832411167fSJim Ingham m_offset_addr = 0; 584fab10e89SJim Ingham m_catch_bp = false; 585fab10e89SJim Ingham m_throw_bp = true; 586eb023e75SGreg Clayton m_hardware = false; 587a72b31c7SJim Ingham m_exception_language = eLanguageTypeUnknown; 58823b1decbSDawn Perchik m_language = lldb::eLanguageTypeUnknown; 589a8558b62SJim Ingham m_skip_prologue = eLazyBoolCalculate; 5905e09c8c3SJim Ingham m_breakpoint_names.clear(); 591e732052fSJim Ingham m_all_files = false; 592a72b31c7SJim Ingham m_exception_extra_args.Clear(); 593055ad9beSIlia K m_move_to_nearest_code = eLazyBoolCalculate; 59476bb8d67SJim Ingham m_source_regex_func_names.clear(); 59530fdc8d8SChris Lattner } 59630fdc8d8SChris Lattner 5971f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 59870602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_set_options); 5991f0f5b5bSZachary Turner } 60030fdc8d8SChris Lattner 6015a988416SJim Ingham // Instance variables to hold the values for command options. 602969795f1SJim Ingham 6035a988416SJim Ingham std::string m_condition; 6045a988416SJim Ingham FileSpecList m_filenames; 6055a988416SJim Ingham uint32_t m_line_num; 6065a988416SJim Ingham uint32_t m_column; 6075a988416SJim Ingham std::vector<std::string> m_func_names; 6085e09c8c3SJim Ingham std::vector<std::string> m_breakpoint_names; 6095a988416SJim Ingham uint32_t m_func_name_type_mask; 6105a988416SJim Ingham std::string m_func_regexp; 6115a988416SJim Ingham std::string m_source_text_regexp; 6125a988416SJim Ingham FileSpecList m_modules; 6135a988416SJim Ingham lldb::addr_t m_load_addr; 6142411167fSJim Ingham lldb::addr_t m_offset_addr; 6155a988416SJim Ingham bool m_catch_bp; 6165a988416SJim Ingham bool m_throw_bp; 617eb023e75SGreg Clayton bool m_hardware; // Request to use hardware breakpoints 618a72b31c7SJim Ingham lldb::LanguageType m_exception_language; 61923b1decbSDawn Perchik lldb::LanguageType m_language; 6205a988416SJim Ingham LazyBool m_skip_prologue; 621e732052fSJim Ingham bool m_all_files; 622a72b31c7SJim Ingham Args m_exception_extra_args; 623055ad9beSIlia K LazyBool m_move_to_nearest_code; 62476bb8d67SJim Ingham std::unordered_set<std::string> m_source_regex_func_names; 6255a988416SJim Ingham }; 6265a988416SJim Ingham 6275a988416SJim Ingham protected: 628b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 629b842f2ecSJim Ingham Target *target = GetSelectedOrDummyTarget(m_dummy_options.m_use_dummy); 63033df7cd3SJim Ingham 631b9c1b51eSKate Stone if (target == nullptr) { 632b9c1b51eSKate Stone result.AppendError("Invalid target. Must set target before setting " 633b9c1b51eSKate Stone "breakpoints (see 'target create' command)."); 63430fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 63530fdc8d8SChris Lattner return false; 63630fdc8d8SChris Lattner } 63730fdc8d8SChris Lattner 63830fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 63930fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 64030fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 64130fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 642b9c1b51eSKate Stone // 4). -r [-s -g] (setting breakpoint by function name regular 643b9c1b51eSKate Stone // expression) 644b9c1b51eSKate Stone // 5). -p -f (setting a breakpoint by comparing a reg-exp 645b9c1b51eSKate Stone // to source text) 646b9c1b51eSKate Stone // 6). -E [-w -h] (setting a breakpoint for exceptions for a 647b9c1b51eSKate Stone // given language.) 64830fdc8d8SChris Lattner 64930fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 65030fdc8d8SChris Lattner 65130fdc8d8SChris Lattner if (m_options.m_line_num != 0) 65230fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 65330fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 65430fdc8d8SChris Lattner break_type = eSetTypeAddress; 655fab10e89SJim Ingham else if (!m_options.m_func_names.empty()) 65630fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 65730fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 65830fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 659969795f1SJim Ingham else if (!m_options.m_source_text_regexp.empty()) 660969795f1SJim Ingham break_type = eSetTypeSourceRegexp; 661a72b31c7SJim Ingham else if (m_options.m_exception_language != eLanguageTypeUnknown) 662fab10e89SJim Ingham break_type = eSetTypeException; 66330fdc8d8SChris Lattner 664b842f2ecSJim Ingham BreakpointSP bp_sp = nullptr; 665274060b6SGreg Clayton FileSpec module_spec; 666a8558b62SJim Ingham const bool internal = false; 667a8558b62SJim Ingham 668b9c1b51eSKate Stone // If the user didn't specify skip-prologue, having an offset should turn 669b9c1b51eSKate Stone // that off. 670b9c1b51eSKate Stone if (m_options.m_offset_addr != 0 && 671b9c1b51eSKate Stone m_options.m_skip_prologue == eLazyBoolCalculate) 6722411167fSJim Ingham m_options.m_skip_prologue = eLazyBoolNo; 6732411167fSJim Ingham 674b9c1b51eSKate Stone switch (break_type) { 67530fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 67630fdc8d8SChris Lattner { 67730fdc8d8SChris Lattner FileSpec file; 678c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 679b9c1b51eSKate Stone if (num_files == 0) { 680b9c1b51eSKate Stone if (!GetDefaultFile(target, file, result)) { 68187df91b8SJim Ingham result.AppendError("No file supplied and no default file available."); 68287df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 68387df91b8SJim Ingham return false; 68487df91b8SJim Ingham } 685b9c1b51eSKate Stone } else if (num_files > 1) { 686b9c1b51eSKate Stone result.AppendError("Only one file at a time is allowed for file and " 687b9c1b51eSKate Stone "line breakpoints."); 68887df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 68987df91b8SJim Ingham return false; 690b9c1b51eSKate Stone } else 69187df91b8SJim Ingham file = m_options.m_filenames.GetFileSpecAtIndex(0); 69230fdc8d8SChris Lattner 6931f746071SGreg Clayton // Only check for inline functions if 6941f746071SGreg Clayton LazyBool check_inlines = eLazyBoolCalculate; 6951f746071SGreg Clayton 696b842f2ecSJim Ingham bp_sp = target->CreateBreakpoint(&(m_options.m_modules), 697b842f2ecSJim Ingham file, 698b842f2ecSJim Ingham m_options.m_line_num, 699b842f2ecSJim Ingham m_options.m_offset_addr, 700b842f2ecSJim Ingham check_inlines, 701b842f2ecSJim Ingham m_options.m_skip_prologue, 702b842f2ecSJim Ingham internal, 703b842f2ecSJim Ingham m_options.m_hardware, 704b842f2ecSJim Ingham m_options.m_move_to_nearest_code); 705b9c1b51eSKate Stone } break; 7066eee5aa0SGreg Clayton 70730fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 708055a08a4SJim Ingham { 709b9c1b51eSKate Stone // If a shared library has been specified, make an lldb_private::Address 710b842f2ecSJim Ingham // with the library, and use that. That way the address breakpoint 711b842f2ecSJim Ingham // will track the load location of the library. 712055a08a4SJim Ingham size_t num_modules_specified = m_options.m_modules.GetSize(); 713b9c1b51eSKate Stone if (num_modules_specified == 1) { 714b9c1b51eSKate Stone const FileSpec *file_spec = 715b9c1b51eSKate Stone m_options.m_modules.GetFileSpecPointerAtIndex(0); 716b842f2ecSJim Ingham bp_sp = target->CreateAddressInModuleBreakpoint(m_options.m_load_addr, 717b9c1b51eSKate Stone internal, file_spec, 718b842f2ecSJim Ingham m_options.m_hardware); 719b9c1b51eSKate Stone } else if (num_modules_specified == 0) { 720b842f2ecSJim Ingham bp_sp = target->CreateBreakpoint(m_options.m_load_addr, internal, 721b842f2ecSJim Ingham m_options.m_hardware); 722b9c1b51eSKate Stone } else { 723b9c1b51eSKate Stone result.AppendError("Only one shared library can be specified for " 724b9c1b51eSKate Stone "address breakpoints."); 725055a08a4SJim Ingham result.SetStatus(eReturnStatusFailed); 726055a08a4SJim Ingham return false; 727055a08a4SJim Ingham } 72830fdc8d8SChris Lattner break; 729055a08a4SJim Ingham } 73030fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 7310c5cd90dSGreg Clayton { 7320c5cd90dSGreg Clayton uint32_t name_type_mask = m_options.m_func_name_type_mask; 7330c5cd90dSGreg Clayton 7340c5cd90dSGreg Clayton if (name_type_mask == 0) 735e02b8504SGreg Clayton name_type_mask = eFunctionNameTypeAuto; 7360c5cd90dSGreg Clayton 737b842f2ecSJim Ingham bp_sp = target->CreateBreakpoint(&(m_options.m_modules), 738b842f2ecSJim Ingham &(m_options.m_filenames), 739b842f2ecSJim Ingham m_options.m_func_names, 740b842f2ecSJim Ingham name_type_mask, 741b842f2ecSJim Ingham m_options.m_language, 742b842f2ecSJim Ingham m_options.m_offset_addr, 743b842f2ecSJim Ingham m_options.m_skip_prologue, 744b842f2ecSJim Ingham internal, 745b842f2ecSJim Ingham m_options.m_hardware); 746b9c1b51eSKate Stone } break; 7470c5cd90dSGreg Clayton 748b9c1b51eSKate Stone case eSetTypeFunctionRegexp: // Breakpoint by regular expression function 749b9c1b51eSKate Stone // name 75030fdc8d8SChris Lattner { 75195eae423SZachary Turner RegularExpression regexp(m_options.m_func_regexp); 752b9c1b51eSKate Stone if (!regexp.IsValid()) { 753969795f1SJim Ingham char err_str[1024]; 754969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 755b9c1b51eSKate Stone result.AppendErrorWithFormat( 756b9c1b51eSKate Stone "Function name regular expression could not be compiled: \"%s\"", 757969795f1SJim Ingham err_str); 75830fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 759969795f1SJim Ingham return false; 76030fdc8d8SChris Lattner } 76187df91b8SJim Ingham 762b842f2ecSJim Ingham bp_sp = target->CreateFuncRegexBreakpoint(&(m_options.m_modules), 763b842f2ecSJim Ingham &(m_options.m_filenames), 764b842f2ecSJim Ingham regexp, 765b842f2ecSJim Ingham m_options.m_language, 766b842f2ecSJim Ingham m_options.m_skip_prologue, 767b842f2ecSJim Ingham internal, 768b842f2ecSJim Ingham m_options.m_hardware); 769e14dc268SJim Ingham } 770e14dc268SJim Ingham break; 771969795f1SJim Ingham case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. 772969795f1SJim Ingham { 773c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 77487df91b8SJim Ingham 775b9c1b51eSKate Stone if (num_files == 0 && !m_options.m_all_files) { 776969795f1SJim Ingham FileSpec file; 777b9c1b51eSKate Stone if (!GetDefaultFile(target, file, result)) { 778b9c1b51eSKate Stone result.AppendError( 779b9c1b51eSKate Stone "No files provided and could not find default file."); 78087df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 78187df91b8SJim Ingham return false; 782b9c1b51eSKate Stone } else { 78387df91b8SJim Ingham m_options.m_filenames.Append(file); 78487df91b8SJim Ingham } 78587df91b8SJim Ingham } 7860c5cd90dSGreg Clayton 78795eae423SZachary Turner RegularExpression regexp(m_options.m_source_text_regexp); 788b9c1b51eSKate Stone if (!regexp.IsValid()) { 789969795f1SJim Ingham char err_str[1024]; 790969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 791b9c1b51eSKate Stone result.AppendErrorWithFormat( 792b9c1b51eSKate Stone "Source text regular expression could not be compiled: \"%s\"", 793969795f1SJim Ingham err_str); 794969795f1SJim Ingham result.SetStatus(eReturnStatusFailed); 795969795f1SJim Ingham return false; 796969795f1SJim Ingham } 797b842f2ecSJim Ingham bp_sp = 798b842f2ecSJim Ingham target->CreateSourceRegexBreakpoint(&(m_options.m_modules), 799b842f2ecSJim Ingham &(m_options.m_filenames), 800b842f2ecSJim Ingham m_options 801b842f2ecSJim Ingham .m_source_regex_func_names, 802b842f2ecSJim Ingham regexp, 803b842f2ecSJim Ingham internal, 804b842f2ecSJim Ingham m_options.m_hardware, 805b842f2ecSJim Ingham m_options.m_move_to_nearest_code); 806b9c1b51eSKate Stone } break; 807b9c1b51eSKate Stone case eSetTypeException: { 80897206d57SZachary Turner Status precond_error; 809b842f2ecSJim Ingham bp_sp = target->CreateExceptionBreakpoint(m_options.m_exception_language, 810b842f2ecSJim Ingham m_options.m_catch_bp, 811b842f2ecSJim Ingham m_options.m_throw_bp, 812b842f2ecSJim Ingham internal, 813b842f2ecSJim Ingham &m_options 814b842f2ecSJim Ingham .m_exception_extra_args, 815b842f2ecSJim Ingham &precond_error); 816b9c1b51eSKate Stone if (precond_error.Fail()) { 817b9c1b51eSKate Stone result.AppendErrorWithFormat( 818b9c1b51eSKate Stone "Error setting extra exception arguments: %s", 819a72b31c7SJim Ingham precond_error.AsCString()); 820b842f2ecSJim Ingham target->RemoveBreakpointByID(bp_sp->GetID()); 821a72b31c7SJim Ingham result.SetStatus(eReturnStatusFailed); 822a72b31c7SJim Ingham return false; 823a72b31c7SJim Ingham } 824b9c1b51eSKate Stone } break; 82530fdc8d8SChris Lattner default: 82630fdc8d8SChris Lattner break; 82730fdc8d8SChris Lattner } 82830fdc8d8SChris Lattner 8291b54c88cSJim Ingham // Now set the various options that were passed in: 830b842f2ecSJim Ingham if (bp_sp) { 831b842f2ecSJim Ingham bp_sp->GetOptions()->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); 832ca36cd16SJim Ingham 833b9c1b51eSKate Stone if (!m_options.m_breakpoint_names.empty()) { 83497206d57SZachary Turner Status name_error; 835ff9a91eaSJim Ingham for (auto name : m_options.m_breakpoint_names) { 836b842f2ecSJim Ingham target->AddNameToBreakpoint(bp_sp, name.c_str(), name_error); 837ff9a91eaSJim Ingham if (name_error.Fail()) { 838ff9a91eaSJim Ingham result.AppendErrorWithFormat("Invalid breakpoint name: %s", 839ff9a91eaSJim Ingham name.c_str()); 840b842f2ecSJim Ingham target->RemoveBreakpointByID(bp_sp->GetID()); 841ff9a91eaSJim Ingham result.SetStatus(eReturnStatusFailed); 842ff9a91eaSJim Ingham return false; 843ff9a91eaSJim Ingham } 844ff9a91eaSJim Ingham } 8455e09c8c3SJim Ingham } 8461b54c88cSJim Ingham } 8471b54c88cSJim Ingham 848b842f2ecSJim Ingham if (bp_sp) { 84985e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 8501391cc7dSJim Ingham const bool show_locations = false; 851b842f2ecSJim Ingham bp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, 852b9c1b51eSKate Stone show_locations); 8534aeb1989SJim Ingham if (target == m_interpreter.GetDebugger().GetDummyTarget()) 854b9c1b51eSKate Stone output_stream.Printf("Breakpoint set in dummy target, will get copied " 855b9c1b51eSKate Stone "into future targets.\n"); 856b9c1b51eSKate Stone else { 857b9c1b51eSKate Stone // Don't print out this warning for exception breakpoints. They can get 858b842f2ecSJim Ingham // set before the target is set, but we won't know how to actually set 859b842f2ecSJim Ingham // the breakpoint till we run. 860b842f2ecSJim Ingham if (bp_sp->GetNumLocations() == 0 && break_type != eSetTypeException) { 861b9c1b51eSKate Stone output_stream.Printf("WARNING: Unable to resolve breakpoint to any " 862b9c1b51eSKate Stone "actual locations.\n"); 8634aeb1989SJim Ingham } 8644aeb1989SJim Ingham } 86530fdc8d8SChris Lattner result.SetStatus(eReturnStatusSuccessFinishResult); 866b842f2ecSJim Ingham } else if (!bp_sp) { 86730fdc8d8SChris Lattner result.AppendError("Breakpoint creation failed: No breakpoint created."); 86830fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 86930fdc8d8SChris Lattner } 87030fdc8d8SChris Lattner 87130fdc8d8SChris Lattner return result.Succeeded(); 87230fdc8d8SChris Lattner } 87330fdc8d8SChris Lattner 8745a988416SJim Ingham private: 875b9c1b51eSKate Stone bool GetDefaultFile(Target *target, FileSpec &file, 876b9c1b51eSKate Stone CommandReturnObject &result) { 8775a988416SJim Ingham uint32_t default_line; 8785a988416SJim Ingham // First use the Source Manager's default file. 8795a988416SJim Ingham // Then use the current stack frame's file. 880b9c1b51eSKate Stone if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) { 881b57e4a1bSJason Molenda StackFrame *cur_frame = m_exe_ctx.GetFramePtr(); 882b9c1b51eSKate Stone if (cur_frame == nullptr) { 883b9c1b51eSKate Stone result.AppendError( 884b9c1b51eSKate Stone "No selected frame to use to find the default file."); 8855a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 8865a988416SJim Ingham return false; 887b9c1b51eSKate Stone } else if (!cur_frame->HasDebugInformation()) { 888b9c1b51eSKate Stone result.AppendError("Cannot use the selected frame to find the default " 889b9c1b51eSKate Stone "file, it has no debug info."); 8905a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 8915a988416SJim Ingham return false; 892b9c1b51eSKate Stone } else { 893b9c1b51eSKate Stone const SymbolContext &sc = 894b9c1b51eSKate Stone cur_frame->GetSymbolContext(eSymbolContextLineEntry); 895b9c1b51eSKate Stone if (sc.line_entry.file) { 8965a988416SJim Ingham file = sc.line_entry.file; 897b9c1b51eSKate Stone } else { 898b9c1b51eSKate Stone result.AppendError("Can't find the file for the selected frame to " 899b9c1b51eSKate Stone "use as the default file."); 9005a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 9015a988416SJim Ingham return false; 9025a988416SJim Ingham } 9035a988416SJim Ingham } 9045a988416SJim Ingham } 9055a988416SJim Ingham return true; 9065a988416SJim Ingham } 9075a988416SJim Ingham 908b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 909b842f2ecSJim Ingham BreakpointDummyOptionGroup m_dummy_options; 9105a988416SJim Ingham CommandOptions m_options; 911b842f2ecSJim Ingham OptionGroupOptions m_all_options; 9125a988416SJim Ingham }; 9139e85e5a8SEugene Zelenko 9145a988416SJim Ingham //------------------------------------------------------------------------- 9155a988416SJim Ingham // CommandObjectBreakpointModify 9165a988416SJim Ingham //------------------------------------------------------------------------- 9175a988416SJim Ingham #pragma mark Modify 9185a988416SJim Ingham 919b9c1b51eSKate Stone class CommandObjectBreakpointModify : public CommandObjectParsed { 9205a988416SJim Ingham public: 921b9c1b51eSKate Stone CommandObjectBreakpointModify(CommandInterpreter &interpreter) 922b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "breakpoint modify", 923b9c1b51eSKate Stone "Modify the options on a breakpoint or set of " 924b9c1b51eSKate Stone "breakpoints in the executable. " 925b9c1b51eSKate Stone "If no breakpoint is specified, acts on the last " 926b9c1b51eSKate Stone "created breakpoint. " 927b9c1b51eSKate Stone "With the exception of -e, -d and -i, passing an " 928b9c1b51eSKate Stone "empty argument clears the modification.", 9299e85e5a8SEugene Zelenko nullptr), 930b9c1b51eSKate Stone m_options() { 9315a988416SJim Ingham CommandArgumentEntry arg; 932b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 933b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 934b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 935b9c1b51eSKate Stone // arguments vector. 9365a988416SJim Ingham m_arguments.push_back(arg); 937b842f2ecSJim Ingham 938b842f2ecSJim Ingham m_options.Append(&m_bp_opts, 939b842f2ecSJim Ingham LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3, 940b842f2ecSJim Ingham LLDB_OPT_SET_ALL); 941b842f2ecSJim Ingham m_options.Append(&m_dummy_opts, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 942b842f2ecSJim Ingham m_options.Finalize(); 9435a988416SJim Ingham } 9445a988416SJim Ingham 9459e85e5a8SEugene Zelenko ~CommandObjectBreakpointModify() override = default; 9465a988416SJim Ingham 947b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 9485a988416SJim Ingham 9495a988416SJim Ingham protected: 950b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 951b842f2ecSJim Ingham Target *target = GetSelectedOrDummyTarget(m_dummy_opts.m_use_dummy); 952b9c1b51eSKate Stone if (target == nullptr) { 9535a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 9545a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 9555a988416SJim Ingham return false; 9565a988416SJim Ingham } 9575a988416SJim Ingham 958bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 959bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 9605a988416SJim Ingham 9615a988416SJim Ingham BreakpointIDList valid_bp_ids; 9625a988416SJim Ingham 963b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 964b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 965b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 9665a988416SJim Ingham 967b9c1b51eSKate Stone if (result.Succeeded()) { 9685a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 969b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 9705a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 9715a988416SJim Ingham 972b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 973b9c1b51eSKate Stone Breakpoint *bp = 974b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 975b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 976b9c1b51eSKate Stone BreakpointLocation *location = 977b9c1b51eSKate Stone bp->FindLocationByID(cur_bp_id.GetLocationID()).get(); 978b842f2ecSJim Ingham if (location) 979b842f2ecSJim Ingham location->GetLocationOptions() 980b842f2ecSJim Ingham ->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); 981b9c1b51eSKate Stone } else { 982b842f2ecSJim Ingham bp->GetOptions() 983b842f2ecSJim Ingham ->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); 9845a988416SJim Ingham } 9855a988416SJim Ingham } 9865a988416SJim Ingham } 9875a988416SJim Ingham } 9885a988416SJim Ingham 9895a988416SJim Ingham return result.Succeeded(); 9905a988416SJim Ingham } 9915a988416SJim Ingham 9925a988416SJim Ingham private: 993b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 994b842f2ecSJim Ingham BreakpointDummyOptionGroup m_dummy_opts; 995b842f2ecSJim Ingham OptionGroupOptions m_options; 9965a988416SJim Ingham }; 9975a988416SJim Ingham 9985a988416SJim Ingham //------------------------------------------------------------------------- 9995a988416SJim Ingham // CommandObjectBreakpointEnable 10005a988416SJim Ingham //------------------------------------------------------------------------- 10015a988416SJim Ingham #pragma mark Enable 10025a988416SJim Ingham 1003b9c1b51eSKate Stone class CommandObjectBreakpointEnable : public CommandObjectParsed { 10045a988416SJim Ingham public: 1005b9c1b51eSKate Stone CommandObjectBreakpointEnable(CommandInterpreter &interpreter) 1006b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "enable", 1007b9c1b51eSKate Stone "Enable the specified disabled breakpoint(s). If " 1008b9c1b51eSKate Stone "no breakpoints are specified, enable all of them.", 1009b9c1b51eSKate Stone nullptr) { 10105a988416SJim Ingham CommandArgumentEntry arg; 1011b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1012b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1013b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1014b9c1b51eSKate Stone // arguments vector. 10155a988416SJim Ingham m_arguments.push_back(arg); 10165a988416SJim Ingham } 10175a988416SJim Ingham 10189e85e5a8SEugene Zelenko ~CommandObjectBreakpointEnable() override = default; 10195a988416SJim Ingham 10205a988416SJim Ingham protected: 1021b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1022893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1023b9c1b51eSKate Stone if (target == nullptr) { 10245a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 10255a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 10265a988416SJim Ingham return false; 10275a988416SJim Ingham } 10285a988416SJim Ingham 1029bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1030bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 10315a988416SJim Ingham 10325a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 10335a988416SJim Ingham 10345a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 10355a988416SJim Ingham 1036b9c1b51eSKate Stone if (num_breakpoints == 0) { 10375a988416SJim Ingham result.AppendError("No breakpoints exist to be enabled."); 10385a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 10395a988416SJim Ingham return false; 10405a988416SJim Ingham } 10415a988416SJim Ingham 104211eb9c64SZachary Turner if (command.empty()) { 10435a988416SJim Ingham // No breakpoint selected; enable all currently set breakpoints. 1044b842f2ecSJim Ingham target->EnableAllowedBreakpoints(); 1045b9c1b51eSKate Stone result.AppendMessageWithFormat("All breakpoints enabled. (%" PRIu64 1046b9c1b51eSKate Stone " breakpoints)\n", 1047b9c1b51eSKate Stone (uint64_t)num_breakpoints); 10485a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1049b9c1b51eSKate Stone } else { 10505a988416SJim Ingham // Particular breakpoint selected; enable that breakpoint. 10515a988416SJim Ingham BreakpointIDList valid_bp_ids; 1052b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1053b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1054b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 10555a988416SJim Ingham 1056b9c1b51eSKate Stone if (result.Succeeded()) { 10575a988416SJim Ingham int enable_count = 0; 10585a988416SJim Ingham int loc_count = 0; 10595a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1060b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 10615a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 10625a988416SJim Ingham 1063b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1064b9c1b51eSKate Stone Breakpoint *breakpoint = 1065b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1066b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1067b9c1b51eSKate Stone BreakpointLocation *location = 1068b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1069b9c1b51eSKate Stone if (location) { 10705a988416SJim Ingham location->SetEnabled(true); 10715a988416SJim Ingham ++loc_count; 10725a988416SJim Ingham } 1073b9c1b51eSKate Stone } else { 10745a988416SJim Ingham breakpoint->SetEnabled(true); 10755a988416SJim Ingham ++enable_count; 10765a988416SJim Ingham } 10775a988416SJim Ingham } 10785a988416SJim Ingham } 1079b9c1b51eSKate Stone result.AppendMessageWithFormat("%d breakpoints enabled.\n", 1080b9c1b51eSKate Stone enable_count + loc_count); 10815a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 10825a988416SJim Ingham } 10835a988416SJim Ingham } 10845a988416SJim Ingham 10855a988416SJim Ingham return result.Succeeded(); 10865a988416SJim Ingham } 10875a988416SJim Ingham }; 10885a988416SJim Ingham 10895a988416SJim Ingham //------------------------------------------------------------------------- 10905a988416SJim Ingham // CommandObjectBreakpointDisable 10915a988416SJim Ingham //------------------------------------------------------------------------- 10925a988416SJim Ingham #pragma mark Disable 10935a988416SJim Ingham 1094b9c1b51eSKate Stone class CommandObjectBreakpointDisable : public CommandObjectParsed { 10955a988416SJim Ingham public: 10967428a18cSKate Stone CommandObjectBreakpointDisable(CommandInterpreter &interpreter) 1097b9c1b51eSKate Stone : CommandObjectParsed( 1098b9c1b51eSKate Stone interpreter, "breakpoint disable", 1099b9c1b51eSKate Stone "Disable the specified breakpoint(s) without deleting " 11007428a18cSKate Stone "them. If none are specified, disable all " 11017428a18cSKate Stone "breakpoints.", 1102b9c1b51eSKate Stone nullptr) { 1103b9c1b51eSKate Stone SetHelpLong( 1104b9c1b51eSKate Stone "Disable the specified breakpoint(s) without deleting them. \ 11057428a18cSKate Stone If none are specified, disable all breakpoints." 11067428a18cSKate Stone R"( 1107ea671fbdSKate Stone 11087428a18cSKate Stone )" 11097428a18cSKate Stone "Note: disabling a breakpoint will cause none of its locations to be hit \ 11107428a18cSKate Stone regardless of whether individual locations are enabled or disabled. After the sequence:" 11117428a18cSKate Stone R"( 1112ea671fbdSKate Stone 1113ea671fbdSKate Stone (lldb) break disable 1 1114ea671fbdSKate Stone (lldb) break enable 1.1 1115ea671fbdSKate Stone 1116ea671fbdSKate Stone execution will NOT stop at location 1.1. To achieve that, type: 1117ea671fbdSKate Stone 1118ea671fbdSKate Stone (lldb) break disable 1.* 1119ea671fbdSKate Stone (lldb) break enable 1.1 1120ea671fbdSKate Stone 11217428a18cSKate Stone )" 11227428a18cSKate Stone "The first command disables all locations for breakpoint 1, \ 11237428a18cSKate Stone the second re-enables the first location."); 1124b0fac509SJim Ingham 11255a988416SJim Ingham CommandArgumentEntry arg; 1126b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1127b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1128b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1129b9c1b51eSKate Stone // arguments vector. 11305a988416SJim Ingham m_arguments.push_back(arg); 11315a988416SJim Ingham } 11325a988416SJim Ingham 11339e85e5a8SEugene Zelenko ~CommandObjectBreakpointDisable() override = default; 11345a988416SJim Ingham 11355a988416SJim Ingham protected: 1136b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1137893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1138b9c1b51eSKate Stone if (target == nullptr) { 11395a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 11405a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 11415a988416SJim Ingham return false; 11425a988416SJim Ingham } 11435a988416SJim Ingham 1144bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1145bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 11465a988416SJim Ingham 11475a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 11485a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 11495a988416SJim Ingham 1150b9c1b51eSKate Stone if (num_breakpoints == 0) { 11515a988416SJim Ingham result.AppendError("No breakpoints exist to be disabled."); 11525a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 11535a988416SJim Ingham return false; 11545a988416SJim Ingham } 11555a988416SJim Ingham 115611eb9c64SZachary Turner if (command.empty()) { 11575a988416SJim Ingham // No breakpoint selected; disable all currently set breakpoints. 1158b842f2ecSJim Ingham target->DisableAllowedBreakpoints(); 1159b9c1b51eSKate Stone result.AppendMessageWithFormat("All breakpoints disabled. (%" PRIu64 1160b9c1b51eSKate Stone " breakpoints)\n", 1161b9c1b51eSKate Stone (uint64_t)num_breakpoints); 11625a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1163b9c1b51eSKate Stone } else { 11645a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 11655a988416SJim Ingham BreakpointIDList valid_bp_ids; 11665a988416SJim Ingham 1167b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1168b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1169b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 11705a988416SJim Ingham 1171b9c1b51eSKate Stone if (result.Succeeded()) { 11725a988416SJim Ingham int disable_count = 0; 11735a988416SJim Ingham int loc_count = 0; 11745a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1175b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 11765a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 11775a988416SJim Ingham 1178b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1179b9c1b51eSKate Stone Breakpoint *breakpoint = 1180b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1181b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1182b9c1b51eSKate Stone BreakpointLocation *location = 1183b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1184b9c1b51eSKate Stone if (location) { 11855a988416SJim Ingham location->SetEnabled(false); 11865a988416SJim Ingham ++loc_count; 11875a988416SJim Ingham } 1188b9c1b51eSKate Stone } else { 11895a988416SJim Ingham breakpoint->SetEnabled(false); 11905a988416SJim Ingham ++disable_count; 11915a988416SJim Ingham } 11925a988416SJim Ingham } 11935a988416SJim Ingham } 1194b9c1b51eSKate Stone result.AppendMessageWithFormat("%d breakpoints disabled.\n", 1195b9c1b51eSKate Stone disable_count + loc_count); 11965a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 11975a988416SJim Ingham } 11985a988416SJim Ingham } 11995a988416SJim Ingham 12005a988416SJim Ingham return result.Succeeded(); 12015a988416SJim Ingham } 12025a988416SJim Ingham }; 12035a988416SJim Ingham 12045a988416SJim Ingham //------------------------------------------------------------------------- 12055a988416SJim Ingham // CommandObjectBreakpointList 12065a988416SJim Ingham //------------------------------------------------------------------------- 12071f0f5b5bSZachary Turner 12081f0f5b5bSZachary Turner #pragma mark List::CommandOptions 12091f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_list_options[] = { 12101f0f5b5bSZachary Turner // clang-format off 12111f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show debugger internal breakpoints" }, 12121f0f5b5bSZachary Turner { LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a brief description of the breakpoint (no location info)." }, 12131f0f5b5bSZachary Turner // FIXME: We need to add an "internal" command, and then add this sort of thing to it. 12141f0f5b5bSZachary Turner // But I need to see it for now, and don't want to wait. 12151f0f5b5bSZachary Turner { LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a full description of the breakpoint and its locations." }, 12161f0f5b5bSZachary Turner { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, 12171f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets." }, 12181f0f5b5bSZachary Turner // clang-format on 12191f0f5b5bSZachary Turner }; 12201f0f5b5bSZachary Turner 12215a988416SJim Ingham #pragma mark List 12225a988416SJim Ingham 1223b9c1b51eSKate Stone class CommandObjectBreakpointList : public CommandObjectParsed { 12245a988416SJim Ingham public: 1225b9c1b51eSKate Stone CommandObjectBreakpointList(CommandInterpreter &interpreter) 1226b9c1b51eSKate Stone : CommandObjectParsed( 1227b9c1b51eSKate Stone interpreter, "breakpoint list", 12285a988416SJim Ingham "List some or all breakpoints at configurable levels of detail.", 12299e85e5a8SEugene Zelenko nullptr), 1230b9c1b51eSKate Stone m_options() { 12315a988416SJim Ingham CommandArgumentEntry arg; 12325a988416SJim Ingham CommandArgumentData bp_id_arg; 12335a988416SJim Ingham 12345a988416SJim Ingham // Define the first (and only) variant of this arg. 12355a988416SJim Ingham bp_id_arg.arg_type = eArgTypeBreakpointID; 12365a988416SJim Ingham bp_id_arg.arg_repetition = eArgRepeatOptional; 12375a988416SJim Ingham 1238b9c1b51eSKate Stone // There is only one variant this argument could be; put it into the 1239b9c1b51eSKate Stone // argument entry. 12405a988416SJim Ingham arg.push_back(bp_id_arg); 12415a988416SJim Ingham 12425a988416SJim Ingham // Push the data for the first argument into the m_arguments vector. 12435a988416SJim Ingham m_arguments.push_back(arg); 12445a988416SJim Ingham } 12455a988416SJim Ingham 12469e85e5a8SEugene Zelenko ~CommandObjectBreakpointList() override = default; 12475a988416SJim Ingham 1248b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 12495a988416SJim Ingham 1250b9c1b51eSKate Stone class CommandOptions : public Options { 12515a988416SJim Ingham public: 1252b9c1b51eSKate Stone CommandOptions() 1253b9c1b51eSKate Stone : Options(), m_level(lldb::eDescriptionLevelBrief), m_use_dummy(false) { 12545a988416SJim Ingham } 12555a988416SJim Ingham 12569e85e5a8SEugene Zelenko ~CommandOptions() override = default; 12575a988416SJim Ingham 125897206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1259b9c1b51eSKate Stone ExecutionContext *execution_context) override { 126097206d57SZachary Turner Status error; 12613bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 12625a988416SJim Ingham 1263b9c1b51eSKate Stone switch (short_option) { 12645a988416SJim Ingham case 'b': 12655a988416SJim Ingham m_level = lldb::eDescriptionLevelBrief; 12665a988416SJim Ingham break; 126733df7cd3SJim Ingham case 'D': 126833df7cd3SJim Ingham m_use_dummy = true; 126933df7cd3SJim Ingham break; 12705a988416SJim Ingham case 'f': 12715a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 12725a988416SJim Ingham break; 12735a988416SJim Ingham case 'v': 12745a988416SJim Ingham m_level = lldb::eDescriptionLevelVerbose; 12755a988416SJim Ingham break; 12765a988416SJim Ingham case 'i': 12775a988416SJim Ingham m_internal = true; 12785a988416SJim Ingham break; 12795a988416SJim Ingham default: 1280b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1281b9c1b51eSKate Stone short_option); 12825a988416SJim Ingham break; 12835a988416SJim Ingham } 12845a988416SJim Ingham 12855a988416SJim Ingham return error; 12865a988416SJim Ingham } 12875a988416SJim Ingham 1288b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 12895a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 12905a988416SJim Ingham m_internal = false; 129133df7cd3SJim Ingham m_use_dummy = false; 12925a988416SJim Ingham } 12935a988416SJim Ingham 12941f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 129570602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_list_options); 12961f0f5b5bSZachary Turner } 12975a988416SJim Ingham 12985a988416SJim Ingham // Instance variables to hold the values for command options. 12995a988416SJim Ingham 13005a988416SJim Ingham lldb::DescriptionLevel m_level; 13015a988416SJim Ingham 13025a988416SJim Ingham bool m_internal; 130333df7cd3SJim Ingham bool m_use_dummy; 13045a988416SJim Ingham }; 13055a988416SJim Ingham 13065a988416SJim Ingham protected: 1307b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 130833df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 130933df7cd3SJim Ingham 1310b9c1b51eSKate Stone if (target == nullptr) { 13115a988416SJim Ingham result.AppendError("Invalid target. No current target or breakpoints."); 13125a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 13135a988416SJim Ingham return true; 13145a988416SJim Ingham } 13155a988416SJim Ingham 1316b9c1b51eSKate Stone const BreakpointList &breakpoints = 1317b9c1b51eSKate Stone target->GetBreakpointList(m_options.m_internal); 1318bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1319bb19a13cSSaleem Abdulrasool target->GetBreakpointList(m_options.m_internal).GetListMutex(lock); 13205a988416SJim Ingham 13215a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 13225a988416SJim Ingham 1323b9c1b51eSKate Stone if (num_breakpoints == 0) { 13245a988416SJim Ingham result.AppendMessage("No breakpoints currently set."); 13255a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 13265a988416SJim Ingham return true; 13275a988416SJim Ingham } 13285a988416SJim Ingham 13295a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 13305a988416SJim Ingham 133111eb9c64SZachary Turner if (command.empty()) { 13325a988416SJim Ingham // No breakpoint selected; show info about all currently set breakpoints. 13335a988416SJim Ingham result.AppendMessage("Current breakpoints:"); 1334b9c1b51eSKate Stone for (size_t i = 0; i < num_breakpoints; ++i) { 13355a988416SJim Ingham Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex(i).get(); 1336b842f2ecSJim Ingham if (breakpoint->AllowList()) 1337b842f2ecSJim Ingham AddBreakpointDescription(&output_stream, breakpoint, 1338b842f2ecSJim Ingham m_options.m_level); 13395a988416SJim Ingham } 13405a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1341b9c1b51eSKate Stone } else { 13425a988416SJim Ingham // Particular breakpoints selected; show info about that breakpoint. 13435a988416SJim Ingham BreakpointIDList valid_bp_ids; 1344b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1345b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1346b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 13475a988416SJim Ingham 1348b9c1b51eSKate Stone if (result.Succeeded()) { 1349b9c1b51eSKate Stone for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) { 13505a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 1351b9c1b51eSKate Stone Breakpoint *breakpoint = 1352b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1353b9c1b51eSKate Stone AddBreakpointDescription(&output_stream, breakpoint, 1354b9c1b51eSKate Stone m_options.m_level); 13555a988416SJim Ingham } 13565a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1357b9c1b51eSKate Stone } else { 13587428a18cSKate Stone result.AppendError("Invalid breakpoint ID."); 13595a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 13605a988416SJim Ingham } 13615a988416SJim Ingham } 13625a988416SJim Ingham 13635a988416SJim Ingham return result.Succeeded(); 13645a988416SJim Ingham } 13655a988416SJim Ingham 13665a988416SJim Ingham private: 13675a988416SJim Ingham CommandOptions m_options; 13685a988416SJim Ingham }; 13695a988416SJim Ingham 13705a988416SJim Ingham //------------------------------------------------------------------------- 13715a988416SJim Ingham // CommandObjectBreakpointClear 13725a988416SJim Ingham //------------------------------------------------------------------------- 13731f0f5b5bSZachary Turner #pragma mark Clear::CommandOptions 13741f0f5b5bSZachary Turner 13751f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_clear_options[] = { 13761f0f5b5bSZachary Turner // clang-format off 13771f0f5b5bSZachary Turner { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specify the breakpoint by source location in this particular file." }, 13781f0f5b5bSZachary Turner { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Specify the breakpoint by source location at this particular line." } 13791f0f5b5bSZachary Turner // clang-format on 13801f0f5b5bSZachary Turner }; 13811f0f5b5bSZachary Turner 13825a988416SJim Ingham #pragma mark Clear 13835a988416SJim Ingham 1384b9c1b51eSKate Stone class CommandObjectBreakpointClear : public CommandObjectParsed { 13855a988416SJim Ingham public: 1386b9c1b51eSKate Stone typedef enum BreakpointClearType { 13875a988416SJim Ingham eClearTypeInvalid, 13885a988416SJim Ingham eClearTypeFileAndLine 13895a988416SJim Ingham } BreakpointClearType; 13905a988416SJim Ingham 13917428a18cSKate Stone CommandObjectBreakpointClear(CommandInterpreter &interpreter) 13927428a18cSKate Stone : CommandObjectParsed(interpreter, "breakpoint clear", 1393b9c1b51eSKate Stone "Delete or disable breakpoints matching the " 1394b9c1b51eSKate Stone "specified source file and line.", 13955a988416SJim Ingham "breakpoint clear <cmd-options>"), 1396b9c1b51eSKate Stone m_options() {} 13975a988416SJim Ingham 13989e85e5a8SEugene Zelenko ~CommandObjectBreakpointClear() override = default; 13995a988416SJim Ingham 1400b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 14015a988416SJim Ingham 1402b9c1b51eSKate Stone class CommandOptions : public Options { 14035a988416SJim Ingham public: 1404b9c1b51eSKate Stone CommandOptions() : Options(), m_filename(), m_line_num(0) {} 14055a988416SJim Ingham 14069e85e5a8SEugene Zelenko ~CommandOptions() override = default; 14075a988416SJim Ingham 140897206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1409b9c1b51eSKate Stone ExecutionContext *execution_context) override { 141097206d57SZachary Turner Status error; 14113bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 14125a988416SJim Ingham 1413b9c1b51eSKate Stone switch (short_option) { 14145a988416SJim Ingham case 'f': 14155a988416SJim Ingham m_filename.assign(option_arg); 14165a988416SJim Ingham break; 14175a988416SJim Ingham 14185a988416SJim Ingham case 'l': 1419fe11483bSZachary Turner option_arg.getAsInteger(0, m_line_num); 14205a988416SJim Ingham break; 14215a988416SJim Ingham 14225a988416SJim Ingham default: 1423b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1424b9c1b51eSKate Stone short_option); 14255a988416SJim Ingham break; 14265a988416SJim Ingham } 14275a988416SJim Ingham 14285a988416SJim Ingham return error; 14295a988416SJim Ingham } 14305a988416SJim Ingham 1431b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 14325a988416SJim Ingham m_filename.clear(); 14335a988416SJim Ingham m_line_num = 0; 14345a988416SJim Ingham } 14355a988416SJim Ingham 14361f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 143770602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_clear_options); 14381f0f5b5bSZachary Turner } 14395a988416SJim Ingham 14405a988416SJim Ingham // Instance variables to hold the values for command options. 14415a988416SJim Ingham 14425a988416SJim Ingham std::string m_filename; 14435a988416SJim Ingham uint32_t m_line_num; 14445a988416SJim Ingham }; 14455a988416SJim Ingham 14465a988416SJim Ingham protected: 1447b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1448893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1449b9c1b51eSKate Stone if (target == nullptr) { 14505a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 14515a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 14525a988416SJim Ingham return false; 14535a988416SJim Ingham } 14545a988416SJim Ingham 14555a988416SJim Ingham // The following are the various types of breakpoints that could be cleared: 14565a988416SJim Ingham // 1). -f -l (clearing breakpoint by source location) 14575a988416SJim Ingham 14585a988416SJim Ingham BreakpointClearType break_type = eClearTypeInvalid; 14595a988416SJim Ingham 14605a988416SJim Ingham if (m_options.m_line_num != 0) 14615a988416SJim Ingham break_type = eClearTypeFileAndLine; 14625a988416SJim Ingham 1463bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1464bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 14655a988416SJim Ingham 14665a988416SJim Ingham BreakpointList &breakpoints = target->GetBreakpointList(); 14675a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 14685a988416SJim Ingham 14695a988416SJim Ingham // Early return if there's no breakpoint at all. 1470b9c1b51eSKate Stone if (num_breakpoints == 0) { 14715a988416SJim Ingham result.AppendError("Breakpoint clear: No breakpoint cleared."); 14725a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 14735a988416SJim Ingham return result.Succeeded(); 14745a988416SJim Ingham } 14755a988416SJim Ingham 14765a988416SJim Ingham // Find matching breakpoints and delete them. 14775a988416SJim Ingham 14785a988416SJim Ingham // First create a copy of all the IDs. 14795a988416SJim Ingham std::vector<break_id_t> BreakIDs; 14805a988416SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) 14819e85e5a8SEugene Zelenko BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID()); 14825a988416SJim Ingham 14835a988416SJim Ingham int num_cleared = 0; 14845a988416SJim Ingham StreamString ss; 1485b9c1b51eSKate Stone switch (break_type) { 14865a988416SJim Ingham case eClearTypeFileAndLine: // Breakpoint by source position 14875a988416SJim Ingham { 14885a988416SJim Ingham const ConstString filename(m_options.m_filename.c_str()); 14895a988416SJim Ingham BreakpointLocationCollection loc_coll; 14905a988416SJim Ingham 1491b9c1b51eSKate Stone for (size_t i = 0; i < num_breakpoints; ++i) { 14925a988416SJim Ingham Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); 14935a988416SJim Ingham 1494b9c1b51eSKate Stone if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) { 1495b9c1b51eSKate Stone // If the collection size is 0, it's a full match and we can just 1496b9c1b51eSKate Stone // remove the breakpoint. 1497b9c1b51eSKate Stone if (loc_coll.GetSize() == 0) { 14985a988416SJim Ingham bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); 14995a988416SJim Ingham ss.EOL(); 15005a988416SJim Ingham target->RemoveBreakpointByID(bp->GetID()); 15015a988416SJim Ingham ++num_cleared; 15025a988416SJim Ingham } 15035a988416SJim Ingham } 15045a988416SJim Ingham } 1505b9c1b51eSKate Stone } break; 15065a988416SJim Ingham 15075a988416SJim Ingham default: 15085a988416SJim Ingham break; 15095a988416SJim Ingham } 15105a988416SJim Ingham 1511b9c1b51eSKate Stone if (num_cleared > 0) { 15125a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 15135a988416SJim Ingham output_stream.Printf("%d breakpoints cleared:\n", num_cleared); 1514c156427dSZachary Turner output_stream << ss.GetString(); 15155a988416SJim Ingham output_stream.EOL(); 15165a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1517b9c1b51eSKate Stone } else { 15185a988416SJim Ingham result.AppendError("Breakpoint clear: No breakpoint cleared."); 15195a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 15205a988416SJim Ingham } 15215a988416SJim Ingham 15225a988416SJim Ingham return result.Succeeded(); 15235a988416SJim Ingham } 15245a988416SJim Ingham 15255a988416SJim Ingham private: 15265a988416SJim Ingham CommandOptions m_options; 15275a988416SJim Ingham }; 15285a988416SJim Ingham 15295a988416SJim Ingham //------------------------------------------------------------------------- 15305a988416SJim Ingham // CommandObjectBreakpointDelete 15315a988416SJim Ingham //------------------------------------------------------------------------- 15321f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_delete_options[] = { 15331f0f5b5bSZachary Turner // clang-format off 15341f0f5b5bSZachary Turner { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete all breakpoints without querying for confirmation." }, 15351f0f5b5bSZachary Turner { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets." }, 15361f0f5b5bSZachary Turner // clang-format on 15371f0f5b5bSZachary Turner }; 15381f0f5b5bSZachary Turner 15395a988416SJim Ingham #pragma mark Delete 15405a988416SJim Ingham 1541b9c1b51eSKate Stone class CommandObjectBreakpointDelete : public CommandObjectParsed { 15425a988416SJim Ingham public: 1543b9c1b51eSKate Stone CommandObjectBreakpointDelete(CommandInterpreter &interpreter) 1544b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "breakpoint delete", 1545b9c1b51eSKate Stone "Delete the specified breakpoint(s). If no " 1546b9c1b51eSKate Stone "breakpoints are specified, delete them all.", 15479e85e5a8SEugene Zelenko nullptr), 1548b9c1b51eSKate Stone m_options() { 15495a988416SJim Ingham CommandArgumentEntry arg; 1550b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1551b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1552b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1553b9c1b51eSKate Stone // arguments vector. 15545a988416SJim Ingham m_arguments.push_back(arg); 15555a988416SJim Ingham } 15565a988416SJim Ingham 15579e85e5a8SEugene Zelenko ~CommandObjectBreakpointDelete() override = default; 15585a988416SJim Ingham 1559b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 156033df7cd3SJim Ingham 1561b9c1b51eSKate Stone class CommandOptions : public Options { 156233df7cd3SJim Ingham public: 1563b9c1b51eSKate Stone CommandOptions() : Options(), m_use_dummy(false), m_force(false) {} 156433df7cd3SJim Ingham 15659e85e5a8SEugene Zelenko ~CommandOptions() override = default; 156633df7cd3SJim Ingham 156797206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1568b9c1b51eSKate Stone ExecutionContext *execution_context) override { 156997206d57SZachary Turner Status error; 157033df7cd3SJim Ingham const int short_option = m_getopt_table[option_idx].val; 157133df7cd3SJim Ingham 1572b9c1b51eSKate Stone switch (short_option) { 157333df7cd3SJim Ingham case 'f': 157433df7cd3SJim Ingham m_force = true; 157533df7cd3SJim Ingham break; 157633df7cd3SJim Ingham 157733df7cd3SJim Ingham case 'D': 157833df7cd3SJim Ingham m_use_dummy = true; 157933df7cd3SJim Ingham break; 158033df7cd3SJim Ingham 158133df7cd3SJim Ingham default: 1582b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1583b9c1b51eSKate Stone short_option); 158433df7cd3SJim Ingham break; 158533df7cd3SJim Ingham } 158633df7cd3SJim Ingham 158733df7cd3SJim Ingham return error; 158833df7cd3SJim Ingham } 158933df7cd3SJim Ingham 1590b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 159133df7cd3SJim Ingham m_use_dummy = false; 159233df7cd3SJim Ingham m_force = false; 159333df7cd3SJim Ingham } 159433df7cd3SJim Ingham 15951f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 159670602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_delete_options); 15971f0f5b5bSZachary Turner } 159833df7cd3SJim Ingham 159933df7cd3SJim Ingham // Instance variables to hold the values for command options. 160033df7cd3SJim Ingham bool m_use_dummy; 160133df7cd3SJim Ingham bool m_force; 160233df7cd3SJim Ingham }; 160333df7cd3SJim Ingham 16045a988416SJim Ingham protected: 1605b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 160633df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 160733df7cd3SJim Ingham 1608b9c1b51eSKate Stone if (target == nullptr) { 16095a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 16105a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 16115a988416SJim Ingham return false; 16125a988416SJim Ingham } 16135a988416SJim Ingham 1614bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1615bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 16165a988416SJim Ingham 16175a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 16185a988416SJim Ingham 16195a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 16205a988416SJim Ingham 1621b9c1b51eSKate Stone if (num_breakpoints == 0) { 16225a988416SJim Ingham result.AppendError("No breakpoints exist to be deleted."); 16235a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 16245a988416SJim Ingham return false; 16255a988416SJim Ingham } 16265a988416SJim Ingham 162711eb9c64SZachary Turner if (command.empty()) { 1628b9c1b51eSKate Stone if (!m_options.m_force && 1629b9c1b51eSKate Stone !m_interpreter.Confirm( 1630b9c1b51eSKate Stone "About to delete all breakpoints, do you want to do that?", 1631b9c1b51eSKate Stone true)) { 16325a988416SJim Ingham result.AppendMessage("Operation cancelled..."); 1633b9c1b51eSKate Stone } else { 1634b842f2ecSJim Ingham target->RemoveAllowedBreakpoints(); 1635b9c1b51eSKate Stone result.AppendMessageWithFormat( 1636b9c1b51eSKate Stone "All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", 1637b9c1b51eSKate Stone (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : ""); 16385a988416SJim Ingham } 16395a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1640b9c1b51eSKate Stone } else { 16415a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 16425a988416SJim Ingham BreakpointIDList valid_bp_ids; 1643b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1644b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1645b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::deletePerm); 16465a988416SJim Ingham 1647b9c1b51eSKate Stone if (result.Succeeded()) { 16485a988416SJim Ingham int delete_count = 0; 16495a988416SJim Ingham int disable_count = 0; 16505a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1651b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 16525a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 16535a988416SJim Ingham 1654b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1655b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1656b9c1b51eSKate Stone Breakpoint *breakpoint = 1657b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1658b9c1b51eSKate Stone BreakpointLocation *location = 1659b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1660b9c1b51eSKate Stone // It makes no sense to try to delete individual locations, so we 1661b9c1b51eSKate Stone // disable them instead. 1662b9c1b51eSKate Stone if (location) { 16635a988416SJim Ingham location->SetEnabled(false); 16645a988416SJim Ingham ++disable_count; 16655a988416SJim Ingham } 1666b9c1b51eSKate Stone } else { 16675a988416SJim Ingham target->RemoveBreakpointByID(cur_bp_id.GetBreakpointID()); 16685a988416SJim Ingham ++delete_count; 16695a988416SJim Ingham } 16705a988416SJim Ingham } 16715a988416SJim Ingham } 1672b9c1b51eSKate Stone result.AppendMessageWithFormat( 1673b9c1b51eSKate Stone "%d breakpoints deleted; %d breakpoint locations disabled.\n", 16745a988416SJim Ingham delete_count, disable_count); 16755a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 16765a988416SJim Ingham } 16775a988416SJim Ingham } 16785a988416SJim Ingham return result.Succeeded(); 16795a988416SJim Ingham } 16809e85e5a8SEugene Zelenko 168133df7cd3SJim Ingham private: 168233df7cd3SJim Ingham CommandOptions m_options; 168333df7cd3SJim Ingham }; 168433df7cd3SJim Ingham 168530fdc8d8SChris Lattner //------------------------------------------------------------------------- 16865e09c8c3SJim Ingham // CommandObjectBreakpointName 16875e09c8c3SJim Ingham //------------------------------------------------------------------------- 16885e09c8c3SJim Ingham 16897428a18cSKate Stone static OptionDefinition g_breakpoint_name_options[] = { 1690ac9c3a62SKate Stone // clang-format off 1691ac9c3a62SKate Stone {LLDB_OPT_SET_1, false, "name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."}, 1692ac9c3a62SKate Stone {LLDB_OPT_SET_2, false, "breakpoint-id", 'B', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointID, "Specify a breakpoint ID to use."}, 1693b842f2ecSJim Ingham {LLDB_OPT_SET_3, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Operate on Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, 1694e9632ebaSJim Ingham {LLDB_OPT_SET_4, false, "help-string", 'H', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNone, "A help string describing the purpose of this name."}, 1695ac9c3a62SKate Stone // clang-format on 16965e09c8c3SJim Ingham }; 1697b9c1b51eSKate Stone class BreakpointNameOptionGroup : public OptionGroup { 16985e09c8c3SJim Ingham public: 1699b9c1b51eSKate Stone BreakpointNameOptionGroup() 1700b9c1b51eSKate Stone : OptionGroup(), m_breakpoint(LLDB_INVALID_BREAK_ID), m_use_dummy(false) { 17015e09c8c3SJim Ingham } 17025e09c8c3SJim Ingham 17039e85e5a8SEugene Zelenko ~BreakpointNameOptionGroup() override = default; 17045e09c8c3SJim Ingham 17051f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 170670602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_name_options); 17075e09c8c3SJim Ingham } 17085e09c8c3SJim Ingham 170997206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1710b9c1b51eSKate Stone ExecutionContext *execution_context) override { 171197206d57SZachary Turner Status error; 17125e09c8c3SJim Ingham const int short_option = g_breakpoint_name_options[option_idx].short_option; 17135e09c8c3SJim Ingham 1714b9c1b51eSKate Stone switch (short_option) { 17155e09c8c3SJim Ingham case 'N': 1716fe11483bSZachary Turner if (BreakpointID::StringIsBreakpointName(option_arg, error) && 1717b9c1b51eSKate Stone error.Success()) 1718fe11483bSZachary Turner m_name.SetValueFromString(option_arg); 17195e09c8c3SJim Ingham break; 17205e09c8c3SJim Ingham case 'B': 1721fe11483bSZachary Turner if (m_breakpoint.SetValueFromString(option_arg).Fail()) 1722b9c1b51eSKate Stone error.SetErrorStringWithFormat( 17238cef4b0bSZachary Turner "unrecognized value \"%s\" for breakpoint", 1724fe11483bSZachary Turner option_arg.str().c_str()); 17255e09c8c3SJim Ingham break; 17265e09c8c3SJim Ingham case 'D': 1727fe11483bSZachary Turner if (m_use_dummy.SetValueFromString(option_arg).Fail()) 1728b9c1b51eSKate Stone error.SetErrorStringWithFormat( 17298cef4b0bSZachary Turner "unrecognized value \"%s\" for use-dummy", 1730fe11483bSZachary Turner option_arg.str().c_str()); 17315e09c8c3SJim Ingham break; 1732e9632ebaSJim Ingham case 'H': 1733e9632ebaSJim Ingham m_help_string.SetValueFromString(option_arg); 1734e9632ebaSJim Ingham break; 17355e09c8c3SJim Ingham 17365e09c8c3SJim Ingham default: 1737b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized short option '%c'", 1738b9c1b51eSKate Stone short_option); 17395e09c8c3SJim Ingham break; 17405e09c8c3SJim Ingham } 17415e09c8c3SJim Ingham return error; 17425e09c8c3SJim Ingham } 17435e09c8c3SJim Ingham 1744b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 17455e09c8c3SJim Ingham m_name.Clear(); 17465e09c8c3SJim Ingham m_breakpoint.Clear(); 17475e09c8c3SJim Ingham m_use_dummy.Clear(); 17485e09c8c3SJim Ingham m_use_dummy.SetDefaultValue(false); 1749e9632ebaSJim Ingham m_help_string.Clear(); 17505e09c8c3SJim Ingham } 17515e09c8c3SJim Ingham 17525e09c8c3SJim Ingham OptionValueString m_name; 17535e09c8c3SJim Ingham OptionValueUInt64 m_breakpoint; 17545e09c8c3SJim Ingham OptionValueBoolean m_use_dummy; 1755e9632ebaSJim Ingham OptionValueString m_help_string; 17565e09c8c3SJim Ingham }; 17575e09c8c3SJim Ingham 1758b842f2ecSJim Ingham static OptionDefinition g_breakpoint_access_options[] = { 1759b842f2ecSJim Ingham // clang-format off 1760b842f2ecSJim Ingham {LLDB_OPT_SET_1, false, "allow-list", 'L', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Determines whether the breakpoint will show up in break list if not referred to explicitly."}, 1761b842f2ecSJim Ingham {LLDB_OPT_SET_2, false, "allow-disable", 'A', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Determines whether the breakpoint can be disabled by name or when all breakpoints are disabled."}, 1762b842f2ecSJim Ingham {LLDB_OPT_SET_3, false, "allow-delete", 'D', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Determines whether the breakpoint can be deleted by name or when all breakpoints are deleted."}, 1763b842f2ecSJim Ingham // clang-format on 1764b842f2ecSJim Ingham }; 1765b842f2ecSJim Ingham 1766b842f2ecSJim Ingham class BreakpointAccessOptionGroup : public OptionGroup 1767b842f2ecSJim Ingham { 1768b842f2ecSJim Ingham public: 1769b842f2ecSJim Ingham BreakpointAccessOptionGroup() : 1770b842f2ecSJim Ingham OptionGroup() 1771b842f2ecSJim Ingham {} 1772b842f2ecSJim Ingham 1773b842f2ecSJim Ingham ~BreakpointAccessOptionGroup() override = default; 1774b842f2ecSJim Ingham 1775b842f2ecSJim Ingham llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 1776b842f2ecSJim Ingham return llvm::makeArrayRef(g_breakpoint_access_options); 1777b842f2ecSJim Ingham } 1778b842f2ecSJim Ingham Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1779b842f2ecSJim Ingham ExecutionContext *execution_context) override { 1780b842f2ecSJim Ingham Status error; 1781b842f2ecSJim Ingham const int short_option 1782b842f2ecSJim Ingham = g_breakpoint_access_options[option_idx].short_option; 1783b842f2ecSJim Ingham 1784b842f2ecSJim Ingham switch (short_option) { 1785b842f2ecSJim Ingham case 'L': { 1786b842f2ecSJim Ingham bool value, success; 1787*47cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1788b842f2ecSJim Ingham if (success) { 1789b842f2ecSJim Ingham m_permissions.SetAllowList(value); 1790b842f2ecSJim Ingham } else 1791b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1792b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1793b842f2ecSJim Ingham option_arg.str().c_str()); 1794b842f2ecSJim Ingham } break; 1795b842f2ecSJim Ingham case 'A': { 1796b842f2ecSJim Ingham bool value, success; 1797*47cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1798b842f2ecSJim Ingham if (success) { 1799b842f2ecSJim Ingham m_permissions.SetAllowDisable(value); 1800b842f2ecSJim Ingham } else 1801b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1802b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1803b842f2ecSJim Ingham option_arg.str().c_str()); 1804b842f2ecSJim Ingham } break; 1805b842f2ecSJim Ingham case 'D': { 1806b842f2ecSJim Ingham bool value, success; 1807*47cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1808b842f2ecSJim Ingham if (success) { 1809b842f2ecSJim Ingham m_permissions.SetAllowDelete(value); 1810b842f2ecSJim Ingham } else 1811b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1812b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1813b842f2ecSJim Ingham option_arg.str().c_str()); 1814b842f2ecSJim Ingham } break; 1815b842f2ecSJim Ingham 1816b842f2ecSJim Ingham } 1817b842f2ecSJim Ingham 1818b842f2ecSJim Ingham return error; 1819b842f2ecSJim Ingham } 1820b842f2ecSJim Ingham 1821b842f2ecSJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 1822b842f2ecSJim Ingham } 1823b842f2ecSJim Ingham 1824b842f2ecSJim Ingham const BreakpointName::Permissions &GetPermissions() const 1825b842f2ecSJim Ingham { 1826b842f2ecSJim Ingham return m_permissions; 1827b842f2ecSJim Ingham } 1828b842f2ecSJim Ingham BreakpointName::Permissions m_permissions; 1829b842f2ecSJim Ingham }; 1830b842f2ecSJim Ingham 1831b842f2ecSJim Ingham class CommandObjectBreakpointNameConfigure : public CommandObjectParsed { 1832b842f2ecSJim Ingham public: 1833b842f2ecSJim Ingham CommandObjectBreakpointNameConfigure(CommandInterpreter &interpreter) 1834b842f2ecSJim Ingham : CommandObjectParsed( 1835b842f2ecSJim Ingham interpreter, "configure", "Configure the options for the breakpoint" 1836b842f2ecSJim Ingham " name provided. " 1837b842f2ecSJim Ingham "If you provide a breakpoint id, the options will be copied from " 1838b842f2ecSJim Ingham "the breakpoint, otherwise only the options specified will be set " 1839b842f2ecSJim Ingham "on the name.", 1840b842f2ecSJim Ingham "breakpoint name configure <command-options> " 1841b842f2ecSJim Ingham "<breakpoint-name-list>"), 1842b842f2ecSJim Ingham m_bp_opts(), m_option_group() { 1843b842f2ecSJim Ingham // Create the first variant for the first (and only) argument for this 1844b842f2ecSJim Ingham // command. 1845b842f2ecSJim Ingham CommandArgumentEntry arg1; 1846b842f2ecSJim Ingham CommandArgumentData id_arg; 1847b842f2ecSJim Ingham id_arg.arg_type = eArgTypeBreakpointName; 1848b842f2ecSJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 1849b842f2ecSJim Ingham arg1.push_back(id_arg); 1850b842f2ecSJim Ingham m_arguments.push_back(arg1); 1851b842f2ecSJim Ingham 1852b842f2ecSJim Ingham m_option_group.Append(&m_bp_opts, 1853b842f2ecSJim Ingham LLDB_OPT_SET_ALL, 1854b842f2ecSJim Ingham LLDB_OPT_SET_1); 1855b842f2ecSJim Ingham m_option_group.Append(&m_access_options, 1856b842f2ecSJim Ingham LLDB_OPT_SET_ALL, 1857b842f2ecSJim Ingham LLDB_OPT_SET_ALL); 1858e9632ebaSJim Ingham m_option_group.Append(&m_bp_id, 1859e9632ebaSJim Ingham LLDB_OPT_SET_2|LLDB_OPT_SET_4, 1860e9632ebaSJim Ingham LLDB_OPT_SET_ALL); 1861b842f2ecSJim Ingham m_option_group.Finalize(); 1862b842f2ecSJim Ingham } 1863b842f2ecSJim Ingham 1864b842f2ecSJim Ingham ~CommandObjectBreakpointNameConfigure() override = default; 1865b842f2ecSJim Ingham 1866b842f2ecSJim Ingham Options *GetOptions() override { return &m_option_group; } 1867b842f2ecSJim Ingham 1868b842f2ecSJim Ingham protected: 1869b842f2ecSJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 1870b842f2ecSJim Ingham 1871b842f2ecSJim Ingham const size_t argc = command.GetArgumentCount(); 1872b842f2ecSJim Ingham if (argc == 0) { 1873b842f2ecSJim Ingham result.AppendError("No names provided."); 1874b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1875b842f2ecSJim Ingham return false; 1876b842f2ecSJim Ingham } 1877b842f2ecSJim Ingham 1878b842f2ecSJim Ingham Target *target = 1879b842f2ecSJim Ingham GetSelectedOrDummyTarget(false); 1880b842f2ecSJim Ingham 1881b842f2ecSJim Ingham if (target == nullptr) { 1882b842f2ecSJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 1883b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1884b842f2ecSJim Ingham return false; 1885b842f2ecSJim Ingham } 1886b842f2ecSJim Ingham 1887b842f2ecSJim Ingham std::unique_lock<std::recursive_mutex> lock; 1888b842f2ecSJim Ingham target->GetBreakpointList().GetListMutex(lock); 1889b842f2ecSJim Ingham 1890b842f2ecSJim Ingham // Make a pass through first to see that all the names are legal. 1891b842f2ecSJim Ingham for (auto &entry : command.entries()) { 1892b842f2ecSJim Ingham Status error; 1893b842f2ecSJim Ingham if (!BreakpointID::StringIsBreakpointName(entry.ref, error)) 1894b842f2ecSJim Ingham { 1895b842f2ecSJim Ingham result.AppendErrorWithFormat("Invalid breakpoint name: %s - %s", 1896b842f2ecSJim Ingham entry.c_str(), error.AsCString()); 1897b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1898b842f2ecSJim Ingham return false; 1899b842f2ecSJim Ingham } 1900b842f2ecSJim Ingham } 1901b842f2ecSJim Ingham // Now configure them, we already pre-checked the names so we don't need 1902b842f2ecSJim Ingham // to check the error: 1903b842f2ecSJim Ingham BreakpointSP bp_sp; 1904b842f2ecSJim Ingham if (m_bp_id.m_breakpoint.OptionWasSet()) 1905b842f2ecSJim Ingham { 1906b842f2ecSJim Ingham lldb::break_id_t bp_id = m_bp_id.m_breakpoint.GetUInt64Value(); 1907b842f2ecSJim Ingham bp_sp = target->GetBreakpointByID(bp_id); 1908b842f2ecSJim Ingham if (!bp_sp) 1909b842f2ecSJim Ingham { 1910b842f2ecSJim Ingham result.AppendErrorWithFormatv("Could not find specified breakpoint {0}", 1911b842f2ecSJim Ingham bp_id); 1912b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1913b842f2ecSJim Ingham return false; 1914b842f2ecSJim Ingham } 1915b842f2ecSJim Ingham } 1916b842f2ecSJim Ingham 1917b842f2ecSJim Ingham Status error; 1918b842f2ecSJim Ingham for (auto &entry : command.entries()) { 1919b842f2ecSJim Ingham ConstString name(entry.c_str()); 1920b842f2ecSJim Ingham BreakpointName *bp_name = target->FindBreakpointName(name, true, error); 1921b842f2ecSJim Ingham if (!bp_name) 1922b842f2ecSJim Ingham continue; 1923e9632ebaSJim Ingham if (m_bp_id.m_help_string.OptionWasSet()) 1924e9632ebaSJim Ingham bp_name->SetHelp(m_bp_id.m_help_string.GetStringValue().str().c_str()); 1925e9632ebaSJim Ingham 1926b842f2ecSJim Ingham if (bp_sp) 1927b842f2ecSJim Ingham target->ConfigureBreakpointName(*bp_name, 1928b842f2ecSJim Ingham *bp_sp->GetOptions(), 1929b842f2ecSJim Ingham m_access_options.GetPermissions()); 1930b842f2ecSJim Ingham else 1931b842f2ecSJim Ingham target->ConfigureBreakpointName(*bp_name, 1932b842f2ecSJim Ingham m_bp_opts.GetBreakpointOptions(), 1933b842f2ecSJim Ingham m_access_options.GetPermissions()); 1934b842f2ecSJim Ingham } 1935b842f2ecSJim Ingham return true; 1936b842f2ecSJim Ingham } 1937b842f2ecSJim Ingham 1938b842f2ecSJim Ingham private: 1939b842f2ecSJim Ingham BreakpointNameOptionGroup m_bp_id; // Only using the id part of this. 1940b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 1941b842f2ecSJim Ingham BreakpointAccessOptionGroup m_access_options; 1942b842f2ecSJim Ingham OptionGroupOptions m_option_group; 1943b842f2ecSJim Ingham }; 1944b842f2ecSJim Ingham 1945b9c1b51eSKate Stone class CommandObjectBreakpointNameAdd : public CommandObjectParsed { 19465e09c8c3SJim Ingham public: 1947b9c1b51eSKate Stone CommandObjectBreakpointNameAdd(CommandInterpreter &interpreter) 1948b9c1b51eSKate Stone : CommandObjectParsed( 1949b9c1b51eSKate Stone interpreter, "add", "Add a name to the breakpoints provided.", 19505e09c8c3SJim Ingham "breakpoint name add <command-options> <breakpoint-id-list>"), 1951b9c1b51eSKate Stone m_name_options(), m_option_group() { 1952b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 1953b9c1b51eSKate Stone // command. 19545e09c8c3SJim Ingham CommandArgumentEntry arg1; 19555e09c8c3SJim Ingham CommandArgumentData id_arg; 19565e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 19575e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 19585e09c8c3SJim Ingham arg1.push_back(id_arg); 19595e09c8c3SJim Ingham m_arguments.push_back(arg1); 19605e09c8c3SJim Ingham 19615e09c8c3SJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 19625e09c8c3SJim Ingham m_option_group.Finalize(); 19635e09c8c3SJim Ingham } 19645e09c8c3SJim Ingham 19659e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameAdd() override = default; 19665e09c8c3SJim Ingham 1967b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 19685e09c8c3SJim Ingham 19695e09c8c3SJim Ingham protected: 1970b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1971b9c1b51eSKate Stone if (!m_name_options.m_name.OptionWasSet()) { 19725e09c8c3SJim Ingham result.SetError("No name option provided."); 19735e09c8c3SJim Ingham return false; 19745e09c8c3SJim Ingham } 19755e09c8c3SJim Ingham 1976b9c1b51eSKate Stone Target *target = 1977b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 19785e09c8c3SJim Ingham 1979b9c1b51eSKate Stone if (target == nullptr) { 19805e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 19815e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 19825e09c8c3SJim Ingham return false; 19835e09c8c3SJim Ingham } 19845e09c8c3SJim Ingham 1985bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1986bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 19875e09c8c3SJim Ingham 19885e09c8c3SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 19895e09c8c3SJim Ingham 19905e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 1991b9c1b51eSKate Stone if (num_breakpoints == 0) { 19925e09c8c3SJim Ingham result.SetError("No breakpoints, cannot add names."); 19935e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 19945e09c8c3SJim Ingham return false; 19955e09c8c3SJim Ingham } 19965e09c8c3SJim Ingham 19975e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 19985e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 1999b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 2000b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 2001b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 20025e09c8c3SJim Ingham 2003b9c1b51eSKate Stone if (result.Succeeded()) { 2004b9c1b51eSKate Stone if (valid_bp_ids.GetSize() == 0) { 20055e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot add names."); 20065e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20075e09c8c3SJim Ingham return false; 20085e09c8c3SJim Ingham } 20095e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 2010b842f2ecSJim Ingham const char *bp_name = m_name_options.m_name.GetCurrentValue(); 2011b842f2ecSJim Ingham Status error; // This error reports illegal names, but we've already 2012b842f2ecSJim Ingham // checked that, so we don't need to check it again here. 2013b9c1b51eSKate Stone for (size_t index = 0; index < num_valid_ids; index++) { 2014b9c1b51eSKate Stone lldb::break_id_t bp_id = 2015b9c1b51eSKate Stone valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 20165e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 2017b842f2ecSJim Ingham target->AddNameToBreakpoint(bp_sp, bp_name, error); 20185e09c8c3SJim Ingham } 20195e09c8c3SJim Ingham } 20205e09c8c3SJim Ingham 20215e09c8c3SJim Ingham return true; 20225e09c8c3SJim Ingham } 20235e09c8c3SJim Ingham 20245e09c8c3SJim Ingham private: 20255e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 20265e09c8c3SJim Ingham OptionGroupOptions m_option_group; 20275e09c8c3SJim Ingham }; 20285e09c8c3SJim Ingham 2029b9c1b51eSKate Stone class CommandObjectBreakpointNameDelete : public CommandObjectParsed { 20305e09c8c3SJim Ingham public: 2031b9c1b51eSKate Stone CommandObjectBreakpointNameDelete(CommandInterpreter &interpreter) 2032b9c1b51eSKate Stone : CommandObjectParsed( 2033b9c1b51eSKate Stone interpreter, "delete", 20345e09c8c3SJim Ingham "Delete a name from the breakpoints provided.", 20355e09c8c3SJim Ingham "breakpoint name delete <command-options> <breakpoint-id-list>"), 2036b9c1b51eSKate Stone m_name_options(), m_option_group() { 2037b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 2038b9c1b51eSKate Stone // command. 20395e09c8c3SJim Ingham CommandArgumentEntry arg1; 20405e09c8c3SJim Ingham CommandArgumentData id_arg; 20415e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 20425e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 20435e09c8c3SJim Ingham arg1.push_back(id_arg); 20445e09c8c3SJim Ingham m_arguments.push_back(arg1); 20455e09c8c3SJim Ingham 20465e09c8c3SJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 20475e09c8c3SJim Ingham m_option_group.Finalize(); 20485e09c8c3SJim Ingham } 20495e09c8c3SJim Ingham 20509e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameDelete() override = default; 20515e09c8c3SJim Ingham 2052b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 20535e09c8c3SJim Ingham 20545e09c8c3SJim Ingham protected: 2055b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 2056b9c1b51eSKate Stone if (!m_name_options.m_name.OptionWasSet()) { 20575e09c8c3SJim Ingham result.SetError("No name option provided."); 20585e09c8c3SJim Ingham return false; 20595e09c8c3SJim Ingham } 20605e09c8c3SJim Ingham 2061b9c1b51eSKate Stone Target *target = 2062b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 20635e09c8c3SJim Ingham 2064b9c1b51eSKate Stone if (target == nullptr) { 20655e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 20665e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20675e09c8c3SJim Ingham return false; 20685e09c8c3SJim Ingham } 20695e09c8c3SJim Ingham 2070bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 2071bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 20725e09c8c3SJim Ingham 20735e09c8c3SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 20745e09c8c3SJim Ingham 20755e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 2076b9c1b51eSKate Stone if (num_breakpoints == 0) { 20775e09c8c3SJim Ingham result.SetError("No breakpoints, cannot delete names."); 20785e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20795e09c8c3SJim Ingham return false; 20805e09c8c3SJim Ingham } 20815e09c8c3SJim Ingham 20825e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 20835e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 2084b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 2085b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 2086b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::deletePerm); 20875e09c8c3SJim Ingham 2088b9c1b51eSKate Stone if (result.Succeeded()) { 2089b9c1b51eSKate Stone if (valid_bp_ids.GetSize() == 0) { 20905e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot delete names."); 20915e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20925e09c8c3SJim Ingham return false; 20935e09c8c3SJim Ingham } 2094b842f2ecSJim Ingham ConstString bp_name(m_name_options.m_name.GetCurrentValue()); 20955e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 2096b9c1b51eSKate Stone for (size_t index = 0; index < num_valid_ids; index++) { 2097b9c1b51eSKate Stone lldb::break_id_t bp_id = 2098b9c1b51eSKate Stone valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 20995e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 2100b842f2ecSJim Ingham target->RemoveNameFromBreakpoint(bp_sp, bp_name); 21015e09c8c3SJim Ingham } 21025e09c8c3SJim Ingham } 21035e09c8c3SJim Ingham 21045e09c8c3SJim Ingham return true; 21055e09c8c3SJim Ingham } 21065e09c8c3SJim Ingham 21075e09c8c3SJim Ingham private: 21085e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 21095e09c8c3SJim Ingham OptionGroupOptions m_option_group; 21105e09c8c3SJim Ingham }; 21115e09c8c3SJim Ingham 2112b9c1b51eSKate Stone class CommandObjectBreakpointNameList : public CommandObjectParsed { 21135e09c8c3SJim Ingham public: 2114b9c1b51eSKate Stone CommandObjectBreakpointNameList(CommandInterpreter &interpreter) 2115b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "list", 2116b842f2ecSJim Ingham "List either the names for a breakpoint or info " 2117b842f2ecSJim Ingham "about a given name. With no arguments, lists all " 2118b842f2ecSJim Ingham "names", 21195e09c8c3SJim Ingham "breakpoint name list <command-options>"), 2120b9c1b51eSKate Stone m_name_options(), m_option_group() { 2121b842f2ecSJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_3, LLDB_OPT_SET_ALL); 21225e09c8c3SJim Ingham m_option_group.Finalize(); 21235e09c8c3SJim Ingham } 21245e09c8c3SJim Ingham 21259e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameList() override = default; 21265e09c8c3SJim Ingham 2127b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 21285e09c8c3SJim Ingham 21295e09c8c3SJim Ingham protected: 2130b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 2131b9c1b51eSKate Stone Target *target = 2132b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 21335e09c8c3SJim Ingham 2134b9c1b51eSKate Stone if (target == nullptr) { 21355e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 21365e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 21375e09c8c3SJim Ingham return false; 21385e09c8c3SJim Ingham } 21395e09c8c3SJim Ingham 2140b842f2ecSJim Ingham 2141b842f2ecSJim Ingham std::vector<std::string> name_list; 2142b842f2ecSJim Ingham if (command.empty()) { 2143b842f2ecSJim Ingham target->GetBreakpointNames(name_list); 2144b842f2ecSJim Ingham } else { 2145b842f2ecSJim Ingham for (const Args::ArgEntry &arg : command) 2146b842f2ecSJim Ingham { 2147b842f2ecSJim Ingham name_list.push_back(arg.c_str()); 2148b842f2ecSJim Ingham } 2149b842f2ecSJim Ingham } 2150b842f2ecSJim Ingham 2151b842f2ecSJim Ingham if (name_list.empty()) { 2152b842f2ecSJim Ingham result.AppendMessage("No breakpoint names found."); 2153b842f2ecSJim Ingham } else { 2154b842f2ecSJim Ingham for (const std::string &name_str : name_list) { 2155b842f2ecSJim Ingham const char *name = name_str.c_str(); 2156b842f2ecSJim Ingham // First print out the options for the name: 2157b842f2ecSJim Ingham Status error; 2158b842f2ecSJim Ingham BreakpointName *bp_name = target->FindBreakpointName(ConstString(name), 2159b842f2ecSJim Ingham false, 2160b842f2ecSJim Ingham error); 2161b842f2ecSJim Ingham if (bp_name) 2162b842f2ecSJim Ingham { 2163b842f2ecSJim Ingham StreamString s; 2164b842f2ecSJim Ingham result.AppendMessageWithFormat("Name: %s\n", name); 2165b842f2ecSJim Ingham if (bp_name->GetDescription(&s, eDescriptionLevelFull)) 2166b842f2ecSJim Ingham { 2167b842f2ecSJim Ingham result.AppendMessage(s.GetString()); 2168b842f2ecSJim Ingham } 2169b842f2ecSJim Ingham 2170bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 2171bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 21725e09c8c3SJim Ingham 21735e09c8c3SJim Ingham BreakpointList &breakpoints = target->GetBreakpointList(); 2174b842f2ecSJim Ingham bool any_set = false; 2175b9c1b51eSKate Stone for (BreakpointSP bp_sp : breakpoints.Breakpoints()) { 2176b9c1b51eSKate Stone if (bp_sp->MatchesName(name)) { 21775e09c8c3SJim Ingham StreamString s; 2178b842f2ecSJim Ingham any_set = true; 21795e09c8c3SJim Ingham bp_sp->GetDescription(&s, eDescriptionLevelBrief); 21805e09c8c3SJim Ingham s.EOL(); 2181c156427dSZachary Turner result.AppendMessage(s.GetString()); 21825e09c8c3SJim Ingham } 21835e09c8c3SJim Ingham } 2184b842f2ecSJim Ingham if (!any_set) 2185b842f2ecSJim Ingham result.AppendMessage("No breakpoints using this name."); 2186b9c1b51eSKate Stone } else { 2187b842f2ecSJim Ingham result.AppendMessageWithFormat("Name: %s not found.\n", name); 21885e09c8c3SJim Ingham } 2189b842f2ecSJim Ingham } 21905e09c8c3SJim Ingham } 21915e09c8c3SJim Ingham return true; 21925e09c8c3SJim Ingham } 21935e09c8c3SJim Ingham 21945e09c8c3SJim Ingham private: 21955e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 21965e09c8c3SJim Ingham OptionGroupOptions m_option_group; 21975e09c8c3SJim Ingham }; 21985e09c8c3SJim Ingham 21995e09c8c3SJim Ingham //------------------------------------------------------------------------- 2200e14dc268SJim Ingham // CommandObjectBreakpointName 22015e09c8c3SJim Ingham //------------------------------------------------------------------------- 2202b9c1b51eSKate Stone class CommandObjectBreakpointName : public CommandObjectMultiword { 22035e09c8c3SJim Ingham public: 22047428a18cSKate Stone CommandObjectBreakpointName(CommandInterpreter &interpreter) 2205b9c1b51eSKate Stone : CommandObjectMultiword( 2206b9c1b51eSKate Stone interpreter, "name", "Commands to manage name tags for breakpoints", 2207b9c1b51eSKate Stone "breakpoint name <subcommand> [<command-options>]") { 2208b9c1b51eSKate Stone CommandObjectSP add_command_object( 2209b9c1b51eSKate Stone new CommandObjectBreakpointNameAdd(interpreter)); 2210b9c1b51eSKate Stone CommandObjectSP delete_command_object( 2211b9c1b51eSKate Stone new CommandObjectBreakpointNameDelete(interpreter)); 2212b9c1b51eSKate Stone CommandObjectSP list_command_object( 2213b9c1b51eSKate Stone new CommandObjectBreakpointNameList(interpreter)); 2214b842f2ecSJim Ingham CommandObjectSP configure_command_object( 2215b842f2ecSJim Ingham new CommandObjectBreakpointNameConfigure(interpreter)); 22165e09c8c3SJim Ingham 22175e09c8c3SJim Ingham LoadSubCommand("add", add_command_object); 22185e09c8c3SJim Ingham LoadSubCommand("delete", delete_command_object); 22195e09c8c3SJim Ingham LoadSubCommand("list", list_command_object); 2220b842f2ecSJim Ingham LoadSubCommand("configure", configure_command_object); 22215e09c8c3SJim Ingham } 22225e09c8c3SJim Ingham 22239e85e5a8SEugene Zelenko ~CommandObjectBreakpointName() override = default; 22245e09c8c3SJim Ingham }; 22255e09c8c3SJim Ingham 22265e09c8c3SJim Ingham //------------------------------------------------------------------------- 2227e14dc268SJim Ingham // CommandObjectBreakpointRead 2228e14dc268SJim Ingham //------------------------------------------------------------------------- 22293acdf385SJim Ingham #pragma mark Read::CommandOptions 22301f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_read_options[] = { 22311f0f5b5bSZachary Turner // clang-format off 22321f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename, "The file from which to read the breakpoints." }, 22333acdf385SJim Ingham {LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Only read in breakpoints with this name."}, 22341f0f5b5bSZachary Turner // clang-format on 22351f0f5b5bSZachary Turner }; 22361f0f5b5bSZachary Turner 22371f0f5b5bSZachary Turner #pragma mark Read 2238e14dc268SJim Ingham 2239e14dc268SJim Ingham class CommandObjectBreakpointRead : public CommandObjectParsed { 2240e14dc268SJim Ingham public: 2241e14dc268SJim Ingham CommandObjectBreakpointRead(CommandInterpreter &interpreter) 2242e14dc268SJim Ingham : CommandObjectParsed(interpreter, "breakpoint read", 2243e14dc268SJim Ingham "Read and set the breakpoints previously saved to " 2244e14dc268SJim Ingham "a file with \"breakpoint write\". ", 2245e14dc268SJim Ingham nullptr), 2246e14dc268SJim Ingham m_options() { 2247e14dc268SJim Ingham CommandArgumentEntry arg; 2248e14dc268SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 2249e14dc268SJim Ingham eArgTypeBreakpointIDRange); 2250e14dc268SJim Ingham // Add the entry for the first argument for this command to the object's 2251e14dc268SJim Ingham // arguments vector. 2252e14dc268SJim Ingham m_arguments.push_back(arg); 2253e14dc268SJim Ingham } 2254e14dc268SJim Ingham 2255e14dc268SJim Ingham ~CommandObjectBreakpointRead() override = default; 2256e14dc268SJim Ingham 2257e14dc268SJim Ingham Options *GetOptions() override { return &m_options; } 2258e14dc268SJim Ingham 2259e14dc268SJim Ingham class CommandOptions : public Options { 2260e14dc268SJim Ingham public: 2261e14dc268SJim Ingham CommandOptions() : Options() {} 2262e14dc268SJim Ingham 2263e14dc268SJim Ingham ~CommandOptions() override = default; 2264e14dc268SJim Ingham 226597206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 2266e14dc268SJim Ingham ExecutionContext *execution_context) override { 226797206d57SZachary Turner Status error; 2268e14dc268SJim Ingham const int short_option = m_getopt_table[option_idx].val; 2269e14dc268SJim Ingham 2270e14dc268SJim Ingham switch (short_option) { 2271e14dc268SJim Ingham case 'f': 2272e14dc268SJim Ingham m_filename.assign(option_arg); 2273e14dc268SJim Ingham break; 22743acdf385SJim Ingham case 'N': { 227597206d57SZachary Turner Status name_error; 22763acdf385SJim Ingham if (!BreakpointID::StringIsBreakpointName(llvm::StringRef(option_arg), 22773acdf385SJim Ingham name_error)) { 22783acdf385SJim Ingham error.SetErrorStringWithFormat("Invalid breakpoint name: %s", 22793acdf385SJim Ingham name_error.AsCString()); 22803acdf385SJim Ingham } 22813acdf385SJim Ingham m_names.push_back(option_arg); 22823acdf385SJim Ingham break; 22833acdf385SJim Ingham } 2284e14dc268SJim Ingham default: 2285e14dc268SJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 2286e14dc268SJim Ingham short_option); 2287e14dc268SJim Ingham break; 2288e14dc268SJim Ingham } 2289e14dc268SJim Ingham 2290e14dc268SJim Ingham return error; 2291e14dc268SJim Ingham } 2292e14dc268SJim Ingham 2293e14dc268SJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 2294e14dc268SJim Ingham m_filename.clear(); 22953acdf385SJim Ingham m_names.clear(); 2296e14dc268SJim Ingham } 2297e14dc268SJim Ingham 22981f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 229970602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_read_options); 23001f0f5b5bSZachary Turner } 2301e14dc268SJim Ingham 2302e14dc268SJim Ingham // Instance variables to hold the values for command options. 2303e14dc268SJim Ingham 2304e14dc268SJim Ingham std::string m_filename; 23053acdf385SJim Ingham std::vector<std::string> m_names; 2306e14dc268SJim Ingham }; 2307e14dc268SJim Ingham 2308e14dc268SJim Ingham protected: 2309e14dc268SJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 2310e14dc268SJim Ingham Target *target = GetSelectedOrDummyTarget(); 2311e14dc268SJim Ingham if (target == nullptr) { 2312e14dc268SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 2313e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2314e14dc268SJim Ingham return false; 2315e14dc268SJim Ingham } 2316e14dc268SJim Ingham 23173acdf385SJim Ingham std::unique_lock<std::recursive_mutex> lock; 23183acdf385SJim Ingham target->GetBreakpointList().GetListMutex(lock); 23193acdf385SJim Ingham 2320e14dc268SJim Ingham FileSpec input_spec(m_options.m_filename, true); 232101f16664SJim Ingham BreakpointIDList new_bps; 232297206d57SZachary Turner Status error = target->CreateBreakpointsFromFile( 232397206d57SZachary Turner input_spec, m_options.m_names, new_bps); 2324e14dc268SJim Ingham 2325e14dc268SJim Ingham if (!error.Success()) { 232601f16664SJim Ingham result.AppendError(error.AsCString()); 2327e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 232801f16664SJim Ingham return false; 2329e14dc268SJim Ingham } 23303acdf385SJim Ingham 23313acdf385SJim Ingham Stream &output_stream = result.GetOutputStream(); 23323acdf385SJim Ingham 23333acdf385SJim Ingham size_t num_breakpoints = new_bps.GetSize(); 23343acdf385SJim Ingham if (num_breakpoints == 0) { 23353acdf385SJim Ingham result.AppendMessage("No breakpoints added."); 23363acdf385SJim Ingham } else { 23373acdf385SJim Ingham // No breakpoint selected; show info about all currently set breakpoints. 23383acdf385SJim Ingham result.AppendMessage("New breakpoints:"); 23393acdf385SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) { 23403acdf385SJim Ingham BreakpointID bp_id = new_bps.GetBreakpointIDAtIndex(i); 23413acdf385SJim Ingham Breakpoint *bp = target->GetBreakpointList() 23423acdf385SJim Ingham .FindBreakpointByID(bp_id.GetBreakpointID()) 23433acdf385SJim Ingham .get(); 23443acdf385SJim Ingham if (bp) 23453acdf385SJim Ingham bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, 23463acdf385SJim Ingham false); 23473acdf385SJim Ingham } 23483acdf385SJim Ingham } 2349e14dc268SJim Ingham return result.Succeeded(); 2350e14dc268SJim Ingham } 2351e14dc268SJim Ingham 2352e14dc268SJim Ingham private: 2353e14dc268SJim Ingham CommandOptions m_options; 2354e14dc268SJim Ingham }; 2355e14dc268SJim Ingham 2356e14dc268SJim Ingham //------------------------------------------------------------------------- 2357e14dc268SJim Ingham // CommandObjectBreakpointWrite 2358e14dc268SJim Ingham //------------------------------------------------------------------------- 23591f0f5b5bSZachary Turner #pragma mark Write::CommandOptions 23601f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_write_options[] = { 23611f0f5b5bSZachary Turner // clang-format off 23621f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename, "The file into which to write the breakpoints." }, 23632d3628e1SJim Ingham { LLDB_OPT_SET_ALL, false, "append",'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Append to saved breakpoints file if it exists."}, 23641f0f5b5bSZachary Turner // clang-format on 23651f0f5b5bSZachary Turner }; 23661f0f5b5bSZachary Turner 23671f0f5b5bSZachary Turner #pragma mark Write 2368e14dc268SJim Ingham class CommandObjectBreakpointWrite : public CommandObjectParsed { 2369e14dc268SJim Ingham public: 2370e14dc268SJim Ingham CommandObjectBreakpointWrite(CommandInterpreter &interpreter) 2371e14dc268SJim Ingham : CommandObjectParsed(interpreter, "breakpoint write", 2372e14dc268SJim Ingham "Write the breakpoints listed to a file that can " 2373e14dc268SJim Ingham "be read in with \"breakpoint read\". " 2374e14dc268SJim Ingham "If given no arguments, writes all breakpoints.", 2375e14dc268SJim Ingham nullptr), 2376e14dc268SJim Ingham m_options() { 2377e14dc268SJim Ingham CommandArgumentEntry arg; 2378e14dc268SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 2379e14dc268SJim Ingham eArgTypeBreakpointIDRange); 2380e14dc268SJim Ingham // Add the entry for the first argument for this command to the object's 2381e14dc268SJim Ingham // arguments vector. 2382e14dc268SJim Ingham m_arguments.push_back(arg); 2383e14dc268SJim Ingham } 2384e14dc268SJim Ingham 2385e14dc268SJim Ingham ~CommandObjectBreakpointWrite() override = default; 2386e14dc268SJim Ingham 2387e14dc268SJim Ingham Options *GetOptions() override { return &m_options; } 2388e14dc268SJim Ingham 2389e14dc268SJim Ingham class CommandOptions : public Options { 2390e14dc268SJim Ingham public: 2391e14dc268SJim Ingham CommandOptions() : Options() {} 2392e14dc268SJim Ingham 2393e14dc268SJim Ingham ~CommandOptions() override = default; 2394e14dc268SJim Ingham 239597206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 2396e14dc268SJim Ingham ExecutionContext *execution_context) override { 239797206d57SZachary Turner Status error; 2398e14dc268SJim Ingham const int short_option = m_getopt_table[option_idx].val; 2399e14dc268SJim Ingham 2400e14dc268SJim Ingham switch (short_option) { 2401e14dc268SJim Ingham case 'f': 2402e14dc268SJim Ingham m_filename.assign(option_arg); 2403e14dc268SJim Ingham break; 24042d3628e1SJim Ingham case 'a': 24052d3628e1SJim Ingham m_append = true; 24062d3628e1SJim Ingham break; 2407e14dc268SJim Ingham default: 2408e14dc268SJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 2409e14dc268SJim Ingham short_option); 2410e14dc268SJim Ingham break; 2411e14dc268SJim Ingham } 2412e14dc268SJim Ingham 2413e14dc268SJim Ingham return error; 2414e14dc268SJim Ingham } 2415e14dc268SJim Ingham 2416e14dc268SJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 2417e14dc268SJim Ingham m_filename.clear(); 24182d3628e1SJim Ingham m_append = false; 2419e14dc268SJim Ingham } 2420e14dc268SJim Ingham 24211f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 242270602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_write_options); 24231f0f5b5bSZachary Turner } 2424e14dc268SJim Ingham 2425e14dc268SJim Ingham // Instance variables to hold the values for command options. 2426e14dc268SJim Ingham 2427e14dc268SJim Ingham std::string m_filename; 24282d3628e1SJim Ingham bool m_append = false; 2429e14dc268SJim Ingham }; 2430e14dc268SJim Ingham 2431e14dc268SJim Ingham protected: 2432e14dc268SJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 2433e14dc268SJim Ingham Target *target = GetSelectedOrDummyTarget(); 2434e14dc268SJim Ingham if (target == nullptr) { 2435e14dc268SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 2436e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2437e14dc268SJim Ingham return false; 2438e14dc268SJim Ingham } 2439e14dc268SJim Ingham 2440e14dc268SJim Ingham std::unique_lock<std::recursive_mutex> lock; 2441e14dc268SJim Ingham target->GetBreakpointList().GetListMutex(lock); 2442e14dc268SJim Ingham 2443e14dc268SJim Ingham BreakpointIDList valid_bp_ids; 244411eb9c64SZachary Turner if (!command.empty()) { 2445e14dc268SJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 2446b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 2447b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 2448e14dc268SJim Ingham 244901f16664SJim Ingham if (!result.Succeeded()) { 2450e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2451e14dc268SJim Ingham return false; 2452e14dc268SJim Ingham } 2453e14dc268SJim Ingham } 245497206d57SZachary Turner Status error = target->SerializeBreakpointsToFile( 2455771ef6d4SMalcolm Parsons FileSpec(m_options.m_filename, true), valid_bp_ids, m_options.m_append); 245601f16664SJim Ingham if (!error.Success()) { 245701f16664SJim Ingham result.AppendErrorWithFormat("error serializing breakpoints: %s.", 245801f16664SJim Ingham error.AsCString()); 245901f16664SJim Ingham result.SetStatus(eReturnStatusFailed); 2460e14dc268SJim Ingham } 2461e14dc268SJim Ingham return result.Succeeded(); 2462e14dc268SJim Ingham } 2463e14dc268SJim Ingham 2464e14dc268SJim Ingham private: 2465e14dc268SJim Ingham CommandOptions m_options; 2466e14dc268SJim Ingham }; 2467e14dc268SJim Ingham 2468e14dc268SJim Ingham //------------------------------------------------------------------------- 246930fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 247030fdc8d8SChris Lattner //------------------------------------------------------------------------- 2471ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 247230fdc8d8SChris Lattner 2473b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint( 2474b9c1b51eSKate Stone CommandInterpreter &interpreter) 2475b9c1b51eSKate Stone : CommandObjectMultiword( 2476b9c1b51eSKate Stone interpreter, "breakpoint", 24777428a18cSKate Stone "Commands for operating on breakpoints (see 'help b' for shorthand.)", 2478b9c1b51eSKate Stone "breakpoint <subcommand> [<command-options>]") { 2479b9c1b51eSKate Stone CommandObjectSP list_command_object( 2480b9c1b51eSKate Stone new CommandObjectBreakpointList(interpreter)); 2481b9c1b51eSKate Stone CommandObjectSP enable_command_object( 2482b9c1b51eSKate Stone new CommandObjectBreakpointEnable(interpreter)); 2483b9c1b51eSKate Stone CommandObjectSP disable_command_object( 2484b9c1b51eSKate Stone new CommandObjectBreakpointDisable(interpreter)); 2485b9c1b51eSKate Stone CommandObjectSP clear_command_object( 2486b9c1b51eSKate Stone new CommandObjectBreakpointClear(interpreter)); 2487b9c1b51eSKate Stone CommandObjectSP delete_command_object( 2488b9c1b51eSKate Stone new CommandObjectBreakpointDelete(interpreter)); 2489b9c1b51eSKate Stone CommandObjectSP set_command_object( 2490b9c1b51eSKate Stone new CommandObjectBreakpointSet(interpreter)); 2491b9c1b51eSKate Stone CommandObjectSP command_command_object( 2492b9c1b51eSKate Stone new CommandObjectBreakpointCommand(interpreter)); 2493b9c1b51eSKate Stone CommandObjectSP modify_command_object( 2494b9c1b51eSKate Stone new CommandObjectBreakpointModify(interpreter)); 2495b9c1b51eSKate Stone CommandObjectSP name_command_object( 2496b9c1b51eSKate Stone new CommandObjectBreakpointName(interpreter)); 2497e14dc268SJim Ingham CommandObjectSP write_command_object( 2498e14dc268SJim Ingham new CommandObjectBreakpointWrite(interpreter)); 2499e14dc268SJim Ingham CommandObjectSP read_command_object( 2500e14dc268SJim Ingham new CommandObjectBreakpointRead(interpreter)); 250130fdc8d8SChris Lattner 2502b7234e40SJohnny Chen list_command_object->SetCommandName("breakpoint list"); 250330fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 250430fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 2505b7234e40SJohnny Chen clear_command_object->SetCommandName("breakpoint clear"); 2506b7234e40SJohnny Chen delete_command_object->SetCommandName("breakpoint delete"); 2507ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 2508b7234e40SJohnny Chen command_command_object->SetCommandName("breakpoint command"); 2509b7234e40SJohnny Chen modify_command_object->SetCommandName("breakpoint modify"); 25105e09c8c3SJim Ingham name_command_object->SetCommandName("breakpoint name"); 2511e14dc268SJim Ingham write_command_object->SetCommandName("breakpoint write"); 2512e14dc268SJim Ingham read_command_object->SetCommandName("breakpoint read"); 251330fdc8d8SChris Lattner 251423f59509SGreg Clayton LoadSubCommand("list", list_command_object); 251523f59509SGreg Clayton LoadSubCommand("enable", enable_command_object); 251623f59509SGreg Clayton LoadSubCommand("disable", disable_command_object); 251723f59509SGreg Clayton LoadSubCommand("clear", clear_command_object); 251823f59509SGreg Clayton LoadSubCommand("delete", delete_command_object); 251923f59509SGreg Clayton LoadSubCommand("set", set_command_object); 252023f59509SGreg Clayton LoadSubCommand("command", command_command_object); 252123f59509SGreg Clayton LoadSubCommand("modify", modify_command_object); 25225e09c8c3SJim Ingham LoadSubCommand("name", name_command_object); 2523e14dc268SJim Ingham LoadSubCommand("write", write_command_object); 2524e14dc268SJim Ingham LoadSubCommand("read", read_command_object); 252530fdc8d8SChris Lattner } 252630fdc8d8SChris Lattner 25279e85e5a8SEugene Zelenko CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default; 252830fdc8d8SChris Lattner 2529b9c1b51eSKate Stone void CommandObjectMultiwordBreakpoint::VerifyIDs(Args &args, Target *target, 25305e09c8c3SJim Ingham bool allow_locations, 25315e09c8c3SJim Ingham CommandReturnObject &result, 2532b842f2ecSJim Ingham BreakpointIDList *valid_ids, 2533b842f2ecSJim Ingham BreakpointName::Permissions 2534b842f2ecSJim Ingham ::PermissionKinds 2535b842f2ecSJim Ingham purpose) { 253630fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 2537b9c1b51eSKate Stone // 2). the full breakpoint & location 2538b9c1b51eSKate Stone // canonical representation 2539b9c1b51eSKate Stone // 3). the word "to" or a hyphen, 2540b9c1b51eSKate Stone // representing a range (in which case there 2541b9c1b51eSKate Stone // had *better* be an entry both before & 2542b9c1b51eSKate Stone // after of one of the first two types. 25435e09c8c3SJim Ingham // 4). A breakpoint name 2544b9c1b51eSKate Stone // If args is empty, we will use the last created breakpoint (if there is 2545b9c1b51eSKate Stone // one.) 254630fdc8d8SChris Lattner 254730fdc8d8SChris Lattner Args temp_args; 254830fdc8d8SChris Lattner 254911eb9c64SZachary Turner if (args.empty()) { 2550b9c1b51eSKate Stone if (target->GetLastCreatedBreakpoint()) { 2551b9c1b51eSKate Stone valid_ids->AddBreakpointID(BreakpointID( 2552b9c1b51eSKate Stone target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); 255336f3b369SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 2554b9c1b51eSKate Stone } else { 2555b9c1b51eSKate Stone result.AppendError( 2556b9c1b51eSKate Stone "No breakpoint specified and no last created breakpoint."); 255736f3b369SJim Ingham result.SetStatus(eReturnStatusFailed); 255836f3b369SJim Ingham } 255936f3b369SJim Ingham return; 256036f3b369SJim Ingham } 256136f3b369SJim Ingham 2562b9c1b51eSKate Stone // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff 2563b9c1b51eSKate Stone // directly from the old ARGS to 2564b9c1b51eSKate Stone // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead 2565b9c1b51eSKate Stone // generate a list of strings for 2566b9c1b51eSKate Stone // all the breakpoint ids in the range, and shove all of those breakpoint id 2567b9c1b51eSKate Stone // strings into TEMP_ARGS. 256830fdc8d8SChris Lattner 2569b9c1b51eSKate Stone BreakpointIDList::FindAndReplaceIDRanges(args, target, allow_locations, 2570b842f2ecSJim Ingham purpose, result, temp_args); 257130fdc8d8SChris Lattner 2572b9c1b51eSKate Stone // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual 2573b9c1b51eSKate Stone // BreakpointIDList: 257430fdc8d8SChris Lattner 2575b9c1b51eSKate Stone valid_ids->InsertStringArray(temp_args.GetConstArgumentVector(), 2576b9c1b51eSKate Stone temp_args.GetArgumentCount(), result); 257730fdc8d8SChris Lattner 2578b9c1b51eSKate Stone // At this point, all of the breakpoint ids that the user passed in have been 2579b9c1b51eSKate Stone // converted to breakpoint IDs 258030fdc8d8SChris Lattner // and put into valid_ids. 258130fdc8d8SChris Lattner 2582b9c1b51eSKate Stone if (result.Succeeded()) { 2583b9c1b51eSKate Stone // Now that we've converted everything from args into a list of breakpoint 2584b9c1b51eSKate Stone // ids, go through our tentative list 2585b9c1b51eSKate Stone // of breakpoint id's and verify that they correspond to valid/currently set 2586b9c1b51eSKate Stone // breakpoints. 258730fdc8d8SChris Lattner 2588c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 2589b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 259030fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex(i); 2591b9c1b51eSKate Stone Breakpoint *breakpoint = 2592b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 2593b9c1b51eSKate Stone if (breakpoint != nullptr) { 2594c7bece56SGreg Clayton const size_t num_locations = breakpoint->GetNumLocations(); 2595b9c1b51eSKate Stone if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations) { 259630fdc8d8SChris Lattner StreamString id_str; 2597b9c1b51eSKate Stone BreakpointID::GetCanonicalReference( 2598b9c1b51eSKate Stone &id_str, cur_bp_id.GetBreakpointID(), cur_bp_id.GetLocationID()); 2599c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 2600b9c1b51eSKate Stone result.AppendErrorWithFormat( 2601b9c1b51eSKate Stone "'%s' is not a currently valid breakpoint/location id.\n", 260230fdc8d8SChris Lattner id_str.GetData()); 260330fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 260430fdc8d8SChris Lattner } 2605b9c1b51eSKate Stone } else { 2606c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 2607b9c1b51eSKate Stone result.AppendErrorWithFormat( 2608b9c1b51eSKate Stone "'%d' is not a currently valid breakpoint ID.\n", 26097428a18cSKate Stone cur_bp_id.GetBreakpointID()); 261030fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 261130fdc8d8SChris Lattner } 261230fdc8d8SChris Lattner } 261330fdc8d8SChris Lattner } 261430fdc8d8SChris Lattner } 2615