blob: 6a8aabc2d70f11504582219fdf225bf4d074ca5c [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
10#include "CommandObjectBreakpoint.h"
11#include "CommandObjectBreakpointCommand.h"
12
13// C Includes
14// C++ Includes
15// Other libraries and framework includes
16// Project includes
17#include "lldb/Breakpoint/Breakpoint.h"
18#include "lldb/Breakpoint/BreakpointIDList.h"
19#include "lldb/Breakpoint/BreakpointLocation.h"
Jim Ingham84cdc152010-06-15 19:49:27 +000020#include "lldb/Interpreter/Options.h"
Chris Lattner24943d22010-06-08 16:52:24 +000021#include "lldb/Core/RegularExpression.h"
22#include "lldb/Core/StreamString.h"
23#include "lldb/Interpreter/CommandInterpreter.h"
24#include "lldb/Interpreter/CommandReturnObject.h"
25#include "lldb/Target/Target.h"
26#include "lldb/Interpreter/CommandCompletions.h"
27#include "lldb/Target/StackFrame.h"
Jim Ingham3c7b5b92010-06-16 02:00:15 +000028#include "lldb/Target/Thread.h"
29#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000030
31using namespace lldb;
32using namespace lldb_private;
33
34static void
Greg Clayton63094e02010-06-23 01:19:29 +000035AddBreakpointDescription (StreamString *s, Breakpoint *bp, lldb::DescriptionLevel level)
Chris Lattner24943d22010-06-08 16:52:24 +000036{
37 s->IndentMore();
38 bp->GetDescription (s, level, true);
39 s->IndentLess();
40 s->EOL();
41}
42
43//-------------------------------------------------------------------------
44// CommandObjectBreakpointSet::CommandOptions
45//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +000046#pragma mark Set::CommandOptions
Chris Lattner24943d22010-06-08 16:52:24 +000047
48CommandObjectBreakpointSet::CommandOptions::CommandOptions() :
49 Options (),
50 m_filename (),
51 m_line_num (0),
52 m_column (0),
53 m_ignore_inlines (false),
54 m_func_name (),
Greg Clayton12bec712010-06-28 21:30:43 +000055 m_func_name_type_mask (0),
Chris Lattner24943d22010-06-08 16:52:24 +000056 m_func_regexp (),
57 m_modules (),
Jim Ingham3c7b5b92010-06-16 02:00:15 +000058 m_load_addr(),
Greg Clayton54e7afa2010-07-09 20:39:50 +000059 m_ignore_count (0),
Jim Ingham3c7b5b92010-06-16 02:00:15 +000060 m_thread_id(LLDB_INVALID_THREAD_ID),
Greg Clayton54e7afa2010-07-09 20:39:50 +000061 m_thread_index (UINT32_MAX),
Jim Ingham3c7b5b92010-06-16 02:00:15 +000062 m_thread_name(),
Greg Clayton54e7afa2010-07-09 20:39:50 +000063 m_queue_name()
Chris Lattner24943d22010-06-08 16:52:24 +000064{
Chris Lattner24943d22010-06-08 16:52:24 +000065}
66
67CommandObjectBreakpointSet::CommandOptions::~CommandOptions ()
68{
69}
70
71lldb::OptionDefinition
72CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
73{
Greg Clayton12bec712010-06-28 21:30:43 +000074 { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, "<shlib-name>",
Jim Ingham34e9a982010-06-15 18:47:14 +000075 "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."},
76
Greg Claytonfe424a92010-09-18 03:37:20 +000077 { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, "<n>",
Jim Ingham3c7b5b92010-06-16 02:00:15 +000078 "Set the number of times this breakpoint is sKipped before stopping." },
79
Greg Claytonfe424a92010-09-18 03:37:20 +000080 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, "<thread-index>",
81 "The breakpoint stops only for the thread whose index matches this argument."},
Jim Ingham3c7b5b92010-06-16 02:00:15 +000082
Greg Claytonfe424a92010-09-18 03:37:20 +000083 { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, "<thread-id>",
Jim Ingham3c7b5b92010-06-16 02:00:15 +000084 "The breakpoint stops only for the thread whose TID matches this argument."},
85
Greg Claytonfe424a92010-09-18 03:37:20 +000086 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, "<thread-name>",
Jim Ingham3c7b5b92010-06-16 02:00:15 +000087 "The breakpoint stops only for the thread whose thread name matches this argument."},
88
Greg Claytonfe424a92010-09-18 03:37:20 +000089 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, "<queue-name>",
Jim Ingham3c7b5b92010-06-16 02:00:15 +000090 "The breakpoint stops only for threads in the queue whose name is given by this argument."},
91
Greg Clayton12bec712010-06-28 21:30:43 +000092 { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, "<filename>",
Chris Lattner24943d22010-06-08 16:52:24 +000093 "Set the breakpoint by source location in this particular file."},
94
Greg Clayton12bec712010-06-28 21:30:43 +000095 { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, "<linenum>",
Chris Lattner24943d22010-06-08 16:52:24 +000096 "Set the breakpoint by source location at this particular line."},
97
Chris Lattner24943d22010-06-08 16:52:24 +000098 // Comment out this option for the moment, as we don't actually use it, but will in the future.
99 // This way users won't see it, but the infrastructure is left in place.
100 // { 0, false, "column", 'c', required_argument, NULL, "<column>",
101 // "Set the breakpoint by source location at this particular column."},
102
Greg Clayton12bec712010-06-28 21:30:43 +0000103 { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, "<address>",
Chris Lattner24943d22010-06-08 16:52:24 +0000104 "Set the breakpoint by address, at the specified address."},
105
Greg Clayton12bec712010-06-28 21:30:43 +0000106 { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, "<name>",
Jim Inghamd9e2b762010-08-26 23:56:11 +0000107 "Set the breakpoint by function name - for C++ this means namespaces and arguments will be ignored." },
Chris Lattner24943d22010-06-08 16:52:24 +0000108
Jim Inghamb0f55d42010-09-08 17:52:03 +0000109 { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, "<fullname>",
Jim Inghamd9e2b762010-08-26 23:56:11 +0000110 "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguemnts, and "
111 "for Objective C this means a full function prototype with class and selector." },
Greg Clayton12bec712010-06-28 21:30:43 +0000112
Jim Inghamd9e2b762010-08-26 23:56:11 +0000113 { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, "<selector>",
114 "Set the breakpoint by ObjC selector name." },
Greg Clayton12bec712010-06-28 21:30:43 +0000115
Jim Inghamd9e2b762010-08-26 23:56:11 +0000116 { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, "<method>",
117 "Set the breakpoint by C++ method names." },
Greg Clayton12bec712010-06-28 21:30:43 +0000118
Greg Claytonfe424a92010-09-18 03:37:20 +0000119 { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, "<regex>",
Chris Lattner24943d22010-06-08 16:52:24 +0000120 "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
121
Chris Lattner24943d22010-06-08 16:52:24 +0000122 { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL }
123};
124
125const lldb::OptionDefinition*
126CommandObjectBreakpointSet::CommandOptions::GetDefinitions ()
127{
128 return g_option_table;
129}
130
131Error
132CommandObjectBreakpointSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
133{
134 Error error;
135 char short_option = (char) m_getopt_table[option_idx].val;
136
137 switch (short_option)
138 {
139 case 'a':
140 m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 0);
141 if (m_load_addr == LLDB_INVALID_ADDRESS)
142 m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 16);
143
144 if (m_load_addr == LLDB_INVALID_ADDRESS)
145 error.SetErrorStringWithFormat ("Invalid address string '%s'.\n", optarg);
146 break;
147
148 case 'c':
149 m_column = Args::StringToUInt32 (option_arg, 0);
150 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000151
Chris Lattner24943d22010-06-08 16:52:24 +0000152 case 'f':
153 m_filename = option_arg;
154 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000155
Chris Lattner24943d22010-06-08 16:52:24 +0000156 case 'l':
157 m_line_num = Args::StringToUInt32 (option_arg, 0);
158 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000159
Chris Lattner24943d22010-06-08 16:52:24 +0000160 case 'n':
161 m_func_name = option_arg;
Greg Clayton12bec712010-06-28 21:30:43 +0000162 m_func_name_type_mask |= eFunctionNameTypeBase;
163 break;
164
165 case 'F':
Jim Inghamd9e2b762010-08-26 23:56:11 +0000166 m_func_name = option_arg;
Greg Clayton12bec712010-06-28 21:30:43 +0000167 m_func_name_type_mask |= eFunctionNameTypeFull;
168 break;
169
170 case 'S':
Jim Inghamd9e2b762010-08-26 23:56:11 +0000171 m_func_name = option_arg;
Greg Clayton12bec712010-06-28 21:30:43 +0000172 m_func_name_type_mask |= eFunctionNameTypeSelector;
173 break;
174
Jim Inghamd9e2b762010-08-26 23:56:11 +0000175 case 'M':
176 m_func_name = option_arg;
Greg Clayton12bec712010-06-28 21:30:43 +0000177 m_func_name_type_mask |= eFunctionNameTypeMethod;
178 break;
179
Chris Lattner24943d22010-06-08 16:52:24 +0000180 case 'r':
181 m_func_regexp = option_arg;
182 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000183
Chris Lattner24943d22010-06-08 16:52:24 +0000184 case 's':
185 {
186 m_modules.push_back (std::string (option_arg));
187 break;
188 }
Greg Claytonfe424a92010-09-18 03:37:20 +0000189 case 'i':
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000190 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000191 m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0);
192 if (m_ignore_count == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000193 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg);
194 }
Jim Ingham10622a22010-06-18 00:58:52 +0000195 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000196 case 't' :
197 {
198 m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0);
199 if (m_thread_id == LLDB_INVALID_THREAD_ID)
200 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg);
201 }
202 break;
203 case 'T':
204 m_thread_name = option_arg;
205 break;
206 case 'q':
207 m_queue_name = option_arg;
208 break;
209 case 'x':
210 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000211 m_thread_index = Args::StringToUInt32(optarg, UINT32_MAX, 0);
212 if (m_thread_id == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000213 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg);
214
215 }
216 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000217 default:
218 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
219 break;
220 }
221
222 return error;
223}
224
225void
226CommandObjectBreakpointSet::CommandOptions::ResetOptionValues ()
227{
228 Options::ResetOptionValues();
229
230 m_filename.clear();
231 m_line_num = 0;
232 m_column = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000233 m_func_name.clear();
Greg Clayton12bec712010-06-28 21:30:43 +0000234 m_func_name_type_mask = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000235 m_func_regexp.clear();
236 m_load_addr = LLDB_INVALID_ADDRESS;
237 m_modules.clear();
Greg Clayton54e7afa2010-07-09 20:39:50 +0000238 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000239 m_thread_id = LLDB_INVALID_THREAD_ID;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000240 m_thread_index = UINT32_MAX;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000241 m_thread_name.clear();
242 m_queue_name.clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000243}
244
245//-------------------------------------------------------------------------
246// CommandObjectBreakpointSet
247//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000248#pragma mark Set
Chris Lattner24943d22010-06-08 16:52:24 +0000249
Greg Clayton238c0a12010-09-18 01:14:36 +0000250CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
251 CommandObject (interpreter,
252 "breakpoint set",
253 "Sets a breakpoint or set of breakpoints in the executable.",
Chris Lattner24943d22010-06-08 16:52:24 +0000254 "breakpoint set <cmd-options>")
255{
256}
257
258CommandObjectBreakpointSet::~CommandObjectBreakpointSet ()
259{
260}
261
262Options *
263CommandObjectBreakpointSet::GetOptions ()
264{
265 return &m_options;
266}
267
268bool
269CommandObjectBreakpointSet::Execute
270(
271 Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000272 CommandReturnObject &result
273)
274{
Greg Clayton238c0a12010-09-18 01:14:36 +0000275 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000276 if (target == NULL)
277 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000278 result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'file' command).");
Chris Lattner24943d22010-06-08 16:52:24 +0000279 result.SetStatus (eReturnStatusFailed);
280 return false;
281 }
282
283 // The following are the various types of breakpoints that could be set:
284 // 1). -f -l -p [-s -g] (setting breakpoint by source location)
285 // 2). -a [-s -g] (setting breakpoint by address)
286 // 3). -n [-s -g] (setting breakpoint by function name)
287 // 4). -r [-s -g] (setting breakpoint by function name regular expression)
288
289 BreakpointSetType break_type = eSetTypeInvalid;
290
291 if (m_options.m_line_num != 0)
292 break_type = eSetTypeFileAndLine;
293 else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
294 break_type = eSetTypeAddress;
295 else if (!m_options.m_func_name.empty())
296 break_type = eSetTypeFunctionName;
297 else if (!m_options.m_func_regexp.empty())
298 break_type = eSetTypeFunctionRegexp;
299
300 ModuleSP module_sp = target->GetExecutableModule();
301 Breakpoint *bp = NULL;
302 FileSpec module;
303 bool use_module = false;
304 int num_modules = m_options.m_modules.size();
305
306 if ((num_modules > 0) && (break_type != eSetTypeAddress))
307 use_module = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000308
Chris Lattner24943d22010-06-08 16:52:24 +0000309 switch (break_type)
310 {
311 case eSetTypeFileAndLine: // Breakpoint by source position
312 {
313 FileSpec file;
314 if (m_options.m_filename.empty())
315 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000316 StackFrame *cur_frame = m_interpreter.GetDebugger().GetExecutionContext().frame;
Chris Lattner24943d22010-06-08 16:52:24 +0000317 if (cur_frame == NULL)
318 {
319 result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame.");
320 result.SetStatus (eReturnStatusFailed);
321 break;
322 }
323 else if (!cur_frame->HasDebugInformation())
324 {
325 result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info.");
326 result.SetStatus (eReturnStatusFailed);
327 break;
328 }
329 else
330 {
331 const SymbolContext &context = cur_frame->GetSymbolContext(true);
332 if (context.line_entry.file)
333 {
334 file = context.line_entry.file;
335 }
336 else if (context.comp_unit != NULL)
337 { file = context.comp_unit;
338 }
339 else
340 {
341 result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame.");
342 result.SetStatus (eReturnStatusFailed);
343 break;
344 }
345 }
346 }
347 else
348 {
349 file.SetFile(m_options.m_filename.c_str());
350 }
351
352 if (use_module)
353 {
354 for (int i = 0; i < num_modules; ++i)
355 {
356 module.SetFile(m_options.m_modules[i].c_str());
357 bp = target->CreateBreakpoint (&module,
358 file,
359 m_options.m_line_num,
360 m_options.m_ignore_inlines).get();
361 if (bp)
362 {
363 StreamString &output_stream = result.GetOutputStream();
364 output_stream.Printf ("Breakpoint created: ");
365 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
366 output_stream.EOL();
367 result.SetStatus (eReturnStatusSuccessFinishResult);
368 }
369 else
370 {
371 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
372 m_options.m_modules[i].c_str());
373 result.SetStatus (eReturnStatusFailed);
374 }
375 }
376 }
377 else
378 bp = target->CreateBreakpoint (NULL,
379 file,
380 m_options.m_line_num,
381 m_options.m_ignore_inlines).get();
382 }
383 break;
384 case eSetTypeAddress: // Breakpoint by address
385 bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
386 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000387
Chris Lattner24943d22010-06-08 16:52:24 +0000388 case eSetTypeFunctionName: // Breakpoint by function name
Chris Lattner24943d22010-06-08 16:52:24 +0000389 {
Greg Clayton12bec712010-06-28 21:30:43 +0000390 uint32_t name_type_mask = m_options.m_func_name_type_mask;
391
392 if (name_type_mask == 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000393 {
Greg Clayton12bec712010-06-28 21:30:43 +0000394
395 if (m_options.m_func_name.find('(') != std::string::npos ||
396 m_options.m_func_name.find("-[") == 0 ||
397 m_options.m_func_name.find("+[") == 0)
398 name_type_mask |= eFunctionNameTypeFull;
Chris Lattner24943d22010-06-08 16:52:24 +0000399 else
Greg Clayton12bec712010-06-28 21:30:43 +0000400 name_type_mask |= eFunctionNameTypeBase;
401 }
402
403
404 if (use_module)
405 {
406 for (int i = 0; i < num_modules; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000407 {
Greg Clayton12bec712010-06-28 21:30:43 +0000408 module.SetFile(m_options.m_modules[i].c_str());
409 bp = target->CreateBreakpoint (&module, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get();
410 if (bp)
411 {
412 StreamString &output_stream = result.GetOutputStream();
413 output_stream.Printf ("Breakpoint created: ");
414 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
415 output_stream.EOL();
416 result.SetStatus (eReturnStatusSuccessFinishResult);
417 }
418 else
419 {
420 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
421 m_options.m_modules[i].c_str());
422 result.SetStatus (eReturnStatusFailed);
423 }
Chris Lattner24943d22010-06-08 16:52:24 +0000424 }
425 }
Greg Clayton12bec712010-06-28 21:30:43 +0000426 else
427 bp = target->CreateBreakpoint (NULL, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000428 }
Chris Lattner24943d22010-06-08 16:52:24 +0000429 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000430
Chris Lattner24943d22010-06-08 16:52:24 +0000431 case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
432 {
433 RegularExpression regexp(m_options.m_func_regexp.c_str());
434 if (use_module)
435 {
436 for (int i = 0; i < num_modules; ++i)
437 {
438 module.SetFile(m_options.m_modules[i].c_str());
439 bp = target->CreateBreakpoint (&module, regexp).get();
440 if (bp)
441 {
442 StreamString &output_stream = result.GetOutputStream();
443 output_stream.Printf ("Breakpoint created: ");
444 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
445 output_stream.EOL();
446 result.SetStatus (eReturnStatusSuccessFinishResult);
447 }
448 else
449 {
450 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
451 m_options.m_modules[i].c_str());
452 result.SetStatus (eReturnStatusFailed);
453 }
454 }
455 }
456 else
457 bp = target->CreateBreakpoint (NULL, regexp).get();
458 }
459 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000460
Chris Lattner24943d22010-06-08 16:52:24 +0000461 default:
462 break;
463 }
464
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000465 // Now set the various options that were passed in:
466 if (bp)
467 {
468 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
469 bp->SetThreadID (m_options.m_thread_id);
470
Greg Clayton54e7afa2010-07-09 20:39:50 +0000471 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000472 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
473
474 if (!m_options.m_thread_name.empty())
475 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
476
477 if (!m_options.m_queue_name.empty())
478 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
479
Greg Clayton54e7afa2010-07-09 20:39:50 +0000480 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000481 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
482 }
483
Chris Lattner24943d22010-06-08 16:52:24 +0000484 if (bp && !use_module)
485 {
486 StreamString &output_stream = result.GetOutputStream();
487 output_stream.Printf ("Breakpoint created: ");
488 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
489 output_stream.EOL();
490 result.SetStatus (eReturnStatusSuccessFinishResult);
491 }
492 else if (!bp)
493 {
494 result.AppendError ("Breakpoint creation failed: No breakpoint created.");
495 result.SetStatus (eReturnStatusFailed);
496 }
497
498 return result.Succeeded();
499}
500
Chris Lattner24943d22010-06-08 16:52:24 +0000501//-------------------------------------------------------------------------
502// CommandObjectMultiwordBreakpoint
503//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000504#pragma mark MultiwordBreakpoint
Chris Lattner24943d22010-06-08 16:52:24 +0000505
Greg Clayton63094e02010-06-23 01:19:29 +0000506CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000507 CommandObjectMultiword (interpreter,
508 "breakpoint",
509 "A set of commands for operating on breakpoints. Also see regexp-break.",
510 "breakpoint <command> [<command-options>]")
Chris Lattner24943d22010-06-08 16:52:24 +0000511{
512 bool status;
513
Greg Clayton238c0a12010-09-18 01:14:36 +0000514 CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
515 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
516 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
517 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
518 CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +0000519 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000520 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +0000521
Jim Ingham10622a22010-06-18 00:58:52 +0000522 command_command_object->SetCommandName ("breakpoint command");
Chris Lattner24943d22010-06-08 16:52:24 +0000523 enable_command_object->SetCommandName("breakpoint enable");
524 disable_command_object->SetCommandName("breakpoint disable");
Chris Lattner24943d22010-06-08 16:52:24 +0000525 list_command_object->SetCommandName ("breakpoint list");
Jim Ingham10622a22010-06-18 00:58:52 +0000526 modify_command_object->SetCommandName ("breakpoint modify");
527 set_command_object->SetCommandName("breakpoint set");
Chris Lattner24943d22010-06-08 16:52:24 +0000528
Greg Clayton238c0a12010-09-18 01:14:36 +0000529 status = LoadSubCommand ("list", list_command_object);
530 status = LoadSubCommand ("enable", enable_command_object);
531 status = LoadSubCommand ("disable", disable_command_object);
532 status = LoadSubCommand ("delete", delete_command_object);
533 status = LoadSubCommand ("set", set_command_object);
534 status = LoadSubCommand ("command", command_command_object);
535 status = LoadSubCommand ("modify", modify_command_object);
Chris Lattner24943d22010-06-08 16:52:24 +0000536}
537
538CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
539{
540}
541
542void
543CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result,
544 BreakpointIDList *valid_ids)
545{
546 // args can be strings representing 1). integers (for breakpoint ids)
547 // 2). the full breakpoint & location canonical representation
548 // 3). the word "to" or a hyphen, representing a range (in which case there
549 // had *better* be an entry both before & after of one of the first two types.
550
551 Args temp_args;
552
553 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
554 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
555 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
556
557 BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
558
559 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
560
Greg Clayton54e7afa2010-07-09 20:39:50 +0000561 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
Chris Lattner24943d22010-06-08 16:52:24 +0000562
563 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
564 // and put into valid_ids.
565
566 if (result.Succeeded())
567 {
568 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
569 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
570
Greg Clayton54e7afa2010-07-09 20:39:50 +0000571 const size_t count = valid_ids->GetSize();
572 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000573 {
574 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
575 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
576 if (breakpoint != NULL)
577 {
578 int num_locations = breakpoint->GetNumLocations();
579 if (cur_bp_id.GetLocationID() > num_locations)
580 {
581 StreamString id_str;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000582 BreakpointID::GetCanonicalReference (&id_str,
583 cur_bp_id.GetBreakpointID(),
584 cur_bp_id.GetLocationID());
585 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000586 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
587 id_str.GetData());
588 result.SetStatus (eReturnStatusFailed);
589 }
590 }
591 else
592 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000593 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000594 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
595 result.SetStatus (eReturnStatusFailed);
596 }
597 }
598 }
599}
600
601//-------------------------------------------------------------------------
602// CommandObjectBreakpointList::Options
603//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000604#pragma mark List::CommandOptions
Chris Lattner24943d22010-06-08 16:52:24 +0000605
606CommandObjectBreakpointList::CommandOptions::CommandOptions() :
607 Options (),
608 m_level (lldb::eDescriptionLevelFull) // Breakpoint List defaults to brief descriptions
609{
Chris Lattner24943d22010-06-08 16:52:24 +0000610}
611
612CommandObjectBreakpointList::CommandOptions::~CommandOptions ()
613{
614}
615
616lldb::OptionDefinition
617CommandObjectBreakpointList::CommandOptions::g_option_table[] =
618{
Jim Ingham34e9a982010-06-15 18:47:14 +0000619 { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, NULL,
620 "Show debugger internal breakpoints" },
621
622 { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, NULL,
Chris Lattner24943d22010-06-08 16:52:24 +0000623 "Give a brief description of the breakpoint (no location info)."},
624
625 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
626 // But I need to see it for now, and don't want to wait.
Jim Ingham34e9a982010-06-15 18:47:14 +0000627 { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, NULL,
Chris Lattner24943d22010-06-08 16:52:24 +0000628 "Give a full description of the breakpoint and its locations."},
Chris Lattner24943d22010-06-08 16:52:24 +0000629
Jim Ingham34e9a982010-06-15 18:47:14 +0000630 { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, NULL,
Chris Lattner24943d22010-06-08 16:52:24 +0000631 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
Chris Lattner24943d22010-06-08 16:52:24 +0000632
633 { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL }
634};
635
636const lldb::OptionDefinition*
637CommandObjectBreakpointList::CommandOptions::GetDefinitions ()
638{
639 return g_option_table;
640}
641
642Error
643CommandObjectBreakpointList::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
644{
645 Error error;
646 char short_option = (char) m_getopt_table[option_idx].val;
647
648 switch (short_option)
649 {
650 case 'b':
651 m_level = lldb::eDescriptionLevelBrief;
652 break;
653 case 'f':
654 m_level = lldb::eDescriptionLevelFull;
655 break;
656 case 'v':
657 m_level = lldb::eDescriptionLevelVerbose;
658 break;
659 case 'i':
660 m_internal = true;
661 break;
662 default:
663 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
664 break;
665 }
666
667 return error;
668}
669
670void
671CommandObjectBreakpointList::CommandOptions::ResetOptionValues ()
672{
673 Options::ResetOptionValues();
674
675 m_level = lldb::eDescriptionLevelFull;
676 m_internal = false;
677}
678
679//-------------------------------------------------------------------------
680// CommandObjectBreakpointList
681//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000682#pragma mark List
Chris Lattner24943d22010-06-08 16:52:24 +0000683
Greg Clayton238c0a12010-09-18 01:14:36 +0000684CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) :
685 CommandObject (interpreter,
686 "breakpoint list",
687 "List some or all breakpoints at configurable levels of detail.",
Caroline Ticefb355112010-10-01 17:46:38 +0000688 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000689{
Caroline Ticefb355112010-10-01 17:46:38 +0000690 CommandArgumentEntry arg;
691 CommandArgumentData bp_id_arg;
692
693 // Define the first (and only) variant of this arg.
694 bp_id_arg.arg_type = eArgTypeBreakpointID;
695 bp_id_arg.arg_repetition = eArgRepeatStar;
696
697 // There is only one variant this argument could be; put it into the argument entry.
698 arg.push_back (bp_id_arg);
699
700 // Push the data for the first argument into the m_arguments vector.
701 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000702}
703
704CommandObjectBreakpointList::~CommandObjectBreakpointList ()
705{
706}
707
708Options *
709CommandObjectBreakpointList::GetOptions ()
710{
711 return &m_options;
712}
713
714bool
715CommandObjectBreakpointList::Execute
716(
717 Args& args,
Chris Lattner24943d22010-06-08 16:52:24 +0000718 CommandReturnObject &result
719)
720{
Greg Clayton238c0a12010-09-18 01:14:36 +0000721 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000722 if (target == NULL)
723 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000724 result.AppendError ("Invalid target. No current target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000725 result.SetStatus (eReturnStatusSuccessFinishNoResult);
726 return true;
727 }
728
729 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000730 Mutex::Locker locker;
731 target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
732
Chris Lattner24943d22010-06-08 16:52:24 +0000733 size_t num_breakpoints = breakpoints.GetSize();
734
735 if (num_breakpoints == 0)
736 {
737 result.AppendMessage ("No breakpoints currently set.");
738 result.SetStatus (eReturnStatusSuccessFinishNoResult);
739 return true;
740 }
741
742 StreamString &output_stream = result.GetOutputStream();
743
744 if (args.GetArgumentCount() == 0)
745 {
746 // No breakpoint selected; show info about all currently set breakpoints.
747 result.AppendMessage ("Current breakpoints:");
Greg Clayton54e7afa2010-07-09 20:39:50 +0000748 for (size_t i = 0; i < num_breakpoints; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000749 {
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000750 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000751 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000752 }
753 result.SetStatus (eReturnStatusSuccessFinishNoResult);
754 }
755 else
756 {
757 // Particular breakpoints selected; show info about that breakpoint.
758 BreakpointIDList valid_bp_ids;
759 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
760
761 if (result.Succeeded())
762 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000763 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000764 {
765 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
766 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000767 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000768 }
769 result.SetStatus (eReturnStatusSuccessFinishNoResult);
770 }
771 else
772 {
773 result.AppendError ("Invalid breakpoint id.");
774 result.SetStatus (eReturnStatusFailed);
775 }
776 }
777
778 return result.Succeeded();
779}
780
781//-------------------------------------------------------------------------
782// CommandObjectBreakpointEnable
783//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000784#pragma mark Enable
Chris Lattner24943d22010-06-08 16:52:24 +0000785
Greg Clayton238c0a12010-09-18 01:14:36 +0000786CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
787 CommandObject (interpreter,
788 "enable",
Caroline Ticefb355112010-10-01 17:46:38 +0000789 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
790 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000791{
Caroline Ticefb355112010-10-01 17:46:38 +0000792 CommandArgumentEntry arg;
793 CommandArgumentData bp_id_arg;
794 CommandArgumentData bp_id_range_arg;
795
796 // Create the first variant for the first (and only) argument for this command.
797 bp_id_arg.arg_type = eArgTypeBreakpointID;
798 bp_id_arg.arg_repetition = eArgRepeatStar;
799
800 // Create the second variant for the first (and only) argument for this command.
801 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
802 bp_id_range_arg.arg_repetition = eArgRepeatStar;
803
804 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
805 // Push both variants into the entry for the first argument for this command.
806 arg.push_back (bp_id_arg);
807 arg.push_back (bp_id_range_arg);
808
809 // Add the entry for the first argument for this command to the object's arguments vector.
810 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000811}
812
813
814CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable ()
815{
816}
817
818
819bool
Greg Clayton63094e02010-06-23 01:19:29 +0000820CommandObjectBreakpointEnable::Execute
821(
Greg Clayton63094e02010-06-23 01:19:29 +0000822 Args& args,
823 CommandReturnObject &result
824)
Chris Lattner24943d22010-06-08 16:52:24 +0000825{
Greg Clayton238c0a12010-09-18 01:14:36 +0000826 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000827 if (target == NULL)
828 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000829 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000830 result.SetStatus (eReturnStatusFailed);
831 return false;
832 }
833
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000834 Mutex::Locker locker;
835 target->GetBreakpointList().GetListMutex(locker);
836
Chris Lattner24943d22010-06-08 16:52:24 +0000837 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000838
Chris Lattner24943d22010-06-08 16:52:24 +0000839 size_t num_breakpoints = breakpoints.GetSize();
840
841 if (num_breakpoints == 0)
842 {
843 result.AppendError ("No breakpoints exist to be enabled.");
844 result.SetStatus (eReturnStatusFailed);
845 return false;
846 }
847
848 if (args.GetArgumentCount() == 0)
849 {
850 // No breakpoint selected; enable all currently set breakpoints.
851 target->EnableAllBreakpoints ();
852 result.AppendMessageWithFormat ("All breakpoints enabled. (%d breakpoints)\n", num_breakpoints);
853 result.SetStatus (eReturnStatusSuccessFinishNoResult);
854 }
855 else
856 {
857 // Particular breakpoint selected; enable that breakpoint.
858 BreakpointIDList valid_bp_ids;
859 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
860
861 if (result.Succeeded())
862 {
863 int enable_count = 0;
864 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000865 const size_t count = valid_bp_ids.GetSize();
866 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000867 {
868 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
869
870 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
871 {
872 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
873 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
874 {
875 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
876 if (location)
877 {
878 location->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000879 ++loc_count;
880 }
881 }
882 else
883 {
Jim Ingham10622a22010-06-18 00:58:52 +0000884 breakpoint->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000885 ++enable_count;
Chris Lattner24943d22010-06-08 16:52:24 +0000886 }
887 }
888 }
889 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
890 result.SetStatus (eReturnStatusSuccessFinishNoResult);
891 }
892 }
893
894 return result.Succeeded();
895}
896
897//-------------------------------------------------------------------------
898// CommandObjectBreakpointDisable
899//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000900#pragma mark Disable
Chris Lattner24943d22010-06-08 16:52:24 +0000901
Greg Clayton238c0a12010-09-18 01:14:36 +0000902CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
903 CommandObject (interpreter,
Caroline Ticefb355112010-10-01 17:46:38 +0000904 "breakpoint disable",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000905 "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.",
Caroline Ticefb355112010-10-01 17:46:38 +0000906 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000907{
Caroline Ticefb355112010-10-01 17:46:38 +0000908 CommandArgumentEntry arg;
909 CommandArgumentData bp_id_arg;
910 CommandArgumentData bp_id_range_arg;
911
912 // Create the first variant for the first (and only) argument for this command.
913 bp_id_arg.arg_type = eArgTypeBreakpointID;
914 bp_id_arg.arg_repetition = eArgRepeatStar;
915
916 // Create the second variant for the first (and only) argument for this command.
917 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
918 bp_id_range_arg.arg_repetition = eArgRepeatStar;
919
920 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
921 // Push both variants into the entry for the first argument for this command.
922 arg.push_back (bp_id_arg);
923 arg.push_back (bp_id_range_arg);
924
925 // Add the entry for the first argument for this command to the object's arguments vector.
926 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000927}
928
929CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable ()
930{
931}
932
933bool
Greg Clayton63094e02010-06-23 01:19:29 +0000934CommandObjectBreakpointDisable::Execute
935(
Greg Clayton63094e02010-06-23 01:19:29 +0000936 Args& args,
937 CommandReturnObject &result
938)
Chris Lattner24943d22010-06-08 16:52:24 +0000939{
Greg Clayton238c0a12010-09-18 01:14:36 +0000940 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000941 if (target == NULL)
942 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000943 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000944 result.SetStatus (eReturnStatusFailed);
945 return false;
946 }
947
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000948 Mutex::Locker locker;
949 target->GetBreakpointList().GetListMutex(locker);
950
Chris Lattner24943d22010-06-08 16:52:24 +0000951 const BreakpointList &breakpoints = target->GetBreakpointList();
952 size_t num_breakpoints = breakpoints.GetSize();
953
954 if (num_breakpoints == 0)
955 {
956 result.AppendError ("No breakpoints exist to be disabled.");
957 result.SetStatus (eReturnStatusFailed);
958 return false;
959 }
960
961 if (args.GetArgumentCount() == 0)
962 {
963 // No breakpoint selected; disable all currently set breakpoints.
964 target->DisableAllBreakpoints ();
965 result.AppendMessageWithFormat ("All breakpoints disabled. (%d breakpoints)\n", num_breakpoints);
966 result.SetStatus (eReturnStatusSuccessFinishNoResult);
967 }
968 else
969 {
970 // Particular breakpoint selected; disable that breakpoint.
971 BreakpointIDList valid_bp_ids;
972
973 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
974
975 if (result.Succeeded())
976 {
977 int disable_count = 0;
978 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000979 const size_t count = valid_bp_ids.GetSize();
980 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000981 {
982 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
983
984 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
985 {
986 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
987 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
988 {
989 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
990 if (location)
991 {
992 location->SetEnabled (false);
993 ++loc_count;
994 }
995 }
996 else
997 {
Jim Ingham10622a22010-06-18 00:58:52 +0000998 breakpoint->SetEnabled (false);
Chris Lattner24943d22010-06-08 16:52:24 +0000999 ++disable_count;
Chris Lattner24943d22010-06-08 16:52:24 +00001000 }
1001 }
1002 }
1003 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
1004 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1005 }
1006 }
1007
1008 return result.Succeeded();
1009}
1010
1011//-------------------------------------------------------------------------
1012// CommandObjectBreakpointDelete
1013//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001014#pragma mark Delete
Chris Lattner24943d22010-06-08 16:52:24 +00001015
Greg Clayton238c0a12010-09-18 01:14:36 +00001016CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) :
1017 CommandObject (interpreter,
1018 "breakpoint delete",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001019 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
Caroline Ticefb355112010-10-01 17:46:38 +00001020 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +00001021{
Caroline Ticefb355112010-10-01 17:46:38 +00001022 CommandArgumentEntry arg;
1023 CommandArgumentData bp_id_arg;
1024 CommandArgumentData bp_id_range_arg;
1025
1026 // Create the first variant for the first (and only) argument for this command.
1027 bp_id_arg.arg_type = eArgTypeBreakpointID;
1028 bp_id_arg.arg_repetition = eArgRepeatStar;
1029
1030 // Create the second variant for the first (and only) argument for this command.
1031 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
1032 bp_id_range_arg.arg_repetition = eArgRepeatStar;
1033
1034 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1035 // Push both variants into the entry for the first argument for this command.
1036 arg.push_back (bp_id_arg);
1037 arg.push_back (bp_id_range_arg);
1038
1039 // Add the entry for the first argument for this command to the object's arguments vector.
1040 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +00001041}
1042
1043
1044CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete ()
1045{
1046}
1047
1048bool
Greg Clayton63094e02010-06-23 01:19:29 +00001049CommandObjectBreakpointDelete::Execute
1050(
Greg Clayton63094e02010-06-23 01:19:29 +00001051 Args& args,
1052 CommandReturnObject &result
1053)
Chris Lattner24943d22010-06-08 16:52:24 +00001054{
Greg Clayton238c0a12010-09-18 01:14:36 +00001055 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001056 if (target == NULL)
1057 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001058 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +00001059 result.SetStatus (eReturnStatusFailed);
1060 return false;
1061 }
1062
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001063 Mutex::Locker locker;
1064 target->GetBreakpointList().GetListMutex(locker);
1065
Chris Lattner24943d22010-06-08 16:52:24 +00001066 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001067
Chris Lattner24943d22010-06-08 16:52:24 +00001068 size_t num_breakpoints = breakpoints.GetSize();
1069
1070 if (num_breakpoints == 0)
1071 {
1072 result.AppendError ("No breakpoints exist to be deleted.");
1073 result.SetStatus (eReturnStatusFailed);
1074 return false;
1075 }
1076
1077 if (args.GetArgumentCount() == 0)
1078 {
1079 // No breakpoint selected; disable all currently set breakpoints.
1080 if (args.GetArgumentCount() != 0)
1081 {
1082 result.AppendErrorWithFormat ("Specify breakpoints to delete with the -i option.\n");
1083 result.SetStatus (eReturnStatusFailed);
1084 return false;
1085 }
1086
1087 target->RemoveAllBreakpoints ();
1088 result.AppendMessageWithFormat ("All breakpoints removed. (%d breakpoints)\n", num_breakpoints);
1089 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1090 }
1091 else
1092 {
1093 // Particular breakpoint selected; disable that breakpoint.
1094 BreakpointIDList valid_bp_ids;
1095 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
1096
1097 if (result.Succeeded())
1098 {
1099 int delete_count = 0;
1100 int disable_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001101 const size_t count = valid_bp_ids.GetSize();
1102 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +00001103 {
1104 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1105
1106 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1107 {
1108 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1109 {
1110 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1111 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1112 // It makes no sense to try to delete individual locations, so we disable them instead.
1113 if (location)
1114 {
1115 location->SetEnabled (false);
1116 ++disable_count;
1117 }
1118 }
1119 else
1120 {
1121 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1122 ++delete_count;
1123 }
1124 }
1125 }
1126 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1127 delete_count, disable_count);
1128 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1129 }
1130 }
1131 return result.Succeeded();
1132}
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001133
1134//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001135// CommandObjectBreakpointModify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001136//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001137#pragma mark Modify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001138
Jim Ingham10622a22010-06-18 00:58:52 +00001139CommandObjectBreakpointModify::CommandOptions::CommandOptions() :
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001140 Options (),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001141 m_ignore_count (0),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001142 m_thread_id(LLDB_INVALID_THREAD_ID),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001143 m_thread_index (UINT32_MAX),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001144 m_thread_name(),
1145 m_queue_name(),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001146 m_enable_passed (false),
1147 m_enable_value (false),
1148 m_name_passed (false),
1149 m_queue_passed (false)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001150{
1151}
1152
Jim Ingham10622a22010-06-18 00:58:52 +00001153CommandObjectBreakpointModify::CommandOptions::~CommandOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001154{
1155}
1156
1157lldb::OptionDefinition
Jim Ingham10622a22010-06-18 00:58:52 +00001158CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001159{
Greg Claytonfe424a92010-09-18 03:37:20 +00001160{ LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, NULL, "<n>", "Set the number of times this breakpoint is skipped before stopping." },
1161{ LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, "<thread-index>", "The breakpoint stops only for the thread whose indeX matches this argument."},
1162{ LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, "<thread-id>", "The breakpoint stops only for the thread whose TID matches this argument."},
1163{ LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, "<thread-name>", "The breakpoint stops only for the thread whose thread name matches this argument."},
1164{ LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, "<queue-name>", "The breakpoint stops only for threads in the queue whose name is given by this argument."},
1165{ LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, NULL, "Enable the breakpoint."},
1166{ LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, NULL, "Disable the breakpoint."},
1167{ 0, false, NULL, 0 , 0, NULL, 0, NULL, NULL }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001168};
1169
1170const lldb::OptionDefinition*
Jim Ingham10622a22010-06-18 00:58:52 +00001171CommandObjectBreakpointModify::CommandOptions::GetDefinitions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001172{
1173 return g_option_table;
1174}
1175
1176Error
Jim Ingham10622a22010-06-18 00:58:52 +00001177CommandObjectBreakpointModify::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001178{
1179 Error error;
1180 char short_option = (char) m_getopt_table[option_idx].val;
1181
1182 switch (short_option)
1183 {
Jim Ingham10622a22010-06-18 00:58:52 +00001184 case 'd':
1185 m_enable_passed = true;
1186 m_enable_value = false;
1187 break;
1188 case 'e':
1189 m_enable_passed = true;
1190 m_enable_value = true;
1191 break;
Greg Claytonfe424a92010-09-18 03:37:20 +00001192 case 'i':
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001193 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001194 m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0);
1195 if (m_ignore_count == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001196 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg);
1197 }
Jim Ingham10622a22010-06-18 00:58:52 +00001198 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001199 case 't' :
1200 {
1201 m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0);
1202 if (m_thread_id == LLDB_INVALID_THREAD_ID)
1203 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg);
1204 }
1205 break;
1206 case 'T':
Jim Inghamd4571222010-06-19 04:35:20 +00001207 if (option_arg != NULL)
1208 m_thread_name = option_arg;
1209 else
1210 m_thread_name.clear();
1211 m_name_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001212 break;
1213 case 'q':
Jim Inghamd4571222010-06-19 04:35:20 +00001214 if (option_arg != NULL)
1215 m_queue_name = option_arg;
1216 else
1217 m_queue_name.clear();
1218 m_queue_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001219 break;
1220 case 'x':
1221 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001222 m_thread_index = Args::StringToUInt32 (optarg, UINT32_MAX, 0);
1223 if (m_thread_id == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001224 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg);
1225
1226 }
1227 break;
1228 default:
1229 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1230 break;
1231 }
1232
1233 return error;
1234}
1235
1236void
Jim Ingham10622a22010-06-18 00:58:52 +00001237CommandObjectBreakpointModify::CommandOptions::ResetOptionValues ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001238{
1239 Options::ResetOptionValues();
1240
Greg Clayton54e7afa2010-07-09 20:39:50 +00001241 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001242 m_thread_id = LLDB_INVALID_THREAD_ID;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001243 m_thread_index = UINT32_MAX;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001244 m_thread_name.clear();
1245 m_queue_name.clear();
Jim Ingham10622a22010-06-18 00:58:52 +00001246 m_enable_passed = false;
Jim Inghamd4571222010-06-19 04:35:20 +00001247 m_queue_passed = false;
1248 m_name_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001249}
1250
1251//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001252// CommandObjectBreakpointModify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001253//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001254#pragma mark Modify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001255
Greg Clayton238c0a12010-09-18 01:14:36 +00001256CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
1257 CommandObject (interpreter,
1258 "breakpoint modify",
1259 "Modify the options on a breakpoint or set of breakpoints in the executable.",
Caroline Ticefb355112010-10-01 17:46:38 +00001260 NULL)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001261{
Caroline Ticefb355112010-10-01 17:46:38 +00001262 CommandArgumentEntry arg;
1263 CommandArgumentData bp_id_arg;
1264 CommandArgumentData bp_id_range_arg;
1265
1266 // Create the first variant for the first (and only) argument for this command.
1267 bp_id_arg.arg_type = eArgTypeBreakpointID;
1268 bp_id_arg.arg_repetition = eArgRepeatPlus;
1269
1270 // Create the second variant for the first (and only) argument for this command.
1271 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
1272 bp_id_range_arg.arg_repetition = eArgRepeatPlus;
1273
1274 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1275 // Push both variants into the entry for the first argument for this command.
1276 arg.push_back (bp_id_arg);
1277 arg.push_back (bp_id_range_arg);
1278
1279 // Add the entry for the first argument for this command to the object's arguments vector.
1280 m_arguments.push_back (arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001281}
1282
Jim Ingham10622a22010-06-18 00:58:52 +00001283CommandObjectBreakpointModify::~CommandObjectBreakpointModify ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001284{
1285}
1286
1287Options *
Jim Ingham10622a22010-06-18 00:58:52 +00001288CommandObjectBreakpointModify::GetOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001289{
1290 return &m_options;
1291}
1292
1293bool
Jim Ingham10622a22010-06-18 00:58:52 +00001294CommandObjectBreakpointModify::Execute
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001295(
1296 Args& command,
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001297 CommandReturnObject &result
1298)
1299{
1300 if (command.GetArgumentCount() == 0)
1301 {
1302 result.AppendError ("No breakpoints specified.");
1303 result.SetStatus (eReturnStatusFailed);
1304 return false;
1305 }
1306
Greg Clayton238c0a12010-09-18 01:14:36 +00001307 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001308 if (target == NULL)
1309 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001310 result.AppendError ("Invalid target. No existing target or breakpoints.");
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001311 result.SetStatus (eReturnStatusFailed);
1312 return false;
1313 }
1314
1315 Mutex::Locker locker;
1316 target->GetBreakpointList().GetListMutex(locker);
1317
1318 BreakpointIDList valid_bp_ids;
1319
1320 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1321
1322 if (result.Succeeded())
1323 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001324 const size_t count = valid_bp_ids.GetSize();
1325 for (size_t i = 0; i < count; ++i)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001326 {
1327 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1328
1329 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1330 {
1331 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1332 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1333 {
1334 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
1335 if (location)
1336 {
1337 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
1338 location->SetThreadID (m_options.m_thread_id);
1339
Greg Clayton54e7afa2010-07-09 20:39:50 +00001340 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001341 location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1342
Jim Inghamd4571222010-06-19 04:35:20 +00001343 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001344 location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1345
Jim Inghamd4571222010-06-19 04:35:20 +00001346 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001347 location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1348
Greg Clayton54e7afa2010-07-09 20:39:50 +00001349 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001350 location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001351
1352 if (m_options.m_enable_passed)
1353 location->SetEnabled (m_options.m_enable_value);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001354 }
1355 }
1356 else
1357 {
1358 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
1359 bp->SetThreadID (m_options.m_thread_id);
1360
Greg Clayton54e7afa2010-07-09 20:39:50 +00001361 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001362 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1363
Jim Inghamd4571222010-06-19 04:35:20 +00001364 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001365 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1366
Jim Inghamd4571222010-06-19 04:35:20 +00001367 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001368 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1369
Greg Clayton54e7afa2010-07-09 20:39:50 +00001370 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001371 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001372
1373 if (m_options.m_enable_passed)
1374 bp->SetEnabled (m_options.m_enable_value);
1375
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001376 }
1377 }
1378 }
1379 }
1380
1381 return result.Succeeded();
1382}
1383
1384