blob: 6b9db6ae85e77b493e409aae6b49a570b59bce69 [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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "CommandObjectBreakpoint.h"
13#include "CommandObjectBreakpointCommand.h"
14
15// C Includes
16// C++ Includes
17// Other libraries and framework includes
18// Project includes
19#include "lldb/Breakpoint/Breakpoint.h"
20#include "lldb/Breakpoint/BreakpointIDList.h"
21#include "lldb/Breakpoint/BreakpointLocation.h"
Jim Ingham40af72e2010-06-15 19:49:27 +000022#include "lldb/Interpreter/Options.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"
29#include "lldb/Target/Target.h"
30#include "lldb/Interpreter/CommandCompletions.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000031#include "lldb/Target/StackFrame.h"
Jim Ingham1b54c882010-06-16 02:00:15 +000032#include "lldb/Target/Thread.h"
33#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034
Johnny Chenb7234e42010-10-28 17:27:46 +000035#include <vector>
36
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037using namespace lldb;
38using namespace lldb_private;
39
40static void
Jim Ingham85e8b812011-02-19 02:53:09 +000041AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042{
43 s->IndentMore();
44 bp->GetDescription (s, level, true);
45 s->IndentLess();
46 s->EOL();
47}
48
49//-------------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +000050// CommandObjectBreakpointSet
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051//-------------------------------------------------------------------------
52
Jim Ingham5a988412012-06-08 21:56:10 +000053
54class CommandObjectBreakpointSet : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055{
Jim Ingham5a988412012-06-08 21:56:10 +000056public:
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
Jim Ingham5a988412012-06-08 21:56:10 +000058 typedef enum BreakpointSetType
59 {
60 eSetTypeInvalid,
61 eSetTypeFileAndLine,
62 eSetTypeAddress,
63 eSetTypeFunctionName,
64 eSetTypeFunctionRegexp,
65 eSetTypeSourceRegexp,
66 eSetTypeException
67 } BreakpointSetType;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068
Jim Ingham5a988412012-06-08 21:56:10 +000069 CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
70 CommandObjectParsed (interpreter,
71 "breakpoint set",
72 "Sets a breakpoint or set of breakpoints in the executable.",
73 "breakpoint set <cmd-options>"),
74 m_options (interpreter)
75 {
76 }
77
78
79 virtual
80 ~CommandObjectBreakpointSet () {}
81
82 virtual Options *
83 GetOptions ()
84 {
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 Ingham5a988412012-06-08 21:56:10 +0000112 m_language (eLanguageTypeUnknown),
Jim Inghamca36cd12012-10-05 19:16:31 +0000113 m_skip_prologue (eLazyBoolCalculate),
114 m_one_shot (false)
Jim Ingham5a988412012-06-08 21:56:10 +0000115 {
116 }
117
118
119 virtual
120 ~CommandOptions () {}
121
122 virtual Error
123 SetOptionValue (uint32_t option_idx, const char *option_arg)
124 {
125 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000126 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham5a988412012-06-08 21:56:10 +0000127
128 switch (short_option)
129 {
130 case 'a':
Greg Claytonb9d5df52012-12-06 22:49:16 +0000131 {
132 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
133 m_load_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
134 }
Jim Ingham5a988412012-06-08 21:56:10 +0000135 break;
136
Jim Inghamca36cd12012-10-05 19:16:31 +0000137 case 'b':
138 m_func_names.push_back (option_arg);
139 m_func_name_type_mask |= eFunctionNameTypeBase;
140 break;
141
Jim Ingham5a988412012-06-08 21:56:10 +0000142 case 'C':
143 m_column = Args::StringToUInt32 (option_arg, 0);
144 break;
145
146 case 'c':
147 m_condition.assign(option_arg);
148 break;
149
Jim Ingham33df7cd2014-12-06 01:28:03 +0000150 case 'D':
151 m_use_dummy = true;
152 break;
153
Jim Ingham5a988412012-06-08 21:56:10 +0000154 case 'E':
155 {
156 LanguageType language = LanguageRuntime::GetLanguageTypeFromString (option_arg);
157
158 switch (language)
159 {
160 case eLanguageTypeC89:
161 case eLanguageTypeC:
162 case eLanguageTypeC99:
Bruce Mitchener1d0089f2014-07-03 00:49:08 +0000163 case eLanguageTypeC11:
Jim Ingham5a988412012-06-08 21:56:10 +0000164 m_language = eLanguageTypeC;
165 break;
166 case eLanguageTypeC_plus_plus:
Bruce Mitchener1d0089f2014-07-03 00:49:08 +0000167 case eLanguageTypeC_plus_plus_03:
168 case eLanguageTypeC_plus_plus_11:
Jim Ingham5a988412012-06-08 21:56:10 +0000169 m_language = eLanguageTypeC_plus_plus;
170 break;
171 case eLanguageTypeObjC:
172 m_language = eLanguageTypeObjC;
173 break;
174 case eLanguageTypeObjC_plus_plus:
175 error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c");
176 break;
177 case eLanguageTypeUnknown:
178 error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg);
179 break;
180 default:
181 error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg);
182 }
183 }
184 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000185
186 case 'f':
187 m_filenames.AppendIfUnique (FileSpec(option_arg, false));
188 break;
189
190 case 'F':
191 m_func_names.push_back (option_arg);
192 m_func_name_type_mask |= eFunctionNameTypeFull;
193 break;
194
Jim Ingham5a988412012-06-08 21:56:10 +0000195 case 'h':
Greg Claytoneb023e72013-10-11 19:48:25 +0000196 {
197 bool success;
198 m_catch_bp = Args::StringToBoolean (option_arg, true, &success);
199 if (!success)
200 error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg);
201 }
202 break;
203
204 case 'H':
205 m_hardware = true;
206 break;
207
Jim Inghamca36cd12012-10-05 19:16:31 +0000208 case 'i':
209 {
210 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
211 if (m_ignore_count == UINT32_MAX)
212 error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
213 break;
214 }
215
Jim Ingham5a988412012-06-08 21:56:10 +0000216 case 'K':
217 {
218 bool success;
219 bool value;
220 value = Args::StringToBoolean (option_arg, true, &success);
221 if (value)
222 m_skip_prologue = eLazyBoolYes;
223 else
224 m_skip_prologue = eLazyBoolNo;
225
226 if (!success)
227 error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg);
228 }
229 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000230
231 case 'l':
232 m_line_num = Args::StringToUInt32 (option_arg, 0);
233 break;
234
235 case 'M':
236 m_func_names.push_back (option_arg);
237 m_func_name_type_mask |= eFunctionNameTypeMethod;
238 break;
239
240 case 'n':
241 m_func_names.push_back (option_arg);
242 m_func_name_type_mask |= eFunctionNameTypeAuto;
243 break;
244
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000245 case 'N':
246 if (BreakpointID::StringIsBreakpointName(option_arg, error))
247 m_breakpoint_names.push_back (option_arg);
248 else
249 error.SetErrorStringWithFormat(error.AsCString());
250 break;
251
Jim Inghamca36cd12012-10-05 19:16:31 +0000252 case 'o':
253 m_one_shot = true;
254 break;
255
256 case 'p':
257 m_source_text_regexp.assign (option_arg);
258 break;
259
260 case 'q':
261 m_queue_name.assign (option_arg);
262 break;
263
264 case 'r':
265 m_func_regexp.assign (option_arg);
266 break;
267
268 case 's':
269 {
270 m_modules.AppendIfUnique (FileSpec (option_arg, false));
271 break;
272 }
273
274 case 'S':
275 m_func_names.push_back (option_arg);
276 m_func_name_type_mask |= eFunctionNameTypeSelector;
277 break;
278
279 case 't' :
280 {
281 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
282 if (m_thread_id == LLDB_INVALID_THREAD_ID)
283 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
284 }
285 break;
286
287 case 'T':
288 m_thread_name.assign (option_arg);
289 break;
290
291 case 'w':
292 {
293 bool success;
294 m_throw_bp = Args::StringToBoolean (option_arg, true, &success);
295 if (!success)
296 error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg);
297 }
298 break;
299
300 case 'x':
301 {
302 m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
303 if (m_thread_id == UINT32_MAX)
304 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
305
306 }
307 break;
308
Jim Ingham5a988412012-06-08 21:56:10 +0000309 default:
310 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
311 break;
312 }
313
314 return error;
315 }
316 void
317 OptionParsingStarting ()
318 {
319 m_condition.clear();
320 m_filenames.Clear();
321 m_line_num = 0;
322 m_column = 0;
323 m_func_names.clear();
Greg Clayton1f746072012-08-29 21:13:06 +0000324 m_func_name_type_mask = eFunctionNameTypeNone;
Jim Ingham5a988412012-06-08 21:56:10 +0000325 m_func_regexp.clear();
Greg Clayton1f746072012-08-29 21:13:06 +0000326 m_source_text_regexp.clear();
Jim Ingham5a988412012-06-08 21:56:10 +0000327 m_modules.Clear();
Greg Clayton1f746072012-08-29 21:13:06 +0000328 m_load_addr = LLDB_INVALID_ADDRESS;
Jim Ingham5a988412012-06-08 21:56:10 +0000329 m_ignore_count = 0;
330 m_thread_id = LLDB_INVALID_THREAD_ID;
331 m_thread_index = UINT32_MAX;
332 m_thread_name.clear();
333 m_queue_name.clear();
Jim Ingham5a988412012-06-08 21:56:10 +0000334 m_catch_bp = false;
335 m_throw_bp = true;
Greg Claytoneb023e72013-10-11 19:48:25 +0000336 m_hardware = false;
Greg Clayton1f746072012-08-29 21:13:06 +0000337 m_language = eLanguageTypeUnknown;
Jim Ingham5a988412012-06-08 21:56:10 +0000338 m_skip_prologue = eLazyBoolCalculate;
Jim Inghamca36cd12012-10-05 19:16:31 +0000339 m_one_shot = false;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000340 m_use_dummy = false;
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000341 m_breakpoint_names.clear();
Jim Ingham5a988412012-06-08 21:56:10 +0000342 }
343
344 const OptionDefinition*
345 GetDefinitions ()
346 {
347 return g_option_table;
348 }
349
350 // Options table: Required for subclasses of Options.
351
352 static OptionDefinition g_option_table[];
353
354 // Instance variables to hold the values for command options.
355
356 std::string m_condition;
357 FileSpecList m_filenames;
358 uint32_t m_line_num;
359 uint32_t m_column;
Jim Ingham5a988412012-06-08 21:56:10 +0000360 std::vector<std::string> m_func_names;
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000361 std::vector<std::string> m_breakpoint_names;
Jim Ingham5a988412012-06-08 21:56:10 +0000362 uint32_t m_func_name_type_mask;
363 std::string m_func_regexp;
364 std::string m_source_text_regexp;
365 FileSpecList m_modules;
366 lldb::addr_t m_load_addr;
367 uint32_t m_ignore_count;
368 lldb::tid_t m_thread_id;
369 uint32_t m_thread_index;
370 std::string m_thread_name;
371 std::string m_queue_name;
372 bool m_catch_bp;
373 bool m_throw_bp;
Greg Claytoneb023e72013-10-11 19:48:25 +0000374 bool m_hardware; // Request to use hardware breakpoints
Jim Ingham5a988412012-06-08 21:56:10 +0000375 lldb::LanguageType m_language;
376 LazyBool m_skip_prologue;
Jim Inghamca36cd12012-10-05 19:16:31 +0000377 bool m_one_shot;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000378 bool m_use_dummy;
Jim Ingham5a988412012-06-08 21:56:10 +0000379
380 };
381
382protected:
383 virtual bool
384 DoExecute (Args& command,
Jim Ingham33df7cd2014-12-06 01:28:03 +0000385 CommandReturnObject &result)
Jim Ingham5a988412012-06-08 21:56:10 +0000386 {
Jim Ingham33df7cd2014-12-06 01:28:03 +0000387 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
388
Jim Ingham893c9322014-11-22 01:42:44 +0000389 if (target == nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +0000390 {
391 result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command).");
392 result.SetStatus (eReturnStatusFailed);
393 return false;
394 }
395
396 // The following are the various types of breakpoints that could be set:
397 // 1). -f -l -p [-s -g] (setting breakpoint by source location)
398 // 2). -a [-s -g] (setting breakpoint by address)
399 // 3). -n [-s -g] (setting breakpoint by function name)
400 // 4). -r [-s -g] (setting breakpoint by function name regular expression)
401 // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text)
402 // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.)
403
404 BreakpointSetType break_type = eSetTypeInvalid;
405
406 if (m_options.m_line_num != 0)
407 break_type = eSetTypeFileAndLine;
408 else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
409 break_type = eSetTypeAddress;
410 else if (!m_options.m_func_names.empty())
411 break_type = eSetTypeFunctionName;
412 else if (!m_options.m_func_regexp.empty())
413 break_type = eSetTypeFunctionRegexp;
414 else if (!m_options.m_source_text_regexp.empty())
415 break_type = eSetTypeSourceRegexp;
416 else if (m_options.m_language != eLanguageTypeUnknown)
417 break_type = eSetTypeException;
418
419 Breakpoint *bp = NULL;
420 FileSpec module_spec;
Jim Ingham5a988412012-06-08 21:56:10 +0000421 const bool internal = false;
422
Jim Ingham5a988412012-06-08 21:56:10 +0000423 switch (break_type)
424 {
425 case eSetTypeFileAndLine: // Breakpoint by source position
426 {
427 FileSpec file;
Greg Claytonc7bece562013-01-25 18:06:21 +0000428 const size_t num_files = m_options.m_filenames.GetSize();
Jim Ingham5a988412012-06-08 21:56:10 +0000429 if (num_files == 0)
430 {
431 if (!GetDefaultFile (target, file, result))
432 {
433 result.AppendError("No file supplied and no default file available.");
434 result.SetStatus (eReturnStatusFailed);
435 return false;
436 }
437 }
438 else if (num_files > 1)
439 {
440 result.AppendError("Only one file at a time is allowed for file and line breakpoints.");
441 result.SetStatus (eReturnStatusFailed);
442 return false;
443 }
444 else
445 file = m_options.m_filenames.GetFileSpecAtIndex(0);
Greg Clayton1f746072012-08-29 21:13:06 +0000446
447 // Only check for inline functions if
448 LazyBool check_inlines = eLazyBoolCalculate;
449
Jim Ingham5a988412012-06-08 21:56:10 +0000450 bp = target->CreateBreakpoint (&(m_options.m_modules),
451 file,
452 m_options.m_line_num,
Greg Clayton1f746072012-08-29 21:13:06 +0000453 check_inlines,
Jim Ingham5a988412012-06-08 21:56:10 +0000454 m_options.m_skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000455 internal,
456 m_options.m_hardware).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000457 }
458 break;
459
460 case eSetTypeAddress: // Breakpoint by address
Greg Claytoneb023e72013-10-11 19:48:25 +0000461 bp = target->CreateBreakpoint (m_options.m_load_addr,
462 internal,
463 m_options.m_hardware).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000464 break;
465
466 case eSetTypeFunctionName: // Breakpoint by function name
467 {
468 uint32_t name_type_mask = m_options.m_func_name_type_mask;
469
470 if (name_type_mask == 0)
471 name_type_mask = eFunctionNameTypeAuto;
472
473 bp = target->CreateBreakpoint (&(m_options.m_modules),
474 &(m_options.m_filenames),
475 m_options.m_func_names,
476 name_type_mask,
477 m_options.m_skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000478 internal,
479 m_options.m_hardware).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000480 }
481 break;
482
483 case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
484 {
485 RegularExpression regexp(m_options.m_func_regexp.c_str());
486 if (!regexp.IsValid())
487 {
488 char err_str[1024];
489 regexp.GetErrorAsCString(err_str, sizeof(err_str));
490 result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"",
491 err_str);
492 result.SetStatus (eReturnStatusFailed);
493 return false;
494 }
495
496 bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules),
497 &(m_options.m_filenames),
498 regexp,
499 m_options.m_skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000500 internal,
501 m_options.m_hardware).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000502 }
503 break;
504 case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
505 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000506 const size_t num_files = m_options.m_filenames.GetSize();
Jim Ingham5a988412012-06-08 21:56:10 +0000507
508 if (num_files == 0)
509 {
510 FileSpec file;
511 if (!GetDefaultFile (target, file, result))
512 {
513 result.AppendError ("No files provided and could not find default file.");
514 result.SetStatus (eReturnStatusFailed);
515 return false;
516 }
517 else
518 {
519 m_options.m_filenames.Append (file);
520 }
521 }
522
523 RegularExpression regexp(m_options.m_source_text_regexp.c_str());
524 if (!regexp.IsValid())
525 {
526 char err_str[1024];
527 regexp.GetErrorAsCString(err_str, sizeof(err_str));
528 result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"",
529 err_str);
530 result.SetStatus (eReturnStatusFailed);
531 return false;
532 }
Greg Claytoneb023e72013-10-11 19:48:25 +0000533 bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules),
534 &(m_options.m_filenames),
535 regexp,
536 internal,
537 m_options.m_hardware).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000538 }
539 break;
540 case eSetTypeException:
541 {
Greg Claytoneb023e72013-10-11 19:48:25 +0000542 bp = target->CreateExceptionBreakpoint (m_options.m_language,
543 m_options.m_catch_bp,
544 m_options.m_throw_bp,
545 m_options.m_hardware).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000546 }
547 break;
548 default:
549 break;
550 }
551
552 // Now set the various options that were passed in:
553 if (bp)
554 {
555 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
556 bp->SetThreadID (m_options.m_thread_id);
557
558 if (m_options.m_thread_index != UINT32_MAX)
559 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
560
561 if (!m_options.m_thread_name.empty())
562 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
563
564 if (!m_options.m_queue_name.empty())
565 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
566
567 if (m_options.m_ignore_count != 0)
568 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
569
570 if (!m_options.m_condition.empty())
571 bp->GetOptions()->SetCondition(m_options.m_condition.c_str());
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000572
573 if (!m_options.m_breakpoint_names.empty())
574 {
575 Error error; // We don't need to check the error here, since the option parser checked it...
576 for (auto name : m_options.m_breakpoint_names)
577 bp->AddName(name.c_str(), error);
578 }
Jim Inghamca36cd12012-10-05 19:16:31 +0000579
580 bp->SetOneShot (m_options.m_one_shot);
Jim Ingham5a988412012-06-08 21:56:10 +0000581 }
582
583 if (bp)
584 {
585 Stream &output_stream = result.GetOutputStream();
Jim Ingham1391cc72012-09-22 00:04:04 +0000586 const bool show_locations = false;
587 bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, show_locations);
Jim Ingham5a988412012-06-08 21:56:10 +0000588 // Don't print out this warning for exception breakpoints. They can get set before the target
589 // is set, but we won't know how to actually set the breakpoint till we run.
590 if (bp->GetNumLocations() == 0 && break_type != eSetTypeException)
591 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n");
592 result.SetStatus (eReturnStatusSuccessFinishResult);
593 }
594 else if (!bp)
595 {
596 result.AppendError ("Breakpoint creation failed: No breakpoint created.");
597 result.SetStatus (eReturnStatusFailed);
598 }
599
600 return result.Succeeded();
601 }
602
603private:
604 bool
605 GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result)
606 {
607 uint32_t default_line;
608 // First use the Source Manager's default file.
609 // Then use the current stack frame's file.
610 if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line))
611 {
Jason Molendab57e4a12013-11-04 09:33:30 +0000612 StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
Jim Ingham5a988412012-06-08 21:56:10 +0000613 if (cur_frame == NULL)
614 {
615 result.AppendError ("No selected frame to use to find the default file.");
616 result.SetStatus (eReturnStatusFailed);
617 return false;
618 }
619 else if (!cur_frame->HasDebugInformation())
620 {
621 result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info.");
622 result.SetStatus (eReturnStatusFailed);
623 return false;
624 }
625 else
626 {
627 const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
628 if (sc.line_entry.file)
629 {
630 file = sc.line_entry.file;
631 }
632 else
633 {
634 result.AppendError ("Can't find the file for the selected frame to use as the default file.");
635 result.SetStatus (eReturnStatusFailed);
636 return false;
637 }
638 }
639 }
640 return true;
641 }
642
643 CommandOptions m_options;
644};
Johnny Chen6943e7c2012-05-08 00:43:20 +0000645// If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to
646// update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately.
Johnny Chen4ab2e6b2012-05-07 23:23:41 +0000647#define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 )
648#define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 )
Jim Inghama8558b62012-05-22 00:12:20 +0000649#define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) )
Jim Ingham87df91b2011-09-23 00:54:11 +0000650
Greg Claytone0d378b2011-03-24 21:19:54 +0000651OptionDefinition
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000652CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
653{
Zachary Turnerd37221d2014-07-09 16:31:49 +0000654 { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000655 "Set the breakpoint only in this shared library. "
656 "Can repeat this option multiple times to specify multiple shared libraries."},
Jim Ingham86511212010-06-15 18:47:14 +0000657
Zachary Turnerd37221d2014-07-09 16:31:49 +0000658 { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCount,
Caroline Ticedeaab222010-10-01 19:59:14 +0000659 "Set the number of times this breakpoint is skipped before stopping." },
Jim Ingham1b54c882010-06-16 02:00:15 +0000660
Zachary Turnerd37221d2014-07-09 16:31:49 +0000661 { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
Jim Inghamb2b256a2013-04-09 18:05:22 +0000662 "The breakpoint is deleted the first time it causes a stop." },
Jim Inghamca36cd12012-10-05 19:16:31 +0000663
Zachary Turnerd37221d2014-07-09 16:31:49 +0000664 { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeExpression,
Johnny Chen7d49c9c2012-05-25 21:10:46 +0000665 "The breakpoint stops only if this condition expression evaluates to true."},
666
Zachary Turnerd37221d2014-07-09 16:31:49 +0000667 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadIndex,
Jim Inghama89be912013-03-26 18:29:03 +0000668 "The breakpoint stops only for the thread whose indeX matches this argument."},
Jim Ingham1b54c882010-06-16 02:00:15 +0000669
Zachary Turnerd37221d2014-07-09 16:31:49 +0000670 { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadID,
Jim Ingham1b54c882010-06-16 02:00:15 +0000671 "The breakpoint stops only for the thread whose TID matches this argument."},
672
Zachary Turnerd37221d2014-07-09 16:31:49 +0000673 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadName,
Jim Ingham1b54c882010-06-16 02:00:15 +0000674 "The breakpoint stops only for the thread whose thread name matches this argument."},
675
Zachary Turnerd37221d2014-07-09 16:31:49 +0000676 { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
Greg Claytoneb023e72013-10-11 19:48:25 +0000677 "Require the breakpoint to use hardware breakpoints."},
678
Zachary Turnerd37221d2014-07-09 16:31:49 +0000679 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeQueueName,
Jim Ingham1b54c882010-06-16 02:00:15 +0000680 "The breakpoint stops only for threads in the queue whose name is given by this argument."},
681
Zachary Turnerd37221d2014-07-09 16:31:49 +0000682 { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
Jim Ingham289aca62013-02-14 19:10:36 +0000683 "Specifies the source file in which to set this breakpoint. "
684 "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 +0000685 "To set breakpoints on .c/.cpp/.m/.mm files that are #included, set target.inline-breakpoint-strategy"
Jim Ingham289aca62013-02-14 19:10:36 +0000686 " to \"always\"."},
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687
Zachary Turnerd37221d2014-07-09 16:31:49 +0000688 { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLineNum,
Jim Ingham87df91b2011-09-23 00:54:11 +0000689 "Specifies the line number on which to set this breakpoint."},
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000690
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691 // Comment out this option for the moment, as we don't actually use it, but will in the future.
692 // This way users won't see it, but the infrastructure is left in place.
Virgile Belloe2607b52013-09-05 16:42:23 +0000693 // { 0, false, "column", 'C', OptionParser::eRequiredArgument, NULL, "<column>",
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000694 // "Set the breakpoint by source location at this particular column."},
695
Zachary Turnerd37221d2014-07-09 16:31:49 +0000696 { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeAddressOrExpression,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000697 "Set the breakpoint by address, at the specified address."},
698
Zachary Turnerd37221d2014-07-09 16:31:49 +0000699 { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Jim Ingham551262d2013-03-27 17:36:54 +0000700 "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 +0000701
Zachary Turnerd37221d2014-07-09 16:31:49 +0000702 { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000703 "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and "
704 "for Objective C this means a full function prototype with class and selector. "
705 "Can be repeated multiple times to make one breakpoint for multiple names." },
Greg Clayton0c5cd902010-06-28 21:30:43 +0000706
Zachary Turnerd37221d2014-07-09 16:31:49 +0000707 { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeSelector,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000708 "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 +0000709
Zachary Turnerd37221d2014-07-09 16:31:49 +0000710 { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeMethod,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000711 "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 +0000712
Zachary Turnerd37221d2014-07-09 16:31:49 +0000713 { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeRegularExpression,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000714 "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
715
Zachary Turnerd37221d2014-07-09 16:31:49 +0000716 { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000717 "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). "
718 "Can be repeated multiple times to make one breakpoint for multiple symbols." },
Greg Claytone02b8502010-10-12 04:29:14 +0000719
Zachary Turnerd37221d2014-07-09 16:31:49 +0000720 { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeRegularExpression,
Jim Inghame96ade82013-06-07 01:13:00 +0000721 "Set the breakpoint by specifying a regular expression which is matched against the source text in a source file or files "
722 "specified with the -f option. The -f option can be specified more than once. "
723 "If no source files are specified, uses the current \"default source file\"" },
Jim Ingham969795f2011-09-21 01:17:13 +0000724
Zachary Turnerd37221d2014-07-09 16:31:49 +0000725 { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLanguage,
Jim Inghamfab10e82012-03-06 00:37:27 +0000726 "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" },
727
Zachary Turnerd37221d2014-07-09 16:31:49 +0000728 { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean,
Jim Inghamfab10e82012-03-06 00:37:27 +0000729 "Set the breakpoint on exception throW." },
730
Zachary Turnerd37221d2014-07-09 16:31:49 +0000731 { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean,
Jim Inghamfab10e82012-03-06 00:37:27 +0000732 "Set the breakpoint on exception catcH." },
Jim Ingham969795f2011-09-21 01:17:13 +0000733
Zachary Turnerd37221d2014-07-09 16:31:49 +0000734 { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean,
Jim Inghama8558b62012-05-22 00:12:20 +0000735 "sKip the prologue if the breakpoint is at the beginning of a function. If not set the target.skip-prologue setting is used." },
736
Jim Ingham33df7cd2014-12-06 01:28:03 +0000737 { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
738 "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
739
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000740 { LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointName,
741 "Adds this to the list of names for this breakopint."},
742
Zachary Turnerd37221d2014-07-09 16:31:49 +0000743 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000744};
745
Jim Ingham5a988412012-06-08 21:56:10 +0000746//-------------------------------------------------------------------------
747// CommandObjectBreakpointModify
748//-------------------------------------------------------------------------
749#pragma mark Modify
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750
Jim Ingham5a988412012-06-08 21:56:10 +0000751class CommandObjectBreakpointModify : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000752{
Jim Ingham5a988412012-06-08 21:56:10 +0000753public:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000754
Jim Ingham5a988412012-06-08 21:56:10 +0000755 CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
756 CommandObjectParsed (interpreter,
757 "breakpoint modify",
758 "Modify the options on a breakpoint or set of breakpoints in the executable. "
759 "If no breakpoint is specified, acts on the last created breakpoint. "
760 "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
761 NULL),
762 m_options (interpreter)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000763 {
Jim Ingham5a988412012-06-08 21:56:10 +0000764 CommandArgumentEntry arg;
765 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
766 // Add the entry for the first argument for this command to the object's arguments vector.
767 m_arguments.push_back (arg);
768 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000769
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770
Jim Ingham5a988412012-06-08 21:56:10 +0000771 virtual
772 ~CommandObjectBreakpointModify () {}
Greg Clayton0c5cd902010-06-28 21:30:43 +0000773
Jim Ingham5a988412012-06-08 21:56:10 +0000774 virtual Options *
775 GetOptions ()
776 {
777 return &m_options;
778 }
Johnny Chen7d49c9c2012-05-25 21:10:46 +0000779
Jim Ingham5a988412012-06-08 21:56:10 +0000780 class CommandOptions : public Options
781 {
782 public:
Greg Clayton0c5cd902010-06-28 21:30:43 +0000783
Jim Ingham5a988412012-06-08 21:56:10 +0000784 CommandOptions (CommandInterpreter &interpreter) :
785 Options (interpreter),
786 m_ignore_count (0),
787 m_thread_id(LLDB_INVALID_THREAD_ID),
788 m_thread_id_passed(false),
789 m_thread_index (UINT32_MAX),
790 m_thread_index_passed(false),
791 m_thread_name(),
792 m_queue_name(),
793 m_condition (),
Jim Inghamca36cd12012-10-05 19:16:31 +0000794 m_one_shot (false),
Jim Ingham5a988412012-06-08 21:56:10 +0000795 m_enable_passed (false),
796 m_enable_value (false),
797 m_name_passed (false),
798 m_queue_passed (false),
Jim Inghamca36cd12012-10-05 19:16:31 +0000799 m_condition_passed (false),
Jim Ingham33df7cd2014-12-06 01:28:03 +0000800 m_one_shot_passed (false),
801 m_use_dummy (false)
Jim Ingham5a988412012-06-08 21:56:10 +0000802 {
803 }
Greg Clayton0c5cd902010-06-28 21:30:43 +0000804
Jim Ingham5a988412012-06-08 21:56:10 +0000805 virtual
806 ~CommandOptions () {}
Greg Clayton0c5cd902010-06-28 21:30:43 +0000807
Jim Ingham5a988412012-06-08 21:56:10 +0000808 virtual Error
809 SetOptionValue (uint32_t option_idx, const char *option_arg)
810 {
811 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000812 const int short_option = m_getopt_table[option_idx].val;
Greg Claytone02b8502010-10-12 04:29:14 +0000813
Jim Ingham5a988412012-06-08 21:56:10 +0000814 switch (short_option)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000815 {
Jim Ingham5a988412012-06-08 21:56:10 +0000816 case 'c':
817 if (option_arg != NULL)
818 m_condition.assign (option_arg);
819 else
820 m_condition.clear();
821 m_condition_passed = true;
822 break;
823 case 'd':
824 m_enable_passed = true;
825 m_enable_value = false;
826 break;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000827 case 'D':
828 m_use_dummy = true;
829 break;
Jim Ingham5a988412012-06-08 21:56:10 +0000830 case 'e':
831 m_enable_passed = true;
832 m_enable_value = true;
833 break;
834 case 'i':
835 {
836 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
837 if (m_ignore_count == UINT32_MAX)
838 error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
839 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000840 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000841 case 'o':
842 {
843 bool value, success;
844 value = Args::StringToBoolean(option_arg, false, &success);
845 if (success)
846 {
847 m_one_shot_passed = true;
848 m_one_shot = value;
849 }
850 else
851 error.SetErrorStringWithFormat("invalid boolean value '%s' passed for -o option", option_arg);
852 }
853 break;
Jim Ingham5a988412012-06-08 21:56:10 +0000854 case 't' :
Jim Ingham87df91b2011-09-23 00:54:11 +0000855 {
Jim Ingham5a988412012-06-08 21:56:10 +0000856 if (option_arg[0] == '\0')
Jim Ingham87df91b2011-09-23 00:54:11 +0000857 {
Jim Ingham5a988412012-06-08 21:56:10 +0000858 m_thread_id = LLDB_INVALID_THREAD_ID;
859 m_thread_id_passed = true;
Jim Ingham87df91b2011-09-23 00:54:11 +0000860 }
861 else
862 {
Jim Ingham5a988412012-06-08 21:56:10 +0000863 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
864 if (m_thread_id == LLDB_INVALID_THREAD_ID)
865 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
866 else
867 m_thread_id_passed = true;
Jim Ingham87df91b2011-09-23 00:54:11 +0000868 }
869 }
Jim Ingham5a988412012-06-08 21:56:10 +0000870 break;
871 case 'T':
872 if (option_arg != NULL)
873 m_thread_name.assign (option_arg);
874 else
875 m_thread_name.clear();
876 m_name_passed = true;
877 break;
878 case 'q':
879 if (option_arg != NULL)
880 m_queue_name.assign (option_arg);
881 else
882 m_queue_name.clear();
883 m_queue_passed = true;
884 break;
885 case 'x':
Jim Ingham969795f2011-09-21 01:17:13 +0000886 {
Jim Ingham5a988412012-06-08 21:56:10 +0000887 if (option_arg[0] == '\n')
888 {
889 m_thread_index = UINT32_MAX;
890 m_thread_index_passed = true;
891 }
892 else
893 {
894 m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0);
895 if (m_thread_id == UINT32_MAX)
896 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
897 else
898 m_thread_index_passed = true;
899 }
Jim Ingham969795f2011-09-21 01:17:13 +0000900 }
Jim Ingham5a988412012-06-08 21:56:10 +0000901 break;
902 default:
903 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
904 break;
Jim Ingham969795f2011-09-21 01:17:13 +0000905 }
Jim Ingham5a988412012-06-08 21:56:10 +0000906
907 return error;
908 }
909 void
910 OptionParsingStarting ()
911 {
912 m_ignore_count = 0;
913 m_thread_id = LLDB_INVALID_THREAD_ID;
914 m_thread_id_passed = false;
915 m_thread_index = UINT32_MAX;
916 m_thread_index_passed = false;
917 m_thread_name.clear();
918 m_queue_name.clear();
919 m_condition.clear();
Jim Inghamca36cd12012-10-05 19:16:31 +0000920 m_one_shot = false;
Jim Ingham5a988412012-06-08 21:56:10 +0000921 m_enable_passed = false;
922 m_queue_passed = false;
923 m_name_passed = false;
924 m_condition_passed = false;
Jim Inghamca36cd12012-10-05 19:16:31 +0000925 m_one_shot_passed = false;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000926 m_use_dummy = false;
Jim Ingham5a988412012-06-08 21:56:10 +0000927 }
928
929 const OptionDefinition*
930 GetDefinitions ()
931 {
932 return g_option_table;
933 }
934
935
936 // Options table: Required for subclasses of Options.
937
938 static OptionDefinition g_option_table[];
939
940 // Instance variables to hold the values for command options.
941
942 uint32_t m_ignore_count;
943 lldb::tid_t m_thread_id;
944 bool m_thread_id_passed;
945 uint32_t m_thread_index;
946 bool m_thread_index_passed;
947 std::string m_thread_name;
948 std::string m_queue_name;
949 std::string m_condition;
Jim Inghamca36cd12012-10-05 19:16:31 +0000950 bool m_one_shot;
Jim Ingham5a988412012-06-08 21:56:10 +0000951 bool m_enable_passed;
952 bool m_enable_value;
953 bool m_name_passed;
954 bool m_queue_passed;
955 bool m_condition_passed;
Jim Inghamca36cd12012-10-05 19:16:31 +0000956 bool m_one_shot_passed;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000957 bool m_use_dummy;
Jim Ingham5a988412012-06-08 21:56:10 +0000958
959 };
960
961protected:
962 virtual bool
963 DoExecute (Args& command, CommandReturnObject &result)
964 {
Jim Ingham33df7cd2014-12-06 01:28:03 +0000965 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
Jim Ingham5a988412012-06-08 21:56:10 +0000966 if (target == NULL)
967 {
968 result.AppendError ("Invalid target. No existing target or breakpoints.");
969 result.SetStatus (eReturnStatusFailed);
970 return false;
971 }
972
973 Mutex::Locker locker;
974 target->GetBreakpointList().GetListMutex(locker);
975
976 BreakpointIDList valid_bp_ids;
977
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000978 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +0000979
980 if (result.Succeeded())
981 {
982 const size_t count = valid_bp_ids.GetSize();
983 for (size_t i = 0; i < count; ++i)
Jim Inghamfab10e82012-03-06 00:37:27 +0000984 {
Jim Ingham5a988412012-06-08 21:56:10 +0000985 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
986
987 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
988 {
989 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
990 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
991 {
992 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
993 if (location)
994 {
995 if (m_options.m_thread_id_passed)
996 location->SetThreadID (m_options.m_thread_id);
997
998 if (m_options.m_thread_index_passed)
999 location->SetThreadIndex(m_options.m_thread_index);
1000
1001 if (m_options.m_name_passed)
1002 location->SetThreadName(m_options.m_thread_name.c_str());
1003
1004 if (m_options.m_queue_passed)
1005 location->SetQueueName(m_options.m_queue_name.c_str());
1006
1007 if (m_options.m_ignore_count != 0)
1008 location->SetIgnoreCount(m_options.m_ignore_count);
1009
1010 if (m_options.m_enable_passed)
1011 location->SetEnabled (m_options.m_enable_value);
1012
1013 if (m_options.m_condition_passed)
1014 location->SetCondition (m_options.m_condition.c_str());
1015 }
1016 }
1017 else
1018 {
1019 if (m_options.m_thread_id_passed)
1020 bp->SetThreadID (m_options.m_thread_id);
1021
1022 if (m_options.m_thread_index_passed)
1023 bp->SetThreadIndex(m_options.m_thread_index);
1024
1025 if (m_options.m_name_passed)
1026 bp->SetThreadName(m_options.m_thread_name.c_str());
1027
1028 if (m_options.m_queue_passed)
1029 bp->SetQueueName(m_options.m_queue_name.c_str());
1030
1031 if (m_options.m_ignore_count != 0)
1032 bp->SetIgnoreCount(m_options.m_ignore_count);
1033
1034 if (m_options.m_enable_passed)
1035 bp->SetEnabled (m_options.m_enable_value);
1036
1037 if (m_options.m_condition_passed)
1038 bp->SetCondition (m_options.m_condition.c_str());
1039 }
1040 }
Jim Inghamfab10e82012-03-06 00:37:27 +00001041 }
Jim Ingham5a988412012-06-08 21:56:10 +00001042 }
1043
1044 return result.Succeeded();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001045 }
1046
Jim Ingham5a988412012-06-08 21:56:10 +00001047private:
1048 CommandOptions m_options;
1049};
Johnny Chen7d49c9c2012-05-25 21:10:46 +00001050
Jim Ingham5a988412012-06-08 21:56:10 +00001051#pragma mark Modify::CommandOptions
1052OptionDefinition
1053CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
1054{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001055{ 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." },
1056{ 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." },
1057{ 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."},
1058{ 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."},
1059{ 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."},
1060{ 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."},
1061{ LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."},
1062{ LLDB_OPT_SET_1, false, "enable", 'e', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Enable the breakpoint."},
1063{ LLDB_OPT_SET_2, false, "disable", 'd', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Disable the breakpoint."},
Jim Ingham33df7cd2014-12-06 01:28:03 +00001064{ 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."},
1065
Zachary Turnerd37221d2014-07-09 16:31:49 +00001066{ 0, false, NULL, 0 , 0, NULL, NULL, 0, eArgTypeNone, NULL }
Jim Ingham5a988412012-06-08 21:56:10 +00001067};
1068
1069//-------------------------------------------------------------------------
1070// CommandObjectBreakpointEnable
1071//-------------------------------------------------------------------------
1072#pragma mark Enable
1073
1074class CommandObjectBreakpointEnable : public CommandObjectParsed
1075{
1076public:
1077 CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
1078 CommandObjectParsed (interpreter,
1079 "enable",
1080 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
1081 NULL)
1082 {
1083 CommandArgumentEntry arg;
1084 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1085 // Add the entry for the first argument for this command to the object's arguments vector.
1086 m_arguments.push_back (arg);
1087 }
1088
1089
1090 virtual
1091 ~CommandObjectBreakpointEnable () {}
1092
1093protected:
1094 virtual bool
1095 DoExecute (Args& command, CommandReturnObject &result)
1096 {
Jim Ingham893c9322014-11-22 01:42:44 +00001097 Target *target = GetSelectedOrDummyTarget();
Jim Ingham5a988412012-06-08 21:56:10 +00001098 if (target == NULL)
1099 {
1100 result.AppendError ("Invalid target. No existing target or breakpoints.");
1101 result.SetStatus (eReturnStatusFailed);
1102 return false;
1103 }
1104
1105 Mutex::Locker locker;
1106 target->GetBreakpointList().GetListMutex(locker);
1107
1108 const BreakpointList &breakpoints = target->GetBreakpointList();
1109
1110 size_t num_breakpoints = breakpoints.GetSize();
1111
1112 if (num_breakpoints == 0)
1113 {
1114 result.AppendError ("No breakpoints exist to be enabled.");
1115 result.SetStatus (eReturnStatusFailed);
1116 return false;
1117 }
1118
1119 if (command.GetArgumentCount() == 0)
1120 {
1121 // No breakpoint selected; enable all currently set breakpoints.
1122 target->EnableAllBreakpoints ();
Greg Clayton6fea17e2014-03-03 19:15:20 +00001123 result.AppendMessageWithFormat ("All breakpoints enabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints);
Jim Ingham5a988412012-06-08 21:56:10 +00001124 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1125 }
1126 else
1127 {
1128 // Particular breakpoint selected; enable that breakpoint.
1129 BreakpointIDList valid_bp_ids;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001130 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +00001131
1132 if (result.Succeeded())
1133 {
1134 int enable_count = 0;
1135 int loc_count = 0;
1136 const size_t count = valid_bp_ids.GetSize();
1137 for (size_t i = 0; i < count; ++i)
1138 {
1139 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1140
1141 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1142 {
1143 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1144 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1145 {
1146 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1147 if (location)
1148 {
1149 location->SetEnabled (true);
1150 ++loc_count;
1151 }
1152 }
1153 else
1154 {
1155 breakpoint->SetEnabled (true);
1156 ++enable_count;
1157 }
1158 }
1159 }
1160 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
1161 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1162 }
1163 }
1164
1165 return result.Succeeded();
1166 }
1167};
1168
1169//-------------------------------------------------------------------------
1170// CommandObjectBreakpointDisable
1171//-------------------------------------------------------------------------
1172#pragma mark Disable
1173
1174class CommandObjectBreakpointDisable : public CommandObjectParsed
1175{
1176public:
1177 CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
1178 CommandObjectParsed (interpreter,
1179 "breakpoint disable",
1180 "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.",
1181 NULL)
1182 {
Jim Inghamb0fac502013-03-08 00:31:40 +00001183 SetHelpLong(
1184"Disable the specified breakpoint(s) without removing it/them. \n\
1185If no breakpoints are specified, disable them all.\n\
1186\n\
1187Note: disabling a breakpoint will cause none of its locations to be hit\n\
1188regardless of whether they are enabled or disabled. So the sequence: \n\
1189\n\
1190 (lldb) break disable 1\n\
1191 (lldb) break enable 1.1\n\
1192\n\
1193will NOT cause location 1.1 to get hit. To achieve that, do:\n\
1194\n\
1195 (lldb) break disable 1.*\n\
1196 (lldb) break enable 1.1\n\
1197\n\
1198The first command disables all the locations of breakpoint 1, \n\
1199the second re-enables the first location."
1200 );
1201
Jim Ingham5a988412012-06-08 21:56:10 +00001202 CommandArgumentEntry arg;
1203 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1204 // Add the entry for the first argument for this command to the object's arguments vector.
Jim Inghamb0fac502013-03-08 00:31:40 +00001205 m_arguments.push_back (arg);
1206
Jim Ingham5a988412012-06-08 21:56:10 +00001207 }
1208
1209
1210 virtual
1211 ~CommandObjectBreakpointDisable () {}
1212
1213protected:
1214 virtual bool
1215 DoExecute (Args& command, CommandReturnObject &result)
1216 {
Jim Ingham893c9322014-11-22 01:42:44 +00001217 Target *target = GetSelectedOrDummyTarget();
Jim Ingham5a988412012-06-08 21:56:10 +00001218 if (target == NULL)
1219 {
1220 result.AppendError ("Invalid target. No existing target or breakpoints.");
1221 result.SetStatus (eReturnStatusFailed);
1222 return false;
1223 }
1224
1225 Mutex::Locker locker;
1226 target->GetBreakpointList().GetListMutex(locker);
1227
1228 const BreakpointList &breakpoints = target->GetBreakpointList();
1229 size_t num_breakpoints = breakpoints.GetSize();
1230
1231 if (num_breakpoints == 0)
1232 {
1233 result.AppendError ("No breakpoints exist to be disabled.");
1234 result.SetStatus (eReturnStatusFailed);
1235 return false;
1236 }
1237
1238 if (command.GetArgumentCount() == 0)
1239 {
1240 // No breakpoint selected; disable all currently set breakpoints.
1241 target->DisableAllBreakpoints ();
Greg Clayton6fea17e2014-03-03 19:15:20 +00001242 result.AppendMessageWithFormat ("All breakpoints disabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints);
Jim Ingham5a988412012-06-08 21:56:10 +00001243 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1244 }
1245 else
1246 {
1247 // Particular breakpoint selected; disable that breakpoint.
1248 BreakpointIDList valid_bp_ids;
1249
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001250 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +00001251
1252 if (result.Succeeded())
1253 {
1254 int disable_count = 0;
1255 int loc_count = 0;
1256 const size_t count = valid_bp_ids.GetSize();
1257 for (size_t i = 0; i < count; ++i)
1258 {
1259 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1260
1261 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1262 {
1263 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1264 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1265 {
1266 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1267 if (location)
1268 {
1269 location->SetEnabled (false);
1270 ++loc_count;
1271 }
1272 }
1273 else
1274 {
1275 breakpoint->SetEnabled (false);
1276 ++disable_count;
1277 }
1278 }
1279 }
1280 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
1281 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1282 }
1283 }
1284
1285 return result.Succeeded();
1286 }
1287
1288};
1289
1290//-------------------------------------------------------------------------
1291// CommandObjectBreakpointList
1292//-------------------------------------------------------------------------
1293#pragma mark List
1294
1295class CommandObjectBreakpointList : public CommandObjectParsed
1296{
1297public:
1298 CommandObjectBreakpointList (CommandInterpreter &interpreter) :
1299 CommandObjectParsed (interpreter,
1300 "breakpoint list",
1301 "List some or all breakpoints at configurable levels of detail.",
1302 NULL),
1303 m_options (interpreter)
1304 {
1305 CommandArgumentEntry arg;
1306 CommandArgumentData bp_id_arg;
1307
1308 // Define the first (and only) variant of this arg.
1309 bp_id_arg.arg_type = eArgTypeBreakpointID;
1310 bp_id_arg.arg_repetition = eArgRepeatOptional;
1311
1312 // There is only one variant this argument could be; put it into the argument entry.
1313 arg.push_back (bp_id_arg);
1314
1315 // Push the data for the first argument into the m_arguments vector.
1316 m_arguments.push_back (arg);
1317 }
1318
1319
1320 virtual
1321 ~CommandObjectBreakpointList () {}
1322
1323 virtual Options *
1324 GetOptions ()
1325 {
1326 return &m_options;
Jim Ingham1b54c882010-06-16 02:00:15 +00001327 }
1328
Jim Ingham5a988412012-06-08 21:56:10 +00001329 class CommandOptions : public Options
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001330 {
Jim Ingham5a988412012-06-08 21:56:10 +00001331 public:
1332
1333 CommandOptions (CommandInterpreter &interpreter) :
1334 Options (interpreter),
Jim Ingham33df7cd2014-12-06 01:28:03 +00001335 m_level (lldb::eDescriptionLevelBrief),
1336 m_use_dummy(false)
Jim Ingham5a988412012-06-08 21:56:10 +00001337 {
1338 }
1339
1340 virtual
1341 ~CommandOptions () {}
1342
1343 virtual Error
1344 SetOptionValue (uint32_t option_idx, const char *option_arg)
1345 {
1346 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00001347 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham5a988412012-06-08 21:56:10 +00001348
1349 switch (short_option)
1350 {
1351 case 'b':
1352 m_level = lldb::eDescriptionLevelBrief;
1353 break;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001354 case 'D':
1355 m_use_dummy = true;
1356 break;
Jim Ingham5a988412012-06-08 21:56:10 +00001357 case 'f':
1358 m_level = lldb::eDescriptionLevelFull;
1359 break;
1360 case 'v':
1361 m_level = lldb::eDescriptionLevelVerbose;
1362 break;
1363 case 'i':
1364 m_internal = true;
1365 break;
1366 default:
1367 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1368 break;
1369 }
1370
1371 return error;
1372 }
1373
1374 void
1375 OptionParsingStarting ()
1376 {
1377 m_level = lldb::eDescriptionLevelFull;
1378 m_internal = false;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001379 m_use_dummy = false;
Jim Ingham5a988412012-06-08 21:56:10 +00001380 }
1381
1382 const OptionDefinition *
1383 GetDefinitions ()
1384 {
1385 return g_option_table;
1386 }
1387
1388 // Options table: Required for subclasses of Options.
1389
1390 static OptionDefinition g_option_table[];
1391
1392 // Instance variables to hold the values for command options.
1393
1394 lldb::DescriptionLevel m_level;
1395
1396 bool m_internal;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001397 bool m_use_dummy;
Jim Ingham5a988412012-06-08 21:56:10 +00001398 };
1399
1400protected:
1401 virtual bool
1402 DoExecute (Args& command, CommandReturnObject &result)
1403 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001404 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
1405
Jim Ingham5a988412012-06-08 21:56:10 +00001406 if (target == NULL)
1407 {
1408 result.AppendError ("Invalid target. No current target or breakpoints.");
1409 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1410 return true;
1411 }
1412
1413 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
1414 Mutex::Locker locker;
1415 target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
1416
1417 size_t num_breakpoints = breakpoints.GetSize();
1418
1419 if (num_breakpoints == 0)
1420 {
1421 result.AppendMessage ("No breakpoints currently set.");
1422 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1423 return true;
1424 }
1425
Jim Ingham85e8b812011-02-19 02:53:09 +00001426 Stream &output_stream = result.GetOutputStream();
Jim Ingham5a988412012-06-08 21:56:10 +00001427
1428 if (command.GetArgumentCount() == 0)
1429 {
1430 // No breakpoint selected; show info about all currently set breakpoints.
1431 result.AppendMessage ("Current breakpoints:");
1432 for (size_t i = 0; i < num_breakpoints; ++i)
1433 {
1434 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
1435 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
1436 }
1437 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1438 }
1439 else
1440 {
1441 // Particular breakpoints selected; show info about that breakpoint.
1442 BreakpointIDList valid_bp_ids;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001443 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +00001444
1445 if (result.Succeeded())
1446 {
1447 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
1448 {
1449 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1450 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1451 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
1452 }
1453 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1454 }
1455 else
1456 {
1457 result.AppendError ("Invalid breakpoint id.");
1458 result.SetStatus (eReturnStatusFailed);
1459 }
1460 }
1461
1462 return result.Succeeded();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001463 }
1464
Jim Ingham5a988412012-06-08 21:56:10 +00001465private:
1466 CommandOptions m_options;
1467};
1468
1469#pragma mark List::CommandOptions
1470OptionDefinition
1471CommandObjectBreakpointList::CommandOptions::g_option_table[] =
1472{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001473 { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
Jim Ingham5a988412012-06-08 21:56:10 +00001474 "Show debugger internal breakpoints" },
1475
Zachary Turnerd37221d2014-07-09 16:31:49 +00001476 { LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
Jim Ingham5a988412012-06-08 21:56:10 +00001477 "Give a brief description of the breakpoint (no location info)."},
1478
1479 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
1480 // But I need to see it for now, and don't want to wait.
Zachary Turnerd37221d2014-07-09 16:31:49 +00001481 { LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
Jim Ingham5a988412012-06-08 21:56:10 +00001482 "Give a full description of the breakpoint and its locations."},
1483
Zachary Turnerd37221d2014-07-09 16:31:49 +00001484 { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
Jim Ingham5a988412012-06-08 21:56:10 +00001485 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
1486
Jim Ingham33df7cd2014-12-06 01:28:03 +00001487 { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1488 "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
1489
Zachary Turnerd37221d2014-07-09 16:31:49 +00001490 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Jim Ingham5a988412012-06-08 21:56:10 +00001491};
1492
1493//-------------------------------------------------------------------------
1494// CommandObjectBreakpointClear
1495//-------------------------------------------------------------------------
1496#pragma mark Clear
1497
1498class CommandObjectBreakpointClear : public CommandObjectParsed
1499{
1500public:
1501
1502 typedef enum BreakpointClearType
1503 {
1504 eClearTypeInvalid,
1505 eClearTypeFileAndLine
1506 } BreakpointClearType;
1507
1508 CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
1509 CommandObjectParsed (interpreter,
1510 "breakpoint clear",
1511 "Clears a breakpoint or set of breakpoints in the executable.",
1512 "breakpoint clear <cmd-options>"),
1513 m_options (interpreter)
1514 {
1515 }
1516
1517 virtual
1518 ~CommandObjectBreakpointClear () {}
1519
1520 virtual Options *
1521 GetOptions ()
1522 {
1523 return &m_options;
1524 }
1525
1526 class CommandOptions : public Options
1527 {
1528 public:
1529
1530 CommandOptions (CommandInterpreter &interpreter) :
1531 Options (interpreter),
1532 m_filename (),
1533 m_line_num (0)
1534 {
1535 }
1536
1537 virtual
1538 ~CommandOptions () {}
1539
1540 virtual Error
1541 SetOptionValue (uint32_t option_idx, const char *option_arg)
1542 {
1543 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00001544 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham5a988412012-06-08 21:56:10 +00001545
1546 switch (short_option)
1547 {
1548 case 'f':
1549 m_filename.assign (option_arg);
1550 break;
1551
1552 case 'l':
1553 m_line_num = Args::StringToUInt32 (option_arg, 0);
1554 break;
1555
1556 default:
1557 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1558 break;
1559 }
1560
1561 return error;
1562 }
1563
1564 void
1565 OptionParsingStarting ()
1566 {
1567 m_filename.clear();
1568 m_line_num = 0;
1569 }
1570
1571 const OptionDefinition*
1572 GetDefinitions ()
1573 {
1574 return g_option_table;
1575 }
1576
1577 // Options table: Required for subclasses of Options.
1578
1579 static OptionDefinition g_option_table[];
1580
1581 // Instance variables to hold the values for command options.
1582
1583 std::string m_filename;
1584 uint32_t m_line_num;
1585
1586 };
1587
1588protected:
1589 virtual bool
1590 DoExecute (Args& command, CommandReturnObject &result)
1591 {
Jim Ingham893c9322014-11-22 01:42:44 +00001592 Target *target = GetSelectedOrDummyTarget();
Jim Ingham5a988412012-06-08 21:56:10 +00001593 if (target == NULL)
1594 {
1595 result.AppendError ("Invalid target. No existing target or breakpoints.");
1596 result.SetStatus (eReturnStatusFailed);
1597 return false;
1598 }
1599
1600 // The following are the various types of breakpoints that could be cleared:
1601 // 1). -f -l (clearing breakpoint by source location)
1602
1603 BreakpointClearType break_type = eClearTypeInvalid;
1604
1605 if (m_options.m_line_num != 0)
1606 break_type = eClearTypeFileAndLine;
1607
1608 Mutex::Locker locker;
1609 target->GetBreakpointList().GetListMutex(locker);
1610
1611 BreakpointList &breakpoints = target->GetBreakpointList();
1612 size_t num_breakpoints = breakpoints.GetSize();
1613
1614 // Early return if there's no breakpoint at all.
1615 if (num_breakpoints == 0)
1616 {
1617 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1618 result.SetStatus (eReturnStatusFailed);
1619 return result.Succeeded();
1620 }
1621
1622 // Find matching breakpoints and delete them.
1623
1624 // First create a copy of all the IDs.
1625 std::vector<break_id_t> BreakIDs;
1626 for (size_t i = 0; i < num_breakpoints; ++i)
1627 BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID());
1628
1629 int num_cleared = 0;
1630 StreamString ss;
1631 switch (break_type)
1632 {
1633 case eClearTypeFileAndLine: // Breakpoint by source position
1634 {
1635 const ConstString filename(m_options.m_filename.c_str());
1636 BreakpointLocationCollection loc_coll;
1637
1638 for (size_t i = 0; i < num_breakpoints; ++i)
1639 {
1640 Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
1641
1642 if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
1643 {
1644 // If the collection size is 0, it's a full match and we can just remove the breakpoint.
1645 if (loc_coll.GetSize() == 0)
1646 {
1647 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
1648 ss.EOL();
1649 target->RemoveBreakpointByID (bp->GetID());
1650 ++num_cleared;
1651 }
1652 }
1653 }
1654 }
1655 break;
1656
1657 default:
1658 break;
1659 }
1660
1661 if (num_cleared > 0)
1662 {
1663 Stream &output_stream = result.GetOutputStream();
1664 output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
1665 output_stream << ss.GetData();
1666 output_stream.EOL();
1667 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1668 }
1669 else
1670 {
1671 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1672 result.SetStatus (eReturnStatusFailed);
1673 }
1674
1675 return result.Succeeded();
1676 }
1677
1678private:
1679 CommandOptions m_options;
1680};
1681
1682#pragma mark Clear::CommandOptions
1683
1684OptionDefinition
1685CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
1686{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001687 { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
Jim Ingham5a988412012-06-08 21:56:10 +00001688 "Specify the breakpoint by source location in this particular file."},
1689
Zachary Turnerd37221d2014-07-09 16:31:49 +00001690 { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLineNum,
Jim Ingham5a988412012-06-08 21:56:10 +00001691 "Specify the breakpoint by source location at this particular line."},
1692
Zachary Turnerd37221d2014-07-09 16:31:49 +00001693 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Jim Ingham5a988412012-06-08 21:56:10 +00001694};
1695
1696//-------------------------------------------------------------------------
1697// CommandObjectBreakpointDelete
1698//-------------------------------------------------------------------------
1699#pragma mark Delete
1700
1701class CommandObjectBreakpointDelete : public CommandObjectParsed
1702{
1703public:
1704 CommandObjectBreakpointDelete (CommandInterpreter &interpreter) :
1705 CommandObjectParsed (interpreter,
1706 "breakpoint delete",
1707 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
Jim Ingham33df7cd2014-12-06 01:28:03 +00001708 NULL),
1709 m_options (interpreter)
Jim Ingham5a988412012-06-08 21:56:10 +00001710 {
1711 CommandArgumentEntry arg;
1712 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1713 // Add the entry for the first argument for this command to the object's arguments vector.
1714 m_arguments.push_back (arg);
1715 }
1716
1717 virtual
1718 ~CommandObjectBreakpointDelete () {}
1719
Jim Ingham33df7cd2014-12-06 01:28:03 +00001720 virtual Options *
1721 GetOptions ()
1722 {
1723 return &m_options;
1724 }
1725
1726 class CommandOptions : public Options
1727 {
1728 public:
1729
1730 CommandOptions (CommandInterpreter &interpreter) :
1731 Options (interpreter),
1732 m_use_dummy (false),
1733 m_force (false)
1734 {
1735 }
1736
1737 virtual
1738 ~CommandOptions () {}
1739
1740 virtual Error
1741 SetOptionValue (uint32_t option_idx, const char *option_arg)
1742 {
1743 Error error;
1744 const int short_option = m_getopt_table[option_idx].val;
1745
1746 switch (short_option)
1747 {
1748 case 'f':
1749 m_force = true;
1750 break;
1751
1752 case 'D':
1753 m_use_dummy = true;
1754 break;
1755
1756 default:
1757 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1758 break;
1759 }
1760
1761 return error;
1762 }
1763
1764 void
1765 OptionParsingStarting ()
1766 {
1767 m_use_dummy = false;
1768 m_force = false;
1769 }
1770
1771 const OptionDefinition*
1772 GetDefinitions ()
1773 {
1774 return g_option_table;
1775 }
1776
1777 // Options table: Required for subclasses of Options.
1778
1779 static OptionDefinition g_option_table[];
1780
1781 // Instance variables to hold the values for command options.
1782 bool m_use_dummy;
1783 bool m_force;
1784 };
1785
Jim Ingham5a988412012-06-08 21:56:10 +00001786protected:
1787 virtual bool
1788 DoExecute (Args& command, CommandReturnObject &result)
1789 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001790 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
1791
Jim Ingham5a988412012-06-08 21:56:10 +00001792 if (target == NULL)
1793 {
1794 result.AppendError ("Invalid target. No existing target or breakpoints.");
1795 result.SetStatus (eReturnStatusFailed);
1796 return false;
1797 }
1798
1799 Mutex::Locker locker;
1800 target->GetBreakpointList().GetListMutex(locker);
1801
1802 const BreakpointList &breakpoints = target->GetBreakpointList();
1803
1804 size_t num_breakpoints = breakpoints.GetSize();
1805
1806 if (num_breakpoints == 0)
1807 {
1808 result.AppendError ("No breakpoints exist to be deleted.");
1809 result.SetStatus (eReturnStatusFailed);
1810 return false;
1811 }
1812
1813 if (command.GetArgumentCount() == 0)
1814 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001815 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 +00001816 {
1817 result.AppendMessage("Operation cancelled...");
1818 }
1819 else
1820 {
1821 target->RemoveAllBreakpoints ();
Greg Clayton6fea17e2014-03-03 19:15:20 +00001822 result.AppendMessageWithFormat ("All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : "");
Jim Ingham5a988412012-06-08 21:56:10 +00001823 }
1824 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1825 }
1826 else
1827 {
1828 // Particular breakpoint selected; disable that breakpoint.
1829 BreakpointIDList valid_bp_ids;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001830 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +00001831
1832 if (result.Succeeded())
1833 {
1834 int delete_count = 0;
1835 int disable_count = 0;
1836 const size_t count = valid_bp_ids.GetSize();
1837 for (size_t i = 0; i < count; ++i)
1838 {
1839 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1840
1841 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1842 {
1843 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1844 {
1845 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1846 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1847 // It makes no sense to try to delete individual locations, so we disable them instead.
1848 if (location)
1849 {
1850 location->SetEnabled (false);
1851 ++disable_count;
1852 }
1853 }
1854 else
1855 {
1856 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1857 ++delete_count;
1858 }
1859 }
1860 }
1861 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1862 delete_count, disable_count);
1863 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1864 }
1865 }
1866 return result.Succeeded();
1867 }
Jim Ingham33df7cd2014-12-06 01:28:03 +00001868private:
1869 CommandOptions m_options;
1870};
1871
1872OptionDefinition
1873CommandObjectBreakpointDelete::CommandOptions::g_option_table[] =
1874{
1875 { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1876 "Delete all breakpoints without querying for confirmation."},
1877
1878 { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1879 "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
1880
1881 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Jim Ingham5a988412012-06-08 21:56:10 +00001882};
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001883
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001884//-------------------------------------------------------------------------
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001885// CommandObjectBreakpointName
1886//-------------------------------------------------------------------------
1887
1888static OptionDefinition
1889g_breakpoint_name_options[] =
1890{
1891 { LLDB_OPT_SET_1, false, "name", 'N', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointName, "Specifies a breakpoint name to use."},
1892 { LLDB_OPT_SET_2, false, "breakpoint-id", 'B', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBreakpointID, "Specify a breakpoint id to use."},
1893 { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,
1894 "Operate on Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
1895};
1896class BreakpointNameOptionGroup : public OptionGroup
1897{
1898public:
1899 BreakpointNameOptionGroup() :
1900 OptionGroup(),
1901 m_breakpoint(LLDB_INVALID_BREAK_ID),
1902 m_use_dummy (false)
1903 {
1904
1905 }
1906
1907 virtual
1908 ~BreakpointNameOptionGroup ()
1909 {
1910 }
1911
1912 virtual uint32_t
1913 GetNumDefinitions ()
1914 {
1915 return sizeof (g_breakpoint_name_options) / sizeof (OptionDefinition);
1916 }
1917
1918 virtual const OptionDefinition*
1919 GetDefinitions ()
1920 {
1921 return g_breakpoint_name_options;
1922 }
1923
1924 virtual Error
1925 SetOptionValue (CommandInterpreter &interpreter,
1926 uint32_t option_idx,
1927 const char *option_value)
1928 {
1929 Error error;
1930 const int short_option = g_breakpoint_name_options[option_idx].short_option;
1931
1932 switch (short_option)
1933 {
1934 case 'N':
1935 if (BreakpointID::StringIsBreakpointName(option_value, error) && error.Success())
1936 m_name.SetValueFromCString(option_value);
1937 break;
1938
1939 case 'B':
1940 if (m_breakpoint.SetValueFromCString(option_value).Fail())
1941 error.SetErrorStringWithFormat ("unrecognized value \"%s\" for breakpoint", option_value);
1942 break;
1943 case 'D':
1944 if (m_use_dummy.SetValueFromCString(option_value).Fail())
1945 error.SetErrorStringWithFormat ("unrecognized value \"%s\" for use-dummy", option_value);
1946 break;
1947
1948 default:
1949 error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
1950 break;
1951 }
1952 return error;
1953 }
1954
1955 virtual void
1956 OptionParsingStarting (CommandInterpreter &interpreter)
1957 {
1958 m_name.Clear();
1959 m_breakpoint.Clear();
1960 m_use_dummy.Clear();
1961 m_use_dummy.SetDefaultValue(false);
1962 }
1963
1964 OptionValueString m_name;
1965 OptionValueUInt64 m_breakpoint;
1966 OptionValueBoolean m_use_dummy;
1967};
1968
1969
1970class CommandObjectBreakpointNameAdd : public CommandObjectParsed
1971{
1972public:
1973 CommandObjectBreakpointNameAdd (CommandInterpreter &interpreter) :
1974 CommandObjectParsed (interpreter,
1975 "add",
1976 "Add a name to the breakpoints provided.",
1977 "breakpoint name add <command-options> <breakpoint-id-list>"),
1978 m_name_options(),
1979 m_option_group(interpreter)
1980 {
1981 // Create the first variant for the first (and only) argument for this command.
1982 CommandArgumentEntry arg1;
1983 CommandArgumentData id_arg;
1984 id_arg.arg_type = eArgTypeBreakpointID;
1985 id_arg.arg_repetition = eArgRepeatOptional;
1986 arg1.push_back(id_arg);
1987 m_arguments.push_back (arg1);
1988
1989 m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
1990 m_option_group.Finalize();
1991 }
1992
1993 virtual
1994 ~CommandObjectBreakpointNameAdd () {}
1995
1996 Options *
1997 GetOptions ()
1998 {
1999 return &m_option_group;
2000 }
2001
2002protected:
2003 virtual bool
2004 DoExecute (Args& command, CommandReturnObject &result)
2005 {
2006 if (!m_name_options.m_name.OptionWasSet())
2007 {
2008 result.SetError("No name option provided.");
2009 return false;
2010 }
2011
2012 Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
2013
2014 if (target == NULL)
2015 {
2016 result.AppendError ("Invalid target. No existing target or breakpoints.");
2017 result.SetStatus (eReturnStatusFailed);
2018 return false;
2019 }
2020
2021 Mutex::Locker locker;
2022 target->GetBreakpointList().GetListMutex(locker);
2023
2024 const BreakpointList &breakpoints = target->GetBreakpointList();
2025
2026 size_t num_breakpoints = breakpoints.GetSize();
2027 if (num_breakpoints == 0)
2028 {
2029 result.SetError("No breakpoints, cannot add names.");
2030 result.SetStatus (eReturnStatusFailed);
2031 return false;
2032 }
2033
2034 // Particular breakpoint selected; disable that breakpoint.
2035 BreakpointIDList valid_bp_ids;
2036 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
2037
2038 if (result.Succeeded())
2039 {
2040 if (valid_bp_ids.GetSize() == 0)
2041 {
2042 result.SetError("No breakpoints specified, cannot add names.");
2043 result.SetStatus (eReturnStatusFailed);
2044 return false;
2045 }
2046 size_t num_valid_ids = valid_bp_ids.GetSize();
2047 for (size_t index = 0; index < num_valid_ids; index++)
2048 {
2049 lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
2050 BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
2051 Error error; // We don't need to check the error here, since the option parser checked it...
2052 bp_sp->AddName(m_name_options.m_name.GetCurrentValue(), error);
2053 }
2054 }
2055
2056 return true;
2057 }
2058
2059private:
2060 BreakpointNameOptionGroup m_name_options;
2061 OptionGroupOptions m_option_group;
2062};
2063
2064
2065
2066class CommandObjectBreakpointNameDelete : public CommandObjectParsed
2067{
2068public:
2069 CommandObjectBreakpointNameDelete (CommandInterpreter &interpreter) :
2070 CommandObjectParsed (interpreter,
2071 "delete",
2072 "Delete a name from the breakpoints provided.",
2073 "breakpoint name delete <command-options> <breakpoint-id-list>"),
2074 m_name_options(),
2075 m_option_group(interpreter)
2076 {
2077 // Create the first variant for the first (and only) argument for this command.
2078 CommandArgumentEntry arg1;
2079 CommandArgumentData id_arg;
2080 id_arg.arg_type = eArgTypeBreakpointID;
2081 id_arg.arg_repetition = eArgRepeatOptional;
2082 arg1.push_back(id_arg);
2083 m_arguments.push_back (arg1);
2084
2085 m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
2086 m_option_group.Finalize();
2087 }
2088
2089 virtual
2090 ~CommandObjectBreakpointNameDelete () {}
2091
2092 Options *
2093 GetOptions ()
2094 {
2095 return &m_option_group;
2096 }
2097
2098protected:
2099 virtual bool
2100 DoExecute (Args& command, CommandReturnObject &result)
2101 {
2102 if (!m_name_options.m_name.OptionWasSet())
2103 {
2104 result.SetError("No name option provided.");
2105 return false;
2106 }
2107
2108 Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
2109
2110 if (target == NULL)
2111 {
2112 result.AppendError ("Invalid target. No existing target or breakpoints.");
2113 result.SetStatus (eReturnStatusFailed);
2114 return false;
2115 }
2116
2117 Mutex::Locker locker;
2118 target->GetBreakpointList().GetListMutex(locker);
2119
2120 const BreakpointList &breakpoints = target->GetBreakpointList();
2121
2122 size_t num_breakpoints = breakpoints.GetSize();
2123 if (num_breakpoints == 0)
2124 {
2125 result.SetError("No breakpoints, cannot delete names.");
2126 result.SetStatus (eReturnStatusFailed);
2127 return false;
2128 }
2129
2130 // Particular breakpoint selected; disable that breakpoint.
2131 BreakpointIDList valid_bp_ids;
2132 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
2133
2134 if (result.Succeeded())
2135 {
2136 if (valid_bp_ids.GetSize() == 0)
2137 {
2138 result.SetError("No breakpoints specified, cannot delete names.");
2139 result.SetStatus (eReturnStatusFailed);
2140 return false;
2141 }
2142 size_t num_valid_ids = valid_bp_ids.GetSize();
2143 for (size_t index = 0; index < num_valid_ids; index++)
2144 {
2145 lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
2146 BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
2147 bp_sp->RemoveName(m_name_options.m_name.GetCurrentValue());
2148 }
2149 }
2150
2151 return true;
2152 }
2153
2154private:
2155 BreakpointNameOptionGroup m_name_options;
2156 OptionGroupOptions m_option_group;
2157};
2158
2159class CommandObjectBreakpointNameList : public CommandObjectParsed
2160{
2161public:
2162 CommandObjectBreakpointNameList (CommandInterpreter &interpreter) :
2163 CommandObjectParsed (interpreter,
2164 "list",
2165 "List either the names for a breakpoint or the breakpoints for a given name.",
2166 "breakpoint name list <command-options>"),
2167 m_name_options(),
2168 m_option_group(interpreter)
2169 {
2170 m_option_group.Append (&m_name_options);
2171 m_option_group.Finalize();
2172 }
2173
2174 virtual
2175 ~CommandObjectBreakpointNameList () {}
2176
2177 Options *
2178 GetOptions ()
2179 {
2180 return &m_option_group;
2181 }
2182
2183protected:
2184protected:
2185 virtual bool
2186 DoExecute (Args& command, CommandReturnObject &result)
2187 {
2188 Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
2189
2190 if (target == NULL)
2191 {
2192 result.AppendError ("Invalid target. No existing target or breakpoints.");
2193 result.SetStatus (eReturnStatusFailed);
2194 return false;
2195 }
2196
2197 if (m_name_options.m_name.OptionWasSet())
2198 {
2199 const char *name = m_name_options.m_name.GetCurrentValue();
2200 Mutex::Locker locker;
2201 target->GetBreakpointList().GetListMutex(locker);
2202
2203 BreakpointList &breakpoints = target->GetBreakpointList();
2204 for (BreakpointSP bp_sp : breakpoints.Breakpoints())
2205 {
2206 if (bp_sp->MatchesName(name))
2207 {
2208 StreamString s;
2209 bp_sp->GetDescription(&s, eDescriptionLevelBrief);
2210 s.EOL();
2211 result.AppendMessage(s.GetData());
2212 }
2213 }
2214
2215 }
2216 else if (m_name_options.m_breakpoint.OptionWasSet())
2217 {
2218 BreakpointSP bp_sp = target->GetBreakpointList().FindBreakpointByID(m_name_options.m_breakpoint.GetCurrentValue());
2219 if (bp_sp)
2220 {
2221 std::vector<std::string> names;
2222 bp_sp->GetNames (names);
2223 result.AppendMessage ("Names:");
2224 for (auto name : names)
2225 result.AppendMessageWithFormat (" %s\n", name.c_str());
2226 }
2227 else
2228 {
2229 result.AppendErrorWithFormat ("Could not find breakpoint %" PRId64 ".\n",
2230 m_name_options.m_breakpoint.GetCurrentValue());
2231 result.SetStatus (eReturnStatusFailed);
2232 return false;
2233 }
2234 }
2235 else
2236 {
2237 result.SetError ("Must specify -N or -B option to list.");
2238 result.SetStatus (eReturnStatusFailed);
2239 return false;
2240 }
2241 return true;
2242 }
2243
2244private:
2245 BreakpointNameOptionGroup m_name_options;
2246 OptionGroupOptions m_option_group;
2247};
2248
2249//-------------------------------------------------------------------------
2250// CommandObjectMultiwordBreakpoint
2251//-------------------------------------------------------------------------
2252class CommandObjectBreakpointName : public CommandObjectMultiword
2253{
2254public:
2255 CommandObjectBreakpointName (CommandInterpreter &interpreter) :
2256 CommandObjectMultiword(interpreter,
2257 "name",
2258 "A set of commands to manage name tags for breakpoints",
2259 "breakpoint name <command> [<command-options>]")
2260 {
2261 CommandObjectSP add_command_object (new CommandObjectBreakpointNameAdd (interpreter));
2262 CommandObjectSP delete_command_object (new CommandObjectBreakpointNameDelete (interpreter));
2263 CommandObjectSP list_command_object (new CommandObjectBreakpointNameList (interpreter));
2264
2265 LoadSubCommand ("add", add_command_object);
2266 LoadSubCommand ("delete", delete_command_object);
2267 LoadSubCommand ("list", list_command_object);
2268
2269 }
2270
2271 virtual
2272 ~CommandObjectBreakpointName ()
2273 {
2274 }
2275
2276};
2277
2278
2279//-------------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002280// CommandObjectMultiwordBreakpoint
2281//-------------------------------------------------------------------------
Jim Inghamae1c4cf2010-06-18 00:58:52 +00002282#pragma mark MultiwordBreakpoint
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002283
Greg Clayton66111032010-06-23 01:19:29 +00002284CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
Greg Claytona7015092010-09-18 01:14:36 +00002285 CommandObjectMultiword (interpreter,
2286 "breakpoint",
Jim Ingham46fbc602011-05-26 20:39:01 +00002287 "A set of commands for operating on breakpoints. Also see _regexp-break.",
Greg Claytona7015092010-09-18 01:14:36 +00002288 "breakpoint <command> [<command-options>]")
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002289{
Greg Claytona7015092010-09-18 01:14:36 +00002290 CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
Greg Claytona7015092010-09-18 01:14:36 +00002291 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
2292 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
Johnny Chenb7234e42010-10-28 17:27:46 +00002293 CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
2294 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
Greg Claytona7015092010-09-18 01:14:36 +00002295 CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002296 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
Greg Claytona7015092010-09-18 01:14:36 +00002297 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002298 CommandObjectSP name_command_object (new CommandObjectBreakpointName(interpreter));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002299
Johnny Chenb7234e42010-10-28 17:27:46 +00002300 list_command_object->SetCommandName ("breakpoint list");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002301 enable_command_object->SetCommandName("breakpoint enable");
2302 disable_command_object->SetCommandName("breakpoint disable");
Johnny Chenb7234e42010-10-28 17:27:46 +00002303 clear_command_object->SetCommandName("breakpoint clear");
2304 delete_command_object->SetCommandName("breakpoint delete");
Jim Inghamae1c4cf2010-06-18 00:58:52 +00002305 set_command_object->SetCommandName("breakpoint set");
Johnny Chenb7234e42010-10-28 17:27:46 +00002306 command_command_object->SetCommandName ("breakpoint command");
2307 modify_command_object->SetCommandName ("breakpoint modify");
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002308 name_command_object->SetCommandName ("breakpoint name");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002309
Greg Clayton23f59502012-07-17 03:23:13 +00002310 LoadSubCommand ("list", list_command_object);
2311 LoadSubCommand ("enable", enable_command_object);
2312 LoadSubCommand ("disable", disable_command_object);
2313 LoadSubCommand ("clear", clear_command_object);
2314 LoadSubCommand ("delete", delete_command_object);
2315 LoadSubCommand ("set", set_command_object);
2316 LoadSubCommand ("command", command_command_object);
2317 LoadSubCommand ("modify", modify_command_object);
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002318 LoadSubCommand ("name", name_command_object);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002319}
2320
2321CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
2322{
2323}
2324
2325void
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002326CommandObjectMultiwordBreakpoint::VerifyIDs (Args &args,
2327 Target *target,
2328 bool allow_locations,
2329 CommandReturnObject &result,
2330 BreakpointIDList *valid_ids)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002331{
2332 // args can be strings representing 1). integers (for breakpoint ids)
2333 // 2). the full breakpoint & location canonical representation
2334 // 3). the word "to" or a hyphen, representing a range (in which case there
2335 // had *better* be an entry both before & after of one of the first two types.
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002336 // 4). A breakpoint name
Jim Ingham36f3b362010-10-14 23:45:03 +00002337 // If args is empty, we will use the last created breakpoint (if there is one.)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002338
2339 Args temp_args;
2340
Jim Ingham36f3b362010-10-14 23:45:03 +00002341 if (args.GetArgumentCount() == 0)
2342 {
Greg Clayton4d122c42011-09-17 08:33:22 +00002343 if (target->GetLastCreatedBreakpoint())
Jim Ingham36f3b362010-10-14 23:45:03 +00002344 {
2345 valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
2346 result.SetStatus (eReturnStatusSuccessFinishNoResult);
2347 }
2348 else
2349 {
2350 result.AppendError("No breakpoint specified and no last created breakpoint.");
2351 result.SetStatus (eReturnStatusFailed);
2352 }
2353 return;
2354 }
2355
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002356 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
2357 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
2358 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
2359
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002360 BreakpointIDList::FindAndReplaceIDRanges (args, target, allow_locations, result, temp_args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002361
2362 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
2363
Greg Claytonc982c762010-07-09 20:39:50 +00002364 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002365
2366 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
2367 // and put into valid_ids.
2368
2369 if (result.Succeeded())
2370 {
2371 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
2372 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
2373
Greg Claytonc982c762010-07-09 20:39:50 +00002374 const size_t count = valid_ids->GetSize();
2375 for (size_t i = 0; i < count; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002376 {
2377 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
2378 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
2379 if (breakpoint != NULL)
2380 {
Greg Claytonc7bece562013-01-25 18:06:21 +00002381 const size_t num_locations = breakpoint->GetNumLocations();
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +00002382 if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002383 {
2384 StreamString id_str;
Greg Claytonc982c762010-07-09 20:39:50 +00002385 BreakpointID::GetCanonicalReference (&id_str,
2386 cur_bp_id.GetBreakpointID(),
2387 cur_bp_id.GetLocationID());
2388 i = valid_ids->GetSize() + 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002389 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
2390 id_str.GetData());
2391 result.SetStatus (eReturnStatusFailed);
2392 }
2393 }
2394 else
2395 {
Greg Claytonc982c762010-07-09 20:39:50 +00002396 i = valid_ids->GetSize() + 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002397 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
2398 result.SetStatus (eReturnStatusFailed);
2399 }
2400 }
2401 }
2402}