blob: 682e26bbbb4ae1aba88d6d7cfda11901a50f9f23 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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 Lattner30fdc8d2010-06-08 16:52:24 +000010// C Includes
11// C++ Includes
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +000012#include <vector>
13
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014// Other libraries and framework includes
15// Project includes
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +000016#include "CommandObjectBreakpoint.h"
17#include "CommandObjectBreakpointCommand.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/Breakpoint/Breakpoint.h"
19#include "lldb/Breakpoint/BreakpointIDList.h"
20#include "lldb/Breakpoint/BreakpointLocation.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000021#include "lldb/Core/RegularExpression.h"
22#include "lldb/Core/StreamString.h"
Vince Harron5275aaa2015-01-15 20:08:35 +000023#include "lldb/Host/StringConvert.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000024#include "lldb/Interpreter/CommandCompletions.h"
25#include "lldb/Interpreter/CommandInterpreter.h"
26#include "lldb/Interpreter/CommandReturnObject.h"
Zachary Turner32abc6e2015-03-03 19:23:09 +000027#include "lldb/Interpreter/OptionValueBoolean.h"
Jim Ingham5e09c8c2014-12-16 23:40:14 +000028#include "lldb/Interpreter/OptionValueString.h"
29#include "lldb/Interpreter/OptionValueUInt64.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000030#include "lldb/Interpreter/Options.h"
Jim Ingham0e0984e2015-09-02 01:06:46 +000031#include "lldb/Target/Language.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000032#include "lldb/Target/StackFrame.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000033#include "lldb/Target/Target.h"
Jim Ingham1b54c882010-06-16 02:00:15 +000034#include "lldb/Target/Thread.h"
35#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036
37using namespace lldb;
38using namespace lldb_private;
39
Kate Stoneb9c1b512016-09-06 20:57:50 +000040static 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 Lattner30fdc8d2010-06-08 16:52:24 +000046}
47
48//-------------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +000049// CommandObjectBreakpointSet
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050//-------------------------------------------------------------------------
51
Kate Stoneb9c1b512016-09-06 20:57:50 +000052class CommandObjectBreakpointSet : public CommandObjectParsed {
Jim Ingham5a988412012-06-08 21:56:10 +000053public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000054 typedef enum BreakpointSetType {
55 eSetTypeInvalid,
56 eSetTypeFileAndLine,
57 eSetTypeAddress,
58 eSetTypeFunctionName,
59 eSetTypeFunctionRegexp,
60 eSetTypeSourceRegexp,
61 eSetTypeException
62 } BreakpointSetType;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 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 Turner6fa7681b2016-09-17 02:00:02 +000095 llvm::StringRef option_strref(option_arg ? option_arg : "");
Kate Stoneb9c1b512016-09-06 20:57:50 +000096
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 Turner6fa7681b2016-09-17 02:00:02 +0000249 case 'N': {
250 if (BreakpointID::StringIsBreakpointName(option_strref, error))
Kate Stoneb9c1b512016-09-06 20:57:50 +0000251 m_breakpoint_names.push_back(option_arg);
252 break;
Zachary Turner6fa7681b2016-09-17 02:00:02 +0000253 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000254
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 Ingham5a988412012-06-08 21:56:10 +0000331 }
332
Kate Stoneb9c1b512016-09-06 20:57:50 +0000333 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 Ingham5a988412012-06-08 21:56:10 +0000363 }
364
Kate Stoneb9c1b512016-09-06 20:57:50 +0000365 const OptionDefinition *GetDefinitions() override { return g_option_table; }
Jim Ingham5a988412012-06-08 21:56:10 +0000366
Kate Stoneb9c1b512016-09-06 20:57:50 +0000367 // Options table: Required for subclasses of Options.
Jim Ingham5a988412012-06-08 21:56:10 +0000368
Kate Stoneb9c1b512016-09-06 20:57:50 +0000369 static OptionDefinition g_option_table[];
Jim Ingham5a988412012-06-08 21:56:10 +0000370
Kate Stoneb9c1b512016-09-06 20:57:50 +0000371 // Instance variables to hold the values for command options.
Jim Ingham5a988412012-06-08 21:56:10 +0000372
Kate Stoneb9c1b512016-09-06 20:57:50 +0000373 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 Ingham5a988412012-06-08 21:56:10 +0000403
404protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000405 bool DoExecute(Args &command, CommandReturnObject &result) override {
406 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
Jim Ingham33df7cd2014-12-06 01:28:03 +0000407
Kate Stoneb9c1b512016-09-06 20:57:50 +0000408 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 Ingham5a988412012-06-08 21:56:10 +0000413 }
414
Kate Stoneb9c1b512016-09-06 20:57:50 +0000415 // 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 Inghame14dc262016-09-12 23:10:56 +0000528 {
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 Stoneb9c1b512016-09-06 20:57:50 +0000539
Jim Inghame14dc262016-09-12 23:10:56 +0000540 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 Stoneb9c1b512016-09-06 20:57:50 +0000548 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 Ingham5a988412012-06-08 21:56:10 +0000661private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000662 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 Ingham5a988412012-06-08 21:56:10 +0000689 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000690 }
Jim Ingham5a988412012-06-08 21:56:10 +0000691 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000692 return true;
693 }
694
695 CommandOptions m_options;
Jim Ingham5a988412012-06-08 21:56:10 +0000696};
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000697
Johnny Chen6943e7c2012-05-08 00:43:20 +0000698// 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 Stoneb9c1b512016-09-06 20:57:50 +0000700#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 Ingham87df91b2011-09-23 00:54:11 +0000706
Kate Stoneb9c1b512016-09-06 20:57:50 +0000707OptionDefinition CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
708 {
709 // clang-format off
Kate Stoneac9c3a62016-08-26 23:28:47 +0000710 {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 Lattner30fdc8d2010-06-08 16:52:24 +0000727
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000728 // 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 Zelenko9e85e5a2016-02-18 22:39:14 +0000730 // { 0, false, "column", 'C', OptionParser::eRequiredArgument, nullptr, "<column>",
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000731 // "Set the breakpoint by source location at this particular column."},
732
Kate Stoneac9c3a62016-08-26 23:28:47 +0000733 {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 Ingham969795f2011-09-21 01:17:13 +0000769
Jim Inghama72b31c2015-04-22 19:42:18 +0000770// Don't add this option till it actually does something useful...
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000771// { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName,
Jim Inghama72b31c2015-04-22 19:42:18 +0000772// "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 Stoneac9c3a62016-08-26 23:28:47 +0000774 {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 Ingham24111672016-03-09 18:59:13 +0000783 "At present this applies the offset directly as given, and doesn't try to align it to instruction boundaries."},
Kate Stoneac9c3a62016-08-26 23:28:47 +0000784 {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 Stoneb9c1b512016-09-06 20:57:50 +0000787 // clang-format on
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000788};
789
Jim Ingham5a988412012-06-08 21:56:10 +0000790//-------------------------------------------------------------------------
791// CommandObjectBreakpointModify
792//-------------------------------------------------------------------------
793#pragma mark Modify
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000794
Kate Stoneb9c1b512016-09-06 20:57:50 +0000795class CommandObjectBreakpointModify : public CommandObjectParsed {
Jim Ingham5a988412012-06-08 21:56:10 +0000796public:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000797 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 Zelenko9e85e5a2016-02-18 22:39:14 +0000805 nullptr),
Kate Stoneb9c1b512016-09-06 20:57:50 +0000806 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 Ingham5a988412012-06-08 21:56:10 +0000920 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000921
Kate Stoneb9c1b512016-09-06 20:57:50 +0000922 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 Ingham5a988412012-06-08 21:56:10 +0000938 }
Johnny Chen7d49c9c2012-05-25 21:10:46 +0000939
Kate Stoneb9c1b512016-09-06 20:57:50 +0000940 const OptionDefinition *GetDefinitions() override { return g_option_table; }
Greg Clayton0c5cd902010-06-28 21:30:43 +0000941
Kate Stoneb9c1b512016-09-06 20:57:50 +0000942 // Options table: Required for subclasses of Options.
Greg Clayton0c5cd902010-06-28 21:30:43 +0000943
Kate Stoneb9c1b512016-09-06 20:57:50 +0000944 static OptionDefinition g_option_table[];
Greg Claytone02b8502010-10-12 04:29:14 +0000945
Kate Stoneb9c1b512016-09-06 20:57:50 +0000946 // Instance variables to hold the values for command options.
Jim Ingham5a988412012-06-08 21:56:10 +0000947
Kate Stoneb9c1b512016-09-06 20:57:50 +0000948 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 Ingham5a988412012-06-08 21:56:10 +0000965
966protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000967 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 Lattner30fdc8d2010-06-08 16:52:24 +0000973 }
974
Kate Stoneb9c1b512016-09-06 20:57:50 +0000975 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 Ingham5a988412012-06-08 21:56:10 +00001045private:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001046 CommandOptions m_options;
Jim Ingham5a988412012-06-08 21:56:10 +00001047};
Johnny Chen7d49c9c2012-05-25 21:10:46 +00001048
Jim Ingham5a988412012-06-08 21:56:10 +00001049#pragma mark Modify::CommandOptions
1050OptionDefinition
Kate Stoneb9c1b512016-09-06 20:57:50 +00001051 CommandObjectBreakpointModify::CommandOptions::g_option_table[] = {
1052 // clang-format off
Kate Stoneac9c3a62016-08-26 23:28:47 +00001053 {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 Stoneb9c1b512016-09-06 20:57:50 +00001064 // clang-format on
Jim Ingham5a988412012-06-08 21:56:10 +00001065};
1066
1067//-------------------------------------------------------------------------
1068// CommandObjectBreakpointEnable
1069//-------------------------------------------------------------------------
1070#pragma mark Enable
1071
Kate Stoneb9c1b512016-09-06 20:57:50 +00001072class CommandObjectBreakpointEnable : public CommandObjectParsed {
Jim Ingham5a988412012-06-08 21:56:10 +00001073public:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001074 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 Ingham5a988412012-06-08 21:56:10 +00001086
Kate Stoneb9c1b512016-09-06 20:57:50 +00001087 ~CommandObjectBreakpointEnable() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +00001088
1089protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001090 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 Ingham5a988412012-06-08 21:56:10 +00001096 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001097
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 Ingham5a988412012-06-08 21:56:10 +00001155};
1156
1157//-------------------------------------------------------------------------
1158// CommandObjectBreakpointDisable
1159//-------------------------------------------------------------------------
1160#pragma mark Disable
1161
Kate Stoneb9c1b512016-09-06 20:57:50 +00001162class CommandObjectBreakpointDisable : public CommandObjectParsed {
Jim Ingham5a988412012-06-08 21:56:10 +00001163public:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001164 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 Stone7428a182016-07-14 22:03:10 +00001173If none are specified, disable all breakpoints."
Kate Stoneb9c1b512016-09-06 20:57:50 +00001174 R"(
Kate Stoneea671fb2015-07-14 05:48:36 +00001175
Kate Stone7428a182016-07-14 22:03:10 +00001176)"
Kate Stoneb9c1b512016-09-06 20:57:50 +00001177 "Note: disabling a breakpoint will cause none of its locations to be hit \
Kate Stone7428a182016-07-14 22:03:10 +00001178regardless of whether individual locations are enabled or disabled. After the sequence:"
Kate Stoneb9c1b512016-09-06 20:57:50 +00001179 R"(
Kate Stoneea671fb2015-07-14 05:48:36 +00001180
1181 (lldb) break disable 1
1182 (lldb) break enable 1.1
1183
1184execution 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 Stone7428a182016-07-14 22:03:10 +00001189)"
Kate Stoneb9c1b512016-09-06 20:57:50 +00001190 "The first command disables all locations for breakpoint 1, \
Kate Stone7428a182016-07-14 22:03:10 +00001191the second re-enables the first location.");
1192
Kate Stoneb9c1b512016-09-06 20:57:50 +00001193 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 Ingham5a988412012-06-08 21:56:10 +00001200
Kate Stoneb9c1b512016-09-06 20:57:50 +00001201 ~CommandObjectBreakpointDisable() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +00001202
1203protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001204 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 Ingham5a988412012-06-08 21:56:10 +00001210 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001211
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 Ingham5a988412012-06-08 21:56:10 +00001269};
1270
1271//-------------------------------------------------------------------------
1272// CommandObjectBreakpointList
1273//-------------------------------------------------------------------------
1274#pragma mark List
1275
Kate Stoneb9c1b512016-09-06 20:57:50 +00001276class CommandObjectBreakpointList : public CommandObjectParsed {
Jim Ingham5a988412012-06-08 21:56:10 +00001277public:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001278 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 Ingham5a988412012-06-08 21:56:10 +00001286
Kate Stoneb9c1b512016-09-06 20:57:50 +00001287 // Define the first (and only) variant of this arg.
1288 bp_id_arg.arg_type = eArgTypeBreakpointID;
1289 bp_id_arg.arg_repetition = eArgRepeatOptional;
Jim Ingham5a988412012-06-08 21:56:10 +00001290
Kate Stoneb9c1b512016-09-06 20:57:50 +00001291 // There is only one variant this argument could be; put it into the
1292 // argument entry.
1293 arg.push_back(bp_id_arg);
Jim Ingham5a988412012-06-08 21:56:10 +00001294
Kate Stoneb9c1b512016-09-06 20:57:50 +00001295 // 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 Ingham5a988412012-06-08 21:56:10 +00001307 }
1308
Kate Stoneb9c1b512016-09-06 20:57:50 +00001309 ~CommandOptions() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +00001310
Kate Stoneb9c1b512016-09-06 20:57:50 +00001311 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 Ingham1b54c882010-06-16 02:00:15 +00001339 }
Jim Ingham5a988412012-06-08 21:56:10 +00001340
Kate Stoneb9c1b512016-09-06 20:57:50 +00001341 void OptionParsingStarting(ExecutionContext *execution_context) override {
1342 m_level = lldb::eDescriptionLevelFull;
1343 m_internal = false;
1344 m_use_dummy = false;
1345 }
Jim Ingham5a988412012-06-08 21:56:10 +00001346
Kate Stoneb9c1b512016-09-06 20:57:50 +00001347 const OptionDefinition *GetDefinitions() override { return g_option_table; }
Jim Ingham5a988412012-06-08 21:56:10 +00001348
Kate Stoneb9c1b512016-09-06 20:57:50 +00001349 // Options table: Required for subclasses of Options.
Jim Ingham5a988412012-06-08 21:56:10 +00001350
Kate Stoneb9c1b512016-09-06 20:57:50 +00001351 static OptionDefinition g_option_table[];
Jim Ingham5a988412012-06-08 21:56:10 +00001352
Kate Stoneb9c1b512016-09-06 20:57:50 +00001353 // Instance variables to hold the values for command options.
Jim Ingham5a988412012-06-08 21:56:10 +00001354
Kate Stoneb9c1b512016-09-06 20:57:50 +00001355 lldb::DescriptionLevel m_level;
Jim Ingham5a988412012-06-08 21:56:10 +00001356
Kate Stoneb9c1b512016-09-06 20:57:50 +00001357 bool m_internal;
1358 bool m_use_dummy;
1359 };
Jim Ingham5a988412012-06-08 21:56:10 +00001360
1361protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001362 bool DoExecute(Args &command, CommandReturnObject &result) override {
1363 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
Jim Ingham33df7cd2014-12-06 01:28:03 +00001364
Kate Stoneb9c1b512016-09-06 20:57:50 +00001365 if (target == nullptr) {
1366 result.AppendError("Invalid target. No current target or breakpoints.");
1367 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1368 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001369 }
1370
Kate Stoneb9c1b512016-09-06 20:57:50 +00001371 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 Ingham5a988412012-06-08 21:56:10 +00001418private:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001419 CommandOptions m_options;
Jim Ingham5a988412012-06-08 21:56:10 +00001420};
1421
1422#pragma mark List::CommandOptions
Kate Stoneb9c1b512016-09-06 20:57:50 +00001423OptionDefinition CommandObjectBreakpointList::CommandOptions::g_option_table[] =
1424 {
1425 // clang-format off
Kate Stoneac9c3a62016-08-26 23:28:47 +00001426 {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 Ingham5a988412012-06-08 21:56:10 +00001428 // 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 Stoneac9c3a62016-08-26 23:28:47 +00001430 {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 Stoneb9c1b512016-09-06 20:57:50 +00001434 // clang-format on
Jim Ingham5a988412012-06-08 21:56:10 +00001435};
1436
1437//-------------------------------------------------------------------------
1438// CommandObjectBreakpointClear
1439//-------------------------------------------------------------------------
1440#pragma mark Clear
1441
Kate Stoneb9c1b512016-09-06 20:57:50 +00001442class CommandObjectBreakpointClear : public CommandObjectParsed {
Jim Ingham5a988412012-06-08 21:56:10 +00001443public:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001444 typedef enum BreakpointClearType {
1445 eClearTypeInvalid,
1446 eClearTypeFileAndLine
1447 } BreakpointClearType;
Jim Ingham5a988412012-06-08 21:56:10 +00001448
Kate Stoneb9c1b512016-09-06 20:57:50 +00001449 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 Ingham5a988412012-06-08 21:56:10 +00001487 }
1488
Kate Stoneb9c1b512016-09-06 20:57:50 +00001489 void OptionParsingStarting(ExecutionContext *execution_context) override {
1490 m_filename.clear();
1491 m_line_num = 0;
Jim Ingham5a988412012-06-08 21:56:10 +00001492 }
1493
Kate Stoneb9c1b512016-09-06 20:57:50 +00001494 const OptionDefinition *GetDefinitions() override { return g_option_table; }
Jim Ingham5a988412012-06-08 21:56:10 +00001495
Kate Stoneb9c1b512016-09-06 20:57:50 +00001496 // Options table: Required for subclasses of Options.
Jim Ingham5a988412012-06-08 21:56:10 +00001497
Kate Stoneb9c1b512016-09-06 20:57:50 +00001498 static OptionDefinition g_option_table[];
Jim Ingham5a988412012-06-08 21:56:10 +00001499
Kate Stoneb9c1b512016-09-06 20:57:50 +00001500 // Instance variables to hold the values for command options.
Jim Ingham5a988412012-06-08 21:56:10 +00001501
Kate Stoneb9c1b512016-09-06 20:57:50 +00001502 std::string m_filename;
1503 uint32_t m_line_num;
1504 };
Jim Ingham5a988412012-06-08 21:56:10 +00001505
1506protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001507 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 Ingham5a988412012-06-08 21:56:10 +00001513 }
1514
Kate Stoneb9c1b512016-09-06 20:57:50 +00001515 // 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 Ingham5a988412012-06-08 21:56:10 +00001585private:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001586 CommandOptions m_options;
Jim Ingham5a988412012-06-08 21:56:10 +00001587};
1588
1589#pragma mark Clear::CommandOptions
1590
1591OptionDefinition
Kate Stoneb9c1b512016-09-06 20:57:50 +00001592 CommandObjectBreakpointClear::CommandOptions::g_option_table[] = {
1593 // clang-format off
Kate Stoneac9c3a62016-08-26 23:28:47 +00001594 {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 Stoneb9c1b512016-09-06 20:57:50 +00001597 // clang-format on
Jim Ingham5a988412012-06-08 21:56:10 +00001598};
1599
1600//-------------------------------------------------------------------------
1601// CommandObjectBreakpointDelete
1602//-------------------------------------------------------------------------
1603#pragma mark Delete
1604
Kate Stoneb9c1b512016-09-06 20:57:50 +00001605class CommandObjectBreakpointDelete : public CommandObjectParsed {
Jim Ingham5a988412012-06-08 21:56:10 +00001606public:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001607 CommandObjectBreakpointDelete(CommandInterpreter &interpreter)
1608 : CommandObjectParsed(interpreter, "breakpoint delete",
1609 "Delete the specified breakpoint(s). If no "
1610 "breakpoints are specified, delete them all.",
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001611 nullptr),
Kate Stoneb9c1b512016-09-06 20:57:50 +00001612 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 Ingham5a988412012-06-08 21:56:10 +00001652 }
1653
Kate Stoneb9c1b512016-09-06 20:57:50 +00001654 void OptionParsingStarting(ExecutionContext *execution_context) override {
1655 m_use_dummy = false;
1656 m_force = false;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001657 }
1658
Kate Stoneb9c1b512016-09-06 20:57:50 +00001659 const OptionDefinition *GetDefinitions() override { return g_option_table; }
Jim Ingham33df7cd2014-12-06 01:28:03 +00001660
Kate Stoneb9c1b512016-09-06 20:57:50 +00001661 // Options table: Required for subclasses of Options.
Jim Ingham33df7cd2014-12-06 01:28:03 +00001662
Kate Stoneb9c1b512016-09-06 20:57:50 +00001663 static OptionDefinition g_option_table[];
Jim Ingham33df7cd2014-12-06 01:28:03 +00001664
Kate Stoneb9c1b512016-09-06 20:57:50 +00001665 // Instance variables to hold the values for command options.
1666 bool m_use_dummy;
1667 bool m_force;
1668 };
Jim Ingham33df7cd2014-12-06 01:28:03 +00001669
Jim Ingham5a988412012-06-08 21:56:10 +00001670protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001671 bool DoExecute(Args &command, CommandReturnObject &result) override {
1672 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
Jim Ingham33df7cd2014-12-06 01:28:03 +00001673
Kate Stoneb9c1b512016-09-06 20:57:50 +00001674 if (target == nullptr) {
1675 result.AppendError("Invalid target. No existing target or breakpoints.");
1676 result.SetStatus(eReturnStatusFailed);
1677 return false;
Jim Ingham5a988412012-06-08 21:56:10 +00001678 }
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001679
Kate Stoneb9c1b512016-09-06 20:57:50 +00001680 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 Ingham33df7cd2014-12-06 01:28:03 +00001746private:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001747 CommandOptions m_options;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001748};
1749
1750OptionDefinition
Kate Stoneb9c1b512016-09-06 20:57:50 +00001751 CommandObjectBreakpointDelete::CommandOptions::g_option_table[] = {
1752 // clang-format off
Kate Stoneac9c3a62016-08-26 23:28:47 +00001753 {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 Stoneb9c1b512016-09-06 20:57:50 +00001756 // clang-format on
Jim Ingham5a988412012-06-08 21:56:10 +00001757};
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001758
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001759//-------------------------------------------------------------------------
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001760// CommandObjectBreakpointName
1761//-------------------------------------------------------------------------
1762
Kate Stone7428a182016-07-14 22:03:10 +00001763static OptionDefinition g_breakpoint_name_options[] = {
Kate Stoneb9c1b512016-09-06 20:57:50 +00001764 // clang-format off
Kate Stoneac9c3a62016-08-26 23:28:47 +00001765 {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 Stoneb9c1b512016-09-06 20:57:50 +00001768 // clang-format on
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001769};
Kate Stoneb9c1b512016-09-06 20:57:50 +00001770class BreakpointNameOptionGroup : public OptionGroup {
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001771public:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001772 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 Turner6fa7681b2016-09-17 02:00:02 +00001790 llvm::StringRef option_strref(option_value ? option_value : "");
Kate Stoneb9c1b512016-09-06 20:57:50 +00001791
1792 switch (short_option) {
1793 case 'N':
Zachary Turner6fa7681b2016-09-17 02:00:02 +00001794 if (BreakpointID::StringIsBreakpointName(option_strref, error) &&
Kate Stoneb9c1b512016-09-06 20:57:50 +00001795 error.Success())
Zachary Turner6fa7681b2016-09-17 02:00:02 +00001796 m_name.SetValueFromString(option_strref);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001797 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 Ingham5e09c8c2014-12-16 23:40:14 +00001814 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001815 return error;
1816 }
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001817
Kate Stoneb9c1b512016-09-06 20:57:50 +00001818 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 Zelenko9e85e5a2016-02-18 22:39:14 +00001824
Kate Stoneb9c1b512016-09-06 20:57:50 +00001825 OptionValueString m_name;
1826 OptionValueUInt64 m_breakpoint;
1827 OptionValueBoolean m_use_dummy;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001828};
1829
Kate Stoneb9c1b512016-09-06 20:57:50 +00001830class CommandObjectBreakpointNameAdd : public CommandObjectParsed {
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001831public:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001832 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 Ingham5e09c8c2014-12-16 23:40:14 +00001845
Kate Stoneb9c1b512016-09-06 20:57:50 +00001846 m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
1847 m_option_group.Finalize();
1848 }
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001849
Kate Stoneb9c1b512016-09-06 20:57:50 +00001850 ~CommandObjectBreakpointNameAdd() override = default;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001851
Kate Stoneb9c1b512016-09-06 20:57:50 +00001852 Options *GetOptions() override { return &m_option_group; }
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001853
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001854protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001855 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 Ingham5e09c8c2014-12-16 23:40:14 +00001859 }
1860
Kate Stoneb9c1b512016-09-06 20:57:50 +00001861 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 Ingham5e09c8c2014-12-16 23:40:14 +00001907private:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001908 BreakpointNameOptionGroup m_name_options;
1909 OptionGroupOptions m_option_group;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001910};
1911
Kate Stoneb9c1b512016-09-06 20:57:50 +00001912class CommandObjectBreakpointNameDelete : public CommandObjectParsed {
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001913public:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001914 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 Ingham5e09c8c2014-12-16 23:40:14 +00001928
Kate Stoneb9c1b512016-09-06 20:57:50 +00001929 m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
1930 m_option_group.Finalize();
1931 }
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001932
Kate Stoneb9c1b512016-09-06 20:57:50 +00001933 ~CommandObjectBreakpointNameDelete() override = default;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001934
Kate Stoneb9c1b512016-09-06 20:57:50 +00001935 Options *GetOptions() override { return &m_option_group; }
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001936
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001937protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001938 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 Ingham5e09c8c2014-12-16 23:40:14 +00001942 }
1943
Kate Stoneb9c1b512016-09-06 20:57:50 +00001944 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 Ingham5e09c8c2014-12-16 23:40:14 +00001988private:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001989 BreakpointNameOptionGroup m_name_options;
1990 OptionGroupOptions m_option_group;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001991};
1992
Kate Stoneb9c1b512016-09-06 20:57:50 +00001993class CommandObjectBreakpointNameList : public CommandObjectParsed {
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001994public:
Kate Stoneb9c1b512016-09-06 20:57:50 +00001995 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 Ingham5e09c8c2014-12-16 23:40:14 +00002004
Kate Stoneb9c1b512016-09-06 20:57:50 +00002005 ~CommandObjectBreakpointNameList() override = default;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002006
Kate Stoneb9c1b512016-09-06 20:57:50 +00002007 Options *GetOptions() override { return &m_option_group; }
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002008
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002009protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +00002010 bool DoExecute(Args &command, CommandReturnObject &result) override {
2011 Target *target =
2012 GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002013
Kate Stoneb9c1b512016-09-06 20:57:50 +00002014 if (target == nullptr) {
2015 result.AppendError("Invalid target. No existing target or breakpoints.");
2016 result.SetStatus(eReturnStatusFailed);
2017 return false;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002018 }
2019
Kate Stoneb9c1b512016-09-06 20:57:50 +00002020 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 Ingham5e09c8c2014-12-16 23:40:14 +00002059private:
Kate Stoneb9c1b512016-09-06 20:57:50 +00002060 BreakpointNameOptionGroup m_name_options;
2061 OptionGroupOptions m_option_group;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002062};
2063
2064//-------------------------------------------------------------------------
Jim Inghame14dc262016-09-12 23:10:56 +00002065// CommandObjectBreakpointName
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002066//-------------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +00002067class CommandObjectBreakpointName : public CommandObjectMultiword {
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002068public:
Kate Stoneb9c1b512016-09-06 20:57:50 +00002069 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 Ingham5e09c8c2014-12-16 23:40:14 +00002079
Kate Stoneb9c1b512016-09-06 20:57:50 +00002080 LoadSubCommand("add", add_command_object);
2081 LoadSubCommand("delete", delete_command_object);
2082 LoadSubCommand("list", list_command_object);
2083 }
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002084
Kate Stoneb9c1b512016-09-06 20:57:50 +00002085 ~CommandObjectBreakpointName() override = default;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002086};
2087
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002088//-------------------------------------------------------------------------
Jim Inghame14dc262016-09-12 23:10:56 +00002089// CommandObjectBreakpointRead
2090//-------------------------------------------------------------------------
2091#pragma mark Restore
2092
2093class CommandObjectBreakpointRead : public CommandObjectParsed {
2094public:
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
2152protected:
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 Inghame14dc262016-09-12 23:10:56 +00002161 FileSpec input_spec(m_options.m_filename, true);
Jim Ingham01f16662016-09-14 19:07:35 +00002162 BreakpointIDList new_bps;
2163 Error error = target->CreateBreakpointsFromFile(input_spec, new_bps);
2164
Jim Inghame14dc262016-09-12 23:10:56 +00002165 if (!error.Success()) {
Jim Ingham01f16662016-09-14 19:07:35 +00002166 result.AppendError(error.AsCString());
Jim Inghame14dc262016-09-12 23:10:56 +00002167 result.SetStatus(eReturnStatusFailed);
2168 return false;
2169 }
Jim Ingham01f16662016-09-14 19:07:35 +00002170 // FIXME: Report the newly created breakpoints.
Jim Inghame14dc262016-09-12 23:10:56 +00002171 return result.Succeeded();
2172 }
2173
2174private:
2175 CommandOptions m_options;
2176};
2177
2178#pragma mark Modify::CommandOptions
2179OptionDefinition 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
2191class CommandObjectBreakpointWrite : public CommandObjectParsed {
2192public:
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
2251protected:
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 Inghame14dc262016-09-12 23:10:56 +00002260 std::unique_lock<std::recursive_mutex> lock;
2261 target->GetBreakpointList().GetListMutex(lock);
2262
Jim Ingham01f16662016-09-14 19:07:35 +00002263 BreakpointIDList valid_bp_ids;
2264 if (command.GetArgumentCount() > 0) {
Jim Inghame14dc262016-09-12 23:10:56 +00002265 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs(
2266 command, target, result, &valid_bp_ids);
2267
Jim Ingham01f16662016-09-14 19:07:35 +00002268 if (!result.Succeeded()) {
2269 result.SetStatus(eReturnStatusFailed);
2270 return false;
Jim Inghame14dc262016-09-12 23:10:56 +00002271 }
2272 }
Jim Ingham01f16662016-09-14 19:07:35 +00002273 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 Inghame14dc262016-09-12 23:10:56 +00002280 return result.Succeeded();
2281 }
2282
2283private:
2284 CommandOptions m_options;
2285};
2286
2287#pragma mark Modify::CommandOptions
2288OptionDefinition
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 Lattner30fdc8d2010-06-08 16:52:24 +00002297// CommandObjectMultiwordBreakpoint
2298//-------------------------------------------------------------------------
Jim Inghamae1c4cf2010-06-18 00:58:52 +00002299#pragma mark MultiwordBreakpoint
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002300
Kate Stoneb9c1b512016-09-06 20:57:50 +00002301CommandObjectMultiwordBreakpoint::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 Inghame14dc262016-09-12 23:10:56 +00002325 CommandObjectSP write_command_object(
2326 new CommandObjectBreakpointWrite(interpreter));
2327 CommandObjectSP read_command_object(
2328 new CommandObjectBreakpointRead(interpreter));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002329
Kate Stoneb9c1b512016-09-06 20:57:50 +00002330 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 Inghame14dc262016-09-12 23:10:56 +00002339 write_command_object->SetCommandName("breakpoint write");
2340 read_command_object->SetCommandName("breakpoint read");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002341
Kate Stoneb9c1b512016-09-06 20:57:50 +00002342 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 Inghame14dc262016-09-12 23:10:56 +00002351 LoadSubCommand("write", write_command_object);
2352 LoadSubCommand("read", read_command_object);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002353}
2354
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002355CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002356
Kate Stoneb9c1b512016-09-06 20:57:50 +00002357void 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 Lattner30fdc8d2010-06-08 16:52:24 +00002371
Kate Stoneb9c1b512016-09-06 20:57:50 +00002372 Args temp_args;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002373
Kate Stoneb9c1b512016-09-06 20:57:50 +00002374 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 Ingham36f3b362010-10-14 23:45:03 +00002383 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002384 return;
2385 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002386
Kate Stoneb9c1b512016-09-06 20:57:50 +00002387 // 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 Lattner30fdc8d2010-06-08 16:52:24 +00002393
Kate Stoneb9c1b512016-09-06 20:57:50 +00002394 BreakpointIDList::FindAndReplaceIDRanges(args, target, allow_locations,
2395 result, temp_args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002396
Kate Stoneb9c1b512016-09-06 20:57:50 +00002397 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual
2398 // BreakpointIDList:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002399
Kate Stoneb9c1b512016-09-06 20:57:50 +00002400 valid_ids->InsertStringArray(temp_args.GetConstArgumentVector(),
2401 temp_args.GetArgumentCount(), result);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002402
Kate Stoneb9c1b512016-09-06 20:57:50 +00002403 // 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 Lattner30fdc8d2010-06-08 16:52:24 +00002406
Kate Stoneb9c1b512016-09-06 20:57:50 +00002407 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 Lattner30fdc8d2010-06-08 16:52:24 +00002429 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002430 } 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 Lattner30fdc8d2010-06-08 16:52:24 +00002437 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002438 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002439}