Chris Lattner | 30fdc8d | 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 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "CommandObjectBreakpoint.h" |
| 13 | #include "CommandObjectBreakpointCommand.h" |
| 14 | |
| 15 | // C Includes |
| 16 | // C++ Includes |
| 17 | // Other libraries and framework includes |
| 18 | // Project includes |
| 19 | #include "lldb/Breakpoint/Breakpoint.h" |
| 20 | #include "lldb/Breakpoint/BreakpointIDList.h" |
| 21 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Jim Ingham | 40af72e | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 22 | #include "lldb/Interpreter/Options.h" |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 23 | #include "lldb/Interpreter/OptionValueString.h" |
| 24 | #include "lldb/Interpreter/OptionValueUInt64.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Core/RegularExpression.h" |
| 26 | #include "lldb/Core/StreamString.h" |
| 27 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 28 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 29 | #include "lldb/Target/Target.h" |
| 30 | #include "lldb/Interpreter/CommandCompletions.h" |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 31 | #include "lldb/Target/StackFrame.h" |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 32 | #include "lldb/Target/Thread.h" |
| 33 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | |
Johnny Chen | b7234e4 | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 35 | #include <vector> |
| 36 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | using namespace lldb; |
| 38 | using namespace lldb_private; |
| 39 | |
| 40 | static void |
Jim Ingham | 85e8b81 | 2011-02-19 02:53:09 +0000 | [diff] [blame] | 41 | AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | { |
| 43 | s->IndentMore(); |
| 44 | bp->GetDescription (s, level, true); |
| 45 | s->IndentLess(); |
| 46 | s->EOL(); |
| 47 | } |
| 48 | |
| 49 | //------------------------------------------------------------------------- |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 50 | // CommandObjectBreakpointSet |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | //------------------------------------------------------------------------- |
| 52 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 53 | |
| 54 | class CommandObjectBreakpointSet : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 56 | public: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 58 | typedef enum BreakpointSetType |
| 59 | { |
| 60 | eSetTypeInvalid, |
| 61 | eSetTypeFileAndLine, |
| 62 | eSetTypeAddress, |
| 63 | eSetTypeFunctionName, |
| 64 | eSetTypeFunctionRegexp, |
| 65 | eSetTypeSourceRegexp, |
| 66 | eSetTypeException |
| 67 | } BreakpointSetType; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 69 | CommandObjectBreakpointSet (CommandInterpreter &interpreter) : |
| 70 | CommandObjectParsed (interpreter, |
| 71 | "breakpoint set", |
| 72 | "Sets a breakpoint or set of breakpoints in the executable.", |
| 73 | "breakpoint set <cmd-options>"), |
| 74 | m_options (interpreter) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | |
| 79 | virtual |
| 80 | ~CommandObjectBreakpointSet () {} |
| 81 | |
| 82 | virtual Options * |
| 83 | GetOptions () |
| 84 | { |
| 85 | return &m_options; |
| 86 | } |
| 87 | |
| 88 | class CommandOptions : public Options |
| 89 | { |
| 90 | public: |
| 91 | |
| 92 | CommandOptions (CommandInterpreter &interpreter) : |
| 93 | Options (interpreter), |
| 94 | m_condition (), |
| 95 | m_filenames (), |
| 96 | m_line_num (0), |
| 97 | m_column (0), |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 98 | m_func_names (), |
| 99 | m_func_name_type_mask (eFunctionNameTypeNone), |
| 100 | m_func_regexp (), |
| 101 | m_source_text_regexp(), |
| 102 | m_modules (), |
| 103 | m_load_addr(), |
| 104 | m_ignore_count (0), |
| 105 | m_thread_id(LLDB_INVALID_THREAD_ID), |
| 106 | m_thread_index (UINT32_MAX), |
| 107 | m_thread_name(), |
| 108 | m_queue_name(), |
| 109 | m_catch_bp (false), |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 110 | m_throw_bp (true), |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 111 | m_hardware (false), |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 112 | m_language (eLanguageTypeUnknown), |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 113 | m_skip_prologue (eLazyBoolCalculate), |
| 114 | m_one_shot (false) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 115 | { |
| 116 | } |
| 117 | |
| 118 | |
| 119 | virtual |
| 120 | ~CommandOptions () {} |
| 121 | |
| 122 | virtual Error |
| 123 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 124 | { |
| 125 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 126 | const int short_option = m_getopt_table[option_idx].val; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 127 | |
| 128 | switch (short_option) |
| 129 | { |
| 130 | case 'a': |
Greg Clayton | b9d5df5 | 2012-12-06 22:49:16 +0000 | [diff] [blame] | 131 | { |
| 132 | ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); |
| 133 | m_load_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error); |
| 134 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 135 | break; |
| 136 | |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 137 | case 'b': |
| 138 | m_func_names.push_back (option_arg); |
| 139 | m_func_name_type_mask |= eFunctionNameTypeBase; |
| 140 | break; |
| 141 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 142 | case 'C': |
| 143 | m_column = Args::StringToUInt32 (option_arg, 0); |
| 144 | break; |
| 145 | |
| 146 | case 'c': |
| 147 | m_condition.assign(option_arg); |
| 148 | break; |
| 149 | |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 150 | case 'D': |
| 151 | m_use_dummy = true; |
| 152 | break; |
| 153 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 154 | case 'E': |
| 155 | { |
| 156 | LanguageType language = LanguageRuntime::GetLanguageTypeFromString (option_arg); |
| 157 | |
| 158 | switch (language) |
| 159 | { |
| 160 | case eLanguageTypeC89: |
| 161 | case eLanguageTypeC: |
| 162 | case eLanguageTypeC99: |
Bruce Mitchener | 1d0089f | 2014-07-03 00:49:08 +0000 | [diff] [blame] | 163 | case eLanguageTypeC11: |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 164 | m_language = eLanguageTypeC; |
| 165 | break; |
| 166 | case eLanguageTypeC_plus_plus: |
Bruce Mitchener | 1d0089f | 2014-07-03 00:49:08 +0000 | [diff] [blame] | 167 | case eLanguageTypeC_plus_plus_03: |
| 168 | case eLanguageTypeC_plus_plus_11: |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 169 | m_language = eLanguageTypeC_plus_plus; |
| 170 | break; |
| 171 | case eLanguageTypeObjC: |
| 172 | m_language = eLanguageTypeObjC; |
| 173 | break; |
| 174 | case eLanguageTypeObjC_plus_plus: |
| 175 | error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c"); |
| 176 | break; |
| 177 | case eLanguageTypeUnknown: |
| 178 | error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg); |
| 179 | break; |
| 180 | default: |
| 181 | error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg); |
| 182 | } |
| 183 | } |
| 184 | break; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 185 | |
| 186 | case 'f': |
| 187 | m_filenames.AppendIfUnique (FileSpec(option_arg, false)); |
| 188 | break; |
| 189 | |
| 190 | case 'F': |
| 191 | m_func_names.push_back (option_arg); |
| 192 | m_func_name_type_mask |= eFunctionNameTypeFull; |
| 193 | break; |
| 194 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 195 | case 'h': |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 196 | { |
| 197 | bool success; |
| 198 | m_catch_bp = Args::StringToBoolean (option_arg, true, &success); |
| 199 | if (!success) |
| 200 | error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg); |
| 201 | } |
| 202 | break; |
| 203 | |
| 204 | case 'H': |
| 205 | m_hardware = true; |
| 206 | break; |
| 207 | |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 208 | case 'i': |
| 209 | { |
| 210 | m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); |
| 211 | if (m_ignore_count == UINT32_MAX) |
| 212 | error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); |
| 213 | break; |
| 214 | } |
| 215 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 216 | case 'K': |
| 217 | { |
| 218 | bool success; |
| 219 | bool value; |
| 220 | value = Args::StringToBoolean (option_arg, true, &success); |
| 221 | if (value) |
| 222 | m_skip_prologue = eLazyBoolYes; |
| 223 | else |
| 224 | m_skip_prologue = eLazyBoolNo; |
| 225 | |
| 226 | if (!success) |
| 227 | error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg); |
| 228 | } |
| 229 | break; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 230 | |
| 231 | case 'l': |
| 232 | m_line_num = Args::StringToUInt32 (option_arg, 0); |
| 233 | break; |
| 234 | |
| 235 | case 'M': |
| 236 | m_func_names.push_back (option_arg); |
| 237 | m_func_name_type_mask |= eFunctionNameTypeMethod; |
| 238 | break; |
| 239 | |
| 240 | case 'n': |
| 241 | m_func_names.push_back (option_arg); |
| 242 | m_func_name_type_mask |= eFunctionNameTypeAuto; |
| 243 | break; |
| 244 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 245 | case 'N': |
| 246 | if (BreakpointID::StringIsBreakpointName(option_arg, error)) |
| 247 | m_breakpoint_names.push_back (option_arg); |
| 248 | else |
| 249 | error.SetErrorStringWithFormat(error.AsCString()); |
| 250 | break; |
| 251 | |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 252 | case 'o': |
| 253 | m_one_shot = true; |
| 254 | break; |
| 255 | |
| 256 | case 'p': |
| 257 | m_source_text_regexp.assign (option_arg); |
| 258 | break; |
| 259 | |
| 260 | case 'q': |
| 261 | m_queue_name.assign (option_arg); |
| 262 | break; |
| 263 | |
| 264 | case 'r': |
| 265 | m_func_regexp.assign (option_arg); |
| 266 | break; |
| 267 | |
| 268 | case 's': |
| 269 | { |
| 270 | m_modules.AppendIfUnique (FileSpec (option_arg, false)); |
| 271 | break; |
| 272 | } |
| 273 | |
| 274 | case 'S': |
| 275 | m_func_names.push_back (option_arg); |
| 276 | m_func_name_type_mask |= eFunctionNameTypeSelector; |
| 277 | break; |
| 278 | |
| 279 | case 't' : |
| 280 | { |
| 281 | m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); |
| 282 | if (m_thread_id == LLDB_INVALID_THREAD_ID) |
| 283 | error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); |
| 284 | } |
| 285 | break; |
| 286 | |
| 287 | case 'T': |
| 288 | m_thread_name.assign (option_arg); |
| 289 | break; |
| 290 | |
| 291 | case 'w': |
| 292 | { |
| 293 | bool success; |
| 294 | m_throw_bp = Args::StringToBoolean (option_arg, true, &success); |
| 295 | if (!success) |
| 296 | error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg); |
| 297 | } |
| 298 | break; |
| 299 | |
| 300 | case 'x': |
| 301 | { |
| 302 | m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0); |
| 303 | if (m_thread_id == UINT32_MAX) |
| 304 | error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); |
| 305 | |
| 306 | } |
| 307 | break; |
| 308 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 309 | default: |
| 310 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 311 | break; |
| 312 | } |
| 313 | |
| 314 | return error; |
| 315 | } |
| 316 | void |
| 317 | OptionParsingStarting () |
| 318 | { |
| 319 | m_condition.clear(); |
| 320 | m_filenames.Clear(); |
| 321 | m_line_num = 0; |
| 322 | m_column = 0; |
| 323 | m_func_names.clear(); |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 324 | m_func_name_type_mask = eFunctionNameTypeNone; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 325 | m_func_regexp.clear(); |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 326 | m_source_text_regexp.clear(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 327 | m_modules.Clear(); |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 328 | m_load_addr = LLDB_INVALID_ADDRESS; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 329 | m_ignore_count = 0; |
| 330 | m_thread_id = LLDB_INVALID_THREAD_ID; |
| 331 | m_thread_index = UINT32_MAX; |
| 332 | m_thread_name.clear(); |
| 333 | m_queue_name.clear(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 334 | m_catch_bp = false; |
| 335 | m_throw_bp = true; |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 336 | m_hardware = false; |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 337 | m_language = eLanguageTypeUnknown; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 338 | m_skip_prologue = eLazyBoolCalculate; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 339 | m_one_shot = false; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 340 | m_use_dummy = false; |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 341 | m_breakpoint_names.clear(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | const OptionDefinition* |
| 345 | GetDefinitions () |
| 346 | { |
| 347 | return g_option_table; |
| 348 | } |
| 349 | |
| 350 | // Options table: Required for subclasses of Options. |
| 351 | |
| 352 | static OptionDefinition g_option_table[]; |
| 353 | |
| 354 | // Instance variables to hold the values for command options. |
| 355 | |
| 356 | std::string m_condition; |
| 357 | FileSpecList m_filenames; |
| 358 | uint32_t m_line_num; |
| 359 | uint32_t m_column; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 360 | std::vector<std::string> m_func_names; |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 361 | std::vector<std::string> m_breakpoint_names; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 362 | uint32_t m_func_name_type_mask; |
| 363 | std::string m_func_regexp; |
| 364 | std::string m_source_text_regexp; |
| 365 | FileSpecList m_modules; |
| 366 | lldb::addr_t m_load_addr; |
| 367 | uint32_t m_ignore_count; |
| 368 | lldb::tid_t m_thread_id; |
| 369 | uint32_t m_thread_index; |
| 370 | std::string m_thread_name; |
| 371 | std::string m_queue_name; |
| 372 | bool m_catch_bp; |
| 373 | bool m_throw_bp; |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 374 | bool m_hardware; // Request to use hardware breakpoints |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 375 | lldb::LanguageType m_language; |
| 376 | LazyBool m_skip_prologue; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 377 | bool m_one_shot; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 378 | bool m_use_dummy; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 379 | |
| 380 | }; |
| 381 | |
| 382 | protected: |
| 383 | virtual bool |
| 384 | DoExecute (Args& command, |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 385 | CommandReturnObject &result) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 386 | { |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 387 | Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); |
| 388 | |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 389 | if (target == nullptr) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 390 | { |
| 391 | result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command)."); |
| 392 | result.SetStatus (eReturnStatusFailed); |
| 393 | return false; |
| 394 | } |
| 395 | |
| 396 | // The following are the various types of breakpoints that could be set: |
| 397 | // 1). -f -l -p [-s -g] (setting breakpoint by source location) |
| 398 | // 2). -a [-s -g] (setting breakpoint by address) |
| 399 | // 3). -n [-s -g] (setting breakpoint by function name) |
| 400 | // 4). -r [-s -g] (setting breakpoint by function name regular expression) |
| 401 | // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text) |
| 402 | // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.) |
| 403 | |
| 404 | BreakpointSetType break_type = eSetTypeInvalid; |
| 405 | |
| 406 | if (m_options.m_line_num != 0) |
| 407 | break_type = eSetTypeFileAndLine; |
| 408 | else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) |
| 409 | break_type = eSetTypeAddress; |
| 410 | else if (!m_options.m_func_names.empty()) |
| 411 | break_type = eSetTypeFunctionName; |
| 412 | else if (!m_options.m_func_regexp.empty()) |
| 413 | break_type = eSetTypeFunctionRegexp; |
| 414 | else if (!m_options.m_source_text_regexp.empty()) |
| 415 | break_type = eSetTypeSourceRegexp; |
| 416 | else if (m_options.m_language != eLanguageTypeUnknown) |
| 417 | break_type = eSetTypeException; |
| 418 | |
| 419 | Breakpoint *bp = NULL; |
| 420 | FileSpec module_spec; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 421 | const bool internal = false; |
| 422 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 423 | switch (break_type) |
| 424 | { |
| 425 | case eSetTypeFileAndLine: // Breakpoint by source position |
| 426 | { |
| 427 | FileSpec file; |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 428 | const size_t num_files = m_options.m_filenames.GetSize(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 429 | if (num_files == 0) |
| 430 | { |
| 431 | if (!GetDefaultFile (target, file, result)) |
| 432 | { |
| 433 | result.AppendError("No file supplied and no default file available."); |
| 434 | result.SetStatus (eReturnStatusFailed); |
| 435 | return false; |
| 436 | } |
| 437 | } |
| 438 | else if (num_files > 1) |
| 439 | { |
| 440 | result.AppendError("Only one file at a time is allowed for file and line breakpoints."); |
| 441 | result.SetStatus (eReturnStatusFailed); |
| 442 | return false; |
| 443 | } |
| 444 | else |
| 445 | file = m_options.m_filenames.GetFileSpecAtIndex(0); |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 446 | |
| 447 | // Only check for inline functions if |
| 448 | LazyBool check_inlines = eLazyBoolCalculate; |
| 449 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 450 | bp = target->CreateBreakpoint (&(m_options.m_modules), |
| 451 | file, |
| 452 | m_options.m_line_num, |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 453 | check_inlines, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 454 | m_options.m_skip_prologue, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 455 | internal, |
| 456 | m_options.m_hardware).get(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 457 | } |
| 458 | break; |
| 459 | |
| 460 | case eSetTypeAddress: // Breakpoint by address |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 461 | bp = target->CreateBreakpoint (m_options.m_load_addr, |
| 462 | internal, |
| 463 | m_options.m_hardware).get(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 464 | break; |
| 465 | |
| 466 | case eSetTypeFunctionName: // Breakpoint by function name |
| 467 | { |
| 468 | uint32_t name_type_mask = m_options.m_func_name_type_mask; |
| 469 | |
| 470 | if (name_type_mask == 0) |
| 471 | name_type_mask = eFunctionNameTypeAuto; |
| 472 | |
| 473 | bp = target->CreateBreakpoint (&(m_options.m_modules), |
| 474 | &(m_options.m_filenames), |
| 475 | m_options.m_func_names, |
| 476 | name_type_mask, |
| 477 | m_options.m_skip_prologue, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 478 | internal, |
| 479 | m_options.m_hardware).get(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 480 | } |
| 481 | break; |
| 482 | |
| 483 | case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name |
| 484 | { |
| 485 | RegularExpression regexp(m_options.m_func_regexp.c_str()); |
| 486 | if (!regexp.IsValid()) |
| 487 | { |
| 488 | char err_str[1024]; |
| 489 | regexp.GetErrorAsCString(err_str, sizeof(err_str)); |
| 490 | result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"", |
| 491 | err_str); |
| 492 | result.SetStatus (eReturnStatusFailed); |
| 493 | return false; |
| 494 | } |
| 495 | |
| 496 | bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules), |
| 497 | &(m_options.m_filenames), |
| 498 | regexp, |
| 499 | m_options.m_skip_prologue, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 500 | internal, |
| 501 | m_options.m_hardware).get(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 502 | } |
| 503 | break; |
| 504 | case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. |
| 505 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 506 | const size_t num_files = m_options.m_filenames.GetSize(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 507 | |
| 508 | if (num_files == 0) |
| 509 | { |
| 510 | FileSpec file; |
| 511 | if (!GetDefaultFile (target, file, result)) |
| 512 | { |
| 513 | result.AppendError ("No files provided and could not find default file."); |
| 514 | result.SetStatus (eReturnStatusFailed); |
| 515 | return false; |
| 516 | } |
| 517 | else |
| 518 | { |
| 519 | m_options.m_filenames.Append (file); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | RegularExpression regexp(m_options.m_source_text_regexp.c_str()); |
| 524 | if (!regexp.IsValid()) |
| 525 | { |
| 526 | char err_str[1024]; |
| 527 | regexp.GetErrorAsCString(err_str, sizeof(err_str)); |
| 528 | result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"", |
| 529 | err_str); |
| 530 | result.SetStatus (eReturnStatusFailed); |
| 531 | return false; |
| 532 | } |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 533 | bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules), |
| 534 | &(m_options.m_filenames), |
| 535 | regexp, |
| 536 | internal, |
| 537 | m_options.m_hardware).get(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 538 | } |
| 539 | break; |
| 540 | case eSetTypeException: |
| 541 | { |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 542 | bp = target->CreateExceptionBreakpoint (m_options.m_language, |
| 543 | m_options.m_catch_bp, |
| 544 | m_options.m_throw_bp, |
| 545 | m_options.m_hardware).get(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 546 | } |
| 547 | break; |
| 548 | default: |
| 549 | break; |
| 550 | } |
| 551 | |
| 552 | // Now set the various options that were passed in: |
| 553 | if (bp) |
| 554 | { |
| 555 | if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) |
| 556 | bp->SetThreadID (m_options.m_thread_id); |
| 557 | |
| 558 | if (m_options.m_thread_index != UINT32_MAX) |
| 559 | bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index); |
| 560 | |
| 561 | if (!m_options.m_thread_name.empty()) |
| 562 | bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str()); |
| 563 | |
| 564 | if (!m_options.m_queue_name.empty()) |
| 565 | bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str()); |
| 566 | |
| 567 | if (m_options.m_ignore_count != 0) |
| 568 | bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count); |
| 569 | |
| 570 | if (!m_options.m_condition.empty()) |
| 571 | bp->GetOptions()->SetCondition(m_options.m_condition.c_str()); |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 572 | |
| 573 | if (!m_options.m_breakpoint_names.empty()) |
| 574 | { |
| 575 | Error error; // We don't need to check the error here, since the option parser checked it... |
| 576 | for (auto name : m_options.m_breakpoint_names) |
| 577 | bp->AddName(name.c_str(), error); |
| 578 | } |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 579 | |
| 580 | bp->SetOneShot (m_options.m_one_shot); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | if (bp) |
| 584 | { |
| 585 | Stream &output_stream = result.GetOutputStream(); |
Jim Ingham | 1391cc7 | 2012-09-22 00:04:04 +0000 | [diff] [blame] | 586 | const bool show_locations = false; |
| 587 | bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, show_locations); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 588 | // Don't print out this warning for exception breakpoints. They can get set before the target |
| 589 | // is set, but we won't know how to actually set the breakpoint till we run. |
| 590 | if (bp->GetNumLocations() == 0 && break_type != eSetTypeException) |
| 591 | output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n"); |
| 592 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 593 | } |
| 594 | else if (!bp) |
| 595 | { |
| 596 | result.AppendError ("Breakpoint creation failed: No breakpoint created."); |
| 597 | result.SetStatus (eReturnStatusFailed); |
| 598 | } |
| 599 | |
| 600 | return result.Succeeded(); |
| 601 | } |
| 602 | |
| 603 | private: |
| 604 | bool |
| 605 | GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result) |
| 606 | { |
| 607 | uint32_t default_line; |
| 608 | // First use the Source Manager's default file. |
| 609 | // Then use the current stack frame's file. |
| 610 | if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) |
| 611 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 612 | StackFrame *cur_frame = m_exe_ctx.GetFramePtr(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 613 | if (cur_frame == NULL) |
| 614 | { |
| 615 | result.AppendError ("No selected frame to use to find the default file."); |
| 616 | result.SetStatus (eReturnStatusFailed); |
| 617 | return false; |
| 618 | } |
| 619 | else if (!cur_frame->HasDebugInformation()) |
| 620 | { |
| 621 | result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info."); |
| 622 | result.SetStatus (eReturnStatusFailed); |
| 623 | return false; |
| 624 | } |
| 625 | else |
| 626 | { |
| 627 | const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry); |
| 628 | if (sc.line_entry.file) |
| 629 | { |
| 630 | file = sc.line_entry.file; |
| 631 | } |
| 632 | else |
| 633 | { |
| 634 | result.AppendError ("Can't find the file for the selected frame to use as the default file."); |
| 635 | result.SetStatus (eReturnStatusFailed); |
| 636 | return false; |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | return true; |
| 641 | } |
| 642 | |
| 643 | CommandOptions m_options; |
| 644 | }; |
Johnny Chen | 6943e7c | 2012-05-08 00:43:20 +0000 | [diff] [blame] | 645 | // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to |
| 646 | // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately. |
Johnny Chen | 4ab2e6b | 2012-05-07 23:23:41 +0000 | [diff] [blame] | 647 | #define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 ) |
| 648 | #define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 ) |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 649 | #define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) ) |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 650 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 651 | OptionDefinition |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 652 | CommandObjectBreakpointSet::CommandOptions::g_option_table[] = |
| 653 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 654 | { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName, |
Jim Ingham | 64cc29c | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 655 | "Set the breakpoint only in this shared library. " |
| 656 | "Can repeat this option multiple times to specify multiple shared libraries."}, |
Jim Ingham | 8651121 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 657 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 658 | { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCount, |
Caroline Tice | deaab22 | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 659 | "Set the number of times this breakpoint is skipped before stopping." }, |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 660 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 661 | { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, |
Jim Ingham | b2b256a | 2013-04-09 18:05:22 +0000 | [diff] [blame] | 662 | "The breakpoint is deleted the first time it causes a stop." }, |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 663 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 664 | { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeExpression, |
Johnny Chen | 7d49c9c | 2012-05-25 21:10:46 +0000 | [diff] [blame] | 665 | "The breakpoint stops only if this condition expression evaluates to true."}, |
| 666 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 667 | { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadIndex, |
Jim Ingham | a89be91 | 2013-03-26 18:29:03 +0000 | [diff] [blame] | 668 | "The breakpoint stops only for the thread whose indeX matches this argument."}, |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 669 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 670 | { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadID, |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 671 | "The breakpoint stops only for the thread whose TID matches this argument."}, |
| 672 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 673 | { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadName, |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 674 | "The breakpoint stops only for the thread whose thread name matches this argument."}, |
| 675 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 676 | { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 677 | "Require the breakpoint to use hardware breakpoints."}, |
| 678 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 679 | { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeQueueName, |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 680 | "The breakpoint stops only for threads in the queue whose name is given by this argument."}, |
| 681 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 682 | { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, |
Jim Ingham | 289aca6 | 2013-02-14 19:10:36 +0000 | [diff] [blame] | 683 | "Specifies the source file in which to set this breakpoint. " |
| 684 | "Note, by default lldb only looks for files that are #included if they use the standard include file extensions. " |
Jim Ingham | 6394479 | 2013-02-14 19:30:35 +0000 | [diff] [blame] | 685 | "To set breakpoints on .c/.cpp/.m/.mm files that are #included, set target.inline-breakpoint-strategy" |
Jim Ingham | 289aca6 | 2013-02-14 19:10:36 +0000 | [diff] [blame] | 686 | " to \"always\"."}, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 687 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 688 | { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLineNum, |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 689 | "Specifies the line number on which to set this breakpoint."}, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 690 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 691 | // Comment out this option for the moment, as we don't actually use it, but will in the future. |
| 692 | // This way users won't see it, but the infrastructure is left in place. |
Virgile Bello | e2607b5 | 2013-09-05 16:42:23 +0000 | [diff] [blame] | 693 | // { 0, false, "column", 'C', OptionParser::eRequiredArgument, NULL, "<column>", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 694 | // "Set the breakpoint by source location at this particular column."}, |
| 695 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 696 | { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeAddressOrExpression, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 697 | "Set the breakpoint by address, at the specified address."}, |
| 698 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 699 | { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, |
Jim Ingham | 551262d | 2013-03-27 17:36:54 +0000 | [diff] [blame] | 700 | "Set the breakpoint by function name. Can be repeated multiple times to make one breakpoint for multiple names" }, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 701 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 702 | { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName, |
Jim Ingham | 64cc29c | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 703 | "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and " |
| 704 | "for Objective C this means a full function prototype with class and selector. " |
| 705 | "Can be repeated multiple times to make one breakpoint for multiple names." }, |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 706 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 707 | { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeSelector, |
Jim Ingham | 64cc29c | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 708 | "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." }, |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 709 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 710 | { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeMethod, |
Jim Ingham | 64cc29c | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 711 | "Set the breakpoint by C++ method names. Can be repeated multiple times to make one breakpoint for multiple methods." }, |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 712 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 713 | { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeRegularExpression, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 714 | "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." }, |
| 715 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 716 | { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, |
Jim Ingham | 64cc29c | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 717 | "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). " |
| 718 | "Can be repeated multiple times to make one breakpoint for multiple symbols." }, |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 719 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 720 | { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeRegularExpression, |
Jim Ingham | e96ade8 | 2013-06-07 01:13:00 +0000 | [diff] [blame] | 721 | "Set the breakpoint by specifying a regular expression which is matched against the source text in a source file or files " |
| 722 | "specified with the -f option. The -f option can be specified more than once. " |
| 723 | "If no source files are specified, uses the current \"default source file\"" }, |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 724 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 725 | { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLanguage, |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 726 | "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" }, |
| 727 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 728 | { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 729 | "Set the breakpoint on exception throW." }, |
| 730 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 731 | { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 732 | "Set the breakpoint on exception catcH." }, |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 733 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 734 | { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 735 | "sKip the prologue if the breakpoint is at the beginning of a function. If not set the target.skip-prologue setting is used." }, |
| 736 | |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 737 | { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, |
| 738 | "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, |
| 739 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 740 | { LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointName, |
| 741 | "Adds this to the list of names for this breakopint."}, |
| 742 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 743 | { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 744 | }; |
| 745 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 746 | //------------------------------------------------------------------------- |
| 747 | // CommandObjectBreakpointModify |
| 748 | //------------------------------------------------------------------------- |
| 749 | #pragma mark Modify |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 750 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 751 | class CommandObjectBreakpointModify : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 752 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 753 | public: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 754 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 755 | CommandObjectBreakpointModify (CommandInterpreter &interpreter) : |
| 756 | CommandObjectParsed (interpreter, |
| 757 | "breakpoint modify", |
| 758 | "Modify the options on a breakpoint or set of breakpoints in the executable. " |
| 759 | "If no breakpoint is specified, acts on the last created breakpoint. " |
| 760 | "With the exception of -e, -d and -i, passing an empty argument clears the modification.", |
| 761 | NULL), |
| 762 | m_options (interpreter) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 763 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 764 | CommandArgumentEntry arg; |
| 765 | CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); |
| 766 | // Add the entry for the first argument for this command to the object's arguments vector. |
| 767 | m_arguments.push_back (arg); |
| 768 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 769 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 770 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 771 | virtual |
| 772 | ~CommandObjectBreakpointModify () {} |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 773 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 774 | virtual Options * |
| 775 | GetOptions () |
| 776 | { |
| 777 | return &m_options; |
| 778 | } |
Johnny Chen | 7d49c9c | 2012-05-25 21:10:46 +0000 | [diff] [blame] | 779 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 780 | class CommandOptions : public Options |
| 781 | { |
| 782 | public: |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 783 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 784 | CommandOptions (CommandInterpreter &interpreter) : |
| 785 | Options (interpreter), |
| 786 | m_ignore_count (0), |
| 787 | m_thread_id(LLDB_INVALID_THREAD_ID), |
| 788 | m_thread_id_passed(false), |
| 789 | m_thread_index (UINT32_MAX), |
| 790 | m_thread_index_passed(false), |
| 791 | m_thread_name(), |
| 792 | m_queue_name(), |
| 793 | m_condition (), |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 794 | m_one_shot (false), |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 795 | m_enable_passed (false), |
| 796 | m_enable_value (false), |
| 797 | m_name_passed (false), |
| 798 | m_queue_passed (false), |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 799 | m_condition_passed (false), |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 800 | m_one_shot_passed (false), |
| 801 | m_use_dummy (false) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 802 | { |
| 803 | } |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 804 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 805 | virtual |
| 806 | ~CommandOptions () {} |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 807 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 808 | virtual Error |
| 809 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 810 | { |
| 811 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 812 | const int short_option = m_getopt_table[option_idx].val; |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 813 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 814 | switch (short_option) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 815 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 816 | case 'c': |
| 817 | if (option_arg != NULL) |
| 818 | m_condition.assign (option_arg); |
| 819 | else |
| 820 | m_condition.clear(); |
| 821 | m_condition_passed = true; |
| 822 | break; |
| 823 | case 'd': |
| 824 | m_enable_passed = true; |
| 825 | m_enable_value = false; |
| 826 | break; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 827 | case 'D': |
| 828 | m_use_dummy = true; |
| 829 | break; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 830 | case 'e': |
| 831 | m_enable_passed = true; |
| 832 | m_enable_value = true; |
| 833 | break; |
| 834 | case 'i': |
| 835 | { |
| 836 | m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); |
| 837 | if (m_ignore_count == UINT32_MAX) |
| 838 | error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); |
| 839 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 840 | break; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 841 | case 'o': |
| 842 | { |
| 843 | bool value, success; |
| 844 | value = Args::StringToBoolean(option_arg, false, &success); |
| 845 | if (success) |
| 846 | { |
| 847 | m_one_shot_passed = true; |
| 848 | m_one_shot = value; |
| 849 | } |
| 850 | else |
| 851 | error.SetErrorStringWithFormat("invalid boolean value '%s' passed for -o option", option_arg); |
| 852 | } |
| 853 | break; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 854 | case 't' : |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 855 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 856 | if (option_arg[0] == '\0') |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 857 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 858 | m_thread_id = LLDB_INVALID_THREAD_ID; |
| 859 | m_thread_id_passed = true; |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 860 | } |
| 861 | else |
| 862 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 863 | m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); |
| 864 | if (m_thread_id == LLDB_INVALID_THREAD_ID) |
| 865 | error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); |
| 866 | else |
| 867 | m_thread_id_passed = true; |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 868 | } |
| 869 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 870 | break; |
| 871 | case 'T': |
| 872 | if (option_arg != NULL) |
| 873 | m_thread_name.assign (option_arg); |
| 874 | else |
| 875 | m_thread_name.clear(); |
| 876 | m_name_passed = true; |
| 877 | break; |
| 878 | case 'q': |
| 879 | if (option_arg != NULL) |
| 880 | m_queue_name.assign (option_arg); |
| 881 | else |
| 882 | m_queue_name.clear(); |
| 883 | m_queue_passed = true; |
| 884 | break; |
| 885 | case 'x': |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 886 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 887 | if (option_arg[0] == '\n') |
| 888 | { |
| 889 | m_thread_index = UINT32_MAX; |
| 890 | m_thread_index_passed = true; |
| 891 | } |
| 892 | else |
| 893 | { |
| 894 | m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0); |
| 895 | if (m_thread_id == UINT32_MAX) |
| 896 | error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); |
| 897 | else |
| 898 | m_thread_index_passed = true; |
| 899 | } |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 900 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 901 | break; |
| 902 | default: |
| 903 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 904 | break; |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 905 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 906 | |
| 907 | return error; |
| 908 | } |
| 909 | void |
| 910 | OptionParsingStarting () |
| 911 | { |
| 912 | m_ignore_count = 0; |
| 913 | m_thread_id = LLDB_INVALID_THREAD_ID; |
| 914 | m_thread_id_passed = false; |
| 915 | m_thread_index = UINT32_MAX; |
| 916 | m_thread_index_passed = false; |
| 917 | m_thread_name.clear(); |
| 918 | m_queue_name.clear(); |
| 919 | m_condition.clear(); |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 920 | m_one_shot = false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 921 | m_enable_passed = false; |
| 922 | m_queue_passed = false; |
| 923 | m_name_passed = false; |
| 924 | m_condition_passed = false; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 925 | m_one_shot_passed = false; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 926 | m_use_dummy = false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | const OptionDefinition* |
| 930 | GetDefinitions () |
| 931 | { |
| 932 | return g_option_table; |
| 933 | } |
| 934 | |
| 935 | |
| 936 | // Options table: Required for subclasses of Options. |
| 937 | |
| 938 | static OptionDefinition g_option_table[]; |
| 939 | |
| 940 | // Instance variables to hold the values for command options. |
| 941 | |
| 942 | uint32_t m_ignore_count; |
| 943 | lldb::tid_t m_thread_id; |
| 944 | bool m_thread_id_passed; |
| 945 | uint32_t m_thread_index; |
| 946 | bool m_thread_index_passed; |
| 947 | std::string m_thread_name; |
| 948 | std::string m_queue_name; |
| 949 | std::string m_condition; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 950 | bool m_one_shot; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 951 | bool m_enable_passed; |
| 952 | bool m_enable_value; |
| 953 | bool m_name_passed; |
| 954 | bool m_queue_passed; |
| 955 | bool m_condition_passed; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 956 | bool m_one_shot_passed; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 957 | bool m_use_dummy; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 958 | |
| 959 | }; |
| 960 | |
| 961 | protected: |
| 962 | virtual bool |
| 963 | DoExecute (Args& command, CommandReturnObject &result) |
| 964 | { |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 965 | Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 966 | if (target == NULL) |
| 967 | { |
| 968 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 969 | result.SetStatus (eReturnStatusFailed); |
| 970 | return false; |
| 971 | } |
| 972 | |
| 973 | Mutex::Locker locker; |
| 974 | target->GetBreakpointList().GetListMutex(locker); |
| 975 | |
| 976 | BreakpointIDList valid_bp_ids; |
| 977 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 978 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 979 | |
| 980 | if (result.Succeeded()) |
| 981 | { |
| 982 | const size_t count = valid_bp_ids.GetSize(); |
| 983 | for (size_t i = 0; i < count; ++i) |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 984 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 985 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); |
| 986 | |
| 987 | if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) |
| 988 | { |
| 989 | Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); |
| 990 | if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) |
| 991 | { |
| 992 | BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get(); |
| 993 | if (location) |
| 994 | { |
| 995 | if (m_options.m_thread_id_passed) |
| 996 | location->SetThreadID (m_options.m_thread_id); |
| 997 | |
| 998 | if (m_options.m_thread_index_passed) |
| 999 | location->SetThreadIndex(m_options.m_thread_index); |
| 1000 | |
| 1001 | if (m_options.m_name_passed) |
| 1002 | location->SetThreadName(m_options.m_thread_name.c_str()); |
| 1003 | |
| 1004 | if (m_options.m_queue_passed) |
| 1005 | location->SetQueueName(m_options.m_queue_name.c_str()); |
| 1006 | |
| 1007 | if (m_options.m_ignore_count != 0) |
| 1008 | location->SetIgnoreCount(m_options.m_ignore_count); |
| 1009 | |
| 1010 | if (m_options.m_enable_passed) |
| 1011 | location->SetEnabled (m_options.m_enable_value); |
| 1012 | |
| 1013 | if (m_options.m_condition_passed) |
| 1014 | location->SetCondition (m_options.m_condition.c_str()); |
| 1015 | } |
| 1016 | } |
| 1017 | else |
| 1018 | { |
| 1019 | if (m_options.m_thread_id_passed) |
| 1020 | bp->SetThreadID (m_options.m_thread_id); |
| 1021 | |
| 1022 | if (m_options.m_thread_index_passed) |
| 1023 | bp->SetThreadIndex(m_options.m_thread_index); |
| 1024 | |
| 1025 | if (m_options.m_name_passed) |
| 1026 | bp->SetThreadName(m_options.m_thread_name.c_str()); |
| 1027 | |
| 1028 | if (m_options.m_queue_passed) |
| 1029 | bp->SetQueueName(m_options.m_queue_name.c_str()); |
| 1030 | |
| 1031 | if (m_options.m_ignore_count != 0) |
| 1032 | bp->SetIgnoreCount(m_options.m_ignore_count); |
| 1033 | |
| 1034 | if (m_options.m_enable_passed) |
| 1035 | bp->SetEnabled (m_options.m_enable_value); |
| 1036 | |
| 1037 | if (m_options.m_condition_passed) |
| 1038 | bp->SetCondition (m_options.m_condition.c_str()); |
| 1039 | } |
| 1040 | } |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1041 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | return result.Succeeded(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1047 | private: |
| 1048 | CommandOptions m_options; |
| 1049 | }; |
Johnny Chen | 7d49c9c | 2012-05-25 21:10:46 +0000 | [diff] [blame] | 1050 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1051 | #pragma mark Modify::CommandOptions |
| 1052 | OptionDefinition |
| 1053 | CommandObjectBreakpointModify::CommandOptions::g_option_table[] = |
| 1054 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1055 | { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." }, |
| 1056 | { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "The breakpoint is deleted the first time it stop causes a stop." }, |
| 1057 | { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose index matches this argument."}, |
| 1058 | { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."}, |
| 1059 | { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."}, |
| 1060 | { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."}, |
| 1061 | { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."}, |
| 1062 | { LLDB_OPT_SET_1, false, "enable", 'e', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Enable the breakpoint."}, |
| 1063 | { LLDB_OPT_SET_2, false, "disable", 'd', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Disable the breakpoint."}, |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1064 | { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, |
| 1065 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1066 | { 0, false, NULL, 0 , 0, NULL, NULL, 0, eArgTypeNone, NULL } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1067 | }; |
| 1068 | |
| 1069 | //------------------------------------------------------------------------- |
| 1070 | // CommandObjectBreakpointEnable |
| 1071 | //------------------------------------------------------------------------- |
| 1072 | #pragma mark Enable |
| 1073 | |
| 1074 | class CommandObjectBreakpointEnable : public CommandObjectParsed |
| 1075 | { |
| 1076 | public: |
| 1077 | CommandObjectBreakpointEnable (CommandInterpreter &interpreter) : |
| 1078 | CommandObjectParsed (interpreter, |
| 1079 | "enable", |
| 1080 | "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.", |
| 1081 | NULL) |
| 1082 | { |
| 1083 | CommandArgumentEntry arg; |
| 1084 | CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); |
| 1085 | // Add the entry for the first argument for this command to the object's arguments vector. |
| 1086 | m_arguments.push_back (arg); |
| 1087 | } |
| 1088 | |
| 1089 | |
| 1090 | virtual |
| 1091 | ~CommandObjectBreakpointEnable () {} |
| 1092 | |
| 1093 | protected: |
| 1094 | virtual bool |
| 1095 | DoExecute (Args& command, CommandReturnObject &result) |
| 1096 | { |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 1097 | Target *target = GetSelectedOrDummyTarget(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1098 | if (target == NULL) |
| 1099 | { |
| 1100 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 1101 | result.SetStatus (eReturnStatusFailed); |
| 1102 | return false; |
| 1103 | } |
| 1104 | |
| 1105 | Mutex::Locker locker; |
| 1106 | target->GetBreakpointList().GetListMutex(locker); |
| 1107 | |
| 1108 | const BreakpointList &breakpoints = target->GetBreakpointList(); |
| 1109 | |
| 1110 | size_t num_breakpoints = breakpoints.GetSize(); |
| 1111 | |
| 1112 | if (num_breakpoints == 0) |
| 1113 | { |
| 1114 | result.AppendError ("No breakpoints exist to be enabled."); |
| 1115 | result.SetStatus (eReturnStatusFailed); |
| 1116 | return false; |
| 1117 | } |
| 1118 | |
| 1119 | if (command.GetArgumentCount() == 0) |
| 1120 | { |
| 1121 | // No breakpoint selected; enable all currently set breakpoints. |
| 1122 | target->EnableAllBreakpoints (); |
Greg Clayton | 6fea17e | 2014-03-03 19:15:20 +0000 | [diff] [blame] | 1123 | result.AppendMessageWithFormat ("All breakpoints enabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1124 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1125 | } |
| 1126 | else |
| 1127 | { |
| 1128 | // Particular breakpoint selected; enable that breakpoint. |
| 1129 | BreakpointIDList valid_bp_ids; |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 1130 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1131 | |
| 1132 | if (result.Succeeded()) |
| 1133 | { |
| 1134 | int enable_count = 0; |
| 1135 | int loc_count = 0; |
| 1136 | const size_t count = valid_bp_ids.GetSize(); |
| 1137 | for (size_t i = 0; i < count; ++i) |
| 1138 | { |
| 1139 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); |
| 1140 | |
| 1141 | if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) |
| 1142 | { |
| 1143 | Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); |
| 1144 | if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) |
| 1145 | { |
| 1146 | BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); |
| 1147 | if (location) |
| 1148 | { |
| 1149 | location->SetEnabled (true); |
| 1150 | ++loc_count; |
| 1151 | } |
| 1152 | } |
| 1153 | else |
| 1154 | { |
| 1155 | breakpoint->SetEnabled (true); |
| 1156 | ++enable_count; |
| 1157 | } |
| 1158 | } |
| 1159 | } |
| 1160 | result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count); |
| 1161 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | return result.Succeeded(); |
| 1166 | } |
| 1167 | }; |
| 1168 | |
| 1169 | //------------------------------------------------------------------------- |
| 1170 | // CommandObjectBreakpointDisable |
| 1171 | //------------------------------------------------------------------------- |
| 1172 | #pragma mark Disable |
| 1173 | |
| 1174 | class CommandObjectBreakpointDisable : public CommandObjectParsed |
| 1175 | { |
| 1176 | public: |
| 1177 | CommandObjectBreakpointDisable (CommandInterpreter &interpreter) : |
| 1178 | CommandObjectParsed (interpreter, |
| 1179 | "breakpoint disable", |
| 1180 | "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.", |
| 1181 | NULL) |
| 1182 | { |
Jim Ingham | b0fac50 | 2013-03-08 00:31:40 +0000 | [diff] [blame] | 1183 | SetHelpLong( |
| 1184 | "Disable the specified breakpoint(s) without removing it/them. \n\ |
| 1185 | If no breakpoints are specified, disable them all.\n\ |
| 1186 | \n\ |
| 1187 | Note: disabling a breakpoint will cause none of its locations to be hit\n\ |
| 1188 | regardless of whether they are enabled or disabled. So the sequence: \n\ |
| 1189 | \n\ |
| 1190 | (lldb) break disable 1\n\ |
| 1191 | (lldb) break enable 1.1\n\ |
| 1192 | \n\ |
| 1193 | will NOT cause location 1.1 to get hit. To achieve that, do:\n\ |
| 1194 | \n\ |
| 1195 | (lldb) break disable 1.*\n\ |
| 1196 | (lldb) break enable 1.1\n\ |
| 1197 | \n\ |
| 1198 | The first command disables all the locations of breakpoint 1, \n\ |
| 1199 | the second re-enables the first location." |
| 1200 | ); |
| 1201 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1202 | CommandArgumentEntry arg; |
| 1203 | CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); |
| 1204 | // Add the entry for the first argument for this command to the object's arguments vector. |
Jim Ingham | b0fac50 | 2013-03-08 00:31:40 +0000 | [diff] [blame] | 1205 | m_arguments.push_back (arg); |
| 1206 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | |
| 1210 | virtual |
| 1211 | ~CommandObjectBreakpointDisable () {} |
| 1212 | |
| 1213 | protected: |
| 1214 | virtual bool |
| 1215 | DoExecute (Args& command, CommandReturnObject &result) |
| 1216 | { |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 1217 | Target *target = GetSelectedOrDummyTarget(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1218 | if (target == NULL) |
| 1219 | { |
| 1220 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 1221 | result.SetStatus (eReturnStatusFailed); |
| 1222 | return false; |
| 1223 | } |
| 1224 | |
| 1225 | Mutex::Locker locker; |
| 1226 | target->GetBreakpointList().GetListMutex(locker); |
| 1227 | |
| 1228 | const BreakpointList &breakpoints = target->GetBreakpointList(); |
| 1229 | size_t num_breakpoints = breakpoints.GetSize(); |
| 1230 | |
| 1231 | if (num_breakpoints == 0) |
| 1232 | { |
| 1233 | result.AppendError ("No breakpoints exist to be disabled."); |
| 1234 | result.SetStatus (eReturnStatusFailed); |
| 1235 | return false; |
| 1236 | } |
| 1237 | |
| 1238 | if (command.GetArgumentCount() == 0) |
| 1239 | { |
| 1240 | // No breakpoint selected; disable all currently set breakpoints. |
| 1241 | target->DisableAllBreakpoints (); |
Greg Clayton | 6fea17e | 2014-03-03 19:15:20 +0000 | [diff] [blame] | 1242 | result.AppendMessageWithFormat ("All breakpoints disabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1243 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1244 | } |
| 1245 | else |
| 1246 | { |
| 1247 | // Particular breakpoint selected; disable that breakpoint. |
| 1248 | BreakpointIDList valid_bp_ids; |
| 1249 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 1250 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1251 | |
| 1252 | if (result.Succeeded()) |
| 1253 | { |
| 1254 | int disable_count = 0; |
| 1255 | int loc_count = 0; |
| 1256 | const size_t count = valid_bp_ids.GetSize(); |
| 1257 | for (size_t i = 0; i < count; ++i) |
| 1258 | { |
| 1259 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); |
| 1260 | |
| 1261 | if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) |
| 1262 | { |
| 1263 | Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); |
| 1264 | if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) |
| 1265 | { |
| 1266 | BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); |
| 1267 | if (location) |
| 1268 | { |
| 1269 | location->SetEnabled (false); |
| 1270 | ++loc_count; |
| 1271 | } |
| 1272 | } |
| 1273 | else |
| 1274 | { |
| 1275 | breakpoint->SetEnabled (false); |
| 1276 | ++disable_count; |
| 1277 | } |
| 1278 | } |
| 1279 | } |
| 1280 | result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count); |
| 1281 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | return result.Succeeded(); |
| 1286 | } |
| 1287 | |
| 1288 | }; |
| 1289 | |
| 1290 | //------------------------------------------------------------------------- |
| 1291 | // CommandObjectBreakpointList |
| 1292 | //------------------------------------------------------------------------- |
| 1293 | #pragma mark List |
| 1294 | |
| 1295 | class CommandObjectBreakpointList : public CommandObjectParsed |
| 1296 | { |
| 1297 | public: |
| 1298 | CommandObjectBreakpointList (CommandInterpreter &interpreter) : |
| 1299 | CommandObjectParsed (interpreter, |
| 1300 | "breakpoint list", |
| 1301 | "List some or all breakpoints at configurable levels of detail.", |
| 1302 | NULL), |
| 1303 | m_options (interpreter) |
| 1304 | { |
| 1305 | CommandArgumentEntry arg; |
| 1306 | CommandArgumentData bp_id_arg; |
| 1307 | |
| 1308 | // Define the first (and only) variant of this arg. |
| 1309 | bp_id_arg.arg_type = eArgTypeBreakpointID; |
| 1310 | bp_id_arg.arg_repetition = eArgRepeatOptional; |
| 1311 | |
| 1312 | // There is only one variant this argument could be; put it into the argument entry. |
| 1313 | arg.push_back (bp_id_arg); |
| 1314 | |
| 1315 | // Push the data for the first argument into the m_arguments vector. |
| 1316 | m_arguments.push_back (arg); |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | virtual |
| 1321 | ~CommandObjectBreakpointList () {} |
| 1322 | |
| 1323 | virtual Options * |
| 1324 | GetOptions () |
| 1325 | { |
| 1326 | return &m_options; |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1329 | class CommandOptions : public Options |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1330 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1331 | public: |
| 1332 | |
| 1333 | CommandOptions (CommandInterpreter &interpreter) : |
| 1334 | Options (interpreter), |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1335 | m_level (lldb::eDescriptionLevelBrief), |
| 1336 | m_use_dummy(false) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1337 | { |
| 1338 | } |
| 1339 | |
| 1340 | virtual |
| 1341 | ~CommandOptions () {} |
| 1342 | |
| 1343 | virtual Error |
| 1344 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 1345 | { |
| 1346 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 1347 | const int short_option = m_getopt_table[option_idx].val; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1348 | |
| 1349 | switch (short_option) |
| 1350 | { |
| 1351 | case 'b': |
| 1352 | m_level = lldb::eDescriptionLevelBrief; |
| 1353 | break; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1354 | case 'D': |
| 1355 | m_use_dummy = true; |
| 1356 | break; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1357 | case 'f': |
| 1358 | m_level = lldb::eDescriptionLevelFull; |
| 1359 | break; |
| 1360 | case 'v': |
| 1361 | m_level = lldb::eDescriptionLevelVerbose; |
| 1362 | break; |
| 1363 | case 'i': |
| 1364 | m_internal = true; |
| 1365 | break; |
| 1366 | default: |
| 1367 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 1368 | break; |
| 1369 | } |
| 1370 | |
| 1371 | return error; |
| 1372 | } |
| 1373 | |
| 1374 | void |
| 1375 | OptionParsingStarting () |
| 1376 | { |
| 1377 | m_level = lldb::eDescriptionLevelFull; |
| 1378 | m_internal = false; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1379 | m_use_dummy = false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | const OptionDefinition * |
| 1383 | GetDefinitions () |
| 1384 | { |
| 1385 | return g_option_table; |
| 1386 | } |
| 1387 | |
| 1388 | // Options table: Required for subclasses of Options. |
| 1389 | |
| 1390 | static OptionDefinition g_option_table[]; |
| 1391 | |
| 1392 | // Instance variables to hold the values for command options. |
| 1393 | |
| 1394 | lldb::DescriptionLevel m_level; |
| 1395 | |
| 1396 | bool m_internal; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1397 | bool m_use_dummy; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1398 | }; |
| 1399 | |
| 1400 | protected: |
| 1401 | virtual bool |
| 1402 | DoExecute (Args& command, CommandReturnObject &result) |
| 1403 | { |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1404 | Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); |
| 1405 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1406 | if (target == NULL) |
| 1407 | { |
| 1408 | result.AppendError ("Invalid target. No current target or breakpoints."); |
| 1409 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1410 | return true; |
| 1411 | } |
| 1412 | |
| 1413 | const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal); |
| 1414 | Mutex::Locker locker; |
| 1415 | target->GetBreakpointList(m_options.m_internal).GetListMutex(locker); |
| 1416 | |
| 1417 | size_t num_breakpoints = breakpoints.GetSize(); |
| 1418 | |
| 1419 | if (num_breakpoints == 0) |
| 1420 | { |
| 1421 | result.AppendMessage ("No breakpoints currently set."); |
| 1422 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1423 | return true; |
| 1424 | } |
| 1425 | |
Jim Ingham | 85e8b81 | 2011-02-19 02:53:09 +0000 | [diff] [blame] | 1426 | Stream &output_stream = result.GetOutputStream(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1427 | |
| 1428 | if (command.GetArgumentCount() == 0) |
| 1429 | { |
| 1430 | // No breakpoint selected; show info about all currently set breakpoints. |
| 1431 | result.AppendMessage ("Current breakpoints:"); |
| 1432 | for (size_t i = 0; i < num_breakpoints; ++i) |
| 1433 | { |
| 1434 | Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get(); |
| 1435 | AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); |
| 1436 | } |
| 1437 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1438 | } |
| 1439 | else |
| 1440 | { |
| 1441 | // Particular breakpoints selected; show info about that breakpoint. |
| 1442 | BreakpointIDList valid_bp_ids; |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 1443 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1444 | |
| 1445 | if (result.Succeeded()) |
| 1446 | { |
| 1447 | for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) |
| 1448 | { |
| 1449 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); |
| 1450 | Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); |
| 1451 | AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level); |
| 1452 | } |
| 1453 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1454 | } |
| 1455 | else |
| 1456 | { |
| 1457 | result.AppendError ("Invalid breakpoint id."); |
| 1458 | result.SetStatus (eReturnStatusFailed); |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | return result.Succeeded(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1465 | private: |
| 1466 | CommandOptions m_options; |
| 1467 | }; |
| 1468 | |
| 1469 | #pragma mark List::CommandOptions |
| 1470 | OptionDefinition |
| 1471 | CommandObjectBreakpointList::CommandOptions::g_option_table[] = |
| 1472 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1473 | { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1474 | "Show debugger internal breakpoints" }, |
| 1475 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1476 | { LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1477 | "Give a brief description of the breakpoint (no location info)."}, |
| 1478 | |
| 1479 | // FIXME: We need to add an "internal" command, and then add this sort of thing to it. |
| 1480 | // But I need to see it for now, and don't want to wait. |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1481 | { LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1482 | "Give a full description of the breakpoint and its locations."}, |
| 1483 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1484 | { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1485 | "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, |
| 1486 | |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1487 | { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, |
| 1488 | "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, |
| 1489 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1490 | { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1491 | }; |
| 1492 | |
| 1493 | //------------------------------------------------------------------------- |
| 1494 | // CommandObjectBreakpointClear |
| 1495 | //------------------------------------------------------------------------- |
| 1496 | #pragma mark Clear |
| 1497 | |
| 1498 | class CommandObjectBreakpointClear : public CommandObjectParsed |
| 1499 | { |
| 1500 | public: |
| 1501 | |
| 1502 | typedef enum BreakpointClearType |
| 1503 | { |
| 1504 | eClearTypeInvalid, |
| 1505 | eClearTypeFileAndLine |
| 1506 | } BreakpointClearType; |
| 1507 | |
| 1508 | CommandObjectBreakpointClear (CommandInterpreter &interpreter) : |
| 1509 | CommandObjectParsed (interpreter, |
| 1510 | "breakpoint clear", |
| 1511 | "Clears a breakpoint or set of breakpoints in the executable.", |
| 1512 | "breakpoint clear <cmd-options>"), |
| 1513 | m_options (interpreter) |
| 1514 | { |
| 1515 | } |
| 1516 | |
| 1517 | virtual |
| 1518 | ~CommandObjectBreakpointClear () {} |
| 1519 | |
| 1520 | virtual Options * |
| 1521 | GetOptions () |
| 1522 | { |
| 1523 | return &m_options; |
| 1524 | } |
| 1525 | |
| 1526 | class CommandOptions : public Options |
| 1527 | { |
| 1528 | public: |
| 1529 | |
| 1530 | CommandOptions (CommandInterpreter &interpreter) : |
| 1531 | Options (interpreter), |
| 1532 | m_filename (), |
| 1533 | m_line_num (0) |
| 1534 | { |
| 1535 | } |
| 1536 | |
| 1537 | virtual |
| 1538 | ~CommandOptions () {} |
| 1539 | |
| 1540 | virtual Error |
| 1541 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 1542 | { |
| 1543 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 1544 | const int short_option = m_getopt_table[option_idx].val; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1545 | |
| 1546 | switch (short_option) |
| 1547 | { |
| 1548 | case 'f': |
| 1549 | m_filename.assign (option_arg); |
| 1550 | break; |
| 1551 | |
| 1552 | case 'l': |
| 1553 | m_line_num = Args::StringToUInt32 (option_arg, 0); |
| 1554 | break; |
| 1555 | |
| 1556 | default: |
| 1557 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 1558 | break; |
| 1559 | } |
| 1560 | |
| 1561 | return error; |
| 1562 | } |
| 1563 | |
| 1564 | void |
| 1565 | OptionParsingStarting () |
| 1566 | { |
| 1567 | m_filename.clear(); |
| 1568 | m_line_num = 0; |
| 1569 | } |
| 1570 | |
| 1571 | const OptionDefinition* |
| 1572 | GetDefinitions () |
| 1573 | { |
| 1574 | return g_option_table; |
| 1575 | } |
| 1576 | |
| 1577 | // Options table: Required for subclasses of Options. |
| 1578 | |
| 1579 | static OptionDefinition g_option_table[]; |
| 1580 | |
| 1581 | // Instance variables to hold the values for command options. |
| 1582 | |
| 1583 | std::string m_filename; |
| 1584 | uint32_t m_line_num; |
| 1585 | |
| 1586 | }; |
| 1587 | |
| 1588 | protected: |
| 1589 | virtual bool |
| 1590 | DoExecute (Args& command, CommandReturnObject &result) |
| 1591 | { |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 1592 | Target *target = GetSelectedOrDummyTarget(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1593 | if (target == NULL) |
| 1594 | { |
| 1595 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 1596 | result.SetStatus (eReturnStatusFailed); |
| 1597 | return false; |
| 1598 | } |
| 1599 | |
| 1600 | // The following are the various types of breakpoints that could be cleared: |
| 1601 | // 1). -f -l (clearing breakpoint by source location) |
| 1602 | |
| 1603 | BreakpointClearType break_type = eClearTypeInvalid; |
| 1604 | |
| 1605 | if (m_options.m_line_num != 0) |
| 1606 | break_type = eClearTypeFileAndLine; |
| 1607 | |
| 1608 | Mutex::Locker locker; |
| 1609 | target->GetBreakpointList().GetListMutex(locker); |
| 1610 | |
| 1611 | BreakpointList &breakpoints = target->GetBreakpointList(); |
| 1612 | size_t num_breakpoints = breakpoints.GetSize(); |
| 1613 | |
| 1614 | // Early return if there's no breakpoint at all. |
| 1615 | if (num_breakpoints == 0) |
| 1616 | { |
| 1617 | result.AppendError ("Breakpoint clear: No breakpoint cleared."); |
| 1618 | result.SetStatus (eReturnStatusFailed); |
| 1619 | return result.Succeeded(); |
| 1620 | } |
| 1621 | |
| 1622 | // Find matching breakpoints and delete them. |
| 1623 | |
| 1624 | // First create a copy of all the IDs. |
| 1625 | std::vector<break_id_t> BreakIDs; |
| 1626 | for (size_t i = 0; i < num_breakpoints; ++i) |
| 1627 | BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID()); |
| 1628 | |
| 1629 | int num_cleared = 0; |
| 1630 | StreamString ss; |
| 1631 | switch (break_type) |
| 1632 | { |
| 1633 | case eClearTypeFileAndLine: // Breakpoint by source position |
| 1634 | { |
| 1635 | const ConstString filename(m_options.m_filename.c_str()); |
| 1636 | BreakpointLocationCollection loc_coll; |
| 1637 | |
| 1638 | for (size_t i = 0; i < num_breakpoints; ++i) |
| 1639 | { |
| 1640 | Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); |
| 1641 | |
| 1642 | if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) |
| 1643 | { |
| 1644 | // If the collection size is 0, it's a full match and we can just remove the breakpoint. |
| 1645 | if (loc_coll.GetSize() == 0) |
| 1646 | { |
| 1647 | bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); |
| 1648 | ss.EOL(); |
| 1649 | target->RemoveBreakpointByID (bp->GetID()); |
| 1650 | ++num_cleared; |
| 1651 | } |
| 1652 | } |
| 1653 | } |
| 1654 | } |
| 1655 | break; |
| 1656 | |
| 1657 | default: |
| 1658 | break; |
| 1659 | } |
| 1660 | |
| 1661 | if (num_cleared > 0) |
| 1662 | { |
| 1663 | Stream &output_stream = result.GetOutputStream(); |
| 1664 | output_stream.Printf ("%d breakpoints cleared:\n", num_cleared); |
| 1665 | output_stream << ss.GetData(); |
| 1666 | output_stream.EOL(); |
| 1667 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1668 | } |
| 1669 | else |
| 1670 | { |
| 1671 | result.AppendError ("Breakpoint clear: No breakpoint cleared."); |
| 1672 | result.SetStatus (eReturnStatusFailed); |
| 1673 | } |
| 1674 | |
| 1675 | return result.Succeeded(); |
| 1676 | } |
| 1677 | |
| 1678 | private: |
| 1679 | CommandOptions m_options; |
| 1680 | }; |
| 1681 | |
| 1682 | #pragma mark Clear::CommandOptions |
| 1683 | |
| 1684 | OptionDefinition |
| 1685 | CommandObjectBreakpointClear::CommandOptions::g_option_table[] = |
| 1686 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1687 | { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1688 | "Specify the breakpoint by source location in this particular file."}, |
| 1689 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1690 | { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLineNum, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1691 | "Specify the breakpoint by source location at this particular line."}, |
| 1692 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1693 | { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1694 | }; |
| 1695 | |
| 1696 | //------------------------------------------------------------------------- |
| 1697 | // CommandObjectBreakpointDelete |
| 1698 | //------------------------------------------------------------------------- |
| 1699 | #pragma mark Delete |
| 1700 | |
| 1701 | class CommandObjectBreakpointDelete : public CommandObjectParsed |
| 1702 | { |
| 1703 | public: |
| 1704 | CommandObjectBreakpointDelete (CommandInterpreter &interpreter) : |
| 1705 | CommandObjectParsed (interpreter, |
| 1706 | "breakpoint delete", |
| 1707 | "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.", |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1708 | NULL), |
| 1709 | m_options (interpreter) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1710 | { |
| 1711 | CommandArgumentEntry arg; |
| 1712 | CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange); |
| 1713 | // Add the entry for the first argument for this command to the object's arguments vector. |
| 1714 | m_arguments.push_back (arg); |
| 1715 | } |
| 1716 | |
| 1717 | virtual |
| 1718 | ~CommandObjectBreakpointDelete () {} |
| 1719 | |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1720 | virtual Options * |
| 1721 | GetOptions () |
| 1722 | { |
| 1723 | return &m_options; |
| 1724 | } |
| 1725 | |
| 1726 | class CommandOptions : public Options |
| 1727 | { |
| 1728 | public: |
| 1729 | |
| 1730 | CommandOptions (CommandInterpreter &interpreter) : |
| 1731 | Options (interpreter), |
| 1732 | m_use_dummy (false), |
| 1733 | m_force (false) |
| 1734 | { |
| 1735 | } |
| 1736 | |
| 1737 | virtual |
| 1738 | ~CommandOptions () {} |
| 1739 | |
| 1740 | virtual Error |
| 1741 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 1742 | { |
| 1743 | Error error; |
| 1744 | const int short_option = m_getopt_table[option_idx].val; |
| 1745 | |
| 1746 | switch (short_option) |
| 1747 | { |
| 1748 | case 'f': |
| 1749 | m_force = true; |
| 1750 | break; |
| 1751 | |
| 1752 | case 'D': |
| 1753 | m_use_dummy = true; |
| 1754 | break; |
| 1755 | |
| 1756 | default: |
| 1757 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 1758 | break; |
| 1759 | } |
| 1760 | |
| 1761 | return error; |
| 1762 | } |
| 1763 | |
| 1764 | void |
| 1765 | OptionParsingStarting () |
| 1766 | { |
| 1767 | m_use_dummy = false; |
| 1768 | m_force = false; |
| 1769 | } |
| 1770 | |
| 1771 | const OptionDefinition* |
| 1772 | GetDefinitions () |
| 1773 | { |
| 1774 | return g_option_table; |
| 1775 | } |
| 1776 | |
| 1777 | // Options table: Required for subclasses of Options. |
| 1778 | |
| 1779 | static OptionDefinition g_option_table[]; |
| 1780 | |
| 1781 | // Instance variables to hold the values for command options. |
| 1782 | bool m_use_dummy; |
| 1783 | bool m_force; |
| 1784 | }; |
| 1785 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1786 | protected: |
| 1787 | virtual bool |
| 1788 | DoExecute (Args& command, CommandReturnObject &result) |
| 1789 | { |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1790 | Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); |
| 1791 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1792 | if (target == NULL) |
| 1793 | { |
| 1794 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 1795 | result.SetStatus (eReturnStatusFailed); |
| 1796 | return false; |
| 1797 | } |
| 1798 | |
| 1799 | Mutex::Locker locker; |
| 1800 | target->GetBreakpointList().GetListMutex(locker); |
| 1801 | |
| 1802 | const BreakpointList &breakpoints = target->GetBreakpointList(); |
| 1803 | |
| 1804 | size_t num_breakpoints = breakpoints.GetSize(); |
| 1805 | |
| 1806 | if (num_breakpoints == 0) |
| 1807 | { |
| 1808 | result.AppendError ("No breakpoints exist to be deleted."); |
| 1809 | result.SetStatus (eReturnStatusFailed); |
| 1810 | return false; |
| 1811 | } |
| 1812 | |
| 1813 | if (command.GetArgumentCount() == 0) |
| 1814 | { |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1815 | if (!m_options.m_force && !m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true)) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1816 | { |
| 1817 | result.AppendMessage("Operation cancelled..."); |
| 1818 | } |
| 1819 | else |
| 1820 | { |
| 1821 | target->RemoveAllBreakpoints (); |
Greg Clayton | 6fea17e | 2014-03-03 19:15:20 +0000 | [diff] [blame] | 1822 | result.AppendMessageWithFormat ("All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : ""); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1823 | } |
| 1824 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1825 | } |
| 1826 | else |
| 1827 | { |
| 1828 | // Particular breakpoint selected; disable that breakpoint. |
| 1829 | BreakpointIDList valid_bp_ids; |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 1830 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1831 | |
| 1832 | if (result.Succeeded()) |
| 1833 | { |
| 1834 | int delete_count = 0; |
| 1835 | int disable_count = 0; |
| 1836 | const size_t count = valid_bp_ids.GetSize(); |
| 1837 | for (size_t i = 0; i < count; ++i) |
| 1838 | { |
| 1839 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i); |
| 1840 | |
| 1841 | if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) |
| 1842 | { |
| 1843 | if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) |
| 1844 | { |
| 1845 | Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); |
| 1846 | BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get(); |
| 1847 | // It makes no sense to try to delete individual locations, so we disable them instead. |
| 1848 | if (location) |
| 1849 | { |
| 1850 | location->SetEnabled (false); |
| 1851 | ++disable_count; |
| 1852 | } |
| 1853 | } |
| 1854 | else |
| 1855 | { |
| 1856 | target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID()); |
| 1857 | ++delete_count; |
| 1858 | } |
| 1859 | } |
| 1860 | } |
| 1861 | result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n", |
| 1862 | delete_count, disable_count); |
| 1863 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1864 | } |
| 1865 | } |
| 1866 | return result.Succeeded(); |
| 1867 | } |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1868 | private: |
| 1869 | CommandOptions m_options; |
| 1870 | }; |
| 1871 | |
| 1872 | OptionDefinition |
| 1873 | CommandObjectBreakpointDelete::CommandOptions::g_option_table[] = |
| 1874 | { |
| 1875 | { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, |
| 1876 | "Delete all breakpoints without querying for confirmation."}, |
| 1877 | |
| 1878 | { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, |
| 1879 | "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, |
| 1880 | |
| 1881 | { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1882 | }; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1883 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1884 | //------------------------------------------------------------------------- |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 1885 | // CommandObjectBreakpointName |
| 1886 | //------------------------------------------------------------------------- |
| 1887 | |
| 1888 | static OptionDefinition |
| 1889 | g_breakpoint_name_options[] = |
| 1890 | { |
| 1891 | { LLDB_OPT_SET_1, false, "name", 'N', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."}, |
| 1892 | { LLDB_OPT_SET_2, false, "breakpoint-id", 'B', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointID, "Specify a breakpoint id to use."}, |
| 1893 | { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, |
| 1894 | "Operate on Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, |
| 1895 | }; |
| 1896 | class BreakpointNameOptionGroup : public OptionGroup |
| 1897 | { |
| 1898 | public: |
| 1899 | BreakpointNameOptionGroup() : |
| 1900 | OptionGroup(), |
| 1901 | m_breakpoint(LLDB_INVALID_BREAK_ID), |
| 1902 | m_use_dummy (false) |
| 1903 | { |
| 1904 | |
| 1905 | } |
| 1906 | |
| 1907 | virtual |
| 1908 | ~BreakpointNameOptionGroup () |
| 1909 | { |
| 1910 | } |
| 1911 | |
| 1912 | virtual uint32_t |
| 1913 | GetNumDefinitions () |
| 1914 | { |
| 1915 | return sizeof (g_breakpoint_name_options) / sizeof (OptionDefinition); |
| 1916 | } |
| 1917 | |
| 1918 | virtual const OptionDefinition* |
| 1919 | GetDefinitions () |
| 1920 | { |
| 1921 | return g_breakpoint_name_options; |
| 1922 | } |
| 1923 | |
| 1924 | virtual Error |
| 1925 | SetOptionValue (CommandInterpreter &interpreter, |
| 1926 | uint32_t option_idx, |
| 1927 | const char *option_value) |
| 1928 | { |
| 1929 | Error error; |
| 1930 | const int short_option = g_breakpoint_name_options[option_idx].short_option; |
| 1931 | |
| 1932 | switch (short_option) |
| 1933 | { |
| 1934 | case 'N': |
| 1935 | if (BreakpointID::StringIsBreakpointName(option_value, error) && error.Success()) |
| 1936 | m_name.SetValueFromCString(option_value); |
| 1937 | break; |
| 1938 | |
| 1939 | case 'B': |
| 1940 | if (m_breakpoint.SetValueFromCString(option_value).Fail()) |
| 1941 | error.SetErrorStringWithFormat ("unrecognized value \"%s\" for breakpoint", option_value); |
| 1942 | break; |
| 1943 | case 'D': |
| 1944 | if (m_use_dummy.SetValueFromCString(option_value).Fail()) |
| 1945 | error.SetErrorStringWithFormat ("unrecognized value \"%s\" for use-dummy", option_value); |
| 1946 | break; |
| 1947 | |
| 1948 | default: |
| 1949 | error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option); |
| 1950 | break; |
| 1951 | } |
| 1952 | return error; |
| 1953 | } |
| 1954 | |
| 1955 | virtual void |
| 1956 | OptionParsingStarting (CommandInterpreter &interpreter) |
| 1957 | { |
| 1958 | m_name.Clear(); |
| 1959 | m_breakpoint.Clear(); |
| 1960 | m_use_dummy.Clear(); |
| 1961 | m_use_dummy.SetDefaultValue(false); |
| 1962 | } |
| 1963 | |
| 1964 | OptionValueString m_name; |
| 1965 | OptionValueUInt64 m_breakpoint; |
| 1966 | OptionValueBoolean m_use_dummy; |
| 1967 | }; |
| 1968 | |
| 1969 | |
| 1970 | class CommandObjectBreakpointNameAdd : public CommandObjectParsed |
| 1971 | { |
| 1972 | public: |
| 1973 | CommandObjectBreakpointNameAdd (CommandInterpreter &interpreter) : |
| 1974 | CommandObjectParsed (interpreter, |
| 1975 | "add", |
| 1976 | "Add a name to the breakpoints provided.", |
| 1977 | "breakpoint name add <command-options> <breakpoint-id-list>"), |
| 1978 | m_name_options(), |
| 1979 | m_option_group(interpreter) |
| 1980 | { |
| 1981 | // Create the first variant for the first (and only) argument for this command. |
| 1982 | CommandArgumentEntry arg1; |
| 1983 | CommandArgumentData id_arg; |
| 1984 | id_arg.arg_type = eArgTypeBreakpointID; |
| 1985 | id_arg.arg_repetition = eArgRepeatOptional; |
| 1986 | arg1.push_back(id_arg); |
| 1987 | m_arguments.push_back (arg1); |
| 1988 | |
| 1989 | m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); |
| 1990 | m_option_group.Finalize(); |
| 1991 | } |
| 1992 | |
| 1993 | virtual |
| 1994 | ~CommandObjectBreakpointNameAdd () {} |
| 1995 | |
| 1996 | Options * |
| 1997 | GetOptions () |
| 1998 | { |
| 1999 | return &m_option_group; |
| 2000 | } |
| 2001 | |
| 2002 | protected: |
| 2003 | virtual bool |
| 2004 | DoExecute (Args& command, CommandReturnObject &result) |
| 2005 | { |
| 2006 | if (!m_name_options.m_name.OptionWasSet()) |
| 2007 | { |
| 2008 | result.SetError("No name option provided."); |
| 2009 | return false; |
| 2010 | } |
| 2011 | |
| 2012 | Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); |
| 2013 | |
| 2014 | if (target == NULL) |
| 2015 | { |
| 2016 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 2017 | result.SetStatus (eReturnStatusFailed); |
| 2018 | return false; |
| 2019 | } |
| 2020 | |
| 2021 | Mutex::Locker locker; |
| 2022 | target->GetBreakpointList().GetListMutex(locker); |
| 2023 | |
| 2024 | const BreakpointList &breakpoints = target->GetBreakpointList(); |
| 2025 | |
| 2026 | size_t num_breakpoints = breakpoints.GetSize(); |
| 2027 | if (num_breakpoints == 0) |
| 2028 | { |
| 2029 | result.SetError("No breakpoints, cannot add names."); |
| 2030 | result.SetStatus (eReturnStatusFailed); |
| 2031 | return false; |
| 2032 | } |
| 2033 | |
| 2034 | // Particular breakpoint selected; disable that breakpoint. |
| 2035 | BreakpointIDList valid_bp_ids; |
| 2036 | CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); |
| 2037 | |
| 2038 | if (result.Succeeded()) |
| 2039 | { |
| 2040 | if (valid_bp_ids.GetSize() == 0) |
| 2041 | { |
| 2042 | result.SetError("No breakpoints specified, cannot add names."); |
| 2043 | result.SetStatus (eReturnStatusFailed); |
| 2044 | return false; |
| 2045 | } |
| 2046 | size_t num_valid_ids = valid_bp_ids.GetSize(); |
| 2047 | for (size_t index = 0; index < num_valid_ids; index++) |
| 2048 | { |
| 2049 | lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); |
| 2050 | BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); |
| 2051 | Error error; // We don't need to check the error here, since the option parser checked it... |
| 2052 | bp_sp->AddName(m_name_options.m_name.GetCurrentValue(), error); |
| 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | return true; |
| 2057 | } |
| 2058 | |
| 2059 | private: |
| 2060 | BreakpointNameOptionGroup m_name_options; |
| 2061 | OptionGroupOptions m_option_group; |
| 2062 | }; |
| 2063 | |
| 2064 | |
| 2065 | |
| 2066 | class CommandObjectBreakpointNameDelete : public CommandObjectParsed |
| 2067 | { |
| 2068 | public: |
| 2069 | CommandObjectBreakpointNameDelete (CommandInterpreter &interpreter) : |
| 2070 | CommandObjectParsed (interpreter, |
| 2071 | "delete", |
| 2072 | "Delete a name from the breakpoints provided.", |
| 2073 | "breakpoint name delete <command-options> <breakpoint-id-list>"), |
| 2074 | m_name_options(), |
| 2075 | m_option_group(interpreter) |
| 2076 | { |
| 2077 | // Create the first variant for the first (and only) argument for this command. |
| 2078 | CommandArgumentEntry arg1; |
| 2079 | CommandArgumentData id_arg; |
| 2080 | id_arg.arg_type = eArgTypeBreakpointID; |
| 2081 | id_arg.arg_repetition = eArgRepeatOptional; |
| 2082 | arg1.push_back(id_arg); |
| 2083 | m_arguments.push_back (arg1); |
| 2084 | |
| 2085 | m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); |
| 2086 | m_option_group.Finalize(); |
| 2087 | } |
| 2088 | |
| 2089 | virtual |
| 2090 | ~CommandObjectBreakpointNameDelete () {} |
| 2091 | |
| 2092 | Options * |
| 2093 | GetOptions () |
| 2094 | { |
| 2095 | return &m_option_group; |
| 2096 | } |
| 2097 | |
| 2098 | protected: |
| 2099 | virtual bool |
| 2100 | DoExecute (Args& command, CommandReturnObject &result) |
| 2101 | { |
| 2102 | if (!m_name_options.m_name.OptionWasSet()) |
| 2103 | { |
| 2104 | result.SetError("No name option provided."); |
| 2105 | return false; |
| 2106 | } |
| 2107 | |
| 2108 | Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); |
| 2109 | |
| 2110 | if (target == NULL) |
| 2111 | { |
| 2112 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 2113 | result.SetStatus (eReturnStatusFailed); |
| 2114 | return false; |
| 2115 | } |
| 2116 | |
| 2117 | Mutex::Locker locker; |
| 2118 | target->GetBreakpointList().GetListMutex(locker); |
| 2119 | |
| 2120 | const BreakpointList &breakpoints = target->GetBreakpointList(); |
| 2121 | |
| 2122 | size_t num_breakpoints = breakpoints.GetSize(); |
| 2123 | if (num_breakpoints == 0) |
| 2124 | { |
| 2125 | result.SetError("No breakpoints, cannot delete names."); |
| 2126 | result.SetStatus (eReturnStatusFailed); |
| 2127 | return false; |
| 2128 | } |
| 2129 | |
| 2130 | // Particular breakpoint selected; disable that breakpoint. |
| 2131 | BreakpointIDList valid_bp_ids; |
| 2132 | CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); |
| 2133 | |
| 2134 | if (result.Succeeded()) |
| 2135 | { |
| 2136 | if (valid_bp_ids.GetSize() == 0) |
| 2137 | { |
| 2138 | result.SetError("No breakpoints specified, cannot delete names."); |
| 2139 | result.SetStatus (eReturnStatusFailed); |
| 2140 | return false; |
| 2141 | } |
| 2142 | size_t num_valid_ids = valid_bp_ids.GetSize(); |
| 2143 | for (size_t index = 0; index < num_valid_ids; index++) |
| 2144 | { |
| 2145 | lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); |
| 2146 | BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); |
| 2147 | bp_sp->RemoveName(m_name_options.m_name.GetCurrentValue()); |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | return true; |
| 2152 | } |
| 2153 | |
| 2154 | private: |
| 2155 | BreakpointNameOptionGroup m_name_options; |
| 2156 | OptionGroupOptions m_option_group; |
| 2157 | }; |
| 2158 | |
| 2159 | class CommandObjectBreakpointNameList : public CommandObjectParsed |
| 2160 | { |
| 2161 | public: |
| 2162 | CommandObjectBreakpointNameList (CommandInterpreter &interpreter) : |
| 2163 | CommandObjectParsed (interpreter, |
| 2164 | "list", |
| 2165 | "List either the names for a breakpoint or the breakpoints for a given name.", |
| 2166 | "breakpoint name list <command-options>"), |
| 2167 | m_name_options(), |
| 2168 | m_option_group(interpreter) |
| 2169 | { |
| 2170 | m_option_group.Append (&m_name_options); |
| 2171 | m_option_group.Finalize(); |
| 2172 | } |
| 2173 | |
| 2174 | virtual |
| 2175 | ~CommandObjectBreakpointNameList () {} |
| 2176 | |
| 2177 | Options * |
| 2178 | GetOptions () |
| 2179 | { |
| 2180 | return &m_option_group; |
| 2181 | } |
| 2182 | |
| 2183 | protected: |
| 2184 | protected: |
| 2185 | virtual bool |
| 2186 | DoExecute (Args& command, CommandReturnObject &result) |
| 2187 | { |
| 2188 | Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); |
| 2189 | |
| 2190 | if (target == NULL) |
| 2191 | { |
| 2192 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 2193 | result.SetStatus (eReturnStatusFailed); |
| 2194 | return false; |
| 2195 | } |
| 2196 | |
| 2197 | if (m_name_options.m_name.OptionWasSet()) |
| 2198 | { |
| 2199 | const char *name = m_name_options.m_name.GetCurrentValue(); |
| 2200 | Mutex::Locker locker; |
| 2201 | target->GetBreakpointList().GetListMutex(locker); |
| 2202 | |
| 2203 | BreakpointList &breakpoints = target->GetBreakpointList(); |
| 2204 | for (BreakpointSP bp_sp : breakpoints.Breakpoints()) |
| 2205 | { |
| 2206 | if (bp_sp->MatchesName(name)) |
| 2207 | { |
| 2208 | StreamString s; |
| 2209 | bp_sp->GetDescription(&s, eDescriptionLevelBrief); |
| 2210 | s.EOL(); |
| 2211 | result.AppendMessage(s.GetData()); |
| 2212 | } |
| 2213 | } |
| 2214 | |
| 2215 | } |
| 2216 | else if (m_name_options.m_breakpoint.OptionWasSet()) |
| 2217 | { |
| 2218 | BreakpointSP bp_sp = target->GetBreakpointList().FindBreakpointByID(m_name_options.m_breakpoint.GetCurrentValue()); |
| 2219 | if (bp_sp) |
| 2220 | { |
| 2221 | std::vector<std::string> names; |
| 2222 | bp_sp->GetNames (names); |
| 2223 | result.AppendMessage ("Names:"); |
| 2224 | for (auto name : names) |
| 2225 | result.AppendMessageWithFormat (" %s\n", name.c_str()); |
| 2226 | } |
| 2227 | else |
| 2228 | { |
| 2229 | result.AppendErrorWithFormat ("Could not find breakpoint %" PRId64 ".\n", |
| 2230 | m_name_options.m_breakpoint.GetCurrentValue()); |
| 2231 | result.SetStatus (eReturnStatusFailed); |
| 2232 | return false; |
| 2233 | } |
| 2234 | } |
| 2235 | else |
| 2236 | { |
| 2237 | result.SetError ("Must specify -N or -B option to list."); |
| 2238 | result.SetStatus (eReturnStatusFailed); |
| 2239 | return false; |
| 2240 | } |
| 2241 | return true; |
| 2242 | } |
| 2243 | |
| 2244 | private: |
| 2245 | BreakpointNameOptionGroup m_name_options; |
| 2246 | OptionGroupOptions m_option_group; |
| 2247 | }; |
| 2248 | |
| 2249 | //------------------------------------------------------------------------- |
| 2250 | // CommandObjectMultiwordBreakpoint |
| 2251 | //------------------------------------------------------------------------- |
| 2252 | class CommandObjectBreakpointName : public CommandObjectMultiword |
| 2253 | { |
| 2254 | public: |
| 2255 | CommandObjectBreakpointName (CommandInterpreter &interpreter) : |
| 2256 | CommandObjectMultiword(interpreter, |
| 2257 | "name", |
| 2258 | "A set of commands to manage name tags for breakpoints", |
| 2259 | "breakpoint name <command> [<command-options>]") |
| 2260 | { |
| 2261 | CommandObjectSP add_command_object (new CommandObjectBreakpointNameAdd (interpreter)); |
| 2262 | CommandObjectSP delete_command_object (new CommandObjectBreakpointNameDelete (interpreter)); |
| 2263 | CommandObjectSP list_command_object (new CommandObjectBreakpointNameList (interpreter)); |
| 2264 | |
| 2265 | LoadSubCommand ("add", add_command_object); |
| 2266 | LoadSubCommand ("delete", delete_command_object); |
| 2267 | LoadSubCommand ("list", list_command_object); |
| 2268 | |
| 2269 | } |
| 2270 | |
| 2271 | virtual |
| 2272 | ~CommandObjectBreakpointName () |
| 2273 | { |
| 2274 | } |
| 2275 | |
| 2276 | }; |
| 2277 | |
| 2278 | |
| 2279 | //------------------------------------------------------------------------- |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2280 | // CommandObjectMultiwordBreakpoint |
| 2281 | //------------------------------------------------------------------------- |
Jim Ingham | ae1c4cf | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 2282 | #pragma mark MultiwordBreakpoint |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2283 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 2284 | CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) : |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2285 | CommandObjectMultiword (interpreter, |
| 2286 | "breakpoint", |
Jim Ingham | 46fbc60 | 2011-05-26 20:39:01 +0000 | [diff] [blame] | 2287 | "A set of commands for operating on breakpoints. Also see _regexp-break.", |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2288 | "breakpoint <command> [<command-options>]") |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2289 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2290 | CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter)); |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2291 | CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter)); |
| 2292 | CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter)); |
Johnny Chen | b7234e4 | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 2293 | CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter)); |
| 2294 | CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter)); |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2295 | CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2296 | CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter)); |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2297 | CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter)); |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 2298 | CommandObjectSP name_command_object (new CommandObjectBreakpointName(interpreter)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2299 | |
Johnny Chen | b7234e4 | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 2300 | list_command_object->SetCommandName ("breakpoint list"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2301 | enable_command_object->SetCommandName("breakpoint enable"); |
| 2302 | disable_command_object->SetCommandName("breakpoint disable"); |
Johnny Chen | b7234e4 | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 2303 | clear_command_object->SetCommandName("breakpoint clear"); |
| 2304 | delete_command_object->SetCommandName("breakpoint delete"); |
Jim Ingham | ae1c4cf | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 2305 | set_command_object->SetCommandName("breakpoint set"); |
Johnny Chen | b7234e4 | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 2306 | command_command_object->SetCommandName ("breakpoint command"); |
| 2307 | modify_command_object->SetCommandName ("breakpoint modify"); |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 2308 | name_command_object->SetCommandName ("breakpoint name"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2309 | |
Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 2310 | LoadSubCommand ("list", list_command_object); |
| 2311 | LoadSubCommand ("enable", enable_command_object); |
| 2312 | LoadSubCommand ("disable", disable_command_object); |
| 2313 | LoadSubCommand ("clear", clear_command_object); |
| 2314 | LoadSubCommand ("delete", delete_command_object); |
| 2315 | LoadSubCommand ("set", set_command_object); |
| 2316 | LoadSubCommand ("command", command_command_object); |
| 2317 | LoadSubCommand ("modify", modify_command_object); |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 2318 | LoadSubCommand ("name", name_command_object); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint () |
| 2322 | { |
| 2323 | } |
| 2324 | |
| 2325 | void |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 2326 | CommandObjectMultiwordBreakpoint::VerifyIDs (Args &args, |
| 2327 | Target *target, |
| 2328 | bool allow_locations, |
| 2329 | CommandReturnObject &result, |
| 2330 | BreakpointIDList *valid_ids) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2331 | { |
| 2332 | // args can be strings representing 1). integers (for breakpoint ids) |
| 2333 | // 2). the full breakpoint & location canonical representation |
| 2334 | // 3). the word "to" or a hyphen, representing a range (in which case there |
| 2335 | // had *better* be an entry both before & after of one of the first two types. |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 2336 | // 4). A breakpoint name |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 2337 | // If args is empty, we will use the last created breakpoint (if there is one.) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2338 | |
| 2339 | Args temp_args; |
| 2340 | |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 2341 | if (args.GetArgumentCount() == 0) |
| 2342 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 2343 | if (target->GetLastCreatedBreakpoint()) |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 2344 | { |
| 2345 | valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); |
| 2346 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 2347 | } |
| 2348 | else |
| 2349 | { |
| 2350 | result.AppendError("No breakpoint specified and no last created breakpoint."); |
| 2351 | result.SetStatus (eReturnStatusFailed); |
| 2352 | } |
| 2353 | return; |
| 2354 | } |
| 2355 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2356 | // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to |
| 2357 | // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for |
| 2358 | // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS. |
| 2359 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame^] | 2360 | BreakpointIDList::FindAndReplaceIDRanges (args, target, allow_locations, result, temp_args); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2361 | |
| 2362 | // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList: |
| 2363 | |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 2364 | valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2365 | |
| 2366 | // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs |
| 2367 | // and put into valid_ids. |
| 2368 | |
| 2369 | if (result.Succeeded()) |
| 2370 | { |
| 2371 | // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list |
| 2372 | // of breakpoint id's and verify that they correspond to valid/currently set breakpoints. |
| 2373 | |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 2374 | const size_t count = valid_ids->GetSize(); |
| 2375 | for (size_t i = 0; i < count; ++i) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2376 | { |
| 2377 | BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i); |
| 2378 | Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); |
| 2379 | if (breakpoint != NULL) |
| 2380 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2381 | const size_t num_locations = breakpoint->GetNumLocations(); |
Saleem Abdulrasool | 3985c8c | 2014-04-02 03:51:35 +0000 | [diff] [blame] | 2382 | if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2383 | { |
| 2384 | StreamString id_str; |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 2385 | BreakpointID::GetCanonicalReference (&id_str, |
| 2386 | cur_bp_id.GetBreakpointID(), |
| 2387 | cur_bp_id.GetLocationID()); |
| 2388 | i = valid_ids->GetSize() + 1; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2389 | result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n", |
| 2390 | id_str.GetData()); |
| 2391 | result.SetStatus (eReturnStatusFailed); |
| 2392 | } |
| 2393 | } |
| 2394 | else |
| 2395 | { |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 2396 | i = valid_ids->GetSize() + 1; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2397 | result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID()); |
| 2398 | result.SetStatus (eReturnStatusFailed); |
| 2399 | } |
| 2400 | } |
| 2401 | } |
| 2402 | } |