130fdc8d8SChris Lattner //===-- CommandObjectBreakpoint.cpp -----------------------------*- C++ -*-===// 230fdc8d8SChris Lattner // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 630fdc8d8SChris Lattner // 730fdc8d8SChris Lattner //===----------------------------------------------------------------------===// 830fdc8d8SChris Lattner 99e85e5a8SEugene Zelenko #include "CommandObjectBreakpoint.h" 109e85e5a8SEugene Zelenko #include "CommandObjectBreakpointCommand.h" 1130fdc8d8SChris Lattner #include "lldb/Breakpoint/Breakpoint.h" 1230fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointIDList.h" 1330fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointLocation.h" 143eb2b44dSZachary Turner #include "lldb/Host/OptionParser.h" 15b9c1b51eSKate Stone #include "lldb/Interpreter/CommandCompletions.h" 16b9c1b51eSKate Stone #include "lldb/Interpreter/CommandInterpreter.h" 17b9c1b51eSKate Stone #include "lldb/Interpreter/CommandReturnObject.h" 1847cbf4a0SPavel Labath #include "lldb/Interpreter/OptionArgParser.h" 1932abc6edSZachary Turner #include "lldb/Interpreter/OptionValueBoolean.h" 205e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueString.h" 215e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueUInt64.h" 22b9c1b51eSKate Stone #include "lldb/Interpreter/Options.h" 230e0984eeSJim Ingham #include "lldb/Target/Language.h" 24b57e4a1bSJason Molenda #include "lldb/Target/StackFrame.h" 25b9c1b51eSKate Stone #include "lldb/Target/Target.h" 261b54c88cSJim Ingham #include "lldb/Target/Thread.h" 271b54c88cSJim Ingham #include "lldb/Target/ThreadSpec.h" 28bf9a7730SZachary Turner #include "lldb/Utility/RegularExpression.h" 29bf9a7730SZachary Turner #include "lldb/Utility/StreamString.h" 3030fdc8d8SChris Lattner 31796ac80bSJonas Devlieghere #include <memory> 32796ac80bSJonas Devlieghere #include <vector> 33796ac80bSJonas Devlieghere 3430fdc8d8SChris Lattner using namespace lldb; 3530fdc8d8SChris Lattner using namespace lldb_private; 3630fdc8d8SChris Lattner 37b9c1b51eSKate Stone static void AddBreakpointDescription(Stream *s, Breakpoint *bp, 38b9c1b51eSKate Stone lldb::DescriptionLevel level) { 3930fdc8d8SChris Lattner s->IndentMore(); 4030fdc8d8SChris Lattner bp->GetDescription(s, level, true); 4130fdc8d8SChris Lattner s->IndentLess(); 4230fdc8d8SChris Lattner s->EOL(); 4330fdc8d8SChris Lattner } 4430fdc8d8SChris Lattner 45b842f2ecSJim Ingham // Modifiable Breakpoint Options 46b842f2ecSJim Ingham #pragma mark Modify::CommandOptions 47f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_modify 48f94668e3SRaphael Isemann #include "CommandOptions.inc" 49*bd68a052SRaphael Isemann 50b842f2ecSJim Ingham class lldb_private::BreakpointOptionGroup : public OptionGroup 51b842f2ecSJim Ingham { 52b842f2ecSJim Ingham public: 53b842f2ecSJim Ingham BreakpointOptionGroup() : 54b842f2ecSJim Ingham OptionGroup(), 55b842f2ecSJim Ingham m_bp_opts(false) {} 56b842f2ecSJim Ingham 57b842f2ecSJim Ingham ~BreakpointOptionGroup() override = default; 58b842f2ecSJim Ingham 59b842f2ecSJim Ingham llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 60b842f2ecSJim Ingham return llvm::makeArrayRef(g_breakpoint_modify_options); 61b842f2ecSJim Ingham } 62b842f2ecSJim Ingham 63b842f2ecSJim Ingham Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 64b842f2ecSJim Ingham ExecutionContext *execution_context) override { 65b842f2ecSJim Ingham Status error; 66b842f2ecSJim Ingham const int short_option = g_breakpoint_modify_options[option_idx].short_option; 67b842f2ecSJim Ingham 68b842f2ecSJim Ingham switch (short_option) { 69b842f2ecSJim Ingham case 'c': 7005097246SAdrian Prantl // Normally an empty breakpoint condition marks is as unset. But we need 7105097246SAdrian Prantl // to say it was passed in. 72b842f2ecSJim Ingham m_bp_opts.SetCondition(option_arg.str().c_str()); 73b842f2ecSJim Ingham m_bp_opts.m_set_flags.Set(BreakpointOptions::eCondition); 74b842f2ecSJim Ingham break; 75b842f2ecSJim Ingham case 'C': 76b842f2ecSJim Ingham m_commands.push_back(option_arg); 77b842f2ecSJim Ingham break; 78b842f2ecSJim Ingham case 'd': 79b842f2ecSJim Ingham m_bp_opts.SetEnabled(false); 80b842f2ecSJim Ingham break; 81b842f2ecSJim Ingham case 'e': 82b842f2ecSJim Ingham m_bp_opts.SetEnabled(true); 83b842f2ecSJim Ingham break; 84b842f2ecSJim Ingham case 'G': { 85b842f2ecSJim Ingham bool value, success; 8647cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 87b842f2ecSJim Ingham if (success) { 88b842f2ecSJim Ingham m_bp_opts.SetAutoContinue(value); 89b842f2ecSJim Ingham } else 90b842f2ecSJim Ingham error.SetErrorStringWithFormat( 91b842f2ecSJim Ingham "invalid boolean value '%s' passed for -G option", 92b842f2ecSJim Ingham option_arg.str().c_str()); 93b842f2ecSJim Ingham } 94b842f2ecSJim Ingham break; 95b842f2ecSJim Ingham case 'i': 96b842f2ecSJim Ingham { 97b842f2ecSJim Ingham uint32_t ignore_count; 98b842f2ecSJim Ingham if (option_arg.getAsInteger(0, ignore_count)) 99b842f2ecSJim Ingham error.SetErrorStringWithFormat("invalid ignore count '%s'", 100b842f2ecSJim Ingham option_arg.str().c_str()); 101b842f2ecSJim Ingham else 102b842f2ecSJim Ingham m_bp_opts.SetIgnoreCount(ignore_count); 103b842f2ecSJim Ingham } 104b842f2ecSJim Ingham break; 105b842f2ecSJim Ingham case 'o': { 106b842f2ecSJim Ingham bool value, success; 10747cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 108b842f2ecSJim Ingham if (success) { 109b842f2ecSJim Ingham m_bp_opts.SetOneShot(value); 110b842f2ecSJim Ingham } else 111b842f2ecSJim Ingham error.SetErrorStringWithFormat( 112b842f2ecSJim Ingham "invalid boolean value '%s' passed for -o option", 113b842f2ecSJim Ingham option_arg.str().c_str()); 114b842f2ecSJim Ingham } break; 115b842f2ecSJim Ingham case 't': 116b842f2ecSJim Ingham { 117b842f2ecSJim Ingham lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID; 118b842f2ecSJim Ingham if (option_arg[0] != '\0') { 119b842f2ecSJim Ingham if (option_arg.getAsInteger(0, thread_id)) 120b842f2ecSJim Ingham error.SetErrorStringWithFormat("invalid thread id string '%s'", 121b842f2ecSJim Ingham option_arg.str().c_str()); 122b842f2ecSJim Ingham } 123b842f2ecSJim Ingham m_bp_opts.SetThreadID(thread_id); 124b842f2ecSJim Ingham } 125b842f2ecSJim Ingham break; 126b842f2ecSJim Ingham case 'T': 127b842f2ecSJim Ingham m_bp_opts.GetThreadSpec()->SetName(option_arg.str().c_str()); 128b842f2ecSJim Ingham break; 129b842f2ecSJim Ingham case 'q': 130b842f2ecSJim Ingham m_bp_opts.GetThreadSpec()->SetQueueName(option_arg.str().c_str()); 131b842f2ecSJim Ingham break; 132b842f2ecSJim Ingham case 'x': 133b842f2ecSJim Ingham { 134b842f2ecSJim Ingham uint32_t thread_index = UINT32_MAX; 135b842f2ecSJim Ingham if (option_arg[0] != '\n') { 136b842f2ecSJim Ingham if (option_arg.getAsInteger(0, thread_index)) 137b842f2ecSJim Ingham error.SetErrorStringWithFormat("invalid thread index string '%s'", 138b842f2ecSJim Ingham option_arg.str().c_str()); 139b842f2ecSJim Ingham } 140b842f2ecSJim Ingham m_bp_opts.GetThreadSpec()->SetIndex(thread_index); 141b842f2ecSJim Ingham } 142b842f2ecSJim Ingham break; 143b842f2ecSJim Ingham default: 144b842f2ecSJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 145b842f2ecSJim Ingham short_option); 146b842f2ecSJim Ingham break; 147b842f2ecSJim Ingham } 148b842f2ecSJim Ingham 149b842f2ecSJim Ingham return error; 150b842f2ecSJim Ingham } 151b842f2ecSJim Ingham 152b842f2ecSJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 153b842f2ecSJim Ingham m_bp_opts.Clear(); 154b842f2ecSJim Ingham m_commands.clear(); 155b842f2ecSJim Ingham } 156b842f2ecSJim Ingham 157b842f2ecSJim Ingham Status OptionParsingFinished(ExecutionContext *execution_context) override { 158b842f2ecSJim Ingham if (!m_commands.empty()) 159b842f2ecSJim Ingham { 160b842f2ecSJim Ingham if (!m_commands.empty()) 161b842f2ecSJim Ingham { 162b842f2ecSJim Ingham auto cmd_data = llvm::make_unique<BreakpointOptions::CommandData>(); 163b842f2ecSJim Ingham 164b842f2ecSJim Ingham for (std::string &str : m_commands) 165b842f2ecSJim Ingham cmd_data->user_source.AppendString(str); 166b842f2ecSJim Ingham 167b842f2ecSJim Ingham cmd_data->stop_on_error = true; 168b842f2ecSJim Ingham m_bp_opts.SetCommandDataCallback(cmd_data); 169b842f2ecSJim Ingham } 170b842f2ecSJim Ingham } 171b842f2ecSJim Ingham return Status(); 172b842f2ecSJim Ingham } 173b842f2ecSJim Ingham 174b842f2ecSJim Ingham const BreakpointOptions &GetBreakpointOptions() 175b842f2ecSJim Ingham { 176b842f2ecSJim Ingham return m_bp_opts; 177b842f2ecSJim Ingham } 178b842f2ecSJim Ingham 179b842f2ecSJim Ingham std::vector<std::string> m_commands; 180b842f2ecSJim Ingham BreakpointOptions m_bp_opts; 181b842f2ecSJim Ingham 182b842f2ecSJim Ingham }; 183*bd68a052SRaphael Isemann 184f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_dummy 185f94668e3SRaphael Isemann #include "CommandOptions.inc" 186b842f2ecSJim Ingham 187b842f2ecSJim Ingham class BreakpointDummyOptionGroup : public OptionGroup 188b842f2ecSJim Ingham { 189b842f2ecSJim Ingham public: 190b842f2ecSJim Ingham BreakpointDummyOptionGroup() : 191b842f2ecSJim Ingham OptionGroup() {} 192b842f2ecSJim Ingham 193b842f2ecSJim Ingham ~BreakpointDummyOptionGroup() override = default; 194b842f2ecSJim Ingham 195b842f2ecSJim Ingham llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 196b842f2ecSJim Ingham return llvm::makeArrayRef(g_breakpoint_dummy_options); 197b842f2ecSJim Ingham } 198b842f2ecSJim Ingham 199b842f2ecSJim Ingham Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 200b842f2ecSJim Ingham ExecutionContext *execution_context) override { 201b842f2ecSJim Ingham Status error; 202b842f2ecSJim Ingham const int short_option = g_breakpoint_modify_options[option_idx].short_option; 203b842f2ecSJim Ingham 204b842f2ecSJim Ingham switch (short_option) { 205b842f2ecSJim Ingham case 'D': 206b842f2ecSJim Ingham m_use_dummy = true; 207b842f2ecSJim Ingham break; 208b842f2ecSJim Ingham default: 209b842f2ecSJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 210b842f2ecSJim Ingham short_option); 211b842f2ecSJim Ingham break; 212b842f2ecSJim Ingham } 213b842f2ecSJim Ingham 214b842f2ecSJim Ingham return error; 215b842f2ecSJim Ingham } 216b842f2ecSJim Ingham 217b842f2ecSJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 218b842f2ecSJim Ingham m_use_dummy = false; 219b842f2ecSJim Ingham } 220b842f2ecSJim Ingham 221b842f2ecSJim Ingham bool m_use_dummy; 222b842f2ecSJim Ingham 223b842f2ecSJim Ingham }; 224b842f2ecSJim Ingham 225f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_set 226f94668e3SRaphael Isemann #include "CommandOptions.inc" 2271f0f5b5bSZachary Turner 2285a988416SJim Ingham // CommandObjectBreakpointSet 22930fdc8d8SChris Lattner 230b9c1b51eSKate Stone class CommandObjectBreakpointSet : public CommandObjectParsed { 2315a988416SJim Ingham public: 232efe8e7e3SFangrui Song enum BreakpointSetType { 2335a988416SJim Ingham eSetTypeInvalid, 2345a988416SJim Ingham eSetTypeFileAndLine, 2355a988416SJim Ingham eSetTypeAddress, 2365a988416SJim Ingham eSetTypeFunctionName, 2375a988416SJim Ingham eSetTypeFunctionRegexp, 2385a988416SJim Ingham eSetTypeSourceRegexp, 2393815e702SJim Ingham eSetTypeException, 2403815e702SJim Ingham eSetTypeScripted, 241efe8e7e3SFangrui Song }; 2425a988416SJim Ingham 243b9c1b51eSKate Stone CommandObjectBreakpointSet(CommandInterpreter &interpreter) 244b9c1b51eSKate Stone : CommandObjectParsed( 245b9c1b51eSKate Stone interpreter, "breakpoint set", 2465a988416SJim Ingham "Sets a breakpoint or set of breakpoints in the executable.", 2475a988416SJim Ingham "breakpoint set <cmd-options>"), 248b842f2ecSJim Ingham m_bp_opts(), m_options() { 249b842f2ecSJim Ingham // We're picking up all the normal options, commands and disable. 250b842f2ecSJim Ingham m_all_options.Append(&m_bp_opts, 251b842f2ecSJim Ingham LLDB_OPT_SET_1 | LLDB_OPT_SET_3 | LLDB_OPT_SET_4, 252b842f2ecSJim Ingham LLDB_OPT_SET_ALL); 253b842f2ecSJim Ingham m_all_options.Append(&m_dummy_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 254b842f2ecSJim Ingham m_all_options.Append(&m_options); 255b842f2ecSJim Ingham m_all_options.Finalize(); 256b842f2ecSJim Ingham } 2575a988416SJim Ingham 2589e85e5a8SEugene Zelenko ~CommandObjectBreakpointSet() override = default; 2595a988416SJim Ingham 260b842f2ecSJim Ingham Options *GetOptions() override { return &m_all_options; } 2615a988416SJim Ingham 262b842f2ecSJim Ingham class CommandOptions : public OptionGroup { 2635a988416SJim Ingham public: 264b9c1b51eSKate Stone CommandOptions() 265b842f2ecSJim Ingham : OptionGroup(), m_condition(), m_filenames(), m_line_num(0), m_column(0), 266b9c1b51eSKate Stone m_func_names(), m_func_name_type_mask(eFunctionNameTypeNone), 267b9c1b51eSKate Stone m_func_regexp(), m_source_text_regexp(), m_modules(), m_load_addr(), 268b9c1b51eSKate Stone m_catch_bp(false), m_throw_bp(true), m_hardware(false), 269a72b31c7SJim Ingham m_exception_language(eLanguageTypeUnknown), 27023b1decbSDawn Perchik m_language(lldb::eLanguageTypeUnknown), 271b842f2ecSJim Ingham m_skip_prologue(eLazyBoolCalculate), 272b9c1b51eSKate Stone m_all_files(false), m_move_to_nearest_code(eLazyBoolCalculate) {} 27330fdc8d8SChris Lattner 2749e85e5a8SEugene Zelenko ~CommandOptions() override = default; 27587df91b8SJim Ingham 27697206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 277b9c1b51eSKate Stone ExecutionContext *execution_context) override { 27897206d57SZachary Turner Status error; 279b842f2ecSJim Ingham const int short_option = g_breakpoint_set_options[option_idx].short_option; 28030fdc8d8SChris Lattner 281b9c1b51eSKate Stone switch (short_option) { 282b9c1b51eSKate Stone case 'a': { 28347cbf4a0SPavel Labath m_load_addr = OptionArgParser::ToAddress(execution_context, option_arg, 284e1cfbc79STodd Fiala LLDB_INVALID_ADDRESS, &error); 285b9c1b51eSKate Stone } break; 28630fdc8d8SChris Lattner 287e732052fSJim Ingham case 'A': 288e732052fSJim Ingham m_all_files = true; 289e732052fSJim Ingham break; 290e732052fSJim Ingham 291ca36cd16SJim Ingham case 'b': 292ca36cd16SJim Ingham m_func_names.push_back(option_arg); 293ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeBase; 294ca36cd16SJim Ingham break; 295ca36cd16SJim Ingham 296fe11483bSZachary Turner case 'C': 297fe11483bSZachary Turner if (option_arg.getAsInteger(0, m_column)) 298b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid column number: %s", 299fe11483bSZachary Turner option_arg.str().c_str()); 30030fdc8d8SChris Lattner break; 3019e85e5a8SEugene Zelenko 302b9c1b51eSKate Stone case 'E': { 303fe11483bSZachary Turner LanguageType language = Language::GetLanguageTypeFromString(option_arg); 304fab10e89SJim Ingham 305b9c1b51eSKate Stone switch (language) { 306fab10e89SJim Ingham case eLanguageTypeC89: 307fab10e89SJim Ingham case eLanguageTypeC: 308fab10e89SJim Ingham case eLanguageTypeC99: 3091d0089faSBruce Mitchener case eLanguageTypeC11: 310a72b31c7SJim Ingham m_exception_language = eLanguageTypeC; 311fab10e89SJim Ingham break; 312fab10e89SJim Ingham case eLanguageTypeC_plus_plus: 3131d0089faSBruce Mitchener case eLanguageTypeC_plus_plus_03: 3141d0089faSBruce Mitchener case eLanguageTypeC_plus_plus_11: 3152ba84a6aSBruce Mitchener case eLanguageTypeC_plus_plus_14: 316a72b31c7SJim Ingham m_exception_language = eLanguageTypeC_plus_plus; 317fab10e89SJim Ingham break; 318fab10e89SJim Ingham case eLanguageTypeObjC: 319a72b31c7SJim Ingham m_exception_language = eLanguageTypeObjC; 320fab10e89SJim Ingham break; 321fab10e89SJim Ingham case eLanguageTypeObjC_plus_plus: 322b9c1b51eSKate Stone error.SetErrorStringWithFormat( 323b9c1b51eSKate Stone "Set exception breakpoints separately for c++ and objective-c"); 324fab10e89SJim Ingham break; 325fab10e89SJim Ingham case eLanguageTypeUnknown: 326b9c1b51eSKate Stone error.SetErrorStringWithFormat( 327b9c1b51eSKate Stone "Unknown language type: '%s' for exception breakpoint", 328fe11483bSZachary Turner option_arg.str().c_str()); 329fab10e89SJim Ingham break; 330fab10e89SJim Ingham default: 331b9c1b51eSKate Stone error.SetErrorStringWithFormat( 332b9c1b51eSKate Stone "Unsupported language type: '%s' for exception breakpoint", 333fe11483bSZachary Turner option_arg.str().c_str()); 334fab10e89SJim Ingham } 335b9c1b51eSKate Stone } break; 336ca36cd16SJim Ingham 337ca36cd16SJim Ingham case 'f': 3388f3be7a3SJonas Devlieghere m_filenames.AppendIfUnique(FileSpec(option_arg)); 339fab10e89SJim Ingham break; 340ca36cd16SJim Ingham 341ca36cd16SJim Ingham case 'F': 342ca36cd16SJim Ingham m_func_names.push_back(option_arg); 343ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeFull; 344ca36cd16SJim Ingham break; 345ca36cd16SJim Ingham 346b9c1b51eSKate Stone case 'h': { 347fab10e89SJim Ingham bool success; 34847cbf4a0SPavel Labath m_catch_bp = OptionArgParser::ToBoolean(option_arg, true, &success); 349fab10e89SJim Ingham if (!success) 350b9c1b51eSKate Stone error.SetErrorStringWithFormat( 351fe11483bSZachary Turner "Invalid boolean value for on-catch option: '%s'", 352fe11483bSZachary Turner option_arg.str().c_str()); 353b9c1b51eSKate Stone } break; 354eb023e75SGreg Clayton 355eb023e75SGreg Clayton case 'H': 356eb023e75SGreg Clayton m_hardware = true; 357eb023e75SGreg Clayton break; 358eb023e75SGreg Clayton 3593815e702SJim Ingham case 'k': { 3603815e702SJim Ingham if (m_current_key.empty()) 3613815e702SJim Ingham m_current_key.assign(option_arg); 3623815e702SJim Ingham else 3633815e702SJim Ingham error.SetErrorStringWithFormat("Key: %s missing value.", 3643815e702SJim Ingham m_current_key.c_str()); 3653815e702SJim Ingham 3663815e702SJim Ingham } break; 367b9c1b51eSKate Stone case 'K': { 368a8558b62SJim Ingham bool success; 369a8558b62SJim Ingham bool value; 37047cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, true, &success); 371a8558b62SJim Ingham if (value) 372a8558b62SJim Ingham m_skip_prologue = eLazyBoolYes; 373a8558b62SJim Ingham else 374a8558b62SJim Ingham m_skip_prologue = eLazyBoolNo; 375a8558b62SJim Ingham 376a8558b62SJim Ingham if (!success) 377b9c1b51eSKate Stone error.SetErrorStringWithFormat( 378b9c1b51eSKate Stone "Invalid boolean value for skip prologue option: '%s'", 379fe11483bSZachary Turner option_arg.str().c_str()); 380b9c1b51eSKate Stone } break; 381ca36cd16SJim Ingham 382fe11483bSZachary Turner case 'l': 383fe11483bSZachary Turner if (option_arg.getAsInteger(0, m_line_num)) 384b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid line number: %s.", 385fe11483bSZachary Turner option_arg.str().c_str()); 386ca36cd16SJim Ingham break; 387055ad9beSIlia K 38823b1decbSDawn Perchik case 'L': 389fe11483bSZachary Turner m_language = Language::GetLanguageTypeFromString(option_arg); 39023b1decbSDawn Perchik if (m_language == eLanguageTypeUnknown) 391b9c1b51eSKate Stone error.SetErrorStringWithFormat( 392fe11483bSZachary Turner "Unknown language type: '%s' for breakpoint", 393fe11483bSZachary Turner option_arg.str().c_str()); 39423b1decbSDawn Perchik break; 39523b1decbSDawn Perchik 396b9c1b51eSKate Stone case 'm': { 397055ad9beSIlia K bool success; 398055ad9beSIlia K bool value; 39947cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, true, &success); 400055ad9beSIlia K if (value) 401055ad9beSIlia K m_move_to_nearest_code = eLazyBoolYes; 402055ad9beSIlia K else 403055ad9beSIlia K m_move_to_nearest_code = eLazyBoolNo; 404055ad9beSIlia K 405055ad9beSIlia K if (!success) 406b9c1b51eSKate Stone error.SetErrorStringWithFormat( 407b9c1b51eSKate Stone "Invalid boolean value for move-to-nearest-code option: '%s'", 408fe11483bSZachary Turner option_arg.str().c_str()); 409055ad9beSIlia K break; 410055ad9beSIlia K } 411055ad9beSIlia K 412ca36cd16SJim Ingham case 'M': 413ca36cd16SJim Ingham m_func_names.push_back(option_arg); 414ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeMethod; 415ca36cd16SJim Ingham break; 416ca36cd16SJim Ingham 417ca36cd16SJim Ingham case 'n': 418ca36cd16SJim Ingham m_func_names.push_back(option_arg); 419ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeAuto; 420ca36cd16SJim Ingham break; 421ca36cd16SJim Ingham 4226fa7681bSZachary Turner case 'N': { 423fe11483bSZachary Turner if (BreakpointID::StringIsBreakpointName(option_arg, error)) 4245e09c8c3SJim Ingham m_breakpoint_names.push_back(option_arg); 425ff9a91eaSJim Ingham else 426ff9a91eaSJim Ingham error.SetErrorStringWithFormat("Invalid breakpoint name: %s", 427fe11483bSZachary Turner option_arg.str().c_str()); 4285e09c8c3SJim Ingham break; 4296fa7681bSZachary Turner } 4305e09c8c3SJim Ingham 431b9c1b51eSKate Stone case 'R': { 4322411167fSJim Ingham lldb::addr_t tmp_offset_addr; 43347cbf4a0SPavel Labath tmp_offset_addr = OptionArgParser::ToAddress(execution_context, 43447cbf4a0SPavel Labath option_arg, 0, &error); 4352411167fSJim Ingham if (error.Success()) 4362411167fSJim Ingham m_offset_addr = tmp_offset_addr; 437b9c1b51eSKate Stone } break; 4382411167fSJim Ingham 439a72b31c7SJim Ingham case 'O': 440fe11483bSZachary Turner m_exception_extra_args.AppendArgument("-O"); 441fe11483bSZachary Turner m_exception_extra_args.AppendArgument(option_arg); 442a72b31c7SJim Ingham break; 443a72b31c7SJim Ingham 444ca36cd16SJim Ingham case 'p': 445ca36cd16SJim Ingham m_source_text_regexp.assign(option_arg); 446ca36cd16SJim Ingham break; 447ca36cd16SJim Ingham 4483815e702SJim Ingham case 'P': 4493815e702SJim Ingham m_python_class.assign(option_arg); 4503815e702SJim Ingham break; 4513815e702SJim Ingham 452ca36cd16SJim Ingham case 'r': 453ca36cd16SJim Ingham m_func_regexp.assign(option_arg); 454ca36cd16SJim Ingham break; 455ca36cd16SJim Ingham 456ca36cd16SJim Ingham case 's': 4578f3be7a3SJonas Devlieghere m_modules.AppendIfUnique(FileSpec(option_arg)); 458ca36cd16SJim Ingham break; 459ca36cd16SJim Ingham 460ca36cd16SJim Ingham case 'S': 461ca36cd16SJim Ingham m_func_names.push_back(option_arg); 462ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeSelector; 463ca36cd16SJim Ingham break; 464ca36cd16SJim Ingham 4653815e702SJim Ingham case 'v': { 4663815e702SJim Ingham if (!m_current_key.empty()) { 4673815e702SJim Ingham m_extra_args_sp->AddStringItem(m_current_key, option_arg); 4683815e702SJim Ingham m_current_key.clear(); 4693815e702SJim Ingham } 4703815e702SJim Ingham else 4713815e702SJim Ingham error.SetErrorStringWithFormat("Value \"%s\" missing matching key.", 4723815e702SJim Ingham option_arg.str().c_str()); 4733815e702SJim Ingham } break; 4743815e702SJim Ingham 475b9c1b51eSKate Stone case 'w': { 476ca36cd16SJim Ingham bool success; 47747cbf4a0SPavel Labath m_throw_bp = OptionArgParser::ToBoolean(option_arg, true, &success); 478ca36cd16SJim Ingham if (!success) 479b9c1b51eSKate Stone error.SetErrorStringWithFormat( 480fe11483bSZachary Turner "Invalid boolean value for on-throw option: '%s'", 481fe11483bSZachary Turner option_arg.str().c_str()); 482b9c1b51eSKate Stone } break; 483ca36cd16SJim Ingham 48476bb8d67SJim Ingham case 'X': 48576bb8d67SJim Ingham m_source_regex_func_names.insert(option_arg); 48676bb8d67SJim Ingham break; 48776bb8d67SJim Ingham 48830fdc8d8SChris Lattner default: 489b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 490b9c1b51eSKate Stone short_option); 49130fdc8d8SChris Lattner break; 49230fdc8d8SChris Lattner } 49330fdc8d8SChris Lattner 49430fdc8d8SChris Lattner return error; 49530fdc8d8SChris Lattner } 4969e85e5a8SEugene Zelenko 497b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 49887df91b8SJim Ingham m_filenames.Clear(); 49930fdc8d8SChris Lattner m_line_num = 0; 50030fdc8d8SChris Lattner m_column = 0; 501fab10e89SJim Ingham m_func_names.clear(); 5021f746071SGreg Clayton m_func_name_type_mask = eFunctionNameTypeNone; 50330fdc8d8SChris Lattner m_func_regexp.clear(); 5041f746071SGreg Clayton m_source_text_regexp.clear(); 50587df91b8SJim Ingham m_modules.Clear(); 5061f746071SGreg Clayton m_load_addr = LLDB_INVALID_ADDRESS; 5072411167fSJim Ingham m_offset_addr = 0; 508fab10e89SJim Ingham m_catch_bp = false; 509fab10e89SJim Ingham m_throw_bp = true; 510eb023e75SGreg Clayton m_hardware = false; 511a72b31c7SJim Ingham m_exception_language = eLanguageTypeUnknown; 51223b1decbSDawn Perchik m_language = lldb::eLanguageTypeUnknown; 513a8558b62SJim Ingham m_skip_prologue = eLazyBoolCalculate; 5145e09c8c3SJim Ingham m_breakpoint_names.clear(); 515e732052fSJim Ingham m_all_files = false; 516a72b31c7SJim Ingham m_exception_extra_args.Clear(); 517055ad9beSIlia K m_move_to_nearest_code = eLazyBoolCalculate; 51876bb8d67SJim Ingham m_source_regex_func_names.clear(); 5193815e702SJim Ingham m_python_class.clear(); 520796ac80bSJonas Devlieghere m_extra_args_sp = std::make_shared<StructuredData::Dictionary>(); 5213815e702SJim Ingham m_current_key.clear(); 52230fdc8d8SChris Lattner } 52330fdc8d8SChris Lattner 5241f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 52570602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_set_options); 5261f0f5b5bSZachary Turner } 52730fdc8d8SChris Lattner 5285a988416SJim Ingham // Instance variables to hold the values for command options. 529969795f1SJim Ingham 5305a988416SJim Ingham std::string m_condition; 5315a988416SJim Ingham FileSpecList m_filenames; 5325a988416SJim Ingham uint32_t m_line_num; 5335a988416SJim Ingham uint32_t m_column; 5345a988416SJim Ingham std::vector<std::string> m_func_names; 5355e09c8c3SJim Ingham std::vector<std::string> m_breakpoint_names; 536117b1fa1SZachary Turner lldb::FunctionNameType m_func_name_type_mask; 5375a988416SJim Ingham std::string m_func_regexp; 5385a988416SJim Ingham std::string m_source_text_regexp; 5395a988416SJim Ingham FileSpecList m_modules; 5405a988416SJim Ingham lldb::addr_t m_load_addr; 5412411167fSJim Ingham lldb::addr_t m_offset_addr; 5425a988416SJim Ingham bool m_catch_bp; 5435a988416SJim Ingham bool m_throw_bp; 544eb023e75SGreg Clayton bool m_hardware; // Request to use hardware breakpoints 545a72b31c7SJim Ingham lldb::LanguageType m_exception_language; 54623b1decbSDawn Perchik lldb::LanguageType m_language; 5475a988416SJim Ingham LazyBool m_skip_prologue; 548e732052fSJim Ingham bool m_all_files; 549a72b31c7SJim Ingham Args m_exception_extra_args; 550055ad9beSIlia K LazyBool m_move_to_nearest_code; 55176bb8d67SJim Ingham std::unordered_set<std::string> m_source_regex_func_names; 5523815e702SJim Ingham std::string m_python_class; 5533815e702SJim Ingham StructuredData::DictionarySP m_extra_args_sp; 5543815e702SJim Ingham std::string m_current_key; 5555a988416SJim Ingham }; 5565a988416SJim Ingham 5575a988416SJim Ingham protected: 558b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 559b842f2ecSJim Ingham Target *target = GetSelectedOrDummyTarget(m_dummy_options.m_use_dummy); 56033df7cd3SJim Ingham 561b9c1b51eSKate Stone if (target == nullptr) { 562b9c1b51eSKate Stone result.AppendError("Invalid target. Must set target before setting " 563b9c1b51eSKate Stone "breakpoints (see 'target create' command)."); 56430fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 56530fdc8d8SChris Lattner return false; 56630fdc8d8SChris Lattner } 56730fdc8d8SChris Lattner 56830fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 56930fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 57030fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 57130fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 572b9c1b51eSKate Stone // 4). -r [-s -g] (setting breakpoint by function name regular 573b9c1b51eSKate Stone // expression) 574b9c1b51eSKate Stone // 5). -p -f (setting a breakpoint by comparing a reg-exp 575b9c1b51eSKate Stone // to source text) 576b9c1b51eSKate Stone // 6). -E [-w -h] (setting a breakpoint for exceptions for a 577b9c1b51eSKate Stone // given language.) 57830fdc8d8SChris Lattner 57930fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 58030fdc8d8SChris Lattner 5813815e702SJim Ingham if (!m_options.m_python_class.empty()) 5823815e702SJim Ingham break_type = eSetTypeScripted; 5833815e702SJim Ingham else if (m_options.m_line_num != 0) 58430fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 58530fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 58630fdc8d8SChris Lattner break_type = eSetTypeAddress; 587fab10e89SJim Ingham else if (!m_options.m_func_names.empty()) 58830fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 58930fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 59030fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 591969795f1SJim Ingham else if (!m_options.m_source_text_regexp.empty()) 592969795f1SJim Ingham break_type = eSetTypeSourceRegexp; 593a72b31c7SJim Ingham else if (m_options.m_exception_language != eLanguageTypeUnknown) 594fab10e89SJim Ingham break_type = eSetTypeException; 59530fdc8d8SChris Lattner 596b842f2ecSJim Ingham BreakpointSP bp_sp = nullptr; 597274060b6SGreg Clayton FileSpec module_spec; 598a8558b62SJim Ingham const bool internal = false; 599a8558b62SJim Ingham 600b9c1b51eSKate Stone // If the user didn't specify skip-prologue, having an offset should turn 601b9c1b51eSKate Stone // that off. 602b9c1b51eSKate Stone if (m_options.m_offset_addr != 0 && 603b9c1b51eSKate Stone m_options.m_skip_prologue == eLazyBoolCalculate) 6042411167fSJim Ingham m_options.m_skip_prologue = eLazyBoolNo; 6052411167fSJim Ingham 606b9c1b51eSKate Stone switch (break_type) { 60730fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 60830fdc8d8SChris Lattner { 60930fdc8d8SChris Lattner FileSpec file; 610c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 611b9c1b51eSKate Stone if (num_files == 0) { 612b9c1b51eSKate Stone if (!GetDefaultFile(target, file, result)) { 61387df91b8SJim Ingham result.AppendError("No file supplied and no default file available."); 61487df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 61587df91b8SJim Ingham return false; 61687df91b8SJim Ingham } 617b9c1b51eSKate Stone } else if (num_files > 1) { 618b9c1b51eSKate Stone result.AppendError("Only one file at a time is allowed for file and " 619b9c1b51eSKate Stone "line breakpoints."); 62087df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 62187df91b8SJim Ingham return false; 622b9c1b51eSKate Stone } else 62387df91b8SJim Ingham file = m_options.m_filenames.GetFileSpecAtIndex(0); 62430fdc8d8SChris Lattner 6251f746071SGreg Clayton // Only check for inline functions if 6261f746071SGreg Clayton LazyBool check_inlines = eLazyBoolCalculate; 6271f746071SGreg Clayton 628b842f2ecSJim Ingham bp_sp = target->CreateBreakpoint(&(m_options.m_modules), 629b842f2ecSJim Ingham file, 630b842f2ecSJim Ingham m_options.m_line_num, 631431b1584SAdrian Prantl m_options.m_column, 632b842f2ecSJim Ingham m_options.m_offset_addr, 633b842f2ecSJim Ingham check_inlines, 634b842f2ecSJim Ingham m_options.m_skip_prologue, 635b842f2ecSJim Ingham internal, 636b842f2ecSJim Ingham m_options.m_hardware, 637b842f2ecSJim Ingham m_options.m_move_to_nearest_code); 638b9c1b51eSKate Stone } break; 6396eee5aa0SGreg Clayton 64030fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 641055a08a4SJim Ingham { 642b9c1b51eSKate Stone // If a shared library has been specified, make an lldb_private::Address 643b842f2ecSJim Ingham // with the library, and use that. That way the address breakpoint 644b842f2ecSJim Ingham // will track the load location of the library. 645055a08a4SJim Ingham size_t num_modules_specified = m_options.m_modules.GetSize(); 646b9c1b51eSKate Stone if (num_modules_specified == 1) { 647b9c1b51eSKate Stone const FileSpec *file_spec = 648b9c1b51eSKate Stone m_options.m_modules.GetFileSpecPointerAtIndex(0); 649b842f2ecSJim Ingham bp_sp = target->CreateAddressInModuleBreakpoint(m_options.m_load_addr, 650b9c1b51eSKate Stone internal, file_spec, 651b842f2ecSJim Ingham m_options.m_hardware); 652b9c1b51eSKate Stone } else if (num_modules_specified == 0) { 653b842f2ecSJim Ingham bp_sp = target->CreateBreakpoint(m_options.m_load_addr, internal, 654b842f2ecSJim Ingham m_options.m_hardware); 655b9c1b51eSKate Stone } else { 656b9c1b51eSKate Stone result.AppendError("Only one shared library can be specified for " 657b9c1b51eSKate Stone "address breakpoints."); 658055a08a4SJim Ingham result.SetStatus(eReturnStatusFailed); 659055a08a4SJim Ingham return false; 660055a08a4SJim Ingham } 66130fdc8d8SChris Lattner break; 662055a08a4SJim Ingham } 66330fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 6640c5cd90dSGreg Clayton { 665117b1fa1SZachary Turner FunctionNameType name_type_mask = m_options.m_func_name_type_mask; 6660c5cd90dSGreg Clayton 6670c5cd90dSGreg Clayton if (name_type_mask == 0) 668e02b8504SGreg Clayton name_type_mask = eFunctionNameTypeAuto; 6690c5cd90dSGreg Clayton 670b842f2ecSJim Ingham bp_sp = target->CreateBreakpoint(&(m_options.m_modules), 671b842f2ecSJim Ingham &(m_options.m_filenames), 672b842f2ecSJim Ingham m_options.m_func_names, 673b842f2ecSJim Ingham name_type_mask, 674b842f2ecSJim Ingham m_options.m_language, 675b842f2ecSJim Ingham m_options.m_offset_addr, 676b842f2ecSJim Ingham m_options.m_skip_prologue, 677b842f2ecSJim Ingham internal, 678b842f2ecSJim Ingham m_options.m_hardware); 679b9c1b51eSKate Stone } break; 6800c5cd90dSGreg Clayton 681b9c1b51eSKate Stone case eSetTypeFunctionRegexp: // Breakpoint by regular expression function 682b9c1b51eSKate Stone // name 68330fdc8d8SChris Lattner { 68495eae423SZachary Turner RegularExpression regexp(m_options.m_func_regexp); 685b9c1b51eSKate Stone if (!regexp.IsValid()) { 686969795f1SJim Ingham char err_str[1024]; 687969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 688b9c1b51eSKate Stone result.AppendErrorWithFormat( 689b9c1b51eSKate Stone "Function name regular expression could not be compiled: \"%s\"", 690969795f1SJim Ingham err_str); 69130fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 692969795f1SJim Ingham return false; 69330fdc8d8SChris Lattner } 69487df91b8SJim Ingham 695b842f2ecSJim Ingham bp_sp = target->CreateFuncRegexBreakpoint(&(m_options.m_modules), 696b842f2ecSJim Ingham &(m_options.m_filenames), 697b842f2ecSJim Ingham regexp, 698b842f2ecSJim Ingham m_options.m_language, 699b842f2ecSJim Ingham m_options.m_skip_prologue, 700b842f2ecSJim Ingham internal, 701b842f2ecSJim Ingham m_options.m_hardware); 702e14dc268SJim Ingham } 703e14dc268SJim Ingham break; 704969795f1SJim Ingham case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. 705969795f1SJim Ingham { 706c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 70787df91b8SJim Ingham 708b9c1b51eSKate Stone if (num_files == 0 && !m_options.m_all_files) { 709969795f1SJim Ingham FileSpec file; 710b9c1b51eSKate Stone if (!GetDefaultFile(target, file, result)) { 711b9c1b51eSKate Stone result.AppendError( 712b9c1b51eSKate Stone "No files provided and could not find default file."); 71387df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 71487df91b8SJim Ingham return false; 715b9c1b51eSKate Stone } else { 71687df91b8SJim Ingham m_options.m_filenames.Append(file); 71787df91b8SJim Ingham } 71887df91b8SJim Ingham } 7190c5cd90dSGreg Clayton 72095eae423SZachary Turner RegularExpression regexp(m_options.m_source_text_regexp); 721b9c1b51eSKate Stone if (!regexp.IsValid()) { 722969795f1SJim Ingham char err_str[1024]; 723969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 724b9c1b51eSKate Stone result.AppendErrorWithFormat( 725b9c1b51eSKate Stone "Source text regular expression could not be compiled: \"%s\"", 726969795f1SJim Ingham err_str); 727969795f1SJim Ingham result.SetStatus(eReturnStatusFailed); 728969795f1SJim Ingham return false; 729969795f1SJim Ingham } 730b842f2ecSJim Ingham bp_sp = 731b842f2ecSJim Ingham target->CreateSourceRegexBreakpoint(&(m_options.m_modules), 732b842f2ecSJim Ingham &(m_options.m_filenames), 733b842f2ecSJim Ingham m_options 734b842f2ecSJim Ingham .m_source_regex_func_names, 735b842f2ecSJim Ingham regexp, 736b842f2ecSJim Ingham internal, 737b842f2ecSJim Ingham m_options.m_hardware, 738b842f2ecSJim Ingham m_options.m_move_to_nearest_code); 739b9c1b51eSKate Stone } break; 740b9c1b51eSKate Stone case eSetTypeException: { 74197206d57SZachary Turner Status precond_error; 742b842f2ecSJim Ingham bp_sp = target->CreateExceptionBreakpoint(m_options.m_exception_language, 743b842f2ecSJim Ingham m_options.m_catch_bp, 744b842f2ecSJim Ingham m_options.m_throw_bp, 745b842f2ecSJim Ingham internal, 746b842f2ecSJim Ingham &m_options 747b842f2ecSJim Ingham .m_exception_extra_args, 748b842f2ecSJim Ingham &precond_error); 749b9c1b51eSKate Stone if (precond_error.Fail()) { 750b9c1b51eSKate Stone result.AppendErrorWithFormat( 751b9c1b51eSKate Stone "Error setting extra exception arguments: %s", 752a72b31c7SJim Ingham precond_error.AsCString()); 753b842f2ecSJim Ingham target->RemoveBreakpointByID(bp_sp->GetID()); 754a72b31c7SJim Ingham result.SetStatus(eReturnStatusFailed); 755a72b31c7SJim Ingham return false; 756a72b31c7SJim Ingham } 757b9c1b51eSKate Stone } break; 7583815e702SJim Ingham case eSetTypeScripted: { 7593815e702SJim Ingham 7603815e702SJim Ingham Status error; 7613815e702SJim Ingham bp_sp = target->CreateScriptedBreakpoint(m_options.m_python_class, 7623815e702SJim Ingham &(m_options.m_modules), 7633815e702SJim Ingham &(m_options.m_filenames), 7643815e702SJim Ingham false, 7653815e702SJim Ingham m_options.m_hardware, 7663815e702SJim Ingham m_options.m_extra_args_sp, 7673815e702SJim Ingham &error); 7683815e702SJim Ingham if (error.Fail()) { 7693815e702SJim Ingham result.AppendErrorWithFormat( 7703815e702SJim Ingham "Error setting extra exception arguments: %s", 7713815e702SJim Ingham error.AsCString()); 7723815e702SJim Ingham target->RemoveBreakpointByID(bp_sp->GetID()); 7733815e702SJim Ingham result.SetStatus(eReturnStatusFailed); 7743815e702SJim Ingham return false; 7753815e702SJim Ingham } 7763815e702SJim Ingham } break; 77730fdc8d8SChris Lattner default: 77830fdc8d8SChris Lattner break; 77930fdc8d8SChris Lattner } 78030fdc8d8SChris Lattner 7811b54c88cSJim Ingham // Now set the various options that were passed in: 782b842f2ecSJim Ingham if (bp_sp) { 783b842f2ecSJim Ingham bp_sp->GetOptions()->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); 784ca36cd16SJim Ingham 785b9c1b51eSKate Stone if (!m_options.m_breakpoint_names.empty()) { 78697206d57SZachary Turner Status name_error; 787ff9a91eaSJim Ingham for (auto name : m_options.m_breakpoint_names) { 788b842f2ecSJim Ingham target->AddNameToBreakpoint(bp_sp, name.c_str(), name_error); 789ff9a91eaSJim Ingham if (name_error.Fail()) { 790ff9a91eaSJim Ingham result.AppendErrorWithFormat("Invalid breakpoint name: %s", 791ff9a91eaSJim Ingham name.c_str()); 792b842f2ecSJim Ingham target->RemoveBreakpointByID(bp_sp->GetID()); 793ff9a91eaSJim Ingham result.SetStatus(eReturnStatusFailed); 794ff9a91eaSJim Ingham return false; 795ff9a91eaSJim Ingham } 796ff9a91eaSJim Ingham } 7975e09c8c3SJim Ingham } 7981b54c88cSJim Ingham } 7991b54c88cSJim Ingham 800b842f2ecSJim Ingham if (bp_sp) { 80185e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 8021391cc7dSJim Ingham const bool show_locations = false; 803b842f2ecSJim Ingham bp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, 804b9c1b51eSKate Stone show_locations); 80557179860SJonas Devlieghere if (target == GetDebugger().GetDummyTarget()) 806b9c1b51eSKate Stone output_stream.Printf("Breakpoint set in dummy target, will get copied " 807b9c1b51eSKate Stone "into future targets.\n"); 808b9c1b51eSKate Stone else { 80905097246SAdrian Prantl // Don't print out this warning for exception breakpoints. They can 81005097246SAdrian Prantl // get set before the target is set, but we won't know how to actually 81105097246SAdrian Prantl // set the breakpoint till we run. 812b842f2ecSJim Ingham if (bp_sp->GetNumLocations() == 0 && break_type != eSetTypeException) { 813b9c1b51eSKate Stone output_stream.Printf("WARNING: Unable to resolve breakpoint to any " 814b9c1b51eSKate Stone "actual locations.\n"); 8154aeb1989SJim Ingham } 8164aeb1989SJim Ingham } 81730fdc8d8SChris Lattner result.SetStatus(eReturnStatusSuccessFinishResult); 818b842f2ecSJim Ingham } else if (!bp_sp) { 81930fdc8d8SChris Lattner result.AppendError("Breakpoint creation failed: No breakpoint created."); 82030fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 82130fdc8d8SChris Lattner } 82230fdc8d8SChris Lattner 82330fdc8d8SChris Lattner return result.Succeeded(); 82430fdc8d8SChris Lattner } 82530fdc8d8SChris Lattner 8265a988416SJim Ingham private: 827b9c1b51eSKate Stone bool GetDefaultFile(Target *target, FileSpec &file, 828b9c1b51eSKate Stone CommandReturnObject &result) { 8295a988416SJim Ingham uint32_t default_line; 83005097246SAdrian Prantl // First use the Source Manager's default file. Then use the current stack 83105097246SAdrian Prantl // frame's file. 832b9c1b51eSKate Stone if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) { 833b57e4a1bSJason Molenda StackFrame *cur_frame = m_exe_ctx.GetFramePtr(); 834b9c1b51eSKate Stone if (cur_frame == nullptr) { 835b9c1b51eSKate Stone result.AppendError( 836b9c1b51eSKate Stone "No selected frame to use to find the default file."); 8375a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 8385a988416SJim Ingham return false; 839b9c1b51eSKate Stone } else if (!cur_frame->HasDebugInformation()) { 840b9c1b51eSKate Stone result.AppendError("Cannot use the selected frame to find the default " 841b9c1b51eSKate Stone "file, it has no debug info."); 8425a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 8435a988416SJim Ingham return false; 844b9c1b51eSKate Stone } else { 845b9c1b51eSKate Stone const SymbolContext &sc = 846b9c1b51eSKate Stone cur_frame->GetSymbolContext(eSymbolContextLineEntry); 847b9c1b51eSKate Stone if (sc.line_entry.file) { 8485a988416SJim Ingham file = sc.line_entry.file; 849b9c1b51eSKate Stone } else { 850b9c1b51eSKate Stone result.AppendError("Can't find the file for the selected frame to " 851b9c1b51eSKate Stone "use as the default file."); 8525a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 8535a988416SJim Ingham return false; 8545a988416SJim Ingham } 8555a988416SJim Ingham } 8565a988416SJim Ingham } 8575a988416SJim Ingham return true; 8585a988416SJim Ingham } 8595a988416SJim Ingham 860b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 861b842f2ecSJim Ingham BreakpointDummyOptionGroup m_dummy_options; 8625a988416SJim Ingham CommandOptions m_options; 863b842f2ecSJim Ingham OptionGroupOptions m_all_options; 8645a988416SJim Ingham }; 8659e85e5a8SEugene Zelenko 8665a988416SJim Ingham // CommandObjectBreakpointModify 8675a988416SJim Ingham #pragma mark Modify 8685a988416SJim Ingham 869b9c1b51eSKate Stone class CommandObjectBreakpointModify : public CommandObjectParsed { 8705a988416SJim Ingham public: 871b9c1b51eSKate Stone CommandObjectBreakpointModify(CommandInterpreter &interpreter) 872b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "breakpoint modify", 873b9c1b51eSKate Stone "Modify the options on a breakpoint or set of " 874b9c1b51eSKate Stone "breakpoints in the executable. " 875b9c1b51eSKate Stone "If no breakpoint is specified, acts on the last " 876b9c1b51eSKate Stone "created breakpoint. " 877b9c1b51eSKate Stone "With the exception of -e, -d and -i, passing an " 878b9c1b51eSKate Stone "empty argument clears the modification.", 8799e85e5a8SEugene Zelenko nullptr), 880b9c1b51eSKate Stone m_options() { 8815a988416SJim Ingham CommandArgumentEntry arg; 882b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 883b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 884b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 885b9c1b51eSKate Stone // arguments vector. 8865a988416SJim Ingham m_arguments.push_back(arg); 887b842f2ecSJim Ingham 888b842f2ecSJim Ingham m_options.Append(&m_bp_opts, 889b842f2ecSJim Ingham LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3, 890b842f2ecSJim Ingham LLDB_OPT_SET_ALL); 891b842f2ecSJim Ingham m_options.Append(&m_dummy_opts, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 892b842f2ecSJim Ingham m_options.Finalize(); 8935a988416SJim Ingham } 8945a988416SJim Ingham 8959e85e5a8SEugene Zelenko ~CommandObjectBreakpointModify() override = default; 8965a988416SJim Ingham 897b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 8985a988416SJim Ingham 8995a988416SJim Ingham protected: 900b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 901b842f2ecSJim Ingham Target *target = GetSelectedOrDummyTarget(m_dummy_opts.m_use_dummy); 902b9c1b51eSKate Stone if (target == nullptr) { 9035a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 9045a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 9055a988416SJim Ingham return false; 9065a988416SJim Ingham } 9075a988416SJim Ingham 908bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 909bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 9105a988416SJim Ingham 9115a988416SJim Ingham BreakpointIDList valid_bp_ids; 9125a988416SJim Ingham 913b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 914b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 915b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 9165a988416SJim Ingham 917b9c1b51eSKate Stone if (result.Succeeded()) { 9185a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 919b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 9205a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 9215a988416SJim Ingham 922b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 923b9c1b51eSKate Stone Breakpoint *bp = 924b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 925b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 926b9c1b51eSKate Stone BreakpointLocation *location = 927b9c1b51eSKate Stone bp->FindLocationByID(cur_bp_id.GetLocationID()).get(); 928b842f2ecSJim Ingham if (location) 929b842f2ecSJim Ingham location->GetLocationOptions() 930b842f2ecSJim Ingham ->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); 931b9c1b51eSKate Stone } else { 932b842f2ecSJim Ingham bp->GetOptions() 933b842f2ecSJim Ingham ->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); 9345a988416SJim Ingham } 9355a988416SJim Ingham } 9365a988416SJim Ingham } 9375a988416SJim Ingham } 9385a988416SJim Ingham 9395a988416SJim Ingham return result.Succeeded(); 9405a988416SJim Ingham } 9415a988416SJim Ingham 9425a988416SJim Ingham private: 943b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 944b842f2ecSJim Ingham BreakpointDummyOptionGroup m_dummy_opts; 945b842f2ecSJim Ingham OptionGroupOptions m_options; 9465a988416SJim Ingham }; 9475a988416SJim Ingham 9485a988416SJim Ingham // CommandObjectBreakpointEnable 9495a988416SJim Ingham #pragma mark Enable 9505a988416SJim Ingham 951b9c1b51eSKate Stone class CommandObjectBreakpointEnable : public CommandObjectParsed { 9525a988416SJim Ingham public: 953b9c1b51eSKate Stone CommandObjectBreakpointEnable(CommandInterpreter &interpreter) 954b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "enable", 955b9c1b51eSKate Stone "Enable the specified disabled breakpoint(s). If " 956b9c1b51eSKate Stone "no breakpoints are specified, enable all of them.", 957b9c1b51eSKate Stone nullptr) { 9585a988416SJim Ingham CommandArgumentEntry arg; 959b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 960b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 961b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 962b9c1b51eSKate Stone // arguments vector. 9635a988416SJim Ingham m_arguments.push_back(arg); 9645a988416SJim Ingham } 9655a988416SJim Ingham 9669e85e5a8SEugene Zelenko ~CommandObjectBreakpointEnable() override = default; 9675a988416SJim Ingham 9685a988416SJim Ingham protected: 969b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 970893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 971b9c1b51eSKate Stone if (target == nullptr) { 9725a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 9735a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 9745a988416SJim Ingham return false; 9755a988416SJim Ingham } 9765a988416SJim Ingham 977bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 978bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 9795a988416SJim Ingham 9805a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 9815a988416SJim Ingham 9825a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 9835a988416SJim Ingham 984b9c1b51eSKate Stone if (num_breakpoints == 0) { 9855a988416SJim Ingham result.AppendError("No breakpoints exist to be enabled."); 9865a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 9875a988416SJim Ingham return false; 9885a988416SJim Ingham } 9895a988416SJim Ingham 99011eb9c64SZachary Turner if (command.empty()) { 9915a988416SJim Ingham // No breakpoint selected; enable all currently set breakpoints. 992b842f2ecSJim Ingham target->EnableAllowedBreakpoints(); 993b9c1b51eSKate Stone result.AppendMessageWithFormat("All breakpoints enabled. (%" PRIu64 994b9c1b51eSKate Stone " breakpoints)\n", 995b9c1b51eSKate Stone (uint64_t)num_breakpoints); 9965a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 997b9c1b51eSKate Stone } else { 9985a988416SJim Ingham // Particular breakpoint selected; enable that breakpoint. 9995a988416SJim Ingham BreakpointIDList valid_bp_ids; 1000b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1001b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1002b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 10035a988416SJim Ingham 1004b9c1b51eSKate Stone if (result.Succeeded()) { 10055a988416SJim Ingham int enable_count = 0; 10065a988416SJim Ingham int loc_count = 0; 10075a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1008b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 10095a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 10105a988416SJim Ingham 1011b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1012b9c1b51eSKate Stone Breakpoint *breakpoint = 1013b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1014b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1015b9c1b51eSKate Stone BreakpointLocation *location = 1016b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1017b9c1b51eSKate Stone if (location) { 10185a988416SJim Ingham location->SetEnabled(true); 10195a988416SJim Ingham ++loc_count; 10205a988416SJim Ingham } 1021b9c1b51eSKate Stone } else { 10225a988416SJim Ingham breakpoint->SetEnabled(true); 10235a988416SJim Ingham ++enable_count; 10245a988416SJim Ingham } 10255a988416SJim Ingham } 10265a988416SJim Ingham } 1027b9c1b51eSKate Stone result.AppendMessageWithFormat("%d breakpoints enabled.\n", 1028b9c1b51eSKate Stone enable_count + loc_count); 10295a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 10305a988416SJim Ingham } 10315a988416SJim Ingham } 10325a988416SJim Ingham 10335a988416SJim Ingham return result.Succeeded(); 10345a988416SJim Ingham } 10355a988416SJim Ingham }; 10365a988416SJim Ingham 10375a988416SJim Ingham // CommandObjectBreakpointDisable 10385a988416SJim Ingham #pragma mark Disable 10395a988416SJim Ingham 1040b9c1b51eSKate Stone class CommandObjectBreakpointDisable : public CommandObjectParsed { 10415a988416SJim Ingham public: 10427428a18cSKate Stone CommandObjectBreakpointDisable(CommandInterpreter &interpreter) 1043b9c1b51eSKate Stone : CommandObjectParsed( 1044b9c1b51eSKate Stone interpreter, "breakpoint disable", 1045b9c1b51eSKate Stone "Disable the specified breakpoint(s) without deleting " 10467428a18cSKate Stone "them. If none are specified, disable all " 10477428a18cSKate Stone "breakpoints.", 1048b9c1b51eSKate Stone nullptr) { 1049b9c1b51eSKate Stone SetHelpLong( 1050b9c1b51eSKate Stone "Disable the specified breakpoint(s) without deleting them. \ 10517428a18cSKate Stone If none are specified, disable all breakpoints." 10527428a18cSKate Stone R"( 1053ea671fbdSKate Stone 10547428a18cSKate Stone )" 10557428a18cSKate Stone "Note: disabling a breakpoint will cause none of its locations to be hit \ 10567428a18cSKate Stone regardless of whether individual locations are enabled or disabled. After the sequence:" 10577428a18cSKate Stone R"( 1058ea671fbdSKate Stone 1059ea671fbdSKate Stone (lldb) break disable 1 1060ea671fbdSKate Stone (lldb) break enable 1.1 1061ea671fbdSKate Stone 1062ea671fbdSKate Stone execution will NOT stop at location 1.1. To achieve that, type: 1063ea671fbdSKate Stone 1064ea671fbdSKate Stone (lldb) break disable 1.* 1065ea671fbdSKate Stone (lldb) break enable 1.1 1066ea671fbdSKate Stone 10677428a18cSKate Stone )" 10687428a18cSKate Stone "The first command disables all locations for breakpoint 1, \ 10697428a18cSKate Stone the second re-enables the first location."); 1070b0fac509SJim Ingham 10715a988416SJim Ingham CommandArgumentEntry arg; 1072b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1073b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1074b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1075b9c1b51eSKate Stone // arguments vector. 10765a988416SJim Ingham m_arguments.push_back(arg); 10775a988416SJim Ingham } 10785a988416SJim Ingham 10799e85e5a8SEugene Zelenko ~CommandObjectBreakpointDisable() override = default; 10805a988416SJim Ingham 10815a988416SJim Ingham protected: 1082b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1083893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1084b9c1b51eSKate Stone if (target == nullptr) { 10855a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 10865a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 10875a988416SJim Ingham return false; 10885a988416SJim Ingham } 10895a988416SJim Ingham 1090bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1091bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 10925a988416SJim Ingham 10935a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 10945a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 10955a988416SJim Ingham 1096b9c1b51eSKate Stone if (num_breakpoints == 0) { 10975a988416SJim Ingham result.AppendError("No breakpoints exist to be disabled."); 10985a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 10995a988416SJim Ingham return false; 11005a988416SJim Ingham } 11015a988416SJim Ingham 110211eb9c64SZachary Turner if (command.empty()) { 11035a988416SJim Ingham // No breakpoint selected; disable all currently set breakpoints. 1104b842f2ecSJim Ingham target->DisableAllowedBreakpoints(); 1105b9c1b51eSKate Stone result.AppendMessageWithFormat("All breakpoints disabled. (%" PRIu64 1106b9c1b51eSKate Stone " breakpoints)\n", 1107b9c1b51eSKate Stone (uint64_t)num_breakpoints); 11085a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1109b9c1b51eSKate Stone } else { 11105a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 11115a988416SJim Ingham BreakpointIDList valid_bp_ids; 11125a988416SJim Ingham 1113b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1114b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1115b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::disablePerm); 11165a988416SJim Ingham 1117b9c1b51eSKate Stone if (result.Succeeded()) { 11185a988416SJim Ingham int disable_count = 0; 11195a988416SJim Ingham int loc_count = 0; 11205a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1121b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 11225a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 11235a988416SJim Ingham 1124b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1125b9c1b51eSKate Stone Breakpoint *breakpoint = 1126b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1127b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1128b9c1b51eSKate Stone BreakpointLocation *location = 1129b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1130b9c1b51eSKate Stone if (location) { 11315a988416SJim Ingham location->SetEnabled(false); 11325a988416SJim Ingham ++loc_count; 11335a988416SJim Ingham } 1134b9c1b51eSKate Stone } else { 11355a988416SJim Ingham breakpoint->SetEnabled(false); 11365a988416SJim Ingham ++disable_count; 11375a988416SJim Ingham } 11385a988416SJim Ingham } 11395a988416SJim Ingham } 1140b9c1b51eSKate Stone result.AppendMessageWithFormat("%d breakpoints disabled.\n", 1141b9c1b51eSKate Stone disable_count + loc_count); 11425a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 11435a988416SJim Ingham } 11445a988416SJim Ingham } 11455a988416SJim Ingham 11465a988416SJim Ingham return result.Succeeded(); 11475a988416SJim Ingham } 11485a988416SJim Ingham }; 11495a988416SJim Ingham 11505a988416SJim Ingham // CommandObjectBreakpointList 11511f0f5b5bSZachary Turner 11521f0f5b5bSZachary Turner #pragma mark List::CommandOptions 11536f4fb4e7SRaphael Isemann #define LLDB_OPTIONS_breakpoint_list 1154c5a2d747SRaphael Isemann #include "CommandOptions.inc" 11551f0f5b5bSZachary Turner 11565a988416SJim Ingham #pragma mark List 11575a988416SJim Ingham 1158b9c1b51eSKate Stone class CommandObjectBreakpointList : public CommandObjectParsed { 11595a988416SJim Ingham public: 1160b9c1b51eSKate Stone CommandObjectBreakpointList(CommandInterpreter &interpreter) 1161b9c1b51eSKate Stone : CommandObjectParsed( 1162b9c1b51eSKate Stone interpreter, "breakpoint list", 11635a988416SJim Ingham "List some or all breakpoints at configurable levels of detail.", 11649e85e5a8SEugene Zelenko nullptr), 1165b9c1b51eSKate Stone m_options() { 11665a988416SJim Ingham CommandArgumentEntry arg; 11675a988416SJim Ingham CommandArgumentData bp_id_arg; 11685a988416SJim Ingham 11695a988416SJim Ingham // Define the first (and only) variant of this arg. 11705a988416SJim Ingham bp_id_arg.arg_type = eArgTypeBreakpointID; 11715a988416SJim Ingham bp_id_arg.arg_repetition = eArgRepeatOptional; 11725a988416SJim Ingham 1173b9c1b51eSKate Stone // There is only one variant this argument could be; put it into the 1174b9c1b51eSKate Stone // argument entry. 11755a988416SJim Ingham arg.push_back(bp_id_arg); 11765a988416SJim Ingham 11775a988416SJim Ingham // Push the data for the first argument into the m_arguments vector. 11785a988416SJim Ingham m_arguments.push_back(arg); 11795a988416SJim Ingham } 11805a988416SJim Ingham 11819e85e5a8SEugene Zelenko ~CommandObjectBreakpointList() override = default; 11825a988416SJim Ingham 1183b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 11845a988416SJim Ingham 1185b9c1b51eSKate Stone class CommandOptions : public Options { 11865a988416SJim Ingham public: 1187b9c1b51eSKate Stone CommandOptions() 1188b9c1b51eSKate Stone : Options(), m_level(lldb::eDescriptionLevelBrief), m_use_dummy(false) { 11895a988416SJim Ingham } 11905a988416SJim Ingham 11919e85e5a8SEugene Zelenko ~CommandOptions() override = default; 11925a988416SJim Ingham 119397206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1194b9c1b51eSKate Stone ExecutionContext *execution_context) override { 119597206d57SZachary Turner Status error; 11963bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 11975a988416SJim Ingham 1198b9c1b51eSKate Stone switch (short_option) { 11995a988416SJim Ingham case 'b': 12005a988416SJim Ingham m_level = lldb::eDescriptionLevelBrief; 12015a988416SJim Ingham break; 120233df7cd3SJim Ingham case 'D': 120333df7cd3SJim Ingham m_use_dummy = true; 120433df7cd3SJim Ingham break; 12055a988416SJim Ingham case 'f': 12065a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 12075a988416SJim Ingham break; 12085a988416SJim Ingham case 'v': 12095a988416SJim Ingham m_level = lldb::eDescriptionLevelVerbose; 12105a988416SJim Ingham break; 12115a988416SJim Ingham case 'i': 12125a988416SJim Ingham m_internal = true; 12135a988416SJim Ingham break; 12145a988416SJim Ingham default: 1215b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1216b9c1b51eSKate Stone short_option); 12175a988416SJim Ingham break; 12185a988416SJim Ingham } 12195a988416SJim Ingham 12205a988416SJim Ingham return error; 12215a988416SJim Ingham } 12225a988416SJim Ingham 1223b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 12245a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 12255a988416SJim Ingham m_internal = false; 122633df7cd3SJim Ingham m_use_dummy = false; 12275a988416SJim Ingham } 12285a988416SJim Ingham 12291f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 123070602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_list_options); 12311f0f5b5bSZachary Turner } 12325a988416SJim Ingham 12335a988416SJim Ingham // Instance variables to hold the values for command options. 12345a988416SJim Ingham 12355a988416SJim Ingham lldb::DescriptionLevel m_level; 12365a988416SJim Ingham 12375a988416SJim Ingham bool m_internal; 123833df7cd3SJim Ingham bool m_use_dummy; 12395a988416SJim Ingham }; 12405a988416SJim Ingham 12415a988416SJim Ingham protected: 1242b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 124333df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 124433df7cd3SJim Ingham 1245b9c1b51eSKate Stone if (target == nullptr) { 12465a988416SJim Ingham result.AppendError("Invalid target. No current target or breakpoints."); 12475a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 12485a988416SJim Ingham return true; 12495a988416SJim Ingham } 12505a988416SJim Ingham 1251b9c1b51eSKate Stone const BreakpointList &breakpoints = 1252b9c1b51eSKate Stone target->GetBreakpointList(m_options.m_internal); 1253bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1254bb19a13cSSaleem Abdulrasool target->GetBreakpointList(m_options.m_internal).GetListMutex(lock); 12555a988416SJim Ingham 12565a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 12575a988416SJim Ingham 1258b9c1b51eSKate Stone if (num_breakpoints == 0) { 12595a988416SJim Ingham result.AppendMessage("No breakpoints currently set."); 12605a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 12615a988416SJim Ingham return true; 12625a988416SJim Ingham } 12635a988416SJim Ingham 12645a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 12655a988416SJim Ingham 126611eb9c64SZachary Turner if (command.empty()) { 12675a988416SJim Ingham // No breakpoint selected; show info about all currently set breakpoints. 12685a988416SJim Ingham result.AppendMessage("Current breakpoints:"); 1269b9c1b51eSKate Stone for (size_t i = 0; i < num_breakpoints; ++i) { 12705a988416SJim Ingham Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex(i).get(); 1271b842f2ecSJim Ingham if (breakpoint->AllowList()) 1272b842f2ecSJim Ingham AddBreakpointDescription(&output_stream, breakpoint, 1273b842f2ecSJim Ingham m_options.m_level); 12745a988416SJim Ingham } 12755a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1276b9c1b51eSKate Stone } else { 12775a988416SJim Ingham // Particular breakpoints selected; show info about that breakpoint. 12785a988416SJim Ingham BreakpointIDList valid_bp_ids; 1279b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1280b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1281b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 12825a988416SJim Ingham 1283b9c1b51eSKate Stone if (result.Succeeded()) { 1284b9c1b51eSKate Stone for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) { 12855a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 1286b9c1b51eSKate Stone Breakpoint *breakpoint = 1287b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1288b9c1b51eSKate Stone AddBreakpointDescription(&output_stream, breakpoint, 1289b9c1b51eSKate Stone m_options.m_level); 12905a988416SJim Ingham } 12915a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1292b9c1b51eSKate Stone } else { 12937428a18cSKate Stone result.AppendError("Invalid breakpoint ID."); 12945a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 12955a988416SJim Ingham } 12965a988416SJim Ingham } 12975a988416SJim Ingham 12985a988416SJim Ingham return result.Succeeded(); 12995a988416SJim Ingham } 13005a988416SJim Ingham 13015a988416SJim Ingham private: 13025a988416SJim Ingham CommandOptions m_options; 13035a988416SJim Ingham }; 13045a988416SJim Ingham 13055a988416SJim Ingham // CommandObjectBreakpointClear 13061f0f5b5bSZachary Turner #pragma mark Clear::CommandOptions 13071f0f5b5bSZachary Turner 1308f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_clear 1309f94668e3SRaphael Isemann #include "CommandOptions.inc" 13101f0f5b5bSZachary Turner 13115a988416SJim Ingham #pragma mark Clear 13125a988416SJim Ingham 1313b9c1b51eSKate Stone class CommandObjectBreakpointClear : public CommandObjectParsed { 13145a988416SJim Ingham public: 1315efe8e7e3SFangrui Song enum BreakpointClearType { eClearTypeInvalid, eClearTypeFileAndLine }; 13165a988416SJim Ingham 13177428a18cSKate Stone CommandObjectBreakpointClear(CommandInterpreter &interpreter) 13187428a18cSKate Stone : CommandObjectParsed(interpreter, "breakpoint clear", 1319b9c1b51eSKate Stone "Delete or disable breakpoints matching the " 1320b9c1b51eSKate Stone "specified source file and line.", 13215a988416SJim Ingham "breakpoint clear <cmd-options>"), 1322b9c1b51eSKate Stone m_options() {} 13235a988416SJim Ingham 13249e85e5a8SEugene Zelenko ~CommandObjectBreakpointClear() override = default; 13255a988416SJim Ingham 1326b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 13275a988416SJim Ingham 1328b9c1b51eSKate Stone class CommandOptions : public Options { 13295a988416SJim Ingham public: 1330b9c1b51eSKate Stone CommandOptions() : Options(), m_filename(), m_line_num(0) {} 13315a988416SJim Ingham 13329e85e5a8SEugene Zelenko ~CommandOptions() override = default; 13335a988416SJim Ingham 133497206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1335b9c1b51eSKate Stone ExecutionContext *execution_context) override { 133697206d57SZachary Turner Status error; 13373bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 13385a988416SJim Ingham 1339b9c1b51eSKate Stone switch (short_option) { 13405a988416SJim Ingham case 'f': 13415a988416SJim Ingham m_filename.assign(option_arg); 13425a988416SJim Ingham break; 13435a988416SJim Ingham 13445a988416SJim Ingham case 'l': 1345fe11483bSZachary Turner option_arg.getAsInteger(0, m_line_num); 13465a988416SJim Ingham break; 13475a988416SJim Ingham 13485a988416SJim Ingham default: 1349b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1350b9c1b51eSKate Stone short_option); 13515a988416SJim Ingham break; 13525a988416SJim Ingham } 13535a988416SJim Ingham 13545a988416SJim Ingham return error; 13555a988416SJim Ingham } 13565a988416SJim Ingham 1357b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 13585a988416SJim Ingham m_filename.clear(); 13595a988416SJim Ingham m_line_num = 0; 13605a988416SJim Ingham } 13615a988416SJim Ingham 13621f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 136370602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_clear_options); 13641f0f5b5bSZachary Turner } 13655a988416SJim Ingham 13665a988416SJim Ingham // Instance variables to hold the values for command options. 13675a988416SJim Ingham 13685a988416SJim Ingham std::string m_filename; 13695a988416SJim Ingham uint32_t m_line_num; 13705a988416SJim Ingham }; 13715a988416SJim Ingham 13725a988416SJim Ingham protected: 1373b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1374893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1375b9c1b51eSKate Stone if (target == nullptr) { 13765a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 13775a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 13785a988416SJim Ingham return false; 13795a988416SJim Ingham } 13805a988416SJim Ingham 138105097246SAdrian Prantl // The following are the various types of breakpoints that could be 138205097246SAdrian Prantl // cleared: 13835a988416SJim Ingham // 1). -f -l (clearing breakpoint by source location) 13845a988416SJim Ingham 13855a988416SJim Ingham BreakpointClearType break_type = eClearTypeInvalid; 13865a988416SJim Ingham 13875a988416SJim Ingham if (m_options.m_line_num != 0) 13885a988416SJim Ingham break_type = eClearTypeFileAndLine; 13895a988416SJim Ingham 1390bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1391bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 13925a988416SJim Ingham 13935a988416SJim Ingham BreakpointList &breakpoints = target->GetBreakpointList(); 13945a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 13955a988416SJim Ingham 13965a988416SJim Ingham // Early return if there's no breakpoint at all. 1397b9c1b51eSKate Stone if (num_breakpoints == 0) { 13985a988416SJim Ingham result.AppendError("Breakpoint clear: No breakpoint cleared."); 13995a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 14005a988416SJim Ingham return result.Succeeded(); 14015a988416SJim Ingham } 14025a988416SJim Ingham 14035a988416SJim Ingham // Find matching breakpoints and delete them. 14045a988416SJim Ingham 14055a988416SJim Ingham // First create a copy of all the IDs. 14065a988416SJim Ingham std::vector<break_id_t> BreakIDs; 14075a988416SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) 14089e85e5a8SEugene Zelenko BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID()); 14095a988416SJim Ingham 14105a988416SJim Ingham int num_cleared = 0; 14115a988416SJim Ingham StreamString ss; 1412b9c1b51eSKate Stone switch (break_type) { 14135a988416SJim Ingham case eClearTypeFileAndLine: // Breakpoint by source position 14145a988416SJim Ingham { 14155a988416SJim Ingham const ConstString filename(m_options.m_filename.c_str()); 14165a988416SJim Ingham BreakpointLocationCollection loc_coll; 14175a988416SJim Ingham 1418b9c1b51eSKate Stone for (size_t i = 0; i < num_breakpoints; ++i) { 14195a988416SJim Ingham Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); 14205a988416SJim Ingham 1421b9c1b51eSKate Stone if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) { 1422b9c1b51eSKate Stone // If the collection size is 0, it's a full match and we can just 1423b9c1b51eSKate Stone // remove the breakpoint. 1424b9c1b51eSKate Stone if (loc_coll.GetSize() == 0) { 14255a988416SJim Ingham bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); 14265a988416SJim Ingham ss.EOL(); 14275a988416SJim Ingham target->RemoveBreakpointByID(bp->GetID()); 14285a988416SJim Ingham ++num_cleared; 14295a988416SJim Ingham } 14305a988416SJim Ingham } 14315a988416SJim Ingham } 1432b9c1b51eSKate Stone } break; 14335a988416SJim Ingham 14345a988416SJim Ingham default: 14355a988416SJim Ingham break; 14365a988416SJim Ingham } 14375a988416SJim Ingham 1438b9c1b51eSKate Stone if (num_cleared > 0) { 14395a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 14405a988416SJim Ingham output_stream.Printf("%d breakpoints cleared:\n", num_cleared); 1441c156427dSZachary Turner output_stream << ss.GetString(); 14425a988416SJim Ingham output_stream.EOL(); 14435a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1444b9c1b51eSKate Stone } else { 14455a988416SJim Ingham result.AppendError("Breakpoint clear: No breakpoint cleared."); 14465a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 14475a988416SJim Ingham } 14485a988416SJim Ingham 14495a988416SJim Ingham return result.Succeeded(); 14505a988416SJim Ingham } 14515a988416SJim Ingham 14525a988416SJim Ingham private: 14535a988416SJim Ingham CommandOptions m_options; 14545a988416SJim Ingham }; 14555a988416SJim Ingham 14565a988416SJim Ingham // CommandObjectBreakpointDelete 1457f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_delete 1458f94668e3SRaphael Isemann #include "CommandOptions.inc" 14591f0f5b5bSZachary Turner 14605a988416SJim Ingham #pragma mark Delete 14615a988416SJim Ingham 1462b9c1b51eSKate Stone class CommandObjectBreakpointDelete : public CommandObjectParsed { 14635a988416SJim Ingham public: 1464b9c1b51eSKate Stone CommandObjectBreakpointDelete(CommandInterpreter &interpreter) 1465b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "breakpoint delete", 1466b9c1b51eSKate Stone "Delete the specified breakpoint(s). If no " 1467b9c1b51eSKate Stone "breakpoints are specified, delete them all.", 14689e85e5a8SEugene Zelenko nullptr), 1469b9c1b51eSKate Stone m_options() { 14705a988416SJim Ingham CommandArgumentEntry arg; 1471b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1472b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1473b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1474b9c1b51eSKate Stone // arguments vector. 14755a988416SJim Ingham m_arguments.push_back(arg); 14765a988416SJim Ingham } 14775a988416SJim Ingham 14789e85e5a8SEugene Zelenko ~CommandObjectBreakpointDelete() override = default; 14795a988416SJim Ingham 1480b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 148133df7cd3SJim Ingham 1482b9c1b51eSKate Stone class CommandOptions : public Options { 148333df7cd3SJim Ingham public: 1484b9c1b51eSKate Stone CommandOptions() : Options(), m_use_dummy(false), m_force(false) {} 148533df7cd3SJim Ingham 14869e85e5a8SEugene Zelenko ~CommandOptions() override = default; 148733df7cd3SJim Ingham 148897206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1489b9c1b51eSKate Stone ExecutionContext *execution_context) override { 149097206d57SZachary Turner Status error; 149133df7cd3SJim Ingham const int short_option = m_getopt_table[option_idx].val; 149233df7cd3SJim Ingham 1493b9c1b51eSKate Stone switch (short_option) { 149433df7cd3SJim Ingham case 'f': 149533df7cd3SJim Ingham m_force = true; 149633df7cd3SJim Ingham break; 149733df7cd3SJim Ingham 149833df7cd3SJim Ingham case 'D': 149933df7cd3SJim Ingham m_use_dummy = true; 150033df7cd3SJim Ingham break; 150133df7cd3SJim Ingham 150233df7cd3SJim Ingham default: 1503b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1504b9c1b51eSKate Stone short_option); 150533df7cd3SJim Ingham break; 150633df7cd3SJim Ingham } 150733df7cd3SJim Ingham 150833df7cd3SJim Ingham return error; 150933df7cd3SJim Ingham } 151033df7cd3SJim Ingham 1511b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 151233df7cd3SJim Ingham m_use_dummy = false; 151333df7cd3SJim Ingham m_force = false; 151433df7cd3SJim Ingham } 151533df7cd3SJim Ingham 15161f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 151770602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_delete_options); 15181f0f5b5bSZachary Turner } 151933df7cd3SJim Ingham 152033df7cd3SJim Ingham // Instance variables to hold the values for command options. 152133df7cd3SJim Ingham bool m_use_dummy; 152233df7cd3SJim Ingham bool m_force; 152333df7cd3SJim Ingham }; 152433df7cd3SJim Ingham 15255a988416SJim Ingham protected: 1526b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 152733df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 152833df7cd3SJim Ingham 1529b9c1b51eSKate Stone if (target == nullptr) { 15305a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 15315a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 15325a988416SJim Ingham return false; 15335a988416SJim Ingham } 15345a988416SJim Ingham 1535bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1536bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 15375a988416SJim Ingham 15385a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 15395a988416SJim Ingham 15405a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 15415a988416SJim Ingham 1542b9c1b51eSKate Stone if (num_breakpoints == 0) { 15435a988416SJim Ingham result.AppendError("No breakpoints exist to be deleted."); 15445a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 15455a988416SJim Ingham return false; 15465a988416SJim Ingham } 15475a988416SJim Ingham 154811eb9c64SZachary Turner if (command.empty()) { 1549b9c1b51eSKate Stone if (!m_options.m_force && 1550b9c1b51eSKate Stone !m_interpreter.Confirm( 1551b9c1b51eSKate Stone "About to delete all breakpoints, do you want to do that?", 1552b9c1b51eSKate Stone true)) { 15535a988416SJim Ingham result.AppendMessage("Operation cancelled..."); 1554b9c1b51eSKate Stone } else { 1555b842f2ecSJim Ingham target->RemoveAllowedBreakpoints(); 1556b9c1b51eSKate Stone result.AppendMessageWithFormat( 1557b9c1b51eSKate Stone "All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", 1558b9c1b51eSKate Stone (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : ""); 15595a988416SJim Ingham } 15605a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1561b9c1b51eSKate Stone } else { 15625a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 15635a988416SJim Ingham BreakpointIDList valid_bp_ids; 1564b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1565b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1566b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::deletePerm); 15675a988416SJim Ingham 1568b9c1b51eSKate Stone if (result.Succeeded()) { 15695a988416SJim Ingham int delete_count = 0; 15705a988416SJim Ingham int disable_count = 0; 15715a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1572b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 15735a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 15745a988416SJim Ingham 1575b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1576b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1577b9c1b51eSKate Stone Breakpoint *breakpoint = 1578b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1579b9c1b51eSKate Stone BreakpointLocation *location = 1580b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1581b9c1b51eSKate Stone // It makes no sense to try to delete individual locations, so we 1582b9c1b51eSKate Stone // disable them instead. 1583b9c1b51eSKate Stone if (location) { 15845a988416SJim Ingham location->SetEnabled(false); 15855a988416SJim Ingham ++disable_count; 15865a988416SJim Ingham } 1587b9c1b51eSKate Stone } else { 15885a988416SJim Ingham target->RemoveBreakpointByID(cur_bp_id.GetBreakpointID()); 15895a988416SJim Ingham ++delete_count; 15905a988416SJim Ingham } 15915a988416SJim Ingham } 15925a988416SJim Ingham } 1593b9c1b51eSKate Stone result.AppendMessageWithFormat( 1594b9c1b51eSKate Stone "%d breakpoints deleted; %d breakpoint locations disabled.\n", 15955a988416SJim Ingham delete_count, disable_count); 15965a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 15975a988416SJim Ingham } 15985a988416SJim Ingham } 15995a988416SJim Ingham return result.Succeeded(); 16005a988416SJim Ingham } 16019e85e5a8SEugene Zelenko 160233df7cd3SJim Ingham private: 160333df7cd3SJim Ingham CommandOptions m_options; 160433df7cd3SJim Ingham }; 160533df7cd3SJim Ingham 16065e09c8c3SJim Ingham // CommandObjectBreakpointName 1607f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_name 1608f94668e3SRaphael Isemann #include "CommandOptions.inc" 1609*bd68a052SRaphael Isemann 1610b9c1b51eSKate Stone class BreakpointNameOptionGroup : public OptionGroup { 16115e09c8c3SJim Ingham public: 1612b9c1b51eSKate Stone BreakpointNameOptionGroup() 1613b9c1b51eSKate Stone : OptionGroup(), m_breakpoint(LLDB_INVALID_BREAK_ID), m_use_dummy(false) { 16145e09c8c3SJim Ingham } 16155e09c8c3SJim Ingham 16169e85e5a8SEugene Zelenko ~BreakpointNameOptionGroup() override = default; 16175e09c8c3SJim Ingham 16181f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 161970602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_name_options); 16205e09c8c3SJim Ingham } 16215e09c8c3SJim Ingham 162297206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1623b9c1b51eSKate Stone ExecutionContext *execution_context) override { 162497206d57SZachary Turner Status error; 16255e09c8c3SJim Ingham const int short_option = g_breakpoint_name_options[option_idx].short_option; 16265e09c8c3SJim Ingham 1627b9c1b51eSKate Stone switch (short_option) { 16285e09c8c3SJim Ingham case 'N': 1629fe11483bSZachary Turner if (BreakpointID::StringIsBreakpointName(option_arg, error) && 1630b9c1b51eSKate Stone error.Success()) 1631fe11483bSZachary Turner m_name.SetValueFromString(option_arg); 16325e09c8c3SJim Ingham break; 16335e09c8c3SJim Ingham case 'B': 1634fe11483bSZachary Turner if (m_breakpoint.SetValueFromString(option_arg).Fail()) 1635b9c1b51eSKate Stone error.SetErrorStringWithFormat( 16368cef4b0bSZachary Turner "unrecognized value \"%s\" for breakpoint", 1637fe11483bSZachary Turner option_arg.str().c_str()); 16385e09c8c3SJim Ingham break; 16395e09c8c3SJim Ingham case 'D': 1640fe11483bSZachary Turner if (m_use_dummy.SetValueFromString(option_arg).Fail()) 1641b9c1b51eSKate Stone error.SetErrorStringWithFormat( 16428cef4b0bSZachary Turner "unrecognized value \"%s\" for use-dummy", 1643fe11483bSZachary Turner option_arg.str().c_str()); 16445e09c8c3SJim Ingham break; 1645e9632ebaSJim Ingham case 'H': 1646e9632ebaSJim Ingham m_help_string.SetValueFromString(option_arg); 1647e9632ebaSJim Ingham break; 16485e09c8c3SJim Ingham 16495e09c8c3SJim Ingham default: 1650b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized short option '%c'", 1651b9c1b51eSKate Stone short_option); 16525e09c8c3SJim Ingham break; 16535e09c8c3SJim Ingham } 16545e09c8c3SJim Ingham return error; 16555e09c8c3SJim Ingham } 16565e09c8c3SJim Ingham 1657b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 16585e09c8c3SJim Ingham m_name.Clear(); 16595e09c8c3SJim Ingham m_breakpoint.Clear(); 16605e09c8c3SJim Ingham m_use_dummy.Clear(); 16615e09c8c3SJim Ingham m_use_dummy.SetDefaultValue(false); 1662e9632ebaSJim Ingham m_help_string.Clear(); 16635e09c8c3SJim Ingham } 16645e09c8c3SJim Ingham 16655e09c8c3SJim Ingham OptionValueString m_name; 16665e09c8c3SJim Ingham OptionValueUInt64 m_breakpoint; 16675e09c8c3SJim Ingham OptionValueBoolean m_use_dummy; 1668e9632ebaSJim Ingham OptionValueString m_help_string; 16695e09c8c3SJim Ingham }; 16705e09c8c3SJim Ingham 1671f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_access 1672f94668e3SRaphael Isemann #include "CommandOptions.inc" 1673b842f2ecSJim Ingham 16748fe53c49STatyana Krasnukha class BreakpointAccessOptionGroup : public OptionGroup { 1675b842f2ecSJim Ingham public: 16768fe53c49STatyana Krasnukha BreakpointAccessOptionGroup() : OptionGroup() {} 1677b842f2ecSJim Ingham 1678b842f2ecSJim Ingham ~BreakpointAccessOptionGroup() override = default; 1679b842f2ecSJim Ingham 1680b842f2ecSJim Ingham llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 1681b842f2ecSJim Ingham return llvm::makeArrayRef(g_breakpoint_access_options); 1682b842f2ecSJim Ingham } 1683b842f2ecSJim Ingham Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1684b842f2ecSJim Ingham ExecutionContext *execution_context) override { 1685b842f2ecSJim Ingham Status error; 1686b842f2ecSJim Ingham const int short_option 1687b842f2ecSJim Ingham = g_breakpoint_access_options[option_idx].short_option; 1688b842f2ecSJim Ingham 1689b842f2ecSJim Ingham switch (short_option) { 1690b842f2ecSJim Ingham case 'L': { 1691b842f2ecSJim Ingham bool value, success; 169247cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1693b842f2ecSJim Ingham if (success) { 1694b842f2ecSJim Ingham m_permissions.SetAllowList(value); 1695b842f2ecSJim Ingham } else 1696b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1697b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1698b842f2ecSJim Ingham option_arg.str().c_str()); 1699b842f2ecSJim Ingham } break; 1700b842f2ecSJim Ingham case 'A': { 1701b842f2ecSJim Ingham bool value, success; 170247cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1703b842f2ecSJim Ingham if (success) { 1704b842f2ecSJim Ingham m_permissions.SetAllowDisable(value); 1705b842f2ecSJim Ingham } else 1706b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1707b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1708b842f2ecSJim Ingham option_arg.str().c_str()); 1709b842f2ecSJim Ingham } break; 1710b842f2ecSJim Ingham case 'D': { 1711b842f2ecSJim Ingham bool value, success; 171247cbf4a0SPavel Labath value = OptionArgParser::ToBoolean(option_arg, false, &success); 1713b842f2ecSJim Ingham if (success) { 1714b842f2ecSJim Ingham m_permissions.SetAllowDelete(value); 1715b842f2ecSJim Ingham } else 1716b842f2ecSJim Ingham error.SetErrorStringWithFormat( 1717b842f2ecSJim Ingham "invalid boolean value '%s' passed for -L option", 1718b842f2ecSJim Ingham option_arg.str().c_str()); 1719b842f2ecSJim Ingham } break; 1720b842f2ecSJim Ingham 1721b842f2ecSJim Ingham } 1722b842f2ecSJim Ingham 1723b842f2ecSJim Ingham return error; 1724b842f2ecSJim Ingham } 1725b842f2ecSJim Ingham 1726b842f2ecSJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 1727b842f2ecSJim Ingham } 1728b842f2ecSJim Ingham 1729b842f2ecSJim Ingham const BreakpointName::Permissions &GetPermissions() const 1730b842f2ecSJim Ingham { 1731b842f2ecSJim Ingham return m_permissions; 1732b842f2ecSJim Ingham } 1733b842f2ecSJim Ingham BreakpointName::Permissions m_permissions; 1734b842f2ecSJim Ingham }; 1735b842f2ecSJim Ingham 1736b842f2ecSJim Ingham class CommandObjectBreakpointNameConfigure : public CommandObjectParsed { 1737b842f2ecSJim Ingham public: 1738b842f2ecSJim Ingham CommandObjectBreakpointNameConfigure(CommandInterpreter &interpreter) 1739b842f2ecSJim Ingham : CommandObjectParsed( 1740b842f2ecSJim Ingham interpreter, "configure", "Configure the options for the breakpoint" 1741b842f2ecSJim Ingham " name provided. " 1742b842f2ecSJim Ingham "If you provide a breakpoint id, the options will be copied from " 1743b842f2ecSJim Ingham "the breakpoint, otherwise only the options specified will be set " 1744b842f2ecSJim Ingham "on the name.", 1745b842f2ecSJim Ingham "breakpoint name configure <command-options> " 1746b842f2ecSJim Ingham "<breakpoint-name-list>"), 1747b842f2ecSJim Ingham m_bp_opts(), m_option_group() { 1748b842f2ecSJim Ingham // Create the first variant for the first (and only) argument for this 1749b842f2ecSJim Ingham // command. 1750b842f2ecSJim Ingham CommandArgumentEntry arg1; 1751b842f2ecSJim Ingham CommandArgumentData id_arg; 1752b842f2ecSJim Ingham id_arg.arg_type = eArgTypeBreakpointName; 1753b842f2ecSJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 1754b842f2ecSJim Ingham arg1.push_back(id_arg); 1755b842f2ecSJim Ingham m_arguments.push_back(arg1); 1756b842f2ecSJim Ingham 1757b842f2ecSJim Ingham m_option_group.Append(&m_bp_opts, 1758b842f2ecSJim Ingham LLDB_OPT_SET_ALL, 1759b842f2ecSJim Ingham LLDB_OPT_SET_1); 1760b842f2ecSJim Ingham m_option_group.Append(&m_access_options, 1761b842f2ecSJim Ingham LLDB_OPT_SET_ALL, 1762b842f2ecSJim Ingham LLDB_OPT_SET_ALL); 1763e9632ebaSJim Ingham m_option_group.Append(&m_bp_id, 1764e9632ebaSJim Ingham LLDB_OPT_SET_2|LLDB_OPT_SET_4, 1765e9632ebaSJim Ingham LLDB_OPT_SET_ALL); 1766b842f2ecSJim Ingham m_option_group.Finalize(); 1767b842f2ecSJim Ingham } 1768b842f2ecSJim Ingham 1769b842f2ecSJim Ingham ~CommandObjectBreakpointNameConfigure() override = default; 1770b842f2ecSJim Ingham 1771b842f2ecSJim Ingham Options *GetOptions() override { return &m_option_group; } 1772b842f2ecSJim Ingham 1773b842f2ecSJim Ingham protected: 1774b842f2ecSJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 1775b842f2ecSJim Ingham 1776b842f2ecSJim Ingham const size_t argc = command.GetArgumentCount(); 1777b842f2ecSJim Ingham if (argc == 0) { 1778b842f2ecSJim Ingham result.AppendError("No names provided."); 1779b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1780b842f2ecSJim Ingham return false; 1781b842f2ecSJim Ingham } 1782b842f2ecSJim Ingham 1783b842f2ecSJim Ingham Target *target = 1784b842f2ecSJim Ingham GetSelectedOrDummyTarget(false); 1785b842f2ecSJim Ingham 1786b842f2ecSJim Ingham if (target == nullptr) { 1787b842f2ecSJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 1788b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1789b842f2ecSJim Ingham return false; 1790b842f2ecSJim Ingham } 1791b842f2ecSJim Ingham 1792b842f2ecSJim Ingham std::unique_lock<std::recursive_mutex> lock; 1793b842f2ecSJim Ingham target->GetBreakpointList().GetListMutex(lock); 1794b842f2ecSJim Ingham 1795b842f2ecSJim Ingham // Make a pass through first to see that all the names are legal. 1796b842f2ecSJim Ingham for (auto &entry : command.entries()) { 1797b842f2ecSJim Ingham Status error; 1798b842f2ecSJim Ingham if (!BreakpointID::StringIsBreakpointName(entry.ref, error)) 1799b842f2ecSJim Ingham { 1800b842f2ecSJim Ingham result.AppendErrorWithFormat("Invalid breakpoint name: %s - %s", 1801b842f2ecSJim Ingham entry.c_str(), error.AsCString()); 1802b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1803b842f2ecSJim Ingham return false; 1804b842f2ecSJim Ingham } 1805b842f2ecSJim Ingham } 180605097246SAdrian Prantl // Now configure them, we already pre-checked the names so we don't need to 180705097246SAdrian Prantl // check the error: 1808b842f2ecSJim Ingham BreakpointSP bp_sp; 1809b842f2ecSJim Ingham if (m_bp_id.m_breakpoint.OptionWasSet()) 1810b842f2ecSJim Ingham { 1811b842f2ecSJim Ingham lldb::break_id_t bp_id = m_bp_id.m_breakpoint.GetUInt64Value(); 1812b842f2ecSJim Ingham bp_sp = target->GetBreakpointByID(bp_id); 1813b842f2ecSJim Ingham if (!bp_sp) 1814b842f2ecSJim Ingham { 1815b842f2ecSJim Ingham result.AppendErrorWithFormatv("Could not find specified breakpoint {0}", 1816b842f2ecSJim Ingham bp_id); 1817b842f2ecSJim Ingham result.SetStatus(eReturnStatusFailed); 1818b842f2ecSJim Ingham return false; 1819b842f2ecSJim Ingham } 1820b842f2ecSJim Ingham } 1821b842f2ecSJim Ingham 1822b842f2ecSJim Ingham Status error; 1823b842f2ecSJim Ingham for (auto &entry : command.entries()) { 1824b842f2ecSJim Ingham ConstString name(entry.c_str()); 1825b842f2ecSJim Ingham BreakpointName *bp_name = target->FindBreakpointName(name, true, error); 1826b842f2ecSJim Ingham if (!bp_name) 1827b842f2ecSJim Ingham continue; 1828e9632ebaSJim Ingham if (m_bp_id.m_help_string.OptionWasSet()) 1829e9632ebaSJim Ingham bp_name->SetHelp(m_bp_id.m_help_string.GetStringValue().str().c_str()); 1830e9632ebaSJim Ingham 1831b842f2ecSJim Ingham if (bp_sp) 1832b842f2ecSJim Ingham target->ConfigureBreakpointName(*bp_name, 1833b842f2ecSJim Ingham *bp_sp->GetOptions(), 1834b842f2ecSJim Ingham m_access_options.GetPermissions()); 1835b842f2ecSJim Ingham else 1836b842f2ecSJim Ingham target->ConfigureBreakpointName(*bp_name, 1837b842f2ecSJim Ingham m_bp_opts.GetBreakpointOptions(), 1838b842f2ecSJim Ingham m_access_options.GetPermissions()); 1839b842f2ecSJim Ingham } 1840b842f2ecSJim Ingham return true; 1841b842f2ecSJim Ingham } 1842b842f2ecSJim Ingham 1843b842f2ecSJim Ingham private: 1844b842f2ecSJim Ingham BreakpointNameOptionGroup m_bp_id; // Only using the id part of this. 1845b842f2ecSJim Ingham BreakpointOptionGroup m_bp_opts; 1846b842f2ecSJim Ingham BreakpointAccessOptionGroup m_access_options; 1847b842f2ecSJim Ingham OptionGroupOptions m_option_group; 1848b842f2ecSJim Ingham }; 1849b842f2ecSJim Ingham 1850b9c1b51eSKate Stone class CommandObjectBreakpointNameAdd : public CommandObjectParsed { 18515e09c8c3SJim Ingham public: 1852b9c1b51eSKate Stone CommandObjectBreakpointNameAdd(CommandInterpreter &interpreter) 1853b9c1b51eSKate Stone : CommandObjectParsed( 1854b9c1b51eSKate Stone interpreter, "add", "Add a name to the breakpoints provided.", 18555e09c8c3SJim Ingham "breakpoint name add <command-options> <breakpoint-id-list>"), 1856b9c1b51eSKate Stone m_name_options(), m_option_group() { 1857b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 1858b9c1b51eSKate Stone // command. 18595e09c8c3SJim Ingham CommandArgumentEntry arg1; 18605e09c8c3SJim Ingham CommandArgumentData id_arg; 18615e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 18625e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 18635e09c8c3SJim Ingham arg1.push_back(id_arg); 18645e09c8c3SJim Ingham m_arguments.push_back(arg1); 18655e09c8c3SJim Ingham 18665e09c8c3SJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 18675e09c8c3SJim Ingham m_option_group.Finalize(); 18685e09c8c3SJim Ingham } 18695e09c8c3SJim Ingham 18709e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameAdd() override = default; 18715e09c8c3SJim Ingham 1872b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 18735e09c8c3SJim Ingham 18745e09c8c3SJim Ingham protected: 1875b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1876b9c1b51eSKate Stone if (!m_name_options.m_name.OptionWasSet()) { 18775e09c8c3SJim Ingham result.SetError("No name option provided."); 18785e09c8c3SJim Ingham return false; 18795e09c8c3SJim Ingham } 18805e09c8c3SJim Ingham 1881b9c1b51eSKate Stone Target *target = 1882b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 18835e09c8c3SJim Ingham 1884b9c1b51eSKate Stone if (target == nullptr) { 18855e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 18865e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 18875e09c8c3SJim Ingham return false; 18885e09c8c3SJim Ingham } 18895e09c8c3SJim Ingham 1890bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1891bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 18925e09c8c3SJim Ingham 18935e09c8c3SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 18945e09c8c3SJim Ingham 18955e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 1896b9c1b51eSKate Stone if (num_breakpoints == 0) { 18975e09c8c3SJim Ingham result.SetError("No breakpoints, cannot add names."); 18985e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 18995e09c8c3SJim Ingham return false; 19005e09c8c3SJim Ingham } 19015e09c8c3SJim Ingham 19025e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 19035e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 1904b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 1905b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1906b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 19075e09c8c3SJim Ingham 1908b9c1b51eSKate Stone if (result.Succeeded()) { 1909b9c1b51eSKate Stone if (valid_bp_ids.GetSize() == 0) { 19105e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot add names."); 19115e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 19125e09c8c3SJim Ingham return false; 19135e09c8c3SJim Ingham } 19145e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 1915b842f2ecSJim Ingham const char *bp_name = m_name_options.m_name.GetCurrentValue(); 1916b842f2ecSJim Ingham Status error; // This error reports illegal names, but we've already 1917b842f2ecSJim Ingham // checked that, so we don't need to check it again here. 1918b9c1b51eSKate Stone for (size_t index = 0; index < num_valid_ids; index++) { 1919b9c1b51eSKate Stone lldb::break_id_t bp_id = 1920b9c1b51eSKate Stone valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 19215e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 1922b842f2ecSJim Ingham target->AddNameToBreakpoint(bp_sp, bp_name, error); 19235e09c8c3SJim Ingham } 19245e09c8c3SJim Ingham } 19255e09c8c3SJim Ingham 19265e09c8c3SJim Ingham return true; 19275e09c8c3SJim Ingham } 19285e09c8c3SJim Ingham 19295e09c8c3SJim Ingham private: 19305e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 19315e09c8c3SJim Ingham OptionGroupOptions m_option_group; 19325e09c8c3SJim Ingham }; 19335e09c8c3SJim Ingham 1934b9c1b51eSKate Stone class CommandObjectBreakpointNameDelete : public CommandObjectParsed { 19355e09c8c3SJim Ingham public: 1936b9c1b51eSKate Stone CommandObjectBreakpointNameDelete(CommandInterpreter &interpreter) 1937b9c1b51eSKate Stone : CommandObjectParsed( 1938b9c1b51eSKate Stone interpreter, "delete", 19395e09c8c3SJim Ingham "Delete a name from the breakpoints provided.", 19405e09c8c3SJim Ingham "breakpoint name delete <command-options> <breakpoint-id-list>"), 1941b9c1b51eSKate Stone m_name_options(), m_option_group() { 1942b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 1943b9c1b51eSKate Stone // command. 19445e09c8c3SJim Ingham CommandArgumentEntry arg1; 19455e09c8c3SJim Ingham CommandArgumentData id_arg; 19465e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 19475e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 19485e09c8c3SJim Ingham arg1.push_back(id_arg); 19495e09c8c3SJim Ingham m_arguments.push_back(arg1); 19505e09c8c3SJim Ingham 19515e09c8c3SJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 19525e09c8c3SJim Ingham m_option_group.Finalize(); 19535e09c8c3SJim Ingham } 19545e09c8c3SJim Ingham 19559e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameDelete() override = default; 19565e09c8c3SJim Ingham 1957b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 19585e09c8c3SJim Ingham 19595e09c8c3SJim Ingham protected: 1960b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1961b9c1b51eSKate Stone if (!m_name_options.m_name.OptionWasSet()) { 19625e09c8c3SJim Ingham result.SetError("No name option provided."); 19635e09c8c3SJim Ingham return false; 19645e09c8c3SJim Ingham } 19655e09c8c3SJim Ingham 1966b9c1b51eSKate Stone Target *target = 1967b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 19685e09c8c3SJim Ingham 1969b9c1b51eSKate Stone if (target == nullptr) { 19705e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 19715e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 19725e09c8c3SJim Ingham return false; 19735e09c8c3SJim Ingham } 19745e09c8c3SJim Ingham 1975bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1976bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 19775e09c8c3SJim Ingham 19785e09c8c3SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 19795e09c8c3SJim Ingham 19805e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 1981b9c1b51eSKate Stone if (num_breakpoints == 0) { 19825e09c8c3SJim Ingham result.SetError("No breakpoints, cannot delete names."); 19835e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 19845e09c8c3SJim Ingham return false; 19855e09c8c3SJim Ingham } 19865e09c8c3SJim Ingham 19875e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 19885e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 1989b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 1990b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 1991b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::deletePerm); 19925e09c8c3SJim Ingham 1993b9c1b51eSKate Stone if (result.Succeeded()) { 1994b9c1b51eSKate Stone if (valid_bp_ids.GetSize() == 0) { 19955e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot delete names."); 19965e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 19975e09c8c3SJim Ingham return false; 19985e09c8c3SJim Ingham } 1999b842f2ecSJim Ingham ConstString bp_name(m_name_options.m_name.GetCurrentValue()); 20005e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 2001b9c1b51eSKate Stone for (size_t index = 0; index < num_valid_ids; index++) { 2002b9c1b51eSKate Stone lldb::break_id_t bp_id = 2003b9c1b51eSKate Stone valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 20045e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 2005b842f2ecSJim Ingham target->RemoveNameFromBreakpoint(bp_sp, bp_name); 20065e09c8c3SJim Ingham } 20075e09c8c3SJim Ingham } 20085e09c8c3SJim Ingham 20095e09c8c3SJim Ingham return true; 20105e09c8c3SJim Ingham } 20115e09c8c3SJim Ingham 20125e09c8c3SJim Ingham private: 20135e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 20145e09c8c3SJim Ingham OptionGroupOptions m_option_group; 20155e09c8c3SJim Ingham }; 20165e09c8c3SJim Ingham 2017b9c1b51eSKate Stone class CommandObjectBreakpointNameList : public CommandObjectParsed { 20185e09c8c3SJim Ingham public: 2019b9c1b51eSKate Stone CommandObjectBreakpointNameList(CommandInterpreter &interpreter) 2020b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "list", 2021b842f2ecSJim Ingham "List either the names for a breakpoint or info " 2022b842f2ecSJim Ingham "about a given name. With no arguments, lists all " 2023b842f2ecSJim Ingham "names", 20245e09c8c3SJim Ingham "breakpoint name list <command-options>"), 2025b9c1b51eSKate Stone m_name_options(), m_option_group() { 2026b842f2ecSJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_3, LLDB_OPT_SET_ALL); 20275e09c8c3SJim Ingham m_option_group.Finalize(); 20285e09c8c3SJim Ingham } 20295e09c8c3SJim Ingham 20309e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameList() override = default; 20315e09c8c3SJim Ingham 2032b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 20335e09c8c3SJim Ingham 20345e09c8c3SJim Ingham protected: 2035b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 2036b9c1b51eSKate Stone Target *target = 2037b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 20385e09c8c3SJim Ingham 2039b9c1b51eSKate Stone if (target == nullptr) { 20405e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 20415e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20425e09c8c3SJim Ingham return false; 20435e09c8c3SJim Ingham } 20445e09c8c3SJim Ingham 2045b842f2ecSJim Ingham 2046b842f2ecSJim Ingham std::vector<std::string> name_list; 2047b842f2ecSJim Ingham if (command.empty()) { 2048b842f2ecSJim Ingham target->GetBreakpointNames(name_list); 2049b842f2ecSJim Ingham } else { 2050b842f2ecSJim Ingham for (const Args::ArgEntry &arg : command) 2051b842f2ecSJim Ingham { 2052b842f2ecSJim Ingham name_list.push_back(arg.c_str()); 2053b842f2ecSJim Ingham } 2054b842f2ecSJim Ingham } 2055b842f2ecSJim Ingham 2056b842f2ecSJim Ingham if (name_list.empty()) { 2057b842f2ecSJim Ingham result.AppendMessage("No breakpoint names found."); 2058b842f2ecSJim Ingham } else { 2059b842f2ecSJim Ingham for (const std::string &name_str : name_list) { 2060b842f2ecSJim Ingham const char *name = name_str.c_str(); 2061b842f2ecSJim Ingham // First print out the options for the name: 2062b842f2ecSJim Ingham Status error; 2063b842f2ecSJim Ingham BreakpointName *bp_name = target->FindBreakpointName(ConstString(name), 2064b842f2ecSJim Ingham false, 2065b842f2ecSJim Ingham error); 2066b842f2ecSJim Ingham if (bp_name) 2067b842f2ecSJim Ingham { 2068b842f2ecSJim Ingham StreamString s; 2069b842f2ecSJim Ingham result.AppendMessageWithFormat("Name: %s\n", name); 2070b842f2ecSJim Ingham if (bp_name->GetDescription(&s, eDescriptionLevelFull)) 2071b842f2ecSJim Ingham { 2072b842f2ecSJim Ingham result.AppendMessage(s.GetString()); 2073b842f2ecSJim Ingham } 2074b842f2ecSJim Ingham 2075bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 2076bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 20775e09c8c3SJim Ingham 20785e09c8c3SJim Ingham BreakpointList &breakpoints = target->GetBreakpointList(); 2079b842f2ecSJim Ingham bool any_set = false; 2080b9c1b51eSKate Stone for (BreakpointSP bp_sp : breakpoints.Breakpoints()) { 2081b9c1b51eSKate Stone if (bp_sp->MatchesName(name)) { 20825e09c8c3SJim Ingham StreamString s; 2083b842f2ecSJim Ingham any_set = true; 20845e09c8c3SJim Ingham bp_sp->GetDescription(&s, eDescriptionLevelBrief); 20855e09c8c3SJim Ingham s.EOL(); 2086c156427dSZachary Turner result.AppendMessage(s.GetString()); 20875e09c8c3SJim Ingham } 20885e09c8c3SJim Ingham } 2089b842f2ecSJim Ingham if (!any_set) 2090b842f2ecSJim Ingham result.AppendMessage("No breakpoints using this name."); 2091b9c1b51eSKate Stone } else { 2092b842f2ecSJim Ingham result.AppendMessageWithFormat("Name: %s not found.\n", name); 20935e09c8c3SJim Ingham } 2094b842f2ecSJim Ingham } 20955e09c8c3SJim Ingham } 20965e09c8c3SJim Ingham return true; 20975e09c8c3SJim Ingham } 20985e09c8c3SJim Ingham 20995e09c8c3SJim Ingham private: 21005e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 21015e09c8c3SJim Ingham OptionGroupOptions m_option_group; 21025e09c8c3SJim Ingham }; 21035e09c8c3SJim Ingham 2104e14dc268SJim Ingham // CommandObjectBreakpointName 2105b9c1b51eSKate Stone class CommandObjectBreakpointName : public CommandObjectMultiword { 21065e09c8c3SJim Ingham public: 21077428a18cSKate Stone CommandObjectBreakpointName(CommandInterpreter &interpreter) 2108b9c1b51eSKate Stone : CommandObjectMultiword( 2109b9c1b51eSKate Stone interpreter, "name", "Commands to manage name tags for breakpoints", 2110b9c1b51eSKate Stone "breakpoint name <subcommand> [<command-options>]") { 2111b9c1b51eSKate Stone CommandObjectSP add_command_object( 2112b9c1b51eSKate Stone new CommandObjectBreakpointNameAdd(interpreter)); 2113b9c1b51eSKate Stone CommandObjectSP delete_command_object( 2114b9c1b51eSKate Stone new CommandObjectBreakpointNameDelete(interpreter)); 2115b9c1b51eSKate Stone CommandObjectSP list_command_object( 2116b9c1b51eSKate Stone new CommandObjectBreakpointNameList(interpreter)); 2117b842f2ecSJim Ingham CommandObjectSP configure_command_object( 2118b842f2ecSJim Ingham new CommandObjectBreakpointNameConfigure(interpreter)); 21195e09c8c3SJim Ingham 21205e09c8c3SJim Ingham LoadSubCommand("add", add_command_object); 21215e09c8c3SJim Ingham LoadSubCommand("delete", delete_command_object); 21225e09c8c3SJim Ingham LoadSubCommand("list", list_command_object); 2123b842f2ecSJim Ingham LoadSubCommand("configure", configure_command_object); 21245e09c8c3SJim Ingham } 21255e09c8c3SJim Ingham 21269e85e5a8SEugene Zelenko ~CommandObjectBreakpointName() override = default; 21275e09c8c3SJim Ingham }; 21285e09c8c3SJim Ingham 2129e14dc268SJim Ingham // CommandObjectBreakpointRead 21303acdf385SJim Ingham #pragma mark Read::CommandOptions 2131f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_read 2132f94668e3SRaphael Isemann #include "CommandOptions.inc" 21331f0f5b5bSZachary Turner 21341f0f5b5bSZachary Turner #pragma mark Read 2135e14dc268SJim Ingham 2136e14dc268SJim Ingham class CommandObjectBreakpointRead : public CommandObjectParsed { 2137e14dc268SJim Ingham public: 2138e14dc268SJim Ingham CommandObjectBreakpointRead(CommandInterpreter &interpreter) 2139e14dc268SJim Ingham : CommandObjectParsed(interpreter, "breakpoint read", 2140e14dc268SJim Ingham "Read and set the breakpoints previously saved to " 2141e14dc268SJim Ingham "a file with \"breakpoint write\". ", 2142e14dc268SJim Ingham nullptr), 2143e14dc268SJim Ingham m_options() { 2144e14dc268SJim Ingham CommandArgumentEntry arg; 2145e14dc268SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 2146e14dc268SJim Ingham eArgTypeBreakpointIDRange); 2147e14dc268SJim Ingham // Add the entry for the first argument for this command to the object's 2148e14dc268SJim Ingham // arguments vector. 2149e14dc268SJim Ingham m_arguments.push_back(arg); 2150e14dc268SJim Ingham } 2151e14dc268SJim Ingham 2152e14dc268SJim Ingham ~CommandObjectBreakpointRead() override = default; 2153e14dc268SJim Ingham 2154e14dc268SJim Ingham Options *GetOptions() override { return &m_options; } 2155e14dc268SJim Ingham 2156e14dc268SJim Ingham class CommandOptions : public Options { 2157e14dc268SJim Ingham public: 2158e14dc268SJim Ingham CommandOptions() : Options() {} 2159e14dc268SJim Ingham 2160e14dc268SJim Ingham ~CommandOptions() override = default; 2161e14dc268SJim Ingham 216297206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 2163e14dc268SJim Ingham ExecutionContext *execution_context) override { 216497206d57SZachary Turner Status error; 2165e14dc268SJim Ingham const int short_option = m_getopt_table[option_idx].val; 2166e14dc268SJim Ingham 2167e14dc268SJim Ingham switch (short_option) { 2168e14dc268SJim Ingham case 'f': 2169e14dc268SJim Ingham m_filename.assign(option_arg); 2170e14dc268SJim Ingham break; 21713acdf385SJim Ingham case 'N': { 217297206d57SZachary Turner Status name_error; 21733acdf385SJim Ingham if (!BreakpointID::StringIsBreakpointName(llvm::StringRef(option_arg), 21743acdf385SJim Ingham name_error)) { 21753acdf385SJim Ingham error.SetErrorStringWithFormat("Invalid breakpoint name: %s", 21763acdf385SJim Ingham name_error.AsCString()); 21773acdf385SJim Ingham } 21783acdf385SJim Ingham m_names.push_back(option_arg); 21793acdf385SJim Ingham break; 21803acdf385SJim Ingham } 2181e14dc268SJim Ingham default: 2182e14dc268SJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 2183e14dc268SJim Ingham short_option); 2184e14dc268SJim Ingham break; 2185e14dc268SJim Ingham } 2186e14dc268SJim Ingham 2187e14dc268SJim Ingham return error; 2188e14dc268SJim Ingham } 2189e14dc268SJim Ingham 2190e14dc268SJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 2191e14dc268SJim Ingham m_filename.clear(); 21923acdf385SJim Ingham m_names.clear(); 2193e14dc268SJim Ingham } 2194e14dc268SJim Ingham 21951f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 219670602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_read_options); 21971f0f5b5bSZachary Turner } 2198e14dc268SJim Ingham 2199e14dc268SJim Ingham // Instance variables to hold the values for command options. 2200e14dc268SJim Ingham 2201e14dc268SJim Ingham std::string m_filename; 22023acdf385SJim Ingham std::vector<std::string> m_names; 2203e14dc268SJim Ingham }; 2204e14dc268SJim Ingham 2205e14dc268SJim Ingham protected: 2206e14dc268SJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 2207e14dc268SJim Ingham Target *target = GetSelectedOrDummyTarget(); 2208e14dc268SJim Ingham if (target == nullptr) { 2209e14dc268SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 2210e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2211e14dc268SJim Ingham return false; 2212e14dc268SJim Ingham } 2213e14dc268SJim Ingham 22143acdf385SJim Ingham std::unique_lock<std::recursive_mutex> lock; 22153acdf385SJim Ingham target->GetBreakpointList().GetListMutex(lock); 22163acdf385SJim Ingham 22178f3be7a3SJonas Devlieghere FileSpec input_spec(m_options.m_filename); 22188f3be7a3SJonas Devlieghere FileSystem::Instance().Resolve(input_spec); 221901f16664SJim Ingham BreakpointIDList new_bps; 222097206d57SZachary Turner Status error = target->CreateBreakpointsFromFile( 222197206d57SZachary Turner input_spec, m_options.m_names, new_bps); 2222e14dc268SJim Ingham 2223e14dc268SJim Ingham if (!error.Success()) { 222401f16664SJim Ingham result.AppendError(error.AsCString()); 2225e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 222601f16664SJim Ingham return false; 2227e14dc268SJim Ingham } 22283acdf385SJim Ingham 22293acdf385SJim Ingham Stream &output_stream = result.GetOutputStream(); 22303acdf385SJim Ingham 22313acdf385SJim Ingham size_t num_breakpoints = new_bps.GetSize(); 22323acdf385SJim Ingham if (num_breakpoints == 0) { 22333acdf385SJim Ingham result.AppendMessage("No breakpoints added."); 22343acdf385SJim Ingham } else { 22353acdf385SJim Ingham // No breakpoint selected; show info about all currently set breakpoints. 22363acdf385SJim Ingham result.AppendMessage("New breakpoints:"); 22373acdf385SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) { 22383acdf385SJim Ingham BreakpointID bp_id = new_bps.GetBreakpointIDAtIndex(i); 22393acdf385SJim Ingham Breakpoint *bp = target->GetBreakpointList() 22403acdf385SJim Ingham .FindBreakpointByID(bp_id.GetBreakpointID()) 22413acdf385SJim Ingham .get(); 22423acdf385SJim Ingham if (bp) 22433acdf385SJim Ingham bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, 22443acdf385SJim Ingham false); 22453acdf385SJim Ingham } 22463acdf385SJim Ingham } 2247e14dc268SJim Ingham return result.Succeeded(); 2248e14dc268SJim Ingham } 2249e14dc268SJim Ingham 2250e14dc268SJim Ingham private: 2251e14dc268SJim Ingham CommandOptions m_options; 2252e14dc268SJim Ingham }; 2253e14dc268SJim Ingham 2254e14dc268SJim Ingham // CommandObjectBreakpointWrite 22551f0f5b5bSZachary Turner #pragma mark Write::CommandOptions 2256f94668e3SRaphael Isemann #define LLDB_OPTIONS_breakpoint_write 2257f94668e3SRaphael Isemann #include "CommandOptions.inc" 22581f0f5b5bSZachary Turner 22591f0f5b5bSZachary Turner #pragma mark Write 2260e14dc268SJim Ingham class CommandObjectBreakpointWrite : public CommandObjectParsed { 2261e14dc268SJim Ingham public: 2262e14dc268SJim Ingham CommandObjectBreakpointWrite(CommandInterpreter &interpreter) 2263e14dc268SJim Ingham : CommandObjectParsed(interpreter, "breakpoint write", 2264e14dc268SJim Ingham "Write the breakpoints listed to a file that can " 2265e14dc268SJim Ingham "be read in with \"breakpoint read\". " 2266e14dc268SJim Ingham "If given no arguments, writes all breakpoints.", 2267e14dc268SJim Ingham nullptr), 2268e14dc268SJim Ingham m_options() { 2269e14dc268SJim Ingham CommandArgumentEntry arg; 2270e14dc268SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 2271e14dc268SJim Ingham eArgTypeBreakpointIDRange); 2272e14dc268SJim Ingham // Add the entry for the first argument for this command to the object's 2273e14dc268SJim Ingham // arguments vector. 2274e14dc268SJim Ingham m_arguments.push_back(arg); 2275e14dc268SJim Ingham } 2276e14dc268SJim Ingham 2277e14dc268SJim Ingham ~CommandObjectBreakpointWrite() override = default; 2278e14dc268SJim Ingham 2279e14dc268SJim Ingham Options *GetOptions() override { return &m_options; } 2280e14dc268SJim Ingham 2281e14dc268SJim Ingham class CommandOptions : public Options { 2282e14dc268SJim Ingham public: 2283e14dc268SJim Ingham CommandOptions() : Options() {} 2284e14dc268SJim Ingham 2285e14dc268SJim Ingham ~CommandOptions() override = default; 2286e14dc268SJim Ingham 228797206d57SZachary Turner Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 2288e14dc268SJim Ingham ExecutionContext *execution_context) override { 228997206d57SZachary Turner Status error; 2290e14dc268SJim Ingham const int short_option = m_getopt_table[option_idx].val; 2291e14dc268SJim Ingham 2292e14dc268SJim Ingham switch (short_option) { 2293e14dc268SJim Ingham case 'f': 2294e14dc268SJim Ingham m_filename.assign(option_arg); 2295e14dc268SJim Ingham break; 22962d3628e1SJim Ingham case 'a': 22972d3628e1SJim Ingham m_append = true; 22982d3628e1SJim Ingham break; 2299e14dc268SJim Ingham default: 2300e14dc268SJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 2301e14dc268SJim Ingham short_option); 2302e14dc268SJim Ingham break; 2303e14dc268SJim Ingham } 2304e14dc268SJim Ingham 2305e14dc268SJim Ingham return error; 2306e14dc268SJim Ingham } 2307e14dc268SJim Ingham 2308e14dc268SJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 2309e14dc268SJim Ingham m_filename.clear(); 23102d3628e1SJim Ingham m_append = false; 2311e14dc268SJim Ingham } 2312e14dc268SJim Ingham 23131f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 231470602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_write_options); 23151f0f5b5bSZachary Turner } 2316e14dc268SJim Ingham 2317e14dc268SJim Ingham // Instance variables to hold the values for command options. 2318e14dc268SJim Ingham 2319e14dc268SJim Ingham std::string m_filename; 23202d3628e1SJim Ingham bool m_append = false; 2321e14dc268SJim Ingham }; 2322e14dc268SJim Ingham 2323e14dc268SJim Ingham protected: 2324e14dc268SJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 2325e14dc268SJim Ingham Target *target = GetSelectedOrDummyTarget(); 2326e14dc268SJim Ingham if (target == nullptr) { 2327e14dc268SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 2328e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2329e14dc268SJim Ingham return false; 2330e14dc268SJim Ingham } 2331e14dc268SJim Ingham 2332e14dc268SJim Ingham std::unique_lock<std::recursive_mutex> lock; 2333e14dc268SJim Ingham target->GetBreakpointList().GetListMutex(lock); 2334e14dc268SJim Ingham 2335e14dc268SJim Ingham BreakpointIDList valid_bp_ids; 233611eb9c64SZachary Turner if (!command.empty()) { 2337e14dc268SJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 2338b842f2ecSJim Ingham command, target, result, &valid_bp_ids, 2339b842f2ecSJim Ingham BreakpointName::Permissions::PermissionKinds::listPerm); 2340e14dc268SJim Ingham 234101f16664SJim Ingham if (!result.Succeeded()) { 2342e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2343e14dc268SJim Ingham return false; 2344e14dc268SJim Ingham } 2345e14dc268SJim Ingham } 23468f3be7a3SJonas Devlieghere FileSpec file_spec(m_options.m_filename); 23478f3be7a3SJonas Devlieghere FileSystem::Instance().Resolve(file_spec); 23488f3be7a3SJonas Devlieghere Status error = target->SerializeBreakpointsToFile(file_spec, valid_bp_ids, 23498f3be7a3SJonas Devlieghere m_options.m_append); 235001f16664SJim Ingham if (!error.Success()) { 235101f16664SJim Ingham result.AppendErrorWithFormat("error serializing breakpoints: %s.", 235201f16664SJim Ingham error.AsCString()); 235301f16664SJim Ingham result.SetStatus(eReturnStatusFailed); 2354e14dc268SJim Ingham } 2355e14dc268SJim Ingham return result.Succeeded(); 2356e14dc268SJim Ingham } 2357e14dc268SJim Ingham 2358e14dc268SJim Ingham private: 2359e14dc268SJim Ingham CommandOptions m_options; 2360e14dc268SJim Ingham }; 2361e14dc268SJim Ingham 236230fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 2363ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 236430fdc8d8SChris Lattner 2365b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint( 2366b9c1b51eSKate Stone CommandInterpreter &interpreter) 2367b9c1b51eSKate Stone : CommandObjectMultiword( 2368b9c1b51eSKate Stone interpreter, "breakpoint", 23697428a18cSKate Stone "Commands for operating on breakpoints (see 'help b' for shorthand.)", 2370b9c1b51eSKate Stone "breakpoint <subcommand> [<command-options>]") { 2371b9c1b51eSKate Stone CommandObjectSP list_command_object( 2372b9c1b51eSKate Stone new CommandObjectBreakpointList(interpreter)); 2373b9c1b51eSKate Stone CommandObjectSP enable_command_object( 2374b9c1b51eSKate Stone new CommandObjectBreakpointEnable(interpreter)); 2375b9c1b51eSKate Stone CommandObjectSP disable_command_object( 2376b9c1b51eSKate Stone new CommandObjectBreakpointDisable(interpreter)); 2377b9c1b51eSKate Stone CommandObjectSP clear_command_object( 2378b9c1b51eSKate Stone new CommandObjectBreakpointClear(interpreter)); 2379b9c1b51eSKate Stone CommandObjectSP delete_command_object( 2380b9c1b51eSKate Stone new CommandObjectBreakpointDelete(interpreter)); 2381b9c1b51eSKate Stone CommandObjectSP set_command_object( 2382b9c1b51eSKate Stone new CommandObjectBreakpointSet(interpreter)); 2383b9c1b51eSKate Stone CommandObjectSP command_command_object( 2384b9c1b51eSKate Stone new CommandObjectBreakpointCommand(interpreter)); 2385b9c1b51eSKate Stone CommandObjectSP modify_command_object( 2386b9c1b51eSKate Stone new CommandObjectBreakpointModify(interpreter)); 2387b9c1b51eSKate Stone CommandObjectSP name_command_object( 2388b9c1b51eSKate Stone new CommandObjectBreakpointName(interpreter)); 2389e14dc268SJim Ingham CommandObjectSP write_command_object( 2390e14dc268SJim Ingham new CommandObjectBreakpointWrite(interpreter)); 2391e14dc268SJim Ingham CommandObjectSP read_command_object( 2392e14dc268SJim Ingham new CommandObjectBreakpointRead(interpreter)); 239330fdc8d8SChris Lattner 2394b7234e40SJohnny Chen list_command_object->SetCommandName("breakpoint list"); 239530fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 239630fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 2397b7234e40SJohnny Chen clear_command_object->SetCommandName("breakpoint clear"); 2398b7234e40SJohnny Chen delete_command_object->SetCommandName("breakpoint delete"); 2399ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 2400b7234e40SJohnny Chen command_command_object->SetCommandName("breakpoint command"); 2401b7234e40SJohnny Chen modify_command_object->SetCommandName("breakpoint modify"); 24025e09c8c3SJim Ingham name_command_object->SetCommandName("breakpoint name"); 2403e14dc268SJim Ingham write_command_object->SetCommandName("breakpoint write"); 2404e14dc268SJim Ingham read_command_object->SetCommandName("breakpoint read"); 240530fdc8d8SChris Lattner 240623f59509SGreg Clayton LoadSubCommand("list", list_command_object); 240723f59509SGreg Clayton LoadSubCommand("enable", enable_command_object); 240823f59509SGreg Clayton LoadSubCommand("disable", disable_command_object); 240923f59509SGreg Clayton LoadSubCommand("clear", clear_command_object); 241023f59509SGreg Clayton LoadSubCommand("delete", delete_command_object); 241123f59509SGreg Clayton LoadSubCommand("set", set_command_object); 241223f59509SGreg Clayton LoadSubCommand("command", command_command_object); 241323f59509SGreg Clayton LoadSubCommand("modify", modify_command_object); 24145e09c8c3SJim Ingham LoadSubCommand("name", name_command_object); 2415e14dc268SJim Ingham LoadSubCommand("write", write_command_object); 2416e14dc268SJim Ingham LoadSubCommand("read", read_command_object); 241730fdc8d8SChris Lattner } 241830fdc8d8SChris Lattner 24199e85e5a8SEugene Zelenko CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default; 242030fdc8d8SChris Lattner 2421b9c1b51eSKate Stone void CommandObjectMultiwordBreakpoint::VerifyIDs(Args &args, Target *target, 24225e09c8c3SJim Ingham bool allow_locations, 24235e09c8c3SJim Ingham CommandReturnObject &result, 2424b842f2ecSJim Ingham BreakpointIDList *valid_ids, 2425b842f2ecSJim Ingham BreakpointName::Permissions 2426b842f2ecSJim Ingham ::PermissionKinds 2427b842f2ecSJim Ingham purpose) { 242830fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 2429b9c1b51eSKate Stone // 2). the full breakpoint & location 2430b9c1b51eSKate Stone // canonical representation 2431b9c1b51eSKate Stone // 3). the word "to" or a hyphen, 2432b9c1b51eSKate Stone // representing a range (in which case there 2433b9c1b51eSKate Stone // had *better* be an entry both before & 2434b9c1b51eSKate Stone // after of one of the first two types. 24355e09c8c3SJim Ingham // 4). A breakpoint name 2436b9c1b51eSKate Stone // If args is empty, we will use the last created breakpoint (if there is 2437b9c1b51eSKate Stone // one.) 243830fdc8d8SChris Lattner 243930fdc8d8SChris Lattner Args temp_args; 244030fdc8d8SChris Lattner 244111eb9c64SZachary Turner if (args.empty()) { 2442b9c1b51eSKate Stone if (target->GetLastCreatedBreakpoint()) { 2443b9c1b51eSKate Stone valid_ids->AddBreakpointID(BreakpointID( 2444b9c1b51eSKate Stone target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); 244536f3b369SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 2446b9c1b51eSKate Stone } else { 2447b9c1b51eSKate Stone result.AppendError( 2448b9c1b51eSKate Stone "No breakpoint specified and no last created breakpoint."); 244936f3b369SJim Ingham result.SetStatus(eReturnStatusFailed); 245036f3b369SJim Ingham } 245136f3b369SJim Ingham return; 245236f3b369SJim Ingham } 245336f3b369SJim Ingham 2454b9c1b51eSKate Stone // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff 245505097246SAdrian Prantl // directly from the old ARGS to the new TEMP_ARGS. Do not copy breakpoint 245605097246SAdrian Prantl // id range strings over; instead generate a list of strings for all the 245705097246SAdrian Prantl // breakpoint ids in the range, and shove all of those breakpoint id strings 245805097246SAdrian Prantl // into TEMP_ARGS. 245930fdc8d8SChris Lattner 2460b9c1b51eSKate Stone BreakpointIDList::FindAndReplaceIDRanges(args, target, allow_locations, 2461b842f2ecSJim Ingham purpose, result, temp_args); 246230fdc8d8SChris Lattner 2463b9c1b51eSKate Stone // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual 2464b9c1b51eSKate Stone // BreakpointIDList: 246530fdc8d8SChris Lattner 246616662f3cSPavel Labath valid_ids->InsertStringArray(temp_args.GetArgumentArrayRef(), result); 246730fdc8d8SChris Lattner 246805097246SAdrian Prantl // At this point, all of the breakpoint ids that the user passed in have 246905097246SAdrian Prantl // been converted to breakpoint IDs and put into valid_ids. 247030fdc8d8SChris Lattner 2471b9c1b51eSKate Stone if (result.Succeeded()) { 2472b9c1b51eSKate Stone // Now that we've converted everything from args into a list of breakpoint 247305097246SAdrian Prantl // ids, go through our tentative list of breakpoint id's and verify that 247405097246SAdrian Prantl // they correspond to valid/currently set breakpoints. 247530fdc8d8SChris Lattner 2476c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 2477b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 247830fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex(i); 2479b9c1b51eSKate Stone Breakpoint *breakpoint = 2480b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 2481b9c1b51eSKate Stone if (breakpoint != nullptr) { 2482c7bece56SGreg Clayton const size_t num_locations = breakpoint->GetNumLocations(); 2483b9c1b51eSKate Stone if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations) { 248430fdc8d8SChris Lattner StreamString id_str; 2485b9c1b51eSKate Stone BreakpointID::GetCanonicalReference( 2486b9c1b51eSKate Stone &id_str, cur_bp_id.GetBreakpointID(), cur_bp_id.GetLocationID()); 2487c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 2488b9c1b51eSKate Stone result.AppendErrorWithFormat( 2489b9c1b51eSKate Stone "'%s' is not a currently valid breakpoint/location id.\n", 249030fdc8d8SChris Lattner id_str.GetData()); 249130fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 249230fdc8d8SChris Lattner } 2493b9c1b51eSKate Stone } else { 2494c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 2495b9c1b51eSKate Stone result.AppendErrorWithFormat( 2496b9c1b51eSKate Stone "'%d' is not a currently valid breakpoint ID.\n", 24977428a18cSKate Stone cur_bp_id.GetBreakpointID()); 249830fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 249930fdc8d8SChris Lattner } 250030fdc8d8SChris Lattner } 250130fdc8d8SChris Lattner } 250230fdc8d8SChris Lattner } 2503