130fdc8d8SChris Lattner //===-- CommandObjectBreakpoint.cpp -----------------------------*- C++ -*-===// 230fdc8d8SChris Lattner // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 630fdc8d8SChris Lattner // 730fdc8d8SChris Lattner //===----------------------------------------------------------------------===// 830fdc8d8SChris Lattner 99e85e5a8SEugene Zelenko #include "CommandObjectBreakpoint.h" 109e85e5a8SEugene Zelenko #include "CommandObjectBreakpointCommand.h" 1130fdc8d8SChris Lattner #include "lldb/Breakpoint/Breakpoint.h" 1230fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointIDList.h" 1330fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointLocation.h" 143eb2b44dSZachary Turner #include "lldb/Host/OptionParser.h" 15b9c1b51eSKate Stone #include "lldb/Interpreter/CommandCompletions.h" 16b9c1b51eSKate Stone #include "lldb/Interpreter/CommandInterpreter.h" 17b9c1b51eSKate Stone #include "lldb/Interpreter/CommandReturnObject.h" 1847cbf4a0SPavel Labath #include "lldb/Interpreter/OptionArgParser.h" 1932abc6edSZachary Turner #include "lldb/Interpreter/OptionValueBoolean.h" 205e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueString.h" 215e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueUInt64.h" 22b9c1b51eSKate Stone #include "lldb/Interpreter/Options.h" 230e0984eeSJim Ingham #include "lldb/Target/Language.h" 24b57e4a1bSJason Molenda #include "lldb/Target/StackFrame.h" 25b9c1b51eSKate Stone #include "lldb/Target/Target.h" 261b54c88cSJim Ingham #include "lldb/Target/Thread.h" 271b54c88cSJim Ingham #include "lldb/Target/ThreadSpec.h" 28bf9a7730SZachary Turner #include "lldb/Utility/RegularExpression.h" 29bf9a7730SZachary Turner #include "lldb/Utility/StreamString.h" 3030fdc8d8SChris Lattner 31*796ac80bSJonas Devlieghere #include <memory> 32*796ac80bSJonas Devlieghere #include <vector> 33*796ac80bSJonas Devlieghere 3430fdc8d8SChris Lattner using namespace lldb; 3530fdc8d8SChris Lattner using namespace lldb_private; 3630fdc8d8SChris Lattner 37b9c1b51eSKate Stone static void AddBreakpointDescription(Stream *s, Breakpoint *bp, 38b9c1b51eSKate Stone lldb::DescriptionLevel level) { 3930fdc8d8SChris Lattner s->IndentMore(); 4030fdc8d8SChris Lattner bp->GetDescription(s, level, true); 4130fdc8d8SChris Lattner s->IndentLess(); 4230fdc8d8SChris Lattner s->EOL(); 4330fdc8d8SChris Lattner } 4430fdc8d8SChris Lattner 45b842f2ecSJim Ingham //------------------------------------------------------------------------- 46b842f2ecSJim Ingham // Modifiable Breakpoint Options 47b842f2ecSJim Ingham //------------------------------------------------------------------------- 48b842f2ecSJim Ingham #pragma mark Modify::CommandOptions 498fe53c49STatyana Krasnukha static constexpr OptionDefinition g_breakpoint_modify_options[] = { 50b842f2ecSJim Ingham // clang-format off 518fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." }, 528fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, false, "one-shot", 'o', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "The breakpoint is deleted the first time it stop causes a stop." }, 538fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose index matches this argument." }, 548fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument." }, 558fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument." }, 568fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument." }, 578fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true." }, 588fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, false, "auto-continue",'G', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "The breakpoint will auto-continue after running its commands." }, 598fe53c49STatyana Krasnukha { LLDB_OPT_SET_2, false, "enable", 'e', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Enable the breakpoint." }, 608fe53c49STatyana Krasnukha { LLDB_OPT_SET_3, false, "disable", 'd', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Disable the breakpoint." }, 618fe53c49STatyana Krasnukha { LLDB_OPT_SET_4, false, "command", 'C', OptionParser::eRequiredArgument, 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." }, 62b842f2ecSJim Ingham // clang-format on 63b842f2ecSJim Ingham }; 64b842f2ecSJim Ingham class lldb_private::BreakpointOptionGroup : public OptionGroup 65b842f2ecSJim Ingham { 66b842f2ecSJim Ingham public: 67b842f2ecSJim Ingham BreakpointOptionGroup() : 68b842f2ecSJim Ingham OptionGroup(), 69b842f2ecSJim Ingham m_bp_opts(false) {} 70b842f2ecSJim Ingham 71b842f2ecSJim Ingham ~BreakpointOptionGroup() override = default; 72b842f2ecSJim Ingham 73b842f2ecSJim Ingham llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 74b842f2ecSJim Ingham return llvm::makeArrayRef(g_breakpoint_modify_options); 75b842f2ecSJim Ingham } 76b842f2ecSJim Ingham 77b842f2ecSJim Ingham Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 78b842f2ecSJim Ingham ExecutionContext *execution_context) override { 79b842f2ecSJim Ingham Status error; 80b842f2ecSJim Ingham const int short_option = g_breakpoint_modify_options[option_idx].short_option; 81b842f2ecSJim Ingham 82b842f2ecSJim Ingham switch (short_option) { 83b842f2ecSJim Ingham case 'c': 8405097246SAdrian Prantl // Normally an empty breakpoint condition marks is as unset. But we need 8505097246SAdrian Prantl // to say it was passed in. 86b842f2ecSJim Ingham m_bp_opts.SetCondition(option_arg.str().c_str()); 87b842f2ecSJim Ingham m_bp_opts.m_set_flags.Set(BreakpointOptions::eCondition); 88b842f2ecSJim Ingham break; 89b842f2ecSJim Ingham case 'C': 90b842f2ecSJim Ingham m_commands.push_back(option_arg); 91b842f2ecSJim Ingham break; 92b842f2ecSJim Ingham case 'd': 93b842f2ecSJim Ingham m_bp_opts.SetEnabled(false); 94b842f2ecSJim Ingham break; 95b842f2ecSJim Ingham case 'e': 96b842f2ecSJim Ingham m_bp_opts.SetEnabled(true); 97b842f2ecSJim Ingham break; 98b842f2ecSJim Ingham case 'G': { 99b842f2ecSJim Ingham bool value, success; 10047cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 101b842f2ecSJim Ingham if (success) { 102b842f2ecSJim Ingham m_bp_opts.SetAutoContinue(value); 103b842f2ecSJim Ingham } else 104b842f2ecSJim Ingham error.SetErrorStringWithFormat( 105b842f2ecSJim Ingham "invalid boolean value '%s' passed for -G option", 106b842f2ecSJim Ingham option_arg.str().c_str()); 107b842f2ecSJim Ingham } 108b842f2ecSJim Ingham break; 109b842f2ecSJim Ingham case 'i': 110b842f2ecSJim Ingham { 111b842f2ecSJim Ingham uint32_t ignore_count; 112b842f2ecSJim Ingham if (option_arg.getAsInteger(0, ignore_count)) 113b842f2ecSJim Ingham error.SetErrorStringWithFormat("invalid ignore count '%s'", 114b842f2ecSJim Ingham option_arg.str().c_str()); 115b842f2ecSJim Ingham else 116b842f2ecSJim Ingham m_bp_opts.SetIgnoreCount(ignore_count); 117b842f2ecSJim Ingham } 118b842f2ecSJim Ingham break; 119b842f2ecSJim Ingham case 'o': { 120b842f2ecSJim Ingham bool value, success; 12147cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 122b842f2ecSJim Ingham if (success) { 123b842f2ecSJim Ingham m_bp_opts.SetOneShot(value); 124b842f2ecSJim Ingham } else 125b842f2ecSJim Ingham error.SetErrorStringWithFormat( 126b842f2ecSJim Ingham "invalid boolean value '%s' passed for -o option", 127b842f2ecSJim Ingham option_arg.str().c_str()); 128b842f2ecSJim Ingham } break; 129b842f2ecSJim Ingham case 't': 130b842f2ecSJim Ingham { 131b842f2ecSJim Ingham lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID; 132b842f2ecSJim Ingham if (option_arg[0] != '\0') { 133b842f2ecSJim Ingham if (option_arg.getAsInteger(0, thread_id)) 134b842f2ecSJim Ingham error.SetErrorStringWithFormat("invalid thread id string '%s'", 135b842f2ecSJim Ingham option_arg.str().c_str()); 136b842f2ecSJim Ingham } 137b842f2ecSJim Ingham m_bp_opts.SetThreadID(thread_id); 138b842f2ecSJim Ingham } 139b842f2ecSJim Ingham break; 140b842f2ecSJim Ingham case 'T': 141b842f2ecSJim Ingham m_bp_opts.GetThreadSpec()->SetName(option_arg.str().c_str()); 142b842f2ecSJim Ingham break; 143b842f2ecSJim Ingham case 'q': 144b842f2ecSJim Ingham m_bp_opts.GetThreadSpec()->SetQueueName(option_arg.str().c_str()); 145b842f2ecSJim Ingham break; 146b842f2ecSJim Ingham case 'x': 147b842f2ecSJim Ingham { 148b842f2ecSJim Ingham uint32_t thread_index = UINT32_MAX; 149b842f2ecSJim Ingham if (option_arg[0] != '\n') { 150b842f2ecSJim Ingham if (option_arg.getAsInteger(0, thread_index)) 151b842f2ecSJim Ingham error.SetErrorStringWithFormat("invalid thread index string '%s'", 152b842f2ecSJim Ingham option_arg.str().c_str()); 153b842f2ecSJim Ingham } 154b842f2ecSJim Ingham m_bp_opts.GetThreadSpec()->SetIndex(thread_index); 155b842f2ecSJim Ingham } 156b842f2ecSJim Ingham break; 157b842f2ecSJim Ingham default: 158b842f2ecSJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 159b842f2ecSJim Ingham short_option); 160b842f2ecSJim Ingham break; 161b842f2ecSJim Ingham } 162b842f2ecSJim Ingham 163b842f2ecSJim Ingham return error; 164b842f2ecSJim Ingham } 165b842f2ecSJim Ingham 166b842f2ecSJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 167b842f2ecSJim Ingham m_bp_opts.Clear(); 168b842f2ecSJim Ingham m_commands.clear(); 169b842f2ecSJim Ingham } 170b842f2ecSJim Ingham 171b842f2ecSJim Ingham Status OptionParsingFinished(ExecutionContext *execution_context) override { 172b842f2ecSJim Ingham if (!m_commands.empty()) 173b842f2ecSJim Ingham { 174b842f2ecSJim Ingham if (!m_commands.empty()) 175b842f2ecSJim Ingham { 176b842f2ecSJim Ingham auto cmd_data = llvm::make_unique<BreakpointOptions::CommandData>(); 177b842f2ecSJim Ingham 178b842f2ecSJim Ingham for (std::string &str : m_commands) 179b842f2ecSJim Ingham cmd_data->user_source.AppendString(str); 180b842f2ecSJim Ingham 181b842f2ecSJim Ingham cmd_data->stop_on_error = true; 182b842f2ecSJim Ingham m_bp_opts.SetCommandDataCallback(cmd_data); 183b842f2ecSJim Ingham } 184b842f2ecSJim Ingham } 185b842f2ecSJim Ingham return Status(); 186b842f2ecSJim Ingham } 187b842f2ecSJim Ingham 188b842f2ecSJim Ingham const BreakpointOptions &GetBreakpointOptions() 189b842f2ecSJim Ingham { 190b842f2ecSJim Ingham return m_bp_opts; 191b842f2ecSJim Ingham } 192b842f2ecSJim Ingham 193b842f2ecSJim Ingham std::vector<std::string> m_commands; 194b842f2ecSJim Ingham BreakpointOptions m_bp_opts; 195b842f2ecSJim Ingham 196b842f2ecSJim Ingham }; 1978fe53c49STatyana Krasnukha static constexpr OptionDefinition g_breakpoint_dummy_options[] = { 198b842f2ecSJim Ingham // clang-format off 1998fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Act on Dummy breakpoints - i.e. breakpoints set before a file is provided, " 200b842f2ecSJim Ingham "which prime new targets." }, 201b842f2ecSJim Ingham // clang-format on 202b842f2ecSJim Ingham }; 203b842f2ecSJim Ingham 204b842f2ecSJim Ingham class BreakpointDummyOptionGroup : public OptionGroup 205b842f2ecSJim Ingham { 206b842f2ecSJim Ingham public: 207b842f2ecSJim Ingham BreakpointDummyOptionGroup() : 208b842f2ecSJim Ingham OptionGroup() {} 209b842f2ecSJim Ingham 210b842f2ecSJim Ingham ~BreakpointDummyOptionGroup() override = default; 211b842f2ecSJim Ingham 212b842f2ecSJim Ingham llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 213b842f2ecSJim Ingham return llvm::makeArrayRef(g_breakpoint_dummy_options); 214b842f2ecSJim Ingham } 215b842f2ecSJim Ingham 216b842f2ecSJim Ingham Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 217b842f2ecSJim Ingham ExecutionContext *execution_context) override { 218b842f2ecSJim Ingham Status error; 219b842f2ecSJim Ingham const int short_option = g_breakpoint_modify_options[option_idx].short_option; 220b842f2ecSJim Ingham 221b842f2ecSJim Ingham switch (short_option) { 222b842f2ecSJim Ingham case 'D': 223b842f2ecSJim Ingham m_use_dummy = true; 224b842f2ecSJim Ingham break; 225b842f2ecSJim Ingham default: 226b842f2ecSJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 227b842f2ecSJim Ingham short_option); 228b842f2ecSJim Ingham break; 229b842f2ecSJim Ingham } 230b842f2ecSJim Ingham 231b842f2ecSJim Ingham return error; 232b842f2ecSJim Ingham } 233b842f2ecSJim Ingham 234b842f2ecSJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 235b842f2ecSJim Ingham m_use_dummy = false; 236b842f2ecSJim Ingham } 237b842f2ecSJim Ingham 238b842f2ecSJim Ingham bool m_use_dummy; 239b842f2ecSJim Ingham 240b842f2ecSJim Ingham }; 241b842f2ecSJim Ingham 2421f0f5b5bSZachary Turner // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to 2431f0f5b5bSZachary Turner // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately. 2443815e702SJim Ingham #define LLDB_OPT_NOT_10 (LLDB_OPT_SET_FROM_TO(1, 11) & ~LLDB_OPT_SET_10) 2451f0f5b5bSZachary Turner #define LLDB_OPT_SKIP_PROLOGUE (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8)) 2463815e702SJim Ingham #define LLDB_OPT_FILE (LLDB_OPT_SET_FROM_TO(1, 11) & ~LLDB_OPT_SET_2 & ~LLDB_OPT_SET_10) 2473815e702SJim Ingham #define LLDB_OPT_OFFSET_APPLIES (LLDB_OPT_SET_FROM_TO(1, 8) & ~LLDB_OPT_SET_2) 2481f0f5b5bSZachary Turner #define LLDB_OPT_MOVE_TO_NEAREST_CODE (LLDB_OPT_SET_1 | LLDB_OPT_SET_9) 2491f0f5b5bSZachary Turner #define LLDB_OPT_EXPR_LANGUAGE (LLDB_OPT_SET_FROM_TO(3, 8)) 2501f0f5b5bSZachary Turner 2518fe53c49STatyana Krasnukha static constexpr OptionDefinition g_breakpoint_set_options[] = { 2521f0f5b5bSZachary Turner // clang-format off 2538fe53c49STatyana Krasnukha { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, {}, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Set the breakpoint only in this shared library. Can repeat this option " 2541f0f5b5bSZachary Turner "multiple times to specify multiple shared libraries." }, 2558fe53c49STatyana Krasnukha { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Require the breakpoint to use hardware breakpoints." }, 2568fe53c49STatyana Krasnukha { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, {}, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specifies the source file in which to set this breakpoint. Note, by default " 2571f0f5b5bSZachary Turner "lldb only looks for files that are #included if they use the standard include " 2581f0f5b5bSZachary Turner "file extensions. To set breakpoints on .c/.cpp/.m/.mm files that are " 2591f0f5b5bSZachary Turner "#included, set target.inline-breakpoint-strategy to \"always\"." }, 2608fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeLineNum, "Specifies the line number on which to set this breakpoint." }, 2611f0f5b5bSZachary Turner 26205097246SAdrian Prantl // Comment out this option for the moment, as we don't actually use it, but 26305097246SAdrian Prantl // will in the future. This way users won't see it, but the infrastructure is 26405097246SAdrian Prantl // left in place. 2651f0f5b5bSZachary Turner // { 0, false, "column", 'C', OptionParser::eRequiredArgument, nullptr, "<column>", 2661f0f5b5bSZachary Turner // "Set the breakpoint by source location at this particular column."}, 2671f0f5b5bSZachary Turner 2688fe53c49STatyana Krasnukha { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeAddressOrExpression, "Set the breakpoint at the specified address. If the address maps uniquely to " 2691f0f5b5bSZachary Turner "a particular binary, then the address will be converted to a \"file\" " 2701f0f5b5bSZachary Turner "address, so that the breakpoint will track that binary+offset no matter where " 2711f0f5b5bSZachary Turner "the binary eventually loads. Alternately, if you also specify the module - " 2721f0f5b5bSZachary Turner "with the -s option - then the address will be treated as a file address in " 2731f0f5b5bSZachary Turner "that module, and resolved accordingly. Again, this will allow lldb to track " 2741f0f5b5bSZachary Turner "that offset on subsequent reloads. The module need not have been loaded at " 2751f0f5b5bSZachary Turner "the time you specify this breakpoint, and will get resolved when the module " 2761f0f5b5bSZachary Turner "is loaded." }, 2778fe53c49STatyana Krasnukha { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, {}, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the breakpoint by function name. Can be repeated multiple times to make " 2781f0f5b5bSZachary Turner "one breakpoint for multiple names" }, 2798fe53c49STatyana Krasnukha { LLDB_OPT_SET_9, false, "source-regexp-function", 'X', OptionParser::eRequiredArgument, nullptr, {}, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "When used with '-p' limits the source regex to source contained in the named " 2801f0f5b5bSZachary Turner "functions. Can be repeated multiple times." }, 2818fe53c49STatyana Krasnukha { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, nullptr, {}, CommandCompletions::eSymbolCompletion, eArgTypeFullName, "Set the breakpoint by fully qualified function names. For C++ this means " 2824e8be2c9SAdrian Prantl "namespaces and all arguments, and for Objective-C this means a full function " 2831f0f5b5bSZachary Turner "prototype with class and selector. Can be repeated multiple times to make " 2841f0f5b5bSZachary Turner "one breakpoint for multiple names." }, 2858fe53c49STatyana Krasnukha { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeSelector, "Set the breakpoint by ObjC selector name. Can be repeated multiple times to " 2861f0f5b5bSZachary Turner "make one breakpoint for multiple Selectors." }, 2878fe53c49STatyana Krasnukha { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeMethod, "Set the breakpoint by C++ method names. Can be repeated multiple times to " 2881f0f5b5bSZachary Turner "make one breakpoint for multiple methods." }, 2898fe53c49STatyana Krasnukha { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeRegularExpression, "Set the breakpoint by function name, evaluating a regular-expression to find " 2901f0f5b5bSZachary Turner "the function name(s)." }, 2918fe53c49STatyana Krasnukha { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, nullptr, {}, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the breakpoint by function basename (C++ namespaces and arguments will be " 2921f0f5b5bSZachary Turner "ignored). Can be repeated multiple times to make one breakpoint for multiple " 2931f0f5b5bSZachary Turner "symbols." }, 2948fe53c49STatyana Krasnukha { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeRegularExpression, "Set the breakpoint by specifying a regular expression which is matched " 2951f0f5b5bSZachary Turner "against the source text in a source file or files specified with the -f " 2961f0f5b5bSZachary Turner "option. The -f option can be specified more than once. If no source files " 2971f0f5b5bSZachary Turner "are specified, uses the current \"default source file\". If you want to " 2981f0f5b5bSZachary Turner "match against all source files, pass the \"--all-files\" option." }, 2998fe53c49STatyana Krasnukha { LLDB_OPT_SET_9, false, "all-files", 'A', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "All files are searched for source pattern matches." }, 3008fe53c49STatyana Krasnukha { LLDB_OPT_SET_11, true, "python-class", 'P', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypePythonClass, "The name of the class that implement a scripted breakpoint." }, 3018fe53c49STatyana Krasnukha { LLDB_OPT_SET_11, false, "python-class-key", 'k', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeNone, "The key for a key/value pair passed to the class that implements a scripted breakpoint. Can be specified more than once." }, 3028fe53c49STatyana Krasnukha { LLDB_OPT_SET_11, false, "python-class-value", 'v', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeNone, "The value for the previous key in the pair passed to the class that implements a scripted breakpoint. Can be specified more than once." }, 3038fe53c49STatyana Krasnukha { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeLanguage, "Set the breakpoint on exceptions thrown by the specified language (without " 3041f0f5b5bSZachary Turner "options, on throw but not catch.)" }, 3058fe53c49STatyana Krasnukha { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "Set the breakpoint on exception throW." }, 3068fe53c49STatyana Krasnukha { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "Set the breakpoint on exception catcH." }, 3071f0f5b5bSZachary Turner 3081f0f5b5bSZachary Turner // Don't add this option till it actually does something useful... 3091f0f5b5bSZachary Turner // { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName, 3101f0f5b5bSZachary Turner // "The breakpoint will only stop if an exception Object of this type is thrown. Can be repeated multiple times to stop for multiple object types" }, 3111f0f5b5bSZachary Turner 3128fe53c49STatyana Krasnukha { LLDB_OPT_EXPR_LANGUAGE, false, "language", 'L', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeLanguage, "Specifies the Language to use when interpreting the breakpoint's expression " 3131f0f5b5bSZachary Turner "(note: currently only implemented for setting breakpoints on identifiers). " 3141f0f5b5bSZachary Turner "If not set the target.language setting is used." }, 3158fe53c49STatyana Krasnukha { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "sKip the prologue if the breakpoint is at the beginning of a function. " 3161f0f5b5bSZachary Turner "If not set the target.skip-prologue setting is used." }, 3178fe53c49STatyana Krasnukha { LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBreakpointName, "Adds this to the list of names for this breakpoint." }, 3188fe53c49STatyana Krasnukha { LLDB_OPT_OFFSET_APPLIES, false, "address-slide", 'R', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeAddress, "Add the specified offset to whatever address(es) the breakpoint resolves to. " 3191f0f5b5bSZachary Turner "At present this applies the offset directly as given, and doesn't try to align it to instruction boundaries." }, 3208fe53c49STatyana Krasnukha { LLDB_OPT_MOVE_TO_NEAREST_CODE, false, "move-to-nearest-code", 'm', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "Move breakpoints to nearest code. If not set the target.move-to-nearest-code " 3211f0f5b5bSZachary Turner "setting is used." }, 3221f0f5b5bSZachary Turner // clang-format on 3231f0f5b5bSZachary Turner }; 3241f0f5b5bSZachary Turner 32530fdc8d8SChris Lattner //------------------------------------------------------------------------- 3265a988416SJim Ingham // CommandObjectBreakpointSet 32730fdc8d8SChris Lattner //------------------------------------------------------------------------- 32830fdc8d8SChris Lattner 329b9c1b51eSKate Stone class CommandObjectBreakpointSet : public CommandObjectParsed { 3305a988416SJim Ingham public: 331b9c1b51eSKate Stone typedef enum BreakpointSetType { 3325a988416SJim Ingham eSetTypeInvalid, 3335a988416SJim Ingham eSetTypeFileAndLine, 3345a988416SJim Ingham eSetTypeAddress, 3355a988416SJim Ingham eSetTypeFunctionName, 3365a988416SJim Ingham eSetTypeFunctionRegexp, 3375a988416SJim Ingham eSetTypeSourceRegexp, 3383815e702SJim Ingham eSetTypeException, 3393815e702SJim Ingham eSetTypeScripted, 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': 4378f3be7a3SJonas Devlieghere m_filenames.AppendIfUnique(FileSpec(option_arg)); 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 4583815e702SJim Ingham case 'k': { 4593815e702SJim Ingham if (m_current_key.empty()) 4603815e702SJim Ingham m_current_key.assign(option_arg); 4613815e702SJim Ingham else 4623815e702SJim Ingham error.SetErrorStringWithFormat("Key: %s missing value.", 4633815e702SJim Ingham m_current_key.c_str()); 4643815e702SJim Ingham 4653815e702SJim Ingham } break; 466b9c1b51eSKate Stone case 'K': { 467a8558b62SJim Ingham bool success; 468a8558b62SJim Ingham bool value; 46947cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, true, &success); 470a8558b62SJim Ingham if (value) 471a8558b62SJim Ingham m_skip_prologue = eLazyBoolYes; 472a8558b62SJim Ingham else 473a8558b62SJim Ingham m_skip_prologue = eLazyBoolNo; 474a8558b62SJim Ingham 475a8558b62SJim Ingham if (!success) 476b9c1b51eSKate Stone error.SetErrorStringWithFormat( 477b9c1b51eSKate Stone "Invalid boolean value for skip prologue option: '%s'", 478fe11483bSZachary Turner option_arg.str().c_str()); 479b9c1b51eSKate Stone } break; 480ca36cd16SJim Ingham 481fe11483bSZachary Turner case 'l': 482fe11483bSZachary Turner if (option_arg.getAsInteger(0, m_line_num)) 483b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid line number: %s.", 484fe11483bSZachary Turner option_arg.str().c_str()); 485ca36cd16SJim Ingham break; 486055ad9beSIlia K 48723b1decbSDawn Perchik case 'L': 488fe11483bSZachary Turner m_language = Language::GetLanguageTypeFromString(option_arg); 48923b1decbSDawn Perchik if (m_language == eLanguageTypeUnknown) 490b9c1b51eSKate Stone error.SetErrorStringWithFormat( 491fe11483bSZachary Turner "Unknown language type: '%s' for breakpoint", 492fe11483bSZachary Turner option_arg.str().c_str()); 49323b1decbSDawn Perchik break; 49423b1decbSDawn Perchik 495b9c1b51eSKate Stone case 'm': { 496055ad9beSIlia K bool success; 497055ad9beSIlia K bool value; 49847cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, true, &success); 499055ad9beSIlia K if (value) 500055ad9beSIlia K m_move_to_nearest_code = eLazyBoolYes; 501055ad9beSIlia K else 502055ad9beSIlia K m_move_to_nearest_code = eLazyBoolNo; 503055ad9beSIlia K 504055ad9beSIlia K if (!success) 505b9c1b51eSKate Stone error.SetErrorStringWithFormat( 506b9c1b51eSKate Stone "Invalid boolean value for move-to-nearest-code option: '%s'", 507fe11483bSZachary Turner option_arg.str().c_str()); 508055ad9beSIlia K break; 509055ad9beSIlia K } 510055ad9beSIlia K 511ca36cd16SJim Ingham case 'M': 512ca36cd16SJim Ingham m_func_names.push_back(option_arg); 513ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeMethod; 514ca36cd16SJim Ingham break; 515ca36cd16SJim Ingham 516ca36cd16SJim Ingham case 'n': 517ca36cd16SJim Ingham m_func_names.push_back(option_arg); 518ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeAuto; 519ca36cd16SJim Ingham break; 520ca36cd16SJim Ingham 5216fa7681bSZachary Turner case 'N': { 522fe11483bSZachary Turner if (BreakpointID::StringIsBreakpointName(option_arg, error)) 5235e09c8c3SJim Ingham m_breakpoint_names.push_back(option_arg); 524ff9a91eaSJim Ingham else 525ff9a91eaSJim Ingham error.SetErrorStringWithFormat("Invalid breakpoint name: %s", 526fe11483bSZachary Turner option_arg.str().c_str()); 5275e09c8c3SJim Ingham break; 5286fa7681bSZachary Turner } 5295e09c8c3SJim Ingham 530b9c1b51eSKate Stone case 'R': { 5312411167fSJim Ingham lldb::addr_t tmp_offset_addr; 53247cbf4a0SPavel Labath tmp_offset_addr = OptionArgParser::ToAddress(execution_context, 53347cbf4a0SPavel Labath option_arg, 0, &error); 5342411167fSJim Ingham if (error.Success()) 5352411167fSJim Ingham m_offset_addr = tmp_offset_addr; 536b9c1b51eSKate Stone } break; 5372411167fSJim Ingham 538a72b31c7SJim Ingham case 'O': 539fe11483bSZachary Turner m_exception_extra_args.AppendArgument("-O"); 540fe11483bSZachary Turner m_exception_extra_args.AppendArgument(option_arg); 541a72b31c7SJim Ingham break; 542a72b31c7SJim Ingham 543ca36cd16SJim Ingham case 'p': 544ca36cd16SJim Ingham m_source_text_regexp.assign(option_arg); 545ca36cd16SJim Ingham break; 546ca36cd16SJim Ingham 5473815e702SJim Ingham case 'P': 5483815e702SJim Ingham m_python_class.assign(option_arg); 5493815e702SJim Ingham break; 5503815e702SJim Ingham 551ca36cd16SJim Ingham case 'r': 552ca36cd16SJim Ingham m_func_regexp.assign(option_arg); 553ca36cd16SJim Ingham break; 554ca36cd16SJim Ingham 555ca36cd16SJim Ingham case 's': 5568f3be7a3SJonas Devlieghere m_modules.AppendIfUnique(FileSpec(option_arg)); 557ca36cd16SJim Ingham break; 558ca36cd16SJim Ingham 559ca36cd16SJim Ingham case 'S': 560ca36cd16SJim Ingham m_func_names.push_back(option_arg); 561ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeSelector; 562ca36cd16SJim Ingham break; 563ca36cd16SJim Ingham 5643815e702SJim Ingham case 'v': { 5653815e702SJim Ingham if (!m_current_key.empty()) { 5663815e702SJim Ingham m_extra_args_sp->AddStringItem(m_current_key, option_arg); 5673815e702SJim Ingham m_current_key.clear(); 5683815e702SJim Ingham } 5693815e702SJim Ingham else 5703815e702SJim Ingham error.SetErrorStringWithFormat("Value \"%s\" missing matching key.", 5713815e702SJim Ingham option_arg.str().c_str()); 5723815e702SJim Ingham } break; 5733815e702SJim Ingham 574b9c1b51eSKate Stone case 'w': { 575ca36cd16SJim Ingham bool success; 57647cbf4a0SPavel Labath m_throw_bp = OptionArgParser::ToBoolean(option_arg, true, &success); 577ca36cd16SJim Ingham if (!success) 578b9c1b51eSKate Stone error.SetErrorStringWithFormat( 579fe11483bSZachary Turner "Invalid boolean value for on-throw option: '%s'", 580fe11483bSZachary Turner option_arg.str().c_str()); 581b9c1b51eSKate Stone } break; 582ca36cd16SJim Ingham 58376bb8d67SJim Ingham case 'X': 58476bb8d67SJim Ingham m_source_regex_func_names.insert(option_arg); 58576bb8d67SJim Ingham break; 58676bb8d67SJim Ingham 58730fdc8d8SChris Lattner default: 588b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 589b9c1b51eSKate Stone short_option); 59030fdc8d8SChris Lattner break; 59130fdc8d8SChris Lattner } 59230fdc8d8SChris Lattner 59330fdc8d8SChris Lattner return error; 59430fdc8d8SChris Lattner } 5959e85e5a8SEugene Zelenko 596b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 59787df91b8SJim Ingham m_filenames.Clear(); 59830fdc8d8SChris Lattner m_line_num = 0; 59930fdc8d8SChris Lattner m_column = 0; 600fab10e89SJim Ingham m_func_names.clear(); 6011f746071SGreg Clayton m_func_name_type_mask = eFunctionNameTypeNone; 60230fdc8d8SChris Lattner m_func_regexp.clear(); 6031f746071SGreg Clayton m_source_text_regexp.clear(); 60487df91b8SJim Ingham m_modules.Clear(); 6051f746071SGreg Clayton m_load_addr = LLDB_INVALID_ADDRESS; 6062411167fSJim Ingham m_offset_addr = 0; 607fab10e89SJim Ingham m_catch_bp = false; 608fab10e89SJim Ingham m_throw_bp = true; 609eb023e75SGreg Clayton m_hardware = false; 610a72b31c7SJim Ingham m_exception_language = eLanguageTypeUnknown; 61123b1decbSDawn Perchik m_language = lldb::eLanguageTypeUnknown; 612a8558b62SJim Ingham m_skip_prologue = eLazyBoolCalculate; 6135e09c8c3SJim Ingham m_breakpoint_names.clear(); 614e732052fSJim Ingham m_all_files = false; 615a72b31c7SJim Ingham m_exception_extra_args.Clear(); 616055ad9beSIlia K m_move_to_nearest_code = eLazyBoolCalculate; 61776bb8d67SJim Ingham m_source_regex_func_names.clear(); 6183815e702SJim Ingham m_python_class.clear(); 619*796ac80bSJonas Devlieghere m_extra_args_sp = std::make_shared<StructuredData::Dictionary>(); 6203815e702SJim Ingham m_current_key.clear(); 62130fdc8d8SChris Lattner } 62230fdc8d8SChris Lattner 6231f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 62470602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_set_options); 6251f0f5b5bSZachary Turner } 62630fdc8d8SChris Lattner 6275a988416SJim Ingham // Instance variables to hold the values for command options. 628969795f1SJim Ingham 6295a988416SJim Ingham std::string m_condition; 6305a988416SJim Ingham FileSpecList m_filenames; 6315a988416SJim Ingham uint32_t m_line_num; 6325a988416SJim Ingham uint32_t m_column; 6335a988416SJim Ingham std::vector<std::string> m_func_names; 6345e09c8c3SJim Ingham std::vector<std::string> m_breakpoint_names; 635117b1fa1SZachary Turner lldb::FunctionNameType m_func_name_type_mask; 6365a988416SJim Ingham std::string m_func_regexp; 6375a988416SJim Ingham std::string m_source_text_regexp; 6385a988416SJim Ingham FileSpecList m_modules; 6395a988416SJim Ingham lldb::addr_t m_load_addr; 6402411167fSJim Ingham lldb::addr_t m_offset_addr; 6415a988416SJim Ingham bool m_catch_bp; 6425a988416SJim Ingham bool m_throw_bp; 643eb023e75SGreg Clayton bool m_hardware; // Request to use hardware breakpoints 644a72b31c7SJim Ingham lldb::LanguageType m_exception_language; 64523b1decbSDawn Perchik lldb::LanguageType m_language; 6465a988416SJim Ingham LazyBool m_skip_prologue; 647e732052fSJim Ingham bool m_all_files; 648a72b31c7SJim Ingham Args m_exception_extra_args; 649055ad9beSIlia K LazyBool m_move_to_nearest_code; 65076bb8d67SJim Ingham std::unordered_set<std::string> m_source_regex_func_names; 6513815e702SJim Ingham std::string m_python_class; 6523815e702SJim Ingham StructuredData::DictionarySP m_extra_args_sp; 6533815e702SJim Ingham std::string m_current_key; 6545a988416SJim Ingham }; 6555a988416SJim Ingham 6565a988416SJim Ingham protected: 657b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 658b842f2ecSJim Ingham Target *target = GetSelectedOrDummyTarget(m_dummy_options.m_use_dummy); 65933df7cd3SJim Ingham 660b9c1b51eSKate Stone if (target == nullptr) { 661b9c1b51eSKate Stone result.AppendError("Invalid target. Must set target before setting " 662b9c1b51eSKate Stone "breakpoints (see 'target create' command)."); 66330fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 66430fdc8d8SChris Lattner return false; 66530fdc8d8SChris Lattner } 66630fdc8d8SChris Lattner 66730fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 66830fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 66930fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 67030fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 671b9c1b51eSKate Stone // 4). -r [-s -g] (setting breakpoint by function name regular 672b9c1b51eSKate Stone // expression) 673b9c1b51eSKate Stone // 5). -p -f (setting a breakpoint by comparing a reg-exp 674b9c1b51eSKate Stone // to source text) 675b9c1b51eSKate Stone // 6). -E [-w -h] (setting a breakpoint for exceptions for a 676b9c1b51eSKate Stone // given language.) 67730fdc8d8SChris Lattner 67830fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 67930fdc8d8SChris Lattner 6803815e702SJim Ingham if (!m_options.m_python_class.empty()) 6813815e702SJim Ingham break_type = eSetTypeScripted; 6823815e702SJim Ingham else if (m_options.m_line_num != 0) 68330fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 68430fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 68530fdc8d8SChris Lattner break_type = eSetTypeAddress; 686fab10e89SJim Ingham else if (!m_options.m_func_names.empty()) 68730fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 68830fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 68930fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 690969795f1SJim Ingham else if (!m_options.m_source_text_regexp.empty()) 691969795f1SJim Ingham break_type = eSetTypeSourceRegexp; 692a72b31c7SJim Ingham else if (m_options.m_exception_language != eLanguageTypeUnknown) 693fab10e89SJim Ingham break_type = eSetTypeException; 69430fdc8d8SChris Lattner 695b842f2ecSJim Ingham BreakpointSP bp_sp = nullptr; 696274060b6SGreg Clayton FileSpec module_spec; 697a8558b62SJim Ingham const bool internal = false; 698a8558b62SJim Ingham 699b9c1b51eSKate Stone // If the user didn't specify skip-prologue, having an offset should turn 700b9c1b51eSKate Stone // that off. 701b9c1b51eSKate Stone if (m_options.m_offset_addr != 0 && 702b9c1b51eSKate Stone m_options.m_skip_prologue == eLazyBoolCalculate) 7032411167fSJim Ingham m_options.m_skip_prologue = eLazyBoolNo; 7042411167fSJim Ingham 705b9c1b51eSKate Stone switch (break_type) { 70630fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 70730fdc8d8SChris Lattner { 70830fdc8d8SChris Lattner FileSpec file; 709c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 710b9c1b51eSKate Stone if (num_files == 0) { 711b9c1b51eSKate Stone if (!GetDefaultFile(target, file, result)) { 71287df91b8SJim Ingham result.AppendError("No file supplied and no default file available."); 71387df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 71487df91b8SJim Ingham return false; 71587df91b8SJim Ingham } 716b9c1b51eSKate Stone } else if (num_files > 1) { 717b9c1b51eSKate Stone result.AppendError("Only one file at a time is allowed for file and " 718b9c1b51eSKate Stone "line breakpoints."); 71987df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 72087df91b8SJim Ingham return false; 721b9c1b51eSKate Stone } else 72287df91b8SJim Ingham file = m_options.m_filenames.GetFileSpecAtIndex(0); 72330fdc8d8SChris Lattner 7241f746071SGreg Clayton // Only check for inline functions if 7251f746071SGreg Clayton LazyBool check_inlines = eLazyBoolCalculate; 7261f746071SGreg Clayton 727b842f2ecSJim Ingham bp_sp = target->CreateBreakpoint(&(m_options.m_modules), 728b842f2ecSJim Ingham file, 729b842f2ecSJim Ingham m_options.m_line_num, 730431b1584SAdrian Prantl m_options.m_column, 731b842f2ecSJim Ingham m_options.m_offset_addr, 732b842f2ecSJim Ingham check_inlines, 733b842f2ecSJim Ingham m_options.m_skip_prologue, 734b842f2ecSJim Ingham internal, 735b842f2ecSJim Ingham m_options.m_hardware, 736b842f2ecSJim Ingham m_options.m_move_to_nearest_code); 737b9c1b51eSKate Stone } break; 7386eee5aa0SGreg Clayton 73930fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 740055a08a4SJim Ingham { 741b9c1b51eSKate Stone // If a shared library has been specified, make an lldb_private::Address 742b842f2ecSJim Ingham // with the library, and use that. That way the address breakpoint 743b842f2ecSJim Ingham // will track the load location of the library. 744055a08a4SJim Ingham size_t num_modules_specified = m_options.m_modules.GetSize(); 745b9c1b51eSKate Stone if (num_modules_specified == 1) { 746b9c1b51eSKate Stone const FileSpec *file_spec = 747b9c1b51eSKate Stone m_options.m_modules.GetFileSpecPointerAtIndex(0); 748b842f2ecSJim Ingham bp_sp = target->CreateAddressInModuleBreakpoint(m_options.m_load_addr, 749b9c1b51eSKate Stone internal, file_spec, 750b842f2ecSJim Ingham m_options.m_hardware); 751b9c1b51eSKate Stone } else if (num_modules_specified == 0) { 752b842f2ecSJim Ingham bp_sp = target->CreateBreakpoint(m_options.m_load_addr, internal, 753b842f2ecSJim Ingham m_options.m_hardware); 754b9c1b51eSKate Stone } else { 755b9c1b51eSKate Stone result.AppendError("Only one shared library can be specified for " 756b9c1b51eSKate Stone "address breakpoints."); 757055a08a4SJim Ingham result.SetStatus(eReturnStatusFailed); 758055a08a4SJim Ingham return false; 759055a08a4SJim Ingham } 76030fdc8d8SChris Lattner break; 761055a08a4SJim Ingham } 76230fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 7630c5cd90dSGreg Clayton { 764117b1fa1SZachary Turner FunctionNameType name_type_mask = m_options.m_func_name_type_mask; 7650c5cd90dSGreg Clayton 7660c5cd90dSGreg Clayton if (name_type_mask == 0) 767e02b8504SGreg Clayton name_type_mask = eFunctionNameTypeAuto; 7680c5cd90dSGreg Clayton 769b842f2ecSJim Ingham bp_sp = target->CreateBreakpoint(&(m_options.m_modules), 770b842f2ecSJim Ingham &(m_options.m_filenames), 771b842f2ecSJim Ingham m_options.m_func_names, 772b842f2ecSJim Ingham name_type_mask, 773b842f2ecSJim Ingham m_options.m_language, 774b842f2ecSJim Ingham m_options.m_offset_addr, 775b842f2ecSJim Ingham m_options.m_skip_prologue, 776b842f2ecSJim Ingham internal, 777b842f2ecSJim Ingham m_options.m_hardware); 778b9c1b51eSKate Stone } break; 7790c5cd90dSGreg Clayton 780b9c1b51eSKate Stone case eSetTypeFunctionRegexp: // Breakpoint by regular expression function 781b9c1b51eSKate Stone // name 78230fdc8d8SChris Lattner { 78395eae423SZachary Turner RegularExpression regexp(m_options.m_func_regexp); 784b9c1b51eSKate Stone if (!regexp.IsValid()) { 785969795f1SJim Ingham char err_str[1024]; 786969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 787b9c1b51eSKate Stone result.AppendErrorWithFormat( 788b9c1b51eSKate Stone "Function name regular expression could not be compiled: \"%s\"", 789969795f1SJim Ingham err_str); 79030fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 791969795f1SJim Ingham return false; 79230fdc8d8SChris Lattner } 79387df91b8SJim Ingham 794b842f2ecSJim Ingham bp_sp = target->CreateFuncRegexBreakpoint(&(m_options.m_modules), 795b842f2ecSJim Ingham &(m_options.m_filenames), 796b842f2ecSJim Ingham regexp, 797b842f2ecSJim Ingham m_options.m_language, 798b842f2ecSJim Ingham m_options.m_skip_prologue, 799b842f2ecSJim Ingham internal, 800b842f2ecSJim Ingham m_options.m_hardware); 801e14dc268SJim Ingham } 802e14dc268SJim Ingham break; 803969795f1SJim Ingham case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. 804969795f1SJim Ingham { 805c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 80687df91b8SJim Ingham 807b9c1b51eSKate Stone if (num_files == 0 && !m_options.m_all_files) { 808969795f1SJim Ingham FileSpec file; 809b9c1b51eSKate Stone if (!GetDefaultFile(target, file, result)) { 810b9c1b51eSKate Stone result.AppendError( 811b9c1b51eSKate Stone "No files provided and could not find default file."); 81287df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 81387df91b8SJim Ingham return false; 814b9c1b51eSKate Stone } else { 81587df91b8SJim Ingham m_options.m_filenames.Append(file); 81687df91b8SJim Ingham } 81787df91b8SJim Ingham } 8180c5cd90dSGreg Clayton 81995eae423SZachary Turner RegularExpression regexp(m_options.m_source_text_regexp); 820b9c1b51eSKate Stone if (!regexp.IsValid()) { 821969795f1SJim Ingham char err_str[1024]; 822969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 823b9c1b51eSKate Stone result.AppendErrorWithFormat( 824b9c1b51eSKate Stone "Source text regular expression could not be compiled: \"%s\"", 825969795f1SJim Ingham err_str); 826969795f1SJim Ingham result.SetStatus(eReturnStatusFailed); 827969795f1SJim Ingham return false; 828969795f1SJim Ingham } 829b842f2ecSJim Ingham bp_sp = 830b842f2ecSJim Ingham target->CreateSourceRegexBreakpoint(&(m_options.m_modules), 831b842f2ecSJim Ingham &(m_options.m_filenames), 832b842f2ecSJim Ingham m_options 833b842f2ecSJim Ingham .m_source_regex_func_names, 834b842f2ecSJim Ingham regexp, 835b842f2ecSJim Ingham internal, 836b842f2ecSJim Ingham m_options.m_hardware, 837b842f2ecSJim Ingham m_options.m_move_to_nearest_code); 838b9c1b51eSKate Stone } break; 839b9c1b51eSKate Stone case eSetTypeException: { 84097206d57SZachary Turner Status precond_error; 841b842f2ecSJim Ingham bp_sp = target->CreateExceptionBreakpoint(m_options.m_exception_language, 842b842f2ecSJim Ingham m_options.m_catch_bp, 843b842f2ecSJim Ingham m_options.m_throw_bp, 844b842f2ecSJim Ingham internal, 845b842f2ecSJim Ingham &m_options 846b842f2ecSJim Ingham .m_exception_extra_args, 847b842f2ecSJim Ingham &precond_error); 848b9c1b51eSKate Stone if (precond_error.Fail()) { 849b9c1b51eSKate Stone result.AppendErrorWithFormat( 850b9c1b51eSKate Stone "Error setting extra exception arguments: %s", 851a72b31c7SJim Ingham precond_error.AsCString()); 852b842f2ecSJim Ingham target->RemoveBreakpointByID(bp_sp->GetID()); 853a72b31c7SJim Ingham result.SetStatus(eReturnStatusFailed); 854a72b31c7SJim Ingham return false; 855a72b31c7SJim Ingham } 856b9c1b51eSKate Stone } break; 8573815e702SJim Ingham case eSetTypeScripted: { 8583815e702SJim Ingham 8593815e702SJim Ingham Status error; 8603815e702SJim Ingham bp_sp = target->CreateScriptedBreakpoint(m_options.m_python_class, 8613815e702SJim Ingham &(m_options.m_modules), 8623815e702SJim Ingham &(m_options.m_filenames), 8633815e702SJim Ingham false, 8643815e702SJim Ingham m_options.m_hardware, 8653815e702SJim Ingham m_options.m_extra_args_sp, 8663815e702SJim Ingham &error); 8673815e702SJim Ingham if (error.Fail()) { 8683815e702SJim Ingham result.AppendErrorWithFormat( 8693815e702SJim Ingham "Error setting extra exception arguments: %s", 8703815e702SJim Ingham error.AsCString()); 8713815e702SJim Ingham target->RemoveBreakpointByID(bp_sp->GetID()); 8723815e702SJim Ingham result.SetStatus(eReturnStatusFailed); 8733815e702SJim Ingham return false; 8743815e702SJim Ingham } 8753815e702SJim Ingham } break; 87630fdc8d8SChris Lattner default: 87730fdc8d8SChris Lattner break; 87830fdc8d8SChris Lattner } 87930fdc8d8SChris Lattner 8801b54c88cSJim Ingham // Now set the various options that were passed in: 881b842f2ecSJim Ingham if (bp_sp) { 882b842f2ecSJim Ingham bp_sp->GetOptions()->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); 883ca36cd16SJim Ingham 884b9c1b51eSKate Stone if (!m_options.m_breakpoint_names.empty()) { 88597206d57SZachary Turner Status name_error; 886ff9a91eaSJim Ingham for (auto name : m_options.m_breakpoint_names) { 887b842f2ecSJim Ingham target->AddNameToBreakpoint(bp_sp, name.c_str(), name_error); 888ff9a91eaSJim Ingham if (name_error.Fail()) { 889ff9a91eaSJim Ingham result.AppendErrorWithFormat("Invalid breakpoint name: %s", 890ff9a91eaSJim Ingham name.c_str()); 891b842f2ecSJim Ingham target->RemoveBreakpointByID(bp_sp->GetID()); 892ff9a91eaSJim Ingham result.SetStatus(eReturnStatusFailed); 893ff9a91eaSJim Ingham return false; 894ff9a91eaSJim Ingham } 895ff9a91eaSJim Ingham } 8965e09c8c3SJim Ingham } 8971b54c88cSJim Ingham } 8981b54c88cSJim Ingham 899b842f2ecSJim Ingham if (bp_sp) { 90085e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 9011391cc7dSJim Ingham const bool show_locations = false; 902b842f2ecSJim Ingham bp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, 903b9c1b51eSKate Stone show_locations); 9044aeb1989SJim Ingham if (target == m_interpreter.GetDebugger().GetDummyTarget()) 905b9c1b51eSKate Stone output_stream.Printf("Breakpoint set in dummy target, will get copied " 906b9c1b51eSKate Stone "into future targets.\n"); 907b9c1b51eSKate Stone else { 90805097246SAdrian Prantl // Don't print out this warning for exception breakpoints. They can 90905097246SAdrian Prantl // get set before the target is set, but we won't know how to actually 91005097246SAdrian Prantl // set the breakpoint till we run. 911b842f2ecSJim Ingham if (bp_sp->GetNumLocations() == 0 && break_type != eSetTypeException) { 912b9c1b51eSKate Stone output_stream.Printf("WARNING: Unable to resolve breakpoint to any " 913b9c1b51eSKate Stone "actual locations.\n"); 9144aeb1989SJim Ingham } 9154aeb1989SJim Ingham } 91630fdc8d8SChris Lattner result.SetStatus(eReturnStatusSuccessFinishResult); 917b842f2ecSJim Ingham } else if (!bp_sp) { 91830fdc8d8SChris Lattner result.AppendError("Breakpoint creation failed: No breakpoint created."); 91930fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 92030fdc8d8SChris Lattner } 92130fdc8d8SChris Lattner 92230fdc8d8SChris Lattner return result.Succeeded(); 92330fdc8d8SChris Lattner } 92430fdc8d8SChris Lattner 9255a988416SJim Ingham private: 926b9c1b51eSKate Stone bool GetDefaultFile(Target *target, FileSpec &file, 927b9c1b51eSKate Stone CommandReturnObject &result) { 9285a988416SJim Ingham uint32_t default_line; 92905097246SAdrian Prantl // First use the Source Manager's default file. Then use the current stack 93005097246SAdrian Prantl // frame's file. 931b9c1b51eSKate Stone if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) { 932b57e4a1bSJason Molenda StackFrame *cur_frame = m_exe_ctx.GetFramePtr(); 933b9c1b51eSKate Stone if (cur_frame == nullptr) { 934b9c1b51eSKate Stone result.AppendError( 935b9c1b51eSKate Stone "No selected frame to use to find the default file."); 9365a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 9375a988416SJim Ingham return false; 938b9c1b51eSKate Stone } else if (!cur_frame->HasDebugInformation()) { 939b9c1b51eSKate Stone result.AppendError("Cannot use the selected frame to find the default " 940b9c1b51eSKate Stone "file, it has no debug info."); 9415a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 9425a988416SJim Ingham return false; 943b9c1b51eSKate Stone } else { 944b9c1b51eSKate Stone const SymbolContext &sc = 945b9c1b51eSKate Stone cur_frame->GetSymbolContext(eSymbolContextLineEntry); 946b9c1b51eSKate Stone if (sc.line_entry.file) { 9475a988416SJim Ingham file = sc.line_entry.file; 948b9c1b51eSKate Stone } else { 949b9c1b51eSKate Stone result.AppendError("Can't find the file for the selected frame to " 950b9c1b51eSKate Stone "use as the default file."); 9515a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 9525a988416SJim Ingham return false; 9535a988416SJim Ingham } 9545a988416SJim Ingham } 9555a988416SJim Ingham } 9565a988416SJim Ingham return true; 9575a988416SJim Ingham } 9585a988416SJim Ingham 959b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 960b842f2ecSJim Ingham BreakpointDummyOptionGroup m_dummy_options; 9615a988416SJim Ingham CommandOptions m_options; 962b842f2ecSJim Ingham OptionGroupOptions m_all_options; 9635a988416SJim Ingham }; 9649e85e5a8SEugene Zelenko 9655a988416SJim Ingham //------------------------------------------------------------------------- 9665a988416SJim Ingham // CommandObjectBreakpointModify 9675a988416SJim Ingham //------------------------------------------------------------------------- 9685a988416SJim Ingham #pragma mark Modify 9695a988416SJim Ingham 970b9c1b51eSKate Stone class CommandObjectBreakpointModify : public CommandObjectParsed { 9715a988416SJim Ingham public: 972b9c1b51eSKate Stone CommandObjectBreakpointModify(CommandInterpreter &interpreter) 973b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "breakpoint modify", 974b9c1b51eSKate Stone "Modify the options on a breakpoint or set of " 975b9c1b51eSKate Stone "breakpoints in the executable. " 976b9c1b51eSKate Stone "If no breakpoint is specified, acts on the last " 977b9c1b51eSKate Stone "created breakpoint. " 978b9c1b51eSKate Stone "With the exception of -e, -d and -i, passing an " 979b9c1b51eSKate Stone "empty argument clears the modification.", 9809e85e5a8SEugene Zelenko nullptr), 981b9c1b51eSKate Stone m_options() { 9825a988416SJim Ingham CommandArgumentEntry arg; 983b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 984b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 985b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 986b9c1b51eSKate Stone // arguments vector. 9875a988416SJim Ingham m_arguments.push_back(arg); 988b842f2ecSJim Ingham 989b842f2ecSJim Ingham m_options.Append(&m_bp_opts, 990b842f2ecSJim Ingham LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3, 991b842f2ecSJim Ingham LLDB_OPT_SET_ALL); 992b842f2ecSJim Ingham m_options.Append(&m_dummy_opts, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 993b842f2ecSJim Ingham m_options.Finalize(); 9945a988416SJim Ingham } 9955a988416SJim Ingham 9969e85e5a8SEugene Zelenko ~CommandObjectBreakpointModify() override = default; 9975a988416SJim Ingham 998b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 9995a988416SJim Ingham 10005a988416SJim Ingham protected: 1001b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1002b842f2ecSJim Ingham Target *target = GetSelectedOrDummyTarget(m_dummy_opts.m_use_dummy); 1003b9c1b51eSKate Stone if (target == nullptr) { 10045a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 10055a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 10065a988416SJim Ingham return false; 10075a988416SJim Ingham } 10085a988416SJim Ingham 1009bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1010bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 10115a988416SJim Ingham 10125a988416SJim Ingham BreakpointIDList valid_bp_ids; 10135a988416SJim Ingham 1014b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1015b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1016b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 10175a988416SJim Ingham 1018b9c1b51eSKate Stone if (result.Succeeded()) { 10195a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1020b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 10215a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 10225a988416SJim Ingham 1023b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1024b9c1b51eSKate Stone Breakpoint *bp = 1025b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1026b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1027b9c1b51eSKate Stone BreakpointLocation *location = 1028b9c1b51eSKate Stone bp->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1029b842f2ecSJim Ingham if (location) 1030b842f2ecSJim Ingham location->GetLocationOptions() 1031b842f2ecSJim Ingham ->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); 1032b9c1b51eSKate Stone } else { 1033b842f2ecSJim Ingham bp->GetOptions() 1034b842f2ecSJim Ingham ->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); 10355a988416SJim Ingham } 10365a988416SJim Ingham } 10375a988416SJim Ingham } 10385a988416SJim Ingham } 10395a988416SJim Ingham 10405a988416SJim Ingham return result.Succeeded(); 10415a988416SJim Ingham } 10425a988416SJim Ingham 10435a988416SJim Ingham private: 1044b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 1045b842f2ecSJim Ingham BreakpointDummyOptionGroup m_dummy_opts; 1046b842f2ecSJim Ingham OptionGroupOptions m_options; 10475a988416SJim Ingham }; 10485a988416SJim Ingham 10495a988416SJim Ingham //------------------------------------------------------------------------- 10505a988416SJim Ingham // CommandObjectBreakpointEnable 10515a988416SJim Ingham //------------------------------------------------------------------------- 10525a988416SJim Ingham #pragma mark Enable 10535a988416SJim Ingham 1054b9c1b51eSKate Stone class CommandObjectBreakpointEnable : public CommandObjectParsed { 10555a988416SJim Ingham public: 1056b9c1b51eSKate Stone CommandObjectBreakpointEnable(CommandInterpreter &interpreter) 1057b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "enable", 1058b9c1b51eSKate Stone "Enable the specified disabled breakpoint(s). If " 1059b9c1b51eSKate Stone "no breakpoints are specified, enable all of them.", 1060b9c1b51eSKate Stone nullptr) { 10615a988416SJim Ingham CommandArgumentEntry arg; 1062b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1063b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1064b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1065b9c1b51eSKate Stone // arguments vector. 10665a988416SJim Ingham m_arguments.push_back(arg); 10675a988416SJim Ingham } 10685a988416SJim Ingham 10699e85e5a8SEugene Zelenko ~CommandObjectBreakpointEnable() override = default; 10705a988416SJim Ingham 10715a988416SJim Ingham protected: 1072b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1073893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1074b9c1b51eSKate Stone if (target == nullptr) { 10755a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 10765a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 10775a988416SJim Ingham return false; 10785a988416SJim Ingham } 10795a988416SJim Ingham 1080bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1081bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 10825a988416SJim Ingham 10835a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 10845a988416SJim Ingham 10855a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 10865a988416SJim Ingham 1087b9c1b51eSKate Stone if (num_breakpoints == 0) { 10885a988416SJim Ingham result.AppendError("No breakpoints exist to be enabled."); 10895a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 10905a988416SJim Ingham return false; 10915a988416SJim Ingham } 10925a988416SJim Ingham 109311eb9c64SZachary Turner if (command.empty()) { 10945a988416SJim Ingham // No breakpoint selected; enable all currently set breakpoints. 1095b842f2ecSJim Ingham target->EnableAllowedBreakpoints(); 1096b9c1b51eSKate Stone result.AppendMessageWithFormat("All breakpoints enabled. (%" PRIu64 1097b9c1b51eSKate Stone " breakpoints)\n", 1098b9c1b51eSKate Stone (uint64_t)num_breakpoints); 10995a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1100b9c1b51eSKate Stone } else { 11015a988416SJim Ingham // Particular breakpoint selected; enable that breakpoint. 11025a988416SJim Ingham BreakpointIDList valid_bp_ids; 1103b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1104b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1105b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 11065a988416SJim Ingham 1107b9c1b51eSKate Stone if (result.Succeeded()) { 11085a988416SJim Ingham int enable_count = 0; 11095a988416SJim Ingham int loc_count = 0; 11105a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1111b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 11125a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 11135a988416SJim Ingham 1114b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1115b9c1b51eSKate Stone Breakpoint *breakpoint = 1116b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1117b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1118b9c1b51eSKate Stone BreakpointLocation *location = 1119b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1120b9c1b51eSKate Stone if (location) { 11215a988416SJim Ingham location->SetEnabled(true); 11225a988416SJim Ingham ++loc_count; 11235a988416SJim Ingham } 1124b9c1b51eSKate Stone } else { 11255a988416SJim Ingham breakpoint->SetEnabled(true); 11265a988416SJim Ingham ++enable_count; 11275a988416SJim Ingham } 11285a988416SJim Ingham } 11295a988416SJim Ingham } 1130b9c1b51eSKate Stone result.AppendMessageWithFormat("%d breakpoints enabled.\n", 1131b9c1b51eSKate Stone enable_count + loc_count); 11325a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 11335a988416SJim Ingham } 11345a988416SJim Ingham } 11355a988416SJim Ingham 11365a988416SJim Ingham return result.Succeeded(); 11375a988416SJim Ingham } 11385a988416SJim Ingham }; 11395a988416SJim Ingham 11405a988416SJim Ingham //------------------------------------------------------------------------- 11415a988416SJim Ingham // CommandObjectBreakpointDisable 11425a988416SJim Ingham //------------------------------------------------------------------------- 11435a988416SJim Ingham #pragma mark Disable 11445a988416SJim Ingham 1145b9c1b51eSKate Stone class CommandObjectBreakpointDisable : public CommandObjectParsed { 11465a988416SJim Ingham public: 11477428a18cSKate Stone CommandObjectBreakpointDisable(CommandInterpreter &interpreter) 1148b9c1b51eSKate Stone : CommandObjectParsed( 1149b9c1b51eSKate Stone interpreter, "breakpoint disable", 1150b9c1b51eSKate Stone "Disable the specified breakpoint(s) without deleting " 11517428a18cSKate Stone "them. If none are specified, disable all " 11527428a18cSKate Stone "breakpoints.", 1153b9c1b51eSKate Stone nullptr) { 1154b9c1b51eSKate Stone SetHelpLong( 1155b9c1b51eSKate Stone "Disable the specified breakpoint(s) without deleting them. \ 11567428a18cSKate Stone If none are specified, disable all breakpoints." 11577428a18cSKate Stone R"( 1158ea671fbdSKate Stone 11597428a18cSKate Stone )" 11607428a18cSKate Stone "Note: disabling a breakpoint will cause none of its locations to be hit \ 11617428a18cSKate Stone regardless of whether individual locations are enabled or disabled. After the sequence:" 11627428a18cSKate Stone R"( 1163ea671fbdSKate Stone 1164ea671fbdSKate Stone (lldb) break disable 1 1165ea671fbdSKate Stone (lldb) break enable 1.1 1166ea671fbdSKate Stone 1167ea671fbdSKate Stone execution will NOT stop at location 1.1. To achieve that, type: 1168ea671fbdSKate Stone 1169ea671fbdSKate Stone (lldb) break disable 1.* 1170ea671fbdSKate Stone (lldb) break enable 1.1 1171ea671fbdSKate Stone 11727428a18cSKate Stone )" 11737428a18cSKate Stone "The first command disables all locations for breakpoint 1, \ 11747428a18cSKate Stone the second re-enables the first location."); 1175b0fac509SJim Ingham 11765a988416SJim Ingham CommandArgumentEntry arg; 1177b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1178b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1179b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1180b9c1b51eSKate Stone // arguments vector. 11815a988416SJim Ingham m_arguments.push_back(arg); 11825a988416SJim Ingham } 11835a988416SJim Ingham 11849e85e5a8SEugene Zelenko ~CommandObjectBreakpointDisable() override = default; 11855a988416SJim Ingham 11865a988416SJim Ingham protected: 1187b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1188893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1189b9c1b51eSKate Stone if (target == nullptr) { 11905a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 11915a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 11925a988416SJim Ingham return false; 11935a988416SJim Ingham } 11945a988416SJim Ingham 1195bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1196bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 11975a988416SJim Ingham 11985a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 11995a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 12005a988416SJim Ingham 1201b9c1b51eSKate Stone if (num_breakpoints == 0) { 12025a988416SJim Ingham result.AppendError("No breakpoints exist to be disabled."); 12035a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 12045a988416SJim Ingham return false; 12055a988416SJim Ingham } 12065a988416SJim Ingham 120711eb9c64SZachary Turner if (command.empty()) { 12085a988416SJim Ingham // No breakpoint selected; disable all currently set breakpoints. 1209b842f2ecSJim Ingham target->DisableAllowedBreakpoints(); 1210b9c1b51eSKate Stone result.AppendMessageWithFormat("All breakpoints disabled. (%" PRIu64 1211b9c1b51eSKate Stone " breakpoints)\n", 1212b9c1b51eSKate Stone (uint64_t)num_breakpoints); 12135a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1214b9c1b51eSKate Stone } else { 12155a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 12165a988416SJim Ingham BreakpointIDList valid_bp_ids; 12175a988416SJim Ingham 1218b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1219b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1220b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 12215a988416SJim Ingham 1222b9c1b51eSKate Stone if (result.Succeeded()) { 12235a988416SJim Ingham int disable_count = 0; 12245a988416SJim Ingham int loc_count = 0; 12255a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1226b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 12275a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 12285a988416SJim Ingham 1229b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1230b9c1b51eSKate Stone Breakpoint *breakpoint = 1231b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1232b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1233b9c1b51eSKate Stone BreakpointLocation *location = 1234b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1235b9c1b51eSKate Stone if (location) { 12365a988416SJim Ingham location->SetEnabled(false); 12375a988416SJim Ingham ++loc_count; 12385a988416SJim Ingham } 1239b9c1b51eSKate Stone } else { 12405a988416SJim Ingham breakpoint->SetEnabled(false); 12415a988416SJim Ingham ++disable_count; 12425a988416SJim Ingham } 12435a988416SJim Ingham } 12445a988416SJim Ingham } 1245b9c1b51eSKate Stone result.AppendMessageWithFormat("%d breakpoints disabled.\n", 1246b9c1b51eSKate Stone disable_count + loc_count); 12475a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 12485a988416SJim Ingham } 12495a988416SJim Ingham } 12505a988416SJim Ingham 12515a988416SJim Ingham return result.Succeeded(); 12525a988416SJim Ingham } 12535a988416SJim Ingham }; 12545a988416SJim Ingham 12555a988416SJim Ingham //------------------------------------------------------------------------- 12565a988416SJim Ingham // CommandObjectBreakpointList 12575a988416SJim Ingham //------------------------------------------------------------------------- 12581f0f5b5bSZachary Turner 12591f0f5b5bSZachary Turner #pragma mark List::CommandOptions 12608fe53c49STatyana Krasnukha static constexpr OptionDefinition g_breakpoint_list_options[] = { 12611f0f5b5bSZachary Turner // clang-format off 12628fe53c49STatyana Krasnukha { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Show debugger internal breakpoints" }, 12638fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Give a brief description of the breakpoint (no location info)." }, 12641f0f5b5bSZachary Turner // FIXME: We need to add an "internal" command, and then add this sort of thing to it. 12651f0f5b5bSZachary Turner // But I need to see it for now, and don't want to wait. 12668fe53c49STatyana Krasnukha { LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Give a full description of the breakpoint and its locations." }, 12678fe53c49STatyana Krasnukha { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, 12688fe53c49STatyana Krasnukha { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets." }, 12691f0f5b5bSZachary Turner // clang-format on 12701f0f5b5bSZachary Turner }; 12711f0f5b5bSZachary Turner 12725a988416SJim Ingham #pragma mark List 12735a988416SJim Ingham 1274b9c1b51eSKate Stone class CommandObjectBreakpointList : public CommandObjectParsed { 12755a988416SJim Ingham public: 1276b9c1b51eSKate Stone CommandObjectBreakpointList(CommandInterpreter &interpreter) 1277b9c1b51eSKate Stone : CommandObjectParsed( 1278b9c1b51eSKate Stone interpreter, "breakpoint list", 12795a988416SJim Ingham "List some or all breakpoints at configurable levels of detail.", 12809e85e5a8SEugene Zelenko nullptr), 1281b9c1b51eSKate Stone m_options() { 12825a988416SJim Ingham CommandArgumentEntry arg; 12835a988416SJim Ingham CommandArgumentData bp_id_arg; 12845a988416SJim Ingham 12855a988416SJim Ingham // Define the first (and only) variant of this arg. 12865a988416SJim Ingham bp_id_arg.arg_type = eArgTypeBreakpointID; 12875a988416SJim Ingham bp_id_arg.arg_repetition = eArgRepeatOptional; 12885a988416SJim Ingham 1289b9c1b51eSKate Stone // There is only one variant this argument could be; put it into the 1290b9c1b51eSKate Stone // argument entry. 12915a988416SJim Ingham arg.push_back(bp_id_arg); 12925a988416SJim Ingham 12935a988416SJim Ingham // Push the data for the first argument into the m_arguments vector. 12945a988416SJim Ingham m_arguments.push_back(arg); 12955a988416SJim Ingham } 12965a988416SJim Ingham 12979e85e5a8SEugene Zelenko ~CommandObjectBreakpointList() override = default; 12985a988416SJim Ingham 1299b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 13005a988416SJim Ingham 1301b9c1b51eSKate Stone class CommandOptions : public Options { 13025a988416SJim Ingham public: 1303b9c1b51eSKate Stone CommandOptions() 1304b9c1b51eSKate Stone : Options(), m_level(lldb::eDescriptionLevelBrief), m_use_dummy(false) { 13055a988416SJim Ingham } 13065a988416SJim Ingham 13079e85e5a8SEugene Zelenko ~CommandOptions() override = default; 13085a988416SJim Ingham 130997206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1310b9c1b51eSKate Stone ExecutionContext *execution_context) override { 131197206d57SZachary Turner Status error; 13123bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 13135a988416SJim Ingham 1314b9c1b51eSKate Stone switch (short_option) { 13155a988416SJim Ingham case 'b': 13165a988416SJim Ingham m_level = lldb::eDescriptionLevelBrief; 13175a988416SJim Ingham break; 131833df7cd3SJim Ingham case 'D': 131933df7cd3SJim Ingham m_use_dummy = true; 132033df7cd3SJim Ingham break; 13215a988416SJim Ingham case 'f': 13225a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 13235a988416SJim Ingham break; 13245a988416SJim Ingham case 'v': 13255a988416SJim Ingham m_level = lldb::eDescriptionLevelVerbose; 13265a988416SJim Ingham break; 13275a988416SJim Ingham case 'i': 13285a988416SJim Ingham m_internal = true; 13295a988416SJim Ingham break; 13305a988416SJim Ingham default: 1331b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1332b9c1b51eSKate Stone short_option); 13335a988416SJim Ingham break; 13345a988416SJim Ingham } 13355a988416SJim Ingham 13365a988416SJim Ingham return error; 13375a988416SJim Ingham } 13385a988416SJim Ingham 1339b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 13405a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 13415a988416SJim Ingham m_internal = false; 134233df7cd3SJim Ingham m_use_dummy = false; 13435a988416SJim Ingham } 13445a988416SJim Ingham 13451f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 134670602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_list_options); 13471f0f5b5bSZachary Turner } 13485a988416SJim Ingham 13495a988416SJim Ingham // Instance variables to hold the values for command options. 13505a988416SJim Ingham 13515a988416SJim Ingham lldb::DescriptionLevel m_level; 13525a988416SJim Ingham 13535a988416SJim Ingham bool m_internal; 135433df7cd3SJim Ingham bool m_use_dummy; 13555a988416SJim Ingham }; 13565a988416SJim Ingham 13575a988416SJim Ingham protected: 1358b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 135933df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 136033df7cd3SJim Ingham 1361b9c1b51eSKate Stone if (target == nullptr) { 13625a988416SJim Ingham result.AppendError("Invalid target. No current target or breakpoints."); 13635a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 13645a988416SJim Ingham return true; 13655a988416SJim Ingham } 13665a988416SJim Ingham 1367b9c1b51eSKate Stone const BreakpointList &breakpoints = 1368b9c1b51eSKate Stone target->GetBreakpointList(m_options.m_internal); 1369bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1370bb19a13cSSaleem Abdulrasool target->GetBreakpointList(m_options.m_internal).GetListMutex(lock); 13715a988416SJim Ingham 13725a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 13735a988416SJim Ingham 1374b9c1b51eSKate Stone if (num_breakpoints == 0) { 13755a988416SJim Ingham result.AppendMessage("No breakpoints currently set."); 13765a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 13775a988416SJim Ingham return true; 13785a988416SJim Ingham } 13795a988416SJim Ingham 13805a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 13815a988416SJim Ingham 138211eb9c64SZachary Turner if (command.empty()) { 13835a988416SJim Ingham // No breakpoint selected; show info about all currently set breakpoints. 13845a988416SJim Ingham result.AppendMessage("Current breakpoints:"); 1385b9c1b51eSKate Stone for (size_t i = 0; i < num_breakpoints; ++i) { 13865a988416SJim Ingham Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex(i).get(); 1387b842f2ecSJim Ingham if (breakpoint->AllowList()) 1388b842f2ecSJim Ingham AddBreakpointDescription(&output_stream, breakpoint, 1389b842f2ecSJim Ingham m_options.m_level); 13905a988416SJim Ingham } 13915a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1392b9c1b51eSKate Stone } else { 13935a988416SJim Ingham // Particular breakpoints selected; show info about that breakpoint. 13945a988416SJim Ingham BreakpointIDList valid_bp_ids; 1395b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1396b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1397b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 13985a988416SJim Ingham 1399b9c1b51eSKate Stone if (result.Succeeded()) { 1400b9c1b51eSKate Stone for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) { 14015a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 1402b9c1b51eSKate Stone Breakpoint *breakpoint = 1403b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1404b9c1b51eSKate Stone AddBreakpointDescription(&output_stream, breakpoint, 1405b9c1b51eSKate Stone m_options.m_level); 14065a988416SJim Ingham } 14075a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1408b9c1b51eSKate Stone } else { 14097428a18cSKate Stone result.AppendError("Invalid breakpoint ID."); 14105a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 14115a988416SJim Ingham } 14125a988416SJim Ingham } 14135a988416SJim Ingham 14145a988416SJim Ingham return result.Succeeded(); 14155a988416SJim Ingham } 14165a988416SJim Ingham 14175a988416SJim Ingham private: 14185a988416SJim Ingham CommandOptions m_options; 14195a988416SJim Ingham }; 14205a988416SJim Ingham 14215a988416SJim Ingham //------------------------------------------------------------------------- 14225a988416SJim Ingham // CommandObjectBreakpointClear 14235a988416SJim Ingham //------------------------------------------------------------------------- 14241f0f5b5bSZachary Turner #pragma mark Clear::CommandOptions 14251f0f5b5bSZachary Turner 14268fe53c49STatyana Krasnukha static constexpr OptionDefinition g_breakpoint_clear_options[] = { 14271f0f5b5bSZachary Turner // clang-format off 14288fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, {}, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specify the breakpoint by source location in this particular file." }, 14298fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeLineNum, "Specify the breakpoint by source location at this particular line." } 14301f0f5b5bSZachary Turner // clang-format on 14311f0f5b5bSZachary Turner }; 14321f0f5b5bSZachary Turner 14335a988416SJim Ingham #pragma mark Clear 14345a988416SJim Ingham 1435b9c1b51eSKate Stone class CommandObjectBreakpointClear : public CommandObjectParsed { 14365a988416SJim Ingham public: 1437b9c1b51eSKate Stone typedef enum BreakpointClearType { 14385a988416SJim Ingham eClearTypeInvalid, 14395a988416SJim Ingham eClearTypeFileAndLine 14405a988416SJim Ingham } BreakpointClearType; 14415a988416SJim Ingham 14427428a18cSKate Stone CommandObjectBreakpointClear(CommandInterpreter &interpreter) 14437428a18cSKate Stone : CommandObjectParsed(interpreter, "breakpoint clear", 1444b9c1b51eSKate Stone "Delete or disable breakpoints matching the " 1445b9c1b51eSKate Stone "specified source file and line.", 14465a988416SJim Ingham "breakpoint clear <cmd-options>"), 1447b9c1b51eSKate Stone m_options() {} 14485a988416SJim Ingham 14499e85e5a8SEugene Zelenko ~CommandObjectBreakpointClear() override = default; 14505a988416SJim Ingham 1451b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 14525a988416SJim Ingham 1453b9c1b51eSKate Stone class CommandOptions : public Options { 14545a988416SJim Ingham public: 1455b9c1b51eSKate Stone CommandOptions() : Options(), m_filename(), m_line_num(0) {} 14565a988416SJim Ingham 14579e85e5a8SEugene Zelenko ~CommandOptions() override = default; 14585a988416SJim Ingham 145997206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1460b9c1b51eSKate Stone ExecutionContext *execution_context) override { 146197206d57SZachary Turner Status error; 14623bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 14635a988416SJim Ingham 1464b9c1b51eSKate Stone switch (short_option) { 14655a988416SJim Ingham case 'f': 14665a988416SJim Ingham m_filename.assign(option_arg); 14675a988416SJim Ingham break; 14685a988416SJim Ingham 14695a988416SJim Ingham case 'l': 1470fe11483bSZachary Turner option_arg.getAsInteger(0, m_line_num); 14715a988416SJim Ingham break; 14725a988416SJim Ingham 14735a988416SJim Ingham default: 1474b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1475b9c1b51eSKate Stone short_option); 14765a988416SJim Ingham break; 14775a988416SJim Ingham } 14785a988416SJim Ingham 14795a988416SJim Ingham return error; 14805a988416SJim Ingham } 14815a988416SJim Ingham 1482b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 14835a988416SJim Ingham m_filename.clear(); 14845a988416SJim Ingham m_line_num = 0; 14855a988416SJim Ingham } 14865a988416SJim Ingham 14871f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 148870602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_clear_options); 14891f0f5b5bSZachary Turner } 14905a988416SJim Ingham 14915a988416SJim Ingham // Instance variables to hold the values for command options. 14925a988416SJim Ingham 14935a988416SJim Ingham std::string m_filename; 14945a988416SJim Ingham uint32_t m_line_num; 14955a988416SJim Ingham }; 14965a988416SJim Ingham 14975a988416SJim Ingham protected: 1498b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1499893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1500b9c1b51eSKate Stone if (target == nullptr) { 15015a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 15025a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 15035a988416SJim Ingham return false; 15045a988416SJim Ingham } 15055a988416SJim Ingham 150605097246SAdrian Prantl // The following are the various types of breakpoints that could be 150705097246SAdrian Prantl // cleared: 15085a988416SJim Ingham // 1). -f -l (clearing breakpoint by source location) 15095a988416SJim Ingham 15105a988416SJim Ingham BreakpointClearType break_type = eClearTypeInvalid; 15115a988416SJim Ingham 15125a988416SJim Ingham if (m_options.m_line_num != 0) 15135a988416SJim Ingham break_type = eClearTypeFileAndLine; 15145a988416SJim Ingham 1515bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1516bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 15175a988416SJim Ingham 15185a988416SJim Ingham BreakpointList &breakpoints = target->GetBreakpointList(); 15195a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 15205a988416SJim Ingham 15215a988416SJim Ingham // Early return if there's no breakpoint at all. 1522b9c1b51eSKate Stone if (num_breakpoints == 0) { 15235a988416SJim Ingham result.AppendError("Breakpoint clear: No breakpoint cleared."); 15245a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 15255a988416SJim Ingham return result.Succeeded(); 15265a988416SJim Ingham } 15275a988416SJim Ingham 15285a988416SJim Ingham // Find matching breakpoints and delete them. 15295a988416SJim Ingham 15305a988416SJim Ingham // First create a copy of all the IDs. 15315a988416SJim Ingham std::vector<break_id_t> BreakIDs; 15325a988416SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) 15339e85e5a8SEugene Zelenko BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID()); 15345a988416SJim Ingham 15355a988416SJim Ingham int num_cleared = 0; 15365a988416SJim Ingham StreamString ss; 1537b9c1b51eSKate Stone switch (break_type) { 15385a988416SJim Ingham case eClearTypeFileAndLine: // Breakpoint by source position 15395a988416SJim Ingham { 15405a988416SJim Ingham const ConstString filename(m_options.m_filename.c_str()); 15415a988416SJim Ingham BreakpointLocationCollection loc_coll; 15425a988416SJim Ingham 1543b9c1b51eSKate Stone for (size_t i = 0; i < num_breakpoints; ++i) { 15445a988416SJim Ingham Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); 15455a988416SJim Ingham 1546b9c1b51eSKate Stone if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) { 1547b9c1b51eSKate Stone // If the collection size is 0, it's a full match and we can just 1548b9c1b51eSKate Stone // remove the breakpoint. 1549b9c1b51eSKate Stone if (loc_coll.GetSize() == 0) { 15505a988416SJim Ingham bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); 15515a988416SJim Ingham ss.EOL(); 15525a988416SJim Ingham target->RemoveBreakpointByID(bp->GetID()); 15535a988416SJim Ingham ++num_cleared; 15545a988416SJim Ingham } 15555a988416SJim Ingham } 15565a988416SJim Ingham } 1557b9c1b51eSKate Stone } break; 15585a988416SJim Ingham 15595a988416SJim Ingham default: 15605a988416SJim Ingham break; 15615a988416SJim Ingham } 15625a988416SJim Ingham 1563b9c1b51eSKate Stone if (num_cleared > 0) { 15645a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 15655a988416SJim Ingham output_stream.Printf("%d breakpoints cleared:\n", num_cleared); 1566c156427dSZachary Turner output_stream << ss.GetString(); 15675a988416SJim Ingham output_stream.EOL(); 15685a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1569b9c1b51eSKate Stone } else { 15705a988416SJim Ingham result.AppendError("Breakpoint clear: No breakpoint cleared."); 15715a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 15725a988416SJim Ingham } 15735a988416SJim Ingham 15745a988416SJim Ingham return result.Succeeded(); 15755a988416SJim Ingham } 15765a988416SJim Ingham 15775a988416SJim Ingham private: 15785a988416SJim Ingham CommandOptions m_options; 15795a988416SJim Ingham }; 15805a988416SJim Ingham 15815a988416SJim Ingham //------------------------------------------------------------------------- 15825a988416SJim Ingham // CommandObjectBreakpointDelete 15835a988416SJim Ingham //------------------------------------------------------------------------- 15848fe53c49STatyana Krasnukha static constexpr OptionDefinition g_breakpoint_delete_options[] = { 15851f0f5b5bSZachary Turner // clang-format off 15868fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Delete all breakpoints without querying for confirmation." }, 15878fe53c49STatyana Krasnukha { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets." }, 15881f0f5b5bSZachary Turner // clang-format on 15891f0f5b5bSZachary Turner }; 15901f0f5b5bSZachary Turner 15915a988416SJim Ingham #pragma mark Delete 15925a988416SJim Ingham 1593b9c1b51eSKate Stone class CommandObjectBreakpointDelete : public CommandObjectParsed { 15945a988416SJim Ingham public: 1595b9c1b51eSKate Stone CommandObjectBreakpointDelete(CommandInterpreter &interpreter) 1596b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "breakpoint delete", 1597b9c1b51eSKate Stone "Delete the specified breakpoint(s). If no " 1598b9c1b51eSKate Stone "breakpoints are specified, delete them all.", 15999e85e5a8SEugene Zelenko nullptr), 1600b9c1b51eSKate Stone m_options() { 16015a988416SJim Ingham CommandArgumentEntry arg; 1602b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1603b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1604b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1605b9c1b51eSKate Stone // arguments vector. 16065a988416SJim Ingham m_arguments.push_back(arg); 16075a988416SJim Ingham } 16085a988416SJim Ingham 16099e85e5a8SEugene Zelenko ~CommandObjectBreakpointDelete() override = default; 16105a988416SJim Ingham 1611b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 161233df7cd3SJim Ingham 1613b9c1b51eSKate Stone class CommandOptions : public Options { 161433df7cd3SJim Ingham public: 1615b9c1b51eSKate Stone CommandOptions() : Options(), m_use_dummy(false), m_force(false) {} 161633df7cd3SJim Ingham 16179e85e5a8SEugene Zelenko ~CommandOptions() override = default; 161833df7cd3SJim Ingham 161997206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1620b9c1b51eSKate Stone ExecutionContext *execution_context) override { 162197206d57SZachary Turner Status error; 162233df7cd3SJim Ingham const int short_option = m_getopt_table[option_idx].val; 162333df7cd3SJim Ingham 1624b9c1b51eSKate Stone switch (short_option) { 162533df7cd3SJim Ingham case 'f': 162633df7cd3SJim Ingham m_force = true; 162733df7cd3SJim Ingham break; 162833df7cd3SJim Ingham 162933df7cd3SJim Ingham case 'D': 163033df7cd3SJim Ingham m_use_dummy = true; 163133df7cd3SJim Ingham break; 163233df7cd3SJim Ingham 163333df7cd3SJim Ingham default: 1634b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1635b9c1b51eSKate Stone short_option); 163633df7cd3SJim Ingham break; 163733df7cd3SJim Ingham } 163833df7cd3SJim Ingham 163933df7cd3SJim Ingham return error; 164033df7cd3SJim Ingham } 164133df7cd3SJim Ingham 1642b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 164333df7cd3SJim Ingham m_use_dummy = false; 164433df7cd3SJim Ingham m_force = false; 164533df7cd3SJim Ingham } 164633df7cd3SJim Ingham 16471f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 164870602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_delete_options); 16491f0f5b5bSZachary Turner } 165033df7cd3SJim Ingham 165133df7cd3SJim Ingham // Instance variables to hold the values for command options. 165233df7cd3SJim Ingham bool m_use_dummy; 165333df7cd3SJim Ingham bool m_force; 165433df7cd3SJim Ingham }; 165533df7cd3SJim Ingham 16565a988416SJim Ingham protected: 1657b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 165833df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 165933df7cd3SJim Ingham 1660b9c1b51eSKate Stone if (target == nullptr) { 16615a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 16625a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 16635a988416SJim Ingham return false; 16645a988416SJim Ingham } 16655a988416SJim Ingham 1666bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1667bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 16685a988416SJim Ingham 16695a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 16705a988416SJim Ingham 16715a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 16725a988416SJim Ingham 1673b9c1b51eSKate Stone if (num_breakpoints == 0) { 16745a988416SJim Ingham result.AppendError("No breakpoints exist to be deleted."); 16755a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 16765a988416SJim Ingham return false; 16775a988416SJim Ingham } 16785a988416SJim Ingham 167911eb9c64SZachary Turner if (command.empty()) { 1680b9c1b51eSKate Stone if (!m_options.m_force && 1681b9c1b51eSKate Stone !m_interpreter.Confirm( 1682b9c1b51eSKate Stone "About to delete all breakpoints, do you want to do that?", 1683b9c1b51eSKate Stone true)) { 16845a988416SJim Ingham result.AppendMessage("Operation cancelled..."); 1685b9c1b51eSKate Stone } else { 1686b842f2ecSJim Ingham target->RemoveAllowedBreakpoints(); 1687b9c1b51eSKate Stone result.AppendMessageWithFormat( 1688b9c1b51eSKate Stone "All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", 1689b9c1b51eSKate Stone (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : ""); 16905a988416SJim Ingham } 16915a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1692b9c1b51eSKate Stone } else { 16935a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 16945a988416SJim Ingham BreakpointIDList valid_bp_ids; 1695b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1696b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1697b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::deletePerm); 16985a988416SJim Ingham 1699b9c1b51eSKate Stone if (result.Succeeded()) { 17005a988416SJim Ingham int delete_count = 0; 17015a988416SJim Ingham int disable_count = 0; 17025a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1703b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 17045a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 17055a988416SJim Ingham 1706b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1707b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1708b9c1b51eSKate Stone Breakpoint *breakpoint = 1709b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1710b9c1b51eSKate Stone BreakpointLocation *location = 1711b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1712b9c1b51eSKate Stone // It makes no sense to try to delete individual locations, so we 1713b9c1b51eSKate Stone // disable them instead. 1714b9c1b51eSKate Stone if (location) { 17155a988416SJim Ingham location->SetEnabled(false); 17165a988416SJim Ingham ++disable_count; 17175a988416SJim Ingham } 1718b9c1b51eSKate Stone } else { 17195a988416SJim Ingham target->RemoveBreakpointByID(cur_bp_id.GetBreakpointID()); 17205a988416SJim Ingham ++delete_count; 17215a988416SJim Ingham } 17225a988416SJim Ingham } 17235a988416SJim Ingham } 1724b9c1b51eSKate Stone result.AppendMessageWithFormat( 1725b9c1b51eSKate Stone "%d breakpoints deleted; %d breakpoint locations disabled.\n", 17265a988416SJim Ingham delete_count, disable_count); 17275a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 17285a988416SJim Ingham } 17295a988416SJim Ingham } 17305a988416SJim Ingham return result.Succeeded(); 17315a988416SJim Ingham } 17329e85e5a8SEugene Zelenko 173333df7cd3SJim Ingham private: 173433df7cd3SJim Ingham CommandOptions m_options; 173533df7cd3SJim Ingham }; 173633df7cd3SJim Ingham 173730fdc8d8SChris Lattner //------------------------------------------------------------------------- 17385e09c8c3SJim Ingham // CommandObjectBreakpointName 17395e09c8c3SJim Ingham //------------------------------------------------------------------------- 17405e09c8c3SJim Ingham 17418fe53c49STatyana Krasnukha static constexpr OptionDefinition g_breakpoint_name_options[] = { 1742ac9c3a62SKate Stone // clang-format off 17438fe53c49STatyana Krasnukha {LLDB_OPT_SET_1, false, "name", 'N', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."}, 17448fe53c49STatyana Krasnukha {LLDB_OPT_SET_2, false, "breakpoint-id", 'B', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBreakpointID, "Specify a breakpoint ID to use."}, 17458fe53c49STatyana Krasnukha {LLDB_OPT_SET_3, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Operate on Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, 17468fe53c49STatyana Krasnukha {LLDB_OPT_SET_4, false, "help-string", 'H', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeNone, "A help string describing the purpose of this name."}, 1747ac9c3a62SKate Stone // clang-format on 17485e09c8c3SJim Ingham }; 1749b9c1b51eSKate Stone class BreakpointNameOptionGroup : public OptionGroup { 17505e09c8c3SJim Ingham public: 1751b9c1b51eSKate Stone BreakpointNameOptionGroup() 1752b9c1b51eSKate Stone : OptionGroup(), m_breakpoint(LLDB_INVALID_BREAK_ID), m_use_dummy(false) { 17535e09c8c3SJim Ingham } 17545e09c8c3SJim Ingham 17559e85e5a8SEugene Zelenko ~BreakpointNameOptionGroup() override = default; 17565e09c8c3SJim Ingham 17571f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 175870602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_name_options); 17595e09c8c3SJim Ingham } 17605e09c8c3SJim Ingham 176197206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1762b9c1b51eSKate Stone ExecutionContext *execution_context) override { 176397206d57SZachary Turner Status error; 17645e09c8c3SJim Ingham const int short_option = g_breakpoint_name_options[option_idx].short_option; 17655e09c8c3SJim Ingham 1766b9c1b51eSKate Stone switch (short_option) { 17675e09c8c3SJim Ingham case 'N': 1768fe11483bSZachary Turner if (BreakpointID::StringIsBreakpointName(option_arg, error) && 1769b9c1b51eSKate Stone error.Success()) 1770fe11483bSZachary Turner m_name.SetValueFromString(option_arg); 17715e09c8c3SJim Ingham break; 17725e09c8c3SJim Ingham case 'B': 1773fe11483bSZachary Turner if (m_breakpoint.SetValueFromString(option_arg).Fail()) 1774b9c1b51eSKate Stone error.SetErrorStringWithFormat( 17758cef4b0bSZachary Turner "unrecognized value \"%s\" for breakpoint", 1776fe11483bSZachary Turner option_arg.str().c_str()); 17775e09c8c3SJim Ingham break; 17785e09c8c3SJim Ingham case 'D': 1779fe11483bSZachary Turner if (m_use_dummy.SetValueFromString(option_arg).Fail()) 1780b9c1b51eSKate Stone error.SetErrorStringWithFormat( 17818cef4b0bSZachary Turner "unrecognized value \"%s\" for use-dummy", 1782fe11483bSZachary Turner option_arg.str().c_str()); 17835e09c8c3SJim Ingham break; 1784e9632ebaSJim Ingham case 'H': 1785e9632ebaSJim Ingham m_help_string.SetValueFromString(option_arg); 1786e9632ebaSJim Ingham break; 17875e09c8c3SJim Ingham 17885e09c8c3SJim Ingham default: 1789b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized short option '%c'", 1790b9c1b51eSKate Stone short_option); 17915e09c8c3SJim Ingham break; 17925e09c8c3SJim Ingham } 17935e09c8c3SJim Ingham return error; 17945e09c8c3SJim Ingham } 17955e09c8c3SJim Ingham 1796b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 17975e09c8c3SJim Ingham m_name.Clear(); 17985e09c8c3SJim Ingham m_breakpoint.Clear(); 17995e09c8c3SJim Ingham m_use_dummy.Clear(); 18005e09c8c3SJim Ingham m_use_dummy.SetDefaultValue(false); 1801e9632ebaSJim Ingham m_help_string.Clear(); 18025e09c8c3SJim Ingham } 18035e09c8c3SJim Ingham 18045e09c8c3SJim Ingham OptionValueString m_name; 18055e09c8c3SJim Ingham OptionValueUInt64 m_breakpoint; 18065e09c8c3SJim Ingham OptionValueBoolean m_use_dummy; 1807e9632ebaSJim Ingham OptionValueString m_help_string; 18085e09c8c3SJim Ingham }; 18095e09c8c3SJim Ingham 18108fe53c49STatyana Krasnukha static constexpr OptionDefinition g_breakpoint_access_options[] = { 1811b842f2ecSJim Ingham // clang-format off 18128fe53c49STatyana Krasnukha {LLDB_OPT_SET_1, false, "allow-list", 'L', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "Determines whether the breakpoint will show up in break list if not referred to explicitly."}, 18138fe53c49STatyana Krasnukha {LLDB_OPT_SET_2, false, "allow-disable", 'A', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "Determines whether the breakpoint can be disabled by name or when all breakpoints are disabled."}, 18148fe53c49STatyana Krasnukha {LLDB_OPT_SET_3, false, "allow-delete", 'D', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "Determines whether the breakpoint can be deleted by name or when all breakpoints are deleted."}, 1815b842f2ecSJim Ingham // clang-format on 1816b842f2ecSJim Ingham }; 1817b842f2ecSJim Ingham 18188fe53c49STatyana Krasnukha class BreakpointAccessOptionGroup : public OptionGroup { 1819b842f2ecSJim Ingham public: 18208fe53c49STatyana Krasnukha BreakpointAccessOptionGroup() : OptionGroup() {} 1821b842f2ecSJim Ingham 1822b842f2ecSJim Ingham ~BreakpointAccessOptionGroup() override = default; 1823b842f2ecSJim Ingham 1824b842f2ecSJim Ingham llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 1825b842f2ecSJim Ingham return llvm::makeArrayRef(g_breakpoint_access_options); 1826b842f2ecSJim Ingham } 1827b842f2ecSJim Ingham Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1828b842f2ecSJim Ingham ExecutionContext *execution_context) override { 1829b842f2ecSJim Ingham Status error; 1830b842f2ecSJim Ingham const int short_option 1831b842f2ecSJim Ingham = g_breakpoint_access_options[option_idx].short_option; 1832b842f2ecSJim Ingham 1833b842f2ecSJim Ingham switch (short_option) { 1834b842f2ecSJim Ingham case 'L': { 1835b842f2ecSJim Ingham bool value, success; 183647cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1837b842f2ecSJim Ingham if (success) { 1838b842f2ecSJim Ingham m_permissions.SetAllowList(value); 1839b842f2ecSJim Ingham } else 1840b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1841b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1842b842f2ecSJim Ingham option_arg.str().c_str()); 1843b842f2ecSJim Ingham } break; 1844b842f2ecSJim Ingham case 'A': { 1845b842f2ecSJim Ingham bool value, success; 184647cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1847b842f2ecSJim Ingham if (success) { 1848b842f2ecSJim Ingham m_permissions.SetAllowDisable(value); 1849b842f2ecSJim Ingham } else 1850b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1851b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1852b842f2ecSJim Ingham option_arg.str().c_str()); 1853b842f2ecSJim Ingham } break; 1854b842f2ecSJim Ingham case 'D': { 1855b842f2ecSJim Ingham bool value, success; 185647cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1857b842f2ecSJim Ingham if (success) { 1858b842f2ecSJim Ingham m_permissions.SetAllowDelete(value); 1859b842f2ecSJim Ingham } else 1860b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1861b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1862b842f2ecSJim Ingham option_arg.str().c_str()); 1863b842f2ecSJim Ingham } break; 1864b842f2ecSJim Ingham 1865b842f2ecSJim Ingham } 1866b842f2ecSJim Ingham 1867b842f2ecSJim Ingham return error; 1868b842f2ecSJim Ingham } 1869b842f2ecSJim Ingham 1870b842f2ecSJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 1871b842f2ecSJim Ingham } 1872b842f2ecSJim Ingham 1873b842f2ecSJim Ingham const BreakpointName::Permissions &GetPermissions() const 1874b842f2ecSJim Ingham { 1875b842f2ecSJim Ingham return m_permissions; 1876b842f2ecSJim Ingham } 1877b842f2ecSJim Ingham BreakpointName::Permissions m_permissions; 1878b842f2ecSJim Ingham }; 1879b842f2ecSJim Ingham 1880b842f2ecSJim Ingham class CommandObjectBreakpointNameConfigure : public CommandObjectParsed { 1881b842f2ecSJim Ingham public: 1882b842f2ecSJim Ingham CommandObjectBreakpointNameConfigure(CommandInterpreter &interpreter) 1883b842f2ecSJim Ingham : CommandObjectParsed( 1884b842f2ecSJim Ingham interpreter, "configure", "Configure the options for the breakpoint" 1885b842f2ecSJim Ingham " name provided. " 1886b842f2ecSJim Ingham "If you provide a breakpoint id, the options will be copied from " 1887b842f2ecSJim Ingham "the breakpoint, otherwise only the options specified will be set " 1888b842f2ecSJim Ingham "on the name.", 1889b842f2ecSJim Ingham "breakpoint name configure <command-options> " 1890b842f2ecSJim Ingham "<breakpoint-name-list>"), 1891b842f2ecSJim Ingham m_bp_opts(), m_option_group() { 1892b842f2ecSJim Ingham // Create the first variant for the first (and only) argument for this 1893b842f2ecSJim Ingham // command. 1894b842f2ecSJim Ingham CommandArgumentEntry arg1; 1895b842f2ecSJim Ingham CommandArgumentData id_arg; 1896b842f2ecSJim Ingham id_arg.arg_type = eArgTypeBreakpointName; 1897b842f2ecSJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 1898b842f2ecSJim Ingham arg1.push_back(id_arg); 1899b842f2ecSJim Ingham m_arguments.push_back(arg1); 1900b842f2ecSJim Ingham 1901b842f2ecSJim Ingham m_option_group.Append(&m_bp_opts, 1902b842f2ecSJim Ingham LLDB_OPT_SET_ALL, 1903b842f2ecSJim Ingham LLDB_OPT_SET_1); 1904b842f2ecSJim Ingham m_option_group.Append(&m_access_options, 1905b842f2ecSJim Ingham LLDB_OPT_SET_ALL, 1906b842f2ecSJim Ingham LLDB_OPT_SET_ALL); 1907e9632ebaSJim Ingham m_option_group.Append(&m_bp_id, 1908e9632ebaSJim Ingham LLDB_OPT_SET_2|LLDB_OPT_SET_4, 1909e9632ebaSJim Ingham LLDB_OPT_SET_ALL); 1910b842f2ecSJim Ingham m_option_group.Finalize(); 1911b842f2ecSJim Ingham } 1912b842f2ecSJim Ingham 1913b842f2ecSJim Ingham ~CommandObjectBreakpointNameConfigure() override = default; 1914b842f2ecSJim Ingham 1915b842f2ecSJim Ingham Options *GetOptions() override { return &m_option_group; } 1916b842f2ecSJim Ingham 1917b842f2ecSJim Ingham protected: 1918b842f2ecSJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 1919b842f2ecSJim Ingham 1920b842f2ecSJim Ingham const size_t argc = command.GetArgumentCount(); 1921b842f2ecSJim Ingham if (argc == 0) { 1922b842f2ecSJim Ingham result.AppendError("No names provided."); 1923b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1924b842f2ecSJim Ingham return false; 1925b842f2ecSJim Ingham } 1926b842f2ecSJim Ingham 1927b842f2ecSJim Ingham Target *target = 1928b842f2ecSJim Ingham GetSelectedOrDummyTarget(false); 1929b842f2ecSJim Ingham 1930b842f2ecSJim Ingham if (target == nullptr) { 1931b842f2ecSJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 1932b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1933b842f2ecSJim Ingham return false; 1934b842f2ecSJim Ingham } 1935b842f2ecSJim Ingham 1936b842f2ecSJim Ingham std::unique_lock<std::recursive_mutex> lock; 1937b842f2ecSJim Ingham target->GetBreakpointList().GetListMutex(lock); 1938b842f2ecSJim Ingham 1939b842f2ecSJim Ingham // Make a pass through first to see that all the names are legal. 1940b842f2ecSJim Ingham for (auto &entry : command.entries()) { 1941b842f2ecSJim Ingham Status error; 1942b842f2ecSJim Ingham if (!BreakpointID::StringIsBreakpointName(entry.ref, error)) 1943b842f2ecSJim Ingham { 1944b842f2ecSJim Ingham result.AppendErrorWithFormat("Invalid breakpoint name: %s - %s", 1945b842f2ecSJim Ingham entry.c_str(), error.AsCString()); 1946b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1947b842f2ecSJim Ingham return false; 1948b842f2ecSJim Ingham } 1949b842f2ecSJim Ingham } 195005097246SAdrian Prantl // Now configure them, we already pre-checked the names so we don't need to 195105097246SAdrian Prantl // check the error: 1952b842f2ecSJim Ingham BreakpointSP bp_sp; 1953b842f2ecSJim Ingham if (m_bp_id.m_breakpoint.OptionWasSet()) 1954b842f2ecSJim Ingham { 1955b842f2ecSJim Ingham lldb::break_id_t bp_id = m_bp_id.m_breakpoint.GetUInt64Value(); 1956b842f2ecSJim Ingham bp_sp = target->GetBreakpointByID(bp_id); 1957b842f2ecSJim Ingham if (!bp_sp) 1958b842f2ecSJim Ingham { 1959b842f2ecSJim Ingham result.AppendErrorWithFormatv("Could not find specified breakpoint {0}", 1960b842f2ecSJim Ingham bp_id); 1961b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1962b842f2ecSJim Ingham return false; 1963b842f2ecSJim Ingham } 1964b842f2ecSJim Ingham } 1965b842f2ecSJim Ingham 1966b842f2ecSJim Ingham Status error; 1967b842f2ecSJim Ingham for (auto &entry : command.entries()) { 1968b842f2ecSJim Ingham ConstString name(entry.c_str()); 1969b842f2ecSJim Ingham BreakpointName *bp_name = target->FindBreakpointName(name, true, error); 1970b842f2ecSJim Ingham if (!bp_name) 1971b842f2ecSJim Ingham continue; 1972e9632ebaSJim Ingham if (m_bp_id.m_help_string.OptionWasSet()) 1973e9632ebaSJim Ingham bp_name->SetHelp(m_bp_id.m_help_string.GetStringValue().str().c_str()); 1974e9632ebaSJim Ingham 1975b842f2ecSJim Ingham if (bp_sp) 1976b842f2ecSJim Ingham target->ConfigureBreakpointName(*bp_name, 1977b842f2ecSJim Ingham *bp_sp->GetOptions(), 1978b842f2ecSJim Ingham m_access_options.GetPermissions()); 1979b842f2ecSJim Ingham else 1980b842f2ecSJim Ingham target->ConfigureBreakpointName(*bp_name, 1981b842f2ecSJim Ingham m_bp_opts.GetBreakpointOptions(), 1982b842f2ecSJim Ingham m_access_options.GetPermissions()); 1983b842f2ecSJim Ingham } 1984b842f2ecSJim Ingham return true; 1985b842f2ecSJim Ingham } 1986b842f2ecSJim Ingham 1987b842f2ecSJim Ingham private: 1988b842f2ecSJim Ingham BreakpointNameOptionGroup m_bp_id; // Only using the id part of this. 1989b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 1990b842f2ecSJim Ingham BreakpointAccessOptionGroup m_access_options; 1991b842f2ecSJim Ingham OptionGroupOptions m_option_group; 1992b842f2ecSJim Ingham }; 1993b842f2ecSJim Ingham 1994b9c1b51eSKate Stone class CommandObjectBreakpointNameAdd : public CommandObjectParsed { 19955e09c8c3SJim Ingham public: 1996b9c1b51eSKate Stone CommandObjectBreakpointNameAdd(CommandInterpreter &interpreter) 1997b9c1b51eSKate Stone : CommandObjectParsed( 1998b9c1b51eSKate Stone interpreter, "add", "Add a name to the breakpoints provided.", 19995e09c8c3SJim Ingham "breakpoint name add <command-options> <breakpoint-id-list>"), 2000b9c1b51eSKate Stone m_name_options(), m_option_group() { 2001b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 2002b9c1b51eSKate Stone // command. 20035e09c8c3SJim Ingham CommandArgumentEntry arg1; 20045e09c8c3SJim Ingham CommandArgumentData id_arg; 20055e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 20065e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 20075e09c8c3SJim Ingham arg1.push_back(id_arg); 20085e09c8c3SJim Ingham m_arguments.push_back(arg1); 20095e09c8c3SJim Ingham 20105e09c8c3SJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 20115e09c8c3SJim Ingham m_option_group.Finalize(); 20125e09c8c3SJim Ingham } 20135e09c8c3SJim Ingham 20149e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameAdd() override = default; 20155e09c8c3SJim Ingham 2016b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 20175e09c8c3SJim Ingham 20185e09c8c3SJim Ingham protected: 2019b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 2020b9c1b51eSKate Stone if (!m_name_options.m_name.OptionWasSet()) { 20215e09c8c3SJim Ingham result.SetError("No name option provided."); 20225e09c8c3SJim Ingham return false; 20235e09c8c3SJim Ingham } 20245e09c8c3SJim Ingham 2025b9c1b51eSKate Stone Target *target = 2026b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 20275e09c8c3SJim Ingham 2028b9c1b51eSKate Stone if (target == nullptr) { 20295e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 20305e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20315e09c8c3SJim Ingham return false; 20325e09c8c3SJim Ingham } 20335e09c8c3SJim Ingham 2034bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 2035bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 20365e09c8c3SJim Ingham 20375e09c8c3SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 20385e09c8c3SJim Ingham 20395e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 2040b9c1b51eSKate Stone if (num_breakpoints == 0) { 20415e09c8c3SJim Ingham result.SetError("No breakpoints, cannot add names."); 20425e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20435e09c8c3SJim Ingham return false; 20445e09c8c3SJim Ingham } 20455e09c8c3SJim Ingham 20465e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 20475e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 2048b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 2049b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 2050b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 20515e09c8c3SJim Ingham 2052b9c1b51eSKate Stone if (result.Succeeded()) { 2053b9c1b51eSKate Stone if (valid_bp_ids.GetSize() == 0) { 20545e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot add names."); 20555e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20565e09c8c3SJim Ingham return false; 20575e09c8c3SJim Ingham } 20585e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 2059b842f2ecSJim Ingham const char *bp_name = m_name_options.m_name.GetCurrentValue(); 2060b842f2ecSJim Ingham Status error; // This error reports illegal names, but we've already 2061b842f2ecSJim Ingham // checked that, so we don't need to check it again here. 2062b9c1b51eSKate Stone for (size_t index = 0; index < num_valid_ids; index++) { 2063b9c1b51eSKate Stone lldb::break_id_t bp_id = 2064b9c1b51eSKate Stone valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 20655e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 2066b842f2ecSJim Ingham target->AddNameToBreakpoint(bp_sp, bp_name, error); 20675e09c8c3SJim Ingham } 20685e09c8c3SJim Ingham } 20695e09c8c3SJim Ingham 20705e09c8c3SJim Ingham return true; 20715e09c8c3SJim Ingham } 20725e09c8c3SJim Ingham 20735e09c8c3SJim Ingham private: 20745e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 20755e09c8c3SJim Ingham OptionGroupOptions m_option_group; 20765e09c8c3SJim Ingham }; 20775e09c8c3SJim Ingham 2078b9c1b51eSKate Stone class CommandObjectBreakpointNameDelete : public CommandObjectParsed { 20795e09c8c3SJim Ingham public: 2080b9c1b51eSKate Stone CommandObjectBreakpointNameDelete(CommandInterpreter &interpreter) 2081b9c1b51eSKate Stone : CommandObjectParsed( 2082b9c1b51eSKate Stone interpreter, "delete", 20835e09c8c3SJim Ingham "Delete a name from the breakpoints provided.", 20845e09c8c3SJim Ingham "breakpoint name delete <command-options> <breakpoint-id-list>"), 2085b9c1b51eSKate Stone m_name_options(), m_option_group() { 2086b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 2087b9c1b51eSKate Stone // command. 20885e09c8c3SJim Ingham CommandArgumentEntry arg1; 20895e09c8c3SJim Ingham CommandArgumentData id_arg; 20905e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 20915e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 20925e09c8c3SJim Ingham arg1.push_back(id_arg); 20935e09c8c3SJim Ingham m_arguments.push_back(arg1); 20945e09c8c3SJim Ingham 20955e09c8c3SJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 20965e09c8c3SJim Ingham m_option_group.Finalize(); 20975e09c8c3SJim Ingham } 20985e09c8c3SJim Ingham 20999e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameDelete() override = default; 21005e09c8c3SJim Ingham 2101b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 21025e09c8c3SJim Ingham 21035e09c8c3SJim Ingham protected: 2104b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 2105b9c1b51eSKate Stone if (!m_name_options.m_name.OptionWasSet()) { 21065e09c8c3SJim Ingham result.SetError("No name option provided."); 21075e09c8c3SJim Ingham return false; 21085e09c8c3SJim Ingham } 21095e09c8c3SJim Ingham 2110b9c1b51eSKate Stone Target *target = 2111b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 21125e09c8c3SJim Ingham 2113b9c1b51eSKate Stone if (target == nullptr) { 21145e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 21155e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 21165e09c8c3SJim Ingham return false; 21175e09c8c3SJim Ingham } 21185e09c8c3SJim Ingham 2119bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 2120bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 21215e09c8c3SJim Ingham 21225e09c8c3SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 21235e09c8c3SJim Ingham 21245e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 2125b9c1b51eSKate Stone if (num_breakpoints == 0) { 21265e09c8c3SJim Ingham result.SetError("No breakpoints, cannot delete names."); 21275e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 21285e09c8c3SJim Ingham return false; 21295e09c8c3SJim Ingham } 21305e09c8c3SJim Ingham 21315e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 21325e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 2133b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 2134b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 2135b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::deletePerm); 21365e09c8c3SJim Ingham 2137b9c1b51eSKate Stone if (result.Succeeded()) { 2138b9c1b51eSKate Stone if (valid_bp_ids.GetSize() == 0) { 21395e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot delete names."); 21405e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 21415e09c8c3SJim Ingham return false; 21425e09c8c3SJim Ingham } 2143b842f2ecSJim Ingham ConstString bp_name(m_name_options.m_name.GetCurrentValue()); 21445e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 2145b9c1b51eSKate Stone for (size_t index = 0; index < num_valid_ids; index++) { 2146b9c1b51eSKate Stone lldb::break_id_t bp_id = 2147b9c1b51eSKate Stone valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 21485e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 2149b842f2ecSJim Ingham target->RemoveNameFromBreakpoint(bp_sp, bp_name); 21505e09c8c3SJim Ingham } 21515e09c8c3SJim Ingham } 21525e09c8c3SJim Ingham 21535e09c8c3SJim Ingham return true; 21545e09c8c3SJim Ingham } 21555e09c8c3SJim Ingham 21565e09c8c3SJim Ingham private: 21575e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 21585e09c8c3SJim Ingham OptionGroupOptions m_option_group; 21595e09c8c3SJim Ingham }; 21605e09c8c3SJim Ingham 2161b9c1b51eSKate Stone class CommandObjectBreakpointNameList : public CommandObjectParsed { 21625e09c8c3SJim Ingham public: 2163b9c1b51eSKate Stone CommandObjectBreakpointNameList(CommandInterpreter &interpreter) 2164b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "list", 2165b842f2ecSJim Ingham "List either the names for a breakpoint or info " 2166b842f2ecSJim Ingham "about a given name. With no arguments, lists all " 2167b842f2ecSJim Ingham "names", 21685e09c8c3SJim Ingham "breakpoint name list <command-options>"), 2169b9c1b51eSKate Stone m_name_options(), m_option_group() { 2170b842f2ecSJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_3, LLDB_OPT_SET_ALL); 21715e09c8c3SJim Ingham m_option_group.Finalize(); 21725e09c8c3SJim Ingham } 21735e09c8c3SJim Ingham 21749e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameList() override = default; 21755e09c8c3SJim Ingham 2176b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 21775e09c8c3SJim Ingham 21785e09c8c3SJim Ingham protected: 2179b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 2180b9c1b51eSKate Stone Target *target = 2181b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 21825e09c8c3SJim Ingham 2183b9c1b51eSKate Stone if (target == nullptr) { 21845e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 21855e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 21865e09c8c3SJim Ingham return false; 21875e09c8c3SJim Ingham } 21885e09c8c3SJim Ingham 2189b842f2ecSJim Ingham 2190b842f2ecSJim Ingham std::vector<std::string> name_list; 2191b842f2ecSJim Ingham if (command.empty()) { 2192b842f2ecSJim Ingham target->GetBreakpointNames(name_list); 2193b842f2ecSJim Ingham } else { 2194b842f2ecSJim Ingham for (const Args::ArgEntry &arg : command) 2195b842f2ecSJim Ingham { 2196b842f2ecSJim Ingham name_list.push_back(arg.c_str()); 2197b842f2ecSJim Ingham } 2198b842f2ecSJim Ingham } 2199b842f2ecSJim Ingham 2200b842f2ecSJim Ingham if (name_list.empty()) { 2201b842f2ecSJim Ingham result.AppendMessage("No breakpoint names found."); 2202b842f2ecSJim Ingham } else { 2203b842f2ecSJim Ingham for (const std::string &name_str : name_list) { 2204b842f2ecSJim Ingham const char *name = name_str.c_str(); 2205b842f2ecSJim Ingham // First print out the options for the name: 2206b842f2ecSJim Ingham Status error; 2207b842f2ecSJim Ingham BreakpointName *bp_name = target->FindBreakpointName(ConstString(name), 2208b842f2ecSJim Ingham false, 2209b842f2ecSJim Ingham error); 2210b842f2ecSJim Ingham if (bp_name) 2211b842f2ecSJim Ingham { 2212b842f2ecSJim Ingham StreamString s; 2213b842f2ecSJim Ingham result.AppendMessageWithFormat("Name: %s\n", name); 2214b842f2ecSJim Ingham if (bp_name->GetDescription(&s, eDescriptionLevelFull)) 2215b842f2ecSJim Ingham { 2216b842f2ecSJim Ingham result.AppendMessage(s.GetString()); 2217b842f2ecSJim Ingham } 2218b842f2ecSJim Ingham 2219bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 2220bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 22215e09c8c3SJim Ingham 22225e09c8c3SJim Ingham BreakpointList &breakpoints = target->GetBreakpointList(); 2223b842f2ecSJim Ingham bool any_set = false; 2224b9c1b51eSKate Stone for (BreakpointSP bp_sp : breakpoints.Breakpoints()) { 2225b9c1b51eSKate Stone if (bp_sp->MatchesName(name)) { 22265e09c8c3SJim Ingham StreamString s; 2227b842f2ecSJim Ingham any_set = true; 22285e09c8c3SJim Ingham bp_sp->GetDescription(&s, eDescriptionLevelBrief); 22295e09c8c3SJim Ingham s.EOL(); 2230c156427dSZachary Turner result.AppendMessage(s.GetString()); 22315e09c8c3SJim Ingham } 22325e09c8c3SJim Ingham } 2233b842f2ecSJim Ingham if (!any_set) 2234b842f2ecSJim Ingham result.AppendMessage("No breakpoints using this name."); 2235b9c1b51eSKate Stone } else { 2236b842f2ecSJim Ingham result.AppendMessageWithFormat("Name: %s not found.\n", name); 22375e09c8c3SJim Ingham } 2238b842f2ecSJim Ingham } 22395e09c8c3SJim Ingham } 22405e09c8c3SJim Ingham return true; 22415e09c8c3SJim Ingham } 22425e09c8c3SJim Ingham 22435e09c8c3SJim Ingham private: 22445e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 22455e09c8c3SJim Ingham OptionGroupOptions m_option_group; 22465e09c8c3SJim Ingham }; 22475e09c8c3SJim Ingham 22485e09c8c3SJim Ingham //------------------------------------------------------------------------- 2249e14dc268SJim Ingham // CommandObjectBreakpointName 22505e09c8c3SJim Ingham //------------------------------------------------------------------------- 2251b9c1b51eSKate Stone class CommandObjectBreakpointName : public CommandObjectMultiword { 22525e09c8c3SJim Ingham public: 22537428a18cSKate Stone CommandObjectBreakpointName(CommandInterpreter &interpreter) 2254b9c1b51eSKate Stone : CommandObjectMultiword( 2255b9c1b51eSKate Stone interpreter, "name", "Commands to manage name tags for breakpoints", 2256b9c1b51eSKate Stone "breakpoint name <subcommand> [<command-options>]") { 2257b9c1b51eSKate Stone CommandObjectSP add_command_object( 2258b9c1b51eSKate Stone new CommandObjectBreakpointNameAdd(interpreter)); 2259b9c1b51eSKate Stone CommandObjectSP delete_command_object( 2260b9c1b51eSKate Stone new CommandObjectBreakpointNameDelete(interpreter)); 2261b9c1b51eSKate Stone CommandObjectSP list_command_object( 2262b9c1b51eSKate Stone new CommandObjectBreakpointNameList(interpreter)); 2263b842f2ecSJim Ingham CommandObjectSP configure_command_object( 2264b842f2ecSJim Ingham new CommandObjectBreakpointNameConfigure(interpreter)); 22655e09c8c3SJim Ingham 22665e09c8c3SJim Ingham LoadSubCommand("add", add_command_object); 22675e09c8c3SJim Ingham LoadSubCommand("delete", delete_command_object); 22685e09c8c3SJim Ingham LoadSubCommand("list", list_command_object); 2269b842f2ecSJim Ingham LoadSubCommand("configure", configure_command_object); 22705e09c8c3SJim Ingham } 22715e09c8c3SJim Ingham 22729e85e5a8SEugene Zelenko ~CommandObjectBreakpointName() override = default; 22735e09c8c3SJim Ingham }; 22745e09c8c3SJim Ingham 22755e09c8c3SJim Ingham //------------------------------------------------------------------------- 2276e14dc268SJim Ingham // CommandObjectBreakpointRead 2277e14dc268SJim Ingham //------------------------------------------------------------------------- 22783acdf385SJim Ingham #pragma mark Read::CommandOptions 22798fe53c49STatyana Krasnukha static constexpr OptionDefinition g_breakpoint_read_options[] = { 22801f0f5b5bSZachary Turner // clang-format off 22818fe53c49STatyana Krasnukha {LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, {}, CommandCompletions::eDiskFileCompletion, eArgTypeFilename, "The file from which to read the breakpoints." }, 22828fe53c49STatyana Krasnukha {LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBreakpointName, "Only read in breakpoints with this name."}, 22831f0f5b5bSZachary Turner // clang-format on 22841f0f5b5bSZachary Turner }; 22851f0f5b5bSZachary Turner 22861f0f5b5bSZachary Turner #pragma mark Read 2287e14dc268SJim Ingham 2288e14dc268SJim Ingham class CommandObjectBreakpointRead : public CommandObjectParsed { 2289e14dc268SJim Ingham public: 2290e14dc268SJim Ingham CommandObjectBreakpointRead(CommandInterpreter &interpreter) 2291e14dc268SJim Ingham : CommandObjectParsed(interpreter, "breakpoint read", 2292e14dc268SJim Ingham "Read and set the breakpoints previously saved to " 2293e14dc268SJim Ingham "a file with \"breakpoint write\". ", 2294e14dc268SJim Ingham nullptr), 2295e14dc268SJim Ingham m_options() { 2296e14dc268SJim Ingham CommandArgumentEntry arg; 2297e14dc268SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 2298e14dc268SJim Ingham eArgTypeBreakpointIDRange); 2299e14dc268SJim Ingham // Add the entry for the first argument for this command to the object's 2300e14dc268SJim Ingham // arguments vector. 2301e14dc268SJim Ingham m_arguments.push_back(arg); 2302e14dc268SJim Ingham } 2303e14dc268SJim Ingham 2304e14dc268SJim Ingham ~CommandObjectBreakpointRead() override = default; 2305e14dc268SJim Ingham 2306e14dc268SJim Ingham Options *GetOptions() override { return &m_options; } 2307e14dc268SJim Ingham 2308e14dc268SJim Ingham class CommandOptions : public Options { 2309e14dc268SJim Ingham public: 2310e14dc268SJim Ingham CommandOptions() : Options() {} 2311e14dc268SJim Ingham 2312e14dc268SJim Ingham ~CommandOptions() override = default; 2313e14dc268SJim Ingham 231497206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 2315e14dc268SJim Ingham ExecutionContext *execution_context) override { 231697206d57SZachary Turner Status error; 2317e14dc268SJim Ingham const int short_option = m_getopt_table[option_idx].val; 2318e14dc268SJim Ingham 2319e14dc268SJim Ingham switch (short_option) { 2320e14dc268SJim Ingham case 'f': 2321e14dc268SJim Ingham m_filename.assign(option_arg); 2322e14dc268SJim Ingham break; 23233acdf385SJim Ingham case 'N': { 232497206d57SZachary Turner Status name_error; 23253acdf385SJim Ingham if (!BreakpointID::StringIsBreakpointName(llvm::StringRef(option_arg), 23263acdf385SJim Ingham name_error)) { 23273acdf385SJim Ingham error.SetErrorStringWithFormat("Invalid breakpoint name: %s", 23283acdf385SJim Ingham name_error.AsCString()); 23293acdf385SJim Ingham } 23303acdf385SJim Ingham m_names.push_back(option_arg); 23313acdf385SJim Ingham break; 23323acdf385SJim Ingham } 2333e14dc268SJim Ingham default: 2334e14dc268SJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 2335e14dc268SJim Ingham short_option); 2336e14dc268SJim Ingham break; 2337e14dc268SJim Ingham } 2338e14dc268SJim Ingham 2339e14dc268SJim Ingham return error; 2340e14dc268SJim Ingham } 2341e14dc268SJim Ingham 2342e14dc268SJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 2343e14dc268SJim Ingham m_filename.clear(); 23443acdf385SJim Ingham m_names.clear(); 2345e14dc268SJim Ingham } 2346e14dc268SJim Ingham 23471f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 234870602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_read_options); 23491f0f5b5bSZachary Turner } 2350e14dc268SJim Ingham 2351e14dc268SJim Ingham // Instance variables to hold the values for command options. 2352e14dc268SJim Ingham 2353e14dc268SJim Ingham std::string m_filename; 23543acdf385SJim Ingham std::vector<std::string> m_names; 2355e14dc268SJim Ingham }; 2356e14dc268SJim Ingham 2357e14dc268SJim Ingham protected: 2358e14dc268SJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 2359e14dc268SJim Ingham Target *target = GetSelectedOrDummyTarget(); 2360e14dc268SJim Ingham if (target == nullptr) { 2361e14dc268SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 2362e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2363e14dc268SJim Ingham return false; 2364e14dc268SJim Ingham } 2365e14dc268SJim Ingham 23663acdf385SJim Ingham std::unique_lock<std::recursive_mutex> lock; 23673acdf385SJim Ingham target->GetBreakpointList().GetListMutex(lock); 23683acdf385SJim Ingham 23698f3be7a3SJonas Devlieghere FileSpec input_spec(m_options.m_filename); 23708f3be7a3SJonas Devlieghere FileSystem::Instance().Resolve(input_spec); 237101f16664SJim Ingham BreakpointIDList new_bps; 237297206d57SZachary Turner Status error = target->CreateBreakpointsFromFile( 237397206d57SZachary Turner input_spec, m_options.m_names, new_bps); 2374e14dc268SJim Ingham 2375e14dc268SJim Ingham if (!error.Success()) { 237601f16664SJim Ingham result.AppendError(error.AsCString()); 2377e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 237801f16664SJim Ingham return false; 2379e14dc268SJim Ingham } 23803acdf385SJim Ingham 23813acdf385SJim Ingham Stream &output_stream = result.GetOutputStream(); 23823acdf385SJim Ingham 23833acdf385SJim Ingham size_t num_breakpoints = new_bps.GetSize(); 23843acdf385SJim Ingham if (num_breakpoints == 0) { 23853acdf385SJim Ingham result.AppendMessage("No breakpoints added."); 23863acdf385SJim Ingham } else { 23873acdf385SJim Ingham // No breakpoint selected; show info about all currently set breakpoints. 23883acdf385SJim Ingham result.AppendMessage("New breakpoints:"); 23893acdf385SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) { 23903acdf385SJim Ingham BreakpointID bp_id = new_bps.GetBreakpointIDAtIndex(i); 23913acdf385SJim Ingham Breakpoint *bp = target->GetBreakpointList() 23923acdf385SJim Ingham .FindBreakpointByID(bp_id.GetBreakpointID()) 23933acdf385SJim Ingham .get(); 23943acdf385SJim Ingham if (bp) 23953acdf385SJim Ingham bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, 23963acdf385SJim Ingham false); 23973acdf385SJim Ingham } 23983acdf385SJim Ingham } 2399e14dc268SJim Ingham return result.Succeeded(); 2400e14dc268SJim Ingham } 2401e14dc268SJim Ingham 2402e14dc268SJim Ingham private: 2403e14dc268SJim Ingham CommandOptions m_options; 2404e14dc268SJim Ingham }; 2405e14dc268SJim Ingham 2406e14dc268SJim Ingham //------------------------------------------------------------------------- 2407e14dc268SJim Ingham // CommandObjectBreakpointWrite 2408e14dc268SJim Ingham //------------------------------------------------------------------------- 24091f0f5b5bSZachary Turner #pragma mark Write::CommandOptions 24108fe53c49STatyana Krasnukha static constexpr OptionDefinition g_breakpoint_write_options[] = { 24111f0f5b5bSZachary Turner // clang-format off 24128fe53c49STatyana Krasnukha { LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, {}, CommandCompletions::eDiskFileCompletion, eArgTypeFilename, "The file into which to write the breakpoints." }, 24138fe53c49STatyana Krasnukha { LLDB_OPT_SET_ALL, false, "append",'a', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Append to saved breakpoints file if it exists."}, 24141f0f5b5bSZachary Turner // clang-format on 24151f0f5b5bSZachary Turner }; 24161f0f5b5bSZachary Turner 24171f0f5b5bSZachary Turner #pragma mark Write 2418e14dc268SJim Ingham class CommandObjectBreakpointWrite : public CommandObjectParsed { 2419e14dc268SJim Ingham public: 2420e14dc268SJim Ingham CommandObjectBreakpointWrite(CommandInterpreter &interpreter) 2421e14dc268SJim Ingham : CommandObjectParsed(interpreter, "breakpoint write", 2422e14dc268SJim Ingham "Write the breakpoints listed to a file that can " 2423e14dc268SJim Ingham "be read in with \"breakpoint read\". " 2424e14dc268SJim Ingham "If given no arguments, writes all breakpoints.", 2425e14dc268SJim Ingham nullptr), 2426e14dc268SJim Ingham m_options() { 2427e14dc268SJim Ingham CommandArgumentEntry arg; 2428e14dc268SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 2429e14dc268SJim Ingham eArgTypeBreakpointIDRange); 2430e14dc268SJim Ingham // Add the entry for the first argument for this command to the object's 2431e14dc268SJim Ingham // arguments vector. 2432e14dc268SJim Ingham m_arguments.push_back(arg); 2433e14dc268SJim Ingham } 2434e14dc268SJim Ingham 2435e14dc268SJim Ingham ~CommandObjectBreakpointWrite() override = default; 2436e14dc268SJim Ingham 2437e14dc268SJim Ingham Options *GetOptions() override { return &m_options; } 2438e14dc268SJim Ingham 2439e14dc268SJim Ingham class CommandOptions : public Options { 2440e14dc268SJim Ingham public: 2441e14dc268SJim Ingham CommandOptions() : Options() {} 2442e14dc268SJim Ingham 2443e14dc268SJim Ingham ~CommandOptions() override = default; 2444e14dc268SJim Ingham 244597206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 2446e14dc268SJim Ingham ExecutionContext *execution_context) override { 244797206d57SZachary Turner Status error; 2448e14dc268SJim Ingham const int short_option = m_getopt_table[option_idx].val; 2449e14dc268SJim Ingham 2450e14dc268SJim Ingham switch (short_option) { 2451e14dc268SJim Ingham case 'f': 2452e14dc268SJim Ingham m_filename.assign(option_arg); 2453e14dc268SJim Ingham break; 24542d3628e1SJim Ingham case 'a': 24552d3628e1SJim Ingham m_append = true; 24562d3628e1SJim Ingham break; 2457e14dc268SJim Ingham default: 2458e14dc268SJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 2459e14dc268SJim Ingham short_option); 2460e14dc268SJim Ingham break; 2461e14dc268SJim Ingham } 2462e14dc268SJim Ingham 2463e14dc268SJim Ingham return error; 2464e14dc268SJim Ingham } 2465e14dc268SJim Ingham 2466e14dc268SJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 2467e14dc268SJim Ingham m_filename.clear(); 24682d3628e1SJim Ingham m_append = false; 2469e14dc268SJim Ingham } 2470e14dc268SJim Ingham 24711f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 247270602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_write_options); 24731f0f5b5bSZachary Turner } 2474e14dc268SJim Ingham 2475e14dc268SJim Ingham // Instance variables to hold the values for command options. 2476e14dc268SJim Ingham 2477e14dc268SJim Ingham std::string m_filename; 24782d3628e1SJim Ingham bool m_append = false; 2479e14dc268SJim Ingham }; 2480e14dc268SJim Ingham 2481e14dc268SJim Ingham protected: 2482e14dc268SJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 2483e14dc268SJim Ingham Target *target = GetSelectedOrDummyTarget(); 2484e14dc268SJim Ingham if (target == nullptr) { 2485e14dc268SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 2486e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2487e14dc268SJim Ingham return false; 2488e14dc268SJim Ingham } 2489e14dc268SJim Ingham 2490e14dc268SJim Ingham std::unique_lock<std::recursive_mutex> lock; 2491e14dc268SJim Ingham target->GetBreakpointList().GetListMutex(lock); 2492e14dc268SJim Ingham 2493e14dc268SJim Ingham BreakpointIDList valid_bp_ids; 249411eb9c64SZachary Turner if (!command.empty()) { 2495e14dc268SJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 2496b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 2497b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 2498e14dc268SJim Ingham 249901f16664SJim Ingham if (!result.Succeeded()) { 2500e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2501e14dc268SJim Ingham return false; 2502e14dc268SJim Ingham } 2503e14dc268SJim Ingham } 25048f3be7a3SJonas Devlieghere FileSpec file_spec(m_options.m_filename); 25058f3be7a3SJonas Devlieghere FileSystem::Instance().Resolve(file_spec); 25068f3be7a3SJonas Devlieghere Status error = target->SerializeBreakpointsToFile(file_spec, valid_bp_ids, 25078f3be7a3SJonas Devlieghere m_options.m_append); 250801f16664SJim Ingham if (!error.Success()) { 250901f16664SJim Ingham result.AppendErrorWithFormat("error serializing breakpoints: %s.", 251001f16664SJim Ingham error.AsCString()); 251101f16664SJim Ingham result.SetStatus(eReturnStatusFailed); 2512e14dc268SJim Ingham } 2513e14dc268SJim Ingham return result.Succeeded(); 2514e14dc268SJim Ingham } 2515e14dc268SJim Ingham 2516e14dc268SJim Ingham private: 2517e14dc268SJim Ingham CommandOptions m_options; 2518e14dc268SJim Ingham }; 2519e14dc268SJim Ingham 2520e14dc268SJim Ingham //------------------------------------------------------------------------- 252130fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 252230fdc8d8SChris Lattner //------------------------------------------------------------------------- 2523ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 252430fdc8d8SChris Lattner 2525b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint( 2526b9c1b51eSKate Stone CommandInterpreter &interpreter) 2527b9c1b51eSKate Stone : CommandObjectMultiword( 2528b9c1b51eSKate Stone interpreter, "breakpoint", 25297428a18cSKate Stone "Commands for operating on breakpoints (see 'help b' for shorthand.)", 2530b9c1b51eSKate Stone "breakpoint <subcommand> [<command-options>]") { 2531b9c1b51eSKate Stone CommandObjectSP list_command_object( 2532b9c1b51eSKate Stone new CommandObjectBreakpointList(interpreter)); 2533b9c1b51eSKate Stone CommandObjectSP enable_command_object( 2534b9c1b51eSKate Stone new CommandObjectBreakpointEnable(interpreter)); 2535b9c1b51eSKate Stone CommandObjectSP disable_command_object( 2536b9c1b51eSKate Stone new CommandObjectBreakpointDisable(interpreter)); 2537b9c1b51eSKate Stone CommandObjectSP clear_command_object( 2538b9c1b51eSKate Stone new CommandObjectBreakpointClear(interpreter)); 2539b9c1b51eSKate Stone CommandObjectSP delete_command_object( 2540b9c1b51eSKate Stone new CommandObjectBreakpointDelete(interpreter)); 2541b9c1b51eSKate Stone CommandObjectSP set_command_object( 2542b9c1b51eSKate Stone new CommandObjectBreakpointSet(interpreter)); 2543b9c1b51eSKate Stone CommandObjectSP command_command_object( 2544b9c1b51eSKate Stone new CommandObjectBreakpointCommand(interpreter)); 2545b9c1b51eSKate Stone CommandObjectSP modify_command_object( 2546b9c1b51eSKate Stone new CommandObjectBreakpointModify(interpreter)); 2547b9c1b51eSKate Stone CommandObjectSP name_command_object( 2548b9c1b51eSKate Stone new CommandObjectBreakpointName(interpreter)); 2549e14dc268SJim Ingham CommandObjectSP write_command_object( 2550e14dc268SJim Ingham new CommandObjectBreakpointWrite(interpreter)); 2551e14dc268SJim Ingham CommandObjectSP read_command_object( 2552e14dc268SJim Ingham new CommandObjectBreakpointRead(interpreter)); 255330fdc8d8SChris Lattner 2554b7234e40SJohnny Chen list_command_object->SetCommandName("breakpoint list"); 255530fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 255630fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 2557b7234e40SJohnny Chen clear_command_object->SetCommandName("breakpoint clear"); 2558b7234e40SJohnny Chen delete_command_object->SetCommandName("breakpoint delete"); 2559ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 2560b7234e40SJohnny Chen command_command_object->SetCommandName("breakpoint command"); 2561b7234e40SJohnny Chen modify_command_object->SetCommandName("breakpoint modify"); 25625e09c8c3SJim Ingham name_command_object->SetCommandName("breakpoint name"); 2563e14dc268SJim Ingham write_command_object->SetCommandName("breakpoint write"); 2564e14dc268SJim Ingham read_command_object->SetCommandName("breakpoint read"); 256530fdc8d8SChris Lattner 256623f59509SGreg Clayton LoadSubCommand("list", list_command_object); 256723f59509SGreg Clayton LoadSubCommand("enable", enable_command_object); 256823f59509SGreg Clayton LoadSubCommand("disable", disable_command_object); 256923f59509SGreg Clayton LoadSubCommand("clear", clear_command_object); 257023f59509SGreg Clayton LoadSubCommand("delete", delete_command_object); 257123f59509SGreg Clayton LoadSubCommand("set", set_command_object); 257223f59509SGreg Clayton LoadSubCommand("command", command_command_object); 257323f59509SGreg Clayton LoadSubCommand("modify", modify_command_object); 25745e09c8c3SJim Ingham LoadSubCommand("name", name_command_object); 2575e14dc268SJim Ingham LoadSubCommand("write", write_command_object); 2576e14dc268SJim Ingham LoadSubCommand("read", read_command_object); 257730fdc8d8SChris Lattner } 257830fdc8d8SChris Lattner 25799e85e5a8SEugene Zelenko CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default; 258030fdc8d8SChris Lattner 2581b9c1b51eSKate Stone void CommandObjectMultiwordBreakpoint::VerifyIDs(Args &args, Target *target, 25825e09c8c3SJim Ingham bool allow_locations, 25835e09c8c3SJim Ingham CommandReturnObject &result, 2584b842f2ecSJim Ingham BreakpointIDList *valid_ids, 2585b842f2ecSJim Ingham BreakpointName::Permissions 2586b842f2ecSJim Ingham ::PermissionKinds 2587b842f2ecSJim Ingham purpose) { 258830fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 2589b9c1b51eSKate Stone // 2). the full breakpoint & location 2590b9c1b51eSKate Stone // canonical representation 2591b9c1b51eSKate Stone // 3). the word "to" or a hyphen, 2592b9c1b51eSKate Stone // representing a range (in which case there 2593b9c1b51eSKate Stone // had *better* be an entry both before & 2594b9c1b51eSKate Stone // after of one of the first two types. 25955e09c8c3SJim Ingham // 4). A breakpoint name 2596b9c1b51eSKate Stone // If args is empty, we will use the last created breakpoint (if there is 2597b9c1b51eSKate Stone // one.) 259830fdc8d8SChris Lattner 259930fdc8d8SChris Lattner Args temp_args; 260030fdc8d8SChris Lattner 260111eb9c64SZachary Turner if (args.empty()) { 2602b9c1b51eSKate Stone if (target->GetLastCreatedBreakpoint()) { 2603b9c1b51eSKate Stone valid_ids->AddBreakpointID(BreakpointID( 2604b9c1b51eSKate Stone target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); 260536f3b369SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 2606b9c1b51eSKate Stone } else { 2607b9c1b51eSKate Stone result.AppendError( 2608b9c1b51eSKate Stone "No breakpoint specified and no last created breakpoint."); 260936f3b369SJim Ingham result.SetStatus(eReturnStatusFailed); 261036f3b369SJim Ingham } 261136f3b369SJim Ingham return; 261236f3b369SJim Ingham } 261336f3b369SJim Ingham 2614b9c1b51eSKate Stone // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff 261505097246SAdrian Prantl // directly from the old ARGS to the new TEMP_ARGS. Do not copy breakpoint 261605097246SAdrian Prantl // id range strings over; instead generate a list of strings for all the 261705097246SAdrian Prantl // breakpoint ids in the range, and shove all of those breakpoint id strings 261805097246SAdrian Prantl // into TEMP_ARGS. 261930fdc8d8SChris Lattner 2620b9c1b51eSKate Stone BreakpointIDList::FindAndReplaceIDRanges(args, target, allow_locations, 2621b842f2ecSJim Ingham purpose, result, temp_args); 262230fdc8d8SChris Lattner 2623b9c1b51eSKate Stone // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual 2624b9c1b51eSKate Stone // BreakpointIDList: 262530fdc8d8SChris Lattner 262616662f3cSPavel Labath valid_ids->InsertStringArray(temp_args.GetArgumentArrayRef(), result); 262730fdc8d8SChris Lattner 262805097246SAdrian Prantl // At this point, all of the breakpoint ids that the user passed in have 262905097246SAdrian Prantl // been converted to breakpoint IDs and put into valid_ids. 263030fdc8d8SChris Lattner 2631b9c1b51eSKate Stone if (result.Succeeded()) { 2632b9c1b51eSKate Stone // Now that we've converted everything from args into a list of breakpoint 263305097246SAdrian Prantl // ids, go through our tentative list of breakpoint id's and verify that 263405097246SAdrian Prantl // they correspond to valid/currently set breakpoints. 263530fdc8d8SChris Lattner 2636c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 2637b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 263830fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex(i); 2639b9c1b51eSKate Stone Breakpoint *breakpoint = 2640b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 2641b9c1b51eSKate Stone if (breakpoint != nullptr) { 2642c7bece56SGreg Clayton const size_t num_locations = breakpoint->GetNumLocations(); 2643b9c1b51eSKate Stone if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations) { 264430fdc8d8SChris Lattner StreamString id_str; 2645b9c1b51eSKate Stone BreakpointID::GetCanonicalReference( 2646b9c1b51eSKate Stone &id_str, cur_bp_id.GetBreakpointID(), cur_bp_id.GetLocationID()); 2647c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 2648b9c1b51eSKate Stone result.AppendErrorWithFormat( 2649b9c1b51eSKate Stone "'%s' is not a currently valid breakpoint/location id.\n", 265030fdc8d8SChris Lattner id_str.GetData()); 265130fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 265230fdc8d8SChris Lattner } 2653b9c1b51eSKate Stone } else { 2654c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 2655b9c1b51eSKate Stone result.AppendErrorWithFormat( 2656b9c1b51eSKate Stone "'%d' is not a currently valid breakpoint ID.\n", 26577428a18cSKate Stone cur_bp_id.GetBreakpointID()); 265830fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 265930fdc8d8SChris Lattner } 266030fdc8d8SChris Lattner } 266130fdc8d8SChris Lattner } 266230fdc8d8SChris Lattner } 2663