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 12*9e85e5a8SEugene Zelenko #include <vector> 13*9e85e5a8SEugene Zelenko 1430fdc8d8SChris Lattner // Other libraries and framework includes 1530fdc8d8SChris Lattner // Project includes 16*9e85e5a8SEugene Zelenko #include "CommandObjectBreakpoint.h" 17*9e85e5a8SEugene 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" 215275aaa0SVince Harron #include "lldb/Host/StringConvert.h" 2240af72e1SJim Ingham #include "lldb/Interpreter/Options.h" 2332abc6edSZachary Turner #include "lldb/Interpreter/OptionValueBoolean.h" 245e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueString.h" 255e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueUInt64.h" 2630fdc8d8SChris Lattner #include "lldb/Core/RegularExpression.h" 2730fdc8d8SChris Lattner #include "lldb/Core/StreamString.h" 2830fdc8d8SChris Lattner #include "lldb/Interpreter/CommandInterpreter.h" 2930fdc8d8SChris Lattner #include "lldb/Interpreter/CommandReturnObject.h" 300e0984eeSJim Ingham #include "lldb/Target/Language.h" 3130fdc8d8SChris Lattner #include "lldb/Target/Target.h" 3230fdc8d8SChris Lattner #include "lldb/Interpreter/CommandCompletions.h" 33b57e4a1bSJason Molenda #include "lldb/Target/StackFrame.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 4030fdc8d8SChris Lattner static void 4185e8b814SJim Ingham AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level) 4230fdc8d8SChris Lattner { 4330fdc8d8SChris Lattner s->IndentMore(); 4430fdc8d8SChris Lattner bp->GetDescription (s, level, true); 4530fdc8d8SChris Lattner s->IndentLess(); 4630fdc8d8SChris Lattner s->EOL(); 4730fdc8d8SChris Lattner } 4830fdc8d8SChris Lattner 4930fdc8d8SChris Lattner //------------------------------------------------------------------------- 505a988416SJim Ingham // CommandObjectBreakpointSet 5130fdc8d8SChris Lattner //------------------------------------------------------------------------- 5230fdc8d8SChris Lattner 535a988416SJim Ingham class CommandObjectBreakpointSet : public CommandObjectParsed 545a988416SJim Ingham { 555a988416SJim Ingham public: 565a988416SJim Ingham typedef enum BreakpointSetType 575a988416SJim Ingham { 585a988416SJim Ingham eSetTypeInvalid, 595a988416SJim Ingham eSetTypeFileAndLine, 605a988416SJim Ingham eSetTypeAddress, 615a988416SJim Ingham eSetTypeFunctionName, 625a988416SJim Ingham eSetTypeFunctionRegexp, 635a988416SJim Ingham eSetTypeSourceRegexp, 645a988416SJim Ingham eSetTypeException 655a988416SJim Ingham } BreakpointSetType; 665a988416SJim Ingham 675a988416SJim Ingham CommandObjectBreakpointSet (CommandInterpreter &interpreter) : 685a988416SJim Ingham CommandObjectParsed (interpreter, 695a988416SJim Ingham "breakpoint set", 705a988416SJim Ingham "Sets a breakpoint or set of breakpoints in the executable.", 715a988416SJim Ingham "breakpoint set <cmd-options>"), 725a988416SJim Ingham m_options (interpreter) 735a988416SJim Ingham { 745a988416SJim Ingham } 755a988416SJim Ingham 76*9e85e5a8SEugene Zelenko ~CommandObjectBreakpointSet() override = default; 775a988416SJim Ingham 7813d21e9aSBruce Mitchener Options * 7913d21e9aSBruce Mitchener GetOptions () override 805a988416SJim Ingham { 815a988416SJim Ingham return &m_options; 825a988416SJim Ingham } 835a988416SJim Ingham 845a988416SJim Ingham class CommandOptions : public Options 855a988416SJim Ingham { 865a988416SJim Ingham public: 875a988416SJim Ingham CommandOptions (CommandInterpreter &interpreter) : 88eb0103f2SGreg Clayton Options (interpreter), 897d49c9c8SJohnny Chen m_condition (), 9087df91b8SJim Ingham m_filenames (), 9130fdc8d8SChris Lattner m_line_num (0), 9230fdc8d8SChris Lattner m_column (0), 93fab10e89SJim Ingham m_func_names (), 94fab10e89SJim Ingham m_func_name_type_mask (eFunctionNameTypeNone), 9530fdc8d8SChris Lattner m_func_regexp (), 96969795f1SJim Ingham m_source_text_regexp(), 9730fdc8d8SChris Lattner m_modules (), 981b54c88cSJim Ingham m_load_addr(), 99c982c768SGreg Clayton m_ignore_count (0), 1001b54c88cSJim Ingham m_thread_id(LLDB_INVALID_THREAD_ID), 101c982c768SGreg Clayton m_thread_index (UINT32_MAX), 1021b54c88cSJim Ingham m_thread_name(), 103fab10e89SJim Ingham m_queue_name(), 104fab10e89SJim Ingham m_catch_bp (false), 1051f746071SGreg Clayton m_throw_bp (true), 106eb023e75SGreg Clayton m_hardware (false), 107a72b31c7SJim Ingham m_exception_language (eLanguageTypeUnknown), 10823b1decbSDawn Perchik m_language (lldb::eLanguageTypeUnknown), 109ca36cd16SJim Ingham m_skip_prologue (eLazyBoolCalculate), 110e732052fSJim Ingham m_one_shot (false), 111055ad9beSIlia K m_all_files (false), 112055ad9beSIlia K m_move_to_nearest_code (eLazyBoolCalculate) 11330fdc8d8SChris Lattner { 11430fdc8d8SChris Lattner } 11530fdc8d8SChris Lattner 116*9e85e5a8SEugene Zelenko ~CommandOptions() override = default; 11787df91b8SJim Ingham 11813d21e9aSBruce Mitchener Error 11913d21e9aSBruce Mitchener SetOptionValue (uint32_t option_idx, const char *option_arg) override 12030fdc8d8SChris Lattner { 12130fdc8d8SChris Lattner Error error; 1223bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 12330fdc8d8SChris Lattner 12430fdc8d8SChris Lattner switch (short_option) 12530fdc8d8SChris Lattner { 12630fdc8d8SChris Lattner case 'a': 127b9d5df58SGreg Clayton { 128b9d5df58SGreg Clayton ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); 129b9d5df58SGreg Clayton m_load_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error); 130b9d5df58SGreg Clayton } 13130fdc8d8SChris Lattner break; 13230fdc8d8SChris Lattner 133e732052fSJim Ingham case 'A': 134e732052fSJim Ingham m_all_files = true; 135e732052fSJim Ingham break; 136e732052fSJim Ingham 137ca36cd16SJim Ingham case 'b': 138ca36cd16SJim Ingham m_func_names.push_back (option_arg); 139ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeBase; 140ca36cd16SJim Ingham break; 141ca36cd16SJim Ingham 1427d49c9c8SJohnny Chen case 'C': 1436312991cSJim Ingham { 1446312991cSJim Ingham bool success; 1456312991cSJim Ingham m_column = StringConvert::ToUInt32 (option_arg, 0, 0, &success); 1466312991cSJim Ingham if (!success) 1476312991cSJim Ingham error.SetErrorStringWithFormat("invalid column number: %s", option_arg); 14830fdc8d8SChris Lattner break; 1496312991cSJim Ingham } 150*9e85e5a8SEugene Zelenko 1517d49c9c8SJohnny Chen case 'c': 1527d49c9c8SJohnny Chen m_condition.assign(option_arg); 1537d49c9c8SJohnny Chen break; 1547d49c9c8SJohnny Chen 15533df7cd3SJim Ingham case 'D': 15633df7cd3SJim Ingham m_use_dummy = true; 15733df7cd3SJim Ingham break; 15833df7cd3SJim Ingham 159fab10e89SJim Ingham case 'E': 160fab10e89SJim Ingham { 1610e0984eeSJim Ingham LanguageType language = Language::GetLanguageTypeFromString (option_arg); 162fab10e89SJim Ingham 163fab10e89SJim Ingham switch (language) 164fab10e89SJim Ingham { 165fab10e89SJim Ingham case eLanguageTypeC89: 166fab10e89SJim Ingham case eLanguageTypeC: 167fab10e89SJim Ingham case eLanguageTypeC99: 1681d0089faSBruce Mitchener case eLanguageTypeC11: 169a72b31c7SJim Ingham m_exception_language = eLanguageTypeC; 170fab10e89SJim Ingham break; 171fab10e89SJim Ingham case eLanguageTypeC_plus_plus: 1721d0089faSBruce Mitchener case eLanguageTypeC_plus_plus_03: 1731d0089faSBruce Mitchener case eLanguageTypeC_plus_plus_11: 1742ba84a6aSBruce Mitchener case eLanguageTypeC_plus_plus_14: 175a72b31c7SJim Ingham m_exception_language = eLanguageTypeC_plus_plus; 176fab10e89SJim Ingham break; 177fab10e89SJim Ingham case eLanguageTypeObjC: 178a72b31c7SJim Ingham m_exception_language = eLanguageTypeObjC; 179fab10e89SJim Ingham break; 180fab10e89SJim Ingham case eLanguageTypeObjC_plus_plus: 181fab10e89SJim Ingham error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c"); 182fab10e89SJim Ingham break; 183fab10e89SJim Ingham case eLanguageTypeUnknown: 184fab10e89SJim Ingham error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg); 185fab10e89SJim Ingham break; 186fab10e89SJim Ingham default: 187fab10e89SJim Ingham error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg); 188fab10e89SJim Ingham } 189fab10e89SJim Ingham } 190fab10e89SJim Ingham break; 191ca36cd16SJim Ingham 192ca36cd16SJim Ingham case 'f': 193ca36cd16SJim Ingham m_filenames.AppendIfUnique (FileSpec(option_arg, false)); 194fab10e89SJim Ingham break; 195ca36cd16SJim Ingham 196ca36cd16SJim Ingham case 'F': 197ca36cd16SJim Ingham m_func_names.push_back (option_arg); 198ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeFull; 199ca36cd16SJim Ingham break; 200ca36cd16SJim Ingham 201fab10e89SJim Ingham case 'h': 202fab10e89SJim Ingham { 203fab10e89SJim Ingham bool success; 204fab10e89SJim Ingham m_catch_bp = Args::StringToBoolean (option_arg, true, &success); 205fab10e89SJim Ingham if (!success) 206fab10e89SJim Ingham error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg); 207fab10e89SJim Ingham } 208168d469aSJim Ingham break; 209eb023e75SGreg Clayton 210eb023e75SGreg Clayton case 'H': 211eb023e75SGreg Clayton m_hardware = true; 212eb023e75SGreg Clayton break; 213eb023e75SGreg Clayton 214ca36cd16SJim Ingham case 'i': 2155275aaa0SVince Harron m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); 216ca36cd16SJim Ingham if (m_ignore_count == UINT32_MAX) 217ca36cd16SJim Ingham error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); 218ca36cd16SJim Ingham break; 219ca36cd16SJim Ingham 220a8558b62SJim Ingham case 'K': 221a8558b62SJim Ingham { 222a8558b62SJim Ingham bool success; 223a8558b62SJim Ingham bool value; 224a8558b62SJim Ingham value = Args::StringToBoolean (option_arg, true, &success); 225a8558b62SJim Ingham if (value) 226a8558b62SJim Ingham m_skip_prologue = eLazyBoolYes; 227a8558b62SJim Ingham else 228a8558b62SJim Ingham m_skip_prologue = eLazyBoolNo; 229a8558b62SJim Ingham 230a8558b62SJim Ingham if (!success) 231a8558b62SJim Ingham error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg); 232a8558b62SJim Ingham } 233fab10e89SJim Ingham break; 234ca36cd16SJim Ingham 235ca36cd16SJim Ingham case 'l': 2366312991cSJim Ingham { 2376312991cSJim Ingham bool success; 2386312991cSJim Ingham m_line_num = StringConvert::ToUInt32 (option_arg, 0, 0, &success); 2396312991cSJim Ingham if (!success) 2406312991cSJim Ingham error.SetErrorStringWithFormat ("invalid line number: %s.", option_arg); 241ca36cd16SJim Ingham break; 2426312991cSJim Ingham } 243055ad9beSIlia K 24423b1decbSDawn Perchik case 'L': 2450e0984eeSJim Ingham m_language = Language::GetLanguageTypeFromString (option_arg); 24623b1decbSDawn Perchik if (m_language == eLanguageTypeUnknown) 24723b1decbSDawn Perchik error.SetErrorStringWithFormat ("Unknown language type: '%s' for breakpoint", option_arg); 24823b1decbSDawn Perchik break; 24923b1decbSDawn Perchik 250055ad9beSIlia K case 'm': 251055ad9beSIlia K { 252055ad9beSIlia K bool success; 253055ad9beSIlia K bool value; 254055ad9beSIlia K value = Args::StringToBoolean (option_arg, true, &success); 255055ad9beSIlia K if (value) 256055ad9beSIlia K m_move_to_nearest_code = eLazyBoolYes; 257055ad9beSIlia K else 258055ad9beSIlia K m_move_to_nearest_code = eLazyBoolNo; 259055ad9beSIlia K 260055ad9beSIlia K if (!success) 261055ad9beSIlia K error.SetErrorStringWithFormat ("Invalid boolean value for move-to-nearest-code option: '%s'", option_arg); 262055ad9beSIlia K break; 263055ad9beSIlia K } 264055ad9beSIlia K 265ca36cd16SJim Ingham case 'M': 266ca36cd16SJim Ingham m_func_names.push_back (option_arg); 267ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeMethod; 268ca36cd16SJim Ingham break; 269ca36cd16SJim Ingham 270ca36cd16SJim Ingham case 'n': 271ca36cd16SJim Ingham m_func_names.push_back (option_arg); 272ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeAuto; 273ca36cd16SJim Ingham break; 274ca36cd16SJim Ingham 2755e09c8c3SJim Ingham case 'N': 2765e09c8c3SJim Ingham if (BreakpointID::StringIsBreakpointName(option_arg, error)) 2775e09c8c3SJim Ingham m_breakpoint_names.push_back (option_arg); 2785e09c8c3SJim Ingham break; 2795e09c8c3SJim Ingham 280ca36cd16SJim Ingham case 'o': 281ca36cd16SJim Ingham m_one_shot = true; 282ca36cd16SJim Ingham break; 283ca36cd16SJim Ingham 284a72b31c7SJim Ingham case 'O': 285a72b31c7SJim Ingham m_exception_extra_args.AppendArgument ("-O"); 286a72b31c7SJim Ingham m_exception_extra_args.AppendArgument (option_arg); 287a72b31c7SJim Ingham break; 288a72b31c7SJim Ingham 289ca36cd16SJim Ingham case 'p': 290ca36cd16SJim Ingham m_source_text_regexp.assign (option_arg); 291ca36cd16SJim Ingham break; 292ca36cd16SJim Ingham 293ca36cd16SJim Ingham case 'q': 294ca36cd16SJim Ingham m_queue_name.assign (option_arg); 295ca36cd16SJim Ingham break; 296ca36cd16SJim Ingham 297ca36cd16SJim Ingham case 'r': 298ca36cd16SJim Ingham m_func_regexp.assign (option_arg); 299ca36cd16SJim Ingham break; 300ca36cd16SJim Ingham 301ca36cd16SJim Ingham case 's': 302ca36cd16SJim Ingham m_modules.AppendIfUnique (FileSpec (option_arg, false)); 303ca36cd16SJim Ingham break; 304ca36cd16SJim Ingham 305ca36cd16SJim Ingham case 'S': 306ca36cd16SJim Ingham m_func_names.push_back (option_arg); 307ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeSelector; 308ca36cd16SJim Ingham break; 309ca36cd16SJim Ingham 310ca36cd16SJim Ingham case 't' : 3115275aaa0SVince Harron m_thread_id = StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 312ca36cd16SJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 313ca36cd16SJim Ingham error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); 314ca36cd16SJim Ingham break; 315ca36cd16SJim Ingham 316ca36cd16SJim Ingham case 'T': 317ca36cd16SJim Ingham m_thread_name.assign (option_arg); 318ca36cd16SJim Ingham break; 319ca36cd16SJim Ingham 320ca36cd16SJim Ingham case 'w': 321ca36cd16SJim Ingham { 322ca36cd16SJim Ingham bool success; 323ca36cd16SJim Ingham m_throw_bp = Args::StringToBoolean (option_arg, true, &success); 324ca36cd16SJim Ingham if (!success) 325ca36cd16SJim Ingham error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg); 326ca36cd16SJim Ingham } 327ca36cd16SJim Ingham break; 328ca36cd16SJim Ingham 329ca36cd16SJim Ingham case 'x': 3305275aaa0SVince Harron m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); 331ca36cd16SJim Ingham if (m_thread_id == UINT32_MAX) 332ca36cd16SJim Ingham error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); 333ca36cd16SJim Ingham break; 334ca36cd16SJim Ingham 33530fdc8d8SChris Lattner default: 33686edbf41SGreg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 33730fdc8d8SChris Lattner break; 33830fdc8d8SChris Lattner } 33930fdc8d8SChris Lattner 34030fdc8d8SChris Lattner return error; 34130fdc8d8SChris Lattner } 342*9e85e5a8SEugene Zelenko 34330fdc8d8SChris Lattner void 34413d21e9aSBruce Mitchener OptionParsingStarting () override 34530fdc8d8SChris Lattner { 3467d49c9c8SJohnny Chen m_condition.clear(); 34787df91b8SJim Ingham m_filenames.Clear(); 34830fdc8d8SChris Lattner m_line_num = 0; 34930fdc8d8SChris Lattner m_column = 0; 350fab10e89SJim Ingham m_func_names.clear(); 3511f746071SGreg Clayton m_func_name_type_mask = eFunctionNameTypeNone; 35230fdc8d8SChris Lattner m_func_regexp.clear(); 3531f746071SGreg Clayton m_source_text_regexp.clear(); 35487df91b8SJim Ingham m_modules.Clear(); 3551f746071SGreg Clayton m_load_addr = LLDB_INVALID_ADDRESS; 356c982c768SGreg Clayton m_ignore_count = 0; 3571b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 358c982c768SGreg Clayton m_thread_index = UINT32_MAX; 3591b54c88cSJim Ingham m_thread_name.clear(); 3601b54c88cSJim Ingham m_queue_name.clear(); 361fab10e89SJim Ingham m_catch_bp = false; 362fab10e89SJim Ingham m_throw_bp = true; 363eb023e75SGreg Clayton m_hardware = false; 364a72b31c7SJim Ingham m_exception_language = eLanguageTypeUnknown; 36523b1decbSDawn Perchik m_language = lldb::eLanguageTypeUnknown; 366a8558b62SJim Ingham m_skip_prologue = eLazyBoolCalculate; 367ca36cd16SJim Ingham m_one_shot = false; 36833df7cd3SJim Ingham m_use_dummy = false; 3695e09c8c3SJim Ingham m_breakpoint_names.clear(); 370e732052fSJim Ingham m_all_files = false; 371a72b31c7SJim Ingham m_exception_extra_args.Clear(); 372055ad9beSIlia K m_move_to_nearest_code = eLazyBoolCalculate; 37330fdc8d8SChris Lattner } 37430fdc8d8SChris Lattner 3755a988416SJim Ingham const OptionDefinition* 37613d21e9aSBruce Mitchener GetDefinitions () override 37730fdc8d8SChris Lattner { 3785a988416SJim Ingham return g_option_table; 37930fdc8d8SChris Lattner } 38030fdc8d8SChris Lattner 3815a988416SJim Ingham // Options table: Required for subclasses of Options. 38230fdc8d8SChris Lattner 3835a988416SJim Ingham static OptionDefinition g_option_table[]; 38430fdc8d8SChris Lattner 3855a988416SJim Ingham // Instance variables to hold the values for command options. 386969795f1SJim Ingham 3875a988416SJim Ingham std::string m_condition; 3885a988416SJim Ingham FileSpecList m_filenames; 3895a988416SJim Ingham uint32_t m_line_num; 3905a988416SJim Ingham uint32_t m_column; 3915a988416SJim Ingham std::vector<std::string> m_func_names; 3925e09c8c3SJim Ingham std::vector<std::string> m_breakpoint_names; 3935a988416SJim Ingham uint32_t m_func_name_type_mask; 3945a988416SJim Ingham std::string m_func_regexp; 3955a988416SJim Ingham std::string m_source_text_regexp; 3965a988416SJim Ingham FileSpecList m_modules; 3975a988416SJim Ingham lldb::addr_t m_load_addr; 3985a988416SJim Ingham uint32_t m_ignore_count; 3995a988416SJim Ingham lldb::tid_t m_thread_id; 4005a988416SJim Ingham uint32_t m_thread_index; 4015a988416SJim Ingham std::string m_thread_name; 4025a988416SJim Ingham std::string m_queue_name; 4035a988416SJim Ingham bool m_catch_bp; 4045a988416SJim Ingham bool m_throw_bp; 405eb023e75SGreg Clayton bool m_hardware; // Request to use hardware breakpoints 406a72b31c7SJim Ingham lldb::LanguageType m_exception_language; 40723b1decbSDawn Perchik lldb::LanguageType m_language; 4085a988416SJim Ingham LazyBool m_skip_prologue; 409ca36cd16SJim Ingham bool m_one_shot; 41033df7cd3SJim Ingham bool m_use_dummy; 411e732052fSJim Ingham bool m_all_files; 412a72b31c7SJim Ingham Args m_exception_extra_args; 413055ad9beSIlia K LazyBool m_move_to_nearest_code; 4145a988416SJim Ingham }; 4155a988416SJim Ingham 4165a988416SJim Ingham protected: 41713d21e9aSBruce Mitchener bool 4185a988416SJim Ingham DoExecute (Args& command, 41913d21e9aSBruce Mitchener CommandReturnObject &result) override 42030fdc8d8SChris Lattner { 42133df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 42233df7cd3SJim Ingham 423893c932aSJim Ingham if (target == nullptr) 42430fdc8d8SChris Lattner { 425effe5c95SGreg Clayton result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command)."); 42630fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 42730fdc8d8SChris Lattner return false; 42830fdc8d8SChris Lattner } 42930fdc8d8SChris Lattner 43030fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 43130fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 43230fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 43330fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 43430fdc8d8SChris Lattner // 4). -r [-s -g] (setting breakpoint by function name regular expression) 435969795f1SJim Ingham // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text) 436fab10e89SJim Ingham // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.) 43730fdc8d8SChris Lattner 43830fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 43930fdc8d8SChris Lattner 44030fdc8d8SChris Lattner if (m_options.m_line_num != 0) 44130fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 44230fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 44330fdc8d8SChris Lattner break_type = eSetTypeAddress; 444fab10e89SJim Ingham else if (!m_options.m_func_names.empty()) 44530fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 44630fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 44730fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 448969795f1SJim Ingham else if (!m_options.m_source_text_regexp.empty()) 449969795f1SJim Ingham break_type = eSetTypeSourceRegexp; 450a72b31c7SJim Ingham else if (m_options.m_exception_language != eLanguageTypeUnknown) 451fab10e89SJim Ingham break_type = eSetTypeException; 45230fdc8d8SChris Lattner 453*9e85e5a8SEugene Zelenko Breakpoint *bp = nullptr; 454274060b6SGreg Clayton FileSpec module_spec; 455a8558b62SJim Ingham const bool internal = false; 456a8558b62SJim Ingham 45730fdc8d8SChris Lattner switch (break_type) 45830fdc8d8SChris Lattner { 45930fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 46030fdc8d8SChris Lattner { 46130fdc8d8SChris Lattner FileSpec file; 462c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 46387df91b8SJim Ingham if (num_files == 0) 46487df91b8SJim Ingham { 46587df91b8SJim Ingham if (!GetDefaultFile (target, file, result)) 46687df91b8SJim Ingham { 46787df91b8SJim Ingham result.AppendError("No file supplied and no default file available."); 46887df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 46987df91b8SJim Ingham return false; 47087df91b8SJim Ingham } 47187df91b8SJim Ingham } 47287df91b8SJim Ingham else if (num_files > 1) 47387df91b8SJim Ingham { 47487df91b8SJim Ingham result.AppendError("Only one file at a time is allowed for file and line breakpoints."); 47587df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 47687df91b8SJim Ingham return false; 47787df91b8SJim Ingham } 47887df91b8SJim Ingham else 47987df91b8SJim Ingham file = m_options.m_filenames.GetFileSpecAtIndex(0); 48030fdc8d8SChris Lattner 4811f746071SGreg Clayton // Only check for inline functions if 4821f746071SGreg Clayton LazyBool check_inlines = eLazyBoolCalculate; 4831f746071SGreg Clayton 48487df91b8SJim Ingham bp = target->CreateBreakpoint (&(m_options.m_modules), 48530fdc8d8SChris Lattner file, 48630fdc8d8SChris Lattner m_options.m_line_num, 4871f746071SGreg Clayton check_inlines, 488a8558b62SJim Ingham m_options.m_skip_prologue, 489eb023e75SGreg Clayton internal, 490055ad9beSIlia K m_options.m_hardware, 491055ad9beSIlia K m_options.m_move_to_nearest_code).get(); 49230fdc8d8SChris Lattner } 49330fdc8d8SChris Lattner break; 4946eee5aa0SGreg Clayton 49530fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 496055a08a4SJim Ingham { 497055a08a4SJim Ingham // If a shared library has been specified, make an lldb_private::Address with the library, and 498055a08a4SJim Ingham // use that. That way the address breakpoint will track the load location of the library. 499055a08a4SJim Ingham size_t num_modules_specified = m_options.m_modules.GetSize(); 500055a08a4SJim Ingham if (num_modules_specified == 1) 501055a08a4SJim Ingham { 502055a08a4SJim Ingham const FileSpec *file_spec = m_options.m_modules.GetFileSpecPointerAtIndex(0); 503055a08a4SJim Ingham bp = target->CreateAddressInModuleBreakpoint (m_options.m_load_addr, 504055a08a4SJim Ingham internal, 505055a08a4SJim Ingham file_spec, 506055a08a4SJim Ingham m_options.m_hardware).get(); 507055a08a4SJim Ingham } 508055a08a4SJim Ingham else if (num_modules_specified == 0) 509055a08a4SJim Ingham { 510eb023e75SGreg Clayton bp = target->CreateBreakpoint (m_options.m_load_addr, 511eb023e75SGreg Clayton internal, 512eb023e75SGreg Clayton m_options.m_hardware).get(); 513055a08a4SJim Ingham } 514055a08a4SJim Ingham else 515055a08a4SJim Ingham { 516055a08a4SJim Ingham result.AppendError("Only one shared library can be specified for address breakpoints."); 517055a08a4SJim Ingham result.SetStatus(eReturnStatusFailed); 518055a08a4SJim Ingham return false; 519055a08a4SJim Ingham } 52030fdc8d8SChris Lattner break; 521055a08a4SJim Ingham } 52230fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 5230c5cd90dSGreg Clayton { 5240c5cd90dSGreg Clayton uint32_t name_type_mask = m_options.m_func_name_type_mask; 5250c5cd90dSGreg Clayton 5260c5cd90dSGreg Clayton if (name_type_mask == 0) 527e02b8504SGreg Clayton name_type_mask = eFunctionNameTypeAuto; 5280c5cd90dSGreg Clayton 52987df91b8SJim Ingham bp = target->CreateBreakpoint (&(m_options.m_modules), 53087df91b8SJim Ingham &(m_options.m_filenames), 531fab10e89SJim Ingham m_options.m_func_names, 532274060b6SGreg Clayton name_type_mask, 53323b1decbSDawn Perchik m_options.m_language, 534a8558b62SJim Ingham m_options.m_skip_prologue, 535eb023e75SGreg Clayton internal, 536eb023e75SGreg Clayton m_options.m_hardware).get(); 5370c5cd90dSGreg Clayton } 53830fdc8d8SChris Lattner break; 5390c5cd90dSGreg Clayton 54030fdc8d8SChris Lattner case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name 54130fdc8d8SChris Lattner { 54230fdc8d8SChris Lattner RegularExpression regexp(m_options.m_func_regexp.c_str()); 543969795f1SJim Ingham if (!regexp.IsValid()) 54430fdc8d8SChris Lattner { 545969795f1SJim Ingham char err_str[1024]; 546969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 547969795f1SJim Ingham result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"", 548969795f1SJim Ingham err_str); 54930fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 550969795f1SJim Ingham return false; 55130fdc8d8SChris Lattner } 55287df91b8SJim Ingham 553a8558b62SJim Ingham bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules), 554a8558b62SJim Ingham &(m_options.m_filenames), 555a8558b62SJim Ingham regexp, 5560fcdac36SJim Ingham m_options.m_language, 557a8558b62SJim Ingham m_options.m_skip_prologue, 558eb023e75SGreg Clayton internal, 559eb023e75SGreg Clayton m_options.m_hardware).get(); 56030fdc8d8SChris Lattner } 56130fdc8d8SChris Lattner break; 562969795f1SJim Ingham case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. 563969795f1SJim Ingham { 564c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 56587df91b8SJim Ingham 566e732052fSJim Ingham if (num_files == 0 && !m_options.m_all_files) 56787df91b8SJim Ingham { 568969795f1SJim Ingham FileSpec file; 56987df91b8SJim Ingham if (!GetDefaultFile (target, file, result)) 57087df91b8SJim Ingham { 57187df91b8SJim Ingham result.AppendError ("No files provided and could not find default file."); 57287df91b8SJim Ingham result.SetStatus (eReturnStatusFailed); 57387df91b8SJim Ingham return false; 57487df91b8SJim Ingham } 57587df91b8SJim Ingham else 57687df91b8SJim Ingham { 57787df91b8SJim Ingham m_options.m_filenames.Append (file); 57887df91b8SJim Ingham } 57987df91b8SJim Ingham } 5800c5cd90dSGreg Clayton 581969795f1SJim Ingham RegularExpression regexp(m_options.m_source_text_regexp.c_str()); 582969795f1SJim Ingham if (!regexp.IsValid()) 583969795f1SJim Ingham { 584969795f1SJim Ingham char err_str[1024]; 585969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 586969795f1SJim Ingham result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"", 587969795f1SJim Ingham err_str); 588969795f1SJim Ingham result.SetStatus (eReturnStatusFailed); 589969795f1SJim Ingham return false; 590969795f1SJim Ingham } 591eb023e75SGreg Clayton bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules), 592eb023e75SGreg Clayton &(m_options.m_filenames), 593eb023e75SGreg Clayton regexp, 594eb023e75SGreg Clayton internal, 595055ad9beSIlia K m_options.m_hardware, 596055ad9beSIlia K m_options.m_move_to_nearest_code).get(); 597969795f1SJim Ingham } 598969795f1SJim Ingham break; 599fab10e89SJim Ingham case eSetTypeException: 600fab10e89SJim Ingham { 601a72b31c7SJim Ingham Error precond_error; 602a72b31c7SJim Ingham bp = target->CreateExceptionBreakpoint (m_options.m_exception_language, 603eb023e75SGreg Clayton m_options.m_catch_bp, 604eb023e75SGreg Clayton m_options.m_throw_bp, 605a72b31c7SJim Ingham internal, 606a72b31c7SJim Ingham &m_options.m_exception_extra_args, 607a72b31c7SJim Ingham &precond_error).get(); 608a72b31c7SJim Ingham if (precond_error.Fail()) 609a72b31c7SJim Ingham { 610a72b31c7SJim Ingham result.AppendErrorWithFormat("Error setting extra exception arguments: %s", 611a72b31c7SJim Ingham precond_error.AsCString()); 612a72b31c7SJim Ingham target->RemoveBreakpointByID(bp->GetID()); 613a72b31c7SJim Ingham result.SetStatus(eReturnStatusFailed); 614a72b31c7SJim Ingham return false; 615a72b31c7SJim Ingham } 616fab10e89SJim Ingham } 617fab10e89SJim Ingham break; 61830fdc8d8SChris Lattner default: 61930fdc8d8SChris Lattner break; 62030fdc8d8SChris Lattner } 62130fdc8d8SChris Lattner 6221b54c88cSJim Ingham // Now set the various options that were passed in: 6231b54c88cSJim Ingham if (bp) 6241b54c88cSJim Ingham { 6251b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 6261b54c88cSJim Ingham bp->SetThreadID (m_options.m_thread_id); 6271b54c88cSJim Ingham 628c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 6291b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 6301b54c88cSJim Ingham 6311b54c88cSJim Ingham if (!m_options.m_thread_name.empty()) 6321b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); 6331b54c88cSJim Ingham 6341b54c88cSJim Ingham if (!m_options.m_queue_name.empty()) 6351b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); 6361b54c88cSJim Ingham 637c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 6381b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 6397d49c9c8SJohnny Chen 6407d49c9c8SJohnny Chen if (!m_options.m_condition.empty()) 6417d49c9c8SJohnny Chen bp->GetOptions()->SetCondition(m_options.m_condition.c_str()); 642ca36cd16SJim Ingham 6435e09c8c3SJim Ingham if (!m_options.m_breakpoint_names.empty()) 6445e09c8c3SJim Ingham { 6455e09c8c3SJim Ingham Error error; // We don't need to check the error here, since the option parser checked it... 6465e09c8c3SJim Ingham for (auto name : m_options.m_breakpoint_names) 6475e09c8c3SJim Ingham bp->AddName(name.c_str(), error); 6485e09c8c3SJim Ingham } 6495e09c8c3SJim Ingham 650ca36cd16SJim Ingham bp->SetOneShot (m_options.m_one_shot); 6511b54c88cSJim Ingham } 6521b54c88cSJim Ingham 653969795f1SJim Ingham if (bp) 65430fdc8d8SChris Lattner { 65585e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 6561391cc7dSJim Ingham const bool show_locations = false; 6571391cc7dSJim Ingham bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, show_locations); 6584aeb1989SJim Ingham if (target == m_interpreter.GetDebugger().GetDummyTarget()) 6594aeb1989SJim Ingham output_stream.Printf ("Breakpoint set in dummy target, will get copied into future targets.\n"); 6604aeb1989SJim Ingham else 6614aeb1989SJim Ingham { 662fab10e89SJim Ingham // Don't print out this warning for exception breakpoints. They can get set before the target 663fab10e89SJim Ingham // is set, but we won't know how to actually set the breakpoint till we run. 664fab10e89SJim Ingham if (bp->GetNumLocations() == 0 && break_type != eSetTypeException) 6654aeb1989SJim Ingham { 666be484f41SCaroline Tice output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n"); 6674aeb1989SJim Ingham } 6684aeb1989SJim Ingham } 66930fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 67030fdc8d8SChris Lattner } 67130fdc8d8SChris Lattner else if (!bp) 67230fdc8d8SChris Lattner { 67330fdc8d8SChris Lattner result.AppendError ("Breakpoint creation failed: No breakpoint created."); 67430fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 67530fdc8d8SChris Lattner } 67630fdc8d8SChris Lattner 67730fdc8d8SChris Lattner return result.Succeeded(); 67830fdc8d8SChris Lattner } 67930fdc8d8SChris Lattner 6805a988416SJim Ingham private: 6815a988416SJim Ingham bool 6825a988416SJim Ingham GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result) 6835a988416SJim Ingham { 6845a988416SJim Ingham uint32_t default_line; 6855a988416SJim Ingham // First use the Source Manager's default file. 6865a988416SJim Ingham // Then use the current stack frame's file. 6875a988416SJim Ingham if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) 6885a988416SJim Ingham { 689b57e4a1bSJason Molenda StackFrame *cur_frame = m_exe_ctx.GetFramePtr(); 690*9e85e5a8SEugene Zelenko if (cur_frame == nullptr) 6915a988416SJim Ingham { 6925a988416SJim Ingham result.AppendError ("No selected frame to use to find the default file."); 6935a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 6945a988416SJim Ingham return false; 6955a988416SJim Ingham } 6965a988416SJim Ingham else if (!cur_frame->HasDebugInformation()) 6975a988416SJim Ingham { 6985a988416SJim Ingham result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info."); 6995a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 7005a988416SJim Ingham return false; 7015a988416SJim Ingham } 7025a988416SJim Ingham else 7035a988416SJim Ingham { 7045a988416SJim Ingham const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry); 7055a988416SJim Ingham if (sc.line_entry.file) 7065a988416SJim Ingham { 7075a988416SJim Ingham file = sc.line_entry.file; 7085a988416SJim Ingham } 7095a988416SJim Ingham else 7105a988416SJim Ingham { 7115a988416SJim Ingham result.AppendError ("Can't find the file for the selected frame to use as the default file."); 7125a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 7135a988416SJim Ingham return false; 7145a988416SJim Ingham } 7155a988416SJim Ingham } 7165a988416SJim Ingham } 7175a988416SJim Ingham return true; 7185a988416SJim Ingham } 7195a988416SJim Ingham 7205a988416SJim Ingham CommandOptions m_options; 7215a988416SJim Ingham }; 722*9e85e5a8SEugene Zelenko 7235a988416SJim Ingham // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to 7245a988416SJim Ingham // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately. 7255a988416SJim Ingham #define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 ) 7265a988416SJim Ingham #define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 ) 7275a988416SJim Ingham #define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) ) 728055ad9beSIlia K #define LLDB_OPT_MOVE_TO_NEAREST_CODE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_9 ) 7290fcdac36SJim Ingham #define LLDB_OPT_EXPR_LANGUAGE ( LLDB_OPT_SET_FROM_TO(3, 8) ) 7305a988416SJim Ingham 7315a988416SJim Ingham OptionDefinition 7325a988416SJim Ingham CommandObjectBreakpointSet::CommandOptions::g_option_table[] = 7335a988416SJim Ingham { 734*9e85e5a8SEugene Zelenko { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, 7355a988416SJim Ingham "Set the breakpoint only in this shared library. " 7365a988416SJim Ingham "Can repeat this option multiple times to specify multiple shared libraries."}, 7375a988416SJim Ingham 738*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, 7395a988416SJim Ingham "Set the number of times this breakpoint is skipped before stopping." }, 7405a988416SJim Ingham 741*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 742b2b256afSJim Ingham "The breakpoint is deleted the first time it causes a stop." }, 743ca36cd16SJim Ingham 744*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, 7455a988416SJim Ingham "The breakpoint stops only if this condition expression evaluates to true."}, 7465a988416SJim Ingham 747*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, 748a89be91fSJim Ingham "The breakpoint stops only for the thread whose indeX matches this argument."}, 7495a988416SJim Ingham 750*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID, 7515a988416SJim Ingham "The breakpoint stops only for the thread whose TID matches this argument."}, 7525a988416SJim Ingham 753*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName, 7545a988416SJim Ingham "The breakpoint stops only for the thread whose thread name matches this argument."}, 7555a988416SJim Ingham 756*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 757eb023e75SGreg Clayton "Require the breakpoint to use hardware breakpoints."}, 758eb023e75SGreg Clayton 759*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName, 7605a988416SJim Ingham "The breakpoint stops only for threads in the queue whose name is given by this argument."}, 7615a988416SJim Ingham 762*9e85e5a8SEugene Zelenko { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, 763289aca64SJim Ingham "Specifies the source file in which to set this breakpoint. " 764289aca64SJim Ingham "Note, by default lldb only looks for files that are #included if they use the standard include file extensions. " 7656394479eSJim Ingham "To set breakpoints on .c/.cpp/.m/.mm files that are #included, set target.inline-breakpoint-strategy" 766289aca64SJim Ingham " to \"always\"."}, 7675a988416SJim Ingham 768*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, 7695a988416SJim Ingham "Specifies the line number on which to set this breakpoint."}, 7705a988416SJim Ingham 7715a988416SJim Ingham // Comment out this option for the moment, as we don't actually use it, but will in the future. 7725a988416SJim Ingham // This way users won't see it, but the infrastructure is left in place. 773*9e85e5a8SEugene Zelenko // { 0, false, "column", 'C', OptionParser::eRequiredArgument, nullptr, "<column>", 7745a988416SJim Ingham // "Set the breakpoint by source location at this particular column."}, 7755a988416SJim Ingham 776*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, 777055a08a4SJim Ingham "Set the breakpoint at the specified address. " 778055a08a4SJim Ingham "If the address maps uniquely to a particular " 779055a08a4SJim Ingham "binary, then the address will be converted to a \"file\" address, so that the breakpoint will track that binary+offset no matter where " 780055a08a4SJim Ingham "the binary eventually loads. " 781055a08a4SJim Ingham "Alternately, if you also specify the module - with the -s option - then the address will be treated as " 782055a08a4SJim Ingham "a file address in that module, and resolved accordingly. Again, this will allow lldb to track that offset on " 783055a08a4SJim Ingham "subsequent reloads. The module need not have been loaded at the time you specify this breakpoint, and will " 784055a08a4SJim Ingham "get resolved when the module is loaded."}, 7855a988416SJim Ingham 786*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, 787551262d7SJim Ingham "Set the breakpoint by function name. Can be repeated multiple times to make one breakpoint for multiple names" }, 7885a988416SJim Ingham 789*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFullName, 7905a988416SJim Ingham "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and " 7915a988416SJim Ingham "for Objective C this means a full function prototype with class and selector. " 7925a988416SJim Ingham "Can be repeated multiple times to make one breakpoint for multiple names." }, 7935a988416SJim Ingham 794*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSelector, 7955a988416SJim Ingham "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." }, 7965a988416SJim Ingham 797*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeMethod, 7985a988416SJim Ingham "Set the breakpoint by C++ method names. Can be repeated multiple times to make one breakpoint for multiple methods." }, 7995a988416SJim Ingham 800*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, 8015a988416SJim Ingham "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." }, 8025a988416SJim Ingham 803*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, 8045a988416SJim Ingham "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). " 8055a988416SJim Ingham "Can be repeated multiple times to make one breakpoint for multiple symbols." }, 8065a988416SJim Ingham 807*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, 808e96ade8bSJim Ingham "Set the breakpoint by specifying a regular expression which is matched against the source text in a source file or files " 809e96ade8bSJim Ingham "specified with the -f option. The -f option can be specified more than once. " 810cc3a4595SJim Ingham "If no source files are specified, uses the current \"default source file\". " 811cc3a4595SJim Ingham "If you want to match against all source files, pass the \"--all-files\" option." }, 8125a988416SJim Ingham 813*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_9, false, "all-files", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 814e732052fSJim Ingham "All files are searched for source pattern matches." }, 815e732052fSJim Ingham 816*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, 8175a988416SJim Ingham "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" }, 8185a988416SJim Ingham 819*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, 820b4a5aa23SJim Ingham "Set the breakpoint on exception throW." }, 8215a988416SJim Ingham 822*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, 823b4a5aa23SJim Ingham "Set the breakpoint on exception catcH." }, 8245a988416SJim Ingham 825a72b31c7SJim Ingham // Don't add this option till it actually does something useful... 826*9e85e5a8SEugene Zelenko // { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName, 827a72b31c7SJim 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" }, 828a72b31c7SJim Ingham 829*9e85e5a8SEugene Zelenko { LLDB_OPT_EXPR_LANGUAGE, false, "language", 'L', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, 8304112ab98SDawn Perchik "Specifies the Language to use when interpreting the breakpoint's expression (note: currently only implemented for setting breakpoints on identifiers). If not set the target.language setting is used." }, 83123b1decbSDawn Perchik 832*9e85e5a8SEugene Zelenko { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, 8335a988416SJim Ingham "sKip the prologue if the breakpoint is at the beginning of a function. If not set the target.skip-prologue setting is used." }, 8345a988416SJim Ingham 835*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 83633df7cd3SJim Ingham "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, 83733df7cd3SJim Ingham 838*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, 8395e09c8c3SJim Ingham "Adds this to the list of names for this breakopint."}, 8405e09c8c3SJim Ingham 841*9e85e5a8SEugene Zelenko { LLDB_OPT_MOVE_TO_NEAREST_CODE, false, "move-to-nearest-code", 'm', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, 842055ad9beSIlia K "Move breakpoints to nearest code. If not set the target.move-to-nearest-code setting is used." }, 843055ad9beSIlia K 844*9e85e5a8SEugene Zelenko { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } 8455a988416SJim Ingham }; 8465a988416SJim Ingham 8475a988416SJim Ingham //------------------------------------------------------------------------- 8485a988416SJim Ingham // CommandObjectBreakpointModify 8495a988416SJim Ingham //------------------------------------------------------------------------- 8505a988416SJim Ingham #pragma mark Modify 8515a988416SJim Ingham 8525a988416SJim Ingham class CommandObjectBreakpointModify : public CommandObjectParsed 8535a988416SJim Ingham { 8545a988416SJim Ingham public: 8555a988416SJim Ingham CommandObjectBreakpointModify (CommandInterpreter &interpreter) : 8565a988416SJim Ingham CommandObjectParsed(interpreter, 8575a988416SJim Ingham "breakpoint modify", 8585a988416SJim Ingham "Modify the options on a breakpoint or set of breakpoints in the executable. " 8595a988416SJim Ingham "If no breakpoint is specified, acts on the last created breakpoint. " 8605a988416SJim Ingham "With the exception of -e, -d and -i, passing an empty argument clears the modification.", 861*9e85e5a8SEugene Zelenko nullptr), 8625a988416SJim Ingham m_options (interpreter) 8635a988416SJim Ingham { 8645a988416SJim Ingham CommandArgumentEntry arg; 8655a988416SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 8665a988416SJim Ingham // Add the entry for the first argument for this command to the object's arguments vector. 8675a988416SJim Ingham m_arguments.push_back (arg); 8685a988416SJim Ingham } 8695a988416SJim Ingham 870*9e85e5a8SEugene Zelenko ~CommandObjectBreakpointModify() override = default; 8715a988416SJim Ingham 87213d21e9aSBruce Mitchener Options * 87313d21e9aSBruce Mitchener GetOptions () override 8745a988416SJim Ingham { 8755a988416SJim Ingham return &m_options; 8765a988416SJim Ingham } 8775a988416SJim Ingham 8785a988416SJim Ingham class CommandOptions : public Options 8795a988416SJim Ingham { 8805a988416SJim Ingham public: 8815a988416SJim Ingham CommandOptions (CommandInterpreter &interpreter) : 8825a988416SJim Ingham Options (interpreter), 8835a988416SJim Ingham m_ignore_count (0), 8845a988416SJim Ingham m_thread_id(LLDB_INVALID_THREAD_ID), 8855a988416SJim Ingham m_thread_id_passed(false), 8865a988416SJim Ingham m_thread_index (UINT32_MAX), 8875a988416SJim Ingham m_thread_index_passed(false), 8885a988416SJim Ingham m_thread_name(), 8895a988416SJim Ingham m_queue_name(), 8905a988416SJim Ingham m_condition (), 891ca36cd16SJim Ingham m_one_shot (false), 8925a988416SJim Ingham m_enable_passed (false), 8935a988416SJim Ingham m_enable_value (false), 8945a988416SJim Ingham m_name_passed (false), 8955a988416SJim Ingham m_queue_passed (false), 896ca36cd16SJim Ingham m_condition_passed (false), 89733df7cd3SJim Ingham m_one_shot_passed (false), 89833df7cd3SJim Ingham m_use_dummy (false) 8995a988416SJim Ingham { 9005a988416SJim Ingham } 9015a988416SJim Ingham 902*9e85e5a8SEugene Zelenko ~CommandOptions() override = default; 9035a988416SJim Ingham 90413d21e9aSBruce Mitchener Error 90513d21e9aSBruce Mitchener SetOptionValue (uint32_t option_idx, const char *option_arg) override 9065a988416SJim Ingham { 9075a988416SJim Ingham Error error; 9083bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 9095a988416SJim Ingham 9105a988416SJim Ingham switch (short_option) 9115a988416SJim Ingham { 9125a988416SJim Ingham case 'c': 913*9e85e5a8SEugene Zelenko if (option_arg != nullptr) 9145a988416SJim Ingham m_condition.assign (option_arg); 9155a988416SJim Ingham else 9165a988416SJim Ingham m_condition.clear(); 9175a988416SJim Ingham m_condition_passed = true; 9185a988416SJim Ingham break; 9195a988416SJim Ingham case 'd': 9205a988416SJim Ingham m_enable_passed = true; 9215a988416SJim Ingham m_enable_value = false; 9225a988416SJim Ingham break; 92333df7cd3SJim Ingham case 'D': 92433df7cd3SJim Ingham m_use_dummy = true; 92533df7cd3SJim Ingham break; 9265a988416SJim Ingham case 'e': 9275a988416SJim Ingham m_enable_passed = true; 9285a988416SJim Ingham m_enable_value = true; 9295a988416SJim Ingham break; 9305a988416SJim Ingham case 'i': 9315275aaa0SVince Harron m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); 9325a988416SJim Ingham if (m_ignore_count == UINT32_MAX) 9335a988416SJim Ingham error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); 9345a988416SJim Ingham break; 935ca36cd16SJim Ingham case 'o': 936ca36cd16SJim Ingham { 937ca36cd16SJim Ingham bool value, success; 938ca36cd16SJim Ingham value = Args::StringToBoolean(option_arg, false, &success); 939ca36cd16SJim Ingham if (success) 940ca36cd16SJim Ingham { 941ca36cd16SJim Ingham m_one_shot_passed = true; 942ca36cd16SJim Ingham m_one_shot = value; 943ca36cd16SJim Ingham } 944ca36cd16SJim Ingham else 945ca36cd16SJim Ingham error.SetErrorStringWithFormat("invalid boolean value '%s' passed for -o option", option_arg); 946ca36cd16SJim Ingham } 947ca36cd16SJim Ingham break; 9485a988416SJim Ingham case 't' : 9495a988416SJim Ingham if (option_arg[0] == '\0') 9505a988416SJim Ingham { 9515a988416SJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 9525a988416SJim Ingham m_thread_id_passed = true; 9535a988416SJim Ingham } 9545a988416SJim Ingham else 9555a988416SJim Ingham { 9565275aaa0SVince Harron m_thread_id = StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 9575a988416SJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 9585a988416SJim Ingham error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); 9595a988416SJim Ingham else 9605a988416SJim Ingham m_thread_id_passed = true; 9615a988416SJim Ingham } 9625a988416SJim Ingham break; 9635a988416SJim Ingham case 'T': 964*9e85e5a8SEugene Zelenko if (option_arg != nullptr) 9655a988416SJim Ingham m_thread_name.assign (option_arg); 9665a988416SJim Ingham else 9675a988416SJim Ingham m_thread_name.clear(); 9685a988416SJim Ingham m_name_passed = true; 9695a988416SJim Ingham break; 9705a988416SJim Ingham case 'q': 971*9e85e5a8SEugene Zelenko if (option_arg != nullptr) 9725a988416SJim Ingham m_queue_name.assign (option_arg); 9735a988416SJim Ingham else 9745a988416SJim Ingham m_queue_name.clear(); 9755a988416SJim Ingham m_queue_passed = true; 9765a988416SJim Ingham break; 9775a988416SJim Ingham case 'x': 9785a988416SJim Ingham if (option_arg[0] == '\n') 9795a988416SJim Ingham { 9805a988416SJim Ingham m_thread_index = UINT32_MAX; 9815a988416SJim Ingham m_thread_index_passed = true; 9825a988416SJim Ingham } 9835a988416SJim Ingham else 9845a988416SJim Ingham { 9855275aaa0SVince Harron m_thread_index = StringConvert::ToUInt32 (option_arg, UINT32_MAX, 0); 9865a988416SJim Ingham if (m_thread_id == UINT32_MAX) 9875a988416SJim Ingham error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); 9885a988416SJim Ingham else 9895a988416SJim Ingham m_thread_index_passed = true; 9905a988416SJim Ingham } 9915a988416SJim Ingham break; 9925a988416SJim Ingham default: 9935a988416SJim Ingham error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 9945a988416SJim Ingham break; 9955a988416SJim Ingham } 9965a988416SJim Ingham 9975a988416SJim Ingham return error; 9985a988416SJim Ingham } 999*9e85e5a8SEugene Zelenko 10005a988416SJim Ingham void 100113d21e9aSBruce Mitchener OptionParsingStarting () override 10025a988416SJim Ingham { 10035a988416SJim Ingham m_ignore_count = 0; 10045a988416SJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 10055a988416SJim Ingham m_thread_id_passed = false; 10065a988416SJim Ingham m_thread_index = UINT32_MAX; 10075a988416SJim Ingham m_thread_index_passed = false; 10085a988416SJim Ingham m_thread_name.clear(); 10095a988416SJim Ingham m_queue_name.clear(); 10105a988416SJim Ingham m_condition.clear(); 1011ca36cd16SJim Ingham m_one_shot = false; 10125a988416SJim Ingham m_enable_passed = false; 10135a988416SJim Ingham m_queue_passed = false; 10145a988416SJim Ingham m_name_passed = false; 10155a988416SJim Ingham m_condition_passed = false; 1016ca36cd16SJim Ingham m_one_shot_passed = false; 101733df7cd3SJim Ingham m_use_dummy = false; 10185a988416SJim Ingham } 10195a988416SJim Ingham 10205a988416SJim Ingham const OptionDefinition* 102113d21e9aSBruce Mitchener GetDefinitions () override 10225a988416SJim Ingham { 10235a988416SJim Ingham return g_option_table; 10245a988416SJim Ingham } 10255a988416SJim Ingham 10265a988416SJim Ingham // Options table: Required for subclasses of Options. 10275a988416SJim Ingham 10285a988416SJim Ingham static OptionDefinition g_option_table[]; 10295a988416SJim Ingham 10305a988416SJim Ingham // Instance variables to hold the values for command options. 10315a988416SJim Ingham 10325a988416SJim Ingham uint32_t m_ignore_count; 10335a988416SJim Ingham lldb::tid_t m_thread_id; 10345a988416SJim Ingham bool m_thread_id_passed; 10355a988416SJim Ingham uint32_t m_thread_index; 10365a988416SJim Ingham bool m_thread_index_passed; 10375a988416SJim Ingham std::string m_thread_name; 10385a988416SJim Ingham std::string m_queue_name; 10395a988416SJim Ingham std::string m_condition; 1040ca36cd16SJim Ingham bool m_one_shot; 10415a988416SJim Ingham bool m_enable_passed; 10425a988416SJim Ingham bool m_enable_value; 10435a988416SJim Ingham bool m_name_passed; 10445a988416SJim Ingham bool m_queue_passed; 10455a988416SJim Ingham bool m_condition_passed; 1046ca36cd16SJim Ingham bool m_one_shot_passed; 104733df7cd3SJim Ingham bool m_use_dummy; 10485a988416SJim Ingham }; 10495a988416SJim Ingham 10505a988416SJim Ingham protected: 105113d21e9aSBruce Mitchener bool 105213d21e9aSBruce Mitchener DoExecute (Args& command, CommandReturnObject &result) override 10535a988416SJim Ingham { 105433df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 1055*9e85e5a8SEugene Zelenko if (target == nullptr) 10565a988416SJim Ingham { 10575a988416SJim Ingham result.AppendError ("Invalid target. No existing target or breakpoints."); 10585a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 10595a988416SJim Ingham return false; 10605a988416SJim Ingham } 10615a988416SJim Ingham 10625a988416SJim Ingham Mutex::Locker locker; 10635a988416SJim Ingham target->GetBreakpointList().GetListMutex(locker); 10645a988416SJim Ingham 10655a988416SJim Ingham BreakpointIDList valid_bp_ids; 10665a988416SJim Ingham 10675e09c8c3SJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); 10685a988416SJim Ingham 10695a988416SJim Ingham if (result.Succeeded()) 10705a988416SJim Ingham { 10715a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 10725a988416SJim Ingham for (size_t i = 0; i < count; ++i) 10735a988416SJim Ingham { 10745a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 10755a988416SJim Ingham 10765a988416SJim Ingham if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 10775a988416SJim Ingham { 10785a988416SJim Ingham Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 10795a988416SJim Ingham if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 10805a988416SJim Ingham { 10815a988416SJim Ingham BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get(); 10825a988416SJim Ingham if (location) 10835a988416SJim Ingham { 10845a988416SJim Ingham if (m_options.m_thread_id_passed) 10855a988416SJim Ingham location->SetThreadID (m_options.m_thread_id); 10865a988416SJim Ingham 10875a988416SJim Ingham if (m_options.m_thread_index_passed) 10885a988416SJim Ingham location->SetThreadIndex(m_options.m_thread_index); 10895a988416SJim Ingham 10905a988416SJim Ingham if (m_options.m_name_passed) 10915a988416SJim Ingham location->SetThreadName(m_options.m_thread_name.c_str()); 10925a988416SJim Ingham 10935a988416SJim Ingham if (m_options.m_queue_passed) 10945a988416SJim Ingham location->SetQueueName(m_options.m_queue_name.c_str()); 10955a988416SJim Ingham 10965a988416SJim Ingham if (m_options.m_ignore_count != 0) 10975a988416SJim Ingham location->SetIgnoreCount(m_options.m_ignore_count); 10985a988416SJim Ingham 10995a988416SJim Ingham if (m_options.m_enable_passed) 11005a988416SJim Ingham location->SetEnabled (m_options.m_enable_value); 11015a988416SJim Ingham 11025a988416SJim Ingham if (m_options.m_condition_passed) 11035a988416SJim Ingham location->SetCondition (m_options.m_condition.c_str()); 11045a988416SJim Ingham } 11055a988416SJim Ingham } 11065a988416SJim Ingham else 11075a988416SJim Ingham { 11085a988416SJim Ingham if (m_options.m_thread_id_passed) 11095a988416SJim Ingham bp->SetThreadID (m_options.m_thread_id); 11105a988416SJim Ingham 11115a988416SJim Ingham if (m_options.m_thread_index_passed) 11125a988416SJim Ingham bp->SetThreadIndex(m_options.m_thread_index); 11135a988416SJim Ingham 11145a988416SJim Ingham if (m_options.m_name_passed) 11155a988416SJim Ingham bp->SetThreadName(m_options.m_thread_name.c_str()); 11165a988416SJim Ingham 11175a988416SJim Ingham if (m_options.m_queue_passed) 11185a988416SJim Ingham bp->SetQueueName(m_options.m_queue_name.c_str()); 11195a988416SJim Ingham 11205a988416SJim Ingham if (m_options.m_ignore_count != 0) 11215a988416SJim Ingham bp->SetIgnoreCount(m_options.m_ignore_count); 11225a988416SJim Ingham 11235a988416SJim Ingham if (m_options.m_enable_passed) 11245a988416SJim Ingham bp->SetEnabled (m_options.m_enable_value); 11255a988416SJim Ingham 11265a988416SJim Ingham if (m_options.m_condition_passed) 11275a988416SJim Ingham bp->SetCondition (m_options.m_condition.c_str()); 11285a988416SJim Ingham } 11295a988416SJim Ingham } 11305a988416SJim Ingham } 11315a988416SJim Ingham } 11325a988416SJim Ingham 11335a988416SJim Ingham return result.Succeeded(); 11345a988416SJim Ingham } 11355a988416SJim Ingham 11365a988416SJim Ingham private: 11375a988416SJim Ingham CommandOptions m_options; 11385a988416SJim Ingham }; 11395a988416SJim Ingham 11405a988416SJim Ingham #pragma mark Modify::CommandOptions 11415a988416SJim Ingham OptionDefinition 11425a988416SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] = 11435a988416SJim Ingham { 1144*9e85e5a8SEugene 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." }, 1145*9e85e5a8SEugene 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." }, 1146*9e85e5a8SEugene 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."}, 1147*9e85e5a8SEugene 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."}, 1148*9e85e5a8SEugene 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."}, 1149*9e85e5a8SEugene 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."}, 1150*9e85e5a8SEugene 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."}, 1151*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_1, false, "enable", 'e', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable the breakpoint."}, 1152*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_2, false, "disable", 'd', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Disable the breakpoint."}, 1153*9e85e5a8SEugene 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."}, 115433df7cd3SJim Ingham 1155*9e85e5a8SEugene Zelenko { 0, false, nullptr, 0 , 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } 11565a988416SJim Ingham }; 11575a988416SJim Ingham 11585a988416SJim Ingham //------------------------------------------------------------------------- 11595a988416SJim Ingham // CommandObjectBreakpointEnable 11605a988416SJim Ingham //------------------------------------------------------------------------- 11615a988416SJim Ingham #pragma mark Enable 11625a988416SJim Ingham 11635a988416SJim Ingham class CommandObjectBreakpointEnable : public CommandObjectParsed 11645a988416SJim Ingham { 11655a988416SJim Ingham public: 11665a988416SJim Ingham CommandObjectBreakpointEnable (CommandInterpreter &interpreter) : 11675a988416SJim Ingham CommandObjectParsed(interpreter, 11685a988416SJim Ingham "enable", 11695a988416SJim Ingham "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.", 1170*9e85e5a8SEugene Zelenko nullptr) 11715a988416SJim Ingham { 11725a988416SJim Ingham CommandArgumentEntry arg; 11735a988416SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 11745a988416SJim Ingham // Add the entry for the first argument for this command to the object's arguments vector. 11755a988416SJim Ingham m_arguments.push_back (arg); 11765a988416SJim Ingham } 11775a988416SJim Ingham 1178*9e85e5a8SEugene Zelenko ~CommandObjectBreakpointEnable() override = default; 11795a988416SJim Ingham 11805a988416SJim Ingham protected: 118113d21e9aSBruce Mitchener bool 118213d21e9aSBruce Mitchener DoExecute (Args& command, CommandReturnObject &result) override 11835a988416SJim Ingham { 1184893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1185*9e85e5a8SEugene Zelenko if (target == nullptr) 11865a988416SJim Ingham { 11875a988416SJim Ingham result.AppendError ("Invalid target. No existing target or breakpoints."); 11885a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 11895a988416SJim Ingham return false; 11905a988416SJim Ingham } 11915a988416SJim Ingham 11925a988416SJim Ingham Mutex::Locker locker; 11935a988416SJim Ingham target->GetBreakpointList().GetListMutex(locker); 11945a988416SJim Ingham 11955a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 11965a988416SJim Ingham 11975a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 11985a988416SJim Ingham 11995a988416SJim Ingham if (num_breakpoints == 0) 12005a988416SJim Ingham { 12015a988416SJim Ingham result.AppendError ("No breakpoints exist to be enabled."); 12025a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 12035a988416SJim Ingham return false; 12045a988416SJim Ingham } 12055a988416SJim Ingham 12065a988416SJim Ingham if (command.GetArgumentCount() == 0) 12075a988416SJim Ingham { 12085a988416SJim Ingham // No breakpoint selected; enable all currently set breakpoints. 12095a988416SJim Ingham target->EnableAllBreakpoints (); 12106fea17e8SGreg Clayton result.AppendMessageWithFormat ("All breakpoints enabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints); 12115a988416SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 12125a988416SJim Ingham } 12135a988416SJim Ingham else 12145a988416SJim Ingham { 12155a988416SJim Ingham // Particular breakpoint selected; enable that breakpoint. 12165a988416SJim Ingham BreakpointIDList valid_bp_ids; 12175e09c8c3SJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); 12185a988416SJim Ingham 12195a988416SJim Ingham if (result.Succeeded()) 12205a988416SJim Ingham { 12215a988416SJim Ingham int enable_count = 0; 12225a988416SJim Ingham int loc_count = 0; 12235a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 12245a988416SJim Ingham for (size_t i = 0; i < count; ++i) 12255a988416SJim Ingham { 12265a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 12275a988416SJim Ingham 12285a988416SJim Ingham if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 12295a988416SJim Ingham { 12305a988416SJim Ingham Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 12315a988416SJim Ingham if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 12325a988416SJim Ingham { 12335a988416SJim Ingham BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 12345a988416SJim Ingham if (location) 12355a988416SJim Ingham { 12365a988416SJim Ingham location->SetEnabled (true); 12375a988416SJim Ingham ++loc_count; 12385a988416SJim Ingham } 12395a988416SJim Ingham } 12405a988416SJim Ingham else 12415a988416SJim Ingham { 12425a988416SJim Ingham breakpoint->SetEnabled (true); 12435a988416SJim Ingham ++enable_count; 12445a988416SJim Ingham } 12455a988416SJim Ingham } 12465a988416SJim Ingham } 12475a988416SJim Ingham result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count); 12485a988416SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 12495a988416SJim Ingham } 12505a988416SJim Ingham } 12515a988416SJim Ingham 12525a988416SJim Ingham return result.Succeeded(); 12535a988416SJim Ingham } 12545a988416SJim Ingham }; 12555a988416SJim Ingham 12565a988416SJim Ingham //------------------------------------------------------------------------- 12575a988416SJim Ingham // CommandObjectBreakpointDisable 12585a988416SJim Ingham //------------------------------------------------------------------------- 12595a988416SJim Ingham #pragma mark Disable 12605a988416SJim Ingham 12615a988416SJim Ingham class CommandObjectBreakpointDisable : public CommandObjectParsed 12625a988416SJim Ingham { 12635a988416SJim Ingham public: 12645a988416SJim Ingham CommandObjectBreakpointDisable (CommandInterpreter &interpreter) : 12655a988416SJim Ingham CommandObjectParsed(interpreter, 12665a988416SJim Ingham "breakpoint disable", 1267ea671fbdSKate Stone "Disable the specified breakpoint(s) without removing them. If none are specified, disable all breakpoints.", 1268*9e85e5a8SEugene Zelenko nullptr) 12695a988416SJim Ingham { 1270b0fac509SJim Ingham SetHelpLong( 1271ea671fbdSKate Stone "Disable the specified breakpoint(s) without removing them. \ 1272ea671fbdSKate Stone If none are specified, disable all breakpoints." R"( 1273ea671fbdSKate Stone 1274ea671fbdSKate Stone )" "Note: disabling a breakpoint will cause none of its locations to be hit \ 1275ea671fbdSKate Stone regardless of whether they are enabled or disabled. After the sequence:" R"( 1276ea671fbdSKate Stone 1277ea671fbdSKate Stone (lldb) break disable 1 1278ea671fbdSKate Stone (lldb) break enable 1.1 1279ea671fbdSKate Stone 1280ea671fbdSKate Stone execution will NOT stop at location 1.1. To achieve that, type: 1281ea671fbdSKate Stone 1282ea671fbdSKate Stone (lldb) break disable 1.* 1283ea671fbdSKate Stone (lldb) break enable 1.1 1284ea671fbdSKate Stone 1285ea671fbdSKate Stone )" "The first command disables all the locations of breakpoint 1, \ 1286b0fac509SJim Ingham the second re-enables the first location." 1287b0fac509SJim Ingham ); 1288b0fac509SJim Ingham 12895a988416SJim Ingham CommandArgumentEntry arg; 12905a988416SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 12915a988416SJim Ingham // Add the entry for the first argument for this command to the object's arguments vector. 12925a988416SJim Ingham m_arguments.push_back (arg); 12935a988416SJim Ingham } 12945a988416SJim Ingham 1295*9e85e5a8SEugene Zelenko ~CommandObjectBreakpointDisable() override = default; 12965a988416SJim Ingham 12975a988416SJim Ingham protected: 129813d21e9aSBruce Mitchener bool 129913d21e9aSBruce Mitchener DoExecute (Args& command, CommandReturnObject &result) override 13005a988416SJim Ingham { 1301893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1302*9e85e5a8SEugene Zelenko if (target == nullptr) 13035a988416SJim Ingham { 13045a988416SJim Ingham result.AppendError ("Invalid target. No existing target or breakpoints."); 13055a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 13065a988416SJim Ingham return false; 13075a988416SJim Ingham } 13085a988416SJim Ingham 13095a988416SJim Ingham Mutex::Locker locker; 13105a988416SJim Ingham target->GetBreakpointList().GetListMutex(locker); 13115a988416SJim Ingham 13125a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 13135a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 13145a988416SJim Ingham 13155a988416SJim Ingham if (num_breakpoints == 0) 13165a988416SJim Ingham { 13175a988416SJim Ingham result.AppendError ("No breakpoints exist to be disabled."); 13185a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 13195a988416SJim Ingham return false; 13205a988416SJim Ingham } 13215a988416SJim Ingham 13225a988416SJim Ingham if (command.GetArgumentCount() == 0) 13235a988416SJim Ingham { 13245a988416SJim Ingham // No breakpoint selected; disable all currently set breakpoints. 13255a988416SJim Ingham target->DisableAllBreakpoints (); 13266fea17e8SGreg Clayton result.AppendMessageWithFormat ("All breakpoints disabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints); 13275a988416SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 13285a988416SJim Ingham } 13295a988416SJim Ingham else 13305a988416SJim Ingham { 13315a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 13325a988416SJim Ingham BreakpointIDList valid_bp_ids; 13335a988416SJim Ingham 13345e09c8c3SJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); 13355a988416SJim Ingham 13365a988416SJim Ingham if (result.Succeeded()) 13375a988416SJim Ingham { 13385a988416SJim Ingham int disable_count = 0; 13395a988416SJim Ingham int loc_count = 0; 13405a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 13415a988416SJim Ingham for (size_t i = 0; i < count; ++i) 13425a988416SJim Ingham { 13435a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 13445a988416SJim Ingham 13455a988416SJim Ingham if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 13465a988416SJim Ingham { 13475a988416SJim Ingham Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 13485a988416SJim Ingham if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 13495a988416SJim Ingham { 13505a988416SJim Ingham BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 13515a988416SJim Ingham if (location) 13525a988416SJim Ingham { 13535a988416SJim Ingham location->SetEnabled (false); 13545a988416SJim Ingham ++loc_count; 13555a988416SJim Ingham } 13565a988416SJim Ingham } 13575a988416SJim Ingham else 13585a988416SJim Ingham { 13595a988416SJim Ingham breakpoint->SetEnabled (false); 13605a988416SJim Ingham ++disable_count; 13615a988416SJim Ingham } 13625a988416SJim Ingham } 13635a988416SJim Ingham } 13645a988416SJim Ingham result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count); 13655a988416SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 13665a988416SJim Ingham } 13675a988416SJim Ingham } 13685a988416SJim Ingham 13695a988416SJim Ingham return result.Succeeded(); 13705a988416SJim Ingham } 13715a988416SJim Ingham }; 13725a988416SJim Ingham 13735a988416SJim Ingham //------------------------------------------------------------------------- 13745a988416SJim Ingham // CommandObjectBreakpointList 13755a988416SJim Ingham //------------------------------------------------------------------------- 13765a988416SJim Ingham #pragma mark List 13775a988416SJim Ingham 13785a988416SJim Ingham class CommandObjectBreakpointList : public CommandObjectParsed 13795a988416SJim Ingham { 13805a988416SJim Ingham public: 13815a988416SJim Ingham CommandObjectBreakpointList (CommandInterpreter &interpreter) : 13825a988416SJim Ingham CommandObjectParsed(interpreter, 13835a988416SJim Ingham "breakpoint list", 13845a988416SJim Ingham "List some or all breakpoints at configurable levels of detail.", 1385*9e85e5a8SEugene Zelenko nullptr), 13865a988416SJim Ingham m_options (interpreter) 13875a988416SJim Ingham { 13885a988416SJim Ingham CommandArgumentEntry arg; 13895a988416SJim Ingham CommandArgumentData bp_id_arg; 13905a988416SJim Ingham 13915a988416SJim Ingham // Define the first (and only) variant of this arg. 13925a988416SJim Ingham bp_id_arg.arg_type = eArgTypeBreakpointID; 13935a988416SJim Ingham bp_id_arg.arg_repetition = eArgRepeatOptional; 13945a988416SJim Ingham 13955a988416SJim Ingham // There is only one variant this argument could be; put it into the argument entry. 13965a988416SJim Ingham arg.push_back (bp_id_arg); 13975a988416SJim Ingham 13985a988416SJim Ingham // Push the data for the first argument into the m_arguments vector. 13995a988416SJim Ingham m_arguments.push_back (arg); 14005a988416SJim Ingham } 14015a988416SJim Ingham 1402*9e85e5a8SEugene Zelenko ~CommandObjectBreakpointList() override = default; 14035a988416SJim Ingham 140413d21e9aSBruce Mitchener Options * 140513d21e9aSBruce Mitchener GetOptions () override 14065a988416SJim Ingham { 14075a988416SJim Ingham return &m_options; 14085a988416SJim Ingham } 14095a988416SJim Ingham 14105a988416SJim Ingham class CommandOptions : public Options 14115a988416SJim Ingham { 14125a988416SJim Ingham public: 14135a988416SJim Ingham CommandOptions (CommandInterpreter &interpreter) : 14145a988416SJim Ingham Options (interpreter), 141533df7cd3SJim Ingham m_level (lldb::eDescriptionLevelBrief), 141633df7cd3SJim Ingham m_use_dummy(false) 14175a988416SJim Ingham { 14185a988416SJim Ingham } 14195a988416SJim Ingham 1420*9e85e5a8SEugene Zelenko ~CommandOptions() override = default; 14215a988416SJim Ingham 142213d21e9aSBruce Mitchener Error 142313d21e9aSBruce Mitchener SetOptionValue (uint32_t option_idx, const char *option_arg) override 14245a988416SJim Ingham { 14255a988416SJim Ingham Error error; 14263bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 14275a988416SJim Ingham 14285a988416SJim Ingham switch (short_option) 14295a988416SJim Ingham { 14305a988416SJim Ingham case 'b': 14315a988416SJim Ingham m_level = lldb::eDescriptionLevelBrief; 14325a988416SJim Ingham break; 143333df7cd3SJim Ingham case 'D': 143433df7cd3SJim Ingham m_use_dummy = true; 143533df7cd3SJim Ingham break; 14365a988416SJim Ingham case 'f': 14375a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 14385a988416SJim Ingham break; 14395a988416SJim Ingham case 'v': 14405a988416SJim Ingham m_level = lldb::eDescriptionLevelVerbose; 14415a988416SJim Ingham break; 14425a988416SJim Ingham case 'i': 14435a988416SJim Ingham m_internal = true; 14445a988416SJim Ingham break; 14455a988416SJim Ingham default: 14465a988416SJim Ingham error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 14475a988416SJim Ingham break; 14485a988416SJim Ingham } 14495a988416SJim Ingham 14505a988416SJim Ingham return error; 14515a988416SJim Ingham } 14525a988416SJim Ingham 14535a988416SJim Ingham void 145413d21e9aSBruce Mitchener OptionParsingStarting () override 14555a988416SJim Ingham { 14565a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 14575a988416SJim Ingham m_internal = false; 145833df7cd3SJim Ingham m_use_dummy = false; 14595a988416SJim Ingham } 14605a988416SJim Ingham 14615a988416SJim Ingham const OptionDefinition * 146213d21e9aSBruce Mitchener GetDefinitions () override 14635a988416SJim Ingham { 14645a988416SJim Ingham return g_option_table; 14655a988416SJim Ingham } 14665a988416SJim Ingham 14675a988416SJim Ingham // Options table: Required for subclasses of Options. 14685a988416SJim Ingham 14695a988416SJim Ingham static OptionDefinition g_option_table[]; 14705a988416SJim Ingham 14715a988416SJim Ingham // Instance variables to hold the values for command options. 14725a988416SJim Ingham 14735a988416SJim Ingham lldb::DescriptionLevel m_level; 14745a988416SJim Ingham 14755a988416SJim Ingham bool m_internal; 147633df7cd3SJim Ingham bool m_use_dummy; 14775a988416SJim Ingham }; 14785a988416SJim Ingham 14795a988416SJim Ingham protected: 148013d21e9aSBruce Mitchener bool 148113d21e9aSBruce Mitchener DoExecute (Args& command, CommandReturnObject &result) override 14825a988416SJim Ingham { 148333df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 148433df7cd3SJim Ingham 1485*9e85e5a8SEugene Zelenko if (target == nullptr) 14865a988416SJim Ingham { 14875a988416SJim Ingham result.AppendError ("Invalid target. No current target or breakpoints."); 14885a988416SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 14895a988416SJim Ingham return true; 14905a988416SJim Ingham } 14915a988416SJim Ingham 14925a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal); 14935a988416SJim Ingham Mutex::Locker locker; 14945a988416SJim Ingham target->GetBreakpointList(m_options.m_internal).GetListMutex(locker); 14955a988416SJim Ingham 14965a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 14975a988416SJim Ingham 14985a988416SJim Ingham if (num_breakpoints == 0) 14995a988416SJim Ingham { 15005a988416SJim Ingham result.AppendMessage ("No breakpoints currently set."); 15015a988416SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 15025a988416SJim Ingham return true; 15035a988416SJim Ingham } 15045a988416SJim Ingham 15055a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 15065a988416SJim Ingham 15075a988416SJim Ingham if (command.GetArgumentCount() == 0) 15085a988416SJim Ingham { 15095a988416SJim Ingham // No breakpoint selected; show info about all currently set breakpoints. 15105a988416SJim Ingham result.AppendMessage ("Current breakpoints:"); 15115a988416SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) 15125a988416SJim Ingham { 15135a988416SJim Ingham Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get(); 15145a988416SJim Ingham AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 15155a988416SJim Ingham } 15165a988416SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 15175a988416SJim Ingham } 15185a988416SJim Ingham else 15195a988416SJim Ingham { 15205a988416SJim Ingham // Particular breakpoints selected; show info about that breakpoint. 15215a988416SJim Ingham BreakpointIDList valid_bp_ids; 15225e09c8c3SJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); 15235a988416SJim Ingham 15245a988416SJim Ingham if (result.Succeeded()) 15255a988416SJim Ingham { 15265a988416SJim Ingham for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) 15275a988416SJim Ingham { 15285a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 15295a988416SJim Ingham Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 15305a988416SJim Ingham AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); 15315a988416SJim Ingham } 15325a988416SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 15335a988416SJim Ingham } 15345a988416SJim Ingham else 15355a988416SJim Ingham { 15365a988416SJim Ingham result.AppendError ("Invalid breakpoint id."); 15375a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 15385a988416SJim Ingham } 15395a988416SJim Ingham } 15405a988416SJim Ingham 15415a988416SJim Ingham return result.Succeeded(); 15425a988416SJim Ingham } 15435a988416SJim Ingham 15445a988416SJim Ingham private: 15455a988416SJim Ingham CommandOptions m_options; 15465a988416SJim Ingham }; 15475a988416SJim Ingham 15485a988416SJim Ingham #pragma mark List::CommandOptions 15495a988416SJim Ingham OptionDefinition 15505a988416SJim Ingham CommandObjectBreakpointList::CommandOptions::g_option_table[] = 15515a988416SJim Ingham { 1552*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 15535a988416SJim Ingham "Show debugger internal breakpoints" }, 15545a988416SJim Ingham 1555*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 15565a988416SJim Ingham "Give a brief description of the breakpoint (no location info)."}, 15575a988416SJim Ingham 15585a988416SJim Ingham // FIXME: We need to add an "internal" command, and then add this sort of thing to it. 15595a988416SJim Ingham // But I need to see it for now, and don't want to wait. 1560*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 15615a988416SJim Ingham "Give a full description of the breakpoint and its locations."}, 15625a988416SJim Ingham 1563*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 15645a988416SJim Ingham "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, 15655a988416SJim Ingham 1566*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 156733df7cd3SJim Ingham "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, 156833df7cd3SJim Ingham 1569*9e85e5a8SEugene Zelenko { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } 15705a988416SJim Ingham }; 15715a988416SJim Ingham 15725a988416SJim Ingham //------------------------------------------------------------------------- 15735a988416SJim Ingham // CommandObjectBreakpointClear 15745a988416SJim Ingham //------------------------------------------------------------------------- 15755a988416SJim Ingham #pragma mark Clear 15765a988416SJim Ingham 15775a988416SJim Ingham class CommandObjectBreakpointClear : public CommandObjectParsed 15785a988416SJim Ingham { 15795a988416SJim Ingham public: 15805a988416SJim Ingham typedef enum BreakpointClearType 15815a988416SJim Ingham { 15825a988416SJim Ingham eClearTypeInvalid, 15835a988416SJim Ingham eClearTypeFileAndLine 15845a988416SJim Ingham } BreakpointClearType; 15855a988416SJim Ingham 15865a988416SJim Ingham CommandObjectBreakpointClear (CommandInterpreter &interpreter) : 15875a988416SJim Ingham CommandObjectParsed (interpreter, 15885a988416SJim Ingham "breakpoint clear", 15895a988416SJim Ingham "Clears a breakpoint or set of breakpoints in the executable.", 15905a988416SJim Ingham "breakpoint clear <cmd-options>"), 15915a988416SJim Ingham m_options (interpreter) 15925a988416SJim Ingham { 15935a988416SJim Ingham } 15945a988416SJim Ingham 1595*9e85e5a8SEugene Zelenko ~CommandObjectBreakpointClear() override = default; 15965a988416SJim Ingham 159713d21e9aSBruce Mitchener Options * 159813d21e9aSBruce Mitchener GetOptions () override 15995a988416SJim Ingham { 16005a988416SJim Ingham return &m_options; 16015a988416SJim Ingham } 16025a988416SJim Ingham 16035a988416SJim Ingham class CommandOptions : public Options 16045a988416SJim Ingham { 16055a988416SJim Ingham public: 16065a988416SJim Ingham CommandOptions (CommandInterpreter &interpreter) : 16075a988416SJim Ingham Options (interpreter), 16085a988416SJim Ingham m_filename (), 16095a988416SJim Ingham m_line_num (0) 16105a988416SJim Ingham { 16115a988416SJim Ingham } 16125a988416SJim Ingham 1613*9e85e5a8SEugene Zelenko ~CommandOptions() override = default; 16145a988416SJim Ingham 161513d21e9aSBruce Mitchener Error 161613d21e9aSBruce Mitchener SetOptionValue (uint32_t option_idx, const char *option_arg) override 16175a988416SJim Ingham { 16185a988416SJim Ingham Error error; 16193bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 16205a988416SJim Ingham 16215a988416SJim Ingham switch (short_option) 16225a988416SJim Ingham { 16235a988416SJim Ingham case 'f': 16245a988416SJim Ingham m_filename.assign (option_arg); 16255a988416SJim Ingham break; 16265a988416SJim Ingham 16275a988416SJim Ingham case 'l': 16285275aaa0SVince Harron m_line_num = StringConvert::ToUInt32 (option_arg, 0); 16295a988416SJim Ingham break; 16305a988416SJim Ingham 16315a988416SJim Ingham default: 16325a988416SJim Ingham error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 16335a988416SJim Ingham break; 16345a988416SJim Ingham } 16355a988416SJim Ingham 16365a988416SJim Ingham return error; 16375a988416SJim Ingham } 16385a988416SJim Ingham 16395a988416SJim Ingham void 164013d21e9aSBruce Mitchener OptionParsingStarting () override 16415a988416SJim Ingham { 16425a988416SJim Ingham m_filename.clear(); 16435a988416SJim Ingham m_line_num = 0; 16445a988416SJim Ingham } 16455a988416SJim Ingham 16465a988416SJim Ingham const OptionDefinition* 164713d21e9aSBruce Mitchener GetDefinitions () override 16485a988416SJim Ingham { 16495a988416SJim Ingham return g_option_table; 16505a988416SJim Ingham } 16515a988416SJim Ingham 16525a988416SJim Ingham // Options table: Required for subclasses of Options. 16535a988416SJim Ingham 16545a988416SJim Ingham static OptionDefinition g_option_table[]; 16555a988416SJim Ingham 16565a988416SJim Ingham // Instance variables to hold the values for command options. 16575a988416SJim Ingham 16585a988416SJim Ingham std::string m_filename; 16595a988416SJim Ingham uint32_t m_line_num; 16605a988416SJim Ingham 16615a988416SJim Ingham }; 16625a988416SJim Ingham 16635a988416SJim Ingham protected: 166413d21e9aSBruce Mitchener bool 166513d21e9aSBruce Mitchener DoExecute (Args& command, CommandReturnObject &result) override 16665a988416SJim Ingham { 1667893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1668*9e85e5a8SEugene Zelenko if (target == nullptr) 16695a988416SJim Ingham { 16705a988416SJim Ingham result.AppendError ("Invalid target. No existing target or breakpoints."); 16715a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 16725a988416SJim Ingham return false; 16735a988416SJim Ingham } 16745a988416SJim Ingham 16755a988416SJim Ingham // The following are the various types of breakpoints that could be cleared: 16765a988416SJim Ingham // 1). -f -l (clearing breakpoint by source location) 16775a988416SJim Ingham 16785a988416SJim Ingham BreakpointClearType break_type = eClearTypeInvalid; 16795a988416SJim Ingham 16805a988416SJim Ingham if (m_options.m_line_num != 0) 16815a988416SJim Ingham break_type = eClearTypeFileAndLine; 16825a988416SJim Ingham 16835a988416SJim Ingham Mutex::Locker locker; 16845a988416SJim Ingham target->GetBreakpointList().GetListMutex(locker); 16855a988416SJim Ingham 16865a988416SJim Ingham BreakpointList &breakpoints = target->GetBreakpointList(); 16875a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 16885a988416SJim Ingham 16895a988416SJim Ingham // Early return if there's no breakpoint at all. 16905a988416SJim Ingham if (num_breakpoints == 0) 16915a988416SJim Ingham { 16925a988416SJim Ingham result.AppendError ("Breakpoint clear: No breakpoint cleared."); 16935a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 16945a988416SJim Ingham return result.Succeeded(); 16955a988416SJim Ingham } 16965a988416SJim Ingham 16975a988416SJim Ingham // Find matching breakpoints and delete them. 16985a988416SJim Ingham 16995a988416SJim Ingham // First create a copy of all the IDs. 17005a988416SJim Ingham std::vector<break_id_t> BreakIDs; 17015a988416SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) 1702*9e85e5a8SEugene Zelenko BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID()); 17035a988416SJim Ingham 17045a988416SJim Ingham int num_cleared = 0; 17055a988416SJim Ingham StreamString ss; 17065a988416SJim Ingham switch (break_type) 17075a988416SJim Ingham { 17085a988416SJim Ingham case eClearTypeFileAndLine: // Breakpoint by source position 17095a988416SJim Ingham { 17105a988416SJim Ingham const ConstString filename(m_options.m_filename.c_str()); 17115a988416SJim Ingham BreakpointLocationCollection loc_coll; 17125a988416SJim Ingham 17135a988416SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) 17145a988416SJim Ingham { 17155a988416SJim Ingham Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); 17165a988416SJim Ingham 17175a988416SJim Ingham if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) 17185a988416SJim Ingham { 17195a988416SJim Ingham // If the collection size is 0, it's a full match and we can just remove the breakpoint. 17205a988416SJim Ingham if (loc_coll.GetSize() == 0) 17215a988416SJim Ingham { 17225a988416SJim Ingham bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); 17235a988416SJim Ingham ss.EOL(); 17245a988416SJim Ingham target->RemoveBreakpointByID (bp->GetID()); 17255a988416SJim Ingham ++num_cleared; 17265a988416SJim Ingham } 17275a988416SJim Ingham } 17285a988416SJim Ingham } 17295a988416SJim Ingham } 17305a988416SJim Ingham break; 17315a988416SJim Ingham 17325a988416SJim Ingham default: 17335a988416SJim Ingham break; 17345a988416SJim Ingham } 17355a988416SJim Ingham 17365a988416SJim Ingham if (num_cleared > 0) 17375a988416SJim Ingham { 17385a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 17395a988416SJim Ingham output_stream.Printf ("%d breakpoints cleared:\n", num_cleared); 17405a988416SJim Ingham output_stream << ss.GetData(); 17415a988416SJim Ingham output_stream.EOL(); 17425a988416SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 17435a988416SJim Ingham } 17445a988416SJim Ingham else 17455a988416SJim Ingham { 17465a988416SJim Ingham result.AppendError ("Breakpoint clear: No breakpoint cleared."); 17475a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 17485a988416SJim Ingham } 17495a988416SJim Ingham 17505a988416SJim Ingham return result.Succeeded(); 17515a988416SJim Ingham } 17525a988416SJim Ingham 17535a988416SJim Ingham private: 17545a988416SJim Ingham CommandOptions m_options; 17555a988416SJim Ingham }; 17565a988416SJim Ingham 17575a988416SJim Ingham #pragma mark Clear::CommandOptions 17585a988416SJim Ingham 17595a988416SJim Ingham OptionDefinition 17605a988416SJim Ingham CommandObjectBreakpointClear::CommandOptions::g_option_table[] = 17615a988416SJim Ingham { 1762*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, 17635a988416SJim Ingham "Specify the breakpoint by source location in this particular file."}, 17645a988416SJim Ingham 1765*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, 17665a988416SJim Ingham "Specify the breakpoint by source location at this particular line."}, 17675a988416SJim Ingham 1768*9e85e5a8SEugene Zelenko { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } 17695a988416SJim Ingham }; 17705a988416SJim Ingham 17715a988416SJim Ingham //------------------------------------------------------------------------- 17725a988416SJim Ingham // CommandObjectBreakpointDelete 17735a988416SJim Ingham //------------------------------------------------------------------------- 17745a988416SJim Ingham #pragma mark Delete 17755a988416SJim Ingham 17765a988416SJim Ingham class CommandObjectBreakpointDelete : public CommandObjectParsed 17775a988416SJim Ingham { 17785a988416SJim Ingham public: 17795a988416SJim Ingham CommandObjectBreakpointDelete (CommandInterpreter &interpreter) : 17805a988416SJim Ingham CommandObjectParsed(interpreter, 17815a988416SJim Ingham "breakpoint delete", 17825a988416SJim Ingham "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.", 1783*9e85e5a8SEugene Zelenko nullptr), 178433df7cd3SJim Ingham m_options (interpreter) 17855a988416SJim Ingham { 17865a988416SJim Ingham CommandArgumentEntry arg; 17875a988416SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); 17885a988416SJim Ingham // Add the entry for the first argument for this command to the object's arguments vector. 17895a988416SJim Ingham m_arguments.push_back (arg); 17905a988416SJim Ingham } 17915a988416SJim Ingham 1792*9e85e5a8SEugene Zelenko ~CommandObjectBreakpointDelete() override = default; 17935a988416SJim Ingham 179413d21e9aSBruce Mitchener Options * 179513d21e9aSBruce Mitchener GetOptions () override 179633df7cd3SJim Ingham { 179733df7cd3SJim Ingham return &m_options; 179833df7cd3SJim Ingham } 179933df7cd3SJim Ingham 180033df7cd3SJim Ingham class CommandOptions : public Options 180133df7cd3SJim Ingham { 180233df7cd3SJim Ingham public: 180333df7cd3SJim Ingham CommandOptions (CommandInterpreter &interpreter) : 180433df7cd3SJim Ingham Options (interpreter), 180533df7cd3SJim Ingham m_use_dummy (false), 180633df7cd3SJim Ingham m_force (false) 180733df7cd3SJim Ingham { 180833df7cd3SJim Ingham } 180933df7cd3SJim Ingham 1810*9e85e5a8SEugene Zelenko ~CommandOptions() override = default; 181133df7cd3SJim Ingham 181213d21e9aSBruce Mitchener Error 181313d21e9aSBruce Mitchener SetOptionValue (uint32_t option_idx, const char *option_arg) override 181433df7cd3SJim Ingham { 181533df7cd3SJim Ingham Error error; 181633df7cd3SJim Ingham const int short_option = m_getopt_table[option_idx].val; 181733df7cd3SJim Ingham 181833df7cd3SJim Ingham switch (short_option) 181933df7cd3SJim Ingham { 182033df7cd3SJim Ingham case 'f': 182133df7cd3SJim Ingham m_force = true; 182233df7cd3SJim Ingham break; 182333df7cd3SJim Ingham 182433df7cd3SJim Ingham case 'D': 182533df7cd3SJim Ingham m_use_dummy = true; 182633df7cd3SJim Ingham break; 182733df7cd3SJim Ingham 182833df7cd3SJim Ingham default: 182933df7cd3SJim Ingham error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 183033df7cd3SJim Ingham break; 183133df7cd3SJim Ingham } 183233df7cd3SJim Ingham 183333df7cd3SJim Ingham return error; 183433df7cd3SJim Ingham } 183533df7cd3SJim Ingham 183633df7cd3SJim Ingham void 183713d21e9aSBruce Mitchener OptionParsingStarting () override 183833df7cd3SJim Ingham { 183933df7cd3SJim Ingham m_use_dummy = false; 184033df7cd3SJim Ingham m_force = false; 184133df7cd3SJim Ingham } 184233df7cd3SJim Ingham 184333df7cd3SJim Ingham const OptionDefinition* 184413d21e9aSBruce Mitchener GetDefinitions () override 184533df7cd3SJim Ingham { 184633df7cd3SJim Ingham return g_option_table; 184733df7cd3SJim Ingham } 184833df7cd3SJim Ingham 184933df7cd3SJim Ingham // Options table: Required for subclasses of Options. 185033df7cd3SJim Ingham 185133df7cd3SJim Ingham static OptionDefinition g_option_table[]; 185233df7cd3SJim Ingham 185333df7cd3SJim Ingham // Instance variables to hold the values for command options. 185433df7cd3SJim Ingham bool m_use_dummy; 185533df7cd3SJim Ingham bool m_force; 185633df7cd3SJim Ingham }; 185733df7cd3SJim Ingham 18585a988416SJim Ingham protected: 185913d21e9aSBruce Mitchener bool 186013d21e9aSBruce Mitchener DoExecute (Args& command, CommandReturnObject &result) override 18615a988416SJim Ingham { 186233df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 186333df7cd3SJim Ingham 1864*9e85e5a8SEugene Zelenko if (target == nullptr) 18655a988416SJim Ingham { 18665a988416SJim Ingham result.AppendError ("Invalid target. No existing target or breakpoints."); 18675a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 18685a988416SJim Ingham return false; 18695a988416SJim Ingham } 18705a988416SJim Ingham 18715a988416SJim Ingham Mutex::Locker locker; 18725a988416SJim Ingham target->GetBreakpointList().GetListMutex(locker); 18735a988416SJim Ingham 18745a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 18755a988416SJim Ingham 18765a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 18775a988416SJim Ingham 18785a988416SJim Ingham if (num_breakpoints == 0) 18795a988416SJim Ingham { 18805a988416SJim Ingham result.AppendError ("No breakpoints exist to be deleted."); 18815a988416SJim Ingham result.SetStatus (eReturnStatusFailed); 18825a988416SJim Ingham return false; 18835a988416SJim Ingham } 18845a988416SJim Ingham 18855a988416SJim Ingham if (command.GetArgumentCount() == 0) 18865a988416SJim Ingham { 188733df7cd3SJim Ingham if (!m_options.m_force && !m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true)) 18885a988416SJim Ingham { 18895a988416SJim Ingham result.AppendMessage("Operation cancelled..."); 18905a988416SJim Ingham } 18915a988416SJim Ingham else 18925a988416SJim Ingham { 18935a988416SJim Ingham target->RemoveAllBreakpoints (); 18946fea17e8SGreg Clayton result.AppendMessageWithFormat ("All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : ""); 18955a988416SJim Ingham } 18965a988416SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 18975a988416SJim Ingham } 18985a988416SJim Ingham else 18995a988416SJim Ingham { 19005a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 19015a988416SJim Ingham BreakpointIDList valid_bp_ids; 19025e09c8c3SJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); 19035a988416SJim Ingham 19045a988416SJim Ingham if (result.Succeeded()) 19055a988416SJim Ingham { 19065a988416SJim Ingham int delete_count = 0; 19075a988416SJim Ingham int disable_count = 0; 19085a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 19095a988416SJim Ingham for (size_t i = 0; i < count; ++i) 19105a988416SJim Ingham { 19115a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); 19125a988416SJim Ingham 19135a988416SJim Ingham if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) 19145a988416SJim Ingham { 19155a988416SJim Ingham if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) 19165a988416SJim Ingham { 19175a988416SJim Ingham Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 19185a988416SJim Ingham BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); 19195a988416SJim Ingham // It makes no sense to try to delete individual locations, so we disable them instead. 19205a988416SJim Ingham if (location) 19215a988416SJim Ingham { 19225a988416SJim Ingham location->SetEnabled (false); 19235a988416SJim Ingham ++disable_count; 19245a988416SJim Ingham } 19255a988416SJim Ingham } 19265a988416SJim Ingham else 19275a988416SJim Ingham { 19285a988416SJim Ingham target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID()); 19295a988416SJim Ingham ++delete_count; 19305a988416SJim Ingham } 19315a988416SJim Ingham } 19325a988416SJim Ingham } 19335a988416SJim Ingham result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n", 19345a988416SJim Ingham delete_count, disable_count); 19355a988416SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 19365a988416SJim Ingham } 19375a988416SJim Ingham } 19385a988416SJim Ingham return result.Succeeded(); 19395a988416SJim Ingham } 1940*9e85e5a8SEugene Zelenko 194133df7cd3SJim Ingham private: 194233df7cd3SJim Ingham CommandOptions m_options; 194333df7cd3SJim Ingham }; 194433df7cd3SJim Ingham 194533df7cd3SJim Ingham OptionDefinition 194633df7cd3SJim Ingham CommandObjectBreakpointDelete::CommandOptions::g_option_table[] = 194733df7cd3SJim Ingham { 1948*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 194933df7cd3SJim Ingham "Delete all breakpoints without querying for confirmation."}, 195033df7cd3SJim Ingham 1951*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 195233df7cd3SJim Ingham "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, 195333df7cd3SJim Ingham 1954*9e85e5a8SEugene Zelenko { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } 19555a988416SJim Ingham }; 19565a988416SJim Ingham 195730fdc8d8SChris Lattner //------------------------------------------------------------------------- 19585e09c8c3SJim Ingham // CommandObjectBreakpointName 19595e09c8c3SJim Ingham //------------------------------------------------------------------------- 19605e09c8c3SJim Ingham 19615e09c8c3SJim Ingham static OptionDefinition 19625e09c8c3SJim Ingham g_breakpoint_name_options[] = 19635e09c8c3SJim Ingham { 1964*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_1, false, "name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."}, 1965*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_2, false, "breakpoint-id", 'B', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointID, "Specify a breakpoint id to use."}, 1966*9e85e5a8SEugene Zelenko { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, 19675e09c8c3SJim Ingham "Operate on Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, 19685e09c8c3SJim Ingham }; 19695e09c8c3SJim Ingham class BreakpointNameOptionGroup : public OptionGroup 19705e09c8c3SJim Ingham { 19715e09c8c3SJim Ingham public: 19725e09c8c3SJim Ingham BreakpointNameOptionGroup() : 19735e09c8c3SJim Ingham OptionGroup(), 19745e09c8c3SJim Ingham m_breakpoint(LLDB_INVALID_BREAK_ID), 19755e09c8c3SJim Ingham m_use_dummy (false) 19765e09c8c3SJim Ingham { 19775e09c8c3SJim Ingham } 19785e09c8c3SJim Ingham 1979*9e85e5a8SEugene Zelenko ~BreakpointNameOptionGroup() override = default; 19805e09c8c3SJim Ingham 198113d21e9aSBruce Mitchener uint32_t 198213d21e9aSBruce Mitchener GetNumDefinitions () override 19835e09c8c3SJim Ingham { 19845e09c8c3SJim Ingham return sizeof (g_breakpoint_name_options) / sizeof (OptionDefinition); 19855e09c8c3SJim Ingham } 19865e09c8c3SJim Ingham 198713d21e9aSBruce Mitchener const OptionDefinition* 198813d21e9aSBruce Mitchener GetDefinitions () override 19895e09c8c3SJim Ingham { 19905e09c8c3SJim Ingham return g_breakpoint_name_options; 19915e09c8c3SJim Ingham } 19925e09c8c3SJim Ingham 199313d21e9aSBruce Mitchener Error 19945e09c8c3SJim Ingham SetOptionValue (CommandInterpreter &interpreter, 19955e09c8c3SJim Ingham uint32_t option_idx, 199613d21e9aSBruce Mitchener const char *option_value) override 19975e09c8c3SJim Ingham { 19985e09c8c3SJim Ingham Error error; 19995e09c8c3SJim Ingham const int short_option = g_breakpoint_name_options[option_idx].short_option; 20005e09c8c3SJim Ingham 20015e09c8c3SJim Ingham switch (short_option) 20025e09c8c3SJim Ingham { 20035e09c8c3SJim Ingham case 'N': 20045e09c8c3SJim Ingham if (BreakpointID::StringIsBreakpointName(option_value, error) && error.Success()) 2005c95f7e2aSPavel Labath m_name.SetValueFromString(option_value); 20065e09c8c3SJim Ingham break; 20075e09c8c3SJim Ingham 20085e09c8c3SJim Ingham case 'B': 2009c95f7e2aSPavel Labath if (m_breakpoint.SetValueFromString(option_value).Fail()) 20105e09c8c3SJim Ingham error.SetErrorStringWithFormat ("unrecognized value \"%s\" for breakpoint", option_value); 20115e09c8c3SJim Ingham break; 20125e09c8c3SJim Ingham case 'D': 2013c95f7e2aSPavel Labath if (m_use_dummy.SetValueFromString(option_value).Fail()) 20145e09c8c3SJim Ingham error.SetErrorStringWithFormat ("unrecognized value \"%s\" for use-dummy", option_value); 20155e09c8c3SJim Ingham break; 20165e09c8c3SJim Ingham 20175e09c8c3SJim Ingham default: 20185e09c8c3SJim Ingham error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option); 20195e09c8c3SJim Ingham break; 20205e09c8c3SJim Ingham } 20215e09c8c3SJim Ingham return error; 20225e09c8c3SJim Ingham } 20235e09c8c3SJim Ingham 202413d21e9aSBruce Mitchener void 202513d21e9aSBruce Mitchener OptionParsingStarting (CommandInterpreter &interpreter) override 20265e09c8c3SJim Ingham { 20275e09c8c3SJim Ingham m_name.Clear(); 20285e09c8c3SJim Ingham m_breakpoint.Clear(); 20295e09c8c3SJim Ingham m_use_dummy.Clear(); 20305e09c8c3SJim Ingham m_use_dummy.SetDefaultValue(false); 20315e09c8c3SJim Ingham } 20325e09c8c3SJim Ingham 20335e09c8c3SJim Ingham OptionValueString m_name; 20345e09c8c3SJim Ingham OptionValueUInt64 m_breakpoint; 20355e09c8c3SJim Ingham OptionValueBoolean m_use_dummy; 20365e09c8c3SJim Ingham }; 20375e09c8c3SJim Ingham 20385e09c8c3SJim Ingham class CommandObjectBreakpointNameAdd : public CommandObjectParsed 20395e09c8c3SJim Ingham { 20405e09c8c3SJim Ingham public: 20415e09c8c3SJim Ingham CommandObjectBreakpointNameAdd (CommandInterpreter &interpreter) : 20425e09c8c3SJim Ingham CommandObjectParsed (interpreter, 20435e09c8c3SJim Ingham "add", 20445e09c8c3SJim Ingham "Add a name to the breakpoints provided.", 20455e09c8c3SJim Ingham "breakpoint name add <command-options> <breakpoint-id-list>"), 20465e09c8c3SJim Ingham m_name_options(), 20475e09c8c3SJim Ingham m_option_group(interpreter) 20485e09c8c3SJim Ingham { 20495e09c8c3SJim Ingham // Create the first variant for the first (and only) argument for this command. 20505e09c8c3SJim Ingham CommandArgumentEntry arg1; 20515e09c8c3SJim Ingham CommandArgumentData id_arg; 20525e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 20535e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 20545e09c8c3SJim Ingham arg1.push_back(id_arg); 20555e09c8c3SJim Ingham m_arguments.push_back (arg1); 20565e09c8c3SJim Ingham 20575e09c8c3SJim Ingham m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 20585e09c8c3SJim Ingham m_option_group.Finalize(); 20595e09c8c3SJim Ingham } 20605e09c8c3SJim Ingham 2061*9e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameAdd() override = default; 20625e09c8c3SJim Ingham 20635e09c8c3SJim Ingham Options * 206413d21e9aSBruce Mitchener GetOptions() override 20655e09c8c3SJim Ingham { 20665e09c8c3SJim Ingham return &m_option_group; 20675e09c8c3SJim Ingham } 20685e09c8c3SJim Ingham 20695e09c8c3SJim Ingham protected: 207013d21e9aSBruce Mitchener bool 207113d21e9aSBruce Mitchener DoExecute (Args& command, CommandReturnObject &result) override 20725e09c8c3SJim Ingham { 20735e09c8c3SJim Ingham if (!m_name_options.m_name.OptionWasSet()) 20745e09c8c3SJim Ingham { 20755e09c8c3SJim Ingham result.SetError("No name option provided."); 20765e09c8c3SJim Ingham return false; 20775e09c8c3SJim Ingham } 20785e09c8c3SJim Ingham 20795e09c8c3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 20805e09c8c3SJim Ingham 2081*9e85e5a8SEugene Zelenko if (target == nullptr) 20825e09c8c3SJim Ingham { 20835e09c8c3SJim Ingham result.AppendError ("Invalid target. No existing target or breakpoints."); 20845e09c8c3SJim Ingham result.SetStatus (eReturnStatusFailed); 20855e09c8c3SJim Ingham return false; 20865e09c8c3SJim Ingham } 20875e09c8c3SJim Ingham 20885e09c8c3SJim Ingham Mutex::Locker locker; 20895e09c8c3SJim Ingham target->GetBreakpointList().GetListMutex(locker); 20905e09c8c3SJim Ingham 20915e09c8c3SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 20925e09c8c3SJim Ingham 20935e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 20945e09c8c3SJim Ingham if (num_breakpoints == 0) 20955e09c8c3SJim Ingham { 20965e09c8c3SJim Ingham result.SetError("No breakpoints, cannot add names."); 20975e09c8c3SJim Ingham result.SetStatus (eReturnStatusFailed); 20985e09c8c3SJim Ingham return false; 20995e09c8c3SJim Ingham } 21005e09c8c3SJim Ingham 21015e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 21025e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 21035e09c8c3SJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 21045e09c8c3SJim Ingham 21055e09c8c3SJim Ingham if (result.Succeeded()) 21065e09c8c3SJim Ingham { 21075e09c8c3SJim Ingham if (valid_bp_ids.GetSize() == 0) 21085e09c8c3SJim Ingham { 21095e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot add names."); 21105e09c8c3SJim Ingham result.SetStatus (eReturnStatusFailed); 21115e09c8c3SJim Ingham return false; 21125e09c8c3SJim Ingham } 21135e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 21145e09c8c3SJim Ingham for (size_t index = 0; index < num_valid_ids; index++) 21155e09c8c3SJim Ingham { 21165e09c8c3SJim Ingham lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 21175e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 21185e09c8c3SJim Ingham Error error; // We don't need to check the error here, since the option parser checked it... 21195e09c8c3SJim Ingham bp_sp->AddName(m_name_options.m_name.GetCurrentValue(), error); 21205e09c8c3SJim Ingham } 21215e09c8c3SJim Ingham } 21225e09c8c3SJim Ingham 21235e09c8c3SJim Ingham return true; 21245e09c8c3SJim Ingham } 21255e09c8c3SJim Ingham 21265e09c8c3SJim Ingham private: 21275e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 21285e09c8c3SJim Ingham OptionGroupOptions m_option_group; 21295e09c8c3SJim Ingham }; 21305e09c8c3SJim Ingham 21315e09c8c3SJim Ingham class CommandObjectBreakpointNameDelete : public CommandObjectParsed 21325e09c8c3SJim Ingham { 21335e09c8c3SJim Ingham public: 21345e09c8c3SJim Ingham CommandObjectBreakpointNameDelete (CommandInterpreter &interpreter) : 21355e09c8c3SJim Ingham CommandObjectParsed (interpreter, 21365e09c8c3SJim Ingham "delete", 21375e09c8c3SJim Ingham "Delete a name from the breakpoints provided.", 21385e09c8c3SJim Ingham "breakpoint name delete <command-options> <breakpoint-id-list>"), 21395e09c8c3SJim Ingham m_name_options(), 21405e09c8c3SJim Ingham m_option_group(interpreter) 21415e09c8c3SJim Ingham { 21425e09c8c3SJim Ingham // Create the first variant for the first (and only) argument for this command. 21435e09c8c3SJim Ingham CommandArgumentEntry arg1; 21445e09c8c3SJim Ingham CommandArgumentData id_arg; 21455e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 21465e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 21475e09c8c3SJim Ingham arg1.push_back(id_arg); 21485e09c8c3SJim Ingham m_arguments.push_back (arg1); 21495e09c8c3SJim Ingham 21505e09c8c3SJim Ingham m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 21515e09c8c3SJim Ingham m_option_group.Finalize(); 21525e09c8c3SJim Ingham } 21535e09c8c3SJim Ingham 2154*9e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameDelete() override = default; 21555e09c8c3SJim Ingham 21565e09c8c3SJim Ingham Options * 215713d21e9aSBruce Mitchener GetOptions() override 21585e09c8c3SJim Ingham { 21595e09c8c3SJim Ingham return &m_option_group; 21605e09c8c3SJim Ingham } 21615e09c8c3SJim Ingham 21625e09c8c3SJim Ingham protected: 216313d21e9aSBruce Mitchener bool 216413d21e9aSBruce Mitchener DoExecute (Args& command, CommandReturnObject &result) override 21655e09c8c3SJim Ingham { 21665e09c8c3SJim Ingham if (!m_name_options.m_name.OptionWasSet()) 21675e09c8c3SJim Ingham { 21685e09c8c3SJim Ingham result.SetError("No name option provided."); 21695e09c8c3SJim Ingham return false; 21705e09c8c3SJim Ingham } 21715e09c8c3SJim Ingham 21725e09c8c3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 21735e09c8c3SJim Ingham 2174*9e85e5a8SEugene Zelenko if (target == nullptr) 21755e09c8c3SJim Ingham { 21765e09c8c3SJim Ingham result.AppendError ("Invalid target. No existing target or breakpoints."); 21775e09c8c3SJim Ingham result.SetStatus (eReturnStatusFailed); 21785e09c8c3SJim Ingham return false; 21795e09c8c3SJim Ingham } 21805e09c8c3SJim Ingham 21815e09c8c3SJim Ingham Mutex::Locker locker; 21825e09c8c3SJim Ingham target->GetBreakpointList().GetListMutex(locker); 21835e09c8c3SJim Ingham 21845e09c8c3SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 21855e09c8c3SJim Ingham 21865e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 21875e09c8c3SJim Ingham if (num_breakpoints == 0) 21885e09c8c3SJim Ingham { 21895e09c8c3SJim Ingham result.SetError("No breakpoints, cannot delete names."); 21905e09c8c3SJim Ingham result.SetStatus (eReturnStatusFailed); 21915e09c8c3SJim Ingham return false; 21925e09c8c3SJim Ingham } 21935e09c8c3SJim Ingham 21945e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 21955e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 21965e09c8c3SJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); 21975e09c8c3SJim Ingham 21985e09c8c3SJim Ingham if (result.Succeeded()) 21995e09c8c3SJim Ingham { 22005e09c8c3SJim Ingham if (valid_bp_ids.GetSize() == 0) 22015e09c8c3SJim Ingham { 22025e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot delete names."); 22035e09c8c3SJim Ingham result.SetStatus (eReturnStatusFailed); 22045e09c8c3SJim Ingham return false; 22055e09c8c3SJim Ingham } 22065e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 22075e09c8c3SJim Ingham for (size_t index = 0; index < num_valid_ids; index++) 22085e09c8c3SJim Ingham { 22095e09c8c3SJim Ingham lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 22105e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 22115e09c8c3SJim Ingham bp_sp->RemoveName(m_name_options.m_name.GetCurrentValue()); 22125e09c8c3SJim Ingham } 22135e09c8c3SJim Ingham } 22145e09c8c3SJim Ingham 22155e09c8c3SJim Ingham return true; 22165e09c8c3SJim Ingham } 22175e09c8c3SJim Ingham 22185e09c8c3SJim Ingham private: 22195e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 22205e09c8c3SJim Ingham OptionGroupOptions m_option_group; 22215e09c8c3SJim Ingham }; 22225e09c8c3SJim Ingham 22235e09c8c3SJim Ingham class CommandObjectBreakpointNameList : public CommandObjectParsed 22245e09c8c3SJim Ingham { 22255e09c8c3SJim Ingham public: 22265e09c8c3SJim Ingham CommandObjectBreakpointNameList (CommandInterpreter &interpreter) : 22275e09c8c3SJim Ingham CommandObjectParsed (interpreter, 22285e09c8c3SJim Ingham "list", 22295e09c8c3SJim Ingham "List either the names for a breakpoint or the breakpoints for a given name.", 22305e09c8c3SJim Ingham "breakpoint name list <command-options>"), 22315e09c8c3SJim Ingham m_name_options(), 22325e09c8c3SJim Ingham m_option_group(interpreter) 22335e09c8c3SJim Ingham { 22345e09c8c3SJim Ingham m_option_group.Append (&m_name_options); 22355e09c8c3SJim Ingham m_option_group.Finalize(); 22365e09c8c3SJim Ingham } 22375e09c8c3SJim Ingham 2238*9e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameList() override = default; 22395e09c8c3SJim Ingham 22405e09c8c3SJim Ingham Options * 224113d21e9aSBruce Mitchener GetOptions() override 22425e09c8c3SJim Ingham { 22435e09c8c3SJim Ingham return &m_option_group; 22445e09c8c3SJim Ingham } 22455e09c8c3SJim Ingham 22465e09c8c3SJim Ingham protected: 224713d21e9aSBruce Mitchener bool 224813d21e9aSBruce Mitchener DoExecute (Args& command, CommandReturnObject &result) override 22495e09c8c3SJim Ingham { 22505e09c8c3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 22515e09c8c3SJim Ingham 2252*9e85e5a8SEugene Zelenko if (target == nullptr) 22535e09c8c3SJim Ingham { 22545e09c8c3SJim Ingham result.AppendError ("Invalid target. No existing target or breakpoints."); 22555e09c8c3SJim Ingham result.SetStatus (eReturnStatusFailed); 22565e09c8c3SJim Ingham return false; 22575e09c8c3SJim Ingham } 22585e09c8c3SJim Ingham 22595e09c8c3SJim Ingham if (m_name_options.m_name.OptionWasSet()) 22605e09c8c3SJim Ingham { 22615e09c8c3SJim Ingham const char *name = m_name_options.m_name.GetCurrentValue(); 22625e09c8c3SJim Ingham Mutex::Locker locker; 22635e09c8c3SJim Ingham target->GetBreakpointList().GetListMutex(locker); 22645e09c8c3SJim Ingham 22655e09c8c3SJim Ingham BreakpointList &breakpoints = target->GetBreakpointList(); 22665e09c8c3SJim Ingham for (BreakpointSP bp_sp : breakpoints.Breakpoints()) 22675e09c8c3SJim Ingham { 22685e09c8c3SJim Ingham if (bp_sp->MatchesName(name)) 22695e09c8c3SJim Ingham { 22705e09c8c3SJim Ingham StreamString s; 22715e09c8c3SJim Ingham bp_sp->GetDescription(&s, eDescriptionLevelBrief); 22725e09c8c3SJim Ingham s.EOL(); 22735e09c8c3SJim Ingham result.AppendMessage(s.GetData()); 22745e09c8c3SJim Ingham } 22755e09c8c3SJim Ingham } 22765e09c8c3SJim Ingham 22775e09c8c3SJim Ingham } 22785e09c8c3SJim Ingham else if (m_name_options.m_breakpoint.OptionWasSet()) 22795e09c8c3SJim Ingham { 22805e09c8c3SJim Ingham BreakpointSP bp_sp = target->GetBreakpointList().FindBreakpointByID(m_name_options.m_breakpoint.GetCurrentValue()); 22815e09c8c3SJim Ingham if (bp_sp) 22825e09c8c3SJim Ingham { 22835e09c8c3SJim Ingham std::vector<std::string> names; 22845e09c8c3SJim Ingham bp_sp->GetNames (names); 22855e09c8c3SJim Ingham result.AppendMessage ("Names:"); 22865e09c8c3SJim Ingham for (auto name : names) 22875e09c8c3SJim Ingham result.AppendMessageWithFormat (" %s\n", name.c_str()); 22885e09c8c3SJim Ingham } 22895e09c8c3SJim Ingham else 22905e09c8c3SJim Ingham { 22915e09c8c3SJim Ingham result.AppendErrorWithFormat ("Could not find breakpoint %" PRId64 ".\n", 22925e09c8c3SJim Ingham m_name_options.m_breakpoint.GetCurrentValue()); 22935e09c8c3SJim Ingham result.SetStatus (eReturnStatusFailed); 22945e09c8c3SJim Ingham return false; 22955e09c8c3SJim Ingham } 22965e09c8c3SJim Ingham } 22975e09c8c3SJim Ingham else 22985e09c8c3SJim Ingham { 22995e09c8c3SJim Ingham result.SetError ("Must specify -N or -B option to list."); 23005e09c8c3SJim Ingham result.SetStatus (eReturnStatusFailed); 23015e09c8c3SJim Ingham return false; 23025e09c8c3SJim Ingham } 23035e09c8c3SJim Ingham return true; 23045e09c8c3SJim Ingham } 23055e09c8c3SJim Ingham 23065e09c8c3SJim Ingham private: 23075e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 23085e09c8c3SJim Ingham OptionGroupOptions m_option_group; 23095e09c8c3SJim Ingham }; 23105e09c8c3SJim Ingham 23115e09c8c3SJim Ingham //------------------------------------------------------------------------- 23125e09c8c3SJim Ingham // CommandObjectMultiwordBreakpoint 23135e09c8c3SJim Ingham //------------------------------------------------------------------------- 23145e09c8c3SJim Ingham class CommandObjectBreakpointName : public CommandObjectMultiword 23155e09c8c3SJim Ingham { 23165e09c8c3SJim Ingham public: 23175e09c8c3SJim Ingham CommandObjectBreakpointName (CommandInterpreter &interpreter) : 23185e09c8c3SJim Ingham CommandObjectMultiword(interpreter, 23195e09c8c3SJim Ingham "name", 23205e09c8c3SJim Ingham "A set of commands to manage name tags for breakpoints", 23215e09c8c3SJim Ingham "breakpoint name <command> [<command-options>]") 23225e09c8c3SJim Ingham { 23235e09c8c3SJim Ingham CommandObjectSP add_command_object (new CommandObjectBreakpointNameAdd (interpreter)); 23245e09c8c3SJim Ingham CommandObjectSP delete_command_object (new CommandObjectBreakpointNameDelete (interpreter)); 23255e09c8c3SJim Ingham CommandObjectSP list_command_object (new CommandObjectBreakpointNameList (interpreter)); 23265e09c8c3SJim Ingham 23275e09c8c3SJim Ingham LoadSubCommand ("add", add_command_object); 23285e09c8c3SJim Ingham LoadSubCommand ("delete", delete_command_object); 23295e09c8c3SJim Ingham LoadSubCommand ("list", list_command_object); 23305e09c8c3SJim Ingham } 23315e09c8c3SJim Ingham 2332*9e85e5a8SEugene Zelenko ~CommandObjectBreakpointName() override = default; 23335e09c8c3SJim Ingham }; 23345e09c8c3SJim Ingham 23355e09c8c3SJim Ingham //------------------------------------------------------------------------- 233630fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 233730fdc8d8SChris Lattner //------------------------------------------------------------------------- 2338ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 233930fdc8d8SChris Lattner 23406611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) : 2341a7015092SGreg Clayton CommandObjectMultiword (interpreter, 2342a7015092SGreg Clayton "breakpoint", 234346fbc60fSJim Ingham "A set of commands for operating on breakpoints. Also see _regexp-break.", 234430fdc8d8SChris Lattner "breakpoint <command> [<command-options>]") 234530fdc8d8SChris Lattner { 2346a7015092SGreg Clayton CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter)); 2347a7015092SGreg Clayton CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter)); 2348a7015092SGreg Clayton CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter)); 2349b7234e40SJohnny Chen CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter)); 2350b7234e40SJohnny Chen CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter)); 2351a7015092SGreg Clayton CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter)); 235230fdc8d8SChris Lattner CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter)); 2353a7015092SGreg Clayton CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter)); 23545e09c8c3SJim Ingham CommandObjectSP name_command_object (new CommandObjectBreakpointName(interpreter)); 235530fdc8d8SChris Lattner 2356b7234e40SJohnny Chen list_command_object->SetCommandName ("breakpoint list"); 235730fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 235830fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 2359b7234e40SJohnny Chen clear_command_object->SetCommandName("breakpoint clear"); 2360b7234e40SJohnny Chen delete_command_object->SetCommandName("breakpoint delete"); 2361ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 2362b7234e40SJohnny Chen command_command_object->SetCommandName ("breakpoint command"); 2363b7234e40SJohnny Chen modify_command_object->SetCommandName ("breakpoint modify"); 23645e09c8c3SJim Ingham name_command_object->SetCommandName ("breakpoint name"); 236530fdc8d8SChris Lattner 236623f59509SGreg Clayton LoadSubCommand ("list", list_command_object); 236723f59509SGreg Clayton LoadSubCommand ("enable", enable_command_object); 236823f59509SGreg Clayton LoadSubCommand ("disable", disable_command_object); 236923f59509SGreg Clayton LoadSubCommand ("clear", clear_command_object); 237023f59509SGreg Clayton LoadSubCommand ("delete", delete_command_object); 237123f59509SGreg Clayton LoadSubCommand ("set", set_command_object); 237223f59509SGreg Clayton LoadSubCommand ("command", command_command_object); 237323f59509SGreg Clayton LoadSubCommand ("modify", modify_command_object); 23745e09c8c3SJim Ingham LoadSubCommand ("name", name_command_object); 237530fdc8d8SChris Lattner } 237630fdc8d8SChris Lattner 2377*9e85e5a8SEugene Zelenko CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default; 237830fdc8d8SChris Lattner 237930fdc8d8SChris Lattner void 23805e09c8c3SJim Ingham CommandObjectMultiwordBreakpoint::VerifyIDs (Args &args, 23815e09c8c3SJim Ingham Target *target, 23825e09c8c3SJim Ingham bool allow_locations, 23835e09c8c3SJim Ingham CommandReturnObject &result, 238430fdc8d8SChris Lattner BreakpointIDList *valid_ids) 238530fdc8d8SChris Lattner { 238630fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 238730fdc8d8SChris Lattner // 2). the full breakpoint & location canonical representation 238830fdc8d8SChris Lattner // 3). the word "to" or a hyphen, representing a range (in which case there 238930fdc8d8SChris Lattner // had *better* be an entry both before & after of one of the first two types. 23905e09c8c3SJim Ingham // 4). A breakpoint name 239136f3b369SJim Ingham // If args is empty, we will use the last created breakpoint (if there is one.) 239230fdc8d8SChris Lattner 239330fdc8d8SChris Lattner Args temp_args; 239430fdc8d8SChris Lattner 239536f3b369SJim Ingham if (args.GetArgumentCount() == 0) 239636f3b369SJim Ingham { 23974d122c40SGreg Clayton if (target->GetLastCreatedBreakpoint()) 239836f3b369SJim Ingham { 239936f3b369SJim Ingham valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); 240036f3b369SJim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 240136f3b369SJim Ingham } 240236f3b369SJim Ingham else 240336f3b369SJim Ingham { 240436f3b369SJim Ingham result.AppendError("No breakpoint specified and no last created breakpoint."); 240536f3b369SJim Ingham result.SetStatus (eReturnStatusFailed); 240636f3b369SJim Ingham } 240736f3b369SJim Ingham return; 240836f3b369SJim Ingham } 240936f3b369SJim Ingham 241030fdc8d8SChris Lattner // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to 241130fdc8d8SChris Lattner // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for 241230fdc8d8SChris Lattner // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS. 241330fdc8d8SChris Lattner 24145e09c8c3SJim Ingham BreakpointIDList::FindAndReplaceIDRanges (args, target, allow_locations, result, temp_args); 241530fdc8d8SChris Lattner 241630fdc8d8SChris Lattner // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList: 241730fdc8d8SChris Lattner 2418c982c768SGreg Clayton valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result); 241930fdc8d8SChris Lattner 242030fdc8d8SChris Lattner // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs 242130fdc8d8SChris Lattner // and put into valid_ids. 242230fdc8d8SChris Lattner 242330fdc8d8SChris Lattner if (result.Succeeded()) 242430fdc8d8SChris Lattner { 242530fdc8d8SChris Lattner // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list 242630fdc8d8SChris Lattner // of breakpoint id's and verify that they correspond to valid/currently set breakpoints. 242730fdc8d8SChris Lattner 2428c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 2429c982c768SGreg Clayton for (size_t i = 0; i < count; ++i) 243030fdc8d8SChris Lattner { 243130fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i); 243230fdc8d8SChris Lattner Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); 2433*9e85e5a8SEugene Zelenko if (breakpoint != nullptr) 243430fdc8d8SChris Lattner { 2435c7bece56SGreg Clayton const size_t num_locations = breakpoint->GetNumLocations(); 24363985c8c6SSaleem Abdulrasool if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations) 243730fdc8d8SChris Lattner { 243830fdc8d8SChris Lattner StreamString id_str; 2439c982c768SGreg Clayton BreakpointID::GetCanonicalReference (&id_str, 2440c982c768SGreg Clayton cur_bp_id.GetBreakpointID(), 244130fdc8d8SChris Lattner cur_bp_id.GetLocationID()); 2442c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 244330fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n", 244430fdc8d8SChris Lattner id_str.GetData()); 244530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 244630fdc8d8SChris Lattner } 244730fdc8d8SChris Lattner } 244830fdc8d8SChris Lattner else 244930fdc8d8SChris Lattner { 2450c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 245130fdc8d8SChris Lattner result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID()); 245230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 245330fdc8d8SChris Lattner } 245430fdc8d8SChris Lattner } 245530fdc8d8SChris Lattner } 245630fdc8d8SChris Lattner } 2457