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;
9530fdc8d8SChris Lattner 
96b9c1b51eSKate Stone       switch (short_option) {
97b9c1b51eSKate Stone       case 'a': {
98b9c1b51eSKate Stone         m_load_addr = Args::StringToAddress(execution_context, option_arg,
99e1cfbc79STodd Fiala                                             LLDB_INVALID_ADDRESS, &error);
100b9c1b51eSKate Stone       } break;
10130fdc8d8SChris Lattner 
102e732052fSJim Ingham       case 'A':
103e732052fSJim Ingham         m_all_files = true;
104e732052fSJim Ingham         break;
105e732052fSJim Ingham 
106ca36cd16SJim Ingham       case 'b':
107ca36cd16SJim Ingham         m_func_names.push_back(option_arg);
108ca36cd16SJim Ingham         m_func_name_type_mask |= eFunctionNameTypeBase;
109ca36cd16SJim Ingham         break;
110ca36cd16SJim Ingham 
111b9c1b51eSKate Stone       case 'C': {
1126312991cSJim Ingham         bool success;
1136312991cSJim Ingham         m_column = StringConvert::ToUInt32(option_arg, 0, 0, &success);
1146312991cSJim Ingham         if (!success)
115b9c1b51eSKate Stone           error.SetErrorStringWithFormat("invalid column number: %s",
116b9c1b51eSKate Stone                                          option_arg);
11730fdc8d8SChris Lattner         break;
1186312991cSJim Ingham       }
1199e85e5a8SEugene Zelenko 
1207d49c9c8SJohnny Chen       case 'c':
1217d49c9c8SJohnny Chen         m_condition.assign(option_arg);
1227d49c9c8SJohnny Chen         break;
1237d49c9c8SJohnny Chen 
12433df7cd3SJim Ingham       case 'D':
12533df7cd3SJim Ingham         m_use_dummy = true;
12633df7cd3SJim Ingham         break;
12733df7cd3SJim Ingham 
128b9c1b51eSKate Stone       case 'E': {
1290e0984eeSJim Ingham         LanguageType language = Language::GetLanguageTypeFromString(option_arg);
130fab10e89SJim Ingham 
131b9c1b51eSKate Stone         switch (language) {
132fab10e89SJim Ingham         case eLanguageTypeC89:
133fab10e89SJim Ingham         case eLanguageTypeC:
134fab10e89SJim Ingham         case eLanguageTypeC99:
1351d0089faSBruce Mitchener         case eLanguageTypeC11:
136a72b31c7SJim Ingham           m_exception_language = eLanguageTypeC;
137fab10e89SJim Ingham           break;
138fab10e89SJim Ingham         case eLanguageTypeC_plus_plus:
1391d0089faSBruce Mitchener         case eLanguageTypeC_plus_plus_03:
1401d0089faSBruce Mitchener         case eLanguageTypeC_plus_plus_11:
1412ba84a6aSBruce Mitchener         case eLanguageTypeC_plus_plus_14:
142a72b31c7SJim Ingham           m_exception_language = eLanguageTypeC_plus_plus;
143fab10e89SJim Ingham           break;
144fab10e89SJim Ingham         case eLanguageTypeObjC:
145a72b31c7SJim Ingham           m_exception_language = eLanguageTypeObjC;
146fab10e89SJim Ingham           break;
147fab10e89SJim Ingham         case eLanguageTypeObjC_plus_plus:
148b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
149b9c1b51eSKate Stone               "Set exception breakpoints separately for c++ and objective-c");
150fab10e89SJim Ingham           break;
151fab10e89SJim Ingham         case eLanguageTypeUnknown:
152b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
153b9c1b51eSKate Stone               "Unknown language type: '%s' for exception breakpoint",
154b9c1b51eSKate Stone               option_arg);
155fab10e89SJim Ingham           break;
156fab10e89SJim Ingham         default:
157b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
158b9c1b51eSKate Stone               "Unsupported language type: '%s' for exception breakpoint",
159b9c1b51eSKate Stone               option_arg);
160fab10e89SJim Ingham         }
161b9c1b51eSKate Stone       } break;
162ca36cd16SJim Ingham 
163ca36cd16SJim Ingham       case 'f':
164ca36cd16SJim Ingham         m_filenames.AppendIfUnique(FileSpec(option_arg, false));
165fab10e89SJim Ingham         break;
166ca36cd16SJim Ingham 
167ca36cd16SJim Ingham       case 'F':
168ca36cd16SJim Ingham         m_func_names.push_back(option_arg);
169ca36cd16SJim Ingham         m_func_name_type_mask |= eFunctionNameTypeFull;
170ca36cd16SJim Ingham         break;
171ca36cd16SJim Ingham 
172b9c1b51eSKate Stone       case 'h': {
173fab10e89SJim Ingham         bool success;
174fab10e89SJim Ingham         m_catch_bp = Args::StringToBoolean(option_arg, true, &success);
175fab10e89SJim Ingham         if (!success)
176b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
177b9c1b51eSKate Stone               "Invalid boolean value for on-catch option: '%s'", option_arg);
178b9c1b51eSKate Stone       } break;
179eb023e75SGreg Clayton 
180eb023e75SGreg Clayton       case 'H':
181eb023e75SGreg Clayton         m_hardware = true;
182eb023e75SGreg Clayton         break;
183eb023e75SGreg Clayton 
184ca36cd16SJim Ingham       case 'i':
1855275aaa0SVince Harron         m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
186ca36cd16SJim Ingham         if (m_ignore_count == UINT32_MAX)
187b9c1b51eSKate Stone           error.SetErrorStringWithFormat("invalid ignore count '%s'",
188b9c1b51eSKate Stone                                          option_arg);
189ca36cd16SJim Ingham         break;
190ca36cd16SJim Ingham 
191b9c1b51eSKate Stone       case 'K': {
192a8558b62SJim Ingham         bool success;
193a8558b62SJim Ingham         bool value;
194a8558b62SJim Ingham         value = Args::StringToBoolean(option_arg, true, &success);
195a8558b62SJim Ingham         if (value)
196a8558b62SJim Ingham           m_skip_prologue = eLazyBoolYes;
197a8558b62SJim Ingham         else
198a8558b62SJim Ingham           m_skip_prologue = eLazyBoolNo;
199a8558b62SJim Ingham 
200a8558b62SJim Ingham         if (!success)
201b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
202b9c1b51eSKate Stone               "Invalid boolean value for skip prologue option: '%s'",
203b9c1b51eSKate Stone               option_arg);
204b9c1b51eSKate Stone       } break;
205ca36cd16SJim Ingham 
206b9c1b51eSKate Stone       case 'l': {
2076312991cSJim Ingham         bool success;
2086312991cSJim Ingham         m_line_num = StringConvert::ToUInt32(option_arg, 0, 0, &success);
2096312991cSJim Ingham         if (!success)
210b9c1b51eSKate Stone           error.SetErrorStringWithFormat("invalid line number: %s.",
211b9c1b51eSKate Stone                                          option_arg);
212ca36cd16SJim Ingham         break;
2136312991cSJim Ingham       }
214055ad9beSIlia K 
21523b1decbSDawn Perchik       case 'L':
2160e0984eeSJim Ingham         m_language = Language::GetLanguageTypeFromString(option_arg);
21723b1decbSDawn Perchik         if (m_language == eLanguageTypeUnknown)
218b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
219b9c1b51eSKate Stone               "Unknown language type: '%s' for breakpoint", option_arg);
22023b1decbSDawn Perchik         break;
22123b1decbSDawn Perchik 
222b9c1b51eSKate Stone       case 'm': {
223055ad9beSIlia K         bool success;
224055ad9beSIlia K         bool value;
225055ad9beSIlia K         value = Args::StringToBoolean(option_arg, true, &success);
226055ad9beSIlia K         if (value)
227055ad9beSIlia K           m_move_to_nearest_code = eLazyBoolYes;
228055ad9beSIlia K         else
229055ad9beSIlia K           m_move_to_nearest_code = eLazyBoolNo;
230055ad9beSIlia K 
231055ad9beSIlia K         if (!success)
232b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
233b9c1b51eSKate Stone               "Invalid boolean value for move-to-nearest-code option: '%s'",
234b9c1b51eSKate Stone               option_arg);
235055ad9beSIlia K         break;
236055ad9beSIlia K       }
237055ad9beSIlia K 
238ca36cd16SJim Ingham       case 'M':
239ca36cd16SJim Ingham         m_func_names.push_back(option_arg);
240ca36cd16SJim Ingham         m_func_name_type_mask |= eFunctionNameTypeMethod;
241ca36cd16SJim Ingham         break;
242ca36cd16SJim Ingham 
243ca36cd16SJim Ingham       case 'n':
244ca36cd16SJim Ingham         m_func_names.push_back(option_arg);
245ca36cd16SJim Ingham         m_func_name_type_mask |= eFunctionNameTypeAuto;
246ca36cd16SJim Ingham         break;
247ca36cd16SJim Ingham 
2485e09c8c3SJim Ingham       case 'N':
2495e09c8c3SJim Ingham         if (BreakpointID::StringIsBreakpointName(option_arg, error))
2505e09c8c3SJim Ingham           m_breakpoint_names.push_back(option_arg);
2515e09c8c3SJim Ingham         break;
2525e09c8c3SJim Ingham 
253b9c1b51eSKate Stone       case 'R': {
2542411167fSJim Ingham         lldb::addr_t tmp_offset_addr;
255e1cfbc79STodd Fiala         tmp_offset_addr =
256b9c1b51eSKate Stone             Args::StringToAddress(execution_context, option_arg, 0, &error);
2572411167fSJim Ingham         if (error.Success())
2582411167fSJim Ingham           m_offset_addr = tmp_offset_addr;
259b9c1b51eSKate Stone       } break;
2602411167fSJim Ingham 
261ca36cd16SJim Ingham       case 'o':
262ca36cd16SJim Ingham         m_one_shot = true;
263ca36cd16SJim Ingham         break;
264ca36cd16SJim Ingham 
265a72b31c7SJim Ingham       case 'O':
266a72b31c7SJim Ingham         m_exception_extra_args.AppendArgument("-O");
267a72b31c7SJim Ingham         m_exception_extra_args.AppendArgument(option_arg);
268a72b31c7SJim Ingham         break;
269a72b31c7SJim Ingham 
270ca36cd16SJim Ingham       case 'p':
271ca36cd16SJim Ingham         m_source_text_regexp.assign(option_arg);
272ca36cd16SJim Ingham         break;
273ca36cd16SJim Ingham 
274ca36cd16SJim Ingham       case 'q':
275ca36cd16SJim Ingham         m_queue_name.assign(option_arg);
276ca36cd16SJim Ingham         break;
277ca36cd16SJim Ingham 
278ca36cd16SJim Ingham       case 'r':
279ca36cd16SJim Ingham         m_func_regexp.assign(option_arg);
280ca36cd16SJim Ingham         break;
281ca36cd16SJim Ingham 
282ca36cd16SJim Ingham       case 's':
283ca36cd16SJim Ingham         m_modules.AppendIfUnique(FileSpec(option_arg, false));
284ca36cd16SJim Ingham         break;
285ca36cd16SJim Ingham 
286ca36cd16SJim Ingham       case 'S':
287ca36cd16SJim Ingham         m_func_names.push_back(option_arg);
288ca36cd16SJim Ingham         m_func_name_type_mask |= eFunctionNameTypeSelector;
289ca36cd16SJim Ingham         break;
290ca36cd16SJim Ingham 
291ca36cd16SJim Ingham       case 't':
292b9c1b51eSKate Stone         m_thread_id =
293b9c1b51eSKate Stone             StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
294ca36cd16SJim Ingham         if (m_thread_id == LLDB_INVALID_THREAD_ID)
295b9c1b51eSKate Stone           error.SetErrorStringWithFormat("invalid thread id string '%s'",
296b9c1b51eSKate Stone                                          option_arg);
297ca36cd16SJim Ingham         break;
298ca36cd16SJim Ingham 
299ca36cd16SJim Ingham       case 'T':
300ca36cd16SJim Ingham         m_thread_name.assign(option_arg);
301ca36cd16SJim Ingham         break;
302ca36cd16SJim Ingham 
303b9c1b51eSKate Stone       case 'w': {
304ca36cd16SJim Ingham         bool success;
305ca36cd16SJim Ingham         m_throw_bp = Args::StringToBoolean(option_arg, true, &success);
306ca36cd16SJim Ingham         if (!success)
307b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
308b9c1b51eSKate Stone               "Invalid boolean value for on-throw option: '%s'", option_arg);
309b9c1b51eSKate Stone       } break;
310ca36cd16SJim Ingham 
311ca36cd16SJim Ingham       case 'x':
3125275aaa0SVince Harron         m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
313ca36cd16SJim Ingham         if (m_thread_id == UINT32_MAX)
314b9c1b51eSKate Stone           error.SetErrorStringWithFormat("invalid thread index string '%s'",
315b9c1b51eSKate Stone                                          option_arg);
316ca36cd16SJim Ingham         break;
317ca36cd16SJim Ingham 
31876bb8d67SJim Ingham       case 'X':
31976bb8d67SJim Ingham         m_source_regex_func_names.insert(option_arg);
32076bb8d67SJim Ingham         break;
32176bb8d67SJim Ingham 
32230fdc8d8SChris Lattner       default:
323b9c1b51eSKate Stone         error.SetErrorStringWithFormat("unrecognized option '%c'",
324b9c1b51eSKate Stone                                        short_option);
32530fdc8d8SChris Lattner         break;
32630fdc8d8SChris Lattner       }
32730fdc8d8SChris Lattner 
32830fdc8d8SChris Lattner       return error;
32930fdc8d8SChris Lattner     }
3309e85e5a8SEugene Zelenko 
331b9c1b51eSKate Stone     void OptionParsingStarting(ExecutionContext *execution_context) override {
3327d49c9c8SJohnny Chen       m_condition.clear();
33387df91b8SJim Ingham       m_filenames.Clear();
33430fdc8d8SChris Lattner       m_line_num = 0;
33530fdc8d8SChris Lattner       m_column = 0;
336fab10e89SJim Ingham       m_func_names.clear();
3371f746071SGreg Clayton       m_func_name_type_mask = eFunctionNameTypeNone;
33830fdc8d8SChris Lattner       m_func_regexp.clear();
3391f746071SGreg Clayton       m_source_text_regexp.clear();
34087df91b8SJim Ingham       m_modules.Clear();
3411f746071SGreg Clayton       m_load_addr = LLDB_INVALID_ADDRESS;
3422411167fSJim Ingham       m_offset_addr = 0;
343c982c768SGreg Clayton       m_ignore_count = 0;
3441b54c88cSJim Ingham       m_thread_id = LLDB_INVALID_THREAD_ID;
345c982c768SGreg Clayton       m_thread_index = UINT32_MAX;
3461b54c88cSJim Ingham       m_thread_name.clear();
3471b54c88cSJim Ingham       m_queue_name.clear();
348fab10e89SJim Ingham       m_catch_bp = false;
349fab10e89SJim Ingham       m_throw_bp = true;
350eb023e75SGreg Clayton       m_hardware = false;
351a72b31c7SJim Ingham       m_exception_language = eLanguageTypeUnknown;
35223b1decbSDawn Perchik       m_language = lldb::eLanguageTypeUnknown;
353a8558b62SJim Ingham       m_skip_prologue = eLazyBoolCalculate;
354ca36cd16SJim Ingham       m_one_shot = false;
35533df7cd3SJim Ingham       m_use_dummy = false;
3565e09c8c3SJim Ingham       m_breakpoint_names.clear();
357e732052fSJim Ingham       m_all_files = false;
358a72b31c7SJim Ingham       m_exception_extra_args.Clear();
359055ad9beSIlia K       m_move_to_nearest_code = eLazyBoolCalculate;
36076bb8d67SJim Ingham       m_source_regex_func_names.clear();
36130fdc8d8SChris Lattner     }
36230fdc8d8SChris Lattner 
363b9c1b51eSKate Stone     const OptionDefinition *GetDefinitions() override { return g_option_table; }
36430fdc8d8SChris Lattner 
3655a988416SJim Ingham     // Options table: Required for subclasses of Options.
36630fdc8d8SChris Lattner 
3675a988416SJim Ingham     static OptionDefinition g_option_table[];
36830fdc8d8SChris Lattner 
3695a988416SJim Ingham     // Instance variables to hold the values for command options.
370969795f1SJim Ingham 
3715a988416SJim Ingham     std::string m_condition;
3725a988416SJim Ingham     FileSpecList m_filenames;
3735a988416SJim Ingham     uint32_t m_line_num;
3745a988416SJim Ingham     uint32_t m_column;
3755a988416SJim Ingham     std::vector<std::string> m_func_names;
3765e09c8c3SJim Ingham     std::vector<std::string> m_breakpoint_names;
3775a988416SJim Ingham     uint32_t m_func_name_type_mask;
3785a988416SJim Ingham     std::string m_func_regexp;
3795a988416SJim Ingham     std::string m_source_text_regexp;
3805a988416SJim Ingham     FileSpecList m_modules;
3815a988416SJim Ingham     lldb::addr_t m_load_addr;
3822411167fSJim Ingham     lldb::addr_t m_offset_addr;
3835a988416SJim Ingham     uint32_t m_ignore_count;
3845a988416SJim Ingham     lldb::tid_t m_thread_id;
3855a988416SJim Ingham     uint32_t m_thread_index;
3865a988416SJim Ingham     std::string m_thread_name;
3875a988416SJim Ingham     std::string m_queue_name;
3885a988416SJim Ingham     bool m_catch_bp;
3895a988416SJim Ingham     bool m_throw_bp;
390eb023e75SGreg Clayton     bool m_hardware; // Request to use hardware breakpoints
391a72b31c7SJim Ingham     lldb::LanguageType m_exception_language;
39223b1decbSDawn Perchik     lldb::LanguageType m_language;
3935a988416SJim Ingham     LazyBool m_skip_prologue;
394ca36cd16SJim Ingham     bool m_one_shot;
39533df7cd3SJim Ingham     bool m_use_dummy;
396e732052fSJim Ingham     bool m_all_files;
397a72b31c7SJim Ingham     Args m_exception_extra_args;
398055ad9beSIlia K     LazyBool m_move_to_nearest_code;
39976bb8d67SJim Ingham     std::unordered_set<std::string> m_source_regex_func_names;
4005a988416SJim Ingham   };
4015a988416SJim Ingham 
4025a988416SJim Ingham protected:
403b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
40433df7cd3SJim Ingham     Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
40533df7cd3SJim Ingham 
406b9c1b51eSKate Stone     if (target == nullptr) {
407b9c1b51eSKate Stone       result.AppendError("Invalid target.  Must set target before setting "
408b9c1b51eSKate Stone                          "breakpoints (see 'target create' command).");
40930fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
41030fdc8d8SChris Lattner       return false;
41130fdc8d8SChris Lattner     }
41230fdc8d8SChris Lattner 
41330fdc8d8SChris Lattner     // The following are the various types of breakpoints that could be set:
41430fdc8d8SChris Lattner     //   1).  -f -l -p  [-s -g]   (setting breakpoint by source location)
41530fdc8d8SChris Lattner     //   2).  -a  [-s -g]         (setting breakpoint by address)
41630fdc8d8SChris Lattner     //   3).  -n  [-s -g]         (setting breakpoint by function name)
417b9c1b51eSKate Stone     //   4).  -r  [-s -g]         (setting breakpoint by function name regular
418b9c1b51eSKate Stone     //   expression)
419b9c1b51eSKate Stone     //   5).  -p -f               (setting a breakpoint by comparing a reg-exp
420b9c1b51eSKate Stone     //   to source text)
421b9c1b51eSKate Stone     //   6).  -E [-w -h]          (setting a breakpoint for exceptions for a
422b9c1b51eSKate Stone     //   given language.)
42330fdc8d8SChris Lattner 
42430fdc8d8SChris Lattner     BreakpointSetType break_type = eSetTypeInvalid;
42530fdc8d8SChris Lattner 
42630fdc8d8SChris Lattner     if (m_options.m_line_num != 0)
42730fdc8d8SChris Lattner       break_type = eSetTypeFileAndLine;
42830fdc8d8SChris Lattner     else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
42930fdc8d8SChris Lattner       break_type = eSetTypeAddress;
430fab10e89SJim Ingham     else if (!m_options.m_func_names.empty())
43130fdc8d8SChris Lattner       break_type = eSetTypeFunctionName;
43230fdc8d8SChris Lattner     else if (!m_options.m_func_regexp.empty())
43330fdc8d8SChris Lattner       break_type = eSetTypeFunctionRegexp;
434969795f1SJim Ingham     else if (!m_options.m_source_text_regexp.empty())
435969795f1SJim Ingham       break_type = eSetTypeSourceRegexp;
436a72b31c7SJim Ingham     else if (m_options.m_exception_language != eLanguageTypeUnknown)
437fab10e89SJim Ingham       break_type = eSetTypeException;
43830fdc8d8SChris Lattner 
4399e85e5a8SEugene Zelenko     Breakpoint *bp = nullptr;
440274060b6SGreg Clayton     FileSpec module_spec;
441a8558b62SJim Ingham     const bool internal = false;
442a8558b62SJim Ingham 
443b9c1b51eSKate Stone     // If the user didn't specify skip-prologue, having an offset should turn
444b9c1b51eSKate Stone     // that off.
445b9c1b51eSKate Stone     if (m_options.m_offset_addr != 0 &&
446b9c1b51eSKate Stone         m_options.m_skip_prologue == eLazyBoolCalculate)
4472411167fSJim Ingham       m_options.m_skip_prologue = eLazyBoolNo;
4482411167fSJim Ingham 
449b9c1b51eSKate Stone     switch (break_type) {
45030fdc8d8SChris Lattner     case eSetTypeFileAndLine: // Breakpoint by source position
45130fdc8d8SChris Lattner     {
45230fdc8d8SChris Lattner       FileSpec file;
453c7bece56SGreg Clayton       const size_t num_files = m_options.m_filenames.GetSize();
454b9c1b51eSKate Stone       if (num_files == 0) {
455b9c1b51eSKate Stone         if (!GetDefaultFile(target, file, result)) {
45687df91b8SJim Ingham           result.AppendError("No file supplied and no default file available.");
45787df91b8SJim Ingham           result.SetStatus(eReturnStatusFailed);
45887df91b8SJim Ingham           return false;
45987df91b8SJim Ingham         }
460b9c1b51eSKate Stone       } else if (num_files > 1) {
461b9c1b51eSKate Stone         result.AppendError("Only one file at a time is allowed for file and "
462b9c1b51eSKate Stone                            "line breakpoints.");
46387df91b8SJim Ingham         result.SetStatus(eReturnStatusFailed);
46487df91b8SJim Ingham         return false;
465b9c1b51eSKate Stone       } else
46687df91b8SJim Ingham         file = m_options.m_filenames.GetFileSpecAtIndex(0);
46730fdc8d8SChris Lattner 
4681f746071SGreg Clayton       // Only check for inline functions if
4691f746071SGreg Clayton       LazyBool check_inlines = eLazyBoolCalculate;
4701f746071SGreg Clayton 
471b9c1b51eSKate Stone       bp = target
472b9c1b51eSKate Stone                ->CreateBreakpoint(&(m_options.m_modules), file,
473b9c1b51eSKate Stone                                   m_options.m_line_num, m_options.m_offset_addr,
474b9c1b51eSKate Stone                                   check_inlines, m_options.m_skip_prologue,
475b9c1b51eSKate Stone                                   internal, m_options.m_hardware,
476b9c1b51eSKate Stone                                   m_options.m_move_to_nearest_code)
477b9c1b51eSKate Stone                .get();
478b9c1b51eSKate Stone     } break;
4796eee5aa0SGreg Clayton 
48030fdc8d8SChris Lattner     case eSetTypeAddress: // Breakpoint by address
481055a08a4SJim Ingham     {
482b9c1b51eSKate Stone       // If a shared library has been specified, make an lldb_private::Address
483b9c1b51eSKate Stone       // with the library, and
484b9c1b51eSKate Stone       // use that.  That way the address breakpoint will track the load location
485b9c1b51eSKate Stone       // of the library.
486055a08a4SJim Ingham       size_t num_modules_specified = m_options.m_modules.GetSize();
487b9c1b51eSKate Stone       if (num_modules_specified == 1) {
488b9c1b51eSKate Stone         const FileSpec *file_spec =
489b9c1b51eSKate Stone             m_options.m_modules.GetFileSpecPointerAtIndex(0);
490b9c1b51eSKate Stone         bp = target
491b9c1b51eSKate Stone                  ->CreateAddressInModuleBreakpoint(m_options.m_load_addr,
492b9c1b51eSKate Stone                                                    internal, file_spec,
493b9c1b51eSKate Stone                                                    m_options.m_hardware)
494b9c1b51eSKate Stone                  .get();
495b9c1b51eSKate Stone       } else if (num_modules_specified == 0) {
496b9c1b51eSKate Stone         bp = target
497b9c1b51eSKate Stone                  ->CreateBreakpoint(m_options.m_load_addr, internal,
498b9c1b51eSKate Stone                                     m_options.m_hardware)
499b9c1b51eSKate Stone                  .get();
500b9c1b51eSKate Stone       } else {
501b9c1b51eSKate Stone         result.AppendError("Only one shared library can be specified for "
502b9c1b51eSKate Stone                            "address breakpoints.");
503055a08a4SJim Ingham         result.SetStatus(eReturnStatusFailed);
504055a08a4SJim Ingham         return false;
505055a08a4SJim Ingham       }
50630fdc8d8SChris Lattner       break;
507055a08a4SJim Ingham     }
50830fdc8d8SChris Lattner     case eSetTypeFunctionName: // Breakpoint by function name
5090c5cd90dSGreg Clayton     {
5100c5cd90dSGreg Clayton       uint32_t name_type_mask = m_options.m_func_name_type_mask;
5110c5cd90dSGreg Clayton 
5120c5cd90dSGreg Clayton       if (name_type_mask == 0)
513e02b8504SGreg Clayton         name_type_mask = eFunctionNameTypeAuto;
5140c5cd90dSGreg Clayton 
515b9c1b51eSKate Stone       bp = target
516b9c1b51eSKate Stone                ->CreateBreakpoint(
517b9c1b51eSKate Stone                    &(m_options.m_modules), &(m_options.m_filenames),
518b9c1b51eSKate Stone                    m_options.m_func_names, name_type_mask, m_options.m_language,
519b9c1b51eSKate Stone                    m_options.m_offset_addr, m_options.m_skip_prologue, internal,
520b9c1b51eSKate Stone                    m_options.m_hardware)
521b9c1b51eSKate Stone                .get();
522b9c1b51eSKate Stone     } break;
5230c5cd90dSGreg Clayton 
524b9c1b51eSKate Stone     case eSetTypeFunctionRegexp: // Breakpoint by regular expression function
525b9c1b51eSKate Stone                                  // name
52630fdc8d8SChris Lattner       {
52730fdc8d8SChris Lattner         RegularExpression regexp(m_options.m_func_regexp.c_str());
528b9c1b51eSKate Stone         if (!regexp.IsValid()) {
529969795f1SJim Ingham           char err_str[1024];
530969795f1SJim Ingham           regexp.GetErrorAsCString(err_str, sizeof(err_str));
531b9c1b51eSKate Stone           result.AppendErrorWithFormat(
532b9c1b51eSKate Stone               "Function name regular expression could not be compiled: \"%s\"",
533969795f1SJim Ingham               err_str);
53430fdc8d8SChris Lattner           result.SetStatus(eReturnStatusFailed);
535969795f1SJim Ingham           return false;
53630fdc8d8SChris Lattner         }
53787df91b8SJim Ingham 
538b9c1b51eSKate Stone         bp = target
539b9c1b51eSKate Stone                  ->CreateFuncRegexBreakpoint(
540b9c1b51eSKate Stone                      &(m_options.m_modules), &(m_options.m_filenames), regexp,
541b9c1b51eSKate Stone                      m_options.m_language, m_options.m_skip_prologue, internal,
542b9c1b51eSKate Stone                      m_options.m_hardware)
543b9c1b51eSKate Stone                  .get();
544e14dc268SJim Ingham       }
545e14dc268SJim Ingham       break;
546969795f1SJim Ingham     case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
547969795f1SJim Ingham     {
548c7bece56SGreg Clayton       const size_t num_files = m_options.m_filenames.GetSize();
54987df91b8SJim Ingham 
550b9c1b51eSKate Stone       if (num_files == 0 && !m_options.m_all_files) {
551969795f1SJim Ingham         FileSpec file;
552b9c1b51eSKate Stone         if (!GetDefaultFile(target, file, result)) {
553b9c1b51eSKate Stone           result.AppendError(
554b9c1b51eSKate Stone               "No files provided and could not find default file.");
55587df91b8SJim Ingham           result.SetStatus(eReturnStatusFailed);
55687df91b8SJim Ingham           return false;
557b9c1b51eSKate Stone         } else {
55887df91b8SJim Ingham           m_options.m_filenames.Append(file);
55987df91b8SJim Ingham         }
56087df91b8SJim Ingham       }
5610c5cd90dSGreg Clayton 
562969795f1SJim Ingham       RegularExpression regexp(m_options.m_source_text_regexp.c_str());
563b9c1b51eSKate Stone       if (!regexp.IsValid()) {
564969795f1SJim Ingham         char err_str[1024];
565969795f1SJim Ingham         regexp.GetErrorAsCString(err_str, sizeof(err_str));
566b9c1b51eSKate Stone         result.AppendErrorWithFormat(
567b9c1b51eSKate Stone             "Source text regular expression could not be compiled: \"%s\"",
568969795f1SJim Ingham             err_str);
569969795f1SJim Ingham         result.SetStatus(eReturnStatusFailed);
570969795f1SJim Ingham         return false;
571969795f1SJim Ingham       }
572b9c1b51eSKate Stone       bp = target
573b9c1b51eSKate Stone                ->CreateSourceRegexBreakpoint(
574b9c1b51eSKate Stone                    &(m_options.m_modules), &(m_options.m_filenames),
575b9c1b51eSKate Stone                    m_options.m_source_regex_func_names, regexp, internal,
576b9c1b51eSKate Stone                    m_options.m_hardware, m_options.m_move_to_nearest_code)
577b9c1b51eSKate Stone                .get();
578b9c1b51eSKate Stone     } break;
579b9c1b51eSKate Stone     case eSetTypeException: {
580a72b31c7SJim Ingham       Error precond_error;
581b9c1b51eSKate Stone       bp = target
582b9c1b51eSKate Stone                ->CreateExceptionBreakpoint(
583b9c1b51eSKate Stone                    m_options.m_exception_language, m_options.m_catch_bp,
584b9c1b51eSKate Stone                    m_options.m_throw_bp, internal,
585b9c1b51eSKate Stone                    &m_options.m_exception_extra_args, &precond_error)
586b9c1b51eSKate Stone                .get();
587b9c1b51eSKate Stone       if (precond_error.Fail()) {
588b9c1b51eSKate Stone         result.AppendErrorWithFormat(
589b9c1b51eSKate Stone             "Error setting extra exception arguments: %s",
590a72b31c7SJim Ingham             precond_error.AsCString());
591a72b31c7SJim Ingham         target->RemoveBreakpointByID(bp->GetID());
592a72b31c7SJim Ingham         result.SetStatus(eReturnStatusFailed);
593a72b31c7SJim Ingham         return false;
594a72b31c7SJim Ingham       }
595b9c1b51eSKate Stone     } break;
59630fdc8d8SChris Lattner     default:
59730fdc8d8SChris Lattner       break;
59830fdc8d8SChris Lattner     }
59930fdc8d8SChris Lattner 
6001b54c88cSJim Ingham     // Now set the various options that were passed in:
601b9c1b51eSKate Stone     if (bp) {
6021b54c88cSJim Ingham       if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
6031b54c88cSJim Ingham         bp->SetThreadID(m_options.m_thread_id);
6041b54c88cSJim Ingham 
605c982c768SGreg Clayton       if (m_options.m_thread_index != UINT32_MAX)
6061b54c88cSJim Ingham         bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
6071b54c88cSJim Ingham 
6081b54c88cSJim Ingham       if (!m_options.m_thread_name.empty())
609b9c1b51eSKate Stone         bp->GetOptions()->GetThreadSpec()->SetName(
610b9c1b51eSKate Stone             m_options.m_thread_name.c_str());
6111b54c88cSJim Ingham 
6121b54c88cSJim Ingham       if (!m_options.m_queue_name.empty())
613b9c1b51eSKate Stone         bp->GetOptions()->GetThreadSpec()->SetQueueName(
614b9c1b51eSKate Stone             m_options.m_queue_name.c_str());
6151b54c88cSJim Ingham 
616c982c768SGreg Clayton       if (m_options.m_ignore_count != 0)
6171b54c88cSJim Ingham         bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
6187d49c9c8SJohnny Chen 
6197d49c9c8SJohnny Chen       if (!m_options.m_condition.empty())
6207d49c9c8SJohnny Chen         bp->GetOptions()->SetCondition(m_options.m_condition.c_str());
621ca36cd16SJim Ingham 
622b9c1b51eSKate Stone       if (!m_options.m_breakpoint_names.empty()) {
623b9c1b51eSKate Stone         Error error; // We don't need to check the error here, since the option
624b9c1b51eSKate Stone                      // parser checked it...
6255e09c8c3SJim Ingham         for (auto name : m_options.m_breakpoint_names)
6265e09c8c3SJim Ingham           bp->AddName(name.c_str(), error);
6275e09c8c3SJim Ingham       }
6285e09c8c3SJim Ingham 
629ca36cd16SJim Ingham       bp->SetOneShot(m_options.m_one_shot);
6301b54c88cSJim Ingham     }
6311b54c88cSJim Ingham 
632b9c1b51eSKate Stone     if (bp) {
63385e8b814SJim Ingham       Stream &output_stream = result.GetOutputStream();
6341391cc7dSJim Ingham       const bool show_locations = false;
635b9c1b51eSKate Stone       bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial,
636b9c1b51eSKate Stone                          show_locations);
6374aeb1989SJim Ingham       if (target == m_interpreter.GetDebugger().GetDummyTarget())
638b9c1b51eSKate Stone         output_stream.Printf("Breakpoint set in dummy target, will get copied "
639b9c1b51eSKate Stone                              "into future targets.\n");
640b9c1b51eSKate Stone       else {
641b9c1b51eSKate Stone         // Don't print out this warning for exception breakpoints.  They can get
642b9c1b51eSKate Stone         // set before the target
643b9c1b51eSKate Stone         // is set, but we won't know how to actually set the breakpoint till we
644b9c1b51eSKate Stone         // run.
645b9c1b51eSKate Stone         if (bp->GetNumLocations() == 0 && break_type != eSetTypeException) {
646b9c1b51eSKate Stone           output_stream.Printf("WARNING:  Unable to resolve breakpoint to any "
647b9c1b51eSKate Stone                                "actual locations.\n");
6484aeb1989SJim Ingham         }
6494aeb1989SJim Ingham       }
65030fdc8d8SChris Lattner       result.SetStatus(eReturnStatusSuccessFinishResult);
651b9c1b51eSKate Stone     } else if (!bp) {
65230fdc8d8SChris Lattner       result.AppendError("Breakpoint creation failed: No breakpoint created.");
65330fdc8d8SChris Lattner       result.SetStatus(eReturnStatusFailed);
65430fdc8d8SChris Lattner     }
65530fdc8d8SChris Lattner 
65630fdc8d8SChris Lattner     return result.Succeeded();
65730fdc8d8SChris Lattner   }
65830fdc8d8SChris Lattner 
6595a988416SJim Ingham private:
660b9c1b51eSKate Stone   bool GetDefaultFile(Target *target, FileSpec &file,
661b9c1b51eSKate Stone                       CommandReturnObject &result) {
6625a988416SJim Ingham     uint32_t default_line;
6635a988416SJim Ingham     // First use the Source Manager's default file.
6645a988416SJim Ingham     // Then use the current stack frame's file.
665b9c1b51eSKate Stone     if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) {
666b57e4a1bSJason Molenda       StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
667b9c1b51eSKate Stone       if (cur_frame == nullptr) {
668b9c1b51eSKate Stone         result.AppendError(
669b9c1b51eSKate Stone             "No selected frame to use to find the default file.");
6705a988416SJim Ingham         result.SetStatus(eReturnStatusFailed);
6715a988416SJim Ingham         return false;
672b9c1b51eSKate Stone       } else if (!cur_frame->HasDebugInformation()) {
673b9c1b51eSKate Stone         result.AppendError("Cannot use the selected frame to find the default "
674b9c1b51eSKate Stone                            "file, it has no debug info.");
6755a988416SJim Ingham         result.SetStatus(eReturnStatusFailed);
6765a988416SJim Ingham         return false;
677b9c1b51eSKate Stone       } else {
678b9c1b51eSKate Stone         const SymbolContext &sc =
679b9c1b51eSKate Stone             cur_frame->GetSymbolContext(eSymbolContextLineEntry);
680b9c1b51eSKate Stone         if (sc.line_entry.file) {
6815a988416SJim Ingham           file = sc.line_entry.file;
682b9c1b51eSKate Stone         } else {
683b9c1b51eSKate Stone           result.AppendError("Can't find the file for the selected frame to "
684b9c1b51eSKate Stone                              "use as the default file.");
6855a988416SJim Ingham           result.SetStatus(eReturnStatusFailed);
6865a988416SJim Ingham           return false;
6875a988416SJim Ingham         }
6885a988416SJim Ingham       }
6895a988416SJim Ingham     }
6905a988416SJim Ingham     return true;
6915a988416SJim Ingham   }
6925a988416SJim Ingham 
6935a988416SJim Ingham   CommandOptions m_options;
6945a988416SJim Ingham };
6959e85e5a8SEugene Zelenko 
6965a988416SJim Ingham // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to
6975a988416SJim Ingham // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately.
6985a988416SJim Ingham #define LLDB_OPT_FILE (LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2)
6995a988416SJim Ingham #define LLDB_OPT_NOT_10 (LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10)
7005a988416SJim Ingham #define LLDB_OPT_SKIP_PROLOGUE (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8))
7012411167fSJim Ingham #define LLDB_OPT_OFFSET_APPLIES (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8))
702055ad9beSIlia K #define LLDB_OPT_MOVE_TO_NEAREST_CODE (LLDB_OPT_SET_1 | LLDB_OPT_SET_9)
7030fcdac36SJim Ingham #define LLDB_OPT_EXPR_LANGUAGE (LLDB_OPT_SET_FROM_TO(3, 8))
7045a988416SJim Ingham 
705b9c1b51eSKate Stone OptionDefinition CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
7065a988416SJim Ingham     {
707ac9c3a62SKate Stone         // clang-format off
708ac9c3a62SKate 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 "
709ac9c3a62SKate Stone                                                                                                                                                                                                    "multiple times to specify multiple shared libraries."},
710ac9c3a62SKate 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." },
711ac9c3a62SKate 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." },
712ac9c3a62SKate 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."},
713ac9c3a62SKate 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."},
714ac9c3a62SKate 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."},
715ac9c3a62SKate 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 "
716ac9c3a62SKate Stone                                                                                                                                                                                                    "argument."},
717ac9c3a62SKate Stone   {LLDB_OPT_SET_ALL,              false, "hardware",               'H', OptionParser::eNoArgument,       nullptr, nullptr, 0,                                         eArgTypeNone,                "Require the breakpoint to use hardware breakpoints."},
718ac9c3a62SKate 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 "
719ac9c3a62SKate Stone                                                                                                                                                                                                    "this argument."},
720ac9c3a62SKate 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 "
721ac9c3a62SKate Stone                                                                                                                                                                                                    "lldb only looks for files that are #included if they use the standard include "
722ac9c3a62SKate Stone                                                                                                                                                                                                    "file extensions.  To set breakpoints on .c/.cpp/.m/.mm files that are "
723ac9c3a62SKate Stone                                                                                                                                                                                                    "#included, set target.inline-breakpoint-strategy to \"always\"."},
724ac9c3a62SKate Stone   {LLDB_OPT_SET_1,                true,  "line",                   'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeLineNum,             "Specifies the line number on which to set this breakpoint."},
7255a988416SJim Ingham 
7265a988416SJim Ingham     // Comment out this option for the moment, as we don't actually use it, but will in the future.
7275a988416SJim Ingham     // This way users won't see it, but the infrastructure is left in place.
7289e85e5a8SEugene Zelenko     //    { 0, false, "column",     'C', OptionParser::eRequiredArgument, nullptr, "<column>",
7295a988416SJim Ingham     //    "Set the breakpoint by source location at this particular column."},
7305a988416SJim Ingham 
731ac9c3a62SKate 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 "
732ac9c3a62SKate Stone                                                                                                                                                                                                    "a particular binary, then the address will be converted to a \"file\" "
733ac9c3a62SKate Stone                                                                                                                                                                                                    "address, so that the breakpoint will track that binary+offset no matter where "
734ac9c3a62SKate Stone                                                                                                                                                                                                    "the binary eventually loads.  Alternately, if you also specify the module - "
735ac9c3a62SKate Stone                                                                                                                                                                                                    "with the -s option - then the address will be treated as a file address in "
736ac9c3a62SKate Stone                                                                                                                                                                                                    "that module, and resolved accordingly.  Again, this will allow lldb to track "
737ac9c3a62SKate Stone                                                                                                                                                                                                    "that offset on subsequent reloads.  The module need not have been loaded at "
738ac9c3a62SKate Stone                                                                                                                                                                                                    "the time you specify this breakpoint, and will get resolved when the module "
739ac9c3a62SKate Stone                                                                                                                                                                                                    "is loaded."},
740ac9c3a62SKate 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 "
741ac9c3a62SKate Stone                                                                                                                                                                                                    "one breakpoint for multiple names"},
742ac9c3a62SKate 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 "
743ac9c3a62SKate Stone                                                                                                                                                                                                    "functions.  Can be repeated multiple times."},
744ac9c3a62SKate 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 "
745ac9c3a62SKate Stone                                                                                                                                                                                                    "namespaces and all arguments, and for Objective C this means a full function "
746ac9c3a62SKate Stone                                                                                                                                                                                                    "prototype with class and selector.  Can be repeated multiple times to make "
747ac9c3a62SKate Stone                                                                                                                                                                                                    "one breakpoint for multiple names."},
748ac9c3a62SKate 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 "
749ac9c3a62SKate Stone                                                                                                                                                                                                    "make one breakpoint for multiple Selectors."},
750ac9c3a62SKate 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 "
751ac9c3a62SKate Stone                                                                                                                                                                                                    "make one breakpoint for multiple methods."},
752ac9c3a62SKate 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 "
753ac9c3a62SKate Stone                                                                                                                                                                                                    "the function name(s)."},
754ac9c3a62SKate 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 "
755ac9c3a62SKate Stone                                                                                                                                                                                                    "ignored).  Can be repeated multiple times to make one breakpoint for multiple "
756ac9c3a62SKate Stone                                                                                                                                                                                                    "symbols."},
757ac9c3a62SKate 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 "
758ac9c3a62SKate Stone                                                                                                                                                                                                    "against the source text in a source file or files specified with the -f "
759ac9c3a62SKate Stone                                                                                                                                                                                                    "option.  The -f option can be specified more than once.  If no source files "
760ac9c3a62SKate Stone                                                                                                                                                                                                    "are specified, uses the current \"default source file\".  If you want to "
761ac9c3a62SKate Stone                                                                                                                                                                                                    "match against all source files, pass the \"--all-files\" option."},
762ac9c3a62SKate Stone   {LLDB_OPT_SET_9,                false, "all-files",              'A', OptionParser::eNoArgument,       nullptr, nullptr, 0,                                         eArgTypeNone,                "All files are searched for source pattern matches."},
763ac9c3a62SKate 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 "
764ac9c3a62SKate Stone                                                                                                                                                                                                    "options, on throw but not catch.)"},
765ac9c3a62SKate Stone   {LLDB_OPT_SET_10,               false, "on-throw",               'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeBoolean,             "Set the breakpoint on exception throW."},
766ac9c3a62SKate Stone   {LLDB_OPT_SET_10,               false, "on-catch",               'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeBoolean,             "Set the breakpoint on exception catcH."},
7675a988416SJim Ingham 
768a72b31c7SJim Ingham //  Don't add this option till it actually does something useful...
7699e85e5a8SEugene Zelenko //    { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName,
770a72b31c7SJim 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" },
771a72b31c7SJim Ingham 
772ac9c3a62SKate 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 "
773ac9c3a62SKate Stone                                                                                                                                                                                                    "(note: currently only implemented for setting breakpoints on identifiers).  "
774ac9c3a62SKate Stone                                                                                                                                                                                                    "If not set the target.language setting is used."},
775ac9c3a62SKate 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.  "
776ac9c3a62SKate Stone                                                                                                                                                                                                    "If not set the target.skip-prologue setting is used."},
777ac9c3a62SKate 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, "
778ac9c3a62SKate Stone                                                                                                                                                                                                    "which prime new targets."},
779ac9c3a62SKate 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."},
780ac9c3a62SKate 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.  "
7812411167fSJim Ingham         "At present this applies the offset directly as given, and doesn't try to align it to instruction boundaries."},
782ac9c3a62SKate 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 "
783ac9c3a62SKate Stone                                                                                                                                                                                                    "setting is used."},
7849e85e5a8SEugene Zelenko   {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
785ac9c3a62SKate Stone         // clang-format on
7865a988416SJim Ingham };
7875a988416SJim Ingham 
7885a988416SJim Ingham //-------------------------------------------------------------------------
7895a988416SJim Ingham // CommandObjectBreakpointModify
7905a988416SJim Ingham //-------------------------------------------------------------------------
7915a988416SJim Ingham #pragma mark Modify
7925a988416SJim Ingham 
793b9c1b51eSKate Stone class CommandObjectBreakpointModify : public CommandObjectParsed {
7945a988416SJim Ingham public:
795b9c1b51eSKate Stone   CommandObjectBreakpointModify(CommandInterpreter &interpreter)
796b9c1b51eSKate Stone       : CommandObjectParsed(interpreter, "breakpoint modify",
797b9c1b51eSKate Stone                             "Modify the options on a breakpoint or set of "
798b9c1b51eSKate Stone                             "breakpoints in the executable.  "
799b9c1b51eSKate Stone                             "If no breakpoint is specified, acts on the last "
800b9c1b51eSKate Stone                             "created breakpoint.  "
801b9c1b51eSKate Stone                             "With the exception of -e, -d and -i, passing an "
802b9c1b51eSKate Stone                             "empty argument clears the modification.",
8039e85e5a8SEugene Zelenko                             nullptr),
804b9c1b51eSKate Stone         m_options() {
8055a988416SJim Ingham     CommandArgumentEntry arg;
806b9c1b51eSKate Stone     CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
807b9c1b51eSKate Stone                                       eArgTypeBreakpointIDRange);
808b9c1b51eSKate Stone     // Add the entry for the first argument for this command to the object's
809b9c1b51eSKate Stone     // arguments vector.
8105a988416SJim Ingham     m_arguments.push_back(arg);
8115a988416SJim Ingham   }
8125a988416SJim Ingham 
8139e85e5a8SEugene Zelenko   ~CommandObjectBreakpointModify() override = default;
8145a988416SJim Ingham 
815b9c1b51eSKate Stone   Options *GetOptions() override { return &m_options; }
8165a988416SJim Ingham 
817b9c1b51eSKate Stone   class CommandOptions : public Options {
8185a988416SJim Ingham   public:
819b9c1b51eSKate Stone     CommandOptions()
820b9c1b51eSKate Stone         : Options(), m_ignore_count(0), m_thread_id(LLDB_INVALID_THREAD_ID),
821b9c1b51eSKate Stone           m_thread_id_passed(false), m_thread_index(UINT32_MAX),
822b9c1b51eSKate Stone           m_thread_index_passed(false), m_thread_name(), m_queue_name(),
823b9c1b51eSKate Stone           m_condition(), m_one_shot(false), m_enable_passed(false),
824b9c1b51eSKate Stone           m_enable_value(false), m_name_passed(false), m_queue_passed(false),
825b9c1b51eSKate Stone           m_condition_passed(false), m_one_shot_passed(false),
826b9c1b51eSKate Stone           m_use_dummy(false) {}
8275a988416SJim Ingham 
8289e85e5a8SEugene Zelenko     ~CommandOptions() override = default;
8295a988416SJim Ingham 
830b9c1b51eSKate Stone     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
831b9c1b51eSKate Stone                          ExecutionContext *execution_context) override {
8325a988416SJim Ingham       Error error;
8333bcdfc0eSGreg Clayton       const int short_option = m_getopt_table[option_idx].val;
8345a988416SJim Ingham 
835b9c1b51eSKate Stone       switch (short_option) {
8365a988416SJim Ingham       case 'c':
8379e85e5a8SEugene Zelenko         if (option_arg != nullptr)
8385a988416SJim Ingham           m_condition.assign(option_arg);
8395a988416SJim Ingham         else
8405a988416SJim Ingham           m_condition.clear();
8415a988416SJim Ingham         m_condition_passed = true;
8425a988416SJim Ingham         break;
8435a988416SJim Ingham       case 'd':
8445a988416SJim Ingham         m_enable_passed = true;
8455a988416SJim Ingham         m_enable_value = false;
8465a988416SJim Ingham         break;
84733df7cd3SJim Ingham       case 'D':
84833df7cd3SJim Ingham         m_use_dummy = true;
84933df7cd3SJim Ingham         break;
8505a988416SJim Ingham       case 'e':
8515a988416SJim Ingham         m_enable_passed = true;
8525a988416SJim Ingham         m_enable_value = true;
8535a988416SJim Ingham         break;
8545a988416SJim Ingham       case 'i':
8555275aaa0SVince Harron         m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
8565a988416SJim Ingham         if (m_ignore_count == UINT32_MAX)
857b9c1b51eSKate Stone           error.SetErrorStringWithFormat("invalid ignore count '%s'",
858b9c1b51eSKate Stone                                          option_arg);
8595a988416SJim Ingham         break;
860b9c1b51eSKate Stone       case 'o': {
861ca36cd16SJim Ingham         bool value, success;
862ca36cd16SJim Ingham         value = Args::StringToBoolean(option_arg, false, &success);
863b9c1b51eSKate Stone         if (success) {
864ca36cd16SJim Ingham           m_one_shot_passed = true;
865ca36cd16SJim Ingham           m_one_shot = value;
866b9c1b51eSKate Stone         } else
867b9c1b51eSKate Stone           error.SetErrorStringWithFormat(
868b9c1b51eSKate Stone               "invalid boolean value '%s' passed for -o option", option_arg);
869b9c1b51eSKate Stone       } break;
8705a988416SJim Ingham       case 't':
871b9c1b51eSKate Stone         if (option_arg[0] == '\0') {
8725a988416SJim Ingham           m_thread_id = LLDB_INVALID_THREAD_ID;
8735a988416SJim Ingham           m_thread_id_passed = true;
874b9c1b51eSKate Stone         } else {
875b9c1b51eSKate Stone           m_thread_id =
876b9c1b51eSKate Stone               StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
8775a988416SJim Ingham           if (m_thread_id == LLDB_INVALID_THREAD_ID)
878b9c1b51eSKate Stone             error.SetErrorStringWithFormat("invalid thread id string '%s'",
879b9c1b51eSKate Stone                                            option_arg);
8805a988416SJim Ingham           else
8815a988416SJim Ingham             m_thread_id_passed = true;
8825a988416SJim Ingham         }
8835a988416SJim Ingham         break;
8845a988416SJim Ingham       case 'T':
8859e85e5a8SEugene Zelenko         if (option_arg != nullptr)
8865a988416SJim Ingham           m_thread_name.assign(option_arg);
8875a988416SJim Ingham         else
8885a988416SJim Ingham           m_thread_name.clear();
8895a988416SJim Ingham         m_name_passed = true;
8905a988416SJim Ingham         break;
8915a988416SJim Ingham       case 'q':
8929e85e5a8SEugene Zelenko         if (option_arg != nullptr)
8935a988416SJim Ingham           m_queue_name.assign(option_arg);
8945a988416SJim Ingham         else
8955a988416SJim Ingham           m_queue_name.clear();
8965a988416SJim Ingham         m_queue_passed = true;
8975a988416SJim Ingham         break;
8985a988416SJim Ingham       case 'x':
899b9c1b51eSKate Stone         if (option_arg[0] == '\n') {
9005a988416SJim Ingham           m_thread_index = UINT32_MAX;
9015a988416SJim Ingham           m_thread_index_passed = true;
902b9c1b51eSKate Stone         } else {
9035275aaa0SVince Harron           m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
9045a988416SJim Ingham           if (m_thread_id == UINT32_MAX)
905b9c1b51eSKate Stone             error.SetErrorStringWithFormat("invalid thread index string '%s'",
906b9c1b51eSKate Stone                                            option_arg);
9075a988416SJim Ingham           else
9085a988416SJim Ingham             m_thread_index_passed = true;
9095a988416SJim Ingham         }
9105a988416SJim Ingham         break;
9115a988416SJim Ingham       default:
912b9c1b51eSKate Stone         error.SetErrorStringWithFormat("unrecognized option '%c'",
913b9c1b51eSKate Stone                                        short_option);
9145a988416SJim Ingham         break;
9155a988416SJim Ingham       }
9165a988416SJim Ingham 
9175a988416SJim Ingham       return error;
9185a988416SJim Ingham     }
9199e85e5a8SEugene Zelenko 
920b9c1b51eSKate Stone     void OptionParsingStarting(ExecutionContext *execution_context) override {
9215a988416SJim Ingham       m_ignore_count = 0;
9225a988416SJim Ingham       m_thread_id = LLDB_INVALID_THREAD_ID;
9235a988416SJim Ingham       m_thread_id_passed = false;
9245a988416SJim Ingham       m_thread_index = UINT32_MAX;
9255a988416SJim Ingham       m_thread_index_passed = false;
9265a988416SJim Ingham       m_thread_name.clear();
9275a988416SJim Ingham       m_queue_name.clear();
9285a988416SJim Ingham       m_condition.clear();
929ca36cd16SJim Ingham       m_one_shot = false;
9305a988416SJim Ingham       m_enable_passed = false;
9315a988416SJim Ingham       m_queue_passed = false;
9325a988416SJim Ingham       m_name_passed = false;
9335a988416SJim Ingham       m_condition_passed = false;
934ca36cd16SJim Ingham       m_one_shot_passed = false;
93533df7cd3SJim Ingham       m_use_dummy = false;
9365a988416SJim Ingham     }
9375a988416SJim Ingham 
938b9c1b51eSKate Stone     const OptionDefinition *GetDefinitions() override { return g_option_table; }
9395a988416SJim Ingham 
9405a988416SJim Ingham     // Options table: Required for subclasses of Options.
9415a988416SJim Ingham 
9425a988416SJim Ingham     static OptionDefinition g_option_table[];
9435a988416SJim Ingham 
9445a988416SJim Ingham     // Instance variables to hold the values for command options.
9455a988416SJim Ingham 
9465a988416SJim Ingham     uint32_t m_ignore_count;
9475a988416SJim Ingham     lldb::tid_t m_thread_id;
9485a988416SJim Ingham     bool m_thread_id_passed;
9495a988416SJim Ingham     uint32_t m_thread_index;
9505a988416SJim Ingham     bool m_thread_index_passed;
9515a988416SJim Ingham     std::string m_thread_name;
9525a988416SJim Ingham     std::string m_queue_name;
9535a988416SJim Ingham     std::string m_condition;
954ca36cd16SJim Ingham     bool m_one_shot;
9555a988416SJim Ingham     bool m_enable_passed;
9565a988416SJim Ingham     bool m_enable_value;
9575a988416SJim Ingham     bool m_name_passed;
9585a988416SJim Ingham     bool m_queue_passed;
9595a988416SJim Ingham     bool m_condition_passed;
960ca36cd16SJim Ingham     bool m_one_shot_passed;
96133df7cd3SJim Ingham     bool m_use_dummy;
9625a988416SJim Ingham   };
9635a988416SJim Ingham 
9645a988416SJim Ingham protected:
965b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
96633df7cd3SJim Ingham     Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
967b9c1b51eSKate Stone     if (target == nullptr) {
9685a988416SJim Ingham       result.AppendError("Invalid target.  No existing target or breakpoints.");
9695a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
9705a988416SJim Ingham       return false;
9715a988416SJim Ingham     }
9725a988416SJim Ingham 
973bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
974bb19a13cSSaleem Abdulrasool     target->GetBreakpointList().GetListMutex(lock);
9755a988416SJim Ingham 
9765a988416SJim Ingham     BreakpointIDList valid_bp_ids;
9775a988416SJim Ingham 
978b9c1b51eSKate Stone     CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
979b9c1b51eSKate Stone         command, target, result, &valid_bp_ids);
9805a988416SJim Ingham 
981b9c1b51eSKate Stone     if (result.Succeeded()) {
9825a988416SJim Ingham       const size_t count = valid_bp_ids.GetSize();
983b9c1b51eSKate Stone       for (size_t i = 0; i < count; ++i) {
9845a988416SJim Ingham         BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
9855a988416SJim Ingham 
986b9c1b51eSKate Stone         if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
987b9c1b51eSKate Stone           Breakpoint *bp =
988b9c1b51eSKate Stone               target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
989b9c1b51eSKate Stone           if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
990b9c1b51eSKate Stone             BreakpointLocation *location =
991b9c1b51eSKate Stone                 bp->FindLocationByID(cur_bp_id.GetLocationID()).get();
992b9c1b51eSKate Stone             if (location) {
9935a988416SJim Ingham               if (m_options.m_thread_id_passed)
9945a988416SJim Ingham                 location->SetThreadID(m_options.m_thread_id);
9955a988416SJim Ingham 
9965a988416SJim Ingham               if (m_options.m_thread_index_passed)
9975a988416SJim Ingham                 location->SetThreadIndex(m_options.m_thread_index);
9985a988416SJim Ingham 
9995a988416SJim Ingham               if (m_options.m_name_passed)
10005a988416SJim Ingham                 location->SetThreadName(m_options.m_thread_name.c_str());
10015a988416SJim Ingham 
10025a988416SJim Ingham               if (m_options.m_queue_passed)
10035a988416SJim Ingham                 location->SetQueueName(m_options.m_queue_name.c_str());
10045a988416SJim Ingham 
10055a988416SJim Ingham               if (m_options.m_ignore_count != 0)
10065a988416SJim Ingham                 location->SetIgnoreCount(m_options.m_ignore_count);
10075a988416SJim Ingham 
10085a988416SJim Ingham               if (m_options.m_enable_passed)
10095a988416SJim Ingham                 location->SetEnabled(m_options.m_enable_value);
10105a988416SJim Ingham 
10115a988416SJim Ingham               if (m_options.m_condition_passed)
10125a988416SJim Ingham                 location->SetCondition(m_options.m_condition.c_str());
10135a988416SJim Ingham             }
1014b9c1b51eSKate Stone           } else {
10155a988416SJim Ingham             if (m_options.m_thread_id_passed)
10165a988416SJim Ingham               bp->SetThreadID(m_options.m_thread_id);
10175a988416SJim Ingham 
10185a988416SJim Ingham             if (m_options.m_thread_index_passed)
10195a988416SJim Ingham               bp->SetThreadIndex(m_options.m_thread_index);
10205a988416SJim Ingham 
10215a988416SJim Ingham             if (m_options.m_name_passed)
10225a988416SJim Ingham               bp->SetThreadName(m_options.m_thread_name.c_str());
10235a988416SJim Ingham 
10245a988416SJim Ingham             if (m_options.m_queue_passed)
10255a988416SJim Ingham               bp->SetQueueName(m_options.m_queue_name.c_str());
10265a988416SJim Ingham 
10275a988416SJim Ingham             if (m_options.m_ignore_count != 0)
10285a988416SJim Ingham               bp->SetIgnoreCount(m_options.m_ignore_count);
10295a988416SJim Ingham 
10305a988416SJim Ingham             if (m_options.m_enable_passed)
10315a988416SJim Ingham               bp->SetEnabled(m_options.m_enable_value);
10325a988416SJim Ingham 
10335a988416SJim Ingham             if (m_options.m_condition_passed)
10345a988416SJim Ingham               bp->SetCondition(m_options.m_condition.c_str());
10355a988416SJim Ingham           }
10365a988416SJim Ingham         }
10375a988416SJim Ingham       }
10385a988416SJim Ingham     }
10395a988416SJim Ingham 
10405a988416SJim Ingham     return result.Succeeded();
10415a988416SJim Ingham   }
10425a988416SJim Ingham 
10435a988416SJim Ingham private:
10445a988416SJim Ingham   CommandOptions m_options;
10455a988416SJim Ingham };
10465a988416SJim Ingham 
10475a988416SJim Ingham #pragma mark Modify::CommandOptions
10485a988416SJim Ingham OptionDefinition
1049b9c1b51eSKate Stone     CommandObjectBreakpointModify::CommandOptions::g_option_table[] = {
1050ac9c3a62SKate Stone         // clang-format off
10519e85e5a8SEugene 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."},
10529e85e5a8SEugene 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."},
10539e85e5a8SEugene 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."},
10549e85e5a8SEugene 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."},
10559e85e5a8SEugene 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."},
10569e85e5a8SEugene 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."},
10579e85e5a8SEugene 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."},
10589e85e5a8SEugene Zelenko   {LLDB_OPT_SET_1,   false, "enable",       'e', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,        "Enable the breakpoint."},
10599e85e5a8SEugene Zelenko   {LLDB_OPT_SET_2,   false, "disable",      'd', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,        "Disable the breakpoint."},
10609e85e5a8SEugene 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."},
10619e85e5a8SEugene Zelenko   {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
1062ac9c3a62SKate Stone         // clang-format on
10635a988416SJim Ingham };
10645a988416SJim Ingham 
10655a988416SJim Ingham //-------------------------------------------------------------------------
10665a988416SJim Ingham // CommandObjectBreakpointEnable
10675a988416SJim Ingham //-------------------------------------------------------------------------
10685a988416SJim Ingham #pragma mark Enable
10695a988416SJim Ingham 
1070b9c1b51eSKate Stone class CommandObjectBreakpointEnable : public CommandObjectParsed {
10715a988416SJim Ingham public:
1072b9c1b51eSKate Stone   CommandObjectBreakpointEnable(CommandInterpreter &interpreter)
1073b9c1b51eSKate Stone       : CommandObjectParsed(interpreter, "enable",
1074b9c1b51eSKate Stone                             "Enable the specified disabled breakpoint(s). If "
1075b9c1b51eSKate Stone                             "no breakpoints are specified, enable all of them.",
1076b9c1b51eSKate Stone                             nullptr) {
10775a988416SJim Ingham     CommandArgumentEntry arg;
1078b9c1b51eSKate Stone     CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
1079b9c1b51eSKate Stone                                       eArgTypeBreakpointIDRange);
1080b9c1b51eSKate Stone     // Add the entry for the first argument for this command to the object's
1081b9c1b51eSKate Stone     // arguments vector.
10825a988416SJim Ingham     m_arguments.push_back(arg);
10835a988416SJim Ingham   }
10845a988416SJim Ingham 
10859e85e5a8SEugene Zelenko   ~CommandObjectBreakpointEnable() override = default;
10865a988416SJim Ingham 
10875a988416SJim Ingham protected:
1088b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
1089893c932aSJim Ingham     Target *target = GetSelectedOrDummyTarget();
1090b9c1b51eSKate Stone     if (target == nullptr) {
10915a988416SJim Ingham       result.AppendError("Invalid target.  No existing target or breakpoints.");
10925a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
10935a988416SJim Ingham       return false;
10945a988416SJim Ingham     }
10955a988416SJim Ingham 
1096bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1097bb19a13cSSaleem Abdulrasool     target->GetBreakpointList().GetListMutex(lock);
10985a988416SJim Ingham 
10995a988416SJim Ingham     const BreakpointList &breakpoints = target->GetBreakpointList();
11005a988416SJim Ingham 
11015a988416SJim Ingham     size_t num_breakpoints = breakpoints.GetSize();
11025a988416SJim Ingham 
1103b9c1b51eSKate Stone     if (num_breakpoints == 0) {
11045a988416SJim Ingham       result.AppendError("No breakpoints exist to be enabled.");
11055a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
11065a988416SJim Ingham       return false;
11075a988416SJim Ingham     }
11085a988416SJim Ingham 
1109b9c1b51eSKate Stone     if (command.GetArgumentCount() == 0) {
11105a988416SJim Ingham       // No breakpoint selected; enable all currently set breakpoints.
11115a988416SJim Ingham       target->EnableAllBreakpoints();
1112b9c1b51eSKate Stone       result.AppendMessageWithFormat("All breakpoints enabled. (%" PRIu64
1113b9c1b51eSKate Stone                                      " breakpoints)\n",
1114b9c1b51eSKate Stone                                      (uint64_t)num_breakpoints);
11155a988416SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
1116b9c1b51eSKate Stone     } else {
11175a988416SJim Ingham       // Particular breakpoint selected; enable that breakpoint.
11185a988416SJim Ingham       BreakpointIDList valid_bp_ids;
1119b9c1b51eSKate Stone       CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
1120b9c1b51eSKate Stone           command, target, result, &valid_bp_ids);
11215a988416SJim Ingham 
1122b9c1b51eSKate Stone       if (result.Succeeded()) {
11235a988416SJim Ingham         int enable_count = 0;
11245a988416SJim Ingham         int loc_count = 0;
11255a988416SJim Ingham         const size_t count = valid_bp_ids.GetSize();
1126b9c1b51eSKate Stone         for (size_t i = 0; i < count; ++i) {
11275a988416SJim Ingham           BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
11285a988416SJim Ingham 
1129b9c1b51eSKate Stone           if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
1130b9c1b51eSKate Stone             Breakpoint *breakpoint =
1131b9c1b51eSKate Stone                 target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
1132b9c1b51eSKate Stone             if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
1133b9c1b51eSKate Stone               BreakpointLocation *location =
1134b9c1b51eSKate Stone                   breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get();
1135b9c1b51eSKate Stone               if (location) {
11365a988416SJim Ingham                 location->SetEnabled(true);
11375a988416SJim Ingham                 ++loc_count;
11385a988416SJim Ingham               }
1139b9c1b51eSKate Stone             } else {
11405a988416SJim Ingham               breakpoint->SetEnabled(true);
11415a988416SJim Ingham               ++enable_count;
11425a988416SJim Ingham             }
11435a988416SJim Ingham           }
11445a988416SJim Ingham         }
1145b9c1b51eSKate Stone         result.AppendMessageWithFormat("%d breakpoints enabled.\n",
1146b9c1b51eSKate Stone                                        enable_count + loc_count);
11475a988416SJim Ingham         result.SetStatus(eReturnStatusSuccessFinishNoResult);
11485a988416SJim Ingham       }
11495a988416SJim Ingham     }
11505a988416SJim Ingham 
11515a988416SJim Ingham     return result.Succeeded();
11525a988416SJim Ingham   }
11535a988416SJim Ingham };
11545a988416SJim Ingham 
11555a988416SJim Ingham //-------------------------------------------------------------------------
11565a988416SJim Ingham // CommandObjectBreakpointDisable
11575a988416SJim Ingham //-------------------------------------------------------------------------
11585a988416SJim Ingham #pragma mark Disable
11595a988416SJim Ingham 
1160b9c1b51eSKate Stone class CommandObjectBreakpointDisable : public CommandObjectParsed {
11615a988416SJim Ingham public:
11627428a18cSKate Stone   CommandObjectBreakpointDisable(CommandInterpreter &interpreter)
1163b9c1b51eSKate Stone       : CommandObjectParsed(
1164b9c1b51eSKate Stone             interpreter, "breakpoint disable",
1165b9c1b51eSKate Stone             "Disable the specified breakpoint(s) without deleting "
11667428a18cSKate Stone             "them.  If none are specified, disable all "
11677428a18cSKate Stone             "breakpoints.",
1168b9c1b51eSKate Stone             nullptr) {
1169b9c1b51eSKate Stone     SetHelpLong(
1170b9c1b51eSKate Stone         "Disable the specified breakpoint(s) without deleting them.  \
11717428a18cSKate Stone If none are specified, disable all breakpoints."
11727428a18cSKate Stone         R"(
1173ea671fbdSKate Stone 
11747428a18cSKate Stone )"
11757428a18cSKate Stone         "Note: disabling a breakpoint will cause none of its locations to be hit \
11767428a18cSKate Stone regardless of whether individual locations are enabled or disabled.  After the sequence:"
11777428a18cSKate Stone         R"(
1178ea671fbdSKate Stone 
1179ea671fbdSKate Stone     (lldb) break disable 1
1180ea671fbdSKate Stone     (lldb) break enable 1.1
1181ea671fbdSKate Stone 
1182ea671fbdSKate Stone execution will NOT stop at location 1.1.  To achieve that, type:
1183ea671fbdSKate Stone 
1184ea671fbdSKate Stone     (lldb) break disable 1.*
1185ea671fbdSKate Stone     (lldb) break enable 1.1
1186ea671fbdSKate Stone 
11877428a18cSKate Stone )"
11887428a18cSKate Stone         "The first command disables all locations for breakpoint 1, \
11897428a18cSKate Stone the second re-enables the first location.");
1190b0fac509SJim Ingham 
11915a988416SJim Ingham     CommandArgumentEntry arg;
1192b9c1b51eSKate Stone     CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
1193b9c1b51eSKate Stone                                       eArgTypeBreakpointIDRange);
1194b9c1b51eSKate Stone     // Add the entry for the first argument for this command to the object's
1195b9c1b51eSKate Stone     // arguments vector.
11965a988416SJim Ingham     m_arguments.push_back(arg);
11975a988416SJim Ingham   }
11985a988416SJim Ingham 
11999e85e5a8SEugene Zelenko   ~CommandObjectBreakpointDisable() override = default;
12005a988416SJim Ingham 
12015a988416SJim Ingham protected:
1202b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
1203893c932aSJim Ingham     Target *target = GetSelectedOrDummyTarget();
1204b9c1b51eSKate Stone     if (target == nullptr) {
12055a988416SJim Ingham       result.AppendError("Invalid target.  No existing target or breakpoints.");
12065a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
12075a988416SJim Ingham       return false;
12085a988416SJim Ingham     }
12095a988416SJim Ingham 
1210bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1211bb19a13cSSaleem Abdulrasool     target->GetBreakpointList().GetListMutex(lock);
12125a988416SJim Ingham 
12135a988416SJim Ingham     const BreakpointList &breakpoints = target->GetBreakpointList();
12145a988416SJim Ingham     size_t num_breakpoints = breakpoints.GetSize();
12155a988416SJim Ingham 
1216b9c1b51eSKate Stone     if (num_breakpoints == 0) {
12175a988416SJim Ingham       result.AppendError("No breakpoints exist to be disabled.");
12185a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
12195a988416SJim Ingham       return false;
12205a988416SJim Ingham     }
12215a988416SJim Ingham 
1222b9c1b51eSKate Stone     if (command.GetArgumentCount() == 0) {
12235a988416SJim Ingham       // No breakpoint selected; disable all currently set breakpoints.
12245a988416SJim Ingham       target->DisableAllBreakpoints();
1225b9c1b51eSKate Stone       result.AppendMessageWithFormat("All breakpoints disabled. (%" PRIu64
1226b9c1b51eSKate Stone                                      " breakpoints)\n",
1227b9c1b51eSKate Stone                                      (uint64_t)num_breakpoints);
12285a988416SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
1229b9c1b51eSKate Stone     } else {
12305a988416SJim Ingham       // Particular breakpoint selected; disable that breakpoint.
12315a988416SJim Ingham       BreakpointIDList valid_bp_ids;
12325a988416SJim Ingham 
1233b9c1b51eSKate Stone       CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
1234b9c1b51eSKate Stone           command, target, result, &valid_bp_ids);
12355a988416SJim Ingham 
1236b9c1b51eSKate Stone       if (result.Succeeded()) {
12375a988416SJim Ingham         int disable_count = 0;
12385a988416SJim Ingham         int loc_count = 0;
12395a988416SJim Ingham         const size_t count = valid_bp_ids.GetSize();
1240b9c1b51eSKate Stone         for (size_t i = 0; i < count; ++i) {
12415a988416SJim Ingham           BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
12425a988416SJim Ingham 
1243b9c1b51eSKate Stone           if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
1244b9c1b51eSKate Stone             Breakpoint *breakpoint =
1245b9c1b51eSKate Stone                 target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
1246b9c1b51eSKate Stone             if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
1247b9c1b51eSKate Stone               BreakpointLocation *location =
1248b9c1b51eSKate Stone                   breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get();
1249b9c1b51eSKate Stone               if (location) {
12505a988416SJim Ingham                 location->SetEnabled(false);
12515a988416SJim Ingham                 ++loc_count;
12525a988416SJim Ingham               }
1253b9c1b51eSKate Stone             } else {
12545a988416SJim Ingham               breakpoint->SetEnabled(false);
12555a988416SJim Ingham               ++disable_count;
12565a988416SJim Ingham             }
12575a988416SJim Ingham           }
12585a988416SJim Ingham         }
1259b9c1b51eSKate Stone         result.AppendMessageWithFormat("%d breakpoints disabled.\n",
1260b9c1b51eSKate Stone                                        disable_count + loc_count);
12615a988416SJim Ingham         result.SetStatus(eReturnStatusSuccessFinishNoResult);
12625a988416SJim Ingham       }
12635a988416SJim Ingham     }
12645a988416SJim Ingham 
12655a988416SJim Ingham     return result.Succeeded();
12665a988416SJim Ingham   }
12675a988416SJim Ingham };
12685a988416SJim Ingham 
12695a988416SJim Ingham //-------------------------------------------------------------------------
12705a988416SJim Ingham // CommandObjectBreakpointList
12715a988416SJim Ingham //-------------------------------------------------------------------------
12725a988416SJim Ingham #pragma mark List
12735a988416SJim Ingham 
1274b9c1b51eSKate Stone class CommandObjectBreakpointList : public CommandObjectParsed {
12755a988416SJim Ingham public:
1276b9c1b51eSKate Stone   CommandObjectBreakpointList(CommandInterpreter &interpreter)
1277b9c1b51eSKate Stone       : CommandObjectParsed(
1278b9c1b51eSKate Stone             interpreter, "breakpoint list",
12795a988416SJim Ingham             "List some or all breakpoints at configurable levels of detail.",
12809e85e5a8SEugene Zelenko             nullptr),
1281b9c1b51eSKate Stone         m_options() {
12825a988416SJim Ingham     CommandArgumentEntry arg;
12835a988416SJim Ingham     CommandArgumentData bp_id_arg;
12845a988416SJim Ingham 
12855a988416SJim Ingham     // Define the first (and only) variant of this arg.
12865a988416SJim Ingham     bp_id_arg.arg_type = eArgTypeBreakpointID;
12875a988416SJim Ingham     bp_id_arg.arg_repetition = eArgRepeatOptional;
12885a988416SJim Ingham 
1289b9c1b51eSKate Stone     // There is only one variant this argument could be; put it into the
1290b9c1b51eSKate Stone     // argument entry.
12915a988416SJim Ingham     arg.push_back(bp_id_arg);
12925a988416SJim Ingham 
12935a988416SJim Ingham     // Push the data for the first argument into the m_arguments vector.
12945a988416SJim Ingham     m_arguments.push_back(arg);
12955a988416SJim Ingham   }
12965a988416SJim Ingham 
12979e85e5a8SEugene Zelenko   ~CommandObjectBreakpointList() override = default;
12985a988416SJim Ingham 
1299b9c1b51eSKate Stone   Options *GetOptions() override { return &m_options; }
13005a988416SJim Ingham 
1301b9c1b51eSKate Stone   class CommandOptions : public Options {
13025a988416SJim Ingham   public:
1303b9c1b51eSKate Stone     CommandOptions()
1304b9c1b51eSKate Stone         : Options(), m_level(lldb::eDescriptionLevelBrief), m_use_dummy(false) {
13055a988416SJim Ingham     }
13065a988416SJim Ingham 
13079e85e5a8SEugene Zelenko     ~CommandOptions() override = default;
13085a988416SJim Ingham 
1309b9c1b51eSKate Stone     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
1310b9c1b51eSKate Stone                          ExecutionContext *execution_context) override {
13115a988416SJim Ingham       Error error;
13123bcdfc0eSGreg Clayton       const int short_option = m_getopt_table[option_idx].val;
13135a988416SJim Ingham 
1314b9c1b51eSKate Stone       switch (short_option) {
13155a988416SJim Ingham       case 'b':
13165a988416SJim Ingham         m_level = lldb::eDescriptionLevelBrief;
13175a988416SJim Ingham         break;
131833df7cd3SJim Ingham       case 'D':
131933df7cd3SJim Ingham         m_use_dummy = true;
132033df7cd3SJim Ingham         break;
13215a988416SJim Ingham       case 'f':
13225a988416SJim Ingham         m_level = lldb::eDescriptionLevelFull;
13235a988416SJim Ingham         break;
13245a988416SJim Ingham       case 'v':
13255a988416SJim Ingham         m_level = lldb::eDescriptionLevelVerbose;
13265a988416SJim Ingham         break;
13275a988416SJim Ingham       case 'i':
13285a988416SJim Ingham         m_internal = true;
13295a988416SJim Ingham         break;
13305a988416SJim Ingham       default:
1331b9c1b51eSKate Stone         error.SetErrorStringWithFormat("unrecognized option '%c'",
1332b9c1b51eSKate Stone                                        short_option);
13335a988416SJim Ingham         break;
13345a988416SJim Ingham       }
13355a988416SJim Ingham 
13365a988416SJim Ingham       return error;
13375a988416SJim Ingham     }
13385a988416SJim Ingham 
1339b9c1b51eSKate Stone     void OptionParsingStarting(ExecutionContext *execution_context) override {
13405a988416SJim Ingham       m_level = lldb::eDescriptionLevelFull;
13415a988416SJim Ingham       m_internal = false;
134233df7cd3SJim Ingham       m_use_dummy = false;
13435a988416SJim Ingham     }
13445a988416SJim Ingham 
1345b9c1b51eSKate Stone     const OptionDefinition *GetDefinitions() override { return g_option_table; }
13465a988416SJim Ingham 
13475a988416SJim Ingham     // Options table: Required for subclasses of Options.
13485a988416SJim Ingham 
13495a988416SJim Ingham     static OptionDefinition g_option_table[];
13505a988416SJim Ingham 
13515a988416SJim Ingham     // Instance variables to hold the values for command options.
13525a988416SJim Ingham 
13535a988416SJim Ingham     lldb::DescriptionLevel m_level;
13545a988416SJim Ingham 
13555a988416SJim Ingham     bool m_internal;
135633df7cd3SJim Ingham     bool m_use_dummy;
13575a988416SJim Ingham   };
13585a988416SJim Ingham 
13595a988416SJim Ingham protected:
1360b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
136133df7cd3SJim Ingham     Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
136233df7cd3SJim Ingham 
1363b9c1b51eSKate Stone     if (target == nullptr) {
13645a988416SJim Ingham       result.AppendError("Invalid target. No current target or breakpoints.");
13655a988416SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
13665a988416SJim Ingham       return true;
13675a988416SJim Ingham     }
13685a988416SJim Ingham 
1369b9c1b51eSKate Stone     const BreakpointList &breakpoints =
1370b9c1b51eSKate Stone         target->GetBreakpointList(m_options.m_internal);
1371bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1372bb19a13cSSaleem Abdulrasool     target->GetBreakpointList(m_options.m_internal).GetListMutex(lock);
13735a988416SJim Ingham 
13745a988416SJim Ingham     size_t num_breakpoints = breakpoints.GetSize();
13755a988416SJim Ingham 
1376b9c1b51eSKate Stone     if (num_breakpoints == 0) {
13775a988416SJim Ingham       result.AppendMessage("No breakpoints currently set.");
13785a988416SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
13795a988416SJim Ingham       return true;
13805a988416SJim Ingham     }
13815a988416SJim Ingham 
13825a988416SJim Ingham     Stream &output_stream = result.GetOutputStream();
13835a988416SJim Ingham 
1384b9c1b51eSKate Stone     if (command.GetArgumentCount() == 0) {
13855a988416SJim Ingham       // No breakpoint selected; show info about all currently set breakpoints.
13865a988416SJim Ingham       result.AppendMessage("Current breakpoints:");
1387b9c1b51eSKate Stone       for (size_t i = 0; i < num_breakpoints; ++i) {
13885a988416SJim Ingham         Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex(i).get();
13895a988416SJim Ingham         AddBreakpointDescription(&output_stream, breakpoint, m_options.m_level);
13905a988416SJim Ingham       }
13915a988416SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
1392b9c1b51eSKate Stone     } else {
13935a988416SJim Ingham       // Particular breakpoints selected; show info about that breakpoint.
13945a988416SJim Ingham       BreakpointIDList valid_bp_ids;
1395b9c1b51eSKate Stone       CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
1396b9c1b51eSKate Stone           command, target, result, &valid_bp_ids);
13975a988416SJim Ingham 
1398b9c1b51eSKate Stone       if (result.Succeeded()) {
1399b9c1b51eSKate Stone         for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) {
14005a988416SJim Ingham           BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
1401b9c1b51eSKate Stone           Breakpoint *breakpoint =
1402b9c1b51eSKate Stone               target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
1403b9c1b51eSKate Stone           AddBreakpointDescription(&output_stream, breakpoint,
1404b9c1b51eSKate Stone                                    m_options.m_level);
14055a988416SJim Ingham         }
14065a988416SJim Ingham         result.SetStatus(eReturnStatusSuccessFinishNoResult);
1407b9c1b51eSKate Stone       } else {
14087428a18cSKate Stone         result.AppendError("Invalid breakpoint ID.");
14095a988416SJim Ingham         result.SetStatus(eReturnStatusFailed);
14105a988416SJim Ingham       }
14115a988416SJim Ingham     }
14125a988416SJim Ingham 
14135a988416SJim Ingham     return result.Succeeded();
14145a988416SJim Ingham   }
14155a988416SJim Ingham 
14165a988416SJim Ingham private:
14175a988416SJim Ingham   CommandOptions m_options;
14185a988416SJim Ingham };
14195a988416SJim Ingham 
14205a988416SJim Ingham #pragma mark List::CommandOptions
1421b9c1b51eSKate Stone OptionDefinition CommandObjectBreakpointList::CommandOptions::g_option_table[] =
14225a988416SJim Ingham     {
1423ac9c3a62SKate Stone         // clang-format off
1424ac9c3a62SKate Stone     {LLDB_OPT_SET_ALL, false, "internal",          'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show debugger internal breakpoints" },
1425ac9c3a62SKate Stone     {LLDB_OPT_SET_1,   false, "brief",             'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a brief description of the breakpoint (no location info)."},
14265a988416SJim Ingham     // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
14275a988416SJim Ingham     // But I need to see it for now, and don't want to wait.
1428ac9c3a62SKate Stone     {LLDB_OPT_SET_2,   false, "full",              'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a full description of the breakpoint and its locations."},
1429ac9c3a62SKate 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)."},
1430ac9c3a62SKate 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."},
14319e85e5a8SEugene Zelenko     {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
1432ac9c3a62SKate Stone         // clang-format on
14335a988416SJim Ingham };
14345a988416SJim Ingham 
14355a988416SJim Ingham //-------------------------------------------------------------------------
14365a988416SJim Ingham // CommandObjectBreakpointClear
14375a988416SJim Ingham //-------------------------------------------------------------------------
14385a988416SJim Ingham #pragma mark Clear
14395a988416SJim Ingham 
1440b9c1b51eSKate Stone class CommandObjectBreakpointClear : public CommandObjectParsed {
14415a988416SJim Ingham public:
1442b9c1b51eSKate Stone   typedef enum BreakpointClearType {
14435a988416SJim Ingham     eClearTypeInvalid,
14445a988416SJim Ingham     eClearTypeFileAndLine
14455a988416SJim Ingham   } BreakpointClearType;
14465a988416SJim Ingham 
14477428a18cSKate Stone   CommandObjectBreakpointClear(CommandInterpreter &interpreter)
14487428a18cSKate Stone       : CommandObjectParsed(interpreter, "breakpoint clear",
1449b9c1b51eSKate Stone                             "Delete or disable breakpoints matching the "
1450b9c1b51eSKate Stone                             "specified source file and line.",
14515a988416SJim Ingham                             "breakpoint clear <cmd-options>"),
1452b9c1b51eSKate Stone         m_options() {}
14535a988416SJim Ingham 
14549e85e5a8SEugene Zelenko   ~CommandObjectBreakpointClear() override = default;
14555a988416SJim Ingham 
1456b9c1b51eSKate Stone   Options *GetOptions() override { return &m_options; }
14575a988416SJim Ingham 
1458b9c1b51eSKate Stone   class CommandOptions : public Options {
14595a988416SJim Ingham   public:
1460b9c1b51eSKate Stone     CommandOptions() : Options(), m_filename(), m_line_num(0) {}
14615a988416SJim Ingham 
14629e85e5a8SEugene Zelenko     ~CommandOptions() override = default;
14635a988416SJim Ingham 
1464b9c1b51eSKate Stone     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
1465b9c1b51eSKate Stone                          ExecutionContext *execution_context) override {
14665a988416SJim Ingham       Error error;
14673bcdfc0eSGreg Clayton       const int short_option = m_getopt_table[option_idx].val;
14685a988416SJim Ingham 
1469b9c1b51eSKate Stone       switch (short_option) {
14705a988416SJim Ingham       case 'f':
14715a988416SJim Ingham         m_filename.assign(option_arg);
14725a988416SJim Ingham         break;
14735a988416SJim Ingham 
14745a988416SJim Ingham       case 'l':
14755275aaa0SVince Harron         m_line_num = StringConvert::ToUInt32(option_arg, 0);
14765a988416SJim Ingham         break;
14775a988416SJim Ingham 
14785a988416SJim Ingham       default:
1479b9c1b51eSKate Stone         error.SetErrorStringWithFormat("unrecognized option '%c'",
1480b9c1b51eSKate Stone                                        short_option);
14815a988416SJim Ingham         break;
14825a988416SJim Ingham       }
14835a988416SJim Ingham 
14845a988416SJim Ingham       return error;
14855a988416SJim Ingham     }
14865a988416SJim Ingham 
1487b9c1b51eSKate Stone     void OptionParsingStarting(ExecutionContext *execution_context) override {
14885a988416SJim Ingham       m_filename.clear();
14895a988416SJim Ingham       m_line_num = 0;
14905a988416SJim Ingham     }
14915a988416SJim Ingham 
1492b9c1b51eSKate Stone     const OptionDefinition *GetDefinitions() override { return g_option_table; }
14935a988416SJim Ingham 
14945a988416SJim Ingham     // Options table: Required for subclasses of Options.
14955a988416SJim Ingham 
14965a988416SJim Ingham     static OptionDefinition g_option_table[];
14975a988416SJim Ingham 
14985a988416SJim Ingham     // Instance variables to hold the values for command options.
14995a988416SJim Ingham 
15005a988416SJim Ingham     std::string m_filename;
15015a988416SJim Ingham     uint32_t m_line_num;
15025a988416SJim Ingham   };
15035a988416SJim Ingham 
15045a988416SJim Ingham protected:
1505b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
1506893c932aSJim Ingham     Target *target = GetSelectedOrDummyTarget();
1507b9c1b51eSKate Stone     if (target == nullptr) {
15085a988416SJim Ingham       result.AppendError("Invalid target. No existing target or breakpoints.");
15095a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
15105a988416SJim Ingham       return false;
15115a988416SJim Ingham     }
15125a988416SJim Ingham 
15135a988416SJim Ingham     // The following are the various types of breakpoints that could be cleared:
15145a988416SJim Ingham     //   1). -f -l (clearing breakpoint by source location)
15155a988416SJim Ingham 
15165a988416SJim Ingham     BreakpointClearType break_type = eClearTypeInvalid;
15175a988416SJim Ingham 
15185a988416SJim Ingham     if (m_options.m_line_num != 0)
15195a988416SJim Ingham       break_type = eClearTypeFileAndLine;
15205a988416SJim Ingham 
1521bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1522bb19a13cSSaleem Abdulrasool     target->GetBreakpointList().GetListMutex(lock);
15235a988416SJim Ingham 
15245a988416SJim Ingham     BreakpointList &breakpoints = target->GetBreakpointList();
15255a988416SJim Ingham     size_t num_breakpoints = breakpoints.GetSize();
15265a988416SJim Ingham 
15275a988416SJim Ingham     // Early return if there's no breakpoint at all.
1528b9c1b51eSKate Stone     if (num_breakpoints == 0) {
15295a988416SJim Ingham       result.AppendError("Breakpoint clear: No breakpoint cleared.");
15305a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
15315a988416SJim Ingham       return result.Succeeded();
15325a988416SJim Ingham     }
15335a988416SJim Ingham 
15345a988416SJim Ingham     // Find matching breakpoints and delete them.
15355a988416SJim Ingham 
15365a988416SJim Ingham     // First create a copy of all the IDs.
15375a988416SJim Ingham     std::vector<break_id_t> BreakIDs;
15385a988416SJim Ingham     for (size_t i = 0; i < num_breakpoints; ++i)
15399e85e5a8SEugene Zelenko       BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID());
15405a988416SJim Ingham 
15415a988416SJim Ingham     int num_cleared = 0;
15425a988416SJim Ingham     StreamString ss;
1543b9c1b51eSKate Stone     switch (break_type) {
15445a988416SJim Ingham     case eClearTypeFileAndLine: // Breakpoint by source position
15455a988416SJim Ingham     {
15465a988416SJim Ingham       const ConstString filename(m_options.m_filename.c_str());
15475a988416SJim Ingham       BreakpointLocationCollection loc_coll;
15485a988416SJim Ingham 
1549b9c1b51eSKate Stone       for (size_t i = 0; i < num_breakpoints; ++i) {
15505a988416SJim Ingham         Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
15515a988416SJim Ingham 
1552b9c1b51eSKate Stone         if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) {
1553b9c1b51eSKate Stone           // If the collection size is 0, it's a full match and we can just
1554b9c1b51eSKate Stone           // remove the breakpoint.
1555b9c1b51eSKate Stone           if (loc_coll.GetSize() == 0) {
15565a988416SJim Ingham             bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
15575a988416SJim Ingham             ss.EOL();
15585a988416SJim Ingham             target->RemoveBreakpointByID(bp->GetID());
15595a988416SJim Ingham             ++num_cleared;
15605a988416SJim Ingham           }
15615a988416SJim Ingham         }
15625a988416SJim Ingham       }
1563b9c1b51eSKate Stone     } break;
15645a988416SJim Ingham 
15655a988416SJim Ingham     default:
15665a988416SJim Ingham       break;
15675a988416SJim Ingham     }
15685a988416SJim Ingham 
1569b9c1b51eSKate Stone     if (num_cleared > 0) {
15705a988416SJim Ingham       Stream &output_stream = result.GetOutputStream();
15715a988416SJim Ingham       output_stream.Printf("%d breakpoints cleared:\n", num_cleared);
15725a988416SJim Ingham       output_stream << ss.GetData();
15735a988416SJim Ingham       output_stream.EOL();
15745a988416SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
1575b9c1b51eSKate Stone     } else {
15765a988416SJim Ingham       result.AppendError("Breakpoint clear: No breakpoint cleared.");
15775a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
15785a988416SJim Ingham     }
15795a988416SJim Ingham 
15805a988416SJim Ingham     return result.Succeeded();
15815a988416SJim Ingham   }
15825a988416SJim Ingham 
15835a988416SJim Ingham private:
15845a988416SJim Ingham   CommandOptions m_options;
15855a988416SJim Ingham };
15865a988416SJim Ingham 
15875a988416SJim Ingham #pragma mark Clear::CommandOptions
15885a988416SJim Ingham 
15895a988416SJim Ingham OptionDefinition
1590b9c1b51eSKate Stone     CommandObjectBreakpointClear::CommandOptions::g_option_table[] = {
1591ac9c3a62SKate Stone         // clang-format off
1592ac9c3a62SKate 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."},
1593ac9c3a62SKate Stone   {LLDB_OPT_SET_1, true,  "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0,                                         eArgTypeLineNum,  "Specify the breakpoint by source location at this particular line."},
15949e85e5a8SEugene Zelenko   {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
1595ac9c3a62SKate Stone         // clang-format on
15965a988416SJim Ingham };
15975a988416SJim Ingham 
15985a988416SJim Ingham //-------------------------------------------------------------------------
15995a988416SJim Ingham // CommandObjectBreakpointDelete
16005a988416SJim Ingham //-------------------------------------------------------------------------
16015a988416SJim Ingham #pragma mark Delete
16025a988416SJim Ingham 
1603b9c1b51eSKate Stone class CommandObjectBreakpointDelete : public CommandObjectParsed {
16045a988416SJim Ingham public:
1605b9c1b51eSKate Stone   CommandObjectBreakpointDelete(CommandInterpreter &interpreter)
1606b9c1b51eSKate Stone       : CommandObjectParsed(interpreter, "breakpoint delete",
1607b9c1b51eSKate Stone                             "Delete the specified breakpoint(s).  If no "
1608b9c1b51eSKate Stone                             "breakpoints are specified, delete them all.",
16099e85e5a8SEugene Zelenko                             nullptr),
1610b9c1b51eSKate Stone         m_options() {
16115a988416SJim Ingham     CommandArgumentEntry arg;
1612b9c1b51eSKate Stone     CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
1613b9c1b51eSKate Stone                                       eArgTypeBreakpointIDRange);
1614b9c1b51eSKate Stone     // Add the entry for the first argument for this command to the object's
1615b9c1b51eSKate Stone     // arguments vector.
16165a988416SJim Ingham     m_arguments.push_back(arg);
16175a988416SJim Ingham   }
16185a988416SJim Ingham 
16199e85e5a8SEugene Zelenko   ~CommandObjectBreakpointDelete() override = default;
16205a988416SJim Ingham 
1621b9c1b51eSKate Stone   Options *GetOptions() override { return &m_options; }
162233df7cd3SJim Ingham 
1623b9c1b51eSKate Stone   class CommandOptions : public Options {
162433df7cd3SJim Ingham   public:
1625b9c1b51eSKate Stone     CommandOptions() : Options(), m_use_dummy(false), m_force(false) {}
162633df7cd3SJim Ingham 
16279e85e5a8SEugene Zelenko     ~CommandOptions() override = default;
162833df7cd3SJim Ingham 
1629b9c1b51eSKate Stone     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
1630b9c1b51eSKate Stone                          ExecutionContext *execution_context) override {
163133df7cd3SJim Ingham       Error error;
163233df7cd3SJim Ingham       const int short_option = m_getopt_table[option_idx].val;
163333df7cd3SJim Ingham 
1634b9c1b51eSKate Stone       switch (short_option) {
163533df7cd3SJim Ingham       case 'f':
163633df7cd3SJim Ingham         m_force = true;
163733df7cd3SJim Ingham         break;
163833df7cd3SJim Ingham 
163933df7cd3SJim Ingham       case 'D':
164033df7cd3SJim Ingham         m_use_dummy = true;
164133df7cd3SJim Ingham         break;
164233df7cd3SJim Ingham 
164333df7cd3SJim Ingham       default:
1644b9c1b51eSKate Stone         error.SetErrorStringWithFormat("unrecognized option '%c'",
1645b9c1b51eSKate Stone                                        short_option);
164633df7cd3SJim Ingham         break;
164733df7cd3SJim Ingham       }
164833df7cd3SJim Ingham 
164933df7cd3SJim Ingham       return error;
165033df7cd3SJim Ingham     }
165133df7cd3SJim Ingham 
1652b9c1b51eSKate Stone     void OptionParsingStarting(ExecutionContext *execution_context) override {
165333df7cd3SJim Ingham       m_use_dummy = false;
165433df7cd3SJim Ingham       m_force = false;
165533df7cd3SJim Ingham     }
165633df7cd3SJim Ingham 
1657b9c1b51eSKate Stone     const OptionDefinition *GetDefinitions() override { return g_option_table; }
165833df7cd3SJim Ingham 
165933df7cd3SJim Ingham     // Options table: Required for subclasses of Options.
166033df7cd3SJim Ingham 
166133df7cd3SJim Ingham     static OptionDefinition g_option_table[];
166233df7cd3SJim Ingham 
166333df7cd3SJim Ingham     // Instance variables to hold the values for command options.
166433df7cd3SJim Ingham     bool m_use_dummy;
166533df7cd3SJim Ingham     bool m_force;
166633df7cd3SJim Ingham   };
166733df7cd3SJim Ingham 
16685a988416SJim Ingham protected:
1669b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
167033df7cd3SJim Ingham     Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
167133df7cd3SJim Ingham 
1672b9c1b51eSKate Stone     if (target == nullptr) {
16735a988416SJim Ingham       result.AppendError("Invalid target. No existing target or breakpoints.");
16745a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
16755a988416SJim Ingham       return false;
16765a988416SJim Ingham     }
16775a988416SJim Ingham 
1678bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1679bb19a13cSSaleem Abdulrasool     target->GetBreakpointList().GetListMutex(lock);
16805a988416SJim Ingham 
16815a988416SJim Ingham     const BreakpointList &breakpoints = target->GetBreakpointList();
16825a988416SJim Ingham 
16835a988416SJim Ingham     size_t num_breakpoints = breakpoints.GetSize();
16845a988416SJim Ingham 
1685b9c1b51eSKate Stone     if (num_breakpoints == 0) {
16865a988416SJim Ingham       result.AppendError("No breakpoints exist to be deleted.");
16875a988416SJim Ingham       result.SetStatus(eReturnStatusFailed);
16885a988416SJim Ingham       return false;
16895a988416SJim Ingham     }
16905a988416SJim Ingham 
1691b9c1b51eSKate Stone     if (command.GetArgumentCount() == 0) {
1692b9c1b51eSKate Stone       if (!m_options.m_force &&
1693b9c1b51eSKate Stone           !m_interpreter.Confirm(
1694b9c1b51eSKate Stone               "About to delete all breakpoints, do you want to do that?",
1695b9c1b51eSKate Stone               true)) {
16965a988416SJim Ingham         result.AppendMessage("Operation cancelled...");
1697b9c1b51eSKate Stone       } else {
16985a988416SJim Ingham         target->RemoveAllBreakpoints();
1699b9c1b51eSKate Stone         result.AppendMessageWithFormat(
1700b9c1b51eSKate Stone             "All breakpoints removed. (%" PRIu64 " breakpoint%s)\n",
1701b9c1b51eSKate Stone             (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : "");
17025a988416SJim Ingham       }
17035a988416SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
1704b9c1b51eSKate Stone     } else {
17055a988416SJim Ingham       // Particular breakpoint selected; disable that breakpoint.
17065a988416SJim Ingham       BreakpointIDList valid_bp_ids;
1707b9c1b51eSKate Stone       CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
1708b9c1b51eSKate Stone           command, target, result, &valid_bp_ids);
17095a988416SJim Ingham 
1710b9c1b51eSKate Stone       if (result.Succeeded()) {
17115a988416SJim Ingham         int delete_count = 0;
17125a988416SJim Ingham         int disable_count = 0;
17135a988416SJim Ingham         const size_t count = valid_bp_ids.GetSize();
1714b9c1b51eSKate Stone         for (size_t i = 0; i < count; ++i) {
17155a988416SJim Ingham           BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
17165a988416SJim Ingham 
1717b9c1b51eSKate Stone           if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
1718b9c1b51eSKate Stone             if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
1719b9c1b51eSKate Stone               Breakpoint *breakpoint =
1720b9c1b51eSKate Stone                   target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
1721b9c1b51eSKate Stone               BreakpointLocation *location =
1722b9c1b51eSKate Stone                   breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get();
1723b9c1b51eSKate Stone               // It makes no sense to try to delete individual locations, so we
1724b9c1b51eSKate Stone               // disable them instead.
1725b9c1b51eSKate Stone               if (location) {
17265a988416SJim Ingham                 location->SetEnabled(false);
17275a988416SJim Ingham                 ++disable_count;
17285a988416SJim Ingham               }
1729b9c1b51eSKate Stone             } else {
17305a988416SJim Ingham               target->RemoveBreakpointByID(cur_bp_id.GetBreakpointID());
17315a988416SJim Ingham               ++delete_count;
17325a988416SJim Ingham             }
17335a988416SJim Ingham           }
17345a988416SJim Ingham         }
1735b9c1b51eSKate Stone         result.AppendMessageWithFormat(
1736b9c1b51eSKate Stone             "%d breakpoints deleted; %d breakpoint locations disabled.\n",
17375a988416SJim Ingham             delete_count, disable_count);
17385a988416SJim Ingham         result.SetStatus(eReturnStatusSuccessFinishNoResult);
17395a988416SJim Ingham       }
17405a988416SJim Ingham     }
17415a988416SJim Ingham     return result.Succeeded();
17425a988416SJim Ingham   }
17439e85e5a8SEugene Zelenko 
174433df7cd3SJim Ingham private:
174533df7cd3SJim Ingham   CommandOptions m_options;
174633df7cd3SJim Ingham };
174733df7cd3SJim Ingham 
174833df7cd3SJim Ingham OptionDefinition
1749b9c1b51eSKate Stone     CommandObjectBreakpointDelete::CommandOptions::g_option_table[] = {
1750ac9c3a62SKate Stone         // clang-format off
1751ac9c3a62SKate Stone   {LLDB_OPT_SET_1, false, "force",             'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete all breakpoints without querying for confirmation."},
1752ac9c3a62SKate 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."},
17539e85e5a8SEugene Zelenko   {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
1754ac9c3a62SKate Stone         // clang-format on
17555a988416SJim Ingham };
17565a988416SJim Ingham 
175730fdc8d8SChris Lattner //-------------------------------------------------------------------------
17585e09c8c3SJim Ingham // CommandObjectBreakpointName
17595e09c8c3SJim Ingham //-------------------------------------------------------------------------
17605e09c8c3SJim Ingham 
17617428a18cSKate Stone static OptionDefinition g_breakpoint_name_options[] = {
1762ac9c3a62SKate Stone     // clang-format off
1763ac9c3a62SKate Stone   {LLDB_OPT_SET_1,   false, "name",              'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."},
1764ac9c3a62SKate Stone   {LLDB_OPT_SET_2,   false, "breakpoint-id",     'B', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointID,   "Specify a breakpoint ID to use."},
1765ac9c3a62SKate 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."},
1766ac9c3a62SKate Stone     // clang-format on
17675e09c8c3SJim Ingham };
1768b9c1b51eSKate Stone class BreakpointNameOptionGroup : public OptionGroup {
17695e09c8c3SJim Ingham public:
1770b9c1b51eSKate Stone   BreakpointNameOptionGroup()
1771b9c1b51eSKate Stone       : OptionGroup(), m_breakpoint(LLDB_INVALID_BREAK_ID), m_use_dummy(false) {
17725e09c8c3SJim Ingham   }
17735e09c8c3SJim Ingham 
17749e85e5a8SEugene Zelenko   ~BreakpointNameOptionGroup() override = default;
17755e09c8c3SJim Ingham 
1776b9c1b51eSKate Stone   uint32_t GetNumDefinitions() override {
17775e09c8c3SJim Ingham     return sizeof(g_breakpoint_name_options) / sizeof(OptionDefinition);
17785e09c8c3SJim Ingham   }
17795e09c8c3SJim Ingham 
1780b9c1b51eSKate Stone   const OptionDefinition *GetDefinitions() override {
17815e09c8c3SJim Ingham     return g_breakpoint_name_options;
17825e09c8c3SJim Ingham   }
17835e09c8c3SJim Ingham 
1784b9c1b51eSKate Stone   Error SetOptionValue(uint32_t option_idx, const char *option_value,
1785b9c1b51eSKate Stone                        ExecutionContext *execution_context) override {
17865e09c8c3SJim Ingham     Error error;
17875e09c8c3SJim Ingham     const int short_option = g_breakpoint_name_options[option_idx].short_option;
17885e09c8c3SJim Ingham 
1789b9c1b51eSKate Stone     switch (short_option) {
17905e09c8c3SJim Ingham     case 'N':
1791b9c1b51eSKate Stone       if (BreakpointID::StringIsBreakpointName(option_value, error) &&
1792b9c1b51eSKate Stone           error.Success())
1793c95f7e2aSPavel Labath         m_name.SetValueFromString(option_value);
17945e09c8c3SJim Ingham       break;
17955e09c8c3SJim Ingham 
17965e09c8c3SJim Ingham     case 'B':
1797c95f7e2aSPavel Labath       if (m_breakpoint.SetValueFromString(option_value).Fail())
1798b9c1b51eSKate Stone         error.SetErrorStringWithFormat(
1799b9c1b51eSKate Stone             "unrecognized value \"%s\" for breakpoint", option_value);
18005e09c8c3SJim Ingham       break;
18015e09c8c3SJim Ingham     case 'D':
1802c95f7e2aSPavel Labath       if (m_use_dummy.SetValueFromString(option_value).Fail())
1803b9c1b51eSKate Stone         error.SetErrorStringWithFormat(
1804b9c1b51eSKate Stone             "unrecognized value \"%s\" for use-dummy", option_value);
18055e09c8c3SJim Ingham       break;
18065e09c8c3SJim Ingham 
18075e09c8c3SJim Ingham     default:
1808b9c1b51eSKate Stone       error.SetErrorStringWithFormat("unrecognized short option '%c'",
1809b9c1b51eSKate Stone                                      short_option);
18105e09c8c3SJim Ingham       break;
18115e09c8c3SJim Ingham     }
18125e09c8c3SJim Ingham     return error;
18135e09c8c3SJim Ingham   }
18145e09c8c3SJim Ingham 
1815b9c1b51eSKate Stone   void OptionParsingStarting(ExecutionContext *execution_context) override {
18165e09c8c3SJim Ingham     m_name.Clear();
18175e09c8c3SJim Ingham     m_breakpoint.Clear();
18185e09c8c3SJim Ingham     m_use_dummy.Clear();
18195e09c8c3SJim Ingham     m_use_dummy.SetDefaultValue(false);
18205e09c8c3SJim Ingham   }
18215e09c8c3SJim Ingham 
18225e09c8c3SJim Ingham   OptionValueString m_name;
18235e09c8c3SJim Ingham   OptionValueUInt64 m_breakpoint;
18245e09c8c3SJim Ingham   OptionValueBoolean m_use_dummy;
18255e09c8c3SJim Ingham };
18265e09c8c3SJim Ingham 
1827b9c1b51eSKate Stone class CommandObjectBreakpointNameAdd : public CommandObjectParsed {
18285e09c8c3SJim Ingham public:
1829b9c1b51eSKate Stone   CommandObjectBreakpointNameAdd(CommandInterpreter &interpreter)
1830b9c1b51eSKate Stone       : CommandObjectParsed(
1831b9c1b51eSKate Stone             interpreter, "add", "Add a name to the breakpoints provided.",
18325e09c8c3SJim Ingham             "breakpoint name add <command-options> <breakpoint-id-list>"),
1833b9c1b51eSKate Stone         m_name_options(), m_option_group() {
1834b9c1b51eSKate Stone     // Create the first variant for the first (and only) argument for this
1835b9c1b51eSKate Stone     // command.
18365e09c8c3SJim Ingham     CommandArgumentEntry arg1;
18375e09c8c3SJim Ingham     CommandArgumentData id_arg;
18385e09c8c3SJim Ingham     id_arg.arg_type = eArgTypeBreakpointID;
18395e09c8c3SJim Ingham     id_arg.arg_repetition = eArgRepeatOptional;
18405e09c8c3SJim Ingham     arg1.push_back(id_arg);
18415e09c8c3SJim Ingham     m_arguments.push_back(arg1);
18425e09c8c3SJim Ingham 
18435e09c8c3SJim Ingham     m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
18445e09c8c3SJim Ingham     m_option_group.Finalize();
18455e09c8c3SJim Ingham   }
18465e09c8c3SJim Ingham 
18479e85e5a8SEugene Zelenko   ~CommandObjectBreakpointNameAdd() override = default;
18485e09c8c3SJim Ingham 
1849b9c1b51eSKate Stone   Options *GetOptions() override { return &m_option_group; }
18505e09c8c3SJim Ingham 
18515e09c8c3SJim Ingham protected:
1852b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
1853b9c1b51eSKate Stone     if (!m_name_options.m_name.OptionWasSet()) {
18545e09c8c3SJim Ingham       result.SetError("No name option provided.");
18555e09c8c3SJim Ingham       return false;
18565e09c8c3SJim Ingham     }
18575e09c8c3SJim Ingham 
1858b9c1b51eSKate Stone     Target *target =
1859b9c1b51eSKate Stone         GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
18605e09c8c3SJim Ingham 
1861b9c1b51eSKate Stone     if (target == nullptr) {
18625e09c8c3SJim Ingham       result.AppendError("Invalid target. No existing target or breakpoints.");
18635e09c8c3SJim Ingham       result.SetStatus(eReturnStatusFailed);
18645e09c8c3SJim Ingham       return false;
18655e09c8c3SJim Ingham     }
18665e09c8c3SJim Ingham 
1867bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1868bb19a13cSSaleem Abdulrasool     target->GetBreakpointList().GetListMutex(lock);
18695e09c8c3SJim Ingham 
18705e09c8c3SJim Ingham     const BreakpointList &breakpoints = target->GetBreakpointList();
18715e09c8c3SJim Ingham 
18725e09c8c3SJim Ingham     size_t num_breakpoints = breakpoints.GetSize();
1873b9c1b51eSKate Stone     if (num_breakpoints == 0) {
18745e09c8c3SJim Ingham       result.SetError("No breakpoints, cannot add names.");
18755e09c8c3SJim Ingham       result.SetStatus(eReturnStatusFailed);
18765e09c8c3SJim Ingham       return false;
18775e09c8c3SJim Ingham     }
18785e09c8c3SJim Ingham 
18795e09c8c3SJim Ingham     // Particular breakpoint selected; disable that breakpoint.
18805e09c8c3SJim Ingham     BreakpointIDList valid_bp_ids;
1881b9c1b51eSKate Stone     CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs(
1882b9c1b51eSKate Stone         command, target, result, &valid_bp_ids);
18835e09c8c3SJim Ingham 
1884b9c1b51eSKate Stone     if (result.Succeeded()) {
1885b9c1b51eSKate Stone       if (valid_bp_ids.GetSize() == 0) {
18865e09c8c3SJim Ingham         result.SetError("No breakpoints specified, cannot add names.");
18875e09c8c3SJim Ingham         result.SetStatus(eReturnStatusFailed);
18885e09c8c3SJim Ingham         return false;
18895e09c8c3SJim Ingham       }
18905e09c8c3SJim Ingham       size_t num_valid_ids = valid_bp_ids.GetSize();
1891b9c1b51eSKate Stone       for (size_t index = 0; index < num_valid_ids; index++) {
1892b9c1b51eSKate Stone         lldb::break_id_t bp_id =
1893b9c1b51eSKate Stone             valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
18945e09c8c3SJim Ingham         BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
1895b9c1b51eSKate Stone         Error error; // We don't need to check the error here, since the option
1896b9c1b51eSKate Stone                      // parser checked it...
18975e09c8c3SJim Ingham         bp_sp->AddName(m_name_options.m_name.GetCurrentValue(), error);
18985e09c8c3SJim Ingham       }
18995e09c8c3SJim Ingham     }
19005e09c8c3SJim Ingham 
19015e09c8c3SJim Ingham     return true;
19025e09c8c3SJim Ingham   }
19035e09c8c3SJim Ingham 
19045e09c8c3SJim Ingham private:
19055e09c8c3SJim Ingham   BreakpointNameOptionGroup m_name_options;
19065e09c8c3SJim Ingham   OptionGroupOptions m_option_group;
19075e09c8c3SJim Ingham };
19085e09c8c3SJim Ingham 
1909b9c1b51eSKate Stone class CommandObjectBreakpointNameDelete : public CommandObjectParsed {
19105e09c8c3SJim Ingham public:
1911b9c1b51eSKate Stone   CommandObjectBreakpointNameDelete(CommandInterpreter &interpreter)
1912b9c1b51eSKate Stone       : CommandObjectParsed(
1913b9c1b51eSKate Stone             interpreter, "delete",
19145e09c8c3SJim Ingham             "Delete a name from the breakpoints provided.",
19155e09c8c3SJim Ingham             "breakpoint name delete <command-options> <breakpoint-id-list>"),
1916b9c1b51eSKate Stone         m_name_options(), m_option_group() {
1917b9c1b51eSKate Stone     // Create the first variant for the first (and only) argument for this
1918b9c1b51eSKate Stone     // command.
19195e09c8c3SJim Ingham     CommandArgumentEntry arg1;
19205e09c8c3SJim Ingham     CommandArgumentData id_arg;
19215e09c8c3SJim Ingham     id_arg.arg_type = eArgTypeBreakpointID;
19225e09c8c3SJim Ingham     id_arg.arg_repetition = eArgRepeatOptional;
19235e09c8c3SJim Ingham     arg1.push_back(id_arg);
19245e09c8c3SJim Ingham     m_arguments.push_back(arg1);
19255e09c8c3SJim Ingham 
19265e09c8c3SJim Ingham     m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
19275e09c8c3SJim Ingham     m_option_group.Finalize();
19285e09c8c3SJim Ingham   }
19295e09c8c3SJim Ingham 
19309e85e5a8SEugene Zelenko   ~CommandObjectBreakpointNameDelete() override = default;
19315e09c8c3SJim Ingham 
1932b9c1b51eSKate Stone   Options *GetOptions() override { return &m_option_group; }
19335e09c8c3SJim Ingham 
19345e09c8c3SJim Ingham protected:
1935b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
1936b9c1b51eSKate Stone     if (!m_name_options.m_name.OptionWasSet()) {
19375e09c8c3SJim Ingham       result.SetError("No name option provided.");
19385e09c8c3SJim Ingham       return false;
19395e09c8c3SJim Ingham     }
19405e09c8c3SJim Ingham 
1941b9c1b51eSKate Stone     Target *target =
1942b9c1b51eSKate Stone         GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
19435e09c8c3SJim Ingham 
1944b9c1b51eSKate Stone     if (target == nullptr) {
19455e09c8c3SJim Ingham       result.AppendError("Invalid target. No existing target or breakpoints.");
19465e09c8c3SJim Ingham       result.SetStatus(eReturnStatusFailed);
19475e09c8c3SJim Ingham       return false;
19485e09c8c3SJim Ingham     }
19495e09c8c3SJim Ingham 
1950bb19a13cSSaleem Abdulrasool     std::unique_lock<std::recursive_mutex> lock;
1951bb19a13cSSaleem Abdulrasool     target->GetBreakpointList().GetListMutex(lock);
19525e09c8c3SJim Ingham 
19535e09c8c3SJim Ingham     const BreakpointList &breakpoints = target->GetBreakpointList();
19545e09c8c3SJim Ingham 
19555e09c8c3SJim Ingham     size_t num_breakpoints = breakpoints.GetSize();
1956b9c1b51eSKate Stone     if (num_breakpoints == 0) {
19575e09c8c3SJim Ingham       result.SetError("No breakpoints, cannot delete names.");
19585e09c8c3SJim Ingham       result.SetStatus(eReturnStatusFailed);
19595e09c8c3SJim Ingham       return false;
19605e09c8c3SJim Ingham     }
19615e09c8c3SJim Ingham 
19625e09c8c3SJim Ingham     // Particular breakpoint selected; disable that breakpoint.
19635e09c8c3SJim Ingham     BreakpointIDList valid_bp_ids;
1964b9c1b51eSKate Stone     CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs(
1965b9c1b51eSKate Stone         command, target, result, &valid_bp_ids);
19665e09c8c3SJim Ingham 
1967b9c1b51eSKate Stone     if (result.Succeeded()) {
1968b9c1b51eSKate Stone       if (valid_bp_ids.GetSize() == 0) {
19695e09c8c3SJim Ingham         result.SetError("No breakpoints specified, cannot delete names.");
19705e09c8c3SJim Ingham         result.SetStatus(eReturnStatusFailed);
19715e09c8c3SJim Ingham         return false;
19725e09c8c3SJim Ingham       }
19735e09c8c3SJim Ingham       size_t num_valid_ids = valid_bp_ids.GetSize();
1974b9c1b51eSKate Stone       for (size_t index = 0; index < num_valid_ids; index++) {
1975b9c1b51eSKate Stone         lldb::break_id_t bp_id =
1976b9c1b51eSKate Stone             valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
19775e09c8c3SJim Ingham         BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
19785e09c8c3SJim Ingham         bp_sp->RemoveName(m_name_options.m_name.GetCurrentValue());
19795e09c8c3SJim Ingham       }
19805e09c8c3SJim Ingham     }
19815e09c8c3SJim Ingham 
19825e09c8c3SJim Ingham     return true;
19835e09c8c3SJim Ingham   }
19845e09c8c3SJim Ingham 
19855e09c8c3SJim Ingham private:
19865e09c8c3SJim Ingham   BreakpointNameOptionGroup m_name_options;
19875e09c8c3SJim Ingham   OptionGroupOptions m_option_group;
19885e09c8c3SJim Ingham };
19895e09c8c3SJim Ingham 
1990b9c1b51eSKate Stone class CommandObjectBreakpointNameList : public CommandObjectParsed {
19915e09c8c3SJim Ingham public:
1992b9c1b51eSKate Stone   CommandObjectBreakpointNameList(CommandInterpreter &interpreter)
1993b9c1b51eSKate Stone       : CommandObjectParsed(interpreter, "list",
1994b9c1b51eSKate Stone                             "List either the names for a breakpoint or the "
1995b9c1b51eSKate Stone                             "breakpoints for a given name.",
19965e09c8c3SJim Ingham                             "breakpoint name list <command-options>"),
1997b9c1b51eSKate Stone         m_name_options(), m_option_group() {
19985e09c8c3SJim Ingham     m_option_group.Append(&m_name_options);
19995e09c8c3SJim Ingham     m_option_group.Finalize();
20005e09c8c3SJim Ingham   }
20015e09c8c3SJim Ingham 
20029e85e5a8SEugene Zelenko   ~CommandObjectBreakpointNameList() override = default;
20035e09c8c3SJim Ingham 
2004b9c1b51eSKate Stone   Options *GetOptions() override { return &m_option_group; }
20055e09c8c3SJim Ingham 
20065e09c8c3SJim Ingham protected:
2007b9c1b51eSKate Stone   bool DoExecute(Args &command, CommandReturnObject &result) override {
2008b9c1b51eSKate Stone     Target *target =
2009b9c1b51eSKate Stone         GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
20105e09c8c3SJim Ingham 
2011b9c1b51eSKate Stone     if (target == nullptr) {
20125e09c8c3SJim Ingham       result.AppendError("Invalid target. No existing target or breakpoints.");
20135e09c8c3SJim Ingham       result.SetStatus(eReturnStatusFailed);
20145e09c8c3SJim Ingham       return false;
20155e09c8c3SJim Ingham     }
20165e09c8c3SJim Ingham 
2017b9c1b51eSKate Stone     if (m_name_options.m_name.OptionWasSet()) {
20185e09c8c3SJim Ingham       const char *name = m_name_options.m_name.GetCurrentValue();
2019bb19a13cSSaleem Abdulrasool       std::unique_lock<std::recursive_mutex> lock;
2020bb19a13cSSaleem Abdulrasool       target->GetBreakpointList().GetListMutex(lock);
20215e09c8c3SJim Ingham 
20225e09c8c3SJim Ingham       BreakpointList &breakpoints = target->GetBreakpointList();
2023b9c1b51eSKate Stone       for (BreakpointSP bp_sp : breakpoints.Breakpoints()) {
2024b9c1b51eSKate Stone         if (bp_sp->MatchesName(name)) {
20255e09c8c3SJim Ingham           StreamString s;
20265e09c8c3SJim Ingham           bp_sp->GetDescription(&s, eDescriptionLevelBrief);
20275e09c8c3SJim Ingham           s.EOL();
20285e09c8c3SJim Ingham           result.AppendMessage(s.GetData());
20295e09c8c3SJim Ingham         }
20305e09c8c3SJim Ingham       }
20315e09c8c3SJim Ingham 
2032b9c1b51eSKate Stone     } else if (m_name_options.m_breakpoint.OptionWasSet()) {
2033b9c1b51eSKate Stone       BreakpointSP bp_sp = target->GetBreakpointList().FindBreakpointByID(
2034b9c1b51eSKate Stone           m_name_options.m_breakpoint.GetCurrentValue());
2035b9c1b51eSKate Stone       if (bp_sp) {
20365e09c8c3SJim Ingham         std::vector<std::string> names;
20375e09c8c3SJim Ingham         bp_sp->GetNames(names);
20385e09c8c3SJim Ingham         result.AppendMessage("Names:");
20395e09c8c3SJim Ingham         for (auto name : names)
20405e09c8c3SJim Ingham           result.AppendMessageWithFormat("    %s\n", name.c_str());
2041b9c1b51eSKate Stone       } else {
2042b9c1b51eSKate Stone         result.AppendErrorWithFormat(
2043b9c1b51eSKate Stone             "Could not find breakpoint %" PRId64 ".\n",
20445e09c8c3SJim Ingham             m_name_options.m_breakpoint.GetCurrentValue());
20455e09c8c3SJim Ingham         result.SetStatus(eReturnStatusFailed);
20465e09c8c3SJim Ingham         return false;
20475e09c8c3SJim Ingham       }
2048b9c1b51eSKate Stone     } else {
20495e09c8c3SJim Ingham       result.SetError("Must specify -N or -B option to list.");
20505e09c8c3SJim Ingham       result.SetStatus(eReturnStatusFailed);
20515e09c8c3SJim Ingham       return false;
20525e09c8c3SJim Ingham     }
20535e09c8c3SJim Ingham     return true;
20545e09c8c3SJim Ingham   }
20555e09c8c3SJim Ingham 
20565e09c8c3SJim Ingham private:
20575e09c8c3SJim Ingham   BreakpointNameOptionGroup m_name_options;
20585e09c8c3SJim Ingham   OptionGroupOptions m_option_group;
20595e09c8c3SJim Ingham };
20605e09c8c3SJim Ingham 
20615e09c8c3SJim Ingham //-------------------------------------------------------------------------
2062e14dc268SJim Ingham // CommandObjectBreakpointName
20635e09c8c3SJim Ingham //-------------------------------------------------------------------------
2064b9c1b51eSKate Stone class CommandObjectBreakpointName : public CommandObjectMultiword {
20655e09c8c3SJim Ingham public:
20667428a18cSKate Stone   CommandObjectBreakpointName(CommandInterpreter &interpreter)
2067b9c1b51eSKate Stone       : CommandObjectMultiword(
2068b9c1b51eSKate Stone             interpreter, "name", "Commands to manage name tags for breakpoints",
2069b9c1b51eSKate Stone             "breakpoint name <subcommand> [<command-options>]") {
2070b9c1b51eSKate Stone     CommandObjectSP add_command_object(
2071b9c1b51eSKate Stone         new CommandObjectBreakpointNameAdd(interpreter));
2072b9c1b51eSKate Stone     CommandObjectSP delete_command_object(
2073b9c1b51eSKate Stone         new CommandObjectBreakpointNameDelete(interpreter));
2074b9c1b51eSKate Stone     CommandObjectSP list_command_object(
2075b9c1b51eSKate Stone         new CommandObjectBreakpointNameList(interpreter));
20765e09c8c3SJim Ingham 
20775e09c8c3SJim Ingham     LoadSubCommand("add", add_command_object);
20785e09c8c3SJim Ingham     LoadSubCommand("delete", delete_command_object);
20795e09c8c3SJim Ingham     LoadSubCommand("list", list_command_object);
20805e09c8c3SJim Ingham   }
20815e09c8c3SJim Ingham 
20829e85e5a8SEugene Zelenko   ~CommandObjectBreakpointName() override = default;
20835e09c8c3SJim Ingham };
20845e09c8c3SJim Ingham 
20855e09c8c3SJim Ingham //-------------------------------------------------------------------------
2086e14dc268SJim Ingham // CommandObjectBreakpointRead
2087e14dc268SJim Ingham //-------------------------------------------------------------------------
2088e14dc268SJim Ingham #pragma mark Restore
2089e14dc268SJim Ingham 
2090e14dc268SJim Ingham class CommandObjectBreakpointRead : public CommandObjectParsed {
2091e14dc268SJim Ingham public:
2092e14dc268SJim Ingham   CommandObjectBreakpointRead(CommandInterpreter &interpreter)
2093e14dc268SJim Ingham       : CommandObjectParsed(interpreter, "breakpoint read",
2094e14dc268SJim Ingham                             "Read and set the breakpoints previously saved to "
2095e14dc268SJim Ingham                             "a file with \"breakpoint write\".  ",
2096e14dc268SJim Ingham                             nullptr),
2097e14dc268SJim Ingham         m_options() {
2098e14dc268SJim Ingham     CommandArgumentEntry arg;
2099e14dc268SJim Ingham     CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
2100e14dc268SJim Ingham                                       eArgTypeBreakpointIDRange);
2101e14dc268SJim Ingham     // Add the entry for the first argument for this command to the object's
2102e14dc268SJim Ingham     // arguments vector.
2103e14dc268SJim Ingham     m_arguments.push_back(arg);
2104e14dc268SJim Ingham   }
2105e14dc268SJim Ingham 
2106e14dc268SJim Ingham   ~CommandObjectBreakpointRead() override = default;
2107e14dc268SJim Ingham 
2108e14dc268SJim Ingham   Options *GetOptions() override { return &m_options; }
2109e14dc268SJim Ingham 
2110e14dc268SJim Ingham   class CommandOptions : public Options {
2111e14dc268SJim Ingham   public:
2112e14dc268SJim Ingham     CommandOptions() : Options() {}
2113e14dc268SJim Ingham 
2114e14dc268SJim Ingham     ~CommandOptions() override = default;
2115e14dc268SJim Ingham 
2116e14dc268SJim Ingham     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
2117e14dc268SJim Ingham                          ExecutionContext *execution_context) override {
2118e14dc268SJim Ingham       Error error;
2119e14dc268SJim Ingham       const int short_option = m_getopt_table[option_idx].val;
2120e14dc268SJim Ingham 
2121e14dc268SJim Ingham       switch (short_option) {
2122e14dc268SJim Ingham       case 'f':
2123e14dc268SJim Ingham         m_filename.assign(option_arg);
2124e14dc268SJim Ingham         break;
2125e14dc268SJim Ingham       default:
2126e14dc268SJim Ingham         error.SetErrorStringWithFormat("unrecognized option '%c'",
2127e14dc268SJim Ingham                                        short_option);
2128e14dc268SJim Ingham         break;
2129e14dc268SJim Ingham       }
2130e14dc268SJim Ingham 
2131e14dc268SJim Ingham       return error;
2132e14dc268SJim Ingham     }
2133e14dc268SJim Ingham 
2134e14dc268SJim Ingham     void OptionParsingStarting(ExecutionContext *execution_context) override {
2135e14dc268SJim Ingham       m_filename.clear();
2136e14dc268SJim Ingham     }
2137e14dc268SJim Ingham 
2138e14dc268SJim Ingham     const OptionDefinition *GetDefinitions() override { return g_option_table; }
2139e14dc268SJim Ingham 
2140e14dc268SJim Ingham     // Options table: Required for subclasses of Options.
2141e14dc268SJim Ingham 
2142e14dc268SJim Ingham     static OptionDefinition g_option_table[];
2143e14dc268SJim Ingham 
2144e14dc268SJim Ingham     // Instance variables to hold the values for command options.
2145e14dc268SJim Ingham 
2146e14dc268SJim Ingham     std::string m_filename;
2147e14dc268SJim Ingham   };
2148e14dc268SJim Ingham 
2149e14dc268SJim Ingham protected:
2150e14dc268SJim Ingham   bool DoExecute(Args &command, CommandReturnObject &result) override {
2151e14dc268SJim Ingham     Target *target = GetSelectedOrDummyTarget();
2152e14dc268SJim Ingham     if (target == nullptr) {
2153e14dc268SJim Ingham       result.AppendError("Invalid target.  No existing target or breakpoints.");
2154e14dc268SJim Ingham       result.SetStatus(eReturnStatusFailed);
2155e14dc268SJim Ingham       return false;
2156e14dc268SJim Ingham     }
2157e14dc268SJim Ingham 
2158e14dc268SJim Ingham     FileSpec input_spec(m_options.m_filename, true);
2159*01f16664SJim Ingham     BreakpointIDList new_bps;
2160*01f16664SJim Ingham     Error error = target->CreateBreakpointsFromFile(input_spec, new_bps);
2161e14dc268SJim Ingham 
2162e14dc268SJim Ingham     if (!error.Success()) {
2163*01f16664SJim Ingham       result.AppendError(error.AsCString());
2164e14dc268SJim Ingham       result.SetStatus(eReturnStatusFailed);
2165*01f16664SJim Ingham       return false;
2166e14dc268SJim Ingham     }
2167*01f16664SJim Ingham     // FIXME: Report the newly created breakpoints.
2168e14dc268SJim Ingham     return result.Succeeded();
2169e14dc268SJim Ingham   }
2170e14dc268SJim Ingham 
2171e14dc268SJim Ingham private:
2172e14dc268SJim Ingham   CommandOptions m_options;
2173e14dc268SJim Ingham };
2174e14dc268SJim Ingham 
2175e14dc268SJim Ingham #pragma mark Modify::CommandOptions
2176e14dc268SJim Ingham OptionDefinition CommandObjectBreakpointRead::CommandOptions::g_option_table[] =
2177e14dc268SJim Ingham     {
2178e14dc268SJim Ingham         // clang-format off
2179e14dc268SJim Ingham   {LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename,    "The file from which to read the breakpoints."},
2180e14dc268SJim Ingham   {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
2181e14dc268SJim Ingham         // clang-format on
2182e14dc268SJim Ingham };
2183e14dc268SJim Ingham 
2184e14dc268SJim Ingham //-------------------------------------------------------------------------
2185e14dc268SJim Ingham // CommandObjectBreakpointWrite
2186e14dc268SJim Ingham //-------------------------------------------------------------------------
2187e14dc268SJim Ingham #pragma mark Save
2188e14dc268SJim Ingham class CommandObjectBreakpointWrite : public CommandObjectParsed {
2189e14dc268SJim Ingham public:
2190e14dc268SJim Ingham   CommandObjectBreakpointWrite(CommandInterpreter &interpreter)
2191e14dc268SJim Ingham       : CommandObjectParsed(interpreter, "breakpoint write",
2192e14dc268SJim Ingham                             "Write the breakpoints listed to a file that can "
2193e14dc268SJim Ingham                             "be read in with \"breakpoint read\".  "
2194e14dc268SJim Ingham                             "If given no arguments, writes all breakpoints.",
2195e14dc268SJim Ingham                             nullptr),
2196e14dc268SJim Ingham         m_options() {
2197e14dc268SJim Ingham     CommandArgumentEntry arg;
2198e14dc268SJim Ingham     CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
2199e14dc268SJim Ingham                                       eArgTypeBreakpointIDRange);
2200e14dc268SJim Ingham     // Add the entry for the first argument for this command to the object's
2201e14dc268SJim Ingham     // arguments vector.
2202e14dc268SJim Ingham     m_arguments.push_back(arg);
2203e14dc268SJim Ingham   }
2204e14dc268SJim Ingham 
2205e14dc268SJim Ingham   ~CommandObjectBreakpointWrite() override = default;
2206e14dc268SJim Ingham 
2207e14dc268SJim Ingham   Options *GetOptions() override { return &m_options; }
2208e14dc268SJim Ingham 
2209e14dc268SJim Ingham   class CommandOptions : public Options {
2210e14dc268SJim Ingham   public:
2211e14dc268SJim Ingham     CommandOptions() : Options() {}
2212e14dc268SJim Ingham 
2213e14dc268SJim Ingham     ~CommandOptions() override = default;
2214e14dc268SJim Ingham 
2215e14dc268SJim Ingham     Error SetOptionValue(uint32_t option_idx, const char *option_arg,
2216e14dc268SJim Ingham                          ExecutionContext *execution_context) override {
2217e14dc268SJim Ingham       Error error;
2218e14dc268SJim Ingham       const int short_option = m_getopt_table[option_idx].val;
2219e14dc268SJim Ingham 
2220e14dc268SJim Ingham       switch (short_option) {
2221e14dc268SJim Ingham       case 'f':
2222e14dc268SJim Ingham         m_filename.assign(option_arg);
2223e14dc268SJim Ingham         break;
2224e14dc268SJim Ingham       default:
2225e14dc268SJim Ingham         error.SetErrorStringWithFormat("unrecognized option '%c'",
2226e14dc268SJim Ingham                                        short_option);
2227e14dc268SJim Ingham         break;
2228e14dc268SJim Ingham       }
2229e14dc268SJim Ingham 
2230e14dc268SJim Ingham       return error;
2231e14dc268SJim Ingham     }
2232e14dc268SJim Ingham 
2233e14dc268SJim Ingham     void OptionParsingStarting(ExecutionContext *execution_context) override {
2234e14dc268SJim Ingham       m_filename.clear();
2235e14dc268SJim Ingham     }
2236e14dc268SJim Ingham 
2237e14dc268SJim Ingham     const OptionDefinition *GetDefinitions() override { return g_option_table; }
2238e14dc268SJim Ingham 
2239e14dc268SJim Ingham     // Options table: Required for subclasses of Options.
2240e14dc268SJim Ingham 
2241e14dc268SJim Ingham     static OptionDefinition g_option_table[];
2242e14dc268SJim Ingham 
2243e14dc268SJim Ingham     // Instance variables to hold the values for command options.
2244e14dc268SJim Ingham 
2245e14dc268SJim Ingham     std::string m_filename;
2246e14dc268SJim Ingham   };
2247e14dc268SJim Ingham 
2248e14dc268SJim Ingham protected:
2249e14dc268SJim Ingham   bool DoExecute(Args &command, CommandReturnObject &result) override {
2250e14dc268SJim Ingham     Target *target = GetSelectedOrDummyTarget();
2251e14dc268SJim Ingham     if (target == nullptr) {
2252e14dc268SJim Ingham       result.AppendError("Invalid target.  No existing target or breakpoints.");
2253e14dc268SJim Ingham       result.SetStatus(eReturnStatusFailed);
2254e14dc268SJim Ingham       return false;
2255e14dc268SJim Ingham     }
2256e14dc268SJim Ingham 
2257e14dc268SJim Ingham     std::unique_lock<std::recursive_mutex> lock;
2258e14dc268SJim Ingham     target->GetBreakpointList().GetListMutex(lock);
2259e14dc268SJim Ingham 
2260e14dc268SJim Ingham     BreakpointIDList valid_bp_ids;
2261*01f16664SJim Ingham     if (command.GetArgumentCount() > 0) {
2262e14dc268SJim Ingham       CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs(
2263e14dc268SJim Ingham           command, target, result, &valid_bp_ids);
2264e14dc268SJim Ingham 
2265*01f16664SJim Ingham       if (!result.Succeeded()) {
2266e14dc268SJim Ingham         result.SetStatus(eReturnStatusFailed);
2267e14dc268SJim Ingham         return false;
2268e14dc268SJim Ingham       }
2269e14dc268SJim Ingham     }
2270*01f16664SJim Ingham     Error error = target->SerializeBreakpointsToFile(
2271*01f16664SJim Ingham         FileSpec(m_options.m_filename.c_str(), true), valid_bp_ids);
2272*01f16664SJim Ingham     if (!error.Success()) {
2273*01f16664SJim Ingham       result.AppendErrorWithFormat("error serializing breakpoints: %s.",
2274*01f16664SJim Ingham                                    error.AsCString());
2275*01f16664SJim Ingham       result.SetStatus(eReturnStatusFailed);
2276e14dc268SJim Ingham     }
2277e14dc268SJim Ingham     return result.Succeeded();
2278e14dc268SJim Ingham   }
2279e14dc268SJim Ingham 
2280e14dc268SJim Ingham private:
2281e14dc268SJim Ingham   CommandOptions m_options;
2282e14dc268SJim Ingham };
2283e14dc268SJim Ingham 
2284e14dc268SJim Ingham #pragma mark Modify::CommandOptions
2285e14dc268SJim Ingham OptionDefinition
2286e14dc268SJim Ingham     CommandObjectBreakpointWrite::CommandOptions::g_option_table[] = {
2287e14dc268SJim Ingham         // clang-format off
2288e14dc268SJim Ingham   {LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename,    "The file into which to write the breakpoints."},
2289e14dc268SJim Ingham   {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
2290e14dc268SJim Ingham         // clang-format on
2291e14dc268SJim Ingham };
2292e14dc268SJim Ingham 
2293e14dc268SJim Ingham //-------------------------------------------------------------------------
229430fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint
229530fdc8d8SChris Lattner //-------------------------------------------------------------------------
2296ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint
229730fdc8d8SChris Lattner 
2298b9c1b51eSKate Stone CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint(
2299b9c1b51eSKate Stone     CommandInterpreter &interpreter)
2300b9c1b51eSKate Stone     : CommandObjectMultiword(
2301b9c1b51eSKate Stone           interpreter, "breakpoint",
23027428a18cSKate Stone           "Commands for operating on breakpoints (see 'help b' for shorthand.)",
2303b9c1b51eSKate Stone           "breakpoint <subcommand> [<command-options>]") {
2304b9c1b51eSKate Stone   CommandObjectSP list_command_object(
2305b9c1b51eSKate Stone       new CommandObjectBreakpointList(interpreter));
2306b9c1b51eSKate Stone   CommandObjectSP enable_command_object(
2307b9c1b51eSKate Stone       new CommandObjectBreakpointEnable(interpreter));
2308b9c1b51eSKate Stone   CommandObjectSP disable_command_object(
2309b9c1b51eSKate Stone       new CommandObjectBreakpointDisable(interpreter));
2310b9c1b51eSKate Stone   CommandObjectSP clear_command_object(
2311b9c1b51eSKate Stone       new CommandObjectBreakpointClear(interpreter));
2312b9c1b51eSKate Stone   CommandObjectSP delete_command_object(
2313b9c1b51eSKate Stone       new CommandObjectBreakpointDelete(interpreter));
2314b9c1b51eSKate Stone   CommandObjectSP set_command_object(
2315b9c1b51eSKate Stone       new CommandObjectBreakpointSet(interpreter));
2316b9c1b51eSKate Stone   CommandObjectSP command_command_object(
2317b9c1b51eSKate Stone       new CommandObjectBreakpointCommand(interpreter));
2318b9c1b51eSKate Stone   CommandObjectSP modify_command_object(
2319b9c1b51eSKate Stone       new CommandObjectBreakpointModify(interpreter));
2320b9c1b51eSKate Stone   CommandObjectSP name_command_object(
2321b9c1b51eSKate Stone       new CommandObjectBreakpointName(interpreter));
2322e14dc268SJim Ingham   CommandObjectSP write_command_object(
2323e14dc268SJim Ingham       new CommandObjectBreakpointWrite(interpreter));
2324e14dc268SJim Ingham   CommandObjectSP read_command_object(
2325e14dc268SJim Ingham       new CommandObjectBreakpointRead(interpreter));
232630fdc8d8SChris Lattner 
2327b7234e40SJohnny Chen   list_command_object->SetCommandName("breakpoint list");
232830fdc8d8SChris Lattner   enable_command_object->SetCommandName("breakpoint enable");
232930fdc8d8SChris Lattner   disable_command_object->SetCommandName("breakpoint disable");
2330b7234e40SJohnny Chen   clear_command_object->SetCommandName("breakpoint clear");
2331b7234e40SJohnny Chen   delete_command_object->SetCommandName("breakpoint delete");
2332ae1c4cf5SJim Ingham   set_command_object->SetCommandName("breakpoint set");
2333b7234e40SJohnny Chen   command_command_object->SetCommandName("breakpoint command");
2334b7234e40SJohnny Chen   modify_command_object->SetCommandName("breakpoint modify");
23355e09c8c3SJim Ingham   name_command_object->SetCommandName("breakpoint name");
2336e14dc268SJim Ingham   write_command_object->SetCommandName("breakpoint write");
2337e14dc268SJim Ingham   read_command_object->SetCommandName("breakpoint read");
233830fdc8d8SChris Lattner 
233923f59509SGreg Clayton   LoadSubCommand("list", list_command_object);
234023f59509SGreg Clayton   LoadSubCommand("enable", enable_command_object);
234123f59509SGreg Clayton   LoadSubCommand("disable", disable_command_object);
234223f59509SGreg Clayton   LoadSubCommand("clear", clear_command_object);
234323f59509SGreg Clayton   LoadSubCommand("delete", delete_command_object);
234423f59509SGreg Clayton   LoadSubCommand("set", set_command_object);
234523f59509SGreg Clayton   LoadSubCommand("command", command_command_object);
234623f59509SGreg Clayton   LoadSubCommand("modify", modify_command_object);
23475e09c8c3SJim Ingham   LoadSubCommand("name", name_command_object);
2348e14dc268SJim Ingham   LoadSubCommand("write", write_command_object);
2349e14dc268SJim Ingham   LoadSubCommand("read", read_command_object);
235030fdc8d8SChris Lattner }
235130fdc8d8SChris Lattner 
23529e85e5a8SEugene Zelenko CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default;
235330fdc8d8SChris Lattner 
2354b9c1b51eSKate Stone void CommandObjectMultiwordBreakpoint::VerifyIDs(Args &args, Target *target,
23555e09c8c3SJim Ingham                                                  bool allow_locations,
23565e09c8c3SJim Ingham                                                  CommandReturnObject &result,
2357b9c1b51eSKate Stone                                                  BreakpointIDList *valid_ids) {
235830fdc8d8SChris Lattner   // args can be strings representing 1). integers (for breakpoint ids)
2359b9c1b51eSKate Stone   //                                  2). the full breakpoint & location
2360b9c1b51eSKate Stone   //                                  canonical representation
2361b9c1b51eSKate Stone   //                                  3). the word "to" or a hyphen,
2362b9c1b51eSKate Stone   //                                  representing a range (in which case there
2363b9c1b51eSKate Stone   //                                      had *better* be an entry both before &
2364b9c1b51eSKate Stone   //                                      after of one of the first two types.
23655e09c8c3SJim Ingham   //                                  4). A breakpoint name
2366b9c1b51eSKate Stone   // If args is empty, we will use the last created breakpoint (if there is
2367b9c1b51eSKate Stone   // one.)
236830fdc8d8SChris Lattner 
236930fdc8d8SChris Lattner   Args temp_args;
237030fdc8d8SChris Lattner 
2371b9c1b51eSKate Stone   if (args.GetArgumentCount() == 0) {
2372b9c1b51eSKate Stone     if (target->GetLastCreatedBreakpoint()) {
2373b9c1b51eSKate Stone       valid_ids->AddBreakpointID(BreakpointID(
2374b9c1b51eSKate Stone           target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
237536f3b369SJim Ingham       result.SetStatus(eReturnStatusSuccessFinishNoResult);
2376b9c1b51eSKate Stone     } else {
2377b9c1b51eSKate Stone       result.AppendError(
2378b9c1b51eSKate Stone           "No breakpoint specified and no last created breakpoint.");
237936f3b369SJim Ingham       result.SetStatus(eReturnStatusFailed);
238036f3b369SJim Ingham     }
238136f3b369SJim Ingham     return;
238236f3b369SJim Ingham   }
238336f3b369SJim Ingham 
2384b9c1b51eSKate Stone   // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff
2385b9c1b51eSKate Stone   // directly from the old ARGS to
2386b9c1b51eSKate Stone   // the new TEMP_ARGS.  Do not copy breakpoint id range strings over; instead
2387b9c1b51eSKate Stone   // generate a list of strings for
2388b9c1b51eSKate Stone   // all the breakpoint ids in the range, and shove all of those breakpoint id
2389b9c1b51eSKate Stone   // strings into TEMP_ARGS.
239030fdc8d8SChris Lattner 
2391b9c1b51eSKate Stone   BreakpointIDList::FindAndReplaceIDRanges(args, target, allow_locations,
2392b9c1b51eSKate Stone                                            result, temp_args);
239330fdc8d8SChris Lattner 
2394b9c1b51eSKate Stone   // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual
2395b9c1b51eSKate Stone   // BreakpointIDList:
239630fdc8d8SChris Lattner 
2397b9c1b51eSKate Stone   valid_ids->InsertStringArray(temp_args.GetConstArgumentVector(),
2398b9c1b51eSKate Stone                                temp_args.GetArgumentCount(), result);
239930fdc8d8SChris Lattner 
2400b9c1b51eSKate Stone   // At this point,  all of the breakpoint ids that the user passed in have been
2401b9c1b51eSKate Stone   // converted to breakpoint IDs
240230fdc8d8SChris Lattner   // and put into valid_ids.
240330fdc8d8SChris Lattner 
2404b9c1b51eSKate Stone   if (result.Succeeded()) {
2405b9c1b51eSKate Stone     // Now that we've converted everything from args into a list of breakpoint
2406b9c1b51eSKate Stone     // ids, go through our tentative list
2407b9c1b51eSKate Stone     // of breakpoint id's and verify that they correspond to valid/currently set
2408b9c1b51eSKate Stone     // breakpoints.
240930fdc8d8SChris Lattner 
2410c982c768SGreg Clayton     const size_t count = valid_ids->GetSize();
2411b9c1b51eSKate Stone     for (size_t i = 0; i < count; ++i) {
241230fdc8d8SChris Lattner       BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex(i);
2413b9c1b51eSKate Stone       Breakpoint *breakpoint =
2414b9c1b51eSKate Stone           target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
2415b9c1b51eSKate Stone       if (breakpoint != nullptr) {
2416c7bece56SGreg Clayton         const size_t num_locations = breakpoint->GetNumLocations();
2417b9c1b51eSKate Stone         if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations) {
241830fdc8d8SChris Lattner           StreamString id_str;
2419b9c1b51eSKate Stone           BreakpointID::GetCanonicalReference(
2420b9c1b51eSKate Stone               &id_str, cur_bp_id.GetBreakpointID(), cur_bp_id.GetLocationID());
2421c982c768SGreg Clayton           i = valid_ids->GetSize() + 1;
2422b9c1b51eSKate Stone           result.AppendErrorWithFormat(
2423b9c1b51eSKate Stone               "'%s' is not a currently valid breakpoint/location id.\n",
242430fdc8d8SChris Lattner               id_str.GetData());
242530fdc8d8SChris Lattner           result.SetStatus(eReturnStatusFailed);
242630fdc8d8SChris Lattner         }
2427b9c1b51eSKate Stone       } else {
2428c982c768SGreg Clayton         i = valid_ids->GetSize() + 1;
2429b9c1b51eSKate Stone         result.AppendErrorWithFormat(
2430b9c1b51eSKate Stone             "'%d' is not a currently valid breakpoint ID.\n",
24317428a18cSKate Stone             cur_bp_id.GetBreakpointID());
243230fdc8d8SChris Lattner         result.SetStatus(eReturnStatusFailed);
243330fdc8d8SChris Lattner       }
243430fdc8d8SChris Lattner     }
243530fdc8d8SChris Lattner   }
243630fdc8d8SChris Lattner }
2437