130fdc8d8SChris Lattner //===-- CommandObjectBreakpoint.cpp -----------------------------*- C++ -*-===//
230fdc8d8SChris Lattner //
330fdc8d8SChris Lattner //                     The LLVM Compiler Infrastructure
430fdc8d8SChris Lattner //
530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source
630fdc8d8SChris Lattner // License. See LICENSE.TXT for details.
730fdc8d8SChris Lattner //
830fdc8d8SChris Lattner //===----------------------------------------------------------------------===//
930fdc8d8SChris Lattner 
1030fdc8d8SChris Lattner // C Includes
1130fdc8d8SChris Lattner // C++ Includes
129e85e5a8SEugene Zelenko #include <vector>
139e85e5a8SEugene Zelenko 
1430fdc8d8SChris Lattner // Other libraries and framework includes
1530fdc8d8SChris Lattner // Project includes
169e85e5a8SEugene Zelenko #include "CommandObjectBreakpoint.h"
179e85e5a8SEugene Zelenko #include "CommandObjectBreakpointCommand.h"
1830fdc8d8SChris Lattner #include "lldb/Breakpoint/Breakpoint.h"
1930fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointIDList.h"
2030fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointLocation.h"
21b9c1b51eSKate Stone #include "lldb/Core/RegularExpression.h"
22b9c1b51eSKate Stone #include "lldb/Core/StreamString.h"
235275aaa0SVince Harron #include "lldb/Host/StringConvert.h"
24b9c1b51eSKate Stone #include "lldb/Interpreter/CommandCompletions.h"
25b9c1b51eSKate Stone #include "lldb/Interpreter/CommandInterpreter.h"
26b9c1b51eSKate Stone #include "lldb/Interpreter/CommandReturnObject.h"
2732abc6edSZachary Turner #include "lldb/Interpreter/OptionValueBoolean.h"
285e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueString.h"
295e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueUInt64.h"
30b9c1b51eSKate Stone #include "lldb/Interpreter/Options.h"
310e0984eeSJim Ingham #include "lldb/Target/Language.h"
32b57e4a1bSJason Molenda #include "lldb/Target/StackFrame.h"
33b9c1b51eSKate Stone #include "lldb/Target/Target.h"
341b54c88cSJim Ingham #include "lldb/Target/Thread.h"
351b54c88cSJim Ingham #include "lldb/Target/ThreadSpec.h"
3630fdc8d8SChris Lattner 
3730fdc8d8SChris Lattner using namespace lldb;
3830fdc8d8SChris Lattner using namespace lldb_private;
3930fdc8d8SChris Lattner 
40b9c1b51eSKate Stone static void AddBreakpointDescription(Stream *s, Breakpoint *bp,
41b9c1b51eSKate Stone                                      lldb::DescriptionLevel level) {
4230fdc8d8SChris Lattner   s->IndentMore();
4330fdc8d8SChris Lattner   bp->GetDescription(s, level, true);
4430fdc8d8SChris Lattner   s->IndentLess();
4530fdc8d8SChris Lattner   s->EOL();
4630fdc8d8SChris Lattner }
4730fdc8d8SChris Lattner 
4830fdc8d8SChris Lattner //-------------------------------------------------------------------------
495a988416SJim Ingham // CommandObjectBreakpointSet
5030fdc8d8SChris Lattner //-------------------------------------------------------------------------
5130fdc8d8SChris Lattner 
52b9c1b51eSKate Stone class CommandObjectBreakpointSet : public CommandObjectParsed {
535a988416SJim Ingham public:
54b9c1b51eSKate Stone   typedef enum BreakpointSetType {
555a988416SJim Ingham     eSetTypeInvalid,
565a988416SJim Ingham     eSetTypeFileAndLine,
575a988416SJim Ingham     eSetTypeAddress,
585a988416SJim Ingham     eSetTypeFunctionName,
595a988416SJim Ingham     eSetTypeFunctionRegexp,
605a988416SJim Ingham     eSetTypeSourceRegexp,
615a988416SJim Ingham     eSetTypeException
625a988416SJim Ingham   } BreakpointSetType;
635a988416SJim Ingham 
64b9c1b51eSKate Stone   CommandObjectBreakpointSet(CommandInterpreter &interpreter)
65b9c1b51eSKate Stone       : CommandObjectParsed(
66b9c1b51eSKate Stone             interpreter, "breakpoint set",
675a988416SJim Ingham             "Sets a breakpoint or set of breakpoints in the executable.",
685a988416SJim Ingham             "breakpoint set <cmd-options>"),
69b9c1b51eSKate Stone         m_options() {}
705a988416SJim Ingham 
719e85e5a8SEugene Zelenko   ~CommandObjectBreakpointSet() override = default;
725a988416SJim Ingham 
73b9c1b51eSKate Stone   Options *GetOptions() override { return &m_options; }
745a988416SJim Ingham 
75b9c1b51eSKate Stone   class CommandOptions : public Options {
765a988416SJim Ingham   public:
77b9c1b51eSKate Stone     CommandOptions()
78b9c1b51eSKate Stone         : Options(), m_condition(), m_filenames(), m_line_num(0), m_column(0),
79b9c1b51eSKate Stone           m_func_names(), m_func_name_type_mask(eFunctionNameTypeNone),
80b9c1b51eSKate Stone           m_func_regexp(), m_source_text_regexp(), m_modules(), m_load_addr(),
81b9c1b51eSKate Stone           m_ignore_count(0), m_thread_id(LLDB_INVALID_THREAD_ID),
82b9c1b51eSKate Stone           m_thread_index(UINT32_MAX), m_thread_name(), m_queue_name(),
83b9c1b51eSKate Stone           m_catch_bp(false), m_throw_bp(true), m_hardware(false),
84a72b31c7SJim Ingham           m_exception_language(eLanguageTypeUnknown),
8523b1decbSDawn Perchik           m_language(lldb::eLanguageTypeUnknown),
86b9c1b51eSKate Stone           m_skip_prologue(eLazyBoolCalculate), m_one_shot(false),
87b9c1b51eSKate Stone           m_all_files(false), m_move_to_nearest_code(eLazyBoolCalculate) {}
8830fdc8d8SChris Lattner 
899e85e5a8SEugene Zelenko     ~CommandOptions() override = default;
9087df91b8SJim Ingham 
91b9c1b51eSKate Stone     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
92b9c1b51eSKate Stone                          ExecutionContext *execution_context) override {
9330fdc8d8SChris Lattner       Error error;
943bcdfc0eSGreg Clayton       const int short_option = m_getopt_table[option_idx].val;
956fa7681bSZachary Turner       llvm::StringRef option_strref(option_arg ? option_arg : "");
9630fdc8d8SChris Lattner 
97b9c1b51eSKate Stone       switch (short_option) {
98b9c1b51eSKate Stone       case 'a': {
99b9c1b51eSKate Stone         m_load_addr = Args::StringToAddress(execution_context, option_arg,
100e1cfbc79STodd Fiala                                             LLDB_INVALID_ADDRESS, &error);
101b9c1b51eSKate Stone       } break;
10230fdc8d8SChris Lattner 
103e732052fSJim Ingham       case 'A':
104e732052fSJim Ingham         m_all_files = true;
105e732052fSJim Ingham         break;
106e732052fSJim Ingham 
107ca36cd16SJim Ingham       case 'b':
108ca36cd16SJim Ingham         m_func_names.push_back(option_arg);
109ca36cd16SJim Ingham         m_func_name_type_mask |= eFunctionNameTypeBase;
110ca36cd16SJim Ingham         break;
111ca36cd16SJim Ingham 
112b9c1b51eSKate Stone       case 'C': {
1136312991cSJim Ingham         bool success;
1146312991cSJim Ingham         m_column = StringConvert::ToUInt32(option_arg, 0, 0, &success);
1156312991cSJim Ingham         if (!success)
116b9c1b51eSKate Stone           error.SetErrorStringWithFormat("invalid column number: %s",
117b9c1b51eSKate Stone                                          option_arg);
11830fdc8d8SChris Lattner         break;
1196312991cSJim Ingham       }
1209e85e5a8SEugene Zelenko 
1217d49c9c8SJohnny Chen       case 'c':
1227d49c9c8SJohnny Chen         m_condition.assign(option_arg);
1237d49c9c8SJohnny Chen         break;
1247d49c9c8SJohnny Chen 
12533df7cd3SJim Ingham       case 'D':
12633df7cd3SJim Ingham         m_use_dummy = true;
12733df7cd3SJim Ingham         break;
12833df7cd3SJim Ingham 
129b9c1b51eSKate Stone       case 'E': {
1300e0984eeSJim Ingham         LanguageType language = Language::GetLanguageTypeFromString(option_arg);
131fab10e89SJim Ingham 
132b9c1b51eSKate Stone         switch (language) {
133fab10e89SJim Ingham         case eLanguageTypeC89:
134fab10e89SJim Ingham         case eLanguageTypeC:
135fab10e89SJim Ingham         case eLanguageTypeC99:
1361d0089faSBruce Mitchener         case eLanguageTypeC11:
137a72b31c7SJim Ingham           m_exception_language = eLanguageTypeC;
138fab10e89SJim Ingham           break;
139fab10e89SJim Ingham         case eLanguageTypeC_plus_plus:
1401d0089faSBruce Mitchener         case eLanguageTypeC_plus_plus_03:
1411d0089faSBruce Mitchener         case eLanguageTypeC_plus_plus_11:
1422ba84a6aSBruce Mitchener         case eLanguageTypeC_plus_plus_14:
143a72b31c7SJim Ingham           m_exception_language = eLanguageTypeC_plus_plus;
144fab10e89SJim Ingham           break;
145fab10e89SJim Ingham         case eLanguageTypeObjC:
146a72b31c7SJim Ingham           m_exception_language = eLanguageTypeObjC;
147fab10e89SJim Ingham           break;
148fab10e89SJim Ingham         case eLanguageTypeObjC_plus_plus:
149b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
150b9c1b51eSKate Stone               "Set exception breakpoints separately for c++ and objective-c");
151fab10e89SJim Ingham           break;
152fab10e89SJim Ingham         case eLanguageTypeUnknown:
153b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
154b9c1b51eSKate Stone               "Unknown language type: '%s' for exception breakpoint",
155b9c1b51eSKate Stone               option_arg);
156fab10e89SJim Ingham           break;
157fab10e89SJim Ingham         default:
158b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
159b9c1b51eSKate Stone               "Unsupported language type: '%s' for exception breakpoint",
160b9c1b51eSKate Stone               option_arg);
161fab10e89SJim Ingham         }
162b9c1b51eSKate Stone       } break;
163ca36cd16SJim Ingham 
164ca36cd16SJim Ingham       case 'f':
165ca36cd16SJim Ingham         m_filenames.AppendIfUnique(FileSpec(option_arg, false));
166fab10e89SJim Ingham         break;
167ca36cd16SJim Ingham 
168ca36cd16SJim Ingham       case 'F':
169ca36cd16SJim Ingham         m_func_names.push_back(option_arg);
170ca36cd16SJim Ingham         m_func_name_type_mask |= eFunctionNameTypeFull;
171ca36cd16SJim Ingham         break;
172ca36cd16SJim Ingham 
173b9c1b51eSKate Stone       case 'h': {
174fab10e89SJim Ingham         bool success;
175*ecbb0bb1SZachary Turner         m_catch_bp = Args::StringToBoolean(option_strref, true, &success);
176fab10e89SJim Ingham         if (!success)
177b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
178b9c1b51eSKate Stone               "Invalid boolean value for on-catch option: '%s'", option_arg);
179b9c1b51eSKate Stone       } break;
180eb023e75SGreg Clayton 
181eb023e75SGreg Clayton       case 'H':
182eb023e75SGreg Clayton         m_hardware = true;
183eb023e75SGreg Clayton         break;
184eb023e75SGreg Clayton 
185ca36cd16SJim Ingham       case 'i':
1865275aaa0SVince Harron         m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
187ca36cd16SJim Ingham         if (m_ignore_count == UINT32_MAX)
188b9c1b51eSKate Stone           error.SetErrorStringWithFormat("invalid ignore count '%s'",
189b9c1b51eSKate Stone                                          option_arg);
190ca36cd16SJim Ingham         break;
191ca36cd16SJim Ingham 
192b9c1b51eSKate Stone       case 'K': {
193a8558b62SJim Ingham         bool success;
194a8558b62SJim Ingham         bool value;
195*ecbb0bb1SZachary Turner         value = Args::StringToBoolean(option_strref, true, &success);
196a8558b62SJim Ingham         if (value)
197a8558b62SJim Ingham           m_skip_prologue = eLazyBoolYes;
198a8558b62SJim Ingham         else
199a8558b62SJim Ingham           m_skip_prologue = eLazyBoolNo;
200a8558b62SJim Ingham 
201a8558b62SJim Ingham         if (!success)
202b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
203b9c1b51eSKate Stone               "Invalid boolean value for skip prologue option: '%s'",
204b9c1b51eSKate Stone               option_arg);
205b9c1b51eSKate Stone       } break;
206ca36cd16SJim Ingham 
207b9c1b51eSKate Stone       case 'l': {
2086312991cSJim Ingham         bool success;
2096312991cSJim Ingham         m_line_num = StringConvert::ToUInt32(option_arg, 0, 0, &success);
2106312991cSJim Ingham         if (!success)
211b9c1b51eSKate Stone           error.SetErrorStringWithFormat("invalid line number: %s.",
212b9c1b51eSKate Stone                                          option_arg);
213ca36cd16SJim Ingham         break;
2146312991cSJim Ingham       }
215055ad9beSIlia K 
21623b1decbSDawn Perchik       case 'L':
2170e0984eeSJim Ingham         m_language = Language::GetLanguageTypeFromString(option_arg);
21823b1decbSDawn Perchik         if (m_language == eLanguageTypeUnknown)
219b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
220b9c1b51eSKate Stone               "Unknown language type: '%s' for breakpoint", option_arg);
22123b1decbSDawn Perchik         break;
22223b1decbSDawn Perchik 
223b9c1b51eSKate Stone       case 'm': {
224055ad9beSIlia K         bool success;
225055ad9beSIlia K         bool value;
226*ecbb0bb1SZachary Turner         value = Args::StringToBoolean(option_strref, true, &success);
227055ad9beSIlia K         if (value)
228055ad9beSIlia K           m_move_to_nearest_code = eLazyBoolYes;
229055ad9beSIlia K         else
230055ad9beSIlia K           m_move_to_nearest_code = eLazyBoolNo;
231055ad9beSIlia K 
232055ad9beSIlia K         if (!success)
233b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
234b9c1b51eSKate Stone               "Invalid boolean value for move-to-nearest-code option: '%s'",
235b9c1b51eSKate Stone               option_arg);
236055ad9beSIlia K         break;
237055ad9beSIlia K       }
238055ad9beSIlia K 
239ca36cd16SJim Ingham       case 'M':
240ca36cd16SJim Ingham         m_func_names.push_back(option_arg);
241ca36cd16SJim Ingham         m_func_name_type_mask |= eFunctionNameTypeMethod;
242ca36cd16SJim Ingham         break;
243ca36cd16SJim Ingham 
244ca36cd16SJim Ingham       case 'n':
245ca36cd16SJim Ingham         m_func_names.push_back(option_arg);
246ca36cd16SJim Ingham         m_func_name_type_mask |= eFunctionNameTypeAuto;
247ca36cd16SJim Ingham         break;
248ca36cd16SJim Ingham 
2496fa7681bSZachary Turner       case 'N': {
2506fa7681bSZachary Turner         if (BreakpointID::StringIsBreakpointName(option_strref, error))
2515e09c8c3SJim Ingham           m_breakpoint_names.push_back(option_arg);
2525e09c8c3SJim Ingham         break;
2536fa7681bSZachary Turner       }
2545e09c8c3SJim Ingham 
255b9c1b51eSKate Stone       case 'R': {
2562411167fSJim Ingham         lldb::addr_t tmp_offset_addr;
257e1cfbc79STodd Fiala         tmp_offset_addr =
258b9c1b51eSKate Stone             Args::StringToAddress(execution_context, option_arg, 0, &error);
2592411167fSJim Ingham         if (error.Success())
2602411167fSJim Ingham           m_offset_addr = tmp_offset_addr;
261b9c1b51eSKate Stone       } break;
2622411167fSJim Ingham 
263ca36cd16SJim Ingham       case 'o':
264ca36cd16SJim Ingham         m_one_shot = true;
265ca36cd16SJim Ingham         break;
266ca36cd16SJim Ingham 
267a72b31c7SJim Ingham       case 'O':
268*ecbb0bb1SZachary Turner         m_exception_extra_args.AppendArgument(llvm::StringRef("-O"));
269*ecbb0bb1SZachary Turner         m_exception_extra_args.AppendArgument(option_strref);
270a72b31c7SJim Ingham         break;
271a72b31c7SJim Ingham 
272ca36cd16SJim Ingham       case 'p':
273ca36cd16SJim Ingham         m_source_text_regexp.assign(option_arg);
274ca36cd16SJim Ingham         break;
275ca36cd16SJim Ingham 
276ca36cd16SJim Ingham       case 'q':
277ca36cd16SJim Ingham         m_queue_name.assign(option_arg);
278ca36cd16SJim Ingham         break;
279ca36cd16SJim Ingham 
280ca36cd16SJim Ingham       case 'r':
281ca36cd16SJim Ingham         m_func_regexp.assign(option_arg);
282ca36cd16SJim Ingham         break;
283ca36cd16SJim Ingham 
284ca36cd16SJim Ingham       case 's':
285ca36cd16SJim Ingham         m_modules.AppendIfUnique(FileSpec(option_arg, false));
286ca36cd16SJim Ingham         break;
287ca36cd16SJim Ingham 
288ca36cd16SJim Ingham       case 'S':
289ca36cd16SJim Ingham         m_func_names.push_back(option_arg);
290ca36cd16SJim Ingham         m_func_name_type_mask |= eFunctionNameTypeSelector;
291ca36cd16SJim Ingham         break;
292ca36cd16SJim Ingham 
293ca36cd16SJim Ingham       case 't':
294b9c1b51eSKate Stone         m_thread_id =
295b9c1b51eSKate Stone             StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
296ca36cd16SJim Ingham         if (m_thread_id == LLDB_INVALID_THREAD_ID)
297b9c1b51eSKate Stone           error.SetErrorStringWithFormat("invalid thread id string '%s'",
298b9c1b51eSKate Stone                                          option_arg);
299ca36cd16SJim Ingham         break;
300ca36cd16SJim Ingham 
301ca36cd16SJim Ingham       case 'T':
302ca36cd16SJim Ingham         m_thread_name.assign(option_arg);
303ca36cd16SJim Ingham         break;
304ca36cd16SJim Ingham 
305b9c1b51eSKate Stone       case 'w': {
306ca36cd16SJim Ingham         bool success;
307*ecbb0bb1SZachary Turner         m_throw_bp = Args::StringToBoolean(option_strref, true, &success);
308ca36cd16SJim Ingham         if (!success)
309b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
310b9c1b51eSKate Stone               "Invalid boolean value for on-throw option: '%s'", option_arg);
311b9c1b51eSKate Stone       } break;
312ca36cd16SJim Ingham 
313ca36cd16SJim Ingham       case 'x':
3145275aaa0SVince Harron         m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
315ca36cd16SJim Ingham         if (m_thread_id == UINT32_MAX)
316b9c1b51eSKate Stone           error.SetErrorStringWithFormat("invalid thread index string '%s'",
317b9c1b51eSKate Stone                                          option_arg);
318ca36cd16SJim Ingham         break;
319ca36cd16SJim Ingham 
32076bb8d67SJim Ingham       case 'X':
32176bb8d67SJim Ingham         m_source_regex_func_names.insert(option_arg);
32276bb8d67SJim Ingham         break;
32376bb8d67SJim Ingham 
32430fdc8d8SChris Lattner       default:
325b9c1b51eSKate Stone         error.SetErrorStringWithFormat("unrecognized option '%c'",
326b9c1b51eSKate Stone                                        short_option);
32730fdc8d8SChris Lattner         break;
32830fdc8d8SChris Lattner       }
32930fdc8d8SChris Lattner 
33030fdc8d8SChris Lattner       return error;
33130fdc8d8SChris Lattner     }
3329e85e5a8SEugene Zelenko 
333b9c1b51eSKate Stone     void OptionParsingStarting(ExecutionContext *execution_context) override {
3347d49c9c8SJohnny Chen       m_condition.clear();
33587df91b8SJim Ingham       m_filenames.Clear();
33630fdc8d8SChris Lattner       m_line_num = 0;
33730fdc8d8SChris Lattner       m_column = 0;
338fab10e89SJim Ingham       m_func_names.clear();
3391f746071SGreg Clayton       m_func_name_type_mask = eFunctionNameTypeNone;
34030fdc8d8SChris Lattner       m_func_regexp.clear();
3411f746071SGreg Clayton       m_source_text_regexp.clear();
34287df91b8SJim Ingham       m_modules.Clear();
3431f746071SGreg Clayton       m_load_addr = LLDB_INVALID_ADDRESS;
3442411167fSJim Ingham       m_offset_addr = 0;
345c982c768SGreg Clayton       m_ignore_count = 0;
3461b54c88cSJim Ingham       m_thread_id = LLDB_INVALID_THREAD_ID;
347c982c768SGreg Clayton       m_thread_index = UINT32_MAX;
3481b54c88cSJim Ingham       m_thread_name.clear();
3491b54c88cSJim Ingham       m_queue_name.clear();
350fab10e89SJim Ingham       m_catch_bp = false;
351fab10e89SJim Ingham       m_throw_bp = true;
352eb023e75SGreg Clayton       m_hardware = false;
353a72b31c7SJim Ingham       m_exception_language = eLanguageTypeUnknown;
35423b1decbSDawn Perchik       m_language = lldb::eLanguageTypeUnknown;
355a8558b62SJim Ingham       m_skip_prologue = eLazyBoolCalculate;
356ca36cd16SJim Ingham       m_one_shot = false;
35733df7cd3SJim Ingham       m_use_dummy = false;
3585e09c8c3SJim Ingham       m_breakpoint_names.clear();
359e732052fSJim Ingham       m_all_files = false;
360a72b31c7SJim Ingham       m_exception_extra_args.Clear();
361055ad9beSIlia K       m_move_to_nearest_code = eLazyBoolCalculate;
36276bb8d67SJim Ingham       m_source_regex_func_names.clear();
36330fdc8d8SChris Lattner     }
36430fdc8d8SChris Lattner 
365b9c1b51eSKate Stone     const OptionDefinition *GetDefinitions() override { return g_option_table; }
36630fdc8d8SChris Lattner 
3675a988416SJim Ingham     // Options table: Required for subclasses of Options.
36830fdc8d8SChris Lattner 
3695a988416SJim Ingham     static OptionDefinition g_option_table[];
37030fdc8d8SChris Lattner 
3715a988416SJim Ingham     // Instance variables to hold the values for command options.
372969795f1SJim Ingham 
3735a988416SJim Ingham     std::string m_condition;
3745a988416SJim Ingham     FileSpecList m_filenames;
3755a988416SJim Ingham     uint32_t m_line_num;
3765a988416SJim Ingham     uint32_t m_column;
3775a988416SJim Ingham     std::vector<std::string> m_func_names;
3785e09c8c3SJim Ingham     std::vector<std::string> m_breakpoint_names;
3795a988416SJim Ingham     uint32_t m_func_name_type_mask;
3805a988416SJim Ingham     std::string m_func_regexp;
3815a988416SJim Ingham     std::string m_source_text_regexp;
3825a988416SJim Ingham     FileSpecList m_modules;
3835a988416SJim Ingham     lldb::addr_t m_load_addr;
3842411167fSJim Ingham     lldb::addr_t m_offset_addr;
3855a988416SJim Ingham     uint32_t m_ignore_count;
3865a988416SJim Ingham     lldb::tid_t m_thread_id;
3875a988416SJim Ingham     uint32_t m_thread_index;
3885a988416SJim Ingham     std::string m_thread_name;
3895a988416SJim Ingham     std::string m_queue_name;
3905a988416SJim Ingham     bool m_catch_bp;
3915a988416SJim Ingham     bool m_throw_bp;
392eb023e75SGreg Clayton     bool m_hardware; // Request to use hardware breakpoints
393a72b31c7SJim Ingham     lldb::LanguageType m_exception_language;
39423b1decbSDawn Perchik     lldb::LanguageType m_language;
3955a988416SJim Ingham     LazyBool m_skip_prologue;
396ca36cd16SJim Ingham     bool m_one_shot;
39733df7cd3SJim Ingham     bool m_use_dummy;
398e732052fSJim Ingham     bool m_all_files;
399a72b31c7SJim Ingham     Args m_exception_extra_args;
400055ad9beSIlia K     LazyBool m_move_to_nearest_code;
40176bb8d67SJim Ingham     std::unordered_set<std::string> m_source_regex_func_names;
4025a988416SJim Ingham   };
4035a988416SJim Ingham 
4045a988416SJim Ingham protected:
405b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
40633df7cd3SJim Ingham     Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
40733df7cd3SJim Ingham 
408b9c1b51eSKate Stone     if (target == nullptr) {
409b9c1b51eSKate Stone       result.AppendError("Invalid target.  Must set target before setting "
410b9c1b51eSKate Stone                          "breakpoints (see 'target create' command).");
41130fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
41230fdc8d8SChris Lattner       return false;
41330fdc8d8SChris Lattner     }
41430fdc8d8SChris Lattner 
41530fdc8d8SChris Lattner     // The following are the various types of breakpoints that could be set:
41630fdc8d8SChris Lattner     //   1).  -f -l -p  [-s -g]   (setting breakpoint by source location)
41730fdc8d8SChris Lattner     //   2).  -a  [-s -g]         (setting breakpoint by address)
41830fdc8d8SChris Lattner     //   3).  -n  [-s -g]         (setting breakpoint by function name)
419b9c1b51eSKate Stone     //   4).  -r  [-s -g]         (setting breakpoint by function name regular
420b9c1b51eSKate Stone     //   expression)
421b9c1b51eSKate Stone     //   5).  -p -f               (setting a breakpoint by comparing a reg-exp
422b9c1b51eSKate Stone     //   to source text)
423b9c1b51eSKate Stone     //   6).  -E [-w -h]          (setting a breakpoint for exceptions for a
424b9c1b51eSKate Stone     //   given language.)
42530fdc8d8SChris Lattner 
42630fdc8d8SChris Lattner     BreakpointSetType break_type = eSetTypeInvalid;
42730fdc8d8SChris Lattner 
42830fdc8d8SChris Lattner     if (m_options.m_line_num != 0)
42930fdc8d8SChris Lattner       break_type = eSetTypeFileAndLine;
43030fdc8d8SChris Lattner     else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
43130fdc8d8SChris Lattner       break_type = eSetTypeAddress;
432fab10e89SJim Ingham     else if (!m_options.m_func_names.empty())
43330fdc8d8SChris Lattner       break_type = eSetTypeFunctionName;
43430fdc8d8SChris Lattner     else if (!m_options.m_func_regexp.empty())
43530fdc8d8SChris Lattner       break_type = eSetTypeFunctionRegexp;
436969795f1SJim Ingham     else if (!m_options.m_source_text_regexp.empty())
437969795f1SJim Ingham       break_type = eSetTypeSourceRegexp;
438a72b31c7SJim Ingham     else if (m_options.m_exception_language != eLanguageTypeUnknown)
439fab10e89SJim Ingham       break_type = eSetTypeException;
44030fdc8d8SChris Lattner 
4419e85e5a8SEugene Zelenko     Breakpoint *bp = nullptr;
442274060b6SGreg Clayton     FileSpec module_spec;
443a8558b62SJim Ingham     const bool internal = false;
444a8558b62SJim Ingham 
445b9c1b51eSKate Stone     // If the user didn't specify skip-prologue, having an offset should turn
446b9c1b51eSKate Stone     // that off.
447b9c1b51eSKate Stone     if (m_options.m_offset_addr != 0 &&
448b9c1b51eSKate Stone         m_options.m_skip_prologue == eLazyBoolCalculate)
4492411167fSJim Ingham       m_options.m_skip_prologue = eLazyBoolNo;
4502411167fSJim Ingham 
451b9c1b51eSKate Stone     switch (break_type) {
45230fdc8d8SChris Lattner     case eSetTypeFileAndLine: // Breakpoint by source position
45330fdc8d8SChris Lattner     {
45430fdc8d8SChris Lattner       FileSpec file;
455c7bece56SGreg Clayton       const size_t num_files = m_options.m_filenames.GetSize();
456b9c1b51eSKate Stone       if (num_files == 0) {
457b9c1b51eSKate Stone         if (!GetDefaultFile(target, file, result)) {
45887df91b8SJim Ingham           result.AppendError("No file supplied and no default file available.");
45987df91b8SJim Ingham           result.SetStatus(eReturnStatusFailed);
46087df91b8SJim Ingham           return false;
46187df91b8SJim Ingham         }
462b9c1b51eSKate Stone       } else if (num_files > 1) {
463b9c1b51eSKate Stone         result.AppendError("Only one file at a time is allowed for file and "
464b9c1b51eSKate Stone                            "line breakpoints.");
46587df91b8SJim Ingham         result.SetStatus(eReturnStatusFailed);
46687df91b8SJim Ingham         return false;
467b9c1b51eSKate Stone       } else
46887df91b8SJim Ingham         file = m_options.m_filenames.GetFileSpecAtIndex(0);
46930fdc8d8SChris Lattner 
4701f746071SGreg Clayton       // Only check for inline functions if
4711f746071SGreg Clayton       LazyBool check_inlines = eLazyBoolCalculate;
4721f746071SGreg Clayton 
473b9c1b51eSKate Stone       bp = target
474b9c1b51eSKate Stone                ->CreateBreakpoint(&(m_options.m_modules), file,
475b9c1b51eSKate Stone                                   m_options.m_line_num, m_options.m_offset_addr,
476b9c1b51eSKate Stone                                   check_inlines, m_options.m_skip_prologue,
477b9c1b51eSKate Stone                                   internal, m_options.m_hardware,
478b9c1b51eSKate Stone                                   m_options.m_move_to_nearest_code)
479b9c1b51eSKate Stone                .get();
480b9c1b51eSKate Stone     } break;
4816eee5aa0SGreg Clayton 
48230fdc8d8SChris Lattner     case eSetTypeAddress: // Breakpoint by address
483055a08a4SJim Ingham     {
484b9c1b51eSKate Stone       // If a shared library has been specified, make an lldb_private::Address
485b9c1b51eSKate Stone       // with the library, and
486b9c1b51eSKate Stone       // use that.  That way the address breakpoint will track the load location
487b9c1b51eSKate Stone       // of the library.
488055a08a4SJim Ingham       size_t num_modules_specified = m_options.m_modules.GetSize();
489b9c1b51eSKate Stone       if (num_modules_specified == 1) {
490b9c1b51eSKate Stone         const FileSpec *file_spec =
491b9c1b51eSKate Stone             m_options.m_modules.GetFileSpecPointerAtIndex(0);
492b9c1b51eSKate Stone         bp = target
493b9c1b51eSKate Stone                  ->CreateAddressInModuleBreakpoint(m_options.m_load_addr,
494b9c1b51eSKate Stone                                                    internal, file_spec,
495b9c1b51eSKate Stone                                                    m_options.m_hardware)
496b9c1b51eSKate Stone                  .get();
497b9c1b51eSKate Stone       } else if (num_modules_specified == 0) {
498b9c1b51eSKate Stone         bp = target
499b9c1b51eSKate Stone                  ->CreateBreakpoint(m_options.m_load_addr, internal,
500b9c1b51eSKate Stone                                     m_options.m_hardware)
501b9c1b51eSKate Stone                  .get();
502b9c1b51eSKate Stone       } else {
503b9c1b51eSKate Stone         result.AppendError("Only one shared library can be specified for "
504b9c1b51eSKate Stone                            "address breakpoints.");
505055a08a4SJim Ingham         result.SetStatus(eReturnStatusFailed);
506055a08a4SJim Ingham         return false;
507055a08a4SJim Ingham       }
50830fdc8d8SChris Lattner       break;
509055a08a4SJim Ingham     }
51030fdc8d8SChris Lattner     case eSetTypeFunctionName: // Breakpoint by function name
5110c5cd90dSGreg Clayton     {
5120c5cd90dSGreg Clayton       uint32_t name_type_mask = m_options.m_func_name_type_mask;
5130c5cd90dSGreg Clayton 
5140c5cd90dSGreg Clayton       if (name_type_mask == 0)
515e02b8504SGreg Clayton         name_type_mask = eFunctionNameTypeAuto;
5160c5cd90dSGreg Clayton 
517b9c1b51eSKate Stone       bp = target
518b9c1b51eSKate Stone                ->CreateBreakpoint(
519b9c1b51eSKate Stone                    &(m_options.m_modules), &(m_options.m_filenames),
520b9c1b51eSKate Stone                    m_options.m_func_names, name_type_mask, m_options.m_language,
521b9c1b51eSKate Stone                    m_options.m_offset_addr, m_options.m_skip_prologue, internal,
522b9c1b51eSKate Stone                    m_options.m_hardware)
523b9c1b51eSKate Stone                .get();
524b9c1b51eSKate Stone     } break;
5250c5cd90dSGreg Clayton 
526b9c1b51eSKate Stone     case eSetTypeFunctionRegexp: // Breakpoint by regular expression function
527b9c1b51eSKate Stone                                  // name
52830fdc8d8SChris Lattner       {
52930fdc8d8SChris Lattner         RegularExpression regexp(m_options.m_func_regexp.c_str());
530b9c1b51eSKate Stone         if (!regexp.IsValid()) {
531969795f1SJim Ingham           char err_str[1024];
532969795f1SJim Ingham           regexp.GetErrorAsCString(err_str, sizeof(err_str));
533b9c1b51eSKate Stone           result.AppendErrorWithFormat(
534b9c1b51eSKate Stone               "Function name regular expression could not be compiled: \"%s\"",
535969795f1SJim Ingham               err_str);
53630fdc8d8SChris Lattner           result.SetStatus(eReturnStatusFailed);
537969795f1SJim Ingham           return false;
53830fdc8d8SChris Lattner         }
53987df91b8SJim Ingham 
540b9c1b51eSKate Stone         bp = target
541b9c1b51eSKate Stone                  ->CreateFuncRegexBreakpoint(
542b9c1b51eSKate Stone                      &(m_options.m_modules), &(m_options.m_filenames), regexp,
543b9c1b51eSKate Stone                      m_options.m_language, m_options.m_skip_prologue, internal,
544b9c1b51eSKate Stone                      m_options.m_hardware)
545b9c1b51eSKate Stone                  .get();
546e14dc268SJim Ingham       }
547e14dc268SJim Ingham       break;
548969795f1SJim Ingham     case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
549969795f1SJim Ingham     {
550c7bece56SGreg Clayton       const size_t num_files = m_options.m_filenames.GetSize();
55187df91b8SJim Ingham 
552b9c1b51eSKate Stone       if (num_files == 0 && !m_options.m_all_files) {
553969795f1SJim Ingham         FileSpec file;
554b9c1b51eSKate Stone         if (!GetDefaultFile(target, file, result)) {
555b9c1b51eSKate Stone           result.AppendError(
556b9c1b51eSKate Stone               "No files provided and could not find default file.");
55787df91b8SJim Ingham           result.SetStatus(eReturnStatusFailed);
55887df91b8SJim Ingham           return false;
559b9c1b51eSKate Stone         } else {
56087df91b8SJim Ingham           m_options.m_filenames.Append(file);
56187df91b8SJim Ingham         }
56287df91b8SJim Ingham       }
5630c5cd90dSGreg Clayton 
564969795f1SJim Ingham       RegularExpression regexp(m_options.m_source_text_regexp.c_str());
565b9c1b51eSKate Stone       if (!regexp.IsValid()) {
566969795f1SJim Ingham         char err_str[1024];
567969795f1SJim Ingham         regexp.GetErrorAsCString(err_str, sizeof(err_str));
568b9c1b51eSKate Stone         result.AppendErrorWithFormat(
569b9c1b51eSKate Stone             "Source text regular expression could not be compiled: \"%s\"",
570969795f1SJim Ingham             err_str);
571969795f1SJim Ingham         result.SetStatus(eReturnStatusFailed);
572969795f1SJim Ingham         return false;
573969795f1SJim Ingham       }
574b9c1b51eSKate Stone       bp = target
575b9c1b51eSKate Stone                ->CreateSourceRegexBreakpoint(
576b9c1b51eSKate Stone                    &(m_options.m_modules), &(m_options.m_filenames),
577b9c1b51eSKate Stone                    m_options.m_source_regex_func_names, regexp, internal,
578b9c1b51eSKate Stone                    m_options.m_hardware, m_options.m_move_to_nearest_code)
579b9c1b51eSKate Stone                .get();
580b9c1b51eSKate Stone     } break;
581b9c1b51eSKate Stone     case eSetTypeException: {
582a72b31c7SJim Ingham       Error precond_error;
583b9c1b51eSKate Stone       bp = target
584b9c1b51eSKate Stone                ->CreateExceptionBreakpoint(
585b9c1b51eSKate Stone                    m_options.m_exception_language, m_options.m_catch_bp,
586b9c1b51eSKate Stone                    m_options.m_throw_bp, internal,
587b9c1b51eSKate Stone                    &m_options.m_exception_extra_args, &precond_error)
588b9c1b51eSKate Stone                .get();
589b9c1b51eSKate Stone       if (precond_error.Fail()) {
590b9c1b51eSKate Stone         result.AppendErrorWithFormat(
591b9c1b51eSKate Stone             "Error setting extra exception arguments: %s",
592a72b31c7SJim Ingham             precond_error.AsCString());
593a72b31c7SJim Ingham         target->RemoveBreakpointByID(bp->GetID());
594a72b31c7SJim Ingham         result.SetStatus(eReturnStatusFailed);
595a72b31c7SJim Ingham         return false;
596a72b31c7SJim Ingham       }
597b9c1b51eSKate Stone     } break;
59830fdc8d8SChris Lattner     default:
59930fdc8d8SChris Lattner       break;
60030fdc8d8SChris Lattner     }
60130fdc8d8SChris Lattner 
6021b54c88cSJim Ingham     // Now set the various options that were passed in:
603b9c1b51eSKate Stone     if (bp) {
6041b54c88cSJim Ingham       if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
6051b54c88cSJim Ingham         bp->SetThreadID(m_options.m_thread_id);
6061b54c88cSJim Ingham 
607c982c768SGreg Clayton       if (m_options.m_thread_index != UINT32_MAX)
6081b54c88cSJim Ingham         bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
6091b54c88cSJim Ingham 
6101b54c88cSJim Ingham       if (!m_options.m_thread_name.empty())
611b9c1b51eSKate Stone         bp->GetOptions()->GetThreadSpec()->SetName(
612b9c1b51eSKate Stone             m_options.m_thread_name.c_str());
6131b54c88cSJim Ingham 
6141b54c88cSJim Ingham       if (!m_options.m_queue_name.empty())
615b9c1b51eSKate Stone         bp->GetOptions()->GetThreadSpec()->SetQueueName(
616b9c1b51eSKate Stone             m_options.m_queue_name.c_str());
6171b54c88cSJim Ingham 
618c982c768SGreg Clayton       if (m_options.m_ignore_count != 0)
6191b54c88cSJim Ingham         bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
6207d49c9c8SJohnny Chen 
6217d49c9c8SJohnny Chen       if (!m_options.m_condition.empty())
6227d49c9c8SJohnny Chen         bp->GetOptions()->SetCondition(m_options.m_condition.c_str());
623ca36cd16SJim Ingham 
624b9c1b51eSKate Stone       if (!m_options.m_breakpoint_names.empty()) {
625b9c1b51eSKate Stone         Error error; // We don't need to check the error here, since the option
626b9c1b51eSKate Stone                      // parser checked it...
6275e09c8c3SJim Ingham         for (auto name : m_options.m_breakpoint_names)
6285e09c8c3SJim Ingham           bp->AddName(name.c_str(), error);
6295e09c8c3SJim Ingham       }
6305e09c8c3SJim Ingham 
631ca36cd16SJim Ingham       bp->SetOneShot(m_options.m_one_shot);
6321b54c88cSJim Ingham     }
6331b54c88cSJim Ingham 
634b9c1b51eSKate Stone     if (bp) {
63585e8b814SJim Ingham       Stream &output_stream = result.GetOutputStream();
6361391cc7dSJim Ingham       const bool show_locations = false;
637b9c1b51eSKate Stone       bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial,
638b9c1b51eSKate Stone                          show_locations);
6394aeb1989SJim Ingham       if (target == m_interpreter.GetDebugger().GetDummyTarget())
640b9c1b51eSKate Stone         output_stream.Printf("Breakpoint set in dummy target, will get copied "
641b9c1b51eSKate Stone                              "into future targets.\n");
642b9c1b51eSKate Stone       else {
643b9c1b51eSKate Stone         // Don't print out this warning for exception breakpoints.  They can get
644b9c1b51eSKate Stone         // set before the target
645b9c1b51eSKate Stone         // is set, but we won't know how to actually set the breakpoint till we
646b9c1b51eSKate Stone         // run.
647b9c1b51eSKate Stone         if (bp->GetNumLocations() == 0 && break_type != eSetTypeException) {
648b9c1b51eSKate Stone           output_stream.Printf("WARNING:  Unable to resolve breakpoint to any "
649b9c1b51eSKate Stone                                "actual locations.\n");
6504aeb1989SJim Ingham         }
6514aeb1989SJim Ingham       }
65230fdc8d8SChris Lattner       result.SetStatus(eReturnStatusSuccessFinishResult);
653b9c1b51eSKate Stone     } else if (!bp) {
65430fdc8d8SChris Lattner       result.AppendError("Breakpoint creation failed: No breakpoint created.");
65530fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
65630fdc8d8SChris Lattner     }
65730fdc8d8SChris Lattner 
65830fdc8d8SChris Lattner     return result.Succeeded();
65930fdc8d8SChris Lattner   }
66030fdc8d8SChris Lattner 
6615a988416SJim Ingham private:
662b9c1b51eSKate Stone   bool GetDefaultFile(Target *target, FileSpec &file,
663b9c1b51eSKate Stone                       CommandReturnObject &result) {
6645a988416SJim Ingham     uint32_t default_line;
6655a988416SJim Ingham     // First use the Source Manager's default file.
6665a988416SJim Ingham     // Then use the current stack frame's file.
667b9c1b51eSKate Stone     if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) {
668b57e4a1bSJason Molenda       StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
669b9c1b51eSKate Stone       if (cur_frame == nullptr) {
670b9c1b51eSKate Stone         result.AppendError(
671b9c1b51eSKate Stone             "No selected frame to use to find the default file.");
6725a988416SJim Ingham         result.SetStatus(eReturnStatusFailed);
6735a988416SJim Ingham         return false;
674b9c1b51eSKate Stone       } else if (!cur_frame->HasDebugInformation()) {
675b9c1b51eSKate Stone         result.AppendError("Cannot use the selected frame to find the default "
676b9c1b51eSKate Stone                            "file, it has no debug info.");
6775a988416SJim Ingham         result.SetStatus(eReturnStatusFailed);
6785a988416SJim Ingham         return false;
679b9c1b51eSKate Stone       } else {
680b9c1b51eSKate Stone         const SymbolContext &sc =
681b9c1b51eSKate Stone             cur_frame->GetSymbolContext(eSymbolContextLineEntry);
682b9c1b51eSKate Stone         if (sc.line_entry.file) {
6835a988416SJim Ingham           file = sc.line_entry.file;
684b9c1b51eSKate Stone         } else {
685b9c1b51eSKate Stone           result.AppendError("Can't find the file for the selected frame to "
686b9c1b51eSKate Stone                              "use as the default file.");
6875a988416SJim Ingham           result.SetStatus(eReturnStatusFailed);
6885a988416SJim Ingham           return false;
6895a988416SJim Ingham         }
6905a988416SJim Ingham       }
6915a988416SJim Ingham     }
6925a988416SJim Ingham     return true;
6935a988416SJim Ingham   }
6945a988416SJim Ingham 
6955a988416SJim Ingham   CommandOptions m_options;
6965a988416SJim Ingham };
6979e85e5a8SEugene Zelenko 
6985a988416SJim Ingham // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to
6995a988416SJim Ingham // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately.
7005a988416SJim Ingham #define LLDB_OPT_FILE (LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2)
7015a988416SJim Ingham #define LLDB_OPT_NOT_10 (LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10)
7025a988416SJim Ingham #define LLDB_OPT_SKIP_PROLOGUE (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8))
7032411167fSJim Ingham #define LLDB_OPT_OFFSET_APPLIES (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8))
704055ad9beSIlia K #define LLDB_OPT_MOVE_TO_NEAREST_CODE (LLDB_OPT_SET_1 | LLDB_OPT_SET_9)
7050fcdac36SJim Ingham #define LLDB_OPT_EXPR_LANGUAGE (LLDB_OPT_SET_FROM_TO(3, 8))
7065a988416SJim Ingham 
707b9c1b51eSKate Stone OptionDefinition CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
7085a988416SJim Ingham     {
709ac9c3a62SKate Stone         // clang-format off
710ac9c3a62SKate Stone   {LLDB_OPT_NOT_10,               false, "shlib",                  's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion,     eArgTypeShlibName,           "Set the breakpoint only in this shared library.  Can repeat this option "
711ac9c3a62SKate Stone                                                                                                                                                                                                    "multiple times to specify multiple shared libraries."},
712ac9c3a62SKate Stone   {LLDB_OPT_SET_ALL,              false, "ignore-count",           'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeCount,               "Set the number of times this breakpoint is skipped before stopping." },
713ac9c3a62SKate Stone   {LLDB_OPT_SET_ALL,              false, "one-shot",               'o', OptionParser::eNoArgument,       nullptr, nullptr, 0,                                         eArgTypeNone,                "The breakpoint is deleted the first time it causes a stop." },
714ac9c3a62SKate Stone   {LLDB_OPT_SET_ALL,              false, "condition",              'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeExpression,          "The breakpoint stops only if this condition expression evaluates to true."},
715ac9c3a62SKate Stone   {LLDB_OPT_SET_ALL,              false, "thread-index",           'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeThreadIndex,         "The breakpoint stops only for the thread whose indeX matches this argument."},
716ac9c3a62SKate Stone   {LLDB_OPT_SET_ALL,              false, "thread-id",              't', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeThreadID,            "The breakpoint stops only for the thread whose TID matches this argument."},
717ac9c3a62SKate Stone   {LLDB_OPT_SET_ALL,              false, "thread-name",            'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeThreadName,          "The breakpoint stops only for the thread whose thread name matches this "
718ac9c3a62SKate Stone                                                                                                                                                                                                    "argument."},
719ac9c3a62SKate Stone   {LLDB_OPT_SET_ALL,              false, "hardware",               'H', OptionParser::eNoArgument,       nullptr, nullptr, 0,                                         eArgTypeNone,                "Require the breakpoint to use hardware breakpoints."},
720ac9c3a62SKate Stone   {LLDB_OPT_SET_ALL,              false, "queue-name",             'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeQueueName,           "The breakpoint stops only for threads in the queue whose name is given by "
721ac9c3a62SKate Stone                                                                                                                                                                                                    "this argument."},
722ac9c3a62SKate Stone   {LLDB_OPT_FILE,                 false, "file",                   'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,            "Specifies the source file in which to set this breakpoint.  Note, by default "
723ac9c3a62SKate Stone                                                                                                                                                                                                    "lldb only looks for files that are #included if they use the standard include "
724ac9c3a62SKate Stone                                                                                                                                                                                                    "file extensions.  To set breakpoints on .c/.cpp/.m/.mm files that are "
725ac9c3a62SKate Stone                                                                                                                                                                                                    "#included, set target.inline-breakpoint-strategy to \"always\"."},
726ac9c3a62SKate Stone   {LLDB_OPT_SET_1,                true,  "line",                   'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeLineNum,             "Specifies the line number on which to set this breakpoint."},
7275a988416SJim Ingham 
7285a988416SJim Ingham     // Comment out this option for the moment, as we don't actually use it, but will in the future.
7295a988416SJim Ingham     // This way users won't see it, but the infrastructure is left in place.
7309e85e5a8SEugene Zelenko     //    { 0, false, "column",     'C', OptionParser::eRequiredArgument, nullptr, "<column>",
7315a988416SJim Ingham     //    "Set the breakpoint by source location at this particular column."},
7325a988416SJim Ingham 
733ac9c3a62SKate Stone   {LLDB_OPT_SET_2,                true,  "address",                'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeAddressOrExpression, "Set the breakpoint at the specified address.  If the address maps uniquely to "
734ac9c3a62SKate Stone                                                                                                                                                                                                    "a particular binary, then the address will be converted to a \"file\" "
735ac9c3a62SKate Stone                                                                                                                                                                                                    "address, so that the breakpoint will track that binary+offset no matter where "
736ac9c3a62SKate Stone                                                                                                                                                                                                    "the binary eventually loads.  Alternately, if you also specify the module - "
737ac9c3a62SKate Stone                                                                                                                                                                                                    "with the -s option - then the address will be treated as a file address in "
738ac9c3a62SKate Stone                                                                                                                                                                                                    "that module, and resolved accordingly.  Again, this will allow lldb to track "
739ac9c3a62SKate Stone                                                                                                                                                                                                    "that offset on subsequent reloads.  The module need not have been loaded at "
740ac9c3a62SKate Stone                                                                                                                                                                                                    "the time you specify this breakpoint, and will get resolved when the module "
741ac9c3a62SKate Stone                                                                                                                                                                                                    "is loaded."},
742ac9c3a62SKate Stone   {LLDB_OPT_SET_3,                true,  "name",                   'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion,     eArgTypeFunctionName,        "Set the breakpoint by function name.  Can be repeated multiple times to make "
743ac9c3a62SKate Stone                                                                                                                                                                                                    "one breakpoint for multiple names"},
744ac9c3a62SKate Stone   {LLDB_OPT_SET_9,                false, "source-regexp-function", 'X', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion,     eArgTypeFunctionName,        "When used with '-p' limits the source regex to source contained in the named "
745ac9c3a62SKate Stone                                                                                                                                                                                                    "functions.  Can be repeated multiple times."},
746ac9c3a62SKate Stone   {LLDB_OPT_SET_4,                true,  "fullname",               'F', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion,     eArgTypeFullName,            "Set the breakpoint by fully qualified function names. For C++ this means "
747ac9c3a62SKate Stone                                                                                                                                                                                                    "namespaces and all arguments, and for Objective C this means a full function "
748ac9c3a62SKate Stone                                                                                                                                                                                                    "prototype with class and selector.  Can be repeated multiple times to make "
749ac9c3a62SKate Stone                                                                                                                                                                                                    "one breakpoint for multiple names."},
750ac9c3a62SKate Stone   {LLDB_OPT_SET_5,                true,  "selector",               'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeSelector,            "Set the breakpoint by ObjC selector name. Can be repeated multiple times to "
751ac9c3a62SKate Stone                                                                                                                                                                                                    "make one breakpoint for multiple Selectors."},
752ac9c3a62SKate Stone   {LLDB_OPT_SET_6,                true,  "method",                 'M', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeMethod,              "Set the breakpoint by C++ method names.  Can be repeated multiple times to "
753ac9c3a62SKate Stone                                                                                                                                                                                                    "make one breakpoint for multiple methods."},
754ac9c3a62SKate Stone   {LLDB_OPT_SET_7,                true,  "func-regex",             'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeRegularExpression,   "Set the breakpoint by function name, evaluating a regular-expression to find "
755ac9c3a62SKate Stone                                                                                                                                                                                                    "the function name(s)."},
756ac9c3a62SKate Stone   {LLDB_OPT_SET_8,                true,  "basename",               'b', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion,     eArgTypeFunctionName,        "Set the breakpoint by function basename (C++ namespaces and arguments will be "
757ac9c3a62SKate Stone                                                                                                                                                                                                    "ignored).  Can be repeated multiple times to make one breakpoint for multiple "
758ac9c3a62SKate Stone                                                                                                                                                                                                    "symbols."},
759ac9c3a62SKate Stone   {LLDB_OPT_SET_9,                true,  "source-pattern-regexp",  'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeRegularExpression,   "Set the breakpoint by specifying a regular expression which is matched "
760ac9c3a62SKate Stone                                                                                                                                                                                                    "against the source text in a source file or files specified with the -f "
761ac9c3a62SKate Stone                                                                                                                                                                                                    "option.  The -f option can be specified more than once.  If no source files "
762ac9c3a62SKate Stone                                                                                                                                                                                                    "are specified, uses the current \"default source file\".  If you want to "
763ac9c3a62SKate Stone                                                                                                                                                                                                    "match against all source files, pass the \"--all-files\" option."},
764ac9c3a62SKate Stone   {LLDB_OPT_SET_9,                false, "all-files",              'A', OptionParser::eNoArgument,       nullptr, nullptr, 0,                                         eArgTypeNone,                "All files are searched for source pattern matches."},
765ac9c3a62SKate Stone   {LLDB_OPT_SET_10,               true,  "language-exception",     'E', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeLanguage,            "Set the breakpoint on exceptions thrown by the specified language (without "
766ac9c3a62SKate Stone                                                                                                                                                                                                    "options, on throw but not catch.)"},
767ac9c3a62SKate Stone   {LLDB_OPT_SET_10,               false, "on-throw",               'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeBoolean,             "Set the breakpoint on exception throW."},
768ac9c3a62SKate Stone   {LLDB_OPT_SET_10,               false, "on-catch",               'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeBoolean,             "Set the breakpoint on exception catcH."},
7695a988416SJim Ingham 
770a72b31c7SJim Ingham //  Don't add this option till it actually does something useful...
7719e85e5a8SEugene Zelenko //    { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName,
772a72b31c7SJim Ingham //        "The breakpoint will only stop if an exception Object of this type is thrown.  Can be repeated multiple times to stop for multiple object types" },
773a72b31c7SJim Ingham 
774ac9c3a62SKate Stone   {LLDB_OPT_EXPR_LANGUAGE,        false, "language",               'L', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeLanguage,            "Specifies the Language to use when interpreting the breakpoint's expression "
775ac9c3a62SKate Stone                                                                                                                                                                                                    "(note: currently only implemented for setting breakpoints on identifiers).  "
776ac9c3a62SKate Stone                                                                                                                                                                                                    "If not set the target.language setting is used."},
777ac9c3a62SKate Stone   {LLDB_OPT_SKIP_PROLOGUE,        false, "skip-prologue",          'K', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeBoolean,             "sKip the prologue if the breakpoint is at the beginning of a function.  "
778ac9c3a62SKate Stone                                                                                                                                                                                                    "If not set the target.skip-prologue setting is used."},
779ac9c3a62SKate Stone   {LLDB_OPT_SET_ALL,              false, "dummy-breakpoints",      'D', OptionParser::eNoArgument,       nullptr, nullptr, 0,                                         eArgTypeNone,                "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, "
780ac9c3a62SKate Stone                                                                                                                                                                                                    "which prime new targets."},
781ac9c3a62SKate Stone   {LLDB_OPT_SET_ALL,              false, "breakpoint-name",        'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeBreakpointName,      "Adds this to the list of names for this breakpoint."},
782ac9c3a62SKate Stone   {LLDB_OPT_OFFSET_APPLIES,       false, "address-slide",          'R', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeAddress,             "Add the specified offset to whatever address(es) the breakpoint resolves to.  "
7832411167fSJim Ingham         "At present this applies the offset directly as given, and doesn't try to align it to instruction boundaries."},
784ac9c3a62SKate Stone   {LLDB_OPT_MOVE_TO_NEAREST_CODE, false, "move-to-nearest-code", 'm', OptionParser::eRequiredArgument,   nullptr, nullptr, 0,                                         eArgTypeBoolean,             "Move breakpoints to nearest code. If not set the target.move-to-nearest-code "
785ac9c3a62SKate Stone                                                                                                                                                                                                    "setting is used."},
7869e85e5a8SEugene Zelenko   {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
787ac9c3a62SKate Stone         // clang-format on
7885a988416SJim Ingham };
7895a988416SJim Ingham 
7905a988416SJim Ingham //-------------------------------------------------------------------------
7915a988416SJim Ingham // CommandObjectBreakpointModify
7925a988416SJim Ingham //-------------------------------------------------------------------------
7935a988416SJim Ingham #pragma mark Modify
7945a988416SJim Ingham 
795b9c1b51eSKate Stone class CommandObjectBreakpointModify : public CommandObjectParsed {
7965a988416SJim Ingham public:
797b9c1b51eSKate Stone   CommandObjectBreakpointModify(CommandInterpreter &interpreter)
798b9c1b51eSKate Stone       : CommandObjectParsed(interpreter, "breakpoint modify",
799b9c1b51eSKate Stone                             "Modify the options on a breakpoint or set of "
800b9c1b51eSKate Stone                             "breakpoints in the executable.  "
801b9c1b51eSKate Stone                             "If no breakpoint is specified, acts on the last "
802b9c1b51eSKate Stone                             "created breakpoint.  "
803b9c1b51eSKate Stone                             "With the exception of -e, -d and -i, passing an "
804b9c1b51eSKate Stone                             "empty argument clears the modification.",
8059e85e5a8SEugene Zelenko                             nullptr),
806b9c1b51eSKate Stone         m_options() {
8075a988416SJim Ingham     CommandArgumentEntry arg;
808b9c1b51eSKate Stone     CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
809b9c1b51eSKate Stone                                       eArgTypeBreakpointIDRange);
810b9c1b51eSKate Stone     // Add the entry for the first argument for this command to the object's
811b9c1b51eSKate Stone     // arguments vector.
8125a988416SJim Ingham     m_arguments.push_back(arg);
8135a988416SJim Ingham   }
8145a988416SJim Ingham 
8159e85e5a8SEugene Zelenko   ~CommandObjectBreakpointModify() override = default;
8165a988416SJim Ingham 
817b9c1b51eSKate Stone   Options *GetOptions() override { return &m_options; }
8185a988416SJim Ingham 
819b9c1b51eSKate Stone   class CommandOptions : public Options {
8205a988416SJim Ingham   public:
821b9c1b51eSKate Stone     CommandOptions()
822b9c1b51eSKate Stone         : Options(), m_ignore_count(0), m_thread_id(LLDB_INVALID_THREAD_ID),
823b9c1b51eSKate Stone           m_thread_id_passed(false), m_thread_index(UINT32_MAX),
824b9c1b51eSKate Stone           m_thread_index_passed(false), m_thread_name(), m_queue_name(),
825b9c1b51eSKate Stone           m_condition(), m_one_shot(false), m_enable_passed(false),
826b9c1b51eSKate Stone           m_enable_value(false), m_name_passed(false), m_queue_passed(false),
827b9c1b51eSKate Stone           m_condition_passed(false), m_one_shot_passed(false),
828b9c1b51eSKate Stone           m_use_dummy(false) {}
8295a988416SJim Ingham 
8309e85e5a8SEugene Zelenko     ~CommandOptions() override = default;
8315a988416SJim Ingham 
832b9c1b51eSKate Stone     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
833b9c1b51eSKate Stone                          ExecutionContext *execution_context) override {
8345a988416SJim Ingham       Error error;
8353bcdfc0eSGreg Clayton       const int short_option = m_getopt_table[option_idx].val;
8365a988416SJim Ingham 
837b9c1b51eSKate Stone       switch (short_option) {
8385a988416SJim Ingham       case 'c':
8399e85e5a8SEugene Zelenko         if (option_arg != nullptr)
8405a988416SJim Ingham           m_condition.assign(option_arg);
8415a988416SJim Ingham         else
8425a988416SJim Ingham           m_condition.clear();
8435a988416SJim Ingham         m_condition_passed = true;
8445a988416SJim Ingham         break;
8455a988416SJim Ingham       case 'd':
8465a988416SJim Ingham         m_enable_passed = true;
8475a988416SJim Ingham         m_enable_value = false;
8485a988416SJim Ingham         break;
84933df7cd3SJim Ingham       case 'D':
85033df7cd3SJim Ingham         m_use_dummy = true;
85133df7cd3SJim Ingham         break;
8525a988416SJim Ingham       case 'e':
8535a988416SJim Ingham         m_enable_passed = true;
8545a988416SJim Ingham         m_enable_value = true;
8555a988416SJim Ingham         break;
8565a988416SJim Ingham       case 'i':
8575275aaa0SVince Harron         m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
8585a988416SJim Ingham         if (m_ignore_count == UINT32_MAX)
859b9c1b51eSKate Stone           error.SetErrorStringWithFormat("invalid ignore count '%s'",
860b9c1b51eSKate Stone                                          option_arg);
8615a988416SJim Ingham         break;
862b9c1b51eSKate Stone       case 'o': {
863ca36cd16SJim Ingham         bool value, success;
864*ecbb0bb1SZachary Turner         value = Args::StringToBoolean(
865*ecbb0bb1SZachary Turner             llvm::StringRef::withNullAsEmpty(option_arg), false, &success);
866b9c1b51eSKate Stone         if (success) {
867ca36cd16SJim Ingham           m_one_shot_passed = true;
868ca36cd16SJim Ingham           m_one_shot = value;
869b9c1b51eSKate Stone         } else
870b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
871b9c1b51eSKate Stone               "invalid boolean value '%s' passed for -o option", option_arg);
872b9c1b51eSKate Stone       } break;
8735a988416SJim Ingham       case 't':
874b9c1b51eSKate Stone         if (option_arg[0] == '\0') {
8755a988416SJim Ingham           m_thread_id = LLDB_INVALID_THREAD_ID;
8765a988416SJim Ingham           m_thread_id_passed = true;
877b9c1b51eSKate Stone         } else {
878b9c1b51eSKate Stone           m_thread_id =
879b9c1b51eSKate Stone               StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
8805a988416SJim Ingham           if (m_thread_id == LLDB_INVALID_THREAD_ID)
881b9c1b51eSKate Stone             error.SetErrorStringWithFormat("invalid thread id string '%s'",
882b9c1b51eSKate Stone                                            option_arg);
8835a988416SJim Ingham           else
8845a988416SJim Ingham             m_thread_id_passed = true;
8855a988416SJim Ingham         }
8865a988416SJim Ingham         break;
8875a988416SJim Ingham       case 'T':
8889e85e5a8SEugene Zelenko         if (option_arg != nullptr)
8895a988416SJim Ingham           m_thread_name.assign(option_arg);
8905a988416SJim Ingham         else
8915a988416SJim Ingham           m_thread_name.clear();
8925a988416SJim Ingham         m_name_passed = true;
8935a988416SJim Ingham         break;
8945a988416SJim Ingham       case 'q':
8959e85e5a8SEugene Zelenko         if (option_arg != nullptr)
8965a988416SJim Ingham           m_queue_name.assign(option_arg);
8975a988416SJim Ingham         else
8985a988416SJim Ingham           m_queue_name.clear();
8995a988416SJim Ingham         m_queue_passed = true;
9005a988416SJim Ingham         break;
9015a988416SJim Ingham       case 'x':
902b9c1b51eSKate Stone         if (option_arg[0] == '\n') {
9035a988416SJim Ingham           m_thread_index = UINT32_MAX;
9045a988416SJim Ingham           m_thread_index_passed = true;
905b9c1b51eSKate Stone         } else {
9065275aaa0SVince Harron           m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
9075a988416SJim Ingham           if (m_thread_id == UINT32_MAX)
908b9c1b51eSKate Stone             error.SetErrorStringWithFormat("invalid thread index string '%s'",
909b9c1b51eSKate Stone                                            option_arg);
9105a988416SJim Ingham           else
9115a988416SJim Ingham             m_thread_index_passed = true;
9125a988416SJim Ingham         }
9135a988416SJim Ingham         break;
9145a988416SJim Ingham       default:
915b9c1b51eSKate Stone         error.SetErrorStringWithFormat("unrecognized option '%c'",
916b9c1b51eSKate Stone                                        short_option);
9175a988416SJim Ingham         break;
9185a988416SJim Ingham       }
9195a988416SJim Ingham 
9205a988416SJim Ingham       return error;
9215a988416SJim Ingham     }
9229e85e5a8SEugene Zelenko 
923b9c1b51eSKate Stone     void OptionParsingStarting(ExecutionContext *execution_context) override {
9245a988416SJim Ingham       m_ignore_count = 0;
9255a988416SJim Ingham       m_thread_id = LLDB_INVALID_THREAD_ID;
9265a988416SJim Ingham       m_thread_id_passed = false;
9275a988416SJim Ingham       m_thread_index = UINT32_MAX;
9285a988416SJim Ingham       m_thread_index_passed = false;
9295a988416SJim Ingham       m_thread_name.clear();
9305a988416SJim Ingham       m_queue_name.clear();
9315a988416SJim Ingham       m_condition.clear();
932ca36cd16SJim Ingham       m_one_shot = false;
9335a988416SJim Ingham       m_enable_passed = false;
9345a988416SJim Ingham       m_queue_passed = false;
9355a988416SJim Ingham       m_name_passed = false;
9365a988416SJim Ingham       m_condition_passed = false;
937ca36cd16SJim Ingham       m_one_shot_passed = false;
93833df7cd3SJim Ingham       m_use_dummy = false;
9395a988416SJim Ingham     }
9405a988416SJim Ingham 
941b9c1b51eSKate Stone     const OptionDefinition *GetDefinitions() override { return g_option_table; }
9425a988416SJim Ingham 
9435a988416SJim Ingham     // Options table: Required for subclasses of Options.
9445a988416SJim Ingham 
9455a988416SJim Ingham     static OptionDefinition g_option_table[];
9465a988416SJim Ingham 
9475a988416SJim Ingham     // Instance variables to hold the values for command options.
9485a988416SJim Ingham 
9495a988416SJim Ingham     uint32_t m_ignore_count;
9505a988416SJim Ingham     lldb::tid_t m_thread_id;
9515a988416SJim Ingham     bool m_thread_id_passed;
9525a988416SJim Ingham     uint32_t m_thread_index;
9535a988416SJim Ingham     bool m_thread_index_passed;
9545a988416SJim Ingham     std::string m_thread_name;
9555a988416SJim Ingham     std::string m_queue_name;
9565a988416SJim Ingham     std::string m_condition;
957ca36cd16SJim Ingham     bool m_one_shot;
9585a988416SJim Ingham     bool m_enable_passed;
9595a988416SJim Ingham     bool m_enable_value;
9605a988416SJim Ingham     bool m_name_passed;
9615a988416SJim Ingham     bool m_queue_passed;
9625a988416SJim Ingham     bool m_condition_passed;
963ca36cd16SJim Ingham     bool m_one_shot_passed;
96433df7cd3SJim Ingham     bool m_use_dummy;
9655a988416SJim Ingham   };
9665a988416SJim Ingham 
9675a988416SJim Ingham protected:
968b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
96933df7cd3SJim Ingham     Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
970b9c1b51eSKate Stone     if (target == nullptr) {
9715a988416SJim Ingham       result.AppendError("Invalid target.  No existing target or breakpoints.");
9725a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
9735a988416SJim Ingham       return false;
9745a988416SJim Ingham     }
9755a988416SJim Ingham 
976bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
977bb19a13cSSaleem Abdulrasool     target->GetBreakpointList().GetListMutex(lock);
9785a988416SJim Ingham 
9795a988416SJim Ingham     BreakpointIDList valid_bp_ids;
9805a988416SJim Ingham 
981b9c1b51eSKate Stone     CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
982b9c1b51eSKate Stone         command, target, result, &valid_bp_ids);
9835a988416SJim Ingham 
984b9c1b51eSKate Stone     if (result.Succeeded()) {
9855a988416SJim Ingham       const size_t count = valid_bp_ids.GetSize();
986b9c1b51eSKate Stone       for (size_t i = 0; i < count; ++i) {
9875a988416SJim Ingham         BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
9885a988416SJim Ingham 
989b9c1b51eSKate Stone         if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
990b9c1b51eSKate Stone           Breakpoint *bp =
991b9c1b51eSKate Stone               target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
992b9c1b51eSKate Stone           if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
993b9c1b51eSKate Stone             BreakpointLocation *location =
994b9c1b51eSKate Stone                 bp->FindLocationByID(cur_bp_id.GetLocationID()).get();
995b9c1b51eSKate Stone             if (location) {
9965a988416SJim Ingham               if (m_options.m_thread_id_passed)
9975a988416SJim Ingham                 location->SetThreadID(m_options.m_thread_id);
9985a988416SJim Ingham 
9995a988416SJim Ingham               if (m_options.m_thread_index_passed)
10005a988416SJim Ingham                 location->SetThreadIndex(m_options.m_thread_index);
10015a988416SJim Ingham 
10025a988416SJim Ingham               if (m_options.m_name_passed)
10035a988416SJim Ingham                 location->SetThreadName(m_options.m_thread_name.c_str());
10045a988416SJim Ingham 
10055a988416SJim Ingham               if (m_options.m_queue_passed)
10065a988416SJim Ingham                 location->SetQueueName(m_options.m_queue_name.c_str());
10075a988416SJim Ingham 
10085a988416SJim Ingham               if (m_options.m_ignore_count != 0)
10095a988416SJim Ingham                 location->SetIgnoreCount(m_options.m_ignore_count);
10105a988416SJim Ingham 
10115a988416SJim Ingham               if (m_options.m_enable_passed)
10125a988416SJim Ingham                 location->SetEnabled(m_options.m_enable_value);
10135a988416SJim Ingham 
10145a988416SJim Ingham               if (m_options.m_condition_passed)
10155a988416SJim Ingham                 location->SetCondition(m_options.m_condition.c_str());
10165a988416SJim Ingham             }
1017b9c1b51eSKate Stone           } else {
10185a988416SJim Ingham             if (m_options.m_thread_id_passed)
10195a988416SJim Ingham               bp->SetThreadID(m_options.m_thread_id);
10205a988416SJim Ingham 
10215a988416SJim Ingham             if (m_options.m_thread_index_passed)
10225a988416SJim Ingham               bp->SetThreadIndex(m_options.m_thread_index);
10235a988416SJim Ingham 
10245a988416SJim Ingham             if (m_options.m_name_passed)
10255a988416SJim Ingham               bp->SetThreadName(m_options.m_thread_name.c_str());
10265a988416SJim Ingham 
10275a988416SJim Ingham             if (m_options.m_queue_passed)
10285a988416SJim Ingham               bp->SetQueueName(m_options.m_queue_name.c_str());
10295a988416SJim Ingham 
10305a988416SJim Ingham             if (m_options.m_ignore_count != 0)
10315a988416SJim Ingham               bp->SetIgnoreCount(m_options.m_ignore_count);
10325a988416SJim Ingham 
10335a988416SJim Ingham             if (m_options.m_enable_passed)
10345a988416SJim Ingham               bp->SetEnabled(m_options.m_enable_value);
10355a988416SJim Ingham 
10365a988416SJim Ingham             if (m_options.m_condition_passed)
10375a988416SJim Ingham               bp->SetCondition(m_options.m_condition.c_str());
10385a988416SJim Ingham           }
10395a988416SJim Ingham         }
10405a988416SJim Ingham       }
10415a988416SJim Ingham     }
10425a988416SJim Ingham 
10435a988416SJim Ingham     return result.Succeeded();
10445a988416SJim Ingham   }
10455a988416SJim Ingham 
10465a988416SJim Ingham private:
10475a988416SJim Ingham   CommandOptions m_options;
10485a988416SJim Ingham };
10495a988416SJim Ingham 
10505a988416SJim Ingham #pragma mark Modify::CommandOptions
10515a988416SJim Ingham OptionDefinition
1052b9c1b51eSKate Stone     CommandObjectBreakpointModify::CommandOptions::g_option_table[] = {
1053ac9c3a62SKate Stone         // clang-format off
10549e85e5a8SEugene Zelenko   {LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount,       "Set the number of times this breakpoint is skipped before stopping."},
10559e85e5a8SEugene Zelenko   {LLDB_OPT_SET_ALL, false, "one-shot",     'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,     "The breakpoint is deleted the first time it stop causes a stop."},
10569e85e5a8SEugene Zelenko   {LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose index matches this argument."},
10579e85e5a8SEugene Zelenko   {LLDB_OPT_SET_ALL, false, "thread-id",    't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID,    "The breakpoint stops only for the thread whose TID matches this argument."},
10589e85e5a8SEugene Zelenko   {LLDB_OPT_SET_ALL, false, "thread-name",  'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName,  "The breakpoint stops only for the thread whose thread name matches this argument."},
10599e85e5a8SEugene Zelenko   {LLDB_OPT_SET_ALL, false, "queue-name",   'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName,   "The breakpoint stops only for threads in the queue whose name is given by this argument."},
10609e85e5a8SEugene Zelenko   {LLDB_OPT_SET_ALL, false, "condition",    'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression,  "The breakpoint stops only if this condition expression evaluates to true."},
10619e85e5a8SEugene Zelenko   {LLDB_OPT_SET_1,   false, "enable",       'e', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,        "Enable the breakpoint."},
10629e85e5a8SEugene Zelenko   {LLDB_OPT_SET_2,   false, "disable",      'd', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,        "Disable the breakpoint."},
10639e85e5a8SEugene Zelenko   {LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument,  nullptr, nullptr, 0, eArgTypeNone,        "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
10649e85e5a8SEugene Zelenko   {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
1065ac9c3a62SKate Stone         // clang-format on
10665a988416SJim Ingham };
10675a988416SJim Ingham 
10685a988416SJim Ingham //-------------------------------------------------------------------------
10695a988416SJim Ingham // CommandObjectBreakpointEnable
10705a988416SJim Ingham //-------------------------------------------------------------------------
10715a988416SJim Ingham #pragma mark Enable
10725a988416SJim Ingham 
1073b9c1b51eSKate Stone class CommandObjectBreakpointEnable : public CommandObjectParsed {
10745a988416SJim Ingham public:
1075b9c1b51eSKate Stone   CommandObjectBreakpointEnable(CommandInterpreter &interpreter)
1076b9c1b51eSKate Stone       : CommandObjectParsed(interpreter, "enable",
1077b9c1b51eSKate Stone                             "Enable the specified disabled breakpoint(s). If "
1078b9c1b51eSKate Stone                             "no breakpoints are specified, enable all of them.",
1079b9c1b51eSKate Stone                             nullptr) {
10805a988416SJim Ingham     CommandArgumentEntry arg;
1081b9c1b51eSKate Stone     CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
1082b9c1b51eSKate Stone                                       eArgTypeBreakpointIDRange);
1083b9c1b51eSKate Stone     // Add the entry for the first argument for this command to the object's
1084b9c1b51eSKate Stone     // arguments vector.
10855a988416SJim Ingham     m_arguments.push_back(arg);
10865a988416SJim Ingham   }
10875a988416SJim Ingham 
10889e85e5a8SEugene Zelenko   ~CommandObjectBreakpointEnable() override = default;
10895a988416SJim Ingham 
10905a988416SJim Ingham protected:
1091b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
1092893c932aSJim Ingham     Target *target = GetSelectedOrDummyTarget();
1093b9c1b51eSKate Stone     if (target == nullptr) {
10945a988416SJim Ingham       result.AppendError("Invalid target.  No existing target or breakpoints.");
10955a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
10965a988416SJim Ingham       return false;
10975a988416SJim Ingham     }
10985a988416SJim Ingham 
1099bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1100bb19a13cSSaleem Abdulrasool     target->GetBreakpointList().GetListMutex(lock);
11015a988416SJim Ingham 
11025a988416SJim Ingham     const BreakpointList &breakpoints = target->GetBreakpointList();
11035a988416SJim Ingham 
11045a988416SJim Ingham     size_t num_breakpoints = breakpoints.GetSize();
11055a988416SJim Ingham 
1106b9c1b51eSKate Stone     if (num_breakpoints == 0) {
11075a988416SJim Ingham       result.AppendError("No breakpoints exist to be enabled.");
11085a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
11095a988416SJim Ingham       return false;
11105a988416SJim Ingham     }
11115a988416SJim Ingham 
1112b9c1b51eSKate Stone     if (command.GetArgumentCount() == 0) {
11135a988416SJim Ingham       // No breakpoint selected; enable all currently set breakpoints.
11145a988416SJim Ingham       target->EnableAllBreakpoints();
1115b9c1b51eSKate Stone       result.AppendMessageWithFormat("All breakpoints enabled. (%" PRIu64
1116b9c1b51eSKate Stone                                      " breakpoints)\n",
1117b9c1b51eSKate Stone                                      (uint64_t)num_breakpoints);
11185a988416SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
1119b9c1b51eSKate Stone     } else {
11205a988416SJim Ingham       // Particular breakpoint selected; enable that breakpoint.
11215a988416SJim Ingham       BreakpointIDList valid_bp_ids;
1122b9c1b51eSKate Stone       CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
1123b9c1b51eSKate Stone           command, target, result, &valid_bp_ids);
11245a988416SJim Ingham 
1125b9c1b51eSKate Stone       if (result.Succeeded()) {
11265a988416SJim Ingham         int enable_count = 0;
11275a988416SJim Ingham         int loc_count = 0;
11285a988416SJim Ingham         const size_t count = valid_bp_ids.GetSize();
1129b9c1b51eSKate Stone         for (size_t i = 0; i < count; ++i) {
11305a988416SJim Ingham           BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
11315a988416SJim Ingham 
1132b9c1b51eSKate Stone           if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
1133b9c1b51eSKate Stone             Breakpoint *breakpoint =
1134b9c1b51eSKate Stone                 target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
1135b9c1b51eSKate Stone             if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
1136b9c1b51eSKate Stone               BreakpointLocation *location =
1137b9c1b51eSKate Stone                   breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get();
1138b9c1b51eSKate Stone               if (location) {
11395a988416SJim Ingham                 location->SetEnabled(true);
11405a988416SJim Ingham                 ++loc_count;
11415a988416SJim Ingham               }
1142b9c1b51eSKate Stone             } else {
11435a988416SJim Ingham               breakpoint->SetEnabled(true);
11445a988416SJim Ingham               ++enable_count;
11455a988416SJim Ingham             }
11465a988416SJim Ingham           }
11475a988416SJim Ingham         }
1148b9c1b51eSKate Stone         result.AppendMessageWithFormat("%d breakpoints enabled.\n",
1149b9c1b51eSKate Stone                                        enable_count + loc_count);
11505a988416SJim Ingham         result.SetStatus(eReturnStatusSuccessFinishNoResult);
11515a988416SJim Ingham       }
11525a988416SJim Ingham     }
11535a988416SJim Ingham 
11545a988416SJim Ingham     return result.Succeeded();
11555a988416SJim Ingham   }
11565a988416SJim Ingham };
11575a988416SJim Ingham 
11585a988416SJim Ingham //-------------------------------------------------------------------------
11595a988416SJim Ingham // CommandObjectBreakpointDisable
11605a988416SJim Ingham //-------------------------------------------------------------------------
11615a988416SJim Ingham #pragma mark Disable
11625a988416SJim Ingham 
1163b9c1b51eSKate Stone class CommandObjectBreakpointDisable : public CommandObjectParsed {
11645a988416SJim Ingham public:
11657428a18cSKate Stone   CommandObjectBreakpointDisable(CommandInterpreter &interpreter)
1166b9c1b51eSKate Stone       : CommandObjectParsed(
1167b9c1b51eSKate Stone             interpreter, "breakpoint disable",
1168b9c1b51eSKate Stone             "Disable the specified breakpoint(s) without deleting "
11697428a18cSKate Stone             "them.  If none are specified, disable all "
11707428a18cSKate Stone             "breakpoints.",
1171b9c1b51eSKate Stone             nullptr) {
1172b9c1b51eSKate Stone     SetHelpLong(
1173b9c1b51eSKate Stone         "Disable the specified breakpoint(s) without deleting them.  \
11747428a18cSKate Stone If none are specified, disable all breakpoints."
11757428a18cSKate Stone         R"(
1176ea671fbdSKate Stone 
11777428a18cSKate Stone )"
11787428a18cSKate Stone         "Note: disabling a breakpoint will cause none of its locations to be hit \
11797428a18cSKate Stone regardless of whether individual locations are enabled or disabled.  After the sequence:"
11807428a18cSKate Stone         R"(
1181ea671fbdSKate Stone 
1182ea671fbdSKate Stone     (lldb) break disable 1
1183ea671fbdSKate Stone     (lldb) break enable 1.1
1184ea671fbdSKate Stone 
1185ea671fbdSKate Stone execution will NOT stop at location 1.1.  To achieve that, type:
1186ea671fbdSKate Stone 
1187ea671fbdSKate Stone     (lldb) break disable 1.*
1188ea671fbdSKate Stone     (lldb) break enable 1.1
1189ea671fbdSKate Stone 
11907428a18cSKate Stone )"
11917428a18cSKate Stone         "The first command disables all locations for breakpoint 1, \
11927428a18cSKate Stone the second re-enables the first location.");
1193b0fac509SJim Ingham 
11945a988416SJim Ingham     CommandArgumentEntry arg;
1195b9c1b51eSKate Stone     CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
1196b9c1b51eSKate Stone                                       eArgTypeBreakpointIDRange);
1197b9c1b51eSKate Stone     // Add the entry for the first argument for this command to the object's
1198b9c1b51eSKate Stone     // arguments vector.
11995a988416SJim Ingham     m_arguments.push_back(arg);
12005a988416SJim Ingham   }
12015a988416SJim Ingham 
12029e85e5a8SEugene Zelenko   ~CommandObjectBreakpointDisable() override = default;
12035a988416SJim Ingham 
12045a988416SJim Ingham protected:
1205b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
1206893c932aSJim Ingham     Target *target = GetSelectedOrDummyTarget();
1207b9c1b51eSKate Stone     if (target == nullptr) {
12085a988416SJim Ingham       result.AppendError("Invalid target.  No existing target or breakpoints.");
12095a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
12105a988416SJim Ingham       return false;
12115a988416SJim Ingham     }
12125a988416SJim Ingham 
1213bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1214bb19a13cSSaleem Abdulrasool     target->GetBreakpointList().GetListMutex(lock);
12155a988416SJim Ingham 
12165a988416SJim Ingham     const BreakpointList &breakpoints = target->GetBreakpointList();
12175a988416SJim Ingham     size_t num_breakpoints = breakpoints.GetSize();
12185a988416SJim Ingham 
1219b9c1b51eSKate Stone     if (num_breakpoints == 0) {
12205a988416SJim Ingham       result.AppendError("No breakpoints exist to be disabled.");
12215a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
12225a988416SJim Ingham       return false;
12235a988416SJim Ingham     }
12245a988416SJim Ingham 
1225b9c1b51eSKate Stone     if (command.GetArgumentCount() == 0) {
12265a988416SJim Ingham       // No breakpoint selected; disable all currently set breakpoints.
12275a988416SJim Ingham       target->DisableAllBreakpoints();
1228b9c1b51eSKate Stone       result.AppendMessageWithFormat("All breakpoints disabled. (%" PRIu64
1229b9c1b51eSKate Stone                                      " breakpoints)\n",
1230b9c1b51eSKate Stone                                      (uint64_t)num_breakpoints);
12315a988416SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
1232b9c1b51eSKate Stone     } else {
12335a988416SJim Ingham       // Particular breakpoint selected; disable that breakpoint.
12345a988416SJim Ingham       BreakpointIDList valid_bp_ids;
12355a988416SJim Ingham 
1236b9c1b51eSKate Stone       CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
1237b9c1b51eSKate Stone           command, target, result, &valid_bp_ids);
12385a988416SJim Ingham 
1239b9c1b51eSKate Stone       if (result.Succeeded()) {
12405a988416SJim Ingham         int disable_count = 0;
12415a988416SJim Ingham         int loc_count = 0;
12425a988416SJim Ingham         const size_t count = valid_bp_ids.GetSize();
1243b9c1b51eSKate Stone         for (size_t i = 0; i < count; ++i) {
12445a988416SJim Ingham           BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
12455a988416SJim Ingham 
1246b9c1b51eSKate Stone           if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
1247b9c1b51eSKate Stone             Breakpoint *breakpoint =
1248b9c1b51eSKate Stone                 target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
1249b9c1b51eSKate Stone             if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
1250b9c1b51eSKate Stone               BreakpointLocation *location =
1251b9c1b51eSKate Stone                   breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get();
1252b9c1b51eSKate Stone               if (location) {
12535a988416SJim Ingham                 location->SetEnabled(false);
12545a988416SJim Ingham                 ++loc_count;
12555a988416SJim Ingham               }
1256b9c1b51eSKate Stone             } else {
12575a988416SJim Ingham               breakpoint->SetEnabled(false);
12585a988416SJim Ingham               ++disable_count;
12595a988416SJim Ingham             }
12605a988416SJim Ingham           }
12615a988416SJim Ingham         }
1262b9c1b51eSKate Stone         result.AppendMessageWithFormat("%d breakpoints disabled.\n",
1263b9c1b51eSKate Stone                                        disable_count + loc_count);
12645a988416SJim Ingham         result.SetStatus(eReturnStatusSuccessFinishNoResult);
12655a988416SJim Ingham       }
12665a988416SJim Ingham     }
12675a988416SJim Ingham 
12685a988416SJim Ingham     return result.Succeeded();
12695a988416SJim Ingham   }
12705a988416SJim Ingham };
12715a988416SJim Ingham 
12725a988416SJim Ingham //-------------------------------------------------------------------------
12735a988416SJim Ingham // CommandObjectBreakpointList
12745a988416SJim Ingham //-------------------------------------------------------------------------
12755a988416SJim Ingham #pragma mark List
12765a988416SJim Ingham 
1277b9c1b51eSKate Stone class CommandObjectBreakpointList : public CommandObjectParsed {
12785a988416SJim Ingham public:
1279b9c1b51eSKate Stone   CommandObjectBreakpointList(CommandInterpreter &interpreter)
1280b9c1b51eSKate Stone       : CommandObjectParsed(
1281b9c1b51eSKate Stone             interpreter, "breakpoint list",
12825a988416SJim Ingham             "List some or all breakpoints at configurable levels of detail.",
12839e85e5a8SEugene Zelenko             nullptr),
1284b9c1b51eSKate Stone         m_options() {
12855a988416SJim Ingham     CommandArgumentEntry arg;
12865a988416SJim Ingham     CommandArgumentData bp_id_arg;
12875a988416SJim Ingham 
12885a988416SJim Ingham     // Define the first (and only) variant of this arg.
12895a988416SJim Ingham     bp_id_arg.arg_type = eArgTypeBreakpointID;
12905a988416SJim Ingham     bp_id_arg.arg_repetition = eArgRepeatOptional;
12915a988416SJim Ingham 
1292b9c1b51eSKate Stone     // There is only one variant this argument could be; put it into the
1293b9c1b51eSKate Stone     // argument entry.
12945a988416SJim Ingham     arg.push_back(bp_id_arg);
12955a988416SJim Ingham 
12965a988416SJim Ingham     // Push the data for the first argument into the m_arguments vector.
12975a988416SJim Ingham     m_arguments.push_back(arg);
12985a988416SJim Ingham   }
12995a988416SJim Ingham 
13009e85e5a8SEugene Zelenko   ~CommandObjectBreakpointList() override = default;
13015a988416SJim Ingham 
1302b9c1b51eSKate Stone   Options *GetOptions() override { return &m_options; }
13035a988416SJim Ingham 
1304b9c1b51eSKate Stone   class CommandOptions : public Options {
13055a988416SJim Ingham   public:
1306b9c1b51eSKate Stone     CommandOptions()
1307b9c1b51eSKate Stone         : Options(), m_level(lldb::eDescriptionLevelBrief), m_use_dummy(false) {
13085a988416SJim Ingham     }
13095a988416SJim Ingham 
13109e85e5a8SEugene Zelenko     ~CommandOptions() override = default;
13115a988416SJim Ingham 
1312b9c1b51eSKate Stone     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
1313b9c1b51eSKate Stone                          ExecutionContext *execution_context) override {
13145a988416SJim Ingham       Error error;
13153bcdfc0eSGreg Clayton       const int short_option = m_getopt_table[option_idx].val;
13165a988416SJim Ingham 
1317b9c1b51eSKate Stone       switch (short_option) {
13185a988416SJim Ingham       case 'b':
13195a988416SJim Ingham         m_level = lldb::eDescriptionLevelBrief;
13205a988416SJim Ingham         break;
132133df7cd3SJim Ingham       case 'D':
132233df7cd3SJim Ingham         m_use_dummy = true;
132333df7cd3SJim Ingham         break;
13245a988416SJim Ingham       case 'f':
13255a988416SJim Ingham         m_level = lldb::eDescriptionLevelFull;
13265a988416SJim Ingham         break;
13275a988416SJim Ingham       case 'v':
13285a988416SJim Ingham         m_level = lldb::eDescriptionLevelVerbose;
13295a988416SJim Ingham         break;
13305a988416SJim Ingham       case 'i':
13315a988416SJim Ingham         m_internal = true;
13325a988416SJim Ingham         break;
13335a988416SJim Ingham       default:
1334b9c1b51eSKate Stone         error.SetErrorStringWithFormat("unrecognized option '%c'",
1335b9c1b51eSKate Stone                                        short_option);
13365a988416SJim Ingham         break;
13375a988416SJim Ingham       }
13385a988416SJim Ingham 
13395a988416SJim Ingham       return error;
13405a988416SJim Ingham     }
13415a988416SJim Ingham 
1342b9c1b51eSKate Stone     void OptionParsingStarting(ExecutionContext *execution_context) override {
13435a988416SJim Ingham       m_level = lldb::eDescriptionLevelFull;
13445a988416SJim Ingham       m_internal = false;
134533df7cd3SJim Ingham       m_use_dummy = false;
13465a988416SJim Ingham     }
13475a988416SJim Ingham 
1348b9c1b51eSKate Stone     const OptionDefinition *GetDefinitions() override { return g_option_table; }
13495a988416SJim Ingham 
13505a988416SJim Ingham     // Options table: Required for subclasses of Options.
13515a988416SJim Ingham 
13525a988416SJim Ingham     static OptionDefinition g_option_table[];
13535a988416SJim Ingham 
13545a988416SJim Ingham     // Instance variables to hold the values for command options.
13555a988416SJim Ingham 
13565a988416SJim Ingham     lldb::DescriptionLevel m_level;
13575a988416SJim Ingham 
13585a988416SJim Ingham     bool m_internal;
135933df7cd3SJim Ingham     bool m_use_dummy;
13605a988416SJim Ingham   };
13615a988416SJim Ingham 
13625a988416SJim Ingham protected:
1363b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
136433df7cd3SJim Ingham     Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
136533df7cd3SJim Ingham 
1366b9c1b51eSKate Stone     if (target == nullptr) {
13675a988416SJim Ingham       result.AppendError("Invalid target. No current target or breakpoints.");
13685a988416SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
13695a988416SJim Ingham       return true;
13705a988416SJim Ingham     }
13715a988416SJim Ingham 
1372b9c1b51eSKate Stone     const BreakpointList &breakpoints =
1373b9c1b51eSKate Stone         target->GetBreakpointList(m_options.m_internal);
1374bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1375bb19a13cSSaleem Abdulrasool     target->GetBreakpointList(m_options.m_internal).GetListMutex(lock);
13765a988416SJim Ingham 
13775a988416SJim Ingham     size_t num_breakpoints = breakpoints.GetSize();
13785a988416SJim Ingham 
1379b9c1b51eSKate Stone     if (num_breakpoints == 0) {
13805a988416SJim Ingham       result.AppendMessage("No breakpoints currently set.");
13815a988416SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
13825a988416SJim Ingham       return true;
13835a988416SJim Ingham     }
13845a988416SJim Ingham 
13855a988416SJim Ingham     Stream &output_stream = result.GetOutputStream();
13865a988416SJim Ingham 
1387b9c1b51eSKate Stone     if (command.GetArgumentCount() == 0) {
13885a988416SJim Ingham       // No breakpoint selected; show info about all currently set breakpoints.
13895a988416SJim Ingham       result.AppendMessage("Current breakpoints:");
1390b9c1b51eSKate Stone       for (size_t i = 0; i < num_breakpoints; ++i) {
13915a988416SJim Ingham         Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex(i).get();
13925a988416SJim Ingham         AddBreakpointDescription(&output_stream, breakpoint, m_options.m_level);
13935a988416SJim Ingham       }
13945a988416SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
1395b9c1b51eSKate Stone     } else {
13965a988416SJim Ingham       // Particular breakpoints selected; show info about that breakpoint.
13975a988416SJim Ingham       BreakpointIDList valid_bp_ids;
1398b9c1b51eSKate Stone       CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
1399b9c1b51eSKate Stone           command, target, result, &valid_bp_ids);
14005a988416SJim Ingham 
1401b9c1b51eSKate Stone       if (result.Succeeded()) {
1402b9c1b51eSKate Stone         for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) {
14035a988416SJim Ingham           BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
1404b9c1b51eSKate Stone           Breakpoint *breakpoint =
1405b9c1b51eSKate Stone               target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
1406b9c1b51eSKate Stone           AddBreakpointDescription(&output_stream, breakpoint,
1407b9c1b51eSKate Stone                                    m_options.m_level);
14085a988416SJim Ingham         }
14095a988416SJim Ingham         result.SetStatus(eReturnStatusSuccessFinishNoResult);
1410b9c1b51eSKate Stone       } else {
14117428a18cSKate Stone         result.AppendError("Invalid breakpoint ID.");
14125a988416SJim Ingham         result.SetStatus(eReturnStatusFailed);
14135a988416SJim Ingham       }
14145a988416SJim Ingham     }
14155a988416SJim Ingham 
14165a988416SJim Ingham     return result.Succeeded();
14175a988416SJim Ingham   }
14185a988416SJim Ingham 
14195a988416SJim Ingham private:
14205a988416SJim Ingham   CommandOptions m_options;
14215a988416SJim Ingham };
14225a988416SJim Ingham 
14235a988416SJim Ingham #pragma mark List::CommandOptions
1424b9c1b51eSKate Stone OptionDefinition CommandObjectBreakpointList::CommandOptions::g_option_table[] =
14255a988416SJim Ingham     {
1426ac9c3a62SKate Stone         // clang-format off
1427ac9c3a62SKate Stone     {LLDB_OPT_SET_ALL, false, "internal",          'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show debugger internal breakpoints" },
1428ac9c3a62SKate Stone     {LLDB_OPT_SET_1,   false, "brief",             'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a brief description of the breakpoint (no location info)."},
14295a988416SJim Ingham     // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
14305a988416SJim Ingham     // But I need to see it for now, and don't want to wait.
1431ac9c3a62SKate Stone     {LLDB_OPT_SET_2,   false, "full",              'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a full description of the breakpoint and its locations."},
1432ac9c3a62SKate Stone     {LLDB_OPT_SET_3,   false, "verbose",           'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Explain everything we know about the breakpoint (for debugging debugger bugs)."},
1433ac9c3a62SKate Stone     {LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
14349e85e5a8SEugene Zelenko     {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
1435ac9c3a62SKate Stone         // clang-format on
14365a988416SJim Ingham };
14375a988416SJim Ingham 
14385a988416SJim Ingham //-------------------------------------------------------------------------
14395a988416SJim Ingham // CommandObjectBreakpointClear
14405a988416SJim Ingham //-------------------------------------------------------------------------
14415a988416SJim Ingham #pragma mark Clear
14425a988416SJim Ingham 
1443b9c1b51eSKate Stone class CommandObjectBreakpointClear : public CommandObjectParsed {
14445a988416SJim Ingham public:
1445b9c1b51eSKate Stone   typedef enum BreakpointClearType {
14465a988416SJim Ingham     eClearTypeInvalid,
14475a988416SJim Ingham     eClearTypeFileAndLine
14485a988416SJim Ingham   } BreakpointClearType;
14495a988416SJim Ingham 
14507428a18cSKate Stone   CommandObjectBreakpointClear(CommandInterpreter &interpreter)
14517428a18cSKate Stone       : CommandObjectParsed(interpreter, "breakpoint clear",
1452b9c1b51eSKate Stone                             "Delete or disable breakpoints matching the "
1453b9c1b51eSKate Stone                             "specified source file and line.",
14545a988416SJim Ingham                             "breakpoint clear <cmd-options>"),
1455b9c1b51eSKate Stone         m_options() {}
14565a988416SJim Ingham 
14579e85e5a8SEugene Zelenko   ~CommandObjectBreakpointClear() override = default;
14585a988416SJim Ingham 
1459b9c1b51eSKate Stone   Options *GetOptions() override { return &m_options; }
14605a988416SJim Ingham 
1461b9c1b51eSKate Stone   class CommandOptions : public Options {
14625a988416SJim Ingham   public:
1463b9c1b51eSKate Stone     CommandOptions() : Options(), m_filename(), m_line_num(0) {}
14645a988416SJim Ingham 
14659e85e5a8SEugene Zelenko     ~CommandOptions() override = default;
14665a988416SJim Ingham 
1467b9c1b51eSKate Stone     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
1468b9c1b51eSKate Stone                          ExecutionContext *execution_context) override {
14695a988416SJim Ingham       Error error;
14703bcdfc0eSGreg Clayton       const int short_option = m_getopt_table[option_idx].val;
14715a988416SJim Ingham 
1472b9c1b51eSKate Stone       switch (short_option) {
14735a988416SJim Ingham       case 'f':
14745a988416SJim Ingham         m_filename.assign(option_arg);
14755a988416SJim Ingham         break;
14765a988416SJim Ingham 
14775a988416SJim Ingham       case 'l':
14785275aaa0SVince Harron         m_line_num = StringConvert::ToUInt32(option_arg, 0);
14795a988416SJim Ingham         break;
14805a988416SJim Ingham 
14815a988416SJim Ingham       default:
1482b9c1b51eSKate Stone         error.SetErrorStringWithFormat("unrecognized option '%c'",
1483b9c1b51eSKate Stone                                        short_option);
14845a988416SJim Ingham         break;
14855a988416SJim Ingham       }
14865a988416SJim Ingham 
14875a988416SJim Ingham       return error;
14885a988416SJim Ingham     }
14895a988416SJim Ingham 
1490b9c1b51eSKate Stone     void OptionParsingStarting(ExecutionContext *execution_context) override {
14915a988416SJim Ingham       m_filename.clear();
14925a988416SJim Ingham       m_line_num = 0;
14935a988416SJim Ingham     }
14945a988416SJim Ingham 
1495b9c1b51eSKate Stone     const OptionDefinition *GetDefinitions() override { return g_option_table; }
14965a988416SJim Ingham 
14975a988416SJim Ingham     // Options table: Required for subclasses of Options.
14985a988416SJim Ingham 
14995a988416SJim Ingham     static OptionDefinition g_option_table[];
15005a988416SJim Ingham 
15015a988416SJim Ingham     // Instance variables to hold the values for command options.
15025a988416SJim Ingham 
15035a988416SJim Ingham     std::string m_filename;
15045a988416SJim Ingham     uint32_t m_line_num;
15055a988416SJim Ingham   };
15065a988416SJim Ingham 
15075a988416SJim Ingham protected:
1508b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
1509893c932aSJim Ingham     Target *target = GetSelectedOrDummyTarget();
1510b9c1b51eSKate Stone     if (target == nullptr) {
15115a988416SJim Ingham       result.AppendError("Invalid target. No existing target or breakpoints.");
15125a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
15135a988416SJim Ingham       return false;
15145a988416SJim Ingham     }
15155a988416SJim Ingham 
15165a988416SJim Ingham     // The following are the various types of breakpoints that could be cleared:
15175a988416SJim Ingham     //   1). -f -l (clearing breakpoint by source location)
15185a988416SJim Ingham 
15195a988416SJim Ingham     BreakpointClearType break_type = eClearTypeInvalid;
15205a988416SJim Ingham 
15215a988416SJim Ingham     if (m_options.m_line_num != 0)
15225a988416SJim Ingham       break_type = eClearTypeFileAndLine;
15235a988416SJim Ingham 
1524bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1525bb19a13cSSaleem Abdulrasool     target->GetBreakpointList().GetListMutex(lock);
15265a988416SJim Ingham 
15275a988416SJim Ingham     BreakpointList &breakpoints = target->GetBreakpointList();
15285a988416SJim Ingham     size_t num_breakpoints = breakpoints.GetSize();
15295a988416SJim Ingham 
15305a988416SJim Ingham     // Early return if there's no breakpoint at all.
1531b9c1b51eSKate Stone     if (num_breakpoints == 0) {
15325a988416SJim Ingham       result.AppendError("Breakpoint clear: No breakpoint cleared.");
15335a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
15345a988416SJim Ingham       return result.Succeeded();
15355a988416SJim Ingham     }
15365a988416SJim Ingham 
15375a988416SJim Ingham     // Find matching breakpoints and delete them.
15385a988416SJim Ingham 
15395a988416SJim Ingham     // First create a copy of all the IDs.
15405a988416SJim Ingham     std::vector<break_id_t> BreakIDs;
15415a988416SJim Ingham     for (size_t i = 0; i < num_breakpoints; ++i)
15429e85e5a8SEugene Zelenko       BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID());
15435a988416SJim Ingham 
15445a988416SJim Ingham     int num_cleared = 0;
15455a988416SJim Ingham     StreamString ss;
1546b9c1b51eSKate Stone     switch (break_type) {
15475a988416SJim Ingham     case eClearTypeFileAndLine: // Breakpoint by source position
15485a988416SJim Ingham     {
15495a988416SJim Ingham       const ConstString filename(m_options.m_filename.c_str());
15505a988416SJim Ingham       BreakpointLocationCollection loc_coll;
15515a988416SJim Ingham 
1552b9c1b51eSKate Stone       for (size_t i = 0; i < num_breakpoints; ++i) {
15535a988416SJim Ingham         Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
15545a988416SJim Ingham 
1555b9c1b51eSKate Stone         if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) {
1556b9c1b51eSKate Stone           // If the collection size is 0, it's a full match and we can just
1557b9c1b51eSKate Stone           // remove the breakpoint.
1558b9c1b51eSKate Stone           if (loc_coll.GetSize() == 0) {
15595a988416SJim Ingham             bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
15605a988416SJim Ingham             ss.EOL();
15615a988416SJim Ingham             target->RemoveBreakpointByID(bp->GetID());
15625a988416SJim Ingham             ++num_cleared;
15635a988416SJim Ingham           }
15645a988416SJim Ingham         }
15655a988416SJim Ingham       }
1566b9c1b51eSKate Stone     } break;
15675a988416SJim Ingham 
15685a988416SJim Ingham     default:
15695a988416SJim Ingham       break;
15705a988416SJim Ingham     }
15715a988416SJim Ingham 
1572b9c1b51eSKate Stone     if (num_cleared > 0) {
15735a988416SJim Ingham       Stream &output_stream = result.GetOutputStream();
15745a988416SJim Ingham       output_stream.Printf("%d breakpoints cleared:\n", num_cleared);
15755a988416SJim Ingham       output_stream << ss.GetData();
15765a988416SJim Ingham       output_stream.EOL();
15775a988416SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
1578b9c1b51eSKate Stone     } else {
15795a988416SJim Ingham       result.AppendError("Breakpoint clear: No breakpoint cleared.");
15805a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
15815a988416SJim Ingham     }
15825a988416SJim Ingham 
15835a988416SJim Ingham     return result.Succeeded();
15845a988416SJim Ingham   }
15855a988416SJim Ingham 
15865a988416SJim Ingham private:
15875a988416SJim Ingham   CommandOptions m_options;
15885a988416SJim Ingham };
15895a988416SJim Ingham 
15905a988416SJim Ingham #pragma mark Clear::CommandOptions
15915a988416SJim Ingham 
15925a988416SJim Ingham OptionDefinition
1593b9c1b51eSKate Stone     CommandObjectBreakpointClear::CommandOptions::g_option_table[] = {
1594ac9c3a62SKate Stone         // clang-format off
1595ac9c3a62SKate Stone   {LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specify the breakpoint by source location in this particular file."},
1596ac9c3a62SKate Stone   {LLDB_OPT_SET_1, true,  "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeLineNum,  "Specify the breakpoint by source location at this particular line."},
15979e85e5a8SEugene Zelenko   {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
1598ac9c3a62SKate Stone         // clang-format on
15995a988416SJim Ingham };
16005a988416SJim Ingham 
16015a988416SJim Ingham //-------------------------------------------------------------------------
16025a988416SJim Ingham // CommandObjectBreakpointDelete
16035a988416SJim Ingham //-------------------------------------------------------------------------
16045a988416SJim Ingham #pragma mark Delete
16055a988416SJim Ingham 
1606b9c1b51eSKate Stone class CommandObjectBreakpointDelete : public CommandObjectParsed {
16075a988416SJim Ingham public:
1608b9c1b51eSKate Stone   CommandObjectBreakpointDelete(CommandInterpreter &interpreter)
1609b9c1b51eSKate Stone       : CommandObjectParsed(interpreter, "breakpoint delete",
1610b9c1b51eSKate Stone                             "Delete the specified breakpoint(s).  If no "
1611b9c1b51eSKate Stone                             "breakpoints are specified, delete them all.",
16129e85e5a8SEugene Zelenko                             nullptr),
1613b9c1b51eSKate Stone         m_options() {
16145a988416SJim Ingham     CommandArgumentEntry arg;
1615b9c1b51eSKate Stone     CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
1616b9c1b51eSKate Stone                                       eArgTypeBreakpointIDRange);
1617b9c1b51eSKate Stone     // Add the entry for the first argument for this command to the object's
1618b9c1b51eSKate Stone     // arguments vector.
16195a988416SJim Ingham     m_arguments.push_back(arg);
16205a988416SJim Ingham   }
16215a988416SJim Ingham 
16229e85e5a8SEugene Zelenko   ~CommandObjectBreakpointDelete() override = default;
16235a988416SJim Ingham 
1624b9c1b51eSKate Stone   Options *GetOptions() override { return &m_options; }
162533df7cd3SJim Ingham 
1626b9c1b51eSKate Stone   class CommandOptions : public Options {
162733df7cd3SJim Ingham   public:
1628b9c1b51eSKate Stone     CommandOptions() : Options(), m_use_dummy(false), m_force(false) {}
162933df7cd3SJim Ingham 
16309e85e5a8SEugene Zelenko     ~CommandOptions() override = default;
163133df7cd3SJim Ingham 
1632b9c1b51eSKate Stone     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
1633b9c1b51eSKate Stone                          ExecutionContext *execution_context) override {
163433df7cd3SJim Ingham       Error error;
163533df7cd3SJim Ingham       const int short_option = m_getopt_table[option_idx].val;
163633df7cd3SJim Ingham 
1637b9c1b51eSKate Stone       switch (short_option) {
163833df7cd3SJim Ingham       case 'f':
163933df7cd3SJim Ingham         m_force = true;
164033df7cd3SJim Ingham         break;
164133df7cd3SJim Ingham 
164233df7cd3SJim Ingham       case 'D':
164333df7cd3SJim Ingham         m_use_dummy = true;
164433df7cd3SJim Ingham         break;
164533df7cd3SJim Ingham 
164633df7cd3SJim Ingham       default:
1647b9c1b51eSKate Stone         error.SetErrorStringWithFormat("unrecognized option '%c'",
1648b9c1b51eSKate Stone                                        short_option);
164933df7cd3SJim Ingham         break;
165033df7cd3SJim Ingham       }
165133df7cd3SJim Ingham 
165233df7cd3SJim Ingham       return error;
165333df7cd3SJim Ingham     }
165433df7cd3SJim Ingham 
1655b9c1b51eSKate Stone     void OptionParsingStarting(ExecutionContext *execution_context) override {
165633df7cd3SJim Ingham       m_use_dummy = false;
165733df7cd3SJim Ingham       m_force = false;
165833df7cd3SJim Ingham     }
165933df7cd3SJim Ingham 
1660b9c1b51eSKate Stone     const OptionDefinition *GetDefinitions() override { return g_option_table; }
166133df7cd3SJim Ingham 
166233df7cd3SJim Ingham     // Options table: Required for subclasses of Options.
166333df7cd3SJim Ingham 
166433df7cd3SJim Ingham     static OptionDefinition g_option_table[];
166533df7cd3SJim Ingham 
166633df7cd3SJim Ingham     // Instance variables to hold the values for command options.
166733df7cd3SJim Ingham     bool m_use_dummy;
166833df7cd3SJim Ingham     bool m_force;
166933df7cd3SJim Ingham   };
167033df7cd3SJim Ingham 
16715a988416SJim Ingham protected:
1672b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
167333df7cd3SJim Ingham     Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
167433df7cd3SJim Ingham 
1675b9c1b51eSKate Stone     if (target == nullptr) {
16765a988416SJim Ingham       result.AppendError("Invalid target. No existing target or breakpoints.");
16775a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
16785a988416SJim Ingham       return false;
16795a988416SJim Ingham     }
16805a988416SJim Ingham 
1681bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1682bb19a13cSSaleem Abdulrasool     target->GetBreakpointList().GetListMutex(lock);
16835a988416SJim Ingham 
16845a988416SJim Ingham     const BreakpointList &breakpoints = target->GetBreakpointList();
16855a988416SJim Ingham 
16865a988416SJim Ingham     size_t num_breakpoints = breakpoints.GetSize();
16875a988416SJim Ingham 
1688b9c1b51eSKate Stone     if (num_breakpoints == 0) {
16895a988416SJim Ingham       result.AppendError("No breakpoints exist to be deleted.");
16905a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
16915a988416SJim Ingham       return false;
16925a988416SJim Ingham     }
16935a988416SJim Ingham 
1694b9c1b51eSKate Stone     if (command.GetArgumentCount() == 0) {
1695b9c1b51eSKate Stone       if (!m_options.m_force &&
1696b9c1b51eSKate Stone           !m_interpreter.Confirm(
1697b9c1b51eSKate Stone               "About to delete all breakpoints, do you want to do that?",
1698b9c1b51eSKate Stone               true)) {
16995a988416SJim Ingham         result.AppendMessage("Operation cancelled...");
1700b9c1b51eSKate Stone       } else {
17015a988416SJim Ingham         target->RemoveAllBreakpoints();
1702b9c1b51eSKate Stone         result.AppendMessageWithFormat(
1703b9c1b51eSKate Stone             "All breakpoints removed. (%" PRIu64 " breakpoint%s)\n",
1704b9c1b51eSKate Stone             (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : "");
17055a988416SJim Ingham       }
17065a988416SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
1707b9c1b51eSKate Stone     } else {
17085a988416SJim Ingham       // Particular breakpoint selected; disable that breakpoint.
17095a988416SJim Ingham       BreakpointIDList valid_bp_ids;
1710b9c1b51eSKate Stone       CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
1711b9c1b51eSKate Stone           command, target, result, &valid_bp_ids);
17125a988416SJim Ingham 
1713b9c1b51eSKate Stone       if (result.Succeeded()) {
17145a988416SJim Ingham         int delete_count = 0;
17155a988416SJim Ingham         int disable_count = 0;
17165a988416SJim Ingham         const size_t count = valid_bp_ids.GetSize();
1717b9c1b51eSKate Stone         for (size_t i = 0; i < count; ++i) {
17185a988416SJim Ingham           BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
17195a988416SJim Ingham 
1720b9c1b51eSKate Stone           if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
1721b9c1b51eSKate Stone             if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
1722b9c1b51eSKate Stone               Breakpoint *breakpoint =
1723b9c1b51eSKate Stone                   target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
1724b9c1b51eSKate Stone               BreakpointLocation *location =
1725b9c1b51eSKate Stone                   breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get();
1726b9c1b51eSKate Stone               // It makes no sense to try to delete individual locations, so we
1727b9c1b51eSKate Stone               // disable them instead.
1728b9c1b51eSKate Stone               if (location) {
17295a988416SJim Ingham                 location->SetEnabled(false);
17305a988416SJim Ingham                 ++disable_count;
17315a988416SJim Ingham               }
1732b9c1b51eSKate Stone             } else {
17335a988416SJim Ingham               target->RemoveBreakpointByID(cur_bp_id.GetBreakpointID());
17345a988416SJim Ingham               ++delete_count;
17355a988416SJim Ingham             }
17365a988416SJim Ingham           }
17375a988416SJim Ingham         }
1738b9c1b51eSKate Stone         result.AppendMessageWithFormat(
1739b9c1b51eSKate Stone             "%d breakpoints deleted; %d breakpoint locations disabled.\n",
17405a988416SJim Ingham             delete_count, disable_count);
17415a988416SJim Ingham         result.SetStatus(eReturnStatusSuccessFinishNoResult);
17425a988416SJim Ingham       }
17435a988416SJim Ingham     }
17445a988416SJim Ingham     return result.Succeeded();
17455a988416SJim Ingham   }
17469e85e5a8SEugene Zelenko 
174733df7cd3SJim Ingham private:
174833df7cd3SJim Ingham   CommandOptions m_options;
174933df7cd3SJim Ingham };
175033df7cd3SJim Ingham 
175133df7cd3SJim Ingham OptionDefinition
1752b9c1b51eSKate Stone     CommandObjectBreakpointDelete::CommandOptions::g_option_table[] = {
1753ac9c3a62SKate Stone         // clang-format off
1754ac9c3a62SKate Stone   {LLDB_OPT_SET_1, false, "force",             'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete all breakpoints without querying for confirmation."},
1755ac9c3a62SKate Stone   {LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
17569e85e5a8SEugene Zelenko   {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
1757ac9c3a62SKate Stone         // clang-format on
17585a988416SJim Ingham };
17595a988416SJim Ingham 
176030fdc8d8SChris Lattner //-------------------------------------------------------------------------
17615e09c8c3SJim Ingham // CommandObjectBreakpointName
17625e09c8c3SJim Ingham //-------------------------------------------------------------------------
17635e09c8c3SJim Ingham 
17647428a18cSKate Stone static OptionDefinition g_breakpoint_name_options[] = {
1765ac9c3a62SKate Stone     // clang-format off
1766ac9c3a62SKate Stone   {LLDB_OPT_SET_1,   false, "name",              'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."},
1767ac9c3a62SKate Stone   {LLDB_OPT_SET_2,   false, "breakpoint-id",     'B', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointID,   "Specify a breakpoint ID to use."},
1768ac9c3a62SKate Stone   {LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,           "Operate on Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
1769ac9c3a62SKate Stone     // clang-format on
17705e09c8c3SJim Ingham };
1771b9c1b51eSKate Stone class BreakpointNameOptionGroup : public OptionGroup {
17725e09c8c3SJim Ingham public:
1773b9c1b51eSKate Stone   BreakpointNameOptionGroup()
1774b9c1b51eSKate Stone       : OptionGroup(), m_breakpoint(LLDB_INVALID_BREAK_ID), m_use_dummy(false) {
17755e09c8c3SJim Ingham   }
17765e09c8c3SJim Ingham 
17779e85e5a8SEugene Zelenko   ~BreakpointNameOptionGroup() override = default;
17785e09c8c3SJim Ingham 
1779b9c1b51eSKate Stone   uint32_t GetNumDefinitions() override {
17805e09c8c3SJim Ingham     return sizeof(g_breakpoint_name_options) / sizeof(OptionDefinition);
17815e09c8c3SJim Ingham   }
17825e09c8c3SJim Ingham 
1783b9c1b51eSKate Stone   const OptionDefinition *GetDefinitions() override {
17845e09c8c3SJim Ingham     return g_breakpoint_name_options;
17855e09c8c3SJim Ingham   }
17865e09c8c3SJim Ingham 
1787b9c1b51eSKate Stone   Error SetOptionValue(uint32_t option_idx, const char *option_value,
1788b9c1b51eSKate Stone                        ExecutionContext *execution_context) override {
17895e09c8c3SJim Ingham     Error error;
17905e09c8c3SJim Ingham     const int short_option = g_breakpoint_name_options[option_idx].short_option;
17916fa7681bSZachary Turner     llvm::StringRef option_strref(option_value ? option_value : "");
17925e09c8c3SJim Ingham 
1793b9c1b51eSKate Stone     switch (short_option) {
17945e09c8c3SJim Ingham     case 'N':
17956fa7681bSZachary Turner       if (BreakpointID::StringIsBreakpointName(option_strref, error) &&
1796b9c1b51eSKate Stone           error.Success())
17976fa7681bSZachary Turner         m_name.SetValueFromString(option_strref);
17985e09c8c3SJim Ingham       break;
17995e09c8c3SJim Ingham 
18005e09c8c3SJim Ingham     case 'B':
1801c95f7e2aSPavel Labath       if (m_breakpoint.SetValueFromString(option_value).Fail())
1802b9c1b51eSKate Stone         error.SetErrorStringWithFormat(
1803b9c1b51eSKate Stone             "unrecognized value \"%s\" for breakpoint", option_value);
18045e09c8c3SJim Ingham       break;
18055e09c8c3SJim Ingham     case 'D':
1806c95f7e2aSPavel Labath       if (m_use_dummy.SetValueFromString(option_value).Fail())
1807b9c1b51eSKate Stone         error.SetErrorStringWithFormat(
1808b9c1b51eSKate Stone             "unrecognized value \"%s\" for use-dummy", option_value);
18095e09c8c3SJim Ingham       break;
18105e09c8c3SJim Ingham 
18115e09c8c3SJim Ingham     default:
1812b9c1b51eSKate Stone       error.SetErrorStringWithFormat("unrecognized short option '%c'",
1813b9c1b51eSKate Stone                                      short_option);
18145e09c8c3SJim Ingham       break;
18155e09c8c3SJim Ingham     }
18165e09c8c3SJim Ingham     return error;
18175e09c8c3SJim Ingham   }
18185e09c8c3SJim Ingham 
1819b9c1b51eSKate Stone   void OptionParsingStarting(ExecutionContext *execution_context) override {
18205e09c8c3SJim Ingham     m_name.Clear();
18215e09c8c3SJim Ingham     m_breakpoint.Clear();
18225e09c8c3SJim Ingham     m_use_dummy.Clear();
18235e09c8c3SJim Ingham     m_use_dummy.SetDefaultValue(false);
18245e09c8c3SJim Ingham   }
18255e09c8c3SJim Ingham 
18265e09c8c3SJim Ingham   OptionValueString m_name;
18275e09c8c3SJim Ingham   OptionValueUInt64 m_breakpoint;
18285e09c8c3SJim Ingham   OptionValueBoolean m_use_dummy;
18295e09c8c3SJim Ingham };
18305e09c8c3SJim Ingham 
1831b9c1b51eSKate Stone class CommandObjectBreakpointNameAdd : public CommandObjectParsed {
18325e09c8c3SJim Ingham public:
1833b9c1b51eSKate Stone   CommandObjectBreakpointNameAdd(CommandInterpreter &interpreter)
1834b9c1b51eSKate Stone       : CommandObjectParsed(
1835b9c1b51eSKate Stone             interpreter, "add", "Add a name to the breakpoints provided.",
18365e09c8c3SJim Ingham             "breakpoint name add <command-options> <breakpoint-id-list>"),
1837b9c1b51eSKate Stone         m_name_options(), m_option_group() {
1838b9c1b51eSKate Stone     // Create the first variant for the first (and only) argument for this
1839b9c1b51eSKate Stone     // command.
18405e09c8c3SJim Ingham     CommandArgumentEntry arg1;
18415e09c8c3SJim Ingham     CommandArgumentData id_arg;
18425e09c8c3SJim Ingham     id_arg.arg_type = eArgTypeBreakpointID;
18435e09c8c3SJim Ingham     id_arg.arg_repetition = eArgRepeatOptional;
18445e09c8c3SJim Ingham     arg1.push_back(id_arg);
18455e09c8c3SJim Ingham     m_arguments.push_back(arg1);
18465e09c8c3SJim Ingham 
18475e09c8c3SJim Ingham     m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
18485e09c8c3SJim Ingham     m_option_group.Finalize();
18495e09c8c3SJim Ingham   }
18505e09c8c3SJim Ingham 
18519e85e5a8SEugene Zelenko   ~CommandObjectBreakpointNameAdd() override = default;
18525e09c8c3SJim Ingham 
1853b9c1b51eSKate Stone   Options *GetOptions() override { return &m_option_group; }
18545e09c8c3SJim Ingham 
18555e09c8c3SJim Ingham protected:
1856b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
1857b9c1b51eSKate Stone     if (!m_name_options.m_name.OptionWasSet()) {
18585e09c8c3SJim Ingham       result.SetError("No name option provided.");
18595e09c8c3SJim Ingham       return false;
18605e09c8c3SJim Ingham     }
18615e09c8c3SJim Ingham 
1862b9c1b51eSKate Stone     Target *target =
1863b9c1b51eSKate Stone         GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
18645e09c8c3SJim Ingham 
1865b9c1b51eSKate Stone     if (target == nullptr) {
18665e09c8c3SJim Ingham       result.AppendError("Invalid target. No existing target or breakpoints.");
18675e09c8c3SJim Ingham       result.SetStatus(eReturnStatusFailed);
18685e09c8c3SJim Ingham       return false;
18695e09c8c3SJim Ingham     }
18705e09c8c3SJim Ingham 
1871bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1872bb19a13cSSaleem Abdulrasool     target->GetBreakpointList().GetListMutex(lock);
18735e09c8c3SJim Ingham 
18745e09c8c3SJim Ingham     const BreakpointList &breakpoints = target->GetBreakpointList();
18755e09c8c3SJim Ingham 
18765e09c8c3SJim Ingham     size_t num_breakpoints = breakpoints.GetSize();
1877b9c1b51eSKate Stone     if (num_breakpoints == 0) {
18785e09c8c3SJim Ingham       result.SetError("No breakpoints, cannot add names.");
18795e09c8c3SJim Ingham       result.SetStatus(eReturnStatusFailed);
18805e09c8c3SJim Ingham       return false;
18815e09c8c3SJim Ingham     }
18825e09c8c3SJim Ingham 
18835e09c8c3SJim Ingham     // Particular breakpoint selected; disable that breakpoint.
18845e09c8c3SJim Ingham     BreakpointIDList valid_bp_ids;
1885b9c1b51eSKate Stone     CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs(
1886b9c1b51eSKate Stone         command, target, result, &valid_bp_ids);
18875e09c8c3SJim Ingham 
1888b9c1b51eSKate Stone     if (result.Succeeded()) {
1889b9c1b51eSKate Stone       if (valid_bp_ids.GetSize() == 0) {
18905e09c8c3SJim Ingham         result.SetError("No breakpoints specified, cannot add names.");
18915e09c8c3SJim Ingham         result.SetStatus(eReturnStatusFailed);
18925e09c8c3SJim Ingham         return false;
18935e09c8c3SJim Ingham       }
18945e09c8c3SJim Ingham       size_t num_valid_ids = valid_bp_ids.GetSize();
1895b9c1b51eSKate Stone       for (size_t index = 0; index < num_valid_ids; index++) {
1896b9c1b51eSKate Stone         lldb::break_id_t bp_id =
1897b9c1b51eSKate Stone             valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
18985e09c8c3SJim Ingham         BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
1899b9c1b51eSKate Stone         Error error; // We don't need to check the error here, since the option
1900b9c1b51eSKate Stone                      // parser checked it...
19015e09c8c3SJim Ingham         bp_sp->AddName(m_name_options.m_name.GetCurrentValue(), error);
19025e09c8c3SJim Ingham       }
19035e09c8c3SJim Ingham     }
19045e09c8c3SJim Ingham 
19055e09c8c3SJim Ingham     return true;
19065e09c8c3SJim Ingham   }
19075e09c8c3SJim Ingham 
19085e09c8c3SJim Ingham private:
19095e09c8c3SJim Ingham   BreakpointNameOptionGroup m_name_options;
19105e09c8c3SJim Ingham   OptionGroupOptions m_option_group;
19115e09c8c3SJim Ingham };
19125e09c8c3SJim Ingham 
1913b9c1b51eSKate Stone class CommandObjectBreakpointNameDelete : public CommandObjectParsed {
19145e09c8c3SJim Ingham public:
1915b9c1b51eSKate Stone   CommandObjectBreakpointNameDelete(CommandInterpreter &interpreter)
1916b9c1b51eSKate Stone       : CommandObjectParsed(
1917b9c1b51eSKate Stone             interpreter, "delete",
19185e09c8c3SJim Ingham             "Delete a name from the breakpoints provided.",
19195e09c8c3SJim Ingham             "breakpoint name delete <command-options> <breakpoint-id-list>"),
1920b9c1b51eSKate Stone         m_name_options(), m_option_group() {
1921b9c1b51eSKate Stone     // Create the first variant for the first (and only) argument for this
1922b9c1b51eSKate Stone     // command.
19235e09c8c3SJim Ingham     CommandArgumentEntry arg1;
19245e09c8c3SJim Ingham     CommandArgumentData id_arg;
19255e09c8c3SJim Ingham     id_arg.arg_type = eArgTypeBreakpointID;
19265e09c8c3SJim Ingham     id_arg.arg_repetition = eArgRepeatOptional;
19275e09c8c3SJim Ingham     arg1.push_back(id_arg);
19285e09c8c3SJim Ingham     m_arguments.push_back(arg1);
19295e09c8c3SJim Ingham 
19305e09c8c3SJim Ingham     m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
19315e09c8c3SJim Ingham     m_option_group.Finalize();
19325e09c8c3SJim Ingham   }
19335e09c8c3SJim Ingham 
19349e85e5a8SEugene Zelenko   ~CommandObjectBreakpointNameDelete() override = default;
19355e09c8c3SJim Ingham 
1936b9c1b51eSKate Stone   Options *GetOptions() override { return &m_option_group; }
19375e09c8c3SJim Ingham 
19385e09c8c3SJim Ingham protected:
1939b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
1940b9c1b51eSKate Stone     if (!m_name_options.m_name.OptionWasSet()) {
19415e09c8c3SJim Ingham       result.SetError("No name option provided.");
19425e09c8c3SJim Ingham       return false;
19435e09c8c3SJim Ingham     }
19445e09c8c3SJim Ingham 
1945b9c1b51eSKate Stone     Target *target =
1946b9c1b51eSKate Stone         GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
19475e09c8c3SJim Ingham 
1948b9c1b51eSKate Stone     if (target == nullptr) {
19495e09c8c3SJim Ingham       result.AppendError("Invalid target. No existing target or breakpoints.");
19505e09c8c3SJim Ingham       result.SetStatus(eReturnStatusFailed);
19515e09c8c3SJim Ingham       return false;
19525e09c8c3SJim Ingham     }
19535e09c8c3SJim Ingham 
1954bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1955bb19a13cSSaleem Abdulrasool     target->GetBreakpointList().GetListMutex(lock);
19565e09c8c3SJim Ingham 
19575e09c8c3SJim Ingham     const BreakpointList &breakpoints = target->GetBreakpointList();
19585e09c8c3SJim Ingham 
19595e09c8c3SJim Ingham     size_t num_breakpoints = breakpoints.GetSize();
1960b9c1b51eSKate Stone     if (num_breakpoints == 0) {
19615e09c8c3SJim Ingham       result.SetError("No breakpoints, cannot delete names.");
19625e09c8c3SJim Ingham       result.SetStatus(eReturnStatusFailed);
19635e09c8c3SJim Ingham       return false;
19645e09c8c3SJim Ingham     }
19655e09c8c3SJim Ingham 
19665e09c8c3SJim Ingham     // Particular breakpoint selected; disable that breakpoint.
19675e09c8c3SJim Ingham     BreakpointIDList valid_bp_ids;
1968b9c1b51eSKate Stone     CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs(
1969b9c1b51eSKate Stone         command, target, result, &valid_bp_ids);
19705e09c8c3SJim Ingham 
1971b9c1b51eSKate Stone     if (result.Succeeded()) {
1972b9c1b51eSKate Stone       if (valid_bp_ids.GetSize() == 0) {
19735e09c8c3SJim Ingham         result.SetError("No breakpoints specified, cannot delete names.");
19745e09c8c3SJim Ingham         result.SetStatus(eReturnStatusFailed);
19755e09c8c3SJim Ingham         return false;
19765e09c8c3SJim Ingham       }
19775e09c8c3SJim Ingham       size_t num_valid_ids = valid_bp_ids.GetSize();
1978b9c1b51eSKate Stone       for (size_t index = 0; index < num_valid_ids; index++) {
1979b9c1b51eSKate Stone         lldb::break_id_t bp_id =
1980b9c1b51eSKate Stone             valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
19815e09c8c3SJim Ingham         BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
19825e09c8c3SJim Ingham         bp_sp->RemoveName(m_name_options.m_name.GetCurrentValue());
19835e09c8c3SJim Ingham       }
19845e09c8c3SJim Ingham     }
19855e09c8c3SJim Ingham 
19865e09c8c3SJim Ingham     return true;
19875e09c8c3SJim Ingham   }
19885e09c8c3SJim Ingham 
19895e09c8c3SJim Ingham private:
19905e09c8c3SJim Ingham   BreakpointNameOptionGroup m_name_options;
19915e09c8c3SJim Ingham   OptionGroupOptions m_option_group;
19925e09c8c3SJim Ingham };
19935e09c8c3SJim Ingham 
1994b9c1b51eSKate Stone class CommandObjectBreakpointNameList : public CommandObjectParsed {
19955e09c8c3SJim Ingham public:
1996b9c1b51eSKate Stone   CommandObjectBreakpointNameList(CommandInterpreter &interpreter)
1997b9c1b51eSKate Stone       : CommandObjectParsed(interpreter, "list",
1998b9c1b51eSKate Stone                             "List either the names for a breakpoint or the "
1999b9c1b51eSKate Stone                             "breakpoints for a given name.",
20005e09c8c3SJim Ingham                             "breakpoint name list <command-options>"),
2001b9c1b51eSKate Stone         m_name_options(), m_option_group() {
20025e09c8c3SJim Ingham     m_option_group.Append(&m_name_options);
20035e09c8c3SJim Ingham     m_option_group.Finalize();
20045e09c8c3SJim Ingham   }
20055e09c8c3SJim Ingham 
20069e85e5a8SEugene Zelenko   ~CommandObjectBreakpointNameList() override = default;
20075e09c8c3SJim Ingham 
2008b9c1b51eSKate Stone   Options *GetOptions() override { return &m_option_group; }
20095e09c8c3SJim Ingham 
20105e09c8c3SJim Ingham protected:
2011b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
2012b9c1b51eSKate Stone     Target *target =
2013b9c1b51eSKate Stone         GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
20145e09c8c3SJim Ingham 
2015b9c1b51eSKate Stone     if (target == nullptr) {
20165e09c8c3SJim Ingham       result.AppendError("Invalid target. No existing target or breakpoints.");
20175e09c8c3SJim Ingham       result.SetStatus(eReturnStatusFailed);
20185e09c8c3SJim Ingham       return false;
20195e09c8c3SJim Ingham     }
20205e09c8c3SJim Ingham 
2021b9c1b51eSKate Stone     if (m_name_options.m_name.OptionWasSet()) {
20225e09c8c3SJim Ingham       const char *name = m_name_options.m_name.GetCurrentValue();
2023bb19a13cSSaleem Abdulrasool       std::unique_lock<std::recursive_mutex> lock;
2024bb19a13cSSaleem Abdulrasool       target->GetBreakpointList().GetListMutex(lock);
20255e09c8c3SJim Ingham 
20265e09c8c3SJim Ingham       BreakpointList &breakpoints = target->GetBreakpointList();
2027b9c1b51eSKate Stone       for (BreakpointSP bp_sp : breakpoints.Breakpoints()) {
2028b9c1b51eSKate Stone         if (bp_sp->MatchesName(name)) {
20295e09c8c3SJim Ingham           StreamString s;
20305e09c8c3SJim Ingham           bp_sp->GetDescription(&s, eDescriptionLevelBrief);
20315e09c8c3SJim Ingham           s.EOL();
20325e09c8c3SJim Ingham           result.AppendMessage(s.GetData());
20335e09c8c3SJim Ingham         }
20345e09c8c3SJim Ingham       }
20355e09c8c3SJim Ingham 
2036b9c1b51eSKate Stone     } else if (m_name_options.m_breakpoint.OptionWasSet()) {
2037b9c1b51eSKate Stone       BreakpointSP bp_sp = target->GetBreakpointList().FindBreakpointByID(
2038b9c1b51eSKate Stone           m_name_options.m_breakpoint.GetCurrentValue());
2039b9c1b51eSKate Stone       if (bp_sp) {
20405e09c8c3SJim Ingham         std::vector<std::string> names;
20415e09c8c3SJim Ingham         bp_sp->GetNames(names);
20425e09c8c3SJim Ingham         result.AppendMessage("Names:");
20435e09c8c3SJim Ingham         for (auto name : names)
20445e09c8c3SJim Ingham           result.AppendMessageWithFormat("    %s\n", name.c_str());
2045b9c1b51eSKate Stone       } else {
2046b9c1b51eSKate Stone         result.AppendErrorWithFormat(
2047b9c1b51eSKate Stone             "Could not find breakpoint %" PRId64 ".\n",
20485e09c8c3SJim Ingham             m_name_options.m_breakpoint.GetCurrentValue());
20495e09c8c3SJim Ingham         result.SetStatus(eReturnStatusFailed);
20505e09c8c3SJim Ingham         return false;
20515e09c8c3SJim Ingham       }
2052b9c1b51eSKate Stone     } else {
20535e09c8c3SJim Ingham       result.SetError("Must specify -N or -B option to list.");
20545e09c8c3SJim Ingham       result.SetStatus(eReturnStatusFailed);
20555e09c8c3SJim Ingham       return false;
20565e09c8c3SJim Ingham     }
20575e09c8c3SJim Ingham     return true;
20585e09c8c3SJim Ingham   }
20595e09c8c3SJim Ingham 
20605e09c8c3SJim Ingham private:
20615e09c8c3SJim Ingham   BreakpointNameOptionGroup m_name_options;
20625e09c8c3SJim Ingham   OptionGroupOptions m_option_group;
20635e09c8c3SJim Ingham };
20645e09c8c3SJim Ingham 
20655e09c8c3SJim Ingham //-------------------------------------------------------------------------
2066e14dc268SJim Ingham // CommandObjectBreakpointName
20675e09c8c3SJim Ingham //-------------------------------------------------------------------------
2068b9c1b51eSKate Stone class CommandObjectBreakpointName : public CommandObjectMultiword {
20695e09c8c3SJim Ingham public:
20707428a18cSKate Stone   CommandObjectBreakpointName(CommandInterpreter &interpreter)
2071b9c1b51eSKate Stone       : CommandObjectMultiword(
2072b9c1b51eSKate Stone             interpreter, "name", "Commands to manage name tags for breakpoints",
2073b9c1b51eSKate Stone             "breakpoint name <subcommand> [<command-options>]") {
2074b9c1b51eSKate Stone     CommandObjectSP add_command_object(
2075b9c1b51eSKate Stone         new CommandObjectBreakpointNameAdd(interpreter));
2076b9c1b51eSKate Stone     CommandObjectSP delete_command_object(
2077b9c1b51eSKate Stone         new CommandObjectBreakpointNameDelete(interpreter));
2078b9c1b51eSKate Stone     CommandObjectSP list_command_object(
2079b9c1b51eSKate Stone         new CommandObjectBreakpointNameList(interpreter));
20805e09c8c3SJim Ingham 
20815e09c8c3SJim Ingham     LoadSubCommand("add", add_command_object);
20825e09c8c3SJim Ingham     LoadSubCommand("delete", delete_command_object);
20835e09c8c3SJim Ingham     LoadSubCommand("list", list_command_object);
20845e09c8c3SJim Ingham   }
20855e09c8c3SJim Ingham 
20869e85e5a8SEugene Zelenko   ~CommandObjectBreakpointName() override = default;
20875e09c8c3SJim Ingham };
20885e09c8c3SJim Ingham 
20895e09c8c3SJim Ingham //-------------------------------------------------------------------------
2090e14dc268SJim Ingham // CommandObjectBreakpointRead
2091e14dc268SJim Ingham //-------------------------------------------------------------------------
2092e14dc268SJim Ingham #pragma mark Restore
2093e14dc268SJim Ingham 
2094e14dc268SJim Ingham class CommandObjectBreakpointRead : public CommandObjectParsed {
2095e14dc268SJim Ingham public:
2096e14dc268SJim Ingham   CommandObjectBreakpointRead(CommandInterpreter &interpreter)
2097e14dc268SJim Ingham       : CommandObjectParsed(interpreter, "breakpoint read",
2098e14dc268SJim Ingham                             "Read and set the breakpoints previously saved to "
2099e14dc268SJim Ingham                             "a file with \"breakpoint write\".  ",
2100e14dc268SJim Ingham                             nullptr),
2101e14dc268SJim Ingham         m_options() {
2102e14dc268SJim Ingham     CommandArgumentEntry arg;
2103e14dc268SJim Ingham     CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
2104e14dc268SJim Ingham                                       eArgTypeBreakpointIDRange);
2105e14dc268SJim Ingham     // Add the entry for the first argument for this command to the object's
2106e14dc268SJim Ingham     // arguments vector.
2107e14dc268SJim Ingham     m_arguments.push_back(arg);
2108e14dc268SJim Ingham   }
2109e14dc268SJim Ingham 
2110e14dc268SJim Ingham   ~CommandObjectBreakpointRead() override = default;
2111e14dc268SJim Ingham 
2112e14dc268SJim Ingham   Options *GetOptions() override { return &m_options; }
2113e14dc268SJim Ingham 
2114e14dc268SJim Ingham   class CommandOptions : public Options {
2115e14dc268SJim Ingham   public:
2116e14dc268SJim Ingham     CommandOptions() : Options() {}
2117e14dc268SJim Ingham 
2118e14dc268SJim Ingham     ~CommandOptions() override = default;
2119e14dc268SJim Ingham 
2120e14dc268SJim Ingham     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
2121e14dc268SJim Ingham                          ExecutionContext *execution_context) override {
2122e14dc268SJim Ingham       Error error;
2123e14dc268SJim Ingham       const int short_option = m_getopt_table[option_idx].val;
2124e14dc268SJim Ingham 
2125e14dc268SJim Ingham       switch (short_option) {
2126e14dc268SJim Ingham       case 'f':
2127e14dc268SJim Ingham         m_filename.assign(option_arg);
2128e14dc268SJim Ingham         break;
2129e14dc268SJim Ingham       default:
2130e14dc268SJim Ingham         error.SetErrorStringWithFormat("unrecognized option '%c'",
2131e14dc268SJim Ingham                                        short_option);
2132e14dc268SJim Ingham         break;
2133e14dc268SJim Ingham       }
2134e14dc268SJim Ingham 
2135e14dc268SJim Ingham       return error;
2136e14dc268SJim Ingham     }
2137e14dc268SJim Ingham 
2138e14dc268SJim Ingham     void OptionParsingStarting(ExecutionContext *execution_context) override {
2139e14dc268SJim Ingham       m_filename.clear();
2140e14dc268SJim Ingham     }
2141e14dc268SJim Ingham 
2142e14dc268SJim Ingham     const OptionDefinition *GetDefinitions() override { return g_option_table; }
2143e14dc268SJim Ingham 
2144e14dc268SJim Ingham     // Options table: Required for subclasses of Options.
2145e14dc268SJim Ingham 
2146e14dc268SJim Ingham     static OptionDefinition g_option_table[];
2147e14dc268SJim Ingham 
2148e14dc268SJim Ingham     // Instance variables to hold the values for command options.
2149e14dc268SJim Ingham 
2150e14dc268SJim Ingham     std::string m_filename;
2151e14dc268SJim Ingham   };
2152e14dc268SJim Ingham 
2153e14dc268SJim Ingham protected:
2154e14dc268SJim Ingham   bool DoExecute(Args &command, CommandReturnObject &result) override {
2155e14dc268SJim Ingham     Target *target = GetSelectedOrDummyTarget();
2156e14dc268SJim Ingham     if (target == nullptr) {
2157e14dc268SJim Ingham       result.AppendError("Invalid target.  No existing target or breakpoints.");
2158e14dc268SJim Ingham       result.SetStatus(eReturnStatusFailed);
2159e14dc268SJim Ingham       return false;
2160e14dc268SJim Ingham     }
2161e14dc268SJim Ingham 
2162e14dc268SJim Ingham     FileSpec input_spec(m_options.m_filename, true);
216301f16664SJim Ingham     BreakpointIDList new_bps;
216401f16664SJim Ingham     Error error = target->CreateBreakpointsFromFile(input_spec, new_bps);
2165e14dc268SJim Ingham 
2166e14dc268SJim Ingham     if (!error.Success()) {
216701f16664SJim Ingham       result.AppendError(error.AsCString());
2168e14dc268SJim Ingham       result.SetStatus(eReturnStatusFailed);
216901f16664SJim Ingham       return false;
2170e14dc268SJim Ingham     }
217101f16664SJim Ingham     // FIXME: Report the newly created breakpoints.
2172e14dc268SJim Ingham     return result.Succeeded();
2173e14dc268SJim Ingham   }
2174e14dc268SJim Ingham 
2175e14dc268SJim Ingham private:
2176e14dc268SJim Ingham   CommandOptions m_options;
2177e14dc268SJim Ingham };
2178e14dc268SJim Ingham 
2179e14dc268SJim Ingham #pragma mark Modify::CommandOptions
2180e14dc268SJim Ingham OptionDefinition CommandObjectBreakpointRead::CommandOptions::g_option_table[] =
2181e14dc268SJim Ingham     {
2182e14dc268SJim Ingham         // clang-format off
2183e14dc268SJim Ingham   {LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename,    "The file from which to read the breakpoints."},
2184e14dc268SJim Ingham   {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
2185e14dc268SJim Ingham         // clang-format on
2186e14dc268SJim Ingham };
2187e14dc268SJim Ingham 
2188e14dc268SJim Ingham //-------------------------------------------------------------------------
2189e14dc268SJim Ingham // CommandObjectBreakpointWrite
2190e14dc268SJim Ingham //-------------------------------------------------------------------------
2191e14dc268SJim Ingham #pragma mark Save
2192e14dc268SJim Ingham class CommandObjectBreakpointWrite : public CommandObjectParsed {
2193e14dc268SJim Ingham public:
2194e14dc268SJim Ingham   CommandObjectBreakpointWrite(CommandInterpreter &interpreter)
2195e14dc268SJim Ingham       : CommandObjectParsed(interpreter, "breakpoint write",
2196e14dc268SJim Ingham                             "Write the breakpoints listed to a file that can "
2197e14dc268SJim Ingham                             "be read in with \"breakpoint read\".  "
2198e14dc268SJim Ingham                             "If given no arguments, writes all breakpoints.",
2199e14dc268SJim Ingham                             nullptr),
2200e14dc268SJim Ingham         m_options() {
2201e14dc268SJim Ingham     CommandArgumentEntry arg;
2202e14dc268SJim Ingham     CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
2203e14dc268SJim Ingham                                       eArgTypeBreakpointIDRange);
2204e14dc268SJim Ingham     // Add the entry for the first argument for this command to the object's
2205e14dc268SJim Ingham     // arguments vector.
2206e14dc268SJim Ingham     m_arguments.push_back(arg);
2207e14dc268SJim Ingham   }
2208e14dc268SJim Ingham 
2209e14dc268SJim Ingham   ~CommandObjectBreakpointWrite() override = default;
2210e14dc268SJim Ingham 
2211e14dc268SJim Ingham   Options *GetOptions() override { return &m_options; }
2212e14dc268SJim Ingham 
2213e14dc268SJim Ingham   class CommandOptions : public Options {
2214e14dc268SJim Ingham   public:
2215e14dc268SJim Ingham     CommandOptions() : Options() {}
2216e14dc268SJim Ingham 
2217e14dc268SJim Ingham     ~CommandOptions() override = default;
2218e14dc268SJim Ingham 
2219e14dc268SJim Ingham     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
2220e14dc268SJim Ingham                          ExecutionContext *execution_context) override {
2221e14dc268SJim Ingham       Error error;
2222e14dc268SJim Ingham       const int short_option = m_getopt_table[option_idx].val;
2223e14dc268SJim Ingham 
2224e14dc268SJim Ingham       switch (short_option) {
2225e14dc268SJim Ingham       case 'f':
2226e14dc268SJim Ingham         m_filename.assign(option_arg);
2227e14dc268SJim Ingham         break;
2228e14dc268SJim Ingham       default:
2229e14dc268SJim Ingham         error.SetErrorStringWithFormat("unrecognized option '%c'",
2230e14dc268SJim Ingham                                        short_option);
2231e14dc268SJim Ingham         break;
2232e14dc268SJim Ingham       }
2233e14dc268SJim Ingham 
2234e14dc268SJim Ingham       return error;
2235e14dc268SJim Ingham     }
2236e14dc268SJim Ingham 
2237e14dc268SJim Ingham     void OptionParsingStarting(ExecutionContext *execution_context) override {
2238e14dc268SJim Ingham       m_filename.clear();
2239e14dc268SJim Ingham     }
2240e14dc268SJim Ingham 
2241e14dc268SJim Ingham     const OptionDefinition *GetDefinitions() override { return g_option_table; }
2242e14dc268SJim Ingham 
2243e14dc268SJim Ingham     // Options table: Required for subclasses of Options.
2244e14dc268SJim Ingham 
2245e14dc268SJim Ingham     static OptionDefinition g_option_table[];
2246e14dc268SJim Ingham 
2247e14dc268SJim Ingham     // Instance variables to hold the values for command options.
2248e14dc268SJim Ingham 
2249e14dc268SJim Ingham     std::string m_filename;
2250e14dc268SJim Ingham   };
2251e14dc268SJim Ingham 
2252e14dc268SJim Ingham protected:
2253e14dc268SJim Ingham   bool DoExecute(Args &command, CommandReturnObject &result) override {
2254e14dc268SJim Ingham     Target *target = GetSelectedOrDummyTarget();
2255e14dc268SJim Ingham     if (target == nullptr) {
2256e14dc268SJim Ingham       result.AppendError("Invalid target.  No existing target or breakpoints.");
2257e14dc268SJim Ingham       result.SetStatus(eReturnStatusFailed);
2258e14dc268SJim Ingham       return false;
2259e14dc268SJim Ingham     }
2260e14dc268SJim Ingham 
2261e14dc268SJim Ingham     std::unique_lock<std::recursive_mutex> lock;
2262e14dc268SJim Ingham     target->GetBreakpointList().GetListMutex(lock);
2263e14dc268SJim Ingham 
2264e14dc268SJim Ingham     BreakpointIDList valid_bp_ids;
226501f16664SJim Ingham     if (command.GetArgumentCount() > 0) {
2266e14dc268SJim Ingham       CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs(
2267e14dc268SJim Ingham           command, target, result, &valid_bp_ids);
2268e14dc268SJim Ingham 
226901f16664SJim Ingham       if (!result.Succeeded()) {
2270e14dc268SJim Ingham         result.SetStatus(eReturnStatusFailed);
2271e14dc268SJim Ingham         return false;
2272e14dc268SJim Ingham       }
2273e14dc268SJim Ingham     }
227401f16664SJim Ingham     Error error = target->SerializeBreakpointsToFile(
227501f16664SJim Ingham         FileSpec(m_options.m_filename.c_str(), true), valid_bp_ids);
227601f16664SJim Ingham     if (!error.Success()) {
227701f16664SJim Ingham       result.AppendErrorWithFormat("error serializing breakpoints: %s.",
227801f16664SJim Ingham                                    error.AsCString());
227901f16664SJim Ingham       result.SetStatus(eReturnStatusFailed);
2280e14dc268SJim Ingham     }
2281e14dc268SJim Ingham     return result.Succeeded();
2282e14dc268SJim Ingham   }
2283e14dc268SJim Ingham 
2284e14dc268SJim Ingham private:
2285e14dc268SJim Ingham   CommandOptions m_options;
2286e14dc268SJim Ingham };
2287e14dc268SJim Ingham 
2288e14dc268SJim Ingham #pragma mark Modify::CommandOptions
2289e14dc268SJim Ingham OptionDefinition
2290e14dc268SJim Ingham     CommandObjectBreakpointWrite::CommandOptions::g_option_table[] = {
2291e14dc268SJim Ingham         // clang-format off
2292e14dc268SJim Ingham   {LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename,    "The file into which to write the breakpoints."},
2293e14dc268SJim Ingham   {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
2294e14dc268SJim Ingham         // clang-format on
2295e14dc268SJim Ingham };
2296e14dc268SJim Ingham 
2297e14dc268SJim Ingham //-------------------------------------------------------------------------
229830fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint
229930fdc8d8SChris Lattner //-------------------------------------------------------------------------
2300ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint
230130fdc8d8SChris Lattner 
2302b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint(
2303b9c1b51eSKate Stone     CommandInterpreter &interpreter)
2304b9c1b51eSKate Stone     : CommandObjectMultiword(
2305b9c1b51eSKate Stone           interpreter, "breakpoint",
23067428a18cSKate Stone           "Commands for operating on breakpoints (see 'help b' for shorthand.)",
2307b9c1b51eSKate Stone           "breakpoint <subcommand> [<command-options>]") {
2308b9c1b51eSKate Stone   CommandObjectSP list_command_object(
2309b9c1b51eSKate Stone       new CommandObjectBreakpointList(interpreter));
2310b9c1b51eSKate Stone   CommandObjectSP enable_command_object(
2311b9c1b51eSKate Stone       new CommandObjectBreakpointEnable(interpreter));
2312b9c1b51eSKate Stone   CommandObjectSP disable_command_object(
2313b9c1b51eSKate Stone       new CommandObjectBreakpointDisable(interpreter));
2314b9c1b51eSKate Stone   CommandObjectSP clear_command_object(
2315b9c1b51eSKate Stone       new CommandObjectBreakpointClear(interpreter));
2316b9c1b51eSKate Stone   CommandObjectSP delete_command_object(
2317b9c1b51eSKate Stone       new CommandObjectBreakpointDelete(interpreter));
2318b9c1b51eSKate Stone   CommandObjectSP set_command_object(
2319b9c1b51eSKate Stone       new CommandObjectBreakpointSet(interpreter));
2320b9c1b51eSKate Stone   CommandObjectSP command_command_object(
2321b9c1b51eSKate Stone       new CommandObjectBreakpointCommand(interpreter));
2322b9c1b51eSKate Stone   CommandObjectSP modify_command_object(
2323b9c1b51eSKate Stone       new CommandObjectBreakpointModify(interpreter));
2324b9c1b51eSKate Stone   CommandObjectSP name_command_object(
2325b9c1b51eSKate Stone       new CommandObjectBreakpointName(interpreter));
2326e14dc268SJim Ingham   CommandObjectSP write_command_object(
2327e14dc268SJim Ingham       new CommandObjectBreakpointWrite(interpreter));
2328e14dc268SJim Ingham   CommandObjectSP read_command_object(
2329e14dc268SJim Ingham       new CommandObjectBreakpointRead(interpreter));
233030fdc8d8SChris Lattner 
2331b7234e40SJohnny Chen   list_command_object->SetCommandName("breakpoint list");
233230fdc8d8SChris Lattner   enable_command_object->SetCommandName("breakpoint enable");
233330fdc8d8SChris Lattner   disable_command_object->SetCommandName("breakpoint disable");
2334b7234e40SJohnny Chen   clear_command_object->SetCommandName("breakpoint clear");
2335b7234e40SJohnny Chen   delete_command_object->SetCommandName("breakpoint delete");
2336ae1c4cf5SJim Ingham   set_command_object->SetCommandName("breakpoint set");
2337b7234e40SJohnny Chen   command_command_object->SetCommandName("breakpoint command");
2338b7234e40SJohnny Chen   modify_command_object->SetCommandName("breakpoint modify");
23395e09c8c3SJim Ingham   name_command_object->SetCommandName("breakpoint name");
2340e14dc268SJim Ingham   write_command_object->SetCommandName("breakpoint write");
2341e14dc268SJim Ingham   read_command_object->SetCommandName("breakpoint read");
234230fdc8d8SChris Lattner 
234323f59509SGreg Clayton   LoadSubCommand("list", list_command_object);
234423f59509SGreg Clayton   LoadSubCommand("enable", enable_command_object);
234523f59509SGreg Clayton   LoadSubCommand("disable", disable_command_object);
234623f59509SGreg Clayton   LoadSubCommand("clear", clear_command_object);
234723f59509SGreg Clayton   LoadSubCommand("delete", delete_command_object);
234823f59509SGreg Clayton   LoadSubCommand("set", set_command_object);
234923f59509SGreg Clayton   LoadSubCommand("command", command_command_object);
235023f59509SGreg Clayton   LoadSubCommand("modify", modify_command_object);
23515e09c8c3SJim Ingham   LoadSubCommand("name", name_command_object);
2352e14dc268SJim Ingham   LoadSubCommand("write", write_command_object);
2353e14dc268SJim Ingham   LoadSubCommand("read", read_command_object);
235430fdc8d8SChris Lattner }
235530fdc8d8SChris Lattner 
23569e85e5a8SEugene Zelenko CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default;
235730fdc8d8SChris Lattner 
2358b9c1b51eSKate Stone void CommandObjectMultiwordBreakpoint::VerifyIDs(Args &args, Target *target,
23595e09c8c3SJim Ingham                                                  bool allow_locations,
23605e09c8c3SJim Ingham                                                  CommandReturnObject &result,
2361b9c1b51eSKate Stone                                                  BreakpointIDList *valid_ids) {
236230fdc8d8SChris Lattner   // args can be strings representing 1). integers (for breakpoint ids)
2363b9c1b51eSKate Stone   //                                  2). the full breakpoint & location
2364b9c1b51eSKate Stone   //                                  canonical representation
2365b9c1b51eSKate Stone   //                                  3). the word "to" or a hyphen,
2366b9c1b51eSKate Stone   //                                  representing a range (in which case there
2367b9c1b51eSKate Stone   //                                      had *better* be an entry both before &
2368b9c1b51eSKate Stone   //                                      after of one of the first two types.
23695e09c8c3SJim Ingham   //                                  4). A breakpoint name
2370b9c1b51eSKate Stone   // If args is empty, we will use the last created breakpoint (if there is
2371b9c1b51eSKate Stone   // one.)
237230fdc8d8SChris Lattner 
237330fdc8d8SChris Lattner   Args temp_args;
237430fdc8d8SChris Lattner 
2375b9c1b51eSKate Stone   if (args.GetArgumentCount() == 0) {
2376b9c1b51eSKate Stone     if (target->GetLastCreatedBreakpoint()) {
2377b9c1b51eSKate Stone       valid_ids->AddBreakpointID(BreakpointID(
2378b9c1b51eSKate Stone           target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
237936f3b369SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
2380b9c1b51eSKate Stone     } else {
2381b9c1b51eSKate Stone       result.AppendError(
2382b9c1b51eSKate Stone           "No breakpoint specified and no last created breakpoint.");
238336f3b369SJim Ingham       result.SetStatus(eReturnStatusFailed);
238436f3b369SJim Ingham     }
238536f3b369SJim Ingham     return;
238636f3b369SJim Ingham   }
238736f3b369SJim Ingham 
2388b9c1b51eSKate Stone   // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff
2389b9c1b51eSKate Stone   // directly from the old ARGS to
2390b9c1b51eSKate Stone   // the new TEMP_ARGS.  Do not copy breakpoint id range strings over; instead
2391b9c1b51eSKate Stone   // generate a list of strings for
2392b9c1b51eSKate Stone   // all the breakpoint ids in the range, and shove all of those breakpoint id
2393b9c1b51eSKate Stone   // strings into TEMP_ARGS.
239430fdc8d8SChris Lattner 
2395b9c1b51eSKate Stone   BreakpointIDList::FindAndReplaceIDRanges(args, target, allow_locations,
2396b9c1b51eSKate Stone                                            result, temp_args);
239730fdc8d8SChris Lattner 
2398b9c1b51eSKate Stone   // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual
2399b9c1b51eSKate Stone   // BreakpointIDList:
240030fdc8d8SChris Lattner 
2401b9c1b51eSKate Stone   valid_ids->InsertStringArray(temp_args.GetConstArgumentVector(),
2402b9c1b51eSKate Stone                                temp_args.GetArgumentCount(), result);
240330fdc8d8SChris Lattner 
2404b9c1b51eSKate Stone   // At this point,  all of the breakpoint ids that the user passed in have been
2405b9c1b51eSKate Stone   // converted to breakpoint IDs
240630fdc8d8SChris Lattner   // and put into valid_ids.
240730fdc8d8SChris Lattner 
2408b9c1b51eSKate Stone   if (result.Succeeded()) {
2409b9c1b51eSKate Stone     // Now that we've converted everything from args into a list of breakpoint
2410b9c1b51eSKate Stone     // ids, go through our tentative list
2411b9c1b51eSKate Stone     // of breakpoint id's and verify that they correspond to valid/currently set
2412b9c1b51eSKate Stone     // breakpoints.
241330fdc8d8SChris Lattner 
2414c982c768SGreg Clayton     const size_t count = valid_ids->GetSize();
2415b9c1b51eSKate Stone     for (size_t i = 0; i < count; ++i) {
241630fdc8d8SChris Lattner       BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex(i);
2417b9c1b51eSKate Stone       Breakpoint *breakpoint =
2418b9c1b51eSKate Stone           target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
2419b9c1b51eSKate Stone       if (breakpoint != nullptr) {
2420c7bece56SGreg Clayton         const size_t num_locations = breakpoint->GetNumLocations();
2421b9c1b51eSKate Stone         if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations) {
242230fdc8d8SChris Lattner           StreamString id_str;
2423b9c1b51eSKate Stone           BreakpointID::GetCanonicalReference(
2424b9c1b51eSKate Stone               &id_str, cur_bp_id.GetBreakpointID(), cur_bp_id.GetLocationID());
2425c982c768SGreg Clayton           i = valid_ids->GetSize() + 1;
2426b9c1b51eSKate Stone           result.AppendErrorWithFormat(
2427b9c1b51eSKate Stone               "'%s' is not a currently valid breakpoint/location id.\n",
242830fdc8d8SChris Lattner               id_str.GetData());
242930fdc8d8SChris Lattner           result.SetStatus(eReturnStatusFailed);
243030fdc8d8SChris Lattner         }
2431b9c1b51eSKate Stone       } else {
2432c982c768SGreg Clayton         i = valid_ids->GetSize() + 1;
2433b9c1b51eSKate Stone         result.AppendErrorWithFormat(
2434b9c1b51eSKate Stone             "'%d' is not a currently valid breakpoint ID.\n",
24357428a18cSKate Stone             cur_bp_id.GetBreakpointID());
243630fdc8d8SChris Lattner         result.SetStatus(eReturnStatusFailed);
243730fdc8d8SChris Lattner       }
243830fdc8d8SChris Lattner     }
243930fdc8d8SChris Lattner   }
244030fdc8d8SChris Lattner }
2441