blob: ca0c52a9bf03f1d98b86ae646ec556c6b5383ea9 [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"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Core/RegularExpression.h"
24#include "lldb/Core/StreamString.h"
25#include "lldb/Interpreter/CommandInterpreter.h"
26#include "lldb/Interpreter/CommandReturnObject.h"
27#include "lldb/Target/Target.h"
28#include "lldb/Interpreter/CommandCompletions.h"
29#include "lldb/Target/StackFrame.h"
Jim Ingham1b54c882010-06-16 02:00:15 +000030#include "lldb/Target/Thread.h"
31#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Johnny Chenb7234e42010-10-28 17:27:46 +000033#include <vector>
34
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035using namespace lldb;
36using namespace lldb_private;
37
38static void
Jim Ingham85e8b812011-02-19 02:53:09 +000039AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040{
41 s->IndentMore();
42 bp->GetDescription (s, level, true);
43 s->IndentLess();
44 s->EOL();
45}
46
47//-------------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +000048// CommandObjectBreakpointSet
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049//-------------------------------------------------------------------------
50
Jim Ingham5a988412012-06-08 21:56:10 +000051
52class CommandObjectBreakpointSet : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053{
Jim Ingham5a988412012-06-08 21:56:10 +000054public:
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055
Jim Ingham5a988412012-06-08 21:56:10 +000056 typedef enum BreakpointSetType
57 {
58 eSetTypeInvalid,
59 eSetTypeFileAndLine,
60 eSetTypeAddress,
61 eSetTypeFunctionName,
62 eSetTypeFunctionRegexp,
63 eSetTypeSourceRegexp,
64 eSetTypeException
65 } BreakpointSetType;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
Jim Ingham5a988412012-06-08 21:56:10 +000067 CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
68 CommandObjectParsed (interpreter,
69 "breakpoint set",
70 "Sets a breakpoint or set of breakpoints in the executable.",
71 "breakpoint set <cmd-options>"),
72 m_options (interpreter)
73 {
74 }
75
76
77 virtual
78 ~CommandObjectBreakpointSet () {}
79
80 virtual Options *
81 GetOptions ()
82 {
83 return &m_options;
84 }
85
86 class CommandOptions : public Options
87 {
88 public:
89
90 CommandOptions (CommandInterpreter &interpreter) :
91 Options (interpreter),
92 m_condition (),
93 m_filenames (),
94 m_line_num (0),
95 m_column (0),
Jim Ingham5a988412012-06-08 21:56:10 +000096 m_func_names (),
97 m_func_name_type_mask (eFunctionNameTypeNone),
98 m_func_regexp (),
99 m_source_text_regexp(),
100 m_modules (),
101 m_load_addr(),
102 m_ignore_count (0),
103 m_thread_id(LLDB_INVALID_THREAD_ID),
104 m_thread_index (UINT32_MAX),
105 m_thread_name(),
106 m_queue_name(),
107 m_catch_bp (false),
Greg Clayton1f746072012-08-29 21:13:06 +0000108 m_throw_bp (true),
Jim Ingham5a988412012-06-08 21:56:10 +0000109 m_language (eLanguageTypeUnknown),
Jim Inghamca36cd12012-10-05 19:16:31 +0000110 m_skip_prologue (eLazyBoolCalculate),
111 m_one_shot (false)
Jim Ingham5a988412012-06-08 21:56:10 +0000112 {
113 }
114
115
116 virtual
117 ~CommandOptions () {}
118
119 virtual Error
120 SetOptionValue (uint32_t option_idx, const char *option_arg)
121 {
122 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000123 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham5a988412012-06-08 21:56:10 +0000124
125 switch (short_option)
126 {
127 case 'a':
Greg Claytonb9d5df52012-12-06 22:49:16 +0000128 {
129 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
130 m_load_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
131 }
Jim Ingham5a988412012-06-08 21:56:10 +0000132 break;
133
Jim Inghamca36cd12012-10-05 19:16:31 +0000134 case 'b':
135 m_func_names.push_back (option_arg);
136 m_func_name_type_mask |= eFunctionNameTypeBase;
137 break;
138
Jim Ingham5a988412012-06-08 21:56:10 +0000139 case 'C':
140 m_column = Args::StringToUInt32 (option_arg, 0);
141 break;
142
143 case 'c':
144 m_condition.assign(option_arg);
145 break;
146
Jim Ingham5a988412012-06-08 21:56:10 +0000147 case 'E':
148 {
149 LanguageType language = LanguageRuntime::GetLanguageTypeFromString (option_arg);
150
151 switch (language)
152 {
153 case eLanguageTypeC89:
154 case eLanguageTypeC:
155 case eLanguageTypeC99:
156 m_language = eLanguageTypeC;
157 break;
158 case eLanguageTypeC_plus_plus:
159 m_language = eLanguageTypeC_plus_plus;
160 break;
161 case eLanguageTypeObjC:
162 m_language = eLanguageTypeObjC;
163 break;
164 case eLanguageTypeObjC_plus_plus:
165 error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c");
166 break;
167 case eLanguageTypeUnknown:
168 error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg);
169 break;
170 default:
171 error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg);
172 }
173 }
174 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000175
176 case 'f':
177 m_filenames.AppendIfUnique (FileSpec(option_arg, false));
178 break;
179
180 case 'F':
181 m_func_names.push_back (option_arg);
182 m_func_name_type_mask |= eFunctionNameTypeFull;
183 break;
184
Jim Ingham5a988412012-06-08 21:56:10 +0000185 case 'h':
186 {
187 bool success;
188 m_catch_bp = Args::StringToBoolean (option_arg, true, &success);
189 if (!success)
190 error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg);
191 }
Jim Inghamca36cd12012-10-05 19:16:31 +0000192
193 case 'i':
194 {
195 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
196 if (m_ignore_count == UINT32_MAX)
197 error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
198 break;
199 }
200
Jim Ingham5a988412012-06-08 21:56:10 +0000201 case 'K':
202 {
203 bool success;
204 bool value;
205 value = Args::StringToBoolean (option_arg, true, &success);
206 if (value)
207 m_skip_prologue = eLazyBoolYes;
208 else
209 m_skip_prologue = eLazyBoolNo;
210
211 if (!success)
212 error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg);
213 }
214 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000215
216 case 'l':
217 m_line_num = Args::StringToUInt32 (option_arg, 0);
218 break;
219
220 case 'M':
221 m_func_names.push_back (option_arg);
222 m_func_name_type_mask |= eFunctionNameTypeMethod;
223 break;
224
225 case 'n':
226 m_func_names.push_back (option_arg);
227 m_func_name_type_mask |= eFunctionNameTypeAuto;
228 break;
229
230 case 'o':
231 m_one_shot = true;
232 break;
233
234 case 'p':
235 m_source_text_regexp.assign (option_arg);
236 break;
237
238 case 'q':
239 m_queue_name.assign (option_arg);
240 break;
241
242 case 'r':
243 m_func_regexp.assign (option_arg);
244 break;
245
246 case 's':
247 {
248 m_modules.AppendIfUnique (FileSpec (option_arg, false));
249 break;
250 }
251
252 case 'S':
253 m_func_names.push_back (option_arg);
254 m_func_name_type_mask |= eFunctionNameTypeSelector;
255 break;
256
257 case 't' :
258 {
259 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
260 if (m_thread_id == LLDB_INVALID_THREAD_ID)
261 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
262 }
263 break;
264
265 case 'T':
266 m_thread_name.assign (option_arg);
267 break;
268
269 case 'w':
270 {
271 bool success;
272 m_throw_bp = Args::StringToBoolean (option_arg, true, &success);
273 if (!success)
274 error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg);
275 }
276 break;
277
278 case 'x':
279 {
280 m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
281 if (m_thread_id == UINT32_MAX)
282 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
283
284 }
285 break;
286
Jim Ingham5a988412012-06-08 21:56:10 +0000287 default:
288 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
289 break;
290 }
291
292 return error;
293 }
294 void
295 OptionParsingStarting ()
296 {
297 m_condition.clear();
298 m_filenames.Clear();
299 m_line_num = 0;
300 m_column = 0;
301 m_func_names.clear();
Greg Clayton1f746072012-08-29 21:13:06 +0000302 m_func_name_type_mask = eFunctionNameTypeNone;
Jim Ingham5a988412012-06-08 21:56:10 +0000303 m_func_regexp.clear();
Greg Clayton1f746072012-08-29 21:13:06 +0000304 m_source_text_regexp.clear();
Jim Ingham5a988412012-06-08 21:56:10 +0000305 m_modules.Clear();
Greg Clayton1f746072012-08-29 21:13:06 +0000306 m_load_addr = LLDB_INVALID_ADDRESS;
Jim Ingham5a988412012-06-08 21:56:10 +0000307 m_ignore_count = 0;
308 m_thread_id = LLDB_INVALID_THREAD_ID;
309 m_thread_index = UINT32_MAX;
310 m_thread_name.clear();
311 m_queue_name.clear();
Jim Ingham5a988412012-06-08 21:56:10 +0000312 m_catch_bp = false;
313 m_throw_bp = true;
Greg Clayton1f746072012-08-29 21:13:06 +0000314 m_language = eLanguageTypeUnknown;
Jim Ingham5a988412012-06-08 21:56:10 +0000315 m_skip_prologue = eLazyBoolCalculate;
Jim Inghamca36cd12012-10-05 19:16:31 +0000316 m_one_shot = false;
Jim Ingham5a988412012-06-08 21:56:10 +0000317 }
318
319 const OptionDefinition*
320 GetDefinitions ()
321 {
322 return g_option_table;
323 }
324
325 // Options table: Required for subclasses of Options.
326
327 static OptionDefinition g_option_table[];
328
329 // Instance variables to hold the values for command options.
330
331 std::string m_condition;
332 FileSpecList m_filenames;
333 uint32_t m_line_num;
334 uint32_t m_column;
Jim Ingham5a988412012-06-08 21:56:10 +0000335 std::vector<std::string> m_func_names;
336 uint32_t m_func_name_type_mask;
337 std::string m_func_regexp;
338 std::string m_source_text_regexp;
339 FileSpecList m_modules;
340 lldb::addr_t m_load_addr;
341 uint32_t m_ignore_count;
342 lldb::tid_t m_thread_id;
343 uint32_t m_thread_index;
344 std::string m_thread_name;
345 std::string m_queue_name;
346 bool m_catch_bp;
347 bool m_throw_bp;
348 lldb::LanguageType m_language;
349 LazyBool m_skip_prologue;
Jim Inghamca36cd12012-10-05 19:16:31 +0000350 bool m_one_shot;
Jim Ingham5a988412012-06-08 21:56:10 +0000351
352 };
353
354protected:
355 virtual bool
356 DoExecute (Args& command,
357 CommandReturnObject &result)
358 {
359 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
360 if (target == NULL)
361 {
362 result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command).");
363 result.SetStatus (eReturnStatusFailed);
364 return false;
365 }
366
367 // The following are the various types of breakpoints that could be set:
368 // 1). -f -l -p [-s -g] (setting breakpoint by source location)
369 // 2). -a [-s -g] (setting breakpoint by address)
370 // 3). -n [-s -g] (setting breakpoint by function name)
371 // 4). -r [-s -g] (setting breakpoint by function name regular expression)
372 // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text)
373 // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.)
374
375 BreakpointSetType break_type = eSetTypeInvalid;
376
377 if (m_options.m_line_num != 0)
378 break_type = eSetTypeFileAndLine;
379 else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
380 break_type = eSetTypeAddress;
381 else if (!m_options.m_func_names.empty())
382 break_type = eSetTypeFunctionName;
383 else if (!m_options.m_func_regexp.empty())
384 break_type = eSetTypeFunctionRegexp;
385 else if (!m_options.m_source_text_regexp.empty())
386 break_type = eSetTypeSourceRegexp;
387 else if (m_options.m_language != eLanguageTypeUnknown)
388 break_type = eSetTypeException;
389
390 Breakpoint *bp = NULL;
391 FileSpec module_spec;
Jim Ingham5a988412012-06-08 21:56:10 +0000392 const bool internal = false;
393
Jim Ingham5a988412012-06-08 21:56:10 +0000394 switch (break_type)
395 {
396 case eSetTypeFileAndLine: // Breakpoint by source position
397 {
398 FileSpec file;
Greg Claytonc7bece562013-01-25 18:06:21 +0000399 const size_t num_files = m_options.m_filenames.GetSize();
Jim Ingham5a988412012-06-08 21:56:10 +0000400 if (num_files == 0)
401 {
402 if (!GetDefaultFile (target, file, result))
403 {
404 result.AppendError("No file supplied and no default file available.");
405 result.SetStatus (eReturnStatusFailed);
406 return false;
407 }
408 }
409 else if (num_files > 1)
410 {
411 result.AppendError("Only one file at a time is allowed for file and line breakpoints.");
412 result.SetStatus (eReturnStatusFailed);
413 return false;
414 }
415 else
416 file = m_options.m_filenames.GetFileSpecAtIndex(0);
Greg Clayton1f746072012-08-29 21:13:06 +0000417
418 // Only check for inline functions if
419 LazyBool check_inlines = eLazyBoolCalculate;
420
Jim Ingham5a988412012-06-08 21:56:10 +0000421 bp = target->CreateBreakpoint (&(m_options.m_modules),
422 file,
423 m_options.m_line_num,
Greg Clayton1f746072012-08-29 21:13:06 +0000424 check_inlines,
Jim Ingham5a988412012-06-08 21:56:10 +0000425 m_options.m_skip_prologue,
426 internal).get();
427 }
428 break;
429
430 case eSetTypeAddress: // Breakpoint by address
431 bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
432 break;
433
434 case eSetTypeFunctionName: // Breakpoint by function name
435 {
436 uint32_t name_type_mask = m_options.m_func_name_type_mask;
437
438 if (name_type_mask == 0)
439 name_type_mask = eFunctionNameTypeAuto;
440
441 bp = target->CreateBreakpoint (&(m_options.m_modules),
442 &(m_options.m_filenames),
443 m_options.m_func_names,
444 name_type_mask,
445 m_options.m_skip_prologue,
446 internal).get();
447 }
448 break;
449
450 case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
451 {
452 RegularExpression regexp(m_options.m_func_regexp.c_str());
453 if (!regexp.IsValid())
454 {
455 char err_str[1024];
456 regexp.GetErrorAsCString(err_str, sizeof(err_str));
457 result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"",
458 err_str);
459 result.SetStatus (eReturnStatusFailed);
460 return false;
461 }
462
463 bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules),
464 &(m_options.m_filenames),
465 regexp,
466 m_options.m_skip_prologue,
467 internal).get();
468 }
469 break;
470 case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
471 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000472 const size_t num_files = m_options.m_filenames.GetSize();
Jim Ingham5a988412012-06-08 21:56:10 +0000473
474 if (num_files == 0)
475 {
476 FileSpec file;
477 if (!GetDefaultFile (target, file, result))
478 {
479 result.AppendError ("No files provided and could not find default file.");
480 result.SetStatus (eReturnStatusFailed);
481 return false;
482 }
483 else
484 {
485 m_options.m_filenames.Append (file);
486 }
487 }
488
489 RegularExpression regexp(m_options.m_source_text_regexp.c_str());
490 if (!regexp.IsValid())
491 {
492 char err_str[1024];
493 regexp.GetErrorAsCString(err_str, sizeof(err_str));
494 result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"",
495 err_str);
496 result.SetStatus (eReturnStatusFailed);
497 return false;
498 }
499 bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules), &(m_options.m_filenames), regexp).get();
500 }
501 break;
502 case eSetTypeException:
503 {
504 bp = target->CreateExceptionBreakpoint (m_options.m_language, m_options.m_catch_bp, m_options.m_throw_bp).get();
505 }
506 break;
507 default:
508 break;
509 }
510
511 // Now set the various options that were passed in:
512 if (bp)
513 {
514 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
515 bp->SetThreadID (m_options.m_thread_id);
516
517 if (m_options.m_thread_index != UINT32_MAX)
518 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
519
520 if (!m_options.m_thread_name.empty())
521 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
522
523 if (!m_options.m_queue_name.empty())
524 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
525
526 if (m_options.m_ignore_count != 0)
527 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
528
529 if (!m_options.m_condition.empty())
530 bp->GetOptions()->SetCondition(m_options.m_condition.c_str());
Jim Inghamca36cd12012-10-05 19:16:31 +0000531
532 bp->SetOneShot (m_options.m_one_shot);
Jim Ingham5a988412012-06-08 21:56:10 +0000533 }
534
535 if (bp)
536 {
537 Stream &output_stream = result.GetOutputStream();
Jim Ingham1391cc72012-09-22 00:04:04 +0000538 const bool show_locations = false;
539 bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, show_locations);
Jim Ingham5a988412012-06-08 21:56:10 +0000540 // Don't print out this warning for exception breakpoints. They can get set before the target
541 // is set, but we won't know how to actually set the breakpoint till we run.
542 if (bp->GetNumLocations() == 0 && break_type != eSetTypeException)
543 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n");
544 result.SetStatus (eReturnStatusSuccessFinishResult);
545 }
546 else if (!bp)
547 {
548 result.AppendError ("Breakpoint creation failed: No breakpoint created.");
549 result.SetStatus (eReturnStatusFailed);
550 }
551
552 return result.Succeeded();
553 }
554
555private:
556 bool
557 GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result)
558 {
559 uint32_t default_line;
560 // First use the Source Manager's default file.
561 // Then use the current stack frame's file.
562 if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line))
563 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000564 StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
Jim Ingham5a988412012-06-08 21:56:10 +0000565 if (cur_frame == NULL)
566 {
567 result.AppendError ("No selected frame to use to find the default file.");
568 result.SetStatus (eReturnStatusFailed);
569 return false;
570 }
571 else if (!cur_frame->HasDebugInformation())
572 {
573 result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info.");
574 result.SetStatus (eReturnStatusFailed);
575 return false;
576 }
577 else
578 {
579 const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
580 if (sc.line_entry.file)
581 {
582 file = sc.line_entry.file;
583 }
584 else
585 {
586 result.AppendError ("Can't find the file for the selected frame to use as the default file.");
587 result.SetStatus (eReturnStatusFailed);
588 return false;
589 }
590 }
591 }
592 return true;
593 }
594
595 CommandOptions m_options;
596};
Johnny Chen6943e7c2012-05-08 00:43:20 +0000597// If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to
598// update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately.
Johnny Chen4ab2e6b2012-05-07 23:23:41 +0000599#define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 )
600#define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 )
Jim Inghama8558b62012-05-22 00:12:20 +0000601#define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) )
Jim Ingham87df91b2011-09-23 00:54:11 +0000602
Greg Claytone0d378b2011-03-24 21:19:54 +0000603OptionDefinition
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000604CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
605{
Jim Inghamfab10e82012-03-06 00:37:27 +0000606 { LLDB_OPT_NOT_10, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000607 "Set the breakpoint only in this shared library. "
608 "Can repeat this option multiple times to specify multiple shared libraries."},
Jim Ingham86511212010-06-15 18:47:14 +0000609
Caroline Ticedeaab222010-10-01 19:59:14 +0000610 { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount,
611 "Set the number of times this breakpoint is skipped before stopping." },
Jim Ingham1b54c882010-06-16 02:00:15 +0000612
Jim Inghamca36cd12012-10-05 19:16:31 +0000613 { LLDB_OPT_SET_ALL, false, "one-shot", 'o', no_argument, NULL, 0, eArgTypeNone,
614 "The breakpoint is deleted the first time it stop causes a stop." },
615
Johnny Chen7d49c9c2012-05-25 21:10:46 +0000616 { LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, 0, eArgTypeExpression,
617 "The breakpoint stops only if this condition expression evaluates to true."},
618
Bill Wendlinga0cd2bc2012-04-03 04:13:41 +0000619 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex,
Greg Claytoned8a7052010-09-18 03:37:20 +0000620 "The breakpoint stops only for the thread whose index matches this argument."},
Jim Ingham1b54c882010-06-16 02:00:15 +0000621
Bill Wendlinga0cd2bc2012-04-03 04:13:41 +0000622 { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID,
Jim Ingham1b54c882010-06-16 02:00:15 +0000623 "The breakpoint stops only for the thread whose TID matches this argument."},
624
Bill Wendlinga0cd2bc2012-04-03 04:13:41 +0000625 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName,
Jim Ingham1b54c882010-06-16 02:00:15 +0000626 "The breakpoint stops only for the thread whose thread name matches this argument."},
627
Bill Wendlinga0cd2bc2012-04-03 04:13:41 +0000628 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName,
Jim Ingham1b54c882010-06-16 02:00:15 +0000629 "The breakpoint stops only for threads in the queue whose name is given by this argument."},
630
Jim Ingham87df91b2011-09-23 00:54:11 +0000631 { LLDB_OPT_FILE, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
Jim Ingham289aca62013-02-14 19:10:36 +0000632 "Specifies the source file in which to set this breakpoint. "
633 "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 +0000634 "To set breakpoints on .c/.cpp/.m/.mm files that are #included, set target.inline-breakpoint-strategy"
Jim Ingham289aca62013-02-14 19:10:36 +0000635 " to \"always\"."},
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636
Caroline Ticedeaab222010-10-01 19:59:14 +0000637 { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
Jim Ingham87df91b2011-09-23 00:54:11 +0000638 "Specifies the line number on which to set this breakpoint."},
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000639
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000640 // Comment out this option for the moment, as we don't actually use it, but will in the future.
641 // This way users won't see it, but the infrastructure is left in place.
Johnny Chen7d49c9c2012-05-25 21:10:46 +0000642 // { 0, false, "column", 'C', required_argument, NULL, "<column>",
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000643 // "Set the breakpoint by source location at this particular column."},
644
Enrico Granatab84a9db2013-01-29 01:48:30 +0000645 { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddressOrExpression,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000646 "Set the breakpoint by address, at the specified address."},
647
Caroline Ticedeaab222010-10-01 19:59:14 +0000648 { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000649 "Set the breakpoint by function name. Can be repeated multiple times to make one breakpoint for multiple snames" },
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000650
Caroline Ticedeaab222010-10-01 19:59:14 +0000651 { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000652 "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and "
653 "for Objective C this means a full function prototype with class and selector. "
654 "Can be repeated multiple times to make one breakpoint for multiple names." },
Greg Clayton0c5cd902010-06-28 21:30:43 +0000655
Caroline Ticedeaab222010-10-01 19:59:14 +0000656 { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000657 "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 +0000658
Caroline Ticedeaab222010-10-01 19:59:14 +0000659 { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000660 "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 +0000661
Caroline Ticedeaab222010-10-01 19:59:14 +0000662 { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000663 "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
664
Greg Claytone02b8502010-10-12 04:29:14 +0000665 { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000666 "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). "
667 "Can be repeated multiple times to make one breakpoint for multiple symbols." },
Greg Claytone02b8502010-10-12 04:29:14 +0000668
Jim Ingham969795f2011-09-21 01:17:13 +0000669 { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', required_argument, NULL, 0, eArgTypeRegularExpression,
670 "Set the breakpoint specifying a regular expression to match a pattern in the source text in a given source file." },
671
Jim Inghamfab10e82012-03-06 00:37:27 +0000672 { LLDB_OPT_SET_10, true, "language-exception", 'E', required_argument, NULL, 0, eArgTypeLanguage,
673 "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" },
674
675 { LLDB_OPT_SET_10, false, "on-throw", 'w', required_argument, NULL, 0, eArgTypeBoolean,
676 "Set the breakpoint on exception throW." },
677
678 { LLDB_OPT_SET_10, false, "on-catch", 'h', required_argument, NULL, 0, eArgTypeBoolean,
679 "Set the breakpoint on exception catcH." },
Jim Ingham969795f2011-09-21 01:17:13 +0000680
Jim Inghama8558b62012-05-22 00:12:20 +0000681 { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', required_argument, NULL, 0, eArgTypeBoolean,
682 "sKip the prologue if the breakpoint is at the beginning of a function. If not set the target.skip-prologue setting is used." },
683
Caroline Ticedeaab222010-10-01 19:59:14 +0000684 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000685};
686
Jim Ingham5a988412012-06-08 21:56:10 +0000687//-------------------------------------------------------------------------
688// CommandObjectBreakpointModify
689//-------------------------------------------------------------------------
690#pragma mark Modify
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691
Jim Ingham5a988412012-06-08 21:56:10 +0000692class CommandObjectBreakpointModify : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000693{
Jim Ingham5a988412012-06-08 21:56:10 +0000694public:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000695
Jim Ingham5a988412012-06-08 21:56:10 +0000696 CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
697 CommandObjectParsed (interpreter,
698 "breakpoint modify",
699 "Modify the options on a breakpoint or set of breakpoints in the executable. "
700 "If no breakpoint is specified, acts on the last created breakpoint. "
701 "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
702 NULL),
703 m_options (interpreter)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000704 {
Jim Ingham5a988412012-06-08 21:56:10 +0000705 CommandArgumentEntry arg;
706 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
707 // Add the entry for the first argument for this command to the object's arguments vector.
708 m_arguments.push_back (arg);
709 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000710
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000711
Jim Ingham5a988412012-06-08 21:56:10 +0000712 virtual
713 ~CommandObjectBreakpointModify () {}
Greg Clayton0c5cd902010-06-28 21:30:43 +0000714
Jim Ingham5a988412012-06-08 21:56:10 +0000715 virtual Options *
716 GetOptions ()
717 {
718 return &m_options;
719 }
Johnny Chen7d49c9c2012-05-25 21:10:46 +0000720
Jim Ingham5a988412012-06-08 21:56:10 +0000721 class CommandOptions : public Options
722 {
723 public:
Greg Clayton0c5cd902010-06-28 21:30:43 +0000724
Jim Ingham5a988412012-06-08 21:56:10 +0000725 CommandOptions (CommandInterpreter &interpreter) :
726 Options (interpreter),
727 m_ignore_count (0),
728 m_thread_id(LLDB_INVALID_THREAD_ID),
729 m_thread_id_passed(false),
730 m_thread_index (UINT32_MAX),
731 m_thread_index_passed(false),
732 m_thread_name(),
733 m_queue_name(),
734 m_condition (),
Jim Inghamca36cd12012-10-05 19:16:31 +0000735 m_one_shot (false),
Jim Ingham5a988412012-06-08 21:56:10 +0000736 m_enable_passed (false),
737 m_enable_value (false),
738 m_name_passed (false),
739 m_queue_passed (false),
Jim Inghamca36cd12012-10-05 19:16:31 +0000740 m_condition_passed (false),
741 m_one_shot_passed (false)
Jim Ingham5a988412012-06-08 21:56:10 +0000742 {
743 }
Greg Clayton0c5cd902010-06-28 21:30:43 +0000744
Jim Ingham5a988412012-06-08 21:56:10 +0000745 virtual
746 ~CommandOptions () {}
Greg Clayton0c5cd902010-06-28 21:30:43 +0000747
Jim Ingham5a988412012-06-08 21:56:10 +0000748 virtual Error
749 SetOptionValue (uint32_t option_idx, const char *option_arg)
750 {
751 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000752 const int short_option = m_getopt_table[option_idx].val;
Greg Claytone02b8502010-10-12 04:29:14 +0000753
Jim Ingham5a988412012-06-08 21:56:10 +0000754 switch (short_option)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000755 {
Jim Ingham5a988412012-06-08 21:56:10 +0000756 case 'c':
757 if (option_arg != NULL)
758 m_condition.assign (option_arg);
759 else
760 m_condition.clear();
761 m_condition_passed = true;
762 break;
763 case 'd':
764 m_enable_passed = true;
765 m_enable_value = false;
766 break;
767 case 'e':
768 m_enable_passed = true;
769 m_enable_value = true;
770 break;
771 case 'i':
772 {
773 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
774 if (m_ignore_count == UINT32_MAX)
775 error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
776 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000777 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000778 case 'o':
779 {
780 bool value, success;
781 value = Args::StringToBoolean(option_arg, false, &success);
782 if (success)
783 {
784 m_one_shot_passed = true;
785 m_one_shot = value;
786 }
787 else
788 error.SetErrorStringWithFormat("invalid boolean value '%s' passed for -o option", option_arg);
789 }
790 break;
Jim Ingham5a988412012-06-08 21:56:10 +0000791 case 't' :
Jim Ingham87df91b2011-09-23 00:54:11 +0000792 {
Jim Ingham5a988412012-06-08 21:56:10 +0000793 if (option_arg[0] == '\0')
Jim Ingham87df91b2011-09-23 00:54:11 +0000794 {
Jim Ingham5a988412012-06-08 21:56:10 +0000795 m_thread_id = LLDB_INVALID_THREAD_ID;
796 m_thread_id_passed = true;
Jim Ingham87df91b2011-09-23 00:54:11 +0000797 }
798 else
799 {
Jim Ingham5a988412012-06-08 21:56:10 +0000800 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
801 if (m_thread_id == LLDB_INVALID_THREAD_ID)
802 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
803 else
804 m_thread_id_passed = true;
Jim Ingham87df91b2011-09-23 00:54:11 +0000805 }
806 }
Jim Ingham5a988412012-06-08 21:56:10 +0000807 break;
808 case 'T':
809 if (option_arg != NULL)
810 m_thread_name.assign (option_arg);
811 else
812 m_thread_name.clear();
813 m_name_passed = true;
814 break;
815 case 'q':
816 if (option_arg != NULL)
817 m_queue_name.assign (option_arg);
818 else
819 m_queue_name.clear();
820 m_queue_passed = true;
821 break;
822 case 'x':
Jim Ingham969795f2011-09-21 01:17:13 +0000823 {
Jim Ingham5a988412012-06-08 21:56:10 +0000824 if (option_arg[0] == '\n')
825 {
826 m_thread_index = UINT32_MAX;
827 m_thread_index_passed = true;
828 }
829 else
830 {
831 m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0);
832 if (m_thread_id == UINT32_MAX)
833 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
834 else
835 m_thread_index_passed = true;
836 }
Jim Ingham969795f2011-09-21 01:17:13 +0000837 }
Jim Ingham5a988412012-06-08 21:56:10 +0000838 break;
839 default:
840 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
841 break;
Jim Ingham969795f2011-09-21 01:17:13 +0000842 }
Jim Ingham5a988412012-06-08 21:56:10 +0000843
844 return error;
845 }
846 void
847 OptionParsingStarting ()
848 {
849 m_ignore_count = 0;
850 m_thread_id = LLDB_INVALID_THREAD_ID;
851 m_thread_id_passed = false;
852 m_thread_index = UINT32_MAX;
853 m_thread_index_passed = false;
854 m_thread_name.clear();
855 m_queue_name.clear();
856 m_condition.clear();
Jim Inghamca36cd12012-10-05 19:16:31 +0000857 m_one_shot = false;
Jim Ingham5a988412012-06-08 21:56:10 +0000858 m_enable_passed = false;
859 m_queue_passed = false;
860 m_name_passed = false;
861 m_condition_passed = false;
Jim Inghamca36cd12012-10-05 19:16:31 +0000862 m_one_shot_passed = false;
Jim Ingham5a988412012-06-08 21:56:10 +0000863 }
864
865 const OptionDefinition*
866 GetDefinitions ()
867 {
868 return g_option_table;
869 }
870
871
872 // Options table: Required for subclasses of Options.
873
874 static OptionDefinition g_option_table[];
875
876 // Instance variables to hold the values for command options.
877
878 uint32_t m_ignore_count;
879 lldb::tid_t m_thread_id;
880 bool m_thread_id_passed;
881 uint32_t m_thread_index;
882 bool m_thread_index_passed;
883 std::string m_thread_name;
884 std::string m_queue_name;
885 std::string m_condition;
Jim Inghamca36cd12012-10-05 19:16:31 +0000886 bool m_one_shot;
Jim Ingham5a988412012-06-08 21:56:10 +0000887 bool m_enable_passed;
888 bool m_enable_value;
889 bool m_name_passed;
890 bool m_queue_passed;
891 bool m_condition_passed;
Jim Inghamca36cd12012-10-05 19:16:31 +0000892 bool m_one_shot_passed;
Jim Ingham5a988412012-06-08 21:56:10 +0000893
894 };
895
896protected:
897 virtual bool
898 DoExecute (Args& command, CommandReturnObject &result)
899 {
900 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
901 if (target == NULL)
902 {
903 result.AppendError ("Invalid target. No existing target or breakpoints.");
904 result.SetStatus (eReturnStatusFailed);
905 return false;
906 }
907
908 Mutex::Locker locker;
909 target->GetBreakpointList().GetListMutex(locker);
910
911 BreakpointIDList valid_bp_ids;
912
913 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
914
915 if (result.Succeeded())
916 {
917 const size_t count = valid_bp_ids.GetSize();
918 for (size_t i = 0; i < count; ++i)
Jim Inghamfab10e82012-03-06 00:37:27 +0000919 {
Jim Ingham5a988412012-06-08 21:56:10 +0000920 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
921
922 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
923 {
924 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
925 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
926 {
927 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
928 if (location)
929 {
930 if (m_options.m_thread_id_passed)
931 location->SetThreadID (m_options.m_thread_id);
932
933 if (m_options.m_thread_index_passed)
934 location->SetThreadIndex(m_options.m_thread_index);
935
936 if (m_options.m_name_passed)
937 location->SetThreadName(m_options.m_thread_name.c_str());
938
939 if (m_options.m_queue_passed)
940 location->SetQueueName(m_options.m_queue_name.c_str());
941
942 if (m_options.m_ignore_count != 0)
943 location->SetIgnoreCount(m_options.m_ignore_count);
944
945 if (m_options.m_enable_passed)
946 location->SetEnabled (m_options.m_enable_value);
947
948 if (m_options.m_condition_passed)
949 location->SetCondition (m_options.m_condition.c_str());
950 }
951 }
952 else
953 {
954 if (m_options.m_thread_id_passed)
955 bp->SetThreadID (m_options.m_thread_id);
956
957 if (m_options.m_thread_index_passed)
958 bp->SetThreadIndex(m_options.m_thread_index);
959
960 if (m_options.m_name_passed)
961 bp->SetThreadName(m_options.m_thread_name.c_str());
962
963 if (m_options.m_queue_passed)
964 bp->SetQueueName(m_options.m_queue_name.c_str());
965
966 if (m_options.m_ignore_count != 0)
967 bp->SetIgnoreCount(m_options.m_ignore_count);
968
969 if (m_options.m_enable_passed)
970 bp->SetEnabled (m_options.m_enable_value);
971
972 if (m_options.m_condition_passed)
973 bp->SetCondition (m_options.m_condition.c_str());
974 }
975 }
Jim Inghamfab10e82012-03-06 00:37:27 +0000976 }
Jim Ingham5a988412012-06-08 21:56:10 +0000977 }
978
979 return result.Succeeded();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000980 }
981
Jim Ingham5a988412012-06-08 21:56:10 +0000982private:
983 CommandOptions m_options;
984};
Johnny Chen7d49c9c2012-05-25 21:10:46 +0000985
Jim Ingham5a988412012-06-08 21:56:10 +0000986#pragma mark Modify::CommandOptions
987OptionDefinition
988CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
989{
990{ LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." },
Jim Inghamca36cd12012-10-05 19:16:31 +0000991{ LLDB_OPT_SET_ALL, false, "one-shot", 'o', required_argument, NULL, 0, eArgTypeBoolean, "The breakpoint is deleted the first time it stop causes a stop." },
Jim Ingham5a988412012-06-08 21:56:10 +0000992{ LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose indeX matches this argument."},
993{ LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."},
994{ LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."},
995{ LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."},
996{ LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."},
997{ LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, 0, eArgTypeNone, "Enable the breakpoint."},
998{ LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, 0, eArgTypeNone, "Disable the breakpoint."},
Jim Inghamca36cd12012-10-05 19:16:31 +0000999{ 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL }
Jim Ingham5a988412012-06-08 21:56:10 +00001000};
1001
1002//-------------------------------------------------------------------------
1003// CommandObjectBreakpointEnable
1004//-------------------------------------------------------------------------
1005#pragma mark Enable
1006
1007class CommandObjectBreakpointEnable : public CommandObjectParsed
1008{
1009public:
1010 CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
1011 CommandObjectParsed (interpreter,
1012 "enable",
1013 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
1014 NULL)
1015 {
1016 CommandArgumentEntry arg;
1017 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1018 // Add the entry for the first argument for this command to the object's arguments vector.
1019 m_arguments.push_back (arg);
1020 }
1021
1022
1023 virtual
1024 ~CommandObjectBreakpointEnable () {}
1025
1026protected:
1027 virtual bool
1028 DoExecute (Args& command, CommandReturnObject &result)
1029 {
1030 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1031 if (target == NULL)
1032 {
1033 result.AppendError ("Invalid target. No existing target or breakpoints.");
1034 result.SetStatus (eReturnStatusFailed);
1035 return false;
1036 }
1037
1038 Mutex::Locker locker;
1039 target->GetBreakpointList().GetListMutex(locker);
1040
1041 const BreakpointList &breakpoints = target->GetBreakpointList();
1042
1043 size_t num_breakpoints = breakpoints.GetSize();
1044
1045 if (num_breakpoints == 0)
1046 {
1047 result.AppendError ("No breakpoints exist to be enabled.");
1048 result.SetStatus (eReturnStatusFailed);
1049 return false;
1050 }
1051
1052 if (command.GetArgumentCount() == 0)
1053 {
1054 // No breakpoint selected; enable all currently set breakpoints.
1055 target->EnableAllBreakpoints ();
1056 result.AppendMessageWithFormat ("All breakpoints enabled. (%lu breakpoints)\n", num_breakpoints);
1057 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1058 }
1059 else
1060 {
1061 // Particular breakpoint selected; enable that breakpoint.
1062 BreakpointIDList valid_bp_ids;
1063 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1064
1065 if (result.Succeeded())
1066 {
1067 int enable_count = 0;
1068 int loc_count = 0;
1069 const size_t count = valid_bp_ids.GetSize();
1070 for (size_t i = 0; i < count; ++i)
1071 {
1072 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1073
1074 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1075 {
1076 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1077 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1078 {
1079 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1080 if (location)
1081 {
1082 location->SetEnabled (true);
1083 ++loc_count;
1084 }
1085 }
1086 else
1087 {
1088 breakpoint->SetEnabled (true);
1089 ++enable_count;
1090 }
1091 }
1092 }
1093 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
1094 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1095 }
1096 }
1097
1098 return result.Succeeded();
1099 }
1100};
1101
1102//-------------------------------------------------------------------------
1103// CommandObjectBreakpointDisable
1104//-------------------------------------------------------------------------
1105#pragma mark Disable
1106
1107class CommandObjectBreakpointDisable : public CommandObjectParsed
1108{
1109public:
1110 CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
1111 CommandObjectParsed (interpreter,
1112 "breakpoint disable",
1113 "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.",
1114 NULL)
1115 {
1116 CommandArgumentEntry arg;
1117 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1118 // Add the entry for the first argument for this command to the object's arguments vector.
1119 m_arguments.push_back (arg);
1120 }
1121
1122
1123 virtual
1124 ~CommandObjectBreakpointDisable () {}
1125
1126protected:
1127 virtual bool
1128 DoExecute (Args& command, CommandReturnObject &result)
1129 {
1130 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1131 if (target == NULL)
1132 {
1133 result.AppendError ("Invalid target. No existing target or breakpoints.");
1134 result.SetStatus (eReturnStatusFailed);
1135 return false;
1136 }
1137
1138 Mutex::Locker locker;
1139 target->GetBreakpointList().GetListMutex(locker);
1140
1141 const BreakpointList &breakpoints = target->GetBreakpointList();
1142 size_t num_breakpoints = breakpoints.GetSize();
1143
1144 if (num_breakpoints == 0)
1145 {
1146 result.AppendError ("No breakpoints exist to be disabled.");
1147 result.SetStatus (eReturnStatusFailed);
1148 return false;
1149 }
1150
1151 if (command.GetArgumentCount() == 0)
1152 {
1153 // No breakpoint selected; disable all currently set breakpoints.
1154 target->DisableAllBreakpoints ();
1155 result.AppendMessageWithFormat ("All breakpoints disabled. (%lu breakpoints)\n", num_breakpoints);
1156 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1157 }
1158 else
1159 {
1160 // Particular breakpoint selected; disable that breakpoint.
1161 BreakpointIDList valid_bp_ids;
1162
1163 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1164
1165 if (result.Succeeded())
1166 {
1167 int disable_count = 0;
1168 int loc_count = 0;
1169 const size_t count = valid_bp_ids.GetSize();
1170 for (size_t i = 0; i < count; ++i)
1171 {
1172 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1173
1174 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1175 {
1176 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1177 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1178 {
1179 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1180 if (location)
1181 {
1182 location->SetEnabled (false);
1183 ++loc_count;
1184 }
1185 }
1186 else
1187 {
1188 breakpoint->SetEnabled (false);
1189 ++disable_count;
1190 }
1191 }
1192 }
1193 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
1194 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1195 }
1196 }
1197
1198 return result.Succeeded();
1199 }
1200
1201};
1202
1203//-------------------------------------------------------------------------
1204// CommandObjectBreakpointList
1205//-------------------------------------------------------------------------
1206#pragma mark List
1207
1208class CommandObjectBreakpointList : public CommandObjectParsed
1209{
1210public:
1211 CommandObjectBreakpointList (CommandInterpreter &interpreter) :
1212 CommandObjectParsed (interpreter,
1213 "breakpoint list",
1214 "List some or all breakpoints at configurable levels of detail.",
1215 NULL),
1216 m_options (interpreter)
1217 {
1218 CommandArgumentEntry arg;
1219 CommandArgumentData bp_id_arg;
1220
1221 // Define the first (and only) variant of this arg.
1222 bp_id_arg.arg_type = eArgTypeBreakpointID;
1223 bp_id_arg.arg_repetition = eArgRepeatOptional;
1224
1225 // There is only one variant this argument could be; put it into the argument entry.
1226 arg.push_back (bp_id_arg);
1227
1228 // Push the data for the first argument into the m_arguments vector.
1229 m_arguments.push_back (arg);
1230 }
1231
1232
1233 virtual
1234 ~CommandObjectBreakpointList () {}
1235
1236 virtual Options *
1237 GetOptions ()
1238 {
1239 return &m_options;
Jim Ingham1b54c882010-06-16 02:00:15 +00001240 }
1241
Jim Ingham5a988412012-06-08 21:56:10 +00001242 class CommandOptions : public Options
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001243 {
Jim Ingham5a988412012-06-08 21:56:10 +00001244 public:
1245
1246 CommandOptions (CommandInterpreter &interpreter) :
1247 Options (interpreter),
1248 m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions
1249 {
1250 }
1251
1252 virtual
1253 ~CommandOptions () {}
1254
1255 virtual Error
1256 SetOptionValue (uint32_t option_idx, const char *option_arg)
1257 {
1258 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00001259 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham5a988412012-06-08 21:56:10 +00001260
1261 switch (short_option)
1262 {
1263 case 'b':
1264 m_level = lldb::eDescriptionLevelBrief;
1265 break;
1266 case 'f':
1267 m_level = lldb::eDescriptionLevelFull;
1268 break;
1269 case 'v':
1270 m_level = lldb::eDescriptionLevelVerbose;
1271 break;
1272 case 'i':
1273 m_internal = true;
1274 break;
1275 default:
1276 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1277 break;
1278 }
1279
1280 return error;
1281 }
1282
1283 void
1284 OptionParsingStarting ()
1285 {
1286 m_level = lldb::eDescriptionLevelFull;
1287 m_internal = false;
1288 }
1289
1290 const OptionDefinition *
1291 GetDefinitions ()
1292 {
1293 return g_option_table;
1294 }
1295
1296 // Options table: Required for subclasses of Options.
1297
1298 static OptionDefinition g_option_table[];
1299
1300 // Instance variables to hold the values for command options.
1301
1302 lldb::DescriptionLevel m_level;
1303
1304 bool m_internal;
1305 };
1306
1307protected:
1308 virtual bool
1309 DoExecute (Args& command, CommandReturnObject &result)
1310 {
1311 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1312 if (target == NULL)
1313 {
1314 result.AppendError ("Invalid target. No current target or breakpoints.");
1315 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1316 return true;
1317 }
1318
1319 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
1320 Mutex::Locker locker;
1321 target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
1322
1323 size_t num_breakpoints = breakpoints.GetSize();
1324
1325 if (num_breakpoints == 0)
1326 {
1327 result.AppendMessage ("No breakpoints currently set.");
1328 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1329 return true;
1330 }
1331
Jim Ingham85e8b812011-02-19 02:53:09 +00001332 Stream &output_stream = result.GetOutputStream();
Jim Ingham5a988412012-06-08 21:56:10 +00001333
1334 if (command.GetArgumentCount() == 0)
1335 {
1336 // No breakpoint selected; show info about all currently set breakpoints.
1337 result.AppendMessage ("Current breakpoints:");
1338 for (size_t i = 0; i < num_breakpoints; ++i)
1339 {
1340 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
1341 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
1342 }
1343 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1344 }
1345 else
1346 {
1347 // Particular breakpoints selected; show info about that breakpoint.
1348 BreakpointIDList valid_bp_ids;
1349 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1350
1351 if (result.Succeeded())
1352 {
1353 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
1354 {
1355 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1356 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1357 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
1358 }
1359 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1360 }
1361 else
1362 {
1363 result.AppendError ("Invalid breakpoint id.");
1364 result.SetStatus (eReturnStatusFailed);
1365 }
1366 }
1367
1368 return result.Succeeded();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001369 }
1370
Jim Ingham5a988412012-06-08 21:56:10 +00001371private:
1372 CommandOptions m_options;
1373};
1374
1375#pragma mark List::CommandOptions
1376OptionDefinition
1377CommandObjectBreakpointList::CommandOptions::g_option_table[] =
1378{
1379 { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone,
1380 "Show debugger internal breakpoints" },
1381
1382 { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone,
1383 "Give a brief description of the breakpoint (no location info)."},
1384
1385 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
1386 // But I need to see it for now, and don't want to wait.
1387 { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone,
1388 "Give a full description of the breakpoint and its locations."},
1389
1390 { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone,
1391 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
1392
1393 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1394};
1395
1396//-------------------------------------------------------------------------
1397// CommandObjectBreakpointClear
1398//-------------------------------------------------------------------------
1399#pragma mark Clear
1400
1401class CommandObjectBreakpointClear : public CommandObjectParsed
1402{
1403public:
1404
1405 typedef enum BreakpointClearType
1406 {
1407 eClearTypeInvalid,
1408 eClearTypeFileAndLine
1409 } BreakpointClearType;
1410
1411 CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
1412 CommandObjectParsed (interpreter,
1413 "breakpoint clear",
1414 "Clears a breakpoint or set of breakpoints in the executable.",
1415 "breakpoint clear <cmd-options>"),
1416 m_options (interpreter)
1417 {
1418 }
1419
1420 virtual
1421 ~CommandObjectBreakpointClear () {}
1422
1423 virtual Options *
1424 GetOptions ()
1425 {
1426 return &m_options;
1427 }
1428
1429 class CommandOptions : public Options
1430 {
1431 public:
1432
1433 CommandOptions (CommandInterpreter &interpreter) :
1434 Options (interpreter),
1435 m_filename (),
1436 m_line_num (0)
1437 {
1438 }
1439
1440 virtual
1441 ~CommandOptions () {}
1442
1443 virtual Error
1444 SetOptionValue (uint32_t option_idx, const char *option_arg)
1445 {
1446 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00001447 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham5a988412012-06-08 21:56:10 +00001448
1449 switch (short_option)
1450 {
1451 case 'f':
1452 m_filename.assign (option_arg);
1453 break;
1454
1455 case 'l':
1456 m_line_num = Args::StringToUInt32 (option_arg, 0);
1457 break;
1458
1459 default:
1460 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1461 break;
1462 }
1463
1464 return error;
1465 }
1466
1467 void
1468 OptionParsingStarting ()
1469 {
1470 m_filename.clear();
1471 m_line_num = 0;
1472 }
1473
1474 const OptionDefinition*
1475 GetDefinitions ()
1476 {
1477 return g_option_table;
1478 }
1479
1480 // Options table: Required for subclasses of Options.
1481
1482 static OptionDefinition g_option_table[];
1483
1484 // Instance variables to hold the values for command options.
1485
1486 std::string m_filename;
1487 uint32_t m_line_num;
1488
1489 };
1490
1491protected:
1492 virtual bool
1493 DoExecute (Args& command, CommandReturnObject &result)
1494 {
1495 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1496 if (target == NULL)
1497 {
1498 result.AppendError ("Invalid target. No existing target or breakpoints.");
1499 result.SetStatus (eReturnStatusFailed);
1500 return false;
1501 }
1502
1503 // The following are the various types of breakpoints that could be cleared:
1504 // 1). -f -l (clearing breakpoint by source location)
1505
1506 BreakpointClearType break_type = eClearTypeInvalid;
1507
1508 if (m_options.m_line_num != 0)
1509 break_type = eClearTypeFileAndLine;
1510
1511 Mutex::Locker locker;
1512 target->GetBreakpointList().GetListMutex(locker);
1513
1514 BreakpointList &breakpoints = target->GetBreakpointList();
1515 size_t num_breakpoints = breakpoints.GetSize();
1516
1517 // Early return if there's no breakpoint at all.
1518 if (num_breakpoints == 0)
1519 {
1520 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1521 result.SetStatus (eReturnStatusFailed);
1522 return result.Succeeded();
1523 }
1524
1525 // Find matching breakpoints and delete them.
1526
1527 // First create a copy of all the IDs.
1528 std::vector<break_id_t> BreakIDs;
1529 for (size_t i = 0; i < num_breakpoints; ++i)
1530 BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID());
1531
1532 int num_cleared = 0;
1533 StreamString ss;
1534 switch (break_type)
1535 {
1536 case eClearTypeFileAndLine: // Breakpoint by source position
1537 {
1538 const ConstString filename(m_options.m_filename.c_str());
1539 BreakpointLocationCollection loc_coll;
1540
1541 for (size_t i = 0; i < num_breakpoints; ++i)
1542 {
1543 Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
1544
1545 if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
1546 {
1547 // If the collection size is 0, it's a full match and we can just remove the breakpoint.
1548 if (loc_coll.GetSize() == 0)
1549 {
1550 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
1551 ss.EOL();
1552 target->RemoveBreakpointByID (bp->GetID());
1553 ++num_cleared;
1554 }
1555 }
1556 }
1557 }
1558 break;
1559
1560 default:
1561 break;
1562 }
1563
1564 if (num_cleared > 0)
1565 {
1566 Stream &output_stream = result.GetOutputStream();
1567 output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
1568 output_stream << ss.GetData();
1569 output_stream.EOL();
1570 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1571 }
1572 else
1573 {
1574 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1575 result.SetStatus (eReturnStatusFailed);
1576 }
1577
1578 return result.Succeeded();
1579 }
1580
1581private:
1582 CommandOptions m_options;
1583};
1584
1585#pragma mark Clear::CommandOptions
1586
1587OptionDefinition
1588CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
1589{
1590 { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
1591 "Specify the breakpoint by source location in this particular file."},
1592
1593 { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
1594 "Specify the breakpoint by source location at this particular line."},
1595
1596 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1597};
1598
1599//-------------------------------------------------------------------------
1600// CommandObjectBreakpointDelete
1601//-------------------------------------------------------------------------
1602#pragma mark Delete
1603
1604class CommandObjectBreakpointDelete : public CommandObjectParsed
1605{
1606public:
1607 CommandObjectBreakpointDelete (CommandInterpreter &interpreter) :
1608 CommandObjectParsed (interpreter,
1609 "breakpoint delete",
1610 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
1611 NULL)
1612 {
1613 CommandArgumentEntry arg;
1614 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1615 // Add the entry for the first argument for this command to the object's arguments vector.
1616 m_arguments.push_back (arg);
1617 }
1618
1619 virtual
1620 ~CommandObjectBreakpointDelete () {}
1621
1622protected:
1623 virtual bool
1624 DoExecute (Args& command, CommandReturnObject &result)
1625 {
1626 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1627 if (target == NULL)
1628 {
1629 result.AppendError ("Invalid target. No existing target or breakpoints.");
1630 result.SetStatus (eReturnStatusFailed);
1631 return false;
1632 }
1633
1634 Mutex::Locker locker;
1635 target->GetBreakpointList().GetListMutex(locker);
1636
1637 const BreakpointList &breakpoints = target->GetBreakpointList();
1638
1639 size_t num_breakpoints = breakpoints.GetSize();
1640
1641 if (num_breakpoints == 0)
1642 {
1643 result.AppendError ("No breakpoints exist to be deleted.");
1644 result.SetStatus (eReturnStatusFailed);
1645 return false;
1646 }
1647
1648 if (command.GetArgumentCount() == 0)
1649 {
1650 if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
1651 {
1652 result.AppendMessage("Operation cancelled...");
1653 }
1654 else
1655 {
1656 target->RemoveAllBreakpoints ();
1657 result.AppendMessageWithFormat ("All breakpoints removed. (%lu breakpoints)\n", num_breakpoints);
1658 }
1659 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1660 }
1661 else
1662 {
1663 // Particular breakpoint selected; disable that breakpoint.
1664 BreakpointIDList valid_bp_ids;
1665 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1666
1667 if (result.Succeeded())
1668 {
1669 int delete_count = 0;
1670 int disable_count = 0;
1671 const size_t count = valid_bp_ids.GetSize();
1672 for (size_t i = 0; i < count; ++i)
1673 {
1674 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1675
1676 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1677 {
1678 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1679 {
1680 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1681 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1682 // It makes no sense to try to delete individual locations, so we disable them instead.
1683 if (location)
1684 {
1685 location->SetEnabled (false);
1686 ++disable_count;
1687 }
1688 }
1689 else
1690 {
1691 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1692 ++delete_count;
1693 }
1694 }
1695 }
1696 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1697 delete_count, disable_count);
1698 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1699 }
1700 }
1701 return result.Succeeded();
1702 }
1703};
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001704
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001705//-------------------------------------------------------------------------
1706// CommandObjectMultiwordBreakpoint
1707//-------------------------------------------------------------------------
Jim Inghamae1c4cf2010-06-18 00:58:52 +00001708#pragma mark MultiwordBreakpoint
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001709
Greg Clayton66111032010-06-23 01:19:29 +00001710CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
Greg Claytona7015092010-09-18 01:14:36 +00001711 CommandObjectMultiword (interpreter,
1712 "breakpoint",
Jim Ingham46fbc602011-05-26 20:39:01 +00001713 "A set of commands for operating on breakpoints. Also see _regexp-break.",
Greg Claytona7015092010-09-18 01:14:36 +00001714 "breakpoint <command> [<command-options>]")
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001715{
Greg Claytona7015092010-09-18 01:14:36 +00001716 CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
Greg Claytona7015092010-09-18 01:14:36 +00001717 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
1718 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
Johnny Chenb7234e42010-10-28 17:27:46 +00001719 CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
1720 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
Greg Claytona7015092010-09-18 01:14:36 +00001721 CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001722 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
Greg Claytona7015092010-09-18 01:14:36 +00001723 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001724
Johnny Chenb7234e42010-10-28 17:27:46 +00001725 list_command_object->SetCommandName ("breakpoint list");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001726 enable_command_object->SetCommandName("breakpoint enable");
1727 disable_command_object->SetCommandName("breakpoint disable");
Johnny Chenb7234e42010-10-28 17:27:46 +00001728 clear_command_object->SetCommandName("breakpoint clear");
1729 delete_command_object->SetCommandName("breakpoint delete");
Jim Inghamae1c4cf2010-06-18 00:58:52 +00001730 set_command_object->SetCommandName("breakpoint set");
Johnny Chenb7234e42010-10-28 17:27:46 +00001731 command_command_object->SetCommandName ("breakpoint command");
1732 modify_command_object->SetCommandName ("breakpoint modify");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001733
Greg Clayton23f59502012-07-17 03:23:13 +00001734 LoadSubCommand ("list", list_command_object);
1735 LoadSubCommand ("enable", enable_command_object);
1736 LoadSubCommand ("disable", disable_command_object);
1737 LoadSubCommand ("clear", clear_command_object);
1738 LoadSubCommand ("delete", delete_command_object);
1739 LoadSubCommand ("set", set_command_object);
1740 LoadSubCommand ("command", command_command_object);
1741 LoadSubCommand ("modify", modify_command_object);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001742}
1743
1744CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
1745{
1746}
1747
1748void
1749CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result,
1750 BreakpointIDList *valid_ids)
1751{
1752 // args can be strings representing 1). integers (for breakpoint ids)
1753 // 2). the full breakpoint & location canonical representation
1754 // 3). the word "to" or a hyphen, representing a range (in which case there
1755 // had *better* be an entry both before & after of one of the first two types.
Jim Ingham36f3b362010-10-14 23:45:03 +00001756 // If args is empty, we will use the last created breakpoint (if there is one.)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001757
1758 Args temp_args;
1759
Jim Ingham36f3b362010-10-14 23:45:03 +00001760 if (args.GetArgumentCount() == 0)
1761 {
Greg Clayton4d122c42011-09-17 08:33:22 +00001762 if (target->GetLastCreatedBreakpoint())
Jim Ingham36f3b362010-10-14 23:45:03 +00001763 {
1764 valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
1765 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1766 }
1767 else
1768 {
1769 result.AppendError("No breakpoint specified and no last created breakpoint.");
1770 result.SetStatus (eReturnStatusFailed);
1771 }
1772 return;
1773 }
1774
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001775 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
1776 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
1777 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
1778
1779 BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
1780
1781 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
1782
Greg Claytonc982c762010-07-09 20:39:50 +00001783 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001784
1785 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
1786 // and put into valid_ids.
1787
1788 if (result.Succeeded())
1789 {
1790 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
1791 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
1792
Greg Claytonc982c762010-07-09 20:39:50 +00001793 const size_t count = valid_ids->GetSize();
1794 for (size_t i = 0; i < count; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001795 {
1796 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
1797 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1798 if (breakpoint != NULL)
1799 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001800 const size_t num_locations = breakpoint->GetNumLocations();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001801 if (cur_bp_id.GetLocationID() > num_locations)
1802 {
1803 StreamString id_str;
Greg Claytonc982c762010-07-09 20:39:50 +00001804 BreakpointID::GetCanonicalReference (&id_str,
1805 cur_bp_id.GetBreakpointID(),
1806 cur_bp_id.GetLocationID());
1807 i = valid_ids->GetSize() + 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001808 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
1809 id_str.GetData());
1810 result.SetStatus (eReturnStatusFailed);
1811 }
1812 }
1813 else
1814 {
Greg Claytonc982c762010-07-09 20:39:50 +00001815 i = valid_ids->GetSize() + 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001816 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
1817 result.SetStatus (eReturnStatusFailed);
1818 }
1819 }
1820 }
1821}