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" 2547cbf4a0SPavel 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': 8805097246SAdrian Prantl // Normally an empty breakpoint condition marks is as unset. But we need 8905097246SAdrian Prantl // 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; 10447cbf4a0SPavel 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; 12547cbf4a0SPavel 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 26605097246SAdrian Prantl // Comment out this option for the moment, as we don't actually use it, but 26705097246SAdrian Prantl // will in the future. This way users won't see it, but the infrastructure is 26805097246SAdrian Prantl // left in place. 2691f0f5b5bSZachary Turner // { 0, false, "column", 'C', OptionParser::eRequiredArgument, nullptr, "<column>", 2701f0f5b5bSZachary Turner // "Set the breakpoint by source location at this particular column."}, 2711f0f5b5bSZachary Turner 2721f0f5b5bSZachary 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 " 2731f0f5b5bSZachary Turner "a particular binary, then the address will be converted to a \"file\" " 2741f0f5b5bSZachary Turner "address, so that the breakpoint will track that binary+offset no matter where " 2751f0f5b5bSZachary Turner "the binary eventually loads. Alternately, if you also specify the module - " 2761f0f5b5bSZachary Turner "with the -s option - then the address will be treated as a file address in " 2771f0f5b5bSZachary Turner "that module, and resolved accordingly. Again, this will allow lldb to track " 2781f0f5b5bSZachary Turner "that offset on subsequent reloads. The module need not have been loaded at " 2791f0f5b5bSZachary Turner "the time you specify this breakpoint, and will get resolved when the module " 2801f0f5b5bSZachary Turner "is loaded." }, 2811f0f5b5bSZachary 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 " 2821f0f5b5bSZachary Turner "one breakpoint for multiple names" }, 2831f0f5b5bSZachary 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 " 2841f0f5b5bSZachary Turner "functions. Can be repeated multiple times." }, 2851f0f5b5bSZachary 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 " 2864e8be2c9SAdrian Prantl "namespaces and all arguments, and for Objective-C this means a full function " 2871f0f5b5bSZachary Turner "prototype with class and selector. Can be repeated multiple times to make " 2881f0f5b5bSZachary Turner "one breakpoint for multiple names." }, 2891f0f5b5bSZachary 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 " 2901f0f5b5bSZachary Turner "make one breakpoint for multiple Selectors." }, 2911f0f5b5bSZachary 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 " 2921f0f5b5bSZachary Turner "make one breakpoint for multiple methods." }, 2931f0f5b5bSZachary 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 " 2941f0f5b5bSZachary Turner "the function name(s)." }, 2951f0f5b5bSZachary 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 " 2961f0f5b5bSZachary Turner "ignored). Can be repeated multiple times to make one breakpoint for multiple " 2971f0f5b5bSZachary Turner "symbols." }, 2981f0f5b5bSZachary 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 " 2991f0f5b5bSZachary Turner "against the source text in a source file or files specified with the -f " 3001f0f5b5bSZachary Turner "option. The -f option can be specified more than once. If no source files " 3011f0f5b5bSZachary Turner "are specified, uses the current \"default source file\". If you want to " 3021f0f5b5bSZachary Turner "match against all source files, pass the \"--all-files\" option." }, 3031f0f5b5bSZachary Turner { LLDB_OPT_SET_9, false, "all-files", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "All files are searched for source pattern matches." }, 3041f0f5b5bSZachary 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 " 3051f0f5b5bSZachary Turner "options, on throw but not catch.)" }, 3061f0f5b5bSZachary Turner { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Set the breakpoint on exception throW." }, 3071f0f5b5bSZachary Turner { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Set the breakpoint on exception catcH." }, 3081f0f5b5bSZachary Turner 3091f0f5b5bSZachary Turner // Don't add this option till it actually does something useful... 3101f0f5b5bSZachary Turner // { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName, 3111f0f5b5bSZachary 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" }, 3121f0f5b5bSZachary Turner 3131f0f5b5bSZachary 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 " 3141f0f5b5bSZachary Turner "(note: currently only implemented for setting breakpoints on identifiers). " 3151f0f5b5bSZachary Turner "If not set the target.language setting is used." }, 3161f0f5b5bSZachary 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. " 3171f0f5b5bSZachary Turner "If not set the target.skip-prologue setting is used." }, 3181f0f5b5bSZachary 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." }, 3191f0f5b5bSZachary 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. " 3201f0f5b5bSZachary Turner "At present this applies the offset directly as given, and doesn't try to align it to instruction boundaries." }, 3211f0f5b5bSZachary 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 " 3221f0f5b5bSZachary Turner "setting is used." }, 3231f0f5b5bSZachary Turner // clang-format on 3241f0f5b5bSZachary Turner }; 3251f0f5b5bSZachary Turner 32630fdc8d8SChris Lattner //------------------------------------------------------------------------- 3275a988416SJim Ingham // CommandObjectBreakpointSet 32830fdc8d8SChris Lattner //------------------------------------------------------------------------- 32930fdc8d8SChris Lattner 330b9c1b51eSKate Stone class CommandObjectBreakpointSet : public CommandObjectParsed { 3315a988416SJim Ingham public: 332b9c1b51eSKate Stone typedef enum BreakpointSetType { 3335a988416SJim Ingham eSetTypeInvalid, 3345a988416SJim Ingham eSetTypeFileAndLine, 3355a988416SJim Ingham eSetTypeAddress, 3365a988416SJim Ingham eSetTypeFunctionName, 3375a988416SJim Ingham eSetTypeFunctionRegexp, 3385a988416SJim Ingham eSetTypeSourceRegexp, 3395a988416SJim Ingham eSetTypeException 3405a988416SJim Ingham } BreakpointSetType; 3415a988416SJim Ingham 342b9c1b51eSKate Stone CommandObjectBreakpointSet(CommandInterpreter &interpreter) 343b9c1b51eSKate Stone : CommandObjectParsed( 344b9c1b51eSKate Stone interpreter, "breakpoint set", 3455a988416SJim Ingham "Sets a breakpoint or set of breakpoints in the executable.", 3465a988416SJim Ingham "breakpoint set <cmd-options>"), 347b842f2ecSJim Ingham m_bp_opts(), m_options() { 348b842f2ecSJim Ingham // We're picking up all the normal options, commands and disable. 349b842f2ecSJim Ingham m_all_options.Append(&m_bp_opts, 350b842f2ecSJim Ingham LLDB_OPT_SET_1 | LLDB_OPT_SET_3 | LLDB_OPT_SET_4, 351b842f2ecSJim Ingham LLDB_OPT_SET_ALL); 352b842f2ecSJim Ingham m_all_options.Append(&m_dummy_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 353b842f2ecSJim Ingham m_all_options.Append(&m_options); 354b842f2ecSJim Ingham m_all_options.Finalize(); 355b842f2ecSJim Ingham } 3565a988416SJim Ingham 3579e85e5a8SEugene Zelenko ~CommandObjectBreakpointSet() override = default; 3585a988416SJim Ingham 359b842f2ecSJim Ingham Options *GetOptions() override { return &m_all_options; } 3605a988416SJim Ingham 361b842f2ecSJim Ingham class CommandOptions : public OptionGroup { 3625a988416SJim Ingham public: 363b9c1b51eSKate Stone CommandOptions() 364b842f2ecSJim Ingham : OptionGroup(), m_condition(), m_filenames(), m_line_num(0), m_column(0), 365b9c1b51eSKate Stone m_func_names(), m_func_name_type_mask(eFunctionNameTypeNone), 366b9c1b51eSKate Stone m_func_regexp(), m_source_text_regexp(), m_modules(), m_load_addr(), 367b9c1b51eSKate Stone m_catch_bp(false), m_throw_bp(true), m_hardware(false), 368a72b31c7SJim Ingham m_exception_language(eLanguageTypeUnknown), 36923b1decbSDawn Perchik m_language(lldb::eLanguageTypeUnknown), 370b842f2ecSJim Ingham m_skip_prologue(eLazyBoolCalculate), 371b9c1b51eSKate Stone m_all_files(false), m_move_to_nearest_code(eLazyBoolCalculate) {} 37230fdc8d8SChris Lattner 3739e85e5a8SEugene Zelenko ~CommandOptions() override = default; 37487df91b8SJim Ingham 37597206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 376b9c1b51eSKate Stone ExecutionContext *execution_context) override { 37797206d57SZachary Turner Status error; 378b842f2ecSJim Ingham const int short_option = g_breakpoint_set_options[option_idx].short_option; 37930fdc8d8SChris Lattner 380b9c1b51eSKate Stone switch (short_option) { 381b9c1b51eSKate Stone case 'a': { 38247cbf4a0SPavel Labath m_load_addr = OptionArgParser::ToAddress(execution_context, option_arg, 383e1cfbc79STodd Fiala LLDB_INVALID_ADDRESS, &error); 384b9c1b51eSKate Stone } break; 38530fdc8d8SChris Lattner 386e732052fSJim Ingham case 'A': 387e732052fSJim Ingham m_all_files = true; 388e732052fSJim Ingham break; 389e732052fSJim Ingham 390ca36cd16SJim Ingham case 'b': 391ca36cd16SJim Ingham m_func_names.push_back(option_arg); 392ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeBase; 393ca36cd16SJim Ingham break; 394ca36cd16SJim Ingham 395fe11483bSZachary Turner case 'C': 396fe11483bSZachary Turner if (option_arg.getAsInteger(0, m_column)) 397b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid column number: %s", 398fe11483bSZachary Turner option_arg.str().c_str()); 39930fdc8d8SChris Lattner break; 4009e85e5a8SEugene Zelenko 401b9c1b51eSKate Stone case 'E': { 402fe11483bSZachary Turner LanguageType language = Language::GetLanguageTypeFromString(option_arg); 403fab10e89SJim Ingham 404b9c1b51eSKate Stone switch (language) { 405fab10e89SJim Ingham case eLanguageTypeC89: 406fab10e89SJim Ingham case eLanguageTypeC: 407fab10e89SJim Ingham case eLanguageTypeC99: 4081d0089faSBruce Mitchener case eLanguageTypeC11: 409a72b31c7SJim Ingham m_exception_language = eLanguageTypeC; 410fab10e89SJim Ingham break; 411fab10e89SJim Ingham case eLanguageTypeC_plus_plus: 4121d0089faSBruce Mitchener case eLanguageTypeC_plus_plus_03: 4131d0089faSBruce Mitchener case eLanguageTypeC_plus_plus_11: 4142ba84a6aSBruce Mitchener case eLanguageTypeC_plus_plus_14: 415a72b31c7SJim Ingham m_exception_language = eLanguageTypeC_plus_plus; 416fab10e89SJim Ingham break; 417fab10e89SJim Ingham case eLanguageTypeObjC: 418a72b31c7SJim Ingham m_exception_language = eLanguageTypeObjC; 419fab10e89SJim Ingham break; 420fab10e89SJim Ingham case eLanguageTypeObjC_plus_plus: 421b9c1b51eSKate Stone error.SetErrorStringWithFormat( 422b9c1b51eSKate Stone "Set exception breakpoints separately for c++ and objective-c"); 423fab10e89SJim Ingham break; 424fab10e89SJim Ingham case eLanguageTypeUnknown: 425b9c1b51eSKate Stone error.SetErrorStringWithFormat( 426b9c1b51eSKate Stone "Unknown language type: '%s' for exception breakpoint", 427fe11483bSZachary Turner option_arg.str().c_str()); 428fab10e89SJim Ingham break; 429fab10e89SJim Ingham default: 430b9c1b51eSKate Stone error.SetErrorStringWithFormat( 431b9c1b51eSKate Stone "Unsupported language type: '%s' for exception breakpoint", 432fe11483bSZachary Turner option_arg.str().c_str()); 433fab10e89SJim Ingham } 434b9c1b51eSKate Stone } break; 435ca36cd16SJim Ingham 436ca36cd16SJim Ingham case 'f': 437ca36cd16SJim Ingham m_filenames.AppendIfUnique(FileSpec(option_arg, false)); 438fab10e89SJim Ingham break; 439ca36cd16SJim Ingham 440ca36cd16SJim Ingham case 'F': 441ca36cd16SJim Ingham m_func_names.push_back(option_arg); 442ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeFull; 443ca36cd16SJim Ingham break; 444ca36cd16SJim Ingham 445b9c1b51eSKate Stone case 'h': { 446fab10e89SJim Ingham bool success; 44747cbf4a0SPavel Labath m_catch_bp = OptionArgParser::ToBoolean(option_arg, true, &success); 448fab10e89SJim Ingham if (!success) 449b9c1b51eSKate Stone error.SetErrorStringWithFormat( 450fe11483bSZachary Turner "Invalid boolean value for on-catch option: '%s'", 451fe11483bSZachary Turner option_arg.str().c_str()); 452b9c1b51eSKate Stone } break; 453eb023e75SGreg Clayton 454eb023e75SGreg Clayton case 'H': 455eb023e75SGreg Clayton m_hardware = true; 456eb023e75SGreg Clayton break; 457eb023e75SGreg Clayton 458b9c1b51eSKate Stone case 'K': { 459a8558b62SJim Ingham bool success; 460a8558b62SJim Ingham bool value; 46147cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, true, &success); 462a8558b62SJim Ingham if (value) 463a8558b62SJim Ingham m_skip_prologue = eLazyBoolYes; 464a8558b62SJim Ingham else 465a8558b62SJim Ingham m_skip_prologue = eLazyBoolNo; 466a8558b62SJim Ingham 467a8558b62SJim Ingham if (!success) 468b9c1b51eSKate Stone error.SetErrorStringWithFormat( 469b9c1b51eSKate Stone "Invalid boolean value for skip prologue option: '%s'", 470fe11483bSZachary Turner option_arg.str().c_str()); 471b9c1b51eSKate Stone } break; 472ca36cd16SJim Ingham 473fe11483bSZachary Turner case 'l': 474fe11483bSZachary Turner if (option_arg.getAsInteger(0, m_line_num)) 475b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid line number: %s.", 476fe11483bSZachary Turner option_arg.str().c_str()); 477ca36cd16SJim Ingham break; 478055ad9beSIlia K 47923b1decbSDawn Perchik case 'L': 480fe11483bSZachary Turner m_language = Language::GetLanguageTypeFromString(option_arg); 48123b1decbSDawn Perchik if (m_language == eLanguageTypeUnknown) 482b9c1b51eSKate Stone error.SetErrorStringWithFormat( 483fe11483bSZachary Turner "Unknown language type: '%s' for breakpoint", 484fe11483bSZachary Turner option_arg.str().c_str()); 48523b1decbSDawn Perchik break; 48623b1decbSDawn Perchik 487b9c1b51eSKate Stone case 'm': { 488055ad9beSIlia K bool success; 489055ad9beSIlia K bool value; 49047cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, true, &success); 491055ad9beSIlia K if (value) 492055ad9beSIlia K m_move_to_nearest_code = eLazyBoolYes; 493055ad9beSIlia K else 494055ad9beSIlia K m_move_to_nearest_code = eLazyBoolNo; 495055ad9beSIlia K 496055ad9beSIlia K if (!success) 497b9c1b51eSKate Stone error.SetErrorStringWithFormat( 498b9c1b51eSKate Stone "Invalid boolean value for move-to-nearest-code option: '%s'", 499fe11483bSZachary Turner option_arg.str().c_str()); 500055ad9beSIlia K break; 501055ad9beSIlia K } 502055ad9beSIlia K 503ca36cd16SJim Ingham case 'M': 504ca36cd16SJim Ingham m_func_names.push_back(option_arg); 505ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeMethod; 506ca36cd16SJim Ingham break; 507ca36cd16SJim Ingham 508ca36cd16SJim Ingham case 'n': 509ca36cd16SJim Ingham m_func_names.push_back(option_arg); 510ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeAuto; 511ca36cd16SJim Ingham break; 512ca36cd16SJim Ingham 5136fa7681bSZachary Turner case 'N': { 514fe11483bSZachary Turner if (BreakpointID::StringIsBreakpointName(option_arg, error)) 5155e09c8c3SJim Ingham m_breakpoint_names.push_back(option_arg); 516ff9a91eaSJim Ingham else 517ff9a91eaSJim Ingham error.SetErrorStringWithFormat("Invalid breakpoint name: %s", 518fe11483bSZachary Turner option_arg.str().c_str()); 5195e09c8c3SJim Ingham break; 5206fa7681bSZachary Turner } 5215e09c8c3SJim Ingham 522b9c1b51eSKate Stone case 'R': { 5232411167fSJim Ingham lldb::addr_t tmp_offset_addr; 52447cbf4a0SPavel Labath tmp_offset_addr = OptionArgParser::ToAddress(execution_context, 52547cbf4a0SPavel Labath option_arg, 0, &error); 5262411167fSJim Ingham if (error.Success()) 5272411167fSJim Ingham m_offset_addr = tmp_offset_addr; 528b9c1b51eSKate Stone } break; 5292411167fSJim Ingham 530a72b31c7SJim Ingham case 'O': 531fe11483bSZachary Turner m_exception_extra_args.AppendArgument("-O"); 532fe11483bSZachary Turner m_exception_extra_args.AppendArgument(option_arg); 533a72b31c7SJim Ingham break; 534a72b31c7SJim Ingham 535ca36cd16SJim Ingham case 'p': 536ca36cd16SJim Ingham m_source_text_regexp.assign(option_arg); 537ca36cd16SJim Ingham break; 538ca36cd16SJim Ingham 539ca36cd16SJim Ingham case 'r': 540ca36cd16SJim Ingham m_func_regexp.assign(option_arg); 541ca36cd16SJim Ingham break; 542ca36cd16SJim Ingham 543ca36cd16SJim Ingham case 's': 544ca36cd16SJim Ingham m_modules.AppendIfUnique(FileSpec(option_arg, false)); 545ca36cd16SJim Ingham break; 546ca36cd16SJim Ingham 547ca36cd16SJim Ingham case 'S': 548ca36cd16SJim Ingham m_func_names.push_back(option_arg); 549ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeSelector; 550ca36cd16SJim Ingham break; 551ca36cd16SJim Ingham 552b9c1b51eSKate Stone case 'w': { 553ca36cd16SJim Ingham bool success; 55447cbf4a0SPavel Labath m_throw_bp = OptionArgParser::ToBoolean(option_arg, true, &success); 555ca36cd16SJim Ingham if (!success) 556b9c1b51eSKate Stone error.SetErrorStringWithFormat( 557fe11483bSZachary Turner "Invalid boolean value for on-throw option: '%s'", 558fe11483bSZachary Turner option_arg.str().c_str()); 559b9c1b51eSKate Stone } break; 560ca36cd16SJim Ingham 56176bb8d67SJim Ingham case 'X': 56276bb8d67SJim Ingham m_source_regex_func_names.insert(option_arg); 56376bb8d67SJim Ingham break; 56476bb8d67SJim Ingham 56530fdc8d8SChris Lattner default: 566b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 567b9c1b51eSKate Stone short_option); 56830fdc8d8SChris Lattner break; 56930fdc8d8SChris Lattner } 57030fdc8d8SChris Lattner 57130fdc8d8SChris Lattner return error; 57230fdc8d8SChris Lattner } 5739e85e5a8SEugene Zelenko 574b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 57587df91b8SJim Ingham m_filenames.Clear(); 57630fdc8d8SChris Lattner m_line_num = 0; 57730fdc8d8SChris Lattner m_column = 0; 578fab10e89SJim Ingham m_func_names.clear(); 5791f746071SGreg Clayton m_func_name_type_mask = eFunctionNameTypeNone; 58030fdc8d8SChris Lattner m_func_regexp.clear(); 5811f746071SGreg Clayton m_source_text_regexp.clear(); 58287df91b8SJim Ingham m_modules.Clear(); 5831f746071SGreg Clayton m_load_addr = LLDB_INVALID_ADDRESS; 5842411167fSJim Ingham m_offset_addr = 0; 585fab10e89SJim Ingham m_catch_bp = false; 586fab10e89SJim Ingham m_throw_bp = true; 587eb023e75SGreg Clayton m_hardware = false; 588a72b31c7SJim Ingham m_exception_language = eLanguageTypeUnknown; 58923b1decbSDawn Perchik m_language = lldb::eLanguageTypeUnknown; 590a8558b62SJim Ingham m_skip_prologue = eLazyBoolCalculate; 5915e09c8c3SJim Ingham m_breakpoint_names.clear(); 592e732052fSJim Ingham m_all_files = false; 593a72b31c7SJim Ingham m_exception_extra_args.Clear(); 594055ad9beSIlia K m_move_to_nearest_code = eLazyBoolCalculate; 59576bb8d67SJim Ingham m_source_regex_func_names.clear(); 59630fdc8d8SChris Lattner } 59730fdc8d8SChris Lattner 5981f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 59970602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_set_options); 6001f0f5b5bSZachary Turner } 60130fdc8d8SChris Lattner 6025a988416SJim Ingham // Instance variables to hold the values for command options. 603969795f1SJim Ingham 6045a988416SJim Ingham std::string m_condition; 6055a988416SJim Ingham FileSpecList m_filenames; 6065a988416SJim Ingham uint32_t m_line_num; 6075a988416SJim Ingham uint32_t m_column; 6085a988416SJim Ingham std::vector<std::string> m_func_names; 6095e09c8c3SJim Ingham std::vector<std::string> m_breakpoint_names; 6105a988416SJim Ingham uint32_t m_func_name_type_mask; 6115a988416SJim Ingham std::string m_func_regexp; 6125a988416SJim Ingham std::string m_source_text_regexp; 6135a988416SJim Ingham FileSpecList m_modules; 6145a988416SJim Ingham lldb::addr_t m_load_addr; 6152411167fSJim Ingham lldb::addr_t m_offset_addr; 6165a988416SJim Ingham bool m_catch_bp; 6175a988416SJim Ingham bool m_throw_bp; 618eb023e75SGreg Clayton bool m_hardware; // Request to use hardware breakpoints 619a72b31c7SJim Ingham lldb::LanguageType m_exception_language; 62023b1decbSDawn Perchik lldb::LanguageType m_language; 6215a988416SJim Ingham LazyBool m_skip_prologue; 622e732052fSJim Ingham bool m_all_files; 623a72b31c7SJim Ingham Args m_exception_extra_args; 624055ad9beSIlia K LazyBool m_move_to_nearest_code; 62576bb8d67SJim Ingham std::unordered_set<std::string> m_source_regex_func_names; 6265a988416SJim Ingham }; 6275a988416SJim Ingham 6285a988416SJim Ingham protected: 629b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 630b842f2ecSJim Ingham Target *target = GetSelectedOrDummyTarget(m_dummy_options.m_use_dummy); 63133df7cd3SJim Ingham 632b9c1b51eSKate Stone if (target == nullptr) { 633b9c1b51eSKate Stone result.AppendError("Invalid target. Must set target before setting " 634b9c1b51eSKate Stone "breakpoints (see 'target create' command)."); 63530fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 63630fdc8d8SChris Lattner return false; 63730fdc8d8SChris Lattner } 63830fdc8d8SChris Lattner 63930fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 64030fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 64130fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 64230fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 643b9c1b51eSKate Stone // 4). -r [-s -g] (setting breakpoint by function name regular 644b9c1b51eSKate Stone // expression) 645b9c1b51eSKate Stone // 5). -p -f (setting a breakpoint by comparing a reg-exp 646b9c1b51eSKate Stone // to source text) 647b9c1b51eSKate Stone // 6). -E [-w -h] (setting a breakpoint for exceptions for a 648b9c1b51eSKate Stone // given language.) 64930fdc8d8SChris Lattner 65030fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 65130fdc8d8SChris Lattner 65230fdc8d8SChris Lattner if (m_options.m_line_num != 0) 65330fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 65430fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 65530fdc8d8SChris Lattner break_type = eSetTypeAddress; 656fab10e89SJim Ingham else if (!m_options.m_func_names.empty()) 65730fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 65830fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 65930fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 660969795f1SJim Ingham else if (!m_options.m_source_text_regexp.empty()) 661969795f1SJim Ingham break_type = eSetTypeSourceRegexp; 662a72b31c7SJim Ingham else if (m_options.m_exception_language != eLanguageTypeUnknown) 663fab10e89SJim Ingham break_type = eSetTypeException; 66430fdc8d8SChris Lattner 665b842f2ecSJim Ingham BreakpointSP bp_sp = nullptr; 666274060b6SGreg Clayton FileSpec module_spec; 667a8558b62SJim Ingham const bool internal = false; 668a8558b62SJim Ingham 669b9c1b51eSKate Stone // If the user didn't specify skip-prologue, having an offset should turn 670b9c1b51eSKate Stone // that off. 671b9c1b51eSKate Stone if (m_options.m_offset_addr != 0 && 672b9c1b51eSKate Stone m_options.m_skip_prologue == eLazyBoolCalculate) 6732411167fSJim Ingham m_options.m_skip_prologue = eLazyBoolNo; 6742411167fSJim Ingham 675b9c1b51eSKate Stone switch (break_type) { 67630fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 67730fdc8d8SChris Lattner { 67830fdc8d8SChris Lattner FileSpec file; 679c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 680b9c1b51eSKate Stone if (num_files == 0) { 681b9c1b51eSKate Stone if (!GetDefaultFile(target, file, result)) { 68287df91b8SJim Ingham result.AppendError("No file supplied and no default file available."); 68387df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 68487df91b8SJim Ingham return false; 68587df91b8SJim Ingham } 686b9c1b51eSKate Stone } else if (num_files > 1) { 687b9c1b51eSKate Stone result.AppendError("Only one file at a time is allowed for file and " 688b9c1b51eSKate Stone "line breakpoints."); 68987df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 69087df91b8SJim Ingham return false; 691b9c1b51eSKate Stone } else 69287df91b8SJim Ingham file = m_options.m_filenames.GetFileSpecAtIndex(0); 69330fdc8d8SChris Lattner 6941f746071SGreg Clayton // Only check for inline functions if 6951f746071SGreg Clayton LazyBool check_inlines = eLazyBoolCalculate; 6961f746071SGreg Clayton 697b842f2ecSJim Ingham bp_sp = target->CreateBreakpoint(&(m_options.m_modules), 698b842f2ecSJim Ingham file, 699b842f2ecSJim Ingham m_options.m_line_num, 700*431b1584SAdrian Prantl m_options.m_column, 701b842f2ecSJim Ingham m_options.m_offset_addr, 702b842f2ecSJim Ingham check_inlines, 703b842f2ecSJim Ingham m_options.m_skip_prologue, 704b842f2ecSJim Ingham internal, 705b842f2ecSJim Ingham m_options.m_hardware, 706b842f2ecSJim Ingham m_options.m_move_to_nearest_code); 707b9c1b51eSKate Stone } break; 7086eee5aa0SGreg Clayton 70930fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 710055a08a4SJim Ingham { 711b9c1b51eSKate Stone // If a shared library has been specified, make an lldb_private::Address 712b842f2ecSJim Ingham // with the library, and use that. That way the address breakpoint 713b842f2ecSJim Ingham // will track the load location of the library. 714055a08a4SJim Ingham size_t num_modules_specified = m_options.m_modules.GetSize(); 715b9c1b51eSKate Stone if (num_modules_specified == 1) { 716b9c1b51eSKate Stone const FileSpec *file_spec = 717b9c1b51eSKate Stone m_options.m_modules.GetFileSpecPointerAtIndex(0); 718b842f2ecSJim Ingham bp_sp = target->CreateAddressInModuleBreakpoint(m_options.m_load_addr, 719b9c1b51eSKate Stone internal, file_spec, 720b842f2ecSJim Ingham m_options.m_hardware); 721b9c1b51eSKate Stone } else if (num_modules_specified == 0) { 722b842f2ecSJim Ingham bp_sp = target->CreateBreakpoint(m_options.m_load_addr, internal, 723b842f2ecSJim Ingham m_options.m_hardware); 724b9c1b51eSKate Stone } else { 725b9c1b51eSKate Stone result.AppendError("Only one shared library can be specified for " 726b9c1b51eSKate Stone "address breakpoints."); 727055a08a4SJim Ingham result.SetStatus(eReturnStatusFailed); 728055a08a4SJim Ingham return false; 729055a08a4SJim Ingham } 73030fdc8d8SChris Lattner break; 731055a08a4SJim Ingham } 73230fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 7330c5cd90dSGreg Clayton { 7340c5cd90dSGreg Clayton uint32_t name_type_mask = m_options.m_func_name_type_mask; 7350c5cd90dSGreg Clayton 7360c5cd90dSGreg Clayton if (name_type_mask == 0) 737e02b8504SGreg Clayton name_type_mask = eFunctionNameTypeAuto; 7380c5cd90dSGreg Clayton 739b842f2ecSJim Ingham bp_sp = target->CreateBreakpoint(&(m_options.m_modules), 740b842f2ecSJim Ingham &(m_options.m_filenames), 741b842f2ecSJim Ingham m_options.m_func_names, 742b842f2ecSJim Ingham name_type_mask, 743b842f2ecSJim Ingham m_options.m_language, 744b842f2ecSJim Ingham m_options.m_offset_addr, 745b842f2ecSJim Ingham m_options.m_skip_prologue, 746b842f2ecSJim Ingham internal, 747b842f2ecSJim Ingham m_options.m_hardware); 748b9c1b51eSKate Stone } break; 7490c5cd90dSGreg Clayton 750b9c1b51eSKate Stone case eSetTypeFunctionRegexp: // Breakpoint by regular expression function 751b9c1b51eSKate Stone // name 75230fdc8d8SChris Lattner { 75395eae423SZachary Turner RegularExpression regexp(m_options.m_func_regexp); 754b9c1b51eSKate Stone if (!regexp.IsValid()) { 755969795f1SJim Ingham char err_str[1024]; 756969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 757b9c1b51eSKate Stone result.AppendErrorWithFormat( 758b9c1b51eSKate Stone "Function name regular expression could not be compiled: \"%s\"", 759969795f1SJim Ingham err_str); 76030fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 761969795f1SJim Ingham return false; 76230fdc8d8SChris Lattner } 76387df91b8SJim Ingham 764b842f2ecSJim Ingham bp_sp = target->CreateFuncRegexBreakpoint(&(m_options.m_modules), 765b842f2ecSJim Ingham &(m_options.m_filenames), 766b842f2ecSJim Ingham regexp, 767b842f2ecSJim Ingham m_options.m_language, 768b842f2ecSJim Ingham m_options.m_skip_prologue, 769b842f2ecSJim Ingham internal, 770b842f2ecSJim Ingham m_options.m_hardware); 771e14dc268SJim Ingham } 772e14dc268SJim Ingham break; 773969795f1SJim Ingham case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. 774969795f1SJim Ingham { 775c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 77687df91b8SJim Ingham 777b9c1b51eSKate Stone if (num_files == 0 && !m_options.m_all_files) { 778969795f1SJim Ingham FileSpec file; 779b9c1b51eSKate Stone if (!GetDefaultFile(target, file, result)) { 780b9c1b51eSKate Stone result.AppendError( 781b9c1b51eSKate Stone "No files provided and could not find default file."); 78287df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 78387df91b8SJim Ingham return false; 784b9c1b51eSKate Stone } else { 78587df91b8SJim Ingham m_options.m_filenames.Append(file); 78687df91b8SJim Ingham } 78787df91b8SJim Ingham } 7880c5cd90dSGreg Clayton 78995eae423SZachary Turner RegularExpression regexp(m_options.m_source_text_regexp); 790b9c1b51eSKate Stone if (!regexp.IsValid()) { 791969795f1SJim Ingham char err_str[1024]; 792969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 793b9c1b51eSKate Stone result.AppendErrorWithFormat( 794b9c1b51eSKate Stone "Source text regular expression could not be compiled: \"%s\"", 795969795f1SJim Ingham err_str); 796969795f1SJim Ingham result.SetStatus(eReturnStatusFailed); 797969795f1SJim Ingham return false; 798969795f1SJim Ingham } 799b842f2ecSJim Ingham bp_sp = 800b842f2ecSJim Ingham target->CreateSourceRegexBreakpoint(&(m_options.m_modules), 801b842f2ecSJim Ingham &(m_options.m_filenames), 802b842f2ecSJim Ingham m_options 803b842f2ecSJim Ingham .m_source_regex_func_names, 804b842f2ecSJim Ingham regexp, 805b842f2ecSJim Ingham internal, 806b842f2ecSJim Ingham m_options.m_hardware, 807b842f2ecSJim Ingham m_options.m_move_to_nearest_code); 808b9c1b51eSKate Stone } break; 809b9c1b51eSKate Stone case eSetTypeException: { 81097206d57SZachary Turner Status precond_error; 811b842f2ecSJim Ingham bp_sp = target->CreateExceptionBreakpoint(m_options.m_exception_language, 812b842f2ecSJim Ingham m_options.m_catch_bp, 813b842f2ecSJim Ingham m_options.m_throw_bp, 814b842f2ecSJim Ingham internal, 815b842f2ecSJim Ingham &m_options 816b842f2ecSJim Ingham .m_exception_extra_args, 817b842f2ecSJim Ingham &precond_error); 818b9c1b51eSKate Stone if (precond_error.Fail()) { 819b9c1b51eSKate Stone result.AppendErrorWithFormat( 820b9c1b51eSKate Stone "Error setting extra exception arguments: %s", 821a72b31c7SJim Ingham precond_error.AsCString()); 822b842f2ecSJim Ingham target->RemoveBreakpointByID(bp_sp->GetID()); 823a72b31c7SJim Ingham result.SetStatus(eReturnStatusFailed); 824a72b31c7SJim Ingham return false; 825a72b31c7SJim Ingham } 826b9c1b51eSKate Stone } break; 82730fdc8d8SChris Lattner default: 82830fdc8d8SChris Lattner break; 82930fdc8d8SChris Lattner } 83030fdc8d8SChris Lattner 8311b54c88cSJim Ingham // Now set the various options that were passed in: 832b842f2ecSJim Ingham if (bp_sp) { 833b842f2ecSJim Ingham bp_sp->GetOptions()->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); 834ca36cd16SJim Ingham 835b9c1b51eSKate Stone if (!m_options.m_breakpoint_names.empty()) { 83697206d57SZachary Turner Status name_error; 837ff9a91eaSJim Ingham for (auto name : m_options.m_breakpoint_names) { 838b842f2ecSJim Ingham target->AddNameToBreakpoint(bp_sp, name.c_str(), name_error); 839ff9a91eaSJim Ingham if (name_error.Fail()) { 840ff9a91eaSJim Ingham result.AppendErrorWithFormat("Invalid breakpoint name: %s", 841ff9a91eaSJim Ingham name.c_str()); 842b842f2ecSJim Ingham target->RemoveBreakpointByID(bp_sp->GetID()); 843ff9a91eaSJim Ingham result.SetStatus(eReturnStatusFailed); 844ff9a91eaSJim Ingham return false; 845ff9a91eaSJim Ingham } 846ff9a91eaSJim Ingham } 8475e09c8c3SJim Ingham } 8481b54c88cSJim Ingham } 8491b54c88cSJim Ingham 850b842f2ecSJim Ingham if (bp_sp) { 85185e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 8521391cc7dSJim Ingham const bool show_locations = false; 853b842f2ecSJim Ingham bp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, 854b9c1b51eSKate Stone show_locations); 8554aeb1989SJim Ingham if (target == m_interpreter.GetDebugger().GetDummyTarget()) 856b9c1b51eSKate Stone output_stream.Printf("Breakpoint set in dummy target, will get copied " 857b9c1b51eSKate Stone "into future targets.\n"); 858b9c1b51eSKate Stone else { 85905097246SAdrian Prantl // Don't print out this warning for exception breakpoints. They can 86005097246SAdrian Prantl // get set before the target is set, but we won't know how to actually 86105097246SAdrian Prantl // set the breakpoint till we run. 862b842f2ecSJim Ingham if (bp_sp->GetNumLocations() == 0 && break_type != eSetTypeException) { 863b9c1b51eSKate Stone output_stream.Printf("WARNING: Unable to resolve breakpoint to any " 864b9c1b51eSKate Stone "actual locations.\n"); 8654aeb1989SJim Ingham } 8664aeb1989SJim Ingham } 86730fdc8d8SChris Lattner result.SetStatus(eReturnStatusSuccessFinishResult); 868b842f2ecSJim Ingham } else if (!bp_sp) { 86930fdc8d8SChris Lattner result.AppendError("Breakpoint creation failed: No breakpoint created."); 87030fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 87130fdc8d8SChris Lattner } 87230fdc8d8SChris Lattner 87330fdc8d8SChris Lattner return result.Succeeded(); 87430fdc8d8SChris Lattner } 87530fdc8d8SChris Lattner 8765a988416SJim Ingham private: 877b9c1b51eSKate Stone bool GetDefaultFile(Target *target, FileSpec &file, 878b9c1b51eSKate Stone CommandReturnObject &result) { 8795a988416SJim Ingham uint32_t default_line; 88005097246SAdrian Prantl // First use the Source Manager's default file. Then use the current stack 88105097246SAdrian Prantl // frame's file. 882b9c1b51eSKate Stone if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) { 883b57e4a1bSJason Molenda StackFrame *cur_frame = m_exe_ctx.GetFramePtr(); 884b9c1b51eSKate Stone if (cur_frame == nullptr) { 885b9c1b51eSKate Stone result.AppendError( 886b9c1b51eSKate Stone "No selected frame to use to find the default file."); 8875a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 8885a988416SJim Ingham return false; 889b9c1b51eSKate Stone } else if (!cur_frame->HasDebugInformation()) { 890b9c1b51eSKate Stone result.AppendError("Cannot use the selected frame to find the default " 891b9c1b51eSKate Stone "file, it has no debug info."); 8925a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 8935a988416SJim Ingham return false; 894b9c1b51eSKate Stone } else { 895b9c1b51eSKate Stone const SymbolContext &sc = 896b9c1b51eSKate Stone cur_frame->GetSymbolContext(eSymbolContextLineEntry); 897b9c1b51eSKate Stone if (sc.line_entry.file) { 8985a988416SJim Ingham file = sc.line_entry.file; 899b9c1b51eSKate Stone } else { 900b9c1b51eSKate Stone result.AppendError("Can't find the file for the selected frame to " 901b9c1b51eSKate Stone "use as the default file."); 9025a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 9035a988416SJim Ingham return false; 9045a988416SJim Ingham } 9055a988416SJim Ingham } 9065a988416SJim Ingham } 9075a988416SJim Ingham return true; 9085a988416SJim Ingham } 9095a988416SJim Ingham 910b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 911b842f2ecSJim Ingham BreakpointDummyOptionGroup m_dummy_options; 9125a988416SJim Ingham CommandOptions m_options; 913b842f2ecSJim Ingham OptionGroupOptions m_all_options; 9145a988416SJim Ingham }; 9159e85e5a8SEugene Zelenko 9165a988416SJim Ingham //------------------------------------------------------------------------- 9175a988416SJim Ingham // CommandObjectBreakpointModify 9185a988416SJim Ingham //------------------------------------------------------------------------- 9195a988416SJim Ingham #pragma mark Modify 9205a988416SJim Ingham 921b9c1b51eSKate Stone class CommandObjectBreakpointModify : public CommandObjectParsed { 9225a988416SJim Ingham public: 923b9c1b51eSKate Stone CommandObjectBreakpointModify(CommandInterpreter &interpreter) 924b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "breakpoint modify", 925b9c1b51eSKate Stone "Modify the options on a breakpoint or set of " 926b9c1b51eSKate Stone "breakpoints in the executable. " 927b9c1b51eSKate Stone "If no breakpoint is specified, acts on the last " 928b9c1b51eSKate Stone "created breakpoint. " 929b9c1b51eSKate Stone "With the exception of -e, -d and -i, passing an " 930b9c1b51eSKate Stone "empty argument clears the modification.", 9319e85e5a8SEugene Zelenko nullptr), 932b9c1b51eSKate Stone m_options() { 9335a988416SJim Ingham CommandArgumentEntry arg; 934b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 935b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 936b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 937b9c1b51eSKate Stone // arguments vector. 9385a988416SJim Ingham m_arguments.push_back(arg); 939b842f2ecSJim Ingham 940b842f2ecSJim Ingham m_options.Append(&m_bp_opts, 941b842f2ecSJim Ingham LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3, 942b842f2ecSJim Ingham LLDB_OPT_SET_ALL); 943b842f2ecSJim Ingham m_options.Append(&m_dummy_opts, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 944b842f2ecSJim Ingham m_options.Finalize(); 9455a988416SJim Ingham } 9465a988416SJim Ingham 9479e85e5a8SEugene Zelenko ~CommandObjectBreakpointModify() override = default; 9485a988416SJim Ingham 949b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 9505a988416SJim Ingham 9515a988416SJim Ingham protected: 952b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 953b842f2ecSJim Ingham Target *target = GetSelectedOrDummyTarget(m_dummy_opts.m_use_dummy); 954b9c1b51eSKate Stone if (target == nullptr) { 9555a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 9565a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 9575a988416SJim Ingham return false; 9585a988416SJim Ingham } 9595a988416SJim Ingham 960bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 961bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 9625a988416SJim Ingham 9635a988416SJim Ingham BreakpointIDList valid_bp_ids; 9645a988416SJim Ingham 965b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 966b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 967b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 9685a988416SJim Ingham 969b9c1b51eSKate Stone if (result.Succeeded()) { 9705a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 971b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 9725a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 9735a988416SJim Ingham 974b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 975b9c1b51eSKate Stone Breakpoint *bp = 976b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 977b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 978b9c1b51eSKate Stone BreakpointLocation *location = 979b9c1b51eSKate Stone bp->FindLocationByID(cur_bp_id.GetLocationID()).get(); 980b842f2ecSJim Ingham if (location) 981b842f2ecSJim Ingham location->GetLocationOptions() 982b842f2ecSJim Ingham ->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); 983b9c1b51eSKate Stone } else { 984b842f2ecSJim Ingham bp->GetOptions() 985b842f2ecSJim Ingham ->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); 9865a988416SJim Ingham } 9875a988416SJim Ingham } 9885a988416SJim Ingham } 9895a988416SJim Ingham } 9905a988416SJim Ingham 9915a988416SJim Ingham return result.Succeeded(); 9925a988416SJim Ingham } 9935a988416SJim Ingham 9945a988416SJim Ingham private: 995b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 996b842f2ecSJim Ingham BreakpointDummyOptionGroup m_dummy_opts; 997b842f2ecSJim Ingham OptionGroupOptions m_options; 9985a988416SJim Ingham }; 9995a988416SJim Ingham 10005a988416SJim Ingham //------------------------------------------------------------------------- 10015a988416SJim Ingham // CommandObjectBreakpointEnable 10025a988416SJim Ingham //------------------------------------------------------------------------- 10035a988416SJim Ingham #pragma mark Enable 10045a988416SJim Ingham 1005b9c1b51eSKate Stone class CommandObjectBreakpointEnable : public CommandObjectParsed { 10065a988416SJim Ingham public: 1007b9c1b51eSKate Stone CommandObjectBreakpointEnable(CommandInterpreter &interpreter) 1008b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "enable", 1009b9c1b51eSKate Stone "Enable the specified disabled breakpoint(s). If " 1010b9c1b51eSKate Stone "no breakpoints are specified, enable all of them.", 1011b9c1b51eSKate Stone nullptr) { 10125a988416SJim Ingham CommandArgumentEntry arg; 1013b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1014b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1015b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1016b9c1b51eSKate Stone // arguments vector. 10175a988416SJim Ingham m_arguments.push_back(arg); 10185a988416SJim Ingham } 10195a988416SJim Ingham 10209e85e5a8SEugene Zelenko ~CommandObjectBreakpointEnable() override = default; 10215a988416SJim Ingham 10225a988416SJim Ingham protected: 1023b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1024893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1025b9c1b51eSKate Stone if (target == nullptr) { 10265a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 10275a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 10285a988416SJim Ingham return false; 10295a988416SJim Ingham } 10305a988416SJim Ingham 1031bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1032bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 10335a988416SJim Ingham 10345a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 10355a988416SJim Ingham 10365a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 10375a988416SJim Ingham 1038b9c1b51eSKate Stone if (num_breakpoints == 0) { 10395a988416SJim Ingham result.AppendError("No breakpoints exist to be enabled."); 10405a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 10415a988416SJim Ingham return false; 10425a988416SJim Ingham } 10435a988416SJim Ingham 104411eb9c64SZachary Turner if (command.empty()) { 10455a988416SJim Ingham // No breakpoint selected; enable all currently set breakpoints. 1046b842f2ecSJim Ingham target->EnableAllowedBreakpoints(); 1047b9c1b51eSKate Stone result.AppendMessageWithFormat("All breakpoints enabled. (%" PRIu64 1048b9c1b51eSKate Stone " breakpoints)\n", 1049b9c1b51eSKate Stone (uint64_t)num_breakpoints); 10505a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1051b9c1b51eSKate Stone } else { 10525a988416SJim Ingham // Particular breakpoint selected; enable that breakpoint. 10535a988416SJim Ingham BreakpointIDList valid_bp_ids; 1054b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1055b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1056b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 10575a988416SJim Ingham 1058b9c1b51eSKate Stone if (result.Succeeded()) { 10595a988416SJim Ingham int enable_count = 0; 10605a988416SJim Ingham int loc_count = 0; 10615a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1062b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 10635a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 10645a988416SJim Ingham 1065b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1066b9c1b51eSKate Stone Breakpoint *breakpoint = 1067b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1068b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1069b9c1b51eSKate Stone BreakpointLocation *location = 1070b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1071b9c1b51eSKate Stone if (location) { 10725a988416SJim Ingham location->SetEnabled(true); 10735a988416SJim Ingham ++loc_count; 10745a988416SJim Ingham } 1075b9c1b51eSKate Stone } else { 10765a988416SJim Ingham breakpoint->SetEnabled(true); 10775a988416SJim Ingham ++enable_count; 10785a988416SJim Ingham } 10795a988416SJim Ingham } 10805a988416SJim Ingham } 1081b9c1b51eSKate Stone result.AppendMessageWithFormat("%d breakpoints enabled.\n", 1082b9c1b51eSKate Stone enable_count + loc_count); 10835a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 10845a988416SJim Ingham } 10855a988416SJim Ingham } 10865a988416SJim Ingham 10875a988416SJim Ingham return result.Succeeded(); 10885a988416SJim Ingham } 10895a988416SJim Ingham }; 10905a988416SJim Ingham 10915a988416SJim Ingham //------------------------------------------------------------------------- 10925a988416SJim Ingham // CommandObjectBreakpointDisable 10935a988416SJim Ingham //------------------------------------------------------------------------- 10945a988416SJim Ingham #pragma mark Disable 10955a988416SJim Ingham 1096b9c1b51eSKate Stone class CommandObjectBreakpointDisable : public CommandObjectParsed { 10975a988416SJim Ingham public: 10987428a18cSKate Stone CommandObjectBreakpointDisable(CommandInterpreter &interpreter) 1099b9c1b51eSKate Stone : CommandObjectParsed( 1100b9c1b51eSKate Stone interpreter, "breakpoint disable", 1101b9c1b51eSKate Stone "Disable the specified breakpoint(s) without deleting " 11027428a18cSKate Stone "them. If none are specified, disable all " 11037428a18cSKate Stone "breakpoints.", 1104b9c1b51eSKate Stone nullptr) { 1105b9c1b51eSKate Stone SetHelpLong( 1106b9c1b51eSKate Stone "Disable the specified breakpoint(s) without deleting them. \ 11077428a18cSKate Stone If none are specified, disable all breakpoints." 11087428a18cSKate Stone R"( 1109ea671fbdSKate Stone 11107428a18cSKate Stone )" 11117428a18cSKate Stone "Note: disabling a breakpoint will cause none of its locations to be hit \ 11127428a18cSKate Stone regardless of whether individual locations are enabled or disabled. After the sequence:" 11137428a18cSKate Stone R"( 1114ea671fbdSKate Stone 1115ea671fbdSKate Stone (lldb) break disable 1 1116ea671fbdSKate Stone (lldb) break enable 1.1 1117ea671fbdSKate Stone 1118ea671fbdSKate Stone execution will NOT stop at location 1.1. To achieve that, type: 1119ea671fbdSKate Stone 1120ea671fbdSKate Stone (lldb) break disable 1.* 1121ea671fbdSKate Stone (lldb) break enable 1.1 1122ea671fbdSKate Stone 11237428a18cSKate Stone )" 11247428a18cSKate Stone "The first command disables all locations for breakpoint 1, \ 11257428a18cSKate Stone the second re-enables the first location."); 1126b0fac509SJim Ingham 11275a988416SJim Ingham CommandArgumentEntry arg; 1128b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1129b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1130b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1131b9c1b51eSKate Stone // arguments vector. 11325a988416SJim Ingham m_arguments.push_back(arg); 11335a988416SJim Ingham } 11345a988416SJim Ingham 11359e85e5a8SEugene Zelenko ~CommandObjectBreakpointDisable() override = default; 11365a988416SJim Ingham 11375a988416SJim Ingham protected: 1138b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1139893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1140b9c1b51eSKate Stone if (target == nullptr) { 11415a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 11425a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 11435a988416SJim Ingham return false; 11445a988416SJim Ingham } 11455a988416SJim Ingham 1146bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1147bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 11485a988416SJim Ingham 11495a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 11505a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 11515a988416SJim Ingham 1152b9c1b51eSKate Stone if (num_breakpoints == 0) { 11535a988416SJim Ingham result.AppendError("No breakpoints exist to be disabled."); 11545a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 11555a988416SJim Ingham return false; 11565a988416SJim Ingham } 11575a988416SJim Ingham 115811eb9c64SZachary Turner if (command.empty()) { 11595a988416SJim Ingham // No breakpoint selected; disable all currently set breakpoints. 1160b842f2ecSJim Ingham target->DisableAllowedBreakpoints(); 1161b9c1b51eSKate Stone result.AppendMessageWithFormat("All breakpoints disabled. (%" PRIu64 1162b9c1b51eSKate Stone " breakpoints)\n", 1163b9c1b51eSKate Stone (uint64_t)num_breakpoints); 11645a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1165b9c1b51eSKate Stone } else { 11665a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 11675a988416SJim Ingham BreakpointIDList valid_bp_ids; 11685a988416SJim Ingham 1169b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1170b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1171b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 11725a988416SJim Ingham 1173b9c1b51eSKate Stone if (result.Succeeded()) { 11745a988416SJim Ingham int disable_count = 0; 11755a988416SJim Ingham int loc_count = 0; 11765a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1177b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 11785a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 11795a988416SJim Ingham 1180b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1181b9c1b51eSKate Stone Breakpoint *breakpoint = 1182b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1183b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1184b9c1b51eSKate Stone BreakpointLocation *location = 1185b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1186b9c1b51eSKate Stone if (location) { 11875a988416SJim Ingham location->SetEnabled(false); 11885a988416SJim Ingham ++loc_count; 11895a988416SJim Ingham } 1190b9c1b51eSKate Stone } else { 11915a988416SJim Ingham breakpoint->SetEnabled(false); 11925a988416SJim Ingham ++disable_count; 11935a988416SJim Ingham } 11945a988416SJim Ingham } 11955a988416SJim Ingham } 1196b9c1b51eSKate Stone result.AppendMessageWithFormat("%d breakpoints disabled.\n", 1197b9c1b51eSKate Stone disable_count + loc_count); 11985a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 11995a988416SJim Ingham } 12005a988416SJim Ingham } 12015a988416SJim Ingham 12025a988416SJim Ingham return result.Succeeded(); 12035a988416SJim Ingham } 12045a988416SJim Ingham }; 12055a988416SJim Ingham 12065a988416SJim Ingham //------------------------------------------------------------------------- 12075a988416SJim Ingham // CommandObjectBreakpointList 12085a988416SJim Ingham //------------------------------------------------------------------------- 12091f0f5b5bSZachary Turner 12101f0f5b5bSZachary Turner #pragma mark List::CommandOptions 12111f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_list_options[] = { 12121f0f5b5bSZachary Turner // clang-format off 12131f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show debugger internal breakpoints" }, 12141f0f5b5bSZachary Turner { LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a brief description of the breakpoint (no location info)." }, 12151f0f5b5bSZachary Turner // FIXME: We need to add an "internal" command, and then add this sort of thing to it. 12161f0f5b5bSZachary Turner // But I need to see it for now, and don't want to wait. 12171f0f5b5bSZachary Turner { LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a full description of the breakpoint and its locations." }, 12181f0f5b5bSZachary 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)." }, 12191f0f5b5bSZachary 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." }, 12201f0f5b5bSZachary Turner // clang-format on 12211f0f5b5bSZachary Turner }; 12221f0f5b5bSZachary Turner 12235a988416SJim Ingham #pragma mark List 12245a988416SJim Ingham 1225b9c1b51eSKate Stone class CommandObjectBreakpointList : public CommandObjectParsed { 12265a988416SJim Ingham public: 1227b9c1b51eSKate Stone CommandObjectBreakpointList(CommandInterpreter &interpreter) 1228b9c1b51eSKate Stone : CommandObjectParsed( 1229b9c1b51eSKate Stone interpreter, "breakpoint list", 12305a988416SJim Ingham "List some or all breakpoints at configurable levels of detail.", 12319e85e5a8SEugene Zelenko nullptr), 1232b9c1b51eSKate Stone m_options() { 12335a988416SJim Ingham CommandArgumentEntry arg; 12345a988416SJim Ingham CommandArgumentData bp_id_arg; 12355a988416SJim Ingham 12365a988416SJim Ingham // Define the first (and only) variant of this arg. 12375a988416SJim Ingham bp_id_arg.arg_type = eArgTypeBreakpointID; 12385a988416SJim Ingham bp_id_arg.arg_repetition = eArgRepeatOptional; 12395a988416SJim Ingham 1240b9c1b51eSKate Stone // There is only one variant this argument could be; put it into the 1241b9c1b51eSKate Stone // argument entry. 12425a988416SJim Ingham arg.push_back(bp_id_arg); 12435a988416SJim Ingham 12445a988416SJim Ingham // Push the data for the first argument into the m_arguments vector. 12455a988416SJim Ingham m_arguments.push_back(arg); 12465a988416SJim Ingham } 12475a988416SJim Ingham 12489e85e5a8SEugene Zelenko ~CommandObjectBreakpointList() override = default; 12495a988416SJim Ingham 1250b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 12515a988416SJim Ingham 1252b9c1b51eSKate Stone class CommandOptions : public Options { 12535a988416SJim Ingham public: 1254b9c1b51eSKate Stone CommandOptions() 1255b9c1b51eSKate Stone : Options(), m_level(lldb::eDescriptionLevelBrief), m_use_dummy(false) { 12565a988416SJim Ingham } 12575a988416SJim Ingham 12589e85e5a8SEugene Zelenko ~CommandOptions() override = default; 12595a988416SJim Ingham 126097206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1261b9c1b51eSKate Stone ExecutionContext *execution_context) override { 126297206d57SZachary Turner Status error; 12633bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 12645a988416SJim Ingham 1265b9c1b51eSKate Stone switch (short_option) { 12665a988416SJim Ingham case 'b': 12675a988416SJim Ingham m_level = lldb::eDescriptionLevelBrief; 12685a988416SJim Ingham break; 126933df7cd3SJim Ingham case 'D': 127033df7cd3SJim Ingham m_use_dummy = true; 127133df7cd3SJim Ingham break; 12725a988416SJim Ingham case 'f': 12735a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 12745a988416SJim Ingham break; 12755a988416SJim Ingham case 'v': 12765a988416SJim Ingham m_level = lldb::eDescriptionLevelVerbose; 12775a988416SJim Ingham break; 12785a988416SJim Ingham case 'i': 12795a988416SJim Ingham m_internal = true; 12805a988416SJim Ingham break; 12815a988416SJim Ingham default: 1282b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1283b9c1b51eSKate Stone short_option); 12845a988416SJim Ingham break; 12855a988416SJim Ingham } 12865a988416SJim Ingham 12875a988416SJim Ingham return error; 12885a988416SJim Ingham } 12895a988416SJim Ingham 1290b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 12915a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 12925a988416SJim Ingham m_internal = false; 129333df7cd3SJim Ingham m_use_dummy = false; 12945a988416SJim Ingham } 12955a988416SJim Ingham 12961f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 129770602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_list_options); 12981f0f5b5bSZachary Turner } 12995a988416SJim Ingham 13005a988416SJim Ingham // Instance variables to hold the values for command options. 13015a988416SJim Ingham 13025a988416SJim Ingham lldb::DescriptionLevel m_level; 13035a988416SJim Ingham 13045a988416SJim Ingham bool m_internal; 130533df7cd3SJim Ingham bool m_use_dummy; 13065a988416SJim Ingham }; 13075a988416SJim Ingham 13085a988416SJim Ingham protected: 1309b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 131033df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 131133df7cd3SJim Ingham 1312b9c1b51eSKate Stone if (target == nullptr) { 13135a988416SJim Ingham result.AppendError("Invalid target. No current target or breakpoints."); 13145a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 13155a988416SJim Ingham return true; 13165a988416SJim Ingham } 13175a988416SJim Ingham 1318b9c1b51eSKate Stone const BreakpointList &breakpoints = 1319b9c1b51eSKate Stone target->GetBreakpointList(m_options.m_internal); 1320bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1321bb19a13cSSaleem Abdulrasool target->GetBreakpointList(m_options.m_internal).GetListMutex(lock); 13225a988416SJim Ingham 13235a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 13245a988416SJim Ingham 1325b9c1b51eSKate Stone if (num_breakpoints == 0) { 13265a988416SJim Ingham result.AppendMessage("No breakpoints currently set."); 13275a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 13285a988416SJim Ingham return true; 13295a988416SJim Ingham } 13305a988416SJim Ingham 13315a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 13325a988416SJim Ingham 133311eb9c64SZachary Turner if (command.empty()) { 13345a988416SJim Ingham // No breakpoint selected; show info about all currently set breakpoints. 13355a988416SJim Ingham result.AppendMessage("Current breakpoints:"); 1336b9c1b51eSKate Stone for (size_t i = 0; i < num_breakpoints; ++i) { 13375a988416SJim Ingham Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex(i).get(); 1338b842f2ecSJim Ingham if (breakpoint->AllowList()) 1339b842f2ecSJim Ingham AddBreakpointDescription(&output_stream, breakpoint, 1340b842f2ecSJim Ingham m_options.m_level); 13415a988416SJim Ingham } 13425a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1343b9c1b51eSKate Stone } else { 13445a988416SJim Ingham // Particular breakpoints selected; show info about that breakpoint. 13455a988416SJim Ingham BreakpointIDList valid_bp_ids; 1346b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1347b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1348b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 13495a988416SJim Ingham 1350b9c1b51eSKate Stone if (result.Succeeded()) { 1351b9c1b51eSKate Stone for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) { 13525a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 1353b9c1b51eSKate Stone Breakpoint *breakpoint = 1354b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1355b9c1b51eSKate Stone AddBreakpointDescription(&output_stream, breakpoint, 1356b9c1b51eSKate Stone m_options.m_level); 13575a988416SJim Ingham } 13585a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1359b9c1b51eSKate Stone } else { 13607428a18cSKate Stone result.AppendError("Invalid breakpoint ID."); 13615a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 13625a988416SJim Ingham } 13635a988416SJim Ingham } 13645a988416SJim Ingham 13655a988416SJim Ingham return result.Succeeded(); 13665a988416SJim Ingham } 13675a988416SJim Ingham 13685a988416SJim Ingham private: 13695a988416SJim Ingham CommandOptions m_options; 13705a988416SJim Ingham }; 13715a988416SJim Ingham 13725a988416SJim Ingham //------------------------------------------------------------------------- 13735a988416SJim Ingham // CommandObjectBreakpointClear 13745a988416SJim Ingham //------------------------------------------------------------------------- 13751f0f5b5bSZachary Turner #pragma mark Clear::CommandOptions 13761f0f5b5bSZachary Turner 13771f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_clear_options[] = { 13781f0f5b5bSZachary Turner // clang-format off 13791f0f5b5bSZachary 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." }, 13801f0f5b5bSZachary Turner { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Specify the breakpoint by source location at this particular line." } 13811f0f5b5bSZachary Turner // clang-format on 13821f0f5b5bSZachary Turner }; 13831f0f5b5bSZachary Turner 13845a988416SJim Ingham #pragma mark Clear 13855a988416SJim Ingham 1386b9c1b51eSKate Stone class CommandObjectBreakpointClear : public CommandObjectParsed { 13875a988416SJim Ingham public: 1388b9c1b51eSKate Stone typedef enum BreakpointClearType { 13895a988416SJim Ingham eClearTypeInvalid, 13905a988416SJim Ingham eClearTypeFileAndLine 13915a988416SJim Ingham } BreakpointClearType; 13925a988416SJim Ingham 13937428a18cSKate Stone CommandObjectBreakpointClear(CommandInterpreter &interpreter) 13947428a18cSKate Stone : CommandObjectParsed(interpreter, "breakpoint clear", 1395b9c1b51eSKate Stone "Delete or disable breakpoints matching the " 1396b9c1b51eSKate Stone "specified source file and line.", 13975a988416SJim Ingham "breakpoint clear <cmd-options>"), 1398b9c1b51eSKate Stone m_options() {} 13995a988416SJim Ingham 14009e85e5a8SEugene Zelenko ~CommandObjectBreakpointClear() override = default; 14015a988416SJim Ingham 1402b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 14035a988416SJim Ingham 1404b9c1b51eSKate Stone class CommandOptions : public Options { 14055a988416SJim Ingham public: 1406b9c1b51eSKate Stone CommandOptions() : Options(), m_filename(), m_line_num(0) {} 14075a988416SJim Ingham 14089e85e5a8SEugene Zelenko ~CommandOptions() override = default; 14095a988416SJim Ingham 141097206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1411b9c1b51eSKate Stone ExecutionContext *execution_context) override { 141297206d57SZachary Turner Status error; 14133bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 14145a988416SJim Ingham 1415b9c1b51eSKate Stone switch (short_option) { 14165a988416SJim Ingham case 'f': 14175a988416SJim Ingham m_filename.assign(option_arg); 14185a988416SJim Ingham break; 14195a988416SJim Ingham 14205a988416SJim Ingham case 'l': 1421fe11483bSZachary Turner option_arg.getAsInteger(0, m_line_num); 14225a988416SJim Ingham break; 14235a988416SJim Ingham 14245a988416SJim Ingham default: 1425b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1426b9c1b51eSKate Stone short_option); 14275a988416SJim Ingham break; 14285a988416SJim Ingham } 14295a988416SJim Ingham 14305a988416SJim Ingham return error; 14315a988416SJim Ingham } 14325a988416SJim Ingham 1433b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 14345a988416SJim Ingham m_filename.clear(); 14355a988416SJim Ingham m_line_num = 0; 14365a988416SJim Ingham } 14375a988416SJim Ingham 14381f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 143970602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_clear_options); 14401f0f5b5bSZachary Turner } 14415a988416SJim Ingham 14425a988416SJim Ingham // Instance variables to hold the values for command options. 14435a988416SJim Ingham 14445a988416SJim Ingham std::string m_filename; 14455a988416SJim Ingham uint32_t m_line_num; 14465a988416SJim Ingham }; 14475a988416SJim Ingham 14485a988416SJim Ingham protected: 1449b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1450893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1451b9c1b51eSKate Stone if (target == nullptr) { 14525a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 14535a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 14545a988416SJim Ingham return false; 14555a988416SJim Ingham } 14565a988416SJim Ingham 145705097246SAdrian Prantl // The following are the various types of breakpoints that could be 145805097246SAdrian Prantl // cleared: 14595a988416SJim Ingham // 1). -f -l (clearing breakpoint by source location) 14605a988416SJim Ingham 14615a988416SJim Ingham BreakpointClearType break_type = eClearTypeInvalid; 14625a988416SJim Ingham 14635a988416SJim Ingham if (m_options.m_line_num != 0) 14645a988416SJim Ingham break_type = eClearTypeFileAndLine; 14655a988416SJim Ingham 1466bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1467bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 14685a988416SJim Ingham 14695a988416SJim Ingham BreakpointList &breakpoints = target->GetBreakpointList(); 14705a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 14715a988416SJim Ingham 14725a988416SJim Ingham // Early return if there's no breakpoint at all. 1473b9c1b51eSKate Stone if (num_breakpoints == 0) { 14745a988416SJim Ingham result.AppendError("Breakpoint clear: No breakpoint cleared."); 14755a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 14765a988416SJim Ingham return result.Succeeded(); 14775a988416SJim Ingham } 14785a988416SJim Ingham 14795a988416SJim Ingham // Find matching breakpoints and delete them. 14805a988416SJim Ingham 14815a988416SJim Ingham // First create a copy of all the IDs. 14825a988416SJim Ingham std::vector<break_id_t> BreakIDs; 14835a988416SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) 14849e85e5a8SEugene Zelenko BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID()); 14855a988416SJim Ingham 14865a988416SJim Ingham int num_cleared = 0; 14875a988416SJim Ingham StreamString ss; 1488b9c1b51eSKate Stone switch (break_type) { 14895a988416SJim Ingham case eClearTypeFileAndLine: // Breakpoint by source position 14905a988416SJim Ingham { 14915a988416SJim Ingham const ConstString filename(m_options.m_filename.c_str()); 14925a988416SJim Ingham BreakpointLocationCollection loc_coll; 14935a988416SJim Ingham 1494b9c1b51eSKate Stone for (size_t i = 0; i < num_breakpoints; ++i) { 14955a988416SJim Ingham Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); 14965a988416SJim Ingham 1497b9c1b51eSKate Stone if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) { 1498b9c1b51eSKate Stone // If the collection size is 0, it's a full match and we can just 1499b9c1b51eSKate Stone // remove the breakpoint. 1500b9c1b51eSKate Stone if (loc_coll.GetSize() == 0) { 15015a988416SJim Ingham bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); 15025a988416SJim Ingham ss.EOL(); 15035a988416SJim Ingham target->RemoveBreakpointByID(bp->GetID()); 15045a988416SJim Ingham ++num_cleared; 15055a988416SJim Ingham } 15065a988416SJim Ingham } 15075a988416SJim Ingham } 1508b9c1b51eSKate Stone } break; 15095a988416SJim Ingham 15105a988416SJim Ingham default: 15115a988416SJim Ingham break; 15125a988416SJim Ingham } 15135a988416SJim Ingham 1514b9c1b51eSKate Stone if (num_cleared > 0) { 15155a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 15165a988416SJim Ingham output_stream.Printf("%d breakpoints cleared:\n", num_cleared); 1517c156427dSZachary Turner output_stream << ss.GetString(); 15185a988416SJim Ingham output_stream.EOL(); 15195a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1520b9c1b51eSKate Stone } else { 15215a988416SJim Ingham result.AppendError("Breakpoint clear: No breakpoint cleared."); 15225a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 15235a988416SJim Ingham } 15245a988416SJim Ingham 15255a988416SJim Ingham return result.Succeeded(); 15265a988416SJim Ingham } 15275a988416SJim Ingham 15285a988416SJim Ingham private: 15295a988416SJim Ingham CommandOptions m_options; 15305a988416SJim Ingham }; 15315a988416SJim Ingham 15325a988416SJim Ingham //------------------------------------------------------------------------- 15335a988416SJim Ingham // CommandObjectBreakpointDelete 15345a988416SJim Ingham //------------------------------------------------------------------------- 15351f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_delete_options[] = { 15361f0f5b5bSZachary Turner // clang-format off 15371f0f5b5bSZachary Turner { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete all breakpoints without querying for confirmation." }, 15381f0f5b5bSZachary 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." }, 15391f0f5b5bSZachary Turner // clang-format on 15401f0f5b5bSZachary Turner }; 15411f0f5b5bSZachary Turner 15425a988416SJim Ingham #pragma mark Delete 15435a988416SJim Ingham 1544b9c1b51eSKate Stone class CommandObjectBreakpointDelete : public CommandObjectParsed { 15455a988416SJim Ingham public: 1546b9c1b51eSKate Stone CommandObjectBreakpointDelete(CommandInterpreter &interpreter) 1547b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "breakpoint delete", 1548b9c1b51eSKate Stone "Delete the specified breakpoint(s). If no " 1549b9c1b51eSKate Stone "breakpoints are specified, delete them all.", 15509e85e5a8SEugene Zelenko nullptr), 1551b9c1b51eSKate Stone m_options() { 15525a988416SJim Ingham CommandArgumentEntry arg; 1553b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1554b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1555b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1556b9c1b51eSKate Stone // arguments vector. 15575a988416SJim Ingham m_arguments.push_back(arg); 15585a988416SJim Ingham } 15595a988416SJim Ingham 15609e85e5a8SEugene Zelenko ~CommandObjectBreakpointDelete() override = default; 15615a988416SJim Ingham 1562b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 156333df7cd3SJim Ingham 1564b9c1b51eSKate Stone class CommandOptions : public Options { 156533df7cd3SJim Ingham public: 1566b9c1b51eSKate Stone CommandOptions() : Options(), m_use_dummy(false), m_force(false) {} 156733df7cd3SJim Ingham 15689e85e5a8SEugene Zelenko ~CommandOptions() override = default; 156933df7cd3SJim Ingham 157097206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1571b9c1b51eSKate Stone ExecutionContext *execution_context) override { 157297206d57SZachary Turner Status error; 157333df7cd3SJim Ingham const int short_option = m_getopt_table[option_idx].val; 157433df7cd3SJim Ingham 1575b9c1b51eSKate Stone switch (short_option) { 157633df7cd3SJim Ingham case 'f': 157733df7cd3SJim Ingham m_force = true; 157833df7cd3SJim Ingham break; 157933df7cd3SJim Ingham 158033df7cd3SJim Ingham case 'D': 158133df7cd3SJim Ingham m_use_dummy = true; 158233df7cd3SJim Ingham break; 158333df7cd3SJim Ingham 158433df7cd3SJim Ingham default: 1585b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1586b9c1b51eSKate Stone short_option); 158733df7cd3SJim Ingham break; 158833df7cd3SJim Ingham } 158933df7cd3SJim Ingham 159033df7cd3SJim Ingham return error; 159133df7cd3SJim Ingham } 159233df7cd3SJim Ingham 1593b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 159433df7cd3SJim Ingham m_use_dummy = false; 159533df7cd3SJim Ingham m_force = false; 159633df7cd3SJim Ingham } 159733df7cd3SJim Ingham 15981f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 159970602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_delete_options); 16001f0f5b5bSZachary Turner } 160133df7cd3SJim Ingham 160233df7cd3SJim Ingham // Instance variables to hold the values for command options. 160333df7cd3SJim Ingham bool m_use_dummy; 160433df7cd3SJim Ingham bool m_force; 160533df7cd3SJim Ingham }; 160633df7cd3SJim Ingham 16075a988416SJim Ingham protected: 1608b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 160933df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 161033df7cd3SJim Ingham 1611b9c1b51eSKate Stone if (target == nullptr) { 16125a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 16135a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 16145a988416SJim Ingham return false; 16155a988416SJim Ingham } 16165a988416SJim Ingham 1617bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1618bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 16195a988416SJim Ingham 16205a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 16215a988416SJim Ingham 16225a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 16235a988416SJim Ingham 1624b9c1b51eSKate Stone if (num_breakpoints == 0) { 16255a988416SJim Ingham result.AppendError("No breakpoints exist to be deleted."); 16265a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 16275a988416SJim Ingham return false; 16285a988416SJim Ingham } 16295a988416SJim Ingham 163011eb9c64SZachary Turner if (command.empty()) { 1631b9c1b51eSKate Stone if (!m_options.m_force && 1632b9c1b51eSKate Stone !m_interpreter.Confirm( 1633b9c1b51eSKate Stone "About to delete all breakpoints, do you want to do that?", 1634b9c1b51eSKate Stone true)) { 16355a988416SJim Ingham result.AppendMessage("Operation cancelled..."); 1636b9c1b51eSKate Stone } else { 1637b842f2ecSJim Ingham target->RemoveAllowedBreakpoints(); 1638b9c1b51eSKate Stone result.AppendMessageWithFormat( 1639b9c1b51eSKate Stone "All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", 1640b9c1b51eSKate Stone (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : ""); 16415a988416SJim Ingham } 16425a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1643b9c1b51eSKate Stone } else { 16445a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 16455a988416SJim Ingham BreakpointIDList valid_bp_ids; 1646b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1647b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1648b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::deletePerm); 16495a988416SJim Ingham 1650b9c1b51eSKate Stone if (result.Succeeded()) { 16515a988416SJim Ingham int delete_count = 0; 16525a988416SJim Ingham int disable_count = 0; 16535a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1654b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 16555a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 16565a988416SJim Ingham 1657b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1658b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1659b9c1b51eSKate Stone Breakpoint *breakpoint = 1660b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1661b9c1b51eSKate Stone BreakpointLocation *location = 1662b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1663b9c1b51eSKate Stone // It makes no sense to try to delete individual locations, so we 1664b9c1b51eSKate Stone // disable them instead. 1665b9c1b51eSKate Stone if (location) { 16665a988416SJim Ingham location->SetEnabled(false); 16675a988416SJim Ingham ++disable_count; 16685a988416SJim Ingham } 1669b9c1b51eSKate Stone } else { 16705a988416SJim Ingham target->RemoveBreakpointByID(cur_bp_id.GetBreakpointID()); 16715a988416SJim Ingham ++delete_count; 16725a988416SJim Ingham } 16735a988416SJim Ingham } 16745a988416SJim Ingham } 1675b9c1b51eSKate Stone result.AppendMessageWithFormat( 1676b9c1b51eSKate Stone "%d breakpoints deleted; %d breakpoint locations disabled.\n", 16775a988416SJim Ingham delete_count, disable_count); 16785a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 16795a988416SJim Ingham } 16805a988416SJim Ingham } 16815a988416SJim Ingham return result.Succeeded(); 16825a988416SJim Ingham } 16839e85e5a8SEugene Zelenko 168433df7cd3SJim Ingham private: 168533df7cd3SJim Ingham CommandOptions m_options; 168633df7cd3SJim Ingham }; 168733df7cd3SJim Ingham 168830fdc8d8SChris Lattner //------------------------------------------------------------------------- 16895e09c8c3SJim Ingham // CommandObjectBreakpointName 16905e09c8c3SJim Ingham //------------------------------------------------------------------------- 16915e09c8c3SJim Ingham 16927428a18cSKate Stone static OptionDefinition g_breakpoint_name_options[] = { 1693ac9c3a62SKate Stone // clang-format off 1694ac9c3a62SKate Stone {LLDB_OPT_SET_1, false, "name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."}, 1695ac9c3a62SKate Stone {LLDB_OPT_SET_2, false, "breakpoint-id", 'B', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointID, "Specify a breakpoint ID to use."}, 1696b842f2ecSJim 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."}, 1697e9632ebaSJim Ingham {LLDB_OPT_SET_4, false, "help-string", 'H', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNone, "A help string describing the purpose of this name."}, 1698ac9c3a62SKate Stone // clang-format on 16995e09c8c3SJim Ingham }; 1700b9c1b51eSKate Stone class BreakpointNameOptionGroup : public OptionGroup { 17015e09c8c3SJim Ingham public: 1702b9c1b51eSKate Stone BreakpointNameOptionGroup() 1703b9c1b51eSKate Stone : OptionGroup(), m_breakpoint(LLDB_INVALID_BREAK_ID), m_use_dummy(false) { 17045e09c8c3SJim Ingham } 17055e09c8c3SJim Ingham 17069e85e5a8SEugene Zelenko ~BreakpointNameOptionGroup() override = default; 17075e09c8c3SJim Ingham 17081f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 170970602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_name_options); 17105e09c8c3SJim Ingham } 17115e09c8c3SJim Ingham 171297206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1713b9c1b51eSKate Stone ExecutionContext *execution_context) override { 171497206d57SZachary Turner Status error; 17155e09c8c3SJim Ingham const int short_option = g_breakpoint_name_options[option_idx].short_option; 17165e09c8c3SJim Ingham 1717b9c1b51eSKate Stone switch (short_option) { 17185e09c8c3SJim Ingham case 'N': 1719fe11483bSZachary Turner if (BreakpointID::StringIsBreakpointName(option_arg, error) && 1720b9c1b51eSKate Stone error.Success()) 1721fe11483bSZachary Turner m_name.SetValueFromString(option_arg); 17225e09c8c3SJim Ingham break; 17235e09c8c3SJim Ingham case 'B': 1724fe11483bSZachary Turner if (m_breakpoint.SetValueFromString(option_arg).Fail()) 1725b9c1b51eSKate Stone error.SetErrorStringWithFormat( 17268cef4b0bSZachary Turner "unrecognized value \"%s\" for breakpoint", 1727fe11483bSZachary Turner option_arg.str().c_str()); 17285e09c8c3SJim Ingham break; 17295e09c8c3SJim Ingham case 'D': 1730fe11483bSZachary Turner if (m_use_dummy.SetValueFromString(option_arg).Fail()) 1731b9c1b51eSKate Stone error.SetErrorStringWithFormat( 17328cef4b0bSZachary Turner "unrecognized value \"%s\" for use-dummy", 1733fe11483bSZachary Turner option_arg.str().c_str()); 17345e09c8c3SJim Ingham break; 1735e9632ebaSJim Ingham case 'H': 1736e9632ebaSJim Ingham m_help_string.SetValueFromString(option_arg); 1737e9632ebaSJim Ingham break; 17385e09c8c3SJim Ingham 17395e09c8c3SJim Ingham default: 1740b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized short option '%c'", 1741b9c1b51eSKate Stone short_option); 17425e09c8c3SJim Ingham break; 17435e09c8c3SJim Ingham } 17445e09c8c3SJim Ingham return error; 17455e09c8c3SJim Ingham } 17465e09c8c3SJim Ingham 1747b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 17485e09c8c3SJim Ingham m_name.Clear(); 17495e09c8c3SJim Ingham m_breakpoint.Clear(); 17505e09c8c3SJim Ingham m_use_dummy.Clear(); 17515e09c8c3SJim Ingham m_use_dummy.SetDefaultValue(false); 1752e9632ebaSJim Ingham m_help_string.Clear(); 17535e09c8c3SJim Ingham } 17545e09c8c3SJim Ingham 17555e09c8c3SJim Ingham OptionValueString m_name; 17565e09c8c3SJim Ingham OptionValueUInt64 m_breakpoint; 17575e09c8c3SJim Ingham OptionValueBoolean m_use_dummy; 1758e9632ebaSJim Ingham OptionValueString m_help_string; 17595e09c8c3SJim Ingham }; 17605e09c8c3SJim Ingham 1761b842f2ecSJim Ingham static OptionDefinition g_breakpoint_access_options[] = { 1762b842f2ecSJim Ingham // clang-format off 1763b842f2ecSJim 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."}, 1764b842f2ecSJim 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."}, 1765b842f2ecSJim 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."}, 1766b842f2ecSJim Ingham // clang-format on 1767b842f2ecSJim Ingham }; 1768b842f2ecSJim Ingham 1769b842f2ecSJim Ingham class BreakpointAccessOptionGroup : public OptionGroup 1770b842f2ecSJim Ingham { 1771b842f2ecSJim Ingham public: 1772b842f2ecSJim Ingham BreakpointAccessOptionGroup() : 1773b842f2ecSJim Ingham OptionGroup() 1774b842f2ecSJim Ingham {} 1775b842f2ecSJim Ingham 1776b842f2ecSJim Ingham ~BreakpointAccessOptionGroup() override = default; 1777b842f2ecSJim Ingham 1778b842f2ecSJim Ingham llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 1779b842f2ecSJim Ingham return llvm::makeArrayRef(g_breakpoint_access_options); 1780b842f2ecSJim Ingham } 1781b842f2ecSJim Ingham Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1782b842f2ecSJim Ingham ExecutionContext *execution_context) override { 1783b842f2ecSJim Ingham Status error; 1784b842f2ecSJim Ingham const int short_option 1785b842f2ecSJim Ingham = g_breakpoint_access_options[option_idx].short_option; 1786b842f2ecSJim Ingham 1787b842f2ecSJim Ingham switch (short_option) { 1788b842f2ecSJim Ingham case 'L': { 1789b842f2ecSJim Ingham bool value, success; 179047cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1791b842f2ecSJim Ingham if (success) { 1792b842f2ecSJim Ingham m_permissions.SetAllowList(value); 1793b842f2ecSJim Ingham } else 1794b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1795b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1796b842f2ecSJim Ingham option_arg.str().c_str()); 1797b842f2ecSJim Ingham } break; 1798b842f2ecSJim Ingham case 'A': { 1799b842f2ecSJim Ingham bool value, success; 180047cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1801b842f2ecSJim Ingham if (success) { 1802b842f2ecSJim Ingham m_permissions.SetAllowDisable(value); 1803b842f2ecSJim Ingham } else 1804b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1805b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1806b842f2ecSJim Ingham option_arg.str().c_str()); 1807b842f2ecSJim Ingham } break; 1808b842f2ecSJim Ingham case 'D': { 1809b842f2ecSJim Ingham bool value, success; 181047cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1811b842f2ecSJim Ingham if (success) { 1812b842f2ecSJim Ingham m_permissions.SetAllowDelete(value); 1813b842f2ecSJim Ingham } else 1814b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1815b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1816b842f2ecSJim Ingham option_arg.str().c_str()); 1817b842f2ecSJim Ingham } break; 1818b842f2ecSJim Ingham 1819b842f2ecSJim Ingham } 1820b842f2ecSJim Ingham 1821b842f2ecSJim Ingham return error; 1822b842f2ecSJim Ingham } 1823b842f2ecSJim Ingham 1824b842f2ecSJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 1825b842f2ecSJim Ingham } 1826b842f2ecSJim Ingham 1827b842f2ecSJim Ingham const BreakpointName::Permissions &GetPermissions() const 1828b842f2ecSJim Ingham { 1829b842f2ecSJim Ingham return m_permissions; 1830b842f2ecSJim Ingham } 1831b842f2ecSJim Ingham BreakpointName::Permissions m_permissions; 1832b842f2ecSJim Ingham }; 1833b842f2ecSJim Ingham 1834b842f2ecSJim Ingham class CommandObjectBreakpointNameConfigure : public CommandObjectParsed { 1835b842f2ecSJim Ingham public: 1836b842f2ecSJim Ingham CommandObjectBreakpointNameConfigure(CommandInterpreter &interpreter) 1837b842f2ecSJim Ingham : CommandObjectParsed( 1838b842f2ecSJim Ingham interpreter, "configure", "Configure the options for the breakpoint" 1839b842f2ecSJim Ingham " name provided. " 1840b842f2ecSJim Ingham "If you provide a breakpoint id, the options will be copied from " 1841b842f2ecSJim Ingham "the breakpoint, otherwise only the options specified will be set " 1842b842f2ecSJim Ingham "on the name.", 1843b842f2ecSJim Ingham "breakpoint name configure <command-options> " 1844b842f2ecSJim Ingham "<breakpoint-name-list>"), 1845b842f2ecSJim Ingham m_bp_opts(), m_option_group() { 1846b842f2ecSJim Ingham // Create the first variant for the first (and only) argument for this 1847b842f2ecSJim Ingham // command. 1848b842f2ecSJim Ingham CommandArgumentEntry arg1; 1849b842f2ecSJim Ingham CommandArgumentData id_arg; 1850b842f2ecSJim Ingham id_arg.arg_type = eArgTypeBreakpointName; 1851b842f2ecSJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 1852b842f2ecSJim Ingham arg1.push_back(id_arg); 1853b842f2ecSJim Ingham m_arguments.push_back(arg1); 1854b842f2ecSJim Ingham 1855b842f2ecSJim Ingham m_option_group.Append(&m_bp_opts, 1856b842f2ecSJim Ingham LLDB_OPT_SET_ALL, 1857b842f2ecSJim Ingham LLDB_OPT_SET_1); 1858b842f2ecSJim Ingham m_option_group.Append(&m_access_options, 1859b842f2ecSJim Ingham LLDB_OPT_SET_ALL, 1860b842f2ecSJim Ingham LLDB_OPT_SET_ALL); 1861e9632ebaSJim Ingham m_option_group.Append(&m_bp_id, 1862e9632ebaSJim Ingham LLDB_OPT_SET_2|LLDB_OPT_SET_4, 1863e9632ebaSJim Ingham LLDB_OPT_SET_ALL); 1864b842f2ecSJim Ingham m_option_group.Finalize(); 1865b842f2ecSJim Ingham } 1866b842f2ecSJim Ingham 1867b842f2ecSJim Ingham ~CommandObjectBreakpointNameConfigure() override = default; 1868b842f2ecSJim Ingham 1869b842f2ecSJim Ingham Options *GetOptions() override { return &m_option_group; } 1870b842f2ecSJim Ingham 1871b842f2ecSJim Ingham protected: 1872b842f2ecSJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 1873b842f2ecSJim Ingham 1874b842f2ecSJim Ingham const size_t argc = command.GetArgumentCount(); 1875b842f2ecSJim Ingham if (argc == 0) { 1876b842f2ecSJim Ingham result.AppendError("No names provided."); 1877b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1878b842f2ecSJim Ingham return false; 1879b842f2ecSJim Ingham } 1880b842f2ecSJim Ingham 1881b842f2ecSJim Ingham Target *target = 1882b842f2ecSJim Ingham GetSelectedOrDummyTarget(false); 1883b842f2ecSJim Ingham 1884b842f2ecSJim Ingham if (target == nullptr) { 1885b842f2ecSJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 1886b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1887b842f2ecSJim Ingham return false; 1888b842f2ecSJim Ingham } 1889b842f2ecSJim Ingham 1890b842f2ecSJim Ingham std::unique_lock<std::recursive_mutex> lock; 1891b842f2ecSJim Ingham target->GetBreakpointList().GetListMutex(lock); 1892b842f2ecSJim Ingham 1893b842f2ecSJim Ingham // Make a pass through first to see that all the names are legal. 1894b842f2ecSJim Ingham for (auto &entry : command.entries()) { 1895b842f2ecSJim Ingham Status error; 1896b842f2ecSJim Ingham if (!BreakpointID::StringIsBreakpointName(entry.ref, error)) 1897b842f2ecSJim Ingham { 1898b842f2ecSJim Ingham result.AppendErrorWithFormat("Invalid breakpoint name: %s - %s", 1899b842f2ecSJim Ingham entry.c_str(), error.AsCString()); 1900b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1901b842f2ecSJim Ingham return false; 1902b842f2ecSJim Ingham } 1903b842f2ecSJim Ingham } 190405097246SAdrian Prantl // Now configure them, we already pre-checked the names so we don't need to 190505097246SAdrian Prantl // check the error: 1906b842f2ecSJim Ingham BreakpointSP bp_sp; 1907b842f2ecSJim Ingham if (m_bp_id.m_breakpoint.OptionWasSet()) 1908b842f2ecSJim Ingham { 1909b842f2ecSJim Ingham lldb::break_id_t bp_id = m_bp_id.m_breakpoint.GetUInt64Value(); 1910b842f2ecSJim Ingham bp_sp = target->GetBreakpointByID(bp_id); 1911b842f2ecSJim Ingham if (!bp_sp) 1912b842f2ecSJim Ingham { 1913b842f2ecSJim Ingham result.AppendErrorWithFormatv("Could not find specified breakpoint {0}", 1914b842f2ecSJim Ingham bp_id); 1915b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1916b842f2ecSJim Ingham return false; 1917b842f2ecSJim Ingham } 1918b842f2ecSJim Ingham } 1919b842f2ecSJim Ingham 1920b842f2ecSJim Ingham Status error; 1921b842f2ecSJim Ingham for (auto &entry : command.entries()) { 1922b842f2ecSJim Ingham ConstString name(entry.c_str()); 1923b842f2ecSJim Ingham BreakpointName *bp_name = target->FindBreakpointName(name, true, error); 1924b842f2ecSJim Ingham if (!bp_name) 1925b842f2ecSJim Ingham continue; 1926e9632ebaSJim Ingham if (m_bp_id.m_help_string.OptionWasSet()) 1927e9632ebaSJim Ingham bp_name->SetHelp(m_bp_id.m_help_string.GetStringValue().str().c_str()); 1928e9632ebaSJim Ingham 1929b842f2ecSJim Ingham if (bp_sp) 1930b842f2ecSJim Ingham target->ConfigureBreakpointName(*bp_name, 1931b842f2ecSJim Ingham *bp_sp->GetOptions(), 1932b842f2ecSJim Ingham m_access_options.GetPermissions()); 1933b842f2ecSJim Ingham else 1934b842f2ecSJim Ingham target->ConfigureBreakpointName(*bp_name, 1935b842f2ecSJim Ingham m_bp_opts.GetBreakpointOptions(), 1936b842f2ecSJim Ingham m_access_options.GetPermissions()); 1937b842f2ecSJim Ingham } 1938b842f2ecSJim Ingham return true; 1939b842f2ecSJim Ingham } 1940b842f2ecSJim Ingham 1941b842f2ecSJim Ingham private: 1942b842f2ecSJim Ingham BreakpointNameOptionGroup m_bp_id; // Only using the id part of this. 1943b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 1944b842f2ecSJim Ingham BreakpointAccessOptionGroup m_access_options; 1945b842f2ecSJim Ingham OptionGroupOptions m_option_group; 1946b842f2ecSJim Ingham }; 1947b842f2ecSJim Ingham 1948b9c1b51eSKate Stone class CommandObjectBreakpointNameAdd : public CommandObjectParsed { 19495e09c8c3SJim Ingham public: 1950b9c1b51eSKate Stone CommandObjectBreakpointNameAdd(CommandInterpreter &interpreter) 1951b9c1b51eSKate Stone : CommandObjectParsed( 1952b9c1b51eSKate Stone interpreter, "add", "Add a name to the breakpoints provided.", 19535e09c8c3SJim Ingham "breakpoint name add <command-options> <breakpoint-id-list>"), 1954b9c1b51eSKate Stone m_name_options(), m_option_group() { 1955b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 1956b9c1b51eSKate Stone // command. 19575e09c8c3SJim Ingham CommandArgumentEntry arg1; 19585e09c8c3SJim Ingham CommandArgumentData id_arg; 19595e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 19605e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 19615e09c8c3SJim Ingham arg1.push_back(id_arg); 19625e09c8c3SJim Ingham m_arguments.push_back(arg1); 19635e09c8c3SJim Ingham 19645e09c8c3SJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 19655e09c8c3SJim Ingham m_option_group.Finalize(); 19665e09c8c3SJim Ingham } 19675e09c8c3SJim Ingham 19689e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameAdd() override = default; 19695e09c8c3SJim Ingham 1970b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 19715e09c8c3SJim Ingham 19725e09c8c3SJim Ingham protected: 1973b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1974b9c1b51eSKate Stone if (!m_name_options.m_name.OptionWasSet()) { 19755e09c8c3SJim Ingham result.SetError("No name option provided."); 19765e09c8c3SJim Ingham return false; 19775e09c8c3SJim Ingham } 19785e09c8c3SJim Ingham 1979b9c1b51eSKate Stone Target *target = 1980b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 19815e09c8c3SJim Ingham 1982b9c1b51eSKate Stone if (target == nullptr) { 19835e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 19845e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 19855e09c8c3SJim Ingham return false; 19865e09c8c3SJim Ingham } 19875e09c8c3SJim Ingham 1988bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1989bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 19905e09c8c3SJim Ingham 19915e09c8c3SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 19925e09c8c3SJim Ingham 19935e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 1994b9c1b51eSKate Stone if (num_breakpoints == 0) { 19955e09c8c3SJim Ingham result.SetError("No breakpoints, cannot add names."); 19965e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 19975e09c8c3SJim Ingham return false; 19985e09c8c3SJim Ingham } 19995e09c8c3SJim Ingham 20005e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 20015e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 2002b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 2003b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 2004b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 20055e09c8c3SJim Ingham 2006b9c1b51eSKate Stone if (result.Succeeded()) { 2007b9c1b51eSKate Stone if (valid_bp_ids.GetSize() == 0) { 20085e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot add names."); 20095e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20105e09c8c3SJim Ingham return false; 20115e09c8c3SJim Ingham } 20125e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 2013b842f2ecSJim Ingham const char *bp_name = m_name_options.m_name.GetCurrentValue(); 2014b842f2ecSJim Ingham Status error; // This error reports illegal names, but we've already 2015b842f2ecSJim Ingham // checked that, so we don't need to check it again here. 2016b9c1b51eSKate Stone for (size_t index = 0; index < num_valid_ids; index++) { 2017b9c1b51eSKate Stone lldb::break_id_t bp_id = 2018b9c1b51eSKate Stone valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 20195e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 2020b842f2ecSJim Ingham target->AddNameToBreakpoint(bp_sp, bp_name, error); 20215e09c8c3SJim Ingham } 20225e09c8c3SJim Ingham } 20235e09c8c3SJim Ingham 20245e09c8c3SJim Ingham return true; 20255e09c8c3SJim Ingham } 20265e09c8c3SJim Ingham 20275e09c8c3SJim Ingham private: 20285e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 20295e09c8c3SJim Ingham OptionGroupOptions m_option_group; 20305e09c8c3SJim Ingham }; 20315e09c8c3SJim Ingham 2032b9c1b51eSKate Stone class CommandObjectBreakpointNameDelete : public CommandObjectParsed { 20335e09c8c3SJim Ingham public: 2034b9c1b51eSKate Stone CommandObjectBreakpointNameDelete(CommandInterpreter &interpreter) 2035b9c1b51eSKate Stone : CommandObjectParsed( 2036b9c1b51eSKate Stone interpreter, "delete", 20375e09c8c3SJim Ingham "Delete a name from the breakpoints provided.", 20385e09c8c3SJim Ingham "breakpoint name delete <command-options> <breakpoint-id-list>"), 2039b9c1b51eSKate Stone m_name_options(), m_option_group() { 2040b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 2041b9c1b51eSKate Stone // command. 20425e09c8c3SJim Ingham CommandArgumentEntry arg1; 20435e09c8c3SJim Ingham CommandArgumentData id_arg; 20445e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 20455e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 20465e09c8c3SJim Ingham arg1.push_back(id_arg); 20475e09c8c3SJim Ingham m_arguments.push_back(arg1); 20485e09c8c3SJim Ingham 20495e09c8c3SJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 20505e09c8c3SJim Ingham m_option_group.Finalize(); 20515e09c8c3SJim Ingham } 20525e09c8c3SJim Ingham 20539e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameDelete() override = default; 20545e09c8c3SJim Ingham 2055b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 20565e09c8c3SJim Ingham 20575e09c8c3SJim Ingham protected: 2058b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 2059b9c1b51eSKate Stone if (!m_name_options.m_name.OptionWasSet()) { 20605e09c8c3SJim Ingham result.SetError("No name option provided."); 20615e09c8c3SJim Ingham return false; 20625e09c8c3SJim Ingham } 20635e09c8c3SJim Ingham 2064b9c1b51eSKate Stone Target *target = 2065b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 20665e09c8c3SJim Ingham 2067b9c1b51eSKate Stone if (target == nullptr) { 20685e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 20695e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20705e09c8c3SJim Ingham return false; 20715e09c8c3SJim Ingham } 20725e09c8c3SJim Ingham 2073bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 2074bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 20755e09c8c3SJim Ingham 20765e09c8c3SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 20775e09c8c3SJim Ingham 20785e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 2079b9c1b51eSKate Stone if (num_breakpoints == 0) { 20805e09c8c3SJim Ingham result.SetError("No breakpoints, cannot delete names."); 20815e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20825e09c8c3SJim Ingham return false; 20835e09c8c3SJim Ingham } 20845e09c8c3SJim Ingham 20855e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 20865e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 2087b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 2088b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 2089b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::deletePerm); 20905e09c8c3SJim Ingham 2091b9c1b51eSKate Stone if (result.Succeeded()) { 2092b9c1b51eSKate Stone if (valid_bp_ids.GetSize() == 0) { 20935e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot delete names."); 20945e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20955e09c8c3SJim Ingham return false; 20965e09c8c3SJim Ingham } 2097b842f2ecSJim Ingham ConstString bp_name(m_name_options.m_name.GetCurrentValue()); 20985e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 2099b9c1b51eSKate Stone for (size_t index = 0; index < num_valid_ids; index++) { 2100b9c1b51eSKate Stone lldb::break_id_t bp_id = 2101b9c1b51eSKate Stone valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 21025e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 2103b842f2ecSJim Ingham target->RemoveNameFromBreakpoint(bp_sp, bp_name); 21045e09c8c3SJim Ingham } 21055e09c8c3SJim Ingham } 21065e09c8c3SJim Ingham 21075e09c8c3SJim Ingham return true; 21085e09c8c3SJim Ingham } 21095e09c8c3SJim Ingham 21105e09c8c3SJim Ingham private: 21115e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 21125e09c8c3SJim Ingham OptionGroupOptions m_option_group; 21135e09c8c3SJim Ingham }; 21145e09c8c3SJim Ingham 2115b9c1b51eSKate Stone class CommandObjectBreakpointNameList : public CommandObjectParsed { 21165e09c8c3SJim Ingham public: 2117b9c1b51eSKate Stone CommandObjectBreakpointNameList(CommandInterpreter &interpreter) 2118b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "list", 2119b842f2ecSJim Ingham "List either the names for a breakpoint or info " 2120b842f2ecSJim Ingham "about a given name. With no arguments, lists all " 2121b842f2ecSJim Ingham "names", 21225e09c8c3SJim Ingham "breakpoint name list <command-options>"), 2123b9c1b51eSKate Stone m_name_options(), m_option_group() { 2124b842f2ecSJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_3, LLDB_OPT_SET_ALL); 21255e09c8c3SJim Ingham m_option_group.Finalize(); 21265e09c8c3SJim Ingham } 21275e09c8c3SJim Ingham 21289e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameList() override = default; 21295e09c8c3SJim Ingham 2130b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 21315e09c8c3SJim Ingham 21325e09c8c3SJim Ingham protected: 2133b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 2134b9c1b51eSKate Stone Target *target = 2135b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 21365e09c8c3SJim Ingham 2137b9c1b51eSKate Stone if (target == nullptr) { 21385e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 21395e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 21405e09c8c3SJim Ingham return false; 21415e09c8c3SJim Ingham } 21425e09c8c3SJim Ingham 2143b842f2ecSJim Ingham 2144b842f2ecSJim Ingham std::vector<std::string> name_list; 2145b842f2ecSJim Ingham if (command.empty()) { 2146b842f2ecSJim Ingham target->GetBreakpointNames(name_list); 2147b842f2ecSJim Ingham } else { 2148b842f2ecSJim Ingham for (const Args::ArgEntry &arg : command) 2149b842f2ecSJim Ingham { 2150b842f2ecSJim Ingham name_list.push_back(arg.c_str()); 2151b842f2ecSJim Ingham } 2152b842f2ecSJim Ingham } 2153b842f2ecSJim Ingham 2154b842f2ecSJim Ingham if (name_list.empty()) { 2155b842f2ecSJim Ingham result.AppendMessage("No breakpoint names found."); 2156b842f2ecSJim Ingham } else { 2157b842f2ecSJim Ingham for (const std::string &name_str : name_list) { 2158b842f2ecSJim Ingham const char *name = name_str.c_str(); 2159b842f2ecSJim Ingham // First print out the options for the name: 2160b842f2ecSJim Ingham Status error; 2161b842f2ecSJim Ingham BreakpointName *bp_name = target->FindBreakpointName(ConstString(name), 2162b842f2ecSJim Ingham false, 2163b842f2ecSJim Ingham error); 2164b842f2ecSJim Ingham if (bp_name) 2165b842f2ecSJim Ingham { 2166b842f2ecSJim Ingham StreamString s; 2167b842f2ecSJim Ingham result.AppendMessageWithFormat("Name: %s\n", name); 2168b842f2ecSJim Ingham if (bp_name->GetDescription(&s, eDescriptionLevelFull)) 2169b842f2ecSJim Ingham { 2170b842f2ecSJim Ingham result.AppendMessage(s.GetString()); 2171b842f2ecSJim Ingham } 2172b842f2ecSJim Ingham 2173bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 2174bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 21755e09c8c3SJim Ingham 21765e09c8c3SJim Ingham BreakpointList &breakpoints = target->GetBreakpointList(); 2177b842f2ecSJim Ingham bool any_set = false; 2178b9c1b51eSKate Stone for (BreakpointSP bp_sp : breakpoints.Breakpoints()) { 2179b9c1b51eSKate Stone if (bp_sp->MatchesName(name)) { 21805e09c8c3SJim Ingham StreamString s; 2181b842f2ecSJim Ingham any_set = true; 21825e09c8c3SJim Ingham bp_sp->GetDescription(&s, eDescriptionLevelBrief); 21835e09c8c3SJim Ingham s.EOL(); 2184c156427dSZachary Turner result.AppendMessage(s.GetString()); 21855e09c8c3SJim Ingham } 21865e09c8c3SJim Ingham } 2187b842f2ecSJim Ingham if (!any_set) 2188b842f2ecSJim Ingham result.AppendMessage("No breakpoints using this name."); 2189b9c1b51eSKate Stone } else { 2190b842f2ecSJim Ingham result.AppendMessageWithFormat("Name: %s not found.\n", name); 21915e09c8c3SJim Ingham } 2192b842f2ecSJim Ingham } 21935e09c8c3SJim Ingham } 21945e09c8c3SJim Ingham return true; 21955e09c8c3SJim Ingham } 21965e09c8c3SJim Ingham 21975e09c8c3SJim Ingham private: 21985e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 21995e09c8c3SJim Ingham OptionGroupOptions m_option_group; 22005e09c8c3SJim Ingham }; 22015e09c8c3SJim Ingham 22025e09c8c3SJim Ingham //------------------------------------------------------------------------- 2203e14dc268SJim Ingham // CommandObjectBreakpointName 22045e09c8c3SJim Ingham //------------------------------------------------------------------------- 2205b9c1b51eSKate Stone class CommandObjectBreakpointName : public CommandObjectMultiword { 22065e09c8c3SJim Ingham public: 22077428a18cSKate Stone CommandObjectBreakpointName(CommandInterpreter &interpreter) 2208b9c1b51eSKate Stone : CommandObjectMultiword( 2209b9c1b51eSKate Stone interpreter, "name", "Commands to manage name tags for breakpoints", 2210b9c1b51eSKate Stone "breakpoint name <subcommand> [<command-options>]") { 2211b9c1b51eSKate Stone CommandObjectSP add_command_object( 2212b9c1b51eSKate Stone new CommandObjectBreakpointNameAdd(interpreter)); 2213b9c1b51eSKate Stone CommandObjectSP delete_command_object( 2214b9c1b51eSKate Stone new CommandObjectBreakpointNameDelete(interpreter)); 2215b9c1b51eSKate Stone CommandObjectSP list_command_object( 2216b9c1b51eSKate Stone new CommandObjectBreakpointNameList(interpreter)); 2217b842f2ecSJim Ingham CommandObjectSP configure_command_object( 2218b842f2ecSJim Ingham new CommandObjectBreakpointNameConfigure(interpreter)); 22195e09c8c3SJim Ingham 22205e09c8c3SJim Ingham LoadSubCommand("add", add_command_object); 22215e09c8c3SJim Ingham LoadSubCommand("delete", delete_command_object); 22225e09c8c3SJim Ingham LoadSubCommand("list", list_command_object); 2223b842f2ecSJim Ingham LoadSubCommand("configure", configure_command_object); 22245e09c8c3SJim Ingham } 22255e09c8c3SJim Ingham 22269e85e5a8SEugene Zelenko ~CommandObjectBreakpointName() override = default; 22275e09c8c3SJim Ingham }; 22285e09c8c3SJim Ingham 22295e09c8c3SJim Ingham //------------------------------------------------------------------------- 2230e14dc268SJim Ingham // CommandObjectBreakpointRead 2231e14dc268SJim Ingham //------------------------------------------------------------------------- 22323acdf385SJim Ingham #pragma mark Read::CommandOptions 22331f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_read_options[] = { 22341f0f5b5bSZachary Turner // clang-format off 22351f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename, "The file from which to read the breakpoints." }, 22363acdf385SJim Ingham {LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Only read in breakpoints with this name."}, 22371f0f5b5bSZachary Turner // clang-format on 22381f0f5b5bSZachary Turner }; 22391f0f5b5bSZachary Turner 22401f0f5b5bSZachary Turner #pragma mark Read 2241e14dc268SJim Ingham 2242e14dc268SJim Ingham class CommandObjectBreakpointRead : public CommandObjectParsed { 2243e14dc268SJim Ingham public: 2244e14dc268SJim Ingham CommandObjectBreakpointRead(CommandInterpreter &interpreter) 2245e14dc268SJim Ingham : CommandObjectParsed(interpreter, "breakpoint read", 2246e14dc268SJim Ingham "Read and set the breakpoints previously saved to " 2247e14dc268SJim Ingham "a file with \"breakpoint write\". ", 2248e14dc268SJim Ingham nullptr), 2249e14dc268SJim Ingham m_options() { 2250e14dc268SJim Ingham CommandArgumentEntry arg; 2251e14dc268SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 2252e14dc268SJim Ingham eArgTypeBreakpointIDRange); 2253e14dc268SJim Ingham // Add the entry for the first argument for this command to the object's 2254e14dc268SJim Ingham // arguments vector. 2255e14dc268SJim Ingham m_arguments.push_back(arg); 2256e14dc268SJim Ingham } 2257e14dc268SJim Ingham 2258e14dc268SJim Ingham ~CommandObjectBreakpointRead() override = default; 2259e14dc268SJim Ingham 2260e14dc268SJim Ingham Options *GetOptions() override { return &m_options; } 2261e14dc268SJim Ingham 2262e14dc268SJim Ingham class CommandOptions : public Options { 2263e14dc268SJim Ingham public: 2264e14dc268SJim Ingham CommandOptions() : Options() {} 2265e14dc268SJim Ingham 2266e14dc268SJim Ingham ~CommandOptions() override = default; 2267e14dc268SJim Ingham 226897206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 2269e14dc268SJim Ingham ExecutionContext *execution_context) override { 227097206d57SZachary Turner Status error; 2271e14dc268SJim Ingham const int short_option = m_getopt_table[option_idx].val; 2272e14dc268SJim Ingham 2273e14dc268SJim Ingham switch (short_option) { 2274e14dc268SJim Ingham case 'f': 2275e14dc268SJim Ingham m_filename.assign(option_arg); 2276e14dc268SJim Ingham break; 22773acdf385SJim Ingham case 'N': { 227897206d57SZachary Turner Status name_error; 22793acdf385SJim Ingham if (!BreakpointID::StringIsBreakpointName(llvm::StringRef(option_arg), 22803acdf385SJim Ingham name_error)) { 22813acdf385SJim Ingham error.SetErrorStringWithFormat("Invalid breakpoint name: %s", 22823acdf385SJim Ingham name_error.AsCString()); 22833acdf385SJim Ingham } 22843acdf385SJim Ingham m_names.push_back(option_arg); 22853acdf385SJim Ingham break; 22863acdf385SJim Ingham } 2287e14dc268SJim Ingham default: 2288e14dc268SJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 2289e14dc268SJim Ingham short_option); 2290e14dc268SJim Ingham break; 2291e14dc268SJim Ingham } 2292e14dc268SJim Ingham 2293e14dc268SJim Ingham return error; 2294e14dc268SJim Ingham } 2295e14dc268SJim Ingham 2296e14dc268SJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 2297e14dc268SJim Ingham m_filename.clear(); 22983acdf385SJim Ingham m_names.clear(); 2299e14dc268SJim Ingham } 2300e14dc268SJim Ingham 23011f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 230270602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_read_options); 23031f0f5b5bSZachary Turner } 2304e14dc268SJim Ingham 2305e14dc268SJim Ingham // Instance variables to hold the values for command options. 2306e14dc268SJim Ingham 2307e14dc268SJim Ingham std::string m_filename; 23083acdf385SJim Ingham std::vector<std::string> m_names; 2309e14dc268SJim Ingham }; 2310e14dc268SJim Ingham 2311e14dc268SJim Ingham protected: 2312e14dc268SJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 2313e14dc268SJim Ingham Target *target = GetSelectedOrDummyTarget(); 2314e14dc268SJim Ingham if (target == nullptr) { 2315e14dc268SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 2316e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2317e14dc268SJim Ingham return false; 2318e14dc268SJim Ingham } 2319e14dc268SJim Ingham 23203acdf385SJim Ingham std::unique_lock<std::recursive_mutex> lock; 23213acdf385SJim Ingham target->GetBreakpointList().GetListMutex(lock); 23223acdf385SJim Ingham 2323e14dc268SJim Ingham FileSpec input_spec(m_options.m_filename, true); 232401f16664SJim Ingham BreakpointIDList new_bps; 232597206d57SZachary Turner Status error = target->CreateBreakpointsFromFile( 232697206d57SZachary Turner input_spec, m_options.m_names, new_bps); 2327e14dc268SJim Ingham 2328e14dc268SJim Ingham if (!error.Success()) { 232901f16664SJim Ingham result.AppendError(error.AsCString()); 2330e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 233101f16664SJim Ingham return false; 2332e14dc268SJim Ingham } 23333acdf385SJim Ingham 23343acdf385SJim Ingham Stream &output_stream = result.GetOutputStream(); 23353acdf385SJim Ingham 23363acdf385SJim Ingham size_t num_breakpoints = new_bps.GetSize(); 23373acdf385SJim Ingham if (num_breakpoints == 0) { 23383acdf385SJim Ingham result.AppendMessage("No breakpoints added."); 23393acdf385SJim Ingham } else { 23403acdf385SJim Ingham // No breakpoint selected; show info about all currently set breakpoints. 23413acdf385SJim Ingham result.AppendMessage("New breakpoints:"); 23423acdf385SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) { 23433acdf385SJim Ingham BreakpointID bp_id = new_bps.GetBreakpointIDAtIndex(i); 23443acdf385SJim Ingham Breakpoint *bp = target->GetBreakpointList() 23453acdf385SJim Ingham .FindBreakpointByID(bp_id.GetBreakpointID()) 23463acdf385SJim Ingham .get(); 23473acdf385SJim Ingham if (bp) 23483acdf385SJim Ingham bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, 23493acdf385SJim Ingham false); 23503acdf385SJim Ingham } 23513acdf385SJim Ingham } 2352e14dc268SJim Ingham return result.Succeeded(); 2353e14dc268SJim Ingham } 2354e14dc268SJim Ingham 2355e14dc268SJim Ingham private: 2356e14dc268SJim Ingham CommandOptions m_options; 2357e14dc268SJim Ingham }; 2358e14dc268SJim Ingham 2359e14dc268SJim Ingham //------------------------------------------------------------------------- 2360e14dc268SJim Ingham // CommandObjectBreakpointWrite 2361e14dc268SJim Ingham //------------------------------------------------------------------------- 23621f0f5b5bSZachary Turner #pragma mark Write::CommandOptions 23631f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_write_options[] = { 23641f0f5b5bSZachary Turner // clang-format off 23651f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename, "The file into which to write the breakpoints." }, 23662d3628e1SJim Ingham { LLDB_OPT_SET_ALL, false, "append",'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Append to saved breakpoints file if it exists."}, 23671f0f5b5bSZachary Turner // clang-format on 23681f0f5b5bSZachary Turner }; 23691f0f5b5bSZachary Turner 23701f0f5b5bSZachary Turner #pragma mark Write 2371e14dc268SJim Ingham class CommandObjectBreakpointWrite : public CommandObjectParsed { 2372e14dc268SJim Ingham public: 2373e14dc268SJim Ingham CommandObjectBreakpointWrite(CommandInterpreter &interpreter) 2374e14dc268SJim Ingham : CommandObjectParsed(interpreter, "breakpoint write", 2375e14dc268SJim Ingham "Write the breakpoints listed to a file that can " 2376e14dc268SJim Ingham "be read in with \"breakpoint read\". " 2377e14dc268SJim Ingham "If given no arguments, writes all breakpoints.", 2378e14dc268SJim Ingham nullptr), 2379e14dc268SJim Ingham m_options() { 2380e14dc268SJim Ingham CommandArgumentEntry arg; 2381e14dc268SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 2382e14dc268SJim Ingham eArgTypeBreakpointIDRange); 2383e14dc268SJim Ingham // Add the entry for the first argument for this command to the object's 2384e14dc268SJim Ingham // arguments vector. 2385e14dc268SJim Ingham m_arguments.push_back(arg); 2386e14dc268SJim Ingham } 2387e14dc268SJim Ingham 2388e14dc268SJim Ingham ~CommandObjectBreakpointWrite() override = default; 2389e14dc268SJim Ingham 2390e14dc268SJim Ingham Options *GetOptions() override { return &m_options; } 2391e14dc268SJim Ingham 2392e14dc268SJim Ingham class CommandOptions : public Options { 2393e14dc268SJim Ingham public: 2394e14dc268SJim Ingham CommandOptions() : Options() {} 2395e14dc268SJim Ingham 2396e14dc268SJim Ingham ~CommandOptions() override = default; 2397e14dc268SJim Ingham 239897206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 2399e14dc268SJim Ingham ExecutionContext *execution_context) override { 240097206d57SZachary Turner Status error; 2401e14dc268SJim Ingham const int short_option = m_getopt_table[option_idx].val; 2402e14dc268SJim Ingham 2403e14dc268SJim Ingham switch (short_option) { 2404e14dc268SJim Ingham case 'f': 2405e14dc268SJim Ingham m_filename.assign(option_arg); 2406e14dc268SJim Ingham break; 24072d3628e1SJim Ingham case 'a': 24082d3628e1SJim Ingham m_append = true; 24092d3628e1SJim Ingham break; 2410e14dc268SJim Ingham default: 2411e14dc268SJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 2412e14dc268SJim Ingham short_option); 2413e14dc268SJim Ingham break; 2414e14dc268SJim Ingham } 2415e14dc268SJim Ingham 2416e14dc268SJim Ingham return error; 2417e14dc268SJim Ingham } 2418e14dc268SJim Ingham 2419e14dc268SJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 2420e14dc268SJim Ingham m_filename.clear(); 24212d3628e1SJim Ingham m_append = false; 2422e14dc268SJim Ingham } 2423e14dc268SJim Ingham 24241f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 242570602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_write_options); 24261f0f5b5bSZachary Turner } 2427e14dc268SJim Ingham 2428e14dc268SJim Ingham // Instance variables to hold the values for command options. 2429e14dc268SJim Ingham 2430e14dc268SJim Ingham std::string m_filename; 24312d3628e1SJim Ingham bool m_append = false; 2432e14dc268SJim Ingham }; 2433e14dc268SJim Ingham 2434e14dc268SJim Ingham protected: 2435e14dc268SJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 2436e14dc268SJim Ingham Target *target = GetSelectedOrDummyTarget(); 2437e14dc268SJim Ingham if (target == nullptr) { 2438e14dc268SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 2439e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2440e14dc268SJim Ingham return false; 2441e14dc268SJim Ingham } 2442e14dc268SJim Ingham 2443e14dc268SJim Ingham std::unique_lock<std::recursive_mutex> lock; 2444e14dc268SJim Ingham target->GetBreakpointList().GetListMutex(lock); 2445e14dc268SJim Ingham 2446e14dc268SJim Ingham BreakpointIDList valid_bp_ids; 244711eb9c64SZachary Turner if (!command.empty()) { 2448e14dc268SJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 2449b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 2450b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 2451e14dc268SJim Ingham 245201f16664SJim Ingham if (!result.Succeeded()) { 2453e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2454e14dc268SJim Ingham return false; 2455e14dc268SJim Ingham } 2456e14dc268SJim Ingham } 245797206d57SZachary Turner Status error = target->SerializeBreakpointsToFile( 2458771ef6d4SMalcolm Parsons FileSpec(m_options.m_filename, true), valid_bp_ids, m_options.m_append); 245901f16664SJim Ingham if (!error.Success()) { 246001f16664SJim Ingham result.AppendErrorWithFormat("error serializing breakpoints: %s.", 246101f16664SJim Ingham error.AsCString()); 246201f16664SJim Ingham result.SetStatus(eReturnStatusFailed); 2463e14dc268SJim Ingham } 2464e14dc268SJim Ingham return result.Succeeded(); 2465e14dc268SJim Ingham } 2466e14dc268SJim Ingham 2467e14dc268SJim Ingham private: 2468e14dc268SJim Ingham CommandOptions m_options; 2469e14dc268SJim Ingham }; 2470e14dc268SJim Ingham 2471e14dc268SJim Ingham //------------------------------------------------------------------------- 247230fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 247330fdc8d8SChris Lattner //------------------------------------------------------------------------- 2474ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 247530fdc8d8SChris Lattner 2476b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint( 2477b9c1b51eSKate Stone CommandInterpreter &interpreter) 2478b9c1b51eSKate Stone : CommandObjectMultiword( 2479b9c1b51eSKate Stone interpreter, "breakpoint", 24807428a18cSKate Stone "Commands for operating on breakpoints (see 'help b' for shorthand.)", 2481b9c1b51eSKate Stone "breakpoint <subcommand> [<command-options>]") { 2482b9c1b51eSKate Stone CommandObjectSP list_command_object( 2483b9c1b51eSKate Stone new CommandObjectBreakpointList(interpreter)); 2484b9c1b51eSKate Stone CommandObjectSP enable_command_object( 2485b9c1b51eSKate Stone new CommandObjectBreakpointEnable(interpreter)); 2486b9c1b51eSKate Stone CommandObjectSP disable_command_object( 2487b9c1b51eSKate Stone new CommandObjectBreakpointDisable(interpreter)); 2488b9c1b51eSKate Stone CommandObjectSP clear_command_object( 2489b9c1b51eSKate Stone new CommandObjectBreakpointClear(interpreter)); 2490b9c1b51eSKate Stone CommandObjectSP delete_command_object( 2491b9c1b51eSKate Stone new CommandObjectBreakpointDelete(interpreter)); 2492b9c1b51eSKate Stone CommandObjectSP set_command_object( 2493b9c1b51eSKate Stone new CommandObjectBreakpointSet(interpreter)); 2494b9c1b51eSKate Stone CommandObjectSP command_command_object( 2495b9c1b51eSKate Stone new CommandObjectBreakpointCommand(interpreter)); 2496b9c1b51eSKate Stone CommandObjectSP modify_command_object( 2497b9c1b51eSKate Stone new CommandObjectBreakpointModify(interpreter)); 2498b9c1b51eSKate Stone CommandObjectSP name_command_object( 2499b9c1b51eSKate Stone new CommandObjectBreakpointName(interpreter)); 2500e14dc268SJim Ingham CommandObjectSP write_command_object( 2501e14dc268SJim Ingham new CommandObjectBreakpointWrite(interpreter)); 2502e14dc268SJim Ingham CommandObjectSP read_command_object( 2503e14dc268SJim Ingham new CommandObjectBreakpointRead(interpreter)); 250430fdc8d8SChris Lattner 2505b7234e40SJohnny Chen list_command_object->SetCommandName("breakpoint list"); 250630fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 250730fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 2508b7234e40SJohnny Chen clear_command_object->SetCommandName("breakpoint clear"); 2509b7234e40SJohnny Chen delete_command_object->SetCommandName("breakpoint delete"); 2510ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 2511b7234e40SJohnny Chen command_command_object->SetCommandName("breakpoint command"); 2512b7234e40SJohnny Chen modify_command_object->SetCommandName("breakpoint modify"); 25135e09c8c3SJim Ingham name_command_object->SetCommandName("breakpoint name"); 2514e14dc268SJim Ingham write_command_object->SetCommandName("breakpoint write"); 2515e14dc268SJim Ingham read_command_object->SetCommandName("breakpoint read"); 251630fdc8d8SChris Lattner 251723f59509SGreg Clayton LoadSubCommand("list", list_command_object); 251823f59509SGreg Clayton LoadSubCommand("enable", enable_command_object); 251923f59509SGreg Clayton LoadSubCommand("disable", disable_command_object); 252023f59509SGreg Clayton LoadSubCommand("clear", clear_command_object); 252123f59509SGreg Clayton LoadSubCommand("delete", delete_command_object); 252223f59509SGreg Clayton LoadSubCommand("set", set_command_object); 252323f59509SGreg Clayton LoadSubCommand("command", command_command_object); 252423f59509SGreg Clayton LoadSubCommand("modify", modify_command_object); 25255e09c8c3SJim Ingham LoadSubCommand("name", name_command_object); 2526e14dc268SJim Ingham LoadSubCommand("write", write_command_object); 2527e14dc268SJim Ingham LoadSubCommand("read", read_command_object); 252830fdc8d8SChris Lattner } 252930fdc8d8SChris Lattner 25309e85e5a8SEugene Zelenko CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default; 253130fdc8d8SChris Lattner 2532b9c1b51eSKate Stone void CommandObjectMultiwordBreakpoint::VerifyIDs(Args &args, Target *target, 25335e09c8c3SJim Ingham bool allow_locations, 25345e09c8c3SJim Ingham CommandReturnObject &result, 2535b842f2ecSJim Ingham BreakpointIDList *valid_ids, 2536b842f2ecSJim Ingham BreakpointName::Permissions 2537b842f2ecSJim Ingham ::PermissionKinds 2538b842f2ecSJim Ingham purpose) { 253930fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 2540b9c1b51eSKate Stone // 2). the full breakpoint & location 2541b9c1b51eSKate Stone // canonical representation 2542b9c1b51eSKate Stone // 3). the word "to" or a hyphen, 2543b9c1b51eSKate Stone // representing a range (in which case there 2544b9c1b51eSKate Stone // had *better* be an entry both before & 2545b9c1b51eSKate Stone // after of one of the first two types. 25465e09c8c3SJim Ingham // 4). A breakpoint name 2547b9c1b51eSKate Stone // If args is empty, we will use the last created breakpoint (if there is 2548b9c1b51eSKate Stone // one.) 254930fdc8d8SChris Lattner 255030fdc8d8SChris Lattner Args temp_args; 255130fdc8d8SChris Lattner 255211eb9c64SZachary Turner if (args.empty()) { 2553b9c1b51eSKate Stone if (target->GetLastCreatedBreakpoint()) { 2554b9c1b51eSKate Stone valid_ids->AddBreakpointID(BreakpointID( 2555b9c1b51eSKate Stone target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); 255636f3b369SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 2557b9c1b51eSKate Stone } else { 2558b9c1b51eSKate Stone result.AppendError( 2559b9c1b51eSKate Stone "No breakpoint specified and no last created breakpoint."); 256036f3b369SJim Ingham result.SetStatus(eReturnStatusFailed); 256136f3b369SJim Ingham } 256236f3b369SJim Ingham return; 256336f3b369SJim Ingham } 256436f3b369SJim Ingham 2565b9c1b51eSKate Stone // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff 256605097246SAdrian Prantl // directly from the old ARGS to the new TEMP_ARGS. Do not copy breakpoint 256705097246SAdrian Prantl // id range strings over; instead generate a list of strings for all the 256805097246SAdrian Prantl // breakpoint ids in the range, and shove all of those breakpoint id strings 256905097246SAdrian Prantl // into TEMP_ARGS. 257030fdc8d8SChris Lattner 2571b9c1b51eSKate Stone BreakpointIDList::FindAndReplaceIDRanges(args, target, allow_locations, 2572b842f2ecSJim Ingham purpose, result, temp_args); 257330fdc8d8SChris Lattner 2574b9c1b51eSKate Stone // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual 2575b9c1b51eSKate Stone // BreakpointIDList: 257630fdc8d8SChris Lattner 257716662f3cSPavel Labath valid_ids->InsertStringArray(temp_args.GetArgumentArrayRef(), result); 257830fdc8d8SChris Lattner 257905097246SAdrian Prantl // At this point, all of the breakpoint ids that the user passed in have 258005097246SAdrian Prantl // been converted to breakpoint IDs 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 258405097246SAdrian Prantl // ids, go through our tentative list of breakpoint id's and verify that 258505097246SAdrian Prantl // they correspond to valid/currently set breakpoints. 258630fdc8d8SChris Lattner 2587c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 2588b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 258930fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex(i); 2590b9c1b51eSKate Stone Breakpoint *breakpoint = 2591b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 2592b9c1b51eSKate Stone if (breakpoint != nullptr) { 2593c7bece56SGreg Clayton const size_t num_locations = breakpoint->GetNumLocations(); 2594b9c1b51eSKate Stone if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations) { 259530fdc8d8SChris Lattner StreamString id_str; 2596b9c1b51eSKate Stone BreakpointID::GetCanonicalReference( 2597b9c1b51eSKate Stone &id_str, cur_bp_id.GetBreakpointID(), cur_bp_id.GetLocationID()); 2598c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 2599b9c1b51eSKate Stone result.AppendErrorWithFormat( 2600b9c1b51eSKate Stone "'%s' is not a currently valid breakpoint/location id.\n", 260130fdc8d8SChris Lattner id_str.GetData()); 260230fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 260330fdc8d8SChris Lattner } 2604b9c1b51eSKate Stone } else { 2605c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 2606b9c1b51eSKate Stone result.AppendErrorWithFormat( 2607b9c1b51eSKate Stone "'%d' is not a currently valid breakpoint ID.\n", 26087428a18cSKate Stone cur_bp_id.GetBreakpointID()); 260930fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 261030fdc8d8SChris Lattner } 261130fdc8d8SChris Lattner } 261230fdc8d8SChris Lattner } 261330fdc8d8SChris Lattner } 2614