Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandObjectBreakpoint.cpp -----------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "CommandObjectBreakpoint.h" |
| 11 | #include "CommandObjectBreakpointCommand.h" |
| 12 | |
| 13 | // C Includes |
| 14 | // C++ Includes |
| 15 | // Other libraries and framework includes |
| 16 | // Project includes |
| 17 | #include "lldb/Breakpoint/Breakpoint.h" |
| 18 | #include "lldb/Breakpoint/BreakpointIDList.h" |
| 19 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Jim Ingham | 84cdc15 | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 20 | #include "lldb/Interpreter/Options.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/Core/RegularExpression.h" |
| 22 | #include "lldb/Core/StreamString.h" |
| 23 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 24 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 25 | #include "lldb/Target/Target.h" |
| 26 | #include "lldb/Interpreter/CommandCompletions.h" |
| 27 | #include "lldb/Target/StackFrame.h" |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 28 | #include "lldb/Target/Thread.h" |
| 29 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 31 | #include <vector> |
| 32 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | using namespace lldb; |
| 34 | using namespace lldb_private; |
| 35 | |
| 36 | static void |
Jim Ingham | 2e8cb8a | 2011-02-19 02:53:09 +0000 | [diff] [blame] | 37 | AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | { |
| 39 | s->IndentMore(); |
| 40 | bp->GetDescription (s, level, true); |
| 41 | s->IndentLess(); |
| 42 | s->EOL(); |
| 43 | } |
| 44 | |
| 45 | //------------------------------------------------------------------------- |
| 46 | // CommandObjectBreakpointSet::CommandOptions |
| 47 | //------------------------------------------------------------------------- |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 48 | #pragma mark Set::CommandOptions |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 50 | CommandObjectBreakpointSet::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : |
| 51 | Options (interpreter), |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 52 | m_filenames (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | m_line_num (0), |
| 54 | m_column (0), |
Greg Clayton | 2dfe4c6 | 2010-11-02 03:02:38 +0000 | [diff] [blame] | 55 | m_check_inlines (true), |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 56 | m_func_names (), |
| 57 | m_func_name_type_mask (eFunctionNameTypeNone), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | m_func_regexp (), |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 59 | m_source_text_regexp(), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | m_modules (), |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 61 | m_load_addr(), |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 62 | m_ignore_count (0), |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 63 | m_thread_id(LLDB_INVALID_THREAD_ID), |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 64 | m_thread_index (UINT32_MAX), |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 65 | m_thread_name(), |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 66 | m_queue_name(), |
| 67 | m_catch_bp (false), |
| 68 | m_throw_bp (false), |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 69 | m_language (eLanguageTypeUnknown), |
| 70 | m_skip_prologue (eLazyBoolCalculate) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | CommandObjectBreakpointSet::CommandOptions::~CommandOptions () |
| 75 | { |
| 76 | } |
| 77 | |
Johnny Chen | 8d03c6f | 2012-05-08 00:43:20 +0000 | [diff] [blame] | 78 | // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to |
| 79 | // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately. |
Johnny Chen | 6f4a115 | 2012-05-07 23:23:41 +0000 | [diff] [blame] | 80 | #define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 ) |
| 81 | #define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 ) |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 82 | #define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) ) |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 83 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 84 | OptionDefinition |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 85 | CommandObjectBreakpointSet::CommandOptions::g_option_table[] = |
| 86 | { |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 87 | { LLDB_OPT_NOT_10, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName, |
Jim Ingham | ee033f2 | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 88 | "Set the breakpoint only in this shared library. " |
| 89 | "Can repeat this option multiple times to specify multiple shared libraries."}, |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 90 | |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 91 | { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount, |
| 92 | "Set the number of times this breakpoint is skipped before stopping." }, |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 93 | |
Bill Wendling | ff7df6d | 2012-04-03 04:13:41 +0000 | [diff] [blame] | 94 | { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex, |
Greg Clayton | fe424a9 | 2010-09-18 03:37:20 +0000 | [diff] [blame] | 95 | "The breakpoint stops only for the thread whose index matches this argument."}, |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 96 | |
Bill Wendling | ff7df6d | 2012-04-03 04:13:41 +0000 | [diff] [blame] | 97 | { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID, |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 98 | "The breakpoint stops only for the thread whose TID matches this argument."}, |
| 99 | |
Bill Wendling | ff7df6d | 2012-04-03 04:13:41 +0000 | [diff] [blame] | 100 | { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName, |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 101 | "The breakpoint stops only for the thread whose thread name matches this argument."}, |
| 102 | |
Bill Wendling | ff7df6d | 2012-04-03 04:13:41 +0000 | [diff] [blame] | 103 | { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName, |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 104 | "The breakpoint stops only for threads in the queue whose name is given by this argument."}, |
| 105 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 106 | { LLDB_OPT_FILE, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, |
| 107 | "Specifies the source file in which to set this breakpoint."}, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 108 | |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 109 | { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 110 | "Specifies the line number on which to set this breakpoint."}, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 112 | // Comment out this option for the moment, as we don't actually use it, but will in the future. |
| 113 | // This way users won't see it, but the infrastructure is left in place. |
| 114 | // { 0, false, "column", 'c', required_argument, NULL, "<column>", |
| 115 | // "Set the breakpoint by source location at this particular column."}, |
| 116 | |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 117 | { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | "Set the breakpoint by address, at the specified address."}, |
| 119 | |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 120 | { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, |
Jim Ingham | ee033f2 | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 121 | "Set the breakpoint by function name. Can be repeated multiple times to make one breakpoint for multiple snames" }, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 122 | |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 123 | { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName, |
Jim Ingham | ee033f2 | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 124 | "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and " |
| 125 | "for Objective C this means a full function prototype with class and selector. " |
| 126 | "Can be repeated multiple times to make one breakpoint for multiple names." }, |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 127 | |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 128 | { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector, |
Jim Ingham | ee033f2 | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 129 | "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." }, |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 130 | |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 131 | { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod, |
Jim Ingham | ee033f2 | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 132 | "Set the breakpoint by C++ method names. Can be repeated multiple times to make one breakpoint for multiple methods." }, |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 133 | |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 134 | { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 135 | "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." }, |
| 136 | |
Greg Clayton | 48fbdf7 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 137 | { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, |
Jim Ingham | ee033f2 | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 138 | "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). " |
| 139 | "Can be repeated multiple times to make one breakpoint for multiple symbols." }, |
Greg Clayton | 48fbdf7 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 140 | |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 141 | { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', required_argument, NULL, 0, eArgTypeRegularExpression, |
| 142 | "Set the breakpoint specifying a regular expression to match a pattern in the source text in a given source file." }, |
| 143 | |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 144 | { LLDB_OPT_SET_10, true, "language-exception", 'E', required_argument, NULL, 0, eArgTypeLanguage, |
| 145 | "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" }, |
| 146 | |
| 147 | { LLDB_OPT_SET_10, false, "on-throw", 'w', required_argument, NULL, 0, eArgTypeBoolean, |
| 148 | "Set the breakpoint on exception throW." }, |
| 149 | |
| 150 | { LLDB_OPT_SET_10, false, "on-catch", 'h', required_argument, NULL, 0, eArgTypeBoolean, |
| 151 | "Set the breakpoint on exception catcH." }, |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 152 | |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 153 | { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', required_argument, NULL, 0, eArgTypeBoolean, |
| 154 | "sKip the prologue if the breakpoint is at the beginning of a function. If not set the target.skip-prologue setting is used." }, |
| 155 | |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 156 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 157 | }; |
| 158 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 159 | const OptionDefinition* |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 160 | CommandObjectBreakpointSet::CommandOptions::GetDefinitions () |
| 161 | { |
| 162 | return g_option_table; |
| 163 | } |
| 164 | |
| 165 | Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 166 | CommandObjectBreakpointSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | { |
| 168 | Error error; |
| 169 | char short_option = (char) m_getopt_table[option_idx].val; |
| 170 | |
| 171 | switch (short_option) |
| 172 | { |
| 173 | case 'a': |
Jim Ingham | 7a4c8ea | 2011-03-22 01:53:33 +0000 | [diff] [blame] | 174 | m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 175 | if (m_load_addr == LLDB_INVALID_ADDRESS) |
Jim Ingham | 7a4c8ea | 2011-03-22 01:53:33 +0000 | [diff] [blame] | 176 | m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 177 | |
| 178 | if (m_load_addr == LLDB_INVALID_ADDRESS) |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 179 | error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 180 | break; |
| 181 | |
| 182 | case 'c': |
| 183 | m_column = Args::StringToUInt32 (option_arg, 0); |
| 184 | break; |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 185 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 186 | case 'f': |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 187 | m_filenames.AppendIfUnique (FileSpec(option_arg, false)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 188 | break; |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 189 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 190 | case 'l': |
| 191 | m_line_num = Args::StringToUInt32 (option_arg, 0); |
| 192 | break; |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 193 | |
Greg Clayton | 48fbdf7 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 194 | case 'b': |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 195 | m_func_names.push_back (option_arg); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 196 | m_func_name_type_mask |= eFunctionNameTypeBase; |
| 197 | break; |
| 198 | |
Greg Clayton | 48fbdf7 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 199 | case 'n': |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 200 | m_func_names.push_back (option_arg); |
Greg Clayton | 48fbdf7 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 201 | m_func_name_type_mask |= eFunctionNameTypeAuto; |
| 202 | break; |
| 203 | |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 204 | case 'F': |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 205 | m_func_names.push_back (option_arg); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 206 | m_func_name_type_mask |= eFunctionNameTypeFull; |
| 207 | break; |
| 208 | |
| 209 | case 'S': |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 210 | m_func_names.push_back (option_arg); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 211 | m_func_name_type_mask |= eFunctionNameTypeSelector; |
| 212 | break; |
| 213 | |
Jim Ingham | d9e2b76 | 2010-08-26 23:56:11 +0000 | [diff] [blame] | 214 | case 'M': |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 215 | m_func_names.push_back (option_arg); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 216 | m_func_name_type_mask |= eFunctionNameTypeMethod; |
| 217 | break; |
| 218 | |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 219 | case 'p': |
| 220 | m_source_text_regexp.assign (option_arg); |
| 221 | break; |
| 222 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 223 | case 'r': |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 224 | m_func_regexp.assign (option_arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 225 | break; |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 226 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 227 | case 's': |
| 228 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 229 | m_modules.AppendIfUnique (FileSpec (option_arg, false)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 230 | break; |
| 231 | } |
Greg Clayton | fe424a9 | 2010-09-18 03:37:20 +0000 | [diff] [blame] | 232 | case 'i': |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 233 | { |
Jim Ingham | 7a4c8ea | 2011-03-22 01:53:33 +0000 | [diff] [blame] | 234 | m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 235 | if (m_ignore_count == UINT32_MAX) |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 236 | error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 237 | } |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 238 | break; |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 239 | case 't' : |
| 240 | { |
Jim Ingham | 7a4c8ea | 2011-03-22 01:53:33 +0000 | [diff] [blame] | 241 | m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 242 | if (m_thread_id == LLDB_INVALID_THREAD_ID) |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 243 | error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 244 | } |
| 245 | break; |
| 246 | case 'T': |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 247 | m_thread_name.assign (option_arg); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 248 | break; |
| 249 | case 'q': |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 250 | m_queue_name.assign (option_arg); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 251 | break; |
| 252 | case 'x': |
| 253 | { |
Jim Ingham | 7a4c8ea | 2011-03-22 01:53:33 +0000 | [diff] [blame] | 254 | m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0); |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 255 | if (m_thread_id == UINT32_MAX) |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 256 | error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 257 | |
| 258 | } |
| 259 | break; |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 260 | case 'E': |
| 261 | { |
| 262 | LanguageType language = LanguageRuntime::GetLanguageTypeFromString (option_arg); |
| 263 | |
| 264 | switch (language) |
| 265 | { |
| 266 | case eLanguageTypeC89: |
| 267 | case eLanguageTypeC: |
| 268 | case eLanguageTypeC99: |
| 269 | m_language = eLanguageTypeC; |
| 270 | break; |
| 271 | case eLanguageTypeC_plus_plus: |
| 272 | m_language = eLanguageTypeC_plus_plus; |
| 273 | break; |
| 274 | case eLanguageTypeObjC: |
| 275 | m_language = eLanguageTypeObjC; |
| 276 | break; |
| 277 | case eLanguageTypeObjC_plus_plus: |
| 278 | error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c"); |
| 279 | break; |
| 280 | case eLanguageTypeUnknown: |
| 281 | error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg); |
| 282 | break; |
| 283 | default: |
| 284 | error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg); |
| 285 | } |
| 286 | } |
| 287 | break; |
| 288 | case 'w': |
| 289 | { |
| 290 | bool success; |
| 291 | m_throw_bp = Args::StringToBoolean (option_arg, true, &success); |
| 292 | if (!success) |
| 293 | error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg); |
| 294 | } |
| 295 | break; |
| 296 | case 'h': |
| 297 | { |
| 298 | bool success; |
| 299 | m_catch_bp = Args::StringToBoolean (option_arg, true, &success); |
| 300 | if (!success) |
| 301 | error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg); |
| 302 | } |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 303 | case 'K': |
| 304 | { |
| 305 | bool success; |
| 306 | bool value; |
| 307 | value = Args::StringToBoolean (option_arg, true, &success); |
| 308 | if (value) |
| 309 | m_skip_prologue = eLazyBoolYes; |
| 310 | else |
| 311 | m_skip_prologue = eLazyBoolNo; |
| 312 | |
| 313 | if (!success) |
| 314 | error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg); |
| 315 | } |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 316 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 317 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 318 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 319 | break; |
| 320 | } |
| 321 | |
| 322 | return error; |
| 323 | } |
| 324 | |
| 325 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 326 | CommandObjectBreakpointSet::CommandOptions::OptionParsingStarting () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 327 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 328 | m_filenames.Clear(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 329 | m_line_num = 0; |
| 330 | m_column = 0; |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 331 | m_func_names.clear(); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 332 | m_func_name_type_mask = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 333 | m_func_regexp.clear(); |
| 334 | m_load_addr = LLDB_INVALID_ADDRESS; |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 335 | m_modules.Clear(); |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 336 | m_ignore_count = 0; |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 337 | m_thread_id = LLDB_INVALID_THREAD_ID; |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 338 | m_thread_index = UINT32_MAX; |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 339 | m_thread_name.clear(); |
| 340 | m_queue_name.clear(); |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 341 | m_language = eLanguageTypeUnknown; |
| 342 | m_catch_bp = false; |
| 343 | m_throw_bp = true; |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 344 | m_skip_prologue = eLazyBoolCalculate; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | //------------------------------------------------------------------------- |
| 348 | // CommandObjectBreakpointSet |
| 349 | //------------------------------------------------------------------------- |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 350 | #pragma mark Set |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 351 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 352 | CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) : |
| 353 | CommandObject (interpreter, |
| 354 | "breakpoint set", |
| 355 | "Sets a breakpoint or set of breakpoints in the executable.", |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 356 | "breakpoint set <cmd-options>"), |
| 357 | m_options (interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 358 | { |
| 359 | } |
| 360 | |
| 361 | CommandObjectBreakpointSet::~CommandObjectBreakpointSet () |
| 362 | { |
| 363 | } |
| 364 | |
| 365 | Options * |
| 366 | CommandObjectBreakpointSet::GetOptions () |
| 367 | { |
| 368 | return &m_options; |
| 369 | } |
| 370 | |
| 371 | bool |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 372 | CommandObjectBreakpointSet::GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result) |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 373 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 374 | uint32_t default_line; |
| 375 | // First use the Source Manager's default file. |
| 376 | // Then use the current stack frame's file. |
| 377 | if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 378 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 379 | StackFrame *cur_frame = m_interpreter.GetExecutionContext().GetFramePtr(); |
| 380 | if (cur_frame == NULL) |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 381 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 382 | result.AppendError ("No selected frame to use to find the default file."); |
| 383 | result.SetStatus (eReturnStatusFailed); |
| 384 | return false; |
| 385 | } |
| 386 | else if (!cur_frame->HasDebugInformation()) |
| 387 | { |
| 388 | result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info."); |
| 389 | result.SetStatus (eReturnStatusFailed); |
| 390 | return false; |
| 391 | } |
| 392 | else |
| 393 | { |
| 394 | const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry); |
| 395 | if (sc.line_entry.file) |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 396 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 397 | file = sc.line_entry.file; |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 398 | } |
| 399 | else |
| 400 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 401 | result.AppendError ("Can't find the file for the selected frame to use as the default file."); |
| 402 | result.SetStatus (eReturnStatusFailed); |
| 403 | return false; |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | } |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 407 | return true; |
| 408 | } |
| 409 | |
| 410 | bool |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 411 | CommandObjectBreakpointSet::Execute |
| 412 | ( |
| 413 | Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 414 | CommandReturnObject &result |
| 415 | ) |
| 416 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 417 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 418 | if (target == NULL) |
| 419 | { |
Greg Clayton | e1f50b9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 420 | result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command)."); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 421 | result.SetStatus (eReturnStatusFailed); |
| 422 | return false; |
| 423 | } |
| 424 | |
| 425 | // The following are the various types of breakpoints that could be set: |
| 426 | // 1). -f -l -p [-s -g] (setting breakpoint by source location) |
| 427 | // 2). -a [-s -g] (setting breakpoint by address) |
| 428 | // 3). -n [-s -g] (setting breakpoint by function name) |
| 429 | // 4). -r [-s -g] (setting breakpoint by function name regular expression) |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 430 | // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text) |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 431 | // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 432 | |
| 433 | BreakpointSetType break_type = eSetTypeInvalid; |
| 434 | |
| 435 | if (m_options.m_line_num != 0) |
| 436 | break_type = eSetTypeFileAndLine; |
| 437 | else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) |
| 438 | break_type = eSetTypeAddress; |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 439 | else if (!m_options.m_func_names.empty()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 440 | break_type = eSetTypeFunctionName; |
| 441 | else if (!m_options.m_func_regexp.empty()) |
| 442 | break_type = eSetTypeFunctionRegexp; |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 443 | else if (!m_options.m_source_text_regexp.empty()) |
| 444 | break_type = eSetTypeSourceRegexp; |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 445 | else if (m_options.m_language != eLanguageTypeUnknown) |
| 446 | break_type = eSetTypeException; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 447 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 448 | Breakpoint *bp = NULL; |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 449 | FileSpec module_spec; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 450 | bool use_module = false; |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 451 | int num_modules = m_options.m_modules.GetSize(); |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 452 | |
| 453 | const bool internal = false; |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 454 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 455 | if ((num_modules > 0) && (break_type != eSetTypeAddress)) |
| 456 | use_module = true; |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 457 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 458 | switch (break_type) |
| 459 | { |
| 460 | case eSetTypeFileAndLine: // Breakpoint by source position |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 461 | { |
Greg Clayton | 887aa28 | 2010-10-11 01:05:37 +0000 | [diff] [blame] | 462 | FileSpec file; |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 463 | uint32_t num_files = m_options.m_filenames.GetSize(); |
| 464 | if (num_files == 0) |
| 465 | { |
| 466 | if (!GetDefaultFile (target, file, result)) |
| 467 | { |
| 468 | result.AppendError("No file supplied and no default file available."); |
| 469 | result.SetStatus (eReturnStatusFailed); |
| 470 | return false; |
| 471 | } |
| 472 | } |
| 473 | else if (num_files > 1) |
| 474 | { |
| 475 | result.AppendError("Only one file at a time is allowed for file and line breakpoints."); |
| 476 | result.SetStatus (eReturnStatusFailed); |
| 477 | return false; |
| 478 | } |
| 479 | else |
| 480 | file = m_options.m_filenames.GetFileSpecAtIndex(0); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 481 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 482 | bp = target->CreateBreakpoint (&(m_options.m_modules), |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 483 | file, |
| 484 | m_options.m_line_num, |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 485 | m_options.m_check_inlines, |
| 486 | m_options.m_skip_prologue, |
| 487 | internal).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 488 | } |
Greg Clayton | 887aa28 | 2010-10-11 01:05:37 +0000 | [diff] [blame] | 489 | break; |
| 490 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 491 | case eSetTypeAddress: // Breakpoint by address |
| 492 | bp = target->CreateBreakpoint (m_options.m_load_addr, false).get(); |
| 493 | break; |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 494 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 495 | case eSetTypeFunctionName: // Breakpoint by function name |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 496 | { |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 497 | uint32_t name_type_mask = m_options.m_func_name_type_mask; |
| 498 | |
| 499 | if (name_type_mask == 0) |
Greg Clayton | 48fbdf7 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 500 | name_type_mask = eFunctionNameTypeAuto; |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 501 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 502 | bp = target->CreateBreakpoint (&(m_options.m_modules), |
| 503 | &(m_options.m_filenames), |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 504 | m_options.m_func_names, |
| 505 | name_type_mask, |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 506 | m_options.m_skip_prologue, |
| 507 | internal).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 508 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 509 | break; |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 510 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 511 | case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name |
| 512 | { |
| 513 | RegularExpression regexp(m_options.m_func_regexp.c_str()); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 514 | if (!regexp.IsValid()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 515 | { |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 516 | char err_str[1024]; |
| 517 | regexp.GetErrorAsCString(err_str, sizeof(err_str)); |
| 518 | result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"", |
| 519 | err_str); |
| 520 | result.SetStatus (eReturnStatusFailed); |
| 521 | return false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 522 | } |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 523 | |
Jim Ingham | 2cf5ccb | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 524 | bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules), |
| 525 | &(m_options.m_filenames), |
| 526 | regexp, |
| 527 | m_options.m_skip_prologue, |
| 528 | internal).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 529 | } |
| 530 | break; |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 531 | case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. |
| 532 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 533 | int num_files = m_options.m_filenames.GetSize(); |
| 534 | |
| 535 | if (num_files == 0) |
| 536 | { |
| 537 | FileSpec file; |
| 538 | if (!GetDefaultFile (target, file, result)) |
| 539 | { |
| 540 | result.AppendError ("No files provided and could not find default file."); |
| 541 | result.SetStatus (eReturnStatusFailed); |
| 542 | return false; |
| 543 | } |
| 544 | else |
| 545 | { |
| 546 | m_options.m_filenames.Append (file); |
| 547 | } |
| 548 | } |
| 549 | |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 550 | RegularExpression regexp(m_options.m_source_text_regexp.c_str()); |
| 551 | if (!regexp.IsValid()) |
| 552 | { |
| 553 | char err_str[1024]; |
| 554 | regexp.GetErrorAsCString(err_str, sizeof(err_str)); |
| 555 | result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"", |
| 556 | err_str); |
| 557 | result.SetStatus (eReturnStatusFailed); |
| 558 | return false; |
| 559 | } |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 560 | bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules), &(m_options.m_filenames), regexp).get(); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 561 | } |
| 562 | break; |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 563 | case eSetTypeException: |
| 564 | { |
| 565 | bp = target->CreateExceptionBreakpoint (m_options.m_language, m_options.m_catch_bp, m_options.m_throw_bp).get(); |
| 566 | } |
| 567 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 568 | default: |
| 569 | break; |
| 570 | } |
| 571 | |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 572 | // Now set the various options that were passed in: |
| 573 | if (bp) |
| 574 | { |
| 575 | if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) |
| 576 | bp->SetThreadID (m_options.m_thread_id); |
| 577 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 578 | if (m_options.m_thread_index != UINT32_MAX) |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 579 | bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); |
| 580 | |
| 581 | if (!m_options.m_thread_name.empty()) |
| 582 | bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); |
| 583 | |
| 584 | if (!m_options.m_queue_name.empty()) |
| 585 | bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); |
| 586 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 587 | if (m_options.m_ignore_count != 0) |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 588 | bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); |
| 589 | } |
| 590 | |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 591 | if (bp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 592 | { |
Jim Ingham | 2e8cb8a | 2011-02-19 02:53:09 +0000 | [diff] [blame] | 593 | Stream &output_stream = result.GetOutputStream(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 594 | output_stream.Printf ("Breakpoint created: "); |
| 595 | bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief); |
| 596 | output_stream.EOL(); |
Jim Ingham | 4722b10 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 597 | // Don't print out this warning for exception breakpoints. They can get set before the target |
| 598 | // is set, but we won't know how to actually set the breakpoint till we run. |
| 599 | if (bp->GetNumLocations() == 0 && break_type != eSetTypeException) |
Caroline Tice | cf2f305 | 2010-10-28 16:28:56 +0000 | [diff] [blame] | 600 | output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 601 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 602 | } |
| 603 | else if (!bp) |
| 604 | { |
| 605 | result.AppendError ("Breakpoint creation failed: No breakpoint created."); |
| 606 | result.SetStatus (eReturnStatusFailed); |
| 607 | } |
| 608 | |
| 609 | return result.Succeeded(); |
| 610 | } |
| 611 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 612 | //------------------------------------------------------------------------- |
| 613 | // CommandObjectMultiwordBreakpoint |
| 614 | //------------------------------------------------------------------------- |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 615 | #pragma mark MultiwordBreakpoint |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 616 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 617 | CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) : |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 618 | CommandObjectMultiword (interpreter, |
| 619 | "breakpoint", |
Jim Ingham | 7224aab | 2011-05-26 20:39:01 +0000 | [diff] [blame] | 620 | "A set of commands for operating on breakpoints. Also see _regexp-break.", |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 621 | "breakpoint <command> [<command-options>]") |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 622 | { |
| 623 | bool status; |
| 624 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 625 | CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter)); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 626 | CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter)); |
| 627 | CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter)); |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 628 | CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter)); |
| 629 | CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter)); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 630 | CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 631 | CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter)); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 632 | CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 633 | |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 634 | list_command_object->SetCommandName ("breakpoint list"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 635 | enable_command_object->SetCommandName("breakpoint enable"); |
| 636 | disable_command_object->SetCommandName("breakpoint disable"); |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 637 | clear_command_object->SetCommandName("breakpoint clear"); |
| 638 | delete_command_object->SetCommandName("breakpoint delete"); |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 639 | set_command_object->SetCommandName("breakpoint set"); |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 640 | command_command_object->SetCommandName ("breakpoint command"); |
| 641 | modify_command_object->SetCommandName ("breakpoint modify"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 642 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 643 | status = LoadSubCommand ("list", list_command_object); |
| 644 | status = LoadSubCommand ("enable", enable_command_object); |
| 645 | status = LoadSubCommand ("disable", disable_command_object); |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 646 | status = LoadSubCommand ("clear", clear_command_object); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 647 | status = LoadSubCommand ("delete", delete_command_object); |
| 648 | status = LoadSubCommand ("set", set_command_object); |
| 649 | status = LoadSubCommand ("command", command_command_object); |
| 650 | status = LoadSubCommand ("modify", modify_command_object); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint () |
| 654 | { |
| 655 | } |
| 656 | |
| 657 | void |
| 658 | CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result, |
| 659 | BreakpointIDList *valid_ids) |
| 660 | { |
| 661 | // args can be strings representing 1). integers (for breakpoint ids) |
| 662 | // 2). the full breakpoint & location canonical representation |
| 663 | // 3). the word "to" or a hyphen, representing a range (in which case there |
| 664 | // had *better* be an entry both before & after of one of the first two types. |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 665 | // If args is empty, we will use the last created breakpoint (if there is one.) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 666 | |
| 667 | Args temp_args; |
| 668 | |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 669 | if (args.GetArgumentCount() == 0) |
| 670 | { |
Greg Clayton | 987c7eb | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 671 | if (target->GetLastCreatedBreakpoint()) |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 672 | { |
| 673 | valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); |
| 674 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 675 | } |
| 676 | else |
| 677 | { |
| 678 | result.AppendError("No breakpoint specified and no last created breakpoint."); |
| 679 | result.SetStatus (eReturnStatusFailed); |
| 680 | } |
| 681 | return; |
| 682 | } |
| 683 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 684 | // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to |
| 685 | // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for |
| 686 | // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS. |
| 687 | |
| 688 | BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args); |
| 689 | |
| 690 | // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList: |
| 691 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 692 | valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 693 | |
| 694 | // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs |
| 695 | // and put into valid_ids. |
| 696 | |
| 697 | if (result.Succeeded()) |
| 698 | { |
| 699 | // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list |
| 700 | // of breakpoint id's and verify that they correspond to valid/currently set breakpoints. |
| 701 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 702 | const size_t count = valid_ids->GetSize(); |
| 703 | for (size_t i = 0; i < count; ++i) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 704 | { |
| 705 | BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i); |
| 706 | Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); |
| 707 | if (breakpoint != NULL) |
| 708 | { |
| 709 | int num_locations = breakpoint->GetNumLocations(); |
| 710 | if (cur_bp_id.GetLocationID() > num_locations) |
| 711 | { |
| 712 | StreamString id_str; |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 713 | BreakpointID::GetCanonicalReference (&id_str, |
| 714 | cur_bp_id.GetBreakpointID(), |
| 715 | cur_bp_id.GetLocationID()); |
| 716 | i = valid_ids->GetSize() + 1; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 717 | result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n", |
| 718 | id_str.GetData()); |
| 719 | result.SetStatus (eReturnStatusFailed); |
| 720 | } |
| 721 | } |
| 722 | else |
| 723 | { |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 724 | i = valid_ids->GetSize() + 1; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID()); |
| 726 | result.SetStatus (eReturnStatusFailed); |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | //------------------------------------------------------------------------- |
| 733 | // CommandObjectBreakpointList::Options |
| 734 | //------------------------------------------------------------------------- |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 735 | #pragma mark List::CommandOptions |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 736 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 737 | CommandObjectBreakpointList::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : |
| 738 | Options (interpreter), |
Caroline Tice | 41950cc | 2011-02-04 22:59:41 +0000 | [diff] [blame] | 739 | m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 740 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | CommandObjectBreakpointList::CommandOptions::~CommandOptions () |
| 744 | { |
| 745 | } |
| 746 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 747 | OptionDefinition |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 748 | CommandObjectBreakpointList::CommandOptions::g_option_table[] = |
| 749 | { |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 750 | { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone, |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 751 | "Show debugger internal breakpoints" }, |
| 752 | |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 753 | { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 754 | "Give a brief description of the breakpoint (no location info)."}, |
| 755 | |
| 756 | // FIXME: We need to add an "internal" command, and then add this sort of thing to it. |
| 757 | // But I need to see it for now, and don't want to wait. |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 758 | { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 759 | "Give a full description of the breakpoint and its locations."}, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 760 | |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 761 | { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 762 | "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 763 | |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 764 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 765 | }; |
| 766 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 767 | const OptionDefinition* |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 768 | CommandObjectBreakpointList::CommandOptions::GetDefinitions () |
| 769 | { |
| 770 | return g_option_table; |
| 771 | } |
| 772 | |
| 773 | Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 774 | CommandObjectBreakpointList::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 775 | { |
| 776 | Error error; |
| 777 | char short_option = (char) m_getopt_table[option_idx].val; |
| 778 | |
| 779 | switch (short_option) |
| 780 | { |
| 781 | case 'b': |
| 782 | m_level = lldb::eDescriptionLevelBrief; |
| 783 | break; |
| 784 | case 'f': |
| 785 | m_level = lldb::eDescriptionLevelFull; |
| 786 | break; |
| 787 | case 'v': |
| 788 | m_level = lldb::eDescriptionLevelVerbose; |
| 789 | break; |
| 790 | case 'i': |
| 791 | m_internal = true; |
| 792 | break; |
| 793 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 794 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 795 | break; |
| 796 | } |
| 797 | |
| 798 | return error; |
| 799 | } |
| 800 | |
| 801 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 802 | CommandObjectBreakpointList::CommandOptions::OptionParsingStarting () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 803 | { |
Jim Ingham | dc25905 | 2011-05-17 01:21:41 +0000 | [diff] [blame] | 804 | m_level = lldb::eDescriptionLevelFull; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 805 | m_internal = false; |
| 806 | } |
| 807 | |
| 808 | //------------------------------------------------------------------------- |
| 809 | // CommandObjectBreakpointList |
| 810 | //------------------------------------------------------------------------- |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 811 | #pragma mark List |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 812 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 813 | CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) : |
| 814 | CommandObject (interpreter, |
| 815 | "breakpoint list", |
| 816 | "List some or all breakpoints at configurable levels of detail.", |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 817 | NULL), |
| 818 | m_options (interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 819 | { |
Caroline Tice | fb35511 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 820 | CommandArgumentEntry arg; |
| 821 | CommandArgumentData bp_id_arg; |
| 822 | |
| 823 | // Define the first (and only) variant of this arg. |
| 824 | bp_id_arg.arg_type = eArgTypeBreakpointID; |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 825 | bp_id_arg.arg_repetition = eArgRepeatOptional; |
Caroline Tice | fb35511 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 826 | |
| 827 | // There is only one variant this argument could be; put it into the argument entry. |
| 828 | arg.push_back (bp_id_arg); |
| 829 | |
| 830 | // Push the data for the first argument into the m_arguments vector. |
| 831 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | CommandObjectBreakpointList::~CommandObjectBreakpointList () |
| 835 | { |
| 836 | } |
| 837 | |
| 838 | Options * |
| 839 | CommandObjectBreakpointList::GetOptions () |
| 840 | { |
| 841 | return &m_options; |
| 842 | } |
| 843 | |
| 844 | bool |
| 845 | CommandObjectBreakpointList::Execute |
| 846 | ( |
| 847 | Args& args, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 848 | CommandReturnObject &result |
| 849 | ) |
| 850 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 851 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 852 | if (target == NULL) |
| 853 | { |
Caroline Tice | 17dce1c | 2010-09-29 19:42:33 +0000 | [diff] [blame] | 854 | result.AppendError ("Invalid target. No current target or breakpoints."); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 855 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 856 | return true; |
| 857 | } |
| 858 | |
| 859 | const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 860 | Mutex::Locker locker; |
| 861 | target->GetBreakpointList(m_options.m_internal).GetListMutex(locker); |
| 862 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 863 | size_t num_breakpoints = breakpoints.GetSize(); |
| 864 | |
| 865 | if (num_breakpoints == 0) |
| 866 | { |
| 867 | result.AppendMessage ("No breakpoints currently set."); |
| 868 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 869 | return true; |
| 870 | } |
| 871 | |
Jim Ingham | 2e8cb8a | 2011-02-19 02:53:09 +0000 | [diff] [blame] | 872 | Stream &output_stream = result.GetOutputStream(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 873 | |
| 874 | if (args.GetArgumentCount() == 0) |
| 875 | { |
| 876 | // No breakpoint selected; show info about all currently set breakpoints. |
| 877 | result.AppendMessage ("Current breakpoints:"); |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 878 | for (size_t i = 0; i < num_breakpoints; ++i) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 879 | { |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 880 | Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get(); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 881 | AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 882 | } |
| 883 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 884 | } |
| 885 | else |
| 886 | { |
| 887 | // Particular breakpoints selected; show info about that breakpoint. |
| 888 | BreakpointIDList valid_bp_ids; |
| 889 | CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); |
| 890 | |
| 891 | if (result.Succeeded()) |
| 892 | { |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 893 | for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 894 | { |
| 895 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); |
| 896 | Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 897 | AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 898 | } |
| 899 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 900 | } |
| 901 | else |
| 902 | { |
| 903 | result.AppendError ("Invalid breakpoint id."); |
| 904 | result.SetStatus (eReturnStatusFailed); |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | return result.Succeeded(); |
| 909 | } |
| 910 | |
| 911 | //------------------------------------------------------------------------- |
| 912 | // CommandObjectBreakpointEnable |
| 913 | //------------------------------------------------------------------------- |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 914 | #pragma mark Enable |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 915 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 916 | CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) : |
| 917 | CommandObject (interpreter, |
| 918 | "enable", |
Caroline Tice | fb35511 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 919 | "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.", |
| 920 | NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 921 | { |
Caroline Tice | fb35511 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 922 | CommandArgumentEntry arg; |
Johnny Chen | cacedfb | 2011-09-22 22:34:09 +0000 | [diff] [blame] | 923 | CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); |
Caroline Tice | fb35511 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 924 | // Add the entry for the first argument for this command to the object's arguments vector. |
| 925 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | |
| 929 | CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable () |
| 930 | { |
| 931 | } |
| 932 | |
| 933 | |
| 934 | bool |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 935 | CommandObjectBreakpointEnable::Execute |
| 936 | ( |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 937 | Args& args, |
| 938 | CommandReturnObject &result |
| 939 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 940 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 941 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 942 | if (target == NULL) |
| 943 | { |
Caroline Tice | 17dce1c | 2010-09-29 19:42:33 +0000 | [diff] [blame] | 944 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 945 | result.SetStatus (eReturnStatusFailed); |
| 946 | return false; |
| 947 | } |
| 948 | |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 949 | Mutex::Locker locker; |
| 950 | target->GetBreakpointList().GetListMutex(locker); |
| 951 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 952 | const BreakpointList &breakpoints = target->GetBreakpointList(); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 953 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 954 | size_t num_breakpoints = breakpoints.GetSize(); |
| 955 | |
| 956 | if (num_breakpoints == 0) |
| 957 | { |
| 958 | result.AppendError ("No breakpoints exist to be enabled."); |
| 959 | result.SetStatus (eReturnStatusFailed); |
| 960 | return false; |
| 961 | } |
| 962 | |
| 963 | if (args.GetArgumentCount() == 0) |
| 964 | { |
| 965 | // No breakpoint selected; enable all currently set breakpoints. |
| 966 | target->EnableAllBreakpoints (); |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 967 | result.AppendMessageWithFormat ("All breakpoints enabled. (%lu breakpoints)\n", num_breakpoints); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 968 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 969 | } |
| 970 | else |
| 971 | { |
| 972 | // Particular breakpoint selected; enable that breakpoint. |
| 973 | BreakpointIDList valid_bp_ids; |
| 974 | CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); |
| 975 | |
| 976 | if (result.Succeeded()) |
| 977 | { |
| 978 | int enable_count = 0; |
| 979 | int loc_count = 0; |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 980 | const size_t count = valid_bp_ids.GetSize(); |
| 981 | for (size_t i = 0; i < count; ++i) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 982 | { |
| 983 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); |
| 984 | |
| 985 | if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) |
| 986 | { |
| 987 | Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); |
| 988 | if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) |
| 989 | { |
| 990 | BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); |
| 991 | if (location) |
| 992 | { |
| 993 | location->SetEnabled (true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 994 | ++loc_count; |
| 995 | } |
| 996 | } |
| 997 | else |
| 998 | { |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 999 | breakpoint->SetEnabled (true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1000 | ++enable_count; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count); |
| 1005 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | return result.Succeeded(); |
| 1010 | } |
| 1011 | |
| 1012 | //------------------------------------------------------------------------- |
| 1013 | // CommandObjectBreakpointDisable |
| 1014 | //------------------------------------------------------------------------- |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1015 | #pragma mark Disable |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1016 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1017 | CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) : |
| 1018 | CommandObject (interpreter, |
Caroline Tice | fb35511 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 1019 | "breakpoint disable", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 1020 | "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.", |
Caroline Tice | fb35511 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 1021 | NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1022 | { |
Caroline Tice | fb35511 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 1023 | CommandArgumentEntry arg; |
Johnny Chen | cacedfb | 2011-09-22 22:34:09 +0000 | [diff] [blame] | 1024 | CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); |
Caroline Tice | fb35511 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 1025 | // Add the entry for the first argument for this command to the object's arguments vector. |
| 1026 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable () |
| 1030 | { |
| 1031 | } |
| 1032 | |
| 1033 | bool |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1034 | CommandObjectBreakpointDisable::Execute |
| 1035 | ( |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1036 | Args& args, |
| 1037 | CommandReturnObject &result |
| 1038 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1039 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1040 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1041 | if (target == NULL) |
| 1042 | { |
Caroline Tice | 17dce1c | 2010-09-29 19:42:33 +0000 | [diff] [blame] | 1043 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1044 | result.SetStatus (eReturnStatusFailed); |
| 1045 | return false; |
| 1046 | } |
| 1047 | |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1048 | Mutex::Locker locker; |
| 1049 | target->GetBreakpointList().GetListMutex(locker); |
| 1050 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1051 | const BreakpointList &breakpoints = target->GetBreakpointList(); |
| 1052 | size_t num_breakpoints = breakpoints.GetSize(); |
| 1053 | |
| 1054 | if (num_breakpoints == 0) |
| 1055 | { |
| 1056 | result.AppendError ("No breakpoints exist to be disabled."); |
| 1057 | result.SetStatus (eReturnStatusFailed); |
| 1058 | return false; |
| 1059 | } |
| 1060 | |
| 1061 | if (args.GetArgumentCount() == 0) |
| 1062 | { |
| 1063 | // No breakpoint selected; disable all currently set breakpoints. |
| 1064 | target->DisableAllBreakpoints (); |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 1065 | result.AppendMessageWithFormat ("All breakpoints disabled. (%lu breakpoints)\n", num_breakpoints); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1066 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1067 | } |
| 1068 | else |
| 1069 | { |
| 1070 | // Particular breakpoint selected; disable that breakpoint. |
| 1071 | BreakpointIDList valid_bp_ids; |
| 1072 | |
| 1073 | CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); |
| 1074 | |
| 1075 | if (result.Succeeded()) |
| 1076 | { |
| 1077 | int disable_count = 0; |
| 1078 | int loc_count = 0; |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1079 | const size_t count = valid_bp_ids.GetSize(); |
| 1080 | for (size_t i = 0; i < count; ++i) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1081 | { |
| 1082 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); |
| 1083 | |
| 1084 | if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) |
| 1085 | { |
| 1086 | Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); |
| 1087 | if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) |
| 1088 | { |
| 1089 | BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); |
| 1090 | if (location) |
| 1091 | { |
| 1092 | location->SetEnabled (false); |
| 1093 | ++loc_count; |
| 1094 | } |
| 1095 | } |
| 1096 | else |
| 1097 | { |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1098 | breakpoint->SetEnabled (false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1099 | ++disable_count; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1100 | } |
| 1101 | } |
| 1102 | } |
| 1103 | result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count); |
| 1104 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | return result.Succeeded(); |
| 1109 | } |
| 1110 | |
| 1111 | //------------------------------------------------------------------------- |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 1112 | // CommandObjectBreakpointClear::CommandOptions |
| 1113 | //------------------------------------------------------------------------- |
| 1114 | #pragma mark Clear::CommandOptions |
| 1115 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 1116 | CommandObjectBreakpointClear::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : |
| 1117 | Options (interpreter), |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 1118 | m_filename (), |
| 1119 | m_line_num (0) |
| 1120 | { |
| 1121 | } |
| 1122 | |
| 1123 | CommandObjectBreakpointClear::CommandOptions::~CommandOptions () |
| 1124 | { |
| 1125 | } |
| 1126 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1127 | OptionDefinition |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 1128 | CommandObjectBreakpointClear::CommandOptions::g_option_table[] = |
| 1129 | { |
| 1130 | { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, |
| 1131 | "Specify the breakpoint by source location in this particular file."}, |
| 1132 | |
| 1133 | { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, |
| 1134 | "Specify the breakpoint by source location at this particular line."}, |
| 1135 | |
| 1136 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
| 1137 | }; |
| 1138 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1139 | const OptionDefinition* |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 1140 | CommandObjectBreakpointClear::CommandOptions::GetDefinitions () |
| 1141 | { |
| 1142 | return g_option_table; |
| 1143 | } |
| 1144 | |
| 1145 | Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 1146 | CommandObjectBreakpointClear::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 1147 | { |
| 1148 | Error error; |
| 1149 | char short_option = (char) m_getopt_table[option_idx].val; |
| 1150 | |
| 1151 | switch (short_option) |
| 1152 | { |
| 1153 | case 'f': |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 1154 | m_filename.assign (option_arg); |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 1155 | break; |
| 1156 | |
| 1157 | case 'l': |
| 1158 | m_line_num = Args::StringToUInt32 (option_arg, 0); |
| 1159 | break; |
| 1160 | |
| 1161 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 1162 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 1163 | break; |
| 1164 | } |
| 1165 | |
| 1166 | return error; |
| 1167 | } |
| 1168 | |
| 1169 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 1170 | CommandObjectBreakpointClear::CommandOptions::OptionParsingStarting () |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 1171 | { |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 1172 | m_filename.clear(); |
| 1173 | m_line_num = 0; |
| 1174 | } |
| 1175 | |
| 1176 | //------------------------------------------------------------------------- |
| 1177 | // CommandObjectBreakpointClear |
| 1178 | //------------------------------------------------------------------------- |
| 1179 | #pragma mark Clear |
| 1180 | |
| 1181 | CommandObjectBreakpointClear::CommandObjectBreakpointClear (CommandInterpreter &interpreter) : |
| 1182 | CommandObject (interpreter, |
| 1183 | "breakpoint clear", |
| 1184 | "Clears a breakpoint or set of breakpoints in the executable.", |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 1185 | "breakpoint clear <cmd-options>"), |
| 1186 | m_options (interpreter) |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 1187 | { |
| 1188 | } |
| 1189 | |
| 1190 | CommandObjectBreakpointClear::~CommandObjectBreakpointClear () |
| 1191 | { |
| 1192 | } |
| 1193 | |
| 1194 | Options * |
| 1195 | CommandObjectBreakpointClear::GetOptions () |
| 1196 | { |
| 1197 | return &m_options; |
| 1198 | } |
| 1199 | |
| 1200 | bool |
| 1201 | CommandObjectBreakpointClear::Execute |
| 1202 | ( |
| 1203 | Args& command, |
| 1204 | CommandReturnObject &result |
| 1205 | ) |
| 1206 | { |
| 1207 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
| 1208 | if (target == NULL) |
| 1209 | { |
| 1210 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 1211 | result.SetStatus (eReturnStatusFailed); |
| 1212 | return false; |
| 1213 | } |
| 1214 | |
| 1215 | // The following are the various types of breakpoints that could be cleared: |
| 1216 | // 1). -f -l (clearing breakpoint by source location) |
| 1217 | |
| 1218 | BreakpointClearType break_type = eClearTypeInvalid; |
| 1219 | |
| 1220 | if (m_options.m_line_num != 0) |
| 1221 | break_type = eClearTypeFileAndLine; |
| 1222 | |
| 1223 | Mutex::Locker locker; |
| 1224 | target->GetBreakpointList().GetListMutex(locker); |
| 1225 | |
| 1226 | BreakpointList &breakpoints = target->GetBreakpointList(); |
| 1227 | size_t num_breakpoints = breakpoints.GetSize(); |
| 1228 | |
| 1229 | // Early return if there's no breakpoint at all. |
| 1230 | if (num_breakpoints == 0) |
| 1231 | { |
| 1232 | result.AppendError ("Breakpoint clear: No breakpoint cleared."); |
| 1233 | result.SetStatus (eReturnStatusFailed); |
| 1234 | return result.Succeeded(); |
| 1235 | } |
| 1236 | |
| 1237 | // Find matching breakpoints and delete them. |
| 1238 | |
| 1239 | // First create a copy of all the IDs. |
| 1240 | std::vector<break_id_t> BreakIDs; |
| 1241 | for (size_t i = 0; i < num_breakpoints; ++i) |
| 1242 | BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID()); |
| 1243 | |
| 1244 | int num_cleared = 0; |
| 1245 | StreamString ss; |
| 1246 | switch (break_type) |
| 1247 | { |
| 1248 | case eClearTypeFileAndLine: // Breakpoint by source position |
| 1249 | { |
| 1250 | const ConstString filename(m_options.m_filename.c_str()); |
| 1251 | BreakpointLocationCollection loc_coll; |
| 1252 | |
| 1253 | for (size_t i = 0; i < num_breakpoints; ++i) |
| 1254 | { |
| 1255 | Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); |
| 1256 | |
| 1257 | if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) |
| 1258 | { |
| 1259 | // If the collection size is 0, it's a full match and we can just remove the breakpoint. |
| 1260 | if (loc_coll.GetSize() == 0) |
| 1261 | { |
| 1262 | bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); |
| 1263 | ss.EOL(); |
| 1264 | target->RemoveBreakpointByID (bp->GetID()); |
| 1265 | ++num_cleared; |
| 1266 | } |
| 1267 | } |
| 1268 | } |
| 1269 | } |
| 1270 | break; |
| 1271 | |
| 1272 | default: |
| 1273 | break; |
| 1274 | } |
| 1275 | |
| 1276 | if (num_cleared > 0) |
| 1277 | { |
Jim Ingham | 2e8cb8a | 2011-02-19 02:53:09 +0000 | [diff] [blame] | 1278 | Stream &output_stream = result.GetOutputStream(); |
Johnny Chen | a62ad7c | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 1279 | output_stream.Printf ("%d breakpoints cleared:\n", num_cleared); |
| 1280 | output_stream << ss.GetData(); |
| 1281 | output_stream.EOL(); |
| 1282 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1283 | } |
| 1284 | else |
| 1285 | { |
| 1286 | result.AppendError ("Breakpoint clear: No breakpoint cleared."); |
| 1287 | result.SetStatus (eReturnStatusFailed); |
| 1288 | } |
| 1289 | |
| 1290 | return result.Succeeded(); |
| 1291 | } |
| 1292 | |
| 1293 | //------------------------------------------------------------------------- |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1294 | // CommandObjectBreakpointDelete |
| 1295 | //------------------------------------------------------------------------- |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1296 | #pragma mark Delete |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1297 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1298 | CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) : |
| 1299 | CommandObject (interpreter, |
| 1300 | "breakpoint delete", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 1301 | "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.", |
Caroline Tice | fb35511 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 1302 | NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1303 | { |
Caroline Tice | fb35511 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 1304 | CommandArgumentEntry arg; |
Johnny Chen | cacedfb | 2011-09-22 22:34:09 +0000 | [diff] [blame] | 1305 | CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); |
Caroline Tice | fb35511 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 1306 | // Add the entry for the first argument for this command to the object's arguments vector. |
| 1307 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | |
| 1311 | CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete () |
| 1312 | { |
| 1313 | } |
| 1314 | |
| 1315 | bool |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1316 | CommandObjectBreakpointDelete::Execute |
| 1317 | ( |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1318 | Args& args, |
| 1319 | CommandReturnObject &result |
| 1320 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1321 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1322 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1323 | if (target == NULL) |
| 1324 | { |
Caroline Tice | 17dce1c | 2010-09-29 19:42:33 +0000 | [diff] [blame] | 1325 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1326 | result.SetStatus (eReturnStatusFailed); |
| 1327 | return false; |
| 1328 | } |
| 1329 | |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1330 | Mutex::Locker locker; |
| 1331 | target->GetBreakpointList().GetListMutex(locker); |
| 1332 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1333 | const BreakpointList &breakpoints = target->GetBreakpointList(); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1334 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1335 | size_t num_breakpoints = breakpoints.GetSize(); |
| 1336 | |
| 1337 | if (num_breakpoints == 0) |
| 1338 | { |
| 1339 | result.AppendError ("No breakpoints exist to be deleted."); |
| 1340 | result.SetStatus (eReturnStatusFailed); |
| 1341 | return false; |
| 1342 | } |
| 1343 | |
| 1344 | if (args.GetArgumentCount() == 0) |
| 1345 | { |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1346 | if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1347 | { |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1348 | result.AppendMessage("Operation cancelled..."); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1349 | } |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1350 | else |
| 1351 | { |
| 1352 | target->RemoveAllBreakpoints (); |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 1353 | result.AppendMessageWithFormat ("All breakpoints removed. (%lu breakpoints)\n", num_breakpoints); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1354 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1355 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1356 | } |
| 1357 | else |
| 1358 | { |
| 1359 | // Particular breakpoint selected; disable that breakpoint. |
| 1360 | BreakpointIDList valid_bp_ids; |
| 1361 | CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids); |
| 1362 | |
| 1363 | if (result.Succeeded()) |
| 1364 | { |
| 1365 | int delete_count = 0; |
| 1366 | int disable_count = 0; |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1367 | const size_t count = valid_bp_ids.GetSize(); |
| 1368 | for (size_t i = 0; i < count; ++i) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1369 | { |
| 1370 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); |
| 1371 | |
| 1372 | if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) |
| 1373 | { |
| 1374 | if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) |
| 1375 | { |
| 1376 | Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); |
| 1377 | BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); |
| 1378 | // It makes no sense to try to delete individual locations, so we disable them instead. |
| 1379 | if (location) |
| 1380 | { |
| 1381 | location->SetEnabled (false); |
| 1382 | ++disable_count; |
| 1383 | } |
| 1384 | } |
| 1385 | else |
| 1386 | { |
| 1387 | target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID()); |
| 1388 | ++delete_count; |
| 1389 | } |
| 1390 | } |
| 1391 | } |
| 1392 | result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n", |
| 1393 | delete_count, disable_count); |
| 1394 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1395 | } |
| 1396 | } |
| 1397 | return result.Succeeded(); |
| 1398 | } |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1399 | |
| 1400 | //------------------------------------------------------------------------- |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1401 | // CommandObjectBreakpointModify::CommandOptions |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1402 | //------------------------------------------------------------------------- |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1403 | #pragma mark Modify::CommandOptions |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1404 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 1405 | CommandObjectBreakpointModify::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : |
| 1406 | Options (interpreter), |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1407 | m_ignore_count (0), |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1408 | m_thread_id(LLDB_INVALID_THREAD_ID), |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1409 | m_thread_id_passed(false), |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1410 | m_thread_index (UINT32_MAX), |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1411 | m_thread_index_passed(false), |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1412 | m_thread_name(), |
| 1413 | m_queue_name(), |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1414 | m_condition (), |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1415 | m_enable_passed (false), |
| 1416 | m_enable_value (false), |
| 1417 | m_name_passed (false), |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1418 | m_queue_passed (false), |
| 1419 | m_condition_passed (false) |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1420 | { |
| 1421 | } |
| 1422 | |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1423 | CommandObjectBreakpointModify::CommandOptions::~CommandOptions () |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1424 | { |
| 1425 | } |
| 1426 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1427 | OptionDefinition |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1428 | CommandObjectBreakpointModify::CommandOptions::g_option_table[] = |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1429 | { |
Bill Wendling | ff7df6d | 2012-04-03 04:13:41 +0000 | [diff] [blame] | 1430 | { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." }, |
| 1431 | { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose indeX matches this argument."}, |
| 1432 | { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."}, |
| 1433 | { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."}, |
| 1434 | { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."}, |
| 1435 | { LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."}, |
| 1436 | { LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, 0, eArgTypeNone, "Enable the breakpoint."}, |
| 1437 | { LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, 0, eArgTypeNone, "Disable the breakpoint."}, |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1438 | { 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1439 | }; |
| 1440 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1441 | const OptionDefinition* |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1442 | CommandObjectBreakpointModify::CommandOptions::GetDefinitions () |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1443 | { |
| 1444 | return g_option_table; |
| 1445 | } |
| 1446 | |
| 1447 | Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 1448 | CommandObjectBreakpointModify::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1449 | { |
| 1450 | Error error; |
| 1451 | char short_option = (char) m_getopt_table[option_idx].val; |
| 1452 | |
| 1453 | switch (short_option) |
| 1454 | { |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1455 | case 'c': |
| 1456 | if (option_arg != NULL) |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 1457 | m_condition.assign (option_arg); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1458 | else |
| 1459 | m_condition.clear(); |
| 1460 | m_condition_passed = true; |
| 1461 | break; |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1462 | case 'd': |
| 1463 | m_enable_passed = true; |
| 1464 | m_enable_value = false; |
| 1465 | break; |
| 1466 | case 'e': |
| 1467 | m_enable_passed = true; |
| 1468 | m_enable_value = true; |
| 1469 | break; |
Greg Clayton | fe424a9 | 2010-09-18 03:37:20 +0000 | [diff] [blame] | 1470 | case 'i': |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1471 | { |
Jim Ingham | 7a4c8ea | 2011-03-22 01:53:33 +0000 | [diff] [blame] | 1472 | m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1473 | if (m_ignore_count == UINT32_MAX) |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 1474 | error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1475 | } |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1476 | break; |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1477 | case 't' : |
| 1478 | { |
Jim Ingham | 7a4c8ea | 2011-03-22 01:53:33 +0000 | [diff] [blame] | 1479 | if (option_arg[0] == '\0') |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1480 | { |
| 1481 | m_thread_id = LLDB_INVALID_THREAD_ID; |
| 1482 | m_thread_id_passed = true; |
| 1483 | } |
| 1484 | else |
| 1485 | { |
Jim Ingham | 7a4c8ea | 2011-03-22 01:53:33 +0000 | [diff] [blame] | 1486 | m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1487 | if (m_thread_id == LLDB_INVALID_THREAD_ID) |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 1488 | error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1489 | else |
| 1490 | m_thread_id_passed = true; |
| 1491 | } |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1492 | } |
| 1493 | break; |
| 1494 | case 'T': |
Jim Ingham | d457122 | 2010-06-19 04:35:20 +0000 | [diff] [blame] | 1495 | if (option_arg != NULL) |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 1496 | m_thread_name.assign (option_arg); |
Jim Ingham | d457122 | 2010-06-19 04:35:20 +0000 | [diff] [blame] | 1497 | else |
| 1498 | m_thread_name.clear(); |
| 1499 | m_name_passed = true; |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1500 | break; |
| 1501 | case 'q': |
Jim Ingham | d457122 | 2010-06-19 04:35:20 +0000 | [diff] [blame] | 1502 | if (option_arg != NULL) |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 1503 | m_queue_name.assign (option_arg); |
Jim Ingham | d457122 | 2010-06-19 04:35:20 +0000 | [diff] [blame] | 1504 | else |
| 1505 | m_queue_name.clear(); |
| 1506 | m_queue_passed = true; |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1507 | break; |
| 1508 | case 'x': |
| 1509 | { |
Jim Ingham | 7a4c8ea | 2011-03-22 01:53:33 +0000 | [diff] [blame] | 1510 | if (option_arg[0] == '\n') |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1511 | { |
| 1512 | m_thread_index = UINT32_MAX; |
| 1513 | m_thread_index_passed = true; |
| 1514 | } |
| 1515 | else |
| 1516 | { |
Jim Ingham | 7a4c8ea | 2011-03-22 01:53:33 +0000 | [diff] [blame] | 1517 | m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0); |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1518 | if (m_thread_id == UINT32_MAX) |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 1519 | error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1520 | else |
| 1521 | m_thread_index_passed = true; |
| 1522 | } |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1523 | } |
| 1524 | break; |
| 1525 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 1526 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1527 | break; |
| 1528 | } |
| 1529 | |
| 1530 | return error; |
| 1531 | } |
| 1532 | |
| 1533 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 1534 | CommandObjectBreakpointModify::CommandOptions::OptionParsingStarting () |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1535 | { |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1536 | m_ignore_count = 0; |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1537 | m_thread_id = LLDB_INVALID_THREAD_ID; |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1538 | m_thread_id_passed = false; |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1539 | m_thread_index = UINT32_MAX; |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1540 | m_thread_index_passed = false; |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1541 | m_thread_name.clear(); |
| 1542 | m_queue_name.clear(); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1543 | m_condition.clear(); |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1544 | m_enable_passed = false; |
Jim Ingham | d457122 | 2010-06-19 04:35:20 +0000 | [diff] [blame] | 1545 | m_queue_passed = false; |
| 1546 | m_name_passed = false; |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1547 | m_condition_passed = false; |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | //------------------------------------------------------------------------- |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1551 | // CommandObjectBreakpointModify |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1552 | //------------------------------------------------------------------------- |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1553 | #pragma mark Modify |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1554 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1555 | CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) : |
| 1556 | CommandObject (interpreter, |
| 1557 | "breakpoint modify", |
Jim Ingham | 19ac0bd | 2010-12-03 22:37:19 +0000 | [diff] [blame] | 1558 | "Modify the options on a breakpoint or set of breakpoints in the executable. " |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1559 | "If no breakpoint is specified, acts on the last created breakpoint. " |
| 1560 | "With the exception of -e, -d and -i, passing an empty argument clears the modification.", |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 1561 | NULL), |
| 1562 | m_options (interpreter) |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1563 | { |
Caroline Tice | fb35511 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 1564 | CommandArgumentEntry arg; |
Johnny Chen | cacedfb | 2011-09-22 22:34:09 +0000 | [diff] [blame] | 1565 | CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); |
Caroline Tice | fb35511 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 1566 | // Add the entry for the first argument for this command to the object's arguments vector. |
| 1567 | m_arguments.push_back (arg); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1570 | CommandObjectBreakpointModify::~CommandObjectBreakpointModify () |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1571 | { |
| 1572 | } |
| 1573 | |
| 1574 | Options * |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1575 | CommandObjectBreakpointModify::GetOptions () |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1576 | { |
| 1577 | return &m_options; |
| 1578 | } |
| 1579 | |
| 1580 | bool |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1581 | CommandObjectBreakpointModify::Execute |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1582 | ( |
| 1583 | Args& command, |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1584 | CommandReturnObject &result |
| 1585 | ) |
| 1586 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1587 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1588 | if (target == NULL) |
| 1589 | { |
Caroline Tice | 17dce1c | 2010-09-29 19:42:33 +0000 | [diff] [blame] | 1590 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1591 | result.SetStatus (eReturnStatusFailed); |
| 1592 | return false; |
| 1593 | } |
| 1594 | |
| 1595 | Mutex::Locker locker; |
| 1596 | target->GetBreakpointList().GetListMutex(locker); |
| 1597 | |
| 1598 | BreakpointIDList valid_bp_ids; |
| 1599 | |
| 1600 | CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); |
| 1601 | |
| 1602 | if (result.Succeeded()) |
| 1603 | { |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1604 | const size_t count = valid_bp_ids.GetSize(); |
| 1605 | for (size_t i = 0; i < count; ++i) |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1606 | { |
| 1607 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); |
| 1608 | |
| 1609 | if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) |
| 1610 | { |
| 1611 | Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); |
| 1612 | if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) |
| 1613 | { |
| 1614 | BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get(); |
| 1615 | if (location) |
| 1616 | { |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1617 | if (m_options.m_thread_id_passed) |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1618 | location->SetThreadID (m_options.m_thread_id); |
| 1619 | |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1620 | if (m_options.m_thread_index_passed) |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 1621 | location->SetThreadIndex(m_options.m_thread_index); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1622 | |
Jim Ingham | d457122 | 2010-06-19 04:35:20 +0000 | [diff] [blame] | 1623 | if (m_options.m_name_passed) |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 1624 | location->SetThreadName(m_options.m_thread_name.c_str()); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1625 | |
Jim Ingham | d457122 | 2010-06-19 04:35:20 +0000 | [diff] [blame] | 1626 | if (m_options.m_queue_passed) |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 1627 | location->SetQueueName(m_options.m_queue_name.c_str()); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1628 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1629 | if (m_options.m_ignore_count != 0) |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 1630 | location->SetIgnoreCount(m_options.m_ignore_count); |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1631 | |
| 1632 | if (m_options.m_enable_passed) |
| 1633 | location->SetEnabled (m_options.m_enable_value); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1634 | |
| 1635 | if (m_options.m_condition_passed) |
| 1636 | location->SetCondition (m_options.m_condition.c_str()); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1637 | } |
| 1638 | } |
| 1639 | else |
| 1640 | { |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1641 | if (m_options.m_thread_id_passed) |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1642 | bp->SetThreadID (m_options.m_thread_id); |
| 1643 | |
Jim Ingham | 9a7b291 | 2010-12-03 23:04:19 +0000 | [diff] [blame] | 1644 | if (m_options.m_thread_index_passed) |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 1645 | bp->SetThreadIndex(m_options.m_thread_index); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1646 | |
Jim Ingham | d457122 | 2010-06-19 04:35:20 +0000 | [diff] [blame] | 1647 | if (m_options.m_name_passed) |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 1648 | bp->SetThreadName(m_options.m_thread_name.c_str()); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1649 | |
Jim Ingham | d457122 | 2010-06-19 04:35:20 +0000 | [diff] [blame] | 1650 | if (m_options.m_queue_passed) |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 1651 | bp->SetQueueName(m_options.m_queue_name.c_str()); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1652 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1653 | if (m_options.m_ignore_count != 0) |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 1654 | bp->SetIgnoreCount(m_options.m_ignore_count); |
Jim Ingham | 10622a2 | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 1655 | |
| 1656 | if (m_options.m_enable_passed) |
| 1657 | bp->SetEnabled (m_options.m_enable_value); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1658 | |
| 1659 | if (m_options.m_condition_passed) |
| 1660 | bp->SetCondition (m_options.m_condition.c_str()); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1661 | } |
| 1662 | } |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | return result.Succeeded(); |
| 1667 | } |
| 1668 | |
| 1669 | |