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 #include "CommandObjectBreakpoint.h"
1130fdc8d8SChris Lattner #include "CommandObjectBreakpointCommand.h"
1230fdc8d8SChris Lattner 
1330fdc8d8SChris Lattner // C Includes
1430fdc8d8SChris Lattner // C++ Includes
1530fdc8d8SChris Lattner // Other libraries and framework includes
1630fdc8d8SChris Lattner // Project includes
1730fdc8d8SChris Lattner #include "lldb/Breakpoint/Breakpoint.h"
1830fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointIDList.h"
1930fdc8d8SChris Lattner #include "lldb/Breakpoint/BreakpointLocation.h"
205275aaa0SVince Harron #include "lldb/Host/StringConvert.h"
2140af72e1SJim Ingham #include "lldb/Interpreter/Options.h"
2232abc6edSZachary Turner #include "lldb/Interpreter/OptionValueBoolean.h"
235e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueString.h"
245e09c8c3SJim Ingham #include "lldb/Interpreter/OptionValueUInt64.h"
2530fdc8d8SChris Lattner #include "lldb/Core/RegularExpression.h"
2630fdc8d8SChris Lattner #include "lldb/Core/StreamString.h"
2730fdc8d8SChris Lattner #include "lldb/Interpreter/CommandInterpreter.h"
2830fdc8d8SChris Lattner #include "lldb/Interpreter/CommandReturnObject.h"
290e0984eeSJim Ingham #include "lldb/Target/Language.h"
3030fdc8d8SChris Lattner #include "lldb/Target/Target.h"
3130fdc8d8SChris Lattner #include "lldb/Interpreter/CommandCompletions.h"
32b57e4a1bSJason Molenda #include "lldb/Target/StackFrame.h"
331b54c88cSJim Ingham #include "lldb/Target/Thread.h"
341b54c88cSJim Ingham #include "lldb/Target/ThreadSpec.h"
3530fdc8d8SChris Lattner 
36b7234e40SJohnny Chen #include <vector>
37b7234e40SJohnny Chen 
3830fdc8d8SChris Lattner using namespace lldb;
3930fdc8d8SChris Lattner using namespace lldb_private;
4030fdc8d8SChris Lattner 
4130fdc8d8SChris Lattner static void
4285e8b814SJim Ingham AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level)
4330fdc8d8SChris Lattner {
4430fdc8d8SChris Lattner     s->IndentMore();
4530fdc8d8SChris Lattner     bp->GetDescription (s, level, true);
4630fdc8d8SChris Lattner     s->IndentLess();
4730fdc8d8SChris Lattner     s->EOL();
4830fdc8d8SChris Lattner }
4930fdc8d8SChris Lattner 
5030fdc8d8SChris Lattner //-------------------------------------------------------------------------
515a988416SJim Ingham // CommandObjectBreakpointSet
5230fdc8d8SChris Lattner //-------------------------------------------------------------------------
5330fdc8d8SChris Lattner 
545a988416SJim Ingham 
555a988416SJim Ingham class CommandObjectBreakpointSet : public CommandObjectParsed
565a988416SJim Ingham {
575a988416SJim Ingham public:
585a988416SJim Ingham 
595a988416SJim Ingham     typedef enum BreakpointSetType
605a988416SJim Ingham     {
615a988416SJim Ingham         eSetTypeInvalid,
625a988416SJim Ingham         eSetTypeFileAndLine,
635a988416SJim Ingham         eSetTypeAddress,
645a988416SJim Ingham         eSetTypeFunctionName,
655a988416SJim Ingham         eSetTypeFunctionRegexp,
665a988416SJim Ingham         eSetTypeSourceRegexp,
675a988416SJim Ingham         eSetTypeException
685a988416SJim Ingham     } BreakpointSetType;
695a988416SJim Ingham 
705a988416SJim Ingham     CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
715a988416SJim Ingham         CommandObjectParsed (interpreter,
725a988416SJim Ingham                              "breakpoint set",
735a988416SJim Ingham                              "Sets a breakpoint or set of breakpoints in the executable.",
745a988416SJim Ingham                              "breakpoint set <cmd-options>"),
755a988416SJim Ingham         m_options (interpreter)
765a988416SJim Ingham     {
775a988416SJim Ingham     }
785a988416SJim Ingham 
795a988416SJim Ingham 
8013d21e9aSBruce Mitchener     ~CommandObjectBreakpointSet () override {}
815a988416SJim Ingham 
8213d21e9aSBruce Mitchener     Options *
8313d21e9aSBruce Mitchener     GetOptions () override
845a988416SJim Ingham     {
855a988416SJim Ingham         return &m_options;
865a988416SJim Ingham     }
875a988416SJim Ingham 
885a988416SJim Ingham     class CommandOptions : public Options
895a988416SJim Ingham     {
905a988416SJim Ingham     public:
915a988416SJim Ingham 
925a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
93eb0103f2SGreg Clayton             Options (interpreter),
947d49c9c8SJohnny Chen             m_condition (),
9587df91b8SJim Ingham             m_filenames (),
9630fdc8d8SChris Lattner             m_line_num (0),
9730fdc8d8SChris Lattner             m_column (0),
98fab10e89SJim Ingham             m_func_names (),
99fab10e89SJim Ingham             m_func_name_type_mask (eFunctionNameTypeNone),
10030fdc8d8SChris Lattner             m_func_regexp (),
101969795f1SJim Ingham             m_source_text_regexp(),
10230fdc8d8SChris Lattner             m_modules (),
1031b54c88cSJim Ingham             m_load_addr(),
104c982c768SGreg Clayton             m_ignore_count (0),
1051b54c88cSJim Ingham             m_thread_id(LLDB_INVALID_THREAD_ID),
106c982c768SGreg Clayton             m_thread_index (UINT32_MAX),
1071b54c88cSJim Ingham             m_thread_name(),
108fab10e89SJim Ingham             m_queue_name(),
109fab10e89SJim Ingham             m_catch_bp (false),
1101f746071SGreg Clayton             m_throw_bp (true),
111eb023e75SGreg Clayton             m_hardware (false),
112a72b31c7SJim Ingham             m_exception_language (eLanguageTypeUnknown),
11323b1decbSDawn Perchik             m_language (lldb::eLanguageTypeUnknown),
114ca36cd16SJim Ingham             m_skip_prologue (eLazyBoolCalculate),
115e732052fSJim Ingham             m_one_shot (false),
116055ad9beSIlia K             m_all_files (false),
117055ad9beSIlia K             m_move_to_nearest_code (eLazyBoolCalculate)
11830fdc8d8SChris Lattner         {
11930fdc8d8SChris Lattner         }
12030fdc8d8SChris Lattner 
12130fdc8d8SChris Lattner 
12213d21e9aSBruce Mitchener         ~CommandOptions () override {}
12387df91b8SJim Ingham 
12413d21e9aSBruce Mitchener         Error
12513d21e9aSBruce Mitchener         SetOptionValue (uint32_t option_idx, const char *option_arg) override
12630fdc8d8SChris Lattner         {
12730fdc8d8SChris Lattner             Error error;
1283bcdfc0eSGreg Clayton             const int short_option = m_getopt_table[option_idx].val;
12930fdc8d8SChris Lattner 
13030fdc8d8SChris Lattner             switch (short_option)
13130fdc8d8SChris Lattner             {
13230fdc8d8SChris Lattner                 case 'a':
133b9d5df58SGreg Clayton                     {
134b9d5df58SGreg Clayton                         ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
135b9d5df58SGreg Clayton                         m_load_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
136b9d5df58SGreg Clayton                     }
13730fdc8d8SChris Lattner                     break;
13830fdc8d8SChris Lattner 
139e732052fSJim Ingham                 case 'A':
140e732052fSJim Ingham                     m_all_files = true;
141e732052fSJim Ingham                     break;
142e732052fSJim Ingham 
143ca36cd16SJim Ingham                 case 'b':
144ca36cd16SJim Ingham                     m_func_names.push_back (option_arg);
145ca36cd16SJim Ingham                     m_func_name_type_mask |= eFunctionNameTypeBase;
146ca36cd16SJim Ingham                     break;
147ca36cd16SJim Ingham 
1487d49c9c8SJohnny Chen                 case 'C':
1496312991cSJim Ingham                 {
1506312991cSJim Ingham                     bool success;
1516312991cSJim Ingham                     m_column = StringConvert::ToUInt32 (option_arg, 0, 0, &success);
1526312991cSJim Ingham                     if (!success)
1536312991cSJim Ingham                         error.SetErrorStringWithFormat("invalid column number: %s", option_arg);
15430fdc8d8SChris Lattner                     break;
1556312991cSJim Ingham                 }
1567d49c9c8SJohnny Chen                 case 'c':
1577d49c9c8SJohnny Chen                     m_condition.assign(option_arg);
1587d49c9c8SJohnny Chen                     break;
1597d49c9c8SJohnny Chen 
16033df7cd3SJim Ingham                 case 'D':
16133df7cd3SJim Ingham                     m_use_dummy = true;
16233df7cd3SJim Ingham                     break;
16333df7cd3SJim Ingham 
164fab10e89SJim Ingham                 case 'E':
165fab10e89SJim Ingham                 {
1660e0984eeSJim Ingham                     LanguageType language = Language::GetLanguageTypeFromString (option_arg);
167fab10e89SJim Ingham 
168fab10e89SJim Ingham                     switch (language)
169fab10e89SJim Ingham                     {
170fab10e89SJim Ingham                         case eLanguageTypeC89:
171fab10e89SJim Ingham                         case eLanguageTypeC:
172fab10e89SJim Ingham                         case eLanguageTypeC99:
1731d0089faSBruce Mitchener                         case eLanguageTypeC11:
174a72b31c7SJim Ingham                             m_exception_language = eLanguageTypeC;
175fab10e89SJim Ingham                             break;
176fab10e89SJim Ingham                         case eLanguageTypeC_plus_plus:
1771d0089faSBruce Mitchener                         case eLanguageTypeC_plus_plus_03:
1781d0089faSBruce Mitchener                         case eLanguageTypeC_plus_plus_11:
1792ba84a6aSBruce Mitchener                         case eLanguageTypeC_plus_plus_14:
180a72b31c7SJim Ingham                             m_exception_language = eLanguageTypeC_plus_plus;
181fab10e89SJim Ingham                             break;
182fab10e89SJim Ingham                         case eLanguageTypeObjC:
183a72b31c7SJim Ingham                             m_exception_language = eLanguageTypeObjC;
184fab10e89SJim Ingham                             break;
185fab10e89SJim Ingham                         case eLanguageTypeObjC_plus_plus:
186fab10e89SJim Ingham                             error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c");
187fab10e89SJim Ingham                             break;
188fab10e89SJim Ingham                         case eLanguageTypeUnknown:
189fab10e89SJim Ingham                             error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg);
190fab10e89SJim Ingham                             break;
191fab10e89SJim Ingham                         default:
192fab10e89SJim Ingham                             error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg);
193fab10e89SJim Ingham                     }
194fab10e89SJim Ingham                 }
195fab10e89SJim Ingham                 break;
196ca36cd16SJim Ingham 
197ca36cd16SJim Ingham                 case 'f':
198ca36cd16SJim Ingham                     m_filenames.AppendIfUnique (FileSpec(option_arg, false));
199fab10e89SJim Ingham                     break;
200ca36cd16SJim Ingham 
201ca36cd16SJim Ingham                 case 'F':
202ca36cd16SJim Ingham                     m_func_names.push_back (option_arg);
203ca36cd16SJim Ingham                     m_func_name_type_mask |= eFunctionNameTypeFull;
204ca36cd16SJim Ingham                     break;
205ca36cd16SJim Ingham 
206fab10e89SJim Ingham                 case 'h':
207fab10e89SJim Ingham                     {
208fab10e89SJim Ingham                         bool success;
209fab10e89SJim Ingham                         m_catch_bp = Args::StringToBoolean (option_arg, true, &success);
210fab10e89SJim Ingham                         if (!success)
211fab10e89SJim Ingham                             error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg);
212fab10e89SJim Ingham                     }
213168d469aSJim Ingham                     break;
214eb023e75SGreg Clayton 
215eb023e75SGreg Clayton                 case 'H':
216eb023e75SGreg Clayton                     m_hardware = true;
217eb023e75SGreg Clayton                     break;
218eb023e75SGreg Clayton 
219ca36cd16SJim Ingham                 case 'i':
220ca36cd16SJim Ingham                 {
2215275aaa0SVince Harron                     m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
222ca36cd16SJim Ingham                     if (m_ignore_count == UINT32_MAX)
223ca36cd16SJim Ingham                        error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
224ca36cd16SJim Ingham                     break;
225ca36cd16SJim Ingham                 }
226ca36cd16SJim Ingham 
227a8558b62SJim Ingham                 case 'K':
228a8558b62SJim Ingham                 {
229a8558b62SJim Ingham                     bool success;
230a8558b62SJim Ingham                     bool value;
231a8558b62SJim Ingham                     value = Args::StringToBoolean (option_arg, true, &success);
232a8558b62SJim Ingham                     if (value)
233a8558b62SJim Ingham                         m_skip_prologue = eLazyBoolYes;
234a8558b62SJim Ingham                     else
235a8558b62SJim Ingham                         m_skip_prologue = eLazyBoolNo;
236a8558b62SJim Ingham 
237a8558b62SJim Ingham                     if (!success)
238a8558b62SJim Ingham                         error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg);
239a8558b62SJim Ingham                 }
240fab10e89SJim Ingham                 break;
241ca36cd16SJim Ingham 
242ca36cd16SJim Ingham                 case 'l':
2436312991cSJim Ingham                 {
2446312991cSJim Ingham                     bool success;
2456312991cSJim Ingham                     m_line_num = StringConvert::ToUInt32 (option_arg, 0, 0, &success);
2466312991cSJim Ingham                     if (!success)
2476312991cSJim Ingham                         error.SetErrorStringWithFormat ("invalid line number: %s.", option_arg);
248ca36cd16SJim Ingham                     break;
2496312991cSJim Ingham                 }
250055ad9beSIlia K 
25123b1decbSDawn Perchik                 case 'L':
2520e0984eeSJim Ingham                     m_language = Language::GetLanguageTypeFromString (option_arg);
25323b1decbSDawn Perchik                     if (m_language == eLanguageTypeUnknown)
25423b1decbSDawn Perchik                         error.SetErrorStringWithFormat ("Unknown language type: '%s' for breakpoint", option_arg);
25523b1decbSDawn Perchik                     break;
25623b1decbSDawn Perchik 
257055ad9beSIlia K                 case 'm':
258055ad9beSIlia K                 {
259055ad9beSIlia K                     bool success;
260055ad9beSIlia K                     bool value;
261055ad9beSIlia K                     value = Args::StringToBoolean (option_arg, true, &success);
262055ad9beSIlia K                     if (value)
263055ad9beSIlia K                         m_move_to_nearest_code = eLazyBoolYes;
264055ad9beSIlia K                     else
265055ad9beSIlia K                         m_move_to_nearest_code = eLazyBoolNo;
266055ad9beSIlia K 
267055ad9beSIlia K                     if (!success)
268055ad9beSIlia K                         error.SetErrorStringWithFormat ("Invalid boolean value for move-to-nearest-code option: '%s'", option_arg);
269055ad9beSIlia K                     break;
270055ad9beSIlia K                 }
271055ad9beSIlia K 
272ca36cd16SJim Ingham                 case 'M':
273ca36cd16SJim Ingham                     m_func_names.push_back (option_arg);
274ca36cd16SJim Ingham                     m_func_name_type_mask |= eFunctionNameTypeMethod;
275ca36cd16SJim Ingham                     break;
276ca36cd16SJim Ingham 
277ca36cd16SJim Ingham                 case 'n':
278ca36cd16SJim Ingham                     m_func_names.push_back (option_arg);
279ca36cd16SJim Ingham                     m_func_name_type_mask |= eFunctionNameTypeAuto;
280ca36cd16SJim Ingham                     break;
281ca36cd16SJim Ingham 
2825e09c8c3SJim Ingham                 case 'N':
2835e09c8c3SJim Ingham                     if (BreakpointID::StringIsBreakpointName(option_arg, error))
2845e09c8c3SJim Ingham                         m_breakpoint_names.push_back (option_arg);
2855e09c8c3SJim Ingham                     break;
2865e09c8c3SJim Ingham 
287ca36cd16SJim Ingham                 case 'o':
288ca36cd16SJim Ingham                     m_one_shot = true;
289ca36cd16SJim Ingham                     break;
290ca36cd16SJim Ingham 
291a72b31c7SJim Ingham                 case 'O':
292a72b31c7SJim Ingham                     m_exception_extra_args.AppendArgument ("-O");
293a72b31c7SJim Ingham                     m_exception_extra_args.AppendArgument (option_arg);
294a72b31c7SJim Ingham                     break;
295a72b31c7SJim Ingham 
296ca36cd16SJim Ingham                 case 'p':
297ca36cd16SJim Ingham                     m_source_text_regexp.assign (option_arg);
298ca36cd16SJim Ingham                     break;
299ca36cd16SJim Ingham 
300ca36cd16SJim Ingham                 case 'q':
301ca36cd16SJim Ingham                     m_queue_name.assign (option_arg);
302ca36cd16SJim Ingham                     break;
303ca36cd16SJim Ingham 
304ca36cd16SJim Ingham                 case 'r':
305ca36cd16SJim Ingham                     m_func_regexp.assign (option_arg);
306ca36cd16SJim Ingham                     break;
307ca36cd16SJim Ingham 
308ca36cd16SJim Ingham                 case 's':
309ca36cd16SJim Ingham                 {
310ca36cd16SJim Ingham                     m_modules.AppendIfUnique (FileSpec (option_arg, false));
311ca36cd16SJim Ingham                     break;
312ca36cd16SJim Ingham                 }
313ca36cd16SJim Ingham 
314ca36cd16SJim Ingham                 case 'S':
315ca36cd16SJim Ingham                     m_func_names.push_back (option_arg);
316ca36cd16SJim Ingham                     m_func_name_type_mask |= eFunctionNameTypeSelector;
317ca36cd16SJim Ingham                     break;
318ca36cd16SJim Ingham 
319ca36cd16SJim Ingham                 case 't' :
320ca36cd16SJim Ingham                 {
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                 }
325ca36cd16SJim Ingham                 break;
326ca36cd16SJim Ingham 
327ca36cd16SJim Ingham                 case 'T':
328ca36cd16SJim Ingham                     m_thread_name.assign (option_arg);
329ca36cd16SJim Ingham                     break;
330ca36cd16SJim Ingham 
331ca36cd16SJim Ingham                 case 'w':
332ca36cd16SJim Ingham                 {
333ca36cd16SJim Ingham                     bool success;
334ca36cd16SJim Ingham                     m_throw_bp = Args::StringToBoolean (option_arg, true, &success);
335ca36cd16SJim Ingham                     if (!success)
336ca36cd16SJim Ingham                         error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg);
337ca36cd16SJim Ingham                 }
338ca36cd16SJim Ingham                 break;
339ca36cd16SJim Ingham 
340ca36cd16SJim Ingham                 case 'x':
341ca36cd16SJim Ingham                 {
3425275aaa0SVince Harron                     m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
343ca36cd16SJim Ingham                     if (m_thread_id == UINT32_MAX)
344ca36cd16SJim Ingham                        error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
345ca36cd16SJim Ingham 
346ca36cd16SJim Ingham                 }
347ca36cd16SJim Ingham                 break;
348ca36cd16SJim Ingham 
34930fdc8d8SChris Lattner                 default:
35086edbf41SGreg Clayton                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
35130fdc8d8SChris Lattner                     break;
35230fdc8d8SChris Lattner             }
35330fdc8d8SChris Lattner 
35430fdc8d8SChris Lattner             return error;
35530fdc8d8SChris Lattner         }
35630fdc8d8SChris Lattner         void
35713d21e9aSBruce Mitchener         OptionParsingStarting () override
35830fdc8d8SChris Lattner         {
3597d49c9c8SJohnny Chen             m_condition.clear();
36087df91b8SJim Ingham             m_filenames.Clear();
36130fdc8d8SChris Lattner             m_line_num = 0;
36230fdc8d8SChris Lattner             m_column = 0;
363fab10e89SJim Ingham             m_func_names.clear();
3641f746071SGreg Clayton             m_func_name_type_mask = eFunctionNameTypeNone;
36530fdc8d8SChris Lattner             m_func_regexp.clear();
3661f746071SGreg Clayton             m_source_text_regexp.clear();
36787df91b8SJim Ingham             m_modules.Clear();
3681f746071SGreg Clayton             m_load_addr = LLDB_INVALID_ADDRESS;
369c982c768SGreg Clayton             m_ignore_count = 0;
3701b54c88cSJim Ingham             m_thread_id = LLDB_INVALID_THREAD_ID;
371c982c768SGreg Clayton             m_thread_index = UINT32_MAX;
3721b54c88cSJim Ingham             m_thread_name.clear();
3731b54c88cSJim Ingham             m_queue_name.clear();
374fab10e89SJim Ingham             m_catch_bp = false;
375fab10e89SJim Ingham             m_throw_bp = true;
376eb023e75SGreg Clayton             m_hardware = false;
377a72b31c7SJim Ingham             m_exception_language = eLanguageTypeUnknown;
37823b1decbSDawn Perchik             m_language = lldb::eLanguageTypeUnknown;
379a8558b62SJim Ingham             m_skip_prologue = eLazyBoolCalculate;
380ca36cd16SJim Ingham             m_one_shot = false;
38133df7cd3SJim Ingham             m_use_dummy = false;
3825e09c8c3SJim Ingham             m_breakpoint_names.clear();
383e732052fSJim Ingham             m_all_files = false;
384a72b31c7SJim Ingham             m_exception_extra_args.Clear();
385055ad9beSIlia K             m_move_to_nearest_code = eLazyBoolCalculate;
38630fdc8d8SChris Lattner         }
38730fdc8d8SChris Lattner 
3885a988416SJim Ingham         const OptionDefinition*
38913d21e9aSBruce Mitchener         GetDefinitions () override
39030fdc8d8SChris Lattner         {
3915a988416SJim Ingham             return g_option_table;
39230fdc8d8SChris Lattner         }
39330fdc8d8SChris Lattner 
3945a988416SJim Ingham         // Options table: Required for subclasses of Options.
39530fdc8d8SChris Lattner 
3965a988416SJim Ingham         static OptionDefinition g_option_table[];
39730fdc8d8SChris Lattner 
3985a988416SJim Ingham         // Instance variables to hold the values for command options.
399969795f1SJim Ingham 
4005a988416SJim Ingham         std::string m_condition;
4015a988416SJim Ingham         FileSpecList m_filenames;
4025a988416SJim Ingham         uint32_t m_line_num;
4035a988416SJim Ingham         uint32_t m_column;
4045a988416SJim Ingham         std::vector<std::string> m_func_names;
4055e09c8c3SJim Ingham         std::vector<std::string> m_breakpoint_names;
4065a988416SJim Ingham         uint32_t m_func_name_type_mask;
4075a988416SJim Ingham         std::string m_func_regexp;
4085a988416SJim Ingham         std::string m_source_text_regexp;
4095a988416SJim Ingham         FileSpecList m_modules;
4105a988416SJim Ingham         lldb::addr_t m_load_addr;
4115a988416SJim Ingham         uint32_t m_ignore_count;
4125a988416SJim Ingham         lldb::tid_t m_thread_id;
4135a988416SJim Ingham         uint32_t m_thread_index;
4145a988416SJim Ingham         std::string m_thread_name;
4155a988416SJim Ingham         std::string m_queue_name;
4165a988416SJim Ingham         bool m_catch_bp;
4175a988416SJim Ingham         bool m_throw_bp;
418eb023e75SGreg Clayton         bool m_hardware; // Request to use hardware breakpoints
419a72b31c7SJim Ingham         lldb::LanguageType m_exception_language;
42023b1decbSDawn Perchik         lldb::LanguageType m_language;
4215a988416SJim Ingham         LazyBool m_skip_prologue;
422ca36cd16SJim Ingham         bool m_one_shot;
42333df7cd3SJim Ingham         bool m_use_dummy;
424e732052fSJim Ingham         bool m_all_files;
425a72b31c7SJim Ingham         Args m_exception_extra_args;
426055ad9beSIlia K         LazyBool m_move_to_nearest_code;
4275a988416SJim Ingham 
4285a988416SJim Ingham     };
4295a988416SJim Ingham 
4305a988416SJim Ingham protected:
43113d21e9aSBruce Mitchener     bool
4325a988416SJim Ingham     DoExecute (Args& command,
43313d21e9aSBruce Mitchener               CommandReturnObject &result) override
43430fdc8d8SChris Lattner     {
43533df7cd3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
43633df7cd3SJim Ingham 
437893c932aSJim Ingham         if (target == nullptr)
43830fdc8d8SChris Lattner         {
439effe5c95SGreg Clayton             result.AppendError ("Invalid target.  Must set target before setting breakpoints (see 'target create' command).");
44030fdc8d8SChris Lattner             result.SetStatus (eReturnStatusFailed);
44130fdc8d8SChris Lattner             return false;
44230fdc8d8SChris Lattner         }
44330fdc8d8SChris Lattner 
44430fdc8d8SChris Lattner         // The following are the various types of breakpoints that could be set:
44530fdc8d8SChris Lattner         //   1).  -f -l -p  [-s -g]   (setting breakpoint by source location)
44630fdc8d8SChris Lattner         //   2).  -a  [-s -g]         (setting breakpoint by address)
44730fdc8d8SChris Lattner         //   3).  -n  [-s -g]         (setting breakpoint by function name)
44830fdc8d8SChris Lattner         //   4).  -r  [-s -g]         (setting breakpoint by function name regular expression)
449969795f1SJim Ingham         //   5).  -p -f               (setting a breakpoint by comparing a reg-exp to source text)
450fab10e89SJim Ingham         //   6).  -E [-w -h]          (setting a breakpoint for exceptions for a given language.)
45130fdc8d8SChris Lattner 
45230fdc8d8SChris Lattner         BreakpointSetType break_type = eSetTypeInvalid;
45330fdc8d8SChris Lattner 
45430fdc8d8SChris Lattner         if (m_options.m_line_num != 0)
45530fdc8d8SChris Lattner             break_type = eSetTypeFileAndLine;
45630fdc8d8SChris Lattner         else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
45730fdc8d8SChris Lattner             break_type = eSetTypeAddress;
458fab10e89SJim Ingham         else if (!m_options.m_func_names.empty())
45930fdc8d8SChris Lattner             break_type = eSetTypeFunctionName;
46030fdc8d8SChris Lattner         else if  (!m_options.m_func_regexp.empty())
46130fdc8d8SChris Lattner             break_type = eSetTypeFunctionRegexp;
462969795f1SJim Ingham         else if (!m_options.m_source_text_regexp.empty())
463969795f1SJim Ingham             break_type = eSetTypeSourceRegexp;
464a72b31c7SJim Ingham         else if (m_options.m_exception_language != eLanguageTypeUnknown)
465fab10e89SJim Ingham             break_type = eSetTypeException;
46630fdc8d8SChris Lattner 
46730fdc8d8SChris Lattner         Breakpoint *bp = NULL;
468274060b6SGreg Clayton         FileSpec module_spec;
469a8558b62SJim Ingham         const bool internal = false;
470a8558b62SJim Ingham 
47130fdc8d8SChris Lattner         switch (break_type)
47230fdc8d8SChris Lattner         {
47330fdc8d8SChris Lattner             case eSetTypeFileAndLine: // Breakpoint by source position
47430fdc8d8SChris Lattner                 {
47530fdc8d8SChris Lattner                     FileSpec file;
476c7bece56SGreg Clayton                     const size_t num_files = m_options.m_filenames.GetSize();
47787df91b8SJim Ingham                     if (num_files == 0)
47887df91b8SJim Ingham                     {
47987df91b8SJim Ingham                         if (!GetDefaultFile (target, file, result))
48087df91b8SJim Ingham                         {
48187df91b8SJim Ingham                             result.AppendError("No file supplied and no default file available.");
48287df91b8SJim Ingham                             result.SetStatus (eReturnStatusFailed);
48387df91b8SJim Ingham                             return false;
48487df91b8SJim Ingham                         }
48587df91b8SJim Ingham                     }
48687df91b8SJim Ingham                     else if (num_files > 1)
48787df91b8SJim Ingham                     {
48887df91b8SJim Ingham                         result.AppendError("Only one file at a time is allowed for file and line breakpoints.");
48987df91b8SJim Ingham                         result.SetStatus (eReturnStatusFailed);
49087df91b8SJim Ingham                         return false;
49187df91b8SJim Ingham                     }
49287df91b8SJim Ingham                     else
49387df91b8SJim Ingham                         file = m_options.m_filenames.GetFileSpecAtIndex(0);
49430fdc8d8SChris Lattner 
4951f746071SGreg Clayton                     // Only check for inline functions if
4961f746071SGreg Clayton                     LazyBool check_inlines = eLazyBoolCalculate;
4971f746071SGreg Clayton 
49887df91b8SJim Ingham                     bp = target->CreateBreakpoint (&(m_options.m_modules),
49930fdc8d8SChris Lattner                                                    file,
50030fdc8d8SChris Lattner                                                    m_options.m_line_num,
5011f746071SGreg Clayton                                                    check_inlines,
502a8558b62SJim Ingham                                                    m_options.m_skip_prologue,
503eb023e75SGreg Clayton                                                    internal,
504055ad9beSIlia K                                                    m_options.m_hardware,
505055ad9beSIlia K                                                    m_options.m_move_to_nearest_code).get();
50630fdc8d8SChris Lattner                 }
50730fdc8d8SChris Lattner                 break;
5086eee5aa0SGreg Clayton 
50930fdc8d8SChris Lattner             case eSetTypeAddress: // Breakpoint by address
510055a08a4SJim Ingham                 {
511055a08a4SJim Ingham                     // If a shared library has been specified, make an lldb_private::Address with the library, and
512055a08a4SJim Ingham                     // use that.  That way the address breakpoint will track the load location of the library.
513055a08a4SJim Ingham                     size_t num_modules_specified = m_options.m_modules.GetSize();
514055a08a4SJim Ingham                     if (num_modules_specified == 1)
515055a08a4SJim Ingham                     {
516055a08a4SJim Ingham                         const FileSpec *file_spec = m_options.m_modules.GetFileSpecPointerAtIndex(0);
517055a08a4SJim Ingham                         bp = target->CreateAddressInModuleBreakpoint (m_options.m_load_addr,
518055a08a4SJim Ingham                                                                       internal,
519055a08a4SJim Ingham                                                                       file_spec,
520055a08a4SJim Ingham                                                                       m_options.m_hardware).get();
521055a08a4SJim Ingham                     }
522055a08a4SJim Ingham                     else if (num_modules_specified == 0)
523055a08a4SJim Ingham                     {
524eb023e75SGreg Clayton                         bp = target->CreateBreakpoint (m_options.m_load_addr,
525eb023e75SGreg Clayton                                                        internal,
526eb023e75SGreg Clayton                                                        m_options.m_hardware).get();
527055a08a4SJim Ingham                     }
528055a08a4SJim Ingham                     else
529055a08a4SJim Ingham                     {
530055a08a4SJim Ingham                         result.AppendError("Only one shared library can be specified for address breakpoints.");
531055a08a4SJim Ingham                         result.SetStatus(eReturnStatusFailed);
532055a08a4SJim Ingham                         return false;
533055a08a4SJim Ingham                     }
53430fdc8d8SChris Lattner                 break;
535055a08a4SJim Ingham                 }
53630fdc8d8SChris Lattner             case eSetTypeFunctionName: // Breakpoint by function name
5370c5cd90dSGreg Clayton                 {
5380c5cd90dSGreg Clayton                     uint32_t name_type_mask = m_options.m_func_name_type_mask;
5390c5cd90dSGreg Clayton 
5400c5cd90dSGreg Clayton                     if (name_type_mask == 0)
541e02b8504SGreg Clayton                         name_type_mask = eFunctionNameTypeAuto;
5420c5cd90dSGreg Clayton 
54387df91b8SJim Ingham                     bp = target->CreateBreakpoint (&(m_options.m_modules),
54487df91b8SJim Ingham                                                    &(m_options.m_filenames),
545fab10e89SJim Ingham                                                    m_options.m_func_names,
546274060b6SGreg Clayton                                                    name_type_mask,
54723b1decbSDawn Perchik                                                    m_options.m_language,
548a8558b62SJim Ingham                                                    m_options.m_skip_prologue,
549eb023e75SGreg Clayton                                                    internal,
550eb023e75SGreg Clayton                                                    m_options.m_hardware).get();
5510c5cd90dSGreg Clayton                 }
55230fdc8d8SChris Lattner                 break;
5530c5cd90dSGreg Clayton 
55430fdc8d8SChris Lattner             case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
55530fdc8d8SChris Lattner                 {
55630fdc8d8SChris Lattner                     RegularExpression regexp(m_options.m_func_regexp.c_str());
557969795f1SJim Ingham                     if (!regexp.IsValid())
55830fdc8d8SChris Lattner                     {
559969795f1SJim Ingham                         char err_str[1024];
560969795f1SJim Ingham                         regexp.GetErrorAsCString(err_str, sizeof(err_str));
561969795f1SJim Ingham                         result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"",
562969795f1SJim Ingham                                                      err_str);
56330fdc8d8SChris Lattner                         result.SetStatus (eReturnStatusFailed);
564969795f1SJim Ingham                         return false;
56530fdc8d8SChris Lattner                     }
56687df91b8SJim Ingham 
567a8558b62SJim Ingham                     bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules),
568a8558b62SJim Ingham                                                             &(m_options.m_filenames),
569a8558b62SJim Ingham                                                             regexp,
5700fcdac36SJim Ingham                                                             m_options.m_language,
571a8558b62SJim Ingham                                                             m_options.m_skip_prologue,
572eb023e75SGreg Clayton                                                             internal,
573eb023e75SGreg Clayton                                                             m_options.m_hardware).get();
57430fdc8d8SChris Lattner                 }
57530fdc8d8SChris Lattner                 break;
576969795f1SJim Ingham             case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
577969795f1SJim Ingham                 {
578c7bece56SGreg Clayton                     const size_t num_files = m_options.m_filenames.GetSize();
57987df91b8SJim Ingham 
580e732052fSJim Ingham                     if (num_files == 0 && !m_options.m_all_files)
58187df91b8SJim Ingham                     {
582969795f1SJim Ingham                         FileSpec file;
58387df91b8SJim Ingham                         if (!GetDefaultFile (target, file, result))
58487df91b8SJim Ingham                         {
58587df91b8SJim Ingham                             result.AppendError ("No files provided and could not find default file.");
58687df91b8SJim Ingham                             result.SetStatus (eReturnStatusFailed);
58787df91b8SJim Ingham                             return false;
58887df91b8SJim Ingham                         }
58987df91b8SJim Ingham                         else
59087df91b8SJim Ingham                         {
59187df91b8SJim Ingham                             m_options.m_filenames.Append (file);
59287df91b8SJim Ingham                         }
59387df91b8SJim Ingham                     }
5940c5cd90dSGreg Clayton 
595969795f1SJim Ingham                     RegularExpression regexp(m_options.m_source_text_regexp.c_str());
596969795f1SJim Ingham                     if (!regexp.IsValid())
597969795f1SJim Ingham                     {
598969795f1SJim Ingham                         char err_str[1024];
599969795f1SJim Ingham                         regexp.GetErrorAsCString(err_str, sizeof(err_str));
600969795f1SJim Ingham                         result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"",
601969795f1SJim Ingham                                                      err_str);
602969795f1SJim Ingham                         result.SetStatus (eReturnStatusFailed);
603969795f1SJim Ingham                         return false;
604969795f1SJim Ingham                     }
605eb023e75SGreg Clayton                     bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules),
606eb023e75SGreg Clayton                                                               &(m_options.m_filenames),
607eb023e75SGreg Clayton                                                               regexp,
608eb023e75SGreg Clayton                                                               internal,
609055ad9beSIlia K                                                               m_options.m_hardware,
610055ad9beSIlia K                                                               m_options.m_move_to_nearest_code).get();
611969795f1SJim Ingham                 }
612969795f1SJim Ingham                 break;
613fab10e89SJim Ingham             case eSetTypeException:
614fab10e89SJim Ingham                 {
615a72b31c7SJim Ingham                     Error precond_error;
616a72b31c7SJim Ingham                     bp = target->CreateExceptionBreakpoint (m_options.m_exception_language,
617eb023e75SGreg Clayton                                                             m_options.m_catch_bp,
618eb023e75SGreg Clayton                                                             m_options.m_throw_bp,
619a72b31c7SJim Ingham                                                             internal,
620a72b31c7SJim Ingham                                                             &m_options.m_exception_extra_args,
621a72b31c7SJim Ingham                                                             &precond_error).get();
622a72b31c7SJim Ingham                     if (precond_error.Fail())
623a72b31c7SJim Ingham                     {
624a72b31c7SJim Ingham                         result.AppendErrorWithFormat("Error setting extra exception arguments: %s",
625a72b31c7SJim Ingham                                                      precond_error.AsCString());
626a72b31c7SJim Ingham                         target->RemoveBreakpointByID(bp->GetID());
627a72b31c7SJim Ingham                         result.SetStatus(eReturnStatusFailed);
628a72b31c7SJim Ingham                         return false;
629a72b31c7SJim Ingham                     }
630fab10e89SJim Ingham                 }
631fab10e89SJim Ingham                 break;
63230fdc8d8SChris Lattner             default:
63330fdc8d8SChris Lattner                 break;
63430fdc8d8SChris Lattner         }
63530fdc8d8SChris Lattner 
6361b54c88cSJim Ingham         // Now set the various options that were passed in:
6371b54c88cSJim Ingham         if (bp)
6381b54c88cSJim Ingham         {
6391b54c88cSJim Ingham             if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
6401b54c88cSJim Ingham                 bp->SetThreadID (m_options.m_thread_id);
6411b54c88cSJim Ingham 
642c982c768SGreg Clayton             if (m_options.m_thread_index != UINT32_MAX)
6431b54c88cSJim Ingham                 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
6441b54c88cSJim Ingham 
6451b54c88cSJim Ingham             if (!m_options.m_thread_name.empty())
6461b54c88cSJim Ingham                 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
6471b54c88cSJim Ingham 
6481b54c88cSJim Ingham             if (!m_options.m_queue_name.empty())
6491b54c88cSJim Ingham                 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
6501b54c88cSJim Ingham 
651c982c768SGreg Clayton             if (m_options.m_ignore_count != 0)
6521b54c88cSJim Ingham                 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
6537d49c9c8SJohnny Chen 
6547d49c9c8SJohnny Chen             if (!m_options.m_condition.empty())
6557d49c9c8SJohnny Chen                 bp->GetOptions()->SetCondition(m_options.m_condition.c_str());
656ca36cd16SJim Ingham 
6575e09c8c3SJim Ingham             if (!m_options.m_breakpoint_names.empty())
6585e09c8c3SJim Ingham             {
6595e09c8c3SJim Ingham                 Error error;  // We don't need to check the error here, since the option parser checked it...
6605e09c8c3SJim Ingham                 for (auto name : m_options.m_breakpoint_names)
6615e09c8c3SJim Ingham                     bp->AddName(name.c_str(), error);
6625e09c8c3SJim Ingham             }
6635e09c8c3SJim Ingham 
664ca36cd16SJim Ingham             bp->SetOneShot (m_options.m_one_shot);
6651b54c88cSJim Ingham         }
6661b54c88cSJim Ingham 
667969795f1SJim Ingham         if (bp)
66830fdc8d8SChris Lattner         {
66985e8b814SJim Ingham             Stream &output_stream = result.GetOutputStream();
6701391cc7dSJim Ingham             const bool show_locations = false;
6711391cc7dSJim Ingham             bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, show_locations);
6724aeb1989SJim Ingham             if (target == m_interpreter.GetDebugger().GetDummyTarget())
6734aeb1989SJim Ingham                     output_stream.Printf ("Breakpoint set in dummy target, will get copied into future targets.\n");
6744aeb1989SJim Ingham             else
6754aeb1989SJim Ingham             {
676fab10e89SJim Ingham                 // Don't print out this warning for exception breakpoints.  They can get set before the target
677fab10e89SJim Ingham                 // is set, but we won't know how to actually set the breakpoint till we run.
678fab10e89SJim Ingham                 if (bp->GetNumLocations() == 0 && break_type != eSetTypeException)
6794aeb1989SJim Ingham                 {
680be484f41SCaroline Tice                     output_stream.Printf ("WARNING:  Unable to resolve breakpoint to any actual locations.\n");
6814aeb1989SJim Ingham                 }
6824aeb1989SJim Ingham             }
68330fdc8d8SChris Lattner             result.SetStatus (eReturnStatusSuccessFinishResult);
68430fdc8d8SChris Lattner         }
68530fdc8d8SChris Lattner         else if (!bp)
68630fdc8d8SChris Lattner         {
68730fdc8d8SChris Lattner             result.AppendError ("Breakpoint creation failed: No breakpoint created.");
68830fdc8d8SChris Lattner             result.SetStatus (eReturnStatusFailed);
68930fdc8d8SChris Lattner         }
69030fdc8d8SChris Lattner 
69130fdc8d8SChris Lattner         return result.Succeeded();
69230fdc8d8SChris Lattner     }
69330fdc8d8SChris Lattner 
6945a988416SJim Ingham private:
6955a988416SJim Ingham     bool
6965a988416SJim Ingham     GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result)
6975a988416SJim Ingham     {
6985a988416SJim Ingham         uint32_t default_line;
6995a988416SJim Ingham         // First use the Source Manager's default file.
7005a988416SJim Ingham         // Then use the current stack frame's file.
7015a988416SJim Ingham         if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line))
7025a988416SJim Ingham         {
703b57e4a1bSJason Molenda             StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
7045a988416SJim Ingham             if (cur_frame == NULL)
7055a988416SJim Ingham             {
7065a988416SJim Ingham                 result.AppendError ("No selected frame to use to find the default file.");
7075a988416SJim Ingham                 result.SetStatus (eReturnStatusFailed);
7085a988416SJim Ingham                 return false;
7095a988416SJim Ingham             }
7105a988416SJim Ingham             else if (!cur_frame->HasDebugInformation())
7115a988416SJim Ingham             {
7125a988416SJim Ingham                 result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info.");
7135a988416SJim Ingham                 result.SetStatus (eReturnStatusFailed);
7145a988416SJim Ingham                 return false;
7155a988416SJim Ingham             }
7165a988416SJim Ingham             else
7175a988416SJim Ingham             {
7185a988416SJim Ingham                 const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
7195a988416SJim Ingham                 if (sc.line_entry.file)
7205a988416SJim Ingham                 {
7215a988416SJim Ingham                     file = sc.line_entry.file;
7225a988416SJim Ingham                 }
7235a988416SJim Ingham                 else
7245a988416SJim Ingham                 {
7255a988416SJim Ingham                     result.AppendError ("Can't find the file for the selected frame to use as the default file.");
7265a988416SJim Ingham                     result.SetStatus (eReturnStatusFailed);
7275a988416SJim Ingham                     return false;
7285a988416SJim Ingham                 }
7295a988416SJim Ingham             }
7305a988416SJim Ingham         }
7315a988416SJim Ingham         return true;
7325a988416SJim Ingham     }
7335a988416SJim Ingham 
7345a988416SJim Ingham     CommandOptions m_options;
7355a988416SJim Ingham };
7365a988416SJim Ingham // If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to
7375a988416SJim Ingham // update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately.
7385a988416SJim Ingham #define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 )
7395a988416SJim Ingham #define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 )
7405a988416SJim Ingham #define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) )
741055ad9beSIlia K #define LLDB_OPT_MOVE_TO_NEAREST_CODE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_9 )
7420fcdac36SJim Ingham #define LLDB_OPT_EXPR_LANGUAGE ( LLDB_OPT_SET_FROM_TO(3, 8) )
7435a988416SJim Ingham 
7445a988416SJim Ingham OptionDefinition
7455a988416SJim Ingham CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
7465a988416SJim Ingham {
747d37221dcSZachary Turner     { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
7485a988416SJim Ingham         "Set the breakpoint only in this shared library.  "
7495a988416SJim Ingham         "Can repeat this option multiple times to specify multiple shared libraries."},
7505a988416SJim Ingham 
751d37221dcSZachary Turner     { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument,   NULL, NULL, 0, eArgTypeCount,
7525a988416SJim Ingham         "Set the number of times this breakpoint is skipped before stopping." },
7535a988416SJim Ingham 
754d37221dcSZachary Turner     { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument,   NULL, NULL, 0, eArgTypeNone,
755b2b256afSJim Ingham         "The breakpoint is deleted the first time it causes a stop." },
756ca36cd16SJim Ingham 
757d37221dcSZachary Turner     { LLDB_OPT_SET_ALL, false, "condition",    'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeExpression,
7585a988416SJim Ingham         "The breakpoint stops only if this condition expression evaluates to true."},
7595a988416SJim Ingham 
760d37221dcSZachary Turner     { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadIndex,
761a89be91fSJim Ingham         "The breakpoint stops only for the thread whose indeX matches this argument."},
7625a988416SJim Ingham 
763d37221dcSZachary Turner     { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadID,
7645a988416SJim Ingham         "The breakpoint stops only for the thread whose TID matches this argument."},
7655a988416SJim Ingham 
766d37221dcSZachary Turner     { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadName,
7675a988416SJim Ingham         "The breakpoint stops only for the thread whose thread name matches this argument."},
7685a988416SJim Ingham 
769d37221dcSZachary Turner     { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
770eb023e75SGreg Clayton         "Require the breakpoint to use hardware breakpoints."},
771eb023e75SGreg Clayton 
772d37221dcSZachary Turner     { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeQueueName,
7735a988416SJim Ingham         "The breakpoint stops only for threads in the queue whose name is given by this argument."},
7745a988416SJim Ingham 
775d37221dcSZachary Turner     { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
776289aca64SJim Ingham         "Specifies the source file in which to set this breakpoint.  "
777289aca64SJim Ingham         "Note, by default lldb only looks for files that are #included if they use the standard include file extensions.  "
7786394479eSJim Ingham         "To set breakpoints on .c/.cpp/.m/.mm files that are #included, set target.inline-breakpoint-strategy"
779289aca64SJim Ingham         " to \"always\"."},
7805a988416SJim Ingham 
781d37221dcSZachary Turner     { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLineNum,
7825a988416SJim Ingham         "Specifies the line number on which to set this breakpoint."},
7835a988416SJim Ingham 
7845a988416SJim Ingham     // Comment out this option for the moment, as we don't actually use it, but will in the future.
7855a988416SJim Ingham     // This way users won't see it, but the infrastructure is left in place.
786e2607b50SVirgile Bello     //    { 0, false, "column",     'C', OptionParser::eRequiredArgument, NULL, "<column>",
7875a988416SJim Ingham     //    "Set the breakpoint by source location at this particular column."},
7885a988416SJim Ingham 
789d37221dcSZachary Turner     { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeAddressOrExpression,
790055a08a4SJim Ingham         "Set the breakpoint at the specified address.  "
791055a08a4SJim Ingham         "If the address maps uniquely to a particular "
792055a08a4SJim Ingham         "binary, then the address will be converted to a \"file\" address, so that the breakpoint will track that binary+offset no matter where "
793055a08a4SJim Ingham         "the binary eventually loads.  "
794055a08a4SJim Ingham         "Alternately, if you also specify the module - with the -s option - then the address will be treated as "
795055a08a4SJim Ingham         "a file address in that module, and resolved accordingly.  Again, this will allow lldb to track that offset on "
796055a08a4SJim Ingham         "subsequent reloads.  The module need not have been loaded at the time you specify this breakpoint, and will "
797055a08a4SJim Ingham         "get resolved when the module is loaded."},
7985a988416SJim Ingham 
799d37221dcSZachary Turner     { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
800551262d7SJim Ingham         "Set the breakpoint by function name.  Can be repeated multiple times to make one breakpoint for multiple names" },
8015a988416SJim Ingham 
802d37221dcSZachary Turner     { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
8035a988416SJim Ingham         "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and "
8045a988416SJim Ingham         "for Objective C this means a full function prototype with class and selector.  "
8055a988416SJim Ingham         "Can be repeated multiple times to make one breakpoint for multiple names." },
8065a988416SJim Ingham 
807d37221dcSZachary Turner     { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeSelector,
8085a988416SJim Ingham         "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." },
8095a988416SJim Ingham 
810d37221dcSZachary Turner     { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeMethod,
8115a988416SJim Ingham         "Set the breakpoint by C++ method names.  Can be repeated multiple times to make one breakpoint for multiple methods." },
8125a988416SJim Ingham 
813d37221dcSZachary Turner     { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeRegularExpression,
8145a988416SJim Ingham         "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
8155a988416SJim Ingham 
816d37221dcSZachary Turner     { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
8175a988416SJim Ingham         "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). "
8185a988416SJim Ingham         "Can be repeated multiple times to make one breakpoint for multiple symbols." },
8195a988416SJim Ingham 
820d37221dcSZachary Turner     { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeRegularExpression,
821e96ade8bSJim Ingham         "Set the breakpoint by specifying a regular expression which is matched against the source text in a source file or files "
822e96ade8bSJim Ingham         "specified with the -f option.  The -f option can be specified more than once.  "
823*cc3a4595SJim Ingham         "If no source files are specified, uses the current \"default source file\".  "
824*cc3a4595SJim Ingham         "If you want to match against all source files, pass the \"--all-files\" option." },
8255a988416SJim Ingham 
826e732052fSJim Ingham     { LLDB_OPT_SET_9, false, "all-files", 'A', OptionParser::eNoArgument,   NULL, NULL, 0, eArgTypeNone,
827e732052fSJim Ingham         "All files are searched for source pattern matches." },
828e732052fSJim Ingham 
829d37221dcSZachary Turner     { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLanguage,
8305a988416SJim Ingham         "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" },
8315a988416SJim Ingham 
832d37221dcSZachary Turner     { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean,
8335a988416SJim Ingham         "Set the breakpoint on exception throW." },
8345a988416SJim Ingham 
835d37221dcSZachary Turner     { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean,
8365a988416SJim Ingham         "Set the breakpoint on exception catcH." },
8375a988416SJim Ingham 
838a72b31c7SJim Ingham //  Don't add this option till it actually does something useful...
839a72b31c7SJim Ingham //    { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeTypeName,
840a72b31c7SJim 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" },
841a72b31c7SJim Ingham 
84223b1decbSDawn Perchik     { LLDB_OPT_EXPR_LANGUAGE, false, "language", 'L', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLanguage,
8434112ab98SDawn 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." },
84423b1decbSDawn Perchik 
845d37221dcSZachary Turner     { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean,
8465a988416SJim Ingham         "sKip the prologue if the breakpoint is at the beginning of a function.  If not set the target.skip-prologue setting is used." },
8475a988416SJim Ingham 
84833df7cd3SJim Ingham     { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
84933df7cd3SJim Ingham         "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
85033df7cd3SJim Ingham 
8515e09c8c3SJim Ingham     { LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointName,
8525e09c8c3SJim Ingham         "Adds this to the list of names for this breakopint."},
8535e09c8c3SJim Ingham 
854055ad9beSIlia K     { LLDB_OPT_MOVE_TO_NEAREST_CODE, false, "move-to-nearest-code", 'm', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean,
855055ad9beSIlia K         "Move breakpoints to nearest code. If not set the target.move-to-nearest-code setting is used." },
856055ad9beSIlia K 
857d37221dcSZachary Turner     { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
8585a988416SJim Ingham };
8595a988416SJim Ingham 
8605a988416SJim Ingham //-------------------------------------------------------------------------
8615a988416SJim Ingham // CommandObjectBreakpointModify
8625a988416SJim Ingham //-------------------------------------------------------------------------
8635a988416SJim Ingham #pragma mark Modify
8645a988416SJim Ingham 
8655a988416SJim Ingham class CommandObjectBreakpointModify : public CommandObjectParsed
8665a988416SJim Ingham {
8675a988416SJim Ingham public:
8685a988416SJim Ingham 
8695a988416SJim Ingham     CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
8705a988416SJim Ingham         CommandObjectParsed (interpreter,
8715a988416SJim Ingham                              "breakpoint modify",
8725a988416SJim Ingham                              "Modify the options on a breakpoint or set of breakpoints in the executable.  "
8735a988416SJim Ingham                              "If no breakpoint is specified, acts on the last created breakpoint.  "
8745a988416SJim Ingham                              "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
8755a988416SJim Ingham                              NULL),
8765a988416SJim Ingham         m_options (interpreter)
8775a988416SJim Ingham     {
8785a988416SJim Ingham         CommandArgumentEntry arg;
8795a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
8805a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
8815a988416SJim Ingham         m_arguments.push_back (arg);
8825a988416SJim Ingham     }
8835a988416SJim Ingham 
8845a988416SJim Ingham 
88513d21e9aSBruce Mitchener     ~CommandObjectBreakpointModify () override {}
8865a988416SJim Ingham 
88713d21e9aSBruce Mitchener     Options *
88813d21e9aSBruce Mitchener     GetOptions () override
8895a988416SJim Ingham     {
8905a988416SJim Ingham         return &m_options;
8915a988416SJim Ingham     }
8925a988416SJim Ingham 
8935a988416SJim Ingham     class CommandOptions : public Options
8945a988416SJim Ingham     {
8955a988416SJim Ingham     public:
8965a988416SJim Ingham 
8975a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
8985a988416SJim Ingham             Options (interpreter),
8995a988416SJim Ingham             m_ignore_count (0),
9005a988416SJim Ingham             m_thread_id(LLDB_INVALID_THREAD_ID),
9015a988416SJim Ingham             m_thread_id_passed(false),
9025a988416SJim Ingham             m_thread_index (UINT32_MAX),
9035a988416SJim Ingham             m_thread_index_passed(false),
9045a988416SJim Ingham             m_thread_name(),
9055a988416SJim Ingham             m_queue_name(),
9065a988416SJim Ingham             m_condition (),
907ca36cd16SJim Ingham             m_one_shot (false),
9085a988416SJim Ingham             m_enable_passed (false),
9095a988416SJim Ingham             m_enable_value (false),
9105a988416SJim Ingham             m_name_passed (false),
9115a988416SJim Ingham             m_queue_passed (false),
912ca36cd16SJim Ingham             m_condition_passed (false),
91333df7cd3SJim Ingham             m_one_shot_passed (false),
91433df7cd3SJim Ingham             m_use_dummy (false)
9155a988416SJim Ingham         {
9165a988416SJim Ingham         }
9175a988416SJim Ingham 
91813d21e9aSBruce Mitchener         ~CommandOptions () override {}
9195a988416SJim Ingham 
92013d21e9aSBruce Mitchener         Error
92113d21e9aSBruce Mitchener         SetOptionValue (uint32_t option_idx, const char *option_arg) override
9225a988416SJim Ingham         {
9235a988416SJim Ingham             Error error;
9243bcdfc0eSGreg Clayton             const int short_option = m_getopt_table[option_idx].val;
9255a988416SJim Ingham 
9265a988416SJim Ingham             switch (short_option)
9275a988416SJim Ingham             {
9285a988416SJim Ingham                 case 'c':
9295a988416SJim Ingham                     if (option_arg != NULL)
9305a988416SJim Ingham                         m_condition.assign (option_arg);
9315a988416SJim Ingham                     else
9325a988416SJim Ingham                         m_condition.clear();
9335a988416SJim Ingham                     m_condition_passed = true;
9345a988416SJim Ingham                     break;
9355a988416SJim Ingham                 case 'd':
9365a988416SJim Ingham                     m_enable_passed = true;
9375a988416SJim Ingham                     m_enable_value = false;
9385a988416SJim Ingham                     break;
93933df7cd3SJim Ingham                 case 'D':
94033df7cd3SJim Ingham                     m_use_dummy = true;
94133df7cd3SJim Ingham                     break;
9425a988416SJim Ingham                 case 'e':
9435a988416SJim Ingham                     m_enable_passed = true;
9445a988416SJim Ingham                     m_enable_value = true;
9455a988416SJim Ingham                     break;
9465a988416SJim Ingham                 case 'i':
9475a988416SJim Ingham                 {
9485275aaa0SVince Harron                     m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
9495a988416SJim Ingham                     if (m_ignore_count == UINT32_MAX)
9505a988416SJim Ingham                        error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
9515a988416SJim Ingham                 }
9525a988416SJim Ingham                 break;
953ca36cd16SJim Ingham                 case 'o':
954ca36cd16SJim Ingham                 {
955ca36cd16SJim Ingham                     bool value, success;
956ca36cd16SJim Ingham                     value = Args::StringToBoolean(option_arg, false, &success);
957ca36cd16SJim Ingham                     if (success)
958ca36cd16SJim Ingham                     {
959ca36cd16SJim Ingham                         m_one_shot_passed = true;
960ca36cd16SJim Ingham                         m_one_shot = value;
961ca36cd16SJim Ingham                     }
962ca36cd16SJim Ingham                     else
963ca36cd16SJim Ingham                         error.SetErrorStringWithFormat("invalid boolean value '%s' passed for -o option", option_arg);
964ca36cd16SJim Ingham                 }
965ca36cd16SJim Ingham                 break;
9665a988416SJim Ingham                 case 't' :
9675a988416SJim Ingham                 {
9685a988416SJim Ingham                     if (option_arg[0] == '\0')
9695a988416SJim Ingham                     {
9705a988416SJim Ingham                         m_thread_id = LLDB_INVALID_THREAD_ID;
9715a988416SJim Ingham                         m_thread_id_passed = true;
9725a988416SJim Ingham                     }
9735a988416SJim Ingham                     else
9745a988416SJim Ingham                     {
9755275aaa0SVince Harron                         m_thread_id = StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
9765a988416SJim Ingham                         if (m_thread_id == LLDB_INVALID_THREAD_ID)
9775a988416SJim Ingham                            error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
9785a988416SJim Ingham                         else
9795a988416SJim Ingham                             m_thread_id_passed = true;
9805a988416SJim Ingham                     }
9815a988416SJim Ingham                 }
9825a988416SJim Ingham                 break;
9835a988416SJim Ingham                 case 'T':
9845a988416SJim Ingham                     if (option_arg != NULL)
9855a988416SJim Ingham                         m_thread_name.assign (option_arg);
9865a988416SJim Ingham                     else
9875a988416SJim Ingham                         m_thread_name.clear();
9885a988416SJim Ingham                     m_name_passed = true;
9895a988416SJim Ingham                     break;
9905a988416SJim Ingham                 case 'q':
9915a988416SJim Ingham                     if (option_arg != NULL)
9925a988416SJim Ingham                         m_queue_name.assign (option_arg);
9935a988416SJim Ingham                     else
9945a988416SJim Ingham                         m_queue_name.clear();
9955a988416SJim Ingham                     m_queue_passed = true;
9965a988416SJim Ingham                     break;
9975a988416SJim Ingham                 case 'x':
9985a988416SJim Ingham                 {
9995a988416SJim Ingham                     if (option_arg[0] == '\n')
10005a988416SJim Ingham                     {
10015a988416SJim Ingham                         m_thread_index = UINT32_MAX;
10025a988416SJim Ingham                         m_thread_index_passed = true;
10035a988416SJim Ingham                     }
10045a988416SJim Ingham                     else
10055a988416SJim Ingham                     {
10065275aaa0SVince Harron                         m_thread_index = StringConvert::ToUInt32 (option_arg, UINT32_MAX, 0);
10075a988416SJim Ingham                         if (m_thread_id == UINT32_MAX)
10085a988416SJim Ingham                            error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
10095a988416SJim Ingham                         else
10105a988416SJim Ingham                             m_thread_index_passed = true;
10115a988416SJim Ingham                     }
10125a988416SJim Ingham                 }
10135a988416SJim Ingham                 break;
10145a988416SJim Ingham                 default:
10155a988416SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
10165a988416SJim Ingham                     break;
10175a988416SJim Ingham             }
10185a988416SJim Ingham 
10195a988416SJim Ingham             return error;
10205a988416SJim Ingham         }
10215a988416SJim Ingham         void
102213d21e9aSBruce Mitchener         OptionParsingStarting () override
10235a988416SJim Ingham         {
10245a988416SJim Ingham             m_ignore_count = 0;
10255a988416SJim Ingham             m_thread_id = LLDB_INVALID_THREAD_ID;
10265a988416SJim Ingham             m_thread_id_passed = false;
10275a988416SJim Ingham             m_thread_index = UINT32_MAX;
10285a988416SJim Ingham             m_thread_index_passed = false;
10295a988416SJim Ingham             m_thread_name.clear();
10305a988416SJim Ingham             m_queue_name.clear();
10315a988416SJim Ingham             m_condition.clear();
1032ca36cd16SJim Ingham             m_one_shot = false;
10335a988416SJim Ingham             m_enable_passed = false;
10345a988416SJim Ingham             m_queue_passed = false;
10355a988416SJim Ingham             m_name_passed = false;
10365a988416SJim Ingham             m_condition_passed = false;
1037ca36cd16SJim Ingham             m_one_shot_passed = false;
103833df7cd3SJim Ingham             m_use_dummy = false;
10395a988416SJim Ingham         }
10405a988416SJim Ingham 
10415a988416SJim Ingham         const OptionDefinition*
104213d21e9aSBruce Mitchener         GetDefinitions () override
10435a988416SJim Ingham         {
10445a988416SJim Ingham             return g_option_table;
10455a988416SJim Ingham         }
10465a988416SJim Ingham 
10475a988416SJim Ingham 
10485a988416SJim Ingham         // Options table: Required for subclasses of Options.
10495a988416SJim Ingham 
10505a988416SJim Ingham         static OptionDefinition g_option_table[];
10515a988416SJim Ingham 
10525a988416SJim Ingham         // Instance variables to hold the values for command options.
10535a988416SJim Ingham 
10545a988416SJim Ingham         uint32_t m_ignore_count;
10555a988416SJim Ingham         lldb::tid_t m_thread_id;
10565a988416SJim Ingham         bool m_thread_id_passed;
10575a988416SJim Ingham         uint32_t m_thread_index;
10585a988416SJim Ingham         bool m_thread_index_passed;
10595a988416SJim Ingham         std::string m_thread_name;
10605a988416SJim Ingham         std::string m_queue_name;
10615a988416SJim Ingham         std::string m_condition;
1062ca36cd16SJim Ingham         bool m_one_shot;
10635a988416SJim Ingham         bool m_enable_passed;
10645a988416SJim Ingham         bool m_enable_value;
10655a988416SJim Ingham         bool m_name_passed;
10665a988416SJim Ingham         bool m_queue_passed;
10675a988416SJim Ingham         bool m_condition_passed;
1068ca36cd16SJim Ingham         bool m_one_shot_passed;
106933df7cd3SJim Ingham         bool m_use_dummy;
10705a988416SJim Ingham 
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);
10785a988416SJim Ingham         if (target == NULL)
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 {
1167d37221dcSZachary Turner { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." },
1168d37221dcSZachary Turner { LLDB_OPT_SET_ALL, false, "one-shot",     'o', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "The breakpoint is deleted the first time it stop causes a stop." },
1169d37221dcSZachary Turner { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose index matches this argument."},
1170d37221dcSZachary Turner { LLDB_OPT_SET_ALL, false, "thread-id",    't', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."},
1171d37221dcSZachary Turner { LLDB_OPT_SET_ALL, false, "thread-name",  'T', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."},
1172d37221dcSZachary Turner { LLDB_OPT_SET_ALL, false, "queue-name",   'q', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."},
1173d37221dcSZachary Turner { LLDB_OPT_SET_ALL, false, "condition",    'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."},
1174d37221dcSZachary Turner { LLDB_OPT_SET_1,   false, "enable",       'e', OptionParser::eNoArgument,       NULL, NULL, 0, eArgTypeNone, "Enable the breakpoint."},
1175d37221dcSZachary Turner { LLDB_OPT_SET_2,   false, "disable",      'd', OptionParser::eNoArgument,       NULL, NULL, 0, eArgTypeNone, "Disable the breakpoint."},
117633df7cd3SJim Ingham { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
117733df7cd3SJim Ingham 
1178d37221dcSZachary Turner { 0,                false, NULL,            0 , 0,                 NULL, NULL, 0, eArgTypeNone, NULL }
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.",
11935a988416SJim Ingham                              NULL)
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 
12015a988416SJim Ingham 
120213d21e9aSBruce Mitchener     ~CommandObjectBreakpointEnable () override {}
12035a988416SJim Ingham 
12045a988416SJim Ingham protected:
120513d21e9aSBruce Mitchener     bool
120613d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
12075a988416SJim Ingham     {
1208893c932aSJim Ingham         Target *target = GetSelectedOrDummyTarget();
12095a988416SJim Ingham         if (target == NULL)
12105a988416SJim Ingham         {
12115a988416SJim Ingham             result.AppendError ("Invalid target.  No existing target or breakpoints.");
12125a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
12135a988416SJim Ingham             return false;
12145a988416SJim Ingham         }
12155a988416SJim Ingham 
12165a988416SJim Ingham         Mutex::Locker locker;
12175a988416SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
12185a988416SJim Ingham 
12195a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
12205a988416SJim Ingham 
12215a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
12225a988416SJim Ingham 
12235a988416SJim Ingham         if (num_breakpoints == 0)
12245a988416SJim Ingham         {
12255a988416SJim Ingham             result.AppendError ("No breakpoints exist to be enabled.");
12265a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
12275a988416SJim Ingham             return false;
12285a988416SJim Ingham         }
12295a988416SJim Ingham 
12305a988416SJim Ingham         if (command.GetArgumentCount() == 0)
12315a988416SJim Ingham         {
12325a988416SJim Ingham             // No breakpoint selected; enable all currently set breakpoints.
12335a988416SJim Ingham             target->EnableAllBreakpoints ();
12346fea17e8SGreg Clayton             result.AppendMessageWithFormat ("All breakpoints enabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints);
12355a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
12365a988416SJim Ingham         }
12375a988416SJim Ingham         else
12385a988416SJim Ingham         {
12395a988416SJim Ingham             // Particular breakpoint selected; enable that breakpoint.
12405a988416SJim Ingham             BreakpointIDList valid_bp_ids;
12415e09c8c3SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
12425a988416SJim Ingham 
12435a988416SJim Ingham             if (result.Succeeded())
12445a988416SJim Ingham             {
12455a988416SJim Ingham                 int enable_count = 0;
12465a988416SJim Ingham                 int loc_count = 0;
12475a988416SJim Ingham                 const size_t count = valid_bp_ids.GetSize();
12485a988416SJim Ingham                 for (size_t i = 0; i < count; ++i)
12495a988416SJim Ingham                 {
12505a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
12515a988416SJim Ingham 
12525a988416SJim Ingham                     if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
12535a988416SJim Ingham                     {
12545a988416SJim Ingham                         Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
12555a988416SJim Ingham                         if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
12565a988416SJim Ingham                         {
12575a988416SJim Ingham                             BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
12585a988416SJim Ingham                             if (location)
12595a988416SJim Ingham                             {
12605a988416SJim Ingham                                 location->SetEnabled (true);
12615a988416SJim Ingham                                 ++loc_count;
12625a988416SJim Ingham                             }
12635a988416SJim Ingham                         }
12645a988416SJim Ingham                         else
12655a988416SJim Ingham                         {
12665a988416SJim Ingham                             breakpoint->SetEnabled (true);
12675a988416SJim Ingham                             ++enable_count;
12685a988416SJim Ingham                         }
12695a988416SJim Ingham                     }
12705a988416SJim Ingham                 }
12715a988416SJim Ingham                 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
12725a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
12735a988416SJim Ingham             }
12745a988416SJim Ingham         }
12755a988416SJim Ingham 
12765a988416SJim Ingham         return result.Succeeded();
12775a988416SJim Ingham     }
12785a988416SJim Ingham };
12795a988416SJim Ingham 
12805a988416SJim Ingham //-------------------------------------------------------------------------
12815a988416SJim Ingham // CommandObjectBreakpointDisable
12825a988416SJim Ingham //-------------------------------------------------------------------------
12835a988416SJim Ingham #pragma mark Disable
12845a988416SJim Ingham 
12855a988416SJim Ingham class CommandObjectBreakpointDisable : public CommandObjectParsed
12865a988416SJim Ingham {
12875a988416SJim Ingham public:
12885a988416SJim Ingham     CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
12895a988416SJim Ingham         CommandObjectParsed (interpreter,
12905a988416SJim Ingham                              "breakpoint disable",
1291ea671fbdSKate Stone                              "Disable the specified breakpoint(s) without removing them.  If none are specified, disable all breakpoints.",
12925a988416SJim Ingham                              NULL)
12935a988416SJim Ingham     {
1294b0fac509SJim Ingham         SetHelpLong(
1295ea671fbdSKate Stone "Disable the specified breakpoint(s) without removing them.  \
1296ea671fbdSKate Stone If none are specified, disable all breakpoints." R"(
1297ea671fbdSKate Stone 
1298ea671fbdSKate Stone )" "Note: disabling a breakpoint will cause none of its locations to be hit \
1299ea671fbdSKate Stone regardless of whether they are enabled or disabled.  After the sequence:" R"(
1300ea671fbdSKate Stone 
1301ea671fbdSKate Stone     (lldb) break disable 1
1302ea671fbdSKate Stone     (lldb) break enable 1.1
1303ea671fbdSKate Stone 
1304ea671fbdSKate Stone execution will NOT stop at location 1.1.  To achieve that, type:
1305ea671fbdSKate Stone 
1306ea671fbdSKate Stone     (lldb) break disable 1.*
1307ea671fbdSKate Stone     (lldb) break enable 1.1
1308ea671fbdSKate Stone 
1309ea671fbdSKate Stone )" "The first command disables all the locations of breakpoint 1, \
1310b0fac509SJim Ingham the second re-enables the first location."
1311b0fac509SJim Ingham         );
1312b0fac509SJim Ingham 
13135a988416SJim Ingham         CommandArgumentEntry arg;
13145a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
13155a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
13165a988416SJim Ingham         m_arguments.push_back (arg);
1317b0fac509SJim Ingham 
13185a988416SJim Ingham     }
13195a988416SJim Ingham 
13205a988416SJim Ingham 
132113d21e9aSBruce Mitchener     ~CommandObjectBreakpointDisable () override {}
13225a988416SJim Ingham 
13235a988416SJim Ingham protected:
132413d21e9aSBruce Mitchener     bool
132513d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
13265a988416SJim Ingham     {
1327893c932aSJim Ingham         Target *target = GetSelectedOrDummyTarget();
13285a988416SJim Ingham         if (target == NULL)
13295a988416SJim Ingham         {
13305a988416SJim Ingham             result.AppendError ("Invalid target.  No existing target or breakpoints.");
13315a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
13325a988416SJim Ingham             return false;
13335a988416SJim Ingham         }
13345a988416SJim Ingham 
13355a988416SJim Ingham         Mutex::Locker locker;
13365a988416SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
13375a988416SJim Ingham 
13385a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
13395a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
13405a988416SJim Ingham 
13415a988416SJim Ingham         if (num_breakpoints == 0)
13425a988416SJim Ingham         {
13435a988416SJim Ingham             result.AppendError ("No breakpoints exist to be disabled.");
13445a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
13455a988416SJim Ingham             return false;
13465a988416SJim Ingham         }
13475a988416SJim Ingham 
13485a988416SJim Ingham         if (command.GetArgumentCount() == 0)
13495a988416SJim Ingham         {
13505a988416SJim Ingham             // No breakpoint selected; disable all currently set breakpoints.
13515a988416SJim Ingham             target->DisableAllBreakpoints ();
13526fea17e8SGreg Clayton             result.AppendMessageWithFormat ("All breakpoints disabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints);
13535a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
13545a988416SJim Ingham         }
13555a988416SJim Ingham         else
13565a988416SJim Ingham         {
13575a988416SJim Ingham             // Particular breakpoint selected; disable that breakpoint.
13585a988416SJim Ingham             BreakpointIDList valid_bp_ids;
13595a988416SJim Ingham 
13605e09c8c3SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
13615a988416SJim Ingham 
13625a988416SJim Ingham             if (result.Succeeded())
13635a988416SJim Ingham             {
13645a988416SJim Ingham                 int disable_count = 0;
13655a988416SJim Ingham                 int loc_count = 0;
13665a988416SJim Ingham                 const size_t count = valid_bp_ids.GetSize();
13675a988416SJim Ingham                 for (size_t i = 0; i < count; ++i)
13685a988416SJim Ingham                 {
13695a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
13705a988416SJim Ingham 
13715a988416SJim Ingham                     if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
13725a988416SJim Ingham                     {
13735a988416SJim Ingham                         Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
13745a988416SJim Ingham                         if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
13755a988416SJim Ingham                         {
13765a988416SJim Ingham                             BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
13775a988416SJim Ingham                             if (location)
13785a988416SJim Ingham                             {
13795a988416SJim Ingham                                 location->SetEnabled (false);
13805a988416SJim Ingham                                 ++loc_count;
13815a988416SJim Ingham                             }
13825a988416SJim Ingham                         }
13835a988416SJim Ingham                         else
13845a988416SJim Ingham                         {
13855a988416SJim Ingham                             breakpoint->SetEnabled (false);
13865a988416SJim Ingham                             ++disable_count;
13875a988416SJim Ingham                         }
13885a988416SJim Ingham                     }
13895a988416SJim Ingham                 }
13905a988416SJim Ingham                 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
13915a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
13925a988416SJim Ingham             }
13935a988416SJim Ingham         }
13945a988416SJim Ingham 
13955a988416SJim Ingham         return result.Succeeded();
13965a988416SJim Ingham     }
13975a988416SJim Ingham 
13985a988416SJim Ingham };
13995a988416SJim Ingham 
14005a988416SJim Ingham //-------------------------------------------------------------------------
14015a988416SJim Ingham // CommandObjectBreakpointList
14025a988416SJim Ingham //-------------------------------------------------------------------------
14035a988416SJim Ingham #pragma mark List
14045a988416SJim Ingham 
14055a988416SJim Ingham class CommandObjectBreakpointList : public CommandObjectParsed
14065a988416SJim Ingham {
14075a988416SJim Ingham public:
14085a988416SJim Ingham     CommandObjectBreakpointList (CommandInterpreter &interpreter) :
14095a988416SJim Ingham         CommandObjectParsed (interpreter,
14105a988416SJim Ingham                              "breakpoint list",
14115a988416SJim Ingham                              "List some or all breakpoints at configurable levels of detail.",
14125a988416SJim Ingham                              NULL),
14135a988416SJim Ingham         m_options (interpreter)
14145a988416SJim Ingham     {
14155a988416SJim Ingham         CommandArgumentEntry arg;
14165a988416SJim Ingham         CommandArgumentData bp_id_arg;
14175a988416SJim Ingham 
14185a988416SJim Ingham         // Define the first (and only) variant of this arg.
14195a988416SJim Ingham         bp_id_arg.arg_type = eArgTypeBreakpointID;
14205a988416SJim Ingham         bp_id_arg.arg_repetition = eArgRepeatOptional;
14215a988416SJim Ingham 
14225a988416SJim Ingham         // There is only one variant this argument could be; put it into the argument entry.
14235a988416SJim Ingham         arg.push_back (bp_id_arg);
14245a988416SJim Ingham 
14255a988416SJim Ingham         // Push the data for the first argument into the m_arguments vector.
14265a988416SJim Ingham         m_arguments.push_back (arg);
14275a988416SJim Ingham     }
14285a988416SJim Ingham 
14295a988416SJim Ingham 
143013d21e9aSBruce Mitchener     ~CommandObjectBreakpointList () override {}
14315a988416SJim Ingham 
143213d21e9aSBruce Mitchener     Options *
143313d21e9aSBruce Mitchener     GetOptions () override
14345a988416SJim Ingham     {
14355a988416SJim Ingham         return &m_options;
14365a988416SJim Ingham     }
14375a988416SJim Ingham 
14385a988416SJim Ingham     class CommandOptions : public Options
14395a988416SJim Ingham     {
14405a988416SJim Ingham     public:
14415a988416SJim Ingham 
14425a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
14435a988416SJim Ingham             Options (interpreter),
144433df7cd3SJim Ingham             m_level (lldb::eDescriptionLevelBrief),
144533df7cd3SJim Ingham             m_use_dummy(false)
14465a988416SJim Ingham         {
14475a988416SJim Ingham         }
14485a988416SJim Ingham 
144913d21e9aSBruce Mitchener         ~CommandOptions () override {}
14505a988416SJim Ingham 
145113d21e9aSBruce Mitchener         Error
145213d21e9aSBruce Mitchener         SetOptionValue (uint32_t option_idx, const char *option_arg) override
14535a988416SJim Ingham         {
14545a988416SJim Ingham             Error error;
14553bcdfc0eSGreg Clayton             const int short_option = m_getopt_table[option_idx].val;
14565a988416SJim Ingham 
14575a988416SJim Ingham             switch (short_option)
14585a988416SJim Ingham             {
14595a988416SJim Ingham                 case 'b':
14605a988416SJim Ingham                     m_level = lldb::eDescriptionLevelBrief;
14615a988416SJim Ingham                     break;
146233df7cd3SJim Ingham                 case 'D':
146333df7cd3SJim Ingham                     m_use_dummy = true;
146433df7cd3SJim Ingham                     break;
14655a988416SJim Ingham                 case 'f':
14665a988416SJim Ingham                     m_level = lldb::eDescriptionLevelFull;
14675a988416SJim Ingham                     break;
14685a988416SJim Ingham                 case 'v':
14695a988416SJim Ingham                     m_level = lldb::eDescriptionLevelVerbose;
14705a988416SJim Ingham                     break;
14715a988416SJim Ingham                 case 'i':
14725a988416SJim Ingham                     m_internal = true;
14735a988416SJim Ingham                     break;
14745a988416SJim Ingham                 default:
14755a988416SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
14765a988416SJim Ingham                     break;
14775a988416SJim Ingham             }
14785a988416SJim Ingham 
14795a988416SJim Ingham             return error;
14805a988416SJim Ingham         }
14815a988416SJim Ingham 
14825a988416SJim Ingham         void
148313d21e9aSBruce Mitchener         OptionParsingStarting () override
14845a988416SJim Ingham         {
14855a988416SJim Ingham             m_level = lldb::eDescriptionLevelFull;
14865a988416SJim Ingham             m_internal = false;
148733df7cd3SJim Ingham             m_use_dummy = false;
14885a988416SJim Ingham         }
14895a988416SJim Ingham 
14905a988416SJim Ingham         const OptionDefinition *
149113d21e9aSBruce Mitchener         GetDefinitions () override
14925a988416SJim Ingham         {
14935a988416SJim Ingham             return g_option_table;
14945a988416SJim Ingham         }
14955a988416SJim Ingham 
14965a988416SJim Ingham         // Options table: Required for subclasses of Options.
14975a988416SJim Ingham 
14985a988416SJim Ingham         static OptionDefinition g_option_table[];
14995a988416SJim Ingham 
15005a988416SJim Ingham         // Instance variables to hold the values for command options.
15015a988416SJim Ingham 
15025a988416SJim Ingham         lldb::DescriptionLevel m_level;
15035a988416SJim Ingham 
15045a988416SJim Ingham         bool m_internal;
150533df7cd3SJim Ingham         bool m_use_dummy;
15065a988416SJim Ingham     };
15075a988416SJim Ingham 
15085a988416SJim Ingham protected:
150913d21e9aSBruce Mitchener     bool
151013d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
15115a988416SJim Ingham     {
151233df7cd3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
151333df7cd3SJim Ingham 
15145a988416SJim Ingham         if (target == NULL)
15155a988416SJim Ingham         {
15165a988416SJim Ingham             result.AppendError ("Invalid target. No current target or breakpoints.");
15175a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
15185a988416SJim Ingham             return true;
15195a988416SJim Ingham         }
15205a988416SJim Ingham 
15215a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
15225a988416SJim Ingham         Mutex::Locker locker;
15235a988416SJim Ingham         target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
15245a988416SJim Ingham 
15255a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
15265a988416SJim Ingham 
15275a988416SJim Ingham         if (num_breakpoints == 0)
15285a988416SJim Ingham         {
15295a988416SJim Ingham             result.AppendMessage ("No breakpoints currently set.");
15305a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
15315a988416SJim Ingham             return true;
15325a988416SJim Ingham         }
15335a988416SJim Ingham 
15345a988416SJim Ingham         Stream &output_stream = result.GetOutputStream();
15355a988416SJim Ingham 
15365a988416SJim Ingham         if (command.GetArgumentCount() == 0)
15375a988416SJim Ingham         {
15385a988416SJim Ingham             // No breakpoint selected; show info about all currently set breakpoints.
15395a988416SJim Ingham             result.AppendMessage ("Current breakpoints:");
15405a988416SJim Ingham             for (size_t i = 0; i < num_breakpoints; ++i)
15415a988416SJim Ingham             {
15425a988416SJim Ingham                 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
15435a988416SJim Ingham                 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
15445a988416SJim Ingham             }
15455a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
15465a988416SJim Ingham         }
15475a988416SJim Ingham         else
15485a988416SJim Ingham         {
15495a988416SJim Ingham             // Particular breakpoints selected; show info about that breakpoint.
15505a988416SJim Ingham             BreakpointIDList valid_bp_ids;
15515e09c8c3SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
15525a988416SJim Ingham 
15535a988416SJim Ingham             if (result.Succeeded())
15545a988416SJim Ingham             {
15555a988416SJim Ingham                 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
15565a988416SJim Ingham                 {
15575a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
15585a988416SJim Ingham                     Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
15595a988416SJim Ingham                     AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
15605a988416SJim Ingham                 }
15615a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
15625a988416SJim Ingham             }
15635a988416SJim Ingham             else
15645a988416SJim Ingham             {
15655a988416SJim Ingham                 result.AppendError ("Invalid breakpoint id.");
15665a988416SJim Ingham                 result.SetStatus (eReturnStatusFailed);
15675a988416SJim Ingham             }
15685a988416SJim Ingham         }
15695a988416SJim Ingham 
15705a988416SJim Ingham         return result.Succeeded();
15715a988416SJim Ingham     }
15725a988416SJim Ingham 
15735a988416SJim Ingham private:
15745a988416SJim Ingham     CommandOptions m_options;
15755a988416SJim Ingham };
15765a988416SJim Ingham 
15775a988416SJim Ingham #pragma mark List::CommandOptions
15785a988416SJim Ingham OptionDefinition
15795a988416SJim Ingham CommandObjectBreakpointList::CommandOptions::g_option_table[] =
15805a988416SJim Ingham {
1581d37221dcSZachary Turner     { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
15825a988416SJim Ingham         "Show debugger internal breakpoints" },
15835a988416SJim Ingham 
1584d37221dcSZachary Turner     { LLDB_OPT_SET_1, false, "brief",    'b', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
15855a988416SJim Ingham         "Give a brief description of the breakpoint (no location info)."},
15865a988416SJim Ingham 
15875a988416SJim Ingham     // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
15885a988416SJim Ingham     // But I need to see it for now, and don't want to wait.
1589d37221dcSZachary Turner     { LLDB_OPT_SET_2, false, "full",    'f', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
15905a988416SJim Ingham         "Give a full description of the breakpoint and its locations."},
15915a988416SJim Ingham 
1592d37221dcSZachary Turner     { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
15935a988416SJim Ingham         "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
15945a988416SJim Ingham 
159533df7cd3SJim Ingham     { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
159633df7cd3SJim Ingham         "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
159733df7cd3SJim Ingham 
1598d37221dcSZachary Turner     { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
15995a988416SJim Ingham };
16005a988416SJim Ingham 
16015a988416SJim Ingham //-------------------------------------------------------------------------
16025a988416SJim Ingham // CommandObjectBreakpointClear
16035a988416SJim Ingham //-------------------------------------------------------------------------
16045a988416SJim Ingham #pragma mark Clear
16055a988416SJim Ingham 
16065a988416SJim Ingham class CommandObjectBreakpointClear : public CommandObjectParsed
16075a988416SJim Ingham {
16085a988416SJim Ingham public:
16095a988416SJim Ingham 
16105a988416SJim Ingham     typedef enum BreakpointClearType
16115a988416SJim Ingham     {
16125a988416SJim Ingham         eClearTypeInvalid,
16135a988416SJim Ingham         eClearTypeFileAndLine
16145a988416SJim Ingham     } BreakpointClearType;
16155a988416SJim Ingham 
16165a988416SJim Ingham     CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
16175a988416SJim Ingham         CommandObjectParsed (interpreter,
16185a988416SJim Ingham                              "breakpoint clear",
16195a988416SJim Ingham                              "Clears a breakpoint or set of breakpoints in the executable.",
16205a988416SJim Ingham                              "breakpoint clear <cmd-options>"),
16215a988416SJim Ingham         m_options (interpreter)
16225a988416SJim Ingham     {
16235a988416SJim Ingham     }
16245a988416SJim Ingham 
162513d21e9aSBruce Mitchener     ~CommandObjectBreakpointClear () override {}
16265a988416SJim Ingham 
162713d21e9aSBruce Mitchener     Options *
162813d21e9aSBruce Mitchener     GetOptions () override
16295a988416SJim Ingham     {
16305a988416SJim Ingham         return &m_options;
16315a988416SJim Ingham     }
16325a988416SJim Ingham 
16335a988416SJim Ingham     class CommandOptions : public Options
16345a988416SJim Ingham     {
16355a988416SJim Ingham     public:
16365a988416SJim Ingham 
16375a988416SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
16385a988416SJim Ingham             Options (interpreter),
16395a988416SJim Ingham             m_filename (),
16405a988416SJim Ingham             m_line_num (0)
16415a988416SJim Ingham         {
16425a988416SJim Ingham         }
16435a988416SJim Ingham 
164413d21e9aSBruce Mitchener         ~CommandOptions () override {}
16455a988416SJim Ingham 
164613d21e9aSBruce Mitchener         Error
164713d21e9aSBruce Mitchener         SetOptionValue (uint32_t option_idx, const char *option_arg) override
16485a988416SJim Ingham         {
16495a988416SJim Ingham             Error error;
16503bcdfc0eSGreg Clayton             const int short_option = m_getopt_table[option_idx].val;
16515a988416SJim Ingham 
16525a988416SJim Ingham             switch (short_option)
16535a988416SJim Ingham             {
16545a988416SJim Ingham                 case 'f':
16555a988416SJim Ingham                     m_filename.assign (option_arg);
16565a988416SJim Ingham                     break;
16575a988416SJim Ingham 
16585a988416SJim Ingham                 case 'l':
16595275aaa0SVince Harron                     m_line_num = StringConvert::ToUInt32 (option_arg, 0);
16605a988416SJim Ingham                     break;
16615a988416SJim Ingham 
16625a988416SJim Ingham                 default:
16635a988416SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
16645a988416SJim Ingham                     break;
16655a988416SJim Ingham             }
16665a988416SJim Ingham 
16675a988416SJim Ingham             return error;
16685a988416SJim Ingham         }
16695a988416SJim Ingham 
16705a988416SJim Ingham         void
167113d21e9aSBruce Mitchener         OptionParsingStarting () override
16725a988416SJim Ingham         {
16735a988416SJim Ingham             m_filename.clear();
16745a988416SJim Ingham             m_line_num = 0;
16755a988416SJim Ingham         }
16765a988416SJim Ingham 
16775a988416SJim Ingham         const OptionDefinition*
167813d21e9aSBruce Mitchener         GetDefinitions () override
16795a988416SJim Ingham         {
16805a988416SJim Ingham             return g_option_table;
16815a988416SJim Ingham         }
16825a988416SJim Ingham 
16835a988416SJim Ingham         // Options table: Required for subclasses of Options.
16845a988416SJim Ingham 
16855a988416SJim Ingham         static OptionDefinition g_option_table[];
16865a988416SJim Ingham 
16875a988416SJim Ingham         // Instance variables to hold the values for command options.
16885a988416SJim Ingham 
16895a988416SJim Ingham         std::string m_filename;
16905a988416SJim Ingham         uint32_t m_line_num;
16915a988416SJim Ingham 
16925a988416SJim Ingham     };
16935a988416SJim Ingham 
16945a988416SJim Ingham protected:
169513d21e9aSBruce Mitchener     bool
169613d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
16975a988416SJim Ingham     {
1698893c932aSJim Ingham         Target *target = GetSelectedOrDummyTarget();
16995a988416SJim Ingham         if (target == NULL)
17005a988416SJim Ingham         {
17015a988416SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
17025a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
17035a988416SJim Ingham             return false;
17045a988416SJim Ingham         }
17055a988416SJim Ingham 
17065a988416SJim Ingham         // The following are the various types of breakpoints that could be cleared:
17075a988416SJim Ingham         //   1). -f -l (clearing breakpoint by source location)
17085a988416SJim Ingham 
17095a988416SJim Ingham         BreakpointClearType break_type = eClearTypeInvalid;
17105a988416SJim Ingham 
17115a988416SJim Ingham         if (m_options.m_line_num != 0)
17125a988416SJim Ingham             break_type = eClearTypeFileAndLine;
17135a988416SJim Ingham 
17145a988416SJim Ingham         Mutex::Locker locker;
17155a988416SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
17165a988416SJim Ingham 
17175a988416SJim Ingham         BreakpointList &breakpoints = target->GetBreakpointList();
17185a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
17195a988416SJim Ingham 
17205a988416SJim Ingham         // Early return if there's no breakpoint at all.
17215a988416SJim Ingham         if (num_breakpoints == 0)
17225a988416SJim Ingham         {
17235a988416SJim Ingham             result.AppendError ("Breakpoint clear: No breakpoint cleared.");
17245a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
17255a988416SJim Ingham             return result.Succeeded();
17265a988416SJim Ingham         }
17275a988416SJim Ingham 
17285a988416SJim Ingham         // Find matching breakpoints and delete them.
17295a988416SJim Ingham 
17305a988416SJim Ingham         // First create a copy of all the IDs.
17315a988416SJim Ingham         std::vector<break_id_t> BreakIDs;
17325a988416SJim Ingham         for (size_t i = 0; i < num_breakpoints; ++i)
17335a988416SJim Ingham             BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID());
17345a988416SJim Ingham 
17355a988416SJim Ingham         int num_cleared = 0;
17365a988416SJim Ingham         StreamString ss;
17375a988416SJim Ingham         switch (break_type)
17385a988416SJim Ingham         {
17395a988416SJim Ingham             case eClearTypeFileAndLine: // Breakpoint by source position
17405a988416SJim Ingham                 {
17415a988416SJim Ingham                     const ConstString filename(m_options.m_filename.c_str());
17425a988416SJim Ingham                     BreakpointLocationCollection loc_coll;
17435a988416SJim Ingham 
17445a988416SJim Ingham                     for (size_t i = 0; i < num_breakpoints; ++i)
17455a988416SJim Ingham                     {
17465a988416SJim Ingham                         Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
17475a988416SJim Ingham 
17485a988416SJim Ingham                         if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
17495a988416SJim Ingham                         {
17505a988416SJim Ingham                             // If the collection size is 0, it's a full match and we can just remove the breakpoint.
17515a988416SJim Ingham                             if (loc_coll.GetSize() == 0)
17525a988416SJim Ingham                             {
17535a988416SJim Ingham                                 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
17545a988416SJim Ingham                                 ss.EOL();
17555a988416SJim Ingham                                 target->RemoveBreakpointByID (bp->GetID());
17565a988416SJim Ingham                                 ++num_cleared;
17575a988416SJim Ingham                             }
17585a988416SJim Ingham                         }
17595a988416SJim Ingham                     }
17605a988416SJim Ingham                 }
17615a988416SJim Ingham                 break;
17625a988416SJim Ingham 
17635a988416SJim Ingham             default:
17645a988416SJim Ingham                 break;
17655a988416SJim Ingham         }
17665a988416SJim Ingham 
17675a988416SJim Ingham         if (num_cleared > 0)
17685a988416SJim Ingham         {
17695a988416SJim Ingham             Stream &output_stream = result.GetOutputStream();
17705a988416SJim Ingham             output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
17715a988416SJim Ingham             output_stream << ss.GetData();
17725a988416SJim Ingham             output_stream.EOL();
17735a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
17745a988416SJim Ingham         }
17755a988416SJim Ingham         else
17765a988416SJim Ingham         {
17775a988416SJim Ingham             result.AppendError ("Breakpoint clear: No breakpoint cleared.");
17785a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
17795a988416SJim Ingham         }
17805a988416SJim Ingham 
17815a988416SJim Ingham         return result.Succeeded();
17825a988416SJim Ingham     }
17835a988416SJim Ingham 
17845a988416SJim Ingham private:
17855a988416SJim Ingham     CommandOptions m_options;
17865a988416SJim Ingham };
17875a988416SJim Ingham 
17885a988416SJim Ingham #pragma mark Clear::CommandOptions
17895a988416SJim Ingham 
17905a988416SJim Ingham OptionDefinition
17915a988416SJim Ingham CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
17925a988416SJim Ingham {
1793d37221dcSZachary Turner     { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
17945a988416SJim Ingham         "Specify the breakpoint by source location in this particular file."},
17955a988416SJim Ingham 
1796d37221dcSZachary Turner     { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLineNum,
17975a988416SJim Ingham         "Specify the breakpoint by source location at this particular line."},
17985a988416SJim Ingham 
1799d37221dcSZachary Turner     { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
18005a988416SJim Ingham };
18015a988416SJim Ingham 
18025a988416SJim Ingham //-------------------------------------------------------------------------
18035a988416SJim Ingham // CommandObjectBreakpointDelete
18045a988416SJim Ingham //-------------------------------------------------------------------------
18055a988416SJim Ingham #pragma mark Delete
18065a988416SJim Ingham 
18075a988416SJim Ingham class CommandObjectBreakpointDelete : public CommandObjectParsed
18085a988416SJim Ingham {
18095a988416SJim Ingham public:
18105a988416SJim Ingham     CommandObjectBreakpointDelete (CommandInterpreter &interpreter) :
18115a988416SJim Ingham         CommandObjectParsed (interpreter,
18125a988416SJim Ingham                              "breakpoint delete",
18135a988416SJim Ingham                              "Delete the specified breakpoint(s).  If no breakpoints are specified, delete them all.",
181433df7cd3SJim Ingham                              NULL),
181533df7cd3SJim Ingham         m_options (interpreter)
18165a988416SJim Ingham     {
18175a988416SJim Ingham         CommandArgumentEntry arg;
18185a988416SJim Ingham         CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
18195a988416SJim Ingham         // Add the entry for the first argument for this command to the object's arguments vector.
18205a988416SJim Ingham         m_arguments.push_back (arg);
18215a988416SJim Ingham     }
18225a988416SJim Ingham 
182313d21e9aSBruce Mitchener     ~CommandObjectBreakpointDelete () override {}
18245a988416SJim Ingham 
182513d21e9aSBruce Mitchener     Options *
182613d21e9aSBruce Mitchener     GetOptions () override
182733df7cd3SJim Ingham     {
182833df7cd3SJim Ingham         return &m_options;
182933df7cd3SJim Ingham     }
183033df7cd3SJim Ingham 
183133df7cd3SJim Ingham     class CommandOptions : public Options
183233df7cd3SJim Ingham     {
183333df7cd3SJim Ingham     public:
183433df7cd3SJim Ingham 
183533df7cd3SJim Ingham         CommandOptions (CommandInterpreter &interpreter) :
183633df7cd3SJim Ingham             Options (interpreter),
183733df7cd3SJim Ingham             m_use_dummy (false),
183833df7cd3SJim Ingham             m_force (false)
183933df7cd3SJim Ingham         {
184033df7cd3SJim Ingham         }
184133df7cd3SJim Ingham 
184213d21e9aSBruce Mitchener         ~CommandOptions () override {}
184333df7cd3SJim Ingham 
184413d21e9aSBruce Mitchener         Error
184513d21e9aSBruce Mitchener         SetOptionValue (uint32_t option_idx, const char *option_arg) override
184633df7cd3SJim Ingham         {
184733df7cd3SJim Ingham             Error error;
184833df7cd3SJim Ingham             const int short_option = m_getopt_table[option_idx].val;
184933df7cd3SJim Ingham 
185033df7cd3SJim Ingham             switch (short_option)
185133df7cd3SJim Ingham             {
185233df7cd3SJim Ingham                 case 'f':
185333df7cd3SJim Ingham                     m_force = true;
185433df7cd3SJim Ingham                     break;
185533df7cd3SJim Ingham 
185633df7cd3SJim Ingham                 case 'D':
185733df7cd3SJim Ingham                     m_use_dummy = true;
185833df7cd3SJim Ingham                     break;
185933df7cd3SJim Ingham 
186033df7cd3SJim Ingham                 default:
186133df7cd3SJim Ingham                     error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
186233df7cd3SJim Ingham                     break;
186333df7cd3SJim Ingham             }
186433df7cd3SJim Ingham 
186533df7cd3SJim Ingham             return error;
186633df7cd3SJim Ingham         }
186733df7cd3SJim Ingham 
186833df7cd3SJim Ingham         void
186913d21e9aSBruce Mitchener         OptionParsingStarting () override
187033df7cd3SJim Ingham         {
187133df7cd3SJim Ingham             m_use_dummy = false;
187233df7cd3SJim Ingham             m_force = false;
187333df7cd3SJim Ingham         }
187433df7cd3SJim Ingham 
187533df7cd3SJim Ingham         const OptionDefinition*
187613d21e9aSBruce Mitchener         GetDefinitions () override
187733df7cd3SJim Ingham         {
187833df7cd3SJim Ingham             return g_option_table;
187933df7cd3SJim Ingham         }
188033df7cd3SJim Ingham 
188133df7cd3SJim Ingham         // Options table: Required for subclasses of Options.
188233df7cd3SJim Ingham 
188333df7cd3SJim Ingham         static OptionDefinition g_option_table[];
188433df7cd3SJim Ingham 
188533df7cd3SJim Ingham         // Instance variables to hold the values for command options.
188633df7cd3SJim Ingham         bool m_use_dummy;
188733df7cd3SJim Ingham         bool m_force;
188833df7cd3SJim Ingham     };
188933df7cd3SJim Ingham 
18905a988416SJim Ingham protected:
189113d21e9aSBruce Mitchener     bool
189213d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
18935a988416SJim Ingham     {
189433df7cd3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
189533df7cd3SJim Ingham 
18965a988416SJim Ingham         if (target == NULL)
18975a988416SJim Ingham         {
18985a988416SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
18995a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
19005a988416SJim Ingham             return false;
19015a988416SJim Ingham         }
19025a988416SJim Ingham 
19035a988416SJim Ingham         Mutex::Locker locker;
19045a988416SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
19055a988416SJim Ingham 
19065a988416SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
19075a988416SJim Ingham 
19085a988416SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
19095a988416SJim Ingham 
19105a988416SJim Ingham         if (num_breakpoints == 0)
19115a988416SJim Ingham         {
19125a988416SJim Ingham             result.AppendError ("No breakpoints exist to be deleted.");
19135a988416SJim Ingham             result.SetStatus (eReturnStatusFailed);
19145a988416SJim Ingham             return false;
19155a988416SJim Ingham         }
19165a988416SJim Ingham 
19175a988416SJim Ingham         if (command.GetArgumentCount() == 0)
19185a988416SJim Ingham         {
191933df7cd3SJim Ingham             if (!m_options.m_force && !m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
19205a988416SJim Ingham             {
19215a988416SJim Ingham                 result.AppendMessage("Operation cancelled...");
19225a988416SJim Ingham             }
19235a988416SJim Ingham             else
19245a988416SJim Ingham             {
19255a988416SJim Ingham                 target->RemoveAllBreakpoints ();
19266fea17e8SGreg Clayton                 result.AppendMessageWithFormat ("All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : "");
19275a988416SJim Ingham             }
19285a988416SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
19295a988416SJim Ingham         }
19305a988416SJim Ingham         else
19315a988416SJim Ingham         {
19325a988416SJim Ingham             // Particular breakpoint selected; disable that breakpoint.
19335a988416SJim Ingham             BreakpointIDList valid_bp_ids;
19345e09c8c3SJim Ingham             CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
19355a988416SJim Ingham 
19365a988416SJim Ingham             if (result.Succeeded())
19375a988416SJim Ingham             {
19385a988416SJim Ingham                 int delete_count = 0;
19395a988416SJim Ingham                 int disable_count = 0;
19405a988416SJim Ingham                 const size_t count = valid_bp_ids.GetSize();
19415a988416SJim Ingham                 for (size_t i = 0; i < count; ++i)
19425a988416SJim Ingham                 {
19435a988416SJim Ingham                     BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
19445a988416SJim Ingham 
19455a988416SJim Ingham                     if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
19465a988416SJim Ingham                     {
19475a988416SJim Ingham                         if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
19485a988416SJim Ingham                         {
19495a988416SJim Ingham                             Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
19505a988416SJim Ingham                             BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
19515a988416SJim Ingham                             // It makes no sense to try to delete individual locations, so we disable them instead.
19525a988416SJim Ingham                             if (location)
19535a988416SJim Ingham                             {
19545a988416SJim Ingham                                 location->SetEnabled (false);
19555a988416SJim Ingham                                 ++disable_count;
19565a988416SJim Ingham                             }
19575a988416SJim Ingham                         }
19585a988416SJim Ingham                         else
19595a988416SJim Ingham                         {
19605a988416SJim Ingham                             target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
19615a988416SJim Ingham                             ++delete_count;
19625a988416SJim Ingham                         }
19635a988416SJim Ingham                     }
19645a988416SJim Ingham                 }
19655a988416SJim Ingham                 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
19665a988416SJim Ingham                                                delete_count, disable_count);
19675a988416SJim Ingham                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
19685a988416SJim Ingham             }
19695a988416SJim Ingham         }
19705a988416SJim Ingham         return result.Succeeded();
19715a988416SJim Ingham     }
197233df7cd3SJim Ingham private:
197333df7cd3SJim Ingham     CommandOptions m_options;
197433df7cd3SJim Ingham };
197533df7cd3SJim Ingham 
197633df7cd3SJim Ingham OptionDefinition
197733df7cd3SJim Ingham CommandObjectBreakpointDelete::CommandOptions::g_option_table[] =
197833df7cd3SJim Ingham {
197933df7cd3SJim Ingham     { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
198033df7cd3SJim Ingham         "Delete all breakpoints without querying for confirmation."},
198133df7cd3SJim Ingham 
198233df7cd3SJim Ingham     { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
198333df7cd3SJim Ingham         "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
198433df7cd3SJim Ingham 
198533df7cd3SJim Ingham     { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
19865a988416SJim Ingham };
19875a988416SJim Ingham 
198830fdc8d8SChris Lattner //-------------------------------------------------------------------------
19895e09c8c3SJim Ingham // CommandObjectBreakpointName
19905e09c8c3SJim Ingham //-------------------------------------------------------------------------
19915e09c8c3SJim Ingham 
19925e09c8c3SJim Ingham static OptionDefinition
19935e09c8c3SJim Ingham g_breakpoint_name_options[] =
19945e09c8c3SJim Ingham {
19955e09c8c3SJim Ingham     { LLDB_OPT_SET_1,   false, "name", 'N', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."},
19965e09c8c3SJim Ingham     { LLDB_OPT_SET_2,   false, "breakpoint-id", 'B', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointID,   "Specify a breakpoint id to use."},
19975e09c8c3SJim Ingham     { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
19985e09c8c3SJim Ingham         "Operate on Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
19995e09c8c3SJim Ingham };
20005e09c8c3SJim Ingham class BreakpointNameOptionGroup : public OptionGroup
20015e09c8c3SJim Ingham {
20025e09c8c3SJim Ingham public:
20035e09c8c3SJim Ingham     BreakpointNameOptionGroup() :
20045e09c8c3SJim Ingham         OptionGroup(),
20055e09c8c3SJim Ingham         m_breakpoint(LLDB_INVALID_BREAK_ID),
20065e09c8c3SJim Ingham         m_use_dummy (false)
20075e09c8c3SJim Ingham     {
20085e09c8c3SJim Ingham 
20095e09c8c3SJim Ingham     }
20105e09c8c3SJim Ingham 
201113d21e9aSBruce Mitchener     ~BreakpointNameOptionGroup () override
20125e09c8c3SJim Ingham     {
20135e09c8c3SJim Ingham     }
20145e09c8c3SJim Ingham 
201513d21e9aSBruce Mitchener     uint32_t
201613d21e9aSBruce Mitchener     GetNumDefinitions () override
20175e09c8c3SJim Ingham     {
20185e09c8c3SJim Ingham       return sizeof (g_breakpoint_name_options) / sizeof (OptionDefinition);
20195e09c8c3SJim Ingham     }
20205e09c8c3SJim Ingham 
202113d21e9aSBruce Mitchener     const OptionDefinition*
202213d21e9aSBruce Mitchener     GetDefinitions () override
20235e09c8c3SJim Ingham     {
20245e09c8c3SJim Ingham         return g_breakpoint_name_options;
20255e09c8c3SJim Ingham     }
20265e09c8c3SJim Ingham 
202713d21e9aSBruce Mitchener     Error
20285e09c8c3SJim Ingham     SetOptionValue (CommandInterpreter &interpreter,
20295e09c8c3SJim Ingham                     uint32_t option_idx,
203013d21e9aSBruce Mitchener                     const char *option_value) override
20315e09c8c3SJim Ingham     {
20325e09c8c3SJim Ingham         Error error;
20335e09c8c3SJim Ingham         const int short_option = g_breakpoint_name_options[option_idx].short_option;
20345e09c8c3SJim Ingham 
20355e09c8c3SJim Ingham         switch (short_option)
20365e09c8c3SJim Ingham         {
20375e09c8c3SJim Ingham         case 'N':
20385e09c8c3SJim Ingham             if (BreakpointID::StringIsBreakpointName(option_value, error) && error.Success())
2039c95f7e2aSPavel Labath                 m_name.SetValueFromString(option_value);
20405e09c8c3SJim Ingham             break;
20415e09c8c3SJim Ingham 
20425e09c8c3SJim Ingham         case 'B':
2043c95f7e2aSPavel Labath             if (m_breakpoint.SetValueFromString(option_value).Fail())
20445e09c8c3SJim Ingham                 error.SetErrorStringWithFormat ("unrecognized value \"%s\" for breakpoint", option_value);
20455e09c8c3SJim Ingham             break;
20465e09c8c3SJim Ingham         case 'D':
2047c95f7e2aSPavel Labath             if (m_use_dummy.SetValueFromString(option_value).Fail())
20485e09c8c3SJim Ingham                 error.SetErrorStringWithFormat ("unrecognized value \"%s\" for use-dummy", option_value);
20495e09c8c3SJim Ingham             break;
20505e09c8c3SJim Ingham 
20515e09c8c3SJim Ingham         default:
20525e09c8c3SJim Ingham               error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
20535e09c8c3SJim Ingham               break;
20545e09c8c3SJim Ingham         }
20555e09c8c3SJim Ingham         return error;
20565e09c8c3SJim Ingham     }
20575e09c8c3SJim Ingham 
205813d21e9aSBruce Mitchener     void
205913d21e9aSBruce Mitchener     OptionParsingStarting (CommandInterpreter &interpreter) override
20605e09c8c3SJim Ingham     {
20615e09c8c3SJim Ingham         m_name.Clear();
20625e09c8c3SJim Ingham         m_breakpoint.Clear();
20635e09c8c3SJim Ingham         m_use_dummy.Clear();
20645e09c8c3SJim Ingham         m_use_dummy.SetDefaultValue(false);
20655e09c8c3SJim Ingham     }
20665e09c8c3SJim Ingham 
20675e09c8c3SJim Ingham     OptionValueString m_name;
20685e09c8c3SJim Ingham     OptionValueUInt64 m_breakpoint;
20695e09c8c3SJim Ingham     OptionValueBoolean m_use_dummy;
20705e09c8c3SJim Ingham };
20715e09c8c3SJim Ingham 
20725e09c8c3SJim Ingham 
20735e09c8c3SJim Ingham class CommandObjectBreakpointNameAdd : public CommandObjectParsed
20745e09c8c3SJim Ingham {
20755e09c8c3SJim Ingham public:
20765e09c8c3SJim Ingham     CommandObjectBreakpointNameAdd (CommandInterpreter &interpreter) :
20775e09c8c3SJim Ingham         CommandObjectParsed (interpreter,
20785e09c8c3SJim Ingham                              "add",
20795e09c8c3SJim Ingham                              "Add a name to the breakpoints provided.",
20805e09c8c3SJim Ingham                              "breakpoint name add <command-options> <breakpoint-id-list>"),
20815e09c8c3SJim Ingham         m_name_options(),
20825e09c8c3SJim Ingham         m_option_group(interpreter)
20835e09c8c3SJim Ingham         {
20845e09c8c3SJim Ingham             // Create the first variant for the first (and only) argument for this command.
20855e09c8c3SJim Ingham             CommandArgumentEntry arg1;
20865e09c8c3SJim Ingham             CommandArgumentData id_arg;
20875e09c8c3SJim Ingham             id_arg.arg_type = eArgTypeBreakpointID;
20885e09c8c3SJim Ingham             id_arg.arg_repetition = eArgRepeatOptional;
20895e09c8c3SJim Ingham             arg1.push_back(id_arg);
20905e09c8c3SJim Ingham             m_arguments.push_back (arg1);
20915e09c8c3SJim Ingham 
20925e09c8c3SJim Ingham             m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
20935e09c8c3SJim Ingham             m_option_group.Finalize();
20945e09c8c3SJim Ingham         }
20955e09c8c3SJim Ingham 
209613d21e9aSBruce Mitchener     ~CommandObjectBreakpointNameAdd () override {}
20975e09c8c3SJim Ingham 
20985e09c8c3SJim Ingham   Options *
209913d21e9aSBruce Mitchener   GetOptions () override
21005e09c8c3SJim Ingham   {
21015e09c8c3SJim Ingham     return &m_option_group;
21025e09c8c3SJim Ingham   }
21035e09c8c3SJim Ingham 
21045e09c8c3SJim Ingham protected:
210513d21e9aSBruce Mitchener     bool
210613d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
21075e09c8c3SJim Ingham     {
21085e09c8c3SJim Ingham         if (!m_name_options.m_name.OptionWasSet())
21095e09c8c3SJim Ingham         {
21105e09c8c3SJim Ingham             result.SetError("No name option provided.");
21115e09c8c3SJim Ingham             return false;
21125e09c8c3SJim Ingham         }
21135e09c8c3SJim Ingham 
21145e09c8c3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
21155e09c8c3SJim Ingham 
21165e09c8c3SJim Ingham         if (target == NULL)
21175e09c8c3SJim Ingham         {
21185e09c8c3SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
21195e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
21205e09c8c3SJim Ingham             return false;
21215e09c8c3SJim Ingham         }
21225e09c8c3SJim Ingham 
21235e09c8c3SJim Ingham         Mutex::Locker locker;
21245e09c8c3SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
21255e09c8c3SJim Ingham 
21265e09c8c3SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
21275e09c8c3SJim Ingham 
21285e09c8c3SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
21295e09c8c3SJim Ingham         if (num_breakpoints == 0)
21305e09c8c3SJim Ingham         {
21315e09c8c3SJim Ingham             result.SetError("No breakpoints, cannot add names.");
21325e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
21335e09c8c3SJim Ingham             return false;
21345e09c8c3SJim Ingham         }
21355e09c8c3SJim Ingham 
21365e09c8c3SJim Ingham         // Particular breakpoint selected; disable that breakpoint.
21375e09c8c3SJim Ingham         BreakpointIDList valid_bp_ids;
21385e09c8c3SJim Ingham         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
21395e09c8c3SJim Ingham 
21405e09c8c3SJim Ingham         if (result.Succeeded())
21415e09c8c3SJim Ingham         {
21425e09c8c3SJim Ingham             if (valid_bp_ids.GetSize() == 0)
21435e09c8c3SJim Ingham             {
21445e09c8c3SJim Ingham                 result.SetError("No breakpoints specified, cannot add names.");
21455e09c8c3SJim Ingham                 result.SetStatus (eReturnStatusFailed);
21465e09c8c3SJim Ingham                 return false;
21475e09c8c3SJim Ingham             }
21485e09c8c3SJim Ingham             size_t num_valid_ids = valid_bp_ids.GetSize();
21495e09c8c3SJim Ingham             for (size_t index = 0; index < num_valid_ids; index++)
21505e09c8c3SJim Ingham             {
21515e09c8c3SJim Ingham                 lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
21525e09c8c3SJim Ingham                 BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
21535e09c8c3SJim Ingham                 Error error;  // We don't need to check the error here, since the option parser checked it...
21545e09c8c3SJim Ingham                 bp_sp->AddName(m_name_options.m_name.GetCurrentValue(), error);
21555e09c8c3SJim Ingham             }
21565e09c8c3SJim Ingham         }
21575e09c8c3SJim Ingham 
21585e09c8c3SJim Ingham         return true;
21595e09c8c3SJim Ingham     }
21605e09c8c3SJim Ingham 
21615e09c8c3SJim Ingham private:
21625e09c8c3SJim Ingham     BreakpointNameOptionGroup m_name_options;
21635e09c8c3SJim Ingham     OptionGroupOptions m_option_group;
21645e09c8c3SJim Ingham };
21655e09c8c3SJim Ingham 
21665e09c8c3SJim Ingham 
21675e09c8c3SJim Ingham 
21685e09c8c3SJim Ingham class CommandObjectBreakpointNameDelete : public CommandObjectParsed
21695e09c8c3SJim Ingham {
21705e09c8c3SJim Ingham public:
21715e09c8c3SJim Ingham     CommandObjectBreakpointNameDelete (CommandInterpreter &interpreter) :
21725e09c8c3SJim Ingham         CommandObjectParsed (interpreter,
21735e09c8c3SJim Ingham                              "delete",
21745e09c8c3SJim Ingham                              "Delete a name from the breakpoints provided.",
21755e09c8c3SJim Ingham                              "breakpoint name delete <command-options> <breakpoint-id-list>"),
21765e09c8c3SJim Ingham         m_name_options(),
21775e09c8c3SJim Ingham         m_option_group(interpreter)
21785e09c8c3SJim Ingham     {
21795e09c8c3SJim Ingham         // Create the first variant for the first (and only) argument for this command.
21805e09c8c3SJim Ingham         CommandArgumentEntry arg1;
21815e09c8c3SJim Ingham         CommandArgumentData id_arg;
21825e09c8c3SJim Ingham         id_arg.arg_type = eArgTypeBreakpointID;
21835e09c8c3SJim Ingham         id_arg.arg_repetition = eArgRepeatOptional;
21845e09c8c3SJim Ingham         arg1.push_back(id_arg);
21855e09c8c3SJim Ingham         m_arguments.push_back (arg1);
21865e09c8c3SJim Ingham 
21875e09c8c3SJim Ingham         m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
21885e09c8c3SJim Ingham         m_option_group.Finalize();
21895e09c8c3SJim Ingham     }
21905e09c8c3SJim Ingham 
219113d21e9aSBruce Mitchener     ~CommandObjectBreakpointNameDelete () override {}
21925e09c8c3SJim Ingham 
21935e09c8c3SJim Ingham   Options *
219413d21e9aSBruce Mitchener   GetOptions () override
21955e09c8c3SJim Ingham   {
21965e09c8c3SJim Ingham     return &m_option_group;
21975e09c8c3SJim Ingham   }
21985e09c8c3SJim Ingham 
21995e09c8c3SJim Ingham protected:
220013d21e9aSBruce Mitchener     bool
220113d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
22025e09c8c3SJim Ingham     {
22035e09c8c3SJim Ingham         if (!m_name_options.m_name.OptionWasSet())
22045e09c8c3SJim Ingham         {
22055e09c8c3SJim Ingham             result.SetError("No name option provided.");
22065e09c8c3SJim Ingham             return false;
22075e09c8c3SJim Ingham         }
22085e09c8c3SJim Ingham 
22095e09c8c3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
22105e09c8c3SJim Ingham 
22115e09c8c3SJim Ingham         if (target == NULL)
22125e09c8c3SJim Ingham         {
22135e09c8c3SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
22145e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
22155e09c8c3SJim Ingham             return false;
22165e09c8c3SJim Ingham         }
22175e09c8c3SJim Ingham 
22185e09c8c3SJim Ingham         Mutex::Locker locker;
22195e09c8c3SJim Ingham         target->GetBreakpointList().GetListMutex(locker);
22205e09c8c3SJim Ingham 
22215e09c8c3SJim Ingham         const BreakpointList &breakpoints = target->GetBreakpointList();
22225e09c8c3SJim Ingham 
22235e09c8c3SJim Ingham         size_t num_breakpoints = breakpoints.GetSize();
22245e09c8c3SJim Ingham         if (num_breakpoints == 0)
22255e09c8c3SJim Ingham         {
22265e09c8c3SJim Ingham             result.SetError("No breakpoints, cannot delete names.");
22275e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
22285e09c8c3SJim Ingham             return false;
22295e09c8c3SJim Ingham         }
22305e09c8c3SJim Ingham 
22315e09c8c3SJim Ingham         // Particular breakpoint selected; disable that breakpoint.
22325e09c8c3SJim Ingham         BreakpointIDList valid_bp_ids;
22335e09c8c3SJim Ingham         CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
22345e09c8c3SJim Ingham 
22355e09c8c3SJim Ingham         if (result.Succeeded())
22365e09c8c3SJim Ingham         {
22375e09c8c3SJim Ingham             if (valid_bp_ids.GetSize() == 0)
22385e09c8c3SJim Ingham             {
22395e09c8c3SJim Ingham                 result.SetError("No breakpoints specified, cannot delete names.");
22405e09c8c3SJim Ingham                 result.SetStatus (eReturnStatusFailed);
22415e09c8c3SJim Ingham                 return false;
22425e09c8c3SJim Ingham             }
22435e09c8c3SJim Ingham             size_t num_valid_ids = valid_bp_ids.GetSize();
22445e09c8c3SJim Ingham             for (size_t index = 0; index < num_valid_ids; index++)
22455e09c8c3SJim Ingham             {
22465e09c8c3SJim Ingham                 lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
22475e09c8c3SJim Ingham                 BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
22485e09c8c3SJim Ingham                 bp_sp->RemoveName(m_name_options.m_name.GetCurrentValue());
22495e09c8c3SJim Ingham             }
22505e09c8c3SJim Ingham         }
22515e09c8c3SJim Ingham 
22525e09c8c3SJim Ingham         return true;
22535e09c8c3SJim Ingham     }
22545e09c8c3SJim Ingham 
22555e09c8c3SJim Ingham private:
22565e09c8c3SJim Ingham     BreakpointNameOptionGroup m_name_options;
22575e09c8c3SJim Ingham     OptionGroupOptions m_option_group;
22585e09c8c3SJim Ingham };
22595e09c8c3SJim Ingham 
22605e09c8c3SJim Ingham class CommandObjectBreakpointNameList : public CommandObjectParsed
22615e09c8c3SJim Ingham {
22625e09c8c3SJim Ingham public:
22635e09c8c3SJim Ingham     CommandObjectBreakpointNameList (CommandInterpreter &interpreter) :
22645e09c8c3SJim Ingham         CommandObjectParsed (interpreter,
22655e09c8c3SJim Ingham                              "list",
22665e09c8c3SJim Ingham                              "List either the names for a breakpoint or the breakpoints for a given name.",
22675e09c8c3SJim Ingham                              "breakpoint name list <command-options>"),
22685e09c8c3SJim Ingham         m_name_options(),
22695e09c8c3SJim Ingham         m_option_group(interpreter)
22705e09c8c3SJim Ingham     {
22715e09c8c3SJim Ingham         m_option_group.Append (&m_name_options);
22725e09c8c3SJim Ingham         m_option_group.Finalize();
22735e09c8c3SJim Ingham     }
22745e09c8c3SJim Ingham 
227513d21e9aSBruce Mitchener     ~CommandObjectBreakpointNameList () override {}
22765e09c8c3SJim Ingham 
22775e09c8c3SJim Ingham   Options *
227813d21e9aSBruce Mitchener   GetOptions () override
22795e09c8c3SJim Ingham   {
22805e09c8c3SJim Ingham     return &m_option_group;
22815e09c8c3SJim Ingham   }
22825e09c8c3SJim Ingham 
22835e09c8c3SJim Ingham protected:
228413d21e9aSBruce Mitchener     bool
228513d21e9aSBruce Mitchener     DoExecute (Args& command, CommandReturnObject &result) override
22865e09c8c3SJim Ingham     {
22875e09c8c3SJim Ingham         Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
22885e09c8c3SJim Ingham 
22895e09c8c3SJim Ingham         if (target == NULL)
22905e09c8c3SJim Ingham         {
22915e09c8c3SJim Ingham             result.AppendError ("Invalid target. No existing target or breakpoints.");
22925e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
22935e09c8c3SJim Ingham             return false;
22945e09c8c3SJim Ingham         }
22955e09c8c3SJim Ingham 
22965e09c8c3SJim Ingham         if (m_name_options.m_name.OptionWasSet())
22975e09c8c3SJim Ingham         {
22985e09c8c3SJim Ingham             const char *name = m_name_options.m_name.GetCurrentValue();
22995e09c8c3SJim Ingham             Mutex::Locker locker;
23005e09c8c3SJim Ingham             target->GetBreakpointList().GetListMutex(locker);
23015e09c8c3SJim Ingham 
23025e09c8c3SJim Ingham             BreakpointList &breakpoints = target->GetBreakpointList();
23035e09c8c3SJim Ingham             for (BreakpointSP bp_sp : breakpoints.Breakpoints())
23045e09c8c3SJim Ingham             {
23055e09c8c3SJim Ingham                 if (bp_sp->MatchesName(name))
23065e09c8c3SJim Ingham                 {
23075e09c8c3SJim Ingham                     StreamString s;
23085e09c8c3SJim Ingham                     bp_sp->GetDescription(&s, eDescriptionLevelBrief);
23095e09c8c3SJim Ingham                     s.EOL();
23105e09c8c3SJim Ingham                     result.AppendMessage(s.GetData());
23115e09c8c3SJim Ingham                 }
23125e09c8c3SJim Ingham             }
23135e09c8c3SJim Ingham 
23145e09c8c3SJim Ingham         }
23155e09c8c3SJim Ingham         else if (m_name_options.m_breakpoint.OptionWasSet())
23165e09c8c3SJim Ingham         {
23175e09c8c3SJim Ingham             BreakpointSP bp_sp = target->GetBreakpointList().FindBreakpointByID(m_name_options.m_breakpoint.GetCurrentValue());
23185e09c8c3SJim Ingham             if (bp_sp)
23195e09c8c3SJim Ingham             {
23205e09c8c3SJim Ingham                 std::vector<std::string> names;
23215e09c8c3SJim Ingham                 bp_sp->GetNames (names);
23225e09c8c3SJim Ingham                 result.AppendMessage ("Names:");
23235e09c8c3SJim Ingham                 for (auto name : names)
23245e09c8c3SJim Ingham                     result.AppendMessageWithFormat ("    %s\n", name.c_str());
23255e09c8c3SJim Ingham             }
23265e09c8c3SJim Ingham             else
23275e09c8c3SJim Ingham             {
23285e09c8c3SJim Ingham                 result.AppendErrorWithFormat ("Could not find breakpoint %" PRId64 ".\n",
23295e09c8c3SJim Ingham                                            m_name_options.m_breakpoint.GetCurrentValue());
23305e09c8c3SJim Ingham                 result.SetStatus (eReturnStatusFailed);
23315e09c8c3SJim Ingham                 return false;
23325e09c8c3SJim Ingham             }
23335e09c8c3SJim Ingham         }
23345e09c8c3SJim Ingham         else
23355e09c8c3SJim Ingham         {
23365e09c8c3SJim Ingham             result.SetError ("Must specify -N or -B option to list.");
23375e09c8c3SJim Ingham             result.SetStatus (eReturnStatusFailed);
23385e09c8c3SJim Ingham             return false;
23395e09c8c3SJim Ingham         }
23405e09c8c3SJim Ingham         return true;
23415e09c8c3SJim Ingham     }
23425e09c8c3SJim Ingham 
23435e09c8c3SJim Ingham private:
23445e09c8c3SJim Ingham     BreakpointNameOptionGroup m_name_options;
23455e09c8c3SJim Ingham     OptionGroupOptions m_option_group;
23465e09c8c3SJim Ingham };
23475e09c8c3SJim Ingham 
23485e09c8c3SJim Ingham //-------------------------------------------------------------------------
23495e09c8c3SJim Ingham // CommandObjectMultiwordBreakpoint
23505e09c8c3SJim Ingham //-------------------------------------------------------------------------
23515e09c8c3SJim Ingham class CommandObjectBreakpointName : public CommandObjectMultiword
23525e09c8c3SJim Ingham {
23535e09c8c3SJim Ingham public:
23545e09c8c3SJim Ingham     CommandObjectBreakpointName (CommandInterpreter &interpreter) :
23555e09c8c3SJim Ingham         CommandObjectMultiword(interpreter,
23565e09c8c3SJim Ingham                                 "name",
23575e09c8c3SJim Ingham                                 "A set of commands to manage name tags for breakpoints",
23585e09c8c3SJim Ingham                                 "breakpoint name <command> [<command-options>]")
23595e09c8c3SJim Ingham     {
23605e09c8c3SJim Ingham         CommandObjectSP add_command_object (new CommandObjectBreakpointNameAdd (interpreter));
23615e09c8c3SJim Ingham         CommandObjectSP delete_command_object (new CommandObjectBreakpointNameDelete (interpreter));
23625e09c8c3SJim Ingham         CommandObjectSP list_command_object (new CommandObjectBreakpointNameList (interpreter));
23635e09c8c3SJim Ingham 
23645e09c8c3SJim Ingham         LoadSubCommand ("add", add_command_object);
23655e09c8c3SJim Ingham         LoadSubCommand ("delete", delete_command_object);
23665e09c8c3SJim Ingham         LoadSubCommand ("list", list_command_object);
23675e09c8c3SJim Ingham 
23685e09c8c3SJim Ingham     }
23695e09c8c3SJim Ingham 
237013d21e9aSBruce Mitchener     ~CommandObjectBreakpointName () override
23715e09c8c3SJim Ingham     {
23725e09c8c3SJim Ingham     }
23735e09c8c3SJim Ingham 
23745e09c8c3SJim Ingham };
23755e09c8c3SJim Ingham 
23765e09c8c3SJim Ingham 
23775e09c8c3SJim Ingham //-------------------------------------------------------------------------
237830fdc8d8SChris Lattner // CommandObjectMultiwordBreakpoint
237930fdc8d8SChris Lattner //-------------------------------------------------------------------------
2380ae1c4cf5SJim Ingham #pragma mark MultiwordBreakpoint
238130fdc8d8SChris Lattner 
23826611103cSGreg Clayton CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
2383a7015092SGreg Clayton     CommandObjectMultiword (interpreter,
2384a7015092SGreg Clayton                             "breakpoint",
238546fbc60fSJim Ingham                             "A set of commands for operating on breakpoints. Also see _regexp-break.",
238630fdc8d8SChris Lattner                             "breakpoint <command> [<command-options>]")
238730fdc8d8SChris Lattner {
2388a7015092SGreg Clayton     CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
2389a7015092SGreg Clayton     CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
2390a7015092SGreg Clayton     CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
2391b7234e40SJohnny Chen     CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
2392b7234e40SJohnny Chen     CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
2393a7015092SGreg Clayton     CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
239430fdc8d8SChris Lattner     CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
2395a7015092SGreg Clayton     CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
23965e09c8c3SJim Ingham     CommandObjectSP name_command_object (new CommandObjectBreakpointName(interpreter));
239730fdc8d8SChris Lattner 
2398b7234e40SJohnny Chen     list_command_object->SetCommandName ("breakpoint list");
239930fdc8d8SChris Lattner     enable_command_object->SetCommandName("breakpoint enable");
240030fdc8d8SChris Lattner     disable_command_object->SetCommandName("breakpoint disable");
2401b7234e40SJohnny Chen     clear_command_object->SetCommandName("breakpoint clear");
2402b7234e40SJohnny Chen     delete_command_object->SetCommandName("breakpoint delete");
2403ae1c4cf5SJim Ingham     set_command_object->SetCommandName("breakpoint set");
2404b7234e40SJohnny Chen     command_command_object->SetCommandName ("breakpoint command");
2405b7234e40SJohnny Chen     modify_command_object->SetCommandName ("breakpoint modify");
24065e09c8c3SJim Ingham     name_command_object->SetCommandName ("breakpoint name");
240730fdc8d8SChris Lattner 
240823f59509SGreg Clayton     LoadSubCommand ("list",       list_command_object);
240923f59509SGreg Clayton     LoadSubCommand ("enable",     enable_command_object);
241023f59509SGreg Clayton     LoadSubCommand ("disable",    disable_command_object);
241123f59509SGreg Clayton     LoadSubCommand ("clear",      clear_command_object);
241223f59509SGreg Clayton     LoadSubCommand ("delete",     delete_command_object);
241323f59509SGreg Clayton     LoadSubCommand ("set",        set_command_object);
241423f59509SGreg Clayton     LoadSubCommand ("command",    command_command_object);
241523f59509SGreg Clayton     LoadSubCommand ("modify",     modify_command_object);
24165e09c8c3SJim Ingham     LoadSubCommand ("name",       name_command_object);
241730fdc8d8SChris Lattner }
241830fdc8d8SChris Lattner 
241930fdc8d8SChris Lattner CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
242030fdc8d8SChris Lattner {
242130fdc8d8SChris Lattner }
242230fdc8d8SChris Lattner 
242330fdc8d8SChris Lattner void
24245e09c8c3SJim Ingham CommandObjectMultiwordBreakpoint::VerifyIDs (Args &args,
24255e09c8c3SJim Ingham                                              Target *target,
24265e09c8c3SJim Ingham                                              bool allow_locations,
24275e09c8c3SJim Ingham                                              CommandReturnObject &result,
242830fdc8d8SChris Lattner                                              BreakpointIDList *valid_ids)
242930fdc8d8SChris Lattner {
243030fdc8d8SChris Lattner     // args can be strings representing 1). integers (for breakpoint ids)
243130fdc8d8SChris Lattner     //                                  2). the full breakpoint & location canonical representation
243230fdc8d8SChris Lattner     //                                  3). the word "to" or a hyphen, representing a range (in which case there
243330fdc8d8SChris Lattner     //                                      had *better* be an entry both before & after of one of the first two types.
24345e09c8c3SJim Ingham     //                                  4). A breakpoint name
243536f3b369SJim Ingham     // If args is empty, we will use the last created breakpoint (if there is one.)
243630fdc8d8SChris Lattner 
243730fdc8d8SChris Lattner     Args temp_args;
243830fdc8d8SChris Lattner 
243936f3b369SJim Ingham     if (args.GetArgumentCount() == 0)
244036f3b369SJim Ingham     {
24414d122c40SGreg Clayton         if (target->GetLastCreatedBreakpoint())
244236f3b369SJim Ingham         {
244336f3b369SJim Ingham             valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
244436f3b369SJim Ingham             result.SetStatus (eReturnStatusSuccessFinishNoResult);
244536f3b369SJim Ingham         }
244636f3b369SJim Ingham         else
244736f3b369SJim Ingham         {
244836f3b369SJim Ingham             result.AppendError("No breakpoint specified and no last created breakpoint.");
244936f3b369SJim Ingham             result.SetStatus (eReturnStatusFailed);
245036f3b369SJim Ingham         }
245136f3b369SJim Ingham         return;
245236f3b369SJim Ingham     }
245336f3b369SJim Ingham 
245430fdc8d8SChris Lattner     // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
245530fdc8d8SChris Lattner     // the new TEMP_ARGS.  Do not copy breakpoint id range strings over; instead generate a list of strings for
245630fdc8d8SChris Lattner     // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
245730fdc8d8SChris Lattner 
24585e09c8c3SJim Ingham     BreakpointIDList::FindAndReplaceIDRanges (args, target, allow_locations, result, temp_args);
245930fdc8d8SChris Lattner 
246030fdc8d8SChris Lattner     // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
246130fdc8d8SChris Lattner 
2462c982c768SGreg Clayton     valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
246330fdc8d8SChris Lattner 
246430fdc8d8SChris Lattner     // At this point,  all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
246530fdc8d8SChris Lattner     // and put into valid_ids.
246630fdc8d8SChris Lattner 
246730fdc8d8SChris Lattner     if (result.Succeeded())
246830fdc8d8SChris Lattner     {
246930fdc8d8SChris Lattner         // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
247030fdc8d8SChris Lattner         // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
247130fdc8d8SChris Lattner 
2472c982c768SGreg Clayton         const size_t count = valid_ids->GetSize();
2473c982c768SGreg Clayton         for (size_t i = 0; i < count; ++i)
247430fdc8d8SChris Lattner         {
247530fdc8d8SChris Lattner             BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
247630fdc8d8SChris Lattner             Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
247730fdc8d8SChris Lattner             if (breakpoint != NULL)
247830fdc8d8SChris Lattner             {
2479c7bece56SGreg Clayton                 const size_t num_locations = breakpoint->GetNumLocations();
24803985c8c6SSaleem Abdulrasool                 if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations)
248130fdc8d8SChris Lattner                 {
248230fdc8d8SChris Lattner                     StreamString id_str;
2483c982c768SGreg Clayton                     BreakpointID::GetCanonicalReference (&id_str,
2484c982c768SGreg Clayton                                                          cur_bp_id.GetBreakpointID(),
248530fdc8d8SChris Lattner                                                          cur_bp_id.GetLocationID());
2486c982c768SGreg Clayton                     i = valid_ids->GetSize() + 1;
248730fdc8d8SChris Lattner                     result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
248830fdc8d8SChris Lattner                                                  id_str.GetData());
248930fdc8d8SChris Lattner                     result.SetStatus (eReturnStatusFailed);
249030fdc8d8SChris Lattner                 }
249130fdc8d8SChris Lattner             }
249230fdc8d8SChris Lattner             else
249330fdc8d8SChris Lattner             {
2494c982c768SGreg Clayton                 i = valid_ids->GetSize() + 1;
249530fdc8d8SChris Lattner                 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
249630fdc8d8SChris Lattner                 result.SetStatus (eReturnStatusFailed);
249730fdc8d8SChris Lattner             }
249830fdc8d8SChris Lattner         }
249930fdc8d8SChris Lattner     }
250030fdc8d8SChris Lattner }
2501