130fdc8d8SChris Lattner //===-- CommandObjectBreakpoint.cpp -----------------------------*- C++ -*-===// 230fdc8d8SChris Lattner // 330fdc8d8SChris Lattner // The LLVM Compiler Infrastructure 430fdc8d8SChris Lattner // 530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source 630fdc8d8SChris Lattner // License. See LICENSE.TXT for details. 730fdc8d8SChris Lattner // 830fdc8d8SChris Lattner //===----------------------------------------------------------------------===// 930fdc8d8SChris Lattner 1030fdc8d8SChris Lattner // C Includes 1130fdc8d8SChris Lattner // C++ Includes 129e85e5a8SEugene Zelenko #include <vector> 139e85e5a8SEugene Zelenko 1430fdc8d8SChris Lattner // Other libraries and framework includes 1530fdc8d8SChris Lattner // Project includes 169e85e5a8SEugene Zelenko #include "CommandObjectBreakpoint.h" 179e85e5a8SEugene Zelenko #include "CommandObjectBreakpointCommand.h" 1830fdc8d8SChris Lattner #include "lldb/Breakpoint/Breakpoint.h" 1930fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointIDList.h" 2030fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointLocation.h" 21b9c1b51eSKate Stone #include "lldb/Core/RegularExpression.h" 22b9c1b51eSKate Stone #include "lldb/Core/StreamString.h" 235275aaa0SVince Harron #include "lldb/Host/StringConvert.h" 24b9c1b51eSKate Stone #include "lldb/Interpreter/CommandCompletions.h" 25b9c1b51eSKate Stone #include "lldb/Interpreter/CommandInterpreter.h" 26b9c1b51eSKate Stone #include "lldb/Interpreter/CommandReturnObject.h" 2732abc6edSZachary Turner #include "lldb/Interpreter/OptionValueBoolean.h" 285e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueString.h" 295e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueUInt64.h" 30b9c1b51eSKate Stone #include "lldb/Interpreter/Options.h" 310e0984eeSJim Ingham #include "lldb/Target/Language.h" 32b57e4a1bSJason Molenda #include "lldb/Target/StackFrame.h" 33b9c1b51eSKate Stone #include "lldb/Target/Target.h" 341b54c88cSJim Ingham #include "lldb/Target/Thread.h" 351b54c88cSJim Ingham #include "lldb/Target/ThreadSpec.h" 3630fdc8d8SChris Lattner 3730fdc8d8SChris Lattner using namespace lldb; 3830fdc8d8SChris Lattner using namespace lldb_private; 3930fdc8d8SChris Lattner 40b9c1b51eSKate Stone static void AddBreakpointDescription(Stream *s, Breakpoint *bp, 41b9c1b51eSKate Stone lldb::DescriptionLevel level) { 4230fdc8d8SChris Lattner s->IndentMore(); 4330fdc8d8SChris Lattner bp->GetDescription(s, level, true); 4430fdc8d8SChris Lattner s->IndentLess(); 4530fdc8d8SChris Lattner s->EOL(); 4630fdc8d8SChris Lattner } 4730fdc8d8SChris Lattner 481f0f5b5bSZachary Turner // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to 491f0f5b5bSZachary Turner // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately. 501f0f5b5bSZachary Turner #define LLDB_OPT_FILE (LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2) 511f0f5b5bSZachary Turner #define LLDB_OPT_NOT_10 (LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10) 521f0f5b5bSZachary Turner #define LLDB_OPT_SKIP_PROLOGUE (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8)) 531f0f5b5bSZachary Turner #define LLDB_OPT_OFFSET_APPLIES (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8)) 541f0f5b5bSZachary Turner #define LLDB_OPT_MOVE_TO_NEAREST_CODE (LLDB_OPT_SET_1 | LLDB_OPT_SET_9) 551f0f5b5bSZachary Turner #define LLDB_OPT_EXPR_LANGUAGE (LLDB_OPT_SET_FROM_TO(3, 8)) 561f0f5b5bSZachary Turner 571f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_set_options[] = { 581f0f5b5bSZachary Turner // clang-format off 591f0f5b5bSZachary Turner { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Set the breakpoint only in this shared library. Can repeat this option " 601f0f5b5bSZachary Turner "multiple times to specify multiple shared libraries." }, 611f0f5b5bSZachary Turner { 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." }, 621f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "The breakpoint is deleted the first time it causes a stop." }, 631f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true." }, 641f0f5b5bSZachary Turner { 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." }, 651f0f5b5bSZachary Turner { 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." }, 661f0f5b5bSZachary Turner { 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 " 671f0f5b5bSZachary Turner "argument." }, 681f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Require the breakpoint to use hardware breakpoints." }, 691f0f5b5bSZachary Turner { 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 " 701f0f5b5bSZachary Turner "this argument." }, 711f0f5b5bSZachary Turner { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specifies the source file in which to set this breakpoint. Note, by default " 721f0f5b5bSZachary Turner "lldb only looks for files that are #included if they use the standard include " 731f0f5b5bSZachary Turner "file extensions. To set breakpoints on .c/.cpp/.m/.mm files that are " 741f0f5b5bSZachary Turner "#included, set target.inline-breakpoint-strategy to \"always\"." }, 751f0f5b5bSZachary Turner { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Specifies the line number on which to set this breakpoint." }, 761f0f5b5bSZachary Turner 771f0f5b5bSZachary Turner // Comment out this option for the moment, as we don't actually use it, but will in the future. 781f0f5b5bSZachary Turner // This way users won't see it, but the infrastructure is left in place. 791f0f5b5bSZachary Turner // { 0, false, "column", 'C', OptionParser::eRequiredArgument, nullptr, "<column>", 801f0f5b5bSZachary Turner // "Set the breakpoint by source location at this particular column."}, 811f0f5b5bSZachary Turner 821f0f5b5bSZachary Turner { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Set the breakpoint at the specified address. If the address maps uniquely to " 831f0f5b5bSZachary Turner "a particular binary, then the address will be converted to a \"file\" " 841f0f5b5bSZachary Turner "address, so that the breakpoint will track that binary+offset no matter where " 851f0f5b5bSZachary Turner "the binary eventually loads. Alternately, if you also specify the module - " 861f0f5b5bSZachary Turner "with the -s option - then the address will be treated as a file address in " 871f0f5b5bSZachary Turner "that module, and resolved accordingly. Again, this will allow lldb to track " 881f0f5b5bSZachary Turner "that offset on subsequent reloads. The module need not have been loaded at " 891f0f5b5bSZachary Turner "the time you specify this breakpoint, and will get resolved when the module " 901f0f5b5bSZachary Turner "is loaded." }, 911f0f5b5bSZachary Turner { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the breakpoint by function name. Can be repeated multiple times to make " 921f0f5b5bSZachary Turner "one breakpoint for multiple names" }, 931f0f5b5bSZachary Turner { LLDB_OPT_SET_9, false, "source-regexp-function", 'X', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "When used with '-p' limits the source regex to source contained in the named " 941f0f5b5bSZachary Turner "functions. Can be repeated multiple times." }, 951f0f5b5bSZachary Turner { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFullName, "Set the breakpoint by fully qualified function names. For C++ this means " 961f0f5b5bSZachary Turner "namespaces and all arguments, and for Objective C this means a full function " 971f0f5b5bSZachary Turner "prototype with class and selector. Can be repeated multiple times to make " 981f0f5b5bSZachary Turner "one breakpoint for multiple names." }, 991f0f5b5bSZachary Turner { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSelector, "Set the breakpoint by ObjC selector name. Can be repeated multiple times to " 1001f0f5b5bSZachary Turner "make one breakpoint for multiple Selectors." }, 1011f0f5b5bSZachary Turner { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeMethod, "Set the breakpoint by C++ method names. Can be repeated multiple times to " 1021f0f5b5bSZachary Turner "make one breakpoint for multiple methods." }, 1031f0f5b5bSZachary Turner { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "Set the breakpoint by function name, evaluating a regular-expression to find " 1041f0f5b5bSZachary Turner "the function name(s)." }, 1051f0f5b5bSZachary Turner { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the breakpoint by function basename (C++ namespaces and arguments will be " 1061f0f5b5bSZachary Turner "ignored). Can be repeated multiple times to make one breakpoint for multiple " 1071f0f5b5bSZachary Turner "symbols." }, 1081f0f5b5bSZachary Turner { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "Set the breakpoint by specifying a regular expression which is matched " 1091f0f5b5bSZachary Turner "against the source text in a source file or files specified with the -f " 1101f0f5b5bSZachary Turner "option. The -f option can be specified more than once. If no source files " 1111f0f5b5bSZachary Turner "are specified, uses the current \"default source file\". If you want to " 1121f0f5b5bSZachary Turner "match against all source files, pass the \"--all-files\" option." }, 1131f0f5b5bSZachary Turner { LLDB_OPT_SET_9, false, "all-files", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "All files are searched for source pattern matches." }, 1141f0f5b5bSZachary Turner { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Set the breakpoint on exceptions thrown by the specified language (without " 1151f0f5b5bSZachary Turner "options, on throw but not catch.)" }, 1161f0f5b5bSZachary Turner { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Set the breakpoint on exception throW." }, 1171f0f5b5bSZachary Turner { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Set the breakpoint on exception catcH." }, 1181f0f5b5bSZachary Turner 1191f0f5b5bSZachary Turner // Don't add this option till it actually does something useful... 1201f0f5b5bSZachary Turner // { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName, 1211f0f5b5bSZachary Turner // "The breakpoint will only stop if an exception Object of this type is thrown. Can be repeated multiple times to stop for multiple object types" }, 1221f0f5b5bSZachary Turner 1231f0f5b5bSZachary Turner { LLDB_OPT_EXPR_LANGUAGE, false, "language", 'L', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Specifies the Language to use when interpreting the breakpoint's expression " 1241f0f5b5bSZachary Turner "(note: currently only implemented for setting breakpoints on identifiers). " 1251f0f5b5bSZachary Turner "If not set the target.language setting is used." }, 1261f0f5b5bSZachary Turner { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "sKip the prologue if the breakpoint is at the beginning of a function. " 1271f0f5b5bSZachary Turner "If not set the target.skip-prologue setting is used." }, 1281f0f5b5bSZachary Turner { 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, " 1291f0f5b5bSZachary Turner "which prime new targets." }, 1301f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Adds this to the list of names for this breakpoint." }, 1311f0f5b5bSZachary Turner { LLDB_OPT_OFFSET_APPLIES, false, "address-slide", 'R', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddress, "Add the specified offset to whatever address(es) the breakpoint resolves to. " 1321f0f5b5bSZachary Turner "At present this applies the offset directly as given, and doesn't try to align it to instruction boundaries." }, 1331f0f5b5bSZachary Turner { LLDB_OPT_MOVE_TO_NEAREST_CODE, false, "move-to-nearest-code", 'm', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Move breakpoints to nearest code. If not set the target.move-to-nearest-code " 1341f0f5b5bSZachary Turner "setting is used." }, 1351f0f5b5bSZachary Turner // clang-format on 1361f0f5b5bSZachary Turner }; 1371f0f5b5bSZachary Turner 13830fdc8d8SChris Lattner //------------------------------------------------------------------------- 1395a988416SJim Ingham // CommandObjectBreakpointSet 14030fdc8d8SChris Lattner //------------------------------------------------------------------------- 14130fdc8d8SChris Lattner 142b9c1b51eSKate Stone class CommandObjectBreakpointSet : public CommandObjectParsed { 1435a988416SJim Ingham public: 144b9c1b51eSKate Stone typedef enum BreakpointSetType { 1455a988416SJim Ingham eSetTypeInvalid, 1465a988416SJim Ingham eSetTypeFileAndLine, 1475a988416SJim Ingham eSetTypeAddress, 1485a988416SJim Ingham eSetTypeFunctionName, 1495a988416SJim Ingham eSetTypeFunctionRegexp, 1505a988416SJim Ingham eSetTypeSourceRegexp, 1515a988416SJim Ingham eSetTypeException 1525a988416SJim Ingham } BreakpointSetType; 1535a988416SJim Ingham 154b9c1b51eSKate Stone CommandObjectBreakpointSet(CommandInterpreter &interpreter) 155b9c1b51eSKate Stone : CommandObjectParsed( 156b9c1b51eSKate Stone interpreter, "breakpoint set", 1575a988416SJim Ingham "Sets a breakpoint or set of breakpoints in the executable.", 1585a988416SJim Ingham "breakpoint set <cmd-options>"), 159b9c1b51eSKate Stone m_options() {} 1605a988416SJim Ingham 1619e85e5a8SEugene Zelenko ~CommandObjectBreakpointSet() override = default; 1625a988416SJim Ingham 163b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 1645a988416SJim Ingham 165b9c1b51eSKate Stone class CommandOptions : public Options { 1665a988416SJim Ingham public: 167b9c1b51eSKate Stone CommandOptions() 168b9c1b51eSKate Stone : Options(), m_condition(), m_filenames(), m_line_num(0), m_column(0), 169b9c1b51eSKate Stone m_func_names(), m_func_name_type_mask(eFunctionNameTypeNone), 170b9c1b51eSKate Stone m_func_regexp(), m_source_text_regexp(), m_modules(), m_load_addr(), 171b9c1b51eSKate Stone m_ignore_count(0), m_thread_id(LLDB_INVALID_THREAD_ID), 172b9c1b51eSKate Stone m_thread_index(UINT32_MAX), m_thread_name(), m_queue_name(), 173b9c1b51eSKate Stone m_catch_bp(false), m_throw_bp(true), m_hardware(false), 174a72b31c7SJim Ingham m_exception_language(eLanguageTypeUnknown), 17523b1decbSDawn Perchik m_language(lldb::eLanguageTypeUnknown), 176b9c1b51eSKate Stone m_skip_prologue(eLazyBoolCalculate), m_one_shot(false), 177b9c1b51eSKate Stone m_all_files(false), m_move_to_nearest_code(eLazyBoolCalculate) {} 17830fdc8d8SChris Lattner 1799e85e5a8SEugene Zelenko ~CommandOptions() override = default; 18087df91b8SJim Ingham 181b9c1b51eSKate Stone Error SetOptionValue(uint32_t option_idx, const char *option_arg, 182b9c1b51eSKate Stone ExecutionContext *execution_context) override { 18330fdc8d8SChris Lattner Error error; 1843bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 1856fa7681bSZachary Turner llvm::StringRef option_strref(option_arg ? option_arg : ""); 18630fdc8d8SChris Lattner 187b9c1b51eSKate Stone switch (short_option) { 188b9c1b51eSKate Stone case 'a': { 189b9c1b51eSKate Stone m_load_addr = Args::StringToAddress(execution_context, option_arg, 190e1cfbc79STodd Fiala LLDB_INVALID_ADDRESS, &error); 191b9c1b51eSKate Stone } break; 19230fdc8d8SChris Lattner 193e732052fSJim Ingham case 'A': 194e732052fSJim Ingham m_all_files = true; 195e732052fSJim Ingham break; 196e732052fSJim Ingham 197ca36cd16SJim Ingham case 'b': 198ca36cd16SJim Ingham m_func_names.push_back(option_arg); 199ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeBase; 200ca36cd16SJim Ingham break; 201ca36cd16SJim Ingham 202b9c1b51eSKate Stone case 'C': { 2036312991cSJim Ingham bool success; 2046312991cSJim Ingham m_column = StringConvert::ToUInt32(option_arg, 0, 0, &success); 2056312991cSJim Ingham if (!success) 206b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid column number: %s", 207b9c1b51eSKate Stone option_arg); 20830fdc8d8SChris Lattner break; 2096312991cSJim Ingham } 2109e85e5a8SEugene Zelenko 2117d49c9c8SJohnny Chen case 'c': 2127d49c9c8SJohnny Chen m_condition.assign(option_arg); 2137d49c9c8SJohnny Chen break; 2147d49c9c8SJohnny Chen 21533df7cd3SJim Ingham case 'D': 21633df7cd3SJim Ingham m_use_dummy = true; 21733df7cd3SJim Ingham break; 21833df7cd3SJim Ingham 219b9c1b51eSKate Stone case 'E': { 2200e0984eeSJim Ingham LanguageType language = Language::GetLanguageTypeFromString(option_arg); 221fab10e89SJim Ingham 222b9c1b51eSKate Stone switch (language) { 223fab10e89SJim Ingham case eLanguageTypeC89: 224fab10e89SJim Ingham case eLanguageTypeC: 225fab10e89SJim Ingham case eLanguageTypeC99: 2261d0089faSBruce Mitchener case eLanguageTypeC11: 227a72b31c7SJim Ingham m_exception_language = eLanguageTypeC; 228fab10e89SJim Ingham break; 229fab10e89SJim Ingham case eLanguageTypeC_plus_plus: 2301d0089faSBruce Mitchener case eLanguageTypeC_plus_plus_03: 2311d0089faSBruce Mitchener case eLanguageTypeC_plus_plus_11: 2322ba84a6aSBruce Mitchener case eLanguageTypeC_plus_plus_14: 233a72b31c7SJim Ingham m_exception_language = eLanguageTypeC_plus_plus; 234fab10e89SJim Ingham break; 235fab10e89SJim Ingham case eLanguageTypeObjC: 236a72b31c7SJim Ingham m_exception_language = eLanguageTypeObjC; 237fab10e89SJim Ingham break; 238fab10e89SJim Ingham case eLanguageTypeObjC_plus_plus: 239b9c1b51eSKate Stone error.SetErrorStringWithFormat( 240b9c1b51eSKate Stone "Set exception breakpoints separately for c++ and objective-c"); 241fab10e89SJim Ingham break; 242fab10e89SJim Ingham case eLanguageTypeUnknown: 243b9c1b51eSKate Stone error.SetErrorStringWithFormat( 244b9c1b51eSKate Stone "Unknown language type: '%s' for exception breakpoint", 245b9c1b51eSKate Stone option_arg); 246fab10e89SJim Ingham break; 247fab10e89SJim Ingham default: 248b9c1b51eSKate Stone error.SetErrorStringWithFormat( 249b9c1b51eSKate Stone "Unsupported language type: '%s' for exception breakpoint", 250b9c1b51eSKate Stone option_arg); 251fab10e89SJim Ingham } 252b9c1b51eSKate Stone } break; 253ca36cd16SJim Ingham 254ca36cd16SJim Ingham case 'f': 255ca36cd16SJim Ingham m_filenames.AppendIfUnique(FileSpec(option_arg, false)); 256fab10e89SJim Ingham break; 257ca36cd16SJim Ingham 258ca36cd16SJim Ingham case 'F': 259ca36cd16SJim Ingham m_func_names.push_back(option_arg); 260ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeFull; 261ca36cd16SJim Ingham break; 262ca36cd16SJim Ingham 263b9c1b51eSKate Stone case 'h': { 264fab10e89SJim Ingham bool success; 265ecbb0bb1SZachary Turner m_catch_bp = Args::StringToBoolean(option_strref, true, &success); 266fab10e89SJim Ingham if (!success) 267b9c1b51eSKate Stone error.SetErrorStringWithFormat( 268b9c1b51eSKate Stone "Invalid boolean value for on-catch option: '%s'", option_arg); 269b9c1b51eSKate Stone } break; 270eb023e75SGreg Clayton 271eb023e75SGreg Clayton case 'H': 272eb023e75SGreg Clayton m_hardware = true; 273eb023e75SGreg Clayton break; 274eb023e75SGreg Clayton 275ca36cd16SJim Ingham case 'i': 2765275aaa0SVince Harron m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); 277ca36cd16SJim Ingham if (m_ignore_count == UINT32_MAX) 278b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid ignore count '%s'", 279b9c1b51eSKate Stone option_arg); 280ca36cd16SJim Ingham break; 281ca36cd16SJim Ingham 282b9c1b51eSKate Stone case 'K': { 283a8558b62SJim Ingham bool success; 284a8558b62SJim Ingham bool value; 285ecbb0bb1SZachary Turner value = Args::StringToBoolean(option_strref, true, &success); 286a8558b62SJim Ingham if (value) 287a8558b62SJim Ingham m_skip_prologue = eLazyBoolYes; 288a8558b62SJim Ingham else 289a8558b62SJim Ingham m_skip_prologue = eLazyBoolNo; 290a8558b62SJim Ingham 291a8558b62SJim Ingham if (!success) 292b9c1b51eSKate Stone error.SetErrorStringWithFormat( 293b9c1b51eSKate Stone "Invalid boolean value for skip prologue option: '%s'", 294b9c1b51eSKate Stone option_arg); 295b9c1b51eSKate Stone } break; 296ca36cd16SJim Ingham 297b9c1b51eSKate Stone case 'l': { 2986312991cSJim Ingham bool success; 2996312991cSJim Ingham m_line_num = StringConvert::ToUInt32(option_arg, 0, 0, &success); 3006312991cSJim Ingham if (!success) 301b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid line number: %s.", 302b9c1b51eSKate Stone option_arg); 303ca36cd16SJim Ingham break; 3046312991cSJim Ingham } 305055ad9beSIlia K 30623b1decbSDawn Perchik case 'L': 3070e0984eeSJim Ingham m_language = Language::GetLanguageTypeFromString(option_arg); 30823b1decbSDawn Perchik if (m_language == eLanguageTypeUnknown) 309b9c1b51eSKate Stone error.SetErrorStringWithFormat( 310b9c1b51eSKate Stone "Unknown language type: '%s' for breakpoint", option_arg); 31123b1decbSDawn Perchik break; 31223b1decbSDawn Perchik 313b9c1b51eSKate Stone case 'm': { 314055ad9beSIlia K bool success; 315055ad9beSIlia K bool value; 316ecbb0bb1SZachary Turner value = Args::StringToBoolean(option_strref, true, &success); 317055ad9beSIlia K if (value) 318055ad9beSIlia K m_move_to_nearest_code = eLazyBoolYes; 319055ad9beSIlia K else 320055ad9beSIlia K m_move_to_nearest_code = eLazyBoolNo; 321055ad9beSIlia K 322055ad9beSIlia K if (!success) 323b9c1b51eSKate Stone error.SetErrorStringWithFormat( 324b9c1b51eSKate Stone "Invalid boolean value for move-to-nearest-code option: '%s'", 325b9c1b51eSKate Stone option_arg); 326055ad9beSIlia K break; 327055ad9beSIlia K } 328055ad9beSIlia K 329ca36cd16SJim Ingham case 'M': 330ca36cd16SJim Ingham m_func_names.push_back(option_arg); 331ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeMethod; 332ca36cd16SJim Ingham break; 333ca36cd16SJim Ingham 334ca36cd16SJim Ingham case 'n': 335ca36cd16SJim Ingham m_func_names.push_back(option_arg); 336ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeAuto; 337ca36cd16SJim Ingham break; 338ca36cd16SJim Ingham 3396fa7681bSZachary Turner case 'N': { 3406fa7681bSZachary Turner if (BreakpointID::StringIsBreakpointName(option_strref, error)) 3415e09c8c3SJim Ingham m_breakpoint_names.push_back(option_arg); 342ff9a91eaSJim Ingham else 343ff9a91eaSJim Ingham error.SetErrorStringWithFormat("Invalid breakpoint name: %s", 344ff9a91eaSJim Ingham option_arg); 3455e09c8c3SJim Ingham break; 3466fa7681bSZachary Turner } 3475e09c8c3SJim Ingham 348b9c1b51eSKate Stone case 'R': { 3492411167fSJim Ingham lldb::addr_t tmp_offset_addr; 350e1cfbc79STodd Fiala tmp_offset_addr = 351b9c1b51eSKate Stone Args::StringToAddress(execution_context, option_arg, 0, &error); 3522411167fSJim Ingham if (error.Success()) 3532411167fSJim Ingham m_offset_addr = tmp_offset_addr; 354b9c1b51eSKate Stone } break; 3552411167fSJim Ingham 356ca36cd16SJim Ingham case 'o': 357ca36cd16SJim Ingham m_one_shot = true; 358ca36cd16SJim Ingham break; 359ca36cd16SJim Ingham 360a72b31c7SJim Ingham case 'O': 361ecbb0bb1SZachary Turner m_exception_extra_args.AppendArgument(llvm::StringRef("-O")); 362ecbb0bb1SZachary Turner m_exception_extra_args.AppendArgument(option_strref); 363a72b31c7SJim Ingham break; 364a72b31c7SJim Ingham 365ca36cd16SJim Ingham case 'p': 366ca36cd16SJim Ingham m_source_text_regexp.assign(option_arg); 367ca36cd16SJim Ingham break; 368ca36cd16SJim Ingham 369ca36cd16SJim Ingham case 'q': 370ca36cd16SJim Ingham m_queue_name.assign(option_arg); 371ca36cd16SJim Ingham break; 372ca36cd16SJim Ingham 373ca36cd16SJim Ingham case 'r': 374ca36cd16SJim Ingham m_func_regexp.assign(option_arg); 375ca36cd16SJim Ingham break; 376ca36cd16SJim Ingham 377ca36cd16SJim Ingham case 's': 378ca36cd16SJim Ingham m_modules.AppendIfUnique(FileSpec(option_arg, false)); 379ca36cd16SJim Ingham break; 380ca36cd16SJim Ingham 381ca36cd16SJim Ingham case 'S': 382ca36cd16SJim Ingham m_func_names.push_back(option_arg); 383ca36cd16SJim Ingham m_func_name_type_mask |= eFunctionNameTypeSelector; 384ca36cd16SJim Ingham break; 385ca36cd16SJim Ingham 386ca36cd16SJim Ingham case 't': 387b9c1b51eSKate Stone m_thread_id = 388b9c1b51eSKate Stone StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 389ca36cd16SJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 390b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid thread id string '%s'", 391b9c1b51eSKate Stone option_arg); 392ca36cd16SJim Ingham break; 393ca36cd16SJim Ingham 394ca36cd16SJim Ingham case 'T': 395ca36cd16SJim Ingham m_thread_name.assign(option_arg); 396ca36cd16SJim Ingham break; 397ca36cd16SJim Ingham 398b9c1b51eSKate Stone case 'w': { 399ca36cd16SJim Ingham bool success; 400ecbb0bb1SZachary Turner m_throw_bp = Args::StringToBoolean(option_strref, true, &success); 401ca36cd16SJim Ingham if (!success) 402b9c1b51eSKate Stone error.SetErrorStringWithFormat( 403b9c1b51eSKate Stone "Invalid boolean value for on-throw option: '%s'", option_arg); 404b9c1b51eSKate Stone } break; 405ca36cd16SJim Ingham 406ca36cd16SJim Ingham case 'x': 4075275aaa0SVince Harron m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); 408ca36cd16SJim Ingham if (m_thread_id == UINT32_MAX) 409b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid thread index string '%s'", 410b9c1b51eSKate Stone option_arg); 411ca36cd16SJim Ingham break; 412ca36cd16SJim Ingham 41376bb8d67SJim Ingham case 'X': 41476bb8d67SJim Ingham m_source_regex_func_names.insert(option_arg); 41576bb8d67SJim Ingham break; 41676bb8d67SJim Ingham 41730fdc8d8SChris Lattner default: 418b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 419b9c1b51eSKate Stone short_option); 42030fdc8d8SChris Lattner break; 42130fdc8d8SChris Lattner } 42230fdc8d8SChris Lattner 42330fdc8d8SChris Lattner return error; 42430fdc8d8SChris Lattner } 4259e85e5a8SEugene Zelenko 426b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 4277d49c9c8SJohnny Chen m_condition.clear(); 42887df91b8SJim Ingham m_filenames.Clear(); 42930fdc8d8SChris Lattner m_line_num = 0; 43030fdc8d8SChris Lattner m_column = 0; 431fab10e89SJim Ingham m_func_names.clear(); 4321f746071SGreg Clayton m_func_name_type_mask = eFunctionNameTypeNone; 43330fdc8d8SChris Lattner m_func_regexp.clear(); 4341f746071SGreg Clayton m_source_text_regexp.clear(); 43587df91b8SJim Ingham m_modules.Clear(); 4361f746071SGreg Clayton m_load_addr = LLDB_INVALID_ADDRESS; 4372411167fSJim Ingham m_offset_addr = 0; 438c982c768SGreg Clayton m_ignore_count = 0; 4391b54c88cSJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 440c982c768SGreg Clayton m_thread_index = UINT32_MAX; 4411b54c88cSJim Ingham m_thread_name.clear(); 4421b54c88cSJim Ingham m_queue_name.clear(); 443fab10e89SJim Ingham m_catch_bp = false; 444fab10e89SJim Ingham m_throw_bp = true; 445eb023e75SGreg Clayton m_hardware = false; 446a72b31c7SJim Ingham m_exception_language = eLanguageTypeUnknown; 44723b1decbSDawn Perchik m_language = lldb::eLanguageTypeUnknown; 448a8558b62SJim Ingham m_skip_prologue = eLazyBoolCalculate; 449ca36cd16SJim Ingham m_one_shot = false; 45033df7cd3SJim Ingham m_use_dummy = false; 4515e09c8c3SJim Ingham m_breakpoint_names.clear(); 452e732052fSJim Ingham m_all_files = false; 453a72b31c7SJim Ingham m_exception_extra_args.Clear(); 454055ad9beSIlia K m_move_to_nearest_code = eLazyBoolCalculate; 45576bb8d67SJim Ingham m_source_regex_func_names.clear(); 45630fdc8d8SChris Lattner } 45730fdc8d8SChris Lattner 4581f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 45970602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_set_options); 4601f0f5b5bSZachary Turner } 46130fdc8d8SChris Lattner 4625a988416SJim Ingham // Instance variables to hold the values for command options. 463969795f1SJim Ingham 4645a988416SJim Ingham std::string m_condition; 4655a988416SJim Ingham FileSpecList m_filenames; 4665a988416SJim Ingham uint32_t m_line_num; 4675a988416SJim Ingham uint32_t m_column; 4685a988416SJim Ingham std::vector<std::string> m_func_names; 4695e09c8c3SJim Ingham std::vector<std::string> m_breakpoint_names; 4705a988416SJim Ingham uint32_t m_func_name_type_mask; 4715a988416SJim Ingham std::string m_func_regexp; 4725a988416SJim Ingham std::string m_source_text_regexp; 4735a988416SJim Ingham FileSpecList m_modules; 4745a988416SJim Ingham lldb::addr_t m_load_addr; 4752411167fSJim Ingham lldb::addr_t m_offset_addr; 4765a988416SJim Ingham uint32_t m_ignore_count; 4775a988416SJim Ingham lldb::tid_t m_thread_id; 4785a988416SJim Ingham uint32_t m_thread_index; 4795a988416SJim Ingham std::string m_thread_name; 4805a988416SJim Ingham std::string m_queue_name; 4815a988416SJim Ingham bool m_catch_bp; 4825a988416SJim Ingham bool m_throw_bp; 483eb023e75SGreg Clayton bool m_hardware; // Request to use hardware breakpoints 484a72b31c7SJim Ingham lldb::LanguageType m_exception_language; 48523b1decbSDawn Perchik lldb::LanguageType m_language; 4865a988416SJim Ingham LazyBool m_skip_prologue; 487ca36cd16SJim Ingham bool m_one_shot; 48833df7cd3SJim Ingham bool m_use_dummy; 489e732052fSJim Ingham bool m_all_files; 490a72b31c7SJim Ingham Args m_exception_extra_args; 491055ad9beSIlia K LazyBool m_move_to_nearest_code; 49276bb8d67SJim Ingham std::unordered_set<std::string> m_source_regex_func_names; 4935a988416SJim Ingham }; 4945a988416SJim Ingham 4955a988416SJim Ingham protected: 496b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 49733df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 49833df7cd3SJim Ingham 499b9c1b51eSKate Stone if (target == nullptr) { 500b9c1b51eSKate Stone result.AppendError("Invalid target. Must set target before setting " 501b9c1b51eSKate Stone "breakpoints (see 'target create' command)."); 50230fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 50330fdc8d8SChris Lattner return false; 50430fdc8d8SChris Lattner } 50530fdc8d8SChris Lattner 50630fdc8d8SChris Lattner // The following are the various types of breakpoints that could be set: 50730fdc8d8SChris Lattner // 1). -f -l -p [-s -g] (setting breakpoint by source location) 50830fdc8d8SChris Lattner // 2). -a [-s -g] (setting breakpoint by address) 50930fdc8d8SChris Lattner // 3). -n [-s -g] (setting breakpoint by function name) 510b9c1b51eSKate Stone // 4). -r [-s -g] (setting breakpoint by function name regular 511b9c1b51eSKate Stone // expression) 512b9c1b51eSKate Stone // 5). -p -f (setting a breakpoint by comparing a reg-exp 513b9c1b51eSKate Stone // to source text) 514b9c1b51eSKate Stone // 6). -E [-w -h] (setting a breakpoint for exceptions for a 515b9c1b51eSKate Stone // given language.) 51630fdc8d8SChris Lattner 51730fdc8d8SChris Lattner BreakpointSetType break_type = eSetTypeInvalid; 51830fdc8d8SChris Lattner 51930fdc8d8SChris Lattner if (m_options.m_line_num != 0) 52030fdc8d8SChris Lattner break_type = eSetTypeFileAndLine; 52130fdc8d8SChris Lattner else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) 52230fdc8d8SChris Lattner break_type = eSetTypeAddress; 523fab10e89SJim Ingham else if (!m_options.m_func_names.empty()) 52430fdc8d8SChris Lattner break_type = eSetTypeFunctionName; 52530fdc8d8SChris Lattner else if (!m_options.m_func_regexp.empty()) 52630fdc8d8SChris Lattner break_type = eSetTypeFunctionRegexp; 527969795f1SJim Ingham else if (!m_options.m_source_text_regexp.empty()) 528969795f1SJim Ingham break_type = eSetTypeSourceRegexp; 529a72b31c7SJim Ingham else if (m_options.m_exception_language != eLanguageTypeUnknown) 530fab10e89SJim Ingham break_type = eSetTypeException; 53130fdc8d8SChris Lattner 5329e85e5a8SEugene Zelenko Breakpoint *bp = nullptr; 533274060b6SGreg Clayton FileSpec module_spec; 534a8558b62SJim Ingham const bool internal = false; 535a8558b62SJim Ingham 536b9c1b51eSKate Stone // If the user didn't specify skip-prologue, having an offset should turn 537b9c1b51eSKate Stone // that off. 538b9c1b51eSKate Stone if (m_options.m_offset_addr != 0 && 539b9c1b51eSKate Stone m_options.m_skip_prologue == eLazyBoolCalculate) 5402411167fSJim Ingham m_options.m_skip_prologue = eLazyBoolNo; 5412411167fSJim Ingham 542b9c1b51eSKate Stone switch (break_type) { 54330fdc8d8SChris Lattner case eSetTypeFileAndLine: // Breakpoint by source position 54430fdc8d8SChris Lattner { 54530fdc8d8SChris Lattner FileSpec file; 546c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 547b9c1b51eSKate Stone if (num_files == 0) { 548b9c1b51eSKate Stone if (!GetDefaultFile(target, file, result)) { 54987df91b8SJim Ingham result.AppendError("No file supplied and no default file available."); 55087df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 55187df91b8SJim Ingham return false; 55287df91b8SJim Ingham } 553b9c1b51eSKate Stone } else if (num_files > 1) { 554b9c1b51eSKate Stone result.AppendError("Only one file at a time is allowed for file and " 555b9c1b51eSKate Stone "line breakpoints."); 55687df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 55787df91b8SJim Ingham return false; 558b9c1b51eSKate Stone } else 55987df91b8SJim Ingham file = m_options.m_filenames.GetFileSpecAtIndex(0); 56030fdc8d8SChris Lattner 5611f746071SGreg Clayton // Only check for inline functions if 5621f746071SGreg Clayton LazyBool check_inlines = eLazyBoolCalculate; 5631f746071SGreg Clayton 564b9c1b51eSKate Stone bp = target 565b9c1b51eSKate Stone ->CreateBreakpoint(&(m_options.m_modules), file, 566b9c1b51eSKate Stone m_options.m_line_num, m_options.m_offset_addr, 567b9c1b51eSKate Stone check_inlines, m_options.m_skip_prologue, 568b9c1b51eSKate Stone internal, m_options.m_hardware, 569b9c1b51eSKate Stone m_options.m_move_to_nearest_code) 570b9c1b51eSKate Stone .get(); 571b9c1b51eSKate Stone } break; 5726eee5aa0SGreg Clayton 57330fdc8d8SChris Lattner case eSetTypeAddress: // Breakpoint by address 574055a08a4SJim Ingham { 575b9c1b51eSKate Stone // If a shared library has been specified, make an lldb_private::Address 576b9c1b51eSKate Stone // with the library, and 577b9c1b51eSKate Stone // use that. That way the address breakpoint will track the load location 578b9c1b51eSKate Stone // of the library. 579055a08a4SJim Ingham size_t num_modules_specified = m_options.m_modules.GetSize(); 580b9c1b51eSKate Stone if (num_modules_specified == 1) { 581b9c1b51eSKate Stone const FileSpec *file_spec = 582b9c1b51eSKate Stone m_options.m_modules.GetFileSpecPointerAtIndex(0); 583b9c1b51eSKate Stone bp = target 584b9c1b51eSKate Stone ->CreateAddressInModuleBreakpoint(m_options.m_load_addr, 585b9c1b51eSKate Stone internal, file_spec, 586b9c1b51eSKate Stone m_options.m_hardware) 587b9c1b51eSKate Stone .get(); 588b9c1b51eSKate Stone } else if (num_modules_specified == 0) { 589b9c1b51eSKate Stone bp = target 590b9c1b51eSKate Stone ->CreateBreakpoint(m_options.m_load_addr, internal, 591b9c1b51eSKate Stone m_options.m_hardware) 592b9c1b51eSKate Stone .get(); 593b9c1b51eSKate Stone } else { 594b9c1b51eSKate Stone result.AppendError("Only one shared library can be specified for " 595b9c1b51eSKate Stone "address breakpoints."); 596055a08a4SJim Ingham result.SetStatus(eReturnStatusFailed); 597055a08a4SJim Ingham return false; 598055a08a4SJim Ingham } 59930fdc8d8SChris Lattner break; 600055a08a4SJim Ingham } 60130fdc8d8SChris Lattner case eSetTypeFunctionName: // Breakpoint by function name 6020c5cd90dSGreg Clayton { 6030c5cd90dSGreg Clayton uint32_t name_type_mask = m_options.m_func_name_type_mask; 6040c5cd90dSGreg Clayton 6050c5cd90dSGreg Clayton if (name_type_mask == 0) 606e02b8504SGreg Clayton name_type_mask = eFunctionNameTypeAuto; 6070c5cd90dSGreg Clayton 608b9c1b51eSKate Stone bp = target 609b9c1b51eSKate Stone ->CreateBreakpoint( 610b9c1b51eSKate Stone &(m_options.m_modules), &(m_options.m_filenames), 611b9c1b51eSKate Stone m_options.m_func_names, name_type_mask, m_options.m_language, 612b9c1b51eSKate Stone m_options.m_offset_addr, m_options.m_skip_prologue, internal, 613b9c1b51eSKate Stone m_options.m_hardware) 614b9c1b51eSKate Stone .get(); 615b9c1b51eSKate Stone } break; 6160c5cd90dSGreg Clayton 617b9c1b51eSKate Stone case eSetTypeFunctionRegexp: // Breakpoint by regular expression function 618b9c1b51eSKate Stone // name 61930fdc8d8SChris Lattner { 62095eae423SZachary Turner RegularExpression regexp(m_options.m_func_regexp); 621b9c1b51eSKate Stone if (!regexp.IsValid()) { 622969795f1SJim Ingham char err_str[1024]; 623969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 624b9c1b51eSKate Stone result.AppendErrorWithFormat( 625b9c1b51eSKate Stone "Function name regular expression could not be compiled: \"%s\"", 626969795f1SJim Ingham err_str); 62730fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 628969795f1SJim Ingham return false; 62930fdc8d8SChris Lattner } 63087df91b8SJim Ingham 631b9c1b51eSKate Stone bp = target 632b9c1b51eSKate Stone ->CreateFuncRegexBreakpoint( 633b9c1b51eSKate Stone &(m_options.m_modules), &(m_options.m_filenames), regexp, 634b9c1b51eSKate Stone m_options.m_language, m_options.m_skip_prologue, internal, 635b9c1b51eSKate Stone m_options.m_hardware) 636b9c1b51eSKate Stone .get(); 637e14dc268SJim Ingham } 638e14dc268SJim Ingham break; 639969795f1SJim Ingham case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. 640969795f1SJim Ingham { 641c7bece56SGreg Clayton const size_t num_files = m_options.m_filenames.GetSize(); 64287df91b8SJim Ingham 643b9c1b51eSKate Stone if (num_files == 0 && !m_options.m_all_files) { 644969795f1SJim Ingham FileSpec file; 645b9c1b51eSKate Stone if (!GetDefaultFile(target, file, result)) { 646b9c1b51eSKate Stone result.AppendError( 647b9c1b51eSKate Stone "No files provided and could not find default file."); 64887df91b8SJim Ingham result.SetStatus(eReturnStatusFailed); 64987df91b8SJim Ingham return false; 650b9c1b51eSKate Stone } else { 65187df91b8SJim Ingham m_options.m_filenames.Append(file); 65287df91b8SJim Ingham } 65387df91b8SJim Ingham } 6540c5cd90dSGreg Clayton 65595eae423SZachary Turner RegularExpression regexp(m_options.m_source_text_regexp); 656b9c1b51eSKate Stone if (!regexp.IsValid()) { 657969795f1SJim Ingham char err_str[1024]; 658969795f1SJim Ingham regexp.GetErrorAsCString(err_str, sizeof(err_str)); 659b9c1b51eSKate Stone result.AppendErrorWithFormat( 660b9c1b51eSKate Stone "Source text regular expression could not be compiled: \"%s\"", 661969795f1SJim Ingham err_str); 662969795f1SJim Ingham result.SetStatus(eReturnStatusFailed); 663969795f1SJim Ingham return false; 664969795f1SJim Ingham } 665b9c1b51eSKate Stone bp = target 666b9c1b51eSKate Stone ->CreateSourceRegexBreakpoint( 667b9c1b51eSKate Stone &(m_options.m_modules), &(m_options.m_filenames), 668b9c1b51eSKate Stone m_options.m_source_regex_func_names, regexp, internal, 669b9c1b51eSKate Stone m_options.m_hardware, m_options.m_move_to_nearest_code) 670b9c1b51eSKate Stone .get(); 671b9c1b51eSKate Stone } break; 672b9c1b51eSKate Stone case eSetTypeException: { 673a72b31c7SJim Ingham Error precond_error; 674b9c1b51eSKate Stone bp = target 675b9c1b51eSKate Stone ->CreateExceptionBreakpoint( 676b9c1b51eSKate Stone m_options.m_exception_language, m_options.m_catch_bp, 677b9c1b51eSKate Stone m_options.m_throw_bp, internal, 678b9c1b51eSKate Stone &m_options.m_exception_extra_args, &precond_error) 679b9c1b51eSKate Stone .get(); 680b9c1b51eSKate Stone if (precond_error.Fail()) { 681b9c1b51eSKate Stone result.AppendErrorWithFormat( 682b9c1b51eSKate Stone "Error setting extra exception arguments: %s", 683a72b31c7SJim Ingham precond_error.AsCString()); 684a72b31c7SJim Ingham target->RemoveBreakpointByID(bp->GetID()); 685a72b31c7SJim Ingham result.SetStatus(eReturnStatusFailed); 686a72b31c7SJim Ingham return false; 687a72b31c7SJim Ingham } 688b9c1b51eSKate Stone } break; 68930fdc8d8SChris Lattner default: 69030fdc8d8SChris Lattner break; 69130fdc8d8SChris Lattner } 69230fdc8d8SChris Lattner 6931b54c88cSJim Ingham // Now set the various options that were passed in: 694b9c1b51eSKate Stone if (bp) { 6951b54c88cSJim Ingham if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) 6961b54c88cSJim Ingham bp->SetThreadID(m_options.m_thread_id); 6971b54c88cSJim Ingham 698c982c768SGreg Clayton if (m_options.m_thread_index != UINT32_MAX) 6991b54c88cSJim Ingham bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); 7001b54c88cSJim Ingham 7011b54c88cSJim Ingham if (!m_options.m_thread_name.empty()) 702b9c1b51eSKate Stone bp->GetOptions()->GetThreadSpec()->SetName( 703b9c1b51eSKate Stone m_options.m_thread_name.c_str()); 7041b54c88cSJim Ingham 7051b54c88cSJim Ingham if (!m_options.m_queue_name.empty()) 706b9c1b51eSKate Stone bp->GetOptions()->GetThreadSpec()->SetQueueName( 707b9c1b51eSKate Stone m_options.m_queue_name.c_str()); 7081b54c88cSJim Ingham 709c982c768SGreg Clayton if (m_options.m_ignore_count != 0) 7101b54c88cSJim Ingham bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); 7117d49c9c8SJohnny Chen 7127d49c9c8SJohnny Chen if (!m_options.m_condition.empty()) 7137d49c9c8SJohnny Chen bp->GetOptions()->SetCondition(m_options.m_condition.c_str()); 714ca36cd16SJim Ingham 715b9c1b51eSKate Stone if (!m_options.m_breakpoint_names.empty()) { 716ff9a91eaSJim Ingham Error name_error; 717ff9a91eaSJim Ingham for (auto name : m_options.m_breakpoint_names) { 718ff9a91eaSJim Ingham bp->AddName(name.c_str(), name_error); 719ff9a91eaSJim Ingham if (name_error.Fail()) { 720ff9a91eaSJim Ingham result.AppendErrorWithFormat("Invalid breakpoint name: %s", 721ff9a91eaSJim Ingham name.c_str()); 722ff9a91eaSJim Ingham target->RemoveBreakpointByID(bp->GetID()); 723ff9a91eaSJim Ingham result.SetStatus(eReturnStatusFailed); 724ff9a91eaSJim Ingham return false; 725ff9a91eaSJim Ingham } 726ff9a91eaSJim Ingham } 7275e09c8c3SJim Ingham } 7285e09c8c3SJim Ingham 729ca36cd16SJim Ingham bp->SetOneShot(m_options.m_one_shot); 7301b54c88cSJim Ingham } 7311b54c88cSJim Ingham 732b9c1b51eSKate Stone if (bp) { 73385e8b814SJim Ingham Stream &output_stream = result.GetOutputStream(); 7341391cc7dSJim Ingham const bool show_locations = false; 735b9c1b51eSKate Stone bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, 736b9c1b51eSKate Stone show_locations); 7374aeb1989SJim Ingham if (target == m_interpreter.GetDebugger().GetDummyTarget()) 738b9c1b51eSKate Stone output_stream.Printf("Breakpoint set in dummy target, will get copied " 739b9c1b51eSKate Stone "into future targets.\n"); 740b9c1b51eSKate Stone else { 741b9c1b51eSKate Stone // Don't print out this warning for exception breakpoints. They can get 742b9c1b51eSKate Stone // set before the target 743b9c1b51eSKate Stone // is set, but we won't know how to actually set the breakpoint till we 744b9c1b51eSKate Stone // run. 745b9c1b51eSKate Stone if (bp->GetNumLocations() == 0 && break_type != eSetTypeException) { 746b9c1b51eSKate Stone output_stream.Printf("WARNING: Unable to resolve breakpoint to any " 747b9c1b51eSKate Stone "actual locations.\n"); 7484aeb1989SJim Ingham } 7494aeb1989SJim Ingham } 75030fdc8d8SChris Lattner result.SetStatus(eReturnStatusSuccessFinishResult); 751b9c1b51eSKate Stone } else if (!bp) { 75230fdc8d8SChris Lattner result.AppendError("Breakpoint creation failed: No breakpoint created."); 75330fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 75430fdc8d8SChris Lattner } 75530fdc8d8SChris Lattner 75630fdc8d8SChris Lattner return result.Succeeded(); 75730fdc8d8SChris Lattner } 75830fdc8d8SChris Lattner 7595a988416SJim Ingham private: 760b9c1b51eSKate Stone bool GetDefaultFile(Target *target, FileSpec &file, 761b9c1b51eSKate Stone CommandReturnObject &result) { 7625a988416SJim Ingham uint32_t default_line; 7635a988416SJim Ingham // First use the Source Manager's default file. 7645a988416SJim Ingham // Then use the current stack frame's file. 765b9c1b51eSKate Stone if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) { 766b57e4a1bSJason Molenda StackFrame *cur_frame = m_exe_ctx.GetFramePtr(); 767b9c1b51eSKate Stone if (cur_frame == nullptr) { 768b9c1b51eSKate Stone result.AppendError( 769b9c1b51eSKate Stone "No selected frame to use to find the default file."); 7705a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 7715a988416SJim Ingham return false; 772b9c1b51eSKate Stone } else if (!cur_frame->HasDebugInformation()) { 773b9c1b51eSKate Stone result.AppendError("Cannot use the selected frame to find the default " 774b9c1b51eSKate Stone "file, it has no debug info."); 7755a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 7765a988416SJim Ingham return false; 777b9c1b51eSKate Stone } else { 778b9c1b51eSKate Stone const SymbolContext &sc = 779b9c1b51eSKate Stone cur_frame->GetSymbolContext(eSymbolContextLineEntry); 780b9c1b51eSKate Stone if (sc.line_entry.file) { 7815a988416SJim Ingham file = sc.line_entry.file; 782b9c1b51eSKate Stone } else { 783b9c1b51eSKate Stone result.AppendError("Can't find the file for the selected frame to " 784b9c1b51eSKate Stone "use as the default file."); 7855a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 7865a988416SJim Ingham return false; 7875a988416SJim Ingham } 7885a988416SJim Ingham } 7895a988416SJim Ingham } 7905a988416SJim Ingham return true; 7915a988416SJim Ingham } 7925a988416SJim Ingham 7935a988416SJim Ingham CommandOptions m_options; 7945a988416SJim Ingham }; 7959e85e5a8SEugene Zelenko 7965a988416SJim Ingham //------------------------------------------------------------------------- 7975a988416SJim Ingham // CommandObjectBreakpointModify 7985a988416SJim Ingham //------------------------------------------------------------------------- 7991f0f5b5bSZachary Turner 8001f0f5b5bSZachary Turner #pragma mark Modify::CommandOptions 8011f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_modify_options[] = { 8021f0f5b5bSZachary Turner // clang-format off 8031f0f5b5bSZachary Turner { 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." }, 8041f0f5b5bSZachary Turner { 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." }, 8051f0f5b5bSZachary Turner { 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." }, 8061f0f5b5bSZachary Turner { 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." }, 8071f0f5b5bSZachary Turner { 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." }, 8081f0f5b5bSZachary Turner { 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." }, 8091f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true." }, 8101f0f5b5bSZachary Turner { LLDB_OPT_SET_1, false, "enable", 'e', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable the breakpoint." }, 8111f0f5b5bSZachary Turner { LLDB_OPT_SET_2, false, "disable", 'd', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Disable the breakpoint." }, 8121f0f5b5bSZachary Turner { 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." }, 8131f0f5b5bSZachary Turner // clang-format on 8141f0f5b5bSZachary Turner }; 8151f0f5b5bSZachary Turner 8165a988416SJim Ingham #pragma mark Modify 8175a988416SJim Ingham 818b9c1b51eSKate Stone class CommandObjectBreakpointModify : public CommandObjectParsed { 8195a988416SJim Ingham public: 820b9c1b51eSKate Stone CommandObjectBreakpointModify(CommandInterpreter &interpreter) 821b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "breakpoint modify", 822b9c1b51eSKate Stone "Modify the options on a breakpoint or set of " 823b9c1b51eSKate Stone "breakpoints in the executable. " 824b9c1b51eSKate Stone "If no breakpoint is specified, acts on the last " 825b9c1b51eSKate Stone "created breakpoint. " 826b9c1b51eSKate Stone "With the exception of -e, -d and -i, passing an " 827b9c1b51eSKate Stone "empty argument clears the modification.", 8289e85e5a8SEugene Zelenko nullptr), 829b9c1b51eSKate Stone m_options() { 8305a988416SJim Ingham CommandArgumentEntry arg; 831b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 832b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 833b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 834b9c1b51eSKate Stone // arguments vector. 8355a988416SJim Ingham m_arguments.push_back(arg); 8365a988416SJim Ingham } 8375a988416SJim Ingham 8389e85e5a8SEugene Zelenko ~CommandObjectBreakpointModify() override = default; 8395a988416SJim Ingham 840b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 8415a988416SJim Ingham 842b9c1b51eSKate Stone class CommandOptions : public Options { 8435a988416SJim Ingham public: 844b9c1b51eSKate Stone CommandOptions() 845b9c1b51eSKate Stone : Options(), m_ignore_count(0), m_thread_id(LLDB_INVALID_THREAD_ID), 846b9c1b51eSKate Stone m_thread_id_passed(false), m_thread_index(UINT32_MAX), 847b9c1b51eSKate Stone m_thread_index_passed(false), m_thread_name(), m_queue_name(), 848b9c1b51eSKate Stone m_condition(), m_one_shot(false), m_enable_passed(false), 849b9c1b51eSKate Stone m_enable_value(false), m_name_passed(false), m_queue_passed(false), 850b9c1b51eSKate Stone m_condition_passed(false), m_one_shot_passed(false), 851b9c1b51eSKate Stone m_use_dummy(false) {} 8525a988416SJim Ingham 8539e85e5a8SEugene Zelenko ~CommandOptions() override = default; 8545a988416SJim Ingham 855b9c1b51eSKate Stone Error SetOptionValue(uint32_t option_idx, const char *option_arg, 856b9c1b51eSKate Stone ExecutionContext *execution_context) override { 8575a988416SJim Ingham Error error; 8583bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 8595a988416SJim Ingham 860b9c1b51eSKate Stone switch (short_option) { 8615a988416SJim Ingham case 'c': 8629e85e5a8SEugene Zelenko if (option_arg != nullptr) 8635a988416SJim Ingham m_condition.assign(option_arg); 8645a988416SJim Ingham else 8655a988416SJim Ingham m_condition.clear(); 8665a988416SJim Ingham m_condition_passed = true; 8675a988416SJim Ingham break; 8685a988416SJim Ingham case 'd': 8695a988416SJim Ingham m_enable_passed = true; 8705a988416SJim Ingham m_enable_value = false; 8715a988416SJim Ingham break; 87233df7cd3SJim Ingham case 'D': 87333df7cd3SJim Ingham m_use_dummy = true; 87433df7cd3SJim Ingham break; 8755a988416SJim Ingham case 'e': 8765a988416SJim Ingham m_enable_passed = true; 8775a988416SJim Ingham m_enable_value = true; 8785a988416SJim Ingham break; 8795a988416SJim Ingham case 'i': 8805275aaa0SVince Harron m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); 8815a988416SJim Ingham if (m_ignore_count == UINT32_MAX) 882b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid ignore count '%s'", 883b9c1b51eSKate Stone option_arg); 8845a988416SJim Ingham break; 885b9c1b51eSKate Stone case 'o': { 886ca36cd16SJim Ingham bool value, success; 887ecbb0bb1SZachary Turner value = Args::StringToBoolean( 888ecbb0bb1SZachary Turner llvm::StringRef::withNullAsEmpty(option_arg), false, &success); 889b9c1b51eSKate Stone if (success) { 890ca36cd16SJim Ingham m_one_shot_passed = true; 891ca36cd16SJim Ingham m_one_shot = value; 892b9c1b51eSKate Stone } else 893b9c1b51eSKate Stone error.SetErrorStringWithFormat( 894b9c1b51eSKate Stone "invalid boolean value '%s' passed for -o option", option_arg); 895b9c1b51eSKate Stone } break; 8965a988416SJim Ingham case 't': 897b9c1b51eSKate Stone if (option_arg[0] == '\0') { 8985a988416SJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 8995a988416SJim Ingham m_thread_id_passed = true; 900b9c1b51eSKate Stone } else { 901b9c1b51eSKate Stone m_thread_id = 902b9c1b51eSKate Stone StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); 9035a988416SJim Ingham if (m_thread_id == LLDB_INVALID_THREAD_ID) 904b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid thread id string '%s'", 905b9c1b51eSKate Stone option_arg); 9065a988416SJim Ingham else 9075a988416SJim Ingham m_thread_id_passed = true; 9085a988416SJim Ingham } 9095a988416SJim Ingham break; 9105a988416SJim Ingham case 'T': 9119e85e5a8SEugene Zelenko if (option_arg != nullptr) 9125a988416SJim Ingham m_thread_name.assign(option_arg); 9135a988416SJim Ingham else 9145a988416SJim Ingham m_thread_name.clear(); 9155a988416SJim Ingham m_name_passed = true; 9165a988416SJim Ingham break; 9175a988416SJim Ingham case 'q': 9189e85e5a8SEugene Zelenko if (option_arg != nullptr) 9195a988416SJim Ingham m_queue_name.assign(option_arg); 9205a988416SJim Ingham else 9215a988416SJim Ingham m_queue_name.clear(); 9225a988416SJim Ingham m_queue_passed = true; 9235a988416SJim Ingham break; 9245a988416SJim Ingham case 'x': 925b9c1b51eSKate Stone if (option_arg[0] == '\n') { 9265a988416SJim Ingham m_thread_index = UINT32_MAX; 9275a988416SJim Ingham m_thread_index_passed = true; 928b9c1b51eSKate Stone } else { 9295275aaa0SVince Harron m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); 9305a988416SJim Ingham if (m_thread_id == UINT32_MAX) 931b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid thread index string '%s'", 932b9c1b51eSKate Stone option_arg); 9335a988416SJim Ingham else 9345a988416SJim Ingham m_thread_index_passed = true; 9355a988416SJim Ingham } 9365a988416SJim Ingham break; 9375a988416SJim Ingham default: 938b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 939b9c1b51eSKate Stone short_option); 9405a988416SJim Ingham break; 9415a988416SJim Ingham } 9425a988416SJim Ingham 9435a988416SJim Ingham return error; 9445a988416SJim Ingham } 9459e85e5a8SEugene Zelenko 946b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 9475a988416SJim Ingham m_ignore_count = 0; 9485a988416SJim Ingham m_thread_id = LLDB_INVALID_THREAD_ID; 9495a988416SJim Ingham m_thread_id_passed = false; 9505a988416SJim Ingham m_thread_index = UINT32_MAX; 9515a988416SJim Ingham m_thread_index_passed = false; 9525a988416SJim Ingham m_thread_name.clear(); 9535a988416SJim Ingham m_queue_name.clear(); 9545a988416SJim Ingham m_condition.clear(); 955ca36cd16SJim Ingham m_one_shot = false; 9565a988416SJim Ingham m_enable_passed = false; 9575a988416SJim Ingham m_queue_passed = false; 9585a988416SJim Ingham m_name_passed = false; 9595a988416SJim Ingham m_condition_passed = false; 960ca36cd16SJim Ingham m_one_shot_passed = false; 96133df7cd3SJim Ingham m_use_dummy = false; 9625a988416SJim Ingham } 9635a988416SJim Ingham 9641f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 96570602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_modify_options); 9661f0f5b5bSZachary Turner } 9675a988416SJim Ingham 9685a988416SJim Ingham // Instance variables to hold the values for command options. 9695a988416SJim Ingham 9705a988416SJim Ingham uint32_t m_ignore_count; 9715a988416SJim Ingham lldb::tid_t m_thread_id; 9725a988416SJim Ingham bool m_thread_id_passed; 9735a988416SJim Ingham uint32_t m_thread_index; 9745a988416SJim Ingham bool m_thread_index_passed; 9755a988416SJim Ingham std::string m_thread_name; 9765a988416SJim Ingham std::string m_queue_name; 9775a988416SJim Ingham std::string m_condition; 978ca36cd16SJim Ingham bool m_one_shot; 9795a988416SJim Ingham bool m_enable_passed; 9805a988416SJim Ingham bool m_enable_value; 9815a988416SJim Ingham bool m_name_passed; 9825a988416SJim Ingham bool m_queue_passed; 9835a988416SJim Ingham bool m_condition_passed; 984ca36cd16SJim Ingham bool m_one_shot_passed; 98533df7cd3SJim Ingham bool m_use_dummy; 9865a988416SJim Ingham }; 9875a988416SJim Ingham 9885a988416SJim Ingham protected: 989b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 99033df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 991b9c1b51eSKate Stone if (target == nullptr) { 9925a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 9935a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 9945a988416SJim Ingham return false; 9955a988416SJim Ingham } 9965a988416SJim Ingham 997bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 998bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 9995a988416SJim Ingham 10005a988416SJim Ingham BreakpointIDList valid_bp_ids; 10015a988416SJim Ingham 1002b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1003b9c1b51eSKate Stone command, target, result, &valid_bp_ids); 10045a988416SJim Ingham 1005b9c1b51eSKate Stone if (result.Succeeded()) { 10065a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1007b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 10085a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 10095a988416SJim Ingham 1010b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1011b9c1b51eSKate Stone Breakpoint *bp = 1012b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1013b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1014b9c1b51eSKate Stone BreakpointLocation *location = 1015b9c1b51eSKate Stone bp->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1016b9c1b51eSKate Stone if (location) { 10175a988416SJim Ingham if (m_options.m_thread_id_passed) 10185a988416SJim Ingham location->SetThreadID(m_options.m_thread_id); 10195a988416SJim Ingham 10205a988416SJim Ingham if (m_options.m_thread_index_passed) 10215a988416SJim Ingham location->SetThreadIndex(m_options.m_thread_index); 10225a988416SJim Ingham 10235a988416SJim Ingham if (m_options.m_name_passed) 10245a988416SJim Ingham location->SetThreadName(m_options.m_thread_name.c_str()); 10255a988416SJim Ingham 10265a988416SJim Ingham if (m_options.m_queue_passed) 10275a988416SJim Ingham location->SetQueueName(m_options.m_queue_name.c_str()); 10285a988416SJim Ingham 10295a988416SJim Ingham if (m_options.m_ignore_count != 0) 10305a988416SJim Ingham location->SetIgnoreCount(m_options.m_ignore_count); 10315a988416SJim Ingham 10325a988416SJim Ingham if (m_options.m_enable_passed) 10335a988416SJim Ingham location->SetEnabled(m_options.m_enable_value); 10345a988416SJim Ingham 10355a988416SJim Ingham if (m_options.m_condition_passed) 10365a988416SJim Ingham location->SetCondition(m_options.m_condition.c_str()); 10375a988416SJim Ingham } 1038b9c1b51eSKate Stone } else { 10395a988416SJim Ingham if (m_options.m_thread_id_passed) 10405a988416SJim Ingham bp->SetThreadID(m_options.m_thread_id); 10415a988416SJim Ingham 10425a988416SJim Ingham if (m_options.m_thread_index_passed) 10435a988416SJim Ingham bp->SetThreadIndex(m_options.m_thread_index); 10445a988416SJim Ingham 10455a988416SJim Ingham if (m_options.m_name_passed) 10465a988416SJim Ingham bp->SetThreadName(m_options.m_thread_name.c_str()); 10475a988416SJim Ingham 10485a988416SJim Ingham if (m_options.m_queue_passed) 10495a988416SJim Ingham bp->SetQueueName(m_options.m_queue_name.c_str()); 10505a988416SJim Ingham 10515a988416SJim Ingham if (m_options.m_ignore_count != 0) 10525a988416SJim Ingham bp->SetIgnoreCount(m_options.m_ignore_count); 10535a988416SJim Ingham 10545a988416SJim Ingham if (m_options.m_enable_passed) 10555a988416SJim Ingham bp->SetEnabled(m_options.m_enable_value); 10565a988416SJim Ingham 10575a988416SJim Ingham if (m_options.m_condition_passed) 10585a988416SJim Ingham bp->SetCondition(m_options.m_condition.c_str()); 10595a988416SJim Ingham } 10605a988416SJim Ingham } 10615a988416SJim Ingham } 10625a988416SJim Ingham } 10635a988416SJim Ingham 10645a988416SJim Ingham return result.Succeeded(); 10655a988416SJim Ingham } 10665a988416SJim Ingham 10675a988416SJim Ingham private: 10685a988416SJim Ingham CommandOptions m_options; 10695a988416SJim Ingham }; 10705a988416SJim Ingham 10715a988416SJim Ingham //------------------------------------------------------------------------- 10725a988416SJim Ingham // CommandObjectBreakpointEnable 10735a988416SJim Ingham //------------------------------------------------------------------------- 10745a988416SJim Ingham #pragma mark Enable 10755a988416SJim Ingham 1076b9c1b51eSKate Stone class CommandObjectBreakpointEnable : public CommandObjectParsed { 10775a988416SJim Ingham public: 1078b9c1b51eSKate Stone CommandObjectBreakpointEnable(CommandInterpreter &interpreter) 1079b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "enable", 1080b9c1b51eSKate Stone "Enable the specified disabled breakpoint(s). If " 1081b9c1b51eSKate Stone "no breakpoints are specified, enable all of them.", 1082b9c1b51eSKate Stone nullptr) { 10835a988416SJim Ingham CommandArgumentEntry arg; 1084b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1085b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1086b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1087b9c1b51eSKate Stone // arguments vector. 10885a988416SJim Ingham m_arguments.push_back(arg); 10895a988416SJim Ingham } 10905a988416SJim Ingham 10919e85e5a8SEugene Zelenko ~CommandObjectBreakpointEnable() override = default; 10925a988416SJim Ingham 10935a988416SJim Ingham protected: 1094b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1095893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1096b9c1b51eSKate Stone if (target == nullptr) { 10975a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 10985a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 10995a988416SJim Ingham return false; 11005a988416SJim Ingham } 11015a988416SJim Ingham 1102bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1103bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 11045a988416SJim Ingham 11055a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 11065a988416SJim Ingham 11075a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 11085a988416SJim Ingham 1109b9c1b51eSKate Stone if (num_breakpoints == 0) { 11105a988416SJim Ingham result.AppendError("No breakpoints exist to be enabled."); 11115a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 11125a988416SJim Ingham return false; 11135a988416SJim Ingham } 11145a988416SJim Ingham 1115b9c1b51eSKate Stone if (command.GetArgumentCount() == 0) { 11165a988416SJim Ingham // No breakpoint selected; enable all currently set breakpoints. 11175a988416SJim Ingham target->EnableAllBreakpoints(); 1118b9c1b51eSKate Stone result.AppendMessageWithFormat("All breakpoints enabled. (%" PRIu64 1119b9c1b51eSKate Stone " breakpoints)\n", 1120b9c1b51eSKate Stone (uint64_t)num_breakpoints); 11215a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1122b9c1b51eSKate Stone } else { 11235a988416SJim Ingham // Particular breakpoint selected; enable that breakpoint. 11245a988416SJim Ingham BreakpointIDList valid_bp_ids; 1125b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1126b9c1b51eSKate Stone command, target, result, &valid_bp_ids); 11275a988416SJim Ingham 1128b9c1b51eSKate Stone if (result.Succeeded()) { 11295a988416SJim Ingham int enable_count = 0; 11305a988416SJim Ingham int loc_count = 0; 11315a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1132b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 11335a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 11345a988416SJim Ingham 1135b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1136b9c1b51eSKate Stone Breakpoint *breakpoint = 1137b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1138b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1139b9c1b51eSKate Stone BreakpointLocation *location = 1140b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1141b9c1b51eSKate Stone if (location) { 11425a988416SJim Ingham location->SetEnabled(true); 11435a988416SJim Ingham ++loc_count; 11445a988416SJim Ingham } 1145b9c1b51eSKate Stone } else { 11465a988416SJim Ingham breakpoint->SetEnabled(true); 11475a988416SJim Ingham ++enable_count; 11485a988416SJim Ingham } 11495a988416SJim Ingham } 11505a988416SJim Ingham } 1151b9c1b51eSKate Stone result.AppendMessageWithFormat("%d breakpoints enabled.\n", 1152b9c1b51eSKate Stone enable_count + loc_count); 11535a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 11545a988416SJim Ingham } 11555a988416SJim Ingham } 11565a988416SJim Ingham 11575a988416SJim Ingham return result.Succeeded(); 11585a988416SJim Ingham } 11595a988416SJim Ingham }; 11605a988416SJim Ingham 11615a988416SJim Ingham //------------------------------------------------------------------------- 11625a988416SJim Ingham // CommandObjectBreakpointDisable 11635a988416SJim Ingham //------------------------------------------------------------------------- 11645a988416SJim Ingham #pragma mark Disable 11655a988416SJim Ingham 1166b9c1b51eSKate Stone class CommandObjectBreakpointDisable : public CommandObjectParsed { 11675a988416SJim Ingham public: 11687428a18cSKate Stone CommandObjectBreakpointDisable(CommandInterpreter &interpreter) 1169b9c1b51eSKate Stone : CommandObjectParsed( 1170b9c1b51eSKate Stone interpreter, "breakpoint disable", 1171b9c1b51eSKate Stone "Disable the specified breakpoint(s) without deleting " 11727428a18cSKate Stone "them. If none are specified, disable all " 11737428a18cSKate Stone "breakpoints.", 1174b9c1b51eSKate Stone nullptr) { 1175b9c1b51eSKate Stone SetHelpLong( 1176b9c1b51eSKate Stone "Disable the specified breakpoint(s) without deleting them. \ 11777428a18cSKate Stone If none are specified, disable all breakpoints." 11787428a18cSKate Stone R"( 1179ea671fbdSKate Stone 11807428a18cSKate Stone )" 11817428a18cSKate Stone "Note: disabling a breakpoint will cause none of its locations to be hit \ 11827428a18cSKate Stone regardless of whether individual locations are enabled or disabled. After the sequence:" 11837428a18cSKate Stone R"( 1184ea671fbdSKate Stone 1185ea671fbdSKate Stone (lldb) break disable 1 1186ea671fbdSKate Stone (lldb) break enable 1.1 1187ea671fbdSKate Stone 1188ea671fbdSKate Stone execution will NOT stop at location 1.1. To achieve that, type: 1189ea671fbdSKate Stone 1190ea671fbdSKate Stone (lldb) break disable 1.* 1191ea671fbdSKate Stone (lldb) break enable 1.1 1192ea671fbdSKate Stone 11937428a18cSKate Stone )" 11947428a18cSKate Stone "The first command disables all locations for breakpoint 1, \ 11957428a18cSKate Stone the second re-enables the first location."); 1196b0fac509SJim Ingham 11975a988416SJim Ingham CommandArgumentEntry arg; 1198b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1199b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1200b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1201b9c1b51eSKate Stone // arguments vector. 12025a988416SJim Ingham m_arguments.push_back(arg); 12035a988416SJim Ingham } 12045a988416SJim Ingham 12059e85e5a8SEugene Zelenko ~CommandObjectBreakpointDisable() override = default; 12065a988416SJim Ingham 12075a988416SJim Ingham protected: 1208b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1209893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1210b9c1b51eSKate Stone if (target == nullptr) { 12115a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 12125a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 12135a988416SJim Ingham return false; 12145a988416SJim Ingham } 12155a988416SJim Ingham 1216bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1217bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 12185a988416SJim Ingham 12195a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 12205a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 12215a988416SJim Ingham 1222b9c1b51eSKate Stone if (num_breakpoints == 0) { 12235a988416SJim Ingham result.AppendError("No breakpoints exist to be disabled."); 12245a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 12255a988416SJim Ingham return false; 12265a988416SJim Ingham } 12275a988416SJim Ingham 1228b9c1b51eSKate Stone if (command.GetArgumentCount() == 0) { 12295a988416SJim Ingham // No breakpoint selected; disable all currently set breakpoints. 12305a988416SJim Ingham target->DisableAllBreakpoints(); 1231b9c1b51eSKate Stone result.AppendMessageWithFormat("All breakpoints disabled. (%" PRIu64 1232b9c1b51eSKate Stone " breakpoints)\n", 1233b9c1b51eSKate Stone (uint64_t)num_breakpoints); 12345a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1235b9c1b51eSKate Stone } else { 12365a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 12375a988416SJim Ingham BreakpointIDList valid_bp_ids; 12385a988416SJim Ingham 1239b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1240b9c1b51eSKate Stone command, target, result, &valid_bp_ids); 12415a988416SJim Ingham 1242b9c1b51eSKate Stone if (result.Succeeded()) { 12435a988416SJim Ingham int disable_count = 0; 12445a988416SJim Ingham int loc_count = 0; 12455a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1246b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 12475a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 12485a988416SJim Ingham 1249b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1250b9c1b51eSKate Stone Breakpoint *breakpoint = 1251b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1252b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1253b9c1b51eSKate Stone BreakpointLocation *location = 1254b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1255b9c1b51eSKate Stone if (location) { 12565a988416SJim Ingham location->SetEnabled(false); 12575a988416SJim Ingham ++loc_count; 12585a988416SJim Ingham } 1259b9c1b51eSKate Stone } else { 12605a988416SJim Ingham breakpoint->SetEnabled(false); 12615a988416SJim Ingham ++disable_count; 12625a988416SJim Ingham } 12635a988416SJim Ingham } 12645a988416SJim Ingham } 1265b9c1b51eSKate Stone result.AppendMessageWithFormat("%d breakpoints disabled.\n", 1266b9c1b51eSKate Stone disable_count + loc_count); 12675a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 12685a988416SJim Ingham } 12695a988416SJim Ingham } 12705a988416SJim Ingham 12715a988416SJim Ingham return result.Succeeded(); 12725a988416SJim Ingham } 12735a988416SJim Ingham }; 12745a988416SJim Ingham 12755a988416SJim Ingham //------------------------------------------------------------------------- 12765a988416SJim Ingham // CommandObjectBreakpointList 12775a988416SJim Ingham //------------------------------------------------------------------------- 12781f0f5b5bSZachary Turner 12791f0f5b5bSZachary Turner #pragma mark List::CommandOptions 12801f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_list_options[] = { 12811f0f5b5bSZachary Turner // clang-format off 12821f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show debugger internal breakpoints" }, 12831f0f5b5bSZachary Turner { LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a brief description of the breakpoint (no location info)." }, 12841f0f5b5bSZachary Turner // FIXME: We need to add an "internal" command, and then add this sort of thing to it. 12851f0f5b5bSZachary Turner // But I need to see it for now, and don't want to wait. 12861f0f5b5bSZachary Turner { LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a full description of the breakpoint and its locations." }, 12871f0f5b5bSZachary Turner { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, 12881f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets." }, 12891f0f5b5bSZachary Turner // clang-format on 12901f0f5b5bSZachary Turner }; 12911f0f5b5bSZachary Turner 12925a988416SJim Ingham #pragma mark List 12935a988416SJim Ingham 1294b9c1b51eSKate Stone class CommandObjectBreakpointList : public CommandObjectParsed { 12955a988416SJim Ingham public: 1296b9c1b51eSKate Stone CommandObjectBreakpointList(CommandInterpreter &interpreter) 1297b9c1b51eSKate Stone : CommandObjectParsed( 1298b9c1b51eSKate Stone interpreter, "breakpoint list", 12995a988416SJim Ingham "List some or all breakpoints at configurable levels of detail.", 13009e85e5a8SEugene Zelenko nullptr), 1301b9c1b51eSKate Stone m_options() { 13025a988416SJim Ingham CommandArgumentEntry arg; 13035a988416SJim Ingham CommandArgumentData bp_id_arg; 13045a988416SJim Ingham 13055a988416SJim Ingham // Define the first (and only) variant of this arg. 13065a988416SJim Ingham bp_id_arg.arg_type = eArgTypeBreakpointID; 13075a988416SJim Ingham bp_id_arg.arg_repetition = eArgRepeatOptional; 13085a988416SJim Ingham 1309b9c1b51eSKate Stone // There is only one variant this argument could be; put it into the 1310b9c1b51eSKate Stone // argument entry. 13115a988416SJim Ingham arg.push_back(bp_id_arg); 13125a988416SJim Ingham 13135a988416SJim Ingham // Push the data for the first argument into the m_arguments vector. 13145a988416SJim Ingham m_arguments.push_back(arg); 13155a988416SJim Ingham } 13165a988416SJim Ingham 13179e85e5a8SEugene Zelenko ~CommandObjectBreakpointList() override = default; 13185a988416SJim Ingham 1319b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 13205a988416SJim Ingham 1321b9c1b51eSKate Stone class CommandOptions : public Options { 13225a988416SJim Ingham public: 1323b9c1b51eSKate Stone CommandOptions() 1324b9c1b51eSKate Stone : Options(), m_level(lldb::eDescriptionLevelBrief), m_use_dummy(false) { 13255a988416SJim Ingham } 13265a988416SJim Ingham 13279e85e5a8SEugene Zelenko ~CommandOptions() override = default; 13285a988416SJim Ingham 1329b9c1b51eSKate Stone Error SetOptionValue(uint32_t option_idx, const char *option_arg, 1330b9c1b51eSKate Stone ExecutionContext *execution_context) override { 13315a988416SJim Ingham Error error; 13323bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 13335a988416SJim Ingham 1334b9c1b51eSKate Stone switch (short_option) { 13355a988416SJim Ingham case 'b': 13365a988416SJim Ingham m_level = lldb::eDescriptionLevelBrief; 13375a988416SJim Ingham break; 133833df7cd3SJim Ingham case 'D': 133933df7cd3SJim Ingham m_use_dummy = true; 134033df7cd3SJim Ingham break; 13415a988416SJim Ingham case 'f': 13425a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 13435a988416SJim Ingham break; 13445a988416SJim Ingham case 'v': 13455a988416SJim Ingham m_level = lldb::eDescriptionLevelVerbose; 13465a988416SJim Ingham break; 13475a988416SJim Ingham case 'i': 13485a988416SJim Ingham m_internal = true; 13495a988416SJim Ingham break; 13505a988416SJim Ingham default: 1351b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1352b9c1b51eSKate Stone short_option); 13535a988416SJim Ingham break; 13545a988416SJim Ingham } 13555a988416SJim Ingham 13565a988416SJim Ingham return error; 13575a988416SJim Ingham } 13585a988416SJim Ingham 1359b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 13605a988416SJim Ingham m_level = lldb::eDescriptionLevelFull; 13615a988416SJim Ingham m_internal = false; 136233df7cd3SJim Ingham m_use_dummy = false; 13635a988416SJim Ingham } 13645a988416SJim Ingham 13651f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 136670602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_list_options); 13671f0f5b5bSZachary Turner } 13685a988416SJim Ingham 13695a988416SJim Ingham // Instance variables to hold the values for command options. 13705a988416SJim Ingham 13715a988416SJim Ingham lldb::DescriptionLevel m_level; 13725a988416SJim Ingham 13735a988416SJim Ingham bool m_internal; 137433df7cd3SJim Ingham bool m_use_dummy; 13755a988416SJim Ingham }; 13765a988416SJim Ingham 13775a988416SJim Ingham protected: 1378b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 137933df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 138033df7cd3SJim Ingham 1381b9c1b51eSKate Stone if (target == nullptr) { 13825a988416SJim Ingham result.AppendError("Invalid target. No current target or breakpoints."); 13835a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 13845a988416SJim Ingham return true; 13855a988416SJim Ingham } 13865a988416SJim Ingham 1387b9c1b51eSKate Stone const BreakpointList &breakpoints = 1388b9c1b51eSKate Stone target->GetBreakpointList(m_options.m_internal); 1389bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1390bb19a13cSSaleem Abdulrasool target->GetBreakpointList(m_options.m_internal).GetListMutex(lock); 13915a988416SJim Ingham 13925a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 13935a988416SJim Ingham 1394b9c1b51eSKate Stone if (num_breakpoints == 0) { 13955a988416SJim Ingham result.AppendMessage("No breakpoints currently set."); 13965a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 13975a988416SJim Ingham return true; 13985a988416SJim Ingham } 13995a988416SJim Ingham 14005a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 14015a988416SJim Ingham 1402b9c1b51eSKate Stone if (command.GetArgumentCount() == 0) { 14035a988416SJim Ingham // No breakpoint selected; show info about all currently set breakpoints. 14045a988416SJim Ingham result.AppendMessage("Current breakpoints:"); 1405b9c1b51eSKate Stone for (size_t i = 0; i < num_breakpoints; ++i) { 14065a988416SJim Ingham Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex(i).get(); 14075a988416SJim Ingham AddBreakpointDescription(&output_stream, breakpoint, m_options.m_level); 14085a988416SJim Ingham } 14095a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1410b9c1b51eSKate Stone } else { 14115a988416SJim Ingham // Particular breakpoints selected; show info about that breakpoint. 14125a988416SJim Ingham BreakpointIDList valid_bp_ids; 1413b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1414b9c1b51eSKate Stone command, target, result, &valid_bp_ids); 14155a988416SJim Ingham 1416b9c1b51eSKate Stone if (result.Succeeded()) { 1417b9c1b51eSKate Stone for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) { 14185a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 1419b9c1b51eSKate Stone Breakpoint *breakpoint = 1420b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1421b9c1b51eSKate Stone AddBreakpointDescription(&output_stream, breakpoint, 1422b9c1b51eSKate Stone m_options.m_level); 14235a988416SJim Ingham } 14245a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1425b9c1b51eSKate Stone } else { 14267428a18cSKate Stone result.AppendError("Invalid breakpoint ID."); 14275a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 14285a988416SJim Ingham } 14295a988416SJim Ingham } 14305a988416SJim Ingham 14315a988416SJim Ingham return result.Succeeded(); 14325a988416SJim Ingham } 14335a988416SJim Ingham 14345a988416SJim Ingham private: 14355a988416SJim Ingham CommandOptions m_options; 14365a988416SJim Ingham }; 14375a988416SJim Ingham 14385a988416SJim Ingham //------------------------------------------------------------------------- 14395a988416SJim Ingham // CommandObjectBreakpointClear 14405a988416SJim Ingham //------------------------------------------------------------------------- 14411f0f5b5bSZachary Turner #pragma mark Clear::CommandOptions 14421f0f5b5bSZachary Turner 14431f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_clear_options[] = { 14441f0f5b5bSZachary Turner // clang-format off 14451f0f5b5bSZachary Turner { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specify the breakpoint by source location in this particular file." }, 14461f0f5b5bSZachary Turner { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Specify the breakpoint by source location at this particular line." } 14471f0f5b5bSZachary Turner // clang-format on 14481f0f5b5bSZachary Turner }; 14491f0f5b5bSZachary Turner 14505a988416SJim Ingham #pragma mark Clear 14515a988416SJim Ingham 1452b9c1b51eSKate Stone class CommandObjectBreakpointClear : public CommandObjectParsed { 14535a988416SJim Ingham public: 1454b9c1b51eSKate Stone typedef enum BreakpointClearType { 14555a988416SJim Ingham eClearTypeInvalid, 14565a988416SJim Ingham eClearTypeFileAndLine 14575a988416SJim Ingham } BreakpointClearType; 14585a988416SJim Ingham 14597428a18cSKate Stone CommandObjectBreakpointClear(CommandInterpreter &interpreter) 14607428a18cSKate Stone : CommandObjectParsed(interpreter, "breakpoint clear", 1461b9c1b51eSKate Stone "Delete or disable breakpoints matching the " 1462b9c1b51eSKate Stone "specified source file and line.", 14635a988416SJim Ingham "breakpoint clear <cmd-options>"), 1464b9c1b51eSKate Stone m_options() {} 14655a988416SJim Ingham 14669e85e5a8SEugene Zelenko ~CommandObjectBreakpointClear() override = default; 14675a988416SJim Ingham 1468b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 14695a988416SJim Ingham 1470b9c1b51eSKate Stone class CommandOptions : public Options { 14715a988416SJim Ingham public: 1472b9c1b51eSKate Stone CommandOptions() : Options(), m_filename(), m_line_num(0) {} 14735a988416SJim Ingham 14749e85e5a8SEugene Zelenko ~CommandOptions() override = default; 14755a988416SJim Ingham 1476b9c1b51eSKate Stone Error SetOptionValue(uint32_t option_idx, const char *option_arg, 1477b9c1b51eSKate Stone ExecutionContext *execution_context) override { 14785a988416SJim Ingham Error error; 14793bcdfc0eSGreg Clayton const int short_option = m_getopt_table[option_idx].val; 14805a988416SJim Ingham 1481b9c1b51eSKate Stone switch (short_option) { 14825a988416SJim Ingham case 'f': 14835a988416SJim Ingham m_filename.assign(option_arg); 14845a988416SJim Ingham break; 14855a988416SJim Ingham 14865a988416SJim Ingham case 'l': 14875275aaa0SVince Harron m_line_num = StringConvert::ToUInt32(option_arg, 0); 14885a988416SJim Ingham break; 14895a988416SJim Ingham 14905a988416SJim Ingham default: 1491b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1492b9c1b51eSKate Stone short_option); 14935a988416SJim Ingham break; 14945a988416SJim Ingham } 14955a988416SJim Ingham 14965a988416SJim Ingham return error; 14975a988416SJim Ingham } 14985a988416SJim Ingham 1499b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 15005a988416SJim Ingham m_filename.clear(); 15015a988416SJim Ingham m_line_num = 0; 15025a988416SJim Ingham } 15035a988416SJim Ingham 15041f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 150570602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_clear_options); 15061f0f5b5bSZachary Turner } 15075a988416SJim Ingham 15085a988416SJim Ingham // Instance variables to hold the values for command options. 15095a988416SJim Ingham 15105a988416SJim Ingham std::string m_filename; 15115a988416SJim Ingham uint32_t m_line_num; 15125a988416SJim Ingham }; 15135a988416SJim Ingham 15145a988416SJim Ingham protected: 1515b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1516893c932aSJim Ingham Target *target = GetSelectedOrDummyTarget(); 1517b9c1b51eSKate Stone if (target == nullptr) { 15185a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 15195a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 15205a988416SJim Ingham return false; 15215a988416SJim Ingham } 15225a988416SJim Ingham 15235a988416SJim Ingham // The following are the various types of breakpoints that could be cleared: 15245a988416SJim Ingham // 1). -f -l (clearing breakpoint by source location) 15255a988416SJim Ingham 15265a988416SJim Ingham BreakpointClearType break_type = eClearTypeInvalid; 15275a988416SJim Ingham 15285a988416SJim Ingham if (m_options.m_line_num != 0) 15295a988416SJim Ingham break_type = eClearTypeFileAndLine; 15305a988416SJim Ingham 1531bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1532bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 15335a988416SJim Ingham 15345a988416SJim Ingham BreakpointList &breakpoints = target->GetBreakpointList(); 15355a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 15365a988416SJim Ingham 15375a988416SJim Ingham // Early return if there's no breakpoint at all. 1538b9c1b51eSKate Stone if (num_breakpoints == 0) { 15395a988416SJim Ingham result.AppendError("Breakpoint clear: No breakpoint cleared."); 15405a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 15415a988416SJim Ingham return result.Succeeded(); 15425a988416SJim Ingham } 15435a988416SJim Ingham 15445a988416SJim Ingham // Find matching breakpoints and delete them. 15455a988416SJim Ingham 15465a988416SJim Ingham // First create a copy of all the IDs. 15475a988416SJim Ingham std::vector<break_id_t> BreakIDs; 15485a988416SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) 15499e85e5a8SEugene Zelenko BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID()); 15505a988416SJim Ingham 15515a988416SJim Ingham int num_cleared = 0; 15525a988416SJim Ingham StreamString ss; 1553b9c1b51eSKate Stone switch (break_type) { 15545a988416SJim Ingham case eClearTypeFileAndLine: // Breakpoint by source position 15555a988416SJim Ingham { 15565a988416SJim Ingham const ConstString filename(m_options.m_filename.c_str()); 15575a988416SJim Ingham BreakpointLocationCollection loc_coll; 15585a988416SJim Ingham 1559b9c1b51eSKate Stone for (size_t i = 0; i < num_breakpoints; ++i) { 15605a988416SJim Ingham Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); 15615a988416SJim Ingham 1562b9c1b51eSKate Stone if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) { 1563b9c1b51eSKate Stone // If the collection size is 0, it's a full match and we can just 1564b9c1b51eSKate Stone // remove the breakpoint. 1565b9c1b51eSKate Stone if (loc_coll.GetSize() == 0) { 15665a988416SJim Ingham bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); 15675a988416SJim Ingham ss.EOL(); 15685a988416SJim Ingham target->RemoveBreakpointByID(bp->GetID()); 15695a988416SJim Ingham ++num_cleared; 15705a988416SJim Ingham } 15715a988416SJim Ingham } 15725a988416SJim Ingham } 1573b9c1b51eSKate Stone } break; 15745a988416SJim Ingham 15755a988416SJim Ingham default: 15765a988416SJim Ingham break; 15775a988416SJim Ingham } 15785a988416SJim Ingham 1579b9c1b51eSKate Stone if (num_cleared > 0) { 15805a988416SJim Ingham Stream &output_stream = result.GetOutputStream(); 15815a988416SJim Ingham output_stream.Printf("%d breakpoints cleared:\n", num_cleared); 15825a988416SJim Ingham output_stream << ss.GetData(); 15835a988416SJim Ingham output_stream.EOL(); 15845a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1585b9c1b51eSKate Stone } else { 15865a988416SJim Ingham result.AppendError("Breakpoint clear: No breakpoint cleared."); 15875a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 15885a988416SJim Ingham } 15895a988416SJim Ingham 15905a988416SJim Ingham return result.Succeeded(); 15915a988416SJim Ingham } 15925a988416SJim Ingham 15935a988416SJim Ingham private: 15945a988416SJim Ingham CommandOptions m_options; 15955a988416SJim Ingham }; 15965a988416SJim Ingham 15975a988416SJim Ingham //------------------------------------------------------------------------- 15985a988416SJim Ingham // CommandObjectBreakpointDelete 15995a988416SJim Ingham //------------------------------------------------------------------------- 16001f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_delete_options[] = { 16011f0f5b5bSZachary Turner // clang-format off 16021f0f5b5bSZachary Turner { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete all breakpoints without querying for confirmation." }, 16031f0f5b5bSZachary Turner { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets." }, 16041f0f5b5bSZachary Turner // clang-format on 16051f0f5b5bSZachary Turner }; 16061f0f5b5bSZachary Turner 16075a988416SJim Ingham #pragma mark Delete 16085a988416SJim Ingham 1609b9c1b51eSKate Stone class CommandObjectBreakpointDelete : public CommandObjectParsed { 16105a988416SJim Ingham public: 1611b9c1b51eSKate Stone CommandObjectBreakpointDelete(CommandInterpreter &interpreter) 1612b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "breakpoint delete", 1613b9c1b51eSKate Stone "Delete the specified breakpoint(s). If no " 1614b9c1b51eSKate Stone "breakpoints are specified, delete them all.", 16159e85e5a8SEugene Zelenko nullptr), 1616b9c1b51eSKate Stone m_options() { 16175a988416SJim Ingham CommandArgumentEntry arg; 1618b9c1b51eSKate Stone CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 1619b9c1b51eSKate Stone eArgTypeBreakpointIDRange); 1620b9c1b51eSKate Stone // Add the entry for the first argument for this command to the object's 1621b9c1b51eSKate Stone // arguments vector. 16225a988416SJim Ingham m_arguments.push_back(arg); 16235a988416SJim Ingham } 16245a988416SJim Ingham 16259e85e5a8SEugene Zelenko ~CommandObjectBreakpointDelete() override = default; 16265a988416SJim Ingham 1627b9c1b51eSKate Stone Options *GetOptions() override { return &m_options; } 162833df7cd3SJim Ingham 1629b9c1b51eSKate Stone class CommandOptions : public Options { 163033df7cd3SJim Ingham public: 1631b9c1b51eSKate Stone CommandOptions() : Options(), m_use_dummy(false), m_force(false) {} 163233df7cd3SJim Ingham 16339e85e5a8SEugene Zelenko ~CommandOptions() override = default; 163433df7cd3SJim Ingham 1635b9c1b51eSKate Stone Error SetOptionValue(uint32_t option_idx, const char *option_arg, 1636b9c1b51eSKate Stone ExecutionContext *execution_context) override { 163733df7cd3SJim Ingham Error error; 163833df7cd3SJim Ingham const int short_option = m_getopt_table[option_idx].val; 163933df7cd3SJim Ingham 1640b9c1b51eSKate Stone switch (short_option) { 164133df7cd3SJim Ingham case 'f': 164233df7cd3SJim Ingham m_force = true; 164333df7cd3SJim Ingham break; 164433df7cd3SJim Ingham 164533df7cd3SJim Ingham case 'D': 164633df7cd3SJim Ingham m_use_dummy = true; 164733df7cd3SJim Ingham break; 164833df7cd3SJim Ingham 164933df7cd3SJim Ingham default: 1650b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized option '%c'", 1651b9c1b51eSKate Stone short_option); 165233df7cd3SJim Ingham break; 165333df7cd3SJim Ingham } 165433df7cd3SJim Ingham 165533df7cd3SJim Ingham return error; 165633df7cd3SJim Ingham } 165733df7cd3SJim Ingham 1658b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 165933df7cd3SJim Ingham m_use_dummy = false; 166033df7cd3SJim Ingham m_force = false; 166133df7cd3SJim Ingham } 166233df7cd3SJim Ingham 16631f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 166470602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_delete_options); 16651f0f5b5bSZachary Turner } 166633df7cd3SJim Ingham 166733df7cd3SJim Ingham // Instance variables to hold the values for command options. 166833df7cd3SJim Ingham bool m_use_dummy; 166933df7cd3SJim Ingham bool m_force; 167033df7cd3SJim Ingham }; 167133df7cd3SJim Ingham 16725a988416SJim Ingham protected: 1673b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 167433df7cd3SJim Ingham Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); 167533df7cd3SJim Ingham 1676b9c1b51eSKate Stone if (target == nullptr) { 16775a988416SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 16785a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 16795a988416SJim Ingham return false; 16805a988416SJim Ingham } 16815a988416SJim Ingham 1682bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1683bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 16845a988416SJim Ingham 16855a988416SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 16865a988416SJim Ingham 16875a988416SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 16885a988416SJim Ingham 1689b9c1b51eSKate Stone if (num_breakpoints == 0) { 16905a988416SJim Ingham result.AppendError("No breakpoints exist to be deleted."); 16915a988416SJim Ingham result.SetStatus(eReturnStatusFailed); 16925a988416SJim Ingham return false; 16935a988416SJim Ingham } 16945a988416SJim Ingham 1695b9c1b51eSKate Stone if (command.GetArgumentCount() == 0) { 1696b9c1b51eSKate Stone if (!m_options.m_force && 1697b9c1b51eSKate Stone !m_interpreter.Confirm( 1698b9c1b51eSKate Stone "About to delete all breakpoints, do you want to do that?", 1699b9c1b51eSKate Stone true)) { 17005a988416SJim Ingham result.AppendMessage("Operation cancelled..."); 1701b9c1b51eSKate Stone } else { 17025a988416SJim Ingham target->RemoveAllBreakpoints(); 1703b9c1b51eSKate Stone result.AppendMessageWithFormat( 1704b9c1b51eSKate Stone "All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", 1705b9c1b51eSKate Stone (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : ""); 17065a988416SJim Ingham } 17075a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1708b9c1b51eSKate Stone } else { 17095a988416SJim Ingham // Particular breakpoint selected; disable that breakpoint. 17105a988416SJim Ingham BreakpointIDList valid_bp_ids; 1711b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( 1712b9c1b51eSKate Stone command, target, result, &valid_bp_ids); 17135a988416SJim Ingham 1714b9c1b51eSKate Stone if (result.Succeeded()) { 17155a988416SJim Ingham int delete_count = 0; 17165a988416SJim Ingham int disable_count = 0; 17175a988416SJim Ingham const size_t count = valid_bp_ids.GetSize(); 1718b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 17195a988416SJim Ingham BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); 17205a988416SJim Ingham 1721b9c1b51eSKate Stone if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { 1722b9c1b51eSKate Stone if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { 1723b9c1b51eSKate Stone Breakpoint *breakpoint = 1724b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 1725b9c1b51eSKate Stone BreakpointLocation *location = 1726b9c1b51eSKate Stone breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); 1727b9c1b51eSKate Stone // It makes no sense to try to delete individual locations, so we 1728b9c1b51eSKate Stone // disable them instead. 1729b9c1b51eSKate Stone if (location) { 17305a988416SJim Ingham location->SetEnabled(false); 17315a988416SJim Ingham ++disable_count; 17325a988416SJim Ingham } 1733b9c1b51eSKate Stone } else { 17345a988416SJim Ingham target->RemoveBreakpointByID(cur_bp_id.GetBreakpointID()); 17355a988416SJim Ingham ++delete_count; 17365a988416SJim Ingham } 17375a988416SJim Ingham } 17385a988416SJim Ingham } 1739b9c1b51eSKate Stone result.AppendMessageWithFormat( 1740b9c1b51eSKate Stone "%d breakpoints deleted; %d breakpoint locations disabled.\n", 17415a988416SJim Ingham delete_count, disable_count); 17425a988416SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 17435a988416SJim Ingham } 17445a988416SJim Ingham } 17455a988416SJim Ingham return result.Succeeded(); 17465a988416SJim Ingham } 17479e85e5a8SEugene Zelenko 174833df7cd3SJim Ingham private: 174933df7cd3SJim Ingham CommandOptions m_options; 175033df7cd3SJim Ingham }; 175133df7cd3SJim Ingham 175230fdc8d8SChris Lattner //------------------------------------------------------------------------- 17535e09c8c3SJim Ingham // CommandObjectBreakpointName 17545e09c8c3SJim Ingham //------------------------------------------------------------------------- 17555e09c8c3SJim Ingham 17567428a18cSKate Stone static OptionDefinition g_breakpoint_name_options[] = { 1757ac9c3a62SKate Stone // clang-format off 1758ac9c3a62SKate Stone {LLDB_OPT_SET_1, false, "name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."}, 1759ac9c3a62SKate Stone {LLDB_OPT_SET_2, false, "breakpoint-id", 'B', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointID, "Specify a breakpoint ID to use."}, 1760ac9c3a62SKate Stone {LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Operate on Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, 1761ac9c3a62SKate Stone // clang-format on 17625e09c8c3SJim Ingham }; 1763b9c1b51eSKate Stone class BreakpointNameOptionGroup : public OptionGroup { 17645e09c8c3SJim Ingham public: 1765b9c1b51eSKate Stone BreakpointNameOptionGroup() 1766b9c1b51eSKate Stone : OptionGroup(), m_breakpoint(LLDB_INVALID_BREAK_ID), m_use_dummy(false) { 17675e09c8c3SJim Ingham } 17685e09c8c3SJim Ingham 17699e85e5a8SEugene Zelenko ~BreakpointNameOptionGroup() override = default; 17705e09c8c3SJim Ingham 17711f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 177270602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_name_options); 17735e09c8c3SJim Ingham } 17745e09c8c3SJim Ingham 1775b9c1b51eSKate Stone Error SetOptionValue(uint32_t option_idx, const char *option_value, 1776b9c1b51eSKate Stone ExecutionContext *execution_context) override { 17775e09c8c3SJim Ingham Error error; 17785e09c8c3SJim Ingham const int short_option = g_breakpoint_name_options[option_idx].short_option; 17796fa7681bSZachary Turner llvm::StringRef option_strref(option_value ? option_value : ""); 17805e09c8c3SJim Ingham 1781b9c1b51eSKate Stone switch (short_option) { 17825e09c8c3SJim Ingham case 'N': 17836fa7681bSZachary Turner if (BreakpointID::StringIsBreakpointName(option_strref, error) && 1784b9c1b51eSKate Stone error.Success()) 17856fa7681bSZachary Turner m_name.SetValueFromString(option_strref); 17865e09c8c3SJim Ingham break; 17875e09c8c3SJim Ingham 17885e09c8c3SJim Ingham case 'B': 1789c95f7e2aSPavel Labath if (m_breakpoint.SetValueFromString(option_value).Fail()) 1790b9c1b51eSKate Stone error.SetErrorStringWithFormat( 1791b9c1b51eSKate Stone "unrecognized value \"%s\" for breakpoint", option_value); 17925e09c8c3SJim Ingham break; 17935e09c8c3SJim Ingham case 'D': 1794c95f7e2aSPavel Labath if (m_use_dummy.SetValueFromString(option_value).Fail()) 1795b9c1b51eSKate Stone error.SetErrorStringWithFormat( 1796b9c1b51eSKate Stone "unrecognized value \"%s\" for use-dummy", option_value); 17975e09c8c3SJim Ingham break; 17985e09c8c3SJim Ingham 17995e09c8c3SJim Ingham default: 1800b9c1b51eSKate Stone error.SetErrorStringWithFormat("unrecognized short option '%c'", 1801b9c1b51eSKate Stone short_option); 18025e09c8c3SJim Ingham break; 18035e09c8c3SJim Ingham } 18045e09c8c3SJim Ingham return error; 18055e09c8c3SJim Ingham } 18065e09c8c3SJim Ingham 1807b9c1b51eSKate Stone void OptionParsingStarting(ExecutionContext *execution_context) override { 18085e09c8c3SJim Ingham m_name.Clear(); 18095e09c8c3SJim Ingham m_breakpoint.Clear(); 18105e09c8c3SJim Ingham m_use_dummy.Clear(); 18115e09c8c3SJim Ingham m_use_dummy.SetDefaultValue(false); 18125e09c8c3SJim Ingham } 18135e09c8c3SJim Ingham 18145e09c8c3SJim Ingham OptionValueString m_name; 18155e09c8c3SJim Ingham OptionValueUInt64 m_breakpoint; 18165e09c8c3SJim Ingham OptionValueBoolean m_use_dummy; 18175e09c8c3SJim Ingham }; 18185e09c8c3SJim Ingham 1819b9c1b51eSKate Stone class CommandObjectBreakpointNameAdd : public CommandObjectParsed { 18205e09c8c3SJim Ingham public: 1821b9c1b51eSKate Stone CommandObjectBreakpointNameAdd(CommandInterpreter &interpreter) 1822b9c1b51eSKate Stone : CommandObjectParsed( 1823b9c1b51eSKate Stone interpreter, "add", "Add a name to the breakpoints provided.", 18245e09c8c3SJim Ingham "breakpoint name add <command-options> <breakpoint-id-list>"), 1825b9c1b51eSKate Stone m_name_options(), m_option_group() { 1826b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 1827b9c1b51eSKate Stone // command. 18285e09c8c3SJim Ingham CommandArgumentEntry arg1; 18295e09c8c3SJim Ingham CommandArgumentData id_arg; 18305e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 18315e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 18325e09c8c3SJim Ingham arg1.push_back(id_arg); 18335e09c8c3SJim Ingham m_arguments.push_back(arg1); 18345e09c8c3SJim Ingham 18355e09c8c3SJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 18365e09c8c3SJim Ingham m_option_group.Finalize(); 18375e09c8c3SJim Ingham } 18385e09c8c3SJim Ingham 18399e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameAdd() override = default; 18405e09c8c3SJim Ingham 1841b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 18425e09c8c3SJim Ingham 18435e09c8c3SJim Ingham protected: 1844b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1845b9c1b51eSKate Stone if (!m_name_options.m_name.OptionWasSet()) { 18465e09c8c3SJim Ingham result.SetError("No name option provided."); 18475e09c8c3SJim Ingham return false; 18485e09c8c3SJim Ingham } 18495e09c8c3SJim Ingham 1850b9c1b51eSKate Stone Target *target = 1851b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 18525e09c8c3SJim Ingham 1853b9c1b51eSKate Stone if (target == nullptr) { 18545e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 18555e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 18565e09c8c3SJim Ingham return false; 18575e09c8c3SJim Ingham } 18585e09c8c3SJim Ingham 1859bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1860bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 18615e09c8c3SJim Ingham 18625e09c8c3SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 18635e09c8c3SJim Ingham 18645e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 1865b9c1b51eSKate Stone if (num_breakpoints == 0) { 18665e09c8c3SJim Ingham result.SetError("No breakpoints, cannot add names."); 18675e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 18685e09c8c3SJim Ingham return false; 18695e09c8c3SJim Ingham } 18705e09c8c3SJim Ingham 18715e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 18725e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 1873b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 1874b9c1b51eSKate Stone command, target, result, &valid_bp_ids); 18755e09c8c3SJim Ingham 1876b9c1b51eSKate Stone if (result.Succeeded()) { 1877b9c1b51eSKate Stone if (valid_bp_ids.GetSize() == 0) { 18785e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot add names."); 18795e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 18805e09c8c3SJim Ingham return false; 18815e09c8c3SJim Ingham } 18825e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 1883b9c1b51eSKate Stone for (size_t index = 0; index < num_valid_ids; index++) { 1884b9c1b51eSKate Stone lldb::break_id_t bp_id = 1885b9c1b51eSKate Stone valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 18865e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 1887b9c1b51eSKate Stone Error error; // We don't need to check the error here, since the option 1888b9c1b51eSKate Stone // parser checked it... 18895e09c8c3SJim Ingham bp_sp->AddName(m_name_options.m_name.GetCurrentValue(), error); 18905e09c8c3SJim Ingham } 18915e09c8c3SJim Ingham } 18925e09c8c3SJim Ingham 18935e09c8c3SJim Ingham return true; 18945e09c8c3SJim Ingham } 18955e09c8c3SJim Ingham 18965e09c8c3SJim Ingham private: 18975e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 18985e09c8c3SJim Ingham OptionGroupOptions m_option_group; 18995e09c8c3SJim Ingham }; 19005e09c8c3SJim Ingham 1901b9c1b51eSKate Stone class CommandObjectBreakpointNameDelete : public CommandObjectParsed { 19025e09c8c3SJim Ingham public: 1903b9c1b51eSKate Stone CommandObjectBreakpointNameDelete(CommandInterpreter &interpreter) 1904b9c1b51eSKate Stone : CommandObjectParsed( 1905b9c1b51eSKate Stone interpreter, "delete", 19065e09c8c3SJim Ingham "Delete a name from the breakpoints provided.", 19075e09c8c3SJim Ingham "breakpoint name delete <command-options> <breakpoint-id-list>"), 1908b9c1b51eSKate Stone m_name_options(), m_option_group() { 1909b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 1910b9c1b51eSKate Stone // command. 19115e09c8c3SJim Ingham CommandArgumentEntry arg1; 19125e09c8c3SJim Ingham CommandArgumentData id_arg; 19135e09c8c3SJim Ingham id_arg.arg_type = eArgTypeBreakpointID; 19145e09c8c3SJim Ingham id_arg.arg_repetition = eArgRepeatOptional; 19155e09c8c3SJim Ingham arg1.push_back(id_arg); 19165e09c8c3SJim Ingham m_arguments.push_back(arg1); 19175e09c8c3SJim Ingham 19185e09c8c3SJim Ingham m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); 19195e09c8c3SJim Ingham m_option_group.Finalize(); 19205e09c8c3SJim Ingham } 19215e09c8c3SJim Ingham 19229e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameDelete() override = default; 19235e09c8c3SJim Ingham 1924b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 19255e09c8c3SJim Ingham 19265e09c8c3SJim Ingham protected: 1927b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 1928b9c1b51eSKate Stone if (!m_name_options.m_name.OptionWasSet()) { 19295e09c8c3SJim Ingham result.SetError("No name option provided."); 19305e09c8c3SJim Ingham return false; 19315e09c8c3SJim Ingham } 19325e09c8c3SJim Ingham 1933b9c1b51eSKate Stone Target *target = 1934b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 19355e09c8c3SJim Ingham 1936b9c1b51eSKate Stone if (target == nullptr) { 19375e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 19385e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 19395e09c8c3SJim Ingham return false; 19405e09c8c3SJim Ingham } 19415e09c8c3SJim Ingham 1942bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 1943bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 19445e09c8c3SJim Ingham 19455e09c8c3SJim Ingham const BreakpointList &breakpoints = target->GetBreakpointList(); 19465e09c8c3SJim Ingham 19475e09c8c3SJim Ingham size_t num_breakpoints = breakpoints.GetSize(); 1948b9c1b51eSKate Stone if (num_breakpoints == 0) { 19495e09c8c3SJim Ingham result.SetError("No breakpoints, cannot delete names."); 19505e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 19515e09c8c3SJim Ingham return false; 19525e09c8c3SJim Ingham } 19535e09c8c3SJim Ingham 19545e09c8c3SJim Ingham // Particular breakpoint selected; disable that breakpoint. 19555e09c8c3SJim Ingham BreakpointIDList valid_bp_ids; 1956b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 1957b9c1b51eSKate Stone command, target, result, &valid_bp_ids); 19585e09c8c3SJim Ingham 1959b9c1b51eSKate Stone if (result.Succeeded()) { 1960b9c1b51eSKate Stone if (valid_bp_ids.GetSize() == 0) { 19615e09c8c3SJim Ingham result.SetError("No breakpoints specified, cannot delete names."); 19625e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 19635e09c8c3SJim Ingham return false; 19645e09c8c3SJim Ingham } 19655e09c8c3SJim Ingham size_t num_valid_ids = valid_bp_ids.GetSize(); 1966b9c1b51eSKate Stone for (size_t index = 0; index < num_valid_ids; index++) { 1967b9c1b51eSKate Stone lldb::break_id_t bp_id = 1968b9c1b51eSKate Stone valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); 19695e09c8c3SJim Ingham BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); 19705e09c8c3SJim Ingham bp_sp->RemoveName(m_name_options.m_name.GetCurrentValue()); 19715e09c8c3SJim Ingham } 19725e09c8c3SJim Ingham } 19735e09c8c3SJim Ingham 19745e09c8c3SJim Ingham return true; 19755e09c8c3SJim Ingham } 19765e09c8c3SJim Ingham 19775e09c8c3SJim Ingham private: 19785e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 19795e09c8c3SJim Ingham OptionGroupOptions m_option_group; 19805e09c8c3SJim Ingham }; 19815e09c8c3SJim Ingham 1982b9c1b51eSKate Stone class CommandObjectBreakpointNameList : public CommandObjectParsed { 19835e09c8c3SJim Ingham public: 1984b9c1b51eSKate Stone CommandObjectBreakpointNameList(CommandInterpreter &interpreter) 1985b9c1b51eSKate Stone : CommandObjectParsed(interpreter, "list", 1986b9c1b51eSKate Stone "List either the names for a breakpoint or the " 1987b9c1b51eSKate Stone "breakpoints for a given name.", 19885e09c8c3SJim Ingham "breakpoint name list <command-options>"), 1989b9c1b51eSKate Stone m_name_options(), m_option_group() { 19905e09c8c3SJim Ingham m_option_group.Append(&m_name_options); 19915e09c8c3SJim Ingham m_option_group.Finalize(); 19925e09c8c3SJim Ingham } 19935e09c8c3SJim Ingham 19949e85e5a8SEugene Zelenko ~CommandObjectBreakpointNameList() override = default; 19955e09c8c3SJim Ingham 1996b9c1b51eSKate Stone Options *GetOptions() override { return &m_option_group; } 19975e09c8c3SJim Ingham 19985e09c8c3SJim Ingham protected: 1999b9c1b51eSKate Stone bool DoExecute(Args &command, CommandReturnObject &result) override { 2000b9c1b51eSKate Stone Target *target = 2001b9c1b51eSKate Stone GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); 20025e09c8c3SJim Ingham 2003b9c1b51eSKate Stone if (target == nullptr) { 20045e09c8c3SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 20055e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20065e09c8c3SJim Ingham return false; 20075e09c8c3SJim Ingham } 20085e09c8c3SJim Ingham 2009b9c1b51eSKate Stone if (m_name_options.m_name.OptionWasSet()) { 20105e09c8c3SJim Ingham const char *name = m_name_options.m_name.GetCurrentValue(); 2011bb19a13cSSaleem Abdulrasool std::unique_lock<std::recursive_mutex> lock; 2012bb19a13cSSaleem Abdulrasool target->GetBreakpointList().GetListMutex(lock); 20135e09c8c3SJim Ingham 20145e09c8c3SJim Ingham BreakpointList &breakpoints = target->GetBreakpointList(); 2015b9c1b51eSKate Stone for (BreakpointSP bp_sp : breakpoints.Breakpoints()) { 2016b9c1b51eSKate Stone if (bp_sp->MatchesName(name)) { 20175e09c8c3SJim Ingham StreamString s; 20185e09c8c3SJim Ingham bp_sp->GetDescription(&s, eDescriptionLevelBrief); 20195e09c8c3SJim Ingham s.EOL(); 20205e09c8c3SJim Ingham result.AppendMessage(s.GetData()); 20215e09c8c3SJim Ingham } 20225e09c8c3SJim Ingham } 20235e09c8c3SJim Ingham 2024b9c1b51eSKate Stone } else if (m_name_options.m_breakpoint.OptionWasSet()) { 2025b9c1b51eSKate Stone BreakpointSP bp_sp = target->GetBreakpointList().FindBreakpointByID( 2026b9c1b51eSKate Stone m_name_options.m_breakpoint.GetCurrentValue()); 2027b9c1b51eSKate Stone if (bp_sp) { 20285e09c8c3SJim Ingham std::vector<std::string> names; 20295e09c8c3SJim Ingham bp_sp->GetNames(names); 20305e09c8c3SJim Ingham result.AppendMessage("Names:"); 20315e09c8c3SJim Ingham for (auto name : names) 20325e09c8c3SJim Ingham result.AppendMessageWithFormat(" %s\n", name.c_str()); 2033b9c1b51eSKate Stone } else { 2034b9c1b51eSKate Stone result.AppendErrorWithFormat( 2035b9c1b51eSKate Stone "Could not find breakpoint %" PRId64 ".\n", 20365e09c8c3SJim Ingham m_name_options.m_breakpoint.GetCurrentValue()); 20375e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20385e09c8c3SJim Ingham return false; 20395e09c8c3SJim Ingham } 2040b9c1b51eSKate Stone } else { 20415e09c8c3SJim Ingham result.SetError("Must specify -N or -B option to list."); 20425e09c8c3SJim Ingham result.SetStatus(eReturnStatusFailed); 20435e09c8c3SJim Ingham return false; 20445e09c8c3SJim Ingham } 20455e09c8c3SJim Ingham return true; 20465e09c8c3SJim Ingham } 20475e09c8c3SJim Ingham 20485e09c8c3SJim Ingham private: 20495e09c8c3SJim Ingham BreakpointNameOptionGroup m_name_options; 20505e09c8c3SJim Ingham OptionGroupOptions m_option_group; 20515e09c8c3SJim Ingham }; 20525e09c8c3SJim Ingham 20535e09c8c3SJim Ingham //------------------------------------------------------------------------- 2054e14dc268SJim Ingham // CommandObjectBreakpointName 20555e09c8c3SJim Ingham //------------------------------------------------------------------------- 2056b9c1b51eSKate Stone class CommandObjectBreakpointName : public CommandObjectMultiword { 20575e09c8c3SJim Ingham public: 20587428a18cSKate Stone CommandObjectBreakpointName(CommandInterpreter &interpreter) 2059b9c1b51eSKate Stone : CommandObjectMultiword( 2060b9c1b51eSKate Stone interpreter, "name", "Commands to manage name tags for breakpoints", 2061b9c1b51eSKate Stone "breakpoint name <subcommand> [<command-options>]") { 2062b9c1b51eSKate Stone CommandObjectSP add_command_object( 2063b9c1b51eSKate Stone new CommandObjectBreakpointNameAdd(interpreter)); 2064b9c1b51eSKate Stone CommandObjectSP delete_command_object( 2065b9c1b51eSKate Stone new CommandObjectBreakpointNameDelete(interpreter)); 2066b9c1b51eSKate Stone CommandObjectSP list_command_object( 2067b9c1b51eSKate Stone new CommandObjectBreakpointNameList(interpreter)); 20685e09c8c3SJim Ingham 20695e09c8c3SJim Ingham LoadSubCommand("add", add_command_object); 20705e09c8c3SJim Ingham LoadSubCommand("delete", delete_command_object); 20715e09c8c3SJim Ingham LoadSubCommand("list", list_command_object); 20725e09c8c3SJim Ingham } 20735e09c8c3SJim Ingham 20749e85e5a8SEugene Zelenko ~CommandObjectBreakpointName() override = default; 20755e09c8c3SJim Ingham }; 20765e09c8c3SJim Ingham 20775e09c8c3SJim Ingham //------------------------------------------------------------------------- 2078e14dc268SJim Ingham // CommandObjectBreakpointRead 2079e14dc268SJim Ingham //------------------------------------------------------------------------- 2080*3acdf385SJim Ingham #pragma mark Read::CommandOptions 20811f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_read_options[] = { 20821f0f5b5bSZachary Turner // clang-format off 20831f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename, "The file from which to read the breakpoints." }, 2084*3acdf385SJim Ingham {LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Only read in breakpoints with this name."}, 20851f0f5b5bSZachary Turner // clang-format on 20861f0f5b5bSZachary Turner }; 20871f0f5b5bSZachary Turner 20881f0f5b5bSZachary Turner #pragma mark Read 2089e14dc268SJim Ingham 2090e14dc268SJim Ingham class CommandObjectBreakpointRead : public CommandObjectParsed { 2091e14dc268SJim Ingham public: 2092e14dc268SJim Ingham CommandObjectBreakpointRead(CommandInterpreter &interpreter) 2093e14dc268SJim Ingham : CommandObjectParsed(interpreter, "breakpoint read", 2094e14dc268SJim Ingham "Read and set the breakpoints previously saved to " 2095e14dc268SJim Ingham "a file with \"breakpoint write\". ", 2096e14dc268SJim Ingham nullptr), 2097e14dc268SJim Ingham m_options() { 2098e14dc268SJim Ingham CommandArgumentEntry arg; 2099e14dc268SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 2100e14dc268SJim Ingham eArgTypeBreakpointIDRange); 2101e14dc268SJim Ingham // Add the entry for the first argument for this command to the object's 2102e14dc268SJim Ingham // arguments vector. 2103e14dc268SJim Ingham m_arguments.push_back(arg); 2104e14dc268SJim Ingham } 2105e14dc268SJim Ingham 2106e14dc268SJim Ingham ~CommandObjectBreakpointRead() override = default; 2107e14dc268SJim Ingham 2108e14dc268SJim Ingham Options *GetOptions() override { return &m_options; } 2109e14dc268SJim Ingham 2110e14dc268SJim Ingham class CommandOptions : public Options { 2111e14dc268SJim Ingham public: 2112e14dc268SJim Ingham CommandOptions() : Options() {} 2113e14dc268SJim Ingham 2114e14dc268SJim Ingham ~CommandOptions() override = default; 2115e14dc268SJim Ingham 2116e14dc268SJim Ingham Error SetOptionValue(uint32_t option_idx, const char *option_arg, 2117e14dc268SJim Ingham ExecutionContext *execution_context) override { 2118e14dc268SJim Ingham Error error; 2119e14dc268SJim Ingham const int short_option = m_getopt_table[option_idx].val; 2120e14dc268SJim Ingham 2121e14dc268SJim Ingham switch (short_option) { 2122e14dc268SJim Ingham case 'f': 2123e14dc268SJim Ingham m_filename.assign(option_arg); 2124e14dc268SJim Ingham break; 2125*3acdf385SJim Ingham case 'N': { 2126*3acdf385SJim Ingham Error name_error; 2127*3acdf385SJim Ingham if (!BreakpointID::StringIsBreakpointName(llvm::StringRef(option_arg), 2128*3acdf385SJim Ingham name_error)) { 2129*3acdf385SJim Ingham error.SetErrorStringWithFormat("Invalid breakpoint name: %s", 2130*3acdf385SJim Ingham name_error.AsCString()); 2131*3acdf385SJim Ingham } 2132*3acdf385SJim Ingham m_names.push_back(option_arg); 2133*3acdf385SJim Ingham break; 2134*3acdf385SJim Ingham } 2135e14dc268SJim Ingham default: 2136e14dc268SJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 2137e14dc268SJim Ingham short_option); 2138e14dc268SJim Ingham break; 2139e14dc268SJim Ingham } 2140e14dc268SJim Ingham 2141e14dc268SJim Ingham return error; 2142e14dc268SJim Ingham } 2143e14dc268SJim Ingham 2144e14dc268SJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 2145e14dc268SJim Ingham m_filename.clear(); 2146*3acdf385SJim Ingham m_names.clear(); 2147e14dc268SJim Ingham } 2148e14dc268SJim Ingham 21491f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 215070602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_read_options); 21511f0f5b5bSZachary Turner } 2152e14dc268SJim Ingham 2153e14dc268SJim Ingham // Instance variables to hold the values for command options. 2154e14dc268SJim Ingham 2155e14dc268SJim Ingham std::string m_filename; 2156*3acdf385SJim Ingham std::vector<std::string> m_names; 2157e14dc268SJim Ingham }; 2158e14dc268SJim Ingham 2159e14dc268SJim Ingham protected: 2160e14dc268SJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 2161e14dc268SJim Ingham Target *target = GetSelectedOrDummyTarget(); 2162e14dc268SJim Ingham if (target == nullptr) { 2163e14dc268SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 2164e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2165e14dc268SJim Ingham return false; 2166e14dc268SJim Ingham } 2167e14dc268SJim Ingham 2168*3acdf385SJim Ingham std::unique_lock<std::recursive_mutex> lock; 2169*3acdf385SJim Ingham target->GetBreakpointList().GetListMutex(lock); 2170*3acdf385SJim Ingham 2171e14dc268SJim Ingham FileSpec input_spec(m_options.m_filename, true); 217201f16664SJim Ingham BreakpointIDList new_bps; 2173*3acdf385SJim Ingham Error error = target->CreateBreakpointsFromFile(input_spec, 2174*3acdf385SJim Ingham m_options.m_names, new_bps); 2175e14dc268SJim Ingham 2176e14dc268SJim Ingham if (!error.Success()) { 217701f16664SJim Ingham result.AppendError(error.AsCString()); 2178e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 217901f16664SJim Ingham return false; 2180e14dc268SJim Ingham } 2181*3acdf385SJim Ingham 2182*3acdf385SJim Ingham Stream &output_stream = result.GetOutputStream(); 2183*3acdf385SJim Ingham 2184*3acdf385SJim Ingham size_t num_breakpoints = new_bps.GetSize(); 2185*3acdf385SJim Ingham if (num_breakpoints == 0) { 2186*3acdf385SJim Ingham result.AppendMessage("No breakpoints added."); 2187*3acdf385SJim Ingham } else { 2188*3acdf385SJim Ingham // No breakpoint selected; show info about all currently set breakpoints. 2189*3acdf385SJim Ingham result.AppendMessage("New breakpoints:"); 2190*3acdf385SJim Ingham for (size_t i = 0; i < num_breakpoints; ++i) { 2191*3acdf385SJim Ingham BreakpointID bp_id = new_bps.GetBreakpointIDAtIndex(i); 2192*3acdf385SJim Ingham Breakpoint *bp = target->GetBreakpointList() 2193*3acdf385SJim Ingham .FindBreakpointByID(bp_id.GetBreakpointID()) 2194*3acdf385SJim Ingham .get(); 2195*3acdf385SJim Ingham if (bp) 2196*3acdf385SJim Ingham bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, 2197*3acdf385SJim Ingham false); 2198*3acdf385SJim Ingham } 2199*3acdf385SJim Ingham } 2200e14dc268SJim Ingham return result.Succeeded(); 2201e14dc268SJim Ingham } 2202e14dc268SJim Ingham 2203e14dc268SJim Ingham private: 2204e14dc268SJim Ingham CommandOptions m_options; 2205e14dc268SJim Ingham }; 2206e14dc268SJim Ingham 2207e14dc268SJim Ingham //------------------------------------------------------------------------- 2208e14dc268SJim Ingham // CommandObjectBreakpointWrite 2209e14dc268SJim Ingham //------------------------------------------------------------------------- 22101f0f5b5bSZachary Turner #pragma mark Write::CommandOptions 22111f0f5b5bSZachary Turner static OptionDefinition g_breakpoint_write_options[] = { 22121f0f5b5bSZachary Turner // clang-format off 22131f0f5b5bSZachary Turner { LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename, "The file into which to write the breakpoints." }, 22141f0f5b5bSZachary Turner // clang-format on 22151f0f5b5bSZachary Turner }; 22161f0f5b5bSZachary Turner 22171f0f5b5bSZachary Turner #pragma mark Write 2218e14dc268SJim Ingham class CommandObjectBreakpointWrite : public CommandObjectParsed { 2219e14dc268SJim Ingham public: 2220e14dc268SJim Ingham CommandObjectBreakpointWrite(CommandInterpreter &interpreter) 2221e14dc268SJim Ingham : CommandObjectParsed(interpreter, "breakpoint write", 2222e14dc268SJim Ingham "Write the breakpoints listed to a file that can " 2223e14dc268SJim Ingham "be read in with \"breakpoint read\". " 2224e14dc268SJim Ingham "If given no arguments, writes all breakpoints.", 2225e14dc268SJim Ingham nullptr), 2226e14dc268SJim Ingham m_options() { 2227e14dc268SJim Ingham CommandArgumentEntry arg; 2228e14dc268SJim Ingham CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, 2229e14dc268SJim Ingham eArgTypeBreakpointIDRange); 2230e14dc268SJim Ingham // Add the entry for the first argument for this command to the object's 2231e14dc268SJim Ingham // arguments vector. 2232e14dc268SJim Ingham m_arguments.push_back(arg); 2233e14dc268SJim Ingham } 2234e14dc268SJim Ingham 2235e14dc268SJim Ingham ~CommandObjectBreakpointWrite() override = default; 2236e14dc268SJim Ingham 2237e14dc268SJim Ingham Options *GetOptions() override { return &m_options; } 2238e14dc268SJim Ingham 2239e14dc268SJim Ingham class CommandOptions : public Options { 2240e14dc268SJim Ingham public: 2241e14dc268SJim Ingham CommandOptions() : Options() {} 2242e14dc268SJim Ingham 2243e14dc268SJim Ingham ~CommandOptions() override = default; 2244e14dc268SJim Ingham 2245e14dc268SJim Ingham Error SetOptionValue(uint32_t option_idx, const char *option_arg, 2246e14dc268SJim Ingham ExecutionContext *execution_context) override { 2247e14dc268SJim Ingham Error error; 2248e14dc268SJim Ingham const int short_option = m_getopt_table[option_idx].val; 2249e14dc268SJim Ingham 2250e14dc268SJim Ingham switch (short_option) { 2251e14dc268SJim Ingham case 'f': 2252e14dc268SJim Ingham m_filename.assign(option_arg); 2253e14dc268SJim Ingham break; 2254e14dc268SJim Ingham default: 2255e14dc268SJim Ingham error.SetErrorStringWithFormat("unrecognized option '%c'", 2256e14dc268SJim Ingham short_option); 2257e14dc268SJim Ingham break; 2258e14dc268SJim Ingham } 2259e14dc268SJim Ingham 2260e14dc268SJim Ingham return error; 2261e14dc268SJim Ingham } 2262e14dc268SJim Ingham 2263e14dc268SJim Ingham void OptionParsingStarting(ExecutionContext *execution_context) override { 2264e14dc268SJim Ingham m_filename.clear(); 2265e14dc268SJim Ingham } 2266e14dc268SJim Ingham 22671f0f5b5bSZachary Turner llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 226870602439SZachary Turner return llvm::makeArrayRef(g_breakpoint_write_options); 22691f0f5b5bSZachary Turner } 2270e14dc268SJim Ingham 2271e14dc268SJim Ingham // Instance variables to hold the values for command options. 2272e14dc268SJim Ingham 2273e14dc268SJim Ingham std::string m_filename; 2274e14dc268SJim Ingham }; 2275e14dc268SJim Ingham 2276e14dc268SJim Ingham protected: 2277e14dc268SJim Ingham bool DoExecute(Args &command, CommandReturnObject &result) override { 2278e14dc268SJim Ingham Target *target = GetSelectedOrDummyTarget(); 2279e14dc268SJim Ingham if (target == nullptr) { 2280e14dc268SJim Ingham result.AppendError("Invalid target. No existing target or breakpoints."); 2281e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2282e14dc268SJim Ingham return false; 2283e14dc268SJim Ingham } 2284e14dc268SJim Ingham 2285e14dc268SJim Ingham std::unique_lock<std::recursive_mutex> lock; 2286e14dc268SJim Ingham target->GetBreakpointList().GetListMutex(lock); 2287e14dc268SJim Ingham 2288e14dc268SJim Ingham BreakpointIDList valid_bp_ids; 228901f16664SJim Ingham if (command.GetArgumentCount() > 0) { 2290e14dc268SJim Ingham CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( 2291e14dc268SJim Ingham command, target, result, &valid_bp_ids); 2292e14dc268SJim Ingham 229301f16664SJim Ingham if (!result.Succeeded()) { 2294e14dc268SJim Ingham result.SetStatus(eReturnStatusFailed); 2295e14dc268SJim Ingham return false; 2296e14dc268SJim Ingham } 2297e14dc268SJim Ingham } 229801f16664SJim Ingham Error error = target->SerializeBreakpointsToFile( 229901f16664SJim Ingham FileSpec(m_options.m_filename.c_str(), true), valid_bp_ids); 230001f16664SJim Ingham if (!error.Success()) { 230101f16664SJim Ingham result.AppendErrorWithFormat("error serializing breakpoints: %s.", 230201f16664SJim Ingham error.AsCString()); 230301f16664SJim Ingham result.SetStatus(eReturnStatusFailed); 2304e14dc268SJim Ingham } 2305e14dc268SJim Ingham return result.Succeeded(); 2306e14dc268SJim Ingham } 2307e14dc268SJim Ingham 2308e14dc268SJim Ingham private: 2309e14dc268SJim Ingham CommandOptions m_options; 2310e14dc268SJim Ingham }; 2311e14dc268SJim Ingham 2312e14dc268SJim Ingham //------------------------------------------------------------------------- 231330fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint 231430fdc8d8SChris Lattner //------------------------------------------------------------------------- 2315ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint 231630fdc8d8SChris Lattner 2317b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint( 2318b9c1b51eSKate Stone CommandInterpreter &interpreter) 2319b9c1b51eSKate Stone : CommandObjectMultiword( 2320b9c1b51eSKate Stone interpreter, "breakpoint", 23217428a18cSKate Stone "Commands for operating on breakpoints (see 'help b' for shorthand.)", 2322b9c1b51eSKate Stone "breakpoint <subcommand> [<command-options>]") { 2323b9c1b51eSKate Stone CommandObjectSP list_command_object( 2324b9c1b51eSKate Stone new CommandObjectBreakpointList(interpreter)); 2325b9c1b51eSKate Stone CommandObjectSP enable_command_object( 2326b9c1b51eSKate Stone new CommandObjectBreakpointEnable(interpreter)); 2327b9c1b51eSKate Stone CommandObjectSP disable_command_object( 2328b9c1b51eSKate Stone new CommandObjectBreakpointDisable(interpreter)); 2329b9c1b51eSKate Stone CommandObjectSP clear_command_object( 2330b9c1b51eSKate Stone new CommandObjectBreakpointClear(interpreter)); 2331b9c1b51eSKate Stone CommandObjectSP delete_command_object( 2332b9c1b51eSKate Stone new CommandObjectBreakpointDelete(interpreter)); 2333b9c1b51eSKate Stone CommandObjectSP set_command_object( 2334b9c1b51eSKate Stone new CommandObjectBreakpointSet(interpreter)); 2335b9c1b51eSKate Stone CommandObjectSP command_command_object( 2336b9c1b51eSKate Stone new CommandObjectBreakpointCommand(interpreter)); 2337b9c1b51eSKate Stone CommandObjectSP modify_command_object( 2338b9c1b51eSKate Stone new CommandObjectBreakpointModify(interpreter)); 2339b9c1b51eSKate Stone CommandObjectSP name_command_object( 2340b9c1b51eSKate Stone new CommandObjectBreakpointName(interpreter)); 2341e14dc268SJim Ingham CommandObjectSP write_command_object( 2342e14dc268SJim Ingham new CommandObjectBreakpointWrite(interpreter)); 2343e14dc268SJim Ingham CommandObjectSP read_command_object( 2344e14dc268SJim Ingham new CommandObjectBreakpointRead(interpreter)); 234530fdc8d8SChris Lattner 2346b7234e40SJohnny Chen list_command_object->SetCommandName("breakpoint list"); 234730fdc8d8SChris Lattner enable_command_object->SetCommandName("breakpoint enable"); 234830fdc8d8SChris Lattner disable_command_object->SetCommandName("breakpoint disable"); 2349b7234e40SJohnny Chen clear_command_object->SetCommandName("breakpoint clear"); 2350b7234e40SJohnny Chen delete_command_object->SetCommandName("breakpoint delete"); 2351ae1c4cf5SJim Ingham set_command_object->SetCommandName("breakpoint set"); 2352b7234e40SJohnny Chen command_command_object->SetCommandName("breakpoint command"); 2353b7234e40SJohnny Chen modify_command_object->SetCommandName("breakpoint modify"); 23545e09c8c3SJim Ingham name_command_object->SetCommandName("breakpoint name"); 2355e14dc268SJim Ingham write_command_object->SetCommandName("breakpoint write"); 2356e14dc268SJim Ingham read_command_object->SetCommandName("breakpoint read"); 235730fdc8d8SChris Lattner 235823f59509SGreg Clayton LoadSubCommand("list", list_command_object); 235923f59509SGreg Clayton LoadSubCommand("enable", enable_command_object); 236023f59509SGreg Clayton LoadSubCommand("disable", disable_command_object); 236123f59509SGreg Clayton LoadSubCommand("clear", clear_command_object); 236223f59509SGreg Clayton LoadSubCommand("delete", delete_command_object); 236323f59509SGreg Clayton LoadSubCommand("set", set_command_object); 236423f59509SGreg Clayton LoadSubCommand("command", command_command_object); 236523f59509SGreg Clayton LoadSubCommand("modify", modify_command_object); 23665e09c8c3SJim Ingham LoadSubCommand("name", name_command_object); 2367e14dc268SJim Ingham LoadSubCommand("write", write_command_object); 2368e14dc268SJim Ingham LoadSubCommand("read", read_command_object); 236930fdc8d8SChris Lattner } 237030fdc8d8SChris Lattner 23719e85e5a8SEugene Zelenko CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default; 237230fdc8d8SChris Lattner 2373b9c1b51eSKate Stone void CommandObjectMultiwordBreakpoint::VerifyIDs(Args &args, Target *target, 23745e09c8c3SJim Ingham bool allow_locations, 23755e09c8c3SJim Ingham CommandReturnObject &result, 2376b9c1b51eSKate Stone BreakpointIDList *valid_ids) { 237730fdc8d8SChris Lattner // args can be strings representing 1). integers (for breakpoint ids) 2378b9c1b51eSKate Stone // 2). the full breakpoint & location 2379b9c1b51eSKate Stone // canonical representation 2380b9c1b51eSKate Stone // 3). the word "to" or a hyphen, 2381b9c1b51eSKate Stone // representing a range (in which case there 2382b9c1b51eSKate Stone // had *better* be an entry both before & 2383b9c1b51eSKate Stone // after of one of the first two types. 23845e09c8c3SJim Ingham // 4). A breakpoint name 2385b9c1b51eSKate Stone // If args is empty, we will use the last created breakpoint (if there is 2386b9c1b51eSKate Stone // one.) 238730fdc8d8SChris Lattner 238830fdc8d8SChris Lattner Args temp_args; 238930fdc8d8SChris Lattner 2390b9c1b51eSKate Stone if (args.GetArgumentCount() == 0) { 2391b9c1b51eSKate Stone if (target->GetLastCreatedBreakpoint()) { 2392b9c1b51eSKate Stone valid_ids->AddBreakpointID(BreakpointID( 2393b9c1b51eSKate Stone target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); 239436f3b369SJim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 2395b9c1b51eSKate Stone } else { 2396b9c1b51eSKate Stone result.AppendError( 2397b9c1b51eSKate Stone "No breakpoint specified and no last created breakpoint."); 239836f3b369SJim Ingham result.SetStatus(eReturnStatusFailed); 239936f3b369SJim Ingham } 240036f3b369SJim Ingham return; 240136f3b369SJim Ingham } 240236f3b369SJim Ingham 2403b9c1b51eSKate Stone // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff 2404b9c1b51eSKate Stone // directly from the old ARGS to 2405b9c1b51eSKate Stone // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead 2406b9c1b51eSKate Stone // generate a list of strings for 2407b9c1b51eSKate Stone // all the breakpoint ids in the range, and shove all of those breakpoint id 2408b9c1b51eSKate Stone // strings into TEMP_ARGS. 240930fdc8d8SChris Lattner 2410b9c1b51eSKate Stone BreakpointIDList::FindAndReplaceIDRanges(args, target, allow_locations, 2411b9c1b51eSKate Stone result, temp_args); 241230fdc8d8SChris Lattner 2413b9c1b51eSKate Stone // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual 2414b9c1b51eSKate Stone // BreakpointIDList: 241530fdc8d8SChris Lattner 2416b9c1b51eSKate Stone valid_ids->InsertStringArray(temp_args.GetConstArgumentVector(), 2417b9c1b51eSKate Stone temp_args.GetArgumentCount(), result); 241830fdc8d8SChris Lattner 2419b9c1b51eSKate Stone // At this point, all of the breakpoint ids that the user passed in have been 2420b9c1b51eSKate Stone // converted to breakpoint IDs 242130fdc8d8SChris Lattner // and put into valid_ids. 242230fdc8d8SChris Lattner 2423b9c1b51eSKate Stone if (result.Succeeded()) { 2424b9c1b51eSKate Stone // Now that we've converted everything from args into a list of breakpoint 2425b9c1b51eSKate Stone // ids, go through our tentative list 2426b9c1b51eSKate Stone // of breakpoint id's and verify that they correspond to valid/currently set 2427b9c1b51eSKate Stone // breakpoints. 242830fdc8d8SChris Lattner 2429c982c768SGreg Clayton const size_t count = valid_ids->GetSize(); 2430b9c1b51eSKate Stone for (size_t i = 0; i < count; ++i) { 243130fdc8d8SChris Lattner BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex(i); 2432b9c1b51eSKate Stone Breakpoint *breakpoint = 2433b9c1b51eSKate Stone target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); 2434b9c1b51eSKate Stone if (breakpoint != nullptr) { 2435c7bece56SGreg Clayton const size_t num_locations = breakpoint->GetNumLocations(); 2436b9c1b51eSKate Stone if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations) { 243730fdc8d8SChris Lattner StreamString id_str; 2438b9c1b51eSKate Stone BreakpointID::GetCanonicalReference( 2439b9c1b51eSKate Stone &id_str, cur_bp_id.GetBreakpointID(), cur_bp_id.GetLocationID()); 2440c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 2441b9c1b51eSKate Stone result.AppendErrorWithFormat( 2442b9c1b51eSKate Stone "'%s' is not a currently valid breakpoint/location id.\n", 244330fdc8d8SChris Lattner id_str.GetData()); 244430fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 244530fdc8d8SChris Lattner } 2446b9c1b51eSKate Stone } else { 2447c982c768SGreg Clayton i = valid_ids->GetSize() + 1; 2448b9c1b51eSKate Stone result.AppendErrorWithFormat( 2449b9c1b51eSKate Stone "'%d' is not a currently valid breakpoint ID.\n", 24507428a18cSKate Stone cur_bp_id.GetBreakpointID()); 245130fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 245230fdc8d8SChris Lattner } 245330fdc8d8SChris Lattner } 245430fdc8d8SChris Lattner } 245530fdc8d8SChris Lattner } 2456