================
@@ -200,41 +200,1341 @@ class lldb_private::BreakpointOptionGroup : public 
OptionGroup {
   BreakpointOptions m_bp_opts;
 };
 
+// This is the Breakpoint Names option group - used to add Names to breakpoints
+// while making them.  Not to be confused with the "Breakpoint Name" option
+// group which is the common options of various "breakpoint name" commands.
+#define LLDB_OPTIONS_breakpoint_names
+#include "CommandOptions.inc"
+
+class BreakpointNamesOptionGroup : public OptionGroup {
+public:
+  BreakpointNamesOptionGroup() = default;
+
+  ~BreakpointNamesOptionGroup() override = default;
+
+  llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+    return g_breakpoint_names_options;
+  }
+
+  Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
+                        ExecutionContext *execution_context) override {
+    Status error;
+    const int short_option = GetDefinitions()[option_idx].short_option;
+    const char *long_option = GetDefinitions()[option_idx].long_option;
+
+    switch (short_option) {
+    case 'N':
+      if (BreakpointID::StringIsBreakpointName(option_value, error))
+        m_breakpoint_names.push_back(std::string(option_value));
+      else
+        error = Status::FromError(
+            CreateOptionParsingError(option_value, short_option, long_option,
+                                     "Invalid breakpoint name"));
+      break;
+    }
+    return error;
+  }
+
+  void OptionParsingStarting(ExecutionContext *execution_context) override {
+    m_breakpoint_names.clear();
+  }
+
+  const std::vector<std::string> &GetBreakpointNames() {
+    return m_breakpoint_names;
+  }
+
+protected:
+  std::vector<std::string> m_breakpoint_names;
+};
+
 #define LLDB_OPTIONS_breakpoint_dummy
 #include "CommandOptions.inc"
 
