blob: edd733667d6f0802f17b486366813df1250af40f [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- CommandObjectBreakpoint.cpp -----------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "CommandObjectBreakpoint.h"
11#include "CommandObjectBreakpointCommand.h"
12
13// C Includes
14// C++ Includes
15// Other libraries and framework includes
16// Project includes
17#include "lldb/Breakpoint/Breakpoint.h"
18#include "lldb/Breakpoint/BreakpointIDList.h"
19#include "lldb/Breakpoint/BreakpointLocation.h"
Vince Harron5275aaa2015-01-15 20:08:35 +000020#include "lldb/Host/StringConvert.h"
Jim Ingham40af72e2010-06-15 19:49:27 +000021#include "lldb/Interpreter/Options.h"
Zachary Turner32abc6e2015-03-03 19:23:09 +000022#include "lldb/Interpreter/OptionValueBoolean.h"
Jim Ingham5e09c8c2014-12-16 23:40:14 +000023#include "lldb/Interpreter/OptionValueString.h"
24#include "lldb/Interpreter/OptionValueUInt64.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/RegularExpression.h"
26#include "lldb/Core/StreamString.h"
27#include "lldb/Interpreter/CommandInterpreter.h"
28#include "lldb/Interpreter/CommandReturnObject.h"
Jim Ingham0e0984e2015-09-02 01:06:46 +000029#include "lldb/Target/Language.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Target/Target.h"
31#include "lldb/Interpreter/CommandCompletions.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000032#include "lldb/Target/StackFrame.h"
Jim Ingham1b54c882010-06-16 02:00:15 +000033#include "lldb/Target/Thread.h"
34#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035
Johnny Chenb7234e42010-10-28 17:27:46 +000036#include <vector>
37
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038using namespace lldb;
39using namespace lldb_private;
40
41static void
Jim Ingham85e8b812011-02-19 02:53:09 +000042AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043{
44 s->IndentMore();
45 bp->GetDescription (s, level, true);
46 s->IndentLess();
47 s->EOL();
48}
49
50//-------------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +000051// CommandObjectBreakpointSet
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052//-------------------------------------------------------------------------
53
Jim Ingham5a988412012-06-08 21:56:10 +000054
55class CommandObjectBreakpointSet : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056{
Jim Ingham5a988412012-06-08 21:56:10 +000057public:
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
Jim Ingham5a988412012-06-08 21:56:10 +000059 typedef enum BreakpointSetType
60 {
61 eSetTypeInvalid,
62 eSetTypeFileAndLine,
63 eSetTypeAddress,
64 eSetTypeFunctionName,
65 eSetTypeFunctionRegexp,
66 eSetTypeSourceRegexp,
67 eSetTypeException
68 } BreakpointSetType;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069
Jim Ingham5a988412012-06-08 21:56:10 +000070 CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
71 CommandObjectParsed (interpreter,
72 "breakpoint set",
73 "Sets a breakpoint or set of breakpoints in the executable.",
74 "breakpoint set <cmd-options>"),
75 m_options (interpreter)
76 {
77 }
78
79
Bruce Mitchener13d21e92015-10-07 16:56:17 +000080 ~CommandObjectBreakpointSet () override {}
Jim Ingham5a988412012-06-08 21:56:10 +000081
Bruce Mitchener13d21e92015-10-07 16:56:17 +000082 Options *
83 GetOptions () override
Jim Ingham5a988412012-06-08 21:56:10 +000084 {
85 return &m_options;
86 }
87
88 class CommandOptions : public Options
89 {
90 public:
91
92 CommandOptions (CommandInterpreter &interpreter) :
93 Options (interpreter),
94 m_condition (),
95 m_filenames (),
96 m_line_num (0),
97 m_column (0),
Jim Ingham5a988412012-06-08 21:56:10 +000098 m_func_names (),
99 m_func_name_type_mask (eFunctionNameTypeNone),
100 m_func_regexp (),
101 m_source_text_regexp(),
102 m_modules (),
103 m_load_addr(),
104 m_ignore_count (0),
105 m_thread_id(LLDB_INVALID_THREAD_ID),
106 m_thread_index (UINT32_MAX),
107 m_thread_name(),
108 m_queue_name(),
109 m_catch_bp (false),
Greg Clayton1f746072012-08-29 21:13:06 +0000110 m_throw_bp (true),
Greg Claytoneb023e72013-10-11 19:48:25 +0000111 m_hardware (false),
Jim Inghama72b31c2015-04-22 19:42:18 +0000112 m_exception_language (eLanguageTypeUnknown),
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000113 m_language (lldb::eLanguageTypeUnknown),
Jim Inghamca36cd12012-10-05 19:16:31 +0000114 m_skip_prologue (eLazyBoolCalculate),
Jim Inghame7320522015-02-12 17:37:46 +0000115 m_one_shot (false),
Ilia K055ad9b2015-05-18 13:41:01 +0000116 m_all_files (false),
117 m_move_to_nearest_code (eLazyBoolCalculate)
Jim Ingham5a988412012-06-08 21:56:10 +0000118 {
119 }
120
121
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000122 ~CommandOptions () override {}
Jim Ingham5a988412012-06-08 21:56:10 +0000123
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000124 Error
125 SetOptionValue (uint32_t option_idx, const char *option_arg) override
Jim Ingham5a988412012-06-08 21:56:10 +0000126 {
127 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000128 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham5a988412012-06-08 21:56:10 +0000129
130 switch (short_option)
131 {
132 case 'a':
Greg Claytonb9d5df52012-12-06 22:49:16 +0000133 {
134 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
135 m_load_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
136 }
Jim Ingham5a988412012-06-08 21:56:10 +0000137 break;
138
Jim Inghame7320522015-02-12 17:37:46 +0000139 case 'A':
140 m_all_files = true;
141 break;
142
Jim Inghamca36cd12012-10-05 19:16:31 +0000143 case 'b':
144 m_func_names.push_back (option_arg);
145 m_func_name_type_mask |= eFunctionNameTypeBase;
146 break;
147
Jim Ingham5a988412012-06-08 21:56:10 +0000148 case 'C':
Jim Ingham63129912015-03-16 22:47:38 +0000149 {
150 bool success;
151 m_column = StringConvert::ToUInt32 (option_arg, 0, 0, &success);
152 if (!success)
153 error.SetErrorStringWithFormat("invalid column number: %s", option_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000154 break;
Jim Ingham63129912015-03-16 22:47:38 +0000155 }
Jim Ingham5a988412012-06-08 21:56:10 +0000156 case 'c':
157 m_condition.assign(option_arg);
158 break;
159
Jim Ingham33df7cd2014-12-06 01:28:03 +0000160 case 'D':
161 m_use_dummy = true;
162 break;
163
Jim Ingham5a988412012-06-08 21:56:10 +0000164 case 'E':
165 {
Jim Ingham0e0984e2015-09-02 01:06:46 +0000166 LanguageType language = Language::GetLanguageTypeFromString (option_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000167
168 switch (language)
169 {
170 case eLanguageTypeC89:
171 case eLanguageTypeC:
172 case eLanguageTypeC99:
Bruce Mitchener1d0089f2014-07-03 00:49:08 +0000173 case eLanguageTypeC11:
Jim Inghama72b31c2015-04-22 19:42:18 +0000174 m_exception_language = eLanguageTypeC;
Jim Ingham5a988412012-06-08 21:56:10 +0000175 break;
176 case eLanguageTypeC_plus_plus:
Bruce Mitchener1d0089f2014-07-03 00:49:08 +0000177 case eLanguageTypeC_plus_plus_03:
178 case eLanguageTypeC_plus_plus_11:
Bruce Mitchener2ba84a62015-02-06 06:46:52 +0000179 case eLanguageTypeC_plus_plus_14:
Jim Inghama72b31c2015-04-22 19:42:18 +0000180 m_exception_language = eLanguageTypeC_plus_plus;
Jim Ingham5a988412012-06-08 21:56:10 +0000181 break;
182 case eLanguageTypeObjC:
Jim Inghama72b31c2015-04-22 19:42:18 +0000183 m_exception_language = eLanguageTypeObjC;
Jim Ingham5a988412012-06-08 21:56:10 +0000184 break;
185 case eLanguageTypeObjC_plus_plus:
186 error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c");
187 break;
188 case eLanguageTypeUnknown:
189 error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg);
190 break;
191 default:
192 error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg);
193 }
194 }
195 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000196
197 case 'f':
198 m_filenames.AppendIfUnique (FileSpec(option_arg, false));
199 break;
200
201 case 'F':
202 m_func_names.push_back (option_arg);
203 m_func_name_type_mask |= eFunctionNameTypeFull;
204 break;
205
Jim Ingham5a988412012-06-08 21:56:10 +0000206 case 'h':
Greg Claytoneb023e72013-10-11 19:48:25 +0000207 {
208 bool success;
209 m_catch_bp = Args::StringToBoolean (option_arg, true, &success);
210 if (!success)
211 error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg);
212 }
213 break;
214
215 case 'H':
216 m_hardware = true;
217 break;
218
Jim Inghamca36cd12012-10-05 19:16:31 +0000219 case 'i':
220 {
Vince Harron5275aaa2015-01-15 20:08:35 +0000221 m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
Jim Inghamca36cd12012-10-05 19:16:31 +0000222 if (m_ignore_count == UINT32_MAX)
223 error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
224 break;
225 }
226
Jim Ingham5a988412012-06-08 21:56:10 +0000227 case 'K':
228 {
229 bool success;
230 bool value;
231 value = Args::StringToBoolean (option_arg, true, &success);
232 if (value)
233 m_skip_prologue = eLazyBoolYes;
234 else
235 m_skip_prologue = eLazyBoolNo;
236
237 if (!success)
238 error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg);
239 }
240 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000241
242 case 'l':
Jim Ingham63129912015-03-16 22:47:38 +0000243 {
244 bool success;
245 m_line_num = StringConvert::ToUInt32 (option_arg, 0, 0, &success);
246 if (!success)
247 error.SetErrorStringWithFormat ("invalid line number: %s.", option_arg);
Jim Inghamca36cd12012-10-05 19:16:31 +0000248 break;
Jim Ingham63129912015-03-16 22:47:38 +0000249 }
Ilia K055ad9b2015-05-18 13:41:01 +0000250
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000251 case 'L':
Jim Ingham0e0984e2015-09-02 01:06:46 +0000252 m_language = Language::GetLanguageTypeFromString (option_arg);
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000253 if (m_language == eLanguageTypeUnknown)
254 error.SetErrorStringWithFormat ("Unknown language type: '%s' for breakpoint", option_arg);
255 break;
256
Ilia K055ad9b2015-05-18 13:41:01 +0000257 case 'm':
258 {
259 bool success;
260 bool value;
261 value = Args::StringToBoolean (option_arg, true, &success);
262 if (value)
263 m_move_to_nearest_code = eLazyBoolYes;
264 else
265 m_move_to_nearest_code = eLazyBoolNo;
266
267 if (!success)
268 error.SetErrorStringWithFormat ("Invalid boolean value for move-to-nearest-code option: '%s'", option_arg);
269 break;
270 }
271
Jim Inghamca36cd12012-10-05 19:16:31 +0000272 case 'M':
273 m_func_names.push_back (option_arg);
274 m_func_name_type_mask |= eFunctionNameTypeMethod;
275 break;
276
277 case 'n':
278 m_func_names.push_back (option_arg);
279 m_func_name_type_mask |= eFunctionNameTypeAuto;
280 break;
281
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000282 case 'N':
283 if (BreakpointID::StringIsBreakpointName(option_arg, error))
284 m_breakpoint_names.push_back (option_arg);
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000285 break;
286
Jim Inghamca36cd12012-10-05 19:16:31 +0000287 case 'o':
288 m_one_shot = true;
289 break;
290
Jim Inghama72b31c2015-04-22 19:42:18 +0000291 case 'O':
292 m_exception_extra_args.AppendArgument ("-O");
293 m_exception_extra_args.AppendArgument (option_arg);
294 break;
295
Jim Inghamca36cd12012-10-05 19:16:31 +0000296 case 'p':
297 m_source_text_regexp.assign (option_arg);
298 break;
299
300 case 'q':
301 m_queue_name.assign (option_arg);
302 break;
303
304 case 'r':
305 m_func_regexp.assign (option_arg);
306 break;
307
308 case 's':
309 {
310 m_modules.AppendIfUnique (FileSpec (option_arg, false));
311 break;
312 }
313
314 case 'S':
315 m_func_names.push_back (option_arg);
316 m_func_name_type_mask |= eFunctionNameTypeSelector;
317 break;
318
319 case 't' :
320 {
Vince Harron5275aaa2015-01-15 20:08:35 +0000321 m_thread_id = StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Inghamca36cd12012-10-05 19:16:31 +0000322 if (m_thread_id == LLDB_INVALID_THREAD_ID)
323 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
324 }
325 break;
326
327 case 'T':
328 m_thread_name.assign (option_arg);
329 break;
330
331 case 'w':
332 {
333 bool success;
334 m_throw_bp = Args::StringToBoolean (option_arg, true, &success);
335 if (!success)
336 error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg);
337 }
338 break;
339
340 case 'x':
341 {
Vince Harron5275aaa2015-01-15 20:08:35 +0000342 m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
Jim Inghamca36cd12012-10-05 19:16:31 +0000343 if (m_thread_id == UINT32_MAX)
344 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
345
346 }
347 break;
348
Jim Ingham5a988412012-06-08 21:56:10 +0000349 default:
350 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
351 break;
352 }
353
354 return error;
355 }
356 void
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000357 OptionParsingStarting () override
Jim Ingham5a988412012-06-08 21:56:10 +0000358 {
359 m_condition.clear();
360 m_filenames.Clear();
361 m_line_num = 0;
362 m_column = 0;
363 m_func_names.clear();
Greg Clayton1f746072012-08-29 21:13:06 +0000364 m_func_name_type_mask = eFunctionNameTypeNone;
Jim Ingham5a988412012-06-08 21:56:10 +0000365 m_func_regexp.clear();
Greg Clayton1f746072012-08-29 21:13:06 +0000366 m_source_text_regexp.clear();
Jim Ingham5a988412012-06-08 21:56:10 +0000367 m_modules.Clear();
Greg Clayton1f746072012-08-29 21:13:06 +0000368 m_load_addr = LLDB_INVALID_ADDRESS;
Jim Ingham5a988412012-06-08 21:56:10 +0000369 m_ignore_count = 0;
370 m_thread_id = LLDB_INVALID_THREAD_ID;
371 m_thread_index = UINT32_MAX;
372 m_thread_name.clear();
373 m_queue_name.clear();
Jim Ingham5a988412012-06-08 21:56:10 +0000374 m_catch_bp = false;
375 m_throw_bp = true;
Greg Claytoneb023e72013-10-11 19:48:25 +0000376 m_hardware = false;
Jim Inghama72b31c2015-04-22 19:42:18 +0000377 m_exception_language = eLanguageTypeUnknown;
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000378 m_language = lldb::eLanguageTypeUnknown;
Jim Ingham5a988412012-06-08 21:56:10 +0000379 m_skip_prologue = eLazyBoolCalculate;
Jim Inghamca36cd12012-10-05 19:16:31 +0000380 m_one_shot = false;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000381 m_use_dummy = false;
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000382 m_breakpoint_names.clear();
Jim Inghame7320522015-02-12 17:37:46 +0000383 m_all_files = false;
Jim Inghama72b31c2015-04-22 19:42:18 +0000384 m_exception_extra_args.Clear();
Ilia K055ad9b2015-05-18 13:41:01 +0000385 m_move_to_nearest_code = eLazyBoolCalculate;
Jim Ingham5a988412012-06-08 21:56:10 +0000386 }
387
388 const OptionDefinition*
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000389 GetDefinitions () override
Jim Ingham5a988412012-06-08 21:56:10 +0000390 {
391 return g_option_table;
392 }
393
394 // Options table: Required for subclasses of Options.
395
396 static OptionDefinition g_option_table[];
397
398 // Instance variables to hold the values for command options.
399
400 std::string m_condition;
401 FileSpecList m_filenames;
402 uint32_t m_line_num;
403 uint32_t m_column;
Jim Ingham5a988412012-06-08 21:56:10 +0000404 std::vector<std::string> m_func_names;
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000405 std::vector<std::string> m_breakpoint_names;
Jim Ingham5a988412012-06-08 21:56:10 +0000406 uint32_t m_func_name_type_mask;
407 std::string m_func_regexp;
408 std::string m_source_text_regexp;
409 FileSpecList m_modules;
410 lldb::addr_t m_load_addr;
411 uint32_t m_ignore_count;
412 lldb::tid_t m_thread_id;
413 uint32_t m_thread_index;
414 std::string m_thread_name;
415 std::string m_queue_name;
416 bool m_catch_bp;
417 bool m_throw_bp;
Greg Claytoneb023e72013-10-11 19:48:25 +0000418 bool m_hardware; // Request to use hardware breakpoints
Jim Inghama72b31c2015-04-22 19:42:18 +0000419 lldb::LanguageType m_exception_language;
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000420 lldb::LanguageType m_language;
Jim Ingham5a988412012-06-08 21:56:10 +0000421 LazyBool m_skip_prologue;
Jim Inghamca36cd12012-10-05 19:16:31 +0000422 bool m_one_shot;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000423 bool m_use_dummy;
Jim Inghame7320522015-02-12 17:37:46 +0000424 bool m_all_files;
Jim Inghama72b31c2015-04-22 19:42:18 +0000425 Args m_exception_extra_args;
Ilia K055ad9b2015-05-18 13:41:01 +0000426 LazyBool m_move_to_nearest_code;
Jim Ingham5a988412012-06-08 21:56:10 +0000427
428 };
429
430protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000431 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000432 DoExecute (Args& command,
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000433 CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +0000434 {
Jim Ingham33df7cd2014-12-06 01:28:03 +0000435 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
436
Jim Ingham893c9322014-11-22 01:42:44 +0000437 if (target == nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +0000438 {
439 result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command).");
440 result.SetStatus (eReturnStatusFailed);
441 return false;
442 }
443
444 // The following are the various types of breakpoints that could be set:
445 // 1). -f -l -p [-s -g] (setting breakpoint by source location)
446 // 2). -a [-s -g] (setting breakpoint by address)
447 // 3). -n [-s -g] (setting breakpoint by function name)
448 // 4). -r [-s -g] (setting breakpoint by function name regular expression)
449 // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text)
450 // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.)
451
452 BreakpointSetType break_type = eSetTypeInvalid;
453
454 if (m_options.m_line_num != 0)
455 break_type = eSetTypeFileAndLine;
456 else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
457 break_type = eSetTypeAddress;
458 else if (!m_options.m_func_names.empty())
459 break_type = eSetTypeFunctionName;
460 else if (!m_options.m_func_regexp.empty())
461 break_type = eSetTypeFunctionRegexp;
462 else if (!m_options.m_source_text_regexp.empty())
463 break_type = eSetTypeSourceRegexp;
Jim Inghama72b31c2015-04-22 19:42:18 +0000464 else if (m_options.m_exception_language != eLanguageTypeUnknown)
Jim Ingham5a988412012-06-08 21:56:10 +0000465 break_type = eSetTypeException;
466
467 Breakpoint *bp = NULL;
468 FileSpec module_spec;
Jim Ingham5a988412012-06-08 21:56:10 +0000469 const bool internal = false;
470
Jim Ingham5a988412012-06-08 21:56:10 +0000471 switch (break_type)
472 {
473 case eSetTypeFileAndLine: // Breakpoint by source position
474 {
475 FileSpec file;
Greg Claytonc7bece562013-01-25 18:06:21 +0000476 const size_t num_files = m_options.m_filenames.GetSize();
Jim Ingham5a988412012-06-08 21:56:10 +0000477 if (num_files == 0)
478 {
479 if (!GetDefaultFile (target, file, result))
480 {
481 result.AppendError("No file supplied and no default file available.");
482 result.SetStatus (eReturnStatusFailed);
483 return false;
484 }
485 }
486 else if (num_files > 1)
487 {
488 result.AppendError("Only one file at a time is allowed for file and line breakpoints.");
489 result.SetStatus (eReturnStatusFailed);
490 return false;
491 }
492 else
493 file = m_options.m_filenames.GetFileSpecAtIndex(0);
Greg Clayton1f746072012-08-29 21:13:06 +0000494
495 // Only check for inline functions if
496 LazyBool check_inlines = eLazyBoolCalculate;
497
Jim Ingham5a988412012-06-08 21:56:10 +0000498 bp = target->CreateBreakpoint (&(m_options.m_modules),
499 file,
500 m_options.m_line_num,
Greg Clayton1f746072012-08-29 21:13:06 +0000501 check_inlines,
Jim Ingham5a988412012-06-08 21:56:10 +0000502 m_options.m_skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000503 internal,
Ilia K055ad9b2015-05-18 13:41:01 +0000504 m_options.m_hardware,
505 m_options.m_move_to_nearest_code).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000506 }
507 break;
508
509 case eSetTypeAddress: // Breakpoint by address
Greg Claytoneb023e72013-10-11 19:48:25 +0000510 bp = target->CreateBreakpoint (m_options.m_load_addr,
511 internal,
512 m_options.m_hardware).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000513 break;
514
515 case eSetTypeFunctionName: // Breakpoint by function name
516 {
517 uint32_t name_type_mask = m_options.m_func_name_type_mask;
518
519 if (name_type_mask == 0)
520 name_type_mask = eFunctionNameTypeAuto;
521
522 bp = target->CreateBreakpoint (&(m_options.m_modules),
523 &(m_options.m_filenames),
524 m_options.m_func_names,
525 name_type_mask,
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000526 m_options.m_language,
Jim Ingham5a988412012-06-08 21:56:10 +0000527 m_options.m_skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000528 internal,
529 m_options.m_hardware).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000530 }
531 break;
532
533 case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
534 {
535 RegularExpression regexp(m_options.m_func_regexp.c_str());
536 if (!regexp.IsValid())
537 {
538 char err_str[1024];
539 regexp.GetErrorAsCString(err_str, sizeof(err_str));
540 result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"",
541 err_str);
542 result.SetStatus (eReturnStatusFailed);
543 return false;
544 }
545
546 bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules),
547 &(m_options.m_filenames),
548 regexp,
Jim Ingham0fcdac32015-11-06 22:48:59 +0000549 m_options.m_language,
Jim Ingham5a988412012-06-08 21:56:10 +0000550 m_options.m_skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000551 internal,
552 m_options.m_hardware).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000553 }
554 break;
555 case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
556 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000557 const size_t num_files = m_options.m_filenames.GetSize();
Jim Ingham5a988412012-06-08 21:56:10 +0000558
Jim Inghame7320522015-02-12 17:37:46 +0000559 if (num_files == 0 && !m_options.m_all_files)
Jim Ingham5a988412012-06-08 21:56:10 +0000560 {
561 FileSpec file;
562 if (!GetDefaultFile (target, file, result))
563 {
564 result.AppendError ("No files provided and could not find default file.");
565 result.SetStatus (eReturnStatusFailed);
566 return false;
567 }
568 else
569 {
570 m_options.m_filenames.Append (file);
571 }
572 }
573
574 RegularExpression regexp(m_options.m_source_text_regexp.c_str());
575 if (!regexp.IsValid())
576 {
577 char err_str[1024];
578 regexp.GetErrorAsCString(err_str, sizeof(err_str));
579 result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"",
580 err_str);
581 result.SetStatus (eReturnStatusFailed);
582 return false;
583 }
Greg Claytoneb023e72013-10-11 19:48:25 +0000584 bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules),
585 &(m_options.m_filenames),
586 regexp,
587 internal,
Ilia K055ad9b2015-05-18 13:41:01 +0000588 m_options.m_hardware,
589 m_options.m_move_to_nearest_code).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000590 }
591 break;
592 case eSetTypeException:
593 {
Jim Inghama72b31c2015-04-22 19:42:18 +0000594 Error precond_error;
595 bp = target->CreateExceptionBreakpoint (m_options.m_exception_language,
Greg Claytoneb023e72013-10-11 19:48:25 +0000596 m_options.m_catch_bp,
597 m_options.m_throw_bp,
Jim Inghama72b31c2015-04-22 19:42:18 +0000598 internal,
599 &m_options.m_exception_extra_args,
600 &precond_error).get();
601 if (precond_error.Fail())
602 {
603 result.AppendErrorWithFormat("Error setting extra exception arguments: %s",
604 precond_error.AsCString());
605 target->RemoveBreakpointByID(bp->GetID());
606 result.SetStatus(eReturnStatusFailed);
607 return false;
608 }
Jim Ingham5a988412012-06-08 21:56:10 +0000609 }
610 break;
611 default:
612 break;
613 }
614
615 // Now set the various options that were passed in:
616 if (bp)
617 {
618 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
619 bp->SetThreadID (m_options.m_thread_id);
620
621 if (m_options.m_thread_index != UINT32_MAX)
622 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
623
624 if (!m_options.m_thread_name.empty())
625 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
626
627 if (!m_options.m_queue_name.empty())
628 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
629
630 if (m_options.m_ignore_count != 0)
631 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
632
633 if (!m_options.m_condition.empty())
634 bp->GetOptions()->SetCondition(m_options.m_condition.c_str());
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000635
636 if (!m_options.m_breakpoint_names.empty())
637 {
638 Error error; // We don't need to check the error here, since the option parser checked it...
639 for (auto name : m_options.m_breakpoint_names)
640 bp->AddName(name.c_str(), error);
641 }
Jim Inghamca36cd12012-10-05 19:16:31 +0000642
643 bp->SetOneShot (m_options.m_one_shot);
Jim Ingham5a988412012-06-08 21:56:10 +0000644 }
645
646 if (bp)
647 {
648 Stream &output_stream = result.GetOutputStream();
Jim Ingham1391cc72012-09-22 00:04:04 +0000649 const bool show_locations = false;
650 bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, show_locations);
Jim Ingham4aeb1982014-12-19 19:45:31 +0000651 if (target == m_interpreter.GetDebugger().GetDummyTarget())
652 output_stream.Printf ("Breakpoint set in dummy target, will get copied into future targets.\n");
653 else
654 {
655 // Don't print out this warning for exception breakpoints. They can get set before the target
656 // is set, but we won't know how to actually set the breakpoint till we run.
657 if (bp->GetNumLocations() == 0 && break_type != eSetTypeException)
658 {
659 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n");
660 }
661 }
Jim Ingham5a988412012-06-08 21:56:10 +0000662 result.SetStatus (eReturnStatusSuccessFinishResult);
663 }
664 else if (!bp)
665 {
666 result.AppendError ("Breakpoint creation failed: No breakpoint created.");
667 result.SetStatus (eReturnStatusFailed);
668 }
669
670 return result.Succeeded();
671 }
672
673private:
674 bool
675 GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result)
676 {
677 uint32_t default_line;
678 // First use the Source Manager's default file.
679 // Then use the current stack frame's file.
680 if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line))
681 {
Jason Molendab57e4a12013-11-04 09:33:30 +0000682 StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
Jim Ingham5a988412012-06-08 21:56:10 +0000683 if (cur_frame == NULL)
684 {
685 result.AppendError ("No selected frame to use to find the default file.");
686 result.SetStatus (eReturnStatusFailed);
687 return false;
688 }
689 else if (!cur_frame->HasDebugInformation())
690 {
691 result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info.");
692 result.SetStatus (eReturnStatusFailed);
693 return false;
694 }
695 else
696 {
697 const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
698 if (sc.line_entry.file)
699 {
700 file = sc.line_entry.file;
701 }
702 else
703 {
704 result.AppendError ("Can't find the file for the selected frame to use as the default file.");
705 result.SetStatus (eReturnStatusFailed);
706 return false;
707 }
708 }
709 }
710 return true;
711 }
712
713 CommandOptions m_options;
714};
Johnny Chen6943e7c2012-05-08 00:43:20 +0000715// If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to
716// update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately.
Johnny Chen4ab2e6b2012-05-07 23:23:41 +0000717#define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 )
718#define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 )
Jim Inghama8558b62012-05-22 00:12:20 +0000719#define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) )
Ilia K055ad9b2015-05-18 13:41:01 +0000720#define LLDB_OPT_MOVE_TO_NEAREST_CODE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_9 )
Jim Ingham0fcdac32015-11-06 22:48:59 +0000721#define LLDB_OPT_EXPR_LANGUAGE ( LLDB_OPT_SET_FROM_TO(3, 8) )
Jim Ingham87df91b2011-09-23 00:54:11 +0000722
Greg Claytone0d378b2011-03-24 21:19:54 +0000723OptionDefinition
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000724CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
725{
Zachary Turnerd37221d2014-07-09 16:31:49 +0000726 { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000727 "Set the breakpoint only in this shared library. "
728 "Can repeat this option multiple times to specify multiple shared libraries."},
Jim Ingham86511212010-06-15 18:47:14 +0000729
Zachary Turnerd37221d2014-07-09 16:31:49 +0000730 { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCount,
Caroline Ticedeaab222010-10-01 19:59:14 +0000731 "Set the number of times this breakpoint is skipped before stopping." },
Jim Ingham1b54c882010-06-16 02:00:15 +0000732
Zachary Turnerd37221d2014-07-09 16:31:49 +0000733 { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
Jim Inghamb2b256a2013-04-09 18:05:22 +0000734 "The breakpoint is deleted the first time it causes a stop." },
Jim Inghamca36cd12012-10-05 19:16:31 +0000735
Zachary Turnerd37221d2014-07-09 16:31:49 +0000736 { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeExpression,
Johnny Chen7d49c9c2012-05-25 21:10:46 +0000737 "The breakpoint stops only if this condition expression evaluates to true."},
738
Zachary Turnerd37221d2014-07-09 16:31:49 +0000739 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadIndex,
Jim Inghama89be912013-03-26 18:29:03 +0000740 "The breakpoint stops only for the thread whose indeX matches this argument."},
Jim Ingham1b54c882010-06-16 02:00:15 +0000741
Zachary Turnerd37221d2014-07-09 16:31:49 +0000742 { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadID,
Jim Ingham1b54c882010-06-16 02:00:15 +0000743 "The breakpoint stops only for the thread whose TID matches this argument."},
744
Zachary Turnerd37221d2014-07-09 16:31:49 +0000745 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadName,
Jim Ingham1b54c882010-06-16 02:00:15 +0000746 "The breakpoint stops only for the thread whose thread name matches this argument."},
747
Zachary Turnerd37221d2014-07-09 16:31:49 +0000748 { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
Greg Claytoneb023e72013-10-11 19:48:25 +0000749 "Require the breakpoint to use hardware breakpoints."},
750
Zachary Turnerd37221d2014-07-09 16:31:49 +0000751 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeQueueName,
Jim Ingham1b54c882010-06-16 02:00:15 +0000752 "The breakpoint stops only for threads in the queue whose name is given by this argument."},
753
Zachary Turnerd37221d2014-07-09 16:31:49 +0000754 { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
Jim Ingham289aca62013-02-14 19:10:36 +0000755 "Specifies the source file in which to set this breakpoint. "
756 "Note, by default lldb only looks for files that are #included if they use the standard include file extensions. "
Jim Ingham63944792013-02-14 19:30:35 +0000757 "To set breakpoints on .c/.cpp/.m/.mm files that are #included, set target.inline-breakpoint-strategy"
Jim Ingham289aca62013-02-14 19:10:36 +0000758 " to \"always\"."},
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000759
Zachary Turnerd37221d2014-07-09 16:31:49 +0000760 { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLineNum,
Jim Ingham87df91b2011-09-23 00:54:11 +0000761 "Specifies the line number on which to set this breakpoint."},
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000762
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000763 // Comment out this option for the moment, as we don't actually use it, but will in the future.
764 // This way users won't see it, but the infrastructure is left in place.
Virgile Belloe2607b52013-09-05 16:42:23 +0000765 // { 0, false, "column", 'C', OptionParser::eRequiredArgument, NULL, "<column>",
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000766 // "Set the breakpoint by source location at this particular column."},
767
Zachary Turnerd37221d2014-07-09 16:31:49 +0000768 { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeAddressOrExpression,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000769 "Set the breakpoint by address, at the specified address."},
770
Zachary Turnerd37221d2014-07-09 16:31:49 +0000771 { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Jim Ingham551262d2013-03-27 17:36:54 +0000772 "Set the breakpoint by function name. Can be repeated multiple times to make one breakpoint for multiple names" },
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000773
Zachary Turnerd37221d2014-07-09 16:31:49 +0000774 { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000775 "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and "
Jason Molendac8badb72015-09-28 23:02:00 +0000776 "for Objective C this means a full function prototype with class and selector. "
Jim Ingham64cc29c2012-05-03 20:30:08 +0000777 "Can be repeated multiple times to make one breakpoint for multiple names." },
Greg Clayton0c5cd902010-06-28 21:30:43 +0000778
Zachary Turnerd37221d2014-07-09 16:31:49 +0000779 { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeSelector,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000780 "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." },
Greg Clayton0c5cd902010-06-28 21:30:43 +0000781
Zachary Turnerd37221d2014-07-09 16:31:49 +0000782 { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeMethod,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000783 "Set the breakpoint by C++ method names. Can be repeated multiple times to make one breakpoint for multiple methods." },
Greg Clayton0c5cd902010-06-28 21:30:43 +0000784
Zachary Turnerd37221d2014-07-09 16:31:49 +0000785 { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeRegularExpression,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000786 "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
787
Zachary Turnerd37221d2014-07-09 16:31:49 +0000788 { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000789 "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). "
790 "Can be repeated multiple times to make one breakpoint for multiple symbols." },
Greg Claytone02b8502010-10-12 04:29:14 +0000791
Zachary Turnerd37221d2014-07-09 16:31:49 +0000792 { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeRegularExpression,
Jim Inghame96ade82013-06-07 01:13:00 +0000793 "Set the breakpoint by specifying a regular expression which is matched against the source text in a source file or files "
794 "specified with the -f option. The -f option can be specified more than once. "
795 "If no source files are specified, uses the current \"default source file\"" },
Jim Ingham969795f2011-09-21 01:17:13 +0000796
Jim Inghame7320522015-02-12 17:37:46 +0000797 { LLDB_OPT_SET_9, false, "all-files", 'A', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
798 "All files are searched for source pattern matches." },
799
Zachary Turnerd37221d2014-07-09 16:31:49 +0000800 { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLanguage,
Jim Inghamfab10e82012-03-06 00:37:27 +0000801 "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" },
802
Zachary Turnerd37221d2014-07-09 16:31:49 +0000803 { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean,
Jim Inghamfab10e82012-03-06 00:37:27 +0000804 "Set the breakpoint on exception throW." },
805
Zachary Turnerd37221d2014-07-09 16:31:49 +0000806 { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean,
Jim Inghamfab10e82012-03-06 00:37:27 +0000807 "Set the breakpoint on exception catcH." },
Jim Ingham969795f2011-09-21 01:17:13 +0000808
Jim Inghama72b31c2015-04-22 19:42:18 +0000809// Don't add this option till it actually does something useful...
810// { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeTypeName,
811// "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" },
812
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000813 { LLDB_OPT_EXPR_LANGUAGE, false, "language", 'L', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLanguage,
Dawn Perchik4112ab92015-07-22 02:01:32 +0000814 "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." },
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000815
Zachary Turnerd37221d2014-07-09 16:31:49 +0000816 { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean,
Jim Inghama8558b62012-05-22 00:12:20 +0000817 "sKip the prologue if the breakpoint is at the beginning of a function. If not set the target.skip-prologue setting is used." },
818
Jim Ingham33df7cd2014-12-06 01:28:03 +0000819 { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
820 "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
821
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000822 { LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointName,
823 "Adds this to the list of names for this breakopint."},
824
Ilia K055ad9b2015-05-18 13:41:01 +0000825 { LLDB_OPT_MOVE_TO_NEAREST_CODE, false, "move-to-nearest-code", 'm', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean,
826 "Move breakpoints to nearest code. If not set the target.move-to-nearest-code setting is used." },
827
Zachary Turnerd37221d2014-07-09 16:31:49 +0000828 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000829};
830
Jim Ingham5a988412012-06-08 21:56:10 +0000831//-------------------------------------------------------------------------
832// CommandObjectBreakpointModify
833//-------------------------------------------------------------------------
834#pragma mark Modify
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000835
Jim Ingham5a988412012-06-08 21:56:10 +0000836class CommandObjectBreakpointModify : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000837{
Jim Ingham5a988412012-06-08 21:56:10 +0000838public:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000839
Jim Ingham5a988412012-06-08 21:56:10 +0000840 CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
841 CommandObjectParsed (interpreter,
842 "breakpoint modify",
843 "Modify the options on a breakpoint or set of breakpoints in the executable. "
844 "If no breakpoint is specified, acts on the last created breakpoint. "
845 "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
846 NULL),
847 m_options (interpreter)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000848 {
Jim Ingham5a988412012-06-08 21:56:10 +0000849 CommandArgumentEntry arg;
850 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
851 // Add the entry for the first argument for this command to the object's arguments vector.
852 m_arguments.push_back (arg);
853 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000856 ~CommandObjectBreakpointModify () override {}
Greg Clayton0c5cd902010-06-28 21:30:43 +0000857
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000858 Options *
859 GetOptions () override
Jim Ingham5a988412012-06-08 21:56:10 +0000860 {
861 return &m_options;
862 }
Johnny Chen7d49c9c2012-05-25 21:10:46 +0000863
Jim Ingham5a988412012-06-08 21:56:10 +0000864 class CommandOptions : public Options
865 {
866 public:
Greg Clayton0c5cd902010-06-28 21:30:43 +0000867
Jim Ingham5a988412012-06-08 21:56:10 +0000868 CommandOptions (CommandInterpreter &interpreter) :
869 Options (interpreter),
870 m_ignore_count (0),
871 m_thread_id(LLDB_INVALID_THREAD_ID),
872 m_thread_id_passed(false),
873 m_thread_index (UINT32_MAX),
874 m_thread_index_passed(false),
875 m_thread_name(),
876 m_queue_name(),
877 m_condition (),
Jim Inghamca36cd12012-10-05 19:16:31 +0000878 m_one_shot (false),
Jim Ingham5a988412012-06-08 21:56:10 +0000879 m_enable_passed (false),
880 m_enable_value (false),
881 m_name_passed (false),
882 m_queue_passed (false),
Jim Inghamca36cd12012-10-05 19:16:31 +0000883 m_condition_passed (false),
Jim Ingham33df7cd2014-12-06 01:28:03 +0000884 m_one_shot_passed (false),
885 m_use_dummy (false)
Jim Ingham5a988412012-06-08 21:56:10 +0000886 {
887 }
Greg Clayton0c5cd902010-06-28 21:30:43 +0000888
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000889 ~CommandOptions () override {}
Greg Clayton0c5cd902010-06-28 21:30:43 +0000890
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000891 Error
892 SetOptionValue (uint32_t option_idx, const char *option_arg) override
Jim Ingham5a988412012-06-08 21:56:10 +0000893 {
894 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000895 const int short_option = m_getopt_table[option_idx].val;
Greg Claytone02b8502010-10-12 04:29:14 +0000896
Jim Ingham5a988412012-06-08 21:56:10 +0000897 switch (short_option)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000898 {
Jim Ingham5a988412012-06-08 21:56:10 +0000899 case 'c':
900 if (option_arg != NULL)
901 m_condition.assign (option_arg);
902 else
903 m_condition.clear();
904 m_condition_passed = true;
905 break;
906 case 'd':
907 m_enable_passed = true;
908 m_enable_value = false;
909 break;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000910 case 'D':
911 m_use_dummy = true;
912 break;
Jim Ingham5a988412012-06-08 21:56:10 +0000913 case 'e':
914 m_enable_passed = true;
915 m_enable_value = true;
916 break;
917 case 'i':
918 {
Vince Harron5275aaa2015-01-15 20:08:35 +0000919 m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
Jim Ingham5a988412012-06-08 21:56:10 +0000920 if (m_ignore_count == UINT32_MAX)
921 error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
922 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000923 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000924 case 'o':
925 {
926 bool value, success;
927 value = Args::StringToBoolean(option_arg, false, &success);
928 if (success)
929 {
930 m_one_shot_passed = true;
931 m_one_shot = value;
932 }
933 else
934 error.SetErrorStringWithFormat("invalid boolean value '%s' passed for -o option", option_arg);
935 }
936 break;
Jim Ingham5a988412012-06-08 21:56:10 +0000937 case 't' :
Jim Ingham87df91b2011-09-23 00:54:11 +0000938 {
Jim Ingham5a988412012-06-08 21:56:10 +0000939 if (option_arg[0] == '\0')
Jim Ingham87df91b2011-09-23 00:54:11 +0000940 {
Jim Ingham5a988412012-06-08 21:56:10 +0000941 m_thread_id = LLDB_INVALID_THREAD_ID;
942 m_thread_id_passed = true;
Jim Ingham87df91b2011-09-23 00:54:11 +0000943 }
944 else
945 {
Vince Harron5275aaa2015-01-15 20:08:35 +0000946 m_thread_id = StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Ingham5a988412012-06-08 21:56:10 +0000947 if (m_thread_id == LLDB_INVALID_THREAD_ID)
948 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
949 else
950 m_thread_id_passed = true;
Jim Ingham87df91b2011-09-23 00:54:11 +0000951 }
952 }
Jim Ingham5a988412012-06-08 21:56:10 +0000953 break;
954 case 'T':
955 if (option_arg != NULL)
956 m_thread_name.assign (option_arg);
957 else
958 m_thread_name.clear();
959 m_name_passed = true;
960 break;
961 case 'q':
962 if (option_arg != NULL)
963 m_queue_name.assign (option_arg);
964 else
965 m_queue_name.clear();
966 m_queue_passed = true;
967 break;
968 case 'x':
Jim Ingham969795f2011-09-21 01:17:13 +0000969 {
Jim Ingham5a988412012-06-08 21:56:10 +0000970 if (option_arg[0] == '\n')
971 {
972 m_thread_index = UINT32_MAX;
973 m_thread_index_passed = true;
974 }
975 else
976 {
Vince Harron5275aaa2015-01-15 20:08:35 +0000977 m_thread_index = StringConvert::ToUInt32 (option_arg, UINT32_MAX, 0);
Jim Ingham5a988412012-06-08 21:56:10 +0000978 if (m_thread_id == UINT32_MAX)
979 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
980 else
981 m_thread_index_passed = true;
982 }
Jim Ingham969795f2011-09-21 01:17:13 +0000983 }
Jim Ingham5a988412012-06-08 21:56:10 +0000984 break;
985 default:
986 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
987 break;
Jim Ingham969795f2011-09-21 01:17:13 +0000988 }
Jim Ingham5a988412012-06-08 21:56:10 +0000989
990 return error;
991 }
992 void
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000993 OptionParsingStarting () override
Jim Ingham5a988412012-06-08 21:56:10 +0000994 {
995 m_ignore_count = 0;
996 m_thread_id = LLDB_INVALID_THREAD_ID;
997 m_thread_id_passed = false;
998 m_thread_index = UINT32_MAX;
999 m_thread_index_passed = false;
1000 m_thread_name.clear();
1001 m_queue_name.clear();
1002 m_condition.clear();
Jim Inghamca36cd12012-10-05 19:16:31 +00001003 m_one_shot = false;
Jim Ingham5a988412012-06-08 21:56:10 +00001004 m_enable_passed = false;
1005 m_queue_passed = false;
1006 m_name_passed = false;
1007 m_condition_passed = false;
Jim Inghamca36cd12012-10-05 19:16:31 +00001008 m_one_shot_passed = false;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001009 m_use_dummy = false;
Jim Ingham5a988412012-06-08 21:56:10 +00001010 }
1011
1012 const OptionDefinition*
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001013 GetDefinitions () override
Jim Ingham5a988412012-06-08 21:56:10 +00001014 {
1015 return g_option_table;
1016 }
1017
1018
1019 // Options table: Required for subclasses of Options.
1020
1021 static OptionDefinition g_option_table[];
1022
1023 // Instance variables to hold the values for command options.
1024
1025 uint32_t m_ignore_count;
1026 lldb::tid_t m_thread_id;
1027 bool m_thread_id_passed;
1028 uint32_t m_thread_index;
1029 bool m_thread_index_passed;
1030 std::string m_thread_name;
1031 std::string m_queue_name;
1032 std::string m_condition;
Jim Inghamca36cd12012-10-05 19:16:31 +00001033 bool m_one_shot;
Jim Ingham5a988412012-06-08 21:56:10 +00001034 bool m_enable_passed;
1035 bool m_enable_value;
1036 bool m_name_passed;
1037 bool m_queue_passed;
1038 bool m_condition_passed;
Jim Inghamca36cd12012-10-05 19:16:31 +00001039 bool m_one_shot_passed;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001040 bool m_use_dummy;
Jim Ingham5a988412012-06-08 21:56:10 +00001041
1042 };
1043
1044protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001045 bool
1046 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +00001047 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001048 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
Jim Ingham5a988412012-06-08 21:56:10 +00001049 if (target == NULL)
1050 {
1051 result.AppendError ("Invalid target. No existing target or breakpoints.");
1052 result.SetStatus (eReturnStatusFailed);
1053 return false;
1054 }
1055
1056 Mutex::Locker locker;
1057 target->GetBreakpointList().GetListMutex(locker);
1058
1059 BreakpointIDList valid_bp_ids;
1060
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001061 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +00001062
1063 if (result.Succeeded())
1064 {
1065 const size_t count = valid_bp_ids.GetSize();
1066 for (size_t i = 0; i < count; ++i)
Jim Inghamfab10e82012-03-06 00:37:27 +00001067 {
Jim Ingham5a988412012-06-08 21:56:10 +00001068 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1069
1070 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1071 {
1072 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1073 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1074 {
1075 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
1076 if (location)
1077 {
1078 if (m_options.m_thread_id_passed)
1079 location->SetThreadID (m_options.m_thread_id);
1080
1081 if (m_options.m_thread_index_passed)
1082 location->SetThreadIndex(m_options.m_thread_index);
1083
1084 if (m_options.m_name_passed)
1085 location->SetThreadName(m_options.m_thread_name.c_str());
1086
1087 if (m_options.m_queue_passed)
1088 location->SetQueueName(m_options.m_queue_name.c_str());
1089
1090 if (m_options.m_ignore_count != 0)
1091 location->SetIgnoreCount(m_options.m_ignore_count);
1092
1093 if (m_options.m_enable_passed)
1094 location->SetEnabled (m_options.m_enable_value);
1095
1096 if (m_options.m_condition_passed)
1097 location->SetCondition (m_options.m_condition.c_str());
1098 }
1099 }
1100 else
1101 {
1102 if (m_options.m_thread_id_passed)
1103 bp->SetThreadID (m_options.m_thread_id);
1104
1105 if (m_options.m_thread_index_passed)
1106 bp->SetThreadIndex(m_options.m_thread_index);
1107
1108 if (m_options.m_name_passed)
1109 bp->SetThreadName(m_options.m_thread_name.c_str());
1110
1111 if (m_options.m_queue_passed)
1112 bp->SetQueueName(m_options.m_queue_name.c_str());
1113
1114 if (m_options.m_ignore_count != 0)
1115 bp->SetIgnoreCount(m_options.m_ignore_count);
1116
1117 if (m_options.m_enable_passed)
1118 bp->SetEnabled (m_options.m_enable_value);
1119
1120 if (m_options.m_condition_passed)
1121 bp->SetCondition (m_options.m_condition.c_str());
1122 }
1123 }
Jim Inghamfab10e82012-03-06 00:37:27 +00001124 }
Jim Ingham5a988412012-06-08 21:56:10 +00001125 }
1126
1127 return result.Succeeded();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001128 }
1129
Jim Ingham5a988412012-06-08 21:56:10 +00001130private:
1131 CommandOptions m_options;
1132};
Johnny Chen7d49c9c2012-05-25 21:10:46 +00001133
Jim Ingham5a988412012-06-08 21:56:10 +00001134#pragma mark Modify::CommandOptions
1135OptionDefinition
1136CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
1137{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001138{ 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." },
1139{ 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." },
1140{ 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."},
1141{ 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."},
1142{ 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."},
1143{ 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."},
1144{ LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."},
1145{ LLDB_OPT_SET_1, false, "enable", 'e', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Enable the breakpoint."},
1146{ LLDB_OPT_SET_2, false, "disable", 'd', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Disable the breakpoint."},
Jim Ingham33df7cd2014-12-06 01:28:03 +00001147{ 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."},
1148
Zachary Turnerd37221d2014-07-09 16:31:49 +00001149{ 0, false, NULL, 0 , 0, NULL, NULL, 0, eArgTypeNone, NULL }
Jim Ingham5a988412012-06-08 21:56:10 +00001150};
1151
1152//-------------------------------------------------------------------------
1153// CommandObjectBreakpointEnable
1154//-------------------------------------------------------------------------
1155#pragma mark Enable
1156
1157class CommandObjectBreakpointEnable : public CommandObjectParsed
1158{
1159public:
1160 CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
1161 CommandObjectParsed (interpreter,
1162 "enable",
1163 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
1164 NULL)
1165 {
1166 CommandArgumentEntry arg;
1167 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1168 // Add the entry for the first argument for this command to the object's arguments vector.
1169 m_arguments.push_back (arg);
1170 }
1171
1172
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001173 ~CommandObjectBreakpointEnable () override {}
Jim Ingham5a988412012-06-08 21:56:10 +00001174
1175protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001176 bool
1177 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +00001178 {
Jim Ingham893c9322014-11-22 01:42:44 +00001179 Target *target = GetSelectedOrDummyTarget();
Jim Ingham5a988412012-06-08 21:56:10 +00001180 if (target == NULL)
1181 {
1182 result.AppendError ("Invalid target. No existing target or breakpoints.");
1183 result.SetStatus (eReturnStatusFailed);
1184 return false;
1185 }
1186
1187 Mutex::Locker locker;
1188 target->GetBreakpointList().GetListMutex(locker);
1189
1190 const BreakpointList &breakpoints = target->GetBreakpointList();
1191
1192 size_t num_breakpoints = breakpoints.GetSize();
1193
1194 if (num_breakpoints == 0)
1195 {
1196 result.AppendError ("No breakpoints exist to be enabled.");
1197 result.SetStatus (eReturnStatusFailed);
1198 return false;
1199 }
1200
1201 if (command.GetArgumentCount() == 0)
1202 {
1203 // No breakpoint selected; enable all currently set breakpoints.
1204 target->EnableAllBreakpoints ();
Greg Clayton6fea17e2014-03-03 19:15:20 +00001205 result.AppendMessageWithFormat ("All breakpoints enabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints);
Jim Ingham5a988412012-06-08 21:56:10 +00001206 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1207 }
1208 else
1209 {
1210 // Particular breakpoint selected; enable that breakpoint.
1211 BreakpointIDList valid_bp_ids;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001212 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +00001213
1214 if (result.Succeeded())
1215 {
1216 int enable_count = 0;
1217 int loc_count = 0;
1218 const size_t count = valid_bp_ids.GetSize();
1219 for (size_t i = 0; i < count; ++i)
1220 {
1221 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1222
1223 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1224 {
1225 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1226 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1227 {
1228 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1229 if (location)
1230 {
1231 location->SetEnabled (true);
1232 ++loc_count;
1233 }
1234 }
1235 else
1236 {
1237 breakpoint->SetEnabled (true);
1238 ++enable_count;
1239 }
1240 }
1241 }
1242 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
1243 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1244 }
1245 }
1246
1247 return result.Succeeded();
1248 }
1249};
1250
1251//-------------------------------------------------------------------------
1252// CommandObjectBreakpointDisable
1253//-------------------------------------------------------------------------
1254#pragma mark Disable
1255
1256class CommandObjectBreakpointDisable : public CommandObjectParsed
1257{
1258public:
1259 CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
1260 CommandObjectParsed (interpreter,
1261 "breakpoint disable",
Kate Stoneea671fb2015-07-14 05:48:36 +00001262 "Disable the specified breakpoint(s) without removing them. If none are specified, disable all breakpoints.",
Jim Ingham5a988412012-06-08 21:56:10 +00001263 NULL)
1264 {
Jim Inghamb0fac502013-03-08 00:31:40 +00001265 SetHelpLong(
Kate Stoneea671fb2015-07-14 05:48:36 +00001266"Disable the specified breakpoint(s) without removing them. \
1267If none are specified, disable all breakpoints." R"(
1268
1269)" "Note: disabling a breakpoint will cause none of its locations to be hit \
1270regardless of whether they are enabled or disabled. After the sequence:" R"(
1271
1272 (lldb) break disable 1
1273 (lldb) break enable 1.1
1274
1275execution will NOT stop at location 1.1. To achieve that, type:
1276
1277 (lldb) break disable 1.*
1278 (lldb) break enable 1.1
1279
1280)" "The first command disables all the locations of breakpoint 1, \
Jim Inghamb0fac502013-03-08 00:31:40 +00001281the second re-enables the first location."
Kate Stoneea671fb2015-07-14 05:48:36 +00001282 );
Jim Inghamb0fac502013-03-08 00:31:40 +00001283
Jim Ingham5a988412012-06-08 21:56:10 +00001284 CommandArgumentEntry arg;
1285 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1286 // Add the entry for the first argument for this command to the object's arguments vector.
Jim Inghamb0fac502013-03-08 00:31:40 +00001287 m_arguments.push_back (arg);
1288
Jim Ingham5a988412012-06-08 21:56:10 +00001289 }
1290
1291
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001292 ~CommandObjectBreakpointDisable () override {}
Jim Ingham5a988412012-06-08 21:56:10 +00001293
1294protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001295 bool
1296 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +00001297 {
Jim Ingham893c9322014-11-22 01:42:44 +00001298 Target *target = GetSelectedOrDummyTarget();
Jim Ingham5a988412012-06-08 21:56:10 +00001299 if (target == NULL)
1300 {
1301 result.AppendError ("Invalid target. No existing target or breakpoints.");
1302 result.SetStatus (eReturnStatusFailed);
1303 return false;
1304 }
1305
1306 Mutex::Locker locker;
1307 target->GetBreakpointList().GetListMutex(locker);
1308
1309 const BreakpointList &breakpoints = target->GetBreakpointList();
1310 size_t num_breakpoints = breakpoints.GetSize();
1311
1312 if (num_breakpoints == 0)
1313 {
1314 result.AppendError ("No breakpoints exist to be disabled.");
1315 result.SetStatus (eReturnStatusFailed);
1316 return false;
1317 }
1318
1319 if (command.GetArgumentCount() == 0)
1320 {
1321 // No breakpoint selected; disable all currently set breakpoints.
1322 target->DisableAllBreakpoints ();
Greg Clayton6fea17e2014-03-03 19:15:20 +00001323 result.AppendMessageWithFormat ("All breakpoints disabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints);
Jim Ingham5a988412012-06-08 21:56:10 +00001324 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1325 }
1326 else
1327 {
1328 // Particular breakpoint selected; disable that breakpoint.
1329 BreakpointIDList valid_bp_ids;
1330
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001331 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +00001332
1333 if (result.Succeeded())
1334 {
1335 int disable_count = 0;
1336 int loc_count = 0;
1337 const size_t count = valid_bp_ids.GetSize();
1338 for (size_t i = 0; i < count; ++i)
1339 {
1340 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1341
1342 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1343 {
1344 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1345 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1346 {
1347 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1348 if (location)
1349 {
1350 location->SetEnabled (false);
1351 ++loc_count;
1352 }
1353 }
1354 else
1355 {
1356 breakpoint->SetEnabled (false);
1357 ++disable_count;
1358 }
1359 }
1360 }
1361 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
1362 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1363 }
1364 }
1365
1366 return result.Succeeded();
1367 }
1368
1369};
1370
1371//-------------------------------------------------------------------------
1372// CommandObjectBreakpointList
1373//-------------------------------------------------------------------------
1374#pragma mark List
1375
1376class CommandObjectBreakpointList : public CommandObjectParsed
1377{
1378public:
1379 CommandObjectBreakpointList (CommandInterpreter &interpreter) :
1380 CommandObjectParsed (interpreter,
1381 "breakpoint list",
1382 "List some or all breakpoints at configurable levels of detail.",
1383 NULL),
1384 m_options (interpreter)
1385 {
1386 CommandArgumentEntry arg;
1387 CommandArgumentData bp_id_arg;
1388
1389 // Define the first (and only) variant of this arg.
1390 bp_id_arg.arg_type = eArgTypeBreakpointID;
1391 bp_id_arg.arg_repetition = eArgRepeatOptional;
1392
1393 // There is only one variant this argument could be; put it into the argument entry.
1394 arg.push_back (bp_id_arg);
1395
1396 // Push the data for the first argument into the m_arguments vector.
1397 m_arguments.push_back (arg);
1398 }
1399
1400
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001401 ~CommandObjectBreakpointList () override {}
Jim Ingham5a988412012-06-08 21:56:10 +00001402
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001403 Options *
1404 GetOptions () override
Jim Ingham5a988412012-06-08 21:56:10 +00001405 {
1406 return &m_options;
Jim Ingham1b54c882010-06-16 02:00:15 +00001407 }
1408
Jim Ingham5a988412012-06-08 21:56:10 +00001409 class CommandOptions : public Options
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001410 {
Jim Ingham5a988412012-06-08 21:56:10 +00001411 public:
1412
1413 CommandOptions (CommandInterpreter &interpreter) :
1414 Options (interpreter),
Jim Ingham33df7cd2014-12-06 01:28:03 +00001415 m_level (lldb::eDescriptionLevelBrief),
1416 m_use_dummy(false)
Jim Ingham5a988412012-06-08 21:56:10 +00001417 {
1418 }
1419
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001420 ~CommandOptions () override {}
Jim Ingham5a988412012-06-08 21:56:10 +00001421
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001422 Error
1423 SetOptionValue (uint32_t option_idx, const char *option_arg) override
Jim Ingham5a988412012-06-08 21:56:10 +00001424 {
1425 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00001426 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham5a988412012-06-08 21:56:10 +00001427
1428 switch (short_option)
1429 {
1430 case 'b':
1431 m_level = lldb::eDescriptionLevelBrief;
1432 break;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001433 case 'D':
1434 m_use_dummy = true;
1435 break;
Jim Ingham5a988412012-06-08 21:56:10 +00001436 case 'f':
1437 m_level = lldb::eDescriptionLevelFull;
1438 break;
1439 case 'v':
1440 m_level = lldb::eDescriptionLevelVerbose;
1441 break;
1442 case 'i':
1443 m_internal = true;
1444 break;
1445 default:
1446 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1447 break;
1448 }
1449
1450 return error;
1451 }
1452
1453 void
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001454 OptionParsingStarting () override
Jim Ingham5a988412012-06-08 21:56:10 +00001455 {
1456 m_level = lldb::eDescriptionLevelFull;
1457 m_internal = false;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001458 m_use_dummy = false;
Jim Ingham5a988412012-06-08 21:56:10 +00001459 }
1460
1461 const OptionDefinition *
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001462 GetDefinitions () override
Jim Ingham5a988412012-06-08 21:56:10 +00001463 {
1464 return g_option_table;
1465 }
1466
1467 // Options table: Required for subclasses of Options.
1468
1469 static OptionDefinition g_option_table[];
1470
1471 // Instance variables to hold the values for command options.
1472
1473 lldb::DescriptionLevel m_level;
1474
1475 bool m_internal;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001476 bool m_use_dummy;
Jim Ingham5a988412012-06-08 21:56:10 +00001477 };
1478
1479protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001480 bool
1481 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +00001482 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001483 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
1484
Jim Ingham5a988412012-06-08 21:56:10 +00001485 if (target == NULL)
1486 {
1487 result.AppendError ("Invalid target. No current target or breakpoints.");
1488 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1489 return true;
1490 }
1491
1492 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
1493 Mutex::Locker locker;
1494 target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
1495
1496 size_t num_breakpoints = breakpoints.GetSize();
1497
1498 if (num_breakpoints == 0)
1499 {
1500 result.AppendMessage ("No breakpoints currently set.");
1501 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1502 return true;
1503 }
1504
Jim Ingham85e8b812011-02-19 02:53:09 +00001505 Stream &output_stream = result.GetOutputStream();
Jim Ingham5a988412012-06-08 21:56:10 +00001506
1507 if (command.GetArgumentCount() == 0)
1508 {
1509 // No breakpoint selected; show info about all currently set breakpoints.
1510 result.AppendMessage ("Current breakpoints:");
1511 for (size_t i = 0; i < num_breakpoints; ++i)
1512 {
1513 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
1514 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
1515 }
1516 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1517 }
1518 else
1519 {
1520 // Particular breakpoints selected; show info about that breakpoint.
1521 BreakpointIDList valid_bp_ids;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001522 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +00001523
1524 if (result.Succeeded())
1525 {
1526 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
1527 {
1528 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1529 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1530 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
1531 }
1532 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1533 }
1534 else
1535 {
1536 result.AppendError ("Invalid breakpoint id.");
1537 result.SetStatus (eReturnStatusFailed);
1538 }
1539 }
1540
1541 return result.Succeeded();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001542 }
1543
Jim Ingham5a988412012-06-08 21:56:10 +00001544private:
1545 CommandOptions m_options;
1546};
1547
1548#pragma mark List::CommandOptions
1549OptionDefinition
1550CommandObjectBreakpointList::CommandOptions::g_option_table[] =
1551{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001552 { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
Jim Ingham5a988412012-06-08 21:56:10 +00001553 "Show debugger internal breakpoints" },
1554
Zachary Turnerd37221d2014-07-09 16:31:49 +00001555 { LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
Jim Ingham5a988412012-06-08 21:56:10 +00001556 "Give a brief description of the breakpoint (no location info)."},
1557
1558 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
1559 // But I need to see it for now, and don't want to wait.
Zachary Turnerd37221d2014-07-09 16:31:49 +00001560 { LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
Jim Ingham5a988412012-06-08 21:56:10 +00001561 "Give a full description of the breakpoint and its locations."},
1562
Zachary Turnerd37221d2014-07-09 16:31:49 +00001563 { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
Jim Ingham5a988412012-06-08 21:56:10 +00001564 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
1565
Jim Ingham33df7cd2014-12-06 01:28:03 +00001566 { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1567 "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
1568
Zachary Turnerd37221d2014-07-09 16:31:49 +00001569 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Jim Ingham5a988412012-06-08 21:56:10 +00001570};
1571
1572//-------------------------------------------------------------------------
1573// CommandObjectBreakpointClear
1574//-------------------------------------------------------------------------
1575#pragma mark Clear
1576
1577class CommandObjectBreakpointClear : public CommandObjectParsed
1578{
1579public:
1580
1581 typedef enum BreakpointClearType
1582 {
1583 eClearTypeInvalid,
1584 eClearTypeFileAndLine
1585 } BreakpointClearType;
1586
1587 CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
1588 CommandObjectParsed (interpreter,
1589 "breakpoint clear",
1590 "Clears a breakpoint or set of breakpoints in the executable.",
1591 "breakpoint clear <cmd-options>"),
1592 m_options (interpreter)
1593 {
1594 }
1595
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001596 ~CommandObjectBreakpointClear () override {}
Jim Ingham5a988412012-06-08 21:56:10 +00001597
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001598 Options *
1599 GetOptions () override
Jim Ingham5a988412012-06-08 21:56:10 +00001600 {
1601 return &m_options;
1602 }
1603
1604 class CommandOptions : public Options
1605 {
1606 public:
1607
1608 CommandOptions (CommandInterpreter &interpreter) :
1609 Options (interpreter),
1610 m_filename (),
1611 m_line_num (0)
1612 {
1613 }
1614
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001615 ~CommandOptions () override {}
Jim Ingham5a988412012-06-08 21:56:10 +00001616
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001617 Error
1618 SetOptionValue (uint32_t option_idx, const char *option_arg) override
Jim Ingham5a988412012-06-08 21:56:10 +00001619 {
1620 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00001621 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham5a988412012-06-08 21:56:10 +00001622
1623 switch (short_option)
1624 {
1625 case 'f':
1626 m_filename.assign (option_arg);
1627 break;
1628
1629 case 'l':
Vince Harron5275aaa2015-01-15 20:08:35 +00001630 m_line_num = StringConvert::ToUInt32 (option_arg, 0);
Jim Ingham5a988412012-06-08 21:56:10 +00001631 break;
1632
1633 default:
1634 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1635 break;
1636 }
1637
1638 return error;
1639 }
1640
1641 void
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001642 OptionParsingStarting () override
Jim Ingham5a988412012-06-08 21:56:10 +00001643 {
1644 m_filename.clear();
1645 m_line_num = 0;
1646 }
1647
1648 const OptionDefinition*
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001649 GetDefinitions () override
Jim Ingham5a988412012-06-08 21:56:10 +00001650 {
1651 return g_option_table;
1652 }
1653
1654 // Options table: Required for subclasses of Options.
1655
1656 static OptionDefinition g_option_table[];
1657
1658 // Instance variables to hold the values for command options.
1659
1660 std::string m_filename;
1661 uint32_t m_line_num;
1662
1663 };
1664
1665protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001666 bool
1667 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +00001668 {
Jim Ingham893c9322014-11-22 01:42:44 +00001669 Target *target = GetSelectedOrDummyTarget();
Jim Ingham5a988412012-06-08 21:56:10 +00001670 if (target == NULL)
1671 {
1672 result.AppendError ("Invalid target. No existing target or breakpoints.");
1673 result.SetStatus (eReturnStatusFailed);
1674 return false;
1675 }
1676
1677 // The following are the various types of breakpoints that could be cleared:
1678 // 1). -f -l (clearing breakpoint by source location)
1679
1680 BreakpointClearType break_type = eClearTypeInvalid;
1681
1682 if (m_options.m_line_num != 0)
1683 break_type = eClearTypeFileAndLine;
1684
1685 Mutex::Locker locker;
1686 target->GetBreakpointList().GetListMutex(locker);
1687
1688 BreakpointList &breakpoints = target->GetBreakpointList();
1689 size_t num_breakpoints = breakpoints.GetSize();
1690
1691 // Early return if there's no breakpoint at all.
1692 if (num_breakpoints == 0)
1693 {
1694 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1695 result.SetStatus (eReturnStatusFailed);
1696 return result.Succeeded();
1697 }
1698
1699 // Find matching breakpoints and delete them.
1700
1701 // First create a copy of all the IDs.
1702 std::vector<break_id_t> BreakIDs;
1703 for (size_t i = 0; i < num_breakpoints; ++i)
1704 BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID());
1705
1706 int num_cleared = 0;
1707 StreamString ss;
1708 switch (break_type)
1709 {
1710 case eClearTypeFileAndLine: // Breakpoint by source position
1711 {
1712 const ConstString filename(m_options.m_filename.c_str());
1713 BreakpointLocationCollection loc_coll;
1714
1715 for (size_t i = 0; i < num_breakpoints; ++i)
1716 {
1717 Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
1718
1719 if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
1720 {
1721 // If the collection size is 0, it's a full match and we can just remove the breakpoint.
1722 if (loc_coll.GetSize() == 0)
1723 {
1724 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
1725 ss.EOL();
1726 target->RemoveBreakpointByID (bp->GetID());
1727 ++num_cleared;
1728 }
1729 }
1730 }
1731 }
1732 break;
1733
1734 default:
1735 break;
1736 }
1737
1738 if (num_cleared > 0)
1739 {
1740 Stream &output_stream = result.GetOutputStream();
1741 output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
1742 output_stream << ss.GetData();
1743 output_stream.EOL();
1744 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1745 }
1746 else
1747 {
1748 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1749 result.SetStatus (eReturnStatusFailed);
1750 }
1751
1752 return result.Succeeded();
1753 }
1754
1755private:
1756 CommandOptions m_options;
1757};
1758
1759#pragma mark Clear::CommandOptions
1760
1761OptionDefinition
1762CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
1763{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001764 { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
Jim Ingham5a988412012-06-08 21:56:10 +00001765 "Specify the breakpoint by source location in this particular file."},
1766
Zachary Turnerd37221d2014-07-09 16:31:49 +00001767 { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLineNum,
Jim Ingham5a988412012-06-08 21:56:10 +00001768 "Specify the breakpoint by source location at this particular line."},
1769
Zachary Turnerd37221d2014-07-09 16:31:49 +00001770 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Jim Ingham5a988412012-06-08 21:56:10 +00001771};
1772
1773//-------------------------------------------------------------------------
1774// CommandObjectBreakpointDelete
1775//-------------------------------------------------------------------------
1776#pragma mark Delete
1777
1778class CommandObjectBreakpointDelete : public CommandObjectParsed
1779{
1780public:
1781 CommandObjectBreakpointDelete (CommandInterpreter &interpreter) :
1782 CommandObjectParsed (interpreter,
1783 "breakpoint delete",
1784 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
Jim Ingham33df7cd2014-12-06 01:28:03 +00001785 NULL),
1786 m_options (interpreter)
Jim Ingham5a988412012-06-08 21:56:10 +00001787 {
1788 CommandArgumentEntry arg;
1789 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1790 // Add the entry for the first argument for this command to the object's arguments vector.
1791 m_arguments.push_back (arg);
1792 }
1793
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001794 ~CommandObjectBreakpointDelete () override {}
Jim Ingham5a988412012-06-08 21:56:10 +00001795
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001796 Options *
1797 GetOptions () override
Jim Ingham33df7cd2014-12-06 01:28:03 +00001798 {
1799 return &m_options;
1800 }
1801
1802 class CommandOptions : public Options
1803 {
1804 public:
1805
1806 CommandOptions (CommandInterpreter &interpreter) :
1807 Options (interpreter),
1808 m_use_dummy (false),
1809 m_force (false)
1810 {
1811 }
1812
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001813 ~CommandOptions () override {}
Jim Ingham33df7cd2014-12-06 01:28:03 +00001814
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001815 Error
1816 SetOptionValue (uint32_t option_idx, const char *option_arg) override
Jim Ingham33df7cd2014-12-06 01:28:03 +00001817 {
1818 Error error;
1819 const int short_option = m_getopt_table[option_idx].val;
1820
1821 switch (short_option)
1822 {
1823 case 'f':
1824 m_force = true;
1825 break;
1826
1827 case 'D':
1828 m_use_dummy = true;
1829 break;
1830
1831 default:
1832 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1833 break;
1834 }
1835
1836 return error;
1837 }
1838
1839 void
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001840 OptionParsingStarting () override
Jim Ingham33df7cd2014-12-06 01:28:03 +00001841 {
1842 m_use_dummy = false;
1843 m_force = false;
1844 }
1845
1846 const OptionDefinition*
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001847 GetDefinitions () override
Jim Ingham33df7cd2014-12-06 01:28:03 +00001848 {
1849 return g_option_table;
1850 }
1851
1852 // Options table: Required for subclasses of Options.
1853
1854 static OptionDefinition g_option_table[];
1855
1856 // Instance variables to hold the values for command options.
1857 bool m_use_dummy;
1858 bool m_force;
1859 };
1860
Jim Ingham5a988412012-06-08 21:56:10 +00001861protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001862 bool
1863 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +00001864 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001865 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
1866
Jim Ingham5a988412012-06-08 21:56:10 +00001867 if (target == NULL)
1868 {
1869 result.AppendError ("Invalid target. No existing target or breakpoints.");
1870 result.SetStatus (eReturnStatusFailed);
1871 return false;
1872 }
1873
1874 Mutex::Locker locker;
1875 target->GetBreakpointList().GetListMutex(locker);
1876
1877 const BreakpointList &breakpoints = target->GetBreakpointList();
1878
1879 size_t num_breakpoints = breakpoints.GetSize();
1880
1881 if (num_breakpoints == 0)
1882 {
1883 result.AppendError ("No breakpoints exist to be deleted.");
1884 result.SetStatus (eReturnStatusFailed);
1885 return false;
1886 }
1887
1888 if (command.GetArgumentCount() == 0)
1889 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001890 if (!m_options.m_force && !m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
Jim Ingham5a988412012-06-08 21:56:10 +00001891 {
1892 result.AppendMessage("Operation cancelled...");
1893 }
1894 else
1895 {
1896 target->RemoveAllBreakpoints ();
Greg Clayton6fea17e2014-03-03 19:15:20 +00001897 result.AppendMessageWithFormat ("All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : "");
Jim Ingham5a988412012-06-08 21:56:10 +00001898 }
1899 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1900 }
1901 else
1902 {
1903 // Particular breakpoint selected; disable that breakpoint.
1904 BreakpointIDList valid_bp_ids;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001905 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +00001906
1907 if (result.Succeeded())
1908 {
1909 int delete_count = 0;
1910 int disable_count = 0;
1911 const size_t count = valid_bp_ids.GetSize();
1912 for (size_t i = 0; i < count; ++i)
1913 {
1914 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1915
1916 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1917 {
1918 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1919 {
1920 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1921 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1922 // It makes no sense to try to delete individual locations, so we disable them instead.
1923 if (location)
1924 {
1925 location->SetEnabled (false);
1926 ++disable_count;
1927 }
1928 }
1929 else
1930 {
1931 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1932 ++delete_count;
1933 }
1934 }
1935 }
1936 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1937 delete_count, disable_count);
1938 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1939 }
1940 }
1941 return result.Succeeded();
1942 }
Jim Ingham33df7cd2014-12-06 01:28:03 +00001943private:
1944 CommandOptions m_options;
1945};
1946
1947OptionDefinition
1948CommandObjectBreakpointDelete::CommandOptions::g_option_table[] =
1949{
1950 { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1951 "Delete all breakpoints without querying for confirmation."},
1952
1953 { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1954 "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
1955
1956 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Jim Ingham5a988412012-06-08 21:56:10 +00001957};
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001958
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001959//-------------------------------------------------------------------------
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001960// CommandObjectBreakpointName
1961//-------------------------------------------------------------------------
1962
1963static OptionDefinition
1964g_breakpoint_name_options[] =
1965{
1966 { LLDB_OPT_SET_1, false, "name", 'N', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."},
1967 { LLDB_OPT_SET_2, false, "breakpoint-id", 'B', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointID, "Specify a breakpoint id to use."},
1968 { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1969 "Operate on Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
1970};
1971class BreakpointNameOptionGroup : public OptionGroup
1972{
1973public:
1974 BreakpointNameOptionGroup() :
1975 OptionGroup(),
1976 m_breakpoint(LLDB_INVALID_BREAK_ID),
1977 m_use_dummy (false)
1978 {
1979
1980 }
1981
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001982 ~BreakpointNameOptionGroup () override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001983 {
1984 }
1985
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001986 uint32_t
1987 GetNumDefinitions () override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001988 {
1989 return sizeof (g_breakpoint_name_options) / sizeof (OptionDefinition);
1990 }
1991
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001992 const OptionDefinition*
1993 GetDefinitions () override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001994 {
1995 return g_breakpoint_name_options;
1996 }
1997
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001998 Error
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001999 SetOptionValue (CommandInterpreter &interpreter,
2000 uint32_t option_idx,
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002001 const char *option_value) override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002002 {
2003 Error error;
2004 const int short_option = g_breakpoint_name_options[option_idx].short_option;
2005
2006 switch (short_option)
2007 {
2008 case 'N':
2009 if (BreakpointID::StringIsBreakpointName(option_value, error) && error.Success())
Pavel Labathc95f7e22015-02-20 11:14:59 +00002010 m_name.SetValueFromString(option_value);
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002011 break;
2012
2013 case 'B':
Pavel Labathc95f7e22015-02-20 11:14:59 +00002014 if (m_breakpoint.SetValueFromString(option_value).Fail())
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002015 error.SetErrorStringWithFormat ("unrecognized value \"%s\" for breakpoint", option_value);
2016 break;
2017 case 'D':
Pavel Labathc95f7e22015-02-20 11:14:59 +00002018 if (m_use_dummy.SetValueFromString(option_value).Fail())
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002019 error.SetErrorStringWithFormat ("unrecognized value \"%s\" for use-dummy", option_value);
2020 break;
2021
2022 default:
2023 error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
2024 break;
2025 }
2026 return error;
2027 }
2028
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002029 void
2030 OptionParsingStarting (CommandInterpreter &interpreter) override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002031 {
2032 m_name.Clear();
2033 m_breakpoint.Clear();
2034 m_use_dummy.Clear();
2035 m_use_dummy.SetDefaultValue(false);
2036 }
2037
2038 OptionValueString m_name;
2039 OptionValueUInt64 m_breakpoint;
2040 OptionValueBoolean m_use_dummy;
2041};
2042
2043
2044class CommandObjectBreakpointNameAdd : public CommandObjectParsed
2045{
2046public:
2047 CommandObjectBreakpointNameAdd (CommandInterpreter &interpreter) :
2048 CommandObjectParsed (interpreter,
2049 "add",
2050 "Add a name to the breakpoints provided.",
2051 "breakpoint name add <command-options> <breakpoint-id-list>"),
2052 m_name_options(),
2053 m_option_group(interpreter)
2054 {
2055 // Create the first variant for the first (and only) argument for this command.
2056 CommandArgumentEntry arg1;
2057 CommandArgumentData id_arg;
2058 id_arg.arg_type = eArgTypeBreakpointID;
2059 id_arg.arg_repetition = eArgRepeatOptional;
2060 arg1.push_back(id_arg);
2061 m_arguments.push_back (arg1);
2062
2063 m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
2064 m_option_group.Finalize();
2065 }
2066
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002067 ~CommandObjectBreakpointNameAdd () override {}
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002068
2069 Options *
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002070 GetOptions () override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002071 {
2072 return &m_option_group;
2073 }
2074
2075protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002076 bool
2077 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002078 {
2079 if (!m_name_options.m_name.OptionWasSet())
2080 {
2081 result.SetError("No name option provided.");
2082 return false;
2083 }
2084
2085 Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
2086
2087 if (target == NULL)
2088 {
2089 result.AppendError ("Invalid target. No existing target or breakpoints.");
2090 result.SetStatus (eReturnStatusFailed);
2091 return false;
2092 }
2093
2094 Mutex::Locker locker;
2095 target->GetBreakpointList().GetListMutex(locker);
2096
2097 const BreakpointList &breakpoints = target->GetBreakpointList();
2098
2099 size_t num_breakpoints = breakpoints.GetSize();
2100 if (num_breakpoints == 0)
2101 {
2102 result.SetError("No breakpoints, cannot add names.");
2103 result.SetStatus (eReturnStatusFailed);
2104 return false;
2105 }
2106
2107 // Particular breakpoint selected; disable that breakpoint.
2108 BreakpointIDList valid_bp_ids;
2109 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
2110
2111 if (result.Succeeded())
2112 {
2113 if (valid_bp_ids.GetSize() == 0)
2114 {
2115 result.SetError("No breakpoints specified, cannot add names.");
2116 result.SetStatus (eReturnStatusFailed);
2117 return false;
2118 }
2119 size_t num_valid_ids = valid_bp_ids.GetSize();
2120 for (size_t index = 0; index < num_valid_ids; index++)
2121 {
2122 lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
2123 BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
2124 Error error; // We don't need to check the error here, since the option parser checked it...
2125 bp_sp->AddName(m_name_options.m_name.GetCurrentValue(), error);
2126 }
2127 }
2128
2129 return true;
2130 }
2131
2132private:
2133 BreakpointNameOptionGroup m_name_options;
2134 OptionGroupOptions m_option_group;
2135};
2136
2137
2138
2139class CommandObjectBreakpointNameDelete : public CommandObjectParsed
2140{
2141public:
2142 CommandObjectBreakpointNameDelete (CommandInterpreter &interpreter) :
2143 CommandObjectParsed (interpreter,
2144 "delete",
2145 "Delete a name from the breakpoints provided.",
2146 "breakpoint name delete <command-options> <breakpoint-id-list>"),
2147 m_name_options(),
2148 m_option_group(interpreter)
2149 {
2150 // Create the first variant for the first (and only) argument for this command.
2151 CommandArgumentEntry arg1;
2152 CommandArgumentData id_arg;
2153 id_arg.arg_type = eArgTypeBreakpointID;
2154 id_arg.arg_repetition = eArgRepeatOptional;
2155 arg1.push_back(id_arg);
2156 m_arguments.push_back (arg1);
2157
2158 m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
2159 m_option_group.Finalize();
2160 }
2161
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002162 ~CommandObjectBreakpointNameDelete () override {}
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002163
2164 Options *
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002165 GetOptions () override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002166 {
2167 return &m_option_group;
2168 }
2169
2170protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002171 bool
2172 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002173 {
2174 if (!m_name_options.m_name.OptionWasSet())
2175 {
2176 result.SetError("No name option provided.");
2177 return false;
2178 }
2179
2180 Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
2181
2182 if (target == NULL)
2183 {
2184 result.AppendError ("Invalid target. No existing target or breakpoints.");
2185 result.SetStatus (eReturnStatusFailed);
2186 return false;
2187 }
2188
2189 Mutex::Locker locker;
2190 target->GetBreakpointList().GetListMutex(locker);
2191
2192 const BreakpointList &breakpoints = target->GetBreakpointList();
2193
2194 size_t num_breakpoints = breakpoints.GetSize();
2195 if (num_breakpoints == 0)
2196 {
2197 result.SetError("No breakpoints, cannot delete names.");
2198 result.SetStatus (eReturnStatusFailed);
2199 return false;
2200 }
2201
2202 // Particular breakpoint selected; disable that breakpoint.
2203 BreakpointIDList valid_bp_ids;
2204 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
2205
2206 if (result.Succeeded())
2207 {
2208 if (valid_bp_ids.GetSize() == 0)
2209 {
2210 result.SetError("No breakpoints specified, cannot delete names.");
2211 result.SetStatus (eReturnStatusFailed);
2212 return false;
2213 }
2214 size_t num_valid_ids = valid_bp_ids.GetSize();
2215 for (size_t index = 0; index < num_valid_ids; index++)
2216 {
2217 lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
2218 BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
2219 bp_sp->RemoveName(m_name_options.m_name.GetCurrentValue());
2220 }
2221 }
2222
2223 return true;
2224 }
2225
2226private:
2227 BreakpointNameOptionGroup m_name_options;
2228 OptionGroupOptions m_option_group;
2229};
2230
2231class CommandObjectBreakpointNameList : public CommandObjectParsed
2232{
2233public:
2234 CommandObjectBreakpointNameList (CommandInterpreter &interpreter) :
2235 CommandObjectParsed (interpreter,
2236 "list",
2237 "List either the names for a breakpoint or the breakpoints for a given name.",
2238 "breakpoint name list <command-options>"),
2239 m_name_options(),
2240 m_option_group(interpreter)
2241 {
2242 m_option_group.Append (&m_name_options);
2243 m_option_group.Finalize();
2244 }
2245
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002246 ~CommandObjectBreakpointNameList () override {}
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002247
2248 Options *
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002249 GetOptions () override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002250 {
2251 return &m_option_group;
2252 }
2253
2254protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002255 bool
2256 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002257 {
2258 Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
2259
2260 if (target == NULL)
2261 {
2262 result.AppendError ("Invalid target. No existing target or breakpoints.");
2263 result.SetStatus (eReturnStatusFailed);
2264 return false;
2265 }
2266
2267 if (m_name_options.m_name.OptionWasSet())
2268 {
2269 const char *name = m_name_options.m_name.GetCurrentValue();
2270 Mutex::Locker locker;
2271 target->GetBreakpointList().GetListMutex(locker);
2272
2273 BreakpointList &breakpoints = target->GetBreakpointList();
2274 for (BreakpointSP bp_sp : breakpoints.Breakpoints())
2275 {
2276 if (bp_sp->MatchesName(name))
2277 {
2278 StreamString s;
2279 bp_sp->GetDescription(&s, eDescriptionLevelBrief);
2280 s.EOL();
2281 result.AppendMessage(s.GetData());
2282 }
2283 }
2284
2285 }
2286 else if (m_name_options.m_breakpoint.OptionWasSet())
2287 {
2288 BreakpointSP bp_sp = target->GetBreakpointList().FindBreakpointByID(m_name_options.m_breakpoint.GetCurrentValue());
2289 if (bp_sp)
2290 {
2291 std::vector<std::string> names;
2292 bp_sp->GetNames (names);
2293 result.AppendMessage ("Names:");
2294 for (auto name : names)
2295 result.AppendMessageWithFormat (" %s\n", name.c_str());
2296 }
2297 else
2298 {
2299 result.AppendErrorWithFormat ("Could not find breakpoint %" PRId64 ".\n",
2300 m_name_options.m_breakpoint.GetCurrentValue());
2301 result.SetStatus (eReturnStatusFailed);
2302 return false;
2303 }
2304 }
2305 else
2306 {
2307 result.SetError ("Must specify -N or -B option to list.");
2308 result.SetStatus (eReturnStatusFailed);
2309 return false;
2310 }
2311 return true;
2312 }
2313
2314private:
2315 BreakpointNameOptionGroup m_name_options;
2316 OptionGroupOptions m_option_group;
2317};
2318
2319//-------------------------------------------------------------------------
2320// CommandObjectMultiwordBreakpoint
2321//-------------------------------------------------------------------------
2322class CommandObjectBreakpointName : public CommandObjectMultiword
2323{
2324public:
2325 CommandObjectBreakpointName (CommandInterpreter &interpreter) :
2326 CommandObjectMultiword(interpreter,
2327 "name",
2328 "A set of commands to manage name tags for breakpoints",
2329 "breakpoint name <command> [<command-options>]")
2330 {
2331 CommandObjectSP add_command_object (new CommandObjectBreakpointNameAdd (interpreter));
2332 CommandObjectSP delete_command_object (new CommandObjectBreakpointNameDelete (interpreter));
2333 CommandObjectSP list_command_object (new CommandObjectBreakpointNameList (interpreter));
2334
2335 LoadSubCommand ("add", add_command_object);
2336 LoadSubCommand ("delete", delete_command_object);
2337 LoadSubCommand ("list", list_command_object);
2338
2339 }
2340
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002341 ~CommandObjectBreakpointName () override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002342 {
2343 }
2344
2345};
2346
2347
2348//-------------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002349// CommandObjectMultiwordBreakpoint
2350//-------------------------------------------------------------------------
Jim Inghamae1c4cf2010-06-18 00:58:52 +00002351#pragma mark MultiwordBreakpoint
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002352
Greg Clayton66111032010-06-23 01:19:29 +00002353CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
Greg Claytona7015092010-09-18 01:14:36 +00002354 CommandObjectMultiword (interpreter,
2355 "breakpoint",
Jim Ingham46fbc602011-05-26 20:39:01 +00002356 "A set of commands for operating on breakpoints. Also see _regexp-break.",
Greg Claytona7015092010-09-18 01:14:36 +00002357 "breakpoint <command> [<command-options>]")
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002358{
Greg Claytona7015092010-09-18 01:14:36 +00002359 CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
Greg Claytona7015092010-09-18 01:14:36 +00002360 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
2361 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
Johnny Chenb7234e42010-10-28 17:27:46 +00002362 CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
2363 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
Greg Claytona7015092010-09-18 01:14:36 +00002364 CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002365 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
Greg Claytona7015092010-09-18 01:14:36 +00002366 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002367 CommandObjectSP name_command_object (new CommandObjectBreakpointName(interpreter));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002368
Johnny Chenb7234e42010-10-28 17:27:46 +00002369 list_command_object->SetCommandName ("breakpoint list");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002370 enable_command_object->SetCommandName("breakpoint enable");
2371 disable_command_object->SetCommandName("breakpoint disable");
Johnny Chenb7234e42010-10-28 17:27:46 +00002372 clear_command_object->SetCommandName("breakpoint clear");
2373 delete_command_object->SetCommandName("breakpoint delete");
Jim Inghamae1c4cf2010-06-18 00:58:52 +00002374 set_command_object->SetCommandName("breakpoint set");
Johnny Chenb7234e42010-10-28 17:27:46 +00002375 command_command_object->SetCommandName ("breakpoint command");
2376 modify_command_object->SetCommandName ("breakpoint modify");
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002377 name_command_object->SetCommandName ("breakpoint name");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002378
Greg Clayton23f59502012-07-17 03:23:13 +00002379 LoadSubCommand ("list", list_command_object);
2380 LoadSubCommand ("enable", enable_command_object);
2381 LoadSubCommand ("disable", disable_command_object);
2382 LoadSubCommand ("clear", clear_command_object);
2383 LoadSubCommand ("delete", delete_command_object);
2384 LoadSubCommand ("set", set_command_object);
2385 LoadSubCommand ("command", command_command_object);
2386 LoadSubCommand ("modify", modify_command_object);
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002387 LoadSubCommand ("name", name_command_object);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002388}
2389
2390CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
2391{
2392}
2393
2394void
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002395CommandObjectMultiwordBreakpoint::VerifyIDs (Args &args,
2396 Target *target,
2397 bool allow_locations,
2398 CommandReturnObject &result,
2399 BreakpointIDList *valid_ids)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002400{
2401 // args can be strings representing 1). integers (for breakpoint ids)
2402 // 2). the full breakpoint & location canonical representation
2403 // 3). the word "to" or a hyphen, representing a range (in which case there
2404 // had *better* be an entry both before & after of one of the first two types.
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002405 // 4). A breakpoint name
Jim Ingham36f3b362010-10-14 23:45:03 +00002406 // If args is empty, we will use the last created breakpoint (if there is one.)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002407
2408 Args temp_args;
2409
Jim Ingham36f3b362010-10-14 23:45:03 +00002410 if (args.GetArgumentCount() == 0)
2411 {
Greg Clayton4d122c42011-09-17 08:33:22 +00002412 if (target->GetLastCreatedBreakpoint())
Jim Ingham36f3b362010-10-14 23:45:03 +00002413 {
2414 valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
2415 result.SetStatus (eReturnStatusSuccessFinishNoResult);
2416 }
2417 else
2418 {
2419 result.AppendError("No breakpoint specified and no last created breakpoint.");
2420 result.SetStatus (eReturnStatusFailed);
2421 }
2422 return;
2423 }
2424
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002425 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
2426 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
2427 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
2428
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002429 BreakpointIDList::FindAndReplaceIDRanges (args, target, allow_locations, result, temp_args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002430
2431 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
2432
Greg Claytonc982c762010-07-09 20:39:50 +00002433 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002434
2435 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
2436 // and put into valid_ids.
2437
2438 if (result.Succeeded())
2439 {
2440 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
2441 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
2442
Greg Claytonc982c762010-07-09 20:39:50 +00002443 const size_t count = valid_ids->GetSize();
2444 for (size_t i = 0; i < count; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002445 {
2446 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
2447 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
2448 if (breakpoint != NULL)
2449 {
Greg Claytonc7bece562013-01-25 18:06:21 +00002450 const size_t num_locations = breakpoint->GetNumLocations();
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +00002451 if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002452 {
2453 StreamString id_str;
Greg Claytonc982c762010-07-09 20:39:50 +00002454 BreakpointID::GetCanonicalReference (&id_str,
2455 cur_bp_id.GetBreakpointID(),
2456 cur_bp_id.GetLocationID());
2457 i = valid_ids->GetSize() + 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002458 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
2459 id_str.GetData());
2460 result.SetStatus (eReturnStatusFailed);
2461 }
2462 }
2463 else
2464 {
Greg Claytonc982c762010-07-09 20:39:50 +00002465 i = valid_ids->GetSize() + 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002466 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
2467 result.SetStatus (eReturnStatusFailed);
2468 }
2469 }
2470 }
2471}