blob: d8cfe0e22afdad9a026954d30789ae5c9b0194e1 [file] [log] [blame]
Chris Lattner24943d22010-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 Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner24943d22010-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 Ingham84cdc152010-06-15 19:49:27 +000022#include "lldb/Interpreter/Options.h"
Chris Lattner24943d22010-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 Ingham3c7b5b92010-06-16 02:00:15 +000030#include "lldb/Target/Thread.h"
31#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000032
Johnny Chena62ad7c2010-10-28 17:27:46 +000033#include <vector>
34
Chris Lattner24943d22010-06-08 16:52:24 +000035using namespace lldb;
36using namespace lldb_private;
37
38static void
Jim Ingham2e8cb8a2011-02-19 02:53:09 +000039AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level)
Chris Lattner24943d22010-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 Inghamda26bd22012-06-08 21:56:10 +000048// CommandObjectBreakpointSet
Chris Lattner24943d22010-06-08 16:52:24 +000049//-------------------------------------------------------------------------
50
Jim Inghamda26bd22012-06-08 21:56:10 +000051
52class CommandObjectBreakpointSet : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +000053{
Jim Inghamda26bd22012-06-08 21:56:10 +000054public:
Chris Lattner24943d22010-06-08 16:52:24 +000055
Jim Inghamda26bd22012-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 Lattner24943d22010-06-08 16:52:24 +000066
Jim Inghamda26bd22012-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 Inghamda26bd22012-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 Clayton49ce8962012-08-29 21:13:06 +0000108 m_throw_bp (true),
Jim Inghamda26bd22012-06-08 21:56:10 +0000109 m_language (eLanguageTypeUnknown),
Jim Ingham2753a022012-10-05 19:16:31 +0000110 m_skip_prologue (eLazyBoolCalculate),
111 m_one_shot (false)
Jim Inghamda26bd22012-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 Clayton6475c422012-12-04 00:32:51 +0000123 const int short_option = m_getopt_table[option_idx].val;
Jim Inghamda26bd22012-06-08 21:56:10 +0000124
125 switch (short_option)
126 {
127 case 'a':
128 m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0);
129 if (m_load_addr == LLDB_INVALID_ADDRESS)
130 m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16);
131
132 if (m_load_addr == LLDB_INVALID_ADDRESS)
133 error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg);
134 break;
135
Jim Ingham2753a022012-10-05 19:16:31 +0000136 case 'b':
137 m_func_names.push_back (option_arg);
138 m_func_name_type_mask |= eFunctionNameTypeBase;
139 break;
140
Jim Inghamda26bd22012-06-08 21:56:10 +0000141 case 'C':
142 m_column = Args::StringToUInt32 (option_arg, 0);
143 break;
144
145 case 'c':
146 m_condition.assign(option_arg);
147 break;
148
Jim Inghamda26bd22012-06-08 21:56:10 +0000149 case 'E':
150 {
151 LanguageType language = LanguageRuntime::GetLanguageTypeFromString (option_arg);
152
153 switch (language)
154 {
155 case eLanguageTypeC89:
156 case eLanguageTypeC:
157 case eLanguageTypeC99:
158 m_language = eLanguageTypeC;
159 break;
160 case eLanguageTypeC_plus_plus:
161 m_language = eLanguageTypeC_plus_plus;
162 break;
163 case eLanguageTypeObjC:
164 m_language = eLanguageTypeObjC;
165 break;
166 case eLanguageTypeObjC_plus_plus:
167 error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c");
168 break;
169 case eLanguageTypeUnknown:
170 error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg);
171 break;
172 default:
173 error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg);
174 }
175 }
176 break;
Jim Ingham2753a022012-10-05 19:16:31 +0000177
178 case 'f':
179 m_filenames.AppendIfUnique (FileSpec(option_arg, false));
180 break;
181
182 case 'F':
183 m_func_names.push_back (option_arg);
184 m_func_name_type_mask |= eFunctionNameTypeFull;
185 break;
186
Jim Inghamda26bd22012-06-08 21:56:10 +0000187 case 'h':
188 {
189 bool success;
190 m_catch_bp = Args::StringToBoolean (option_arg, true, &success);
191 if (!success)
192 error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg);
193 }
Jim Ingham2753a022012-10-05 19:16:31 +0000194
195 case 'i':
196 {
197 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
198 if (m_ignore_count == UINT32_MAX)
199 error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
200 break;
201 }
202
Jim Inghamda26bd22012-06-08 21:56:10 +0000203 case 'K':
204 {
205 bool success;
206 bool value;
207 value = Args::StringToBoolean (option_arg, true, &success);
208 if (value)
209 m_skip_prologue = eLazyBoolYes;
210 else
211 m_skip_prologue = eLazyBoolNo;
212
213 if (!success)
214 error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg);
215 }
216 break;
Jim Ingham2753a022012-10-05 19:16:31 +0000217
218 case 'l':
219 m_line_num = Args::StringToUInt32 (option_arg, 0);
220 break;
221
222 case 'M':
223 m_func_names.push_back (option_arg);
224 m_func_name_type_mask |= eFunctionNameTypeMethod;
225 break;
226
227 case 'n':
228 m_func_names.push_back (option_arg);
229 m_func_name_type_mask |= eFunctionNameTypeAuto;
230 break;
231
232 case 'o':
233 m_one_shot = true;
234 break;
235
236 case 'p':
237 m_source_text_regexp.assign (option_arg);
238 break;
239
240 case 'q':
241 m_queue_name.assign (option_arg);
242 break;
243
244 case 'r':
245 m_func_regexp.assign (option_arg);
246 break;
247
248 case 's':
249 {
250 m_modules.AppendIfUnique (FileSpec (option_arg, false));
251 break;
252 }
253
254 case 'S':
255 m_func_names.push_back (option_arg);
256 m_func_name_type_mask |= eFunctionNameTypeSelector;
257 break;
258
259 case 't' :
260 {
261 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
262 if (m_thread_id == LLDB_INVALID_THREAD_ID)
263 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
264 }
265 break;
266
267 case 'T':
268 m_thread_name.assign (option_arg);
269 break;
270
271 case 'w':
272 {
273 bool success;
274 m_throw_bp = Args::StringToBoolean (option_arg, true, &success);
275 if (!success)
276 error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg);
277 }
278 break;
279
280 case 'x':
281 {
282 m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
283 if (m_thread_id == UINT32_MAX)
284 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
285
286 }
287 break;
288
Jim Inghamda26bd22012-06-08 21:56:10 +0000289 default:
290 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
291 break;
292 }
293
294 return error;
295 }
296 void
297 OptionParsingStarting ()
298 {
299 m_condition.clear();
300 m_filenames.Clear();
301 m_line_num = 0;
302 m_column = 0;
303 m_func_names.clear();
Greg Clayton49ce8962012-08-29 21:13:06 +0000304 m_func_name_type_mask = eFunctionNameTypeNone;
Jim Inghamda26bd22012-06-08 21:56:10 +0000305 m_func_regexp.clear();
Greg Clayton49ce8962012-08-29 21:13:06 +0000306 m_source_text_regexp.clear();
Jim Inghamda26bd22012-06-08 21:56:10 +0000307 m_modules.Clear();
Greg Clayton49ce8962012-08-29 21:13:06 +0000308 m_load_addr = LLDB_INVALID_ADDRESS;
Jim Inghamda26bd22012-06-08 21:56:10 +0000309 m_ignore_count = 0;
310 m_thread_id = LLDB_INVALID_THREAD_ID;
311 m_thread_index = UINT32_MAX;
312 m_thread_name.clear();
313 m_queue_name.clear();
Jim Inghamda26bd22012-06-08 21:56:10 +0000314 m_catch_bp = false;
315 m_throw_bp = true;
Greg Clayton49ce8962012-08-29 21:13:06 +0000316 m_language = eLanguageTypeUnknown;
Jim Inghamda26bd22012-06-08 21:56:10 +0000317 m_skip_prologue = eLazyBoolCalculate;
Jim Ingham2753a022012-10-05 19:16:31 +0000318 m_one_shot = false;
Jim Inghamda26bd22012-06-08 21:56:10 +0000319 }
320
321 const OptionDefinition*
322 GetDefinitions ()
323 {
324 return g_option_table;
325 }
326
327 // Options table: Required for subclasses of Options.
328
329 static OptionDefinition g_option_table[];
330
331 // Instance variables to hold the values for command options.
332
333 std::string m_condition;
334 FileSpecList m_filenames;
335 uint32_t m_line_num;
336 uint32_t m_column;
Jim Inghamda26bd22012-06-08 21:56:10 +0000337 std::vector<std::string> m_func_names;
338 uint32_t m_func_name_type_mask;
339 std::string m_func_regexp;
340 std::string m_source_text_regexp;
341 FileSpecList m_modules;
342 lldb::addr_t m_load_addr;
343 uint32_t m_ignore_count;
344 lldb::tid_t m_thread_id;
345 uint32_t m_thread_index;
346 std::string m_thread_name;
347 std::string m_queue_name;
348 bool m_catch_bp;
349 bool m_throw_bp;
350 lldb::LanguageType m_language;
351 LazyBool m_skip_prologue;
Jim Ingham2753a022012-10-05 19:16:31 +0000352 bool m_one_shot;
Jim Inghamda26bd22012-06-08 21:56:10 +0000353
354 };
355
356protected:
357 virtual bool
358 DoExecute (Args& command,
359 CommandReturnObject &result)
360 {
361 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
362 if (target == NULL)
363 {
364 result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command).");
365 result.SetStatus (eReturnStatusFailed);
366 return false;
367 }
368
369 // The following are the various types of breakpoints that could be set:
370 // 1). -f -l -p [-s -g] (setting breakpoint by source location)
371 // 2). -a [-s -g] (setting breakpoint by address)
372 // 3). -n [-s -g] (setting breakpoint by function name)
373 // 4). -r [-s -g] (setting breakpoint by function name regular expression)
374 // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text)
375 // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.)
376
377 BreakpointSetType break_type = eSetTypeInvalid;
378
379 if (m_options.m_line_num != 0)
380 break_type = eSetTypeFileAndLine;
381 else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
382 break_type = eSetTypeAddress;
383 else if (!m_options.m_func_names.empty())
384 break_type = eSetTypeFunctionName;
385 else if (!m_options.m_func_regexp.empty())
386 break_type = eSetTypeFunctionRegexp;
387 else if (!m_options.m_source_text_regexp.empty())
388 break_type = eSetTypeSourceRegexp;
389 else if (m_options.m_language != eLanguageTypeUnknown)
390 break_type = eSetTypeException;
391
392 Breakpoint *bp = NULL;
393 FileSpec module_spec;
Jim Inghamda26bd22012-06-08 21:56:10 +0000394 const bool internal = false;
395
Jim Inghamda26bd22012-06-08 21:56:10 +0000396 switch (break_type)
397 {
398 case eSetTypeFileAndLine: // Breakpoint by source position
399 {
400 FileSpec file;
401 uint32_t num_files = m_options.m_filenames.GetSize();
402 if (num_files == 0)
403 {
404 if (!GetDefaultFile (target, file, result))
405 {
406 result.AppendError("No file supplied and no default file available.");
407 result.SetStatus (eReturnStatusFailed);
408 return false;
409 }
410 }
411 else if (num_files > 1)
412 {
413 result.AppendError("Only one file at a time is allowed for file and line breakpoints.");
414 result.SetStatus (eReturnStatusFailed);
415 return false;
416 }
417 else
418 file = m_options.m_filenames.GetFileSpecAtIndex(0);
Greg Clayton49ce8962012-08-29 21:13:06 +0000419
420 // Only check for inline functions if
421 LazyBool check_inlines = eLazyBoolCalculate;
422
Jim Inghamda26bd22012-06-08 21:56:10 +0000423 bp = target->CreateBreakpoint (&(m_options.m_modules),
424 file,
425 m_options.m_line_num,
Greg Clayton49ce8962012-08-29 21:13:06 +0000426 check_inlines,
Jim Inghamda26bd22012-06-08 21:56:10 +0000427 m_options.m_skip_prologue,
428 internal).get();
429 }
430 break;
431
432 case eSetTypeAddress: // Breakpoint by address
433 bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
434 break;
435
436 case eSetTypeFunctionName: // Breakpoint by function name
437 {
438 uint32_t name_type_mask = m_options.m_func_name_type_mask;
439
440 if (name_type_mask == 0)
441 name_type_mask = eFunctionNameTypeAuto;
442
443 bp = target->CreateBreakpoint (&(m_options.m_modules),
444 &(m_options.m_filenames),
445 m_options.m_func_names,
446 name_type_mask,
447 m_options.m_skip_prologue,
448 internal).get();
449 }
450 break;
451
452 case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
453 {
454 RegularExpression regexp(m_options.m_func_regexp.c_str());
455 if (!regexp.IsValid())
456 {
457 char err_str[1024];
458 regexp.GetErrorAsCString(err_str, sizeof(err_str));
459 result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"",
460 err_str);
461 result.SetStatus (eReturnStatusFailed);
462 return false;
463 }
464
465 bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules),
466 &(m_options.m_filenames),
467 regexp,
468 m_options.m_skip_prologue,
469 internal).get();
470 }
471 break;
472 case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
473 {
474 int num_files = m_options.m_filenames.GetSize();
475
476 if (num_files == 0)
477 {
478 FileSpec file;
479 if (!GetDefaultFile (target, file, result))
480 {
481 result.AppendError ("No files provided and could not find default file.");
482 result.SetStatus (eReturnStatusFailed);
483 return false;
484 }
485 else
486 {
487 m_options.m_filenames.Append (file);
488 }
489 }
490
491 RegularExpression regexp(m_options.m_source_text_regexp.c_str());
492 if (!regexp.IsValid())
493 {
494 char err_str[1024];
495 regexp.GetErrorAsCString(err_str, sizeof(err_str));
496 result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"",
497 err_str);
498 result.SetStatus (eReturnStatusFailed);
499 return false;
500 }
501 bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules), &(m_options.m_filenames), regexp).get();
502 }
503 break;
504 case eSetTypeException:
505 {
506 bp = target->CreateExceptionBreakpoint (m_options.m_language, m_options.m_catch_bp, m_options.m_throw_bp).get();
507 }
508 break;
509 default:
510 break;
511 }
512
513 // Now set the various options that were passed in:
514 if (bp)
515 {
516 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
517 bp->SetThreadID (m_options.m_thread_id);
518
519 if (m_options.m_thread_index != UINT32_MAX)
520 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
521
522 if (!m_options.m_thread_name.empty())
523 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
524
525 if (!m_options.m_queue_name.empty())
526 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
527
528 if (m_options.m_ignore_count != 0)
529 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
530
531 if (!m_options.m_condition.empty())
532 bp->GetOptions()->SetCondition(m_options.m_condition.c_str());
Jim Ingham2753a022012-10-05 19:16:31 +0000533
534 bp->SetOneShot (m_options.m_one_shot);
Jim Inghamda26bd22012-06-08 21:56:10 +0000535 }
536
537 if (bp)
538 {
539 Stream &output_stream = result.GetOutputStream();
Jim Ingham4f61ba92012-09-22 00:04:04 +0000540 const bool show_locations = false;
541 bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, show_locations);
Jim Inghamda26bd22012-06-08 21:56:10 +0000542 // Don't print out this warning for exception breakpoints. They can get set before the target
543 // is set, but we won't know how to actually set the breakpoint till we run.
544 if (bp->GetNumLocations() == 0 && break_type != eSetTypeException)
545 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n");
546 result.SetStatus (eReturnStatusSuccessFinishResult);
547 }
548 else if (!bp)
549 {
550 result.AppendError ("Breakpoint creation failed: No breakpoint created.");
551 result.SetStatus (eReturnStatusFailed);
552 }
553
554 return result.Succeeded();
555 }
556
557private:
558 bool
559 GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result)
560 {
561 uint32_t default_line;
562 // First use the Source Manager's default file.
563 // Then use the current stack frame's file.
564 if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line))
565 {
566 StackFrame *cur_frame = m_interpreter.GetExecutionContext().GetFramePtr();
567 if (cur_frame == NULL)
568 {
569 result.AppendError ("No selected frame to use to find the default file.");
570 result.SetStatus (eReturnStatusFailed);
571 return false;
572 }
573 else if (!cur_frame->HasDebugInformation())
574 {
575 result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info.");
576 result.SetStatus (eReturnStatusFailed);
577 return false;
578 }
579 else
580 {
581 const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
582 if (sc.line_entry.file)
583 {
584 file = sc.line_entry.file;
585 }
586 else
587 {
588 result.AppendError ("Can't find the file for the selected frame to use as the default file.");
589 result.SetStatus (eReturnStatusFailed);
590 return false;
591 }
592 }
593 }
594 return true;
595 }
596
597 CommandOptions m_options;
598};
Johnny Chen8d03c6f2012-05-08 00:43:20 +0000599// If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to
600// update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately.
Johnny Chen6f4a1152012-05-07 23:23:41 +0000601#define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 )
602#define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 )
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000603#define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) )
Jim Inghamd6d47972011-09-23 00:54:11 +0000604
Greg Claytonb3448432011-03-24 21:19:54 +0000605OptionDefinition
Chris Lattner24943d22010-06-08 16:52:24 +0000606CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
607{
Jim Ingham4722b102012-03-06 00:37:27 +0000608 { LLDB_OPT_NOT_10, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
Jim Inghamee033f22012-05-03 20:30:08 +0000609 "Set the breakpoint only in this shared library. "
610 "Can repeat this option multiple times to specify multiple shared libraries."},
Jim Ingham34e9a982010-06-15 18:47:14 +0000611
Caroline Tice4d6675c2010-10-01 19:59:14 +0000612 { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount,
613 "Set the number of times this breakpoint is skipped before stopping." },
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000614
Jim Ingham2753a022012-10-05 19:16:31 +0000615 { LLDB_OPT_SET_ALL, false, "one-shot", 'o', no_argument, NULL, 0, eArgTypeNone,
616 "The breakpoint is deleted the first time it stop causes a stop." },
617
Johnny Chene4f3cd72012-05-25 21:10:46 +0000618 { LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, 0, eArgTypeExpression,
619 "The breakpoint stops only if this condition expression evaluates to true."},
620
Bill Wendlingff7df6d2012-04-03 04:13:41 +0000621 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex,
Greg Claytonfe424a92010-09-18 03:37:20 +0000622 "The breakpoint stops only for the thread whose index matches this argument."},
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000623
Bill Wendlingff7df6d2012-04-03 04:13:41 +0000624 { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID,
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000625 "The breakpoint stops only for the thread whose TID matches this argument."},
626
Bill Wendlingff7df6d2012-04-03 04:13:41 +0000627 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName,
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000628 "The breakpoint stops only for the thread whose thread name matches this argument."},
629
Bill Wendlingff7df6d2012-04-03 04:13:41 +0000630 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName,
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000631 "The breakpoint stops only for threads in the queue whose name is given by this argument."},
632
Jim Inghamd6d47972011-09-23 00:54:11 +0000633 { LLDB_OPT_FILE, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
634 "Specifies the source file in which to set this breakpoint."},
Chris Lattner24943d22010-06-08 16:52:24 +0000635
Caroline Tice4d6675c2010-10-01 19:59:14 +0000636 { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
Jim Inghamd6d47972011-09-23 00:54:11 +0000637 "Specifies the line number on which to set this breakpoint."},
Chris Lattner24943d22010-06-08 16:52:24 +0000638
Chris Lattner24943d22010-06-08 16:52:24 +0000639 // Comment out this option for the moment, as we don't actually use it, but will in the future.
640 // This way users won't see it, but the infrastructure is left in place.
Johnny Chene4f3cd72012-05-25 21:10:46 +0000641 // { 0, false, "column", 'C', required_argument, NULL, "<column>",
Chris Lattner24943d22010-06-08 16:52:24 +0000642 // "Set the breakpoint by source location at this particular column."},
643
Caroline Tice4d6675c2010-10-01 19:59:14 +0000644 { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress,
Chris Lattner24943d22010-06-08 16:52:24 +0000645 "Set the breakpoint by address, at the specified address."},
646
Caroline Tice4d6675c2010-10-01 19:59:14 +0000647 { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Jim Inghamee033f22012-05-03 20:30:08 +0000648 "Set the breakpoint by function name. Can be repeated multiple times to make one breakpoint for multiple snames" },
Chris Lattner24943d22010-06-08 16:52:24 +0000649
Caroline Tice4d6675c2010-10-01 19:59:14 +0000650 { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
Jim Inghamee033f22012-05-03 20:30:08 +0000651 "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and "
652 "for Objective C this means a full function prototype with class and selector. "
653 "Can be repeated multiple times to make one breakpoint for multiple names." },
Greg Clayton12bec712010-06-28 21:30:43 +0000654
Caroline Tice4d6675c2010-10-01 19:59:14 +0000655 { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector,
Jim Inghamee033f22012-05-03 20:30:08 +0000656 "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." },
Greg Clayton12bec712010-06-28 21:30:43 +0000657
Caroline Tice4d6675c2010-10-01 19:59:14 +0000658 { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod,
Jim Inghamee033f22012-05-03 20:30:08 +0000659 "Set the breakpoint by C++ method names. Can be repeated multiple times to make one breakpoint for multiple methods." },
Greg Clayton12bec712010-06-28 21:30:43 +0000660
Caroline Tice4d6675c2010-10-01 19:59:14 +0000661 { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression,
Chris Lattner24943d22010-06-08 16:52:24 +0000662 "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
663
Greg Clayton48fbdf72010-10-12 04:29:14 +0000664 { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Jim Inghamee033f22012-05-03 20:30:08 +0000665 "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). "
666 "Can be repeated multiple times to make one breakpoint for multiple symbols." },
Greg Clayton48fbdf72010-10-12 04:29:14 +0000667
Jim Ingham03c8ee52011-09-21 01:17:13 +0000668 { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', required_argument, NULL, 0, eArgTypeRegularExpression,
669 "Set the breakpoint specifying a regular expression to match a pattern in the source text in a given source file." },
670
Jim Ingham4722b102012-03-06 00:37:27 +0000671 { LLDB_OPT_SET_10, true, "language-exception", 'E', required_argument, NULL, 0, eArgTypeLanguage,
672 "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" },
673
674 { LLDB_OPT_SET_10, false, "on-throw", 'w', required_argument, NULL, 0, eArgTypeBoolean,
675 "Set the breakpoint on exception throW." },
676
677 { LLDB_OPT_SET_10, false, "on-catch", 'h', required_argument, NULL, 0, eArgTypeBoolean,
678 "Set the breakpoint on exception catcH." },
Jim Ingham03c8ee52011-09-21 01:17:13 +0000679
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000680 { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', required_argument, NULL, 0, eArgTypeBoolean,
681 "sKip the prologue if the breakpoint is at the beginning of a function. If not set the target.skip-prologue setting is used." },
682
Caroline Tice4d6675c2010-10-01 19:59:14 +0000683 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000684};
685
Jim Inghamda26bd22012-06-08 21:56:10 +0000686//-------------------------------------------------------------------------
687// CommandObjectBreakpointModify
688//-------------------------------------------------------------------------
689#pragma mark Modify
Chris Lattner24943d22010-06-08 16:52:24 +0000690
Jim Inghamda26bd22012-06-08 21:56:10 +0000691class CommandObjectBreakpointModify : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +0000692{
Jim Inghamda26bd22012-06-08 21:56:10 +0000693public:
Chris Lattner24943d22010-06-08 16:52:24 +0000694
Jim Inghamda26bd22012-06-08 21:56:10 +0000695 CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
696 CommandObjectParsed (interpreter,
697 "breakpoint modify",
698 "Modify the options on a breakpoint or set of breakpoints in the executable. "
699 "If no breakpoint is specified, acts on the last created breakpoint. "
700 "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
701 NULL),
702 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000703 {
Jim Inghamda26bd22012-06-08 21:56:10 +0000704 CommandArgumentEntry arg;
705 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
706 // Add the entry for the first argument for this command to the object's arguments vector.
707 m_arguments.push_back (arg);
708 }
Chris Lattner24943d22010-06-08 16:52:24 +0000709
Chris Lattner24943d22010-06-08 16:52:24 +0000710
Jim Inghamda26bd22012-06-08 21:56:10 +0000711 virtual
712 ~CommandObjectBreakpointModify () {}
Greg Clayton12bec712010-06-28 21:30:43 +0000713
Jim Inghamda26bd22012-06-08 21:56:10 +0000714 virtual Options *
715 GetOptions ()
716 {
717 return &m_options;
718 }
Johnny Chene4f3cd72012-05-25 21:10:46 +0000719
Jim Inghamda26bd22012-06-08 21:56:10 +0000720 class CommandOptions : public Options
721 {
722 public:
Greg Clayton12bec712010-06-28 21:30:43 +0000723
Jim Inghamda26bd22012-06-08 21:56:10 +0000724 CommandOptions (CommandInterpreter &interpreter) :
725 Options (interpreter),
726 m_ignore_count (0),
727 m_thread_id(LLDB_INVALID_THREAD_ID),
728 m_thread_id_passed(false),
729 m_thread_index (UINT32_MAX),
730 m_thread_index_passed(false),
731 m_thread_name(),
732 m_queue_name(),
733 m_condition (),
Jim Ingham2753a022012-10-05 19:16:31 +0000734 m_one_shot (false),
Jim Inghamda26bd22012-06-08 21:56:10 +0000735 m_enable_passed (false),
736 m_enable_value (false),
737 m_name_passed (false),
738 m_queue_passed (false),
Jim Ingham2753a022012-10-05 19:16:31 +0000739 m_condition_passed (false),
740 m_one_shot_passed (false)
Jim Inghamda26bd22012-06-08 21:56:10 +0000741 {
742 }
Greg Clayton12bec712010-06-28 21:30:43 +0000743
Jim Inghamda26bd22012-06-08 21:56:10 +0000744 virtual
745 ~CommandOptions () {}
Greg Clayton12bec712010-06-28 21:30:43 +0000746
Jim Inghamda26bd22012-06-08 21:56:10 +0000747 virtual Error
748 SetOptionValue (uint32_t option_idx, const char *option_arg)
749 {
750 Error error;
Greg Clayton6475c422012-12-04 00:32:51 +0000751 const int short_option = m_getopt_table[option_idx].val;
Greg Clayton48fbdf72010-10-12 04:29:14 +0000752
Jim Inghamda26bd22012-06-08 21:56:10 +0000753 switch (short_option)
Chris Lattner24943d22010-06-08 16:52:24 +0000754 {
Jim Inghamda26bd22012-06-08 21:56:10 +0000755 case 'c':
756 if (option_arg != NULL)
757 m_condition.assign (option_arg);
758 else
759 m_condition.clear();
760 m_condition_passed = true;
761 break;
762 case 'd':
763 m_enable_passed = true;
764 m_enable_value = false;
765 break;
766 case 'e':
767 m_enable_passed = true;
768 m_enable_value = true;
769 break;
770 case 'i':
771 {
772 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
773 if (m_ignore_count == UINT32_MAX)
774 error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
775 }
Chris Lattner24943d22010-06-08 16:52:24 +0000776 break;
Jim Ingham2753a022012-10-05 19:16:31 +0000777 case 'o':
778 {
779 bool value, success;
780 value = Args::StringToBoolean(option_arg, false, &success);
781 if (success)
782 {
783 m_one_shot_passed = true;
784 m_one_shot = value;
785 }
786 else
787 error.SetErrorStringWithFormat("invalid boolean value '%s' passed for -o option", option_arg);
788 }
789 break;
Jim Inghamda26bd22012-06-08 21:56:10 +0000790 case 't' :
Jim Inghamd6d47972011-09-23 00:54:11 +0000791 {
Jim Inghamda26bd22012-06-08 21:56:10 +0000792 if (option_arg[0] == '\0')
Jim Inghamd6d47972011-09-23 00:54:11 +0000793 {
Jim Inghamda26bd22012-06-08 21:56:10 +0000794 m_thread_id = LLDB_INVALID_THREAD_ID;
795 m_thread_id_passed = true;
Jim Inghamd6d47972011-09-23 00:54:11 +0000796 }
797 else
798 {
Jim Inghamda26bd22012-06-08 21:56:10 +0000799 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
800 if (m_thread_id == LLDB_INVALID_THREAD_ID)
801 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
802 else
803 m_thread_id_passed = true;
Jim Inghamd6d47972011-09-23 00:54:11 +0000804 }
805 }
Jim Inghamda26bd22012-06-08 21:56:10 +0000806 break;
807 case 'T':
808 if (option_arg != NULL)
809 m_thread_name.assign (option_arg);
810 else
811 m_thread_name.clear();
812 m_name_passed = true;
813 break;
814 case 'q':
815 if (option_arg != NULL)
816 m_queue_name.assign (option_arg);
817 else
818 m_queue_name.clear();
819 m_queue_passed = true;
820 break;
821 case 'x':
Jim Ingham03c8ee52011-09-21 01:17:13 +0000822 {
Jim Inghamda26bd22012-06-08 21:56:10 +0000823 if (option_arg[0] == '\n')
824 {
825 m_thread_index = UINT32_MAX;
826 m_thread_index_passed = true;
827 }
828 else
829 {
830 m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0);
831 if (m_thread_id == UINT32_MAX)
832 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
833 else
834 m_thread_index_passed = true;
835 }
Jim Ingham03c8ee52011-09-21 01:17:13 +0000836 }
Jim Inghamda26bd22012-06-08 21:56:10 +0000837 break;
838 default:
839 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
840 break;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000841 }
Jim Inghamda26bd22012-06-08 21:56:10 +0000842
843 return error;
844 }
845 void
846 OptionParsingStarting ()
847 {
848 m_ignore_count = 0;
849 m_thread_id = LLDB_INVALID_THREAD_ID;
850 m_thread_id_passed = false;
851 m_thread_index = UINT32_MAX;
852 m_thread_index_passed = false;
853 m_thread_name.clear();
854 m_queue_name.clear();
855 m_condition.clear();
Jim Ingham2753a022012-10-05 19:16:31 +0000856 m_one_shot = false;
Jim Inghamda26bd22012-06-08 21:56:10 +0000857 m_enable_passed = false;
858 m_queue_passed = false;
859 m_name_passed = false;
860 m_condition_passed = false;
Jim Ingham2753a022012-10-05 19:16:31 +0000861 m_one_shot_passed = false;
Jim Inghamda26bd22012-06-08 21:56:10 +0000862 }
863
864 const OptionDefinition*
865 GetDefinitions ()
866 {
867 return g_option_table;
868 }
869
870
871 // Options table: Required for subclasses of Options.
872
873 static OptionDefinition g_option_table[];
874
875 // Instance variables to hold the values for command options.
876
877 uint32_t m_ignore_count;
878 lldb::tid_t m_thread_id;
879 bool m_thread_id_passed;
880 uint32_t m_thread_index;
881 bool m_thread_index_passed;
882 std::string m_thread_name;
883 std::string m_queue_name;
884 std::string m_condition;
Jim Ingham2753a022012-10-05 19:16:31 +0000885 bool m_one_shot;
Jim Inghamda26bd22012-06-08 21:56:10 +0000886 bool m_enable_passed;
887 bool m_enable_value;
888 bool m_name_passed;
889 bool m_queue_passed;
890 bool m_condition_passed;
Jim Ingham2753a022012-10-05 19:16:31 +0000891 bool m_one_shot_passed;
Jim Inghamda26bd22012-06-08 21:56:10 +0000892
893 };
894
895protected:
896 virtual bool
897 DoExecute (Args& command, CommandReturnObject &result)
898 {
899 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
900 if (target == NULL)
901 {
902 result.AppendError ("Invalid target. No existing target or breakpoints.");
903 result.SetStatus (eReturnStatusFailed);
904 return false;
905 }
906
907 Mutex::Locker locker;
908 target->GetBreakpointList().GetListMutex(locker);
909
910 BreakpointIDList valid_bp_ids;
911
912 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
913
914 if (result.Succeeded())
915 {
916 const size_t count = valid_bp_ids.GetSize();
917 for (size_t i = 0; i < count; ++i)
Jim Ingham4722b102012-03-06 00:37:27 +0000918 {
Jim Inghamda26bd22012-06-08 21:56:10 +0000919 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
920
921 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
922 {
923 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
924 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
925 {
926 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
927 if (location)
928 {
929 if (m_options.m_thread_id_passed)
930 location->SetThreadID (m_options.m_thread_id);
931
932 if (m_options.m_thread_index_passed)
933 location->SetThreadIndex(m_options.m_thread_index);
934
935 if (m_options.m_name_passed)
936 location->SetThreadName(m_options.m_thread_name.c_str());
937
938 if (m_options.m_queue_passed)
939 location->SetQueueName(m_options.m_queue_name.c_str());
940
941 if (m_options.m_ignore_count != 0)
942 location->SetIgnoreCount(m_options.m_ignore_count);
943
944 if (m_options.m_enable_passed)
945 location->SetEnabled (m_options.m_enable_value);
946
947 if (m_options.m_condition_passed)
948 location->SetCondition (m_options.m_condition.c_str());
949 }
950 }
951 else
952 {
953 if (m_options.m_thread_id_passed)
954 bp->SetThreadID (m_options.m_thread_id);
955
956 if (m_options.m_thread_index_passed)
957 bp->SetThreadIndex(m_options.m_thread_index);
958
959 if (m_options.m_name_passed)
960 bp->SetThreadName(m_options.m_thread_name.c_str());
961
962 if (m_options.m_queue_passed)
963 bp->SetQueueName(m_options.m_queue_name.c_str());
964
965 if (m_options.m_ignore_count != 0)
966 bp->SetIgnoreCount(m_options.m_ignore_count);
967
968 if (m_options.m_enable_passed)
969 bp->SetEnabled (m_options.m_enable_value);
970
971 if (m_options.m_condition_passed)
972 bp->SetCondition (m_options.m_condition.c_str());
973 }
974 }
Jim Ingham4722b102012-03-06 00:37:27 +0000975 }
Jim Inghamda26bd22012-06-08 21:56:10 +0000976 }
977
978 return result.Succeeded();
Chris Lattner24943d22010-06-08 16:52:24 +0000979 }
980
Jim Inghamda26bd22012-06-08 21:56:10 +0000981private:
982 CommandOptions m_options;
983};
Johnny Chene4f3cd72012-05-25 21:10:46 +0000984
Jim Inghamda26bd22012-06-08 21:56:10 +0000985#pragma mark Modify::CommandOptions
986OptionDefinition
987CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
988{
989{ 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 Ingham2753a022012-10-05 19:16:31 +0000990{ 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 Inghamda26bd22012-06-08 21:56:10 +0000991{ 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."},
992{ 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."},
993{ 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."},
994{ 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."},
995{ LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."},
996{ LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, 0, eArgTypeNone, "Enable the breakpoint."},
997{ LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, 0, eArgTypeNone, "Disable the breakpoint."},
Jim Ingham2753a022012-10-05 19:16:31 +0000998{ 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL }
Jim Inghamda26bd22012-06-08 21:56:10 +0000999};
1000
1001//-------------------------------------------------------------------------
1002// CommandObjectBreakpointEnable
1003//-------------------------------------------------------------------------
1004#pragma mark Enable
1005
1006class CommandObjectBreakpointEnable : public CommandObjectParsed
1007{
1008public:
1009 CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
1010 CommandObjectParsed (interpreter,
1011 "enable",
1012 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
1013 NULL)
1014 {
1015 CommandArgumentEntry arg;
1016 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1017 // Add the entry for the first argument for this command to the object's arguments vector.
1018 m_arguments.push_back (arg);
1019 }
1020
1021
1022 virtual
1023 ~CommandObjectBreakpointEnable () {}
1024
1025protected:
1026 virtual bool
1027 DoExecute (Args& command, CommandReturnObject &result)
1028 {
1029 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1030 if (target == NULL)
1031 {
1032 result.AppendError ("Invalid target. No existing target or breakpoints.");
1033 result.SetStatus (eReturnStatusFailed);
1034 return false;
1035 }
1036
1037 Mutex::Locker locker;
1038 target->GetBreakpointList().GetListMutex(locker);
1039
1040 const BreakpointList &breakpoints = target->GetBreakpointList();
1041
1042 size_t num_breakpoints = breakpoints.GetSize();
1043
1044 if (num_breakpoints == 0)
1045 {
1046 result.AppendError ("No breakpoints exist to be enabled.");
1047 result.SetStatus (eReturnStatusFailed);
1048 return false;
1049 }
1050
1051 if (command.GetArgumentCount() == 0)
1052 {
1053 // No breakpoint selected; enable all currently set breakpoints.
1054 target->EnableAllBreakpoints ();
1055 result.AppendMessageWithFormat ("All breakpoints enabled. (%lu breakpoints)\n", num_breakpoints);
1056 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1057 }
1058 else
1059 {
1060 // Particular breakpoint selected; enable that breakpoint.
1061 BreakpointIDList valid_bp_ids;
1062 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1063
1064 if (result.Succeeded())
1065 {
1066 int enable_count = 0;
1067 int loc_count = 0;
1068 const size_t count = valid_bp_ids.GetSize();
1069 for (size_t i = 0; i < count; ++i)
1070 {
1071 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1072
1073 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1074 {
1075 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1076 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1077 {
1078 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1079 if (location)
1080 {
1081 location->SetEnabled (true);
1082 ++loc_count;
1083 }
1084 }
1085 else
1086 {
1087 breakpoint->SetEnabled (true);
1088 ++enable_count;
1089 }
1090 }
1091 }
1092 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
1093 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1094 }
1095 }
1096
1097 return result.Succeeded();
1098 }
1099};
1100
1101//-------------------------------------------------------------------------
1102// CommandObjectBreakpointDisable
1103//-------------------------------------------------------------------------
1104#pragma mark Disable
1105
1106class CommandObjectBreakpointDisable : public CommandObjectParsed
1107{
1108public:
1109 CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
1110 CommandObjectParsed (interpreter,
1111 "breakpoint disable",
1112 "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.",
1113 NULL)
1114 {
1115 CommandArgumentEntry arg;
1116 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1117 // Add the entry for the first argument for this command to the object's arguments vector.
1118 m_arguments.push_back (arg);
1119 }
1120
1121
1122 virtual
1123 ~CommandObjectBreakpointDisable () {}
1124
1125protected:
1126 virtual bool
1127 DoExecute (Args& command, CommandReturnObject &result)
1128 {
1129 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1130 if (target == NULL)
1131 {
1132 result.AppendError ("Invalid target. No existing target or breakpoints.");
1133 result.SetStatus (eReturnStatusFailed);
1134 return false;
1135 }
1136
1137 Mutex::Locker locker;
1138 target->GetBreakpointList().GetListMutex(locker);
1139
1140 const BreakpointList &breakpoints = target->GetBreakpointList();
1141 size_t num_breakpoints = breakpoints.GetSize();
1142
1143 if (num_breakpoints == 0)
1144 {
1145 result.AppendError ("No breakpoints exist to be disabled.");
1146 result.SetStatus (eReturnStatusFailed);
1147 return false;
1148 }
1149
1150 if (command.GetArgumentCount() == 0)
1151 {
1152 // No breakpoint selected; disable all currently set breakpoints.
1153 target->DisableAllBreakpoints ();
1154 result.AppendMessageWithFormat ("All breakpoints disabled. (%lu breakpoints)\n", num_breakpoints);
1155 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1156 }
1157 else
1158 {
1159 // Particular breakpoint selected; disable that breakpoint.
1160 BreakpointIDList valid_bp_ids;
1161
1162 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1163
1164 if (result.Succeeded())
1165 {
1166 int disable_count = 0;
1167 int loc_count = 0;
1168 const size_t count = valid_bp_ids.GetSize();
1169 for (size_t i = 0; i < count; ++i)
1170 {
1171 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1172
1173 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1174 {
1175 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1176 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1177 {
1178 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1179 if (location)
1180 {
1181 location->SetEnabled (false);
1182 ++loc_count;
1183 }
1184 }
1185 else
1186 {
1187 breakpoint->SetEnabled (false);
1188 ++disable_count;
1189 }
1190 }
1191 }
1192 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
1193 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1194 }
1195 }
1196
1197 return result.Succeeded();
1198 }
1199
1200};
1201
1202//-------------------------------------------------------------------------
1203// CommandObjectBreakpointList
1204//-------------------------------------------------------------------------
1205#pragma mark List
1206
1207class CommandObjectBreakpointList : public CommandObjectParsed
1208{
1209public:
1210 CommandObjectBreakpointList (CommandInterpreter &interpreter) :
1211 CommandObjectParsed (interpreter,
1212 "breakpoint list",
1213 "List some or all breakpoints at configurable levels of detail.",
1214 NULL),
1215 m_options (interpreter)
1216 {
1217 CommandArgumentEntry arg;
1218 CommandArgumentData bp_id_arg;
1219
1220 // Define the first (and only) variant of this arg.
1221 bp_id_arg.arg_type = eArgTypeBreakpointID;
1222 bp_id_arg.arg_repetition = eArgRepeatOptional;
1223
1224 // There is only one variant this argument could be; put it into the argument entry.
1225 arg.push_back (bp_id_arg);
1226
1227 // Push the data for the first argument into the m_arguments vector.
1228 m_arguments.push_back (arg);
1229 }
1230
1231
1232 virtual
1233 ~CommandObjectBreakpointList () {}
1234
1235 virtual Options *
1236 GetOptions ()
1237 {
1238 return &m_options;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001239 }
1240
Jim Inghamda26bd22012-06-08 21:56:10 +00001241 class CommandOptions : public Options
Chris Lattner24943d22010-06-08 16:52:24 +00001242 {
Jim Inghamda26bd22012-06-08 21:56:10 +00001243 public:
1244
1245 CommandOptions (CommandInterpreter &interpreter) :
1246 Options (interpreter),
1247 m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions
1248 {
1249 }
1250
1251 virtual
1252 ~CommandOptions () {}
1253
1254 virtual Error
1255 SetOptionValue (uint32_t option_idx, const char *option_arg)
1256 {
1257 Error error;
Greg Clayton6475c422012-12-04 00:32:51 +00001258 const int short_option = m_getopt_table[option_idx].val;
Jim Inghamda26bd22012-06-08 21:56:10 +00001259
1260 switch (short_option)
1261 {
1262 case 'b':
1263 m_level = lldb::eDescriptionLevelBrief;
1264 break;
1265 case 'f':
1266 m_level = lldb::eDescriptionLevelFull;
1267 break;
1268 case 'v':
1269 m_level = lldb::eDescriptionLevelVerbose;
1270 break;
1271 case 'i':
1272 m_internal = true;
1273 break;
1274 default:
1275 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1276 break;
1277 }
1278
1279 return error;
1280 }
1281
1282 void
1283 OptionParsingStarting ()
1284 {
1285 m_level = lldb::eDescriptionLevelFull;
1286 m_internal = false;
1287 }
1288
1289 const OptionDefinition *
1290 GetDefinitions ()
1291 {
1292 return g_option_table;
1293 }
1294
1295 // Options table: Required for subclasses of Options.
1296
1297 static OptionDefinition g_option_table[];
1298
1299 // Instance variables to hold the values for command options.
1300
1301 lldb::DescriptionLevel m_level;
1302
1303 bool m_internal;
1304 };
1305
1306protected:
1307 virtual bool
1308 DoExecute (Args& command, CommandReturnObject &result)
1309 {
1310 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1311 if (target == NULL)
1312 {
1313 result.AppendError ("Invalid target. No current target or breakpoints.");
1314 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1315 return true;
1316 }
1317
1318 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
1319 Mutex::Locker locker;
1320 target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
1321
1322 size_t num_breakpoints = breakpoints.GetSize();
1323
1324 if (num_breakpoints == 0)
1325 {
1326 result.AppendMessage ("No breakpoints currently set.");
1327 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1328 return true;
1329 }
1330
Jim Ingham2e8cb8a2011-02-19 02:53:09 +00001331 Stream &output_stream = result.GetOutputStream();
Jim Inghamda26bd22012-06-08 21:56:10 +00001332
1333 if (command.GetArgumentCount() == 0)
1334 {
1335 // No breakpoint selected; show info about all currently set breakpoints.
1336 result.AppendMessage ("Current breakpoints:");
1337 for (size_t i = 0; i < num_breakpoints; ++i)
1338 {
1339 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
1340 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
1341 }
1342 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1343 }
1344 else
1345 {
1346 // Particular breakpoints selected; show info about that breakpoint.
1347 BreakpointIDList valid_bp_ids;
1348 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1349
1350 if (result.Succeeded())
1351 {
1352 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
1353 {
1354 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1355 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1356 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
1357 }
1358 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1359 }
1360 else
1361 {
1362 result.AppendError ("Invalid breakpoint id.");
1363 result.SetStatus (eReturnStatusFailed);
1364 }
1365 }
1366
1367 return result.Succeeded();
Chris Lattner24943d22010-06-08 16:52:24 +00001368 }
1369
Jim Inghamda26bd22012-06-08 21:56:10 +00001370private:
1371 CommandOptions m_options;
1372};
1373
1374#pragma mark List::CommandOptions
1375OptionDefinition
1376CommandObjectBreakpointList::CommandOptions::g_option_table[] =
1377{
1378 { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone,
1379 "Show debugger internal breakpoints" },
1380
1381 { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone,
1382 "Give a brief description of the breakpoint (no location info)."},
1383
1384 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
1385 // But I need to see it for now, and don't want to wait.
1386 { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone,
1387 "Give a full description of the breakpoint and its locations."},
1388
1389 { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone,
1390 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
1391
1392 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1393};
1394
1395//-------------------------------------------------------------------------
1396// CommandObjectBreakpointClear
1397//-------------------------------------------------------------------------
1398#pragma mark Clear
1399
1400class CommandObjectBreakpointClear : public CommandObjectParsed
1401{
1402public:
1403
1404 typedef enum BreakpointClearType
1405 {
1406 eClearTypeInvalid,
1407 eClearTypeFileAndLine
1408 } BreakpointClearType;
1409
1410 CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
1411 CommandObjectParsed (interpreter,
1412 "breakpoint clear",
1413 "Clears a breakpoint or set of breakpoints in the executable.",
1414 "breakpoint clear <cmd-options>"),
1415 m_options (interpreter)
1416 {
1417 }
1418
1419 virtual
1420 ~CommandObjectBreakpointClear () {}
1421
1422 virtual Options *
1423 GetOptions ()
1424 {
1425 return &m_options;
1426 }
1427
1428 class CommandOptions : public Options
1429 {
1430 public:
1431
1432 CommandOptions (CommandInterpreter &interpreter) :
1433 Options (interpreter),
1434 m_filename (),
1435 m_line_num (0)
1436 {
1437 }
1438
1439 virtual
1440 ~CommandOptions () {}
1441
1442 virtual Error
1443 SetOptionValue (uint32_t option_idx, const char *option_arg)
1444 {
1445 Error error;
Greg Clayton6475c422012-12-04 00:32:51 +00001446 const int short_option = m_getopt_table[option_idx].val;
Jim Inghamda26bd22012-06-08 21:56:10 +00001447
1448 switch (short_option)
1449 {
1450 case 'f':
1451 m_filename.assign (option_arg);
1452 break;
1453
1454 case 'l':
1455 m_line_num = Args::StringToUInt32 (option_arg, 0);
1456 break;
1457
1458 default:
1459 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1460 break;
1461 }
1462
1463 return error;
1464 }
1465
1466 void
1467 OptionParsingStarting ()
1468 {
1469 m_filename.clear();
1470 m_line_num = 0;
1471 }
1472
1473 const OptionDefinition*
1474 GetDefinitions ()
1475 {
1476 return g_option_table;
1477 }
1478
1479 // Options table: Required for subclasses of Options.
1480
1481 static OptionDefinition g_option_table[];
1482
1483 // Instance variables to hold the values for command options.
1484
1485 std::string m_filename;
1486 uint32_t m_line_num;
1487
1488 };
1489
1490protected:
1491 virtual bool
1492 DoExecute (Args& command, CommandReturnObject &result)
1493 {
1494 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1495 if (target == NULL)
1496 {
1497 result.AppendError ("Invalid target. No existing target or breakpoints.");
1498 result.SetStatus (eReturnStatusFailed);
1499 return false;
1500 }
1501
1502 // The following are the various types of breakpoints that could be cleared:
1503 // 1). -f -l (clearing breakpoint by source location)
1504
1505 BreakpointClearType break_type = eClearTypeInvalid;
1506
1507 if (m_options.m_line_num != 0)
1508 break_type = eClearTypeFileAndLine;
1509
1510 Mutex::Locker locker;
1511 target->GetBreakpointList().GetListMutex(locker);
1512
1513 BreakpointList &breakpoints = target->GetBreakpointList();
1514 size_t num_breakpoints = breakpoints.GetSize();
1515
1516 // Early return if there's no breakpoint at all.
1517 if (num_breakpoints == 0)
1518 {
1519 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1520 result.SetStatus (eReturnStatusFailed);
1521 return result.Succeeded();
1522 }
1523
1524 // Find matching breakpoints and delete them.
1525
1526 // First create a copy of all the IDs.
1527 std::vector<break_id_t> BreakIDs;
1528 for (size_t i = 0; i < num_breakpoints; ++i)
1529 BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID());
1530
1531 int num_cleared = 0;
1532 StreamString ss;
1533 switch (break_type)
1534 {
1535 case eClearTypeFileAndLine: // Breakpoint by source position
1536 {
1537 const ConstString filename(m_options.m_filename.c_str());
1538 BreakpointLocationCollection loc_coll;
1539
1540 for (size_t i = 0; i < num_breakpoints; ++i)
1541 {
1542 Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
1543
1544 if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
1545 {
1546 // If the collection size is 0, it's a full match and we can just remove the breakpoint.
1547 if (loc_coll.GetSize() == 0)
1548 {
1549 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
1550 ss.EOL();
1551 target->RemoveBreakpointByID (bp->GetID());
1552 ++num_cleared;
1553 }
1554 }
1555 }
1556 }
1557 break;
1558
1559 default:
1560 break;
1561 }
1562
1563 if (num_cleared > 0)
1564 {
1565 Stream &output_stream = result.GetOutputStream();
1566 output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
1567 output_stream << ss.GetData();
1568 output_stream.EOL();
1569 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1570 }
1571 else
1572 {
1573 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1574 result.SetStatus (eReturnStatusFailed);
1575 }
1576
1577 return result.Succeeded();
1578 }
1579
1580private:
1581 CommandOptions m_options;
1582};
1583
1584#pragma mark Clear::CommandOptions
1585
1586OptionDefinition
1587CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
1588{
1589 { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
1590 "Specify the breakpoint by source location in this particular file."},
1591
1592 { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
1593 "Specify the breakpoint by source location at this particular line."},
1594
1595 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1596};
1597
1598//-------------------------------------------------------------------------
1599// CommandObjectBreakpointDelete
1600//-------------------------------------------------------------------------
1601#pragma mark Delete
1602
1603class CommandObjectBreakpointDelete : public CommandObjectParsed
1604{
1605public:
1606 CommandObjectBreakpointDelete (CommandInterpreter &interpreter) :
1607 CommandObjectParsed (interpreter,
1608 "breakpoint delete",
1609 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
1610 NULL)
1611 {
1612 CommandArgumentEntry arg;
1613 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1614 // Add the entry for the first argument for this command to the object's arguments vector.
1615 m_arguments.push_back (arg);
1616 }
1617
1618 virtual
1619 ~CommandObjectBreakpointDelete () {}
1620
1621protected:
1622 virtual bool
1623 DoExecute (Args& command, CommandReturnObject &result)
1624 {
1625 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1626 if (target == NULL)
1627 {
1628 result.AppendError ("Invalid target. No existing target or breakpoints.");
1629 result.SetStatus (eReturnStatusFailed);
1630 return false;
1631 }
1632
1633 Mutex::Locker locker;
1634 target->GetBreakpointList().GetListMutex(locker);
1635
1636 const BreakpointList &breakpoints = target->GetBreakpointList();
1637
1638 size_t num_breakpoints = breakpoints.GetSize();
1639
1640 if (num_breakpoints == 0)
1641 {
1642 result.AppendError ("No breakpoints exist to be deleted.");
1643 result.SetStatus (eReturnStatusFailed);
1644 return false;
1645 }
1646
1647 if (command.GetArgumentCount() == 0)
1648 {
1649 if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
1650 {
1651 result.AppendMessage("Operation cancelled...");
1652 }
1653 else
1654 {
1655 target->RemoveAllBreakpoints ();
1656 result.AppendMessageWithFormat ("All breakpoints removed. (%lu breakpoints)\n", num_breakpoints);
1657 }
1658 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1659 }
1660 else
1661 {
1662 // Particular breakpoint selected; disable that breakpoint.
1663 BreakpointIDList valid_bp_ids;
1664 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1665
1666 if (result.Succeeded())
1667 {
1668 int delete_count = 0;
1669 int disable_count = 0;
1670 const size_t count = valid_bp_ids.GetSize();
1671 for (size_t i = 0; i < count; ++i)
1672 {
1673 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1674
1675 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1676 {
1677 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1678 {
1679 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1680 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1681 // It makes no sense to try to delete individual locations, so we disable them instead.
1682 if (location)
1683 {
1684 location->SetEnabled (false);
1685 ++disable_count;
1686 }
1687 }
1688 else
1689 {
1690 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1691 ++delete_count;
1692 }
1693 }
1694 }
1695 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1696 delete_count, disable_count);
1697 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1698 }
1699 }
1700 return result.Succeeded();
1701 }
1702};
Chris Lattner24943d22010-06-08 16:52:24 +00001703
Chris Lattner24943d22010-06-08 16:52:24 +00001704//-------------------------------------------------------------------------
1705// CommandObjectMultiwordBreakpoint
1706//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001707#pragma mark MultiwordBreakpoint
Chris Lattner24943d22010-06-08 16:52:24 +00001708
Greg Clayton63094e02010-06-23 01:19:29 +00001709CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +00001710 CommandObjectMultiword (interpreter,
1711 "breakpoint",
Jim Ingham7224aab2011-05-26 20:39:01 +00001712 "A set of commands for operating on breakpoints. Also see _regexp-break.",
Greg Clayton238c0a12010-09-18 01:14:36 +00001713 "breakpoint <command> [<command-options>]")
Chris Lattner24943d22010-06-08 16:52:24 +00001714{
Greg Clayton238c0a12010-09-18 01:14:36 +00001715 CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +00001716 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
1717 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
Johnny Chena62ad7c2010-10-28 17:27:46 +00001718 CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
1719 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +00001720 CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +00001721 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +00001722 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +00001723
Johnny Chena62ad7c2010-10-28 17:27:46 +00001724 list_command_object->SetCommandName ("breakpoint list");
Chris Lattner24943d22010-06-08 16:52:24 +00001725 enable_command_object->SetCommandName("breakpoint enable");
1726 disable_command_object->SetCommandName("breakpoint disable");
Johnny Chena62ad7c2010-10-28 17:27:46 +00001727 clear_command_object->SetCommandName("breakpoint clear");
1728 delete_command_object->SetCommandName("breakpoint delete");
Jim Ingham10622a22010-06-18 00:58:52 +00001729 set_command_object->SetCommandName("breakpoint set");
Johnny Chena62ad7c2010-10-28 17:27:46 +00001730 command_command_object->SetCommandName ("breakpoint command");
1731 modify_command_object->SetCommandName ("breakpoint modify");
Chris Lattner24943d22010-06-08 16:52:24 +00001732
Greg Clayton4a379b12012-07-17 03:23:13 +00001733 LoadSubCommand ("list", list_command_object);
1734 LoadSubCommand ("enable", enable_command_object);
1735 LoadSubCommand ("disable", disable_command_object);
1736 LoadSubCommand ("clear", clear_command_object);
1737 LoadSubCommand ("delete", delete_command_object);
1738 LoadSubCommand ("set", set_command_object);
1739 LoadSubCommand ("command", command_command_object);
1740 LoadSubCommand ("modify", modify_command_object);
Chris Lattner24943d22010-06-08 16:52:24 +00001741}
1742
1743CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
1744{
1745}
1746
1747void
1748CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result,
1749 BreakpointIDList *valid_ids)
1750{
1751 // args can be strings representing 1). integers (for breakpoint ids)
1752 // 2). the full breakpoint & location canonical representation
1753 // 3). the word "to" or a hyphen, representing a range (in which case there
1754 // had *better* be an entry both before & after of one of the first two types.
Jim Inghamd1686902010-10-14 23:45:03 +00001755 // If args is empty, we will use the last created breakpoint (if there is one.)
Chris Lattner24943d22010-06-08 16:52:24 +00001756
1757 Args temp_args;
1758
Jim Inghamd1686902010-10-14 23:45:03 +00001759 if (args.GetArgumentCount() == 0)
1760 {
Greg Clayton987c7eb2011-09-17 08:33:22 +00001761 if (target->GetLastCreatedBreakpoint())
Jim Inghamd1686902010-10-14 23:45:03 +00001762 {
1763 valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
1764 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1765 }
1766 else
1767 {
1768 result.AppendError("No breakpoint specified and no last created breakpoint.");
1769 result.SetStatus (eReturnStatusFailed);
1770 }
1771 return;
1772 }
1773
Chris Lattner24943d22010-06-08 16:52:24 +00001774 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
1775 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
1776 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
1777
1778 BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
1779
1780 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
1781
Greg Clayton54e7afa2010-07-09 20:39:50 +00001782 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
Chris Lattner24943d22010-06-08 16:52:24 +00001783
1784 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
1785 // and put into valid_ids.
1786
1787 if (result.Succeeded())
1788 {
1789 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
1790 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
1791
Greg Clayton54e7afa2010-07-09 20:39:50 +00001792 const size_t count = valid_ids->GetSize();
1793 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +00001794 {
1795 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
1796 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1797 if (breakpoint != NULL)
1798 {
1799 int num_locations = breakpoint->GetNumLocations();
1800 if (cur_bp_id.GetLocationID() > num_locations)
1801 {
1802 StreamString id_str;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001803 BreakpointID::GetCanonicalReference (&id_str,
1804 cur_bp_id.GetBreakpointID(),
1805 cur_bp_id.GetLocationID());
1806 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +00001807 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
1808 id_str.GetData());
1809 result.SetStatus (eReturnStatusFailed);
1810 }
1811 }
1812 else
1813 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001814 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +00001815 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
1816 result.SetStatus (eReturnStatusFailed);
1817 }
1818 }
1819 }
1820}