-class BreakpointDummyOptionGroup : public OptionGroup {
+class BreakpointDummyOptionGroup : public OptionGroup {
+public:
+  BreakpointDummyOptionGroup() = default;
+
+  ~BreakpointDummyOptionGroup() override = default;
+
+  llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+    return llvm::ArrayRef(g_breakpoint_dummy_options);
+  }
+
+  Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+                        ExecutionContext *execution_context) override {
+    Status error;
+    const int short_option =
+        g_breakpoint_dummy_options[option_idx].short_option;
+
+    switch (short_option) {
+    case 'D':
+      m_use_dummy = true;
+      break;
+    default:
+      llvm_unreachable("Unimplemented option");
+    }
+
+    return error;
+  }
+
+  void OptionParsingStarting(ExecutionContext *execution_context) override {
+    m_use_dummy = false;
+  }
+
+  bool m_use_dummy;
+};
+
+#pragma mark AddAddress::CommandOptions
+#define LLDB_OPTIONS_breakpoint_add_address
+#include "CommandOptions.inc"
+
+#pragma mark Add Address
+
+static bool CopyOverBreakpointOptions(BreakpointSP bp_sp,
+                                      BreakpointOptionGroup &bp_opts,
+                                      const std::vector<std::string> &bp_names,
+                                      CommandReturnObject &result) {
+  assert(bp_sp && "CopyOverBreakpointOptions called with no breakpoint");
+
+  bp_sp->GetOptions().CopyOverSetOptions(bp_opts.GetBreakpointOptions());
+  Target &target = bp_sp->GetTarget();
+  if (!bp_names.empty()) {
+    Status name_error;
+    for (auto name : bp_names) {
+      target.AddNameToBreakpoint(bp_sp, name.c_str(), name_error);
+      if (name_error.Fail()) {
+        result.AppendErrorWithFormat("Invalid breakpoint name: %s",
+                                     name.c_str());
+        target.RemoveBreakpointByID(bp_sp->GetID());
+        return false;
+      }
+    }
+  }
+  return true;
+}
+
+static llvm::Expected<LanguageType>
+GetExceptionLanguageForLanguage(llvm::StringRef lang_name,
+                                char short_option = '\0',
+                                llvm::StringRef long_option = {}) {
+  LanguageType language = Language::GetLanguageTypeFromString(lang_name);
+  LanguageType exception_language = eLanguageTypeUnknown;
+
+  llvm::StringRef error_context;
+  switch (language) {
+  case eLanguageTypeC89:
+  case eLanguageTypeC:
+  case eLanguageTypeC99:
+  case eLanguageTypeC11:
+    exception_language = eLanguageTypeC;
+    break;
+  case eLanguageTypeC_plus_plus:
+  case eLanguageTypeC_plus_plus_03:
+  case eLanguageTypeC_plus_plus_11:
+  case eLanguageTypeC_plus_plus_14:
+    exception_language = eLanguageTypeC_plus_plus;
+    break;
+  case eLanguageTypeObjC_plus_plus:
+    error_context =
+        "Set exception breakpoints separately for c++ and objective-c";
+    break;
+  case eLanguageTypeUnknown:
+    error_context = "Unknown language type for exception breakpoint";
+    break;
+  default:
+    if (Language *languagePlugin = Language::FindPlugin(language)) {
+      if (languagePlugin->SupportsExceptionBreakpointsOnThrow() ||
+          languagePlugin->SupportsExceptionBreakpointsOnCatch()) {
+        exception_language = language;
+        break;
+      }
+    }
+    error_context = "Unsupported language type for exception breakpoint";
+  }
+  if (!error_context.empty())
+    return CreateOptionParsingError(lang_name, short_option, long_option,
+                                    error_context);
+  return exception_language;
+}
+
+static bool GetDefaultFile(ExecutionContext exe_ctx, FileSpec &file,
+                           std::string &error_msg) {
+  // First use the Source Manager's default file. Then use the current stack
+  // frame's file.
+  if (!exe_ctx.HasTargetScope()) {
+    error_msg = "Can't get a default file with no target.";
+    return false;
+  }
+  Target &target = exe_ctx.GetTargetRef();
+
+  if (auto maybe_file_and_line =
+          target.GetSourceManager().GetDefaultFileAndLine()) {
+    file = maybe_file_and_line->support_file_sp->GetSpecOnly();
+    return true;
+  }
+
+  StackFrame *cur_frame = exe_ctx.GetFramePtr();
+  if (cur_frame == nullptr) {
+    error_msg = "No selected frame to use to find the default file.";
+    return false;
+  }
+  if (!cur_frame->HasDebugInformation()) {
+    error_msg = "Cannot use the selected frame to find the default "
+                "file, it has no debug info.";
+    return false;
+  }
+
+  const SymbolContext &sc =
+      cur_frame->GetSymbolContext(eSymbolContextLineEntry);
+  if (sc.line_entry.GetFile()) {
+    file = sc.line_entry.GetFile();
+  } else {
+    error_msg = "Can't find the file for the selected frame to "
+                "use as the default file.";
+    return false;
+  }
+  return true;
+}
+
+static bool GetDefaultFile(ExecutionContext exe_ctx, FileSpec &file,
+                           CommandReturnObject &result) {
+  std::string error_msg;
+  if (!GetDefaultFile(exe_ctx, file, error_msg)) {
+    result.AppendError(error_msg);
+    return false;
+  }
+  return true;
+}
+
+static Status CompleteLineEntry(ExecutionContext &exe_ctx,
+                                OptionValueFileColonLine &line_entry) {
+  Status error;
+  uint32_t line_num = line_entry.GetLineNumber();
+  if (!line_entry.GetFileSpec()) {
+    FileSpec default_file_spec;
+    std::string error_msg;
+    if (!GetDefaultFile(exe_ctx, default_file_spec, error_msg)) {
+      error.FromErrorStringWithFormatv("Couldn't get default file for "
+                                       "line {0}: {1}",
+                                       line_num, error_msg);
+      return error;
+    }
+    line_entry.SetFile(default_file_spec);
+  }
+  return error;
+}
+
+class CommandObjectBreakpointAddAddress : public CommandObjectParsed {
+public:
+  CommandObjectBreakpointAddAddress(CommandInterpreter &interpreter)
+      : CommandObjectParsed(interpreter, "breakpoint add address",
+                            "Add breakpoints by raw address", nullptr) {
+    CommandArgumentData bp_id_arg;
+
+    // Define the first (and only) variant of this arg.
+    m_all_options.Append(&m_bp_opts, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+    m_all_options.Append(&m_name_opts);
+    m_all_options.Append(&m_dummy_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+    m_all_options.Append(&m_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+    m_all_options.Finalize();
+
+    AddSimpleArgumentList(eArgTypeAddress, eArgRepeatPlus);
+  }
+
+  ~CommandObjectBreakpointAddAddress() override = default;
+
+  Options *GetOptions() override { return &m_all_options; }
+
+  class CommandOptions : public OptionGroup {
+  public:
+    CommandOptions() = default;
+
+    ~CommandOptions() override = default;
+
+    Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+                          ExecutionContext *execution_context) override {
+      Status error;
+      const int short_option = GetDefinitions()[option_idx].short_option;
+      const char *long_option = GetDefinitions()[option_idx].long_option;
+
+      switch (short_option) {
+      case 'H':
+        m_hardware = true;
+        break;
+
+      case 's':
+        if (m_modules.GetSize() == 0)
+          m_modules.AppendIfUnique(FileSpec(option_arg));
+        else
+          error = Status::FromError(
+              CreateOptionParsingError(option_arg, short_option, long_option,
+                                       "Only one shared library can be "
+                                       "specified for address breakpoints."));
+        break;
+
+      default:
+        llvm_unreachable("Unimplemented option");
+      }
+
+      return error;
+    }
+
+    void OptionParsingStarting(ExecutionContext *execution_context) override {
+      m_hardware = false;
+      m_modules.Clear();
+    }
+
+    llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+      return llvm::ArrayRef(g_breakpoint_add_address_options);
+    }
+
+    // Instance variables to hold the values for command options.
+    bool m_hardware = false; // FIXME - this can go in the "modify" options.
+    FileSpecList m_modules;
+  };
+
+protected:
+  void DoExecute(Args &command, CommandReturnObject &result) override {
+    // We've already asserted that there can only be one entry in m_modules:
+    const ExecutionContext &exe_ctx = m_interpreter.GetExecutionContext();
+    // We don't set address breakpoints in the dummy target.
+    if (!exe_ctx.HasTargetScope() || exe_ctx.GetTargetPtr()->IsDummyTarget()) {
+      result.AppendError(
+          "can't set address breakpoints without a real target.");
+      return;
+    }
+    // Commands can't set internal breakpoints:
+    const bool internal = false;
+
+    Target &target = exe_ctx.GetTargetRef();
+
+    FileSpec module_spec;
+    bool has_module = false;
+    if (m_options.m_modules.GetSize() != 0) {
+      has_module = true;
+      module_spec = m_options.m_modules.GetFileSpecAtIndex(0);
+    }
+    BreakpointSP bp_sp;
+    // Let's process the arguments first so we can short-circuit if there are
+    // any errors:
+    std::vector<lldb::addr_t> bp_addrs;
+    for (const Args::ArgEntry &arg_entry : command) {
+      Address bp_address;
+      Status error;
+      lldb::addr_t bp_load_addr = OptionArgParser::ToAddress(
+          &exe_ctx, arg_entry.ref(), LLDB_INVALID_ADDRESS, &error);
+      if (error.Fail()) {
+        result.AppendErrorWithFormatv("invalid argument value '{0}': {1}",
+                                      arg_entry.ref(), error);
+        return;
+      }
+      bp_addrs.push_back(bp_load_addr);
+    }
+    for (auto bp_addr : bp_addrs) {
+      if (has_module)
+        bp_sp = target.CreateAddressInModuleBreakpoint(
+            bp_addr, internal, module_spec, m_options.m_hardware);
+      else
+        // ENHANCEMENT: we should see if bp_addr is in a single loaded module,
+        // and pass that module in if it is.
+        bp_sp =
+            target.CreateBreakpoint(bp_addr, internal, m_options.m_hardware);
+    }
+
+    if (bp_sp) {
+      CopyOverBreakpointOptions(bp_sp, m_bp_opts,
+                                m_name_opts.GetBreakpointNames(), result);
+      Stream &output_stream = result.GetOutputStream();
+      bp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial,
+                            /*show_locations=*/false);
+      result.SetStatus(eReturnStatusSuccessFinishResult);
+    } else {
+      result.AppendError("Breakpoint creation failed: No breakpoint created.");
+    }
+  }
+
+private:
+  BreakpointOptionGroup m_bp_opts;
+  BreakpointNamesOptionGroup m_name_opts;
+  BreakpointDummyOptionGroup m_dummy_options;
+  CommandOptions m_options;
+  OptionGroupOptions m_all_options;
+};
+
+#pragma mark AddException::CommandOptions
+#define LLDB_OPTIONS_breakpoint_add_exception
+#include "CommandOptions.inc"
+
+#pragma mark Add Exception
+
+class CommandObjectBreakpointAddException : public CommandObjectParsed {
+public:
+  CommandObjectBreakpointAddException(CommandInterpreter &interpreter)
+      : CommandObjectParsed(
+            interpreter, "breakpoint add exception",
+            "Add breakpoints on language exceptions.  If no language is "
+            "specified, break on exceptions for all supported languages",
+            nullptr) {
+    // Define the first (and only) variant of this arg.
+    AddSimpleArgumentList(eArgTypeLanguage, eArgRepeatStar);
+
+    // Next add all the options.
+    m_all_options.Append(&m_bp_opts, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+    m_all_options.Append(&m_name_opts);
+    m_all_options.Append(&m_dummy_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+    m_all_options.Append(&m_options);
+    m_all_options.Finalize();
+  }
+
+  ~CommandObjectBreakpointAddException() override = default;
+
+  Options *GetOptions() override { return &m_all_options; }
+
+  class CommandOptions : public OptionGroup {
+  public:
+    CommandOptions() = default;
+
+    ~CommandOptions() override = default;
+
+    Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+                          ExecutionContext *execution_context) override {
+      Status error;
+      const int short_option = GetDefinitions()[option_idx].short_option;
+
+      switch (short_option) {
+      case 'E': {
+        uint32_t this_val = (uint32_t)OptionArgParser::ToOptionEnum(
+            option_arg, GetDefinitions()[option_idx].enum_values,
+            eExceptionStageThrow, error);
+        if (error.Fail())
+          return error;
+        m_exception_stage |= this_val;
+      } break;
+      case 'H':
+        m_hardware = true;
+        break;
+
+      case 'O':
+        m_exception_extra_args.AppendArgument("-O");
+        m_exception_extra_args.AppendArgument(option_arg);
+        break;
+
+      default:
+        llvm_unreachable("Unimplemented option");
+      }
+
+      return error;
+    }
+
+    void OptionParsingStarting(ExecutionContext *execution_context) override {
+      m_hardware = false;
+      m_exception_extra_args.Clear();
+      m_exception_stage = eExceptionStageThrow;
+    }
+
+    llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+      return llvm::ArrayRef(g_breakpoint_add_exception_options);
+    }
+
+    // Instance variables to hold the values for command options.
+    bool m_hardware = false; // FIXME - this can go in the "modify" options.
+    Args m_exception_extra_args;
+    uint32_t m_exception_stage = eExceptionStageThrow;
+  };
+
+protected:
+  void DoExecute(Args &command, CommandReturnObject &result) override {
+    Target &target =
+        m_dummy_options.m_use_dummy ? GetDummyTarget() : GetTarget();
+    BreakpointSP bp_sp;
+    LanguageType exception_language = eLanguageTypeUnknown;
+
+    if (command.size() == 0) {
+      result.AppendError("no languages specified.");
+    } else if (command.size() > 1) {
+      result.AppendError(
+          "can only set exception breakpoints on one language at a time.");
+    } else {
+      llvm::Expected<LanguageType> language =
+          GetExceptionLanguageForLanguage(command[0].ref());
+      if (language)
+        exception_language = *language;
+      else {
+        result.SetError(language.takeError());
+        return;
+      }
+    }
+    Status precond_error;
+    const bool internal = false;
+    bool catch_bp = (m_options.m_exception_stage & eExceptionStageCatch) != 0;
+    bool throw_bp = (m_options.m_exception_stage & eExceptionStageThrow) != 0;
+    bp_sp = target.CreateExceptionBreakpoint(
+        exception_language, catch_bp, throw_bp, internal,
+        &m_options.m_exception_extra_args, &precond_error);
+    if (precond_error.Fail()) {
+      result.AppendErrorWithFormat(
+          "Error setting extra exception arguments: %s",
+          precond_error.AsCString());
+      target.RemoveBreakpointByID(bp_sp->GetID());
+      return;
+    }
+
+    if (bp_sp) {
+      CopyOverBreakpointOptions(bp_sp, m_bp_opts,
+                                m_name_opts.GetBreakpointNames(), result);
+      Stream &output_stream = result.GetOutputStream();
+      bp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial,
+                            /*show_locations=*/false);
+      // Note, we don't print a "got no locations" warning for exception
+      // breakpoints.  They can get set in the dummy target, and we won't know
+      // how to actually set the breakpoint till we know what version of the
+      // relevant LanguageRuntime gets loaded.
+      if (&target == &GetDummyTarget())
+        output_stream.Printf("Breakpoint set in dummy target, will get copied "
+                             "into future targets.\n");
+      result.SetStatus(eReturnStatusSuccessFinishResult);
+    } else {
+      result.AppendError("Breakpoint creation failed: No breakpoint created.");
+    }
+  }
+
+private:
+  BreakpointOptionGroup m_bp_opts;
+  BreakpointNamesOptionGroup m_name_opts;
+  BreakpointDummyOptionGroup m_dummy_options;
+  CommandOptions m_options;
+  OptionGroupOptions m_all_options;
+};
+
+#pragma mark AddFile::CommandOptions
+#define LLDB_OPTIONS_breakpoint_add_file
+#include "CommandOptions.inc"
+
+#pragma mark Add File
+
+class CommandObjectBreakpointAddFile : public CommandObjectParsed {
+public:
+  CommandObjectBreakpointAddFile(CommandInterpreter &interpreter)
+      : CommandObjectParsed(
+            interpreter, "breakpoint add file",
+            "Add breakpoints on lines in specified source files", nullptr) {
+    CommandArgumentEntry arg1;
+    CommandArgumentData linespec_arg;
+    CommandArgumentData no_arg;
+
+    // Any number of linespecs in group 1:
+    linespec_arg.arg_type = eArgTypeFileLineColumn;
+    linespec_arg.arg_repetition = eArgRepeatPlus;
+    linespec_arg.arg_opt_set_association = LLDB_OPT_SET_1;
+
+    arg1.push_back(linespec_arg);
+
+    // Leave arg2 empty, there are no arguments to this variant.
+    CommandArgumentEntry arg2;
+    no_arg.arg_type = eArgTypeNone;
+    no_arg.arg_repetition = eArgRepeatOptional;
+    no_arg.arg_opt_set_association = LLDB_OPT_SET_2;
+
+    arg2.push_back(linespec_arg);
+
+    // Push the data for the first argument into the m_arguments vector.
+    m_arguments.push_back(arg1);
+    m_arguments.push_back(arg2);
+
+    // Define the first (and only) variant of this arg.
+    m_all_options.Append(&m_bp_opts, LLDB_OPT_SET_ALL,
+                         LLDB_OPT_SET_1 | LLDB_OPT_SET_2);
+    m_all_options.Append(&m_name_opts);
+    m_all_options.Append(&m_dummy_options, LLDB_OPT_SET_ALL,
+                         LLDB_OPT_SET_1 | LLDB_OPT_SET_2);
+    m_all_options.Append(&m_options);
+    m_all_options.Finalize();
+  }
+
+  ~CommandObjectBreakpointAddFile() override = default;
+
+  Options *GetOptions() override { return &m_all_options; }
+
+  class CommandOptions : public OptionGroup {
+  public:
+    CommandOptions() = default;
+
+    ~CommandOptions() override = default;
+
+    Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+                          ExecutionContext *execution_context) override {
+      Status error;
+      const int short_option = GetDefinitions()[option_idx].short_option;
+      const char *long_option = GetDefinitions()[option_idx].long_option;
+
+      switch (short_option) {
+      case 'f':
+        m_cur_value.SetFile(FileSpec(option_arg));
+        break;
+      case 'l':
+        uint32_t line_num;
+        if (option_arg.getAsInteger(0, line_num))
+          error = Status::FromError(
+              CreateOptionParsingError(option_arg, short_option, long_option,
+                                       g_int_parsing_error_message));
+        else {
+          // The line number is the only required part of the options for a
+          // specifying the location - since we will fill in the file with the
+          // default file.  So when we see a new line, the old line entry we
+          // were building is done.  If we haven't gotten a file, try to fill
+          // in the default file, and then finish up this linespec and start
+          // the next one.
+          if (m_cur_value.GetLineNumber() != LLDB_INVALID_LINE_NUMBER) {
+            // FIXME: It should be possible to create a breakpoint with a list
+            // of file, line, column values.  But for now we can only create
+            // one, so return an error here.  The commented out code is what we
+            // will do when I come back to add that capability.
+            return Status::FromErrorString("Can only specify one file and line 
"
+                                           "pair at a time.");
+#if 0 // This code will be appropriate once we have a resolver that can take
+      // more than one linespec at a time.         
+            error = CompleteLineEntry(*execution_context, m_cur_value);
+            if (error.Fail())
+              return error;
+          
+            m_line_specs.push_back(m_cur_value);
+            m_cur_value.Clear();
+#endif
+          }
+          m_cur_value.SetLine(line_num);
+        }
+        break;
+      case 'c':
+        uint32_t column_num;
+        if (option_arg.getAsInteger(0, column_num))
+          error = Status::FromError(
+              CreateOptionParsingError(option_arg, short_option, long_option,
+                                       g_int_parsing_error_message));
+        else
+          m_cur_value.SetColumn(column_num);
+        break;
+      case 'K': {
+        bool success;
+        bool value;
+        value = OptionArgParser::ToBoolean(option_arg, true, &success);
+        if (value)
+          m_skip_prologue = eLazyBoolYes;
+        else
+          m_skip_prologue = eLazyBoolNo;
+
+        if (!success)
+          error = Status::FromError(
+              CreateOptionParsingError(option_arg, short_option, long_option,
+                                       g_bool_parsing_error_message));
+      } break;
+      case 'm': {
+        bool success;
+        bool value;
+        value = OptionArgParser::ToBoolean(option_arg, true, &success);
+        if (value)
+          m_move_to_nearest_code = eLazyBoolYes;
+        else
+          m_move_to_nearest_code = eLazyBoolNo;
+
+        if (!success)
+          error = Status::FromError(
+              CreateOptionParsingError(option_arg, short_option, long_option,
+                                       g_bool_parsing_error_message));
+      } break;
+      case 's':
+        m_modules.AppendIfUnique(FileSpec(option_arg));
+        break;
+      case 'H':
+        m_hardware = true;
+        break;
+      case 'S': {
+        lldb::addr_t tmp_offset_addr;
+        tmp_offset_addr = OptionArgParser::ToAddress(execution_context,
+                                                     option_arg, 0, &error);
+        if (error.Success())
+          m_offset_addr = tmp_offset_addr;
+      } break;
+
+      default:
+        llvm_unreachable("Unimplemented option");
+      }
+
+      return error;
+    }
+
+    void OptionParsingStarting(ExecutionContext *execution_context) override {
+      m_hardware = false;
+      m_line_specs.clear();
+      m_cur_value.Clear();
+      m_skip_prologue = eLazyBoolCalculate;
+      m_modules.Clear();
+      m_move_to_nearest_code = eLazyBoolCalculate;
+      m_offset_addr = 0;
+    }
+
+    Status OptionParsingFinished(ExecutionContext *execution_context) override 
{
+      // We were supplied at least a line from the options, so fill in the
+      // default file if needed.
+      if (m_cur_value.GetLineNumber() != LLDB_INVALID_LINE_NUMBER) {
+        Status error = CompleteLineEntry(*execution_context, m_cur_value);
+        if (error.Fail())
+          return error;
+        m_line_specs.push_back(m_cur_value);
+        m_cur_value.Clear();
+      }
+      return {};
+    }
+
+    llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+      return llvm::ArrayRef(g_breakpoint_add_file_options);
+    }
+
+    // Instance variables to hold the values for command options.
+    bool m_hardware = false; // FIXME - this can go in the "modify" options.
+    std::vector<OptionValueFileColonLine> m_line_specs;
+    LazyBool m_skip_prologue = eLazyBoolCalculate;
+    OptionValueFileColonLine m_cur_value;
+    FileSpecList m_modules;
+    LazyBool m_move_to_nearest_code = eLazyBoolCalculate;
+    lldb::addr_t m_offset_addr = 0;
+  };
+
+protected:
+  void DoExecute(Args &command, CommandReturnObject &result) override {
+    bool internal = false;
+    Target &target =
+        m_dummy_options.m_use_dummy ? GetDummyTarget() : GetTarget();
+    // FIXME: At present we can only make file & line breakpoints for one file
+    // and line pair. It wouldn't be hard to extend that, but I'm not adding
+    // features at this point so I'll leave that for a future patch.  For now,
+    // flag this as an error.
+
+    // I'm leaving this as a loop since that's how it should be when we can
+    // do more than one linespec at a time.
+    FileSpec default_file;
+    for (const Args::ArgEntry &this_arg : command) {
+      OptionValueFileColonLine value;
+      uint32_t line_value = LLDB_INVALID_LINE_NUMBER;
+      if (!this_arg.ref().getAsInteger(0, line_value)) {
+        // The argument is a plain number.  Treat that as a line number, and
+        // allow it if we can find a default file & line.
+        std::string error_msg;
+        if (!GetDefaultFile(m_exe_ctx, default_file, error_msg)) {
+          result.AppendErrorWithFormatv("Couldn't find default file for line "
+                                        "input: {0} - {1}",
+                                        line_value, error_msg);
+          return;
+        }
+        value.SetLine(line_value);
+        value.SetFile(default_file);
+      } else {
+        Status error = value.SetValueFromString(this_arg.c_str());
+        if (error.Fail()) {
+          result.AppendErrorWithFormatv("Failed to parse linespec: {0}", 
error);
+          return;
+        }
+      }
+      m_options.m_line_specs.push_back(value);
+    }
+
+    if (m_options.m_line_specs.size() != 1) {
+      result.AppendError("Can only make file and line breakpoints with one "
+                         "specification at a time.");
+      return;
+    }
+
+    BreakpointSP bp_sp;
+    // Only check for inline functions if
+    LazyBool check_inlines = eLazyBoolCalculate;
+
+    OptionValueFileColonLine &this_spec = m_options.m_line_specs[0];
+    bp_sp = target.CreateBreakpoint(
+        &(m_options.m_modules), this_spec.GetFileSpec(),
+        this_spec.GetLineNumber(), this_spec.GetColumnNumber(),
+        m_options.m_offset_addr, check_inlines, m_options.m_skip_prologue,
+        internal, m_options.m_hardware, m_options.m_move_to_nearest_code);
+
+    if (bp_sp) {
+      CopyOverBreakpointOptions(bp_sp, m_bp_opts,
+                                m_name_opts.GetBreakpointNames(), result);
+      Stream &output_stream = result.GetOutputStream();
+      bp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial,
+                            /*show_locations=*/false);
+      if (&target == &GetDummyTarget())
+        output_stream.Printf("Breakpoint set in dummy target, will get copied "
+                             "into future targets.\n");
+      else {
+        // Don't print out this warning for exception breakpoints.  They can
+        // get set before the target is set, but we won't know how to actually
+        // set the breakpoint till we run.
+        if (bp_sp->GetNumLocations() == 0) {
+          output_stream.Printf("WARNING:  Unable to resolve breakpoint to any "
+                               "actual locations.\n");
+        }
+      }
+      result.SetStatus(eReturnStatusSuccessFinishResult);
+    } else {
+      result.AppendError("Breakpoint creation failed: No breakpoint created.");
+    }
+  }
+
+private:
+  BreakpointOptionGroup m_bp_opts;
+  BreakpointNamesOptionGroup m_name_opts;
+  BreakpointDummyOptionGroup m_dummy_options;
+  CommandOptions m_options;
+  OptionGroupOptions m_all_options;
+};
+
+#pragma mark AddName::CommandOptions
+#define LLDB_OPTIONS_breakpoint_add_name
+#include "CommandOptions.inc"
+
+#pragma mark Add Name
+
+class CommandObjectBreakpointAddName : public CommandObjectParsed {
+public:
+  CommandObjectBreakpointAddName(CommandInterpreter &interpreter)
+      : CommandObjectParsed(interpreter, "breakpoint add name",
+                            "Add breakpoints matching function or symbol 
names",
+                            nullptr) {
+    // FIXME: Add a completer that's aware of the name match style.
+    // Define the first (and only) variant of this arg.
+    AddSimpleArgumentList(eArgTypeFunctionOrSymbol, eArgRepeatPlus);
+
+    // Now add all the options groups.
+    m_all_options.Append(&m_bp_opts, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+    m_all_options.Append(&m_name_opts);
+    m_all_options.Append(&m_dummy_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+    m_all_options.Append(&m_options);
+    m_all_options.Finalize();
+  }
+
+  ~CommandObjectBreakpointAddName() override = default;
+
+  Options *GetOptions() override { return &m_all_options; }
+
+  class CommandOptions : public OptionGroup {
+  public:
+    CommandOptions() = default;
+
+    ~CommandOptions() override = default;
+
+    Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+                          ExecutionContext *execution_context) override {
+      Status error;
+      const int short_option = GetDefinitions()[option_idx].short_option;
+      const char *long_option = GetDefinitions()[option_idx].long_option;
+
+      switch (short_option) {
+      case 'f':
+        m_files.AppendIfUnique(FileSpec(option_arg));
+        break;
+      case 'K': {
+        bool success;
+        bool value;
+        value = OptionArgParser::ToBoolean(option_arg, true, &success);
+        if (!success)
+          error = Status::FromError(
+              CreateOptionParsingError(option_arg, short_option, long_option,
+                                       g_bool_parsing_error_message));
+        else {
+          if (value)
+            m_skip_prologue = eLazyBoolYes;
+          else
+            m_skip_prologue = eLazyBoolNo;
+        }
+      } break;
+      case 'L': {
+        m_language = Language::GetLanguageTypeFromString(option_arg);
+        if (m_language == eLanguageTypeUnknown)
+          error = Status::FromError(
+              CreateOptionParsingError(option_arg, short_option, long_option,
+                                       g_language_parsing_error_message));
+      } break;
+      case 'm': {
+        uint32_t this_val = (uint32_t)OptionArgParser::ToOptionEnum(
+            option_arg, GetDefinitions()[option_idx].enum_values,
+            eNameMatchStyleAuto, error);
+        if (error.Fail())
+          return error;
+        m_lookup_style = (NameMatchStyle)this_val;
+      } break;
+      case 's':
+        m_modules.AppendIfUnique(FileSpec(option_arg));
+        break;
+      case 'H':
+        m_hardware = true;
+        break;
+      case 'S': {
+        lldb::addr_t tmp_offset_addr;
+        tmp_offset_addr = OptionArgParser::ToAddress(execution_context,
+                                                     option_arg, 0, &error);
+        if (error.Success())
+          m_offset_addr = tmp_offset_addr;
+      } break;
+
+      default:
+        llvm_unreachable("Unimplemented option");
+      }
+
+      return error;
+    }
+
+    void OptionParsingStarting(ExecutionContext *execution_context) override {
+      m_hardware = false;
+      m_skip_prologue = eLazyBoolCalculate;
+      m_files.Clear();
+      m_language = eLanguageTypeUnknown;
+      m_modules.Clear();
+      m_offset_addr = 0;
+      m_lookup_style = eNameMatchStyleAuto;
+    }
+
+    llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+      return llvm::ArrayRef(g_breakpoint_add_name_options);
+    }
+
+    // Instance variables to hold the values for command options.
+    bool m_hardware = false; // FIXME - this can go in the "modify" options.
+    LazyBool m_skip_prologue = eLazyBoolCalculate;
+    FileSpecList m_modules;
+    LanguageType m_language = eLanguageTypeUnknown;
+    FileSpecList m_files;
+    LazyBool m_move_to_nearest_code = eLazyBoolCalculate;
+    lldb::addr_t m_offset_addr = 0;
+    NameMatchStyle m_lookup_style = eNameMatchStyleAuto;
+  };
+
+protected:
+  void DoExecute(Args &command, CommandReturnObject &result) override {
+    const bool internal = false;
+    Target &target =
+        m_dummy_options.m_use_dummy ? GetDummyTarget() : GetTarget();
+    // Parse the argument list - this is a simple list of names.
+    std::vector<std::string> func_names;
+    for (const Args::ArgEntry &this_arg : command) {
+      func_names.push_back(this_arg.ref().str());
+    }
+    BreakpointSP bp_sp;
+    if (!(m_options.m_lookup_style & eNameMatchStyleRegex))
+      bp_sp = target.CreateBreakpoint(
+          &m_options.m_modules, &m_options.m_files, func_names,
+          (FunctionNameType)m_options.m_lookup_style, m_options.m_language,
+          m_options.m_offset_addr, m_options.m_skip_prologue, internal,
+          m_options.m_hardware);
+    else {
+      if (func_names.size() != 1) {
+        result.AppendError("Can only set function regular expression "
+                           "breakpoints on one regex at a time.");
+        return;
+      }
+      std::string &func_regexp = func_names[0];
+      RegularExpression regexp(func_regexp);
+      if (llvm::Error err = regexp.GetError()) {
+        result.AppendErrorWithFormat(
+            "Function name regular expression could not be compiled: %s",
+            llvm::toString(std::move(err)).c_str());
+        // Check if the incorrect regex looks like a globbing expression and
+        // warn the user about it.
+        if (!func_regexp.empty()) {
+          if (func_regexp[0] == '*' || func_regexp[0] == '?')
+            result.AppendWarning(
+                "Function name regex does not accept glob patterns.");
+        }
+        return;
+      }
+
+      bp_sp = target.CreateFuncRegexBreakpoint(
+          &(m_options.m_modules), &(m_options.m_files), std::move(regexp),
+          m_options.m_language, m_options.m_skip_prologue, internal,
+          m_options.m_hardware);
+    }
+    if (bp_sp) {
+      CopyOverBreakpointOptions(bp_sp, m_bp_opts,
+                                m_name_opts.GetBreakpointNames(), result);
+      Stream &output_stream = result.GetOutputStream();
+      bp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial,
+                            /*show_locations=*/false);
+      if (&target == &GetDummyTarget())
+        output_stream.Printf("Breakpoint set in dummy target, will get copied "
+                             "into future targets.\n");
+      else {
+        if (bp_sp->GetNumLocations() == 0) {
+          output_stream.Printf("WARNING:  Unable to resolve breakpoint to any "
+                               "actual locations.\n");
+        }
+      }
+      result.SetStatus(eReturnStatusSuccessFinishResult);
+    } else {
+      result.AppendError("Breakpoint creation failed: No breakpoint created.");
+    }
+  }
+
+private:
+  BreakpointOptionGroup m_bp_opts;
+  BreakpointNamesOptionGroup m_name_opts;
+  BreakpointDummyOptionGroup m_dummy_options;
+  CommandOptions m_options;
+  OptionGroupOptions m_all_options;
+};
+
+#pragma mark AddPattern::CommandOptions
+#define LLDB_OPTIONS_breakpoint_add_pattern
+#include "CommandOptions.inc"
+
+#pragma mark Add Pattern
+
+class CommandObjectBreakpointAddPattern : public CommandObjectRaw {
 public:
-  BreakpointDummyOptionGroup() = default;
+  CommandObjectBreakpointAddPattern(CommandInterpreter &interpreter)
+      : CommandObjectRaw(interpreter, "breakpoint add pattern",
+                         "Add breakpoints matching patterns in the source 
text",
+                         "breakpoint add pattern [options] -- <pattern>") {
+    AddSimpleArgumentList(eArgTypeRegularExpression, eArgRepeatPlain);
+    // Now add all the options groups.
+    m_all_options.Append(&m_bp_opts, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+    m_all_options.Append(&m_name_opts);
+    m_all_options.Append(&m_dummy_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+    m_all_options.Append(&m_options);
+    m_all_options.Finalize();
+  }
 
-  ~BreakpointDummyOptionGroup() override = default;
+  ~CommandObjectBreakpointAddPattern() override = default;
 
-  llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
-    return llvm::ArrayRef(g_breakpoint_dummy_options);
-  }
+  Options *GetOptions() override { return &m_all_options; }
 
-  Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
-                        ExecutionContext *execution_context) override {
-    Status error;
-    const int short_option =
-        g_breakpoint_dummy_options[option_idx].short_option;
+  class CommandOptions : public OptionGroup {
+  public:
+    CommandOptions() = default;
 
-    switch (short_option) {
-    case 'D':
-      m_use_dummy = true;
-      break;
-    default:
-      llvm_unreachable("Unimplemented option");
+    ~CommandOptions() override = default;
+
+    Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+                          ExecutionContext *execution_context) override {
+      Status error;
+      const int short_option = GetDefinitions()[option_idx].short_option;
+      const char *long_option = GetDefinitions()[option_idx].long_option;
+
+      switch (short_option) {
+      case 'a': {
+        bool success;
+        bool value;
+        value = OptionArgParser::ToBoolean(option_arg, true, &success);
+        if (!success)
+          error = Status::FromError(
+              CreateOptionParsingError(option_arg, short_option, long_option,
+                                       g_bool_parsing_error_message));
+        else
+          m_all_files = value;
+      } break;
+      case 'f':
+        m_files.AppendIfUnique(FileSpec(option_arg));
+        break;
+      case 'm': {
+        bool success;
+        bool value;
+        value = OptionArgParser::ToBoolean(option_arg, true, &success);
+        if (!success)
+          error = Status::FromError(
+              CreateOptionParsingError(option_arg, short_option, long_option,
+                                       g_bool_parsing_error_message));
+        else {
+          if (value)
+            m_move_to_nearest_code = eLazyBoolYes;
+          else
+            m_move_to_nearest_code = eLazyBoolNo;
+        }
+      } break;
+      case 'n':
+        m_func_names.insert(option_arg.str());
+        break;
+      case 's':
+        m_modules.AppendIfUnique(FileSpec(option_arg));
+        break;
+      case 'H':
+        m_hardware = true;
+        break;
+      default:
+        llvm_unreachable("Unimplemented option");
+      }
+
+      return error;
     }
 
-    return error;
+    void OptionParsingStarting(ExecutionContext *execution_context) override {
+      m_hardware = false;
+      m_skip_prologue = eLazyBoolCalculate;
+      m_modules.Clear();
+      m_files.Clear();
+      m_func_names.clear();
+      m_all_files = false;
+      m_move_to_nearest_code = eLazyBoolCalculate;
+    }
+
+    llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
+      return llvm::ArrayRef(g_breakpoint_add_pattern_options);
+    }
+
+    // Instance variables to hold the values for command options.
+    bool m_hardware = false; // FIXME - this can go in the "modify" options.
+    LazyBool m_skip_prologue = eLazyBoolCalculate;
+    FileSpecList m_modules;
+    FileSpecList m_files;
+    std::unordered_set<std::string> m_func_names;
+    bool m_all_files = false;
+    LazyBool m_move_to_nearest_code = eLazyBoolCalculate;
+  };
+
+protected:
+  void DoExecute(llvm::StringRef command,
+                 CommandReturnObject &result) override {
+    const bool internal = false;
+    ExecutionContext exe_ctx = GetCommandInterpreter().GetExecutionContext();
+    Target &target =
+        m_dummy_options.m_use_dummy ? GetDummyTarget() : GetTarget();
+    m_all_options.NotifyOptionParsingStarting(&exe_ctx);
+
+    if (command.empty()) {
+      result.AppendError("no pattern to seek.");
+      return;
+    }
+
+    OptionsWithRaw args(command);
+    llvm::StringRef expr = args.GetRawPart();
+
+    if (args.HasArgs()) {
+      if (!ParseOptionsAndNotify(args.GetArgs(), result, m_all_options,
+                                 exe_ctx))
+        return;
+    }
+    llvm::StringRef pattern = args.GetRawPart();
+    if (pattern.empty()) {
+      result.AppendError("no pattern to seek");
+      return;
+    }
+    printf("Pattern: '%s'\n", pattern.str().c_str());
+
+    BreakpointSP bp_sp;
+    const size_t num_files = m_options.m_files.GetSize();
+
+    if (num_files == 0 && !m_options.m_all_files) {
+      FileSpec file;
+      if (!GetDefaultFile(m_exe_ctx, file, result)) {
+        result.AppendError(
+            "No files provided and could not find default file.");
+        return;
+      } else {
+        m_options.m_files.Append(file);
+      }
+    }
+
+    RegularExpression regexp(pattern);
+    if (llvm::Error err = regexp.GetError()) {
+      result.AppendErrorWithFormat(
+          "Source text regular expression could not be compiled: \"%s\"",
+          llvm::toString(std::move(err)).c_str());
+      return;
+    }
+    bp_sp = target.CreateSourceRegexBreakpoint(
+        &(m_options.m_modules), &(m_options.m_files), m_options.m_func_names,
+        std::move(regexp), internal, m_options.m_hardware,
+        m_options.m_move_to_nearest_code);
+
+    if (bp_sp) {
+      CopyOverBreakpointOptions(bp_sp, m_bp_opts,
+                                m_name_opts.GetBreakpointNames(), result);
+      Stream &output_stream = result.GetOutputStream();
+      bp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial,
+                            /*show_locations=*/false);
+      if (&target == &GetDummyTarget())
+        output_stream.Printf("Breakpoint set in dummy target, will get copied "
+                             "into future targets.\n");
+      else {
+        // Don't print out this warning for exception breakpoints.  They can
----------------
jimingham wrote:

There are always two spaces after a period.

https://github.com/llvm/llvm-project/pull/156067
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to