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/Interpreter/OptionValueString.h"
24 #include "lldb/Interpreter/OptionValueUInt64.h"
25 #include "lldb/Core/RegularExpression.h"
26 #include "lldb/Core/StreamString.h"
27 #include "lldb/Interpreter/CommandInterpreter.h"
28 #include "lldb/Interpreter/CommandReturnObject.h"
29 #include "lldb/Target/Target.h"
30 #include "lldb/Interpreter/CommandCompletions.h"
31 #include "lldb/Target/StackFrame.h"
32 #include "lldb/Target/Thread.h"
33 #include "lldb/Target/ThreadSpec.h"
38 using namespace lldb_private;
41 AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level)
44 bp->GetDescription (s, level, true);
49 //-------------------------------------------------------------------------
50 // CommandObjectBreakpointSet
51 //-------------------------------------------------------------------------
54 class CommandObjectBreakpointSet : public CommandObjectParsed
58 typedef enum BreakpointSetType
64 eSetTypeFunctionRegexp,
69 CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
70 CommandObjectParsed (interpreter,
72 "Sets a breakpoint or set of breakpoints in the executable.",
73 "breakpoint set <cmd-options>"),
74 m_options (interpreter)
80 ~CommandObjectBreakpointSet () {}
88 class CommandOptions : public Options
92 CommandOptions (CommandInterpreter &interpreter) :
93 Options (interpreter),
99 m_func_name_type_mask (eFunctionNameTypeNone),
101 m_source_text_regexp(),
105 m_thread_id(LLDB_INVALID_THREAD_ID),
106 m_thread_index (UINT32_MAX),
112 m_language (eLanguageTypeUnknown),
113 m_skip_prologue (eLazyBoolCalculate),
120 ~CommandOptions () {}
123 SetOptionValue (uint32_t option_idx, const char *option_arg)
126 const int short_option = m_getopt_table[option_idx].val;
128 switch (short_option)
132 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
133 m_load_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
138 m_func_names.push_back (option_arg);
139 m_func_name_type_mask |= eFunctionNameTypeBase;
143 m_column = Args::StringToUInt32 (option_arg, 0);
147 m_condition.assign(option_arg);
156 LanguageType language = LanguageRuntime::GetLanguageTypeFromString (option_arg);
160 case eLanguageTypeC89:
162 case eLanguageTypeC99:
163 case eLanguageTypeC11:
164 m_language = eLanguageTypeC;
166 case eLanguageTypeC_plus_plus:
167 case eLanguageTypeC_plus_plus_03:
168 case eLanguageTypeC_plus_plus_11:
169 m_language = eLanguageTypeC_plus_plus;
171 case eLanguageTypeObjC:
172 m_language = eLanguageTypeObjC;
174 case eLanguageTypeObjC_plus_plus:
175 error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c");
177 case eLanguageTypeUnknown:
178 error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg);
181 error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg);
187 m_filenames.AppendIfUnique (FileSpec(option_arg, false));
191 m_func_names.push_back (option_arg);
192 m_func_name_type_mask |= eFunctionNameTypeFull;
198 m_catch_bp = Args::StringToBoolean (option_arg, true, &success);
200 error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg);
210 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
211 if (m_ignore_count == UINT32_MAX)
212 error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
220 value = Args::StringToBoolean (option_arg, true, &success);
222 m_skip_prologue = eLazyBoolYes;
224 m_skip_prologue = eLazyBoolNo;
227 error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg);
232 m_line_num = Args::StringToUInt32 (option_arg, 0);
236 m_func_names.push_back (option_arg);
237 m_func_name_type_mask |= eFunctionNameTypeMethod;
241 m_func_names.push_back (option_arg);
242 m_func_name_type_mask |= eFunctionNameTypeAuto;
246 if (BreakpointID::StringIsBreakpointName(option_arg, error))
247 m_breakpoint_names.push_back (option_arg);
255 m_source_text_regexp.assign (option_arg);
259 m_queue_name.assign (option_arg);
263 m_func_regexp.assign (option_arg);
268 m_modules.AppendIfUnique (FileSpec (option_arg, false));
273 m_func_names.push_back (option_arg);
274 m_func_name_type_mask |= eFunctionNameTypeSelector;
279 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
280 if (m_thread_id == LLDB_INVALID_THREAD_ID)
281 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
286 m_thread_name.assign (option_arg);
292 m_throw_bp = Args::StringToBoolean (option_arg, true, &success);
294 error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg);
300 m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
301 if (m_thread_id == UINT32_MAX)
302 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
308 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
315 OptionParsingStarting ()
321 m_func_names.clear();
322 m_func_name_type_mask = eFunctionNameTypeNone;
323 m_func_regexp.clear();
324 m_source_text_regexp.clear();
326 m_load_addr = LLDB_INVALID_ADDRESS;
328 m_thread_id = LLDB_INVALID_THREAD_ID;
329 m_thread_index = UINT32_MAX;
330 m_thread_name.clear();
331 m_queue_name.clear();
335 m_language = eLanguageTypeUnknown;
336 m_skip_prologue = eLazyBoolCalculate;
339 m_breakpoint_names.clear();
342 const OptionDefinition*
345 return g_option_table;
348 // Options table: Required for subclasses of Options.
350 static OptionDefinition g_option_table[];
352 // Instance variables to hold the values for command options.
354 std::string m_condition;
355 FileSpecList m_filenames;
358 std::vector<std::string> m_func_names;
359 std::vector<std::string> m_breakpoint_names;
360 uint32_t m_func_name_type_mask;
361 std::string m_func_regexp;
362 std::string m_source_text_regexp;
363 FileSpecList m_modules;
364 lldb::addr_t m_load_addr;
365 uint32_t m_ignore_count;
366 lldb::tid_t m_thread_id;
367 uint32_t m_thread_index;
368 std::string m_thread_name;
369 std::string m_queue_name;
372 bool m_hardware; // Request to use hardware breakpoints
373 lldb::LanguageType m_language;
374 LazyBool m_skip_prologue;
382 DoExecute (Args& command,
383 CommandReturnObject &result)
385 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
387 if (target == nullptr)
389 result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command).");
390 result.SetStatus (eReturnStatusFailed);
394 // The following are the various types of breakpoints that could be set:
395 // 1). -f -l -p [-s -g] (setting breakpoint by source location)
396 // 2). -a [-s -g] (setting breakpoint by address)
397 // 3). -n [-s -g] (setting breakpoint by function name)
398 // 4). -r [-s -g] (setting breakpoint by function name regular expression)
399 // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text)
400 // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.)
402 BreakpointSetType break_type = eSetTypeInvalid;
404 if (m_options.m_line_num != 0)
405 break_type = eSetTypeFileAndLine;
406 else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
407 break_type = eSetTypeAddress;
408 else if (!m_options.m_func_names.empty())
409 break_type = eSetTypeFunctionName;
410 else if (!m_options.m_func_regexp.empty())
411 break_type = eSetTypeFunctionRegexp;
412 else if (!m_options.m_source_text_regexp.empty())
413 break_type = eSetTypeSourceRegexp;
414 else if (m_options.m_language != eLanguageTypeUnknown)
415 break_type = eSetTypeException;
417 Breakpoint *bp = NULL;
418 FileSpec module_spec;
419 const bool internal = false;
423 case eSetTypeFileAndLine: // Breakpoint by source position
426 const size_t num_files = m_options.m_filenames.GetSize();
429 if (!GetDefaultFile (target, file, result))
431 result.AppendError("No file supplied and no default file available.");
432 result.SetStatus (eReturnStatusFailed);
436 else if (num_files > 1)
438 result.AppendError("Only one file at a time is allowed for file and line breakpoints.");
439 result.SetStatus (eReturnStatusFailed);
443 file = m_options.m_filenames.GetFileSpecAtIndex(0);
445 // Only check for inline functions if
446 LazyBool check_inlines = eLazyBoolCalculate;
448 bp = target->CreateBreakpoint (&(m_options.m_modules),
450 m_options.m_line_num,
452 m_options.m_skip_prologue,
454 m_options.m_hardware).get();
458 case eSetTypeAddress: // Breakpoint by address
459 bp = target->CreateBreakpoint (m_options.m_load_addr,
461 m_options.m_hardware).get();
464 case eSetTypeFunctionName: // Breakpoint by function name
466 uint32_t name_type_mask = m_options.m_func_name_type_mask;
468 if (name_type_mask == 0)
469 name_type_mask = eFunctionNameTypeAuto;
471 bp = target->CreateBreakpoint (&(m_options.m_modules),
472 &(m_options.m_filenames),
473 m_options.m_func_names,
475 m_options.m_skip_prologue,
477 m_options.m_hardware).get();
481 case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
483 RegularExpression regexp(m_options.m_func_regexp.c_str());
484 if (!regexp.IsValid())
487 regexp.GetErrorAsCString(err_str, sizeof(err_str));
488 result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"",
490 result.SetStatus (eReturnStatusFailed);
494 bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules),
495 &(m_options.m_filenames),
497 m_options.m_skip_prologue,
499 m_options.m_hardware).get();
502 case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
504 const size_t num_files = m_options.m_filenames.GetSize();
509 if (!GetDefaultFile (target, file, result))
511 result.AppendError ("No files provided and could not find default file.");
512 result.SetStatus (eReturnStatusFailed);
517 m_options.m_filenames.Append (file);
521 RegularExpression regexp(m_options.m_source_text_regexp.c_str());
522 if (!regexp.IsValid())
525 regexp.GetErrorAsCString(err_str, sizeof(err_str));
526 result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"",
528 result.SetStatus (eReturnStatusFailed);
531 bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules),
532 &(m_options.m_filenames),
535 m_options.m_hardware).get();
538 case eSetTypeException:
540 bp = target->CreateExceptionBreakpoint (m_options.m_language,
541 m_options.m_catch_bp,
542 m_options.m_throw_bp,
543 m_options.m_hardware).get();
550 // Now set the various options that were passed in:
553 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
554 bp->SetThreadID (m_options.m_thread_id);
556 if (m_options.m_thread_index != UINT32_MAX)
557 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
559 if (!m_options.m_thread_name.empty())
560 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
562 if (!m_options.m_queue_name.empty())
563 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
565 if (m_options.m_ignore_count != 0)
566 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
568 if (!m_options.m_condition.empty())
569 bp->GetOptions()->SetCondition(m_options.m_condition.c_str());
571 if (!m_options.m_breakpoint_names.empty())
573 Error error; // We don't need to check the error here, since the option parser checked it...
574 for (auto name : m_options.m_breakpoint_names)
575 bp->AddName(name.c_str(), error);
578 bp->SetOneShot (m_options.m_one_shot);
583 Stream &output_stream = result.GetOutputStream();
584 const bool show_locations = false;
585 bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, show_locations);
586 if (target == m_interpreter.GetDebugger().GetDummyTarget())
587 output_stream.Printf ("Breakpoint set in dummy target, will get copied into future targets.\n");
590 // Don't print out this warning for exception breakpoints. They can get set before the target
591 // is set, but we won't know how to actually set the breakpoint till we run.
592 if (bp->GetNumLocations() == 0 && break_type != eSetTypeException)
594 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n");
597 result.SetStatus (eReturnStatusSuccessFinishResult);
601 result.AppendError ("Breakpoint creation failed: No breakpoint created.");
602 result.SetStatus (eReturnStatusFailed);
605 return result.Succeeded();
610 GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result)
612 uint32_t default_line;
613 // First use the Source Manager's default file.
614 // Then use the current stack frame's file.
615 if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line))
617 StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
618 if (cur_frame == NULL)
620 result.AppendError ("No selected frame to use to find the default file.");
621 result.SetStatus (eReturnStatusFailed);
624 else if (!cur_frame->HasDebugInformation())
626 result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info.");
627 result.SetStatus (eReturnStatusFailed);
632 const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
633 if (sc.line_entry.file)
635 file = sc.line_entry.file;
639 result.AppendError ("Can't find the file for the selected frame to use as the default file.");
640 result.SetStatus (eReturnStatusFailed);
648 CommandOptions m_options;
650 // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to
651 // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately.
652 #define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 )
653 #define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 )
654 #define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) )
657 CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
659 { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
660 "Set the breakpoint only in this shared library. "
661 "Can repeat this option multiple times to specify multiple shared libraries."},
663 { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCount,
664 "Set the number of times this breakpoint is skipped before stopping." },
666 { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
667 "The breakpoint is deleted the first time it causes a stop." },
669 { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeExpression,
670 "The breakpoint stops only if this condition expression evaluates to true."},
672 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadIndex,
673 "The breakpoint stops only for the thread whose indeX matches this argument."},
675 { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadID,
676 "The breakpoint stops only for the thread whose TID matches this argument."},
678 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadName,
679 "The breakpoint stops only for the thread whose thread name matches this argument."},
681 { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
682 "Require the breakpoint to use hardware breakpoints."},
684 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeQueueName,
685 "The breakpoint stops only for threads in the queue whose name is given by this argument."},
687 { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
688 "Specifies the source file in which to set this breakpoint. "
689 "Note, by default lldb only looks for files that are #included if they use the standard include file extensions. "
690 "To set breakpoints on .c/.cpp/.m/.mm files that are #included, set target.inline-breakpoint-strategy"
693 { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLineNum,
694 "Specifies the line number on which to set this breakpoint."},
696 // Comment out this option for the moment, as we don't actually use it, but will in the future.
697 // This way users won't see it, but the infrastructure is left in place.
698 // { 0, false, "column", 'C', OptionParser::eRequiredArgument, NULL, "<column>",
699 // "Set the breakpoint by source location at this particular column."},
701 { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeAddressOrExpression,
702 "Set the breakpoint by address, at the specified address."},
704 { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
705 "Set the breakpoint by function name. Can be repeated multiple times to make one breakpoint for multiple names" },
707 { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
708 "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and "
709 "for Objective C this means a full function prototype with class and selector. "
710 "Can be repeated multiple times to make one breakpoint for multiple names." },
712 { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeSelector,
713 "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." },
715 { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeMethod,
716 "Set the breakpoint by C++ method names. Can be repeated multiple times to make one breakpoint for multiple methods." },
718 { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeRegularExpression,
719 "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
721 { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
722 "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). "
723 "Can be repeated multiple times to make one breakpoint for multiple symbols." },
725 { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeRegularExpression,
726 "Set the breakpoint by specifying a regular expression which is matched against the source text in a source file or files "
727 "specified with the -f option. The -f option can be specified more than once. "
728 "If no source files are specified, uses the current \"default source file\"" },
730 { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLanguage,
731 "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" },
733 { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean,
734 "Set the breakpoint on exception throW." },
736 { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean,
737 "Set the breakpoint on exception catcH." },
739 { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean,
740 "sKip the prologue if the breakpoint is at the beginning of a function. If not set the target.skip-prologue setting is used." },
742 { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
743 "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
745 { LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointName,
746 "Adds this to the list of names for this breakopint."},
748 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
751 //-------------------------------------------------------------------------
752 // CommandObjectBreakpointModify
753 //-------------------------------------------------------------------------
756 class CommandObjectBreakpointModify : public CommandObjectParsed
760 CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
761 CommandObjectParsed (interpreter,
763 "Modify the options on a breakpoint or set of breakpoints in the executable. "
764 "If no breakpoint is specified, acts on the last created breakpoint. "
765 "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
767 m_options (interpreter)
769 CommandArgumentEntry arg;
770 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
771 // Add the entry for the first argument for this command to the object's arguments vector.
772 m_arguments.push_back (arg);
777 ~CommandObjectBreakpointModify () {}
785 class CommandOptions : public Options
789 CommandOptions (CommandInterpreter &interpreter) :
790 Options (interpreter),
792 m_thread_id(LLDB_INVALID_THREAD_ID),
793 m_thread_id_passed(false),
794 m_thread_index (UINT32_MAX),
795 m_thread_index_passed(false),
800 m_enable_passed (false),
801 m_enable_value (false),
802 m_name_passed (false),
803 m_queue_passed (false),
804 m_condition_passed (false),
805 m_one_shot_passed (false),
811 ~CommandOptions () {}
814 SetOptionValue (uint32_t option_idx, const char *option_arg)
817 const int short_option = m_getopt_table[option_idx].val;
819 switch (short_option)
822 if (option_arg != NULL)
823 m_condition.assign (option_arg);
826 m_condition_passed = true;
829 m_enable_passed = true;
830 m_enable_value = false;
836 m_enable_passed = true;
837 m_enable_value = true;
841 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
842 if (m_ignore_count == UINT32_MAX)
843 error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
849 value = Args::StringToBoolean(option_arg, false, &success);
852 m_one_shot_passed = true;
856 error.SetErrorStringWithFormat("invalid boolean value '%s' passed for -o option", option_arg);
861 if (option_arg[0] == '\0')
863 m_thread_id = LLDB_INVALID_THREAD_ID;
864 m_thread_id_passed = true;
868 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
869 if (m_thread_id == LLDB_INVALID_THREAD_ID)
870 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
872 m_thread_id_passed = true;
877 if (option_arg != NULL)
878 m_thread_name.assign (option_arg);
880 m_thread_name.clear();
881 m_name_passed = true;
884 if (option_arg != NULL)
885 m_queue_name.assign (option_arg);
887 m_queue_name.clear();
888 m_queue_passed = true;
892 if (option_arg[0] == '\n')
894 m_thread_index = UINT32_MAX;
895 m_thread_index_passed = true;
899 m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0);
900 if (m_thread_id == UINT32_MAX)
901 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
903 m_thread_index_passed = true;
908 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
915 OptionParsingStarting ()
918 m_thread_id = LLDB_INVALID_THREAD_ID;
919 m_thread_id_passed = false;
920 m_thread_index = UINT32_MAX;
921 m_thread_index_passed = false;
922 m_thread_name.clear();
923 m_queue_name.clear();
926 m_enable_passed = false;
927 m_queue_passed = false;
928 m_name_passed = false;
929 m_condition_passed = false;
930 m_one_shot_passed = false;
934 const OptionDefinition*
937 return g_option_table;
941 // Options table: Required for subclasses of Options.
943 static OptionDefinition g_option_table[];
945 // Instance variables to hold the values for command options.
947 uint32_t m_ignore_count;
948 lldb::tid_t m_thread_id;
949 bool m_thread_id_passed;
950 uint32_t m_thread_index;
951 bool m_thread_index_passed;
952 std::string m_thread_name;
953 std::string m_queue_name;
954 std::string m_condition;
956 bool m_enable_passed;
960 bool m_condition_passed;
961 bool m_one_shot_passed;
968 DoExecute (Args& command, CommandReturnObject &result)
970 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
973 result.AppendError ("Invalid target. No existing target or breakpoints.");
974 result.SetStatus (eReturnStatusFailed);
978 Mutex::Locker locker;
979 target->GetBreakpointList().GetListMutex(locker);
981 BreakpointIDList valid_bp_ids;
983 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
985 if (result.Succeeded())
987 const size_t count = valid_bp_ids.GetSize();
988 for (size_t i = 0; i < count; ++i)
990 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
992 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
994 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
995 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
997 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
1000 if (m_options.m_thread_id_passed)
1001 location->SetThreadID (m_options.m_thread_id);
1003 if (m_options.m_thread_index_passed)
1004 location->SetThreadIndex(m_options.m_thread_index);
1006 if (m_options.m_name_passed)
1007 location->SetThreadName(m_options.m_thread_name.c_str());
1009 if (m_options.m_queue_passed)
1010 location->SetQueueName(m_options.m_queue_name.c_str());
1012 if (m_options.m_ignore_count != 0)
1013 location->SetIgnoreCount(m_options.m_ignore_count);
1015 if (m_options.m_enable_passed)
1016 location->SetEnabled (m_options.m_enable_value);
1018 if (m_options.m_condition_passed)
1019 location->SetCondition (m_options.m_condition.c_str());
1024 if (m_options.m_thread_id_passed)
1025 bp->SetThreadID (m_options.m_thread_id);
1027 if (m_options.m_thread_index_passed)
1028 bp->SetThreadIndex(m_options.m_thread_index);
1030 if (m_options.m_name_passed)
1031 bp->SetThreadName(m_options.m_thread_name.c_str());
1033 if (m_options.m_queue_passed)
1034 bp->SetQueueName(m_options.m_queue_name.c_str());
1036 if (m_options.m_ignore_count != 0)
1037 bp->SetIgnoreCount(m_options.m_ignore_count);
1039 if (m_options.m_enable_passed)
1040 bp->SetEnabled (m_options.m_enable_value);
1042 if (m_options.m_condition_passed)
1043 bp->SetCondition (m_options.m_condition.c_str());
1049 return result.Succeeded();
1053 CommandOptions m_options;
1056 #pragma mark Modify::CommandOptions
1058 CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
1060 { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." },
1061 { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "The breakpoint is deleted the first time it stop causes a stop." },
1062 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose index matches this argument."},
1063 { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."},
1064 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."},
1065 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."},
1066 { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."},
1067 { LLDB_OPT_SET_1, false, "enable", 'e', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Enable the breakpoint."},
1068 { LLDB_OPT_SET_2, false, "disable", 'd', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Disable the breakpoint."},
1069 { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
1071 { 0, false, NULL, 0 , 0, NULL, NULL, 0, eArgTypeNone, NULL }
1074 //-------------------------------------------------------------------------
1075 // CommandObjectBreakpointEnable
1076 //-------------------------------------------------------------------------
1079 class CommandObjectBreakpointEnable : public CommandObjectParsed
1082 CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
1083 CommandObjectParsed (interpreter,
1085 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
1088 CommandArgumentEntry arg;
1089 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1090 // Add the entry for the first argument for this command to the object's arguments vector.
1091 m_arguments.push_back (arg);
1096 ~CommandObjectBreakpointEnable () {}
1100 DoExecute (Args& command, CommandReturnObject &result)
1102 Target *target = GetSelectedOrDummyTarget();
1105 result.AppendError ("Invalid target. No existing target or breakpoints.");
1106 result.SetStatus (eReturnStatusFailed);
1110 Mutex::Locker locker;
1111 target->GetBreakpointList().GetListMutex(locker);
1113 const BreakpointList &breakpoints = target->GetBreakpointList();
1115 size_t num_breakpoints = breakpoints.GetSize();
1117 if (num_breakpoints == 0)
1119 result.AppendError ("No breakpoints exist to be enabled.");
1120 result.SetStatus (eReturnStatusFailed);
1124 if (command.GetArgumentCount() == 0)
1126 // No breakpoint selected; enable all currently set breakpoints.
1127 target->EnableAllBreakpoints ();
1128 result.AppendMessageWithFormat ("All breakpoints enabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints);
1129 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1133 // Particular breakpoint selected; enable that breakpoint.
1134 BreakpointIDList valid_bp_ids;
1135 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
1137 if (result.Succeeded())
1139 int enable_count = 0;
1141 const size_t count = valid_bp_ids.GetSize();
1142 for (size_t i = 0; i < count; ++i)
1144 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1146 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1148 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1149 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1151 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1154 location->SetEnabled (true);
1160 breakpoint->SetEnabled (true);
1165 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
1166 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1170 return result.Succeeded();
1174 //-------------------------------------------------------------------------
1175 // CommandObjectBreakpointDisable
1176 //-------------------------------------------------------------------------
1177 #pragma mark Disable
1179 class CommandObjectBreakpointDisable : public CommandObjectParsed
1182 CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
1183 CommandObjectParsed (interpreter,
1184 "breakpoint disable",
1185 "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.",
1189 "Disable the specified breakpoint(s) without removing it/them. \n\
1190 If no breakpoints are specified, disable them all.\n\
1192 Note: disabling a breakpoint will cause none of its locations to be hit\n\
1193 regardless of whether they are enabled or disabled. So the sequence: \n\
1195 (lldb) break disable 1\n\
1196 (lldb) break enable 1.1\n\
1198 will NOT cause location 1.1 to get hit. To achieve that, do:\n\
1200 (lldb) break disable 1.*\n\
1201 (lldb) break enable 1.1\n\
1203 The first command disables all the locations of breakpoint 1, \n\
1204 the second re-enables the first location."
1207 CommandArgumentEntry arg;
1208 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1209 // Add the entry for the first argument for this command to the object's arguments vector.
1210 m_arguments.push_back (arg);
1216 ~CommandObjectBreakpointDisable () {}
1220 DoExecute (Args& command, CommandReturnObject &result)
1222 Target *target = GetSelectedOrDummyTarget();
1225 result.AppendError ("Invalid target. No existing target or breakpoints.");
1226 result.SetStatus (eReturnStatusFailed);
1230 Mutex::Locker locker;
1231 target->GetBreakpointList().GetListMutex(locker);
1233 const BreakpointList &breakpoints = target->GetBreakpointList();
1234 size_t num_breakpoints = breakpoints.GetSize();
1236 if (num_breakpoints == 0)
1238 result.AppendError ("No breakpoints exist to be disabled.");
1239 result.SetStatus (eReturnStatusFailed);
1243 if (command.GetArgumentCount() == 0)
1245 // No breakpoint selected; disable all currently set breakpoints.
1246 target->DisableAllBreakpoints ();
1247 result.AppendMessageWithFormat ("All breakpoints disabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints);
1248 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1252 // Particular breakpoint selected; disable that breakpoint.
1253 BreakpointIDList valid_bp_ids;
1255 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
1257 if (result.Succeeded())
1259 int disable_count = 0;
1261 const size_t count = valid_bp_ids.GetSize();
1262 for (size_t i = 0; i < count; ++i)
1264 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1266 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1268 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1269 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1271 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1274 location->SetEnabled (false);
1280 breakpoint->SetEnabled (false);
1285 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
1286 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1290 return result.Succeeded();
1295 //-------------------------------------------------------------------------
1296 // CommandObjectBreakpointList
1297 //-------------------------------------------------------------------------
1300 class CommandObjectBreakpointList : public CommandObjectParsed
1303 CommandObjectBreakpointList (CommandInterpreter &interpreter) :
1304 CommandObjectParsed (interpreter,
1306 "List some or all breakpoints at configurable levels of detail.",
1308 m_options (interpreter)
1310 CommandArgumentEntry arg;
1311 CommandArgumentData bp_id_arg;
1313 // Define the first (and only) variant of this arg.
1314 bp_id_arg.arg_type = eArgTypeBreakpointID;
1315 bp_id_arg.arg_repetition = eArgRepeatOptional;
1317 // There is only one variant this argument could be; put it into the argument entry.
1318 arg.push_back (bp_id_arg);
1320 // Push the data for the first argument into the m_arguments vector.
1321 m_arguments.push_back (arg);
1326 ~CommandObjectBreakpointList () {}
1334 class CommandOptions : public Options
1338 CommandOptions (CommandInterpreter &interpreter) :
1339 Options (interpreter),
1340 m_level (lldb::eDescriptionLevelBrief),
1346 ~CommandOptions () {}
1349 SetOptionValue (uint32_t option_idx, const char *option_arg)
1352 const int short_option = m_getopt_table[option_idx].val;
1354 switch (short_option)
1357 m_level = lldb::eDescriptionLevelBrief;
1363 m_level = lldb::eDescriptionLevelFull;
1366 m_level = lldb::eDescriptionLevelVerbose;
1372 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1380 OptionParsingStarting ()
1382 m_level = lldb::eDescriptionLevelFull;
1384 m_use_dummy = false;
1387 const OptionDefinition *
1390 return g_option_table;
1393 // Options table: Required for subclasses of Options.
1395 static OptionDefinition g_option_table[];
1397 // Instance variables to hold the values for command options.
1399 lldb::DescriptionLevel m_level;
1407 DoExecute (Args& command, CommandReturnObject &result)
1409 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
1413 result.AppendError ("Invalid target. No current target or breakpoints.");
1414 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1418 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
1419 Mutex::Locker locker;
1420 target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
1422 size_t num_breakpoints = breakpoints.GetSize();
1424 if (num_breakpoints == 0)
1426 result.AppendMessage ("No breakpoints currently set.");
1427 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1431 Stream &output_stream = result.GetOutputStream();
1433 if (command.GetArgumentCount() == 0)
1435 // No breakpoint selected; show info about all currently set breakpoints.
1436 result.AppendMessage ("Current breakpoints:");
1437 for (size_t i = 0; i < num_breakpoints; ++i)
1439 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
1440 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
1442 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1446 // Particular breakpoints selected; show info about that breakpoint.
1447 BreakpointIDList valid_bp_ids;
1448 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
1450 if (result.Succeeded())
1452 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
1454 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1455 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1456 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
1458 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1462 result.AppendError ("Invalid breakpoint id.");
1463 result.SetStatus (eReturnStatusFailed);
1467 return result.Succeeded();
1471 CommandOptions m_options;
1474 #pragma mark List::CommandOptions
1476 CommandObjectBreakpointList::CommandOptions::g_option_table[] =
1478 { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1479 "Show debugger internal breakpoints" },
1481 { LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1482 "Give a brief description of the breakpoint (no location info)."},
1484 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
1485 // But I need to see it for now, and don't want to wait.
1486 { LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1487 "Give a full description of the breakpoint and its locations."},
1489 { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1490 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
1492 { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1493 "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
1495 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
1498 //-------------------------------------------------------------------------
1499 // CommandObjectBreakpointClear
1500 //-------------------------------------------------------------------------
1503 class CommandObjectBreakpointClear : public CommandObjectParsed
1507 typedef enum BreakpointClearType
1510 eClearTypeFileAndLine
1511 } BreakpointClearType;
1513 CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
1514 CommandObjectParsed (interpreter,
1516 "Clears a breakpoint or set of breakpoints in the executable.",
1517 "breakpoint clear <cmd-options>"),
1518 m_options (interpreter)
1523 ~CommandObjectBreakpointClear () {}
1531 class CommandOptions : public Options
1535 CommandOptions (CommandInterpreter &interpreter) :
1536 Options (interpreter),
1543 ~CommandOptions () {}
1546 SetOptionValue (uint32_t option_idx, const char *option_arg)
1549 const int short_option = m_getopt_table[option_idx].val;
1551 switch (short_option)
1554 m_filename.assign (option_arg);
1558 m_line_num = Args::StringToUInt32 (option_arg, 0);
1562 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1570 OptionParsingStarting ()
1576 const OptionDefinition*
1579 return g_option_table;
1582 // Options table: Required for subclasses of Options.
1584 static OptionDefinition g_option_table[];
1586 // Instance variables to hold the values for command options.
1588 std::string m_filename;
1589 uint32_t m_line_num;
1595 DoExecute (Args& command, CommandReturnObject &result)
1597 Target *target = GetSelectedOrDummyTarget();
1600 result.AppendError ("Invalid target. No existing target or breakpoints.");
1601 result.SetStatus (eReturnStatusFailed);
1605 // The following are the various types of breakpoints that could be cleared:
1606 // 1). -f -l (clearing breakpoint by source location)
1608 BreakpointClearType break_type = eClearTypeInvalid;
1610 if (m_options.m_line_num != 0)
1611 break_type = eClearTypeFileAndLine;
1613 Mutex::Locker locker;
1614 target->GetBreakpointList().GetListMutex(locker);
1616 BreakpointList &breakpoints = target->GetBreakpointList();
1617 size_t num_breakpoints = breakpoints.GetSize();
1619 // Early return if there's no breakpoint at all.
1620 if (num_breakpoints == 0)
1622 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1623 result.SetStatus (eReturnStatusFailed);
1624 return result.Succeeded();
1627 // Find matching breakpoints and delete them.
1629 // First create a copy of all the IDs.
1630 std::vector<break_id_t> BreakIDs;
1631 for (size_t i = 0; i < num_breakpoints; ++i)
1632 BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID());
1634 int num_cleared = 0;
1638 case eClearTypeFileAndLine: // Breakpoint by source position
1640 const ConstString filename(m_options.m_filename.c_str());
1641 BreakpointLocationCollection loc_coll;
1643 for (size_t i = 0; i < num_breakpoints; ++i)
1645 Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
1647 if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
1649 // If the collection size is 0, it's a full match and we can just remove the breakpoint.
1650 if (loc_coll.GetSize() == 0)
1652 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
1654 target->RemoveBreakpointByID (bp->GetID());
1666 if (num_cleared > 0)
1668 Stream &output_stream = result.GetOutputStream();
1669 output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
1670 output_stream << ss.GetData();
1671 output_stream.EOL();
1672 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1676 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1677 result.SetStatus (eReturnStatusFailed);
1680 return result.Succeeded();
1684 CommandOptions m_options;
1687 #pragma mark Clear::CommandOptions
1690 CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
1692 { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
1693 "Specify the breakpoint by source location in this particular file."},
1695 { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLineNum,
1696 "Specify the breakpoint by source location at this particular line."},
1698 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
1701 //-------------------------------------------------------------------------
1702 // CommandObjectBreakpointDelete
1703 //-------------------------------------------------------------------------
1706 class CommandObjectBreakpointDelete : public CommandObjectParsed
1709 CommandObjectBreakpointDelete (CommandInterpreter &interpreter) :
1710 CommandObjectParsed (interpreter,
1711 "breakpoint delete",
1712 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
1714 m_options (interpreter)
1716 CommandArgumentEntry arg;
1717 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1718 // Add the entry for the first argument for this command to the object's arguments vector.
1719 m_arguments.push_back (arg);
1723 ~CommandObjectBreakpointDelete () {}
1731 class CommandOptions : public Options
1735 CommandOptions (CommandInterpreter &interpreter) :
1736 Options (interpreter),
1737 m_use_dummy (false),
1743 ~CommandOptions () {}
1746 SetOptionValue (uint32_t option_idx, const char *option_arg)
1749 const int short_option = m_getopt_table[option_idx].val;
1751 switch (short_option)
1762 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1770 OptionParsingStarting ()
1772 m_use_dummy = false;
1776 const OptionDefinition*
1779 return g_option_table;
1782 // Options table: Required for subclasses of Options.
1784 static OptionDefinition g_option_table[];
1786 // Instance variables to hold the values for command options.
1793 DoExecute (Args& command, CommandReturnObject &result)
1795 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
1799 result.AppendError ("Invalid target. No existing target or breakpoints.");
1800 result.SetStatus (eReturnStatusFailed);
1804 Mutex::Locker locker;
1805 target->GetBreakpointList().GetListMutex(locker);
1807 const BreakpointList &breakpoints = target->GetBreakpointList();
1809 size_t num_breakpoints = breakpoints.GetSize();
1811 if (num_breakpoints == 0)
1813 result.AppendError ("No breakpoints exist to be deleted.");
1814 result.SetStatus (eReturnStatusFailed);
1818 if (command.GetArgumentCount() == 0)
1820 if (!m_options.m_force && !m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
1822 result.AppendMessage("Operation cancelled...");
1826 target->RemoveAllBreakpoints ();
1827 result.AppendMessageWithFormat ("All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : "");
1829 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1833 // Particular breakpoint selected; disable that breakpoint.
1834 BreakpointIDList valid_bp_ids;
1835 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
1837 if (result.Succeeded())
1839 int delete_count = 0;
1840 int disable_count = 0;
1841 const size_t count = valid_bp_ids.GetSize();
1842 for (size_t i = 0; i < count; ++i)
1844 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1846 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1848 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1850 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1851 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1852 // It makes no sense to try to delete individual locations, so we disable them instead.
1855 location->SetEnabled (false);
1861 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1866 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1867 delete_count, disable_count);
1868 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1871 return result.Succeeded();
1874 CommandOptions m_options;
1878 CommandObjectBreakpointDelete::CommandOptions::g_option_table[] =
1880 { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1881 "Delete all breakpoints without querying for confirmation."},
1883 { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1884 "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
1886 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
1889 //-------------------------------------------------------------------------
1890 // CommandObjectBreakpointName
1891 //-------------------------------------------------------------------------
1893 static OptionDefinition
1894 g_breakpoint_name_options[] =
1896 { LLDB_OPT_SET_1, false, "name", 'N', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."},
1897 { LLDB_OPT_SET_2, false, "breakpoint-id", 'B', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointID, "Specify a breakpoint id to use."},
1898 { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1899 "Operate on Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
1901 class BreakpointNameOptionGroup : public OptionGroup
1904 BreakpointNameOptionGroup() :
1906 m_breakpoint(LLDB_INVALID_BREAK_ID),
1913 ~BreakpointNameOptionGroup ()
1918 GetNumDefinitions ()
1920 return sizeof (g_breakpoint_name_options) / sizeof (OptionDefinition);
1923 virtual const OptionDefinition*
1926 return g_breakpoint_name_options;
1930 SetOptionValue (CommandInterpreter &interpreter,
1931 uint32_t option_idx,
1932 const char *option_value)
1935 const int short_option = g_breakpoint_name_options[option_idx].short_option;
1937 switch (short_option)
1940 if (BreakpointID::StringIsBreakpointName(option_value, error) && error.Success())
1941 m_name.SetValueFromCString(option_value);
1945 if (m_breakpoint.SetValueFromCString(option_value).Fail())
1946 error.SetErrorStringWithFormat ("unrecognized value \"%s\" for breakpoint", option_value);
1949 if (m_use_dummy.SetValueFromCString(option_value).Fail())
1950 error.SetErrorStringWithFormat ("unrecognized value \"%s\" for use-dummy", option_value);
1954 error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
1961 OptionParsingStarting (CommandInterpreter &interpreter)
1964 m_breakpoint.Clear();
1965 m_use_dummy.Clear();
1966 m_use_dummy.SetDefaultValue(false);
1969 OptionValueString m_name;
1970 OptionValueUInt64 m_breakpoint;
1971 OptionValueBoolean m_use_dummy;
1975 class CommandObjectBreakpointNameAdd : public CommandObjectParsed
1978 CommandObjectBreakpointNameAdd (CommandInterpreter &interpreter) :
1979 CommandObjectParsed (interpreter,
1981 "Add a name to the breakpoints provided.",
1982 "breakpoint name add <command-options> <breakpoint-id-list>"),
1984 m_option_group(interpreter)
1986 // Create the first variant for the first (and only) argument for this command.
1987 CommandArgumentEntry arg1;
1988 CommandArgumentData id_arg;
1989 id_arg.arg_type = eArgTypeBreakpointID;
1990 id_arg.arg_repetition = eArgRepeatOptional;
1991 arg1.push_back(id_arg);
1992 m_arguments.push_back (arg1);
1994 m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
1995 m_option_group.Finalize();
1999 ~CommandObjectBreakpointNameAdd () {}
2004 return &m_option_group;
2009 DoExecute (Args& command, CommandReturnObject &result)
2011 if (!m_name_options.m_name.OptionWasSet())
2013 result.SetError("No name option provided.");
2017 Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
2021 result.AppendError ("Invalid target. No existing target or breakpoints.");
2022 result.SetStatus (eReturnStatusFailed);
2026 Mutex::Locker locker;
2027 target->GetBreakpointList().GetListMutex(locker);
2029 const BreakpointList &breakpoints = target->GetBreakpointList();
2031 size_t num_breakpoints = breakpoints.GetSize();
2032 if (num_breakpoints == 0)
2034 result.SetError("No breakpoints, cannot add names.");
2035 result.SetStatus (eReturnStatusFailed);
2039 // Particular breakpoint selected; disable that breakpoint.
2040 BreakpointIDList valid_bp_ids;
2041 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
2043 if (result.Succeeded())
2045 if (valid_bp_ids.GetSize() == 0)
2047 result.SetError("No breakpoints specified, cannot add names.");
2048 result.SetStatus (eReturnStatusFailed);
2051 size_t num_valid_ids = valid_bp_ids.GetSize();
2052 for (size_t index = 0; index < num_valid_ids; index++)
2054 lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
2055 BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
2056 Error error; // We don't need to check the error here, since the option parser checked it...
2057 bp_sp->AddName(m_name_options.m_name.GetCurrentValue(), error);
2065 BreakpointNameOptionGroup m_name_options;
2066 OptionGroupOptions m_option_group;
2071 class CommandObjectBreakpointNameDelete : public CommandObjectParsed
2074 CommandObjectBreakpointNameDelete (CommandInterpreter &interpreter) :
2075 CommandObjectParsed (interpreter,
2077 "Delete a name from the breakpoints provided.",
2078 "breakpoint name delete <command-options> <breakpoint-id-list>"),
2080 m_option_group(interpreter)
2082 // Create the first variant for the first (and only) argument for this command.
2083 CommandArgumentEntry arg1;
2084 CommandArgumentData id_arg;
2085 id_arg.arg_type = eArgTypeBreakpointID;
2086 id_arg.arg_repetition = eArgRepeatOptional;
2087 arg1.push_back(id_arg);
2088 m_arguments.push_back (arg1);
2090 m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
2091 m_option_group.Finalize();
2095 ~CommandObjectBreakpointNameDelete () {}
2100 return &m_option_group;
2105 DoExecute (Args& command, CommandReturnObject &result)
2107 if (!m_name_options.m_name.OptionWasSet())
2109 result.SetError("No name option provided.");
2113 Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
2117 result.AppendError ("Invalid target. No existing target or breakpoints.");
2118 result.SetStatus (eReturnStatusFailed);
2122 Mutex::Locker locker;
2123 target->GetBreakpointList().GetListMutex(locker);
2125 const BreakpointList &breakpoints = target->GetBreakpointList();
2127 size_t num_breakpoints = breakpoints.GetSize();
2128 if (num_breakpoints == 0)
2130 result.SetError("No breakpoints, cannot delete names.");
2131 result.SetStatus (eReturnStatusFailed);
2135 // Particular breakpoint selected; disable that breakpoint.
2136 BreakpointIDList valid_bp_ids;
2137 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
2139 if (result.Succeeded())
2141 if (valid_bp_ids.GetSize() == 0)
2143 result.SetError("No breakpoints specified, cannot delete names.");
2144 result.SetStatus (eReturnStatusFailed);
2147 size_t num_valid_ids = valid_bp_ids.GetSize();
2148 for (size_t index = 0; index < num_valid_ids; index++)
2150 lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
2151 BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
2152 bp_sp->RemoveName(m_name_options.m_name.GetCurrentValue());
2160 BreakpointNameOptionGroup m_name_options;
2161 OptionGroupOptions m_option_group;
2164 class CommandObjectBreakpointNameList : public CommandObjectParsed
2167 CommandObjectBreakpointNameList (CommandInterpreter &interpreter) :
2168 CommandObjectParsed (interpreter,
2170 "List either the names for a breakpoint or the breakpoints for a given name.",
2171 "breakpoint name list <command-options>"),
2173 m_option_group(interpreter)
2175 m_option_group.Append (&m_name_options);
2176 m_option_group.Finalize();
2180 ~CommandObjectBreakpointNameList () {}
2185 return &m_option_group;
2191 DoExecute (Args& command, CommandReturnObject &result)
2193 Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
2197 result.AppendError ("Invalid target. No existing target or breakpoints.");
2198 result.SetStatus (eReturnStatusFailed);
2202 if (m_name_options.m_name.OptionWasSet())
2204 const char *name = m_name_options.m_name.GetCurrentValue();
2205 Mutex::Locker locker;
2206 target->GetBreakpointList().GetListMutex(locker);
2208 BreakpointList &breakpoints = target->GetBreakpointList();
2209 for (BreakpointSP bp_sp : breakpoints.Breakpoints())
2211 if (bp_sp->MatchesName(name))
2214 bp_sp->GetDescription(&s, eDescriptionLevelBrief);
2216 result.AppendMessage(s.GetData());
2221 else if (m_name_options.m_breakpoint.OptionWasSet())
2223 BreakpointSP bp_sp = target->GetBreakpointList().FindBreakpointByID(m_name_options.m_breakpoint.GetCurrentValue());
2226 std::vector<std::string> names;
2227 bp_sp->GetNames (names);
2228 result.AppendMessage ("Names:");
2229 for (auto name : names)
2230 result.AppendMessageWithFormat (" %s\n", name.c_str());
2234 result.AppendErrorWithFormat ("Could not find breakpoint %" PRId64 ".\n",
2235 m_name_options.m_breakpoint.GetCurrentValue());
2236 result.SetStatus (eReturnStatusFailed);
2242 result.SetError ("Must specify -N or -B option to list.");
2243 result.SetStatus (eReturnStatusFailed);
2250 BreakpointNameOptionGroup m_name_options;
2251 OptionGroupOptions m_option_group;
2254 //-------------------------------------------------------------------------
2255 // CommandObjectMultiwordBreakpoint
2256 //-------------------------------------------------------------------------
2257 class CommandObjectBreakpointName : public CommandObjectMultiword
2260 CommandObjectBreakpointName (CommandInterpreter &interpreter) :
2261 CommandObjectMultiword(interpreter,
2263 "A set of commands to manage name tags for breakpoints",
2264 "breakpoint name <command> [<command-options>]")
2266 CommandObjectSP add_command_object (new CommandObjectBreakpointNameAdd (interpreter));
2267 CommandObjectSP delete_command_object (new CommandObjectBreakpointNameDelete (interpreter));
2268 CommandObjectSP list_command_object (new CommandObjectBreakpointNameList (interpreter));
2270 LoadSubCommand ("add", add_command_object);
2271 LoadSubCommand ("delete", delete_command_object);
2272 LoadSubCommand ("list", list_command_object);
2277 ~CommandObjectBreakpointName ()
2284 //-------------------------------------------------------------------------
2285 // CommandObjectMultiwordBreakpoint
2286 //-------------------------------------------------------------------------
2287 #pragma mark MultiwordBreakpoint
2289 CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
2290 CommandObjectMultiword (interpreter,
2292 "A set of commands for operating on breakpoints. Also see _regexp-break.",
2293 "breakpoint <command> [<command-options>]")
2295 CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
2296 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
2297 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
2298 CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
2299 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
2300 CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
2301 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
2302 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
2303 CommandObjectSP name_command_object (new CommandObjectBreakpointName(interpreter));
2305 list_command_object->SetCommandName ("breakpoint list");
2306 enable_command_object->SetCommandName("breakpoint enable");
2307 disable_command_object->SetCommandName("breakpoint disable");
2308 clear_command_object->SetCommandName("breakpoint clear");
2309 delete_command_object->SetCommandName("breakpoint delete");
2310 set_command_object->SetCommandName("breakpoint set");
2311 command_command_object->SetCommandName ("breakpoint command");
2312 modify_command_object->SetCommandName ("breakpoint modify");
2313 name_command_object->SetCommandName ("breakpoint name");
2315 LoadSubCommand ("list", list_command_object);
2316 LoadSubCommand ("enable", enable_command_object);
2317 LoadSubCommand ("disable", disable_command_object);
2318 LoadSubCommand ("clear", clear_command_object);
2319 LoadSubCommand ("delete", delete_command_object);
2320 LoadSubCommand ("set", set_command_object);
2321 LoadSubCommand ("command", command_command_object);
2322 LoadSubCommand ("modify", modify_command_object);
2323 LoadSubCommand ("name", name_command_object);
2326 CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
2331 CommandObjectMultiwordBreakpoint::VerifyIDs (Args &args,
2333 bool allow_locations,
2334 CommandReturnObject &result,
2335 BreakpointIDList *valid_ids)
2337 // args can be strings representing 1). integers (for breakpoint ids)
2338 // 2). the full breakpoint & location canonical representation
2339 // 3). the word "to" or a hyphen, representing a range (in which case there
2340 // had *better* be an entry both before & after of one of the first two types.
2341 // 4). A breakpoint name
2342 // If args is empty, we will use the last created breakpoint (if there is one.)
2346 if (args.GetArgumentCount() == 0)
2348 if (target->GetLastCreatedBreakpoint())
2350 valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
2351 result.SetStatus (eReturnStatusSuccessFinishNoResult);
2355 result.AppendError("No breakpoint specified and no last created breakpoint.");
2356 result.SetStatus (eReturnStatusFailed);
2361 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
2362 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
2363 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
2365 BreakpointIDList::FindAndReplaceIDRanges (args, target, allow_locations, result, temp_args);
2367 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
2369 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
2371 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
2372 // and put into valid_ids.
2374 if (result.Succeeded())
2376 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
2377 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
2379 const size_t count = valid_ids->GetSize();
2380 for (size_t i = 0; i < count; ++i)
2382 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
2383 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
2384 if (breakpoint != NULL)
2386 const size_t num_locations = breakpoint->GetNumLocations();
2387 if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations)
2389 StreamString id_str;
2390 BreakpointID::GetCanonicalReference (&id_str,
2391 cur_bp_id.GetBreakpointID(),
2392 cur_bp_id.GetLocationID());
2393 i = valid_ids->GetSize() + 1;
2394 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
2396 result.SetStatus (eReturnStatusFailed);
2401 i = valid_ids->GetSize() + 1;
2402 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
2403 result.SetStatus (eReturnStatusFailed);