130fdc8d8SChris Lattner //===-- CommandObjectBreakpoint.cpp -----------------------------*- C++ -*-===// 230fdc8d8SChris Lattner // 330fdc8d8SChris Lattner // The LLVM Compiler Infrastructure 430fdc8d8SChris Lattner // 530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source 630fdc8d8SChris Lattner // License. See LICENSE.TXT for details. 730fdc8d8SChris Lattner // 830fdc8d8SChris Lattner //===----------------------------------------------------------------------===// 930fdc8d8SChris Lattner 1030fdc8d8SChris Lattner // C Includes 1130fdc8d8SChris Lattner // C++ Includes 129e85e5a8SEugene Zelenko #include <vector> 139e85e5a8SEugene Zelenko 1430fdc8d8SChris Lattner // Other libraries and framework includes 1530fdc8d8SChris Lattner // Project includes 169e85e5a8SEugene Zelenko #include "CommandObjectBreakpoint.h" 179e85e5a8SEugene Zelenko #include "CommandObjectBreakpointCommand.h" 1830fdc8d8SChris Lattner #include "lldb/Breakpoint/Breakpoint.h" 1930fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointIDList.h" 2030fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointLocation.h" 21b9c1b51eSKate Stone #include "lldb/Core/RegularExpression.h" 22b9c1b51eSKate Stone #include "lldb/Core/StreamString.h" 235275aaa0SVince Harron #include "lldb/Host/StringConvert.h" 24b9c1b51eSKate Stone #include "lldb/Interpreter/CommandCompletions.h" 25b9c1b51eSKate Stone #include "lldb/Interpreter/CommandInterpreter.h" 26b9c1b51eSKate Stone #include "lldb/Interpreter/CommandReturnObject.h" 2732abc6edSZachary Turner #include "lldb/Interpreter/OptionValueBoolean.h" 285e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueString.h" 295e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueUInt64.h" 30b9c1b51eSKate Stone #include "lldb/Interpreter/Options.h" 310e0984eeSJim Ingham #include "lldb/Target/Language.h" 32b57e4a1bSJason Molenda #include "lldb/Target/StackFrame.h" 33b9c1b51eSKate Stone #include "lldb/Target/Target.h" 341b54c88cSJim Ingham #include "lldb/Target/Thread.h" 351b54c88cSJim Ingham #include "lldb/Target/ThreadSpec.h" 3630fdc8d8SChris Lattner 3730fdc8d8SChris Lattner using namespace lldb; 3830fdc8d8SChris Lattner using namespace lldb_private; 3930fdc8d8SChris Lattner 40b9c1b51eSKate Stone static void AddBreakpointDescription(Stream *s, Breakpoint *bp, 41b9c1b51eSKate Stone lldb::DescriptionLevel level) { 4230fdc8d8SChris Lattner s->IndentMore(); 4330fdc8d8SChris Lattner bp->GetDescription(s, level, true); 4430fdc8d8SChris Lattner s->IndentLess(); 4530fdc8d8SChris Lattner s->EOL(); 4630fdc8d8SChris Lattner } 4730fdc8d8SChris Lattner 4830fdc8d8SChris Lattner //------------------------------------------------------------------------- 495a988416SJim Ingham // CommandObjectBreakpointSet 5030fdc8d8SChris Lattner //------------------------------------------------------------------------- 5130fdc8d8SChris Lattner 52b9c1b51eSKate Stone class CommandObjectBreakpointSet : public CommandObjectParsed { 535a988416SJim Ingham public: 54b9c1b51eSKate Stone typedef enum BreakpointSetType { 555a988416SJim Ingham eSetTypeInvalid, 565a988416SJim Ingham eSetTypeFileAndLine, 575a988416SJim Ingham eSetTypeAddress, 585a988416SJim Ingham eSetTypeFunctionName, 595a988416SJim Ingham eSetTypeFunctionRegexp, 605a988416SJim Ingham eSetTypeSourceRegexp, 615a988416SJim Ingham eSetTypeException 625a988416SJim Ingham } BreakpointSetType; 635a988416SJim Ingham 64b9c1b51eSKate Stone CommandObjectBreakpointSet(CommandInterpreter &interpreter) 65b9c1b51eSKate Stone : CommandObjectParsed( 66b9c1b51eSKate Stone interpreter, "breakpoint set", 675a988416SJim Ingham "Sets a breakpoint or set of breakpoints in the executable.", 685a988416SJim Ingham "breakpoint set <cmd-options>"), 69b9c1b51eSKate Stone m_options() {} 705a988416SJim Ingham 719e85e5a8SEugene Zelenko ~CommandObjectBreakpointSet() override = default; 725a988416SJim Ingham 73b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 745a988416SJim Ingham 75b9c1b51eSKate Stone class CommandOptions : public Options { 765a988416SJim Ingham public: 77b9c1b51eSKate Stone CommandOptions() 78b9c1b51eSKate Stone : Options(), m_condition(), m_filenames(), m_line_num(0), m_column(0), 79b9c1b51eSKate Stone m_func_names(), m_func_name_type_mask(eFunctionNameTypeNone), 80b9c1b51eSKate Stone m_func_regexp(), m_source_text_regexp(), m_modules(), m_load_addr(), 81b9c1b51eSKate Stone m_ignore_count(0), m_thread_id(LLDB_INVALID_THREAD_ID), 82b9c1b51eSKate Stone m_thread_index(UINT32_MAX), m_thread_name(), m_queue_name(), 83b9c1b51eSKate Stone m_catch_bp(false), m_throw_bp(true), m_hardware(false), 84a72b31c7SJim Ingham m_exception_language(eLanguageTypeUnknown), 8523b1decbSDawn Perchik m_language(lldb::eLanguageTypeUnknown), 86b9c1b51eSKate Stone m_skip_prologue(eLazyBoolCalculate), m_one_shot(false), 87b9c1b51eSKate Stone m_all_files(false), m_move_to_nearest_code(eLazyBoolCalculate) {} 8830fdc8d8SChris Lattner 899e85e5a8SEugene Zelenko ~CommandOptions() override = default; 9087df91b8SJim Ingham 91b9c1b51eSKate Stone Error SetOptionValue(uint32_t option_idx, const char *option_arg, 92b9c1b51eSKate Stone ExecutionContext *execution_context) override { 9330fdc8d8SChris Lattner Error error; 943bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 95*6fa7681bSZachary Turner llvm::StringRef option_strref(option_arg ? option_arg : ""); 9630fdc8d8SChris Lattner 97b9c1b51eSKate Stone switch (short_option) { 98b9c1b51eSKate Stone case 'a': { 99b9c1b51eSKate Stone m_load_addr = Args::StringToAddress(execution_context, option_arg, 100e1cfbc79STodd Fiala LLDB_INVALID_ADDRESS, &error); 101b9c1b51eSKate Stone } break; 10230fdc8d8SChris Lattner 103e732052fSJim Ingham case 'A': 104e732052fSJim Ingham m_all_files = true; 105e732052fSJim Ingham break; 106e732052fSJim Ingham 107ca36cd16SJim Ingham case 'b': 108ca36cd16SJim Ingham m_func_names.push_back(option_arg); 109ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeBase; 110ca36cd16SJim Ingham break; 111ca36cd16SJim Ingham 112b9c1b51eSKate Stone case 'C': { 1136312991cSJim Ingham bool success; 1146312991cSJim Ingham m_column = StringConvert::ToUInt32(option_arg, 0, 0, &success); 1156312991cSJim Ingham if (!success) 116b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid column number: %s", 117b9c1b51eSKate Stone option_arg); 11830fdc8d8SChris Lattner break; 1196312991cSJim Ingham } 1209e85e5a8SEugene Zelenko 1217d49c9c8SJohnny Chen case 'c': 1227d49c9c8SJohnny Chen m_condition.assign(option_arg); 1237d49c9c8SJohnny Chen break; 1247d49c9c8SJohnny Chen 12533df7cd3SJim Ingham case 'D': 12633df7cd3SJim Ingham m_use_dummy = true; 12733df7cd3SJim Ingham break; 12833df7cd3SJim Ingham 129b9c1b51eSKate Stone case 'E': { 1300e0984eeSJim Ingham LanguageType language = Language::GetLanguageTypeFromString(option_arg); 131fab10e89SJim Ingham 132b9c1b51eSKate Stone switch (language) { 133fab10e89SJim Ingham case eLanguageTypeC89: 134fab10e89SJim Ingham case eLanguageTypeC: 135fab10e89SJim Ingham case eLanguageTypeC99: 1361d0089faSBruce Mitchener case eLanguageTypeC11: 137a72b31c7SJim Ingham m_exception_language = eLanguageTypeC; 138fab10e89SJim Ingham break; 139fab10e89SJim Ingham case eLanguageTypeC_plus_plus: 1401d0089faSBruce Mitchener case eLanguageTypeC_plus_plus_03: 1411d0089faSBruce Mitchener case eLanguageTypeC_plus_plus_11: 1422ba84a6aSBruce Mitchener case eLanguageTypeC_plus_plus_14: 143a72b31c7SJim Ingham m_exception_language = eLanguageTypeC_plus_plus; 144fab10e89SJim Ingham break; 145fab10e89SJim Ingham case eLanguageTypeObjC: 146a72b31c7SJim Ingham m_exception_language = eLanguageTypeObjC; 147fab10e89SJim Ingham break; 148fab10e89SJim Ingham case eLanguageTypeObjC_plus_plus: 149b9c1b51eSKate Stone error.SetErrorStringWithFormat( 150b9c1b51eSKate Stone "Set exception breakpoints separately for c++ and objective-c"); 151fab10e89SJim Ingham break; 152fab10e89SJim Ingham case eLanguageTypeUnknown: 153b9c1b51eSKate Stone error.SetErrorStringWithFormat( 154b9c1b51eSKate Stone "Unknown language type: '%s' for exception breakpoint", 155b9c1b51eSKate Stone option_arg); 156fab10e89SJim Ingham break; 157fab10e89SJim Ingham default: 158b9c1b51eSKate Stone error.SetErrorStringWithFormat( 159b9c1b51eSKate Stone "Unsupported language type: '%s' for exception breakpoint", 160b9c1b51eSKate Stone option_arg); 161fab10e89SJim Ingham } 162b9c1b51eSKate Stone } break; 163ca36cd16SJim Ingham 164ca36cd16SJim Ingham case 'f': 165ca36cd16SJim Ingham m_filenames.AppendIfUnique(FileSpec(option_arg, false)); 166fab10e89SJim Ingham break; 167ca36cd16SJim Ingham 168ca36cd16SJim Ingham case 'F': 169ca36cd16SJim Ingham m_func_names.push_back(option_arg); 170ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeFull; 171ca36cd16SJim Ingham break; 172ca36cd16SJim Ingham 173b9c1b51eSKate Stone case 'h': { 174fab10e89SJim Ingham bool success; 175fab10e89SJim Ingham m_catch_bp = Args::StringToBoolean(option_arg, true, &success); 176fab10e89SJim Ingham if (!success) 177b9c1b51eSKate Stone error.SetErrorStringWithFormat( 178b9c1b51eSKate Stone "Invalid boolean value for on-catch option: '%s'", option_arg); 179b9c1b51eSKate Stone } break; 180eb023e75SGreg Clayton 181eb023e75SGreg Clayton case 'H': 182eb023e75SGreg Clayton m_hardware = true; 183eb023e75SGreg Clayton break; 184eb023e75SGreg Clayton 185ca36cd16SJim Ingham case 'i': 1865275aaa0SVince Harron m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); 187ca36cd16SJim Ingham if (m_ignore_count == UINT32_MAX) 188b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid ignore count '%s'", 189b9c1b51eSKate Stone option_arg); 190ca36cd16SJim Ingham break; 191ca36cd16SJim Ingham 192b9c1b51eSKate Stone case 'K': { 193a8558b62SJim Ingham bool success; 194a8558b62SJim Ingham bool value; 195a8558b62SJim Ingham value = Args::StringToBoolean(option_arg, true, &success); 196a8558b62SJim Ingham if (value) 197a8558b62SJim Ingham m_skip_prologue = eLazyBoolYes; 198a8558b62SJim Ingham else 199a8558b62SJim Ingham m_skip_prologue = eLazyBoolNo; 200a8558b62SJim Ingham 201a8558b62SJim Ingham if (!success) 202b9c1b51eSKate Stone error.SetErrorStringWithFormat( 203b9c1b51eSKate Stone "Invalid boolean value for skip prologue option: '%s'", 204b9c1b51eSKate Stone option_arg); 205b9c1b51eSKate Stone } break; 206ca36cd16SJim Ingham 207b9c1b51eSKate Stone case 'l': { 2086312991cSJim Ingham bool success; 2096312991cSJim Ingham m_line_num = StringConvert::ToUInt32(option_arg, 0, 0, &success); 2106312991cSJim Ingham if (!success) 211b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid line number: %s.", 212b9c1b51eSKate Stone option_arg); 213ca36cd16SJim Ingham break; 2146312991cSJim Ingham } 215055ad9beSIlia K 21623b1decbSDawn Perchik case 'L': 2170e0984eeSJim Ingham m_language = Language::GetLanguageTypeFromString(option_arg); 21823b1decbSDawn Perchik if (m_language == eLanguageTypeUnknown) 219b9c1b51eSKate Stone error.SetErrorStringWithFormat( 220b9c1b51eSKate Stone "Unknown language type: '%s' for breakpoint", option_arg); 22123b1decbSDawn Perchik break; 22223b1decbSDawn Perchik 223b9c1b51eSKate Stone case 'm': { 224055ad9beSIlia K bool success; 225055ad9beSIlia K bool value; 226055ad9beSIlia K value = Args::StringToBoolean(option_arg, true, &success); 227055ad9beSIlia K if (value) 228055ad9beSIlia K m_move_to_nearest_code = eLazyBoolYes; 229055ad9beSIlia K else 230055ad9beSIlia K m_move_to_nearest_code = eLazyBoolNo; 231055ad9beSIlia K 232055ad9beSIlia K if (!success) 233b9c1b51eSKate Stone error.SetErrorStringWithFormat( 234b9c1b51eSKate Stone "Invalid boolean value for move-to-nearest-code option: '%s'", 235b9c1b51eSKate Stone option_arg); 236055ad9beSIlia K break; 237055ad9beSIlia K } 238055ad9beSIlia K 239ca36cd16SJim Ingham case 'M': 240ca36cd16SJim Ingham m_func_names.push_back(option_arg); 241ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeMethod; 242ca36cd16SJim Ingham break; 243ca36cd16SJim Ingham 244ca36cd16SJim Ingham case 'n': 245ca36cd16SJim Ingham m_func_names.push_back(option_arg); 246ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeAuto; 247ca36cd16SJim Ingham break; 248ca36cd16SJim Ingham 249*6fa7681bSZachary Turner case 'N': { 250*6fa7681bSZachary Turner if (BreakpointID::StringIsBreakpointName(option_strref, error)) 2515e09c8c3SJim Ingham m_breakpoint_names.push_back(option_arg); 2525e09c8c3SJim Ingham break; 253*6fa7681bSZachary Turner } 2545e09c8c3SJim Ingham 255b9c1b51eSKate Stone case 'R': { 2562411167fSJim Ingham lldb::addr_t tmp_offset_addr; 257e1cfbc79STodd Fiala tmp_offset_addr = 258b9c1b51eSKate Stone Args::StringToAddress(execution_context, option_arg, 0, &error); 2592411167fSJim Ingham if (error.Success()) 2602411167fSJim Ingham m_offset_addr = tmp_offset_addr; 261b9c1b51eSKate Stone } break; 2622411167fSJim Ingham 263ca36cd16SJim Ingham case 'o': 264ca36cd16SJim Ingham m_one_shot = true; 265ca36cd16SJim Ingham break; 266ca36cd16SJim Ingham 267a72b31c7SJim Ingham case 'O': 268a72b31c7SJim Ingham m_exception_extra_args.AppendArgument("-O"); 269a72b31c7SJim Ingham m_exception_extra_args.AppendArgument(option_arg); 270a72b31c7SJim Ingham break; 271a72b31c7SJim Ingham 272ca36cd16SJim Ingham case 'p': 273ca36cd16SJim Ingham m_source_text_regexp.assign(option_arg); 274ca36cd16SJim Ingham break; 275ca36cd16SJim Ingham 276ca36cd16SJim Ingham case 'q': 277ca36cd16SJim Ingham m_queue_name.assign(option_arg); 278ca36cd16SJim Ingham break; 279ca36cd16SJim Ingham 280ca36cd16SJim Ingham case 'r': 281ca36cd16SJim Ingham m_func_regexp.assign(option_arg); 282ca36cd16SJim Ingham break; 283ca36cd16SJim Ingham 284ca36cd16SJim Ingham case 's': 285ca36cd16SJim Ingham m_modules.AppendIfUnique(FileSpec(option_arg, false)); 286ca36cd16SJim Ingham break; 287ca36cd16SJim Ingham 288ca36cd16SJim Ingham case 'S': 289ca36cd16SJim Ingham m_func_names.push_back(option_arg); 290ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeSelector; 291ca36cd16SJim Ingham break; 292ca36cd16SJim Ingham 293ca36cd16SJim Ingham case 't': 294b9c1b51eSKate Stone m_thread_id = 295b9c1b51eSKate Stone StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 296ca36cd16SJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 297b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid thread id string '%s'", 298b9c1b51eSKate Stone option_arg); 299ca36cd16SJim Ingham break; 300ca36cd16SJim Ingham 301ca36cd16SJim Ingham case 'T': 302ca36cd16SJim Ingham m_thread_name.assign(option_arg); 303ca36cd16SJim Ingham break; 304ca36cd16SJim Ingham 305b9c1b51eSKate Stone case 'w': { 306ca36cd16SJim Ingham bool success; 307ca36cd16SJim Ingham m_throw_bp = Args::StringToBoolean(option_arg, true, &success); 308ca36cd16SJim Ingham if (!success) 309b9c1b51eSKate Stone error.SetErrorStringWithFormat( 310b9c1b51eSKate Stone "Invalid boolean value for on-throw option: '%s'", option_arg); 311b9c1b51eSKate Stone } break; 312ca36cd16SJim Ingham 313ca36cd16SJim Ingham case 'x': 3145275aaa0SVince Harron m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); 315ca36cd16SJim Ingham if (m_thread_id == UINT32_MAX) 316b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid thread index string '%s'", 317b9c1b51eSKate Stone option_arg); 318ca36cd16SJim Ingham break; 319ca36cd16SJim Ingham 32076bb8d67SJim Ingham case 'X': 32176bb8d67SJim Ingham m_source_regex_func_names.insert(option_arg); 32276bb8d67SJim Ingham break; 32376bb8d67SJim Ingham 32430fdc8d8SChris Lattner default: 325b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 326b9c1b51eSKate Stone short_option); 32730fdc8d8SChris Lattner break; 32830fdc8d8SChris Lattner } 32930fdc8d8SChris Lattner 33030fdc8d8SChris Lattner return error; 33130fdc8d8SChris Lattner } 3329e85e5a8SEugene Zelenko 333b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 3347d49c9c8SJohnny Chen m_condition.clear(); 33587df91b8SJim Ingham m_filenames.Clear(); 33630fdc8d8SChris Lattner m_line_num = 0; 33730fdc8d8SChris Lattner m_column = 0; 338fab10e89SJim Ingham m_func_names.clear(); 3391f746071SGreg Clayton m_func_name_type_mask = eFunctionNameTypeNone; 34030fdc8d8SChris Lattner m_func_regexp.clear(); 3411f746071SGreg Clayton m_source_text_regexp.clear(); 34287df91b8SJim Ingham m_modules.Clear(); 3431f746071SGreg Clayton m_load_addr = LLDB_INVALID_ADDRESS; 3442411167fSJim Ingham m_offset_addr = 0; 345c982c768SGreg Clayton m_ignore_count = 0; 3461b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 347c982c768SGreg Clayton m_thread_index = UINT32_MAX; 3481b54c88cSJim Ingham m_thread_name.clear(); 3491b54c88cSJim Ingham m_queue_name.clear(); 350fab10e89SJim Ingham m_catch_bp = false; 351fab10e89SJim Ingham m_throw_bp = true; 352eb023e75SGreg Clayton m_hardware = false; 353a72b31c7SJim Ingham m_exception_language = eLanguageTypeUnknown; 35423b1decbSDawn Perchik m_language = lldb::eLanguageTypeUnknown; 355a8558b62SJim Ingham m_skip_prologue = eLazyBoolCalculate; 356ca36cd16SJim Ingham m_one_shot = false; 35733df7cd3SJim Ingham m_use_dummy = false; 3585e09c8c3SJim Ingham m_breakpoint_names.clear(); 359e732052fSJim Ingham m_all_files = false; 360a72b31c7SJim Ingham m_exception_extra_args.Clear(); 361055ad9beSIlia K m_move_to_nearest_code = eLazyBoolCalculate; 36276bb8d67SJim Ingham m_source_regex_func_names.clear(); 36330fdc8d8SChris Lattner } 36430fdc8d8SChris Lattner 365b9c1b51eSKate Stone const OptionDefinition *GetDefinitions() override { return g_option_table; } 36630fdc8d8SChris Lattner 3675a988416SJim Ingham // Options table: Required for subclasses of Options. 36830fdc8d8SChris Lattner 3695a988416SJim Ingham static OptionDefinition g_option_table[]; 37030fdc8d8SChris Lattner 3715a988416SJim Ingham // Instance variables to hold the values for command options. 372969795f1SJim Ingham 3735a988416SJim Ingham std::string m_condition; 3745a988416SJim Ingham FileSpecList m_filenames; 3755a988416SJim Ingham uint32_t m_line_num; 3765a988416SJim Ingham uint32_t m_column; 3775a988416SJim Ingham std::vector<std::string> m_func_names; 3785e09c8c3SJim Ingham std::vector<std::string> m_breakpoint_names; 3795a988416SJim Ingham uint32_t m_func_name_type_mask; 3805a988416SJim Ingham std::string m_func_regexp; 3815a988416SJim Ingham std::string m_source_text_regexp; 3825a988416SJim Ingham FileSpecList m_modules; 3835a988416SJim Ingham lldb::addr_t m_load_addr; 3842411167fSJim Ingham lldb::addr_t m_offset_addr; 3855a988416SJim Ingham uint32_t m_ignore_count; 3865a988416SJim Ingham lldb::tid_t m_thread_id; 3875a988416SJim Ingham uint32_t m_thread_index; 3885a988416SJim Ingham std::string m_thread_name; 3895a988416SJim Ingham std::string m_queue_name; 3905a988416SJim Ingham bool m_catch_bp; 3915a988416SJim Ingham bool m_throw_bp; 392eb023e75SGreg Clayton bool m_hardware; // Request to use hardware breakpoints 393a72b31c7SJim Ingham lldb::LanguageType m_exception_language; 39423b1decbSDawn Perchik lldb::LanguageType m_language; 3955a988416SJim Ingham LazyBool m_skip_prologue; 396ca36cd16SJim Ingham bool m_one_shot; 39733df7cd3SJim Ingham bool m_use_dummy; 398e732052fSJim Ingham bool m_all_files; 399a72b31c7SJim Ingham Args m_exception_extra_args; 400055ad9beSIlia K LazyBool m_move_to_nearest_code; 40176bb8d67SJim Ingham std::unordered_set<std::string> m_source_regex_func_names; 4025a988416SJim Ingham }; 4035a988416SJim Ingham 4045a988416SJim Ingham protected: 405b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 40633df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 40733df7cd3SJim Ingham 408b9c1b51eSKate Stone if (target == nullptr) { 409b9c1b51eSKate Stone result.AppendError("Invalid target. Must set target before setting " 410b9c1b51eSKate Stone "breakpoints (see 'target create' command)."); 41130fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 41230fdc8d8SChris Lattner return false; 41330fdc8d8SChris Lattner } 41430fdc8d8SChris Lattner 41530fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 41630fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 41730fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 41830fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 419b9c1b51eSKate Stone // 4). -r [-s -g] (setting breakpoint by function name regular 420b9c1b51eSKate Stone // expression) 421b9c1b51eSKate Stone // 5). -p -f (setting a breakpoint by comparing a reg-exp 422b9c1b51eSKate Stone // to source text) 423b9c1b51eSKate Stone // 6). -E [-w -h] (setting a breakpoint for exceptions for a 424b9c1b51eSKate Stone // given language.) 42530fdc8d8SChris Lattner 42630fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 42730fdc8d8SChris Lattner 42830fdc8d8SChris Lattner if (m_options.m_line_num != 0) 42930fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 43030fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 43130fdc8d8SChris Lattner break_type = eSetTypeAddress; 432fab10e89SJim Ingham else if (!m_options.m_func_names.empty()) 43330fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 43430fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 43530fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 436969795f1SJim Ingham else if (!m_options.m_source_text_regexp.empty()) 437969795f1SJim Ingham break_type = eSetTypeSourceRegexp; 438a72b31c7SJim Ingham else if (m_options.m_exception_language != eLanguageTypeUnknown) 439fab10e89SJim Ingham break_type = eSetTypeException; 44030fdc8d8SChris Lattner 4419e85e5a8SEugene Zelenko Breakpoint *bp = nullptr; 442274060b6SGreg Clayton FileSpec module_spec; 443a8558b62SJim Ingham const bool internal = false; 444a8558b62SJim Ingham 445b9c1b51eSKate Stone // If the user didn't specify skip-prologue, having an offset should turn 446b9c1b51eSKate Stone // that off. 447b9c1b51eSKate Stone if (m_options.m_offset_addr != 0 && 448b9c1b51eSKate Stone m_options.m_skip_prologue == eLazyBoolCalculate) 4492411167fSJim Ingham m_options.m_skip_prologue = eLazyBoolNo; 4502411167fSJim Ingham 451b9c1b51eSKate Stone switch (break_type) { 45230fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 45330fdc8d8SChris Lattner { 45430fdc8d8SChris Lattner FileSpec file; 455c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 456b9c1b51eSKate Stone if (num_files == 0) { 457b9c1b51eSKate Stone if (!GetDefaultFile(target, file, result)) { 45887df91b8SJim Ingham result.AppendError("No file supplied and no default file available."); 45987df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 46087df91b8SJim Ingham return false; 46187df91b8SJim Ingham } 462b9c1b51eSKate Stone } else if (num_files > 1) { 463b9c1b51eSKate Stone result.AppendError("Only one file at a time is allowed for file and " 464b9c1b51eSKate Stone "line breakpoints."); 46587df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 46687df91b8SJim Ingham return false; 467b9c1b51eSKate Stone } else 46887df91b8SJim Ingham file = m_options.m_filenames.GetFileSpecAtIndex(0); 46930fdc8d8SChris Lattner 4701f746071SGreg Clayton // Only check for inline functions if 4711f746071SGreg Clayton LazyBool check_inlines = eLazyBoolCalculate; 4721f746071SGreg Clayton 473b9c1b51eSKate Stone bp = target 474b9c1b51eSKate Stone ->CreateBreakpoint(&(m_options.m_modules), file, 475b9c1b51eSKate Stone m_options.m_line_num, m_options.m_offset_addr, 476b9c1b51eSKate Stone check_inlines, m_options.m_skip_prologue, 477b9c1b51eSKate Stone internal, m_options.m_hardware, 478b9c1b51eSKate Stone m_options.m_move_to_nearest_code) 479b9c1b51eSKate Stone .get(); 480b9c1b51eSKate Stone } break; 4816eee5aa0SGreg Clayton 48230fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 483055a08a4SJim Ingham { 484b9c1b51eSKate Stone // If a shared library has been specified, make an lldb_private::Address 485b9c1b51eSKate Stone // with the library, and 486b9c1b51eSKate Stone // use that. That way the address breakpoint will track the load location 487b9c1b51eSKate Stone // of the library. 488055a08a4SJim Ingham size_t num_modules_specified = m_options.m_modules.GetSize(); 489b9c1b51eSKate Stone if (num_modules_specified == 1) { 490b9c1b51eSKate Stone const FileSpec *file_spec = 491b9c1b51eSKate Stone m_options.m_modules.GetFileSpecPointerAtIndex(0); 492b9c1b51eSKate Stone bp = target 493b9c1b51eSKate Stone ->CreateAddressInModuleBreakpoint(m_options.m_load_addr, 494b9c1b51eSKate Stone internal, file_spec, 495b9c1b51eSKate Stone m_options.m_hardware) 496b9c1b51eSKate Stone .get(); 497b9c1b51eSKate Stone } else if (num_modules_specified == 0) { 498b9c1b51eSKate Stone bp = target 499b9c1b51eSKate Stone ->CreateBreakpoint(m_options.m_load_addr, internal, 500b9c1b51eSKate Stone m_options.m_hardware) 501b9c1b51eSKate Stone .get(); 502b9c1b51eSKate Stone } else { 503b9c1b51eSKate Stone result.AppendError("Only one shared library can be specified for " 504b9c1b51eSKate Stone "address breakpoints."); 505055a08a4SJim Ingham result.SetStatus(eReturnStatusFailed); 506055a08a4SJim Ingham return false; 507055a08a4SJim Ingham } 50830fdc8d8SChris Lattner break; 509055a08a4SJim Ingham } 51030fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 5110c5cd90dSGreg Clayton { 5120c5cd90dSGreg Clayton uint32_t name_type_mask = m_options.m_func_name_type_mask; 5130c5cd90dSGreg Clayton 5140c5cd90dSGreg Clayton if (name_type_mask == 0) 515e02b8504SGreg Clayton name_type_mask = eFunctionNameTypeAuto; 5160c5cd90dSGreg Clayton 517b9c1b51eSKate Stone bp = target 518b9c1b51eSKate Stone ->CreateBreakpoint( 519b9c1b51eSKate Stone &(m_options.m_modules), &(m_options.m_filenames), 520b9c1b51eSKate Stone m_options.m_func_names, name_type_mask, m_options.m_language, 521b9c1b51eSKate Stone m_options.m_offset_addr, m_options.m_skip_prologue, internal, 522b9c1b51eSKate Stone m_options.m_hardware) 523b9c1b51eSKate Stone .get(); 524b9c1b51eSKate Stone } break; 5250c5cd90dSGreg Clayton 526b9c1b51eSKate Stone case eSetTypeFunctionRegexp: // Breakpoint by regular expression function 527b9c1b51eSKate Stone // name 52830fdc8d8SChris Lattner { 52930fdc8d8SChris Lattner RegularExpression regexp(m_options.m_func_regexp.c_str()); 530b9c1b51eSKate Stone if (!regexp.IsValid()) { 531969795f1SJim Ingham char err_str[1024]; 532969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 533b9c1b51eSKate Stone result.AppendErrorWithFormat( 534b9c1b51eSKate Stone "Function name regular expression could not be compiled: \"%s\"", 535969795f1SJim Ingham err_str); 53630fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 537969795f1SJim Ingham return false; 53830fdc8d8SChris Lattner } 53987df91b8SJim Ingham 540b9c1b51eSKate Stone bp = target 541b9c1b51eSKate Stone ->CreateFuncRegexBreakpoint( 542b9c1b51eSKate Stone &(m_options.m_modules), &(m_options.m_filenames), regexp, 543b9c1b51eSKate Stone m_options.m_language, m_options.m_skip_prologue, internal, 544b9c1b51eSKate Stone m_options.m_hardware) 545b9c1b51eSKate Stone .get(); 546e14dc268SJim Ingham } 547e14dc268SJim Ingham break; 548969795f1SJim Ingham case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. 549969795f1SJim Ingham { 550c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 55187df91b8SJim Ingham 552b9c1b51eSKate Stone if (num_files == 0 && !m_options.m_all_files) { 553969795f1SJim Ingham FileSpec file; 554b9c1b51eSKate Stone if (!GetDefaultFile(target, file, result)) { 555b9c1b51eSKate Stone result.AppendError( 556b9c1b51eSKate Stone "No files provided and could not find default file."); 55787df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 55887df91b8SJim Ingham return false; 559b9c1b51eSKate Stone } else { 56087df91b8SJim Ingham m_options.m_filenames.Append(file); 56187df91b8SJim Ingham } 56287df91b8SJim Ingham } 5630c5cd90dSGreg Clayton 564969795f1SJim Ingham RegularExpression regexp(m_options.m_source_text_regexp.c_str()); 565b9c1b51eSKate Stone if (!regexp.IsValid()) { 566969795f1SJim Ingham char err_str[1024]; 567969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 568b9c1b51eSKate Stone result.AppendErrorWithFormat( 569b9c1b51eSKate Stone "Source text regular expression could not be compiled: \"%s\"", 570969795f1SJim Ingham err_str); 571969795f1SJim Ingham result.SetStatus(eReturnStatusFailed); 572969795f1SJim Ingham return false; 573969795f1SJim Ingham } 574b9c1b51eSKate Stone bp = target 575b9c1b51eSKate Stone ->CreateSourceRegexBreakpoint( 576b9c1b51eSKate Stone &(m_options.m_modules), &(m_options.m_filenames), 577b9c1b51eSKate Stone m_options.m_source_regex_func_names, regexp, internal, 578b9c1b51eSKate Stone m_options.m_hardware, m_options.m_move_to_nearest_code) 579b9c1b51eSKate Stone .get(); 580b9c1b51eSKate Stone } break; 581b9c1b51eSKate Stone case eSetTypeException: { 582a72b31c7SJim Ingham Error precond_error; 583b9c1b51eSKate Stone bp = target 584b9c1b51eSKate Stone ->CreateExceptionBreakpoint( 585b9c1b51eSKate Stone m_options.m_exception_language, m_options.m_catch_bp, 586b9c1b51eSKate Stone m_options.m_throw_bp, internal, 587b9c1b51eSKate Stone &m_options.m_exception_extra_args, &precond_error) 588b9c1b51eSKate Stone .get(); 589b9c1b51eSKate Stone if (precond_error.Fail()) { 590b9c1b51eSKate Stone result.AppendErrorWithFormat( 591b9c1b51eSKate Stone "Error setting extra exception arguments: %s", 592a72b31c7SJim Ingham precond_error.AsCString()); 593a72b31c7SJim Ingham target->RemoveBreakpointByID(bp->GetID()); 594a72b31c7SJim Ingham result.SetStatus(eReturnStatusFailed); 595a72b31c7SJim Ingham return false; 596a72b31c7SJim Ingham } 597b9c1b51eSKate Stone } break; 59830fdc8d8SChris Lattner default: 59930fdc8d8SChris Lattner break; 60030fdc8d8SChris Lattner } 60130fdc8d8SChris Lattner 6021b54c88cSJim Ingham // Now set the various options that were passed in: 603b9c1b51eSKate Stone if (bp) { 6041b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 6051b54c88cSJim Ingham bp->SetThreadID(m_options.m_thread_id); 6061b54c88cSJim Ingham 607c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 6081b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 6091b54c88cSJim Ingham 6101b54c88cSJim Ingham if (!m_options.m_thread_name.empty()) 611b9c1b51eSKate Stone bp->GetOptions()->GetThreadSpec()->SetName( 612b9c1b51eSKate Stone m_options.m_thread_name.c_str()); 6131b54c88cSJim Ingham 6141b54c88cSJim Ingham if (!m_options.m_queue_name.empty()) 615b9c1b51eSKate Stone bp->GetOptions()->GetThreadSpec()->SetQueueName( 616b9c1b51eSKate Stone m_options.m_queue_name.c_str()); 6171b54c88cSJim Ingham 618c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 6191b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 6207d49c9c8SJohnny Chen 6217d49c9c8SJohnny Chen if (!m_options.m_condition.empty()) 6227d49c9c8SJohnny Chen bp->GetOptions()->SetCondition(m_options.m_condition.c_str()); 623ca36cd16SJim Ingham 624b9c1b51eSKate Stone if (!m_options.m_breakpoint_names.empty()) { 625b9c1b51eSKate Stone Error error; // We don't need to check the error here, since the option 626b9c1b51eSKate Stone // parser checked it... 6275e09c8c3SJim Ingham for (auto name : m_options.m_breakpoint_names) 6285e09c8c3SJim Ingham bp->AddName(name.c_str(), error); 6295e09c8c3SJim Ingham } 6305e09c8c3SJim Ingham 631ca36cd16SJim Ingham bp->SetOneShot(m_options.m_one_shot); 6321b54c88cSJim Ingham } 6331b54c88cSJim Ingham 634b9c1b51eSKate Stone if (bp) { 63585e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 6361391cc7dSJim Ingham const bool show_locations = false; 637b9c1b51eSKate Stone bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, 638b9c1b51eSKate Stone show_locations); 6394aeb1989SJim Ingham if (target == m_interpreter.GetDebugger().GetDummyTarget()) 640b9c1b51eSKate Stone output_stream.Printf("Breakpoint set in dummy target, will get copied " 641b9c1b51eSKate Stone "into future targets.\n"); 642b9c1b51eSKate Stone else { 643b9c1b51eSKate Stone // Don't print out this warning for exception breakpoints. They can get 644b9c1b51eSKate Stone // set before the target 645b9c1b51eSKate Stone // is set, but we won't know how to actually set the breakpoint till we 646b9c1b51eSKate Stone // run. 647b9c1b51eSKate Stone if (bp->GetNumLocations() == 0 && break_type != eSetTypeException) { 648b9c1b51eSKate Stone output_stream.Printf("WARNING: Unable to resolve breakpoint to any " 649b9c1b51eSKate Stone "actual locations.\n"); 6504aeb1989SJim Ingham } 6514aeb1989SJim Ingham } 65230fdc8d8SChris Lattner result.SetStatus(eReturnStatusSuccessFinishResult); 653b9c1b51eSKate Stone } else if (!bp) { 65430fdc8d8SChris Lattner result.AppendError("Breakpoint creation failed: No breakpoint created."); 65530fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 65630fdc8d8SChris Lattner } 65730fdc8d8SChris Lattner 65830fdc8d8SChris Lattner return result.Succeeded(); 65930fdc8d8SChris Lattner } 66030fdc8d8SChris Lattner 6615a988416SJim Ingham private: 662b9c1b51eSKate Stone bool GetDefaultFile(Target *target, FileSpec &file, 663b9c1b51eSKate Stone CommandReturnObject &result) { 6645a988416SJim Ingham uint32_t default_line; 6655a988416SJim Ingham // First use the Source Manager's default file. 6665a988416SJim Ingham // Then use the current stack frame's file. 667b9c1b51eSKate Stone if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) { 668b57e4a1bSJason Molenda StackFrame *cur_frame = m_exe_ctx.GetFramePtr(); 669b9c1b51eSKate Stone if (cur_frame == nullptr) { 670b9c1b51eSKate Stone result.AppendError( 671b9c1b51eSKate Stone "No selected frame to use to find the default file."); 6725a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 6735a988416SJim Ingham return false; 674b9c1b51eSKate Stone } else if (!cur_frame->HasDebugInformation()) { 675b9c1b51eSKate Stone result.AppendError("Cannot use the selected frame to find the default " 676b9c1b51eSKate Stone "file, it has no debug info."); 6775a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 6785a988416SJim Ingham return false; 679b9c1b51eSKate Stone } else { 680b9c1b51eSKate Stone const SymbolContext &sc = 681b9c1b51eSKate Stone cur_frame->GetSymbolContext(eSymbolContextLineEntry); 682b9c1b51eSKate Stone if (sc.line_entry.file) { 6835a988416SJim Ingham file = sc.line_entry.file; 684b9c1b51eSKate Stone } else { 685b9c1b51eSKate Stone result.AppendError("Can't find the file for the selected frame to " 686b9c1b51eSKate Stone "use as the default file."); 6875a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 6885a988416SJim Ingham return false; 6895a988416SJim Ingham } 6905a988416SJim Ingham } 6915a988416SJim Ingham } 6925a988416SJim Ingham return true; 6935a988416SJim Ingham } 6945a988416SJim Ingham 6955a988416SJim Ingham CommandOptions m_options; 6965a988416SJim Ingham }; 6979e85e5a8SEugene Zelenko 6985a988416SJim Ingham // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to 6995a988416SJim Ingham // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately. 7005a988416SJim Ingham #define LLDB_OPT_FILE (LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2) 7015a988416SJim Ingham #define LLDB_OPT_NOT_10 (LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10) 7025a988416SJim Ingham #define LLDB_OPT_SKIP_PROLOGUE (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8)) 7032411167fSJim Ingham #define LLDB_OPT_OFFSET_APPLIES (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8)) 704055ad9beSIlia K #define LLDB_OPT_MOVE_TO_NEAREST_CODE (LLDB_OPT_SET_1 | LLDB_OPT_SET_9) 7050fcdac36SJim Ingham #define LLDB_OPT_EXPR_LANGUAGE (LLDB_OPT_SET_FROM_TO(3, 8)) 7065a988416SJim Ingham 707b9c1b51eSKate Stone OptionDefinition CommandObjectBreakpointSet::CommandOptions::g_option_table[] = 7085a988416SJim Ingham { 709ac9c3a62SKate Stone // clang-format off 710ac9c3a62SKate Stone {LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Set the breakpoint only in this shared library. Can repeat this option " 711ac9c3a62SKate Stone "multiple times to specify multiple shared libraries."}, 712ac9c3a62SKate Stone {LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." }, 713ac9c3a62SKate Stone {LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "The breakpoint is deleted the first time it causes a stop." }, 714ac9c3a62SKate Stone {LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."}, 715ac9c3a62SKate Stone {LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose indeX matches this argument."}, 716ac9c3a62SKate Stone {LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."}, 717ac9c3a62SKate Stone {LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this " 718ac9c3a62SKate Stone "argument."}, 719ac9c3a62SKate Stone {LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Require the breakpoint to use hardware breakpoints."}, 720ac9c3a62SKate Stone {LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by " 721ac9c3a62SKate Stone "this argument."}, 722ac9c3a62SKate Stone {LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specifies the source file in which to set this breakpoint. Note, by default " 723ac9c3a62SKate Stone "lldb only looks for files that are #included if they use the standard include " 724ac9c3a62SKate Stone "file extensions. To set breakpoints on .c/.cpp/.m/.mm files that are " 725ac9c3a62SKate Stone "#included, set target.inline-breakpoint-strategy to \"always\"."}, 726ac9c3a62SKate Stone {LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Specifies the line number on which to set this breakpoint."}, 7275a988416SJim Ingham 7285a988416SJim Ingham // Comment out this option for the moment, as we don't actually use it, but will in the future. 7295a988416SJim Ingham // This way users won't see it, but the infrastructure is left in place. 7309e85e5a8SEugene Zelenko // { 0, false, "column", 'C', OptionParser::eRequiredArgument, nullptr, "<column>", 7315a988416SJim Ingham // "Set the breakpoint by source location at this particular column."}, 7325a988416SJim Ingham 733ac9c3a62SKate Stone {LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Set the breakpoint at the specified address. If the address maps uniquely to " 734ac9c3a62SKate Stone "a particular binary, then the address will be converted to a \"file\" " 735ac9c3a62SKate Stone "address, so that the breakpoint will track that binary+offset no matter where " 736ac9c3a62SKate Stone "the binary eventually loads. Alternately, if you also specify the module - " 737ac9c3a62SKate Stone "with the -s option - then the address will be treated as a file address in " 738ac9c3a62SKate Stone "that module, and resolved accordingly. Again, this will allow lldb to track " 739ac9c3a62SKate Stone "that offset on subsequent reloads. The module need not have been loaded at " 740ac9c3a62SKate Stone "the time you specify this breakpoint, and will get resolved when the module " 741ac9c3a62SKate Stone "is loaded."}, 742ac9c3a62SKate Stone {LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the breakpoint by function name. Can be repeated multiple times to make " 743ac9c3a62SKate Stone "one breakpoint for multiple names"}, 744ac9c3a62SKate Stone {LLDB_OPT_SET_9, false, "source-regexp-function", 'X', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "When used with '-p' limits the source regex to source contained in the named " 745ac9c3a62SKate Stone "functions. Can be repeated multiple times."}, 746ac9c3a62SKate Stone {LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFullName, "Set the breakpoint by fully qualified function names. For C++ this means " 747ac9c3a62SKate Stone "namespaces and all arguments, and for Objective C this means a full function " 748ac9c3a62SKate Stone "prototype with class and selector. Can be repeated multiple times to make " 749ac9c3a62SKate Stone "one breakpoint for multiple names."}, 750ac9c3a62SKate Stone {LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSelector, "Set the breakpoint by ObjC selector name. Can be repeated multiple times to " 751ac9c3a62SKate Stone "make one breakpoint for multiple Selectors."}, 752ac9c3a62SKate Stone {LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeMethod, "Set the breakpoint by C++ method names. Can be repeated multiple times to " 753ac9c3a62SKate Stone "make one breakpoint for multiple methods."}, 754ac9c3a62SKate Stone {LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "Set the breakpoint by function name, evaluating a regular-expression to find " 755ac9c3a62SKate Stone "the function name(s)."}, 756ac9c3a62SKate Stone {LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the breakpoint by function basename (C++ namespaces and arguments will be " 757ac9c3a62SKate Stone "ignored). Can be repeated multiple times to make one breakpoint for multiple " 758ac9c3a62SKate Stone "symbols."}, 759ac9c3a62SKate Stone {LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "Set the breakpoint by specifying a regular expression which is matched " 760ac9c3a62SKate Stone "against the source text in a source file or files specified with the -f " 761ac9c3a62SKate Stone "option. The -f option can be specified more than once. If no source files " 762ac9c3a62SKate Stone "are specified, uses the current \"default source file\". If you want to " 763ac9c3a62SKate Stone "match against all source files, pass the \"--all-files\" option."}, 764ac9c3a62SKate Stone {LLDB_OPT_SET_9, false, "all-files", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "All files are searched for source pattern matches."}, 765ac9c3a62SKate Stone {LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Set the breakpoint on exceptions thrown by the specified language (without " 766ac9c3a62SKate Stone "options, on throw but not catch.)"}, 767ac9c3a62SKate Stone {LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Set the breakpoint on exception throW."}, 768ac9c3a62SKate Stone {LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Set the breakpoint on exception catcH."}, 7695a988416SJim Ingham 770a72b31c7SJim Ingham // Don't add this option till it actually does something useful... 7719e85e5a8SEugene Zelenko // { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName, 772a72b31c7SJim Ingham // "The breakpoint will only stop if an exception Object of this type is thrown. Can be repeated multiple times to stop for multiple object types" }, 773a72b31c7SJim Ingham 774ac9c3a62SKate Stone {LLDB_OPT_EXPR_LANGUAGE, false, "language", 'L', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Specifies the Language to use when interpreting the breakpoint's expression " 775ac9c3a62SKate Stone "(note: currently only implemented for setting breakpoints on identifiers). " 776ac9c3a62SKate Stone "If not set the target.language setting is used."}, 777ac9c3a62SKate Stone {LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "sKip the prologue if the breakpoint is at the beginning of a function. " 778ac9c3a62SKate Stone "If not set the target.skip-prologue setting is used."}, 779ac9c3a62SKate Stone {LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, " 780ac9c3a62SKate Stone "which prime new targets."}, 781ac9c3a62SKate Stone {LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Adds this to the list of names for this breakpoint."}, 782ac9c3a62SKate Stone {LLDB_OPT_OFFSET_APPLIES, false, "address-slide", 'R', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddress, "Add the specified offset to whatever address(es) the breakpoint resolves to. " 7832411167fSJim Ingham "At present this applies the offset directly as given, and doesn't try to align it to instruction boundaries."}, 784ac9c3a62SKate Stone {LLDB_OPT_MOVE_TO_NEAREST_CODE, false, "move-to-nearest-code", 'm', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Move breakpoints to nearest code. If not set the target.move-to-nearest-code " 785ac9c3a62SKate Stone "setting is used."}, 7869e85e5a8SEugene Zelenko {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} 787ac9c3a62SKate Stone // clang-format on 7885a988416SJim Ingham }; 7895a988416SJim Ingham 7905a988416SJim Ingham //------------------------------------------------------------------------- 7915a988416SJim Ingham // CommandObjectBreakpointModify 7925a988416SJim Ingham //------------------------------------------------------------------------- 7935a988416SJim Ingham #pragma mark Modify 7945a988416SJim Ingham 795b9c1b51eSKate Stone class CommandObjectBreakpointModify : public CommandObjectParsed { 7965a988416SJim Ingham public: 797b9c1b51eSKate Stone CommandObjectBreakpointModify(CommandInterpreter &interpreter) 798b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "breakpoint modify", 799b9c1b51eSKate Stone "Modify the options on a breakpoint or set of " 800b9c1b51eSKate Stone "breakpoints in the executable. " 801b9c1b51eSKate Stone "If no breakpoint is specified, acts on the last " 802b9c1b51eSKate Stone "created breakpoint. " 803b9c1b51eSKate Stone "With the exception of -e, -d and -i, passing an " 804b9c1b51eSKate Stone "empty argument clears the modification.", 8059e85e5a8SEugene Zelenko nullptr), 806b9c1b51eSKate Stone m_options() { 8075a988416SJim Ingham CommandArgumentEntry arg; 808b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 809b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 810b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 811b9c1b51eSKate Stone // arguments vector. 8125a988416SJim Ingham m_arguments.push_back(arg); 8135a988416SJim Ingham } 8145a988416SJim Ingham 8159e85e5a8SEugene Zelenko ~CommandObjectBreakpointModify() override = default; 8165a988416SJim Ingham 817b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 8185a988416SJim Ingham 819b9c1b51eSKate Stone class CommandOptions : public Options { 8205a988416SJim Ingham public: 821b9c1b51eSKate Stone CommandOptions() 822b9c1b51eSKate Stone : Options(), m_ignore_count(0), m_thread_id(LLDB_INVALID_THREAD_ID), 823b9c1b51eSKate Stone m_thread_id_passed(false), m_thread_index(UINT32_MAX), 824b9c1b51eSKate Stone m_thread_index_passed(false), m_thread_name(), m_queue_name(), 825b9c1b51eSKate Stone m_condition(), m_one_shot(false), m_enable_passed(false), 826b9c1b51eSKate Stone m_enable_value(false), m_name_passed(false), m_queue_passed(false), 827b9c1b51eSKate Stone m_condition_passed(false), m_one_shot_passed(false), 828b9c1b51eSKate Stone m_use_dummy(false) {} 8295a988416SJim Ingham 8309e85e5a8SEugene Zelenko ~CommandOptions() override = default; 8315a988416SJim Ingham 832b9c1b51eSKate Stone Error SetOptionValue(uint32_t option_idx, const char *option_arg, 833b9c1b51eSKate Stone ExecutionContext *execution_context) override { 8345a988416SJim Ingham Error error; 8353bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 8365a988416SJim Ingham 837b9c1b51eSKate Stone switch (short_option) { 8385a988416SJim Ingham case 'c': 8399e85e5a8SEugene Zelenko if (option_arg != nullptr) 8405a988416SJim Ingham m_condition.assign(option_arg); 8415a988416SJim Ingham else 8425a988416SJim Ingham m_condition.clear(); 8435a988416SJim Ingham m_condition_passed = true; 8445a988416SJim Ingham break; 8455a988416SJim Ingham case 'd': 8465a988416SJim Ingham m_enable_passed = true; 8475a988416SJim Ingham m_enable_value = false; 8485a988416SJim Ingham break; 84933df7cd3SJim Ingham case 'D': 85033df7cd3SJim Ingham m_use_dummy = true; 85133df7cd3SJim Ingham break; 8525a988416SJim Ingham case 'e': 8535a988416SJim Ingham m_enable_passed = true; 8545a988416SJim Ingham m_enable_value = true; 8555a988416SJim Ingham break; 8565a988416SJim Ingham case 'i': 8575275aaa0SVince Harron m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); 8585a988416SJim Ingham if (m_ignore_count == UINT32_MAX) 859b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid ignore count '%s'", 860b9c1b51eSKate Stone option_arg); 8615a988416SJim Ingham break; 862b9c1b51eSKate Stone case 'o': { 863ca36cd16SJim Ingham bool value, success; 864ca36cd16SJim Ingham value = Args::StringToBoolean(option_arg, false, &success); 865b9c1b51eSKate Stone if (success) { 866ca36cd16SJim Ingham m_one_shot_passed = true; 867ca36cd16SJim Ingham m_one_shot = value; 868b9c1b51eSKate Stone } else 869b9c1b51eSKate Stone error.SetErrorStringWithFormat( 870b9c1b51eSKate Stone "invalid boolean value '%s' passed for -o option", option_arg); 871b9c1b51eSKate Stone } break; 8725a988416SJim Ingham case 't': 873b9c1b51eSKate Stone if (option_arg[0] == '\0') { 8745a988416SJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 8755a988416SJim Ingham m_thread_id_passed = true; 876b9c1b51eSKate Stone } else { 877b9c1b51eSKate Stone m_thread_id = 878b9c1b51eSKate Stone StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 8795a988416SJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 880b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid thread id string '%s'", 881b9c1b51eSKate Stone option_arg); 8825a988416SJim Ingham else 8835a988416SJim Ingham m_thread_id_passed = true; 8845a988416SJim Ingham } 8855a988416SJim Ingham break; 8865a988416SJim Ingham case 'T': 8879e85e5a8SEugene Zelenko if (option_arg != nullptr) 8885a988416SJim Ingham m_thread_name.assign(option_arg); 8895a988416SJim Ingham else 8905a988416SJim Ingham m_thread_name.clear(); 8915a988416SJim Ingham m_name_passed = true; 8925a988416SJim Ingham break; 8935a988416SJim Ingham case 'q': 8949e85e5a8SEugene Zelenko if (option_arg != nullptr) 8955a988416SJim Ingham m_queue_name.assign(option_arg); 8965a988416SJim Ingham else 8975a988416SJim Ingham m_queue_name.clear(); 8985a988416SJim Ingham m_queue_passed = true; 8995a988416SJim Ingham break; 9005a988416SJim Ingham case 'x': 901b9c1b51eSKate Stone if (option_arg[0] == '\n') { 9025a988416SJim Ingham m_thread_index = UINT32_MAX; 9035a988416SJim Ingham m_thread_index_passed = true; 904b9c1b51eSKate Stone } else { 9055275aaa0SVince Harron m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); 9065a988416SJim Ingham if (m_thread_id == UINT32_MAX) 907b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid thread index string '%s'", 908b9c1b51eSKate Stone option_arg); 9095a988416SJim Ingham else 9105a988416SJim Ingham m_thread_index_passed = true; 9115a988416SJim Ingham } 9125a988416SJim Ingham break; 9135a988416SJim Ingham default: 914b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 915b9c1b51eSKate Stone short_option); 9165a988416SJim Ingham break; 9175a988416SJim Ingham } 9185a988416SJim Ingham 9195a988416SJim Ingham return error; 9205a988416SJim Ingham } 9219e85e5a8SEugene Zelenko 922b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 9235a988416SJim Ingham m_ignore_count = 0; 9245a988416SJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 9255a988416SJim Ingham m_thread_id_passed = false; 9265a988416SJim Ingham m_thread_index = UINT32_MAX; 9275a988416SJim Ingham m_thread_index_passed = false; 9285a988416SJim Ingham m_thread_name.clear(); 9295a988416SJim Ingham m_queue_name.clear(); 9305a988416SJim Ingham m_condition.clear(); 931ca36cd16SJim Ingham m_one_shot = false; 9325a988416SJim Ingham m_enable_passed = false; 9335a988416SJim Ingham m_queue_passed = false; 9345a988416SJim Ingham m_name_passed = false; 9355a988416SJim Ingham m_condition_passed = false; 936ca36cd16SJim Ingham m_one_shot_passed = false; 93733df7cd3SJim Ingham m_use_dummy = false; 9385a988416SJim Ingham } 9395a988416SJim Ingham 940b9c1b51eSKate Stone const OptionDefinition *GetDefinitions() override { return g_option_table; } 9415a988416SJim Ingham 9425a988416SJim Ingham // Options table: Required for subclasses of Options. 9435a988416SJim Ingham 9445a988416SJim Ingham static OptionDefinition g_option_table[]; 9455a988416SJim Ingham 9465a988416SJim Ingham // Instance variables to hold the values for command options. 9475a988416SJim Ingham 9485a988416SJim Ingham uint32_t m_ignore_count; 9495a988416SJim Ingham lldb::tid_t m_thread_id; 9505a988416SJim Ingham bool m_thread_id_passed; 9515a988416SJim Ingham uint32_t m_thread_index; 9525a988416SJim Ingham bool m_thread_index_passed; 9535a988416SJim Ingham std::string m_thread_name; 9545a988416SJim Ingham std::string m_queue_name; 9555a988416SJim Ingham std::string m_condition; 956ca36cd16SJim Ingham bool m_one_shot; 9575a988416SJim Ingham bool m_enable_passed; 9585a988416SJim Ingham bool m_enable_value; 9595a988416SJim Ingham bool m_name_passed; 9605a988416SJim Ingham bool m_queue_passed; 9615a988416SJim Ingham bool m_condition_passed; 962ca36cd16SJim Ingham bool m_one_shot_passed; 96333df7cd3SJim Ingham bool m_use_dummy; 9645a988416SJim Ingham }; 9655a988416SJim Ingham 9665a988416SJim Ingham protected: 967b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 96833df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 969b9c1b51eSKate Stone if (target == nullptr) { 9705a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 9715a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 9725a988416SJim Ingham return false; 9735a988416SJim Ingham } 9745a988416SJim Ingham 975bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 976bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 9775a988416SJim Ingham 9785a988416SJim Ingham BreakpointIDList valid_bp_ids; 9795a988416SJim Ingham 980b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 981b9c1b51eSKate Stone command, target, result, &valid_bp_ids); 9825a988416SJim Ingham 983b9c1b51eSKate Stone if (result.Succeeded()) { 9845a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 985b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 9865a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 9875a988416SJim Ingham 988b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 989b9c1b51eSKate Stone Breakpoint *bp = 990b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 991b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 992b9c1b51eSKate Stone BreakpointLocation *location = 993b9c1b51eSKate Stone bp->FindLocationByID(cur_bp_id.GetLocationID()).get(); 994b9c1b51eSKate Stone if (location) { 9955a988416SJim Ingham if (m_options.m_thread_id_passed) 9965a988416SJim Ingham location->SetThreadID(m_options.m_thread_id); 9975a988416SJim Ingham 9985a988416SJim Ingham if (m_options.m_thread_index_passed) 9995a988416SJim Ingham location->SetThreadIndex(m_options.m_thread_index); 10005a988416SJim Ingham 10015a988416SJim Ingham if (m_options.m_name_passed) 10025a988416SJim Ingham location->SetThreadName(m_options.m_thread_name.c_str()); 10035a988416SJim Ingham 10045a988416SJim Ingham if (m_options.m_queue_passed) 10055a988416SJim Ingham location->SetQueueName(m_options.m_queue_name.c_str()); 10065a988416SJim Ingham 10075a988416SJim Ingham if (m_options.m_ignore_count != 0) 10085a988416SJim Ingham location->SetIgnoreCount(m_options.m_ignore_count); 10095a988416SJim Ingham 10105a988416SJim Ingham if (m_options.m_enable_passed) 10115a988416SJim Ingham location->SetEnabled(m_options.m_enable_value); 10125a988416SJim Ingham 10135a988416SJim Ingham if (m_options.m_condition_passed) 10145a988416SJim Ingham location->SetCondition(m_options.m_condition.c_str()); 10155a988416SJim Ingham } 1016b9c1b51eSKate Stone } else { 10175a988416SJim Ingham if (m_options.m_thread_id_passed) 10185a988416SJim Ingham bp->SetThreadID(m_options.m_thread_id); 10195a988416SJim Ingham 10205a988416SJim Ingham if (m_options.m_thread_index_passed) 10215a988416SJim Ingham bp->SetThreadIndex(m_options.m_thread_index); 10225a988416SJim Ingham 10235a988416SJim Ingham if (m_options.m_name_passed) 10245a988416SJim Ingham bp->SetThreadName(m_options.m_thread_name.c_str()); 10255a988416SJim Ingham 10265a988416SJim Ingham if (m_options.m_queue_passed) 10275a988416SJim Ingham bp->SetQueueName(m_options.m_queue_name.c_str()); 10285a988416SJim Ingham 10295a988416SJim Ingham if (m_options.m_ignore_count != 0) 10305a988416SJim Ingham bp->SetIgnoreCount(m_options.m_ignore_count); 10315a988416SJim Ingham 10325a988416SJim Ingham if (m_options.m_enable_passed) 10335a988416SJim Ingham bp->SetEnabled(m_options.m_enable_value); 10345a988416SJim Ingham 10355a988416SJim Ingham if (m_options.m_condition_passed) 10365a988416SJim Ingham bp->SetCondition(m_options.m_condition.c_str()); 10375a988416SJim Ingham } 10385a988416SJim Ingham } 10395a988416SJim Ingham } 10405a988416SJim Ingham } 10415a988416SJim Ingham 10425a988416SJim Ingham return result.Succeeded(); 10435a988416SJim Ingham } 10445a988416SJim Ingham 10455a988416SJim Ingham private: 10465a988416SJim Ingham CommandOptions m_options; 10475a988416SJim Ingham }; 10485a988416SJim Ingham 10495a988416SJim Ingham #pragma mark Modify::CommandOptions 10505a988416SJim Ingham OptionDefinition 1051b9c1b51eSKate Stone CommandObjectBreakpointModify::CommandOptions::g_option_table[] = { 1052ac9c3a62SKate Stone // clang-format off 10539e85e5a8SEugene Zelenko {LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping."}, 10549e85e5a8SEugene Zelenko {LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "The breakpoint is deleted the first time it stop causes a stop."}, 10559e85e5a8SEugene Zelenko {LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose index matches this argument."}, 10569e85e5a8SEugene Zelenko {LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."}, 10579e85e5a8SEugene Zelenko {LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."}, 10589e85e5a8SEugene Zelenko {LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."}, 10599e85e5a8SEugene Zelenko {LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."}, 10609e85e5a8SEugene Zelenko {LLDB_OPT_SET_1, false, "enable", 'e', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable the breakpoint."}, 10619e85e5a8SEugene Zelenko {LLDB_OPT_SET_2, false, "disable", 'd', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Disable the breakpoint."}, 10629e85e5a8SEugene Zelenko {LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, 10639e85e5a8SEugene Zelenko {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} 1064ac9c3a62SKate Stone // clang-format on 10655a988416SJim Ingham }; 10665a988416SJim Ingham 10675a988416SJim Ingham //------------------------------------------------------------------------- 10685a988416SJim Ingham // CommandObjectBreakpointEnable 10695a988416SJim Ingham //------------------------------------------------------------------------- 10705a988416SJim Ingham #pragma mark Enable 10715a988416SJim Ingham 1072b9c1b51eSKate Stone class CommandObjectBreakpointEnable : public CommandObjectParsed { 10735a988416SJim Ingham public: 1074b9c1b51eSKate Stone CommandObjectBreakpointEnable(CommandInterpreter &interpreter) 1075b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "enable", 1076b9c1b51eSKate Stone "Enable the specified disabled breakpoint(s). If " 1077b9c1b51eSKate Stone "no breakpoints are specified, enable all of them.", 1078b9c1b51eSKate Stone nullptr) { 10795a988416SJim Ingham CommandArgumentEntry arg; 1080b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1081b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1082b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1083b9c1b51eSKate Stone // arguments vector. 10845a988416SJim Ingham m_arguments.push_back(arg); 10855a988416SJim Ingham } 10865a988416SJim Ingham 10879e85e5a8SEugene Zelenko ~CommandObjectBreakpointEnable() override = default; 10885a988416SJim Ingham 10895a988416SJim Ingham protected: 1090b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1091893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1092b9c1b51eSKate Stone if (target == nullptr) { 10935a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 10945a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 10955a988416SJim Ingham return false; 10965a988416SJim Ingham } 10975a988416SJim Ingham 1098bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1099bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 11005a988416SJim Ingham 11015a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 11025a988416SJim Ingham 11035a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 11045a988416SJim Ingham 1105b9c1b51eSKate Stone if (num_breakpoints == 0) { 11065a988416SJim Ingham result.AppendError("No breakpoints exist to be enabled."); 11075a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 11085a988416SJim Ingham return false; 11095a988416SJim Ingham } 11105a988416SJim Ingham 1111b9c1b51eSKate Stone if (command.GetArgumentCount() == 0) { 11125a988416SJim Ingham // No breakpoint selected; enable all currently set breakpoints. 11135a988416SJim Ingham target->EnableAllBreakpoints(); 1114b9c1b51eSKate Stone result.AppendMessageWithFormat("All breakpoints enabled. (%" PRIu64 1115b9c1b51eSKate Stone " breakpoints)\n", 1116b9c1b51eSKate Stone (uint64_t)num_breakpoints); 11175a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1118b9c1b51eSKate Stone } else { 11195a988416SJim Ingham // Particular breakpoint selected; enable that breakpoint. 11205a988416SJim Ingham BreakpointIDList valid_bp_ids; 1121b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1122b9c1b51eSKate Stone command, target, result, &valid_bp_ids); 11235a988416SJim Ingham 1124b9c1b51eSKate Stone if (result.Succeeded()) { 11255a988416SJim Ingham int enable_count = 0; 11265a988416SJim Ingham int loc_count = 0; 11275a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1128b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 11295a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 11305a988416SJim Ingham 1131b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1132b9c1b51eSKate Stone Breakpoint *breakpoint = 1133b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1134b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1135b9c1b51eSKate Stone BreakpointLocation *location = 1136b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1137b9c1b51eSKate Stone if (location) { 11385a988416SJim Ingham location->SetEnabled(true); 11395a988416SJim Ingham ++loc_count; 11405a988416SJim Ingham } 1141b9c1b51eSKate Stone } else { 11425a988416SJim Ingham breakpoint->SetEnabled(true); 11435a988416SJim Ingham ++enable_count; 11445a988416SJim Ingham } 11455a988416SJim Ingham } 11465a988416SJim Ingham } 1147b9c1b51eSKate Stone result.AppendMessageWithFormat("%d breakpoints enabled.\n", 1148b9c1b51eSKate Stone enable_count + loc_count); 11495a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 11505a988416SJim Ingham } 11515a988416SJim Ingham } 11525a988416SJim Ingham 11535a988416SJim Ingham return result.Succeeded(); 11545a988416SJim Ingham } 11555a988416SJim Ingham }; 11565a988416SJim Ingham 11575a988416SJim Ingham //------------------------------------------------------------------------- 11585a988416SJim Ingham // CommandObjectBreakpointDisable 11595a988416SJim Ingham //------------------------------------------------------------------------- 11605a988416SJim Ingham #pragma mark Disable 11615a988416SJim Ingham 1162b9c1b51eSKate Stone class CommandObjectBreakpointDisable : public CommandObjectParsed { 11635a988416SJim Ingham public: 11647428a18cSKate Stone CommandObjectBreakpointDisable(CommandInterpreter &interpreter) 1165b9c1b51eSKate Stone : CommandObjectParsed( 1166b9c1b51eSKate Stone interpreter, "breakpoint disable", 1167b9c1b51eSKate Stone "Disable the specified breakpoint(s) without deleting " 11687428a18cSKate Stone "them. If none are specified, disable all " 11697428a18cSKate Stone "breakpoints.", 1170b9c1b51eSKate Stone nullptr) { 1171b9c1b51eSKate Stone SetHelpLong( 1172b9c1b51eSKate Stone "Disable the specified breakpoint(s) without deleting them. \ 11737428a18cSKate Stone If none are specified, disable all breakpoints." 11747428a18cSKate Stone R"( 1175ea671fbdSKate Stone 11767428a18cSKate Stone )" 11777428a18cSKate Stone "Note: disabling a breakpoint will cause none of its locations to be hit \ 11787428a18cSKate Stone regardless of whether individual locations are enabled or disabled. After the sequence:" 11797428a18cSKate Stone R"( 1180ea671fbdSKate Stone 1181ea671fbdSKate Stone (lldb) break disable 1 1182ea671fbdSKate Stone (lldb) break enable 1.1 1183ea671fbdSKate Stone 1184ea671fbdSKate Stone execution will NOT stop at location 1.1. To achieve that, type: 1185ea671fbdSKate Stone 1186ea671fbdSKate Stone (lldb) break disable 1.* 1187ea671fbdSKate Stone (lldb) break enable 1.1 1188ea671fbdSKate Stone 11897428a18cSKate Stone )" 11907428a18cSKate Stone "The first command disables all locations for breakpoint 1, \ 11917428a18cSKate Stone the second re-enables the first location."); 1192b0fac509SJim Ingham 11935a988416SJim Ingham CommandArgumentEntry arg; 1194b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1195b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1196b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1197b9c1b51eSKate Stone // arguments vector. 11985a988416SJim Ingham m_arguments.push_back(arg); 11995a988416SJim Ingham } 12005a988416SJim Ingham 12019e85e5a8SEugene Zelenko ~CommandObjectBreakpointDisable() override = default; 12025a988416SJim Ingham 12035a988416SJim Ingham protected: 1204b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1205893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1206b9c1b51eSKate Stone if (target == nullptr) { 12075a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 12085a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 12095a988416SJim Ingham return false; 12105a988416SJim Ingham } 12115a988416SJim Ingham 1212bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1213bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 12145a988416SJim Ingham 12155a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 12165a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 12175a988416SJim Ingham 1218b9c1b51eSKate Stone if (num_breakpoints == 0) { 12195a988416SJim Ingham result.AppendError("No breakpoints exist to be disabled."); 12205a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 12215a988416SJim Ingham return false; 12225a988416SJim Ingham } 12235a988416SJim Ingham 1224b9c1b51eSKate Stone if (command.GetArgumentCount() == 0) { 12255a988416SJim Ingham // No breakpoint selected; disable all currently set breakpoints. 12265a988416SJim Ingham target->DisableAllBreakpoints(); 1227b9c1b51eSKate Stone result.AppendMessageWithFormat("All breakpoints disabled. (%" PRIu64 1228b9c1b51eSKate Stone " breakpoints)\n", 1229b9c1b51eSKate Stone (uint64_t)num_breakpoints); 12305a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1231b9c1b51eSKate Stone } else { 12325a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 12335a988416SJim Ingham BreakpointIDList valid_bp_ids; 12345a988416SJim Ingham 1235b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1236b9c1b51eSKate Stone command, target, result, &valid_bp_ids); 12375a988416SJim Ingham 1238b9c1b51eSKate Stone if (result.Succeeded()) { 12395a988416SJim Ingham int disable_count = 0; 12405a988416SJim Ingham int loc_count = 0; 12415a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1242b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 12435a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 12445a988416SJim Ingham 1245b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1246b9c1b51eSKate Stone Breakpoint *breakpoint = 1247b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1248b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1249b9c1b51eSKate Stone BreakpointLocation *location = 1250b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1251b9c1b51eSKate Stone if (location) { 12525a988416SJim Ingham location->SetEnabled(false); 12535a988416SJim Ingham ++loc_count; 12545a988416SJim Ingham } 1255b9c1b51eSKate Stone } else { 12565a988416SJim Ingham breakpoint->SetEnabled(false); 12575a988416SJim Ingham ++disable_count; 12585a988416SJim Ingham } 12595a988416SJim Ingham } 12605a988416SJim Ingham } 1261b9c1b51eSKate Stone result.AppendMessageWithFormat("%d breakpoints disabled.\n", 1262b9c1b51eSKate Stone disable_count + loc_count); 12635a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 12645a988416SJim Ingham } 12655a988416SJim Ingham } 12665a988416SJim Ingham 12675a988416SJim Ingham return result.Succeeded(); 12685a988416SJim Ingham } 12695a988416SJim Ingham }; 12705a988416SJim Ingham 12715a988416SJim Ingham //------------------------------------------------------------------------- 12725a988416SJim Ingham // CommandObjectBreakpointList 12735a988416SJim Ingham //------------------------------------------------------------------------- 12745a988416SJim Ingham #pragma mark List 12755a988416SJim Ingham 1276b9c1b51eSKate Stone class CommandObjectBreakpointList : public CommandObjectParsed { 12775a988416SJim Ingham public: 1278b9c1b51eSKate Stone CommandObjectBreakpointList(CommandInterpreter &interpreter) 1279b9c1b51eSKate Stone : CommandObjectParsed( 1280b9c1b51eSKate Stone interpreter, "breakpoint list", 12815a988416SJim Ingham "List some or all breakpoints at configurable levels of detail.", 12829e85e5a8SEugene Zelenko nullptr), 1283b9c1b51eSKate Stone m_options() { 12845a988416SJim Ingham CommandArgumentEntry arg; 12855a988416SJim Ingham CommandArgumentData bp_id_arg; 12865a988416SJim Ingham 12875a988416SJim Ingham // Define the first (and only) variant of this arg. 12885a988416SJim Ingham bp_id_arg.arg_type = eArgTypeBreakpointID; 12895a988416SJim Ingham bp_id_arg.arg_repetition = eArgRepeatOptional; 12905a988416SJim Ingham 1291b9c1b51eSKate Stone // There is only one variant this argument could be; put it into the 1292b9c1b51eSKate Stone // argument entry. 12935a988416SJim Ingham arg.push_back(bp_id_arg); 12945a988416SJim Ingham 12955a988416SJim Ingham // Push the data for the first argument into the m_arguments vector. 12965a988416SJim Ingham m_arguments.push_back(arg); 12975a988416SJim Ingham } 12985a988416SJim Ingham 12999e85e5a8SEugene Zelenko ~CommandObjectBreakpointList() override = default; 13005a988416SJim Ingham 1301b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 13025a988416SJim Ingham 1303b9c1b51eSKate Stone class CommandOptions : public Options { 13045a988416SJim Ingham public: 1305b9c1b51eSKate Stone CommandOptions() 1306b9c1b51eSKate Stone : Options(), m_level(lldb::eDescriptionLevelBrief), m_use_dummy(false) { 13075a988416SJim Ingham } 13085a988416SJim Ingham 13099e85e5a8SEugene Zelenko ~CommandOptions() override = default; 13105a988416SJim Ingham 1311b9c1b51eSKate Stone Error SetOptionValue(uint32_t option_idx, const char *option_arg, 1312b9c1b51eSKate Stone ExecutionContext *execution_context) override { 13135a988416SJim Ingham Error error; 13143bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 13155a988416SJim Ingham 1316b9c1b51eSKate Stone switch (short_option) { 13175a988416SJim Ingham case 'b': 13185a988416SJim Ingham m_level = lldb::eDescriptionLevelBrief; 13195a988416SJim Ingham break; 132033df7cd3SJim Ingham case 'D': 132133df7cd3SJim Ingham m_use_dummy = true; 132233df7cd3SJim Ingham break; 13235a988416SJim Ingham case 'f': 13245a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 13255a988416SJim Ingham break; 13265a988416SJim Ingham case 'v': 13275a988416SJim Ingham m_level = lldb::eDescriptionLevelVerbose; 13285a988416SJim Ingham break; 13295a988416SJim Ingham case 'i': 13305a988416SJim Ingham m_internal = true; 13315a988416SJim Ingham break; 13325a988416SJim Ingham default: 1333b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1334b9c1b51eSKate Stone short_option); 13355a988416SJim Ingham break; 13365a988416SJim Ingham } 13375a988416SJim Ingham 13385a988416SJim Ingham return error; 13395a988416SJim Ingham } 13405a988416SJim Ingham 1341b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 13425a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 13435a988416SJim Ingham m_internal = false; 134433df7cd3SJim Ingham m_use_dummy = false; 13455a988416SJim Ingham } 13465a988416SJim Ingham 1347b9c1b51eSKate Stone const OptionDefinition *GetDefinitions() override { return g_option_table; } 13485a988416SJim Ingham 13495a988416SJim Ingham // Options table: Required for subclasses of Options. 13505a988416SJim Ingham 13515a988416SJim Ingham static OptionDefinition g_option_table[]; 13525a988416SJim Ingham 13535a988416SJim Ingham // Instance variables to hold the values for command options. 13545a988416SJim Ingham 13555a988416SJim Ingham lldb::DescriptionLevel m_level; 13565a988416SJim Ingham 13575a988416SJim Ingham bool m_internal; 135833df7cd3SJim Ingham bool m_use_dummy; 13595a988416SJim Ingham }; 13605a988416SJim Ingham 13615a988416SJim Ingham protected: 1362b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 136333df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 136433df7cd3SJim Ingham 1365b9c1b51eSKate Stone if (target == nullptr) { 13665a988416SJim Ingham result.AppendError("Invalid target. No current target or breakpoints."); 13675a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 13685a988416SJim Ingham return true; 13695a988416SJim Ingham } 13705a988416SJim Ingham 1371b9c1b51eSKate Stone const BreakpointList &breakpoints = 1372b9c1b51eSKate Stone target->GetBreakpointList(m_options.m_internal); 1373bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1374bb19a13cSSaleem Abdulrasool target->GetBreakpointList(m_options.m_internal).GetListMutex(lock); 13755a988416SJim Ingham 13765a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 13775a988416SJim Ingham 1378b9c1b51eSKate Stone if (num_breakpoints == 0) { 13795a988416SJim Ingham result.AppendMessage("No breakpoints currently set."); 13805a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 13815a988416SJim Ingham return true; 13825a988416SJim Ingham } 13835a988416SJim Ingham 13845a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 13855a988416SJim Ingham 1386b9c1b51eSKate Stone if (command.GetArgumentCount() == 0) { 13875a988416SJim Ingham // No breakpoint selected; show info about all currently set breakpoints. 13885a988416SJim Ingham result.AppendMessage("Current breakpoints:"); 1389b9c1b51eSKate Stone for (size_t i = 0; i < num_breakpoints; ++i) { 13905a988416SJim Ingham Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex(i).get(); 13915a988416SJim Ingham AddBreakpointDescription(&output_stream, breakpoint, m_options.m_level); 13925a988416SJim Ingham } 13935a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1394b9c1b51eSKate Stone } else { 13955a988416SJim Ingham // Particular breakpoints selected; show info about that breakpoint. 13965a988416SJim Ingham BreakpointIDList valid_bp_ids; 1397b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1398b9c1b51eSKate Stone command, target, result, &valid_bp_ids); 13995a988416SJim Ingham 1400b9c1b51eSKate Stone if (result.Succeeded()) { 1401b9c1b51eSKate Stone for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) { 14025a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 1403b9c1b51eSKate Stone Breakpoint *breakpoint = 1404b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1405b9c1b51eSKate Stone AddBreakpointDescription(&output_stream, breakpoint, 1406b9c1b51eSKate Stone m_options.m_level); 14075a988416SJim Ingham } 14085a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1409b9c1b51eSKate Stone } else { 14107428a18cSKate Stone result.AppendError("Invalid breakpoint ID."); 14115a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 14125a988416SJim Ingham } 14135a988416SJim Ingham } 14145a988416SJim Ingham 14155a988416SJim Ingham return result.Succeeded(); 14165a988416SJim Ingham } 14175a988416SJim Ingham 14185a988416SJim Ingham private: 14195a988416SJim Ingham CommandOptions m_options; 14205a988416SJim Ingham }; 14215a988416SJim Ingham 14225a988416SJim Ingham #pragma mark List::CommandOptions 1423b9c1b51eSKate Stone OptionDefinition CommandObjectBreakpointList::CommandOptions::g_option_table[] = 14245a988416SJim Ingham { 1425ac9c3a62SKate Stone // clang-format off 1426ac9c3a62SKate Stone {LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show debugger internal breakpoints" }, 1427ac9c3a62SKate Stone {LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a brief description of the breakpoint (no location info)."}, 14285a988416SJim Ingham // FIXME: We need to add an "internal" command, and then add this sort of thing to it. 14295a988416SJim Ingham // But I need to see it for now, and don't want to wait. 1430ac9c3a62SKate Stone {LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a full description of the breakpoint and its locations."}, 1431ac9c3a62SKate Stone {LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Explain everything we know about the breakpoint (for debugging debugger bugs)."}, 1432ac9c3a62SKate Stone {LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, 14339e85e5a8SEugene Zelenko {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} 1434ac9c3a62SKate Stone // clang-format on 14355a988416SJim Ingham }; 14365a988416SJim Ingham 14375a988416SJim Ingham //------------------------------------------------------------------------- 14385a988416SJim Ingham // CommandObjectBreakpointClear 14395a988416SJim Ingham //------------------------------------------------------------------------- 14405a988416SJim Ingham #pragma mark Clear 14415a988416SJim Ingham 1442b9c1b51eSKate Stone class CommandObjectBreakpointClear : public CommandObjectParsed { 14435a988416SJim Ingham public: 1444b9c1b51eSKate Stone typedef enum BreakpointClearType { 14455a988416SJim Ingham eClearTypeInvalid, 14465a988416SJim Ingham eClearTypeFileAndLine 14475a988416SJim Ingham } BreakpointClearType; 14485a988416SJim Ingham 14497428a18cSKate Stone CommandObjectBreakpointClear(CommandInterpreter &interpreter) 14507428a18cSKate Stone : CommandObjectParsed(interpreter, "breakpoint clear", 1451b9c1b51eSKate Stone "Delete or disable breakpoints matching the " 1452b9c1b51eSKate Stone "specified source file and line.", 14535a988416SJim Ingham "breakpoint clear <cmd-options>"), 1454b9c1b51eSKate Stone m_options() {} 14555a988416SJim Ingham 14569e85e5a8SEugene Zelenko ~CommandObjectBreakpointClear() override = default; 14575a988416SJim Ingham 1458b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 14595a988416SJim Ingham 1460b9c1b51eSKate Stone class CommandOptions : public Options { 14615a988416SJim Ingham public: 1462b9c1b51eSKate Stone CommandOptions() : Options(), m_filename(), m_line_num(0) {} 14635a988416SJim Ingham 14649e85e5a8SEugene Zelenko ~CommandOptions() override = default; 14655a988416SJim Ingham 1466b9c1b51eSKate Stone Error SetOptionValue(uint32_t option_idx, const char *option_arg, 1467b9c1b51eSKate Stone ExecutionContext *execution_context) override { 14685a988416SJim Ingham Error error; 14693bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 14705a988416SJim Ingham 1471b9c1b51eSKate Stone switch (short_option) { 14725a988416SJim Ingham case 'f': 14735a988416SJim Ingham m_filename.assign(option_arg); 14745a988416SJim Ingham break; 14755a988416SJim Ingham 14765a988416SJim Ingham case 'l': 14775275aaa0SVince Harron m_line_num = StringConvert::ToUInt32(option_arg, 0); 14785a988416SJim Ingham break; 14795a988416SJim Ingham 14805a988416SJim Ingham default: 1481b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1482b9c1b51eSKate Stone short_option); 14835a988416SJim Ingham break; 14845a988416SJim Ingham } 14855a988416SJim Ingham 14865a988416SJim Ingham return error; 14875a988416SJim Ingham } 14885a988416SJim Ingham 1489b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 14905a988416SJim Ingham m_filename.clear(); 14915a988416SJim Ingham m_line_num = 0; 14925a988416SJim Ingham } 14935a988416SJim Ingham 1494b9c1b51eSKate Stone const OptionDefinition *GetDefinitions() override { return g_option_table; } 14955a988416SJim Ingham 14965a988416SJim Ingham // Options table: Required for subclasses of Options. 14975a988416SJim Ingham 14985a988416SJim Ingham static OptionDefinition g_option_table[]; 14995a988416SJim Ingham 15005a988416SJim Ingham // Instance variables to hold the values for command options. 15015a988416SJim Ingham 15025a988416SJim Ingham std::string m_filename; 15035a988416SJim Ingham uint32_t m_line_num; 15045a988416SJim Ingham }; 15055a988416SJim Ingham 15065a988416SJim Ingham protected: 1507b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1508893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1509b9c1b51eSKate Stone if (target == nullptr) { 15105a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 15115a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 15125a988416SJim Ingham return false; 15135a988416SJim Ingham } 15145a988416SJim Ingham 15155a988416SJim Ingham // The following are the various types of breakpoints that could be cleared: 15165a988416SJim Ingham // 1). -f -l (clearing breakpoint by source location) 15175a988416SJim Ingham 15185a988416SJim Ingham BreakpointClearType break_type = eClearTypeInvalid; 15195a988416SJim Ingham 15205a988416SJim Ingham if (m_options.m_line_num != 0) 15215a988416SJim Ingham break_type = eClearTypeFileAndLine; 15225a988416SJim Ingham 1523bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1524bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 15255a988416SJim Ingham 15265a988416SJim Ingham BreakpointList &breakpoints = target->GetBreakpointList(); 15275a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 15285a988416SJim Ingham 15295a988416SJim Ingham // Early return if there's no breakpoint at all. 1530b9c1b51eSKate Stone if (num_breakpoints == 0) { 15315a988416SJim Ingham result.AppendError("Breakpoint clear: No breakpoint cleared."); 15325a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 15335a988416SJim Ingham return result.Succeeded(); 15345a988416SJim Ingham } 15355a988416SJim Ingham 15365a988416SJim Ingham // Find matching breakpoints and delete them. 15375a988416SJim Ingham 15385a988416SJim Ingham // First create a copy of all the IDs. 15395a988416SJim Ingham std::vector<break_id_t> BreakIDs; 15405a988416SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) 15419e85e5a8SEugene Zelenko BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID()); 15425a988416SJim Ingham 15435a988416SJim Ingham int num_cleared = 0; 15445a988416SJim Ingham StreamString ss; 1545b9c1b51eSKate Stone switch (break_type) { 15465a988416SJim Ingham case eClearTypeFileAndLine: // Breakpoint by source position 15475a988416SJim Ingham { 15485a988416SJim Ingham const ConstString filename(m_options.m_filename.c_str()); 15495a988416SJim Ingham BreakpointLocationCollection loc_coll; 15505a988416SJim Ingham 1551b9c1b51eSKate Stone for (size_t i = 0; i < num_breakpoints; ++i) { 15525a988416SJim Ingham Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); 15535a988416SJim Ingham 1554b9c1b51eSKate Stone if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) { 1555b9c1b51eSKate Stone // If the collection size is 0, it's a full match and we can just 1556b9c1b51eSKate Stone // remove the breakpoint. 1557b9c1b51eSKate Stone if (loc_coll.GetSize() == 0) { 15585a988416SJim Ingham bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); 15595a988416SJim Ingham ss.EOL(); 15605a988416SJim Ingham target->RemoveBreakpointByID(bp->GetID()); 15615a988416SJim Ingham ++num_cleared; 15625a988416SJim Ingham } 15635a988416SJim Ingham } 15645a988416SJim Ingham } 1565b9c1b51eSKate Stone } break; 15665a988416SJim Ingham 15675a988416SJim Ingham default: 15685a988416SJim Ingham break; 15695a988416SJim Ingham } 15705a988416SJim Ingham 1571b9c1b51eSKate Stone if (num_cleared > 0) { 15725a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 15735a988416SJim Ingham output_stream.Printf("%d breakpoints cleared:\n", num_cleared); 15745a988416SJim Ingham output_stream << ss.GetData(); 15755a988416SJim Ingham output_stream.EOL(); 15765a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1577b9c1b51eSKate Stone } else { 15785a988416SJim Ingham result.AppendError("Breakpoint clear: No breakpoint cleared."); 15795a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 15805a988416SJim Ingham } 15815a988416SJim Ingham 15825a988416SJim Ingham return result.Succeeded(); 15835a988416SJim Ingham } 15845a988416SJim Ingham 15855a988416SJim Ingham private: 15865a988416SJim Ingham CommandOptions m_options; 15875a988416SJim Ingham }; 15885a988416SJim Ingham 15895a988416SJim Ingham #pragma mark Clear::CommandOptions 15905a988416SJim Ingham 15915a988416SJim Ingham OptionDefinition 1592b9c1b51eSKate Stone CommandObjectBreakpointClear::CommandOptions::g_option_table[] = { 1593ac9c3a62SKate Stone // clang-format off 1594ac9c3a62SKate Stone {LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specify the breakpoint by source location in this particular file."}, 1595ac9c3a62SKate Stone {LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Specify the breakpoint by source location at this particular line."}, 15969e85e5a8SEugene Zelenko {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} 1597ac9c3a62SKate Stone // clang-format on 15985a988416SJim Ingham }; 15995a988416SJim Ingham 16005a988416SJim Ingham //------------------------------------------------------------------------- 16015a988416SJim Ingham // CommandObjectBreakpointDelete 16025a988416SJim Ingham //------------------------------------------------------------------------- 16035a988416SJim Ingham #pragma mark Delete 16045a988416SJim Ingham 1605b9c1b51eSKate Stone class CommandObjectBreakpointDelete : public CommandObjectParsed { 16065a988416SJim Ingham public: 1607b9c1b51eSKate Stone CommandObjectBreakpointDelete(CommandInterpreter &interpreter) 1608b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "breakpoint delete", 1609b9c1b51eSKate Stone "Delete the specified breakpoint(s). If no " 1610b9c1b51eSKate Stone "breakpoints are specified, delete them all.", 16119e85e5a8SEugene Zelenko nullptr), 1612b9c1b51eSKate Stone m_options() { 16135a988416SJim Ingham CommandArgumentEntry arg; 1614b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1615b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1616b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1617b9c1b51eSKate Stone // arguments vector. 16185a988416SJim Ingham m_arguments.push_back(arg); 16195a988416SJim Ingham } 16205a988416SJim Ingham 16219e85e5a8SEugene Zelenko ~CommandObjectBreakpointDelete() override = default; 16225a988416SJim Ingham 1623b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 162433df7cd3SJim Ingham 1625b9c1b51eSKate Stone class CommandOptions : public Options { 162633df7cd3SJim Ingham public: 1627b9c1b51eSKate Stone CommandOptions() : Options(), m_use_dummy(false), m_force(false) {} 162833df7cd3SJim Ingham 16299e85e5a8SEugene Zelenko ~CommandOptions() override = default; 163033df7cd3SJim Ingham 1631b9c1b51eSKate Stone Error SetOptionValue(uint32_t option_idx, const char *option_arg, 1632b9c1b51eSKate Stone ExecutionContext *execution_context) override { 163333df7cd3SJim Ingham Error error; 163433df7cd3SJim Ingham const int short_option = m_getopt_table[option_idx].val; 163533df7cd3SJim Ingham 1636b9c1b51eSKate Stone switch (short_option) { 163733df7cd3SJim Ingham case 'f': 163833df7cd3SJim Ingham m_force = true; 163933df7cd3SJim Ingham break; 164033df7cd3SJim Ingham 164133df7cd3SJim Ingham case 'D': 164233df7cd3SJim Ingham m_use_dummy = true; 164333df7cd3SJim Ingham break; 164433df7cd3SJim Ingham 164533df7cd3SJim Ingham default: 1646b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1647b9c1b51eSKate Stone short_option); 164833df7cd3SJim Ingham break; 164933df7cd3SJim Ingham } 165033df7cd3SJim Ingham 165133df7cd3SJim Ingham return error; 165233df7cd3SJim Ingham } 165333df7cd3SJim Ingham 1654b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 165533df7cd3SJim Ingham m_use_dummy = false; 165633df7cd3SJim Ingham m_force = false; 165733df7cd3SJim Ingham } 165833df7cd3SJim Ingham 1659b9c1b51eSKate Stone const OptionDefinition *GetDefinitions() override { return g_option_table; } 166033df7cd3SJim Ingham 166133df7cd3SJim Ingham // Options table: Required for subclasses of Options. 166233df7cd3SJim Ingham 166333df7cd3SJim Ingham static OptionDefinition g_option_table[]; 166433df7cd3SJim Ingham 166533df7cd3SJim Ingham // Instance variables to hold the values for command options. 166633df7cd3SJim Ingham bool m_use_dummy; 166733df7cd3SJim Ingham bool m_force; 166833df7cd3SJim Ingham }; 166933df7cd3SJim Ingham 16705a988416SJim Ingham protected: 1671b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 167233df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 167333df7cd3SJim Ingham 1674b9c1b51eSKate Stone if (target == nullptr) { 16755a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 16765a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 16775a988416SJim Ingham return false; 16785a988416SJim Ingham } 16795a988416SJim Ingham 1680bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1681bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 16825a988416SJim Ingham 16835a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 16845a988416SJim Ingham 16855a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 16865a988416SJim Ingham 1687b9c1b51eSKate Stone if (num_breakpoints == 0) { 16885a988416SJim Ingham result.AppendError("No breakpoints exist to be deleted."); 16895a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 16905a988416SJim Ingham return false; 16915a988416SJim Ingham } 16925a988416SJim Ingham 1693b9c1b51eSKate Stone if (command.GetArgumentCount() == 0) { 1694b9c1b51eSKate Stone if (!m_options.m_force && 1695b9c1b51eSKate Stone !m_interpreter.Confirm( 1696b9c1b51eSKate Stone "About to delete all breakpoints, do you want to do that?", 1697b9c1b51eSKate Stone true)) { 16985a988416SJim Ingham result.AppendMessage("Operation cancelled..."); 1699b9c1b51eSKate Stone } else { 17005a988416SJim Ingham target->RemoveAllBreakpoints(); 1701b9c1b51eSKate Stone result.AppendMessageWithFormat( 1702b9c1b51eSKate Stone "All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", 1703b9c1b51eSKate Stone (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : ""); 17045a988416SJim Ingham } 17055a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1706b9c1b51eSKate Stone } else { 17075a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 17085a988416SJim Ingham BreakpointIDList valid_bp_ids; 1709b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1710b9c1b51eSKate Stone command, target, result, &valid_bp_ids); 17115a988416SJim Ingham 1712b9c1b51eSKate Stone if (result.Succeeded()) { 17135a988416SJim Ingham int delete_count = 0; 17145a988416SJim Ingham int disable_count = 0; 17155a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1716b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 17175a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 17185a988416SJim Ingham 1719b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1720b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1721b9c1b51eSKate Stone Breakpoint *breakpoint = 1722b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1723b9c1b51eSKate Stone BreakpointLocation *location = 1724b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1725b9c1b51eSKate Stone // It makes no sense to try to delete individual locations, so we 1726b9c1b51eSKate Stone // disable them instead. 1727b9c1b51eSKate Stone if (location) { 17285a988416SJim Ingham location->SetEnabled(false); 17295a988416SJim Ingham ++disable_count; 17305a988416SJim Ingham } 1731b9c1b51eSKate Stone } else { 17325a988416SJim Ingham target->RemoveBreakpointByID(cur_bp_id.GetBreakpointID()); 17335a988416SJim Ingham ++delete_count; 17345a988416SJim Ingham } 17355a988416SJim Ingham } 17365a988416SJim Ingham } 1737b9c1b51eSKate Stone result.AppendMessageWithFormat( 1738b9c1b51eSKate Stone "%d breakpoints deleted; %d breakpoint locations disabled.\n", 17395a988416SJim Ingham delete_count, disable_count); 17405a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 17415a988416SJim Ingham } 17425a988416SJim Ingham } 17435a988416SJim Ingham return result.Succeeded(); 17445a988416SJim Ingham } 17459e85e5a8SEugene Zelenko 174633df7cd3SJim Ingham private: 174733df7cd3SJim Ingham CommandOptions m_options; 174833df7cd3SJim Ingham }; 174933df7cd3SJim Ingham 175033df7cd3SJim Ingham OptionDefinition 1751b9c1b51eSKate Stone CommandObjectBreakpointDelete::CommandOptions::g_option_table[] = { 1752ac9c3a62SKate Stone // clang-format off 1753ac9c3a62SKate Stone {LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete all breakpoints without querying for confirmation."}, 1754ac9c3a62SKate Stone {LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, 17559e85e5a8SEugene Zelenko {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} 1756ac9c3a62SKate Stone // clang-format on 17575a988416SJim Ingham }; 17585a988416SJim Ingham 175930fdc8d8SChris Lattner //------------------------------------------------------------------------- 17605e09c8c3SJim Ingham // CommandObjectBreakpointName 17615e09c8c3SJim Ingham //------------------------------------------------------------------------- 17625e09c8c3SJim Ingham 17637428a18cSKate Stone static OptionDefinition g_breakpoint_name_options[] = { 1764ac9c3a62SKate Stone // clang-format off 1765ac9c3a62SKate Stone {LLDB_OPT_SET_1, false, "name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."}, 1766ac9c3a62SKate Stone {LLDB_OPT_SET_2, false, "breakpoint-id", 'B', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointID, "Specify a breakpoint ID to use."}, 1767ac9c3a62SKate Stone {LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Operate on Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, 1768ac9c3a62SKate Stone // clang-format on 17695e09c8c3SJim Ingham }; 1770b9c1b51eSKate Stone class BreakpointNameOptionGroup : public OptionGroup { 17715e09c8c3SJim Ingham public: 1772b9c1b51eSKate Stone BreakpointNameOptionGroup() 1773b9c1b51eSKate Stone : OptionGroup(), m_breakpoint(LLDB_INVALID_BREAK_ID), m_use_dummy(false) { 17745e09c8c3SJim Ingham } 17755e09c8c3SJim Ingham 17769e85e5a8SEugene Zelenko ~BreakpointNameOptionGroup() override = default; 17775e09c8c3SJim Ingham 1778b9c1b51eSKate Stone uint32_t GetNumDefinitions() override { 17795e09c8c3SJim Ingham return sizeof(g_breakpoint_name_options) / sizeof(OptionDefinition); 17805e09c8c3SJim Ingham } 17815e09c8c3SJim Ingham 1782b9c1b51eSKate Stone const OptionDefinition *GetDefinitions() override { 17835e09c8c3SJim Ingham return g_breakpoint_name_options; 17845e09c8c3SJim Ingham } 17855e09c8c3SJim Ingham 1786b9c1b51eSKate Stone Error SetOptionValue(uint32_t option_idx, const char *option_value, 1787b9c1b51eSKate Stone ExecutionContext *execution_context) override { 17885e09c8c3SJim Ingham Error error; 17895e09c8c3SJim Ingham const int short_option = g_breakpoint_name_options[option_idx].short_option; 1790*6fa7681bSZachary Turner llvm::StringRef option_strref(option_value ? option_value : ""); 17915e09c8c3SJim Ingham 1792b9c1b51eSKate Stone switch (short_option) { 17935e09c8c3SJim Ingham case 'N': 1794*6fa7681bSZachary Turner if (BreakpointID::StringIsBreakpointName(option_strref, error) && 1795b9c1b51eSKate Stone error.Success()) 1796*6fa7681bSZachary Turner m_name.SetValueFromString(option_strref); 17975e09c8c3SJim Ingham break; 17985e09c8c3SJim Ingham 17995e09c8c3SJim Ingham case 'B': 1800c95f7e2aSPavel Labath if (m_breakpoint.SetValueFromString(option_value).Fail()) 1801b9c1b51eSKate Stone error.SetErrorStringWithFormat( 1802b9c1b51eSKate Stone "unrecognized value \"%s\" for breakpoint", option_value); 18035e09c8c3SJim Ingham break; 18045e09c8c3SJim Ingham case 'D': 1805c95f7e2aSPavel Labath if (m_use_dummy.SetValueFromString(option_value).Fail()) 1806b9c1b51eSKate Stone error.SetErrorStringWithFormat( 1807b9c1b51eSKate Stone "unrecognized value \"%s\" for use-dummy", option_value); 18085e09c8c3SJim Ingham break; 18095e09c8c3SJim Ingham 18105e09c8c3SJim Ingham default: 1811b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized short option '%c'", 1812b9c1b51eSKate Stone short_option); 18135e09c8c3SJim Ingham break; 18145e09c8c3SJim Ingham } 18155e09c8c3SJim Ingham return error; 18165e09c8c3SJim Ingham } 18175e09c8c3SJim Ingham 1818b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 18195e09c8c3SJim Ingham m_name.Clear(); 18205e09c8c3SJim Ingham m_breakpoint.Clear(); 18215e09c8c3SJim Ingham m_use_dummy.Clear(); 18225e09c8c3SJim Ingham m_use_dummy.SetDefaultValue(false); 18235e09c8c3SJim Ingham } 18245e09c8c3SJim Ingham 18255e09c8c3SJim Ingham OptionValueString m_name; 18265e09c8c3SJim Ingham OptionValueUInt64 m_breakpoint; 18275e09c8c3SJim Ingham OptionValueBoolean m_use_dummy; 18285e09c8c3SJim Ingham }; 18295e09c8c3SJim Ingham 1830b9c1b51eSKate Stone class CommandObjectBreakpointNameAdd : public CommandObjectParsed { 18315e09c8c3SJim Ingham public: 1832b9c1b51eSKate Stone CommandObjectBreakpointNameAdd(CommandInterpreter &interpreter) 1833b9c1b51eSKate Stone : CommandObjectParsed( 1834b9c1b51eSKate Stone interpreter, "add", "Add a name to the breakpoints provided.", 18355e09c8c3SJim Ingham "breakpoint name add <command-options> <breakpoint-id-list>"), 1836b9c1b51eSKate Stone m_name_options(), m_option_group() { 1837b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 1838b9c1b51eSKate Stone // command. 18395e09c8c3SJim Ingham CommandArgumentEntry arg1; 18405e09c8c3SJim Ingham CommandArgumentData id_arg; 18415e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 18425e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 18435e09c8c3SJim Ingham arg1.push_back(id_arg); 18445e09c8c3SJim Ingham m_arguments.push_back(arg1); 18455e09c8c3SJim Ingham 18465e09c8c3SJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 18475e09c8c3SJim Ingham m_option_group.Finalize(); 18485e09c8c3SJim Ingham } 18495e09c8c3SJim Ingham 18509e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameAdd() override = default; 18515e09c8c3SJim Ingham 1852b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 18535e09c8c3SJim Ingham 18545e09c8c3SJim Ingham protected: 1855b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1856b9c1b51eSKate Stone if (!m_name_options.m_name.OptionWasSet()) { 18575e09c8c3SJim Ingham result.SetError("No name option provided."); 18585e09c8c3SJim Ingham return false; 18595e09c8c3SJim Ingham } 18605e09c8c3SJim Ingham 1861b9c1b51eSKate Stone Target *target = 1862b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 18635e09c8c3SJim Ingham 1864b9c1b51eSKate Stone if (target == nullptr) { 18655e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 18665e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 18675e09c8c3SJim Ingham return false; 18685e09c8c3SJim Ingham } 18695e09c8c3SJim Ingham 1870bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1871bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 18725e09c8c3SJim Ingham 18735e09c8c3SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 18745e09c8c3SJim Ingham 18755e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 1876b9c1b51eSKate Stone if (num_breakpoints == 0) { 18775e09c8c3SJim Ingham result.SetError("No breakpoints, cannot add names."); 18785e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 18795e09c8c3SJim Ingham return false; 18805e09c8c3SJim Ingham } 18815e09c8c3SJim Ingham 18825e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 18835e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 1884b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 1885b9c1b51eSKate Stone command, target, result, &valid_bp_ids); 18865e09c8c3SJim Ingham 1887b9c1b51eSKate Stone if (result.Succeeded()) { 1888b9c1b51eSKate Stone if (valid_bp_ids.GetSize() == 0) { 18895e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot add names."); 18905e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 18915e09c8c3SJim Ingham return false; 18925e09c8c3SJim Ingham } 18935e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 1894b9c1b51eSKate Stone for (size_t index = 0; index < num_valid_ids; index++) { 1895b9c1b51eSKate Stone lldb::break_id_t bp_id = 1896b9c1b51eSKate Stone valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 18975e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 1898b9c1b51eSKate Stone Error error; // We don't need to check the error here, since the option 1899b9c1b51eSKate Stone // parser checked it... 19005e09c8c3SJim Ingham bp_sp->AddName(m_name_options.m_name.GetCurrentValue(), error); 19015e09c8c3SJim Ingham } 19025e09c8c3SJim Ingham } 19035e09c8c3SJim Ingham 19045e09c8c3SJim Ingham return true; 19055e09c8c3SJim Ingham } 19065e09c8c3SJim Ingham 19075e09c8c3SJim Ingham private: 19085e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 19095e09c8c3SJim Ingham OptionGroupOptions m_option_group; 19105e09c8c3SJim Ingham }; 19115e09c8c3SJim Ingham 1912b9c1b51eSKate Stone class CommandObjectBreakpointNameDelete : public CommandObjectParsed { 19135e09c8c3SJim Ingham public: 1914b9c1b51eSKate Stone CommandObjectBreakpointNameDelete(CommandInterpreter &interpreter) 1915b9c1b51eSKate Stone : CommandObjectParsed( 1916b9c1b51eSKate Stone interpreter, "delete", 19175e09c8c3SJim Ingham "Delete a name from the breakpoints provided.", 19185e09c8c3SJim Ingham "breakpoint name delete <command-options> <breakpoint-id-list>"), 1919b9c1b51eSKate Stone m_name_options(), m_option_group() { 1920b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 1921b9c1b51eSKate Stone // command. 19225e09c8c3SJim Ingham CommandArgumentEntry arg1; 19235e09c8c3SJim Ingham CommandArgumentData id_arg; 19245e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 19255e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 19265e09c8c3SJim Ingham arg1.push_back(id_arg); 19275e09c8c3SJim Ingham m_arguments.push_back(arg1); 19285e09c8c3SJim Ingham 19295e09c8c3SJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 19305e09c8c3SJim Ingham m_option_group.Finalize(); 19315e09c8c3SJim Ingham } 19325e09c8c3SJim Ingham 19339e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameDelete() override = default; 19345e09c8c3SJim Ingham 1935b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 19365e09c8c3SJim Ingham 19375e09c8c3SJim Ingham protected: 1938b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1939b9c1b51eSKate Stone if (!m_name_options.m_name.OptionWasSet()) { 19405e09c8c3SJim Ingham result.SetError("No name option provided."); 19415e09c8c3SJim Ingham return false; 19425e09c8c3SJim Ingham } 19435e09c8c3SJim Ingham 1944b9c1b51eSKate Stone Target *target = 1945b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 19465e09c8c3SJim Ingham 1947b9c1b51eSKate Stone if (target == nullptr) { 19485e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 19495e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 19505e09c8c3SJim Ingham return false; 19515e09c8c3SJim Ingham } 19525e09c8c3SJim Ingham 1953bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1954bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 19555e09c8c3SJim Ingham 19565e09c8c3SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 19575e09c8c3SJim Ingham 19585e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 1959b9c1b51eSKate Stone if (num_breakpoints == 0) { 19605e09c8c3SJim Ingham result.SetError("No breakpoints, cannot delete names."); 19615e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 19625e09c8c3SJim Ingham return false; 19635e09c8c3SJim Ingham } 19645e09c8c3SJim Ingham 19655e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 19665e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 1967b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 1968b9c1b51eSKate Stone command, target, result, &valid_bp_ids); 19695e09c8c3SJim Ingham 1970b9c1b51eSKate Stone if (result.Succeeded()) { 1971b9c1b51eSKate Stone if (valid_bp_ids.GetSize() == 0) { 19725e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot delete names."); 19735e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 19745e09c8c3SJim Ingham return false; 19755e09c8c3SJim Ingham } 19765e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 1977b9c1b51eSKate Stone for (size_t index = 0; index < num_valid_ids; index++) { 1978b9c1b51eSKate Stone lldb::break_id_t bp_id = 1979b9c1b51eSKate Stone valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 19805e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 19815e09c8c3SJim Ingham bp_sp->RemoveName(m_name_options.m_name.GetCurrentValue()); 19825e09c8c3SJim Ingham } 19835e09c8c3SJim Ingham } 19845e09c8c3SJim Ingham 19855e09c8c3SJim Ingham return true; 19865e09c8c3SJim Ingham } 19875e09c8c3SJim Ingham 19885e09c8c3SJim Ingham private: 19895e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 19905e09c8c3SJim Ingham OptionGroupOptions m_option_group; 19915e09c8c3SJim Ingham }; 19925e09c8c3SJim Ingham 1993b9c1b51eSKate Stone class CommandObjectBreakpointNameList : public CommandObjectParsed { 19945e09c8c3SJim Ingham public: 1995b9c1b51eSKate Stone CommandObjectBreakpointNameList(CommandInterpreter &interpreter) 1996b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "list", 1997b9c1b51eSKate Stone "List either the names for a breakpoint or the " 1998b9c1b51eSKate Stone "breakpoints for a given name.", 19995e09c8c3SJim Ingham "breakpoint name list <command-options>"), 2000b9c1b51eSKate Stone m_name_options(), m_option_group() { 20015e09c8c3SJim Ingham m_option_group.Append(&m_name_options); 20025e09c8c3SJim Ingham m_option_group.Finalize(); 20035e09c8c3SJim Ingham } 20045e09c8c3SJim Ingham 20059e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameList() override = default; 20065e09c8c3SJim Ingham 2007b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 20085e09c8c3SJim Ingham 20095e09c8c3SJim Ingham protected: 2010b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 2011b9c1b51eSKate Stone Target *target = 2012b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 20135e09c8c3SJim Ingham 2014b9c1b51eSKate Stone if (target == nullptr) { 20155e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 20165e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20175e09c8c3SJim Ingham return false; 20185e09c8c3SJim Ingham } 20195e09c8c3SJim Ingham 2020b9c1b51eSKate Stone if (m_name_options.m_name.OptionWasSet()) { 20215e09c8c3SJim Ingham const char *name = m_name_options.m_name.GetCurrentValue(); 2022bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 2023bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 20245e09c8c3SJim Ingham 20255e09c8c3SJim Ingham BreakpointList &breakpoints = target->GetBreakpointList(); 2026b9c1b51eSKate Stone for (BreakpointSP bp_sp : breakpoints.Breakpoints()) { 2027b9c1b51eSKate Stone if (bp_sp->MatchesName(name)) { 20285e09c8c3SJim Ingham StreamString s; 20295e09c8c3SJim Ingham bp_sp->GetDescription(&s, eDescriptionLevelBrief); 20305e09c8c3SJim Ingham s.EOL(); 20315e09c8c3SJim Ingham result.AppendMessage(s.GetData()); 20325e09c8c3SJim Ingham } 20335e09c8c3SJim Ingham } 20345e09c8c3SJim Ingham 2035b9c1b51eSKate Stone } else if (m_name_options.m_breakpoint.OptionWasSet()) { 2036b9c1b51eSKate Stone BreakpointSP bp_sp = target->GetBreakpointList().FindBreakpointByID( 2037b9c1b51eSKate Stone m_name_options.m_breakpoint.GetCurrentValue()); 2038b9c1b51eSKate Stone if (bp_sp) { 20395e09c8c3SJim Ingham std::vector<std::string> names; 20405e09c8c3SJim Ingham bp_sp->GetNames(names); 20415e09c8c3SJim Ingham result.AppendMessage("Names:"); 20425e09c8c3SJim Ingham for (auto name : names) 20435e09c8c3SJim Ingham result.AppendMessageWithFormat(" %s\n", name.c_str()); 2044b9c1b51eSKate Stone } else { 2045b9c1b51eSKate Stone result.AppendErrorWithFormat( 2046b9c1b51eSKate Stone "Could not find breakpoint %" PRId64 ".\n", 20475e09c8c3SJim Ingham m_name_options.m_breakpoint.GetCurrentValue()); 20485e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20495e09c8c3SJim Ingham return false; 20505e09c8c3SJim Ingham } 2051b9c1b51eSKate Stone } else { 20525e09c8c3SJim Ingham result.SetError("Must specify -N or -B option to list."); 20535e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20545e09c8c3SJim Ingham return false; 20555e09c8c3SJim Ingham } 20565e09c8c3SJim Ingham return true; 20575e09c8c3SJim Ingham } 20585e09c8c3SJim Ingham 20595e09c8c3SJim Ingham private: 20605e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 20615e09c8c3SJim Ingham OptionGroupOptions m_option_group; 20625e09c8c3SJim Ingham }; 20635e09c8c3SJim Ingham 20645e09c8c3SJim Ingham //------------------------------------------------------------------------- 2065e14dc268SJim Ingham // CommandObjectBreakpointName 20665e09c8c3SJim Ingham //------------------------------------------------------------------------- 2067b9c1b51eSKate Stone class CommandObjectBreakpointName : public CommandObjectMultiword { 20685e09c8c3SJim Ingham public: 20697428a18cSKate Stone CommandObjectBreakpointName(CommandInterpreter &interpreter) 2070b9c1b51eSKate Stone : CommandObjectMultiword( 2071b9c1b51eSKate Stone interpreter, "name", "Commands to manage name tags for breakpoints", 2072b9c1b51eSKate Stone "breakpoint name <subcommand> [<command-options>]") { 2073b9c1b51eSKate Stone CommandObjectSP add_command_object( 2074b9c1b51eSKate Stone new CommandObjectBreakpointNameAdd(interpreter)); 2075b9c1b51eSKate Stone CommandObjectSP delete_command_object( 2076b9c1b51eSKate Stone new CommandObjectBreakpointNameDelete(interpreter)); 2077b9c1b51eSKate Stone CommandObjectSP list_command_object( 2078b9c1b51eSKate Stone new CommandObjectBreakpointNameList(interpreter)); 20795e09c8c3SJim Ingham 20805e09c8c3SJim Ingham LoadSubCommand("add", add_command_object); 20815e09c8c3SJim Ingham LoadSubCommand("delete", delete_command_object); 20825e09c8c3SJim Ingham LoadSubCommand("list", list_command_object); 20835e09c8c3SJim Ingham } 20845e09c8c3SJim Ingham 20859e85e5a8SEugene Zelenko ~CommandObjectBreakpointName() override = default; 20865e09c8c3SJim Ingham }; 20875e09c8c3SJim Ingham 20885e09c8c3SJim Ingham //------------------------------------------------------------------------- 2089e14dc268SJim Ingham // CommandObjectBreakpointRead 2090e14dc268SJim Ingham //------------------------------------------------------------------------- 2091e14dc268SJim Ingham #pragma mark Restore 2092e14dc268SJim Ingham 2093e14dc268SJim Ingham class CommandObjectBreakpointRead : public CommandObjectParsed { 2094e14dc268SJim Ingham public: 2095e14dc268SJim Ingham CommandObjectBreakpointRead(CommandInterpreter &interpreter) 2096e14dc268SJim Ingham : CommandObjectParsed(interpreter, "breakpoint read", 2097e14dc268SJim Ingham "Read and set the breakpoints previously saved to " 2098e14dc268SJim Ingham "a file with \"breakpoint write\". ", 2099e14dc268SJim Ingham nullptr), 2100e14dc268SJim Ingham m_options() { 2101e14dc268SJim Ingham CommandArgumentEntry arg; 2102e14dc268SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 2103e14dc268SJim Ingham eArgTypeBreakpointIDRange); 2104e14dc268SJim Ingham // Add the entry for the first argument for this command to the object's 2105e14dc268SJim Ingham // arguments vector. 2106e14dc268SJim Ingham m_arguments.push_back(arg); 2107e14dc268SJim Ingham } 2108e14dc268SJim Ingham 2109e14dc268SJim Ingham ~CommandObjectBreakpointRead() override = default; 2110e14dc268SJim Ingham 2111e14dc268SJim Ingham Options *GetOptions() override { return &m_options; } 2112e14dc268SJim Ingham 2113e14dc268SJim Ingham class CommandOptions : public Options { 2114e14dc268SJim Ingham public: 2115e14dc268SJim Ingham CommandOptions() : Options() {} 2116e14dc268SJim Ingham 2117e14dc268SJim Ingham ~CommandOptions() override = default; 2118e14dc268SJim Ingham 2119e14dc268SJim Ingham Error SetOptionValue(uint32_t option_idx, const char *option_arg, 2120e14dc268SJim Ingham ExecutionContext *execution_context) override { 2121e14dc268SJim Ingham Error error; 2122e14dc268SJim Ingham const int short_option = m_getopt_table[option_idx].val; 2123e14dc268SJim Ingham 2124e14dc268SJim Ingham switch (short_option) { 2125e14dc268SJim Ingham case 'f': 2126e14dc268SJim Ingham m_filename.assign(option_arg); 2127e14dc268SJim Ingham break; 2128e14dc268SJim Ingham default: 2129e14dc268SJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 2130e14dc268SJim Ingham short_option); 2131e14dc268SJim Ingham break; 2132e14dc268SJim Ingham } 2133e14dc268SJim Ingham 2134e14dc268SJim Ingham return error; 2135e14dc268SJim Ingham } 2136e14dc268SJim Ingham 2137e14dc268SJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 2138e14dc268SJim Ingham m_filename.clear(); 2139e14dc268SJim Ingham } 2140e14dc268SJim Ingham 2141e14dc268SJim Ingham const OptionDefinition *GetDefinitions() override { return g_option_table; } 2142e14dc268SJim Ingham 2143e14dc268SJim Ingham // Options table: Required for subclasses of Options. 2144e14dc268SJim Ingham 2145e14dc268SJim Ingham static OptionDefinition g_option_table[]; 2146e14dc268SJim Ingham 2147e14dc268SJim Ingham // Instance variables to hold the values for command options. 2148e14dc268SJim Ingham 2149e14dc268SJim Ingham std::string m_filename; 2150e14dc268SJim Ingham }; 2151e14dc268SJim Ingham 2152e14dc268SJim Ingham protected: 2153e14dc268SJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 2154e14dc268SJim Ingham Target *target = GetSelectedOrDummyTarget(); 2155e14dc268SJim Ingham if (target == nullptr) { 2156e14dc268SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 2157e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2158e14dc268SJim Ingham return false; 2159e14dc268SJim Ingham } 2160e14dc268SJim Ingham 2161e14dc268SJim Ingham FileSpec input_spec(m_options.m_filename, true); 216201f16664SJim Ingham BreakpointIDList new_bps; 216301f16664SJim Ingham Error error = target->CreateBreakpointsFromFile(input_spec, new_bps); 2164e14dc268SJim Ingham 2165e14dc268SJim Ingham if (!error.Success()) { 216601f16664SJim Ingham result.AppendError(error.AsCString()); 2167e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 216801f16664SJim Ingham return false; 2169e14dc268SJim Ingham } 217001f16664SJim Ingham // FIXME: Report the newly created breakpoints. 2171e14dc268SJim Ingham return result.Succeeded(); 2172e14dc268SJim Ingham } 2173e14dc268SJim Ingham 2174e14dc268SJim Ingham private: 2175e14dc268SJim Ingham CommandOptions m_options; 2176e14dc268SJim Ingham }; 2177e14dc268SJim Ingham 2178e14dc268SJim Ingham #pragma mark Modify::CommandOptions 2179e14dc268SJim Ingham OptionDefinition CommandObjectBreakpointRead::CommandOptions::g_option_table[] = 2180e14dc268SJim Ingham { 2181e14dc268SJim Ingham // clang-format off 2182e14dc268SJim Ingham {LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename, "The file from which to read the breakpoints."}, 2183e14dc268SJim Ingham {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} 2184e14dc268SJim Ingham // clang-format on 2185e14dc268SJim Ingham }; 2186e14dc268SJim Ingham 2187e14dc268SJim Ingham //------------------------------------------------------------------------- 2188e14dc268SJim Ingham // CommandObjectBreakpointWrite 2189e14dc268SJim Ingham //------------------------------------------------------------------------- 2190e14dc268SJim Ingham #pragma mark Save 2191e14dc268SJim Ingham class CommandObjectBreakpointWrite : public CommandObjectParsed { 2192e14dc268SJim Ingham public: 2193e14dc268SJim Ingham CommandObjectBreakpointWrite(CommandInterpreter &interpreter) 2194e14dc268SJim Ingham : CommandObjectParsed(interpreter, "breakpoint write", 2195e14dc268SJim Ingham "Write the breakpoints listed to a file that can " 2196e14dc268SJim Ingham "be read in with \"breakpoint read\". " 2197e14dc268SJim Ingham "If given no arguments, writes all breakpoints.", 2198e14dc268SJim Ingham nullptr), 2199e14dc268SJim Ingham m_options() { 2200e14dc268SJim Ingham CommandArgumentEntry arg; 2201e14dc268SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 2202e14dc268SJim Ingham eArgTypeBreakpointIDRange); 2203e14dc268SJim Ingham // Add the entry for the first argument for this command to the object's 2204e14dc268SJim Ingham // arguments vector. 2205e14dc268SJim Ingham m_arguments.push_back(arg); 2206e14dc268SJim Ingham } 2207e14dc268SJim Ingham 2208e14dc268SJim Ingham ~CommandObjectBreakpointWrite() override = default; 2209e14dc268SJim Ingham 2210e14dc268SJim Ingham Options *GetOptions() override { return &m_options; } 2211e14dc268SJim Ingham 2212e14dc268SJim Ingham class CommandOptions : public Options { 2213e14dc268SJim Ingham public: 2214e14dc268SJim Ingham CommandOptions() : Options() {} 2215e14dc268SJim Ingham 2216e14dc268SJim Ingham ~CommandOptions() override = default; 2217e14dc268SJim Ingham 2218e14dc268SJim Ingham Error SetOptionValue(uint32_t option_idx, const char *option_arg, 2219e14dc268SJim Ingham ExecutionContext *execution_context) override { 2220e14dc268SJim Ingham Error error; 2221e14dc268SJim Ingham const int short_option = m_getopt_table[option_idx].val; 2222e14dc268SJim Ingham 2223e14dc268SJim Ingham switch (short_option) { 2224e14dc268SJim Ingham case 'f': 2225e14dc268SJim Ingham m_filename.assign(option_arg); 2226e14dc268SJim Ingham break; 2227e14dc268SJim Ingham default: 2228e14dc268SJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 2229e14dc268SJim Ingham short_option); 2230e14dc268SJim Ingham break; 2231e14dc268SJim Ingham } 2232e14dc268SJim Ingham 2233e14dc268SJim Ingham return error; 2234e14dc268SJim Ingham } 2235e14dc268SJim Ingham 2236e14dc268SJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 2237e14dc268SJim Ingham m_filename.clear(); 2238e14dc268SJim Ingham } 2239e14dc268SJim Ingham 2240e14dc268SJim Ingham const OptionDefinition *GetDefinitions() override { return g_option_table; } 2241e14dc268SJim Ingham 2242e14dc268SJim Ingham // Options table: Required for subclasses of Options. 2243e14dc268SJim Ingham 2244e14dc268SJim Ingham static OptionDefinition g_option_table[]; 2245e14dc268SJim Ingham 2246e14dc268SJim Ingham // Instance variables to hold the values for command options. 2247e14dc268SJim Ingham 2248e14dc268SJim Ingham std::string m_filename; 2249e14dc268SJim Ingham }; 2250e14dc268SJim Ingham 2251e14dc268SJim Ingham protected: 2252e14dc268SJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 2253e14dc268SJim Ingham Target *target = GetSelectedOrDummyTarget(); 2254e14dc268SJim Ingham if (target == nullptr) { 2255e14dc268SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 2256e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2257e14dc268SJim Ingham return false; 2258e14dc268SJim Ingham } 2259e14dc268SJim Ingham 2260e14dc268SJim Ingham std::unique_lock<std::recursive_mutex> lock; 2261e14dc268SJim Ingham target->GetBreakpointList().GetListMutex(lock); 2262e14dc268SJim Ingham 2263e14dc268SJim Ingham BreakpointIDList valid_bp_ids; 226401f16664SJim Ingham if (command.GetArgumentCount() > 0) { 2265e14dc268SJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 2266e14dc268SJim Ingham command, target, result, &valid_bp_ids); 2267e14dc268SJim Ingham 226801f16664SJim Ingham if (!result.Succeeded()) { 2269e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2270e14dc268SJim Ingham return false; 2271e14dc268SJim Ingham } 2272e14dc268SJim Ingham } 227301f16664SJim Ingham Error error = target->SerializeBreakpointsToFile( 227401f16664SJim Ingham FileSpec(m_options.m_filename.c_str(), true), valid_bp_ids); 227501f16664SJim Ingham if (!error.Success()) { 227601f16664SJim Ingham result.AppendErrorWithFormat("error serializing breakpoints: %s.", 227701f16664SJim Ingham error.AsCString()); 227801f16664SJim Ingham result.SetStatus(eReturnStatusFailed); 2279e14dc268SJim Ingham } 2280e14dc268SJim Ingham return result.Succeeded(); 2281e14dc268SJim Ingham } 2282e14dc268SJim Ingham 2283e14dc268SJim Ingham private: 2284e14dc268SJim Ingham CommandOptions m_options; 2285e14dc268SJim Ingham }; 2286e14dc268SJim Ingham 2287e14dc268SJim Ingham #pragma mark Modify::CommandOptions 2288e14dc268SJim Ingham OptionDefinition 2289e14dc268SJim Ingham CommandObjectBreakpointWrite::CommandOptions::g_option_table[] = { 2290e14dc268SJim Ingham // clang-format off 2291e14dc268SJim Ingham {LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename, "The file into which to write the breakpoints."}, 2292e14dc268SJim Ingham {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} 2293e14dc268SJim Ingham // clang-format on 2294e14dc268SJim Ingham }; 2295e14dc268SJim Ingham 2296e14dc268SJim Ingham //------------------------------------------------------------------------- 229730fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 229830fdc8d8SChris Lattner //------------------------------------------------------------------------- 2299ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 230030fdc8d8SChris Lattner 2301b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint( 2302b9c1b51eSKate Stone CommandInterpreter &interpreter) 2303b9c1b51eSKate Stone : CommandObjectMultiword( 2304b9c1b51eSKate Stone interpreter, "breakpoint", 23057428a18cSKate Stone "Commands for operating on breakpoints (see 'help b' for shorthand.)", 2306b9c1b51eSKate Stone "breakpoint <subcommand> [<command-options>]") { 2307b9c1b51eSKate Stone CommandObjectSP list_command_object( 2308b9c1b51eSKate Stone new CommandObjectBreakpointList(interpreter)); 2309b9c1b51eSKate Stone CommandObjectSP enable_command_object( 2310b9c1b51eSKate Stone new CommandObjectBreakpointEnable(interpreter)); 2311b9c1b51eSKate Stone CommandObjectSP disable_command_object( 2312b9c1b51eSKate Stone new CommandObjectBreakpointDisable(interpreter)); 2313b9c1b51eSKate Stone CommandObjectSP clear_command_object( 2314b9c1b51eSKate Stone new CommandObjectBreakpointClear(interpreter)); 2315b9c1b51eSKate Stone CommandObjectSP delete_command_object( 2316b9c1b51eSKate Stone new CommandObjectBreakpointDelete(interpreter)); 2317b9c1b51eSKate Stone CommandObjectSP set_command_object( 2318b9c1b51eSKate Stone new CommandObjectBreakpointSet(interpreter)); 2319b9c1b51eSKate Stone CommandObjectSP command_command_object( 2320b9c1b51eSKate Stone new CommandObjectBreakpointCommand(interpreter)); 2321b9c1b51eSKate Stone CommandObjectSP modify_command_object( 2322b9c1b51eSKate Stone new CommandObjectBreakpointModify(interpreter)); 2323b9c1b51eSKate Stone CommandObjectSP name_command_object( 2324b9c1b51eSKate Stone new CommandObjectBreakpointName(interpreter)); 2325e14dc268SJim Ingham CommandObjectSP write_command_object( 2326e14dc268SJim Ingham new CommandObjectBreakpointWrite(interpreter)); 2327e14dc268SJim Ingham CommandObjectSP read_command_object( 2328e14dc268SJim Ingham new CommandObjectBreakpointRead(interpreter)); 232930fdc8d8SChris Lattner 2330b7234e40SJohnny Chen list_command_object->SetCommandName("breakpoint list"); 233130fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 233230fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 2333b7234e40SJohnny Chen clear_command_object->SetCommandName("breakpoint clear"); 2334b7234e40SJohnny Chen delete_command_object->SetCommandName("breakpoint delete"); 2335ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 2336b7234e40SJohnny Chen command_command_object->SetCommandName("breakpoint command"); 2337b7234e40SJohnny Chen modify_command_object->SetCommandName("breakpoint modify"); 23385e09c8c3SJim Ingham name_command_object->SetCommandName("breakpoint name"); 2339e14dc268SJim Ingham write_command_object->SetCommandName("breakpoint write"); 2340e14dc268SJim Ingham read_command_object->SetCommandName("breakpoint read"); 234130fdc8d8SChris Lattner 234223f59509SGreg Clayton LoadSubCommand("list", list_command_object); 234323f59509SGreg Clayton LoadSubCommand("enable", enable_command_object); 234423f59509SGreg Clayton LoadSubCommand("disable", disable_command_object); 234523f59509SGreg Clayton LoadSubCommand("clear", clear_command_object); 234623f59509SGreg Clayton LoadSubCommand("delete", delete_command_object); 234723f59509SGreg Clayton LoadSubCommand("set", set_command_object); 234823f59509SGreg Clayton LoadSubCommand("command", command_command_object); 234923f59509SGreg Clayton LoadSubCommand("modify", modify_command_object); 23505e09c8c3SJim Ingham LoadSubCommand("name", name_command_object); 2351e14dc268SJim Ingham LoadSubCommand("write", write_command_object); 2352e14dc268SJim Ingham LoadSubCommand("read", read_command_object); 235330fdc8d8SChris Lattner } 235430fdc8d8SChris Lattner 23559e85e5a8SEugene Zelenko CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default; 235630fdc8d8SChris Lattner 2357b9c1b51eSKate Stone void CommandObjectMultiwordBreakpoint::VerifyIDs(Args &args, Target *target, 23585e09c8c3SJim Ingham bool allow_locations, 23595e09c8c3SJim Ingham CommandReturnObject &result, 2360b9c1b51eSKate Stone BreakpointIDList *valid_ids) { 236130fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 2362b9c1b51eSKate Stone // 2). the full breakpoint & location 2363b9c1b51eSKate Stone // canonical representation 2364b9c1b51eSKate Stone // 3). the word "to" or a hyphen, 2365b9c1b51eSKate Stone // representing a range (in which case there 2366b9c1b51eSKate Stone // had *better* be an entry both before & 2367b9c1b51eSKate Stone // after of one of the first two types. 23685e09c8c3SJim Ingham // 4). A breakpoint name 2369b9c1b51eSKate Stone // If args is empty, we will use the last created breakpoint (if there is 2370b9c1b51eSKate Stone // one.) 237130fdc8d8SChris Lattner 237230fdc8d8SChris Lattner Args temp_args; 237330fdc8d8SChris Lattner 2374b9c1b51eSKate Stone if (args.GetArgumentCount() == 0) { 2375b9c1b51eSKate Stone if (target->GetLastCreatedBreakpoint()) { 2376b9c1b51eSKate Stone valid_ids->AddBreakpointID(BreakpointID( 2377b9c1b51eSKate Stone target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); 237836f3b369SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 2379b9c1b51eSKate Stone } else { 2380b9c1b51eSKate Stone result.AppendError( 2381b9c1b51eSKate Stone "No breakpoint specified and no last created breakpoint."); 238236f3b369SJim Ingham result.SetStatus(eReturnStatusFailed); 238336f3b369SJim Ingham } 238436f3b369SJim Ingham return; 238536f3b369SJim Ingham } 238636f3b369SJim Ingham 2387b9c1b51eSKate Stone // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff 2388b9c1b51eSKate Stone // directly from the old ARGS to 2389b9c1b51eSKate Stone // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead 2390b9c1b51eSKate Stone // generate a list of strings for 2391b9c1b51eSKate Stone // all the breakpoint ids in the range, and shove all of those breakpoint id 2392b9c1b51eSKate Stone // strings into TEMP_ARGS. 239330fdc8d8SChris Lattner 2394b9c1b51eSKate Stone BreakpointIDList::FindAndReplaceIDRanges(args, target, allow_locations, 2395b9c1b51eSKate Stone result, temp_args); 239630fdc8d8SChris Lattner 2397b9c1b51eSKate Stone // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual 2398b9c1b51eSKate Stone // BreakpointIDList: 239930fdc8d8SChris Lattner 2400b9c1b51eSKate Stone valid_ids->InsertStringArray(temp_args.GetConstArgumentVector(), 2401b9c1b51eSKate Stone temp_args.GetArgumentCount(), result); 240230fdc8d8SChris Lattner 2403b9c1b51eSKate Stone // At this point, all of the breakpoint ids that the user passed in have been 2404b9c1b51eSKate Stone // converted to breakpoint IDs 240530fdc8d8SChris Lattner // and put into valid_ids. 240630fdc8d8SChris Lattner 2407b9c1b51eSKate Stone if (result.Succeeded()) { 2408b9c1b51eSKate Stone // Now that we've converted everything from args into a list of breakpoint 2409b9c1b51eSKate Stone // ids, go through our tentative list 2410b9c1b51eSKate Stone // of breakpoint id's and verify that they correspond to valid/currently set 2411b9c1b51eSKate Stone // breakpoints. 241230fdc8d8SChris Lattner 2413c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 2414b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 241530fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex(i); 2416b9c1b51eSKate Stone Breakpoint *breakpoint = 2417b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 2418b9c1b51eSKate Stone if (breakpoint != nullptr) { 2419c7bece56SGreg Clayton const size_t num_locations = breakpoint->GetNumLocations(); 2420b9c1b51eSKate Stone if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations) { 242130fdc8d8SChris Lattner StreamString id_str; 2422b9c1b51eSKate Stone BreakpointID::GetCanonicalReference( 2423b9c1b51eSKate Stone &id_str, cur_bp_id.GetBreakpointID(), cur_bp_id.GetLocationID()); 2424c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 2425b9c1b51eSKate Stone result.AppendErrorWithFormat( 2426b9c1b51eSKate Stone "'%s' is not a currently valid breakpoint/location id.\n", 242730fdc8d8SChris Lattner id_str.GetData()); 242830fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 242930fdc8d8SChris Lattner } 2430b9c1b51eSKate Stone } else { 2431c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 2432b9c1b51eSKate Stone result.AppendErrorWithFormat( 2433b9c1b51eSKate Stone "'%d' is not a currently valid breakpoint ID.\n", 24347428a18cSKate Stone cur_bp_id.GetBreakpointID()); 243530fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 243630fdc8d8SChris Lattner } 243730fdc8d8SChris Lattner } 243830fdc8d8SChris Lattner } 243930fdc8d8SChris Lattner } 2440