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