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