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