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 
280*2411167fSJim Ingham                 case 'R':
281*2411167fSJim Ingham                     {
282*2411167fSJim Ingham                         ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
283*2411167fSJim Ingham                         lldb::addr_t tmp_offset_addr;
284*2411167fSJim Ingham                         tmp_offset_addr = Args::StringToAddress(&exe_ctx, option_arg, 0, &error);
285*2411167fSJim Ingham                         if (error.Success())
286*2411167fSJim Ingham                             m_offset_addr = tmp_offset_addr;
287*2411167fSJim Ingham                     }
288*2411167fSJim Ingham                     break;
289*2411167fSJim 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 
34530fdc8d8SChris Lattner                 default:
34686edbf41SGreg Clayton                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
34730fdc8d8SChris Lattner                     break;
34830fdc8d8SChris Lattner             }
34930fdc8d8SChris Lattner 
35030fdc8d8SChris Lattner             return error;
35130fdc8d8SChris Lattner         }
3529e85e5a8SEugene Zelenko 
35330fdc8d8SChris Lattner         void
35413d21e9aSBruce Mitchener         OptionParsingStarting () override
35530fdc8d8SChris Lattner         {
3567d49c9c8SJohnny Chen             m_condition.clear();
35787df91b8SJim Ingham             m_filenames.Clear();
35830fdc8d8SChris Lattner             m_line_num = 0;
35930fdc8d8SChris Lattner             m_column = 0;
360fab10e89SJim Ingham             m_func_names.clear();
3611f746071SGreg Clayton             m_func_name_type_mask = eFunctionNameTypeNone;
36230fdc8d8SChris Lattner             m_func_regexp.clear();
3631f746071SGreg Clayton             m_source_text_regexp.clear();
36487df91b8SJim Ingham             m_modules.Clear();
3651f746071SGreg Clayton             m_load_addr = LLDB_INVALID_ADDRESS;
366*2411167fSJim Ingham             m_offset_addr = 0;
367c982c768SGreg Clayton             m_ignore_count = 0;
3681b54c88cSJim Ingham             m_thread_id = LLDB_INVALID_THREAD_ID;
369c982c768SGreg Clayton             m_thread_index = UINT32_MAX;
3701b54c88cSJim Ingham             m_thread_name.clear();
3711b54c88cSJim Ingham             m_queue_name.clear();
372fab10e89SJim Ingham             m_catch_bp = false;
373fab10e89SJim Ingham             m_throw_bp = true;
374eb023e75SGreg Clayton             m_hardware = false;
375a72b31c7SJim Ingham             m_exception_language = eLanguageTypeUnknown;
37623b1decbSDawn Perchik             m_language = lldb::eLanguageTypeUnknown;
377a8558b62SJim Ingham             m_skip_prologue = eLazyBoolCalculate;
378ca36cd16SJim Ingham             m_one_shot = false;
37933df7cd3SJim Ingham             m_use_dummy = false;
3805e09c8c3SJim Ingham             m_breakpoint_names.clear();
381e732052fSJim Ingham             m_all_files = false;
382a72b31c7SJim Ingham             m_exception_extra_args.Clear();
383055ad9beSIlia K             m_move_to_nearest_code = eLazyBoolCalculate;
38430fdc8d8SChris Lattner         }
38530fdc8d8SChris Lattner 
3865a988416SJim Ingham         const OptionDefinition*
38713d21e9aSBruce Mitchener         GetDefinitions () override
38830fdc8d8SChris Lattner         {
3895a988416SJim Ingham             return g_option_table;
39030fdc8d8SChris Lattner         }
39130fdc8d8SChris Lattner 
3925a988416SJim Ingham         // Options table: Required for subclasses of Options.
39330fdc8d8SChris Lattner 
3945a988416SJim Ingham         static OptionDefinition g_option_table[];
39530fdc8d8SChris Lattner 
3965a988416SJim Ingham         // Instance variables to hold the values for command options.
397969795f1SJim Ingham 
3985a988416SJim Ingham         std::string m_condition;
3995a988416SJim Ingham         FileSpecList m_filenames;
4005a988416SJim Ingham         uint32_t m_line_num;
4015a988416SJim Ingham         uint32_t m_column;
4025a988416SJim Ingham         std::vector<std::string> m_func_names;
4035e09c8c3SJim Ingham         std::vector<std::string> m_breakpoint_names;
4045a988416SJim Ingham         uint32_t m_func_name_type_mask;
4055a988416SJim Ingham         std::string m_func_regexp;
4065a988416SJim Ingham         std::string m_source_text_regexp;
4075a988416SJim Ingham         FileSpecList m_modules;
4085a988416SJim Ingham         lldb::addr_t m_load_addr;
409*2411167fSJim Ingham         lldb::addr_t m_offset_addr;
4105a988416SJim Ingham         uint32_t m_ignore_count;
4115a988416SJim Ingham         lldb::tid_t m_thread_id;
4125a988416SJim Ingham         uint32_t m_thread_index;
4135a988416SJim Ingham         std::string m_thread_name;
4145a988416SJim Ingham         std::string m_queue_name;
4155a988416SJim Ingham         bool m_catch_bp;
4165a988416SJim Ingham         bool m_throw_bp;
417eb023e75SGreg Clayton         bool m_hardware; // Request to use hardware breakpoints
418a72b31c7SJim Ingham         lldb::LanguageType m_exception_language;
41923b1decbSDawn Perchik         lldb::LanguageType m_language;
4205a988416SJim Ingham         LazyBool m_skip_prologue;
421ca36cd16SJim Ingham         bool m_one_shot;
42233df7cd3SJim Ingham         bool m_use_dummy;
423e732052fSJim Ingham         bool m_all_files;
424a72b31c7SJim Ingham         Args m_exception_extra_args;
425055ad9beSIlia K         LazyBool m_move_to_nearest_code;
4265a988416SJim Ingham     };
4275a988416SJim Ingham 
4285a988416SJim Ingham protected:
42913d21e9aSBruce Mitchener     bool
4305a988416SJim Ingham     DoExecute (Args& command,
43113d21e9aSBruce Mitchener               CommandReturnObject &result) override
43230fdc8d8SChris Lattner     {
43333df7cd3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
43433df7cd3SJim Ingham 
435893c932aSJim Ingham         if (target == nullptr)
43630fdc8d8SChris Lattner         {
437effe5c95SGreg Clayton             result.AppendError ("Invalid target.  Must set target before setting breakpoints (see 'target create' command).");
43830fdc8d8SChris Lattner             result.SetStatus (eReturnStatusFailed);
43930fdc8d8SChris Lattner             return false;
44030fdc8d8SChris Lattner         }
44130fdc8d8SChris Lattner 
44230fdc8d8SChris Lattner         // The following are the various types of breakpoints that could be set:
44330fdc8d8SChris Lattner         //   1).  -f -l -p  [-s -g]   (setting breakpoint by source location)
44430fdc8d8SChris Lattner         //   2).  -a  [-s -g]         (setting breakpoint by address)
44530fdc8d8SChris Lattner         //   3).  -n  [-s -g]         (setting breakpoint by function name)
44630fdc8d8SChris Lattner         //   4).  -r  [-s -g]         (setting breakpoint by function name regular expression)
447969795f1SJim Ingham         //   5).  -p -f               (setting a breakpoint by comparing a reg-exp to source text)
448fab10e89SJim Ingham         //   6).  -E [-w -h]          (setting a breakpoint for exceptions for a given language.)
44930fdc8d8SChris Lattner 
45030fdc8d8SChris Lattner         BreakpointSetType break_type = eSetTypeInvalid;
45130fdc8d8SChris Lattner 
45230fdc8d8SChris Lattner         if (m_options.m_line_num != 0)
45330fdc8d8SChris Lattner             break_type = eSetTypeFileAndLine;
45430fdc8d8SChris Lattner         else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
45530fdc8d8SChris Lattner             break_type = eSetTypeAddress;
456fab10e89SJim Ingham         else if (!m_options.m_func_names.empty())
45730fdc8d8SChris Lattner             break_type = eSetTypeFunctionName;
45830fdc8d8SChris Lattner         else if  (!m_options.m_func_regexp.empty())
45930fdc8d8SChris Lattner             break_type = eSetTypeFunctionRegexp;
460969795f1SJim Ingham         else if (!m_options.m_source_text_regexp.empty())
461969795f1SJim Ingham             break_type = eSetTypeSourceRegexp;
462a72b31c7SJim Ingham         else if (m_options.m_exception_language != eLanguageTypeUnknown)
463fab10e89SJim Ingham             break_type = eSetTypeException;
46430fdc8d8SChris Lattner 
4659e85e5a8SEugene Zelenko         Breakpoint *bp = nullptr;
466274060b6SGreg Clayton         FileSpec module_spec;
467a8558b62SJim Ingham         const bool internal = false;
468a8558b62SJim Ingham 
469*2411167fSJim Ingham         // If the user didn't specify skip-prologue, having an offset should turn that off.
470*2411167fSJim Ingham         if (m_options.m_offset_addr != 0 && m_options.m_skip_prologue == eLazyBoolCalculate)
471*2411167fSJim Ingham             m_options.m_skip_prologue = eLazyBoolNo;
472*2411167fSJim Ingham 
47330fdc8d8SChris Lattner         switch (break_type)
47430fdc8d8SChris Lattner         {
47530fdc8d8SChris Lattner             case eSetTypeFileAndLine: // Breakpoint by source position
47630fdc8d8SChris Lattner                 {
47730fdc8d8SChris Lattner                     FileSpec file;
478c7bece56SGreg Clayton                     const size_t num_files = m_options.m_filenames.GetSize();
47987df91b8SJim Ingham                     if (num_files == 0)
48087df91b8SJim Ingham                     {
48187df91b8SJim Ingham                         if (!GetDefaultFile (target, file, result))
48287df91b8SJim Ingham                         {
48387df91b8SJim Ingham                             result.AppendError("No file supplied and no default file available.");
48487df91b8SJim Ingham                             result.SetStatus (eReturnStatusFailed);
48587df91b8SJim Ingham                             return false;
48687df91b8SJim Ingham                         }
48787df91b8SJim Ingham                     }
48887df91b8SJim Ingham                     else if (num_files > 1)
48987df91b8SJim Ingham                     {
49087df91b8SJim Ingham                         result.AppendError("Only one file at a time is allowed for file and line breakpoints.");
49187df91b8SJim Ingham                         result.SetStatus (eReturnStatusFailed);
49287df91b8SJim Ingham                         return false;
49387df91b8SJim Ingham                     }
49487df91b8SJim Ingham                     else
49587df91b8SJim Ingham                         file = m_options.m_filenames.GetFileSpecAtIndex(0);
49630fdc8d8SChris Lattner 
4971f746071SGreg Clayton                     // Only check for inline functions if
4981f746071SGreg Clayton                     LazyBool check_inlines = eLazyBoolCalculate;
4991f746071SGreg Clayton 
50087df91b8SJim Ingham                     bp = target->CreateBreakpoint (&(m_options.m_modules),
50130fdc8d8SChris Lattner                                                    file,
50230fdc8d8SChris Lattner                                                    m_options.m_line_num,
503*2411167fSJim Ingham                                                    m_options.m_offset_addr,
5041f746071SGreg Clayton                                                    check_inlines,
505a8558b62SJim Ingham                                                    m_options.m_skip_prologue,
506eb023e75SGreg Clayton                                                    internal,
507055ad9beSIlia K                                                    m_options.m_hardware,
508055ad9beSIlia K                                                    m_options.m_move_to_nearest_code).get();
50930fdc8d8SChris Lattner                 }
51030fdc8d8SChris Lattner                 break;
5116eee5aa0SGreg Clayton 
51230fdc8d8SChris Lattner             case eSetTypeAddress: // Breakpoint by address
513055a08a4SJim Ingham                 {
514055a08a4SJim Ingham                     // If a shared library has been specified, make an lldb_private::Address with the library, and
515055a08a4SJim Ingham                     // use that.  That way the address breakpoint will track the load location of the library.
516055a08a4SJim Ingham                     size_t num_modules_specified = m_options.m_modules.GetSize();
517055a08a4SJim Ingham                     if (num_modules_specified == 1)
518055a08a4SJim Ingham                     {
519055a08a4SJim Ingham                         const FileSpec *file_spec = m_options.m_modules.GetFileSpecPointerAtIndex(0);
520055a08a4SJim Ingham                         bp = target->CreateAddressInModuleBreakpoint (m_options.m_load_addr,
521055a08a4SJim Ingham                                                                       internal,
522055a08a4SJim Ingham                                                                       file_spec,
523055a08a4SJim Ingham                                                                       m_options.m_hardware).get();
524055a08a4SJim Ingham                     }
525055a08a4SJim Ingham                     else if (num_modules_specified == 0)
526055a08a4SJim Ingham                     {
527eb023e75SGreg Clayton                         bp = target->CreateBreakpoint (m_options.m_load_addr,
528eb023e75SGreg Clayton                                                        internal,
529eb023e75SGreg Clayton                                                        m_options.m_hardware).get();
530055a08a4SJim Ingham                     }
531055a08a4SJim Ingham                     else
532055a08a4SJim Ingham                     {
533055a08a4SJim Ingham                         result.AppendError("Only one shared library can be specified for address breakpoints.");
534055a08a4SJim Ingham                         result.SetStatus(eReturnStatusFailed);
535055a08a4SJim Ingham                         return false;
536055a08a4SJim Ingham                     }
53730fdc8d8SChris Lattner                 break;
538055a08a4SJim Ingham                 }
53930fdc8d8SChris Lattner             case eSetTypeFunctionName: // Breakpoint by function name
5400c5cd90dSGreg Clayton                 {
5410c5cd90dSGreg Clayton                     uint32_t name_type_mask = m_options.m_func_name_type_mask;
5420c5cd90dSGreg Clayton 
5430c5cd90dSGreg Clayton                     if (name_type_mask == 0)
544e02b8504SGreg Clayton                         name_type_mask = eFunctionNameTypeAuto;
5450c5cd90dSGreg Clayton 
54687df91b8SJim Ingham                     bp = target->CreateBreakpoint (&(m_options.m_modules),
54787df91b8SJim Ingham                                                    &(m_options.m_filenames),
548fab10e89SJim Ingham                                                    m_options.m_func_names,
549274060b6SGreg Clayton                                                    name_type_mask,
55023b1decbSDawn Perchik                                                    m_options.m_language,
551*2411167fSJim Ingham                                                    m_options.m_offset_addr,
552a8558b62SJim Ingham                                                    m_options.m_skip_prologue,
553eb023e75SGreg Clayton                                                    internal,
554eb023e75SGreg Clayton                                                    m_options.m_hardware).get();
5550c5cd90dSGreg Clayton                 }
55630fdc8d8SChris Lattner                 break;
5570c5cd90dSGreg Clayton 
55830fdc8d8SChris Lattner             case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
55930fdc8d8SChris Lattner                 {
56030fdc8d8SChris Lattner                     RegularExpression regexp(m_options.m_func_regexp.c_str());
561969795f1SJim Ingham                     if (!regexp.IsValid())
56230fdc8d8SChris Lattner                     {
563969795f1SJim Ingham                         char err_str[1024];
564969795f1SJim Ingham                         regexp.GetErrorAsCString(err_str, sizeof(err_str));
565969795f1SJim Ingham                         result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"",
566969795f1SJim Ingham                                                      err_str);
56730fdc8d8SChris Lattner                         result.SetStatus (eReturnStatusFailed);
568969795f1SJim Ingham                         return false;
56930fdc8d8SChris Lattner                     }
57087df91b8SJim Ingham 
571a8558b62SJim Ingham                     bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules),
572a8558b62SJim Ingham                                                             &(m_options.m_filenames),
573a8558b62SJim Ingham                                                             regexp,
5740fcdac36SJim Ingham                                                             m_options.m_language,
575a8558b62SJim Ingham                                                             m_options.m_skip_prologue,
576eb023e75SGreg Clayton                                                             internal,
577eb023e75SGreg Clayton                                                             m_options.m_hardware).get();
57830fdc8d8SChris Lattner                 }
57930fdc8d8SChris Lattner                 break;
580969795f1SJim Ingham             case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
581969795f1SJim Ingham                 {
582c7bece56SGreg Clayton                     const size_t num_files = m_options.m_filenames.GetSize();
58387df91b8SJim Ingham 
584e732052fSJim Ingham                     if (num_files == 0 && !m_options.m_all_files)
58587df91b8SJim Ingham                     {
586969795f1SJim Ingham                         FileSpec file;
58787df91b8SJim Ingham                         if (!GetDefaultFile (target, file, result))
58887df91b8SJim Ingham                         {
58987df91b8SJim Ingham                             result.AppendError ("No files provided and could not find default file.");
59087df91b8SJim Ingham                             result.SetStatus (eReturnStatusFailed);
59187df91b8SJim Ingham                             return false;
59287df91b8SJim Ingham                         }
59387df91b8SJim Ingham                         else
59487df91b8SJim Ingham                         {
59587df91b8SJim Ingham                             m_options.m_filenames.Append (file);
59687df91b8SJim Ingham                         }
59787df91b8SJim Ingham                     }
5980c5cd90dSGreg Clayton 
599969795f1SJim Ingham                     RegularExpression regexp(m_options.m_source_text_regexp.c_str());
600969795f1SJim Ingham                     if (!regexp.IsValid())
601969795f1SJim Ingham                     {
602969795f1SJim Ingham                         char err_str[1024];
603969795f1SJim Ingham                         regexp.GetErrorAsCString(err_str, sizeof(err_str));
604969795f1SJim Ingham                         result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"",
605969795f1SJim Ingham                                                      err_str);
606969795f1SJim Ingham                         result.SetStatus (eReturnStatusFailed);
607969795f1SJim Ingham                         return false;
608969795f1SJim Ingham                     }
609eb023e75SGreg Clayton                     bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules),
610eb023e75SGreg Clayton                                                               &(m_options.m_filenames),
611eb023e75SGreg Clayton                                                               regexp,
612eb023e75SGreg Clayton                                                               internal,
613055ad9beSIlia K                                                               m_options.m_hardware,
614055ad9beSIlia K                                                               m_options.m_move_to_nearest_code).get();
615969795f1SJim Ingham                 }
616969795f1SJim Ingham                 break;
617fab10e89SJim Ingham             case eSetTypeException:
618fab10e89SJim Ingham                 {
619a72b31c7SJim Ingham                     Error precond_error;
620a72b31c7SJim Ingham                     bp = target->CreateExceptionBreakpoint (m_options.m_exception_language,
621eb023e75SGreg Clayton                                                             m_options.m_catch_bp,
622eb023e75SGreg Clayton                                                             m_options.m_throw_bp,
623a72b31c7SJim Ingham                                                             internal,
624a72b31c7SJim Ingham                                                             &m_options.m_exception_extra_args,
625a72b31c7SJim Ingham                                                             &precond_error).get();
626a72b31c7SJim Ingham                     if (precond_error.Fail())
627a72b31c7SJim Ingham                     {
628a72b31c7SJim Ingham                         result.AppendErrorWithFormat("Error setting extra exception arguments: %s",
629a72b31c7SJim Ingham                                                      precond_error.AsCString());
630a72b31c7SJim Ingham                         target->RemoveBreakpointByID(bp->GetID());
631a72b31c7SJim Ingham                         result.SetStatus(eReturnStatusFailed);
632a72b31c7SJim Ingham                         return false;
633a72b31c7SJim Ingham                     }
634fab10e89SJim Ingham                 }
635fab10e89SJim Ingham                 break;
63630fdc8d8SChris Lattner             default:
63730fdc8d8SChris Lattner                 break;
63830fdc8d8SChris Lattner         }
63930fdc8d8SChris Lattner 
6401b54c88cSJim Ingham         // Now set the various options that were passed in:
6411b54c88cSJim Ingham         if (bp)
6421b54c88cSJim Ingham         {
6431b54c88cSJim Ingham             if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
6441b54c88cSJim Ingham                 bp->SetThreadID (m_options.m_thread_id);
6451b54c88cSJim Ingham 
646c982c768SGreg Clayton             if (m_options.m_thread_index != UINT32_MAX)
6471b54c88cSJim Ingham                 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
6481b54c88cSJim Ingham 
6491b54c88cSJim Ingham             if (!m_options.m_thread_name.empty())
6501b54c88cSJim Ingham                 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
6511b54c88cSJim Ingham 
6521b54c88cSJim Ingham             if (!m_options.m_queue_name.empty())
6531b54c88cSJim Ingham                 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
6541b54c88cSJim Ingham 
655c982c768SGreg Clayton             if (m_options.m_ignore_count != 0)
6561b54c88cSJim Ingham                 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
6577d49c9c8SJohnny Chen 
6587d49c9c8SJohnny Chen             if (!m_options.m_condition.empty())
6597d49c9c8SJohnny Chen                 bp->GetOptions()->SetCondition(m_options.m_condition.c_str());
660ca36cd16SJim Ingham 
6615e09c8c3SJim Ingham             if (!m_options.m_breakpoint_names.empty())
6625e09c8c3SJim Ingham             {
6635e09c8c3SJim Ingham                 Error error;  // We don't need to check the error here, since the option parser checked it...
6645e09c8c3SJim Ingham                 for (auto name : m_options.m_breakpoint_names)
6655e09c8c3SJim Ingham                     bp->AddName(name.c_str(), error);
6665e09c8c3SJim Ingham             }
6675e09c8c3SJim Ingham 
668ca36cd16SJim Ingham             bp->SetOneShot (m_options.m_one_shot);
6691b54c88cSJim Ingham         }
6701b54c88cSJim Ingham 
671969795f1SJim Ingham         if (bp)
67230fdc8d8SChris Lattner         {
67385e8b814SJim Ingham             Stream &output_stream = result.GetOutputStream();
6741391cc7dSJim Ingham             const bool show_locations = false;
6751391cc7dSJim Ingham             bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, show_locations);
6764aeb1989SJim Ingham             if (target == m_interpreter.GetDebugger().GetDummyTarget())
6774aeb1989SJim Ingham                     output_stream.Printf ("Breakpoint set in dummy target, will get copied into future targets.\n");
6784aeb1989SJim Ingham             else
6794aeb1989SJim Ingham             {
680fab10e89SJim Ingham                 // Don't print out this warning for exception breakpoints.  They can get set before the target
681fab10e89SJim Ingham                 // is set, but we won't know how to actually set the breakpoint till we run.
682fab10e89SJim Ingham                 if (bp->GetNumLocations() == 0 && break_type != eSetTypeException)
6834aeb1989SJim Ingham                 {
684be484f41SCaroline Tice                     output_stream.Printf ("WARNING:  Unable to resolve breakpoint to any actual locations.\n");
6854aeb1989SJim Ingham                 }
6864aeb1989SJim Ingham             }
68730fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishResult);
68830fdc8d8SChris Lattner         }
68930fdc8d8SChris Lattner         else if (!bp)
69030fdc8d8SChris Lattner         {
69130fdc8d8SChris Lattner             result.AppendError ("Breakpoint creation failed: No breakpoint created.");
69230fdc8d8SChris Lattner             result.SetStatus (eReturnStatusFailed);
69330fdc8d8SChris Lattner         }
69430fdc8d8SChris Lattner 
69530fdc8d8SChris Lattner         return result.Succeeded();
69630fdc8d8SChris Lattner     }
69730fdc8d8SChris Lattner 
6985a988416SJim Ingham private:
6995a988416SJim Ingham     bool
7005a988416SJim Ingham     GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result)
7015a988416SJim Ingham     {
7025a988416SJim Ingham         uint32_t default_line;
7035a988416SJim Ingham         // First use the Source Manager's default file.
7045a988416SJim Ingham         // Then use the current stack frame's file.
7055a988416SJim Ingham         if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line))
7065a988416SJim Ingham         {
707b57e4a1bSJason Molenda             StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
7089e85e5a8SEugene Zelenko             if (cur_frame == nullptr)
7095a988416SJim Ingham             {
7105a988416SJim Ingham                 result.AppendError ("No selected frame to use to find the default file.");
7115a988416SJim Ingham                 result.SetStatus (eReturnStatusFailed);
7125a988416SJim Ingham                 return false;
7135a988416SJim Ingham             }
7145a988416SJim Ingham             else if (!cur_frame->HasDebugInformation())
7155a988416SJim Ingham             {
7165a988416SJim Ingham                 result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info.");
7175a988416SJim Ingham                 result.SetStatus (eReturnStatusFailed);
7185a988416SJim Ingham                 return false;
7195a988416SJim Ingham             }
7205a988416SJim Ingham             else
7215a988416SJim Ingham             {
7225a988416SJim Ingham                 const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
7235a988416SJim Ingham                 if (sc.line_entry.file)
7245a988416SJim Ingham                 {
7255a988416SJim Ingham                     file = sc.line_entry.file;
7265a988416SJim Ingham                 }
7275a988416SJim Ingham                 else
7285a988416SJim Ingham                 {
7295a988416SJim Ingham                     result.AppendError ("Can't find the file for the selected frame to use as the default file.");
7305a988416SJim Ingham                     result.SetStatus (eReturnStatusFailed);
7315a988416SJim Ingham                     return false;
7325a988416SJim Ingham                 }
7335a988416SJim Ingham             }
7345a988416SJim Ingham         }
7355a988416SJim Ingham         return true;
7365a988416SJim Ingham     }
7375a988416SJim Ingham 
7385a988416SJim Ingham     CommandOptions m_options;
7395a988416SJim Ingham };
7409e85e5a8SEugene Zelenko 
7415a988416SJim Ingham // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to
7425a988416SJim Ingham // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately.
7435a988416SJim Ingham #define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 )
7445a988416SJim Ingham #define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 )
7455a988416SJim Ingham #define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) )
746*2411167fSJim Ingham #define LLDB_OPT_OFFSET_APPLIES (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) )
747055ad9beSIlia K #define LLDB_OPT_MOVE_TO_NEAREST_CODE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_9 )
7480fcdac36SJim Ingham #define LLDB_OPT_EXPR_LANGUAGE ( LLDB_OPT_SET_FROM_TO(3, 8) )
7495a988416SJim Ingham 
7505a988416SJim Ingham OptionDefinition
7515a988416SJim Ingham CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
7525a988416SJim Ingham {
7539e85e5a8SEugene Zelenko     { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
7545a988416SJim Ingham         "Set the breakpoint only in this shared library.  "
7555a988416SJim Ingham         "Can repeat this option multiple times to specify multiple shared libraries."},
7565a988416SJim Ingham 
7579e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount,
7585a988416SJim Ingham         "Set the number of times this breakpoint is skipped before stopping." },
7595a988416SJim Ingham 
7609e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
761b2b256afSJim Ingham         "The breakpoint is deleted the first time it causes a stop." },
762ca36cd16SJim Ingham 
7639e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "condition",    'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression,
7645a988416SJim Ingham         "The breakpoint stops only if this condition expression evaluates to true."},
7655a988416SJim Ingham 
7669e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex,
767a89be91fSJim Ingham         "The breakpoint stops only for the thread whose indeX matches this argument."},
7685a988416SJim Ingham 
7699e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID,
7705a988416SJim Ingham         "The breakpoint stops only for the thread whose TID matches this argument."},
7715a988416SJim Ingham 
7729e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName,
7735a988416SJim Ingham         "The breakpoint stops only for the thread whose thread name matches this argument."},
7745a988416SJim Ingham 
7759e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
776eb023e75SGreg Clayton         "Require the breakpoint to use hardware breakpoints."},
777eb023e75SGreg Clayton 
7789e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName,
7795a988416SJim Ingham         "The breakpoint stops only for threads in the queue whose name is given by this argument."},
7805a988416SJim Ingham 
7819e85e5a8SEugene Zelenko     { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
782289aca64SJim Ingham         "Specifies the source file in which to set this breakpoint.  "
783289aca64SJim Ingham         "Note, by default lldb only looks for files that are #included if they use the standard include file extensions.  "
7846394479eSJim Ingham         "To set breakpoints on .c/.cpp/.m/.mm files that are #included, set target.inline-breakpoint-strategy"
785289aca64SJim Ingham         " to \"always\"."},
7865a988416SJim Ingham 
7879e85e5a8SEugene Zelenko     { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum,
7885a988416SJim Ingham         "Specifies the line number on which to set this breakpoint."},
7895a988416SJim Ingham 
7905a988416SJim Ingham     // Comment out this option for the moment, as we don't actually use it, but will in the future.
7915a988416SJim Ingham     // This way users won't see it, but the infrastructure is left in place.
7929e85e5a8SEugene Zelenko     //    { 0, false, "column",     'C', OptionParser::eRequiredArgument, nullptr, "<column>",
7935a988416SJim Ingham     //    "Set the breakpoint by source location at this particular column."},
7945a988416SJim Ingham 
7959e85e5a8SEugene Zelenko     { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression,
796055a08a4SJim Ingham         "Set the breakpoint at the specified address.  "
797055a08a4SJim Ingham         "If the address maps uniquely to a particular "
798055a08a4SJim Ingham         "binary, then the address will be converted to a \"file\" address, so that the breakpoint will track that binary+offset no matter where "
799055a08a4SJim Ingham         "the binary eventually loads.  "
800055a08a4SJim Ingham         "Alternately, if you also specify the module - with the -s option - then the address will be treated as "
801055a08a4SJim Ingham         "a file address in that module, and resolved accordingly.  Again, this will allow lldb to track that offset on "
802055a08a4SJim Ingham         "subsequent reloads.  The module need not have been loaded at the time you specify this breakpoint, and will "
803055a08a4SJim Ingham         "get resolved when the module is loaded."},
8045a988416SJim Ingham 
8059e85e5a8SEugene Zelenko     { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
806551262d7SJim Ingham         "Set the breakpoint by function name.  Can be repeated multiple times to make one breakpoint for multiple names" },
8075a988416SJim Ingham 
8089e85e5a8SEugene Zelenko     { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
8095a988416SJim Ingham         "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and "
8105a988416SJim Ingham         "for Objective C this means a full function prototype with class and selector.  "
8115a988416SJim Ingham         "Can be repeated multiple times to make one breakpoint for multiple names." },
8125a988416SJim Ingham 
8139e85e5a8SEugene Zelenko     { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSelector,
8145a988416SJim Ingham         "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." },
8155a988416SJim Ingham 
8169e85e5a8SEugene Zelenko     { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeMethod,
8175a988416SJim Ingham         "Set the breakpoint by C++ method names.  Can be repeated multiple times to make one breakpoint for multiple methods." },
8185a988416SJim Ingham 
8199e85e5a8SEugene Zelenko     { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression,
8205a988416SJim Ingham         "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
8215a988416SJim Ingham 
8229e85e5a8SEugene Zelenko     { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
8235a988416SJim Ingham         "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). "
8245a988416SJim Ingham         "Can be repeated multiple times to make one breakpoint for multiple symbols." },
8255a988416SJim Ingham 
8269e85e5a8SEugene Zelenko     { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression,
827e96ade8bSJim Ingham         "Set the breakpoint by specifying a regular expression which is matched against the source text in a source file or files "
828e96ade8bSJim Ingham         "specified with the -f option.  The -f option can be specified more than once.  "
829cc3a4595SJim Ingham         "If no source files are specified, uses the current \"default source file\".  "
830cc3a4595SJim Ingham         "If you want to match against all source files, pass the \"--all-files\" option." },
8315a988416SJim Ingham 
8329e85e5a8SEugene Zelenko     { LLDB_OPT_SET_9, false, "all-files", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
833e732052fSJim Ingham         "All files are searched for source pattern matches." },
834e732052fSJim Ingham 
8359e85e5a8SEugene Zelenko     { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage,
8365a988416SJim Ingham         "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" },
8375a988416SJim Ingham 
8389e85e5a8SEugene Zelenko     { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
839b4a5aa23SJim Ingham         "Set the breakpoint on exception throW." },
8405a988416SJim Ingham 
8419e85e5a8SEugene Zelenko     { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
842b4a5aa23SJim Ingham         "Set the breakpoint on exception catcH." },
8435a988416SJim Ingham 
844a72b31c7SJim Ingham //  Don't add this option till it actually does something useful...
8459e85e5a8SEugene Zelenko //    { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName,
846a72b31c7SJim 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" },
847a72b31c7SJim Ingham 
8489e85e5a8SEugene Zelenko     { LLDB_OPT_EXPR_LANGUAGE, false, "language", 'L', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage,
8494112ab98SDawn 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." },
85023b1decbSDawn Perchik 
8519e85e5a8SEugene Zelenko     { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
8525a988416SJim Ingham         "sKip the prologue if the breakpoint is at the beginning of a function.  If not set the target.skip-prologue setting is used." },
8535a988416SJim Ingham 
8549e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
85533df7cd3SJim Ingham         "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
85633df7cd3SJim Ingham 
8579e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName,
8585e09c8c3SJim Ingham         "Adds this to the list of names for this breakopint."},
8595e09c8c3SJim Ingham 
860*2411167fSJim Ingham     { LLDB_OPT_OFFSET_APPLIES, false, "address-slide", 'R', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddress,
861*2411167fSJim Ingham         "Add the specified offset to whatever address(es) the breakpoint resolves to.  "
862*2411167fSJim Ingham         "At present this applies the offset directly as given, and doesn't try to align it to instruction boundaries."},
863*2411167fSJim Ingham 
8649e85e5a8SEugene Zelenko     { LLDB_OPT_MOVE_TO_NEAREST_CODE, false, "move-to-nearest-code", 'm', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
865055ad9beSIlia K         "Move breakpoints to nearest code. If not set the target.move-to-nearest-code setting is used." },
866055ad9beSIlia K 
8679e85e5a8SEugene Zelenko     { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
8685a988416SJim Ingham };
8695a988416SJim Ingham 
8705a988416SJim Ingham //-------------------------------------------------------------------------
8715a988416SJim Ingham // CommandObjectBreakpointModify
8725a988416SJim Ingham //-------------------------------------------------------------------------
8735a988416SJim Ingham #pragma mark Modify
8745a988416SJim Ingham 
8755a988416SJim Ingham class CommandObjectBreakpointModify : public CommandObjectParsed
8765a988416SJim Ingham {
8775a988416SJim Ingham public:
8785a988416SJim Ingham     CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
8795a988416SJim Ingham         CommandObjectParsed(interpreter,
8805a988416SJim Ingham                             "breakpoint modify",
8815a988416SJim Ingham                             "Modify the options on a breakpoint or set of breakpoints in the executable.  "
8825a988416SJim Ingham                             "If no breakpoint is specified, acts on the last created breakpoint.  "
8835a988416SJim Ingham                             "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
8849e85e5a8SEugene Zelenko                             nullptr),
8855a988416SJim Ingham         m_options (interpreter)
8865a988416SJim Ingham     {
8875a988416SJim Ingham         CommandArgumentEntry arg;
8885a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
8895a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
8905a988416SJim Ingham         m_arguments.push_back (arg);
8915a988416SJim Ingham     }
8925a988416SJim Ingham 
8939e85e5a8SEugene Zelenko     ~CommandObjectBreakpointModify() override = default;
8945a988416SJim Ingham 
89513d21e9aSBruce Mitchener     Options *
89613d21e9aSBruce Mitchener     GetOptions () override
8975a988416SJim Ingham     {
8985a988416SJim Ingham         return &m_options;
8995a988416SJim Ingham     }
9005a988416SJim Ingham 
9015a988416SJim Ingham     class CommandOptions : public Options
9025a988416SJim Ingham     {
9035a988416SJim Ingham     public:
9045a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
9055a988416SJim Ingham             Options (interpreter),
9065a988416SJim Ingham             m_ignore_count (0),
9075a988416SJim Ingham             m_thread_id(LLDB_INVALID_THREAD_ID),
9085a988416SJim Ingham             m_thread_id_passed(false),
9095a988416SJim Ingham             m_thread_index (UINT32_MAX),
9105a988416SJim Ingham             m_thread_index_passed(false),
9115a988416SJim Ingham             m_thread_name(),
9125a988416SJim Ingham             m_queue_name(),
9135a988416SJim Ingham             m_condition (),
914ca36cd16SJim Ingham             m_one_shot (false),
9155a988416SJim Ingham             m_enable_passed (false),
9165a988416SJim Ingham             m_enable_value (false),
9175a988416SJim Ingham             m_name_passed (false),
9185a988416SJim Ingham             m_queue_passed (false),
919ca36cd16SJim Ingham             m_condition_passed (false),
92033df7cd3SJim Ingham             m_one_shot_passed (false),
92133df7cd3SJim Ingham             m_use_dummy (false)
9225a988416SJim Ingham         {
9235a988416SJim Ingham         }
9245a988416SJim Ingham 
9259e85e5a8SEugene Zelenko         ~CommandOptions() override = default;
9265a988416SJim Ingham 
92713d21e9aSBruce Mitchener         Error
92813d21e9aSBruce Mitchener         SetOptionValue (uint32_t option_idx, const char *option_arg) override
9295a988416SJim Ingham         {
9305a988416SJim Ingham             Error error;
9313bcdfc0eSGreg Clayton             const int short_option = m_getopt_table[option_idx].val;
9325a988416SJim Ingham 
9335a988416SJim Ingham             switch (short_option)
9345a988416SJim Ingham             {
9355a988416SJim Ingham                 case 'c':
9369e85e5a8SEugene Zelenko                     if (option_arg != nullptr)
9375a988416SJim Ingham                         m_condition.assign (option_arg);
9385a988416SJim Ingham                     else
9395a988416SJim Ingham                         m_condition.clear();
9405a988416SJim Ingham                     m_condition_passed = true;
9415a988416SJim Ingham                     break;
9425a988416SJim Ingham                 case 'd':
9435a988416SJim Ingham                     m_enable_passed = true;
9445a988416SJim Ingham                     m_enable_value = false;
9455a988416SJim Ingham                     break;
94633df7cd3SJim Ingham                 case 'D':
94733df7cd3SJim Ingham                     m_use_dummy = true;
94833df7cd3SJim Ingham                     break;
9495a988416SJim Ingham                 case 'e':
9505a988416SJim Ingham                     m_enable_passed = true;
9515a988416SJim Ingham                     m_enable_value = true;
9525a988416SJim Ingham                     break;
9535a988416SJim Ingham                 case 'i':
9545275aaa0SVince Harron                     m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
9555a988416SJim Ingham                     if (m_ignore_count == UINT32_MAX)
9565a988416SJim Ingham                        error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
9575a988416SJim Ingham                     break;
958ca36cd16SJim Ingham                 case 'o':
959ca36cd16SJim Ingham                 {
960ca36cd16SJim Ingham                     bool value, success;
961ca36cd16SJim Ingham                     value = Args::StringToBoolean(option_arg, false, &success);
962ca36cd16SJim Ingham                     if (success)
963ca36cd16SJim Ingham                     {
964ca36cd16SJim Ingham                         m_one_shot_passed = true;
965ca36cd16SJim Ingham                         m_one_shot = value;
966ca36cd16SJim Ingham                     }
967ca36cd16SJim Ingham                     else
968ca36cd16SJim Ingham                         error.SetErrorStringWithFormat("invalid boolean value '%s' passed for -o option", option_arg);
969ca36cd16SJim Ingham                 }
970ca36cd16SJim Ingham                 break;
9715a988416SJim Ingham                 case 't' :
9725a988416SJim Ingham                     if (option_arg[0] == '\0')
9735a988416SJim Ingham                     {
9745a988416SJim Ingham                         m_thread_id = LLDB_INVALID_THREAD_ID;
9755a988416SJim Ingham                         m_thread_id_passed = true;
9765a988416SJim Ingham                     }
9775a988416SJim Ingham                     else
9785a988416SJim Ingham                     {
9795275aaa0SVince Harron                         m_thread_id = StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
9805a988416SJim Ingham                         if (m_thread_id == LLDB_INVALID_THREAD_ID)
9815a988416SJim Ingham                            error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
9825a988416SJim Ingham                         else
9835a988416SJim Ingham                             m_thread_id_passed = true;
9845a988416SJim Ingham                     }
9855a988416SJim Ingham                     break;
9865a988416SJim Ingham                 case 'T':
9879e85e5a8SEugene Zelenko                     if (option_arg != nullptr)
9885a988416SJim Ingham                         m_thread_name.assign (option_arg);
9895a988416SJim Ingham                     else
9905a988416SJim Ingham                         m_thread_name.clear();
9915a988416SJim Ingham                     m_name_passed = true;
9925a988416SJim Ingham                     break;
9935a988416SJim Ingham                 case 'q':
9949e85e5a8SEugene Zelenko                     if (option_arg != nullptr)
9955a988416SJim Ingham                         m_queue_name.assign (option_arg);
9965a988416SJim Ingham                     else
9975a988416SJim Ingham                         m_queue_name.clear();
9985a988416SJim Ingham                     m_queue_passed = true;
9995a988416SJim Ingham                     break;
10005a988416SJim Ingham                 case 'x':
10015a988416SJim Ingham                     if (option_arg[0] == '\n')
10025a988416SJim Ingham                     {
10035a988416SJim Ingham                         m_thread_index = UINT32_MAX;
10045a988416SJim Ingham                         m_thread_index_passed = true;
10055a988416SJim Ingham                     }
10065a988416SJim Ingham                     else
10075a988416SJim Ingham                     {
10085275aaa0SVince Harron                         m_thread_index = StringConvert::ToUInt32 (option_arg, UINT32_MAX, 0);
10095a988416SJim Ingham                         if (m_thread_id == UINT32_MAX)
10105a988416SJim Ingham                            error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
10115a988416SJim Ingham                         else
10125a988416SJim Ingham                             m_thread_index_passed = true;
10135a988416SJim Ingham                     }
10145a988416SJim Ingham                     break;
10155a988416SJim Ingham                 default:
10165a988416SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
10175a988416SJim Ingham                     break;
10185a988416SJim Ingham             }
10195a988416SJim Ingham 
10205a988416SJim Ingham             return error;
10215a988416SJim Ingham         }
10229e85e5a8SEugene Zelenko 
10235a988416SJim Ingham         void
102413d21e9aSBruce Mitchener         OptionParsingStarting () override
10255a988416SJim Ingham         {
10265a988416SJim Ingham             m_ignore_count = 0;
10275a988416SJim Ingham             m_thread_id = LLDB_INVALID_THREAD_ID;
10285a988416SJim Ingham             m_thread_id_passed = false;
10295a988416SJim Ingham             m_thread_index = UINT32_MAX;
10305a988416SJim Ingham             m_thread_index_passed = false;
10315a988416SJim Ingham             m_thread_name.clear();
10325a988416SJim Ingham             m_queue_name.clear();
10335a988416SJim Ingham             m_condition.clear();
1034ca36cd16SJim Ingham             m_one_shot = false;
10355a988416SJim Ingham             m_enable_passed = false;
10365a988416SJim Ingham             m_queue_passed = false;
10375a988416SJim Ingham             m_name_passed = false;
10385a988416SJim Ingham             m_condition_passed = false;
1039ca36cd16SJim Ingham             m_one_shot_passed = false;
104033df7cd3SJim Ingham             m_use_dummy = false;
10415a988416SJim Ingham         }
10425a988416SJim Ingham 
10435a988416SJim Ingham         const OptionDefinition*
104413d21e9aSBruce Mitchener         GetDefinitions () override
10455a988416SJim Ingham         {
10465a988416SJim Ingham             return g_option_table;
10475a988416SJim Ingham         }
10485a988416SJim Ingham 
10495a988416SJim Ingham         // Options table: Required for subclasses of Options.
10505a988416SJim Ingham 
10515a988416SJim Ingham         static OptionDefinition g_option_table[];
10525a988416SJim Ingham 
10535a988416SJim Ingham         // Instance variables to hold the values for command options.
10545a988416SJim Ingham 
10555a988416SJim Ingham         uint32_t m_ignore_count;
10565a988416SJim Ingham         lldb::tid_t m_thread_id;
10575a988416SJim Ingham         bool m_thread_id_passed;
10585a988416SJim Ingham         uint32_t m_thread_index;
10595a988416SJim Ingham         bool m_thread_index_passed;
10605a988416SJim Ingham         std::string m_thread_name;
10615a988416SJim Ingham         std::string m_queue_name;
10625a988416SJim Ingham         std::string m_condition;
1063ca36cd16SJim Ingham         bool m_one_shot;
10645a988416SJim Ingham         bool m_enable_passed;
10655a988416SJim Ingham         bool m_enable_value;
10665a988416SJim Ingham         bool m_name_passed;
10675a988416SJim Ingham         bool m_queue_passed;
10685a988416SJim Ingham         bool m_condition_passed;
1069ca36cd16SJim Ingham         bool m_one_shot_passed;
107033df7cd3SJim Ingham         bool m_use_dummy;
10715a988416SJim Ingham     };
10725a988416SJim Ingham 
10735a988416SJim Ingham protected:
107413d21e9aSBruce Mitchener     bool
107513d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
10765a988416SJim Ingham     {
107733df7cd3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
10789e85e5a8SEugene Zelenko         if (target == nullptr)
10795a988416SJim Ingham         {
10805a988416SJim Ingham             result.AppendError ("Invalid target.  No existing target or breakpoints.");
10815a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
10825a988416SJim Ingham             return false;
10835a988416SJim Ingham         }
10845a988416SJim Ingham 
10855a988416SJim Ingham         Mutex::Locker locker;
10865a988416SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
10875a988416SJim Ingham 
10885a988416SJim Ingham         BreakpointIDList valid_bp_ids;
10895a988416SJim Ingham 
10905e09c8c3SJim Ingham         CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
10915a988416SJim Ingham 
10925a988416SJim Ingham         if (result.Succeeded())
10935a988416SJim Ingham         {
10945a988416SJim Ingham             const size_t count = valid_bp_ids.GetSize();
10955a988416SJim Ingham             for (size_t i = 0; i < count; ++i)
10965a988416SJim Ingham             {
10975a988416SJim Ingham                 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
10985a988416SJim Ingham 
10995a988416SJim Ingham                 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
11005a988416SJim Ingham                 {
11015a988416SJim Ingham                     Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
11025a988416SJim Ingham                     if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
11035a988416SJim Ingham                     {
11045a988416SJim Ingham                         BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
11055a988416SJim Ingham                         if (location)
11065a988416SJim Ingham                         {
11075a988416SJim Ingham                             if (m_options.m_thread_id_passed)
11085a988416SJim Ingham                                 location->SetThreadID (m_options.m_thread_id);
11095a988416SJim Ingham 
11105a988416SJim Ingham                             if (m_options.m_thread_index_passed)
11115a988416SJim Ingham                                 location->SetThreadIndex(m_options.m_thread_index);
11125a988416SJim Ingham 
11135a988416SJim Ingham                             if (m_options.m_name_passed)
11145a988416SJim Ingham                                 location->SetThreadName(m_options.m_thread_name.c_str());
11155a988416SJim Ingham 
11165a988416SJim Ingham                             if (m_options.m_queue_passed)
11175a988416SJim Ingham                                 location->SetQueueName(m_options.m_queue_name.c_str());
11185a988416SJim Ingham 
11195a988416SJim Ingham                             if (m_options.m_ignore_count != 0)
11205a988416SJim Ingham                                 location->SetIgnoreCount(m_options.m_ignore_count);
11215a988416SJim Ingham 
11225a988416SJim Ingham                             if (m_options.m_enable_passed)
11235a988416SJim Ingham                                 location->SetEnabled (m_options.m_enable_value);
11245a988416SJim Ingham 
11255a988416SJim Ingham                             if (m_options.m_condition_passed)
11265a988416SJim Ingham                                 location->SetCondition (m_options.m_condition.c_str());
11275a988416SJim Ingham                         }
11285a988416SJim Ingham                     }
11295a988416SJim Ingham                     else
11305a988416SJim Ingham                     {
11315a988416SJim Ingham                         if (m_options.m_thread_id_passed)
11325a988416SJim Ingham                             bp->SetThreadID (m_options.m_thread_id);
11335a988416SJim Ingham 
11345a988416SJim Ingham                         if (m_options.m_thread_index_passed)
11355a988416SJim Ingham                             bp->SetThreadIndex(m_options.m_thread_index);
11365a988416SJim Ingham 
11375a988416SJim Ingham                         if (m_options.m_name_passed)
11385a988416SJim Ingham                             bp->SetThreadName(m_options.m_thread_name.c_str());
11395a988416SJim Ingham 
11405a988416SJim Ingham                         if (m_options.m_queue_passed)
11415a988416SJim Ingham                             bp->SetQueueName(m_options.m_queue_name.c_str());
11425a988416SJim Ingham 
11435a988416SJim Ingham                         if (m_options.m_ignore_count != 0)
11445a988416SJim Ingham                             bp->SetIgnoreCount(m_options.m_ignore_count);
11455a988416SJim Ingham 
11465a988416SJim Ingham                         if (m_options.m_enable_passed)
11475a988416SJim Ingham                             bp->SetEnabled (m_options.m_enable_value);
11485a988416SJim Ingham 
11495a988416SJim Ingham                         if (m_options.m_condition_passed)
11505a988416SJim Ingham                             bp->SetCondition (m_options.m_condition.c_str());
11515a988416SJim Ingham                     }
11525a988416SJim Ingham                 }
11535a988416SJim Ingham             }
11545a988416SJim Ingham         }
11555a988416SJim Ingham 
11565a988416SJim Ingham         return result.Succeeded();
11575a988416SJim Ingham     }
11585a988416SJim Ingham 
11595a988416SJim Ingham private:
11605a988416SJim Ingham     CommandOptions m_options;
11615a988416SJim Ingham };
11625a988416SJim Ingham 
11635a988416SJim Ingham #pragma mark Modify::CommandOptions
11645a988416SJim Ingham OptionDefinition
11655a988416SJim Ingham CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
11665a988416SJim Ingham {
11679e85e5a8SEugene 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." },
11689e85e5a8SEugene 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." },
11699e85e5a8SEugene 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."},
11709e85e5a8SEugene 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."},
11719e85e5a8SEugene 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."},
11729e85e5a8SEugene 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."},
11739e85e5a8SEugene 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."},
11749e85e5a8SEugene Zelenko { LLDB_OPT_SET_1,   false, "enable",       'e', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone, "Enable the breakpoint."},
11759e85e5a8SEugene Zelenko { LLDB_OPT_SET_2,   false, "disable",      'd', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone, "Disable the breakpoint."},
11769e85e5a8SEugene 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."},
117733df7cd3SJim Ingham 
11789e85e5a8SEugene Zelenko { 0,                false, nullptr,            0 , 0,                 nullptr, nullptr, 0, eArgTypeNone, nullptr }
11795a988416SJim Ingham };
11805a988416SJim Ingham 
11815a988416SJim Ingham //-------------------------------------------------------------------------
11825a988416SJim Ingham // CommandObjectBreakpointEnable
11835a988416SJim Ingham //-------------------------------------------------------------------------
11845a988416SJim Ingham #pragma mark Enable
11855a988416SJim Ingham 
11865a988416SJim Ingham class CommandObjectBreakpointEnable : public CommandObjectParsed
11875a988416SJim Ingham {
11885a988416SJim Ingham public:
11895a988416SJim Ingham     CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
11905a988416SJim Ingham         CommandObjectParsed(interpreter,
11915a988416SJim Ingham                             "enable",
11925a988416SJim Ingham                             "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
11939e85e5a8SEugene Zelenko                             nullptr)
11945a988416SJim Ingham     {
11955a988416SJim Ingham         CommandArgumentEntry arg;
11965a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
11975a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
11985a988416SJim Ingham         m_arguments.push_back (arg);
11995a988416SJim Ingham     }
12005a988416SJim Ingham 
12019e85e5a8SEugene Zelenko     ~CommandObjectBreakpointEnable() override = default;
12025a988416SJim Ingham 
12035a988416SJim Ingham protected:
120413d21e9aSBruce Mitchener     bool
120513d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
12065a988416SJim Ingham     {
1207893c932aSJim Ingham         Target *target = GetSelectedOrDummyTarget();
12089e85e5a8SEugene Zelenko         if (target == nullptr)
12095a988416SJim Ingham         {
12105a988416SJim Ingham             result.AppendError ("Invalid target.  No existing target or breakpoints.");
12115a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
12125a988416SJim Ingham             return false;
12135a988416SJim Ingham         }
12145a988416SJim Ingham 
12155a988416SJim Ingham         Mutex::Locker locker;
12165a988416SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
12175a988416SJim Ingham 
12185a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
12195a988416SJim Ingham 
12205a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
12215a988416SJim Ingham 
12225a988416SJim Ingham         if (num_breakpoints == 0)
12235a988416SJim Ingham         {
12245a988416SJim Ingham             result.AppendError ("No breakpoints exist to be enabled.");
12255a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
12265a988416SJim Ingham             return false;
12275a988416SJim Ingham         }
12285a988416SJim Ingham 
12295a988416SJim Ingham         if (command.GetArgumentCount() == 0)
12305a988416SJim Ingham         {
12315a988416SJim Ingham             // No breakpoint selected; enable all currently set breakpoints.
12325a988416SJim Ingham             target->EnableAllBreakpoints ();
12336fea17e8SGreg Clayton             result.AppendMessageWithFormat ("All breakpoints enabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints);
12345a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
12355a988416SJim Ingham         }
12365a988416SJim Ingham         else
12375a988416SJim Ingham         {
12385a988416SJim Ingham             // Particular breakpoint selected; enable that breakpoint.
12395a988416SJim Ingham             BreakpointIDList valid_bp_ids;
12405e09c8c3SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
12415a988416SJim Ingham 
12425a988416SJim Ingham             if (result.Succeeded())
12435a988416SJim Ingham             {
12445a988416SJim Ingham                 int enable_count = 0;
12455a988416SJim Ingham                 int loc_count = 0;
12465a988416SJim Ingham                 const size_t count = valid_bp_ids.GetSize();
12475a988416SJim Ingham                 for (size_t i = 0; i < count; ++i)
12485a988416SJim Ingham                 {
12495a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
12505a988416SJim Ingham 
12515a988416SJim Ingham                     if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
12525a988416SJim Ingham                     {
12535a988416SJim Ingham                         Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
12545a988416SJim Ingham                         if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
12555a988416SJim Ingham                         {
12565a988416SJim Ingham                             BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
12575a988416SJim Ingham                             if (location)
12585a988416SJim Ingham                             {
12595a988416SJim Ingham                                 location->SetEnabled (true);
12605a988416SJim Ingham                                 ++loc_count;
12615a988416SJim Ingham                             }
12625a988416SJim Ingham                         }
12635a988416SJim Ingham                         else
12645a988416SJim Ingham                         {
12655a988416SJim Ingham                             breakpoint->SetEnabled (true);
12665a988416SJim Ingham                             ++enable_count;
12675a988416SJim Ingham                         }
12685a988416SJim Ingham                     }
12695a988416SJim Ingham                 }
12705a988416SJim Ingham                 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
12715a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
12725a988416SJim Ingham             }
12735a988416SJim Ingham         }
12745a988416SJim Ingham 
12755a988416SJim Ingham         return result.Succeeded();
12765a988416SJim Ingham     }
12775a988416SJim Ingham };
12785a988416SJim Ingham 
12795a988416SJim Ingham //-------------------------------------------------------------------------
12805a988416SJim Ingham // CommandObjectBreakpointDisable
12815a988416SJim Ingham //-------------------------------------------------------------------------
12825a988416SJim Ingham #pragma mark Disable
12835a988416SJim Ingham 
12845a988416SJim Ingham class CommandObjectBreakpointDisable : public CommandObjectParsed
12855a988416SJim Ingham {
12865a988416SJim Ingham public:
12875a988416SJim Ingham     CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
12885a988416SJim Ingham         CommandObjectParsed(interpreter,
12895a988416SJim Ingham                             "breakpoint disable",
1290ea671fbdSKate Stone                             "Disable the specified breakpoint(s) without removing them.  If none are specified, disable all breakpoints.",
12919e85e5a8SEugene Zelenko                             nullptr)
12925a988416SJim Ingham     {
1293b0fac509SJim Ingham         SetHelpLong(
1294ea671fbdSKate Stone "Disable the specified breakpoint(s) without removing them.  \
1295ea671fbdSKate Stone If none are specified, disable all breakpoints." R"(
1296ea671fbdSKate Stone 
1297ea671fbdSKate Stone )" "Note: disabling a breakpoint will cause none of its locations to be hit \
1298ea671fbdSKate Stone regardless of whether they are enabled or disabled.  After the sequence:" R"(
1299ea671fbdSKate Stone 
1300ea671fbdSKate Stone     (lldb) break disable 1
1301ea671fbdSKate Stone     (lldb) break enable 1.1
1302ea671fbdSKate Stone 
1303ea671fbdSKate Stone execution will NOT stop at location 1.1.  To achieve that, type:
1304ea671fbdSKate Stone 
1305ea671fbdSKate Stone     (lldb) break disable 1.*
1306ea671fbdSKate Stone     (lldb) break enable 1.1
1307ea671fbdSKate Stone 
1308ea671fbdSKate Stone )" "The first command disables all the locations of breakpoint 1, \
1309b0fac509SJim Ingham the second re-enables the first location."
1310b0fac509SJim Ingham         );
1311b0fac509SJim Ingham 
13125a988416SJim Ingham         CommandArgumentEntry arg;
13135a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
13145a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
13155a988416SJim Ingham         m_arguments.push_back (arg);
13165a988416SJim Ingham     }
13175a988416SJim Ingham 
13189e85e5a8SEugene Zelenko     ~CommandObjectBreakpointDisable() override = default;
13195a988416SJim Ingham 
13205a988416SJim Ingham protected:
132113d21e9aSBruce Mitchener     bool
132213d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
13235a988416SJim Ingham     {
1324893c932aSJim Ingham         Target *target = GetSelectedOrDummyTarget();
13259e85e5a8SEugene Zelenko         if (target == nullptr)
13265a988416SJim Ingham         {
13275a988416SJim Ingham             result.AppendError ("Invalid target.  No existing target or breakpoints.");
13285a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
13295a988416SJim Ingham             return false;
13305a988416SJim Ingham         }
13315a988416SJim Ingham 
13325a988416SJim Ingham         Mutex::Locker locker;
13335a988416SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
13345a988416SJim Ingham 
13355a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
13365a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
13375a988416SJim Ingham 
13385a988416SJim Ingham         if (num_breakpoints == 0)
13395a988416SJim Ingham         {
13405a988416SJim Ingham             result.AppendError ("No breakpoints exist to be disabled.");
13415a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
13425a988416SJim Ingham             return false;
13435a988416SJim Ingham         }
13445a988416SJim Ingham 
13455a988416SJim Ingham         if (command.GetArgumentCount() == 0)
13465a988416SJim Ingham         {
13475a988416SJim Ingham             // No breakpoint selected; disable all currently set breakpoints.
13485a988416SJim Ingham             target->DisableAllBreakpoints ();
13496fea17e8SGreg Clayton             result.AppendMessageWithFormat ("All breakpoints disabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints);
13505a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
13515a988416SJim Ingham         }
13525a988416SJim Ingham         else
13535a988416SJim Ingham         {
13545a988416SJim Ingham             // Particular breakpoint selected; disable that breakpoint.
13555a988416SJim Ingham             BreakpointIDList valid_bp_ids;
13565a988416SJim Ingham 
13575e09c8c3SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
13585a988416SJim Ingham 
13595a988416SJim Ingham             if (result.Succeeded())
13605a988416SJim Ingham             {
13615a988416SJim Ingham                 int disable_count = 0;
13625a988416SJim Ingham                 int loc_count = 0;
13635a988416SJim Ingham                 const size_t count = valid_bp_ids.GetSize();
13645a988416SJim Ingham                 for (size_t i = 0; i < count; ++i)
13655a988416SJim Ingham                 {
13665a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
13675a988416SJim Ingham 
13685a988416SJim Ingham                     if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
13695a988416SJim Ingham                     {
13705a988416SJim Ingham                         Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
13715a988416SJim Ingham                         if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
13725a988416SJim Ingham                         {
13735a988416SJim Ingham                             BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
13745a988416SJim Ingham                             if (location)
13755a988416SJim Ingham                             {
13765a988416SJim Ingham                                 location->SetEnabled (false);
13775a988416SJim Ingham                                 ++loc_count;
13785a988416SJim Ingham                             }
13795a988416SJim Ingham                         }
13805a988416SJim Ingham                         else
13815a988416SJim Ingham                         {
13825a988416SJim Ingham                             breakpoint->SetEnabled (false);
13835a988416SJim Ingham                             ++disable_count;
13845a988416SJim Ingham                         }
13855a988416SJim Ingham                     }
13865a988416SJim Ingham                 }
13875a988416SJim Ingham                 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
13885a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
13895a988416SJim Ingham             }
13905a988416SJim Ingham         }
13915a988416SJim Ingham 
13925a988416SJim Ingham         return result.Succeeded();
13935a988416SJim Ingham     }
13945a988416SJim Ingham };
13955a988416SJim Ingham 
13965a988416SJim Ingham //-------------------------------------------------------------------------
13975a988416SJim Ingham // CommandObjectBreakpointList
13985a988416SJim Ingham //-------------------------------------------------------------------------
13995a988416SJim Ingham #pragma mark List
14005a988416SJim Ingham 
14015a988416SJim Ingham class CommandObjectBreakpointList : public CommandObjectParsed
14025a988416SJim Ingham {
14035a988416SJim Ingham public:
14045a988416SJim Ingham     CommandObjectBreakpointList (CommandInterpreter &interpreter) :
14055a988416SJim Ingham         CommandObjectParsed(interpreter,
14065a988416SJim Ingham                             "breakpoint list",
14075a988416SJim Ingham                             "List some or all breakpoints at configurable levels of detail.",
14089e85e5a8SEugene Zelenko                             nullptr),
14095a988416SJim Ingham         m_options (interpreter)
14105a988416SJim Ingham     {
14115a988416SJim Ingham         CommandArgumentEntry arg;
14125a988416SJim Ingham         CommandArgumentData bp_id_arg;
14135a988416SJim Ingham 
14145a988416SJim Ingham         // Define the first (and only) variant of this arg.
14155a988416SJim Ingham         bp_id_arg.arg_type = eArgTypeBreakpointID;
14165a988416SJim Ingham         bp_id_arg.arg_repetition = eArgRepeatOptional;
14175a988416SJim Ingham 
14185a988416SJim Ingham         // There is only one variant this argument could be; put it into the argument entry.
14195a988416SJim Ingham         arg.push_back (bp_id_arg);
14205a988416SJim Ingham 
14215a988416SJim Ingham         // Push the data for the first argument into the m_arguments vector.
14225a988416SJim Ingham         m_arguments.push_back (arg);
14235a988416SJim Ingham     }
14245a988416SJim Ingham 
14259e85e5a8SEugene Zelenko     ~CommandObjectBreakpointList() override = default;
14265a988416SJim Ingham 
142713d21e9aSBruce Mitchener     Options *
142813d21e9aSBruce Mitchener     GetOptions () override
14295a988416SJim Ingham     {
14305a988416SJim Ingham         return &m_options;
14315a988416SJim Ingham     }
14325a988416SJim Ingham 
14335a988416SJim Ingham     class CommandOptions : public Options
14345a988416SJim Ingham     {
14355a988416SJim Ingham     public:
14365a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
14375a988416SJim Ingham             Options (interpreter),
143833df7cd3SJim Ingham             m_level (lldb::eDescriptionLevelBrief),
143933df7cd3SJim Ingham             m_use_dummy(false)
14405a988416SJim Ingham         {
14415a988416SJim Ingham         }
14425a988416SJim Ingham 
14439e85e5a8SEugene Zelenko         ~CommandOptions() override = default;
14445a988416SJim Ingham 
144513d21e9aSBruce Mitchener         Error
144613d21e9aSBruce Mitchener         SetOptionValue (uint32_t option_idx, const char *option_arg) override
14475a988416SJim Ingham         {
14485a988416SJim Ingham             Error error;
14493bcdfc0eSGreg Clayton             const int short_option = m_getopt_table[option_idx].val;
14505a988416SJim Ingham 
14515a988416SJim Ingham             switch (short_option)
14525a988416SJim Ingham             {
14535a988416SJim Ingham                 case 'b':
14545a988416SJim Ingham                     m_level = lldb::eDescriptionLevelBrief;
14555a988416SJim Ingham                     break;
145633df7cd3SJim Ingham                 case 'D':
145733df7cd3SJim Ingham                     m_use_dummy = true;
145833df7cd3SJim Ingham                     break;
14595a988416SJim Ingham                 case 'f':
14605a988416SJim Ingham                     m_level = lldb::eDescriptionLevelFull;
14615a988416SJim Ingham                     break;
14625a988416SJim Ingham                 case 'v':
14635a988416SJim Ingham                     m_level = lldb::eDescriptionLevelVerbose;
14645a988416SJim Ingham                     break;
14655a988416SJim Ingham                 case 'i':
14665a988416SJim Ingham                     m_internal = true;
14675a988416SJim Ingham                     break;
14685a988416SJim Ingham                 default:
14695a988416SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
14705a988416SJim Ingham                     break;
14715a988416SJim Ingham             }
14725a988416SJim Ingham 
14735a988416SJim Ingham             return error;
14745a988416SJim Ingham         }
14755a988416SJim Ingham 
14765a988416SJim Ingham         void
147713d21e9aSBruce Mitchener         OptionParsingStarting () override
14785a988416SJim Ingham         {
14795a988416SJim Ingham             m_level = lldb::eDescriptionLevelFull;
14805a988416SJim Ingham             m_internal = false;
148133df7cd3SJim Ingham             m_use_dummy = false;
14825a988416SJim Ingham         }
14835a988416SJim Ingham 
14845a988416SJim Ingham         const OptionDefinition *
148513d21e9aSBruce Mitchener         GetDefinitions () override
14865a988416SJim Ingham         {
14875a988416SJim Ingham             return g_option_table;
14885a988416SJim Ingham         }
14895a988416SJim Ingham 
14905a988416SJim Ingham         // Options table: Required for subclasses of Options.
14915a988416SJim Ingham 
14925a988416SJim Ingham         static OptionDefinition g_option_table[];
14935a988416SJim Ingham 
14945a988416SJim Ingham         // Instance variables to hold the values for command options.
14955a988416SJim Ingham 
14965a988416SJim Ingham         lldb::DescriptionLevel m_level;
14975a988416SJim Ingham 
14985a988416SJim Ingham         bool m_internal;
149933df7cd3SJim Ingham         bool m_use_dummy;
15005a988416SJim Ingham     };
15015a988416SJim Ingham 
15025a988416SJim Ingham protected:
150313d21e9aSBruce Mitchener     bool
150413d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
15055a988416SJim Ingham     {
150633df7cd3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
150733df7cd3SJim Ingham 
15089e85e5a8SEugene Zelenko         if (target == nullptr)
15095a988416SJim Ingham         {
15105a988416SJim Ingham             result.AppendError ("Invalid target. No current target or breakpoints.");
15115a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
15125a988416SJim Ingham             return true;
15135a988416SJim Ingham         }
15145a988416SJim Ingham 
15155a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
15165a988416SJim Ingham         Mutex::Locker locker;
15175a988416SJim Ingham         target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
15185a988416SJim Ingham 
15195a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
15205a988416SJim Ingham 
15215a988416SJim Ingham         if (num_breakpoints == 0)
15225a988416SJim Ingham         {
15235a988416SJim Ingham             result.AppendMessage ("No breakpoints currently set.");
15245a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
15255a988416SJim Ingham             return true;
15265a988416SJim Ingham         }
15275a988416SJim Ingham 
15285a988416SJim Ingham         Stream &output_stream = result.GetOutputStream();
15295a988416SJim Ingham 
15305a988416SJim Ingham         if (command.GetArgumentCount() == 0)
15315a988416SJim Ingham         {
15325a988416SJim Ingham             // No breakpoint selected; show info about all currently set breakpoints.
15335a988416SJim Ingham             result.AppendMessage ("Current breakpoints:");
15345a988416SJim Ingham             for (size_t i = 0; i < num_breakpoints; ++i)
15355a988416SJim Ingham             {
15365a988416SJim Ingham                 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
15375a988416SJim Ingham                 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
15385a988416SJim Ingham             }
15395a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
15405a988416SJim Ingham         }
15415a988416SJim Ingham         else
15425a988416SJim Ingham         {
15435a988416SJim Ingham             // Particular breakpoints selected; show info about that breakpoint.
15445a988416SJim Ingham             BreakpointIDList valid_bp_ids;
15455e09c8c3SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
15465a988416SJim Ingham 
15475a988416SJim Ingham             if (result.Succeeded())
15485a988416SJim Ingham             {
15495a988416SJim Ingham                 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
15505a988416SJim Ingham                 {
15515a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
15525a988416SJim Ingham                     Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
15535a988416SJim Ingham                     AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
15545a988416SJim Ingham                 }
15555a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
15565a988416SJim Ingham             }
15575a988416SJim Ingham             else
15585a988416SJim Ingham             {
15595a988416SJim Ingham                 result.AppendError ("Invalid breakpoint id.");
15605a988416SJim Ingham                 result.SetStatus (eReturnStatusFailed);
15615a988416SJim Ingham             }
15625a988416SJim Ingham         }
15635a988416SJim Ingham 
15645a988416SJim Ingham         return result.Succeeded();
15655a988416SJim Ingham     }
15665a988416SJim Ingham 
15675a988416SJim Ingham private:
15685a988416SJim Ingham     CommandOptions m_options;
15695a988416SJim Ingham };
15705a988416SJim Ingham 
15715a988416SJim Ingham #pragma mark List::CommandOptions
15725a988416SJim Ingham OptionDefinition
15735a988416SJim Ingham CommandObjectBreakpointList::CommandOptions::g_option_table[] =
15745a988416SJim Ingham {
15759e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
15765a988416SJim Ingham         "Show debugger internal breakpoints" },
15775a988416SJim Ingham 
15789e85e5a8SEugene Zelenko     { LLDB_OPT_SET_1, false, "brief",    'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
15795a988416SJim Ingham         "Give a brief description of the breakpoint (no location info)."},
15805a988416SJim Ingham 
15815a988416SJim Ingham     // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
15825a988416SJim Ingham     // But I need to see it for now, and don't want to wait.
15839e85e5a8SEugene Zelenko     { LLDB_OPT_SET_2, false, "full",    'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
15845a988416SJim Ingham         "Give a full description of the breakpoint and its locations."},
15855a988416SJim Ingham 
15869e85e5a8SEugene Zelenko     { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
15875a988416SJim Ingham         "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
15885a988416SJim Ingham 
15899e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
159033df7cd3SJim Ingham         "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
159133df7cd3SJim Ingham 
15929e85e5a8SEugene Zelenko     { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
15935a988416SJim Ingham };
15945a988416SJim Ingham 
15955a988416SJim Ingham //-------------------------------------------------------------------------
15965a988416SJim Ingham // CommandObjectBreakpointClear
15975a988416SJim Ingham //-------------------------------------------------------------------------
15985a988416SJim Ingham #pragma mark Clear
15995a988416SJim Ingham 
16005a988416SJim Ingham class CommandObjectBreakpointClear : public CommandObjectParsed
16015a988416SJim Ingham {
16025a988416SJim Ingham public:
16035a988416SJim Ingham     typedef enum BreakpointClearType
16045a988416SJim Ingham     {
16055a988416SJim Ingham         eClearTypeInvalid,
16065a988416SJim Ingham         eClearTypeFileAndLine
16075a988416SJim Ingham     } BreakpointClearType;
16085a988416SJim Ingham 
16095a988416SJim Ingham     CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
16105a988416SJim Ingham         CommandObjectParsed (interpreter,
16115a988416SJim Ingham                              "breakpoint clear",
16125a988416SJim Ingham                              "Clears a breakpoint or set of breakpoints in the executable.",
16135a988416SJim Ingham                              "breakpoint clear <cmd-options>"),
16145a988416SJim Ingham         m_options (interpreter)
16155a988416SJim Ingham     {
16165a988416SJim Ingham     }
16175a988416SJim Ingham 
16189e85e5a8SEugene Zelenko     ~CommandObjectBreakpointClear() override = default;
16195a988416SJim Ingham 
162013d21e9aSBruce Mitchener     Options *
162113d21e9aSBruce Mitchener     GetOptions () override
16225a988416SJim Ingham     {
16235a988416SJim Ingham         return &m_options;
16245a988416SJim Ingham     }
16255a988416SJim Ingham 
16265a988416SJim Ingham     class CommandOptions : public Options
16275a988416SJim Ingham     {
16285a988416SJim Ingham     public:
16295a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
16305a988416SJim Ingham             Options (interpreter),
16315a988416SJim Ingham             m_filename (),
16325a988416SJim Ingham             m_line_num (0)
16335a988416SJim Ingham         {
16345a988416SJim Ingham         }
16355a988416SJim Ingham 
16369e85e5a8SEugene Zelenko         ~CommandOptions() override = default;
16375a988416SJim Ingham 
163813d21e9aSBruce Mitchener         Error
163913d21e9aSBruce Mitchener         SetOptionValue (uint32_t option_idx, const char *option_arg) override
16405a988416SJim Ingham         {
16415a988416SJim Ingham             Error error;
16423bcdfc0eSGreg Clayton             const int short_option = m_getopt_table[option_idx].val;
16435a988416SJim Ingham 
16445a988416SJim Ingham             switch (short_option)
16455a988416SJim Ingham             {
16465a988416SJim Ingham                 case 'f':
16475a988416SJim Ingham                     m_filename.assign (option_arg);
16485a988416SJim Ingham                     break;
16495a988416SJim Ingham 
16505a988416SJim Ingham                 case 'l':
16515275aaa0SVince Harron                     m_line_num = StringConvert::ToUInt32 (option_arg, 0);
16525a988416SJim Ingham                     break;
16535a988416SJim Ingham 
16545a988416SJim Ingham                 default:
16555a988416SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
16565a988416SJim Ingham                     break;
16575a988416SJim Ingham             }
16585a988416SJim Ingham 
16595a988416SJim Ingham             return error;
16605a988416SJim Ingham         }
16615a988416SJim Ingham 
16625a988416SJim Ingham         void
166313d21e9aSBruce Mitchener         OptionParsingStarting () override
16645a988416SJim Ingham         {
16655a988416SJim Ingham             m_filename.clear();
16665a988416SJim Ingham             m_line_num = 0;
16675a988416SJim Ingham         }
16685a988416SJim Ingham 
16695a988416SJim Ingham         const OptionDefinition*
167013d21e9aSBruce Mitchener         GetDefinitions () override
16715a988416SJim Ingham         {
16725a988416SJim Ingham             return g_option_table;
16735a988416SJim Ingham         }
16745a988416SJim Ingham 
16755a988416SJim Ingham         // Options table: Required for subclasses of Options.
16765a988416SJim Ingham 
16775a988416SJim Ingham         static OptionDefinition g_option_table[];
16785a988416SJim Ingham 
16795a988416SJim Ingham         // Instance variables to hold the values for command options.
16805a988416SJim Ingham 
16815a988416SJim Ingham         std::string m_filename;
16825a988416SJim Ingham         uint32_t m_line_num;
16835a988416SJim Ingham 
16845a988416SJim Ingham     };
16855a988416SJim Ingham 
16865a988416SJim Ingham protected:
168713d21e9aSBruce Mitchener     bool
168813d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
16895a988416SJim Ingham     {
1690893c932aSJim Ingham         Target *target = GetSelectedOrDummyTarget();
16919e85e5a8SEugene Zelenko         if (target == nullptr)
16925a988416SJim Ingham         {
16935a988416SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
16945a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
16955a988416SJim Ingham             return false;
16965a988416SJim Ingham         }
16975a988416SJim Ingham 
16985a988416SJim Ingham         // The following are the various types of breakpoints that could be cleared:
16995a988416SJim Ingham         //   1). -f -l (clearing breakpoint by source location)
17005a988416SJim Ingham 
17015a988416SJim Ingham         BreakpointClearType break_type = eClearTypeInvalid;
17025a988416SJim Ingham 
17035a988416SJim Ingham         if (m_options.m_line_num != 0)
17045a988416SJim Ingham             break_type = eClearTypeFileAndLine;
17055a988416SJim Ingham 
17065a988416SJim Ingham         Mutex::Locker locker;
17075a988416SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
17085a988416SJim Ingham 
17095a988416SJim Ingham         BreakpointList &breakpoints = target->GetBreakpointList();
17105a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
17115a988416SJim Ingham 
17125a988416SJim Ingham         // Early return if there's no breakpoint at all.
17135a988416SJim Ingham         if (num_breakpoints == 0)
17145a988416SJim Ingham         {
17155a988416SJim Ingham             result.AppendError ("Breakpoint clear: No breakpoint cleared.");
17165a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
17175a988416SJim Ingham             return result.Succeeded();
17185a988416SJim Ingham         }
17195a988416SJim Ingham 
17205a988416SJim Ingham         // Find matching breakpoints and delete them.
17215a988416SJim Ingham 
17225a988416SJim Ingham         // First create a copy of all the IDs.
17235a988416SJim Ingham         std::vector<break_id_t> BreakIDs;
17245a988416SJim Ingham         for (size_t i = 0; i < num_breakpoints; ++i)
17259e85e5a8SEugene Zelenko             BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID());
17265a988416SJim Ingham 
17275a988416SJim Ingham         int num_cleared = 0;
17285a988416SJim Ingham         StreamString ss;
17295a988416SJim Ingham         switch (break_type)
17305a988416SJim Ingham         {
17315a988416SJim Ingham             case eClearTypeFileAndLine: // Breakpoint by source position
17325a988416SJim Ingham                 {
17335a988416SJim Ingham                     const ConstString filename(m_options.m_filename.c_str());
17345a988416SJim Ingham                     BreakpointLocationCollection loc_coll;
17355a988416SJim Ingham 
17365a988416SJim Ingham                     for (size_t i = 0; i < num_breakpoints; ++i)
17375a988416SJim Ingham                     {
17385a988416SJim Ingham                         Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
17395a988416SJim Ingham 
17405a988416SJim Ingham                         if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
17415a988416SJim Ingham                         {
17425a988416SJim Ingham                             // If the collection size is 0, it's a full match and we can just remove the breakpoint.
17435a988416SJim Ingham                             if (loc_coll.GetSize() == 0)
17445a988416SJim Ingham                             {
17455a988416SJim Ingham                                 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
17465a988416SJim Ingham                                 ss.EOL();
17475a988416SJim Ingham                                 target->RemoveBreakpointByID (bp->GetID());
17485a988416SJim Ingham                                 ++num_cleared;
17495a988416SJim Ingham                             }
17505a988416SJim Ingham                         }
17515a988416SJim Ingham                     }
17525a988416SJim Ingham                 }
17535a988416SJim Ingham                 break;
17545a988416SJim Ingham 
17555a988416SJim Ingham             default:
17565a988416SJim Ingham                 break;
17575a988416SJim Ingham         }
17585a988416SJim Ingham 
17595a988416SJim Ingham         if (num_cleared > 0)
17605a988416SJim Ingham         {
17615a988416SJim Ingham             Stream &output_stream = result.GetOutputStream();
17625a988416SJim Ingham             output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
17635a988416SJim Ingham             output_stream << ss.GetData();
17645a988416SJim Ingham             output_stream.EOL();
17655a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
17665a988416SJim Ingham         }
17675a988416SJim Ingham         else
17685a988416SJim Ingham         {
17695a988416SJim Ingham             result.AppendError ("Breakpoint clear: No breakpoint cleared.");
17705a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
17715a988416SJim Ingham         }
17725a988416SJim Ingham 
17735a988416SJim Ingham         return result.Succeeded();
17745a988416SJim Ingham     }
17755a988416SJim Ingham 
17765a988416SJim Ingham private:
17775a988416SJim Ingham     CommandOptions m_options;
17785a988416SJim Ingham };
17795a988416SJim Ingham 
17805a988416SJim Ingham #pragma mark Clear::CommandOptions
17815a988416SJim Ingham 
17825a988416SJim Ingham OptionDefinition
17835a988416SJim Ingham CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
17845a988416SJim Ingham {
17859e85e5a8SEugene Zelenko     { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
17865a988416SJim Ingham         "Specify the breakpoint by source location in this particular file."},
17875a988416SJim Ingham 
17889e85e5a8SEugene Zelenko     { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum,
17895a988416SJim Ingham         "Specify the breakpoint by source location at this particular line."},
17905a988416SJim Ingham 
17919e85e5a8SEugene Zelenko     { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
17925a988416SJim Ingham };
17935a988416SJim Ingham 
17945a988416SJim Ingham //-------------------------------------------------------------------------
17955a988416SJim Ingham // CommandObjectBreakpointDelete
17965a988416SJim Ingham //-------------------------------------------------------------------------
17975a988416SJim Ingham #pragma mark Delete
17985a988416SJim Ingham 
17995a988416SJim Ingham class CommandObjectBreakpointDelete : public CommandObjectParsed
18005a988416SJim Ingham {
18015a988416SJim Ingham public:
18025a988416SJim Ingham     CommandObjectBreakpointDelete (CommandInterpreter &interpreter) :
18035a988416SJim Ingham         CommandObjectParsed(interpreter,
18045a988416SJim Ingham                             "breakpoint delete",
18055a988416SJim Ingham                             "Delete the specified breakpoint(s).  If no breakpoints are specified, delete them all.",
18069e85e5a8SEugene Zelenko                             nullptr),
180733df7cd3SJim Ingham         m_options (interpreter)
18085a988416SJim Ingham     {
18095a988416SJim Ingham         CommandArgumentEntry arg;
18105a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
18115a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
18125a988416SJim Ingham         m_arguments.push_back (arg);
18135a988416SJim Ingham     }
18145a988416SJim Ingham 
18159e85e5a8SEugene Zelenko     ~CommandObjectBreakpointDelete() override = default;
18165a988416SJim Ingham 
181713d21e9aSBruce Mitchener     Options *
181813d21e9aSBruce Mitchener     GetOptions () override
181933df7cd3SJim Ingham     {
182033df7cd3SJim Ingham         return &m_options;
182133df7cd3SJim Ingham     }
182233df7cd3SJim Ingham 
182333df7cd3SJim Ingham     class CommandOptions : public Options
182433df7cd3SJim Ingham     {
182533df7cd3SJim Ingham     public:
182633df7cd3SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
182733df7cd3SJim Ingham             Options (interpreter),
182833df7cd3SJim Ingham             m_use_dummy (false),
182933df7cd3SJim Ingham             m_force (false)
183033df7cd3SJim Ingham         {
183133df7cd3SJim Ingham         }
183233df7cd3SJim Ingham 
18339e85e5a8SEugene Zelenko         ~CommandOptions() override = default;
183433df7cd3SJim Ingham 
183513d21e9aSBruce Mitchener         Error
183613d21e9aSBruce Mitchener         SetOptionValue (uint32_t option_idx, const char *option_arg) override
183733df7cd3SJim Ingham         {
183833df7cd3SJim Ingham             Error error;
183933df7cd3SJim Ingham             const int short_option = m_getopt_table[option_idx].val;
184033df7cd3SJim Ingham 
184133df7cd3SJim Ingham             switch (short_option)
184233df7cd3SJim Ingham             {
184333df7cd3SJim Ingham                 case 'f':
184433df7cd3SJim Ingham                     m_force = true;
184533df7cd3SJim Ingham                     break;
184633df7cd3SJim Ingham 
184733df7cd3SJim Ingham                 case 'D':
184833df7cd3SJim Ingham                     m_use_dummy = true;
184933df7cd3SJim Ingham                     break;
185033df7cd3SJim Ingham 
185133df7cd3SJim Ingham                 default:
185233df7cd3SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
185333df7cd3SJim Ingham                     break;
185433df7cd3SJim Ingham             }
185533df7cd3SJim Ingham 
185633df7cd3SJim Ingham             return error;
185733df7cd3SJim Ingham         }
185833df7cd3SJim Ingham 
185933df7cd3SJim Ingham         void
186013d21e9aSBruce Mitchener         OptionParsingStarting () override
186133df7cd3SJim Ingham         {
186233df7cd3SJim Ingham             m_use_dummy = false;
186333df7cd3SJim Ingham             m_force = false;
186433df7cd3SJim Ingham         }
186533df7cd3SJim Ingham 
186633df7cd3SJim Ingham         const OptionDefinition*
186713d21e9aSBruce Mitchener         GetDefinitions () override
186833df7cd3SJim Ingham         {
186933df7cd3SJim Ingham             return g_option_table;
187033df7cd3SJim Ingham         }
187133df7cd3SJim Ingham 
187233df7cd3SJim Ingham         // Options table: Required for subclasses of Options.
187333df7cd3SJim Ingham 
187433df7cd3SJim Ingham         static OptionDefinition g_option_table[];
187533df7cd3SJim Ingham 
187633df7cd3SJim Ingham         // Instance variables to hold the values for command options.
187733df7cd3SJim Ingham         bool m_use_dummy;
187833df7cd3SJim Ingham         bool m_force;
187933df7cd3SJim Ingham     };
188033df7cd3SJim Ingham 
18815a988416SJim Ingham protected:
188213d21e9aSBruce Mitchener     bool
188313d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
18845a988416SJim Ingham     {
188533df7cd3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
188633df7cd3SJim Ingham 
18879e85e5a8SEugene Zelenko         if (target == nullptr)
18885a988416SJim Ingham         {
18895a988416SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
18905a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
18915a988416SJim Ingham             return false;
18925a988416SJim Ingham         }
18935a988416SJim Ingham 
18945a988416SJim Ingham         Mutex::Locker locker;
18955a988416SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
18965a988416SJim Ingham 
18975a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
18985a988416SJim Ingham 
18995a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
19005a988416SJim Ingham 
19015a988416SJim Ingham         if (num_breakpoints == 0)
19025a988416SJim Ingham         {
19035a988416SJim Ingham             result.AppendError ("No breakpoints exist to be deleted.");
19045a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
19055a988416SJim Ingham             return false;
19065a988416SJim Ingham         }
19075a988416SJim Ingham 
19085a988416SJim Ingham         if (command.GetArgumentCount() == 0)
19095a988416SJim Ingham         {
191033df7cd3SJim Ingham             if (!m_options.m_force && !m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
19115a988416SJim Ingham             {
19125a988416SJim Ingham                 result.AppendMessage("Operation cancelled...");
19135a988416SJim Ingham             }
19145a988416SJim Ingham             else
19155a988416SJim Ingham             {
19165a988416SJim Ingham                 target->RemoveAllBreakpoints ();
19176fea17e8SGreg Clayton                 result.AppendMessageWithFormat ("All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : "");
19185a988416SJim Ingham             }
19195a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
19205a988416SJim Ingham         }
19215a988416SJim Ingham         else
19225a988416SJim Ingham         {
19235a988416SJim Ingham             // Particular breakpoint selected; disable that breakpoint.
19245a988416SJim Ingham             BreakpointIDList valid_bp_ids;
19255e09c8c3SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
19265a988416SJim Ingham 
19275a988416SJim Ingham             if (result.Succeeded())
19285a988416SJim Ingham             {
19295a988416SJim Ingham                 int delete_count = 0;
19305a988416SJim Ingham                 int disable_count = 0;
19315a988416SJim Ingham                 const size_t count = valid_bp_ids.GetSize();
19325a988416SJim Ingham                 for (size_t i = 0; i < count; ++i)
19335a988416SJim Ingham                 {
19345a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
19355a988416SJim Ingham 
19365a988416SJim Ingham                     if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
19375a988416SJim Ingham                     {
19385a988416SJim Ingham                         if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
19395a988416SJim Ingham                         {
19405a988416SJim Ingham                             Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
19415a988416SJim Ingham                             BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
19425a988416SJim Ingham                             // It makes no sense to try to delete individual locations, so we disable them instead.
19435a988416SJim Ingham                             if (location)
19445a988416SJim Ingham                             {
19455a988416SJim Ingham                                 location->SetEnabled (false);
19465a988416SJim Ingham                                 ++disable_count;
19475a988416SJim Ingham                             }
19485a988416SJim Ingham                         }
19495a988416SJim Ingham                         else
19505a988416SJim Ingham                         {
19515a988416SJim Ingham                             target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
19525a988416SJim Ingham                             ++delete_count;
19535a988416SJim Ingham                         }
19545a988416SJim Ingham                     }
19555a988416SJim Ingham                 }
19565a988416SJim Ingham                 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
19575a988416SJim Ingham                                                delete_count, disable_count);
19585a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
19595a988416SJim Ingham             }
19605a988416SJim Ingham         }
19615a988416SJim Ingham         return result.Succeeded();
19625a988416SJim Ingham     }
19639e85e5a8SEugene Zelenko 
196433df7cd3SJim Ingham private:
196533df7cd3SJim Ingham     CommandOptions m_options;
196633df7cd3SJim Ingham };
196733df7cd3SJim Ingham 
196833df7cd3SJim Ingham OptionDefinition
196933df7cd3SJim Ingham CommandObjectBreakpointDelete::CommandOptions::g_option_table[] =
197033df7cd3SJim Ingham {
19719e85e5a8SEugene Zelenko     { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
197233df7cd3SJim Ingham         "Delete all breakpoints without querying for confirmation."},
197333df7cd3SJim Ingham 
19749e85e5a8SEugene Zelenko     { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
197533df7cd3SJim Ingham         "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
197633df7cd3SJim Ingham 
19779e85e5a8SEugene Zelenko     { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
19785a988416SJim Ingham };
19795a988416SJim Ingham 
198030fdc8d8SChris Lattner //-------------------------------------------------------------------------
19815e09c8c3SJim Ingham // CommandObjectBreakpointName
19825e09c8c3SJim Ingham //-------------------------------------------------------------------------
19835e09c8c3SJim Ingham 
19845e09c8c3SJim Ingham static OptionDefinition
19855e09c8c3SJim Ingham g_breakpoint_name_options[] =
19865e09c8c3SJim Ingham {
19879e85e5a8SEugene Zelenko     { LLDB_OPT_SET_1,   false, "name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."},
19889e85e5a8SEugene Zelenko     { LLDB_OPT_SET_2,   false, "breakpoint-id", 'B', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointID,   "Specify a breakpoint id to use."},
19899e85e5a8SEugene Zelenko     { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
19905e09c8c3SJim Ingham         "Operate on Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
19915e09c8c3SJim Ingham };
19925e09c8c3SJim Ingham class BreakpointNameOptionGroup : public OptionGroup
19935e09c8c3SJim Ingham {
19945e09c8c3SJim Ingham public:
19955e09c8c3SJim Ingham     BreakpointNameOptionGroup() :
19965e09c8c3SJim Ingham         OptionGroup(),
19975e09c8c3SJim Ingham         m_breakpoint(LLDB_INVALID_BREAK_ID),
19985e09c8c3SJim Ingham         m_use_dummy (false)
19995e09c8c3SJim Ingham     {
20005e09c8c3SJim Ingham     }
20015e09c8c3SJim Ingham 
20029e85e5a8SEugene Zelenko     ~BreakpointNameOptionGroup() override = default;
20035e09c8c3SJim Ingham 
200413d21e9aSBruce Mitchener     uint32_t
200513d21e9aSBruce Mitchener     GetNumDefinitions () override
20065e09c8c3SJim Ingham     {
20075e09c8c3SJim Ingham       return sizeof (g_breakpoint_name_options) / sizeof (OptionDefinition);
20085e09c8c3SJim Ingham     }
20095e09c8c3SJim Ingham 
201013d21e9aSBruce Mitchener     const OptionDefinition*
201113d21e9aSBruce Mitchener     GetDefinitions () override
20125e09c8c3SJim Ingham     {
20135e09c8c3SJim Ingham         return g_breakpoint_name_options;
20145e09c8c3SJim Ingham     }
20155e09c8c3SJim Ingham 
201613d21e9aSBruce Mitchener     Error
20175e09c8c3SJim Ingham     SetOptionValue (CommandInterpreter &interpreter,
20185e09c8c3SJim Ingham                     uint32_t option_idx,
201913d21e9aSBruce Mitchener                     const char *option_value) override
20205e09c8c3SJim Ingham     {
20215e09c8c3SJim Ingham         Error error;
20225e09c8c3SJim Ingham         const int short_option = g_breakpoint_name_options[option_idx].short_option;
20235e09c8c3SJim Ingham 
20245e09c8c3SJim Ingham         switch (short_option)
20255e09c8c3SJim Ingham         {
20265e09c8c3SJim Ingham         case 'N':
20275e09c8c3SJim Ingham             if (BreakpointID::StringIsBreakpointName(option_value, error) && error.Success())
2028c95f7e2aSPavel Labath                 m_name.SetValueFromString(option_value);
20295e09c8c3SJim Ingham             break;
20305e09c8c3SJim Ingham 
20315e09c8c3SJim Ingham         case 'B':
2032c95f7e2aSPavel Labath             if (m_breakpoint.SetValueFromString(option_value).Fail())
20335e09c8c3SJim Ingham                 error.SetErrorStringWithFormat ("unrecognized value \"%s\" for breakpoint", option_value);
20345e09c8c3SJim Ingham             break;
20355e09c8c3SJim Ingham         case 'D':
2036c95f7e2aSPavel Labath             if (m_use_dummy.SetValueFromString(option_value).Fail())
20375e09c8c3SJim Ingham                 error.SetErrorStringWithFormat ("unrecognized value \"%s\" for use-dummy", option_value);
20385e09c8c3SJim Ingham             break;
20395e09c8c3SJim Ingham 
20405e09c8c3SJim Ingham         default:
20415e09c8c3SJim Ingham               error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
20425e09c8c3SJim Ingham               break;
20435e09c8c3SJim Ingham         }
20445e09c8c3SJim Ingham         return error;
20455e09c8c3SJim Ingham     }
20465e09c8c3SJim Ingham 
204713d21e9aSBruce Mitchener     void
204813d21e9aSBruce Mitchener     OptionParsingStarting (CommandInterpreter &interpreter) override
20495e09c8c3SJim Ingham     {
20505e09c8c3SJim Ingham         m_name.Clear();
20515e09c8c3SJim Ingham         m_breakpoint.Clear();
20525e09c8c3SJim Ingham         m_use_dummy.Clear();
20535e09c8c3SJim Ingham         m_use_dummy.SetDefaultValue(false);
20545e09c8c3SJim Ingham     }
20555e09c8c3SJim Ingham 
20565e09c8c3SJim Ingham     OptionValueString m_name;
20575e09c8c3SJim Ingham     OptionValueUInt64 m_breakpoint;
20585e09c8c3SJim Ingham     OptionValueBoolean m_use_dummy;
20595e09c8c3SJim Ingham };
20605e09c8c3SJim Ingham 
20615e09c8c3SJim Ingham class CommandObjectBreakpointNameAdd : public CommandObjectParsed
20625e09c8c3SJim Ingham {
20635e09c8c3SJim Ingham public:
20645e09c8c3SJim Ingham     CommandObjectBreakpointNameAdd (CommandInterpreter &interpreter) :
20655e09c8c3SJim Ingham         CommandObjectParsed (interpreter,
20665e09c8c3SJim Ingham                              "add",
20675e09c8c3SJim Ingham                              "Add a name to the breakpoints provided.",
20685e09c8c3SJim Ingham                              "breakpoint name add <command-options> <breakpoint-id-list>"),
20695e09c8c3SJim Ingham         m_name_options(),
20705e09c8c3SJim Ingham         m_option_group(interpreter)
20715e09c8c3SJim Ingham         {
20725e09c8c3SJim Ingham             // Create the first variant for the first (and only) argument for this command.
20735e09c8c3SJim Ingham             CommandArgumentEntry arg1;
20745e09c8c3SJim Ingham             CommandArgumentData id_arg;
20755e09c8c3SJim Ingham             id_arg.arg_type = eArgTypeBreakpointID;
20765e09c8c3SJim Ingham             id_arg.arg_repetition = eArgRepeatOptional;
20775e09c8c3SJim Ingham             arg1.push_back(id_arg);
20785e09c8c3SJim Ingham             m_arguments.push_back (arg1);
20795e09c8c3SJim Ingham 
20805e09c8c3SJim Ingham             m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
20815e09c8c3SJim Ingham             m_option_group.Finalize();
20825e09c8c3SJim Ingham         }
20835e09c8c3SJim Ingham 
20849e85e5a8SEugene Zelenko     ~CommandObjectBreakpointNameAdd() override = default;
20855e09c8c3SJim Ingham 
20865e09c8c3SJim Ingham     Options *
208713d21e9aSBruce Mitchener     GetOptions() override
20885e09c8c3SJim Ingham     {
20895e09c8c3SJim Ingham         return &m_option_group;
20905e09c8c3SJim Ingham     }
20915e09c8c3SJim Ingham 
20925e09c8c3SJim Ingham protected:
209313d21e9aSBruce Mitchener     bool
209413d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
20955e09c8c3SJim Ingham     {
20965e09c8c3SJim Ingham         if (!m_name_options.m_name.OptionWasSet())
20975e09c8c3SJim Ingham         {
20985e09c8c3SJim Ingham             result.SetError("No name option provided.");
20995e09c8c3SJim Ingham             return false;
21005e09c8c3SJim Ingham         }
21015e09c8c3SJim Ingham 
21025e09c8c3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
21035e09c8c3SJim Ingham 
21049e85e5a8SEugene Zelenko         if (target == nullptr)
21055e09c8c3SJim Ingham         {
21065e09c8c3SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
21075e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
21085e09c8c3SJim Ingham             return false;
21095e09c8c3SJim Ingham         }
21105e09c8c3SJim Ingham 
21115e09c8c3SJim Ingham         Mutex::Locker locker;
21125e09c8c3SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
21135e09c8c3SJim Ingham 
21145e09c8c3SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
21155e09c8c3SJim Ingham 
21165e09c8c3SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
21175e09c8c3SJim Ingham         if (num_breakpoints == 0)
21185e09c8c3SJim Ingham         {
21195e09c8c3SJim Ingham             result.SetError("No breakpoints, cannot add names.");
21205e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
21215e09c8c3SJim Ingham             return false;
21225e09c8c3SJim Ingham         }
21235e09c8c3SJim Ingham 
21245e09c8c3SJim Ingham         // Particular breakpoint selected; disable that breakpoint.
21255e09c8c3SJim Ingham         BreakpointIDList valid_bp_ids;
21265e09c8c3SJim Ingham         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
21275e09c8c3SJim Ingham 
21285e09c8c3SJim Ingham         if (result.Succeeded())
21295e09c8c3SJim Ingham         {
21305e09c8c3SJim Ingham             if (valid_bp_ids.GetSize() == 0)
21315e09c8c3SJim Ingham             {
21325e09c8c3SJim Ingham                 result.SetError("No breakpoints specified, cannot add names.");
21335e09c8c3SJim Ingham                 result.SetStatus (eReturnStatusFailed);
21345e09c8c3SJim Ingham                 return false;
21355e09c8c3SJim Ingham             }
21365e09c8c3SJim Ingham             size_t num_valid_ids = valid_bp_ids.GetSize();
21375e09c8c3SJim Ingham             for (size_t index = 0; index < num_valid_ids; index++)
21385e09c8c3SJim Ingham             {
21395e09c8c3SJim Ingham                 lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
21405e09c8c3SJim Ingham                 BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
21415e09c8c3SJim Ingham                 Error error;  // We don't need to check the error here, since the option parser checked it...
21425e09c8c3SJim Ingham                 bp_sp->AddName(m_name_options.m_name.GetCurrentValue(), error);
21435e09c8c3SJim Ingham             }
21445e09c8c3SJim Ingham         }
21455e09c8c3SJim Ingham 
21465e09c8c3SJim Ingham         return true;
21475e09c8c3SJim Ingham     }
21485e09c8c3SJim Ingham 
21495e09c8c3SJim Ingham private:
21505e09c8c3SJim Ingham     BreakpointNameOptionGroup m_name_options;
21515e09c8c3SJim Ingham     OptionGroupOptions m_option_group;
21525e09c8c3SJim Ingham };
21535e09c8c3SJim Ingham 
21545e09c8c3SJim Ingham class CommandObjectBreakpointNameDelete : public CommandObjectParsed
21555e09c8c3SJim Ingham {
21565e09c8c3SJim Ingham public:
21575e09c8c3SJim Ingham     CommandObjectBreakpointNameDelete (CommandInterpreter &interpreter) :
21585e09c8c3SJim Ingham         CommandObjectParsed (interpreter,
21595e09c8c3SJim Ingham                              "delete",
21605e09c8c3SJim Ingham                              "Delete a name from the breakpoints provided.",
21615e09c8c3SJim Ingham                              "breakpoint name delete <command-options> <breakpoint-id-list>"),
21625e09c8c3SJim Ingham         m_name_options(),
21635e09c8c3SJim Ingham         m_option_group(interpreter)
21645e09c8c3SJim Ingham     {
21655e09c8c3SJim Ingham         // Create the first variant for the first (and only) argument for this command.
21665e09c8c3SJim Ingham         CommandArgumentEntry arg1;
21675e09c8c3SJim Ingham         CommandArgumentData id_arg;
21685e09c8c3SJim Ingham         id_arg.arg_type = eArgTypeBreakpointID;
21695e09c8c3SJim Ingham         id_arg.arg_repetition = eArgRepeatOptional;
21705e09c8c3SJim Ingham         arg1.push_back(id_arg);
21715e09c8c3SJim Ingham         m_arguments.push_back (arg1);
21725e09c8c3SJim Ingham 
21735e09c8c3SJim Ingham         m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
21745e09c8c3SJim Ingham         m_option_group.Finalize();
21755e09c8c3SJim Ingham     }
21765e09c8c3SJim Ingham 
21779e85e5a8SEugene Zelenko     ~CommandObjectBreakpointNameDelete() override = default;
21785e09c8c3SJim Ingham 
21795e09c8c3SJim Ingham     Options *
218013d21e9aSBruce Mitchener     GetOptions() override
21815e09c8c3SJim Ingham     {
21825e09c8c3SJim Ingham         return &m_option_group;
21835e09c8c3SJim Ingham     }
21845e09c8c3SJim Ingham 
21855e09c8c3SJim Ingham protected:
218613d21e9aSBruce Mitchener     bool
218713d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
21885e09c8c3SJim Ingham     {
21895e09c8c3SJim Ingham         if (!m_name_options.m_name.OptionWasSet())
21905e09c8c3SJim Ingham         {
21915e09c8c3SJim Ingham             result.SetError("No name option provided.");
21925e09c8c3SJim Ingham             return false;
21935e09c8c3SJim Ingham         }
21945e09c8c3SJim Ingham 
21955e09c8c3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
21965e09c8c3SJim Ingham 
21979e85e5a8SEugene Zelenko         if (target == nullptr)
21985e09c8c3SJim Ingham         {
21995e09c8c3SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
22005e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
22015e09c8c3SJim Ingham             return false;
22025e09c8c3SJim Ingham         }
22035e09c8c3SJim Ingham 
22045e09c8c3SJim Ingham         Mutex::Locker locker;
22055e09c8c3SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
22065e09c8c3SJim Ingham 
22075e09c8c3SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
22085e09c8c3SJim Ingham 
22095e09c8c3SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
22105e09c8c3SJim Ingham         if (num_breakpoints == 0)
22115e09c8c3SJim Ingham         {
22125e09c8c3SJim Ingham             result.SetError("No breakpoints, cannot delete names.");
22135e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
22145e09c8c3SJim Ingham             return false;
22155e09c8c3SJim Ingham         }
22165e09c8c3SJim Ingham 
22175e09c8c3SJim Ingham         // Particular breakpoint selected; disable that breakpoint.
22185e09c8c3SJim Ingham         BreakpointIDList valid_bp_ids;
22195e09c8c3SJim Ingham         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
22205e09c8c3SJim Ingham 
22215e09c8c3SJim Ingham         if (result.Succeeded())
22225e09c8c3SJim Ingham         {
22235e09c8c3SJim Ingham             if (valid_bp_ids.GetSize() == 0)
22245e09c8c3SJim Ingham             {
22255e09c8c3SJim Ingham                 result.SetError("No breakpoints specified, cannot delete names.");
22265e09c8c3SJim Ingham                 result.SetStatus (eReturnStatusFailed);
22275e09c8c3SJim Ingham                 return false;
22285e09c8c3SJim Ingham             }
22295e09c8c3SJim Ingham             size_t num_valid_ids = valid_bp_ids.GetSize();
22305e09c8c3SJim Ingham             for (size_t index = 0; index < num_valid_ids; index++)
22315e09c8c3SJim Ingham             {
22325e09c8c3SJim Ingham                 lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
22335e09c8c3SJim Ingham                 BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
22345e09c8c3SJim Ingham                 bp_sp->RemoveName(m_name_options.m_name.GetCurrentValue());
22355e09c8c3SJim Ingham             }
22365e09c8c3SJim Ingham         }
22375e09c8c3SJim Ingham 
22385e09c8c3SJim Ingham         return true;
22395e09c8c3SJim Ingham     }
22405e09c8c3SJim Ingham 
22415e09c8c3SJim Ingham private:
22425e09c8c3SJim Ingham     BreakpointNameOptionGroup m_name_options;
22435e09c8c3SJim Ingham     OptionGroupOptions m_option_group;
22445e09c8c3SJim Ingham };
22455e09c8c3SJim Ingham 
22465e09c8c3SJim Ingham class CommandObjectBreakpointNameList : public CommandObjectParsed
22475e09c8c3SJim Ingham {
22485e09c8c3SJim Ingham public:
22495e09c8c3SJim Ingham     CommandObjectBreakpointNameList (CommandInterpreter &interpreter) :
22505e09c8c3SJim Ingham         CommandObjectParsed (interpreter,
22515e09c8c3SJim Ingham                              "list",
22525e09c8c3SJim Ingham                              "List either the names for a breakpoint or the breakpoints for a given name.",
22535e09c8c3SJim Ingham                              "breakpoint name list <command-options>"),
22545e09c8c3SJim Ingham         m_name_options(),
22555e09c8c3SJim Ingham         m_option_group(interpreter)
22565e09c8c3SJim Ingham     {
22575e09c8c3SJim Ingham         m_option_group.Append (&m_name_options);
22585e09c8c3SJim Ingham         m_option_group.Finalize();
22595e09c8c3SJim Ingham     }
22605e09c8c3SJim Ingham 
22619e85e5a8SEugene Zelenko     ~CommandObjectBreakpointNameList() override = default;
22625e09c8c3SJim Ingham 
22635e09c8c3SJim Ingham     Options *
226413d21e9aSBruce Mitchener     GetOptions() override
22655e09c8c3SJim Ingham     {
22665e09c8c3SJim Ingham         return &m_option_group;
22675e09c8c3SJim Ingham     }
22685e09c8c3SJim Ingham 
22695e09c8c3SJim Ingham protected:
227013d21e9aSBruce Mitchener     bool
227113d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
22725e09c8c3SJim Ingham     {
22735e09c8c3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
22745e09c8c3SJim Ingham 
22759e85e5a8SEugene Zelenko         if (target == nullptr)
22765e09c8c3SJim Ingham         {
22775e09c8c3SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
22785e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
22795e09c8c3SJim Ingham             return false;
22805e09c8c3SJim Ingham         }
22815e09c8c3SJim Ingham 
22825e09c8c3SJim Ingham         if (m_name_options.m_name.OptionWasSet())
22835e09c8c3SJim Ingham         {
22845e09c8c3SJim Ingham             const char *name = m_name_options.m_name.GetCurrentValue();
22855e09c8c3SJim Ingham             Mutex::Locker locker;
22865e09c8c3SJim Ingham             target->GetBreakpointList().GetListMutex(locker);
22875e09c8c3SJim Ingham 
22885e09c8c3SJim Ingham             BreakpointList &breakpoints = target->GetBreakpointList();
22895e09c8c3SJim Ingham             for (BreakpointSP bp_sp : breakpoints.Breakpoints())
22905e09c8c3SJim Ingham             {
22915e09c8c3SJim Ingham                 if (bp_sp->MatchesName(name))
22925e09c8c3SJim Ingham                 {
22935e09c8c3SJim Ingham                     StreamString s;
22945e09c8c3SJim Ingham                     bp_sp->GetDescription(&s, eDescriptionLevelBrief);
22955e09c8c3SJim Ingham                     s.EOL();
22965e09c8c3SJim Ingham                     result.AppendMessage(s.GetData());
22975e09c8c3SJim Ingham                 }
22985e09c8c3SJim Ingham             }
22995e09c8c3SJim Ingham 
23005e09c8c3SJim Ingham         }
23015e09c8c3SJim Ingham         else if (m_name_options.m_breakpoint.OptionWasSet())
23025e09c8c3SJim Ingham         {
23035e09c8c3SJim Ingham             BreakpointSP bp_sp = target->GetBreakpointList().FindBreakpointByID(m_name_options.m_breakpoint.GetCurrentValue());
23045e09c8c3SJim Ingham             if (bp_sp)
23055e09c8c3SJim Ingham             {
23065e09c8c3SJim Ingham                 std::vector<std::string> names;
23075e09c8c3SJim Ingham                 bp_sp->GetNames (names);
23085e09c8c3SJim Ingham                 result.AppendMessage ("Names:");
23095e09c8c3SJim Ingham                 for (auto name : names)
23105e09c8c3SJim Ingham                     result.AppendMessageWithFormat ("    %s\n", name.c_str());
23115e09c8c3SJim Ingham             }
23125e09c8c3SJim Ingham             else
23135e09c8c3SJim Ingham             {
23145e09c8c3SJim Ingham                 result.AppendErrorWithFormat ("Could not find breakpoint %" PRId64 ".\n",
23155e09c8c3SJim Ingham                                            m_name_options.m_breakpoint.GetCurrentValue());
23165e09c8c3SJim Ingham                 result.SetStatus (eReturnStatusFailed);
23175e09c8c3SJim Ingham                 return false;
23185e09c8c3SJim Ingham             }
23195e09c8c3SJim Ingham         }
23205e09c8c3SJim Ingham         else
23215e09c8c3SJim Ingham         {
23225e09c8c3SJim Ingham             result.SetError ("Must specify -N or -B option to list.");
23235e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
23245e09c8c3SJim Ingham             return false;
23255e09c8c3SJim Ingham         }
23265e09c8c3SJim Ingham         return true;
23275e09c8c3SJim Ingham     }
23285e09c8c3SJim Ingham 
23295e09c8c3SJim Ingham private:
23305e09c8c3SJim Ingham     BreakpointNameOptionGroup m_name_options;
23315e09c8c3SJim Ingham     OptionGroupOptions m_option_group;
23325e09c8c3SJim Ingham };
23335e09c8c3SJim Ingham 
23345e09c8c3SJim Ingham //-------------------------------------------------------------------------
23355e09c8c3SJim Ingham // CommandObjectMultiwordBreakpoint
23365e09c8c3SJim Ingham //-------------------------------------------------------------------------
23375e09c8c3SJim Ingham class CommandObjectBreakpointName : public CommandObjectMultiword
23385e09c8c3SJim Ingham {
23395e09c8c3SJim Ingham public:
23405e09c8c3SJim Ingham     CommandObjectBreakpointName (CommandInterpreter &interpreter) :
23415e09c8c3SJim Ingham         CommandObjectMultiword(interpreter,
23425e09c8c3SJim Ingham                                 "name",
23435e09c8c3SJim Ingham                                 "A set of commands to manage name tags for breakpoints",
23445e09c8c3SJim Ingham                                 "breakpoint name <command> [<command-options>]")
23455e09c8c3SJim Ingham     {
23465e09c8c3SJim Ingham         CommandObjectSP add_command_object (new CommandObjectBreakpointNameAdd (interpreter));
23475e09c8c3SJim Ingham         CommandObjectSP delete_command_object (new CommandObjectBreakpointNameDelete (interpreter));
23485e09c8c3SJim Ingham         CommandObjectSP list_command_object (new CommandObjectBreakpointNameList (interpreter));
23495e09c8c3SJim Ingham 
23505e09c8c3SJim Ingham         LoadSubCommand ("add", add_command_object);
23515e09c8c3SJim Ingham         LoadSubCommand ("delete", delete_command_object);
23525e09c8c3SJim Ingham         LoadSubCommand ("list", list_command_object);
23535e09c8c3SJim Ingham     }
23545e09c8c3SJim Ingham 
23559e85e5a8SEugene Zelenko     ~CommandObjectBreakpointName() override = default;
23565e09c8c3SJim Ingham };
23575e09c8c3SJim Ingham 
23585e09c8c3SJim Ingham //-------------------------------------------------------------------------
235930fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint
236030fdc8d8SChris Lattner //-------------------------------------------------------------------------
2361ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint
236230fdc8d8SChris Lattner 
23636611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
2364a7015092SGreg Clayton     CommandObjectMultiword (interpreter,
2365a7015092SGreg Clayton                             "breakpoint",
236646fbc60fSJim Ingham                             "A set of commands for operating on breakpoints. Also see _regexp-break.",
236730fdc8d8SChris Lattner                             "breakpoint <command> [<command-options>]")
236830fdc8d8SChris Lattner {
2369a7015092SGreg Clayton     CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
2370a7015092SGreg Clayton     CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
2371a7015092SGreg Clayton     CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
2372b7234e40SJohnny Chen     CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
2373b7234e40SJohnny Chen     CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
2374a7015092SGreg Clayton     CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
237530fdc8d8SChris Lattner     CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
2376a7015092SGreg Clayton     CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
23775e09c8c3SJim Ingham     CommandObjectSP name_command_object (new CommandObjectBreakpointName(interpreter));
237830fdc8d8SChris Lattner 
2379b7234e40SJohnny Chen     list_command_object->SetCommandName ("breakpoint list");
238030fdc8d8SChris Lattner     enable_command_object->SetCommandName("breakpoint enable");
238130fdc8d8SChris Lattner     disable_command_object->SetCommandName("breakpoint disable");
2382b7234e40SJohnny Chen     clear_command_object->SetCommandName("breakpoint clear");
2383b7234e40SJohnny Chen     delete_command_object->SetCommandName("breakpoint delete");
2384ae1c4cf5SJim Ingham     set_command_object->SetCommandName("breakpoint set");
2385b7234e40SJohnny Chen     command_command_object->SetCommandName ("breakpoint command");
2386b7234e40SJohnny Chen     modify_command_object->SetCommandName ("breakpoint modify");
23875e09c8c3SJim Ingham     name_command_object->SetCommandName ("breakpoint name");
238830fdc8d8SChris Lattner 
238923f59509SGreg Clayton     LoadSubCommand ("list",       list_command_object);
239023f59509SGreg Clayton     LoadSubCommand ("enable",     enable_command_object);
239123f59509SGreg Clayton     LoadSubCommand ("disable",    disable_command_object);
239223f59509SGreg Clayton     LoadSubCommand ("clear",      clear_command_object);
239323f59509SGreg Clayton     LoadSubCommand ("delete",     delete_command_object);
239423f59509SGreg Clayton     LoadSubCommand ("set",        set_command_object);
239523f59509SGreg Clayton     LoadSubCommand ("command",    command_command_object);
239623f59509SGreg Clayton     LoadSubCommand ("modify",     modify_command_object);
23975e09c8c3SJim Ingham     LoadSubCommand ("name",       name_command_object);
239830fdc8d8SChris Lattner }
239930fdc8d8SChris Lattner 
24009e85e5a8SEugene Zelenko CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default;
240130fdc8d8SChris Lattner 
240230fdc8d8SChris Lattner void
24035e09c8c3SJim Ingham CommandObjectMultiwordBreakpoint::VerifyIDs (Args &args,
24045e09c8c3SJim Ingham                                              Target *target,
24055e09c8c3SJim Ingham                                              bool allow_locations,
24065e09c8c3SJim Ingham                                              CommandReturnObject &result,
240730fdc8d8SChris Lattner                                              BreakpointIDList *valid_ids)
240830fdc8d8SChris Lattner {
240930fdc8d8SChris Lattner     // args can be strings representing 1). integers (for breakpoint ids)
241030fdc8d8SChris Lattner     //                                  2). the full breakpoint & location canonical representation
241130fdc8d8SChris Lattner     //                                  3). the word "to" or a hyphen, representing a range (in which case there
241230fdc8d8SChris Lattner     //                                      had *better* be an entry both before & after of one of the first two types.
24135e09c8c3SJim Ingham     //                                  4). A breakpoint name
241436f3b369SJim Ingham     // If args is empty, we will use the last created breakpoint (if there is one.)
241530fdc8d8SChris Lattner 
241630fdc8d8SChris Lattner     Args temp_args;
241730fdc8d8SChris Lattner 
241836f3b369SJim Ingham     if (args.GetArgumentCount() == 0)
241936f3b369SJim Ingham     {
24204d122c40SGreg Clayton         if (target->GetLastCreatedBreakpoint())
242136f3b369SJim Ingham         {
242236f3b369SJim Ingham             valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
242336f3b369SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
242436f3b369SJim Ingham         }
242536f3b369SJim Ingham         else
242636f3b369SJim Ingham         {
242736f3b369SJim Ingham             result.AppendError("No breakpoint specified and no last created breakpoint.");
242836f3b369SJim Ingham             result.SetStatus (eReturnStatusFailed);
242936f3b369SJim Ingham         }
243036f3b369SJim Ingham         return;
243136f3b369SJim Ingham     }
243236f3b369SJim Ingham 
243330fdc8d8SChris Lattner     // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
243430fdc8d8SChris Lattner     // the new TEMP_ARGS.  Do not copy breakpoint id range strings over; instead generate a list of strings for
243530fdc8d8SChris Lattner     // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
243630fdc8d8SChris Lattner 
24375e09c8c3SJim Ingham     BreakpointIDList::FindAndReplaceIDRanges (args, target, allow_locations, result, temp_args);
243830fdc8d8SChris Lattner 
243930fdc8d8SChris Lattner     // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
244030fdc8d8SChris Lattner 
2441c982c768SGreg Clayton     valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
244230fdc8d8SChris Lattner 
244330fdc8d8SChris Lattner     // At this point,  all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
244430fdc8d8SChris Lattner     // and put into valid_ids.
244530fdc8d8SChris Lattner 
244630fdc8d8SChris Lattner     if (result.Succeeded())
244730fdc8d8SChris Lattner     {
244830fdc8d8SChris Lattner         // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
244930fdc8d8SChris Lattner         // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
245030fdc8d8SChris Lattner 
2451c982c768SGreg Clayton         const size_t count = valid_ids->GetSize();
2452c982c768SGreg Clayton         for (size_t i = 0; i < count; ++i)
245330fdc8d8SChris Lattner         {
245430fdc8d8SChris Lattner             BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
245530fdc8d8SChris Lattner             Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
24569e85e5a8SEugene Zelenko             if (breakpoint != nullptr)
245730fdc8d8SChris Lattner             {
2458c7bece56SGreg Clayton                 const size_t num_locations = breakpoint->GetNumLocations();
24593985c8c6SSaleem Abdulrasool                 if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations)
246030fdc8d8SChris Lattner                 {
246130fdc8d8SChris Lattner                     StreamString id_str;
2462c982c768SGreg Clayton                     BreakpointID::GetCanonicalReference (&id_str,
2463c982c768SGreg Clayton                                                          cur_bp_id.GetBreakpointID(),
246430fdc8d8SChris Lattner                                                          cur_bp_id.GetLocationID());
2465c982c768SGreg Clayton                     i = valid_ids->GetSize() + 1;
246630fdc8d8SChris Lattner                     result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
246730fdc8d8SChris Lattner                                                  id_str.GetData());
246830fdc8d8SChris Lattner                     result.SetStatus (eReturnStatusFailed);
246930fdc8d8SChris Lattner                 }
247030fdc8d8SChris Lattner             }
247130fdc8d8SChris Lattner             else
247230fdc8d8SChris Lattner             {
2473c982c768SGreg Clayton                 i = valid_ids->GetSize() + 1;
247430fdc8d8SChris Lattner                 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
247530fdc8d8SChris Lattner                 result.SetStatus (eReturnStatusFailed);
247630fdc8d8SChris Lattner             }
247730fdc8d8SChris Lattner         }
247830fdc8d8SChris Lattner     }
247930fdc8d8SChris Lattner }
2480