180814287SRaphael Isemann //===-- CommandObjectBreakpoint.cpp ---------------------------------------===// 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/CommandInterpreter.h" 16b9c1b51eSKate Stone #include "lldb/Interpreter/CommandReturnObject.h" 1747cbf4a0SPavel Labath #include "lldb/Interpreter/OptionArgParser.h" 18943a2481SJim Ingham #include "lldb/Interpreter/OptionGroupPythonClassWithDict.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/ThreadSpec.h" 27bf9a7730SZachary Turner #include "lldb/Utility/RegularExpression.h" 28bf9a7730SZachary Turner #include "lldb/Utility/StreamString.h" 2930fdc8d8SChris Lattner 30796ac80bSJonas Devlieghere #include <memory> 31796ac80bSJonas Devlieghere #include <vector> 32796ac80bSJonas Devlieghere 3330fdc8d8SChris Lattner using namespace lldb; 3430fdc8d8SChris Lattner using namespace lldb_private; 3530fdc8d8SChris Lattner 36b9c1b51eSKate Stone static void AddBreakpointDescription(Stream *s, Breakpoint *bp, 37b9c1b51eSKate Stone lldb::DescriptionLevel level) { 3830fdc8d8SChris Lattner s->IndentMore(); 3930fdc8d8SChris Lattner bp->GetDescription(s, level, true); 4030fdc8d8SChris Lattner s->IndentLess(); 4130fdc8d8SChris Lattner s->EOL(); 4230fdc8d8SChris Lattner } 4330fdc8d8SChris Lattner 44b842f2ecSJim Ingham // Modifiable Breakpoint Options 45b842f2ecSJim Ingham #pragma mark Modify::CommandOptions 46f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_modify 47f94668e3SRaphael Isemann #include "CommandOptions.inc" 48bd68a052SRaphael Isemann 49a925974bSAdrian Prantl class lldb_private::BreakpointOptionGroup : public OptionGroup { 50b842f2ecSJim Ingham public: 51a925974bSAdrian Prantl BreakpointOptionGroup() : OptionGroup(), m_bp_opts(false) {} 52b842f2ecSJim Ingham 53b842f2ecSJim Ingham ~BreakpointOptionGroup() override = default; 54b842f2ecSJim Ingham 55b842f2ecSJim Ingham llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 56b842f2ecSJim Ingham return llvm::makeArrayRef(g_breakpoint_modify_options); 57b842f2ecSJim Ingham } 58b842f2ecSJim Ingham 59b842f2ecSJim Ingham Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 60b842f2ecSJim Ingham ExecutionContext *execution_context) override { 61b842f2ecSJim Ingham Status error; 62a925974bSAdrian Prantl const int short_option = 63a925974bSAdrian Prantl g_breakpoint_modify_options[option_idx].short_option; 64b842f2ecSJim Ingham 65b842f2ecSJim Ingham switch (short_option) { 66b842f2ecSJim Ingham case 'c': 6705097246SAdrian Prantl // Normally an empty breakpoint condition marks is as unset. But we need 6805097246SAdrian Prantl // to say it was passed in. 69b842f2ecSJim Ingham m_bp_opts.SetCondition(option_arg.str().c_str()); 70b842f2ecSJim Ingham m_bp_opts.m_set_flags.Set(BreakpointOptions::eCondition); 71b842f2ecSJim Ingham break; 72b842f2ecSJim Ingham case 'C': 73adcd0268SBenjamin Kramer m_commands.push_back(std::string(option_arg)); 74b842f2ecSJim Ingham break; 75b842f2ecSJim Ingham case 'd': 76b842f2ecSJim Ingham m_bp_opts.SetEnabled(false); 77b842f2ecSJim Ingham break; 78b842f2ecSJim Ingham case 'e': 79b842f2ecSJim Ingham m_bp_opts.SetEnabled(true); 80b842f2ecSJim Ingham break; 81b842f2ecSJim Ingham case 'G': { 82b842f2ecSJim Ingham bool value, success; 8347cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 84b842f2ecSJim Ingham if (success) { 85b842f2ecSJim Ingham m_bp_opts.SetAutoContinue(value); 86b842f2ecSJim Ingham } else 87b842f2ecSJim Ingham error.SetErrorStringWithFormat( 88b842f2ecSJim Ingham "invalid boolean value '%s' passed for -G option", 89b842f2ecSJim Ingham option_arg.str().c_str()); 90a925974bSAdrian Prantl } break; 91a925974bSAdrian Prantl case 'i': { 92b842f2ecSJim Ingham uint32_t ignore_count; 93b842f2ecSJim Ingham if (option_arg.getAsInteger(0, ignore_count)) 94b842f2ecSJim Ingham error.SetErrorStringWithFormat("invalid ignore count '%s'", 95b842f2ecSJim Ingham option_arg.str().c_str()); 96b842f2ecSJim Ingham else 97b842f2ecSJim Ingham m_bp_opts.SetIgnoreCount(ignore_count); 98a925974bSAdrian Prantl } break; 99b842f2ecSJim Ingham case 'o': { 100b842f2ecSJim Ingham bool value, success; 10147cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 102b842f2ecSJim Ingham if (success) { 103b842f2ecSJim Ingham m_bp_opts.SetOneShot(value); 104b842f2ecSJim Ingham } else 105b842f2ecSJim Ingham error.SetErrorStringWithFormat( 106b842f2ecSJim Ingham "invalid boolean value '%s' passed for -o option", 107b842f2ecSJim Ingham option_arg.str().c_str()); 108b842f2ecSJim Ingham } break; 109a925974bSAdrian Prantl case 't': { 110b842f2ecSJim Ingham lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID; 111b842f2ecSJim Ingham if (option_arg[0] != '\0') { 112b842f2ecSJim Ingham if (option_arg.getAsInteger(0, thread_id)) 113b842f2ecSJim Ingham error.SetErrorStringWithFormat("invalid thread id string '%s'", 114b842f2ecSJim Ingham option_arg.str().c_str()); 115b842f2ecSJim Ingham } 116b842f2ecSJim Ingham m_bp_opts.SetThreadID(thread_id); 117a925974bSAdrian Prantl } break; 118b842f2ecSJim Ingham case 'T': 119b842f2ecSJim Ingham m_bp_opts.GetThreadSpec()->SetName(option_arg.str().c_str()); 120b842f2ecSJim Ingham break; 121b842f2ecSJim Ingham case 'q': 122b842f2ecSJim Ingham m_bp_opts.GetThreadSpec()->SetQueueName(option_arg.str().c_str()); 123b842f2ecSJim Ingham break; 124a925974bSAdrian Prantl case 'x': { 125b842f2ecSJim Ingham uint32_t thread_index = UINT32_MAX; 126b842f2ecSJim Ingham if (option_arg[0] != '\n') { 127b842f2ecSJim Ingham if (option_arg.getAsInteger(0, thread_index)) 128b842f2ecSJim Ingham error.SetErrorStringWithFormat("invalid thread index string '%s'", 129b842f2ecSJim Ingham option_arg.str().c_str()); 130b842f2ecSJim Ingham } 131b842f2ecSJim Ingham m_bp_opts.GetThreadSpec()->SetIndex(thread_index); 132a925974bSAdrian Prantl } break; 133b842f2ecSJim Ingham default: 13436162014SRaphael Isemann llvm_unreachable("Unimplemented option"); 135b842f2ecSJim Ingham } 136b842f2ecSJim Ingham 137b842f2ecSJim Ingham return error; 138b842f2ecSJim Ingham } 139b842f2ecSJim Ingham 140b842f2ecSJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 141b842f2ecSJim Ingham m_bp_opts.Clear(); 142b842f2ecSJim Ingham m_commands.clear(); 143b842f2ecSJim Ingham } 144b842f2ecSJim Ingham 145b842f2ecSJim Ingham Status OptionParsingFinished(ExecutionContext *execution_context) override { 146a925974bSAdrian Prantl if (!m_commands.empty()) { 147a8f3ae7cSJonas Devlieghere auto cmd_data = std::make_unique<BreakpointOptions::CommandData>(); 148b842f2ecSJim Ingham 149b842f2ecSJim Ingham for (std::string &str : m_commands) 150b842f2ecSJim Ingham cmd_data->user_source.AppendString(str); 151b842f2ecSJim Ingham 152b842f2ecSJim Ingham cmd_data->stop_on_error = true; 153b842f2ecSJim Ingham m_bp_opts.SetCommandDataCallback(cmd_data); 154b842f2ecSJim Ingham } 155b842f2ecSJim Ingham return Status(); 156b842f2ecSJim Ingham } 157b842f2ecSJim Ingham 158a925974bSAdrian Prantl const BreakpointOptions &GetBreakpointOptions() { return m_bp_opts; } 159b842f2ecSJim Ingham 160b842f2ecSJim Ingham std::vector<std::string> m_commands; 161b842f2ecSJim Ingham BreakpointOptions m_bp_opts; 162b842f2ecSJim Ingham }; 163bd68a052SRaphael Isemann 164f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_dummy 165f94668e3SRaphael Isemann #include "CommandOptions.inc" 166b842f2ecSJim Ingham 167a925974bSAdrian Prantl class BreakpointDummyOptionGroup : public OptionGroup { 168b842f2ecSJim Ingham public: 169a925974bSAdrian Prantl BreakpointDummyOptionGroup() : OptionGroup() {} 170b842f2ecSJim Ingham 171b842f2ecSJim Ingham ~BreakpointDummyOptionGroup() override = default; 172b842f2ecSJim Ingham 173b842f2ecSJim Ingham llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 174b842f2ecSJim Ingham return llvm::makeArrayRef(g_breakpoint_dummy_options); 175b842f2ecSJim Ingham } 176b842f2ecSJim Ingham 177b842f2ecSJim Ingham Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 178b842f2ecSJim Ingham ExecutionContext *execution_context) override { 179b842f2ecSJim Ingham Status error; 180a925974bSAdrian Prantl const int short_option = 181f1539b9dSJim Ingham g_breakpoint_dummy_options[option_idx].short_option; 182b842f2ecSJim Ingham 183b842f2ecSJim Ingham switch (short_option) { 184b842f2ecSJim Ingham case 'D': 185b842f2ecSJim Ingham m_use_dummy = true; 186b842f2ecSJim Ingham break; 187b842f2ecSJim Ingham default: 18836162014SRaphael Isemann llvm_unreachable("Unimplemented option"); 189b842f2ecSJim Ingham } 190b842f2ecSJim Ingham 191b842f2ecSJim Ingham return error; 192b842f2ecSJim Ingham } 193b842f2ecSJim Ingham 194b842f2ecSJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 195b842f2ecSJim Ingham m_use_dummy = false; 196b842f2ecSJim Ingham } 197b842f2ecSJim Ingham 198b842f2ecSJim Ingham bool m_use_dummy; 199b842f2ecSJim Ingham }; 200b842f2ecSJim Ingham 201f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_set 202f94668e3SRaphael Isemann #include "CommandOptions.inc" 2031f0f5b5bSZachary Turner 2045a988416SJim Ingham // CommandObjectBreakpointSet 20530fdc8d8SChris Lattner 206b9c1b51eSKate Stone class CommandObjectBreakpointSet : public CommandObjectParsed { 2075a988416SJim Ingham public: 208efe8e7e3SFangrui Song enum BreakpointSetType { 2095a988416SJim Ingham eSetTypeInvalid, 2105a988416SJim Ingham eSetTypeFileAndLine, 2115a988416SJim Ingham eSetTypeAddress, 2125a988416SJim Ingham eSetTypeFunctionName, 2135a988416SJim Ingham eSetTypeFunctionRegexp, 2145a988416SJim Ingham eSetTypeSourceRegexp, 2153815e702SJim Ingham eSetTypeException, 2163815e702SJim Ingham eSetTypeScripted, 217efe8e7e3SFangrui Song }; 2185a988416SJim Ingham 219b9c1b51eSKate Stone CommandObjectBreakpointSet(CommandInterpreter &interpreter) 220b9c1b51eSKate Stone : CommandObjectParsed( 221b9c1b51eSKate Stone interpreter, "breakpoint set", 2225a988416SJim Ingham "Sets a breakpoint or set of breakpoints in the executable.", 2235a988416SJim Ingham "breakpoint set <cmd-options>"), 224738af7a6SJim Ingham m_bp_opts(), m_python_class_options("scripted breakpoint", true, 'P'), 225f6a2086dSSam McCall m_options() { 226b842f2ecSJim Ingham // We're picking up all the normal options, commands and disable. 227a925974bSAdrian Prantl m_all_options.Append(&m_python_class_options, 228a925974bSAdrian Prantl LLDB_OPT_SET_1 | LLDB_OPT_SET_2, LLDB_OPT_SET_11); 229b842f2ecSJim Ingham m_all_options.Append(&m_bp_opts, 230b842f2ecSJim Ingham LLDB_OPT_SET_1 | LLDB_OPT_SET_3 | LLDB_OPT_SET_4, 231b842f2ecSJim Ingham LLDB_OPT_SET_ALL); 232f6a2086dSSam McCall m_all_options.Append(&m_dummy_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 233b842f2ecSJim Ingham m_all_options.Append(&m_options); 234b842f2ecSJim Ingham m_all_options.Finalize(); 235b842f2ecSJim Ingham } 2365a988416SJim Ingham 2379e85e5a8SEugene Zelenko ~CommandObjectBreakpointSet() override = default; 2385a988416SJim Ingham 239b842f2ecSJim Ingham Options *GetOptions() override { return &m_all_options; } 2405a988416SJim Ingham 241b842f2ecSJim Ingham class CommandOptions : public OptionGroup { 2425a988416SJim Ingham public: 243b9c1b51eSKate Stone CommandOptions() 244a925974bSAdrian Prantl : OptionGroup(), m_condition(), m_filenames(), m_line_num(0), 245a925974bSAdrian Prantl m_column(0), m_func_names(), 246a925974bSAdrian Prantl m_func_name_type_mask(eFunctionNameTypeNone), m_func_regexp(), 247a925974bSAdrian Prantl m_source_text_regexp(), m_modules(), m_load_addr(), m_catch_bp(false), 248a925974bSAdrian Prantl m_throw_bp(true), m_hardware(false), 249a72b31c7SJim Ingham m_exception_language(eLanguageTypeUnknown), 25023b1decbSDawn Perchik m_language(lldb::eLanguageTypeUnknown), 251a925974bSAdrian Prantl m_skip_prologue(eLazyBoolCalculate), m_all_files(false), 252a925974bSAdrian Prantl m_move_to_nearest_code(eLazyBoolCalculate) {} 25330fdc8d8SChris Lattner 2549e85e5a8SEugene Zelenko ~CommandOptions() override = default; 25587df91b8SJim Ingham 25697206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 257b9c1b51eSKate Stone ExecutionContext *execution_context) override { 25897206d57SZachary Turner Status error; 259a925974bSAdrian Prantl const int short_option = 260a925974bSAdrian Prantl g_breakpoint_set_options[option_idx].short_option; 26130fdc8d8SChris Lattner 262b9c1b51eSKate Stone switch (short_option) { 263b9c1b51eSKate Stone case 'a': { 26447cbf4a0SPavel Labath m_load_addr = OptionArgParser::ToAddress(execution_context, option_arg, 265e1cfbc79STodd Fiala LLDB_INVALID_ADDRESS, &error); 266b9c1b51eSKate Stone } break; 26730fdc8d8SChris Lattner 268e732052fSJim Ingham case 'A': 269e732052fSJim Ingham m_all_files = true; 270e732052fSJim Ingham break; 271e732052fSJim Ingham 272ca36cd16SJim Ingham case 'b': 273adcd0268SBenjamin Kramer m_func_names.push_back(std::string(option_arg)); 274ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeBase; 275ca36cd16SJim Ingham break; 276ca36cd16SJim Ingham 2776672a4f5SJonas Devlieghere case 'u': 278fe11483bSZachary Turner if (option_arg.getAsInteger(0, m_column)) 279b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid column number: %s", 280fe11483bSZachary Turner option_arg.str().c_str()); 28130fdc8d8SChris Lattner break; 2829e85e5a8SEugene Zelenko 283b9c1b51eSKate Stone case 'E': { 284fe11483bSZachary Turner LanguageType language = Language::GetLanguageTypeFromString(option_arg); 285fab10e89SJim Ingham 286b9c1b51eSKate Stone switch (language) { 287fab10e89SJim Ingham case eLanguageTypeC89: 288fab10e89SJim Ingham case eLanguageTypeC: 289fab10e89SJim Ingham case eLanguageTypeC99: 2901d0089faSBruce Mitchener case eLanguageTypeC11: 291a72b31c7SJim Ingham m_exception_language = eLanguageTypeC; 292fab10e89SJim Ingham break; 293fab10e89SJim Ingham case eLanguageTypeC_plus_plus: 2941d0089faSBruce Mitchener case eLanguageTypeC_plus_plus_03: 2951d0089faSBruce Mitchener case eLanguageTypeC_plus_plus_11: 2962ba84a6aSBruce Mitchener case eLanguageTypeC_plus_plus_14: 297a72b31c7SJim Ingham m_exception_language = eLanguageTypeC_plus_plus; 298fab10e89SJim Ingham break; 299fab10e89SJim Ingham case eLanguageTypeObjC: 300a72b31c7SJim Ingham m_exception_language = eLanguageTypeObjC; 301fab10e89SJim Ingham break; 302fab10e89SJim Ingham case eLanguageTypeObjC_plus_plus: 303b9c1b51eSKate Stone error.SetErrorStringWithFormat( 304b9c1b51eSKate Stone "Set exception breakpoints separately for c++ and objective-c"); 305fab10e89SJim Ingham break; 306fab10e89SJim Ingham case eLanguageTypeUnknown: 307b9c1b51eSKate Stone error.SetErrorStringWithFormat( 308b9c1b51eSKate Stone "Unknown language type: '%s' for exception breakpoint", 309fe11483bSZachary Turner option_arg.str().c_str()); 310fab10e89SJim Ingham break; 311fab10e89SJim Ingham default: 312b9c1b51eSKate Stone error.SetErrorStringWithFormat( 313b9c1b51eSKate Stone "Unsupported language type: '%s' for exception breakpoint", 314fe11483bSZachary Turner option_arg.str().c_str()); 315fab10e89SJim Ingham } 316b9c1b51eSKate Stone } break; 317ca36cd16SJim Ingham 318ca36cd16SJim Ingham case 'f': 3198f3be7a3SJonas Devlieghere m_filenames.AppendIfUnique(FileSpec(option_arg)); 320fab10e89SJim Ingham break; 321ca36cd16SJim Ingham 322ca36cd16SJim Ingham case 'F': 323adcd0268SBenjamin Kramer m_func_names.push_back(std::string(option_arg)); 324ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeFull; 325ca36cd16SJim Ingham break; 326ca36cd16SJim Ingham 327b9c1b51eSKate Stone case 'h': { 328fab10e89SJim Ingham bool success; 32947cbf4a0SPavel Labath m_catch_bp = OptionArgParser::ToBoolean(option_arg, true, &success); 330fab10e89SJim Ingham if (!success) 331b9c1b51eSKate Stone error.SetErrorStringWithFormat( 332fe11483bSZachary Turner "Invalid boolean value for on-catch option: '%s'", 333fe11483bSZachary Turner option_arg.str().c_str()); 334b9c1b51eSKate Stone } break; 335eb023e75SGreg Clayton 336eb023e75SGreg Clayton case 'H': 337eb023e75SGreg Clayton m_hardware = true; 338eb023e75SGreg Clayton break; 339eb023e75SGreg Clayton 340b9c1b51eSKate Stone case 'K': { 341a8558b62SJim Ingham bool success; 342a8558b62SJim Ingham bool value; 34347cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, true, &success); 344a8558b62SJim Ingham if (value) 345a8558b62SJim Ingham m_skip_prologue = eLazyBoolYes; 346a8558b62SJim Ingham else 347a8558b62SJim Ingham m_skip_prologue = eLazyBoolNo; 348a8558b62SJim Ingham 349a8558b62SJim Ingham if (!success) 350b9c1b51eSKate Stone error.SetErrorStringWithFormat( 351b9c1b51eSKate Stone "Invalid boolean value for skip prologue option: '%s'", 352fe11483bSZachary Turner option_arg.str().c_str()); 353b9c1b51eSKate Stone } break; 354ca36cd16SJim Ingham 355fe11483bSZachary Turner case 'l': 356fe11483bSZachary Turner if (option_arg.getAsInteger(0, m_line_num)) 357b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid line number: %s.", 358fe11483bSZachary Turner option_arg.str().c_str()); 359ca36cd16SJim Ingham break; 360055ad9beSIlia K 36123b1decbSDawn Perchik case 'L': 362fe11483bSZachary Turner m_language = Language::GetLanguageTypeFromString(option_arg); 36323b1decbSDawn Perchik if (m_language == eLanguageTypeUnknown) 364b9c1b51eSKate Stone error.SetErrorStringWithFormat( 365fe11483bSZachary Turner "Unknown language type: '%s' for breakpoint", 366fe11483bSZachary Turner option_arg.str().c_str()); 36723b1decbSDawn Perchik break; 36823b1decbSDawn Perchik 369b9c1b51eSKate Stone case 'm': { 370055ad9beSIlia K bool success; 371055ad9beSIlia K bool value; 37247cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, true, &success); 373055ad9beSIlia K if (value) 374055ad9beSIlia K m_move_to_nearest_code = eLazyBoolYes; 375055ad9beSIlia K else 376055ad9beSIlia K m_move_to_nearest_code = eLazyBoolNo; 377055ad9beSIlia K 378055ad9beSIlia K if (!success) 379b9c1b51eSKate Stone error.SetErrorStringWithFormat( 380b9c1b51eSKate Stone "Invalid boolean value for move-to-nearest-code option: '%s'", 381fe11483bSZachary Turner option_arg.str().c_str()); 382055ad9beSIlia K break; 383055ad9beSIlia K } 384055ad9beSIlia K 385ca36cd16SJim Ingham case 'M': 386adcd0268SBenjamin Kramer m_func_names.push_back(std::string(option_arg)); 387ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeMethod; 388ca36cd16SJim Ingham break; 389ca36cd16SJim Ingham 390ca36cd16SJim Ingham case 'n': 391adcd0268SBenjamin Kramer m_func_names.push_back(std::string(option_arg)); 392ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeAuto; 393ca36cd16SJim Ingham break; 394ca36cd16SJim Ingham 3956fa7681bSZachary Turner case 'N': { 396fe11483bSZachary Turner if (BreakpointID::StringIsBreakpointName(option_arg, error)) 397adcd0268SBenjamin Kramer m_breakpoint_names.push_back(std::string(option_arg)); 398ff9a91eaSJim Ingham else 399ff9a91eaSJim Ingham error.SetErrorStringWithFormat("Invalid breakpoint name: %s", 400fe11483bSZachary Turner option_arg.str().c_str()); 4015e09c8c3SJim Ingham break; 4026fa7681bSZachary Turner } 4035e09c8c3SJim Ingham 404b9c1b51eSKate Stone case 'R': { 4052411167fSJim Ingham lldb::addr_t tmp_offset_addr; 40647cbf4a0SPavel Labath tmp_offset_addr = OptionArgParser::ToAddress(execution_context, 40747cbf4a0SPavel Labath option_arg, 0, &error); 4082411167fSJim Ingham if (error.Success()) 4092411167fSJim Ingham m_offset_addr = tmp_offset_addr; 410b9c1b51eSKate Stone } break; 4112411167fSJim Ingham 412a72b31c7SJim Ingham case 'O': 413fe11483bSZachary Turner m_exception_extra_args.AppendArgument("-O"); 414fe11483bSZachary Turner m_exception_extra_args.AppendArgument(option_arg); 415a72b31c7SJim Ingham break; 416a72b31c7SJim Ingham 417ca36cd16SJim Ingham case 'p': 418adcd0268SBenjamin Kramer m_source_text_regexp.assign(std::string(option_arg)); 419ca36cd16SJim Ingham break; 420ca36cd16SJim Ingham 421ca36cd16SJim Ingham case 'r': 422adcd0268SBenjamin Kramer m_func_regexp.assign(std::string(option_arg)); 423ca36cd16SJim Ingham break; 424ca36cd16SJim Ingham 425ca36cd16SJim Ingham case 's': 4268f3be7a3SJonas Devlieghere m_modules.AppendIfUnique(FileSpec(option_arg)); 427ca36cd16SJim Ingham break; 428ca36cd16SJim Ingham 429ca36cd16SJim Ingham case 'S': 430adcd0268SBenjamin Kramer m_func_names.push_back(std::string(option_arg)); 431ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeSelector; 432ca36cd16SJim Ingham break; 433ca36cd16SJim Ingham 434b9c1b51eSKate Stone case 'w': { 435ca36cd16SJim Ingham bool success; 43647cbf4a0SPavel Labath m_throw_bp = OptionArgParser::ToBoolean(option_arg, true, &success); 437ca36cd16SJim Ingham if (!success) 438b9c1b51eSKate Stone error.SetErrorStringWithFormat( 439fe11483bSZachary Turner "Invalid boolean value for on-throw option: '%s'", 440fe11483bSZachary Turner option_arg.str().c_str()); 441b9c1b51eSKate Stone } break; 442ca36cd16SJim Ingham 44376bb8d67SJim Ingham case 'X': 444adcd0268SBenjamin Kramer m_source_regex_func_names.insert(std::string(option_arg)); 44576bb8d67SJim Ingham break; 44676bb8d67SJim Ingham 44730fdc8d8SChris Lattner default: 44836162014SRaphael Isemann llvm_unreachable("Unimplemented option"); 44930fdc8d8SChris Lattner } 45030fdc8d8SChris Lattner 45130fdc8d8SChris Lattner return error; 45230fdc8d8SChris Lattner } 4539e85e5a8SEugene Zelenko 454b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 45587df91b8SJim Ingham m_filenames.Clear(); 45630fdc8d8SChris Lattner m_line_num = 0; 45730fdc8d8SChris Lattner m_column = 0; 458fab10e89SJim Ingham m_func_names.clear(); 4591f746071SGreg Clayton m_func_name_type_mask = eFunctionNameTypeNone; 46030fdc8d8SChris Lattner m_func_regexp.clear(); 4611f746071SGreg Clayton m_source_text_regexp.clear(); 46287df91b8SJim Ingham m_modules.Clear(); 4631f746071SGreg Clayton m_load_addr = LLDB_INVALID_ADDRESS; 4642411167fSJim Ingham m_offset_addr = 0; 465fab10e89SJim Ingham m_catch_bp = false; 466fab10e89SJim Ingham m_throw_bp = true; 467eb023e75SGreg Clayton m_hardware = false; 468a72b31c7SJim Ingham m_exception_language = eLanguageTypeUnknown; 46923b1decbSDawn Perchik m_language = lldb::eLanguageTypeUnknown; 470a8558b62SJim Ingham m_skip_prologue = eLazyBoolCalculate; 4715e09c8c3SJim Ingham m_breakpoint_names.clear(); 472e732052fSJim Ingham m_all_files = false; 473a72b31c7SJim Ingham m_exception_extra_args.Clear(); 474055ad9beSIlia K m_move_to_nearest_code = eLazyBoolCalculate; 47576bb8d67SJim Ingham m_source_regex_func_names.clear(); 4763815e702SJim Ingham m_current_key.clear(); 47730fdc8d8SChris Lattner } 47830fdc8d8SChris Lattner 4791f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 48070602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_set_options); 4811f0f5b5bSZachary Turner } 48230fdc8d8SChris Lattner 4835a988416SJim Ingham // Instance variables to hold the values for command options. 484969795f1SJim Ingham 4855a988416SJim Ingham std::string m_condition; 4865a988416SJim Ingham FileSpecList m_filenames; 4875a988416SJim Ingham uint32_t m_line_num; 4885a988416SJim Ingham uint32_t m_column; 4895a988416SJim Ingham std::vector<std::string> m_func_names; 4905e09c8c3SJim Ingham std::vector<std::string> m_breakpoint_names; 491117b1fa1SZachary Turner lldb::FunctionNameType m_func_name_type_mask; 4925a988416SJim Ingham std::string m_func_regexp; 4935a988416SJim Ingham std::string m_source_text_regexp; 4945a988416SJim Ingham FileSpecList m_modules; 4955a988416SJim Ingham lldb::addr_t m_load_addr; 4962411167fSJim Ingham lldb::addr_t m_offset_addr; 4975a988416SJim Ingham bool m_catch_bp; 4985a988416SJim Ingham bool m_throw_bp; 499eb023e75SGreg Clayton bool m_hardware; // Request to use hardware breakpoints 500a72b31c7SJim Ingham lldb::LanguageType m_exception_language; 50123b1decbSDawn Perchik lldb::LanguageType m_language; 5025a988416SJim Ingham LazyBool m_skip_prologue; 503e732052fSJim Ingham bool m_all_files; 504a72b31c7SJim Ingham Args m_exception_extra_args; 505055ad9beSIlia K LazyBool m_move_to_nearest_code; 50676bb8d67SJim Ingham std::unordered_set<std::string> m_source_regex_func_names; 5073815e702SJim Ingham std::string m_current_key; 5085a988416SJim Ingham }; 5095a988416SJim Ingham 5105a988416SJim Ingham protected: 511b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 512cb2380c9SRaphael Isemann Target &target = GetSelectedOrDummyTarget(m_dummy_options.m_use_dummy); 51330fdc8d8SChris Lattner 51430fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 51530fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 51630fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 51730fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 518b9c1b51eSKate Stone // 4). -r [-s -g] (setting breakpoint by function name regular 519b9c1b51eSKate Stone // expression) 520b9c1b51eSKate Stone // 5). -p -f (setting a breakpoint by comparing a reg-exp 521b9c1b51eSKate Stone // to source text) 522b9c1b51eSKate Stone // 6). -E [-w -h] (setting a breakpoint for exceptions for a 523b9c1b51eSKate Stone // given language.) 52430fdc8d8SChris Lattner 52530fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 52630fdc8d8SChris Lattner 527738af7a6SJim Ingham if (!m_python_class_options.GetName().empty()) 5283815e702SJim Ingham break_type = eSetTypeScripted; 5293815e702SJim Ingham else if (m_options.m_line_num != 0) 53030fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 53130fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 53230fdc8d8SChris Lattner break_type = eSetTypeAddress; 533fab10e89SJim Ingham else if (!m_options.m_func_names.empty()) 53430fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 53530fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 53630fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 537969795f1SJim Ingham else if (!m_options.m_source_text_regexp.empty()) 538969795f1SJim Ingham break_type = eSetTypeSourceRegexp; 539a72b31c7SJim Ingham else if (m_options.m_exception_language != eLanguageTypeUnknown) 540fab10e89SJim Ingham break_type = eSetTypeException; 54130fdc8d8SChris Lattner 542b842f2ecSJim Ingham BreakpointSP bp_sp = nullptr; 543274060b6SGreg Clayton FileSpec module_spec; 544a8558b62SJim Ingham const bool internal = false; 545a8558b62SJim Ingham 546b9c1b51eSKate Stone // If the user didn't specify skip-prologue, having an offset should turn 547b9c1b51eSKate Stone // that off. 548b9c1b51eSKate Stone if (m_options.m_offset_addr != 0 && 549b9c1b51eSKate Stone m_options.m_skip_prologue == eLazyBoolCalculate) 5502411167fSJim Ingham m_options.m_skip_prologue = eLazyBoolNo; 5512411167fSJim Ingham 552b9c1b51eSKate Stone switch (break_type) { 55330fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 55430fdc8d8SChris Lattner { 55530fdc8d8SChris Lattner FileSpec file; 556c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 557b9c1b51eSKate Stone if (num_files == 0) { 558b9c1b51eSKate Stone if (!GetDefaultFile(target, file, result)) { 55987df91b8SJim Ingham result.AppendError("No file supplied and no default file available."); 56087df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 56187df91b8SJim Ingham return false; 56287df91b8SJim Ingham } 563b9c1b51eSKate Stone } else if (num_files > 1) { 564b9c1b51eSKate Stone result.AppendError("Only one file at a time is allowed for file and " 565b9c1b51eSKate Stone "line breakpoints."); 56687df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 56787df91b8SJim Ingham return false; 568b9c1b51eSKate Stone } else 56987df91b8SJim Ingham file = m_options.m_filenames.GetFileSpecAtIndex(0); 57030fdc8d8SChris Lattner 5711f746071SGreg Clayton // Only check for inline functions if 5721f746071SGreg Clayton LazyBool check_inlines = eLazyBoolCalculate; 5731f746071SGreg Clayton 574cb2380c9SRaphael Isemann bp_sp = target.CreateBreakpoint( 575cb2380c9SRaphael Isemann &(m_options.m_modules), file, m_options.m_line_num, 576cb2380c9SRaphael Isemann m_options.m_column, m_options.m_offset_addr, check_inlines, 577cb2380c9SRaphael Isemann m_options.m_skip_prologue, internal, m_options.m_hardware, 578b842f2ecSJim Ingham m_options.m_move_to_nearest_code); 579b9c1b51eSKate Stone } break; 5806eee5aa0SGreg Clayton 58130fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 582055a08a4SJim Ingham { 583b9c1b51eSKate Stone // If a shared library has been specified, make an lldb_private::Address 584b842f2ecSJim Ingham // with the library, and use that. That way the address breakpoint 585b842f2ecSJim Ingham // will track the load location of the library. 586055a08a4SJim Ingham size_t num_modules_specified = m_options.m_modules.GetSize(); 587b9c1b51eSKate Stone if (num_modules_specified == 1) { 588b9c1b51eSKate Stone const FileSpec *file_spec = 589b9c1b51eSKate Stone m_options.m_modules.GetFileSpecPointerAtIndex(0); 590cb2380c9SRaphael Isemann bp_sp = target.CreateAddressInModuleBreakpoint( 591cb2380c9SRaphael Isemann m_options.m_load_addr, internal, file_spec, m_options.m_hardware); 592b9c1b51eSKate Stone } else if (num_modules_specified == 0) { 593cb2380c9SRaphael Isemann bp_sp = target.CreateBreakpoint(m_options.m_load_addr, internal, 594b842f2ecSJim Ingham m_options.m_hardware); 595b9c1b51eSKate Stone } else { 596b9c1b51eSKate Stone result.AppendError("Only one shared library can be specified for " 597b9c1b51eSKate Stone "address breakpoints."); 598055a08a4SJim Ingham result.SetStatus(eReturnStatusFailed); 599055a08a4SJim Ingham return false; 600055a08a4SJim Ingham } 60130fdc8d8SChris Lattner break; 602055a08a4SJim Ingham } 60330fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 6040c5cd90dSGreg Clayton { 605117b1fa1SZachary Turner FunctionNameType name_type_mask = m_options.m_func_name_type_mask; 6060c5cd90dSGreg Clayton 6070c5cd90dSGreg Clayton if (name_type_mask == 0) 608e02b8504SGreg Clayton name_type_mask = eFunctionNameTypeAuto; 6090c5cd90dSGreg Clayton 610cb2380c9SRaphael Isemann bp_sp = target.CreateBreakpoint( 611cb2380c9SRaphael Isemann &(m_options.m_modules), &(m_options.m_filenames), 612cb2380c9SRaphael Isemann m_options.m_func_names, name_type_mask, m_options.m_language, 613cb2380c9SRaphael Isemann m_options.m_offset_addr, m_options.m_skip_prologue, internal, 614b842f2ecSJim Ingham m_options.m_hardware); 615b9c1b51eSKate Stone } break; 6160c5cd90dSGreg Clayton 617b9c1b51eSKate Stone case eSetTypeFunctionRegexp: // Breakpoint by regular expression function 618b9c1b51eSKate Stone // name 61930fdc8d8SChris Lattner { 62095eae423SZachary Turner RegularExpression regexp(m_options.m_func_regexp); 6213af3f1e8SJonas Devlieghere if (llvm::Error err = regexp.GetError()) { 622b9c1b51eSKate Stone result.AppendErrorWithFormat( 623*b58af8d2SRaphael Isemann "Function name regular expression could not be compiled: %s", 6243af3f1e8SJonas Devlieghere llvm::toString(std::move(err)).c_str()); 62530fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 626969795f1SJim Ingham return false; 62730fdc8d8SChris Lattner } 62887df91b8SJim Ingham 629cb2380c9SRaphael Isemann bp_sp = target.CreateFuncRegexBreakpoint( 6305aa1d819SJan Kratochvil &(m_options.m_modules), &(m_options.m_filenames), std::move(regexp), 631cb2380c9SRaphael Isemann m_options.m_language, m_options.m_skip_prologue, internal, 632b842f2ecSJim Ingham m_options.m_hardware); 633a925974bSAdrian Prantl } break; 634969795f1SJim Ingham case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. 635969795f1SJim Ingham { 636c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 63787df91b8SJim Ingham 638b9c1b51eSKate Stone if (num_files == 0 && !m_options.m_all_files) { 639969795f1SJim Ingham FileSpec file; 640b9c1b51eSKate Stone if (!GetDefaultFile(target, file, result)) { 641b9c1b51eSKate Stone result.AppendError( 642b9c1b51eSKate Stone "No files provided and could not find default file."); 64387df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 64487df91b8SJim Ingham return false; 645b9c1b51eSKate Stone } else { 64687df91b8SJim Ingham m_options.m_filenames.Append(file); 64787df91b8SJim Ingham } 64887df91b8SJim Ingham } 6490c5cd90dSGreg Clayton 65095eae423SZachary Turner RegularExpression regexp(m_options.m_source_text_regexp); 6513af3f1e8SJonas Devlieghere if (llvm::Error err = regexp.GetError()) { 652b9c1b51eSKate Stone result.AppendErrorWithFormat( 653b9c1b51eSKate Stone "Source text regular expression could not be compiled: \"%s\"", 6543af3f1e8SJonas Devlieghere llvm::toString(std::move(err)).c_str()); 655969795f1SJim Ingham result.SetStatus(eReturnStatusFailed); 656969795f1SJim Ingham return false; 657969795f1SJim Ingham } 658cb2380c9SRaphael Isemann bp_sp = target.CreateSourceRegexBreakpoint( 659cb2380c9SRaphael Isemann &(m_options.m_modules), &(m_options.m_filenames), 6605aa1d819SJan Kratochvil m_options.m_source_regex_func_names, std::move(regexp), internal, 661cb2380c9SRaphael Isemann m_options.m_hardware, m_options.m_move_to_nearest_code); 662b9c1b51eSKate Stone } break; 663b9c1b51eSKate Stone case eSetTypeException: { 66497206d57SZachary Turner Status precond_error; 665cb2380c9SRaphael Isemann bp_sp = target.CreateExceptionBreakpoint( 666cb2380c9SRaphael Isemann m_options.m_exception_language, m_options.m_catch_bp, 667cb2380c9SRaphael Isemann m_options.m_throw_bp, internal, &m_options.m_exception_extra_args, 668b842f2ecSJim Ingham &precond_error); 669b9c1b51eSKate Stone if (precond_error.Fail()) { 670b9c1b51eSKate Stone result.AppendErrorWithFormat( 671b9c1b51eSKate Stone "Error setting extra exception arguments: %s", 672a72b31c7SJim Ingham precond_error.AsCString()); 673cb2380c9SRaphael Isemann target.RemoveBreakpointByID(bp_sp->GetID()); 674a72b31c7SJim Ingham result.SetStatus(eReturnStatusFailed); 675a72b31c7SJim Ingham return false; 676a72b31c7SJim Ingham } 677b9c1b51eSKate Stone } break; 6783815e702SJim Ingham case eSetTypeScripted: { 6793815e702SJim Ingham 6803815e702SJim Ingham Status error; 681cb2380c9SRaphael Isemann bp_sp = target.CreateScriptedBreakpoint( 682738af7a6SJim Ingham m_python_class_options.GetName().c_str(), &(m_options.m_modules), 683cb2380c9SRaphael Isemann &(m_options.m_filenames), false, m_options.m_hardware, 684943a2481SJim Ingham m_python_class_options.GetStructuredData(), &error); 6853815e702SJim Ingham if (error.Fail()) { 6863815e702SJim Ingham result.AppendErrorWithFormat( 687a925974bSAdrian Prantl "Error setting extra exception arguments: %s", error.AsCString()); 688cb2380c9SRaphael Isemann target.RemoveBreakpointByID(bp_sp->GetID()); 6893815e702SJim Ingham result.SetStatus(eReturnStatusFailed); 6903815e702SJim Ingham return false; 6913815e702SJim Ingham } 6923815e702SJim Ingham } break; 69330fdc8d8SChris Lattner default: 69430fdc8d8SChris Lattner break; 69530fdc8d8SChris Lattner } 69630fdc8d8SChris Lattner 6971b54c88cSJim Ingham // Now set the various options that were passed in: 698b842f2ecSJim Ingham if (bp_sp) { 699b842f2ecSJim Ingham bp_sp->GetOptions()->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); 700ca36cd16SJim Ingham 701b9c1b51eSKate Stone if (!m_options.m_breakpoint_names.empty()) { 70297206d57SZachary Turner Status name_error; 703ff9a91eaSJim Ingham for (auto name : m_options.m_breakpoint_names) { 704cb2380c9SRaphael Isemann target.AddNameToBreakpoint(bp_sp, name.c_str(), name_error); 705ff9a91eaSJim Ingham if (name_error.Fail()) { 706ff9a91eaSJim Ingham result.AppendErrorWithFormat("Invalid breakpoint name: %s", 707ff9a91eaSJim Ingham name.c_str()); 708cb2380c9SRaphael Isemann target.RemoveBreakpointByID(bp_sp->GetID()); 709ff9a91eaSJim Ingham result.SetStatus(eReturnStatusFailed); 710ff9a91eaSJim Ingham return false; 711ff9a91eaSJim Ingham } 712ff9a91eaSJim Ingham } 7135e09c8c3SJim Ingham } 7141b54c88cSJim Ingham } 7151b54c88cSJim Ingham 716b842f2ecSJim Ingham if (bp_sp) { 71785e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 7181391cc7dSJim Ingham const bool show_locations = false; 719b842f2ecSJim Ingham bp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, 720b9c1b51eSKate Stone show_locations); 721cb2380c9SRaphael Isemann if (&target == &GetDummyTarget()) 722b9c1b51eSKate Stone output_stream.Printf("Breakpoint set in dummy target, will get copied " 723b9c1b51eSKate Stone "into future targets.\n"); 724b9c1b51eSKate Stone else { 72505097246SAdrian Prantl // Don't print out this warning for exception breakpoints. They can 72605097246SAdrian Prantl // get set before the target is set, but we won't know how to actually 72705097246SAdrian Prantl // set the breakpoint till we run. 728b842f2ecSJim Ingham if (bp_sp->GetNumLocations() == 0 && break_type != eSetTypeException) { 729b9c1b51eSKate Stone output_stream.Printf("WARNING: Unable to resolve breakpoint to any " 730b9c1b51eSKate Stone "actual locations.\n"); 7314aeb1989SJim Ingham } 7324aeb1989SJim Ingham } 73330fdc8d8SChris Lattner result.SetStatus(eReturnStatusSuccessFinishResult); 734b842f2ecSJim Ingham } else if (!bp_sp) { 73530fdc8d8SChris Lattner result.AppendError("Breakpoint creation failed: No breakpoint created."); 73630fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 73730fdc8d8SChris Lattner } 73830fdc8d8SChris Lattner 73930fdc8d8SChris Lattner return result.Succeeded(); 74030fdc8d8SChris Lattner } 74130fdc8d8SChris Lattner 7425a988416SJim Ingham private: 743cb2380c9SRaphael Isemann bool GetDefaultFile(Target &target, FileSpec &file, 744b9c1b51eSKate Stone CommandReturnObject &result) { 7455a988416SJim Ingham uint32_t default_line; 74605097246SAdrian Prantl // First use the Source Manager's default file. Then use the current stack 74705097246SAdrian Prantl // frame's file. 748cb2380c9SRaphael Isemann if (!target.GetSourceManager().GetDefaultFileAndLine(file, default_line)) { 749b57e4a1bSJason Molenda StackFrame *cur_frame = m_exe_ctx.GetFramePtr(); 750b9c1b51eSKate Stone if (cur_frame == nullptr) { 751b9c1b51eSKate Stone result.AppendError( 752b9c1b51eSKate Stone "No selected frame to use to find the default file."); 7535a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 7545a988416SJim Ingham return false; 755b9c1b51eSKate Stone } else if (!cur_frame->HasDebugInformation()) { 756b9c1b51eSKate Stone result.AppendError("Cannot use the selected frame to find the default " 757b9c1b51eSKate Stone "file, it has no debug info."); 7585a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 7595a988416SJim Ingham return false; 760b9c1b51eSKate Stone } else { 761b9c1b51eSKate Stone const SymbolContext &sc = 762b9c1b51eSKate Stone cur_frame->GetSymbolContext(eSymbolContextLineEntry); 763b9c1b51eSKate Stone if (sc.line_entry.file) { 7645a988416SJim Ingham file = sc.line_entry.file; 765b9c1b51eSKate Stone } else { 766b9c1b51eSKate Stone result.AppendError("Can't find the file for the selected frame to " 767b9c1b51eSKate Stone "use as the default file."); 7685a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 7695a988416SJim Ingham return false; 7705a988416SJim Ingham } 7715a988416SJim Ingham } 7725a988416SJim Ingham } 7735a988416SJim Ingham return true; 7745a988416SJim Ingham } 7755a988416SJim Ingham 776b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 777b842f2ecSJim Ingham BreakpointDummyOptionGroup m_dummy_options; 778943a2481SJim Ingham OptionGroupPythonClassWithDict m_python_class_options; 7795a988416SJim Ingham CommandOptions m_options; 780b842f2ecSJim Ingham OptionGroupOptions m_all_options; 7815a988416SJim Ingham }; 7829e85e5a8SEugene Zelenko 7835a988416SJim Ingham // CommandObjectBreakpointModify 7845a988416SJim Ingham #pragma mark Modify 7855a988416SJim Ingham 786b9c1b51eSKate Stone class CommandObjectBreakpointModify : public CommandObjectParsed { 7875a988416SJim Ingham public: 788b9c1b51eSKate Stone CommandObjectBreakpointModify(CommandInterpreter &interpreter) 789b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "breakpoint modify", 790b9c1b51eSKate Stone "Modify the options on a breakpoint or set of " 791b9c1b51eSKate Stone "breakpoints in the executable. " 792b9c1b51eSKate Stone "If no breakpoint is specified, acts on the last " 793b9c1b51eSKate Stone "created breakpoint. " 794b9c1b51eSKate Stone "With the exception of -e, -d and -i, passing an " 795b9c1b51eSKate Stone "empty argument clears the modification.", 7969e85e5a8SEugene Zelenko nullptr), 797b9c1b51eSKate Stone m_options() { 7985a988416SJim Ingham CommandArgumentEntry arg; 799b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 800b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 801b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 802b9c1b51eSKate Stone // arguments vector. 8035a988416SJim Ingham m_arguments.push_back(arg); 804b842f2ecSJim Ingham 805b842f2ecSJim Ingham m_options.Append(&m_bp_opts, 806b842f2ecSJim Ingham LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3, 807b842f2ecSJim Ingham LLDB_OPT_SET_ALL); 808b842f2ecSJim Ingham m_options.Append(&m_dummy_opts, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 809b842f2ecSJim Ingham m_options.Finalize(); 8105a988416SJim Ingham } 8115a988416SJim Ingham 8129e85e5a8SEugene Zelenko ~CommandObjectBreakpointModify() override = default; 8135a988416SJim Ingham 814b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 8155a988416SJim Ingham 8165a988416SJim Ingham protected: 817b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 818cb2380c9SRaphael Isemann Target &target = GetSelectedOrDummyTarget(m_dummy_opts.m_use_dummy); 8195a988416SJim Ingham 820bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 821cb2380c9SRaphael Isemann target.GetBreakpointList().GetListMutex(lock); 8225a988416SJim Ingham 8235a988416SJim Ingham BreakpointIDList valid_bp_ids; 8245a988416SJim Ingham 825b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 826cb2380c9SRaphael Isemann command, &target, result, &valid_bp_ids, 827b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 8285a988416SJim Ingham 829b9c1b51eSKate Stone if (result.Succeeded()) { 8305a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 831b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 8325a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 8335a988416SJim Ingham 834b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 835b9c1b51eSKate Stone Breakpoint *bp = 836cb2380c9SRaphael Isemann target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 837b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 838b9c1b51eSKate Stone BreakpointLocation *location = 839b9c1b51eSKate Stone bp->FindLocationByID(cur_bp_id.GetLocationID()).get(); 840b842f2ecSJim Ingham if (location) 841a925974bSAdrian Prantl location->GetLocationOptions()->CopyOverSetOptions( 842a925974bSAdrian Prantl m_bp_opts.GetBreakpointOptions()); 843b9c1b51eSKate Stone } else { 844a925974bSAdrian Prantl bp->GetOptions()->CopyOverSetOptions( 845a925974bSAdrian Prantl m_bp_opts.GetBreakpointOptions()); 8465a988416SJim Ingham } 8475a988416SJim Ingham } 8485a988416SJim Ingham } 8495a988416SJim Ingham } 8505a988416SJim Ingham 8515a988416SJim Ingham return result.Succeeded(); 8525a988416SJim Ingham } 8535a988416SJim Ingham 8545a988416SJim Ingham private: 855b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 856b842f2ecSJim Ingham BreakpointDummyOptionGroup m_dummy_opts; 857b842f2ecSJim Ingham OptionGroupOptions m_options; 8585a988416SJim Ingham }; 8595a988416SJim Ingham 8605a988416SJim Ingham // CommandObjectBreakpointEnable 8615a988416SJim Ingham #pragma mark Enable 8625a988416SJim Ingham 863b9c1b51eSKate Stone class CommandObjectBreakpointEnable : public CommandObjectParsed { 8645a988416SJim Ingham public: 865b9c1b51eSKate Stone CommandObjectBreakpointEnable(CommandInterpreter &interpreter) 866b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "enable", 867b9c1b51eSKate Stone "Enable the specified disabled breakpoint(s). If " 868b9c1b51eSKate Stone "no breakpoints are specified, enable all of them.", 869b9c1b51eSKate Stone nullptr) { 8705a988416SJim Ingham CommandArgumentEntry arg; 871b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 872b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 873b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 874b9c1b51eSKate Stone // arguments vector. 8755a988416SJim Ingham m_arguments.push_back(arg); 8765a988416SJim Ingham } 8775a988416SJim Ingham 8789e85e5a8SEugene Zelenko ~CommandObjectBreakpointEnable() override = default; 8795a988416SJim Ingham 8805a988416SJim Ingham protected: 881b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 882cb2380c9SRaphael Isemann Target &target = GetSelectedOrDummyTarget(); 8835a988416SJim Ingham 884bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 885cb2380c9SRaphael Isemann target.GetBreakpointList().GetListMutex(lock); 8865a988416SJim Ingham 887cb2380c9SRaphael Isemann const BreakpointList &breakpoints = target.GetBreakpointList(); 8885a988416SJim Ingham 8895a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 8905a988416SJim Ingham 891b9c1b51eSKate Stone if (num_breakpoints == 0) { 8925a988416SJim Ingham result.AppendError("No breakpoints exist to be enabled."); 8935a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 8945a988416SJim Ingham return false; 8955a988416SJim Ingham } 8965a988416SJim Ingham 89711eb9c64SZachary Turner if (command.empty()) { 8985a988416SJim Ingham // No breakpoint selected; enable all currently set breakpoints. 899cb2380c9SRaphael Isemann target.EnableAllowedBreakpoints(); 900b9c1b51eSKate Stone result.AppendMessageWithFormat("All breakpoints enabled. (%" PRIu64 901b9c1b51eSKate Stone " breakpoints)\n", 902b9c1b51eSKate Stone (uint64_t)num_breakpoints); 9035a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 904b9c1b51eSKate Stone } else { 9055a988416SJim Ingham // Particular breakpoint selected; enable that breakpoint. 9065a988416SJim Ingham BreakpointIDList valid_bp_ids; 907b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 908cb2380c9SRaphael Isemann command, &target, result, &valid_bp_ids, 909b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 9105a988416SJim Ingham 911b9c1b51eSKate Stone if (result.Succeeded()) { 9125a988416SJim Ingham int enable_count = 0; 9135a988416SJim Ingham int loc_count = 0; 9145a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 915b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 9165a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 9175a988416SJim Ingham 918b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 919b9c1b51eSKate Stone Breakpoint *breakpoint = 920cb2380c9SRaphael Isemann target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 921b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 922b9c1b51eSKate Stone BreakpointLocation *location = 923b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 924b9c1b51eSKate Stone if (location) { 9255a988416SJim Ingham location->SetEnabled(true); 9265a988416SJim Ingham ++loc_count; 9275a988416SJim Ingham } 928b9c1b51eSKate Stone } else { 9295a988416SJim Ingham breakpoint->SetEnabled(true); 9305a988416SJim Ingham ++enable_count; 9315a988416SJim Ingham } 9325a988416SJim Ingham } 9335a988416SJim Ingham } 934b9c1b51eSKate Stone result.AppendMessageWithFormat("%d breakpoints enabled.\n", 935b9c1b51eSKate Stone enable_count + loc_count); 9365a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 9375a988416SJim Ingham } 9385a988416SJim Ingham } 9395a988416SJim Ingham 9405a988416SJim Ingham return result.Succeeded(); 9415a988416SJim Ingham } 9425a988416SJim Ingham }; 9435a988416SJim Ingham 9445a988416SJim Ingham // CommandObjectBreakpointDisable 9455a988416SJim Ingham #pragma mark Disable 9465a988416SJim Ingham 947b9c1b51eSKate Stone class CommandObjectBreakpointDisable : public CommandObjectParsed { 9485a988416SJim Ingham public: 9497428a18cSKate Stone CommandObjectBreakpointDisable(CommandInterpreter &interpreter) 950b9c1b51eSKate Stone : CommandObjectParsed( 951b9c1b51eSKate Stone interpreter, "breakpoint disable", 952b9c1b51eSKate Stone "Disable the specified breakpoint(s) without deleting " 9537428a18cSKate Stone "them. If none are specified, disable all " 9547428a18cSKate Stone "breakpoints.", 955b9c1b51eSKate Stone nullptr) { 956b9c1b51eSKate Stone SetHelpLong( 957b9c1b51eSKate Stone "Disable the specified breakpoint(s) without deleting them. \ 9587428a18cSKate Stone If none are specified, disable all breakpoints." 9597428a18cSKate Stone R"( 960ea671fbdSKate Stone 9617428a18cSKate Stone )" 9627428a18cSKate Stone "Note: disabling a breakpoint will cause none of its locations to be hit \ 9637428a18cSKate Stone regardless of whether individual locations are enabled or disabled. After the sequence:" 9647428a18cSKate Stone R"( 965ea671fbdSKate Stone 966ea671fbdSKate Stone (lldb) break disable 1 967ea671fbdSKate Stone (lldb) break enable 1.1 968ea671fbdSKate Stone 969ea671fbdSKate Stone execution will NOT stop at location 1.1. To achieve that, type: 970ea671fbdSKate Stone 971ea671fbdSKate Stone (lldb) break disable 1.* 972ea671fbdSKate Stone (lldb) break enable 1.1 973ea671fbdSKate Stone 9747428a18cSKate Stone )" 9757428a18cSKate Stone "The first command disables all locations for breakpoint 1, \ 9767428a18cSKate Stone the second re-enables the first location."); 977b0fac509SJim Ingham 9785a988416SJim Ingham CommandArgumentEntry arg; 979b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 980b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 981b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 982b9c1b51eSKate Stone // arguments vector. 9835a988416SJim Ingham m_arguments.push_back(arg); 9845a988416SJim Ingham } 9855a988416SJim Ingham 9869e85e5a8SEugene Zelenko ~CommandObjectBreakpointDisable() override = default; 9875a988416SJim Ingham 9885a988416SJim Ingham protected: 989b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 990cb2380c9SRaphael Isemann Target &target = GetSelectedOrDummyTarget(); 991bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 992cb2380c9SRaphael Isemann target.GetBreakpointList().GetListMutex(lock); 9935a988416SJim Ingham 994cb2380c9SRaphael Isemann const BreakpointList &breakpoints = target.GetBreakpointList(); 9955a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 9965a988416SJim Ingham 997b9c1b51eSKate Stone if (num_breakpoints == 0) { 9985a988416SJim Ingham result.AppendError("No breakpoints exist to be disabled."); 9995a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 10005a988416SJim Ingham return false; 10015a988416SJim Ingham } 10025a988416SJim Ingham 100311eb9c64SZachary Turner if (command.empty()) { 10045a988416SJim Ingham // No breakpoint selected; disable all currently set breakpoints. 1005cb2380c9SRaphael Isemann target.DisableAllowedBreakpoints(); 1006b9c1b51eSKate Stone result.AppendMessageWithFormat("All breakpoints disabled. (%" PRIu64 1007b9c1b51eSKate Stone " breakpoints)\n", 1008b9c1b51eSKate Stone (uint64_t)num_breakpoints); 10095a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1010b9c1b51eSKate Stone } else { 10115a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 10125a988416SJim Ingham BreakpointIDList valid_bp_ids; 10135a988416SJim Ingham 1014b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1015cb2380c9SRaphael Isemann command, &target, result, &valid_bp_ids, 1016b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 10175a988416SJim Ingham 1018b9c1b51eSKate Stone if (result.Succeeded()) { 10195a988416SJim Ingham int disable_count = 0; 10205a988416SJim Ingham int loc_count = 0; 10215a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1022b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 10235a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 10245a988416SJim Ingham 1025b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1026b9c1b51eSKate Stone Breakpoint *breakpoint = 1027cb2380c9SRaphael Isemann target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1028b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1029b9c1b51eSKate Stone BreakpointLocation *location = 1030b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1031b9c1b51eSKate Stone if (location) { 10325a988416SJim Ingham location->SetEnabled(false); 10335a988416SJim Ingham ++loc_count; 10345a988416SJim Ingham } 1035b9c1b51eSKate Stone } else { 10365a988416SJim Ingham breakpoint->SetEnabled(false); 10375a988416SJim Ingham ++disable_count; 10385a988416SJim Ingham } 10395a988416SJim Ingham } 10405a988416SJim Ingham } 1041b9c1b51eSKate Stone result.AppendMessageWithFormat("%d breakpoints disabled.\n", 1042b9c1b51eSKate Stone disable_count + loc_count); 10435a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 10445a988416SJim Ingham } 10455a988416SJim Ingham } 10465a988416SJim Ingham 10475a988416SJim Ingham return result.Succeeded(); 10485a988416SJim Ingham } 10495a988416SJim Ingham }; 10505a988416SJim Ingham 10515a988416SJim Ingham // CommandObjectBreakpointList 10521f0f5b5bSZachary Turner 10531f0f5b5bSZachary Turner #pragma mark List::CommandOptions 10546f4fb4e7SRaphael Isemann #define LLDB_OPTIONS_breakpoint_list 1055c5a2d747SRaphael Isemann #include "CommandOptions.inc" 10561f0f5b5bSZachary Turner 10575a988416SJim Ingham #pragma mark List 10585a988416SJim Ingham 1059b9c1b51eSKate Stone class CommandObjectBreakpointList : public CommandObjectParsed { 10605a988416SJim Ingham public: 1061b9c1b51eSKate Stone CommandObjectBreakpointList(CommandInterpreter &interpreter) 1062b9c1b51eSKate Stone : CommandObjectParsed( 1063b9c1b51eSKate Stone interpreter, "breakpoint list", 10645a988416SJim Ingham "List some or all breakpoints at configurable levels of detail.", 10659e85e5a8SEugene Zelenko nullptr), 1066b9c1b51eSKate Stone m_options() { 10675a988416SJim Ingham CommandArgumentEntry arg; 10685a988416SJim Ingham CommandArgumentData bp_id_arg; 10695a988416SJim Ingham 10705a988416SJim Ingham // Define the first (and only) variant of this arg. 10715a988416SJim Ingham bp_id_arg.arg_type = eArgTypeBreakpointID; 10725a988416SJim Ingham bp_id_arg.arg_repetition = eArgRepeatOptional; 10735a988416SJim Ingham 1074b9c1b51eSKate Stone // There is only one variant this argument could be; put it into the 1075b9c1b51eSKate Stone // argument entry. 10765a988416SJim Ingham arg.push_back(bp_id_arg); 10775a988416SJim Ingham 10785a988416SJim Ingham // Push the data for the first argument into the m_arguments vector. 10795a988416SJim Ingham m_arguments.push_back(arg); 10805a988416SJim Ingham } 10815a988416SJim Ingham 10829e85e5a8SEugene Zelenko ~CommandObjectBreakpointList() override = default; 10835a988416SJim Ingham 1084b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 10855a988416SJim Ingham 1086b9c1b51eSKate Stone class CommandOptions : public Options { 10875a988416SJim Ingham public: 1088b9c1b51eSKate Stone CommandOptions() 1089b9c1b51eSKate Stone : Options(), m_level(lldb::eDescriptionLevelBrief), m_use_dummy(false) { 10905a988416SJim Ingham } 10915a988416SJim Ingham 10929e85e5a8SEugene Zelenko ~CommandOptions() override = default; 10935a988416SJim Ingham 109497206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1095b9c1b51eSKate Stone ExecutionContext *execution_context) override { 109697206d57SZachary Turner Status error; 10973bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 10985a988416SJim Ingham 1099b9c1b51eSKate Stone switch (short_option) { 11005a988416SJim Ingham case 'b': 11015a988416SJim Ingham m_level = lldb::eDescriptionLevelBrief; 11025a988416SJim Ingham break; 110333df7cd3SJim Ingham case 'D': 110433df7cd3SJim Ingham m_use_dummy = true; 110533df7cd3SJim Ingham break; 11065a988416SJim Ingham case 'f': 11075a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 11085a988416SJim Ingham break; 11095a988416SJim Ingham case 'v': 11105a988416SJim Ingham m_level = lldb::eDescriptionLevelVerbose; 11115a988416SJim Ingham break; 11125a988416SJim Ingham case 'i': 11135a988416SJim Ingham m_internal = true; 11145a988416SJim Ingham break; 11155a988416SJim Ingham default: 111636162014SRaphael Isemann llvm_unreachable("Unimplemented option"); 11175a988416SJim Ingham } 11185a988416SJim Ingham 11195a988416SJim Ingham return error; 11205a988416SJim Ingham } 11215a988416SJim Ingham 1122b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 11235a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 11245a988416SJim Ingham m_internal = false; 112533df7cd3SJim Ingham m_use_dummy = false; 11265a988416SJim Ingham } 11275a988416SJim Ingham 11281f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 112970602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_list_options); 11301f0f5b5bSZachary Turner } 11315a988416SJim Ingham 11325a988416SJim Ingham // Instance variables to hold the values for command options. 11335a988416SJim Ingham 11345a988416SJim Ingham lldb::DescriptionLevel m_level; 11355a988416SJim Ingham 11365a988416SJim Ingham bool m_internal; 113733df7cd3SJim Ingham bool m_use_dummy; 11385a988416SJim Ingham }; 11395a988416SJim Ingham 11405a988416SJim Ingham protected: 1141b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1142cb2380c9SRaphael Isemann Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 11435a988416SJim Ingham 1144b9c1b51eSKate Stone const BreakpointList &breakpoints = 1145cb2380c9SRaphael Isemann target.GetBreakpointList(m_options.m_internal); 1146bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1147cb2380c9SRaphael Isemann target.GetBreakpointList(m_options.m_internal).GetListMutex(lock); 11485a988416SJim Ingham 11495a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 11505a988416SJim Ingham 1151b9c1b51eSKate Stone if (num_breakpoints == 0) { 11525a988416SJim Ingham result.AppendMessage("No breakpoints currently set."); 11535a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 11545a988416SJim Ingham return true; 11555a988416SJim Ingham } 11565a988416SJim Ingham 11575a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 11585a988416SJim Ingham 115911eb9c64SZachary Turner if (command.empty()) { 11605a988416SJim Ingham // No breakpoint selected; show info about all currently set breakpoints. 11615a988416SJim Ingham result.AppendMessage("Current breakpoints:"); 1162b9c1b51eSKate Stone for (size_t i = 0; i < num_breakpoints; ++i) { 11635a988416SJim Ingham Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex(i).get(); 1164b842f2ecSJim Ingham if (breakpoint->AllowList()) 1165b842f2ecSJim Ingham AddBreakpointDescription(&output_stream, breakpoint, 1166b842f2ecSJim Ingham m_options.m_level); 11675a988416SJim Ingham } 11685a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1169b9c1b51eSKate Stone } else { 11705a988416SJim Ingham // Particular breakpoints selected; show info about that breakpoint. 11715a988416SJim Ingham BreakpointIDList valid_bp_ids; 1172b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1173cb2380c9SRaphael Isemann command, &target, result, &valid_bp_ids, 1174b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 11755a988416SJim Ingham 1176b9c1b51eSKate Stone if (result.Succeeded()) { 1177b9c1b51eSKate Stone for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) { 11785a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 1179b9c1b51eSKate Stone Breakpoint *breakpoint = 1180cb2380c9SRaphael Isemann target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1181b9c1b51eSKate Stone AddBreakpointDescription(&output_stream, breakpoint, 1182b9c1b51eSKate Stone m_options.m_level); 11835a988416SJim Ingham } 11845a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1185b9c1b51eSKate Stone } else { 11867428a18cSKate Stone result.AppendError("Invalid breakpoint ID."); 11875a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 11885a988416SJim Ingham } 11895a988416SJim Ingham } 11905a988416SJim Ingham 11915a988416SJim Ingham return result.Succeeded(); 11925a988416SJim Ingham } 11935a988416SJim Ingham 11945a988416SJim Ingham private: 11955a988416SJim Ingham CommandOptions m_options; 11965a988416SJim Ingham }; 11975a988416SJim Ingham 11985a988416SJim Ingham // CommandObjectBreakpointClear 11991f0f5b5bSZachary Turner #pragma mark Clear::CommandOptions 12001f0f5b5bSZachary Turner 1201f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_clear 1202f94668e3SRaphael Isemann #include "CommandOptions.inc" 12031f0f5b5bSZachary Turner 12045a988416SJim Ingham #pragma mark Clear 12055a988416SJim Ingham 1206b9c1b51eSKate Stone class CommandObjectBreakpointClear : public CommandObjectParsed { 12075a988416SJim Ingham public: 1208efe8e7e3SFangrui Song enum BreakpointClearType { eClearTypeInvalid, eClearTypeFileAndLine }; 12095a988416SJim Ingham 12107428a18cSKate Stone CommandObjectBreakpointClear(CommandInterpreter &interpreter) 12117428a18cSKate Stone : CommandObjectParsed(interpreter, "breakpoint clear", 1212b9c1b51eSKate Stone "Delete or disable breakpoints matching the " 1213b9c1b51eSKate Stone "specified source file and line.", 12145a988416SJim Ingham "breakpoint clear <cmd-options>"), 1215b9c1b51eSKate Stone m_options() {} 12165a988416SJim Ingham 12179e85e5a8SEugene Zelenko ~CommandObjectBreakpointClear() override = default; 12185a988416SJim Ingham 1219b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 12205a988416SJim Ingham 1221b9c1b51eSKate Stone class CommandOptions : public Options { 12225a988416SJim Ingham public: 1223b9c1b51eSKate Stone CommandOptions() : Options(), m_filename(), m_line_num(0) {} 12245a988416SJim Ingham 12259e85e5a8SEugene Zelenko ~CommandOptions() override = default; 12265a988416SJim Ingham 122797206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1228b9c1b51eSKate Stone ExecutionContext *execution_context) override { 122997206d57SZachary Turner Status error; 12303bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 12315a988416SJim Ingham 1232b9c1b51eSKate Stone switch (short_option) { 12335a988416SJim Ingham case 'f': 1234adcd0268SBenjamin Kramer m_filename.assign(std::string(option_arg)); 12355a988416SJim Ingham break; 12365a988416SJim Ingham 12375a988416SJim Ingham case 'l': 1238fe11483bSZachary Turner option_arg.getAsInteger(0, m_line_num); 12395a988416SJim Ingham break; 12405a988416SJim Ingham 12415a988416SJim Ingham default: 124236162014SRaphael Isemann llvm_unreachable("Unimplemented option"); 12435a988416SJim Ingham } 12445a988416SJim Ingham 12455a988416SJim Ingham return error; 12465a988416SJim Ingham } 12475a988416SJim Ingham 1248b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 12495a988416SJim Ingham m_filename.clear(); 12505a988416SJim Ingham m_line_num = 0; 12515a988416SJim Ingham } 12525a988416SJim Ingham 12531f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 125470602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_clear_options); 12551f0f5b5bSZachary Turner } 12565a988416SJim Ingham 12575a988416SJim Ingham // Instance variables to hold the values for command options. 12585a988416SJim Ingham 12595a988416SJim Ingham std::string m_filename; 12605a988416SJim Ingham uint32_t m_line_num; 12615a988416SJim Ingham }; 12625a988416SJim Ingham 12635a988416SJim Ingham protected: 1264b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1265cb2380c9SRaphael Isemann Target &target = GetSelectedOrDummyTarget(); 12665a988416SJim Ingham 126705097246SAdrian Prantl // The following are the various types of breakpoints that could be 126805097246SAdrian Prantl // cleared: 12695a988416SJim Ingham // 1). -f -l (clearing breakpoint by source location) 12705a988416SJim Ingham 12715a988416SJim Ingham BreakpointClearType break_type = eClearTypeInvalid; 12725a988416SJim Ingham 12735a988416SJim Ingham if (m_options.m_line_num != 0) 12745a988416SJim Ingham break_type = eClearTypeFileAndLine; 12755a988416SJim Ingham 1276bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1277cb2380c9SRaphael Isemann target.GetBreakpointList().GetListMutex(lock); 12785a988416SJim Ingham 1279cb2380c9SRaphael Isemann BreakpointList &breakpoints = target.GetBreakpointList(); 12805a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 12815a988416SJim Ingham 12825a988416SJim Ingham // Early return if there's no breakpoint at all. 1283b9c1b51eSKate Stone if (num_breakpoints == 0) { 12845a988416SJim Ingham result.AppendError("Breakpoint clear: No breakpoint cleared."); 12855a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 12865a988416SJim Ingham return result.Succeeded(); 12875a988416SJim Ingham } 12885a988416SJim Ingham 12895a988416SJim Ingham // Find matching breakpoints and delete them. 12905a988416SJim Ingham 12915a988416SJim Ingham // First create a copy of all the IDs. 12925a988416SJim Ingham std::vector<break_id_t> BreakIDs; 12935a988416SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) 12949e85e5a8SEugene Zelenko BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID()); 12955a988416SJim Ingham 12965a988416SJim Ingham int num_cleared = 0; 12975a988416SJim Ingham StreamString ss; 1298b9c1b51eSKate Stone switch (break_type) { 12995a988416SJim Ingham case eClearTypeFileAndLine: // Breakpoint by source position 13005a988416SJim Ingham { 13015a988416SJim Ingham const ConstString filename(m_options.m_filename.c_str()); 13025a988416SJim Ingham BreakpointLocationCollection loc_coll; 13035a988416SJim Ingham 1304b9c1b51eSKate Stone for (size_t i = 0; i < num_breakpoints; ++i) { 13055a988416SJim Ingham Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); 13065a988416SJim Ingham 1307b9c1b51eSKate Stone if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) { 1308b9c1b51eSKate Stone // If the collection size is 0, it's a full match and we can just 1309b9c1b51eSKate Stone // remove the breakpoint. 1310b9c1b51eSKate Stone if (loc_coll.GetSize() == 0) { 13115a988416SJim Ingham bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); 13125a988416SJim Ingham ss.EOL(); 1313cb2380c9SRaphael Isemann target.RemoveBreakpointByID(bp->GetID()); 13145a988416SJim Ingham ++num_cleared; 13155a988416SJim Ingham } 13165a988416SJim Ingham } 13175a988416SJim Ingham } 1318b9c1b51eSKate Stone } break; 13195a988416SJim Ingham 13205a988416SJim Ingham default: 13215a988416SJim Ingham break; 13225a988416SJim Ingham } 13235a988416SJim Ingham 1324b9c1b51eSKate Stone if (num_cleared > 0) { 13255a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 13265a988416SJim Ingham output_stream.Printf("%d breakpoints cleared:\n", num_cleared); 1327c156427dSZachary Turner output_stream << ss.GetString(); 13285a988416SJim Ingham output_stream.EOL(); 13295a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1330b9c1b51eSKate Stone } else { 13315a988416SJim Ingham result.AppendError("Breakpoint clear: No breakpoint cleared."); 13325a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 13335a988416SJim Ingham } 13345a988416SJim Ingham 13355a988416SJim Ingham return result.Succeeded(); 13365a988416SJim Ingham } 13375a988416SJim Ingham 13385a988416SJim Ingham private: 13395a988416SJim Ingham CommandOptions m_options; 13405a988416SJim Ingham }; 13415a988416SJim Ingham 13425a988416SJim Ingham // CommandObjectBreakpointDelete 1343f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_delete 1344f94668e3SRaphael Isemann #include "CommandOptions.inc" 13451f0f5b5bSZachary Turner 13465a988416SJim Ingham #pragma mark Delete 13475a988416SJim Ingham 1348b9c1b51eSKate Stone class CommandObjectBreakpointDelete : public CommandObjectParsed { 13495a988416SJim Ingham public: 1350b9c1b51eSKate Stone CommandObjectBreakpointDelete(CommandInterpreter &interpreter) 1351b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "breakpoint delete", 1352b9c1b51eSKate Stone "Delete the specified breakpoint(s). If no " 1353b9c1b51eSKate Stone "breakpoints are specified, delete them all.", 13549e85e5a8SEugene Zelenko nullptr), 1355b9c1b51eSKate Stone m_options() { 13565a988416SJim Ingham CommandArgumentEntry arg; 1357b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1358b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1359b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1360b9c1b51eSKate Stone // arguments vector. 13615a988416SJim Ingham m_arguments.push_back(arg); 13625a988416SJim Ingham } 13635a988416SJim Ingham 13649e85e5a8SEugene Zelenko ~CommandObjectBreakpointDelete() override = default; 13655a988416SJim Ingham 1366b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 136733df7cd3SJim Ingham 1368b9c1b51eSKate Stone class CommandOptions : public Options { 136933df7cd3SJim Ingham public: 1370b9c1b51eSKate Stone CommandOptions() : Options(), m_use_dummy(false), m_force(false) {} 137133df7cd3SJim Ingham 13729e85e5a8SEugene Zelenko ~CommandOptions() override = default; 137333df7cd3SJim Ingham 137497206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1375b9c1b51eSKate Stone ExecutionContext *execution_context) override { 137697206d57SZachary Turner Status error; 137733df7cd3SJim Ingham const int short_option = m_getopt_table[option_idx].val; 137833df7cd3SJim Ingham 1379b9c1b51eSKate Stone switch (short_option) { 138033df7cd3SJim Ingham case 'f': 138133df7cd3SJim Ingham m_force = true; 138233df7cd3SJim Ingham break; 138333df7cd3SJim Ingham 138433df7cd3SJim Ingham case 'D': 138533df7cd3SJim Ingham m_use_dummy = true; 138633df7cd3SJim Ingham break; 138733df7cd3SJim Ingham 138833df7cd3SJim Ingham default: 138936162014SRaphael Isemann llvm_unreachable("Unimplemented option"); 139033df7cd3SJim Ingham } 139133df7cd3SJim Ingham 139233df7cd3SJim Ingham return error; 139333df7cd3SJim Ingham } 139433df7cd3SJim Ingham 1395b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 139633df7cd3SJim Ingham m_use_dummy = false; 139733df7cd3SJim Ingham m_force = false; 139833df7cd3SJim Ingham } 139933df7cd3SJim Ingham 14001f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 140170602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_delete_options); 14021f0f5b5bSZachary Turner } 140333df7cd3SJim Ingham 140433df7cd3SJim Ingham // Instance variables to hold the values for command options. 140533df7cd3SJim Ingham bool m_use_dummy; 140633df7cd3SJim Ingham bool m_force; 140733df7cd3SJim Ingham }; 140833df7cd3SJim Ingham 14095a988416SJim Ingham protected: 1410b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1411cb2380c9SRaphael Isemann Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 14125a988416SJim Ingham 1413bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1414cb2380c9SRaphael Isemann target.GetBreakpointList().GetListMutex(lock); 14155a988416SJim Ingham 1416cb2380c9SRaphael Isemann const BreakpointList &breakpoints = target.GetBreakpointList(); 14175a988416SJim Ingham 14185a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 14195a988416SJim Ingham 1420b9c1b51eSKate Stone if (num_breakpoints == 0) { 14215a988416SJim Ingham result.AppendError("No breakpoints exist to be deleted."); 14225a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 14235a988416SJim Ingham return false; 14245a988416SJim Ingham } 14255a988416SJim Ingham 142611eb9c64SZachary Turner if (command.empty()) { 1427b9c1b51eSKate Stone if (!m_options.m_force && 1428b9c1b51eSKate Stone !m_interpreter.Confirm( 1429b9c1b51eSKate Stone "About to delete all breakpoints, do you want to do that?", 1430b9c1b51eSKate Stone true)) { 14315a988416SJim Ingham result.AppendMessage("Operation cancelled..."); 1432b9c1b51eSKate Stone } else { 1433cb2380c9SRaphael Isemann target.RemoveAllowedBreakpoints(); 1434b9c1b51eSKate Stone result.AppendMessageWithFormat( 1435b9c1b51eSKate Stone "All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", 1436b9c1b51eSKate Stone (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : ""); 14375a988416SJim Ingham } 14385a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1439b9c1b51eSKate Stone } else { 14405a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 14415a988416SJim Ingham BreakpointIDList valid_bp_ids; 1442b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1443cb2380c9SRaphael Isemann command, &target, result, &valid_bp_ids, 1444b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::deletePerm); 14455a988416SJim Ingham 1446b9c1b51eSKate Stone if (result.Succeeded()) { 14475a988416SJim Ingham int delete_count = 0; 14485a988416SJim Ingham int disable_count = 0; 14495a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1450b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 14515a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 14525a988416SJim Ingham 1453b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1454b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1455b9c1b51eSKate Stone Breakpoint *breakpoint = 1456cb2380c9SRaphael Isemann target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1457b9c1b51eSKate Stone BreakpointLocation *location = 1458b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1459b9c1b51eSKate Stone // It makes no sense to try to delete individual locations, so we 1460b9c1b51eSKate Stone // disable them instead. 1461b9c1b51eSKate Stone if (location) { 14625a988416SJim Ingham location->SetEnabled(false); 14635a988416SJim Ingham ++disable_count; 14645a988416SJim Ingham } 1465b9c1b51eSKate Stone } else { 1466cb2380c9SRaphael Isemann target.RemoveBreakpointByID(cur_bp_id.GetBreakpointID()); 14675a988416SJim Ingham ++delete_count; 14685a988416SJim Ingham } 14695a988416SJim Ingham } 14705a988416SJim Ingham } 1471b9c1b51eSKate Stone result.AppendMessageWithFormat( 1472b9c1b51eSKate Stone "%d breakpoints deleted; %d breakpoint locations disabled.\n", 14735a988416SJim Ingham delete_count, disable_count); 14745a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 14755a988416SJim Ingham } 14765a988416SJim Ingham } 14775a988416SJim Ingham return result.Succeeded(); 14785a988416SJim Ingham } 14799e85e5a8SEugene Zelenko 148033df7cd3SJim Ingham private: 148133df7cd3SJim Ingham CommandOptions m_options; 148233df7cd3SJim Ingham }; 148333df7cd3SJim Ingham 14845e09c8c3SJim Ingham // CommandObjectBreakpointName 1485f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_name 1486f94668e3SRaphael Isemann #include "CommandOptions.inc" 1487bd68a052SRaphael Isemann 1488b9c1b51eSKate Stone class BreakpointNameOptionGroup : public OptionGroup { 14895e09c8c3SJim Ingham public: 1490b9c1b51eSKate Stone BreakpointNameOptionGroup() 1491b9c1b51eSKate Stone : OptionGroup(), m_breakpoint(LLDB_INVALID_BREAK_ID), m_use_dummy(false) { 14925e09c8c3SJim Ingham } 14935e09c8c3SJim Ingham 14949e85e5a8SEugene Zelenko ~BreakpointNameOptionGroup() override = default; 14955e09c8c3SJim Ingham 14961f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 149770602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_name_options); 14985e09c8c3SJim Ingham } 14995e09c8c3SJim Ingham 150097206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1501b9c1b51eSKate Stone ExecutionContext *execution_context) override { 150297206d57SZachary Turner Status error; 15035e09c8c3SJim Ingham const int short_option = g_breakpoint_name_options[option_idx].short_option; 15045e09c8c3SJim Ingham 1505b9c1b51eSKate Stone switch (short_option) { 15065e09c8c3SJim Ingham case 'N': 1507fe11483bSZachary Turner if (BreakpointID::StringIsBreakpointName(option_arg, error) && 1508b9c1b51eSKate Stone error.Success()) 1509fe11483bSZachary Turner m_name.SetValueFromString(option_arg); 15105e09c8c3SJim Ingham break; 15115e09c8c3SJim Ingham case 'B': 1512fe11483bSZachary Turner if (m_breakpoint.SetValueFromString(option_arg).Fail()) 1513b9c1b51eSKate Stone error.SetErrorStringWithFormat( 15148cef4b0bSZachary Turner "unrecognized value \"%s\" for breakpoint", 1515fe11483bSZachary Turner option_arg.str().c_str()); 15165e09c8c3SJim Ingham break; 15175e09c8c3SJim Ingham case 'D': 1518fe11483bSZachary Turner if (m_use_dummy.SetValueFromString(option_arg).Fail()) 1519b9c1b51eSKate Stone error.SetErrorStringWithFormat( 15208cef4b0bSZachary Turner "unrecognized value \"%s\" for use-dummy", 1521fe11483bSZachary Turner option_arg.str().c_str()); 15225e09c8c3SJim Ingham break; 1523e9632ebaSJim Ingham case 'H': 1524e9632ebaSJim Ingham m_help_string.SetValueFromString(option_arg); 1525e9632ebaSJim Ingham break; 15265e09c8c3SJim Ingham 15275e09c8c3SJim Ingham default: 152836162014SRaphael Isemann llvm_unreachable("Unimplemented option"); 15295e09c8c3SJim Ingham } 15305e09c8c3SJim Ingham return error; 15315e09c8c3SJim Ingham } 15325e09c8c3SJim Ingham 1533b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 15345e09c8c3SJim Ingham m_name.Clear(); 15355e09c8c3SJim Ingham m_breakpoint.Clear(); 15365e09c8c3SJim Ingham m_use_dummy.Clear(); 15375e09c8c3SJim Ingham m_use_dummy.SetDefaultValue(false); 1538e9632ebaSJim Ingham m_help_string.Clear(); 15395e09c8c3SJim Ingham } 15405e09c8c3SJim Ingham 15415e09c8c3SJim Ingham OptionValueString m_name; 15425e09c8c3SJim Ingham OptionValueUInt64 m_breakpoint; 15435e09c8c3SJim Ingham OptionValueBoolean m_use_dummy; 1544e9632ebaSJim Ingham OptionValueString m_help_string; 15455e09c8c3SJim Ingham }; 15465e09c8c3SJim Ingham 1547f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_access 1548f94668e3SRaphael Isemann #include "CommandOptions.inc" 1549b842f2ecSJim Ingham 15508fe53c49STatyana Krasnukha class BreakpointAccessOptionGroup : public OptionGroup { 1551b842f2ecSJim Ingham public: 15528fe53c49STatyana Krasnukha BreakpointAccessOptionGroup() : OptionGroup() {} 1553b842f2ecSJim Ingham 1554b842f2ecSJim Ingham ~BreakpointAccessOptionGroup() override = default; 1555b842f2ecSJim Ingham 1556b842f2ecSJim Ingham llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 1557b842f2ecSJim Ingham return llvm::makeArrayRef(g_breakpoint_access_options); 1558b842f2ecSJim Ingham } 1559b842f2ecSJim Ingham Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1560b842f2ecSJim Ingham ExecutionContext *execution_context) override { 1561b842f2ecSJim Ingham Status error; 1562a925974bSAdrian Prantl const int short_option = 1563a925974bSAdrian Prantl g_breakpoint_access_options[option_idx].short_option; 1564b842f2ecSJim Ingham 1565b842f2ecSJim Ingham switch (short_option) { 1566b842f2ecSJim Ingham case 'L': { 1567b842f2ecSJim Ingham bool value, success; 156847cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1569b842f2ecSJim Ingham if (success) { 1570b842f2ecSJim Ingham m_permissions.SetAllowList(value); 1571b842f2ecSJim Ingham } else 1572b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1573b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1574b842f2ecSJim Ingham option_arg.str().c_str()); 1575b842f2ecSJim Ingham } break; 1576b842f2ecSJim Ingham case 'A': { 1577b842f2ecSJim Ingham bool value, success; 157847cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1579b842f2ecSJim Ingham if (success) { 1580b842f2ecSJim Ingham m_permissions.SetAllowDisable(value); 1581b842f2ecSJim Ingham } else 1582b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1583b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1584b842f2ecSJim Ingham option_arg.str().c_str()); 1585b842f2ecSJim Ingham } break; 1586b842f2ecSJim Ingham case 'D': { 1587b842f2ecSJim Ingham bool value, success; 158847cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1589b842f2ecSJim Ingham if (success) { 1590b842f2ecSJim Ingham m_permissions.SetAllowDelete(value); 1591b842f2ecSJim Ingham } else 1592b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1593b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1594b842f2ecSJim Ingham option_arg.str().c_str()); 1595b842f2ecSJim Ingham } break; 159636162014SRaphael Isemann default: 159736162014SRaphael Isemann llvm_unreachable("Unimplemented option"); 1598b842f2ecSJim Ingham } 1599b842f2ecSJim Ingham 1600b842f2ecSJim Ingham return error; 1601b842f2ecSJim Ingham } 1602b842f2ecSJim Ingham 1603a925974bSAdrian Prantl void OptionParsingStarting(ExecutionContext *execution_context) override {} 1604b842f2ecSJim Ingham 1605a925974bSAdrian Prantl const BreakpointName::Permissions &GetPermissions() const { 1606b842f2ecSJim Ingham return m_permissions; 1607b842f2ecSJim Ingham } 1608b842f2ecSJim Ingham BreakpointName::Permissions m_permissions; 1609b842f2ecSJim Ingham }; 1610b842f2ecSJim Ingham 1611b842f2ecSJim Ingham class CommandObjectBreakpointNameConfigure : public CommandObjectParsed { 1612b842f2ecSJim Ingham public: 1613b842f2ecSJim Ingham CommandObjectBreakpointNameConfigure(CommandInterpreter &interpreter) 1614b842f2ecSJim Ingham : CommandObjectParsed( 1615a925974bSAdrian Prantl interpreter, "configure", 1616a925974bSAdrian Prantl "Configure the options for the breakpoint" 1617b842f2ecSJim Ingham " name provided. " 1618b842f2ecSJim Ingham "If you provide a breakpoint id, the options will be copied from " 1619b842f2ecSJim Ingham "the breakpoint, otherwise only the options specified will be set " 1620b842f2ecSJim Ingham "on the name.", 1621b842f2ecSJim Ingham "breakpoint name configure <command-options> " 1622b842f2ecSJim Ingham "<breakpoint-name-list>"), 1623b842f2ecSJim Ingham m_bp_opts(), m_option_group() { 1624b842f2ecSJim Ingham // Create the first variant for the first (and only) argument for this 1625b842f2ecSJim Ingham // command. 1626b842f2ecSJim Ingham CommandArgumentEntry arg1; 1627b842f2ecSJim Ingham CommandArgumentData id_arg; 1628b842f2ecSJim Ingham id_arg.arg_type = eArgTypeBreakpointName; 1629b842f2ecSJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 1630b842f2ecSJim Ingham arg1.push_back(id_arg); 1631b842f2ecSJim Ingham m_arguments.push_back(arg1); 1632b842f2ecSJim Ingham 1633a925974bSAdrian Prantl m_option_group.Append(&m_bp_opts, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); 1634a925974bSAdrian Prantl m_option_group.Append(&m_access_options, LLDB_OPT_SET_ALL, 1635b842f2ecSJim Ingham LLDB_OPT_SET_ALL); 1636a925974bSAdrian Prantl m_option_group.Append(&m_bp_id, LLDB_OPT_SET_2 | LLDB_OPT_SET_4, 1637e9632ebaSJim Ingham LLDB_OPT_SET_ALL); 1638b842f2ecSJim Ingham m_option_group.Finalize(); 1639b842f2ecSJim Ingham } 1640b842f2ecSJim Ingham 1641b842f2ecSJim Ingham ~CommandObjectBreakpointNameConfigure() override = default; 1642b842f2ecSJim Ingham 1643b842f2ecSJim Ingham Options *GetOptions() override { return &m_option_group; } 1644b842f2ecSJim Ingham 1645b842f2ecSJim Ingham protected: 1646b842f2ecSJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 1647b842f2ecSJim Ingham 1648b842f2ecSJim Ingham const size_t argc = command.GetArgumentCount(); 1649b842f2ecSJim Ingham if (argc == 0) { 1650b842f2ecSJim Ingham result.AppendError("No names provided."); 1651b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1652b842f2ecSJim Ingham return false; 1653b842f2ecSJim Ingham } 1654b842f2ecSJim Ingham 1655cb2380c9SRaphael Isemann Target &target = GetSelectedOrDummyTarget(false); 1656b842f2ecSJim Ingham 1657b842f2ecSJim Ingham std::unique_lock<std::recursive_mutex> lock; 1658cb2380c9SRaphael Isemann target.GetBreakpointList().GetListMutex(lock); 1659b842f2ecSJim Ingham 1660b842f2ecSJim Ingham // Make a pass through first to see that all the names are legal. 1661b842f2ecSJim Ingham for (auto &entry : command.entries()) { 1662b842f2ecSJim Ingham Status error; 1663a925974bSAdrian Prantl if (!BreakpointID::StringIsBreakpointName(entry.ref(), error)) { 1664b842f2ecSJim Ingham result.AppendErrorWithFormat("Invalid breakpoint name: %s - %s", 1665b842f2ecSJim Ingham entry.c_str(), error.AsCString()); 1666b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1667b842f2ecSJim Ingham return false; 1668b842f2ecSJim Ingham } 1669b842f2ecSJim Ingham } 167005097246SAdrian Prantl // Now configure them, we already pre-checked the names so we don't need to 167105097246SAdrian Prantl // check the error: 1672b842f2ecSJim Ingham BreakpointSP bp_sp; 1673a925974bSAdrian Prantl if (m_bp_id.m_breakpoint.OptionWasSet()) { 1674b842f2ecSJim Ingham lldb::break_id_t bp_id = m_bp_id.m_breakpoint.GetUInt64Value(); 1675cb2380c9SRaphael Isemann bp_sp = target.GetBreakpointByID(bp_id); 1676a925974bSAdrian Prantl if (!bp_sp) { 1677b842f2ecSJim Ingham result.AppendErrorWithFormatv("Could not find specified breakpoint {0}", 1678b842f2ecSJim Ingham bp_id); 1679b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1680b842f2ecSJim Ingham return false; 1681b842f2ecSJim Ingham } 1682b842f2ecSJim Ingham } 1683b842f2ecSJim Ingham 1684b842f2ecSJim Ingham Status error; 1685b842f2ecSJim Ingham for (auto &entry : command.entries()) { 1686b842f2ecSJim Ingham ConstString name(entry.c_str()); 1687cb2380c9SRaphael Isemann BreakpointName *bp_name = target.FindBreakpointName(name, true, error); 1688b842f2ecSJim Ingham if (!bp_name) 1689b842f2ecSJim Ingham continue; 1690e9632ebaSJim Ingham if (m_bp_id.m_help_string.OptionWasSet()) 1691e9632ebaSJim Ingham bp_name->SetHelp(m_bp_id.m_help_string.GetStringValue().str().c_str()); 1692e9632ebaSJim Ingham 1693b842f2ecSJim Ingham if (bp_sp) 1694cb2380c9SRaphael Isemann target.ConfigureBreakpointName(*bp_name, *bp_sp->GetOptions(), 1695b842f2ecSJim Ingham m_access_options.GetPermissions()); 1696b842f2ecSJim Ingham else 1697cb2380c9SRaphael Isemann target.ConfigureBreakpointName(*bp_name, 1698b842f2ecSJim Ingham m_bp_opts.GetBreakpointOptions(), 1699b842f2ecSJim Ingham m_access_options.GetPermissions()); 1700b842f2ecSJim Ingham } 1701b842f2ecSJim Ingham return true; 1702b842f2ecSJim Ingham } 1703b842f2ecSJim Ingham 1704b842f2ecSJim Ingham private: 1705b842f2ecSJim Ingham BreakpointNameOptionGroup m_bp_id; // Only using the id part of this. 1706b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 1707b842f2ecSJim Ingham BreakpointAccessOptionGroup m_access_options; 1708b842f2ecSJim Ingham OptionGroupOptions m_option_group; 1709b842f2ecSJim Ingham }; 1710b842f2ecSJim Ingham 1711b9c1b51eSKate Stone class CommandObjectBreakpointNameAdd : public CommandObjectParsed { 17125e09c8c3SJim Ingham public: 1713b9c1b51eSKate Stone CommandObjectBreakpointNameAdd(CommandInterpreter &interpreter) 1714b9c1b51eSKate Stone : CommandObjectParsed( 1715b9c1b51eSKate Stone interpreter, "add", "Add a name to the breakpoints provided.", 17165e09c8c3SJim Ingham "breakpoint name add <command-options> <breakpoint-id-list>"), 1717b9c1b51eSKate Stone m_name_options(), m_option_group() { 1718b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 1719b9c1b51eSKate Stone // command. 17205e09c8c3SJim Ingham CommandArgumentEntry arg1; 17215e09c8c3SJim Ingham CommandArgumentData id_arg; 17225e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 17235e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 17245e09c8c3SJim Ingham arg1.push_back(id_arg); 17255e09c8c3SJim Ingham m_arguments.push_back(arg1); 17265e09c8c3SJim Ingham 17275e09c8c3SJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 17285e09c8c3SJim Ingham m_option_group.Finalize(); 17295e09c8c3SJim Ingham } 17305e09c8c3SJim Ingham 17319e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameAdd() override = default; 17325e09c8c3SJim Ingham 1733b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 17345e09c8c3SJim Ingham 17355e09c8c3SJim Ingham protected: 1736b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1737b9c1b51eSKate Stone if (!m_name_options.m_name.OptionWasSet()) { 17385e09c8c3SJim Ingham result.SetError("No name option provided."); 17395e09c8c3SJim Ingham return false; 17405e09c8c3SJim Ingham } 17415e09c8c3SJim Ingham 1742cb2380c9SRaphael Isemann Target &target = 1743b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 17445e09c8c3SJim Ingham 1745bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1746cb2380c9SRaphael Isemann target.GetBreakpointList().GetListMutex(lock); 17475e09c8c3SJim Ingham 1748cb2380c9SRaphael Isemann const BreakpointList &breakpoints = target.GetBreakpointList(); 17495e09c8c3SJim Ingham 17505e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 1751b9c1b51eSKate Stone if (num_breakpoints == 0) { 17525e09c8c3SJim Ingham result.SetError("No breakpoints, cannot add names."); 17535e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 17545e09c8c3SJim Ingham return false; 17555e09c8c3SJim Ingham } 17565e09c8c3SJim Ingham 17575e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 17585e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 1759b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 1760cb2380c9SRaphael Isemann command, &target, result, &valid_bp_ids, 1761b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 17625e09c8c3SJim Ingham 1763b9c1b51eSKate Stone if (result.Succeeded()) { 1764b9c1b51eSKate Stone if (valid_bp_ids.GetSize() == 0) { 17655e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot add names."); 17665e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 17675e09c8c3SJim Ingham return false; 17685e09c8c3SJim Ingham } 17695e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 1770b842f2ecSJim Ingham const char *bp_name = m_name_options.m_name.GetCurrentValue(); 1771b842f2ecSJim Ingham Status error; // This error reports illegal names, but we've already 1772b842f2ecSJim Ingham // checked that, so we don't need to check it again here. 1773b9c1b51eSKate Stone for (size_t index = 0; index < num_valid_ids; index++) { 1774b9c1b51eSKate Stone lldb::break_id_t bp_id = 1775b9c1b51eSKate Stone valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 17765e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 1777cb2380c9SRaphael Isemann target.AddNameToBreakpoint(bp_sp, bp_name, error); 17785e09c8c3SJim Ingham } 17795e09c8c3SJim Ingham } 17805e09c8c3SJim Ingham 17815e09c8c3SJim Ingham return true; 17825e09c8c3SJim Ingham } 17835e09c8c3SJim Ingham 17845e09c8c3SJim Ingham private: 17855e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 17865e09c8c3SJim Ingham OptionGroupOptions m_option_group; 17875e09c8c3SJim Ingham }; 17885e09c8c3SJim Ingham 1789b9c1b51eSKate Stone class CommandObjectBreakpointNameDelete : public CommandObjectParsed { 17905e09c8c3SJim Ingham public: 1791b9c1b51eSKate Stone CommandObjectBreakpointNameDelete(CommandInterpreter &interpreter) 1792b9c1b51eSKate Stone : CommandObjectParsed( 1793b9c1b51eSKate Stone interpreter, "delete", 17945e09c8c3SJim Ingham "Delete a name from the breakpoints provided.", 17955e09c8c3SJim Ingham "breakpoint name delete <command-options> <breakpoint-id-list>"), 1796b9c1b51eSKate Stone m_name_options(), m_option_group() { 1797b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 1798b9c1b51eSKate Stone // command. 17995e09c8c3SJim Ingham CommandArgumentEntry arg1; 18005e09c8c3SJim Ingham CommandArgumentData id_arg; 18015e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 18025e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 18035e09c8c3SJim Ingham arg1.push_back(id_arg); 18045e09c8c3SJim Ingham m_arguments.push_back(arg1); 18055e09c8c3SJim Ingham 18065e09c8c3SJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 18075e09c8c3SJim Ingham m_option_group.Finalize(); 18085e09c8c3SJim Ingham } 18095e09c8c3SJim Ingham 18109e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameDelete() override = default; 18115e09c8c3SJim Ingham 1812b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 18135e09c8c3SJim Ingham 18145e09c8c3SJim Ingham protected: 1815b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1816b9c1b51eSKate Stone if (!m_name_options.m_name.OptionWasSet()) { 18175e09c8c3SJim Ingham result.SetError("No name option provided."); 18185e09c8c3SJim Ingham return false; 18195e09c8c3SJim Ingham } 18205e09c8c3SJim Ingham 1821cb2380c9SRaphael Isemann Target &target = 1822b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 18235e09c8c3SJim Ingham 1824bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1825cb2380c9SRaphael Isemann target.GetBreakpointList().GetListMutex(lock); 18265e09c8c3SJim Ingham 1827cb2380c9SRaphael Isemann const BreakpointList &breakpoints = target.GetBreakpointList(); 18285e09c8c3SJim Ingham 18295e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 1830b9c1b51eSKate Stone if (num_breakpoints == 0) { 18315e09c8c3SJim Ingham result.SetError("No breakpoints, cannot delete names."); 18325e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 18335e09c8c3SJim Ingham return false; 18345e09c8c3SJim Ingham } 18355e09c8c3SJim Ingham 18365e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 18375e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 1838b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 1839cb2380c9SRaphael Isemann command, &target, result, &valid_bp_ids, 1840b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::deletePerm); 18415e09c8c3SJim Ingham 1842b9c1b51eSKate Stone if (result.Succeeded()) { 1843b9c1b51eSKate Stone if (valid_bp_ids.GetSize() == 0) { 18445e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot delete names."); 18455e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 18465e09c8c3SJim Ingham return false; 18475e09c8c3SJim Ingham } 1848b842f2ecSJim Ingham ConstString bp_name(m_name_options.m_name.GetCurrentValue()); 18495e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 1850b9c1b51eSKate Stone for (size_t index = 0; index < num_valid_ids; index++) { 1851b9c1b51eSKate Stone lldb::break_id_t bp_id = 1852b9c1b51eSKate Stone valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 18535e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 1854cb2380c9SRaphael Isemann target.RemoveNameFromBreakpoint(bp_sp, bp_name); 18555e09c8c3SJim Ingham } 18565e09c8c3SJim Ingham } 18575e09c8c3SJim Ingham 18585e09c8c3SJim Ingham return true; 18595e09c8c3SJim Ingham } 18605e09c8c3SJim Ingham 18615e09c8c3SJim Ingham private: 18625e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 18635e09c8c3SJim Ingham OptionGroupOptions m_option_group; 18645e09c8c3SJim Ingham }; 18655e09c8c3SJim Ingham 1866b9c1b51eSKate Stone class CommandObjectBreakpointNameList : public CommandObjectParsed { 18675e09c8c3SJim Ingham public: 1868b9c1b51eSKate Stone CommandObjectBreakpointNameList(CommandInterpreter &interpreter) 1869b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "list", 1870b842f2ecSJim Ingham "List either the names for a breakpoint or info " 1871b842f2ecSJim Ingham "about a given name. With no arguments, lists all " 1872b842f2ecSJim Ingham "names", 18735e09c8c3SJim Ingham "breakpoint name list <command-options>"), 1874b9c1b51eSKate Stone m_name_options(), m_option_group() { 1875b842f2ecSJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_3, LLDB_OPT_SET_ALL); 18765e09c8c3SJim Ingham m_option_group.Finalize(); 18775e09c8c3SJim Ingham } 18785e09c8c3SJim Ingham 18799e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameList() override = default; 18805e09c8c3SJim Ingham 1881b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 18825e09c8c3SJim Ingham 18835e09c8c3SJim Ingham protected: 1884b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1885cb2380c9SRaphael Isemann Target &target = 1886b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 18875e09c8c3SJim Ingham 1888b842f2ecSJim Ingham std::vector<std::string> name_list; 1889b842f2ecSJim Ingham if (command.empty()) { 1890cb2380c9SRaphael Isemann target.GetBreakpointNames(name_list); 1891b842f2ecSJim Ingham } else { 1892a925974bSAdrian Prantl for (const Args::ArgEntry &arg : command) { 1893b842f2ecSJim Ingham name_list.push_back(arg.c_str()); 1894b842f2ecSJim Ingham } 1895b842f2ecSJim Ingham } 1896b842f2ecSJim Ingham 1897b842f2ecSJim Ingham if (name_list.empty()) { 1898b842f2ecSJim Ingham result.AppendMessage("No breakpoint names found."); 1899b842f2ecSJim Ingham } else { 1900b842f2ecSJim Ingham for (const std::string &name_str : name_list) { 1901b842f2ecSJim Ingham const char *name = name_str.c_str(); 1902b842f2ecSJim Ingham // First print out the options for the name: 1903b842f2ecSJim Ingham Status error; 1904cb2380c9SRaphael Isemann BreakpointName *bp_name = 1905cb2380c9SRaphael Isemann target.FindBreakpointName(ConstString(name), false, error); 1906a925974bSAdrian Prantl if (bp_name) { 1907b842f2ecSJim Ingham StreamString s; 1908b842f2ecSJim Ingham result.AppendMessageWithFormat("Name: %s\n", name); 1909a925974bSAdrian Prantl if (bp_name->GetDescription(&s, eDescriptionLevelFull)) { 1910b842f2ecSJim Ingham result.AppendMessage(s.GetString()); 1911b842f2ecSJim Ingham } 1912b842f2ecSJim Ingham 1913bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1914cb2380c9SRaphael Isemann target.GetBreakpointList().GetListMutex(lock); 19155e09c8c3SJim Ingham 1916cb2380c9SRaphael Isemann BreakpointList &breakpoints = target.GetBreakpointList(); 1917b842f2ecSJim Ingham bool any_set = false; 1918b9c1b51eSKate Stone for (BreakpointSP bp_sp : breakpoints.Breakpoints()) { 1919b9c1b51eSKate Stone if (bp_sp->MatchesName(name)) { 19205e09c8c3SJim Ingham StreamString s; 1921b842f2ecSJim Ingham any_set = true; 19225e09c8c3SJim Ingham bp_sp->GetDescription(&s, eDescriptionLevelBrief); 19235e09c8c3SJim Ingham s.EOL(); 1924c156427dSZachary Turner result.AppendMessage(s.GetString()); 19255e09c8c3SJim Ingham } 19265e09c8c3SJim Ingham } 1927b842f2ecSJim Ingham if (!any_set) 1928b842f2ecSJim Ingham result.AppendMessage("No breakpoints using this name."); 1929b9c1b51eSKate Stone } else { 1930b842f2ecSJim Ingham result.AppendMessageWithFormat("Name: %s not found.\n", name); 19315e09c8c3SJim Ingham } 1932b842f2ecSJim Ingham } 19335e09c8c3SJim Ingham } 19345e09c8c3SJim Ingham return true; 19355e09c8c3SJim Ingham } 19365e09c8c3SJim Ingham 19375e09c8c3SJim Ingham private: 19385e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 19395e09c8c3SJim Ingham OptionGroupOptions m_option_group; 19405e09c8c3SJim Ingham }; 19415e09c8c3SJim Ingham 1942e14dc268SJim Ingham // CommandObjectBreakpointName 1943b9c1b51eSKate Stone class CommandObjectBreakpointName : public CommandObjectMultiword { 19445e09c8c3SJim Ingham public: 19457428a18cSKate Stone CommandObjectBreakpointName(CommandInterpreter &interpreter) 1946b9c1b51eSKate Stone : CommandObjectMultiword( 1947b9c1b51eSKate Stone interpreter, "name", "Commands to manage name tags for breakpoints", 1948b9c1b51eSKate Stone "breakpoint name <subcommand> [<command-options>]") { 1949b9c1b51eSKate Stone CommandObjectSP add_command_object( 1950b9c1b51eSKate Stone new CommandObjectBreakpointNameAdd(interpreter)); 1951b9c1b51eSKate Stone CommandObjectSP delete_command_object( 1952b9c1b51eSKate Stone new CommandObjectBreakpointNameDelete(interpreter)); 1953b9c1b51eSKate Stone CommandObjectSP list_command_object( 1954b9c1b51eSKate Stone new CommandObjectBreakpointNameList(interpreter)); 1955b842f2ecSJim Ingham CommandObjectSP configure_command_object( 1956b842f2ecSJim Ingham new CommandObjectBreakpointNameConfigure(interpreter)); 19575e09c8c3SJim Ingham 19585e09c8c3SJim Ingham LoadSubCommand("add", add_command_object); 19595e09c8c3SJim Ingham LoadSubCommand("delete", delete_command_object); 19605e09c8c3SJim Ingham LoadSubCommand("list", list_command_object); 1961b842f2ecSJim Ingham LoadSubCommand("configure", configure_command_object); 19625e09c8c3SJim Ingham } 19635e09c8c3SJim Ingham 19649e85e5a8SEugene Zelenko ~CommandObjectBreakpointName() override = default; 19655e09c8c3SJim Ingham }; 19665e09c8c3SJim Ingham 1967e14dc268SJim Ingham // CommandObjectBreakpointRead 19683acdf385SJim Ingham #pragma mark Read::CommandOptions 1969f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_read 1970f94668e3SRaphael Isemann #include "CommandOptions.inc" 19711f0f5b5bSZachary Turner 19721f0f5b5bSZachary Turner #pragma mark Read 1973e14dc268SJim Ingham 1974e14dc268SJim Ingham class CommandObjectBreakpointRead : public CommandObjectParsed { 1975e14dc268SJim Ingham public: 1976e14dc268SJim Ingham CommandObjectBreakpointRead(CommandInterpreter &interpreter) 1977e14dc268SJim Ingham : CommandObjectParsed(interpreter, "breakpoint read", 1978e14dc268SJim Ingham "Read and set the breakpoints previously saved to " 1979e14dc268SJim Ingham "a file with \"breakpoint write\". ", 1980e14dc268SJim Ingham nullptr), 1981e14dc268SJim Ingham m_options() { 1982e14dc268SJim Ingham CommandArgumentEntry arg; 1983e14dc268SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1984e14dc268SJim Ingham eArgTypeBreakpointIDRange); 1985e14dc268SJim Ingham // Add the entry for the first argument for this command to the object's 1986e14dc268SJim Ingham // arguments vector. 1987e14dc268SJim Ingham m_arguments.push_back(arg); 1988e14dc268SJim Ingham } 1989e14dc268SJim Ingham 1990e14dc268SJim Ingham ~CommandObjectBreakpointRead() override = default; 1991e14dc268SJim Ingham 1992e14dc268SJim Ingham Options *GetOptions() override { return &m_options; } 1993e14dc268SJim Ingham 1994e14dc268SJim Ingham class CommandOptions : public Options { 1995e14dc268SJim Ingham public: 1996e14dc268SJim Ingham CommandOptions() : Options() {} 1997e14dc268SJim Ingham 1998e14dc268SJim Ingham ~CommandOptions() override = default; 1999e14dc268SJim Ingham 200097206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 2001e14dc268SJim Ingham ExecutionContext *execution_context) override { 200297206d57SZachary Turner Status error; 2003e14dc268SJim Ingham const int short_option = m_getopt_table[option_idx].val; 2004e14dc268SJim Ingham 2005e14dc268SJim Ingham switch (short_option) { 2006e14dc268SJim Ingham case 'f': 2007adcd0268SBenjamin Kramer m_filename.assign(std::string(option_arg)); 2008e14dc268SJim Ingham break; 20093acdf385SJim Ingham case 'N': { 201097206d57SZachary Turner Status name_error; 20113acdf385SJim Ingham if (!BreakpointID::StringIsBreakpointName(llvm::StringRef(option_arg), 20123acdf385SJim Ingham name_error)) { 20133acdf385SJim Ingham error.SetErrorStringWithFormat("Invalid breakpoint name: %s", 20143acdf385SJim Ingham name_error.AsCString()); 20153acdf385SJim Ingham } 2016adcd0268SBenjamin Kramer m_names.push_back(std::string(option_arg)); 20173acdf385SJim Ingham break; 20183acdf385SJim Ingham } 2019e14dc268SJim Ingham default: 202036162014SRaphael Isemann llvm_unreachable("Unimplemented option"); 2021e14dc268SJim Ingham } 2022e14dc268SJim Ingham 2023e14dc268SJim Ingham return error; 2024e14dc268SJim Ingham } 2025e14dc268SJim Ingham 2026e14dc268SJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 2027e14dc268SJim Ingham m_filename.clear(); 20283acdf385SJim Ingham m_names.clear(); 2029e14dc268SJim Ingham } 2030e14dc268SJim Ingham 20311f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 203270602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_read_options); 20331f0f5b5bSZachary Turner } 2034e14dc268SJim Ingham 2035e14dc268SJim Ingham // Instance variables to hold the values for command options. 2036e14dc268SJim Ingham 2037e14dc268SJim Ingham std::string m_filename; 20383acdf385SJim Ingham std::vector<std::string> m_names; 2039e14dc268SJim Ingham }; 2040e14dc268SJim Ingham 2041e14dc268SJim Ingham protected: 2042e14dc268SJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 2043cb2380c9SRaphael Isemann Target &target = GetSelectedOrDummyTarget(); 2044e14dc268SJim Ingham 20453acdf385SJim Ingham std::unique_lock<std::recursive_mutex> lock; 2046cb2380c9SRaphael Isemann target.GetBreakpointList().GetListMutex(lock); 20473acdf385SJim Ingham 20488f3be7a3SJonas Devlieghere FileSpec input_spec(m_options.m_filename); 20498f3be7a3SJonas Devlieghere FileSystem::Instance().Resolve(input_spec); 205001f16664SJim Ingham BreakpointIDList new_bps; 2051cb2380c9SRaphael Isemann Status error = target.CreateBreakpointsFromFile(input_spec, 2052cb2380c9SRaphael Isemann m_options.m_names, new_bps); 2053e14dc268SJim Ingham 2054e14dc268SJim Ingham if (!error.Success()) { 205501f16664SJim Ingham result.AppendError(error.AsCString()); 2056e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 205701f16664SJim Ingham return false; 2058e14dc268SJim Ingham } 20593acdf385SJim Ingham 20603acdf385SJim Ingham Stream &output_stream = result.GetOutputStream(); 20613acdf385SJim Ingham 20623acdf385SJim Ingham size_t num_breakpoints = new_bps.GetSize(); 20633acdf385SJim Ingham if (num_breakpoints == 0) { 20643acdf385SJim Ingham result.AppendMessage("No breakpoints added."); 20653acdf385SJim Ingham } else { 20663acdf385SJim Ingham // No breakpoint selected; show info about all currently set breakpoints. 20673acdf385SJim Ingham result.AppendMessage("New breakpoints:"); 20683acdf385SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) { 20693acdf385SJim Ingham BreakpointID bp_id = new_bps.GetBreakpointIDAtIndex(i); 2070cb2380c9SRaphael Isemann Breakpoint *bp = target.GetBreakpointList() 20713acdf385SJim Ingham .FindBreakpointByID(bp_id.GetBreakpointID()) 20723acdf385SJim Ingham .get(); 20733acdf385SJim Ingham if (bp) 20743acdf385SJim Ingham bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, 20753acdf385SJim Ingham false); 20763acdf385SJim Ingham } 20773acdf385SJim Ingham } 2078e14dc268SJim Ingham return result.Succeeded(); 2079e14dc268SJim Ingham } 2080e14dc268SJim Ingham 2081e14dc268SJim Ingham private: 2082e14dc268SJim Ingham CommandOptions m_options; 2083e14dc268SJim Ingham }; 2084e14dc268SJim Ingham 2085e14dc268SJim Ingham // CommandObjectBreakpointWrite 20861f0f5b5bSZachary Turner #pragma mark Write::CommandOptions 2087f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_write 2088f94668e3SRaphael Isemann #include "CommandOptions.inc" 20891f0f5b5bSZachary Turner 20901f0f5b5bSZachary Turner #pragma mark Write 2091e14dc268SJim Ingham class CommandObjectBreakpointWrite : public CommandObjectParsed { 2092e14dc268SJim Ingham public: 2093e14dc268SJim Ingham CommandObjectBreakpointWrite(CommandInterpreter &interpreter) 2094e14dc268SJim Ingham : CommandObjectParsed(interpreter, "breakpoint write", 2095e14dc268SJim Ingham "Write the breakpoints listed to a file that can " 2096e14dc268SJim Ingham "be read in with \"breakpoint read\". " 2097e14dc268SJim Ingham "If given no arguments, writes all breakpoints.", 2098e14dc268SJim Ingham nullptr), 2099e14dc268SJim Ingham m_options() { 2100e14dc268SJim Ingham CommandArgumentEntry arg; 2101e14dc268SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 2102e14dc268SJim Ingham eArgTypeBreakpointIDRange); 2103e14dc268SJim Ingham // Add the entry for the first argument for this command to the object's 2104e14dc268SJim Ingham // arguments vector. 2105e14dc268SJim Ingham m_arguments.push_back(arg); 2106e14dc268SJim Ingham } 2107e14dc268SJim Ingham 2108e14dc268SJim Ingham ~CommandObjectBreakpointWrite() override = default; 2109e14dc268SJim Ingham 2110e14dc268SJim Ingham Options *GetOptions() override { return &m_options; } 2111e14dc268SJim Ingham 2112e14dc268SJim Ingham class CommandOptions : public Options { 2113e14dc268SJim Ingham public: 2114e14dc268SJim Ingham CommandOptions() : Options() {} 2115e14dc268SJim Ingham 2116e14dc268SJim Ingham ~CommandOptions() override = default; 2117e14dc268SJim Ingham 211897206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 2119e14dc268SJim Ingham ExecutionContext *execution_context) override { 212097206d57SZachary Turner Status error; 2121e14dc268SJim Ingham const int short_option = m_getopt_table[option_idx].val; 2122e14dc268SJim Ingham 2123e14dc268SJim Ingham switch (short_option) { 2124e14dc268SJim Ingham case 'f': 2125adcd0268SBenjamin Kramer m_filename.assign(std::string(option_arg)); 2126e14dc268SJim Ingham break; 21272d3628e1SJim Ingham case 'a': 21282d3628e1SJim Ingham m_append = true; 21292d3628e1SJim Ingham break; 2130e14dc268SJim Ingham default: 213136162014SRaphael Isemann llvm_unreachable("Unimplemented option"); 2132e14dc268SJim Ingham } 2133e14dc268SJim Ingham 2134e14dc268SJim Ingham return error; 2135e14dc268SJim Ingham } 2136e14dc268SJim Ingham 2137e14dc268SJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 2138e14dc268SJim Ingham m_filename.clear(); 21392d3628e1SJim Ingham m_append = false; 2140e14dc268SJim Ingham } 2141e14dc268SJim Ingham 21421f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 214370602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_write_options); 21441f0f5b5bSZachary Turner } 2145e14dc268SJim Ingham 2146e14dc268SJim Ingham // Instance variables to hold the values for command options. 2147e14dc268SJim Ingham 2148e14dc268SJim Ingham std::string m_filename; 21492d3628e1SJim Ingham bool m_append = false; 2150e14dc268SJim Ingham }; 2151e14dc268SJim Ingham 2152e14dc268SJim Ingham protected: 2153e14dc268SJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 2154cb2380c9SRaphael Isemann Target &target = GetSelectedOrDummyTarget(); 2155e14dc268SJim Ingham 2156e14dc268SJim Ingham std::unique_lock<std::recursive_mutex> lock; 2157cb2380c9SRaphael Isemann target.GetBreakpointList().GetListMutex(lock); 2158e14dc268SJim Ingham 2159e14dc268SJim Ingham BreakpointIDList valid_bp_ids; 216011eb9c64SZachary Turner if (!command.empty()) { 2161e14dc268SJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 2162cb2380c9SRaphael Isemann command, &target, result, &valid_bp_ids, 2163b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 2164e14dc268SJim Ingham 216501f16664SJim Ingham if (!result.Succeeded()) { 2166e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2167e14dc268SJim Ingham return false; 2168e14dc268SJim Ingham } 2169e14dc268SJim Ingham } 21708f3be7a3SJonas Devlieghere FileSpec file_spec(m_options.m_filename); 21718f3be7a3SJonas Devlieghere FileSystem::Instance().Resolve(file_spec); 2172cb2380c9SRaphael Isemann Status error = target.SerializeBreakpointsToFile(file_spec, valid_bp_ids, 21738f3be7a3SJonas Devlieghere m_options.m_append); 217401f16664SJim Ingham if (!error.Success()) { 217501f16664SJim Ingham result.AppendErrorWithFormat("error serializing breakpoints: %s.", 217601f16664SJim Ingham error.AsCString()); 217701f16664SJim Ingham result.SetStatus(eReturnStatusFailed); 2178e14dc268SJim Ingham } 2179e14dc268SJim Ingham return result.Succeeded(); 2180e14dc268SJim Ingham } 2181e14dc268SJim Ingham 2182e14dc268SJim Ingham private: 2183e14dc268SJim Ingham CommandOptions m_options; 2184e14dc268SJim Ingham }; 2185e14dc268SJim Ingham 218630fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 2187ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 218830fdc8d8SChris Lattner 2189b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint( 2190b9c1b51eSKate Stone CommandInterpreter &interpreter) 2191b9c1b51eSKate Stone : CommandObjectMultiword( 2192b9c1b51eSKate Stone interpreter, "breakpoint", 21937428a18cSKate Stone "Commands for operating on breakpoints (see 'help b' for shorthand.)", 2194b9c1b51eSKate Stone "breakpoint <subcommand> [<command-options>]") { 2195b9c1b51eSKate Stone CommandObjectSP list_command_object( 2196b9c1b51eSKate Stone new CommandObjectBreakpointList(interpreter)); 2197b9c1b51eSKate Stone CommandObjectSP enable_command_object( 2198b9c1b51eSKate Stone new CommandObjectBreakpointEnable(interpreter)); 2199b9c1b51eSKate Stone CommandObjectSP disable_command_object( 2200b9c1b51eSKate Stone new CommandObjectBreakpointDisable(interpreter)); 2201b9c1b51eSKate Stone CommandObjectSP clear_command_object( 2202b9c1b51eSKate Stone new CommandObjectBreakpointClear(interpreter)); 2203b9c1b51eSKate Stone CommandObjectSP delete_command_object( 2204b9c1b51eSKate Stone new CommandObjectBreakpointDelete(interpreter)); 2205b9c1b51eSKate Stone CommandObjectSP set_command_object( 2206b9c1b51eSKate Stone new CommandObjectBreakpointSet(interpreter)); 2207b9c1b51eSKate Stone CommandObjectSP command_command_object( 2208b9c1b51eSKate Stone new CommandObjectBreakpointCommand(interpreter)); 2209b9c1b51eSKate Stone CommandObjectSP modify_command_object( 2210b9c1b51eSKate Stone new CommandObjectBreakpointModify(interpreter)); 2211b9c1b51eSKate Stone CommandObjectSP name_command_object( 2212b9c1b51eSKate Stone new CommandObjectBreakpointName(interpreter)); 2213e14dc268SJim Ingham CommandObjectSP write_command_object( 2214e14dc268SJim Ingham new CommandObjectBreakpointWrite(interpreter)); 2215e14dc268SJim Ingham CommandObjectSP read_command_object( 2216e14dc268SJim Ingham new CommandObjectBreakpointRead(interpreter)); 221730fdc8d8SChris Lattner 2218b7234e40SJohnny Chen list_command_object->SetCommandName("breakpoint list"); 221930fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 222030fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 2221b7234e40SJohnny Chen clear_command_object->SetCommandName("breakpoint clear"); 2222b7234e40SJohnny Chen delete_command_object->SetCommandName("breakpoint delete"); 2223ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 2224b7234e40SJohnny Chen command_command_object->SetCommandName("breakpoint command"); 2225b7234e40SJohnny Chen modify_command_object->SetCommandName("breakpoint modify"); 22265e09c8c3SJim Ingham name_command_object->SetCommandName("breakpoint name"); 2227e14dc268SJim Ingham write_command_object->SetCommandName("breakpoint write"); 2228e14dc268SJim Ingham read_command_object->SetCommandName("breakpoint read"); 222930fdc8d8SChris Lattner 223023f59509SGreg Clayton LoadSubCommand("list", list_command_object); 223123f59509SGreg Clayton LoadSubCommand("enable", enable_command_object); 223223f59509SGreg Clayton LoadSubCommand("disable", disable_command_object); 223323f59509SGreg Clayton LoadSubCommand("clear", clear_command_object); 223423f59509SGreg Clayton LoadSubCommand("delete", delete_command_object); 223523f59509SGreg Clayton LoadSubCommand("set", set_command_object); 223623f59509SGreg Clayton LoadSubCommand("command", command_command_object); 223723f59509SGreg Clayton LoadSubCommand("modify", modify_command_object); 22385e09c8c3SJim Ingham LoadSubCommand("name", name_command_object); 2239e14dc268SJim Ingham LoadSubCommand("write", write_command_object); 2240e14dc268SJim Ingham LoadSubCommand("read", read_command_object); 224130fdc8d8SChris Lattner } 224230fdc8d8SChris Lattner 22439e85e5a8SEugene Zelenko CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default; 224430fdc8d8SChris Lattner 2245a925974bSAdrian Prantl void CommandObjectMultiwordBreakpoint::VerifyIDs( 2246a925974bSAdrian Prantl Args &args, Target *target, bool allow_locations, 2247a925974bSAdrian Prantl CommandReturnObject &result, BreakpointIDList *valid_ids, 2248a925974bSAdrian Prantl BreakpointName::Permissions ::PermissionKinds purpose) { 224930fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 2250b9c1b51eSKate Stone // 2). the full breakpoint & location 2251b9c1b51eSKate Stone // canonical representation 2252b9c1b51eSKate Stone // 3). the word "to" or a hyphen, 2253b9c1b51eSKate Stone // representing a range (in which case there 2254b9c1b51eSKate Stone // had *better* be an entry both before & 2255b9c1b51eSKate Stone // after of one of the first two types. 22565e09c8c3SJim Ingham // 4). A breakpoint name 2257b9c1b51eSKate Stone // If args is empty, we will use the last created breakpoint (if there is 2258b9c1b51eSKate Stone // one.) 225930fdc8d8SChris Lattner 226030fdc8d8SChris Lattner Args temp_args; 226130fdc8d8SChris Lattner 226211eb9c64SZachary Turner if (args.empty()) { 2263b9c1b51eSKate Stone if (target->GetLastCreatedBreakpoint()) { 2264b9c1b51eSKate Stone valid_ids->AddBreakpointID(BreakpointID( 2265b9c1b51eSKate Stone target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); 226636f3b369SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 2267b9c1b51eSKate Stone } else { 2268b9c1b51eSKate Stone result.AppendError( 2269b9c1b51eSKate Stone "No breakpoint specified and no last created breakpoint."); 227036f3b369SJim Ingham result.SetStatus(eReturnStatusFailed); 227136f3b369SJim Ingham } 227236f3b369SJim Ingham return; 227336f3b369SJim Ingham } 227436f3b369SJim Ingham 2275b9c1b51eSKate Stone // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff 227605097246SAdrian Prantl // directly from the old ARGS to the new TEMP_ARGS. Do not copy breakpoint 227705097246SAdrian Prantl // id range strings over; instead generate a list of strings for all the 227805097246SAdrian Prantl // breakpoint ids in the range, and shove all of those breakpoint id strings 227905097246SAdrian Prantl // into TEMP_ARGS. 228030fdc8d8SChris Lattner 2281b9c1b51eSKate Stone BreakpointIDList::FindAndReplaceIDRanges(args, target, allow_locations, 2282b842f2ecSJim Ingham purpose, result, temp_args); 228330fdc8d8SChris Lattner 2284b9c1b51eSKate Stone // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual 2285b9c1b51eSKate Stone // BreakpointIDList: 228630fdc8d8SChris Lattner 228716662f3cSPavel Labath valid_ids->InsertStringArray(temp_args.GetArgumentArrayRef(), result); 228830fdc8d8SChris Lattner 228905097246SAdrian Prantl // At this point, all of the breakpoint ids that the user passed in have 229005097246SAdrian Prantl // been converted to breakpoint IDs and put into valid_ids. 229130fdc8d8SChris Lattner 2292b9c1b51eSKate Stone if (result.Succeeded()) { 2293b9c1b51eSKate Stone // Now that we've converted everything from args into a list of breakpoint 229405097246SAdrian Prantl // ids, go through our tentative list of breakpoint id's and verify that 229505097246SAdrian Prantl // they correspond to valid/currently set breakpoints. 229630fdc8d8SChris Lattner 2297c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 2298b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 229930fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex(i); 2300b9c1b51eSKate Stone Breakpoint *breakpoint = 2301b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 2302b9c1b51eSKate Stone if (breakpoint != nullptr) { 2303c7bece56SGreg Clayton const size_t num_locations = breakpoint->GetNumLocations(); 2304b9c1b51eSKate Stone if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations) { 230530fdc8d8SChris Lattner StreamString id_str; 2306b9c1b51eSKate Stone BreakpointID::GetCanonicalReference( 2307b9c1b51eSKate Stone &id_str, cur_bp_id.GetBreakpointID(), cur_bp_id.GetLocationID()); 2308c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 2309b9c1b51eSKate Stone result.AppendErrorWithFormat( 2310b9c1b51eSKate Stone "'%s' is not a currently valid breakpoint/location id.\n", 231130fdc8d8SChris Lattner id_str.GetData()); 231230fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 231330fdc8d8SChris Lattner } 2314b9c1b51eSKate Stone } else { 2315c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 2316b9c1b51eSKate Stone result.AppendErrorWithFormat( 2317b9c1b51eSKate Stone "'%d' is not a currently valid breakpoint ID.\n", 23187428a18cSKate Stone cur_bp_id.GetBreakpointID()); 231930fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 232030fdc8d8SChris Lattner } 232130fdc8d8SChris Lattner } 232230fdc8d8SChris Lattner } 232330fdc8d8SChris Lattner } 2324