1 //===-- CommandObjectBreakpoint.cpp -----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "CommandObjectBreakpoint.h"
13 #include "CommandObjectBreakpointCommand.h"
17 // Other libraries and framework includes
19 #include "lldb/Breakpoint/Breakpoint.h"
20 #include "lldb/Breakpoint/BreakpointIDList.h"
21 #include "lldb/Breakpoint/BreakpointLocation.h"
22 #include "lldb/Interpreter/Options.h"
23 #include "lldb/Core/RegularExpression.h"
24 #include "lldb/Core/StreamString.h"
25 #include "lldb/Interpreter/CommandInterpreter.h"
26 #include "lldb/Interpreter/CommandReturnObject.h"
27 #include "lldb/Target/Target.h"
28 #include "lldb/Interpreter/CommandCompletions.h"
29 #include "lldb/Target/StackFrame.h"
30 #include "lldb/Target/Thread.h"
31 #include "lldb/Target/ThreadSpec.h"
36 using namespace lldb_private;
39 AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level)
42 bp->GetDescription (s, level, true);
47 //-------------------------------------------------------------------------
48 // CommandObjectBreakpointSet
49 //-------------------------------------------------------------------------
52 class CommandObjectBreakpointSet : public CommandObjectParsed
56 typedef enum BreakpointSetType
62 eSetTypeFunctionRegexp,
67 CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
68 CommandObjectParsed (interpreter,
70 "Sets a breakpoint or set of breakpoints in the executable.",
71 "breakpoint set <cmd-options>"),
72 m_options (interpreter)
78 ~CommandObjectBreakpointSet () {}
86 class CommandOptions : public Options
90 CommandOptions (CommandInterpreter &interpreter) :
91 Options (interpreter),
97 m_func_name_type_mask (eFunctionNameTypeNone),
99 m_source_text_regexp(),
103 m_thread_id(LLDB_INVALID_THREAD_ID),
104 m_thread_index (UINT32_MAX),
110 m_language (eLanguageTypeUnknown),
111 m_skip_prologue (eLazyBoolCalculate),
118 ~CommandOptions () {}
121 SetOptionValue (uint32_t option_idx, const char *option_arg)
124 const int short_option = m_getopt_table[option_idx].val;
126 switch (short_option)
130 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
131 m_load_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
136 m_func_names.push_back (option_arg);
137 m_func_name_type_mask |= eFunctionNameTypeBase;
141 m_column = Args::StringToUInt32 (option_arg, 0);
145 m_condition.assign(option_arg);
150 LanguageType language = LanguageRuntime::GetLanguageTypeFromString (option_arg);
154 case eLanguageTypeC89:
156 case eLanguageTypeC99:
157 m_language = eLanguageTypeC;
159 case eLanguageTypeC_plus_plus:
160 m_language = eLanguageTypeC_plus_plus;
162 case eLanguageTypeObjC:
163 m_language = eLanguageTypeObjC;
165 case eLanguageTypeObjC_plus_plus:
166 error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c");
168 case eLanguageTypeUnknown:
169 error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg);
172 error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg);
178 m_filenames.AppendIfUnique (FileSpec(option_arg, false));
182 m_func_names.push_back (option_arg);
183 m_func_name_type_mask |= eFunctionNameTypeFull;
189 m_catch_bp = Args::StringToBoolean (option_arg, true, &success);
191 error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg);
201 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
202 if (m_ignore_count == UINT32_MAX)
203 error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
211 value = Args::StringToBoolean (option_arg, true, &success);
213 m_skip_prologue = eLazyBoolYes;
215 m_skip_prologue = eLazyBoolNo;
218 error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg);
223 m_line_num = Args::StringToUInt32 (option_arg, 0);
227 m_func_names.push_back (option_arg);
228 m_func_name_type_mask |= eFunctionNameTypeMethod;
232 m_func_names.push_back (option_arg);
233 m_func_name_type_mask |= eFunctionNameTypeAuto;
241 m_source_text_regexp.assign (option_arg);
245 m_queue_name.assign (option_arg);
249 m_func_regexp.assign (option_arg);
254 m_modules.AppendIfUnique (FileSpec (option_arg, false));
259 m_func_names.push_back (option_arg);
260 m_func_name_type_mask |= eFunctionNameTypeSelector;
265 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
266 if (m_thread_id == LLDB_INVALID_THREAD_ID)
267 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
272 m_thread_name.assign (option_arg);
278 m_throw_bp = Args::StringToBoolean (option_arg, true, &success);
280 error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg);
286 m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
287 if (m_thread_id == UINT32_MAX)
288 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
294 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
301 OptionParsingStarting ()
307 m_func_names.clear();
308 m_func_name_type_mask = eFunctionNameTypeNone;
309 m_func_regexp.clear();
310 m_source_text_regexp.clear();
312 m_load_addr = LLDB_INVALID_ADDRESS;
314 m_thread_id = LLDB_INVALID_THREAD_ID;
315 m_thread_index = UINT32_MAX;
316 m_thread_name.clear();
317 m_queue_name.clear();
321 m_language = eLanguageTypeUnknown;
322 m_skip_prologue = eLazyBoolCalculate;
326 const OptionDefinition*
329 return g_option_table;
332 // Options table: Required for subclasses of Options.
334 static OptionDefinition g_option_table[];
336 // Instance variables to hold the values for command options.
338 std::string m_condition;
339 FileSpecList m_filenames;
342 std::vector<std::string> m_func_names;
343 uint32_t m_func_name_type_mask;
344 std::string m_func_regexp;
345 std::string m_source_text_regexp;
346 FileSpecList m_modules;
347 lldb::addr_t m_load_addr;
348 uint32_t m_ignore_count;
349 lldb::tid_t m_thread_id;
350 uint32_t m_thread_index;
351 std::string m_thread_name;
352 std::string m_queue_name;
355 bool m_hardware; // Request to use hardware breakpoints
356 lldb::LanguageType m_language;
357 LazyBool m_skip_prologue;
364 DoExecute (Args& command,
365 CommandReturnObject &result)
367 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
370 result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command).");
371 result.SetStatus (eReturnStatusFailed);
375 // The following are the various types of breakpoints that could be set:
376 // 1). -f -l -p [-s -g] (setting breakpoint by source location)
377 // 2). -a [-s -g] (setting breakpoint by address)
378 // 3). -n [-s -g] (setting breakpoint by function name)
379 // 4). -r [-s -g] (setting breakpoint by function name regular expression)
380 // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text)
381 // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.)
383 BreakpointSetType break_type = eSetTypeInvalid;
385 if (m_options.m_line_num != 0)
386 break_type = eSetTypeFileAndLine;
387 else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
388 break_type = eSetTypeAddress;
389 else if (!m_options.m_func_names.empty())
390 break_type = eSetTypeFunctionName;
391 else if (!m_options.m_func_regexp.empty())
392 break_type = eSetTypeFunctionRegexp;
393 else if (!m_options.m_source_text_regexp.empty())
394 break_type = eSetTypeSourceRegexp;
395 else if (m_options.m_language != eLanguageTypeUnknown)
396 break_type = eSetTypeException;
398 Breakpoint *bp = NULL;
399 FileSpec module_spec;
400 const bool internal = false;
404 case eSetTypeFileAndLine: // Breakpoint by source position
407 const size_t num_files = m_options.m_filenames.GetSize();
410 if (!GetDefaultFile (target, file, result))
412 result.AppendError("No file supplied and no default file available.");
413 result.SetStatus (eReturnStatusFailed);
417 else if (num_files > 1)
419 result.AppendError("Only one file at a time is allowed for file and line breakpoints.");
420 result.SetStatus (eReturnStatusFailed);
424 file = m_options.m_filenames.GetFileSpecAtIndex(0);
426 // Only check for inline functions if
427 LazyBool check_inlines = eLazyBoolCalculate;
429 bp = target->CreateBreakpoint (&(m_options.m_modules),
431 m_options.m_line_num,
433 m_options.m_skip_prologue,
435 m_options.m_hardware).get();
439 case eSetTypeAddress: // Breakpoint by address
440 bp = target->CreateBreakpoint (m_options.m_load_addr,
442 m_options.m_hardware).get();
445 case eSetTypeFunctionName: // Breakpoint by function name
447 uint32_t name_type_mask = m_options.m_func_name_type_mask;
449 if (name_type_mask == 0)
450 name_type_mask = eFunctionNameTypeAuto;
452 bp = target->CreateBreakpoint (&(m_options.m_modules),
453 &(m_options.m_filenames),
454 m_options.m_func_names,
456 m_options.m_skip_prologue,
458 m_options.m_hardware).get();
462 case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
464 RegularExpression regexp(m_options.m_func_regexp.c_str());
465 if (!regexp.IsValid())
468 regexp.GetErrorAsCString(err_str, sizeof(err_str));
469 result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"",
471 result.SetStatus (eReturnStatusFailed);
475 bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules),
476 &(m_options.m_filenames),
478 m_options.m_skip_prologue,
480 m_options.m_hardware).get();
483 case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
485 const size_t num_files = m_options.m_filenames.GetSize();
490 if (!GetDefaultFile (target, file, result))
492 result.AppendError ("No files provided and could not find default file.");
493 result.SetStatus (eReturnStatusFailed);
498 m_options.m_filenames.Append (file);
502 RegularExpression regexp(m_options.m_source_text_regexp.c_str());
503 if (!regexp.IsValid())
506 regexp.GetErrorAsCString(err_str, sizeof(err_str));
507 result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"",
509 result.SetStatus (eReturnStatusFailed);
512 bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules),
513 &(m_options.m_filenames),
516 m_options.m_hardware).get();
519 case eSetTypeException:
521 bp = target->CreateExceptionBreakpoint (m_options.m_language,
522 m_options.m_catch_bp,
523 m_options.m_throw_bp,
524 m_options.m_hardware).get();
531 // Now set the various options that were passed in:
534 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
535 bp->SetThreadID (m_options.m_thread_id);
537 if (m_options.m_thread_index != UINT32_MAX)
538 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
540 if (!m_options.m_thread_name.empty())
541 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
543 if (!m_options.m_queue_name.empty())
544 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
546 if (m_options.m_ignore_count != 0)
547 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
549 if (!m_options.m_condition.empty())
550 bp->GetOptions()->SetCondition(m_options.m_condition.c_str());
552 bp->SetOneShot (m_options.m_one_shot);
557 Stream &output_stream = result.GetOutputStream();
558 const bool show_locations = false;
559 bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, show_locations);
560 // Don't print out this warning for exception breakpoints. They can get set before the target
561 // is set, but we won't know how to actually set the breakpoint till we run.
562 if (bp->GetNumLocations() == 0 && break_type != eSetTypeException)
563 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n");
564 result.SetStatus (eReturnStatusSuccessFinishResult);
568 result.AppendError ("Breakpoint creation failed: No breakpoint created.");
569 result.SetStatus (eReturnStatusFailed);
572 return result.Succeeded();
577 GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result)
579 uint32_t default_line;
580 // First use the Source Manager's default file.
581 // Then use the current stack frame's file.
582 if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line))
584 StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
585 if (cur_frame == NULL)
587 result.AppendError ("No selected frame to use to find the default file.");
588 result.SetStatus (eReturnStatusFailed);
591 else if (!cur_frame->HasDebugInformation())
593 result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info.");
594 result.SetStatus (eReturnStatusFailed);
599 const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
600 if (sc.line_entry.file)
602 file = sc.line_entry.file;
606 result.AppendError ("Can't find the file for the selected frame to use as the default file.");
607 result.SetStatus (eReturnStatusFailed);
615 CommandOptions m_options;
617 // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to
618 // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately.
619 #define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 )
620 #define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 )
621 #define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) )
624 CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
626 { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
627 "Set the breakpoint only in this shared library. "
628 "Can repeat this option multiple times to specify multiple shared libraries."},
630 { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCount,
631 "Set the number of times this breakpoint is skipped before stopping." },
633 { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument, NULL, 0, eArgTypeNone,
634 "The breakpoint is deleted the first time it causes a stop." },
636 { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, NULL, 0, eArgTypeExpression,
637 "The breakpoint stops only if this condition expression evaluates to true."},
639 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, NULL, 0, eArgTypeThreadIndex,
640 "The breakpoint stops only for the thread whose indeX matches this argument."},
642 { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, NULL, 0, eArgTypeThreadID,
643 "The breakpoint stops only for the thread whose TID matches this argument."},
645 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, NULL, 0, eArgTypeThreadName,
646 "The breakpoint stops only for the thread whose thread name matches this argument."},
648 { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, NULL, 0, eArgTypeNone,
649 "Require the breakpoint to use hardware breakpoints."},
651 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, NULL, 0, eArgTypeQueueName,
652 "The breakpoint stops only for threads in the queue whose name is given by this argument."},
654 { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
655 "Specifies the source file in which to set this breakpoint. "
656 "Note, by default lldb only looks for files that are #included if they use the standard include file extensions. "
657 "To set breakpoints on .c/.cpp/.m/.mm files that are #included, set target.inline-breakpoint-strategy"
660 { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, NULL, 0, eArgTypeLineNum,
661 "Specifies the line number on which to set this breakpoint."},
663 // Comment out this option for the moment, as we don't actually use it, but will in the future.
664 // This way users won't see it, but the infrastructure is left in place.
665 // { 0, false, "column", 'C', OptionParser::eRequiredArgument, NULL, "<column>",
666 // "Set the breakpoint by source location at this particular column."},
668 { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, NULL, 0, eArgTypeAddressOrExpression,
669 "Set the breakpoint by address, at the specified address."},
671 { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
672 "Set the breakpoint by function name. Can be repeated multiple times to make one breakpoint for multiple names" },
674 { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
675 "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and "
676 "for Objective C this means a full function prototype with class and selector. "
677 "Can be repeated multiple times to make one breakpoint for multiple names." },
679 { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, NULL, 0, eArgTypeSelector,
680 "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." },
682 { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, NULL, 0, eArgTypeMethod,
683 "Set the breakpoint by C++ method names. Can be repeated multiple times to make one breakpoint for multiple methods." },
685 { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, NULL, 0, eArgTypeRegularExpression,
686 "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
688 { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
689 "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). "
690 "Can be repeated multiple times to make one breakpoint for multiple symbols." },
692 { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, NULL, 0, eArgTypeRegularExpression,
693 "Set the breakpoint by specifying a regular expression which is matched against the source text in a source file or files "
694 "specified with the -f option. The -f option can be specified more than once. "
695 "If no source files are specified, uses the current \"default source file\"" },
697 { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, NULL, 0, eArgTypeLanguage,
698 "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" },
700 { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean,
701 "Set the breakpoint on exception throW." },
703 { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean,
704 "Set the breakpoint on exception catcH." },
706 { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean,
707 "sKip the prologue if the breakpoint is at the beginning of a function. If not set the target.skip-prologue setting is used." },
709 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
712 //-------------------------------------------------------------------------
713 // CommandObjectBreakpointModify
714 //-------------------------------------------------------------------------
717 class CommandObjectBreakpointModify : public CommandObjectParsed
721 CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
722 CommandObjectParsed (interpreter,
724 "Modify the options on a breakpoint or set of breakpoints in the executable. "
725 "If no breakpoint is specified, acts on the last created breakpoint. "
726 "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
728 m_options (interpreter)
730 CommandArgumentEntry arg;
731 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
732 // Add the entry for the first argument for this command to the object's arguments vector.
733 m_arguments.push_back (arg);
738 ~CommandObjectBreakpointModify () {}
746 class CommandOptions : public Options
750 CommandOptions (CommandInterpreter &interpreter) :
751 Options (interpreter),
753 m_thread_id(LLDB_INVALID_THREAD_ID),
754 m_thread_id_passed(false),
755 m_thread_index (UINT32_MAX),
756 m_thread_index_passed(false),
761 m_enable_passed (false),
762 m_enable_value (false),
763 m_name_passed (false),
764 m_queue_passed (false),
765 m_condition_passed (false),
766 m_one_shot_passed (false)
771 ~CommandOptions () {}
774 SetOptionValue (uint32_t option_idx, const char *option_arg)
777 const int short_option = m_getopt_table[option_idx].val;
779 switch (short_option)
782 if (option_arg != NULL)
783 m_condition.assign (option_arg);
786 m_condition_passed = true;
789 m_enable_passed = true;
790 m_enable_value = false;
793 m_enable_passed = true;
794 m_enable_value = true;
798 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
799 if (m_ignore_count == UINT32_MAX)
800 error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
806 value = Args::StringToBoolean(option_arg, false, &success);
809 m_one_shot_passed = true;
813 error.SetErrorStringWithFormat("invalid boolean value '%s' passed for -o option", option_arg);
818 if (option_arg[0] == '\0')
820 m_thread_id = LLDB_INVALID_THREAD_ID;
821 m_thread_id_passed = true;
825 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
826 if (m_thread_id == LLDB_INVALID_THREAD_ID)
827 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
829 m_thread_id_passed = true;
834 if (option_arg != NULL)
835 m_thread_name.assign (option_arg);
837 m_thread_name.clear();
838 m_name_passed = true;
841 if (option_arg != NULL)
842 m_queue_name.assign (option_arg);
844 m_queue_name.clear();
845 m_queue_passed = true;
849 if (option_arg[0] == '\n')
851 m_thread_index = UINT32_MAX;
852 m_thread_index_passed = true;
856 m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0);
857 if (m_thread_id == UINT32_MAX)
858 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
860 m_thread_index_passed = true;
865 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
872 OptionParsingStarting ()
875 m_thread_id = LLDB_INVALID_THREAD_ID;
876 m_thread_id_passed = false;
877 m_thread_index = UINT32_MAX;
878 m_thread_index_passed = false;
879 m_thread_name.clear();
880 m_queue_name.clear();
883 m_enable_passed = false;
884 m_queue_passed = false;
885 m_name_passed = false;
886 m_condition_passed = false;
887 m_one_shot_passed = false;
890 const OptionDefinition*
893 return g_option_table;
897 // Options table: Required for subclasses of Options.
899 static OptionDefinition g_option_table[];
901 // Instance variables to hold the values for command options.
903 uint32_t m_ignore_count;
904 lldb::tid_t m_thread_id;
905 bool m_thread_id_passed;
906 uint32_t m_thread_index;
907 bool m_thread_index_passed;
908 std::string m_thread_name;
909 std::string m_queue_name;
910 std::string m_condition;
912 bool m_enable_passed;
916 bool m_condition_passed;
917 bool m_one_shot_passed;
923 DoExecute (Args& command, CommandReturnObject &result)
925 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
928 result.AppendError ("Invalid target. No existing target or breakpoints.");
929 result.SetStatus (eReturnStatusFailed);
933 Mutex::Locker locker;
934 target->GetBreakpointList().GetListMutex(locker);
936 BreakpointIDList valid_bp_ids;
938 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
940 if (result.Succeeded())
942 const size_t count = valid_bp_ids.GetSize();
943 for (size_t i = 0; i < count; ++i)
945 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
947 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
949 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
950 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
952 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
955 if (m_options.m_thread_id_passed)
956 location->SetThreadID (m_options.m_thread_id);
958 if (m_options.m_thread_index_passed)
959 location->SetThreadIndex(m_options.m_thread_index);
961 if (m_options.m_name_passed)
962 location->SetThreadName(m_options.m_thread_name.c_str());
964 if (m_options.m_queue_passed)
965 location->SetQueueName(m_options.m_queue_name.c_str());
967 if (m_options.m_ignore_count != 0)
968 location->SetIgnoreCount(m_options.m_ignore_count);
970 if (m_options.m_enable_passed)
971 location->SetEnabled (m_options.m_enable_value);
973 if (m_options.m_condition_passed)
974 location->SetCondition (m_options.m_condition.c_str());
979 if (m_options.m_thread_id_passed)
980 bp->SetThreadID (m_options.m_thread_id);
982 if (m_options.m_thread_index_passed)
983 bp->SetThreadIndex(m_options.m_thread_index);
985 if (m_options.m_name_passed)
986 bp->SetThreadName(m_options.m_thread_name.c_str());
988 if (m_options.m_queue_passed)
989 bp->SetQueueName(m_options.m_queue_name.c_str());
991 if (m_options.m_ignore_count != 0)
992 bp->SetIgnoreCount(m_options.m_ignore_count);
994 if (m_options.m_enable_passed)
995 bp->SetEnabled (m_options.m_enable_value);
997 if (m_options.m_condition_passed)
998 bp->SetCondition (m_options.m_condition.c_str());
1004 return result.Succeeded();
1008 CommandOptions m_options;
1011 #pragma mark Modify::CommandOptions
1013 CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
1015 { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." },
1016 { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean, "The breakpoint is deleted the first time it stop causes a stop." },
1017 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, NULL, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose index matches this argument."},
1018 { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, NULL, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."},
1019 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, NULL, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."},
1020 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, NULL, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."},
1021 { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."},
1022 { LLDB_OPT_SET_1, false, "enable", 'e', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Enable the breakpoint."},
1023 { LLDB_OPT_SET_2, false, "disable", 'd', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Disable the breakpoint."},
1024 { 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL }
1027 //-------------------------------------------------------------------------
1028 // CommandObjectBreakpointEnable
1029 //-------------------------------------------------------------------------
1032 class CommandObjectBreakpointEnable : public CommandObjectParsed
1035 CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
1036 CommandObjectParsed (interpreter,
1038 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
1041 CommandArgumentEntry arg;
1042 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1043 // Add the entry for the first argument for this command to the object's arguments vector.
1044 m_arguments.push_back (arg);
1049 ~CommandObjectBreakpointEnable () {}
1053 DoExecute (Args& command, CommandReturnObject &result)
1055 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1058 result.AppendError ("Invalid target. No existing target or breakpoints.");
1059 result.SetStatus (eReturnStatusFailed);
1063 Mutex::Locker locker;
1064 target->GetBreakpointList().GetListMutex(locker);
1066 const BreakpointList &breakpoints = target->GetBreakpointList();
1068 size_t num_breakpoints = breakpoints.GetSize();
1070 if (num_breakpoints == 0)
1072 result.AppendError ("No breakpoints exist to be enabled.");
1073 result.SetStatus (eReturnStatusFailed);
1077 if (command.GetArgumentCount() == 0)
1079 // No breakpoint selected; enable all currently set breakpoints.
1080 target->EnableAllBreakpoints ();
1081 result.AppendMessageWithFormat ("All breakpoints enabled. (%zu breakpoints)\n", num_breakpoints);
1082 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1086 // Particular breakpoint selected; enable that breakpoint.
1087 BreakpointIDList valid_bp_ids;
1088 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1090 if (result.Succeeded())
1092 int enable_count = 0;
1094 const size_t count = valid_bp_ids.GetSize();
1095 for (size_t i = 0; i < count; ++i)
1097 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1099 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1101 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1102 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1104 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1107 location->SetEnabled (true);
1113 breakpoint->SetEnabled (true);
1118 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
1119 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1123 return result.Succeeded();
1127 //-------------------------------------------------------------------------
1128 // CommandObjectBreakpointDisable
1129 //-------------------------------------------------------------------------
1130 #pragma mark Disable
1132 class CommandObjectBreakpointDisable : public CommandObjectParsed
1135 CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
1136 CommandObjectParsed (interpreter,
1137 "breakpoint disable",
1138 "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.",
1142 "Disable the specified breakpoint(s) without removing it/them. \n\
1143 If no breakpoints are specified, disable them all.\n\
1145 Note: disabling a breakpoint will cause none of its locations to be hit\n\
1146 regardless of whether they are enabled or disabled. So the sequence: \n\
1148 (lldb) break disable 1\n\
1149 (lldb) break enable 1.1\n\
1151 will NOT cause location 1.1 to get hit. To achieve that, do:\n\
1153 (lldb) break disable 1.*\n\
1154 (lldb) break enable 1.1\n\
1156 The first command disables all the locations of breakpoint 1, \n\
1157 the second re-enables the first location."
1160 CommandArgumentEntry arg;
1161 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1162 // Add the entry for the first argument for this command to the object's arguments vector.
1163 m_arguments.push_back (arg);
1169 ~CommandObjectBreakpointDisable () {}
1173 DoExecute (Args& command, CommandReturnObject &result)
1175 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1178 result.AppendError ("Invalid target. No existing target or breakpoints.");
1179 result.SetStatus (eReturnStatusFailed);
1183 Mutex::Locker locker;
1184 target->GetBreakpointList().GetListMutex(locker);
1186 const BreakpointList &breakpoints = target->GetBreakpointList();
1187 size_t num_breakpoints = breakpoints.GetSize();
1189 if (num_breakpoints == 0)
1191 result.AppendError ("No breakpoints exist to be disabled.");
1192 result.SetStatus (eReturnStatusFailed);
1196 if (command.GetArgumentCount() == 0)
1198 // No breakpoint selected; disable all currently set breakpoints.
1199 target->DisableAllBreakpoints ();
1200 result.AppendMessageWithFormat ("All breakpoints disabled. (%zu breakpoints)\n", num_breakpoints);
1201 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1205 // Particular breakpoint selected; disable that breakpoint.
1206 BreakpointIDList valid_bp_ids;
1208 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1210 if (result.Succeeded())
1212 int disable_count = 0;
1214 const size_t count = valid_bp_ids.GetSize();
1215 for (size_t i = 0; i < count; ++i)
1217 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1219 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1221 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1222 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1224 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1227 location->SetEnabled (false);
1233 breakpoint->SetEnabled (false);
1238 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
1239 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1243 return result.Succeeded();
1248 //-------------------------------------------------------------------------
1249 // CommandObjectBreakpointList
1250 //-------------------------------------------------------------------------
1253 class CommandObjectBreakpointList : public CommandObjectParsed
1256 CommandObjectBreakpointList (CommandInterpreter &interpreter) :
1257 CommandObjectParsed (interpreter,
1259 "List some or all breakpoints at configurable levels of detail.",
1261 m_options (interpreter)
1263 CommandArgumentEntry arg;
1264 CommandArgumentData bp_id_arg;
1266 // Define the first (and only) variant of this arg.
1267 bp_id_arg.arg_type = eArgTypeBreakpointID;
1268 bp_id_arg.arg_repetition = eArgRepeatOptional;
1270 // There is only one variant this argument could be; put it into the argument entry.
1271 arg.push_back (bp_id_arg);
1273 // Push the data for the first argument into the m_arguments vector.
1274 m_arguments.push_back (arg);
1279 ~CommandObjectBreakpointList () {}
1287 class CommandOptions : public Options
1291 CommandOptions (CommandInterpreter &interpreter) :
1292 Options (interpreter),
1293 m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions
1298 ~CommandOptions () {}
1301 SetOptionValue (uint32_t option_idx, const char *option_arg)
1304 const int short_option = m_getopt_table[option_idx].val;
1306 switch (short_option)
1309 m_level = lldb::eDescriptionLevelBrief;
1312 m_level = lldb::eDescriptionLevelFull;
1315 m_level = lldb::eDescriptionLevelVerbose;
1321 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1329 OptionParsingStarting ()
1331 m_level = lldb::eDescriptionLevelFull;
1335 const OptionDefinition *
1338 return g_option_table;
1341 // Options table: Required for subclasses of Options.
1343 static OptionDefinition g_option_table[];
1345 // Instance variables to hold the values for command options.
1347 lldb::DescriptionLevel m_level;
1354 DoExecute (Args& command, CommandReturnObject &result)
1356 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1359 result.AppendError ("Invalid target. No current target or breakpoints.");
1360 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1364 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
1365 Mutex::Locker locker;
1366 target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
1368 size_t num_breakpoints = breakpoints.GetSize();
1370 if (num_breakpoints == 0)
1372 result.AppendMessage ("No breakpoints currently set.");
1373 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1377 Stream &output_stream = result.GetOutputStream();
1379 if (command.GetArgumentCount() == 0)
1381 // No breakpoint selected; show info about all currently set breakpoints.
1382 result.AppendMessage ("Current breakpoints:");
1383 for (size_t i = 0; i < num_breakpoints; ++i)
1385 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
1386 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
1388 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1392 // Particular breakpoints selected; show info about that breakpoint.
1393 BreakpointIDList valid_bp_ids;
1394 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1396 if (result.Succeeded())
1398 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
1400 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1401 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1402 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
1404 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1408 result.AppendError ("Invalid breakpoint id.");
1409 result.SetStatus (eReturnStatusFailed);
1413 return result.Succeeded();
1417 CommandOptions m_options;
1420 #pragma mark List::CommandOptions
1422 CommandObjectBreakpointList::CommandOptions::g_option_table[] =
1424 { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, NULL, 0, eArgTypeNone,
1425 "Show debugger internal breakpoints" },
1427 { LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, NULL, 0, eArgTypeNone,
1428 "Give a brief description of the breakpoint (no location info)."},
1430 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
1431 // But I need to see it for now, and don't want to wait.
1432 { LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, NULL, 0, eArgTypeNone,
1433 "Give a full description of the breakpoint and its locations."},
1435 { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, NULL, 0, eArgTypeNone,
1436 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
1438 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1441 //-------------------------------------------------------------------------
1442 // CommandObjectBreakpointClear
1443 //-------------------------------------------------------------------------
1446 class CommandObjectBreakpointClear : public CommandObjectParsed
1450 typedef enum BreakpointClearType
1453 eClearTypeFileAndLine
1454 } BreakpointClearType;
1456 CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
1457 CommandObjectParsed (interpreter,
1459 "Clears a breakpoint or set of breakpoints in the executable.",
1460 "breakpoint clear <cmd-options>"),
1461 m_options (interpreter)
1466 ~CommandObjectBreakpointClear () {}
1474 class CommandOptions : public Options
1478 CommandOptions (CommandInterpreter &interpreter) :
1479 Options (interpreter),
1486 ~CommandOptions () {}
1489 SetOptionValue (uint32_t option_idx, const char *option_arg)
1492 const int short_option = m_getopt_table[option_idx].val;
1494 switch (short_option)
1497 m_filename.assign (option_arg);
1501 m_line_num = Args::StringToUInt32 (option_arg, 0);
1505 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1513 OptionParsingStarting ()
1519 const OptionDefinition*
1522 return g_option_table;
1525 // Options table: Required for subclasses of Options.
1527 static OptionDefinition g_option_table[];
1529 // Instance variables to hold the values for command options.
1531 std::string m_filename;
1532 uint32_t m_line_num;
1538 DoExecute (Args& command, CommandReturnObject &result)
1540 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1543 result.AppendError ("Invalid target. No existing target or breakpoints.");
1544 result.SetStatus (eReturnStatusFailed);
1548 // The following are the various types of breakpoints that could be cleared:
1549 // 1). -f -l (clearing breakpoint by source location)
1551 BreakpointClearType break_type = eClearTypeInvalid;
1553 if (m_options.m_line_num != 0)
1554 break_type = eClearTypeFileAndLine;
1556 Mutex::Locker locker;
1557 target->GetBreakpointList().GetListMutex(locker);
1559 BreakpointList &breakpoints = target->GetBreakpointList();
1560 size_t num_breakpoints = breakpoints.GetSize();
1562 // Early return if there's no breakpoint at all.
1563 if (num_breakpoints == 0)
1565 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1566 result.SetStatus (eReturnStatusFailed);
1567 return result.Succeeded();
1570 // Find matching breakpoints and delete them.
1572 // First create a copy of all the IDs.
1573 std::vector<break_id_t> BreakIDs;
1574 for (size_t i = 0; i < num_breakpoints; ++i)
1575 BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID());
1577 int num_cleared = 0;
1581 case eClearTypeFileAndLine: // Breakpoint by source position
1583 const ConstString filename(m_options.m_filename.c_str());
1584 BreakpointLocationCollection loc_coll;
1586 for (size_t i = 0; i < num_breakpoints; ++i)
1588 Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
1590 if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
1592 // If the collection size is 0, it's a full match and we can just remove the breakpoint.
1593 if (loc_coll.GetSize() == 0)
1595 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
1597 target->RemoveBreakpointByID (bp->GetID());
1609 if (num_cleared > 0)
1611 Stream &output_stream = result.GetOutputStream();
1612 output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
1613 output_stream << ss.GetData();
1614 output_stream.EOL();
1615 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1619 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1620 result.SetStatus (eReturnStatusFailed);
1623 return result.Succeeded();
1627 CommandOptions m_options;
1630 #pragma mark Clear::CommandOptions
1633 CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
1635 { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
1636 "Specify the breakpoint by source location in this particular file."},
1638 { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, NULL, 0, eArgTypeLineNum,
1639 "Specify the breakpoint by source location at this particular line."},
1641 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1644 //-------------------------------------------------------------------------
1645 // CommandObjectBreakpointDelete
1646 //-------------------------------------------------------------------------
1649 class CommandObjectBreakpointDelete : public CommandObjectParsed
1652 CommandObjectBreakpointDelete (CommandInterpreter &interpreter) :
1653 CommandObjectParsed (interpreter,
1654 "breakpoint delete",
1655 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
1658 CommandArgumentEntry arg;
1659 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1660 // Add the entry for the first argument for this command to the object's arguments vector.
1661 m_arguments.push_back (arg);
1665 ~CommandObjectBreakpointDelete () {}
1669 DoExecute (Args& command, CommandReturnObject &result)
1671 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1674 result.AppendError ("Invalid target. No existing target or breakpoints.");
1675 result.SetStatus (eReturnStatusFailed);
1679 Mutex::Locker locker;
1680 target->GetBreakpointList().GetListMutex(locker);
1682 const BreakpointList &breakpoints = target->GetBreakpointList();
1684 size_t num_breakpoints = breakpoints.GetSize();
1686 if (num_breakpoints == 0)
1688 result.AppendError ("No breakpoints exist to be deleted.");
1689 result.SetStatus (eReturnStatusFailed);
1693 if (command.GetArgumentCount() == 0)
1695 if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
1697 result.AppendMessage("Operation cancelled...");
1701 target->RemoveAllBreakpoints ();
1702 result.AppendMessageWithFormat ("All breakpoints removed. (%zu %s)\n", num_breakpoints, num_breakpoints > 1 ? "breakpoints" : "breakpoint");
1704 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1708 // Particular breakpoint selected; disable that breakpoint.
1709 BreakpointIDList valid_bp_ids;
1710 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1712 if (result.Succeeded())
1714 int delete_count = 0;
1715 int disable_count = 0;
1716 const size_t count = valid_bp_ids.GetSize();
1717 for (size_t i = 0; i < count; ++i)
1719 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1721 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1723 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1725 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1726 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1727 // It makes no sense to try to delete individual locations, so we disable them instead.
1730 location->SetEnabled (false);
1736 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1741 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1742 delete_count, disable_count);
1743 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1746 return result.Succeeded();
1750 //-------------------------------------------------------------------------
1751 // CommandObjectMultiwordBreakpoint
1752 //-------------------------------------------------------------------------
1753 #pragma mark MultiwordBreakpoint
1755 CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
1756 CommandObjectMultiword (interpreter,
1758 "A set of commands for operating on breakpoints. Also see _regexp-break.",
1759 "breakpoint <command> [<command-options>]")
1761 CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
1762 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
1763 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
1764 CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
1765 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
1766 CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
1767 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
1768 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
1770 list_command_object->SetCommandName ("breakpoint list");
1771 enable_command_object->SetCommandName("breakpoint enable");
1772 disable_command_object->SetCommandName("breakpoint disable");
1773 clear_command_object->SetCommandName("breakpoint clear");
1774 delete_command_object->SetCommandName("breakpoint delete");
1775 set_command_object->SetCommandName("breakpoint set");
1776 command_command_object->SetCommandName ("breakpoint command");
1777 modify_command_object->SetCommandName ("breakpoint modify");
1779 LoadSubCommand ("list", list_command_object);
1780 LoadSubCommand ("enable", enable_command_object);
1781 LoadSubCommand ("disable", disable_command_object);
1782 LoadSubCommand ("clear", clear_command_object);
1783 LoadSubCommand ("delete", delete_command_object);
1784 LoadSubCommand ("set", set_command_object);
1785 LoadSubCommand ("command", command_command_object);
1786 LoadSubCommand ("modify", modify_command_object);
1789 CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
1794 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result,
1795 BreakpointIDList *valid_ids)
1797 // args can be strings representing 1). integers (for breakpoint ids)
1798 // 2). the full breakpoint & location canonical representation
1799 // 3). the word "to" or a hyphen, representing a range (in which case there
1800 // had *better* be an entry both before & after of one of the first two types.
1801 // If args is empty, we will use the last created breakpoint (if there is one.)
1805 if (args.GetArgumentCount() == 0)
1807 if (target->GetLastCreatedBreakpoint())
1809 valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
1810 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1814 result.AppendError("No breakpoint specified and no last created breakpoint.");
1815 result.SetStatus (eReturnStatusFailed);
1820 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
1821 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
1822 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
1824 BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
1826 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
1828 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
1830 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
1831 // and put into valid_ids.
1833 if (result.Succeeded())
1835 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
1836 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
1838 const size_t count = valid_ids->GetSize();
1839 for (size_t i = 0; i < count; ++i)
1841 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
1842 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1843 if (breakpoint != NULL)
1845 const size_t num_locations = breakpoint->GetNumLocations();
1846 if (cur_bp_id.GetLocationID() > num_locations)
1848 StreamString id_str;
1849 BreakpointID::GetCanonicalReference (&id_str,
1850 cur_bp_id.GetBreakpointID(),
1851 cur_bp_id.GetLocationID());
1852 i = valid_ids->GetSize() + 1;
1853 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
1855 result.SetStatus (eReturnStatusFailed);
1860 i = valid_ids->GetSize() + 1;
1861 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
1862 result.SetStatus (eReturnStatusFailed);