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"
215275aaa0SVince Harron #include "lldb/Host/StringConvert.h"
2240af72e1SJim Ingham #include "lldb/Interpreter/Options.h"
2332abc6edSZachary Turner #include "lldb/Interpreter/OptionValueBoolean.h"
245e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueString.h"
255e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueUInt64.h"
2630fdc8d8SChris Lattner #include "lldb/Core/RegularExpression.h"
2730fdc8d8SChris Lattner #include "lldb/Core/StreamString.h"
2830fdc8d8SChris Lattner #include "lldb/Interpreter/CommandInterpreter.h"
2930fdc8d8SChris Lattner #include "lldb/Interpreter/CommandReturnObject.h"
300e0984eeSJim Ingham #include "lldb/Target/Language.h"
3130fdc8d8SChris Lattner #include "lldb/Target/Target.h"
3230fdc8d8SChris Lattner #include "lldb/Interpreter/CommandCompletions.h"
33b57e4a1bSJason Molenda #include "lldb/Target/StackFrame.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 
4030fdc8d8SChris Lattner static void
4185e8b814SJim Ingham AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level)
4230fdc8d8SChris Lattner {
4330fdc8d8SChris Lattner     s->IndentMore();
4430fdc8d8SChris Lattner     bp->GetDescription (s, level, true);
4530fdc8d8SChris Lattner     s->IndentLess();
4630fdc8d8SChris Lattner     s->EOL();
4730fdc8d8SChris Lattner }
4830fdc8d8SChris Lattner 
4930fdc8d8SChris Lattner //-------------------------------------------------------------------------
505a988416SJim Ingham // CommandObjectBreakpointSet
5130fdc8d8SChris Lattner //-------------------------------------------------------------------------
5230fdc8d8SChris Lattner 
535a988416SJim Ingham class CommandObjectBreakpointSet : public CommandObjectParsed
545a988416SJim Ingham {
555a988416SJim Ingham public:
565a988416SJim Ingham     typedef enum BreakpointSetType
575a988416SJim Ingham     {
585a988416SJim Ingham         eSetTypeInvalid,
595a988416SJim Ingham         eSetTypeFileAndLine,
605a988416SJim Ingham         eSetTypeAddress,
615a988416SJim Ingham         eSetTypeFunctionName,
625a988416SJim Ingham         eSetTypeFunctionRegexp,
635a988416SJim Ingham         eSetTypeSourceRegexp,
645a988416SJim Ingham         eSetTypeException
655a988416SJim Ingham     } BreakpointSetType;
665a988416SJim Ingham 
675a988416SJim Ingham     CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
685a988416SJim Ingham         CommandObjectParsed (interpreter,
695a988416SJim Ingham                              "breakpoint set",
705a988416SJim Ingham                              "Sets a breakpoint or set of breakpoints in the executable.",
715a988416SJim Ingham                              "breakpoint set <cmd-options>"),
725a988416SJim Ingham         m_options (interpreter)
735a988416SJim Ingham     {
745a988416SJim Ingham     }
755a988416SJim Ingham 
769e85e5a8SEugene Zelenko     ~CommandObjectBreakpointSet() override = default;
775a988416SJim Ingham 
7813d21e9aSBruce Mitchener     Options *
7913d21e9aSBruce Mitchener     GetOptions () override
805a988416SJim Ingham     {
815a988416SJim Ingham         return &m_options;
825a988416SJim Ingham     }
835a988416SJim Ingham 
845a988416SJim Ingham     class CommandOptions : public Options
855a988416SJim Ingham     {
865a988416SJim Ingham     public:
875a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
88eb0103f2SGreg Clayton             Options (interpreter),
897d49c9c8SJohnny Chen             m_condition (),
9087df91b8SJim Ingham             m_filenames (),
9130fdc8d8SChris Lattner             m_line_num (0),
9230fdc8d8SChris Lattner             m_column (0),
93fab10e89SJim Ingham             m_func_names (),
94fab10e89SJim Ingham             m_func_name_type_mask (eFunctionNameTypeNone),
9530fdc8d8SChris Lattner             m_func_regexp (),
96969795f1SJim Ingham             m_source_text_regexp(),
9730fdc8d8SChris Lattner             m_modules (),
981b54c88cSJim Ingham             m_load_addr(),
99c982c768SGreg Clayton             m_ignore_count (0),
1001b54c88cSJim Ingham             m_thread_id(LLDB_INVALID_THREAD_ID),
101c982c768SGreg Clayton             m_thread_index (UINT32_MAX),
1021b54c88cSJim Ingham             m_thread_name(),
103fab10e89SJim Ingham             m_queue_name(),
104fab10e89SJim Ingham             m_catch_bp (false),
1051f746071SGreg Clayton             m_throw_bp (true),
106eb023e75SGreg Clayton             m_hardware (false),
107a72b31c7SJim Ingham             m_exception_language (eLanguageTypeUnknown),
10823b1decbSDawn Perchik             m_language (lldb::eLanguageTypeUnknown),
109ca36cd16SJim Ingham             m_skip_prologue (eLazyBoolCalculate),
110e732052fSJim Ingham             m_one_shot (false),
111055ad9beSIlia K             m_all_files (false),
112055ad9beSIlia K             m_move_to_nearest_code (eLazyBoolCalculate)
11330fdc8d8SChris Lattner         {
11430fdc8d8SChris Lattner         }
11530fdc8d8SChris Lattner 
1169e85e5a8SEugene Zelenko         ~CommandOptions() override = default;
11787df91b8SJim Ingham 
11813d21e9aSBruce Mitchener         Error
11913d21e9aSBruce Mitchener         SetOptionValue (uint32_t option_idx, const char *option_arg) override
12030fdc8d8SChris Lattner         {
12130fdc8d8SChris Lattner             Error error;
1223bcdfc0eSGreg Clayton             const int short_option = m_getopt_table[option_idx].val;
12330fdc8d8SChris Lattner 
12430fdc8d8SChris Lattner             switch (short_option)
12530fdc8d8SChris Lattner             {
12630fdc8d8SChris Lattner                 case 'a':
127b9d5df58SGreg Clayton                     {
128b9d5df58SGreg Clayton                         ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
129b9d5df58SGreg Clayton                         m_load_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
130b9d5df58SGreg Clayton                     }
13130fdc8d8SChris Lattner                     break;
13230fdc8d8SChris Lattner 
133e732052fSJim Ingham                 case 'A':
134e732052fSJim Ingham                     m_all_files = true;
135e732052fSJim Ingham                     break;
136e732052fSJim Ingham 
137ca36cd16SJim Ingham                 case 'b':
138ca36cd16SJim Ingham                     m_func_names.push_back (option_arg);
139ca36cd16SJim Ingham                     m_func_name_type_mask |= eFunctionNameTypeBase;
140ca36cd16SJim Ingham                     break;
141ca36cd16SJim Ingham 
1427d49c9c8SJohnny Chen                 case 'C':
1436312991cSJim Ingham                 {
1446312991cSJim Ingham                     bool success;
1456312991cSJim Ingham                     m_column = StringConvert::ToUInt32 (option_arg, 0, 0, &success);
1466312991cSJim Ingham                     if (!success)
1476312991cSJim Ingham                         error.SetErrorStringWithFormat("invalid column number: %s", option_arg);
14830fdc8d8SChris Lattner                     break;
1496312991cSJim Ingham                 }
1509e85e5a8SEugene Zelenko 
1517d49c9c8SJohnny Chen                 case 'c':
1527d49c9c8SJohnny Chen                     m_condition.assign(option_arg);
1537d49c9c8SJohnny Chen                     break;
1547d49c9c8SJohnny Chen 
15533df7cd3SJim Ingham                 case 'D':
15633df7cd3SJim Ingham                     m_use_dummy = true;
15733df7cd3SJim Ingham                     break;
15833df7cd3SJim Ingham 
159fab10e89SJim Ingham                 case 'E':
160fab10e89SJim Ingham                 {
1610e0984eeSJim Ingham                     LanguageType language = Language::GetLanguageTypeFromString (option_arg);
162fab10e89SJim Ingham 
163fab10e89SJim Ingham                     switch (language)
164fab10e89SJim Ingham                     {
165fab10e89SJim Ingham                         case eLanguageTypeC89:
166fab10e89SJim Ingham                         case eLanguageTypeC:
167fab10e89SJim Ingham                         case eLanguageTypeC99:
1681d0089faSBruce Mitchener                         case eLanguageTypeC11:
169a72b31c7SJim Ingham                             m_exception_language = eLanguageTypeC;
170fab10e89SJim Ingham                             break;
171fab10e89SJim Ingham                         case eLanguageTypeC_plus_plus:
1721d0089faSBruce Mitchener                         case eLanguageTypeC_plus_plus_03:
1731d0089faSBruce Mitchener                         case eLanguageTypeC_plus_plus_11:
1742ba84a6aSBruce Mitchener                         case eLanguageTypeC_plus_plus_14:
175a72b31c7SJim Ingham                             m_exception_language = eLanguageTypeC_plus_plus;
176fab10e89SJim Ingham                             break;
177fab10e89SJim Ingham                         case eLanguageTypeObjC:
178a72b31c7SJim Ingham                             m_exception_language = eLanguageTypeObjC;
179fab10e89SJim Ingham                             break;
180fab10e89SJim Ingham                         case eLanguageTypeObjC_plus_plus:
181fab10e89SJim Ingham                             error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c");
182fab10e89SJim Ingham                             break;
183fab10e89SJim Ingham                         case eLanguageTypeUnknown:
184fab10e89SJim Ingham                             error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg);
185fab10e89SJim Ingham                             break;
186fab10e89SJim Ingham                         default:
187fab10e89SJim Ingham                             error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg);
188fab10e89SJim Ingham                     }
189fab10e89SJim Ingham                 }
190fab10e89SJim Ingham                 break;
191ca36cd16SJim Ingham 
192ca36cd16SJim Ingham                 case 'f':
193ca36cd16SJim Ingham                     m_filenames.AppendIfUnique (FileSpec(option_arg, false));
194fab10e89SJim Ingham                     break;
195ca36cd16SJim Ingham 
196ca36cd16SJim Ingham                 case 'F':
197ca36cd16SJim Ingham                     m_func_names.push_back (option_arg);
198ca36cd16SJim Ingham                     m_func_name_type_mask |= eFunctionNameTypeFull;
199ca36cd16SJim Ingham                     break;
200ca36cd16SJim Ingham 
201fab10e89SJim Ingham                 case 'h':
202fab10e89SJim Ingham                     {
203fab10e89SJim Ingham                         bool success;
204fab10e89SJim Ingham                         m_catch_bp = Args::StringToBoolean (option_arg, true, &success);
205fab10e89SJim Ingham                         if (!success)
206fab10e89SJim Ingham                             error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg);
207fab10e89SJim Ingham                     }
208168d469aSJim Ingham                     break;
209eb023e75SGreg Clayton 
210eb023e75SGreg Clayton                 case 'H':
211eb023e75SGreg Clayton                     m_hardware = true;
212eb023e75SGreg Clayton                     break;
213eb023e75SGreg Clayton 
214ca36cd16SJim Ingham                 case 'i':
2155275aaa0SVince Harron                     m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
216ca36cd16SJim Ingham                     if (m_ignore_count == UINT32_MAX)
217ca36cd16SJim Ingham                        error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
218ca36cd16SJim Ingham                     break;
219ca36cd16SJim Ingham 
220a8558b62SJim Ingham                 case 'K':
221a8558b62SJim Ingham                 {
222a8558b62SJim Ingham                     bool success;
223a8558b62SJim Ingham                     bool value;
224a8558b62SJim Ingham                     value = Args::StringToBoolean (option_arg, true, &success);
225a8558b62SJim Ingham                     if (value)
226a8558b62SJim Ingham                         m_skip_prologue = eLazyBoolYes;
227a8558b62SJim Ingham                     else
228a8558b62SJim Ingham                         m_skip_prologue = eLazyBoolNo;
229a8558b62SJim Ingham 
230a8558b62SJim Ingham                     if (!success)
231a8558b62SJim Ingham                         error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg);
232a8558b62SJim Ingham                 }
233fab10e89SJim Ingham                 break;
234ca36cd16SJim Ingham 
235ca36cd16SJim Ingham                 case 'l':
2366312991cSJim Ingham                 {
2376312991cSJim Ingham                     bool success;
2386312991cSJim Ingham                     m_line_num = StringConvert::ToUInt32 (option_arg, 0, 0, &success);
2396312991cSJim Ingham                     if (!success)
2406312991cSJim Ingham                         error.SetErrorStringWithFormat ("invalid line number: %s.", option_arg);
241ca36cd16SJim Ingham                     break;
2426312991cSJim Ingham                 }
243055ad9beSIlia K 
24423b1decbSDawn Perchik                 case 'L':
2450e0984eeSJim Ingham                     m_language = Language::GetLanguageTypeFromString (option_arg);
24623b1decbSDawn Perchik                     if (m_language == eLanguageTypeUnknown)
24723b1decbSDawn Perchik                         error.SetErrorStringWithFormat ("Unknown language type: '%s' for breakpoint", option_arg);
24823b1decbSDawn Perchik                     break;
24923b1decbSDawn Perchik 
250055ad9beSIlia K                 case 'm':
251055ad9beSIlia K                 {
252055ad9beSIlia K                     bool success;
253055ad9beSIlia K                     bool value;
254055ad9beSIlia K                     value = Args::StringToBoolean (option_arg, true, &success);
255055ad9beSIlia K                     if (value)
256055ad9beSIlia K                         m_move_to_nearest_code = eLazyBoolYes;
257055ad9beSIlia K                     else
258055ad9beSIlia K                         m_move_to_nearest_code = eLazyBoolNo;
259055ad9beSIlia K 
260055ad9beSIlia K                     if (!success)
261055ad9beSIlia K                         error.SetErrorStringWithFormat ("Invalid boolean value for move-to-nearest-code option: '%s'", option_arg);
262055ad9beSIlia K                     break;
263055ad9beSIlia K                 }
264055ad9beSIlia K 
265ca36cd16SJim Ingham                 case 'M':
266ca36cd16SJim Ingham                     m_func_names.push_back (option_arg);
267ca36cd16SJim Ingham                     m_func_name_type_mask |= eFunctionNameTypeMethod;
268ca36cd16SJim Ingham                     break;
269ca36cd16SJim Ingham 
270ca36cd16SJim Ingham                 case 'n':
271ca36cd16SJim Ingham                     m_func_names.push_back (option_arg);
272ca36cd16SJim Ingham                     m_func_name_type_mask |= eFunctionNameTypeAuto;
273ca36cd16SJim Ingham                     break;
274ca36cd16SJim Ingham 
2755e09c8c3SJim Ingham                 case 'N':
2765e09c8c3SJim Ingham                     if (BreakpointID::StringIsBreakpointName(option_arg, error))
2775e09c8c3SJim Ingham                         m_breakpoint_names.push_back (option_arg);
2785e09c8c3SJim Ingham                     break;
2795e09c8c3SJim Ingham 
2802411167fSJim Ingham                 case 'R':
2812411167fSJim Ingham                     {
2822411167fSJim Ingham                         ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
2832411167fSJim Ingham                         lldb::addr_t tmp_offset_addr;
2842411167fSJim Ingham                         tmp_offset_addr = Args::StringToAddress(&exe_ctx, option_arg, 0, &error);
2852411167fSJim Ingham                         if (error.Success())
2862411167fSJim Ingham                             m_offset_addr = tmp_offset_addr;
2872411167fSJim Ingham                     }
2882411167fSJim Ingham                     break;
2892411167fSJim Ingham 
290ca36cd16SJim Ingham                 case 'o':
291ca36cd16SJim Ingham                     m_one_shot = true;
292ca36cd16SJim Ingham                     break;
293ca36cd16SJim Ingham 
294a72b31c7SJim Ingham                 case 'O':
295a72b31c7SJim Ingham                     m_exception_extra_args.AppendArgument ("-O");
296a72b31c7SJim Ingham                     m_exception_extra_args.AppendArgument (option_arg);
297a72b31c7SJim Ingham                     break;
298a72b31c7SJim Ingham 
299ca36cd16SJim Ingham                 case 'p':
300ca36cd16SJim Ingham                     m_source_text_regexp.assign (option_arg);
301ca36cd16SJim Ingham                     break;
302ca36cd16SJim Ingham 
303ca36cd16SJim Ingham                 case 'q':
304ca36cd16SJim Ingham                     m_queue_name.assign (option_arg);
305ca36cd16SJim Ingham                     break;
306ca36cd16SJim Ingham 
307ca36cd16SJim Ingham                 case 'r':
308ca36cd16SJim Ingham                     m_func_regexp.assign (option_arg);
309ca36cd16SJim Ingham                     break;
310ca36cd16SJim Ingham 
311ca36cd16SJim Ingham                 case 's':
312ca36cd16SJim Ingham                     m_modules.AppendIfUnique (FileSpec (option_arg, false));
313ca36cd16SJim Ingham                     break;
314ca36cd16SJim Ingham 
315ca36cd16SJim Ingham                 case 'S':
316ca36cd16SJim Ingham                     m_func_names.push_back (option_arg);
317ca36cd16SJim Ingham                     m_func_name_type_mask |= eFunctionNameTypeSelector;
318ca36cd16SJim Ingham                     break;
319ca36cd16SJim Ingham 
320ca36cd16SJim Ingham                 case 't' :
3215275aaa0SVince Harron                     m_thread_id = StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
322ca36cd16SJim Ingham                     if (m_thread_id == LLDB_INVALID_THREAD_ID)
323ca36cd16SJim Ingham                        error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
324ca36cd16SJim Ingham                     break;
325ca36cd16SJim Ingham 
326ca36cd16SJim Ingham                 case 'T':
327ca36cd16SJim Ingham                     m_thread_name.assign (option_arg);
328ca36cd16SJim Ingham                     break;
329ca36cd16SJim Ingham 
330ca36cd16SJim Ingham                 case 'w':
331ca36cd16SJim Ingham                 {
332ca36cd16SJim Ingham                     bool success;
333ca36cd16SJim Ingham                     m_throw_bp = Args::StringToBoolean (option_arg, true, &success);
334ca36cd16SJim Ingham                     if (!success)
335ca36cd16SJim Ingham                         error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg);
336ca36cd16SJim Ingham                 }
337ca36cd16SJim Ingham                 break;
338ca36cd16SJim Ingham 
339ca36cd16SJim Ingham                 case 'x':
3405275aaa0SVince Harron                     m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
341ca36cd16SJim Ingham                     if (m_thread_id == UINT32_MAX)
342ca36cd16SJim Ingham                        error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
343ca36cd16SJim Ingham                     break;
344ca36cd16SJim Ingham 
34576bb8d67SJim Ingham                 case 'X':
34676bb8d67SJim Ingham                     m_source_regex_func_names.insert(option_arg);
34776bb8d67SJim Ingham                     break;
34876bb8d67SJim Ingham 
34930fdc8d8SChris Lattner                 default:
35086edbf41SGreg Clayton                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
35130fdc8d8SChris Lattner                     break;
35230fdc8d8SChris Lattner             }
35330fdc8d8SChris Lattner 
35430fdc8d8SChris Lattner             return error;
35530fdc8d8SChris Lattner         }
3569e85e5a8SEugene Zelenko 
35730fdc8d8SChris Lattner         void
35813d21e9aSBruce Mitchener         OptionParsingStarting () override
35930fdc8d8SChris Lattner         {
3607d49c9c8SJohnny Chen             m_condition.clear();
36187df91b8SJim Ingham             m_filenames.Clear();
36230fdc8d8SChris Lattner             m_line_num = 0;
36330fdc8d8SChris Lattner             m_column = 0;
364fab10e89SJim Ingham             m_func_names.clear();
3651f746071SGreg Clayton             m_func_name_type_mask = eFunctionNameTypeNone;
36630fdc8d8SChris Lattner             m_func_regexp.clear();
3671f746071SGreg Clayton             m_source_text_regexp.clear();
36887df91b8SJim Ingham             m_modules.Clear();
3691f746071SGreg Clayton             m_load_addr = LLDB_INVALID_ADDRESS;
3702411167fSJim Ingham             m_offset_addr = 0;
371c982c768SGreg Clayton             m_ignore_count = 0;
3721b54c88cSJim Ingham             m_thread_id = LLDB_INVALID_THREAD_ID;
373c982c768SGreg Clayton             m_thread_index = UINT32_MAX;
3741b54c88cSJim Ingham             m_thread_name.clear();
3751b54c88cSJim Ingham             m_queue_name.clear();
376fab10e89SJim Ingham             m_catch_bp = false;
377fab10e89SJim Ingham             m_throw_bp = true;
378eb023e75SGreg Clayton             m_hardware = false;
379a72b31c7SJim Ingham             m_exception_language = eLanguageTypeUnknown;
38023b1decbSDawn Perchik             m_language = lldb::eLanguageTypeUnknown;
381a8558b62SJim Ingham             m_skip_prologue = eLazyBoolCalculate;
382ca36cd16SJim Ingham             m_one_shot = false;
38333df7cd3SJim Ingham             m_use_dummy = false;
3845e09c8c3SJim Ingham             m_breakpoint_names.clear();
385e732052fSJim Ingham             m_all_files = false;
386a72b31c7SJim Ingham             m_exception_extra_args.Clear();
387055ad9beSIlia K             m_move_to_nearest_code = eLazyBoolCalculate;
38876bb8d67SJim Ingham             m_source_regex_func_names.clear();
38930fdc8d8SChris Lattner         }
39030fdc8d8SChris Lattner 
3915a988416SJim Ingham         const OptionDefinition*
39213d21e9aSBruce Mitchener         GetDefinitions () override
39330fdc8d8SChris Lattner         {
3945a988416SJim Ingham             return g_option_table;
39530fdc8d8SChris Lattner         }
39630fdc8d8SChris Lattner 
3975a988416SJim Ingham         // Options table: Required for subclasses of Options.
39830fdc8d8SChris Lattner 
3995a988416SJim Ingham         static OptionDefinition g_option_table[];
40030fdc8d8SChris Lattner 
4015a988416SJim Ingham         // Instance variables to hold the values for command options.
402969795f1SJim Ingham 
4035a988416SJim Ingham         std::string m_condition;
4045a988416SJim Ingham         FileSpecList m_filenames;
4055a988416SJim Ingham         uint32_t m_line_num;
4065a988416SJim Ingham         uint32_t m_column;
4075a988416SJim Ingham         std::vector<std::string> m_func_names;
4085e09c8c3SJim Ingham         std::vector<std::string> m_breakpoint_names;
4095a988416SJim Ingham         uint32_t m_func_name_type_mask;
4105a988416SJim Ingham         std::string m_func_regexp;
4115a988416SJim Ingham         std::string m_source_text_regexp;
4125a988416SJim Ingham         FileSpecList m_modules;
4135a988416SJim Ingham         lldb::addr_t m_load_addr;
4142411167fSJim Ingham         lldb::addr_t m_offset_addr;
4155a988416SJim Ingham         uint32_t m_ignore_count;
4165a988416SJim Ingham         lldb::tid_t m_thread_id;
4175a988416SJim Ingham         uint32_t m_thread_index;
4185a988416SJim Ingham         std::string m_thread_name;
4195a988416SJim Ingham         std::string m_queue_name;
4205a988416SJim Ingham         bool m_catch_bp;
4215a988416SJim Ingham         bool m_throw_bp;
422eb023e75SGreg Clayton         bool m_hardware; // Request to use hardware breakpoints
423a72b31c7SJim Ingham         lldb::LanguageType m_exception_language;
42423b1decbSDawn Perchik         lldb::LanguageType m_language;
4255a988416SJim Ingham         LazyBool m_skip_prologue;
426ca36cd16SJim Ingham         bool m_one_shot;
42733df7cd3SJim Ingham         bool m_use_dummy;
428e732052fSJim Ingham         bool m_all_files;
429a72b31c7SJim Ingham         Args m_exception_extra_args;
430055ad9beSIlia K         LazyBool m_move_to_nearest_code;
43176bb8d67SJim Ingham         std::unordered_set<std::string> m_source_regex_func_names;
4325a988416SJim Ingham     };
4335a988416SJim Ingham 
4345a988416SJim Ingham protected:
43513d21e9aSBruce Mitchener     bool
4365a988416SJim Ingham     DoExecute (Args& command,
43713d21e9aSBruce Mitchener               CommandReturnObject &result) override
43830fdc8d8SChris Lattner     {
43933df7cd3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
44033df7cd3SJim Ingham 
441893c932aSJim Ingham         if (target == nullptr)
44230fdc8d8SChris Lattner         {
443effe5c95SGreg Clayton             result.AppendError ("Invalid target.  Must set target before setting breakpoints (see 'target create' command).");
44430fdc8d8SChris Lattner             result.SetStatus (eReturnStatusFailed);
44530fdc8d8SChris Lattner             return false;
44630fdc8d8SChris Lattner         }
44730fdc8d8SChris Lattner 
44830fdc8d8SChris Lattner         // The following are the various types of breakpoints that could be set:
44930fdc8d8SChris Lattner         //   1).  -f -l -p  [-s -g]   (setting breakpoint by source location)
45030fdc8d8SChris Lattner         //   2).  -a  [-s -g]         (setting breakpoint by address)
45130fdc8d8SChris Lattner         //   3).  -n  [-s -g]         (setting breakpoint by function name)
45230fdc8d8SChris Lattner         //   4).  -r  [-s -g]         (setting breakpoint by function name regular expression)
453969795f1SJim Ingham         //   5).  -p -f               (setting a breakpoint by comparing a reg-exp to source text)
454fab10e89SJim Ingham         //   6).  -E [-w -h]          (setting a breakpoint for exceptions for a given language.)
45530fdc8d8SChris Lattner 
45630fdc8d8SChris Lattner         BreakpointSetType break_type = eSetTypeInvalid;
45730fdc8d8SChris Lattner 
45830fdc8d8SChris Lattner         if (m_options.m_line_num != 0)
45930fdc8d8SChris Lattner             break_type = eSetTypeFileAndLine;
46030fdc8d8SChris Lattner         else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
46130fdc8d8SChris Lattner             break_type = eSetTypeAddress;
462fab10e89SJim Ingham         else if (!m_options.m_func_names.empty())
46330fdc8d8SChris Lattner             break_type = eSetTypeFunctionName;
46430fdc8d8SChris Lattner         else if  (!m_options.m_func_regexp.empty())
46530fdc8d8SChris Lattner             break_type = eSetTypeFunctionRegexp;
466969795f1SJim Ingham         else if (!m_options.m_source_text_regexp.empty())
467969795f1SJim Ingham             break_type = eSetTypeSourceRegexp;
468a72b31c7SJim Ingham         else if (m_options.m_exception_language != eLanguageTypeUnknown)
469fab10e89SJim Ingham             break_type = eSetTypeException;
47030fdc8d8SChris Lattner 
4719e85e5a8SEugene Zelenko         Breakpoint *bp = nullptr;
472274060b6SGreg Clayton         FileSpec module_spec;
473a8558b62SJim Ingham         const bool internal = false;
474a8558b62SJim Ingham 
4752411167fSJim Ingham         // If the user didn't specify skip-prologue, having an offset should turn that off.
4762411167fSJim Ingham         if (m_options.m_offset_addr != 0 && m_options.m_skip_prologue == eLazyBoolCalculate)
4772411167fSJim Ingham             m_options.m_skip_prologue = eLazyBoolNo;
4782411167fSJim Ingham 
47930fdc8d8SChris Lattner         switch (break_type)
48030fdc8d8SChris Lattner         {
48130fdc8d8SChris Lattner             case eSetTypeFileAndLine: // Breakpoint by source position
48230fdc8d8SChris Lattner                 {
48330fdc8d8SChris Lattner                     FileSpec file;
484c7bece56SGreg Clayton                     const size_t num_files = m_options.m_filenames.GetSize();
48587df91b8SJim Ingham                     if (num_files == 0)
48687df91b8SJim Ingham                     {
48787df91b8SJim Ingham                         if (!GetDefaultFile (target, file, result))
48887df91b8SJim Ingham                         {
48987df91b8SJim Ingham                             result.AppendError("No file supplied and no default file available.");
49087df91b8SJim Ingham                             result.SetStatus (eReturnStatusFailed);
49187df91b8SJim Ingham                             return false;
49287df91b8SJim Ingham                         }
49387df91b8SJim Ingham                     }
49487df91b8SJim Ingham                     else if (num_files > 1)
49587df91b8SJim Ingham                     {
49687df91b8SJim Ingham                         result.AppendError("Only one file at a time is allowed for file and line breakpoints.");
49787df91b8SJim Ingham                         result.SetStatus (eReturnStatusFailed);
49887df91b8SJim Ingham                         return false;
49987df91b8SJim Ingham                     }
50087df91b8SJim Ingham                     else
50187df91b8SJim Ingham                         file = m_options.m_filenames.GetFileSpecAtIndex(0);
50230fdc8d8SChris Lattner 
5031f746071SGreg Clayton                     // Only check for inline functions if
5041f746071SGreg Clayton                     LazyBool check_inlines = eLazyBoolCalculate;
5051f746071SGreg Clayton 
50687df91b8SJim Ingham                     bp = target->CreateBreakpoint (&(m_options.m_modules),
50730fdc8d8SChris Lattner                                                    file,
50830fdc8d8SChris Lattner                                                    m_options.m_line_num,
5092411167fSJim Ingham                                                    m_options.m_offset_addr,
5101f746071SGreg Clayton                                                    check_inlines,
511a8558b62SJim Ingham                                                    m_options.m_skip_prologue,
512eb023e75SGreg Clayton                                                    internal,
513055ad9beSIlia K                                                    m_options.m_hardware,
514055ad9beSIlia K                                                    m_options.m_move_to_nearest_code).get();
51530fdc8d8SChris Lattner                 }
51630fdc8d8SChris Lattner                 break;
5176eee5aa0SGreg Clayton 
51830fdc8d8SChris Lattner             case eSetTypeAddress: // Breakpoint by address
519055a08a4SJim Ingham                 {
520055a08a4SJim Ingham                     // If a shared library has been specified, make an lldb_private::Address with the library, and
521055a08a4SJim Ingham                     // use that.  That way the address breakpoint will track the load location of the library.
522055a08a4SJim Ingham                     size_t num_modules_specified = m_options.m_modules.GetSize();
523055a08a4SJim Ingham                     if (num_modules_specified == 1)
524055a08a4SJim Ingham                     {
525055a08a4SJim Ingham                         const FileSpec *file_spec = m_options.m_modules.GetFileSpecPointerAtIndex(0);
526055a08a4SJim Ingham                         bp = target->CreateAddressInModuleBreakpoint (m_options.m_load_addr,
527055a08a4SJim Ingham                                                                       internal,
528055a08a4SJim Ingham                                                                       file_spec,
529055a08a4SJim Ingham                                                                       m_options.m_hardware).get();
530055a08a4SJim Ingham                     }
531055a08a4SJim Ingham                     else if (num_modules_specified == 0)
532055a08a4SJim Ingham                     {
533eb023e75SGreg Clayton                         bp = target->CreateBreakpoint (m_options.m_load_addr,
534eb023e75SGreg Clayton                                                        internal,
535eb023e75SGreg Clayton                                                        m_options.m_hardware).get();
536055a08a4SJim Ingham                     }
537055a08a4SJim Ingham                     else
538055a08a4SJim Ingham                     {
539055a08a4SJim Ingham                         result.AppendError("Only one shared library can be specified for address breakpoints.");
540055a08a4SJim Ingham                         result.SetStatus(eReturnStatusFailed);
541055a08a4SJim Ingham                         return false;
542055a08a4SJim Ingham                     }
54330fdc8d8SChris Lattner                 break;
544055a08a4SJim Ingham                 }
54530fdc8d8SChris Lattner             case eSetTypeFunctionName: // Breakpoint by function name
5460c5cd90dSGreg Clayton                 {
5470c5cd90dSGreg Clayton                     uint32_t name_type_mask = m_options.m_func_name_type_mask;
5480c5cd90dSGreg Clayton 
5490c5cd90dSGreg Clayton                     if (name_type_mask == 0)
550e02b8504SGreg Clayton                         name_type_mask = eFunctionNameTypeAuto;
5510c5cd90dSGreg Clayton 
55287df91b8SJim Ingham                     bp = target->CreateBreakpoint (&(m_options.m_modules),
55387df91b8SJim Ingham                                                    &(m_options.m_filenames),
554fab10e89SJim Ingham                                                    m_options.m_func_names,
555274060b6SGreg Clayton                                                    name_type_mask,
55623b1decbSDawn Perchik                                                    m_options.m_language,
5572411167fSJim Ingham                                                    m_options.m_offset_addr,
558a8558b62SJim Ingham                                                    m_options.m_skip_prologue,
559eb023e75SGreg Clayton                                                    internal,
560eb023e75SGreg Clayton                                                    m_options.m_hardware).get();
5610c5cd90dSGreg Clayton                 }
56230fdc8d8SChris Lattner                 break;
5630c5cd90dSGreg Clayton 
56430fdc8d8SChris Lattner             case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
56530fdc8d8SChris Lattner                 {
56630fdc8d8SChris Lattner                     RegularExpression regexp(m_options.m_func_regexp.c_str());
567969795f1SJim Ingham                     if (!regexp.IsValid())
56830fdc8d8SChris Lattner                     {
569969795f1SJim Ingham                         char err_str[1024];
570969795f1SJim Ingham                         regexp.GetErrorAsCString(err_str, sizeof(err_str));
571969795f1SJim Ingham                         result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"",
572969795f1SJim Ingham                                                      err_str);
57330fdc8d8SChris Lattner                         result.SetStatus (eReturnStatusFailed);
574969795f1SJim Ingham                         return false;
57530fdc8d8SChris Lattner                     }
57687df91b8SJim Ingham 
577a8558b62SJim Ingham                     bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules),
578a8558b62SJim Ingham                                                             &(m_options.m_filenames),
579a8558b62SJim Ingham                                                             regexp,
5800fcdac36SJim Ingham                                                             m_options.m_language,
581a8558b62SJim Ingham                                                             m_options.m_skip_prologue,
582eb023e75SGreg Clayton                                                             internal,
583eb023e75SGreg Clayton                                                             m_options.m_hardware).get();
58430fdc8d8SChris Lattner                 }
58530fdc8d8SChris Lattner                 break;
586969795f1SJim Ingham             case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
587969795f1SJim Ingham                 {
588c7bece56SGreg Clayton                     const size_t num_files = m_options.m_filenames.GetSize();
58987df91b8SJim Ingham 
590e732052fSJim Ingham                     if (num_files == 0 && !m_options.m_all_files)
59187df91b8SJim Ingham                     {
592969795f1SJim Ingham                         FileSpec file;
59387df91b8SJim Ingham                         if (!GetDefaultFile (target, file, result))
59487df91b8SJim Ingham                         {
59587df91b8SJim Ingham                             result.AppendError ("No files provided and could not find default file.");
59687df91b8SJim Ingham                             result.SetStatus (eReturnStatusFailed);
59787df91b8SJim Ingham                             return false;
59887df91b8SJim Ingham                         }
59987df91b8SJim Ingham                         else
60087df91b8SJim Ingham                         {
60187df91b8SJim Ingham                             m_options.m_filenames.Append (file);
60287df91b8SJim Ingham                         }
60387df91b8SJim Ingham                     }
6040c5cd90dSGreg Clayton 
605969795f1SJim Ingham                     RegularExpression regexp(m_options.m_source_text_regexp.c_str());
606969795f1SJim Ingham                     if (!regexp.IsValid())
607969795f1SJim Ingham                     {
608969795f1SJim Ingham                         char err_str[1024];
609969795f1SJim Ingham                         regexp.GetErrorAsCString(err_str, sizeof(err_str));
610969795f1SJim Ingham                         result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"",
611969795f1SJim Ingham                                                      err_str);
612969795f1SJim Ingham                         result.SetStatus (eReturnStatusFailed);
613969795f1SJim Ingham                         return false;
614969795f1SJim Ingham                     }
615eb023e75SGreg Clayton                     bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules),
616eb023e75SGreg Clayton                                                               &(m_options.m_filenames),
61776bb8d67SJim Ingham                                                               m_options.m_source_regex_func_names,
618eb023e75SGreg Clayton                                                               regexp,
619eb023e75SGreg Clayton                                                               internal,
620055ad9beSIlia K                                                               m_options.m_hardware,
621055ad9beSIlia K                                                               m_options.m_move_to_nearest_code).get();
622969795f1SJim Ingham                 }
623969795f1SJim Ingham                 break;
624fab10e89SJim Ingham             case eSetTypeException:
625fab10e89SJim Ingham                 {
626a72b31c7SJim Ingham                     Error precond_error;
627a72b31c7SJim Ingham                     bp = target->CreateExceptionBreakpoint (m_options.m_exception_language,
628eb023e75SGreg Clayton                                                             m_options.m_catch_bp,
629eb023e75SGreg Clayton                                                             m_options.m_throw_bp,
630a72b31c7SJim Ingham                                                             internal,
631a72b31c7SJim Ingham                                                             &m_options.m_exception_extra_args,
632a72b31c7SJim Ingham                                                             &precond_error).get();
633a72b31c7SJim Ingham                     if (precond_error.Fail())
634a72b31c7SJim Ingham                     {
635a72b31c7SJim Ingham                         result.AppendErrorWithFormat("Error setting extra exception arguments: %s",
636a72b31c7SJim Ingham                                                      precond_error.AsCString());
637a72b31c7SJim Ingham                         target->RemoveBreakpointByID(bp->GetID());
638a72b31c7SJim Ingham                         result.SetStatus(eReturnStatusFailed);
639a72b31c7SJim Ingham                         return false;
640a72b31c7SJim Ingham                     }
641fab10e89SJim Ingham                 }
642fab10e89SJim Ingham                 break;
64330fdc8d8SChris Lattner             default:
64430fdc8d8SChris Lattner                 break;
64530fdc8d8SChris Lattner         }
64630fdc8d8SChris Lattner 
6471b54c88cSJim Ingham         // Now set the various options that were passed in:
6481b54c88cSJim Ingham         if (bp)
6491b54c88cSJim Ingham         {
6501b54c88cSJim Ingham             if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
6511b54c88cSJim Ingham                 bp->SetThreadID (m_options.m_thread_id);
6521b54c88cSJim Ingham 
653c982c768SGreg Clayton             if (m_options.m_thread_index != UINT32_MAX)
6541b54c88cSJim Ingham                 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
6551b54c88cSJim Ingham 
6561b54c88cSJim Ingham             if (!m_options.m_thread_name.empty())
6571b54c88cSJim Ingham                 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
6581b54c88cSJim Ingham 
6591b54c88cSJim Ingham             if (!m_options.m_queue_name.empty())
6601b54c88cSJim Ingham                 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
6611b54c88cSJim Ingham 
662c982c768SGreg Clayton             if (m_options.m_ignore_count != 0)
6631b54c88cSJim Ingham                 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
6647d49c9c8SJohnny Chen 
6657d49c9c8SJohnny Chen             if (!m_options.m_condition.empty())
6667d49c9c8SJohnny Chen                 bp->GetOptions()->SetCondition(m_options.m_condition.c_str());
667ca36cd16SJim Ingham 
6685e09c8c3SJim Ingham             if (!m_options.m_breakpoint_names.empty())
6695e09c8c3SJim Ingham             {
6705e09c8c3SJim Ingham                 Error error;  // We don't need to check the error here, since the option parser checked it...
6715e09c8c3SJim Ingham                 for (auto name : m_options.m_breakpoint_names)
6725e09c8c3SJim Ingham                     bp->AddName(name.c_str(), error);
6735e09c8c3SJim Ingham             }
6745e09c8c3SJim Ingham 
675ca36cd16SJim Ingham             bp->SetOneShot (m_options.m_one_shot);
6761b54c88cSJim Ingham         }
6771b54c88cSJim Ingham 
678969795f1SJim Ingham         if (bp)
67930fdc8d8SChris Lattner         {
68085e8b814SJim Ingham             Stream &output_stream = result.GetOutputStream();
6811391cc7dSJim Ingham             const bool show_locations = false;
6821391cc7dSJim Ingham             bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, show_locations);
6834aeb1989SJim Ingham             if (target == m_interpreter.GetDebugger().GetDummyTarget())
6844aeb1989SJim Ingham                     output_stream.Printf ("Breakpoint set in dummy target, will get copied into future targets.\n");
6854aeb1989SJim Ingham             else
6864aeb1989SJim Ingham             {
687fab10e89SJim Ingham                 // Don't print out this warning for exception breakpoints.  They can get set before the target
688fab10e89SJim Ingham                 // is set, but we won't know how to actually set the breakpoint till we run.
689fab10e89SJim Ingham                 if (bp->GetNumLocations() == 0 && break_type != eSetTypeException)
6904aeb1989SJim Ingham                 {
691be484f41SCaroline Tice                     output_stream.Printf ("WARNING:  Unable to resolve breakpoint to any actual locations.\n");
6924aeb1989SJim Ingham                 }
6934aeb1989SJim Ingham             }
69430fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishResult);
69530fdc8d8SChris Lattner         }
69630fdc8d8SChris Lattner         else if (!bp)
69730fdc8d8SChris Lattner         {
69830fdc8d8SChris Lattner             result.AppendError ("Breakpoint creation failed: No breakpoint created.");
69930fdc8d8SChris Lattner             result.SetStatus (eReturnStatusFailed);
70030fdc8d8SChris Lattner         }
70130fdc8d8SChris Lattner 
70230fdc8d8SChris Lattner         return result.Succeeded();
70330fdc8d8SChris Lattner     }
70430fdc8d8SChris Lattner 
7055a988416SJim Ingham private:
7065a988416SJim Ingham     bool
7075a988416SJim Ingham     GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result)
7085a988416SJim Ingham     {
7095a988416SJim Ingham         uint32_t default_line;
7105a988416SJim Ingham         // First use the Source Manager's default file.
7115a988416SJim Ingham         // Then use the current stack frame's file.
7125a988416SJim Ingham         if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line))
7135a988416SJim Ingham         {
714b57e4a1bSJason Molenda             StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
7159e85e5a8SEugene Zelenko             if (cur_frame == nullptr)
7165a988416SJim Ingham             {
7175a988416SJim Ingham                 result.AppendError ("No selected frame to use to find the default file.");
7185a988416SJim Ingham                 result.SetStatus (eReturnStatusFailed);
7195a988416SJim Ingham                 return false;
7205a988416SJim Ingham             }
7215a988416SJim Ingham             else if (!cur_frame->HasDebugInformation())
7225a988416SJim Ingham             {
7235a988416SJim Ingham                 result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info.");
7245a988416SJim Ingham                 result.SetStatus (eReturnStatusFailed);
7255a988416SJim Ingham                 return false;
7265a988416SJim Ingham             }
7275a988416SJim Ingham             else
7285a988416SJim Ingham             {
7295a988416SJim Ingham                 const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
7305a988416SJim Ingham                 if (sc.line_entry.file)
7315a988416SJim Ingham                 {
7325a988416SJim Ingham                     file = sc.line_entry.file;
7335a988416SJim Ingham                 }
7345a988416SJim Ingham                 else
7355a988416SJim Ingham                 {
7365a988416SJim Ingham                     result.AppendError ("Can't find the file for the selected frame to use as the default file.");
7375a988416SJim Ingham                     result.SetStatus (eReturnStatusFailed);
7385a988416SJim Ingham                     return false;
7395a988416SJim Ingham                 }
7405a988416SJim Ingham             }
7415a988416SJim Ingham         }
7425a988416SJim Ingham         return true;
7435a988416SJim Ingham     }
7445a988416SJim Ingham 
7455a988416SJim Ingham     CommandOptions m_options;
7465a988416SJim Ingham };
7479e85e5a8SEugene Zelenko 
7485a988416SJim Ingham // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to
7495a988416SJim Ingham // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately.
7505a988416SJim Ingham #define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 )
7515a988416SJim Ingham #define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 )
7525a988416SJim Ingham #define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) )
7532411167fSJim Ingham #define LLDB_OPT_OFFSET_APPLIES (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) )
754055ad9beSIlia K #define LLDB_OPT_MOVE_TO_NEAREST_CODE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_9 )
7550fcdac36SJim Ingham #define LLDB_OPT_EXPR_LANGUAGE ( LLDB_OPT_SET_FROM_TO(3, 8) )
7565a988416SJim Ingham 
7575a988416SJim Ingham OptionDefinition
7585a988416SJim Ingham CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
7595a988416SJim Ingham {
7609e85e5a8SEugene Zelenko     { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
7615a988416SJim Ingham         "Set the breakpoint only in this shared library.  "
7625a988416SJim Ingham         "Can repeat this option multiple times to specify multiple shared libraries."},
7635a988416SJim Ingham 
7649e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount,
7655a988416SJim Ingham         "Set the number of times this breakpoint is skipped before stopping." },
7665a988416SJim Ingham 
7679e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
768b2b256afSJim Ingham         "The breakpoint is deleted the first time it causes a stop." },
769ca36cd16SJim Ingham 
7709e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "condition",    'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression,
7715a988416SJim Ingham         "The breakpoint stops only if this condition expression evaluates to true."},
7725a988416SJim Ingham 
7739e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex,
774a89be91fSJim Ingham         "The breakpoint stops only for the thread whose indeX matches this argument."},
7755a988416SJim Ingham 
7769e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID,
7775a988416SJim Ingham         "The breakpoint stops only for the thread whose TID matches this argument."},
7785a988416SJim Ingham 
7799e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName,
7805a988416SJim Ingham         "The breakpoint stops only for the thread whose thread name matches this argument."},
7815a988416SJim Ingham 
7829e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
783eb023e75SGreg Clayton         "Require the breakpoint to use hardware breakpoints."},
784eb023e75SGreg Clayton 
7859e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName,
7865a988416SJim Ingham         "The breakpoint stops only for threads in the queue whose name is given by this argument."},
7875a988416SJim Ingham 
7889e85e5a8SEugene Zelenko     { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
789289aca64SJim Ingham         "Specifies the source file in which to set this breakpoint.  "
790289aca64SJim Ingham         "Note, by default lldb only looks for files that are #included if they use the standard include file extensions.  "
7916394479eSJim Ingham         "To set breakpoints on .c/.cpp/.m/.mm files that are #included, set target.inline-breakpoint-strategy"
792289aca64SJim Ingham         " to \"always\"."},
7935a988416SJim Ingham 
7949e85e5a8SEugene Zelenko     { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum,
7955a988416SJim Ingham         "Specifies the line number on which to set this breakpoint."},
7965a988416SJim Ingham 
7975a988416SJim Ingham     // Comment out this option for the moment, as we don't actually use it, but will in the future.
7985a988416SJim Ingham     // This way users won't see it, but the infrastructure is left in place.
7999e85e5a8SEugene Zelenko     //    { 0, false, "column",     'C', OptionParser::eRequiredArgument, nullptr, "<column>",
8005a988416SJim Ingham     //    "Set the breakpoint by source location at this particular column."},
8015a988416SJim Ingham 
8029e85e5a8SEugene Zelenko     { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression,
803055a08a4SJim Ingham         "Set the breakpoint at the specified address.  "
804055a08a4SJim Ingham         "If the address maps uniquely to a particular "
805055a08a4SJim Ingham         "binary, then the address will be converted to a \"file\" address, so that the breakpoint will track that binary+offset no matter where "
806055a08a4SJim Ingham         "the binary eventually loads.  "
807055a08a4SJim Ingham         "Alternately, if you also specify the module - with the -s option - then the address will be treated as "
808055a08a4SJim Ingham         "a file address in that module, and resolved accordingly.  Again, this will allow lldb to track that offset on "
809055a08a4SJim Ingham         "subsequent reloads.  The module need not have been loaded at the time you specify this breakpoint, and will "
810055a08a4SJim Ingham         "get resolved when the module is loaded."},
8115a988416SJim Ingham 
8129e85e5a8SEugene Zelenko     { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
813551262d7SJim Ingham         "Set the breakpoint by function name.  Can be repeated multiple times to make one breakpoint for multiple names" },
8145a988416SJim Ingham 
81576bb8d67SJim Ingham     { LLDB_OPT_SET_9, false, "source-regexp-function", 'X', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
81676bb8d67SJim Ingham         "When used with '-p' limits the source regex to source contained in the named functions.  Can be repeated multiple times." },
81776bb8d67SJim Ingham 
8189e85e5a8SEugene Zelenko     { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
8195a988416SJim Ingham         "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and "
8205a988416SJim Ingham         "for Objective C this means a full function prototype with class and selector.  "
8215a988416SJim Ingham         "Can be repeated multiple times to make one breakpoint for multiple names." },
8225a988416SJim Ingham 
8239e85e5a8SEugene Zelenko     { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSelector,
8245a988416SJim Ingham         "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." },
8255a988416SJim Ingham 
8269e85e5a8SEugene Zelenko     { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeMethod,
8275a988416SJim Ingham         "Set the breakpoint by C++ method names.  Can be repeated multiple times to make one breakpoint for multiple methods." },
8285a988416SJim Ingham 
8299e85e5a8SEugene Zelenko     { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression,
8305a988416SJim Ingham         "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
8315a988416SJim Ingham 
8329e85e5a8SEugene Zelenko     { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
8335a988416SJim Ingham         "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). "
8345a988416SJim Ingham         "Can be repeated multiple times to make one breakpoint for multiple symbols." },
8355a988416SJim Ingham 
8369e85e5a8SEugene Zelenko     { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression,
837e96ade8bSJim Ingham         "Set the breakpoint by specifying a regular expression which is matched against the source text in a source file or files "
838e96ade8bSJim Ingham         "specified with the -f option.  The -f option can be specified more than once.  "
839cc3a4595SJim Ingham         "If no source files are specified, uses the current \"default source file\".  "
840cc3a4595SJim Ingham         "If you want to match against all source files, pass the \"--all-files\" option." },
8415a988416SJim Ingham 
8429e85e5a8SEugene Zelenko     { LLDB_OPT_SET_9, false, "all-files", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
843e732052fSJim Ingham         "All files are searched for source pattern matches." },
844e732052fSJim Ingham 
8459e85e5a8SEugene Zelenko     { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage,
8465a988416SJim Ingham         "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" },
8475a988416SJim Ingham 
8489e85e5a8SEugene Zelenko     { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
849b4a5aa23SJim Ingham         "Set the breakpoint on exception throW." },
8505a988416SJim Ingham 
8519e85e5a8SEugene Zelenko     { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
852b4a5aa23SJim Ingham         "Set the breakpoint on exception catcH." },
8535a988416SJim Ingham 
854a72b31c7SJim Ingham //  Don't add this option till it actually does something useful...
8559e85e5a8SEugene Zelenko //    { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName,
856a72b31c7SJim 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" },
857a72b31c7SJim Ingham 
8589e85e5a8SEugene Zelenko     { LLDB_OPT_EXPR_LANGUAGE, false, "language", 'L', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage,
8594112ab98SDawn Perchik         "Specifies the Language to use when interpreting the breakpoint's expression (note: currently only implemented for setting breakpoints on identifiers).  If not set the target.language setting is used." },
86023b1decbSDawn Perchik 
8619e85e5a8SEugene Zelenko     { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
8625a988416SJim Ingham         "sKip the prologue if the breakpoint is at the beginning of a function.  If not set the target.skip-prologue setting is used." },
8635a988416SJim Ingham 
8649e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
86533df7cd3SJim Ingham         "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
86633df7cd3SJim Ingham 
8679e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName,
86876bb8d67SJim Ingham         "Adds this to the list of names for this breakpoint."},
8695e09c8c3SJim Ingham 
8702411167fSJim Ingham     { LLDB_OPT_OFFSET_APPLIES, false, "address-slide", 'R', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddress,
8712411167fSJim Ingham         "Add the specified offset to whatever address(es) the breakpoint resolves to.  "
8722411167fSJim Ingham         "At present this applies the offset directly as given, and doesn't try to align it to instruction boundaries."},
8732411167fSJim Ingham 
8749e85e5a8SEugene Zelenko     { LLDB_OPT_MOVE_TO_NEAREST_CODE, false, "move-to-nearest-code", 'm', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
875055ad9beSIlia K         "Move breakpoints to nearest code. If not set the target.move-to-nearest-code setting is used." },
876055ad9beSIlia K 
8779e85e5a8SEugene Zelenko     { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
8785a988416SJim Ingham };
8795a988416SJim Ingham 
8805a988416SJim Ingham //-------------------------------------------------------------------------
8815a988416SJim Ingham // CommandObjectBreakpointModify
8825a988416SJim Ingham //-------------------------------------------------------------------------
8835a988416SJim Ingham #pragma mark Modify
8845a988416SJim Ingham 
8855a988416SJim Ingham class CommandObjectBreakpointModify : public CommandObjectParsed
8865a988416SJim Ingham {
8875a988416SJim Ingham public:
8885a988416SJim Ingham     CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
8895a988416SJim Ingham         CommandObjectParsed(interpreter,
8905a988416SJim Ingham                             "breakpoint modify",
8915a988416SJim Ingham                             "Modify the options on a breakpoint or set of breakpoints in the executable.  "
8925a988416SJim Ingham                             "If no breakpoint is specified, acts on the last created breakpoint.  "
8935a988416SJim Ingham                             "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
8949e85e5a8SEugene Zelenko                             nullptr),
8955a988416SJim Ingham         m_options (interpreter)
8965a988416SJim Ingham     {
8975a988416SJim Ingham         CommandArgumentEntry arg;
8985a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
8995a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
9005a988416SJim Ingham         m_arguments.push_back (arg);
9015a988416SJim Ingham     }
9025a988416SJim Ingham 
9039e85e5a8SEugene Zelenko     ~CommandObjectBreakpointModify() override = default;
9045a988416SJim Ingham 
90513d21e9aSBruce Mitchener     Options *
90613d21e9aSBruce Mitchener     GetOptions () override
9075a988416SJim Ingham     {
9085a988416SJim Ingham         return &m_options;
9095a988416SJim Ingham     }
9105a988416SJim Ingham 
9115a988416SJim Ingham     class CommandOptions : public Options
9125a988416SJim Ingham     {
9135a988416SJim Ingham     public:
9145a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
9155a988416SJim Ingham             Options (interpreter),
9165a988416SJim Ingham             m_ignore_count (0),
9175a988416SJim Ingham             m_thread_id(LLDB_INVALID_THREAD_ID),
9185a988416SJim Ingham             m_thread_id_passed(false),
9195a988416SJim Ingham             m_thread_index (UINT32_MAX),
9205a988416SJim Ingham             m_thread_index_passed(false),
9215a988416SJim Ingham             m_thread_name(),
9225a988416SJim Ingham             m_queue_name(),
9235a988416SJim Ingham             m_condition (),
924ca36cd16SJim Ingham             m_one_shot (false),
9255a988416SJim Ingham             m_enable_passed (false),
9265a988416SJim Ingham             m_enable_value (false),
9275a988416SJim Ingham             m_name_passed (false),
9285a988416SJim Ingham             m_queue_passed (false),
929ca36cd16SJim Ingham             m_condition_passed (false),
93033df7cd3SJim Ingham             m_one_shot_passed (false),
93133df7cd3SJim Ingham             m_use_dummy (false)
9325a988416SJim Ingham         {
9335a988416SJim Ingham         }
9345a988416SJim Ingham 
9359e85e5a8SEugene Zelenko         ~CommandOptions() override = default;
9365a988416SJim Ingham 
93713d21e9aSBruce Mitchener         Error
93813d21e9aSBruce Mitchener         SetOptionValue (uint32_t option_idx, const char *option_arg) override
9395a988416SJim Ingham         {
9405a988416SJim Ingham             Error error;
9413bcdfc0eSGreg Clayton             const int short_option = m_getopt_table[option_idx].val;
9425a988416SJim Ingham 
9435a988416SJim Ingham             switch (short_option)
9445a988416SJim Ingham             {
9455a988416SJim Ingham                 case 'c':
9469e85e5a8SEugene Zelenko                     if (option_arg != nullptr)
9475a988416SJim Ingham                         m_condition.assign (option_arg);
9485a988416SJim Ingham                     else
9495a988416SJim Ingham                         m_condition.clear();
9505a988416SJim Ingham                     m_condition_passed = true;
9515a988416SJim Ingham                     break;
9525a988416SJim Ingham                 case 'd':
9535a988416SJim Ingham                     m_enable_passed = true;
9545a988416SJim Ingham                     m_enable_value = false;
9555a988416SJim Ingham                     break;
95633df7cd3SJim Ingham                 case 'D':
95733df7cd3SJim Ingham                     m_use_dummy = true;
95833df7cd3SJim Ingham                     break;
9595a988416SJim Ingham                 case 'e':
9605a988416SJim Ingham                     m_enable_passed = true;
9615a988416SJim Ingham                     m_enable_value = true;
9625a988416SJim Ingham                     break;
9635a988416SJim Ingham                 case 'i':
9645275aaa0SVince Harron                     m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
9655a988416SJim Ingham                     if (m_ignore_count == UINT32_MAX)
9665a988416SJim Ingham                        error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
9675a988416SJim Ingham                     break;
968ca36cd16SJim Ingham                 case 'o':
969ca36cd16SJim Ingham                 {
970ca36cd16SJim Ingham                     bool value, success;
971ca36cd16SJim Ingham                     value = Args::StringToBoolean(option_arg, false, &success);
972ca36cd16SJim Ingham                     if (success)
973ca36cd16SJim Ingham                     {
974ca36cd16SJim Ingham                         m_one_shot_passed = true;
975ca36cd16SJim Ingham                         m_one_shot = value;
976ca36cd16SJim Ingham                     }
977ca36cd16SJim Ingham                     else
978ca36cd16SJim Ingham                         error.SetErrorStringWithFormat("invalid boolean value '%s' passed for -o option", option_arg);
979ca36cd16SJim Ingham                 }
980ca36cd16SJim Ingham                 break;
9815a988416SJim Ingham                 case 't' :
9825a988416SJim Ingham                     if (option_arg[0] == '\0')
9835a988416SJim Ingham                     {
9845a988416SJim Ingham                         m_thread_id = LLDB_INVALID_THREAD_ID;
9855a988416SJim Ingham                         m_thread_id_passed = true;
9865a988416SJim Ingham                     }
9875a988416SJim Ingham                     else
9885a988416SJim Ingham                     {
9895275aaa0SVince Harron                         m_thread_id = StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
9905a988416SJim Ingham                         if (m_thread_id == LLDB_INVALID_THREAD_ID)
9915a988416SJim Ingham                            error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
9925a988416SJim Ingham                         else
9935a988416SJim Ingham                             m_thread_id_passed = true;
9945a988416SJim Ingham                     }
9955a988416SJim Ingham                     break;
9965a988416SJim Ingham                 case 'T':
9979e85e5a8SEugene Zelenko                     if (option_arg != nullptr)
9985a988416SJim Ingham                         m_thread_name.assign (option_arg);
9995a988416SJim Ingham                     else
10005a988416SJim Ingham                         m_thread_name.clear();
10015a988416SJim Ingham                     m_name_passed = true;
10025a988416SJim Ingham                     break;
10035a988416SJim Ingham                 case 'q':
10049e85e5a8SEugene Zelenko                     if (option_arg != nullptr)
10055a988416SJim Ingham                         m_queue_name.assign (option_arg);
10065a988416SJim Ingham                     else
10075a988416SJim Ingham                         m_queue_name.clear();
10085a988416SJim Ingham                     m_queue_passed = true;
10095a988416SJim Ingham                     break;
10105a988416SJim Ingham                 case 'x':
10115a988416SJim Ingham                     if (option_arg[0] == '\n')
10125a988416SJim Ingham                     {
10135a988416SJim Ingham                         m_thread_index = UINT32_MAX;
10145a988416SJim Ingham                         m_thread_index_passed = true;
10155a988416SJim Ingham                     }
10165a988416SJim Ingham                     else
10175a988416SJim Ingham                     {
10185275aaa0SVince Harron                         m_thread_index = StringConvert::ToUInt32 (option_arg, UINT32_MAX, 0);
10195a988416SJim Ingham                         if (m_thread_id == UINT32_MAX)
10205a988416SJim Ingham                            error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
10215a988416SJim Ingham                         else
10225a988416SJim Ingham                             m_thread_index_passed = true;
10235a988416SJim Ingham                     }
10245a988416SJim Ingham                     break;
10255a988416SJim Ingham                 default:
10265a988416SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
10275a988416SJim Ingham                     break;
10285a988416SJim Ingham             }
10295a988416SJim Ingham 
10305a988416SJim Ingham             return error;
10315a988416SJim Ingham         }
10329e85e5a8SEugene Zelenko 
10335a988416SJim Ingham         void
103413d21e9aSBruce Mitchener         OptionParsingStarting () override
10355a988416SJim Ingham         {
10365a988416SJim Ingham             m_ignore_count = 0;
10375a988416SJim Ingham             m_thread_id = LLDB_INVALID_THREAD_ID;
10385a988416SJim Ingham             m_thread_id_passed = false;
10395a988416SJim Ingham             m_thread_index = UINT32_MAX;
10405a988416SJim Ingham             m_thread_index_passed = false;
10415a988416SJim Ingham             m_thread_name.clear();
10425a988416SJim Ingham             m_queue_name.clear();
10435a988416SJim Ingham             m_condition.clear();
1044ca36cd16SJim Ingham             m_one_shot = false;
10455a988416SJim Ingham             m_enable_passed = false;
10465a988416SJim Ingham             m_queue_passed = false;
10475a988416SJim Ingham             m_name_passed = false;
10485a988416SJim Ingham             m_condition_passed = false;
1049ca36cd16SJim Ingham             m_one_shot_passed = false;
105033df7cd3SJim Ingham             m_use_dummy = false;
10515a988416SJim Ingham         }
10525a988416SJim Ingham 
10535a988416SJim Ingham         const OptionDefinition*
105413d21e9aSBruce Mitchener         GetDefinitions () override
10555a988416SJim Ingham         {
10565a988416SJim Ingham             return g_option_table;
10575a988416SJim Ingham         }
10585a988416SJim Ingham 
10595a988416SJim Ingham         // Options table: Required for subclasses of Options.
10605a988416SJim Ingham 
10615a988416SJim Ingham         static OptionDefinition g_option_table[];
10625a988416SJim Ingham 
10635a988416SJim Ingham         // Instance variables to hold the values for command options.
10645a988416SJim Ingham 
10655a988416SJim Ingham         uint32_t m_ignore_count;
10665a988416SJim Ingham         lldb::tid_t m_thread_id;
10675a988416SJim Ingham         bool m_thread_id_passed;
10685a988416SJim Ingham         uint32_t m_thread_index;
10695a988416SJim Ingham         bool m_thread_index_passed;
10705a988416SJim Ingham         std::string m_thread_name;
10715a988416SJim Ingham         std::string m_queue_name;
10725a988416SJim Ingham         std::string m_condition;
1073ca36cd16SJim Ingham         bool m_one_shot;
10745a988416SJim Ingham         bool m_enable_passed;
10755a988416SJim Ingham         bool m_enable_value;
10765a988416SJim Ingham         bool m_name_passed;
10775a988416SJim Ingham         bool m_queue_passed;
10785a988416SJim Ingham         bool m_condition_passed;
1079ca36cd16SJim Ingham         bool m_one_shot_passed;
108033df7cd3SJim Ingham         bool m_use_dummy;
10815a988416SJim Ingham     };
10825a988416SJim Ingham 
10835a988416SJim Ingham protected:
108413d21e9aSBruce Mitchener     bool
108513d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
10865a988416SJim Ingham     {
108733df7cd3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
10889e85e5a8SEugene Zelenko         if (target == nullptr)
10895a988416SJim Ingham         {
10905a988416SJim Ingham             result.AppendError ("Invalid target.  No existing target or breakpoints.");
10915a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
10925a988416SJim Ingham             return false;
10935a988416SJim Ingham         }
10945a988416SJim Ingham 
1095*bb19a13cSSaleem Abdulrasool         std::unique_lock<std::recursive_mutex> lock;
1096*bb19a13cSSaleem Abdulrasool         target->GetBreakpointList().GetListMutex(lock);
10975a988416SJim Ingham 
10985a988416SJim Ingham         BreakpointIDList valid_bp_ids;
10995a988416SJim Ingham 
11005e09c8c3SJim Ingham         CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
11015a988416SJim Ingham 
11025a988416SJim Ingham         if (result.Succeeded())
11035a988416SJim Ingham         {
11045a988416SJim Ingham             const size_t count = valid_bp_ids.GetSize();
11055a988416SJim Ingham             for (size_t i = 0; i < count; ++i)
11065a988416SJim Ingham             {
11075a988416SJim Ingham                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
11085a988416SJim Ingham 
11095a988416SJim Ingham                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
11105a988416SJim Ingham                 {
11115a988416SJim Ingham                     Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
11125a988416SJim Ingham                     if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
11135a988416SJim Ingham                     {
11145a988416SJim Ingham                         BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
11155a988416SJim Ingham                         if (location)
11165a988416SJim Ingham                         {
11175a988416SJim Ingham                             if (m_options.m_thread_id_passed)
11185a988416SJim Ingham                                 location->SetThreadID (m_options.m_thread_id);
11195a988416SJim Ingham 
11205a988416SJim Ingham                             if (m_options.m_thread_index_passed)
11215a988416SJim Ingham                                 location->SetThreadIndex(m_options.m_thread_index);
11225a988416SJim Ingham 
11235a988416SJim Ingham                             if (m_options.m_name_passed)
11245a988416SJim Ingham                                 location->SetThreadName(m_options.m_thread_name.c_str());
11255a988416SJim Ingham 
11265a988416SJim Ingham                             if (m_options.m_queue_passed)
11275a988416SJim Ingham                                 location->SetQueueName(m_options.m_queue_name.c_str());
11285a988416SJim Ingham 
11295a988416SJim Ingham                             if (m_options.m_ignore_count != 0)
11305a988416SJim Ingham                                 location->SetIgnoreCount(m_options.m_ignore_count);
11315a988416SJim Ingham 
11325a988416SJim Ingham                             if (m_options.m_enable_passed)
11335a988416SJim Ingham                                 location->SetEnabled (m_options.m_enable_value);
11345a988416SJim Ingham 
11355a988416SJim Ingham                             if (m_options.m_condition_passed)
11365a988416SJim Ingham                                 location->SetCondition (m_options.m_condition.c_str());
11375a988416SJim Ingham                         }
11385a988416SJim Ingham                     }
11395a988416SJim Ingham                     else
11405a988416SJim Ingham                     {
11415a988416SJim Ingham                         if (m_options.m_thread_id_passed)
11425a988416SJim Ingham                             bp->SetThreadID (m_options.m_thread_id);
11435a988416SJim Ingham 
11445a988416SJim Ingham                         if (m_options.m_thread_index_passed)
11455a988416SJim Ingham                             bp->SetThreadIndex(m_options.m_thread_index);
11465a988416SJim Ingham 
11475a988416SJim Ingham                         if (m_options.m_name_passed)
11485a988416SJim Ingham                             bp->SetThreadName(m_options.m_thread_name.c_str());
11495a988416SJim Ingham 
11505a988416SJim Ingham                         if (m_options.m_queue_passed)
11515a988416SJim Ingham                             bp->SetQueueName(m_options.m_queue_name.c_str());
11525a988416SJim Ingham 
11535a988416SJim Ingham                         if (m_options.m_ignore_count != 0)
11545a988416SJim Ingham                             bp->SetIgnoreCount(m_options.m_ignore_count);
11555a988416SJim Ingham 
11565a988416SJim Ingham                         if (m_options.m_enable_passed)
11575a988416SJim Ingham                             bp->SetEnabled (m_options.m_enable_value);
11585a988416SJim Ingham 
11595a988416SJim Ingham                         if (m_options.m_condition_passed)
11605a988416SJim Ingham                             bp->SetCondition (m_options.m_condition.c_str());
11615a988416SJim Ingham                     }
11625a988416SJim Ingham                 }
11635a988416SJim Ingham             }
11645a988416SJim Ingham         }
11655a988416SJim Ingham 
11665a988416SJim Ingham         return result.Succeeded();
11675a988416SJim Ingham     }
11685a988416SJim Ingham 
11695a988416SJim Ingham private:
11705a988416SJim Ingham     CommandOptions m_options;
11715a988416SJim Ingham };
11725a988416SJim Ingham 
11735a988416SJim Ingham #pragma mark Modify::CommandOptions
11745a988416SJim Ingham OptionDefinition
11755a988416SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
11765a988416SJim Ingham {
11779e85e5a8SEugene 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." },
11789e85e5a8SEugene 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." },
11799e85e5a8SEugene 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."},
11809e85e5a8SEugene 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."},
11819e85e5a8SEugene 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."},
11829e85e5a8SEugene 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."},
11839e85e5a8SEugene 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."},
11849e85e5a8SEugene Zelenko { LLDB_OPT_SET_1,   false, "enable",       'e', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone, "Enable the breakpoint."},
11859e85e5a8SEugene Zelenko { LLDB_OPT_SET_2,   false, "disable",      'd', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone, "Disable the breakpoint."},
11869e85e5a8SEugene 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."},
118733df7cd3SJim Ingham 
11889e85e5a8SEugene Zelenko { 0,                false, nullptr,            0 , 0,                 nullptr, nullptr, 0, eArgTypeNone, nullptr }
11895a988416SJim Ingham };
11905a988416SJim Ingham 
11915a988416SJim Ingham //-------------------------------------------------------------------------
11925a988416SJim Ingham // CommandObjectBreakpointEnable
11935a988416SJim Ingham //-------------------------------------------------------------------------
11945a988416SJim Ingham #pragma mark Enable
11955a988416SJim Ingham 
11965a988416SJim Ingham class CommandObjectBreakpointEnable : public CommandObjectParsed
11975a988416SJim Ingham {
11985a988416SJim Ingham public:
11995a988416SJim Ingham     CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
12005a988416SJim Ingham         CommandObjectParsed(interpreter,
12015a988416SJim Ingham                             "enable",
12025a988416SJim Ingham                             "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
12039e85e5a8SEugene Zelenko                             nullptr)
12045a988416SJim Ingham     {
12055a988416SJim Ingham         CommandArgumentEntry arg;
12065a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
12075a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
12085a988416SJim Ingham         m_arguments.push_back (arg);
12095a988416SJim Ingham     }
12105a988416SJim Ingham 
12119e85e5a8SEugene Zelenko     ~CommandObjectBreakpointEnable() override = default;
12125a988416SJim Ingham 
12135a988416SJim Ingham protected:
121413d21e9aSBruce Mitchener     bool
121513d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
12165a988416SJim Ingham     {
1217893c932aSJim Ingham         Target *target = GetSelectedOrDummyTarget();
12189e85e5a8SEugene Zelenko         if (target == nullptr)
12195a988416SJim Ingham         {
12205a988416SJim Ingham             result.AppendError ("Invalid target.  No existing target or breakpoints.");
12215a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
12225a988416SJim Ingham             return false;
12235a988416SJim Ingham         }
12245a988416SJim Ingham 
1225*bb19a13cSSaleem Abdulrasool         std::unique_lock<std::recursive_mutex> lock;
1226*bb19a13cSSaleem Abdulrasool         target->GetBreakpointList().GetListMutex(lock);
12275a988416SJim Ingham 
12285a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
12295a988416SJim Ingham 
12305a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
12315a988416SJim Ingham 
12325a988416SJim Ingham         if (num_breakpoints == 0)
12335a988416SJim Ingham         {
12345a988416SJim Ingham             result.AppendError ("No breakpoints exist to be enabled.");
12355a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
12365a988416SJim Ingham             return false;
12375a988416SJim Ingham         }
12385a988416SJim Ingham 
12395a988416SJim Ingham         if (command.GetArgumentCount() == 0)
12405a988416SJim Ingham         {
12415a988416SJim Ingham             // No breakpoint selected; enable all currently set breakpoints.
12425a988416SJim Ingham             target->EnableAllBreakpoints ();
12436fea17e8SGreg Clayton             result.AppendMessageWithFormat ("All breakpoints enabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints);
12445a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
12455a988416SJim Ingham         }
12465a988416SJim Ingham         else
12475a988416SJim Ingham         {
12485a988416SJim Ingham             // Particular breakpoint selected; enable that breakpoint.
12495a988416SJim Ingham             BreakpointIDList valid_bp_ids;
12505e09c8c3SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
12515a988416SJim Ingham 
12525a988416SJim Ingham             if (result.Succeeded())
12535a988416SJim Ingham             {
12545a988416SJim Ingham                 int enable_count = 0;
12555a988416SJim Ingham                 int loc_count = 0;
12565a988416SJim Ingham                 const size_t count = valid_bp_ids.GetSize();
12575a988416SJim Ingham                 for (size_t i = 0; i < count; ++i)
12585a988416SJim Ingham                 {
12595a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
12605a988416SJim Ingham 
12615a988416SJim Ingham                     if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
12625a988416SJim Ingham                     {
12635a988416SJim Ingham                         Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
12645a988416SJim Ingham                         if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
12655a988416SJim Ingham                         {
12665a988416SJim Ingham                             BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
12675a988416SJim Ingham                             if (location)
12685a988416SJim Ingham                             {
12695a988416SJim Ingham                                 location->SetEnabled (true);
12705a988416SJim Ingham                                 ++loc_count;
12715a988416SJim Ingham                             }
12725a988416SJim Ingham                         }
12735a988416SJim Ingham                         else
12745a988416SJim Ingham                         {
12755a988416SJim Ingham                             breakpoint->SetEnabled (true);
12765a988416SJim Ingham                             ++enable_count;
12775a988416SJim Ingham                         }
12785a988416SJim Ingham                     }
12795a988416SJim Ingham                 }
12805a988416SJim Ingham                 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
12815a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
12825a988416SJim Ingham             }
12835a988416SJim Ingham         }
12845a988416SJim Ingham 
12855a988416SJim Ingham         return result.Succeeded();
12865a988416SJim Ingham     }
12875a988416SJim Ingham };
12885a988416SJim Ingham 
12895a988416SJim Ingham //-------------------------------------------------------------------------
12905a988416SJim Ingham // CommandObjectBreakpointDisable
12915a988416SJim Ingham //-------------------------------------------------------------------------
12925a988416SJim Ingham #pragma mark Disable
12935a988416SJim Ingham 
12945a988416SJim Ingham class CommandObjectBreakpointDisable : public CommandObjectParsed
12955a988416SJim Ingham {
12965a988416SJim Ingham public:
12975a988416SJim Ingham     CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
12985a988416SJim Ingham         CommandObjectParsed(interpreter,
12995a988416SJim Ingham                             "breakpoint disable",
1300ea671fbdSKate Stone                             "Disable the specified breakpoint(s) without removing them.  If none are specified, disable all breakpoints.",
13019e85e5a8SEugene Zelenko                             nullptr)
13025a988416SJim Ingham     {
1303b0fac509SJim Ingham         SetHelpLong(
1304ea671fbdSKate Stone "Disable the specified breakpoint(s) without removing them.  \
1305ea671fbdSKate Stone If none are specified, disable all breakpoints." R"(
1306ea671fbdSKate Stone 
1307ea671fbdSKate Stone )" "Note: disabling a breakpoint will cause none of its locations to be hit \
1308ea671fbdSKate Stone regardless of whether they are enabled or disabled.  After the sequence:" R"(
1309ea671fbdSKate Stone 
1310ea671fbdSKate Stone     (lldb) break disable 1
1311ea671fbdSKate Stone     (lldb) break enable 1.1
1312ea671fbdSKate Stone 
1313ea671fbdSKate Stone execution will NOT stop at location 1.1.  To achieve that, type:
1314ea671fbdSKate Stone 
1315ea671fbdSKate Stone     (lldb) break disable 1.*
1316ea671fbdSKate Stone     (lldb) break enable 1.1
1317ea671fbdSKate Stone 
1318ea671fbdSKate Stone )" "The first command disables all the locations of breakpoint 1, \
1319b0fac509SJim Ingham the second re-enables the first location."
1320b0fac509SJim Ingham         );
1321b0fac509SJim Ingham 
13225a988416SJim Ingham         CommandArgumentEntry arg;
13235a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
13245a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
13255a988416SJim Ingham         m_arguments.push_back (arg);
13265a988416SJim Ingham     }
13275a988416SJim Ingham 
13289e85e5a8SEugene Zelenko     ~CommandObjectBreakpointDisable() override = default;
13295a988416SJim Ingham 
13305a988416SJim Ingham protected:
133113d21e9aSBruce Mitchener     bool
133213d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
13335a988416SJim Ingham     {
1334893c932aSJim Ingham         Target *target = GetSelectedOrDummyTarget();
13359e85e5a8SEugene Zelenko         if (target == nullptr)
13365a988416SJim Ingham         {
13375a988416SJim Ingham             result.AppendError ("Invalid target.  No existing target or breakpoints.");
13385a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
13395a988416SJim Ingham             return false;
13405a988416SJim Ingham         }
13415a988416SJim Ingham 
1342*bb19a13cSSaleem Abdulrasool         std::unique_lock<std::recursive_mutex> lock;
1343*bb19a13cSSaleem Abdulrasool         target->GetBreakpointList().GetListMutex(lock);
13445a988416SJim Ingham 
13455a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
13465a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
13475a988416SJim Ingham 
13485a988416SJim Ingham         if (num_breakpoints == 0)
13495a988416SJim Ingham         {
13505a988416SJim Ingham             result.AppendError ("No breakpoints exist to be disabled.");
13515a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
13525a988416SJim Ingham             return false;
13535a988416SJim Ingham         }
13545a988416SJim Ingham 
13555a988416SJim Ingham         if (command.GetArgumentCount() == 0)
13565a988416SJim Ingham         {
13575a988416SJim Ingham             // No breakpoint selected; disable all currently set breakpoints.
13585a988416SJim Ingham             target->DisableAllBreakpoints ();
13596fea17e8SGreg Clayton             result.AppendMessageWithFormat ("All breakpoints disabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints);
13605a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
13615a988416SJim Ingham         }
13625a988416SJim Ingham         else
13635a988416SJim Ingham         {
13645a988416SJim Ingham             // Particular breakpoint selected; disable that breakpoint.
13655a988416SJim Ingham             BreakpointIDList valid_bp_ids;
13665a988416SJim Ingham 
13675e09c8c3SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
13685a988416SJim Ingham 
13695a988416SJim Ingham             if (result.Succeeded())
13705a988416SJim Ingham             {
13715a988416SJim Ingham                 int disable_count = 0;
13725a988416SJim Ingham                 int loc_count = 0;
13735a988416SJim Ingham                 const size_t count = valid_bp_ids.GetSize();
13745a988416SJim Ingham                 for (size_t i = 0; i < count; ++i)
13755a988416SJim Ingham                 {
13765a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
13775a988416SJim Ingham 
13785a988416SJim Ingham                     if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
13795a988416SJim Ingham                     {
13805a988416SJim Ingham                         Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
13815a988416SJim Ingham                         if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
13825a988416SJim Ingham                         {
13835a988416SJim Ingham                             BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
13845a988416SJim Ingham                             if (location)
13855a988416SJim Ingham                             {
13865a988416SJim Ingham                                 location->SetEnabled (false);
13875a988416SJim Ingham                                 ++loc_count;
13885a988416SJim Ingham                             }
13895a988416SJim Ingham                         }
13905a988416SJim Ingham                         else
13915a988416SJim Ingham                         {
13925a988416SJim Ingham                             breakpoint->SetEnabled (false);
13935a988416SJim Ingham                             ++disable_count;
13945a988416SJim Ingham                         }
13955a988416SJim Ingham                     }
13965a988416SJim Ingham                 }
13975a988416SJim Ingham                 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
13985a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
13995a988416SJim Ingham             }
14005a988416SJim Ingham         }
14015a988416SJim Ingham 
14025a988416SJim Ingham         return result.Succeeded();
14035a988416SJim Ingham     }
14045a988416SJim Ingham };
14055a988416SJim Ingham 
14065a988416SJim Ingham //-------------------------------------------------------------------------
14075a988416SJim Ingham // CommandObjectBreakpointList
14085a988416SJim Ingham //-------------------------------------------------------------------------
14095a988416SJim Ingham #pragma mark List
14105a988416SJim Ingham 
14115a988416SJim Ingham class CommandObjectBreakpointList : public CommandObjectParsed
14125a988416SJim Ingham {
14135a988416SJim Ingham public:
14145a988416SJim Ingham     CommandObjectBreakpointList (CommandInterpreter &interpreter) :
14155a988416SJim Ingham         CommandObjectParsed(interpreter,
14165a988416SJim Ingham                             "breakpoint list",
14175a988416SJim Ingham                             "List some or all breakpoints at configurable levels of detail.",
14189e85e5a8SEugene Zelenko                             nullptr),
14195a988416SJim Ingham         m_options (interpreter)
14205a988416SJim Ingham     {
14215a988416SJim Ingham         CommandArgumentEntry arg;
14225a988416SJim Ingham         CommandArgumentData bp_id_arg;
14235a988416SJim Ingham 
14245a988416SJim Ingham         // Define the first (and only) variant of this arg.
14255a988416SJim Ingham         bp_id_arg.arg_type = eArgTypeBreakpointID;
14265a988416SJim Ingham         bp_id_arg.arg_repetition = eArgRepeatOptional;
14275a988416SJim Ingham 
14285a988416SJim Ingham         // There is only one variant this argument could be; put it into the argument entry.
14295a988416SJim Ingham         arg.push_back (bp_id_arg);
14305a988416SJim Ingham 
14315a988416SJim Ingham         // Push the data for the first argument into the m_arguments vector.
14325a988416SJim Ingham         m_arguments.push_back (arg);
14335a988416SJim Ingham     }
14345a988416SJim Ingham 
14359e85e5a8SEugene Zelenko     ~CommandObjectBreakpointList() override = default;
14365a988416SJim Ingham 
143713d21e9aSBruce Mitchener     Options *
143813d21e9aSBruce Mitchener     GetOptions () override
14395a988416SJim Ingham     {
14405a988416SJim Ingham         return &m_options;
14415a988416SJim Ingham     }
14425a988416SJim Ingham 
14435a988416SJim Ingham     class CommandOptions : public Options
14445a988416SJim Ingham     {
14455a988416SJim Ingham     public:
14465a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
14475a988416SJim Ingham             Options (interpreter),
144833df7cd3SJim Ingham             m_level (lldb::eDescriptionLevelBrief),
144933df7cd3SJim Ingham             m_use_dummy(false)
14505a988416SJim Ingham         {
14515a988416SJim Ingham         }
14525a988416SJim Ingham 
14539e85e5a8SEugene Zelenko         ~CommandOptions() override = default;
14545a988416SJim Ingham 
145513d21e9aSBruce Mitchener         Error
145613d21e9aSBruce Mitchener         SetOptionValue (uint32_t option_idx, const char *option_arg) override
14575a988416SJim Ingham         {
14585a988416SJim Ingham             Error error;
14593bcdfc0eSGreg Clayton             const int short_option = m_getopt_table[option_idx].val;
14605a988416SJim Ingham 
14615a988416SJim Ingham             switch (short_option)
14625a988416SJim Ingham             {
14635a988416SJim Ingham                 case 'b':
14645a988416SJim Ingham                     m_level = lldb::eDescriptionLevelBrief;
14655a988416SJim Ingham                     break;
146633df7cd3SJim Ingham                 case 'D':
146733df7cd3SJim Ingham                     m_use_dummy = true;
146833df7cd3SJim Ingham                     break;
14695a988416SJim Ingham                 case 'f':
14705a988416SJim Ingham                     m_level = lldb::eDescriptionLevelFull;
14715a988416SJim Ingham                     break;
14725a988416SJim Ingham                 case 'v':
14735a988416SJim Ingham                     m_level = lldb::eDescriptionLevelVerbose;
14745a988416SJim Ingham                     break;
14755a988416SJim Ingham                 case 'i':
14765a988416SJim Ingham                     m_internal = true;
14775a988416SJim Ingham                     break;
14785a988416SJim Ingham                 default:
14795a988416SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
14805a988416SJim Ingham                     break;
14815a988416SJim Ingham             }
14825a988416SJim Ingham 
14835a988416SJim Ingham             return error;
14845a988416SJim Ingham         }
14855a988416SJim Ingham 
14865a988416SJim Ingham         void
148713d21e9aSBruce Mitchener         OptionParsingStarting () override
14885a988416SJim Ingham         {
14895a988416SJim Ingham             m_level = lldb::eDescriptionLevelFull;
14905a988416SJim Ingham             m_internal = false;
149133df7cd3SJim Ingham             m_use_dummy = false;
14925a988416SJim Ingham         }
14935a988416SJim Ingham 
14945a988416SJim Ingham         const OptionDefinition *
149513d21e9aSBruce Mitchener         GetDefinitions () override
14965a988416SJim Ingham         {
14975a988416SJim Ingham             return g_option_table;
14985a988416SJim Ingham         }
14995a988416SJim Ingham 
15005a988416SJim Ingham         // Options table: Required for subclasses of Options.
15015a988416SJim Ingham 
15025a988416SJim Ingham         static OptionDefinition g_option_table[];
15035a988416SJim Ingham 
15045a988416SJim Ingham         // Instance variables to hold the values for command options.
15055a988416SJim Ingham 
15065a988416SJim Ingham         lldb::DescriptionLevel m_level;
15075a988416SJim Ingham 
15085a988416SJim Ingham         bool m_internal;
150933df7cd3SJim Ingham         bool m_use_dummy;
15105a988416SJim Ingham     };
15115a988416SJim Ingham 
15125a988416SJim Ingham protected:
151313d21e9aSBruce Mitchener     bool
151413d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
15155a988416SJim Ingham     {
151633df7cd3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
151733df7cd3SJim Ingham 
15189e85e5a8SEugene Zelenko         if (target == nullptr)
15195a988416SJim Ingham         {
15205a988416SJim Ingham             result.AppendError ("Invalid target. No current target or breakpoints.");
15215a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
15225a988416SJim Ingham             return true;
15235a988416SJim Ingham         }
15245a988416SJim Ingham 
15255a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
1526*bb19a13cSSaleem Abdulrasool         std::unique_lock<std::recursive_mutex> lock;
1527*bb19a13cSSaleem Abdulrasool         target->GetBreakpointList(m_options.m_internal).GetListMutex(lock);
15285a988416SJim Ingham 
15295a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
15305a988416SJim Ingham 
15315a988416SJim Ingham         if (num_breakpoints == 0)
15325a988416SJim Ingham         {
15335a988416SJim Ingham             result.AppendMessage ("No breakpoints currently set.");
15345a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
15355a988416SJim Ingham             return true;
15365a988416SJim Ingham         }
15375a988416SJim Ingham 
15385a988416SJim Ingham         Stream &output_stream = result.GetOutputStream();
15395a988416SJim Ingham 
15405a988416SJim Ingham         if (command.GetArgumentCount() == 0)
15415a988416SJim Ingham         {
15425a988416SJim Ingham             // No breakpoint selected; show info about all currently set breakpoints.
15435a988416SJim Ingham             result.AppendMessage ("Current breakpoints:");
15445a988416SJim Ingham             for (size_t i = 0; i < num_breakpoints; ++i)
15455a988416SJim Ingham             {
15465a988416SJim Ingham                 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
15475a988416SJim Ingham                 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
15485a988416SJim Ingham             }
15495a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
15505a988416SJim Ingham         }
15515a988416SJim Ingham         else
15525a988416SJim Ingham         {
15535a988416SJim Ingham             // Particular breakpoints selected; show info about that breakpoint.
15545a988416SJim Ingham             BreakpointIDList valid_bp_ids;
15555e09c8c3SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
15565a988416SJim Ingham 
15575a988416SJim Ingham             if (result.Succeeded())
15585a988416SJim Ingham             {
15595a988416SJim Ingham                 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
15605a988416SJim Ingham                 {
15615a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
15625a988416SJim Ingham                     Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
15635a988416SJim Ingham                     AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
15645a988416SJim Ingham                 }
15655a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
15665a988416SJim Ingham             }
15675a988416SJim Ingham             else
15685a988416SJim Ingham             {
15695a988416SJim Ingham                 result.AppendError ("Invalid breakpoint id.");
15705a988416SJim Ingham                 result.SetStatus (eReturnStatusFailed);
15715a988416SJim Ingham             }
15725a988416SJim Ingham         }
15735a988416SJim Ingham 
15745a988416SJim Ingham         return result.Succeeded();
15755a988416SJim Ingham     }
15765a988416SJim Ingham 
15775a988416SJim Ingham private:
15785a988416SJim Ingham     CommandOptions m_options;
15795a988416SJim Ingham };
15805a988416SJim Ingham 
15815a988416SJim Ingham #pragma mark List::CommandOptions
15825a988416SJim Ingham OptionDefinition
15835a988416SJim Ingham CommandObjectBreakpointList::CommandOptions::g_option_table[] =
15845a988416SJim Ingham {
15859e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
15865a988416SJim Ingham         "Show debugger internal breakpoints" },
15875a988416SJim Ingham 
15889e85e5a8SEugene Zelenko     { LLDB_OPT_SET_1, false, "brief",    'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
15895a988416SJim Ingham         "Give a brief description of the breakpoint (no location info)."},
15905a988416SJim Ingham 
15915a988416SJim Ingham     // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
15925a988416SJim Ingham     // But I need to see it for now, and don't want to wait.
15939e85e5a8SEugene Zelenko     { LLDB_OPT_SET_2, false, "full",    'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
15945a988416SJim Ingham         "Give a full description of the breakpoint and its locations."},
15955a988416SJim Ingham 
15969e85e5a8SEugene Zelenko     { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
15975a988416SJim Ingham         "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
15985a988416SJim Ingham 
15999e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
160033df7cd3SJim Ingham         "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
160133df7cd3SJim Ingham 
16029e85e5a8SEugene Zelenko     { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
16035a988416SJim Ingham };
16045a988416SJim Ingham 
16055a988416SJim Ingham //-------------------------------------------------------------------------
16065a988416SJim Ingham // CommandObjectBreakpointClear
16075a988416SJim Ingham //-------------------------------------------------------------------------
16085a988416SJim Ingham #pragma mark Clear
16095a988416SJim Ingham 
16105a988416SJim Ingham class CommandObjectBreakpointClear : public CommandObjectParsed
16115a988416SJim Ingham {
16125a988416SJim Ingham public:
16135a988416SJim Ingham     typedef enum BreakpointClearType
16145a988416SJim Ingham     {
16155a988416SJim Ingham         eClearTypeInvalid,
16165a988416SJim Ingham         eClearTypeFileAndLine
16175a988416SJim Ingham     } BreakpointClearType;
16185a988416SJim Ingham 
16195a988416SJim Ingham     CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
16205a988416SJim Ingham         CommandObjectParsed (interpreter,
16215a988416SJim Ingham                              "breakpoint clear",
16225a988416SJim Ingham                              "Clears a breakpoint or set of breakpoints in the executable.",
16235a988416SJim Ingham                              "breakpoint clear <cmd-options>"),
16245a988416SJim Ingham         m_options (interpreter)
16255a988416SJim Ingham     {
16265a988416SJim Ingham     }
16275a988416SJim Ingham 
16289e85e5a8SEugene Zelenko     ~CommandObjectBreakpointClear() override = default;
16295a988416SJim Ingham 
163013d21e9aSBruce Mitchener     Options *
163113d21e9aSBruce Mitchener     GetOptions () override
16325a988416SJim Ingham     {
16335a988416SJim Ingham         return &m_options;
16345a988416SJim Ingham     }
16355a988416SJim Ingham 
16365a988416SJim Ingham     class CommandOptions : public Options
16375a988416SJim Ingham     {
16385a988416SJim Ingham     public:
16395a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
16405a988416SJim Ingham             Options (interpreter),
16415a988416SJim Ingham             m_filename (),
16425a988416SJim Ingham             m_line_num (0)
16435a988416SJim Ingham         {
16445a988416SJim Ingham         }
16455a988416SJim Ingham 
16469e85e5a8SEugene Zelenko         ~CommandOptions() override = default;
16475a988416SJim Ingham 
164813d21e9aSBruce Mitchener         Error
164913d21e9aSBruce Mitchener         SetOptionValue (uint32_t option_idx, const char *option_arg) override
16505a988416SJim Ingham         {
16515a988416SJim Ingham             Error error;
16523bcdfc0eSGreg Clayton             const int short_option = m_getopt_table[option_idx].val;
16535a988416SJim Ingham 
16545a988416SJim Ingham             switch (short_option)
16555a988416SJim Ingham             {
16565a988416SJim Ingham                 case 'f':
16575a988416SJim Ingham                     m_filename.assign (option_arg);
16585a988416SJim Ingham                     break;
16595a988416SJim Ingham 
16605a988416SJim Ingham                 case 'l':
16615275aaa0SVince Harron                     m_line_num = StringConvert::ToUInt32 (option_arg, 0);
16625a988416SJim Ingham                     break;
16635a988416SJim Ingham 
16645a988416SJim Ingham                 default:
16655a988416SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
16665a988416SJim Ingham                     break;
16675a988416SJim Ingham             }
16685a988416SJim Ingham 
16695a988416SJim Ingham             return error;
16705a988416SJim Ingham         }
16715a988416SJim Ingham 
16725a988416SJim Ingham         void
167313d21e9aSBruce Mitchener         OptionParsingStarting () override
16745a988416SJim Ingham         {
16755a988416SJim Ingham             m_filename.clear();
16765a988416SJim Ingham             m_line_num = 0;
16775a988416SJim Ingham         }
16785a988416SJim Ingham 
16795a988416SJim Ingham         const OptionDefinition*
168013d21e9aSBruce Mitchener         GetDefinitions () override
16815a988416SJim Ingham         {
16825a988416SJim Ingham             return g_option_table;
16835a988416SJim Ingham         }
16845a988416SJim Ingham 
16855a988416SJim Ingham         // Options table: Required for subclasses of Options.
16865a988416SJim Ingham 
16875a988416SJim Ingham         static OptionDefinition g_option_table[];
16885a988416SJim Ingham 
16895a988416SJim Ingham         // Instance variables to hold the values for command options.
16905a988416SJim Ingham 
16915a988416SJim Ingham         std::string m_filename;
16925a988416SJim Ingham         uint32_t m_line_num;
16935a988416SJim Ingham 
16945a988416SJim Ingham     };
16955a988416SJim Ingham 
16965a988416SJim Ingham protected:
169713d21e9aSBruce Mitchener     bool
169813d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
16995a988416SJim Ingham     {
1700893c932aSJim Ingham         Target *target = GetSelectedOrDummyTarget();
17019e85e5a8SEugene Zelenko         if (target == nullptr)
17025a988416SJim Ingham         {
17035a988416SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
17045a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
17055a988416SJim Ingham             return false;
17065a988416SJim Ingham         }
17075a988416SJim Ingham 
17085a988416SJim Ingham         // The following are the various types of breakpoints that could be cleared:
17095a988416SJim Ingham         //   1). -f -l (clearing breakpoint by source location)
17105a988416SJim Ingham 
17115a988416SJim Ingham         BreakpointClearType break_type = eClearTypeInvalid;
17125a988416SJim Ingham 
17135a988416SJim Ingham         if (m_options.m_line_num != 0)
17145a988416SJim Ingham             break_type = eClearTypeFileAndLine;
17155a988416SJim Ingham 
1716*bb19a13cSSaleem Abdulrasool         std::unique_lock<std::recursive_mutex> lock;
1717*bb19a13cSSaleem Abdulrasool         target->GetBreakpointList().GetListMutex(lock);
17185a988416SJim Ingham 
17195a988416SJim Ingham         BreakpointList &breakpoints = target->GetBreakpointList();
17205a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
17215a988416SJim Ingham 
17225a988416SJim Ingham         // Early return if there's no breakpoint at all.
17235a988416SJim Ingham         if (num_breakpoints == 0)
17245a988416SJim Ingham         {
17255a988416SJim Ingham             result.AppendError ("Breakpoint clear: No breakpoint cleared.");
17265a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
17275a988416SJim Ingham             return result.Succeeded();
17285a988416SJim Ingham         }
17295a988416SJim Ingham 
17305a988416SJim Ingham         // Find matching breakpoints and delete them.
17315a988416SJim Ingham 
17325a988416SJim Ingham         // First create a copy of all the IDs.
17335a988416SJim Ingham         std::vector<break_id_t> BreakIDs;
17345a988416SJim Ingham         for (size_t i = 0; i < num_breakpoints; ++i)
17359e85e5a8SEugene Zelenko             BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID());
17365a988416SJim Ingham 
17375a988416SJim Ingham         int num_cleared = 0;
17385a988416SJim Ingham         StreamString ss;
17395a988416SJim Ingham         switch (break_type)
17405a988416SJim Ingham         {
17415a988416SJim Ingham             case eClearTypeFileAndLine: // Breakpoint by source position
17425a988416SJim Ingham                 {
17435a988416SJim Ingham                     const ConstString filename(m_options.m_filename.c_str());
17445a988416SJim Ingham                     BreakpointLocationCollection loc_coll;
17455a988416SJim Ingham 
17465a988416SJim Ingham                     for (size_t i = 0; i < num_breakpoints; ++i)
17475a988416SJim Ingham                     {
17485a988416SJim Ingham                         Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
17495a988416SJim Ingham 
17505a988416SJim Ingham                         if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
17515a988416SJim Ingham                         {
17525a988416SJim Ingham                             // If the collection size is 0, it's a full match and we can just remove the breakpoint.
17535a988416SJim Ingham                             if (loc_coll.GetSize() == 0)
17545a988416SJim Ingham                             {
17555a988416SJim Ingham                                 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
17565a988416SJim Ingham                                 ss.EOL();
17575a988416SJim Ingham                                 target->RemoveBreakpointByID (bp->GetID());
17585a988416SJim Ingham                                 ++num_cleared;
17595a988416SJim Ingham                             }
17605a988416SJim Ingham                         }
17615a988416SJim Ingham                     }
17625a988416SJim Ingham                 }
17635a988416SJim Ingham                 break;
17645a988416SJim Ingham 
17655a988416SJim Ingham             default:
17665a988416SJim Ingham                 break;
17675a988416SJim Ingham         }
17685a988416SJim Ingham 
17695a988416SJim Ingham         if (num_cleared > 0)
17705a988416SJim Ingham         {
17715a988416SJim Ingham             Stream &output_stream = result.GetOutputStream();
17725a988416SJim Ingham             output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
17735a988416SJim Ingham             output_stream << ss.GetData();
17745a988416SJim Ingham             output_stream.EOL();
17755a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
17765a988416SJim Ingham         }
17775a988416SJim Ingham         else
17785a988416SJim Ingham         {
17795a988416SJim Ingham             result.AppendError ("Breakpoint clear: No breakpoint cleared.");
17805a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
17815a988416SJim Ingham         }
17825a988416SJim Ingham 
17835a988416SJim Ingham         return result.Succeeded();
17845a988416SJim Ingham     }
17855a988416SJim Ingham 
17865a988416SJim Ingham private:
17875a988416SJim Ingham     CommandOptions m_options;
17885a988416SJim Ingham };
17895a988416SJim Ingham 
17905a988416SJim Ingham #pragma mark Clear::CommandOptions
17915a988416SJim Ingham 
17925a988416SJim Ingham OptionDefinition
17935a988416SJim Ingham CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
17945a988416SJim Ingham {
17959e85e5a8SEugene Zelenko     { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
17965a988416SJim Ingham         "Specify the breakpoint by source location in this particular file."},
17975a988416SJim Ingham 
17989e85e5a8SEugene Zelenko     { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum,
17995a988416SJim Ingham         "Specify the breakpoint by source location at this particular line."},
18005a988416SJim Ingham 
18019e85e5a8SEugene Zelenko     { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
18025a988416SJim Ingham };
18035a988416SJim Ingham 
18045a988416SJim Ingham //-------------------------------------------------------------------------
18055a988416SJim Ingham // CommandObjectBreakpointDelete
18065a988416SJim Ingham //-------------------------------------------------------------------------
18075a988416SJim Ingham #pragma mark Delete
18085a988416SJim Ingham 
18095a988416SJim Ingham class CommandObjectBreakpointDelete : public CommandObjectParsed
18105a988416SJim Ingham {
18115a988416SJim Ingham public:
18125a988416SJim Ingham     CommandObjectBreakpointDelete (CommandInterpreter &interpreter) :
18135a988416SJim Ingham         CommandObjectParsed(interpreter,
18145a988416SJim Ingham                             "breakpoint delete",
18155a988416SJim Ingham                             "Delete the specified breakpoint(s).  If no breakpoints are specified, delete them all.",
18169e85e5a8SEugene Zelenko                             nullptr),
181733df7cd3SJim Ingham         m_options (interpreter)
18185a988416SJim Ingham     {
18195a988416SJim Ingham         CommandArgumentEntry arg;
18205a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
18215a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
18225a988416SJim Ingham         m_arguments.push_back (arg);
18235a988416SJim Ingham     }
18245a988416SJim Ingham 
18259e85e5a8SEugene Zelenko     ~CommandObjectBreakpointDelete() override = default;
18265a988416SJim Ingham 
182713d21e9aSBruce Mitchener     Options *
182813d21e9aSBruce Mitchener     GetOptions () override
182933df7cd3SJim Ingham     {
183033df7cd3SJim Ingham         return &m_options;
183133df7cd3SJim Ingham     }
183233df7cd3SJim Ingham 
183333df7cd3SJim Ingham     class CommandOptions : public Options
183433df7cd3SJim Ingham     {
183533df7cd3SJim Ingham     public:
183633df7cd3SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
183733df7cd3SJim Ingham             Options (interpreter),
183833df7cd3SJim Ingham             m_use_dummy (false),
183933df7cd3SJim Ingham             m_force (false)
184033df7cd3SJim Ingham         {
184133df7cd3SJim Ingham         }
184233df7cd3SJim Ingham 
18439e85e5a8SEugene Zelenko         ~CommandOptions() override = default;
184433df7cd3SJim Ingham 
184513d21e9aSBruce Mitchener         Error
184613d21e9aSBruce Mitchener         SetOptionValue (uint32_t option_idx, const char *option_arg) override
184733df7cd3SJim Ingham         {
184833df7cd3SJim Ingham             Error error;
184933df7cd3SJim Ingham             const int short_option = m_getopt_table[option_idx].val;
185033df7cd3SJim Ingham 
185133df7cd3SJim Ingham             switch (short_option)
185233df7cd3SJim Ingham             {
185333df7cd3SJim Ingham                 case 'f':
185433df7cd3SJim Ingham                     m_force = true;
185533df7cd3SJim Ingham                     break;
185633df7cd3SJim Ingham 
185733df7cd3SJim Ingham                 case 'D':
185833df7cd3SJim Ingham                     m_use_dummy = true;
185933df7cd3SJim Ingham                     break;
186033df7cd3SJim Ingham 
186133df7cd3SJim Ingham                 default:
186233df7cd3SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
186333df7cd3SJim Ingham                     break;
186433df7cd3SJim Ingham             }
186533df7cd3SJim Ingham 
186633df7cd3SJim Ingham             return error;
186733df7cd3SJim Ingham         }
186833df7cd3SJim Ingham 
186933df7cd3SJim Ingham         void
187013d21e9aSBruce Mitchener         OptionParsingStarting () override
187133df7cd3SJim Ingham         {
187233df7cd3SJim Ingham             m_use_dummy = false;
187333df7cd3SJim Ingham             m_force = false;
187433df7cd3SJim Ingham         }
187533df7cd3SJim Ingham 
187633df7cd3SJim Ingham         const OptionDefinition*
187713d21e9aSBruce Mitchener         GetDefinitions () override
187833df7cd3SJim Ingham         {
187933df7cd3SJim Ingham             return g_option_table;
188033df7cd3SJim Ingham         }
188133df7cd3SJim Ingham 
188233df7cd3SJim Ingham         // Options table: Required for subclasses of Options.
188333df7cd3SJim Ingham 
188433df7cd3SJim Ingham         static OptionDefinition g_option_table[];
188533df7cd3SJim Ingham 
188633df7cd3SJim Ingham         // Instance variables to hold the values for command options.
188733df7cd3SJim Ingham         bool m_use_dummy;
188833df7cd3SJim Ingham         bool m_force;
188933df7cd3SJim Ingham     };
189033df7cd3SJim Ingham 
18915a988416SJim Ingham protected:
189213d21e9aSBruce Mitchener     bool
189313d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
18945a988416SJim Ingham     {
189533df7cd3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
189633df7cd3SJim Ingham 
18979e85e5a8SEugene Zelenko         if (target == nullptr)
18985a988416SJim Ingham         {
18995a988416SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
19005a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
19015a988416SJim Ingham             return false;
19025a988416SJim Ingham         }
19035a988416SJim Ingham 
1904*bb19a13cSSaleem Abdulrasool         std::unique_lock<std::recursive_mutex> lock;
1905*bb19a13cSSaleem Abdulrasool         target->GetBreakpointList().GetListMutex(lock);
19065a988416SJim Ingham 
19075a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
19085a988416SJim Ingham 
19095a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
19105a988416SJim Ingham 
19115a988416SJim Ingham         if (num_breakpoints == 0)
19125a988416SJim Ingham         {
19135a988416SJim Ingham             result.AppendError ("No breakpoints exist to be deleted.");
19145a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
19155a988416SJim Ingham             return false;
19165a988416SJim Ingham         }
19175a988416SJim Ingham 
19185a988416SJim Ingham         if (command.GetArgumentCount() == 0)
19195a988416SJim Ingham         {
192033df7cd3SJim Ingham             if (!m_options.m_force && !m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
19215a988416SJim Ingham             {
19225a988416SJim Ingham                 result.AppendMessage("Operation cancelled...");
19235a988416SJim Ingham             }
19245a988416SJim Ingham             else
19255a988416SJim Ingham             {
19265a988416SJim Ingham                 target->RemoveAllBreakpoints ();
19276fea17e8SGreg Clayton                 result.AppendMessageWithFormat ("All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : "");
19285a988416SJim Ingham             }
19295a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
19305a988416SJim Ingham         }
19315a988416SJim Ingham         else
19325a988416SJim Ingham         {
19335a988416SJim Ingham             // Particular breakpoint selected; disable that breakpoint.
19345a988416SJim Ingham             BreakpointIDList valid_bp_ids;
19355e09c8c3SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
19365a988416SJim Ingham 
19375a988416SJim Ingham             if (result.Succeeded())
19385a988416SJim Ingham             {
19395a988416SJim Ingham                 int delete_count = 0;
19405a988416SJim Ingham                 int disable_count = 0;
19415a988416SJim Ingham                 const size_t count = valid_bp_ids.GetSize();
19425a988416SJim Ingham                 for (size_t i = 0; i < count; ++i)
19435a988416SJim Ingham                 {
19445a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
19455a988416SJim Ingham 
19465a988416SJim Ingham                     if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
19475a988416SJim Ingham                     {
19485a988416SJim Ingham                         if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
19495a988416SJim Ingham                         {
19505a988416SJim Ingham                             Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
19515a988416SJim Ingham                             BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
19525a988416SJim Ingham                             // It makes no sense to try to delete individual locations, so we disable them instead.
19535a988416SJim Ingham                             if (location)
19545a988416SJim Ingham                             {
19555a988416SJim Ingham                                 location->SetEnabled (false);
19565a988416SJim Ingham                                 ++disable_count;
19575a988416SJim Ingham                             }
19585a988416SJim Ingham                         }
19595a988416SJim Ingham                         else
19605a988416SJim Ingham                         {
19615a988416SJim Ingham                             target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
19625a988416SJim Ingham                             ++delete_count;
19635a988416SJim Ingham                         }
19645a988416SJim Ingham                     }
19655a988416SJim Ingham                 }
19665a988416SJim Ingham                 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
19675a988416SJim Ingham                                                delete_count, disable_count);
19685a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
19695a988416SJim Ingham             }
19705a988416SJim Ingham         }
19715a988416SJim Ingham         return result.Succeeded();
19725a988416SJim Ingham     }
19739e85e5a8SEugene Zelenko 
197433df7cd3SJim Ingham private:
197533df7cd3SJim Ingham     CommandOptions m_options;
197633df7cd3SJim Ingham };
197733df7cd3SJim Ingham 
197833df7cd3SJim Ingham OptionDefinition
197933df7cd3SJim Ingham CommandObjectBreakpointDelete::CommandOptions::g_option_table[] =
198033df7cd3SJim Ingham {
19819e85e5a8SEugene Zelenko     { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
198233df7cd3SJim Ingham         "Delete all breakpoints without querying for confirmation."},
198333df7cd3SJim Ingham 
19849e85e5a8SEugene Zelenko     { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
198533df7cd3SJim Ingham         "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
198633df7cd3SJim Ingham 
19879e85e5a8SEugene Zelenko     { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
19885a988416SJim Ingham };
19895a988416SJim Ingham 
199030fdc8d8SChris Lattner //-------------------------------------------------------------------------
19915e09c8c3SJim Ingham // CommandObjectBreakpointName
19925e09c8c3SJim Ingham //-------------------------------------------------------------------------
19935e09c8c3SJim Ingham 
19945e09c8c3SJim Ingham static OptionDefinition
19955e09c8c3SJim Ingham g_breakpoint_name_options[] =
19965e09c8c3SJim Ingham {
19979e85e5a8SEugene Zelenko     { LLDB_OPT_SET_1,   false, "name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."},
19989e85e5a8SEugene Zelenko     { LLDB_OPT_SET_2,   false, "breakpoint-id", 'B', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointID,   "Specify a breakpoint id to use."},
19999e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
20005e09c8c3SJim Ingham         "Operate on Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
20015e09c8c3SJim Ingham };
20025e09c8c3SJim Ingham class BreakpointNameOptionGroup : public OptionGroup
20035e09c8c3SJim Ingham {
20045e09c8c3SJim Ingham public:
20055e09c8c3SJim Ingham     BreakpointNameOptionGroup() :
20065e09c8c3SJim Ingham         OptionGroup(),
20075e09c8c3SJim Ingham         m_breakpoint(LLDB_INVALID_BREAK_ID),
20085e09c8c3SJim Ingham         m_use_dummy (false)
20095e09c8c3SJim Ingham     {
20105e09c8c3SJim Ingham     }
20115e09c8c3SJim Ingham 
20129e85e5a8SEugene Zelenko     ~BreakpointNameOptionGroup() override = default;
20135e09c8c3SJim Ingham 
201413d21e9aSBruce Mitchener     uint32_t
201513d21e9aSBruce Mitchener     GetNumDefinitions () override
20165e09c8c3SJim Ingham     {
20175e09c8c3SJim Ingham       return sizeof (g_breakpoint_name_options) / sizeof (OptionDefinition);
20185e09c8c3SJim Ingham     }
20195e09c8c3SJim Ingham 
202013d21e9aSBruce Mitchener     const OptionDefinition*
202113d21e9aSBruce Mitchener     GetDefinitions () override
20225e09c8c3SJim Ingham     {
20235e09c8c3SJim Ingham         return g_breakpoint_name_options;
20245e09c8c3SJim Ingham     }
20255e09c8c3SJim Ingham 
202613d21e9aSBruce Mitchener     Error
20275e09c8c3SJim Ingham     SetOptionValue (CommandInterpreter &interpreter,
20285e09c8c3SJim Ingham                     uint32_t option_idx,
202913d21e9aSBruce Mitchener                     const char *option_value) override
20305e09c8c3SJim Ingham     {
20315e09c8c3SJim Ingham         Error error;
20325e09c8c3SJim Ingham         const int short_option = g_breakpoint_name_options[option_idx].short_option;
20335e09c8c3SJim Ingham 
20345e09c8c3SJim Ingham         switch (short_option)
20355e09c8c3SJim Ingham         {
20365e09c8c3SJim Ingham         case 'N':
20375e09c8c3SJim Ingham             if (BreakpointID::StringIsBreakpointName(option_value, error) && error.Success())
2038c95f7e2aSPavel Labath                 m_name.SetValueFromString(option_value);
20395e09c8c3SJim Ingham             break;
20405e09c8c3SJim Ingham 
20415e09c8c3SJim Ingham         case 'B':
2042c95f7e2aSPavel Labath             if (m_breakpoint.SetValueFromString(option_value).Fail())
20435e09c8c3SJim Ingham                 error.SetErrorStringWithFormat ("unrecognized value \"%s\" for breakpoint", option_value);
20445e09c8c3SJim Ingham             break;
20455e09c8c3SJim Ingham         case 'D':
2046c95f7e2aSPavel Labath             if (m_use_dummy.SetValueFromString(option_value).Fail())
20475e09c8c3SJim Ingham                 error.SetErrorStringWithFormat ("unrecognized value \"%s\" for use-dummy", option_value);
20485e09c8c3SJim Ingham             break;
20495e09c8c3SJim Ingham 
20505e09c8c3SJim Ingham         default:
20515e09c8c3SJim Ingham               error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
20525e09c8c3SJim Ingham               break;
20535e09c8c3SJim Ingham         }
20545e09c8c3SJim Ingham         return error;
20555e09c8c3SJim Ingham     }
20565e09c8c3SJim Ingham 
205713d21e9aSBruce Mitchener     void
205813d21e9aSBruce Mitchener     OptionParsingStarting (CommandInterpreter &interpreter) override
20595e09c8c3SJim Ingham     {
20605e09c8c3SJim Ingham         m_name.Clear();
20615e09c8c3SJim Ingham         m_breakpoint.Clear();
20625e09c8c3SJim Ingham         m_use_dummy.Clear();
20635e09c8c3SJim Ingham         m_use_dummy.SetDefaultValue(false);
20645e09c8c3SJim Ingham     }
20655e09c8c3SJim Ingham 
20665e09c8c3SJim Ingham     OptionValueString m_name;
20675e09c8c3SJim Ingham     OptionValueUInt64 m_breakpoint;
20685e09c8c3SJim Ingham     OptionValueBoolean m_use_dummy;
20695e09c8c3SJim Ingham };
20705e09c8c3SJim Ingham 
20715e09c8c3SJim Ingham class CommandObjectBreakpointNameAdd : public CommandObjectParsed
20725e09c8c3SJim Ingham {
20735e09c8c3SJim Ingham public:
20745e09c8c3SJim Ingham     CommandObjectBreakpointNameAdd (CommandInterpreter &interpreter) :
20755e09c8c3SJim Ingham         CommandObjectParsed (interpreter,
20765e09c8c3SJim Ingham                              "add",
20775e09c8c3SJim Ingham                              "Add a name to the breakpoints provided.",
20785e09c8c3SJim Ingham                              "breakpoint name add <command-options> <breakpoint-id-list>"),
20795e09c8c3SJim Ingham         m_name_options(),
20805e09c8c3SJim Ingham         m_option_group(interpreter)
20815e09c8c3SJim Ingham         {
20825e09c8c3SJim Ingham             // Create the first variant for the first (and only) argument for this command.
20835e09c8c3SJim Ingham             CommandArgumentEntry arg1;
20845e09c8c3SJim Ingham             CommandArgumentData id_arg;
20855e09c8c3SJim Ingham             id_arg.arg_type = eArgTypeBreakpointID;
20865e09c8c3SJim Ingham             id_arg.arg_repetition = eArgRepeatOptional;
20875e09c8c3SJim Ingham             arg1.push_back(id_arg);
20885e09c8c3SJim Ingham             m_arguments.push_back (arg1);
20895e09c8c3SJim Ingham 
20905e09c8c3SJim Ingham             m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
20915e09c8c3SJim Ingham             m_option_group.Finalize();
20925e09c8c3SJim Ingham         }
20935e09c8c3SJim Ingham 
20949e85e5a8SEugene Zelenko     ~CommandObjectBreakpointNameAdd() override = default;
20955e09c8c3SJim Ingham 
20965e09c8c3SJim Ingham     Options *
209713d21e9aSBruce Mitchener     GetOptions() override
20985e09c8c3SJim Ingham     {
20995e09c8c3SJim Ingham         return &m_option_group;
21005e09c8c3SJim Ingham     }
21015e09c8c3SJim Ingham 
21025e09c8c3SJim Ingham protected:
210313d21e9aSBruce Mitchener     bool
210413d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
21055e09c8c3SJim Ingham     {
21065e09c8c3SJim Ingham         if (!m_name_options.m_name.OptionWasSet())
21075e09c8c3SJim Ingham         {
21085e09c8c3SJim Ingham             result.SetError("No name option provided.");
21095e09c8c3SJim Ingham             return false;
21105e09c8c3SJim Ingham         }
21115e09c8c3SJim Ingham 
21125e09c8c3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
21135e09c8c3SJim Ingham 
21149e85e5a8SEugene Zelenko         if (target == nullptr)
21155e09c8c3SJim Ingham         {
21165e09c8c3SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
21175e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
21185e09c8c3SJim Ingham             return false;
21195e09c8c3SJim Ingham         }
21205e09c8c3SJim Ingham 
2121*bb19a13cSSaleem Abdulrasool         std::unique_lock<std::recursive_mutex> lock;
2122*bb19a13cSSaleem Abdulrasool         target->GetBreakpointList().GetListMutex(lock);
21235e09c8c3SJim Ingham 
21245e09c8c3SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
21255e09c8c3SJim Ingham 
21265e09c8c3SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
21275e09c8c3SJim Ingham         if (num_breakpoints == 0)
21285e09c8c3SJim Ingham         {
21295e09c8c3SJim Ingham             result.SetError("No breakpoints, cannot add names.");
21305e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
21315e09c8c3SJim Ingham             return false;
21325e09c8c3SJim Ingham         }
21335e09c8c3SJim Ingham 
21345e09c8c3SJim Ingham         // Particular breakpoint selected; disable that breakpoint.
21355e09c8c3SJim Ingham         BreakpointIDList valid_bp_ids;
21365e09c8c3SJim Ingham         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
21375e09c8c3SJim Ingham 
21385e09c8c3SJim Ingham         if (result.Succeeded())
21395e09c8c3SJim Ingham         {
21405e09c8c3SJim Ingham             if (valid_bp_ids.GetSize() == 0)
21415e09c8c3SJim Ingham             {
21425e09c8c3SJim Ingham                 result.SetError("No breakpoints specified, cannot add names.");
21435e09c8c3SJim Ingham                 result.SetStatus (eReturnStatusFailed);
21445e09c8c3SJim Ingham                 return false;
21455e09c8c3SJim Ingham             }
21465e09c8c3SJim Ingham             size_t num_valid_ids = valid_bp_ids.GetSize();
21475e09c8c3SJim Ingham             for (size_t index = 0; index < num_valid_ids; index++)
21485e09c8c3SJim Ingham             {
21495e09c8c3SJim Ingham                 lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
21505e09c8c3SJim Ingham                 BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
21515e09c8c3SJim Ingham                 Error error;  // We don't need to check the error here, since the option parser checked it...
21525e09c8c3SJim Ingham                 bp_sp->AddName(m_name_options.m_name.GetCurrentValue(), error);
21535e09c8c3SJim Ingham             }
21545e09c8c3SJim Ingham         }
21555e09c8c3SJim Ingham 
21565e09c8c3SJim Ingham         return true;
21575e09c8c3SJim Ingham     }
21585e09c8c3SJim Ingham 
21595e09c8c3SJim Ingham private:
21605e09c8c3SJim Ingham     BreakpointNameOptionGroup m_name_options;
21615e09c8c3SJim Ingham     OptionGroupOptions m_option_group;
21625e09c8c3SJim Ingham };
21635e09c8c3SJim Ingham 
21645e09c8c3SJim Ingham class CommandObjectBreakpointNameDelete : public CommandObjectParsed
21655e09c8c3SJim Ingham {
21665e09c8c3SJim Ingham public:
21675e09c8c3SJim Ingham     CommandObjectBreakpointNameDelete (CommandInterpreter &interpreter) :
21685e09c8c3SJim Ingham         CommandObjectParsed (interpreter,
21695e09c8c3SJim Ingham                              "delete",
21705e09c8c3SJim Ingham                              "Delete a name from the breakpoints provided.",
21715e09c8c3SJim Ingham                              "breakpoint name delete <command-options> <breakpoint-id-list>"),
21725e09c8c3SJim Ingham         m_name_options(),
21735e09c8c3SJim Ingham         m_option_group(interpreter)
21745e09c8c3SJim Ingham     {
21755e09c8c3SJim Ingham         // Create the first variant for the first (and only) argument for this command.
21765e09c8c3SJim Ingham         CommandArgumentEntry arg1;
21775e09c8c3SJim Ingham         CommandArgumentData id_arg;
21785e09c8c3SJim Ingham         id_arg.arg_type = eArgTypeBreakpointID;
21795e09c8c3SJim Ingham         id_arg.arg_repetition = eArgRepeatOptional;
21805e09c8c3SJim Ingham         arg1.push_back(id_arg);
21815e09c8c3SJim Ingham         m_arguments.push_back (arg1);
21825e09c8c3SJim Ingham 
21835e09c8c3SJim Ingham         m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
21845e09c8c3SJim Ingham         m_option_group.Finalize();
21855e09c8c3SJim Ingham     }
21865e09c8c3SJim Ingham 
21879e85e5a8SEugene Zelenko     ~CommandObjectBreakpointNameDelete() override = default;
21885e09c8c3SJim Ingham 
21895e09c8c3SJim Ingham     Options *
219013d21e9aSBruce Mitchener     GetOptions() override
21915e09c8c3SJim Ingham     {
21925e09c8c3SJim Ingham         return &m_option_group;
21935e09c8c3SJim Ingham     }
21945e09c8c3SJim Ingham 
21955e09c8c3SJim Ingham protected:
219613d21e9aSBruce Mitchener     bool
219713d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
21985e09c8c3SJim Ingham     {
21995e09c8c3SJim Ingham         if (!m_name_options.m_name.OptionWasSet())
22005e09c8c3SJim Ingham         {
22015e09c8c3SJim Ingham             result.SetError("No name option provided.");
22025e09c8c3SJim Ingham             return false;
22035e09c8c3SJim Ingham         }
22045e09c8c3SJim Ingham 
22055e09c8c3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
22065e09c8c3SJim Ingham 
22079e85e5a8SEugene Zelenko         if (target == nullptr)
22085e09c8c3SJim Ingham         {
22095e09c8c3SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
22105e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
22115e09c8c3SJim Ingham             return false;
22125e09c8c3SJim Ingham         }
22135e09c8c3SJim Ingham 
2214*bb19a13cSSaleem Abdulrasool         std::unique_lock<std::recursive_mutex> lock;
2215*bb19a13cSSaleem Abdulrasool         target->GetBreakpointList().GetListMutex(lock);
22165e09c8c3SJim Ingham 
22175e09c8c3SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
22185e09c8c3SJim Ingham 
22195e09c8c3SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
22205e09c8c3SJim Ingham         if (num_breakpoints == 0)
22215e09c8c3SJim Ingham         {
22225e09c8c3SJim Ingham             result.SetError("No breakpoints, cannot delete names.");
22235e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
22245e09c8c3SJim Ingham             return false;
22255e09c8c3SJim Ingham         }
22265e09c8c3SJim Ingham 
22275e09c8c3SJim Ingham         // Particular breakpoint selected; disable that breakpoint.
22285e09c8c3SJim Ingham         BreakpointIDList valid_bp_ids;
22295e09c8c3SJim Ingham         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
22305e09c8c3SJim Ingham 
22315e09c8c3SJim Ingham         if (result.Succeeded())
22325e09c8c3SJim Ingham         {
22335e09c8c3SJim Ingham             if (valid_bp_ids.GetSize() == 0)
22345e09c8c3SJim Ingham             {
22355e09c8c3SJim Ingham                 result.SetError("No breakpoints specified, cannot delete names.");
22365e09c8c3SJim Ingham                 result.SetStatus (eReturnStatusFailed);
22375e09c8c3SJim Ingham                 return false;
22385e09c8c3SJim Ingham             }
22395e09c8c3SJim Ingham             size_t num_valid_ids = valid_bp_ids.GetSize();
22405e09c8c3SJim Ingham             for (size_t index = 0; index < num_valid_ids; index++)
22415e09c8c3SJim Ingham             {
22425e09c8c3SJim Ingham                 lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
22435e09c8c3SJim Ingham                 BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
22445e09c8c3SJim Ingham                 bp_sp->RemoveName(m_name_options.m_name.GetCurrentValue());
22455e09c8c3SJim Ingham             }
22465e09c8c3SJim Ingham         }
22475e09c8c3SJim Ingham 
22485e09c8c3SJim Ingham         return true;
22495e09c8c3SJim Ingham     }
22505e09c8c3SJim Ingham 
22515e09c8c3SJim Ingham private:
22525e09c8c3SJim Ingham     BreakpointNameOptionGroup m_name_options;
22535e09c8c3SJim Ingham     OptionGroupOptions m_option_group;
22545e09c8c3SJim Ingham };
22555e09c8c3SJim Ingham 
22565e09c8c3SJim Ingham class CommandObjectBreakpointNameList : public CommandObjectParsed
22575e09c8c3SJim Ingham {
22585e09c8c3SJim Ingham public:
22595e09c8c3SJim Ingham     CommandObjectBreakpointNameList (CommandInterpreter &interpreter) :
22605e09c8c3SJim Ingham         CommandObjectParsed (interpreter,
22615e09c8c3SJim Ingham                              "list",
22625e09c8c3SJim Ingham                              "List either the names for a breakpoint or the breakpoints for a given name.",
22635e09c8c3SJim Ingham                              "breakpoint name list <command-options>"),
22645e09c8c3SJim Ingham         m_name_options(),
22655e09c8c3SJim Ingham         m_option_group(interpreter)
22665e09c8c3SJim Ingham     {
22675e09c8c3SJim Ingham         m_option_group.Append (&m_name_options);
22685e09c8c3SJim Ingham         m_option_group.Finalize();
22695e09c8c3SJim Ingham     }
22705e09c8c3SJim Ingham 
22719e85e5a8SEugene Zelenko     ~CommandObjectBreakpointNameList() override = default;
22725e09c8c3SJim Ingham 
22735e09c8c3SJim Ingham     Options *
227413d21e9aSBruce Mitchener     GetOptions() override
22755e09c8c3SJim Ingham     {
22765e09c8c3SJim Ingham         return &m_option_group;
22775e09c8c3SJim Ingham     }
22785e09c8c3SJim Ingham 
22795e09c8c3SJim Ingham protected:
228013d21e9aSBruce Mitchener     bool
228113d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
22825e09c8c3SJim Ingham     {
22835e09c8c3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
22845e09c8c3SJim Ingham 
22859e85e5a8SEugene Zelenko         if (target == nullptr)
22865e09c8c3SJim Ingham         {
22875e09c8c3SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
22885e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
22895e09c8c3SJim Ingham             return false;
22905e09c8c3SJim Ingham         }
22915e09c8c3SJim Ingham 
22925e09c8c3SJim Ingham         if (m_name_options.m_name.OptionWasSet())
22935e09c8c3SJim Ingham         {
22945e09c8c3SJim Ingham             const char *name = m_name_options.m_name.GetCurrentValue();
2295*bb19a13cSSaleem Abdulrasool             std::unique_lock<std::recursive_mutex> lock;
2296*bb19a13cSSaleem Abdulrasool             target->GetBreakpointList().GetListMutex(lock);
22975e09c8c3SJim Ingham 
22985e09c8c3SJim Ingham             BreakpointList &breakpoints = target->GetBreakpointList();
22995e09c8c3SJim Ingham             for (BreakpointSP bp_sp : breakpoints.Breakpoints())
23005e09c8c3SJim Ingham             {
23015e09c8c3SJim Ingham                 if (bp_sp->MatchesName(name))
23025e09c8c3SJim Ingham                 {
23035e09c8c3SJim Ingham                     StreamString s;
23045e09c8c3SJim Ingham                     bp_sp->GetDescription(&s, eDescriptionLevelBrief);
23055e09c8c3SJim Ingham                     s.EOL();
23065e09c8c3SJim Ingham                     result.AppendMessage(s.GetData());
23075e09c8c3SJim Ingham                 }
23085e09c8c3SJim Ingham             }
23095e09c8c3SJim Ingham 
23105e09c8c3SJim Ingham         }
23115e09c8c3SJim Ingham         else if (m_name_options.m_breakpoint.OptionWasSet())
23125e09c8c3SJim Ingham         {
23135e09c8c3SJim Ingham             BreakpointSP bp_sp = target->GetBreakpointList().FindBreakpointByID(m_name_options.m_breakpoint.GetCurrentValue());
23145e09c8c3SJim Ingham             if (bp_sp)
23155e09c8c3SJim Ingham             {
23165e09c8c3SJim Ingham                 std::vector<std::string> names;
23175e09c8c3SJim Ingham                 bp_sp->GetNames (names);
23185e09c8c3SJim Ingham                 result.AppendMessage ("Names:");
23195e09c8c3SJim Ingham                 for (auto name : names)
23205e09c8c3SJim Ingham                     result.AppendMessageWithFormat ("    %s\n", name.c_str());
23215e09c8c3SJim Ingham             }
23225e09c8c3SJim Ingham             else
23235e09c8c3SJim Ingham             {
23245e09c8c3SJim Ingham                 result.AppendErrorWithFormat ("Could not find breakpoint %" PRId64 ".\n",
23255e09c8c3SJim Ingham                                            m_name_options.m_breakpoint.GetCurrentValue());
23265e09c8c3SJim Ingham                 result.SetStatus (eReturnStatusFailed);
23275e09c8c3SJim Ingham                 return false;
23285e09c8c3SJim Ingham             }
23295e09c8c3SJim Ingham         }
23305e09c8c3SJim Ingham         else
23315e09c8c3SJim Ingham         {
23325e09c8c3SJim Ingham             result.SetError ("Must specify -N or -B option to list.");
23335e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
23345e09c8c3SJim Ingham             return false;
23355e09c8c3SJim Ingham         }
23365e09c8c3SJim Ingham         return true;
23375e09c8c3SJim Ingham     }
23385e09c8c3SJim Ingham 
23395e09c8c3SJim Ingham private:
23405e09c8c3SJim Ingham     BreakpointNameOptionGroup m_name_options;
23415e09c8c3SJim Ingham     OptionGroupOptions m_option_group;
23425e09c8c3SJim Ingham };
23435e09c8c3SJim Ingham 
23445e09c8c3SJim Ingham //-------------------------------------------------------------------------
23455e09c8c3SJim Ingham // CommandObjectMultiwordBreakpoint
23465e09c8c3SJim Ingham //-------------------------------------------------------------------------
23475e09c8c3SJim Ingham class CommandObjectBreakpointName : public CommandObjectMultiword
23485e09c8c3SJim Ingham {
23495e09c8c3SJim Ingham public:
23505e09c8c3SJim Ingham     CommandObjectBreakpointName (CommandInterpreter &interpreter) :
23515e09c8c3SJim Ingham         CommandObjectMultiword(interpreter,
23525e09c8c3SJim Ingham                                 "name",
23535e09c8c3SJim Ingham                                 "A set of commands to manage name tags for breakpoints",
23545e09c8c3SJim Ingham                                 "breakpoint name <command> [<command-options>]")
23555e09c8c3SJim Ingham     {
23565e09c8c3SJim Ingham         CommandObjectSP add_command_object (new CommandObjectBreakpointNameAdd (interpreter));
23575e09c8c3SJim Ingham         CommandObjectSP delete_command_object (new CommandObjectBreakpointNameDelete (interpreter));
23585e09c8c3SJim Ingham         CommandObjectSP list_command_object (new CommandObjectBreakpointNameList (interpreter));
23595e09c8c3SJim Ingham 
23605e09c8c3SJim Ingham         LoadSubCommand ("add", add_command_object);
23615e09c8c3SJim Ingham         LoadSubCommand ("delete", delete_command_object);
23625e09c8c3SJim Ingham         LoadSubCommand ("list", list_command_object);
23635e09c8c3SJim Ingham     }
23645e09c8c3SJim Ingham 
23659e85e5a8SEugene Zelenko     ~CommandObjectBreakpointName() override = default;
23665e09c8c3SJim Ingham };
23675e09c8c3SJim Ingham 
23685e09c8c3SJim Ingham //-------------------------------------------------------------------------
236930fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint
237030fdc8d8SChris Lattner //-------------------------------------------------------------------------
2371ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint
237230fdc8d8SChris Lattner 
23736611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
2374a7015092SGreg Clayton     CommandObjectMultiword (interpreter,
2375a7015092SGreg Clayton                             "breakpoint",
237646fbc60fSJim Ingham                             "A set of commands for operating on breakpoints. Also see _regexp-break.",
237730fdc8d8SChris Lattner                             "breakpoint <command> [<command-options>]")
237830fdc8d8SChris Lattner {
2379a7015092SGreg Clayton     CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
2380a7015092SGreg Clayton     CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
2381a7015092SGreg Clayton     CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
2382b7234e40SJohnny Chen     CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
2383b7234e40SJohnny Chen     CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
2384a7015092SGreg Clayton     CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
238530fdc8d8SChris Lattner     CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
2386a7015092SGreg Clayton     CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
23875e09c8c3SJim Ingham     CommandObjectSP name_command_object (new CommandObjectBreakpointName(interpreter));
238830fdc8d8SChris Lattner 
2389b7234e40SJohnny Chen     list_command_object->SetCommandName ("breakpoint list");
239030fdc8d8SChris Lattner     enable_command_object->SetCommandName("breakpoint enable");
239130fdc8d8SChris Lattner     disable_command_object->SetCommandName("breakpoint disable");
2392b7234e40SJohnny Chen     clear_command_object->SetCommandName("breakpoint clear");
2393b7234e40SJohnny Chen     delete_command_object->SetCommandName("breakpoint delete");
2394ae1c4cf5SJim Ingham     set_command_object->SetCommandName("breakpoint set");
2395b7234e40SJohnny Chen     command_command_object->SetCommandName ("breakpoint command");
2396b7234e40SJohnny Chen     modify_command_object->SetCommandName ("breakpoint modify");
23975e09c8c3SJim Ingham     name_command_object->SetCommandName ("breakpoint name");
239830fdc8d8SChris Lattner 
239923f59509SGreg Clayton     LoadSubCommand ("list",       list_command_object);
240023f59509SGreg Clayton     LoadSubCommand ("enable",     enable_command_object);
240123f59509SGreg Clayton     LoadSubCommand ("disable",    disable_command_object);
240223f59509SGreg Clayton     LoadSubCommand ("clear",      clear_command_object);
240323f59509SGreg Clayton     LoadSubCommand ("delete",     delete_command_object);
240423f59509SGreg Clayton     LoadSubCommand ("set",        set_command_object);
240523f59509SGreg Clayton     LoadSubCommand ("command",    command_command_object);
240623f59509SGreg Clayton     LoadSubCommand ("modify",     modify_command_object);
24075e09c8c3SJim Ingham     LoadSubCommand ("name",       name_command_object);
240830fdc8d8SChris Lattner }
240930fdc8d8SChris Lattner 
24109e85e5a8SEugene Zelenko CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default;
241130fdc8d8SChris Lattner 
241230fdc8d8SChris Lattner void
24135e09c8c3SJim Ingham CommandObjectMultiwordBreakpoint::VerifyIDs (Args &args,
24145e09c8c3SJim Ingham                                              Target *target,
24155e09c8c3SJim Ingham                                              bool allow_locations,
24165e09c8c3SJim Ingham                                              CommandReturnObject &result,
241730fdc8d8SChris Lattner                                              BreakpointIDList *valid_ids)
241830fdc8d8SChris Lattner {
241930fdc8d8SChris Lattner     // args can be strings representing 1). integers (for breakpoint ids)
242030fdc8d8SChris Lattner     //                                  2). the full breakpoint & location canonical representation
242130fdc8d8SChris Lattner     //                                  3). the word "to" or a hyphen, representing a range (in which case there
242230fdc8d8SChris Lattner     //                                      had *better* be an entry both before & after of one of the first two types.
24235e09c8c3SJim Ingham     //                                  4). A breakpoint name
242436f3b369SJim Ingham     // If args is empty, we will use the last created breakpoint (if there is one.)
242530fdc8d8SChris Lattner 
242630fdc8d8SChris Lattner     Args temp_args;
242730fdc8d8SChris Lattner 
242836f3b369SJim Ingham     if (args.GetArgumentCount() == 0)
242936f3b369SJim Ingham     {
24304d122c40SGreg Clayton         if (target->GetLastCreatedBreakpoint())
243136f3b369SJim Ingham         {
243236f3b369SJim Ingham             valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
243336f3b369SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
243436f3b369SJim Ingham         }
243536f3b369SJim Ingham         else
243636f3b369SJim Ingham         {
243736f3b369SJim Ingham             result.AppendError("No breakpoint specified and no last created breakpoint.");
243836f3b369SJim Ingham             result.SetStatus (eReturnStatusFailed);
243936f3b369SJim Ingham         }
244036f3b369SJim Ingham         return;
244136f3b369SJim Ingham     }
244236f3b369SJim Ingham 
244330fdc8d8SChris Lattner     // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
244430fdc8d8SChris Lattner     // the new TEMP_ARGS.  Do not copy breakpoint id range strings over; instead generate a list of strings for
244530fdc8d8SChris Lattner     // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
244630fdc8d8SChris Lattner 
24475e09c8c3SJim Ingham     BreakpointIDList::FindAndReplaceIDRanges (args, target, allow_locations, result, temp_args);
244830fdc8d8SChris Lattner 
244930fdc8d8SChris Lattner     // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
245030fdc8d8SChris Lattner 
2451c982c768SGreg Clayton     valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
245230fdc8d8SChris Lattner 
245330fdc8d8SChris Lattner     // At this point,  all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
245430fdc8d8SChris Lattner     // and put into valid_ids.
245530fdc8d8SChris Lattner 
245630fdc8d8SChris Lattner     if (result.Succeeded())
245730fdc8d8SChris Lattner     {
245830fdc8d8SChris Lattner         // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
245930fdc8d8SChris Lattner         // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
246030fdc8d8SChris Lattner 
2461c982c768SGreg Clayton         const size_t count = valid_ids->GetSize();
2462c982c768SGreg Clayton         for (size_t i = 0; i < count; ++i)
246330fdc8d8SChris Lattner         {
246430fdc8d8SChris Lattner             BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
246530fdc8d8SChris Lattner             Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
24669e85e5a8SEugene Zelenko             if (breakpoint != nullptr)
246730fdc8d8SChris Lattner             {
2468c7bece56SGreg Clayton                 const size_t num_locations = breakpoint->GetNumLocations();
24693985c8c6SSaleem Abdulrasool                 if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations)
247030fdc8d8SChris Lattner                 {
247130fdc8d8SChris Lattner                     StreamString id_str;
2472c982c768SGreg Clayton                     BreakpointID::GetCanonicalReference (&id_str,
2473c982c768SGreg Clayton                                                          cur_bp_id.GetBreakpointID(),
247430fdc8d8SChris Lattner                                                          cur_bp_id.GetLocationID());
2475c982c768SGreg Clayton                     i = valid_ids->GetSize() + 1;
247630fdc8d8SChris Lattner                     result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
247730fdc8d8SChris Lattner                                                  id_str.GetData());
247830fdc8d8SChris Lattner                     result.SetStatus (eReturnStatusFailed);
247930fdc8d8SChris Lattner                 }
248030fdc8d8SChris Lattner             }
248130fdc8d8SChris Lattner             else
248230fdc8d8SChris Lattner             {
2483c982c768SGreg Clayton                 i = valid_ids->GetSize() + 1;
248430fdc8d8SChris Lattner                 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
248530fdc8d8SChris Lattner                 result.SetStatus (eReturnStatusFailed);
248630fdc8d8SChris Lattner             }
248730fdc8d8SChris Lattner         }
248830fdc8d8SChris Lattner     }
248930fdc8d8SChris Lattner }
2490