blob: 2fc5f2b3085dbce40209695870d24358b77df533 [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.",
688 "breakpoint list [<breakpoint-id>]")
Chris Lattner24943d22010-06-08 16:52:24 +0000689{
690}
691
692CommandObjectBreakpointList::~CommandObjectBreakpointList ()
693{
694}
695
696Options *
697CommandObjectBreakpointList::GetOptions ()
698{
699 return &m_options;
700}
701
702bool
703CommandObjectBreakpointList::Execute
704(
705 Args& args,
Chris Lattner24943d22010-06-08 16:52:24 +0000706 CommandReturnObject &result
707)
708{
Greg Clayton238c0a12010-09-18 01:14:36 +0000709 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000710 if (target == NULL)
711 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000712 result.AppendError ("Invalid target. No current target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000713 result.SetStatus (eReturnStatusSuccessFinishNoResult);
714 return true;
715 }
716
717 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000718 Mutex::Locker locker;
719 target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
720
Chris Lattner24943d22010-06-08 16:52:24 +0000721 size_t num_breakpoints = breakpoints.GetSize();
722
723 if (num_breakpoints == 0)
724 {
725 result.AppendMessage ("No breakpoints currently set.");
726 result.SetStatus (eReturnStatusSuccessFinishNoResult);
727 return true;
728 }
729
730 StreamString &output_stream = result.GetOutputStream();
731
732 if (args.GetArgumentCount() == 0)
733 {
734 // No breakpoint selected; show info about all currently set breakpoints.
735 result.AppendMessage ("Current breakpoints:");
Greg Clayton54e7afa2010-07-09 20:39:50 +0000736 for (size_t i = 0; i < num_breakpoints; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000737 {
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000738 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000739 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000740 }
741 result.SetStatus (eReturnStatusSuccessFinishNoResult);
742 }
743 else
744 {
745 // Particular breakpoints selected; show info about that breakpoint.
746 BreakpointIDList valid_bp_ids;
747 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
748
749 if (result.Succeeded())
750 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000751 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000752 {
753 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
754 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000755 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000756 }
757 result.SetStatus (eReturnStatusSuccessFinishNoResult);
758 }
759 else
760 {
761 result.AppendError ("Invalid breakpoint id.");
762 result.SetStatus (eReturnStatusFailed);
763 }
764 }
765
766 return result.Succeeded();
767}
768
769//-------------------------------------------------------------------------
770// CommandObjectBreakpointEnable
771//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000772#pragma mark Enable
Chris Lattner24943d22010-06-08 16:52:24 +0000773
Greg Clayton238c0a12010-09-18 01:14:36 +0000774CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
775 CommandObject (interpreter,
776 "enable",
777 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
778 "breakpoint enable [<breakpoint-id> | <breakpoint-id-list>]")
Chris Lattner24943d22010-06-08 16:52:24 +0000779{
780 // This command object can either be called via 'enable' or 'breakpoint enable'. Because it has two different
781 // potential invocation methods, we need to be a little tricky about generating the syntax string.
782 //StreamString tmp_string;
783 //tmp_string.Printf ("%s <breakpoint-id>", GetCommandName());
784 //m_cmd_syntax.assign (tmp_string.GetData(), tmp_string.GetSize());
785}
786
787
788CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable ()
789{
790}
791
792
793bool
Greg Clayton63094e02010-06-23 01:19:29 +0000794CommandObjectBreakpointEnable::Execute
795(
Greg Clayton63094e02010-06-23 01:19:29 +0000796 Args& args,
797 CommandReturnObject &result
798)
Chris Lattner24943d22010-06-08 16:52:24 +0000799{
Greg Clayton238c0a12010-09-18 01:14:36 +0000800 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000801 if (target == NULL)
802 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000803 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000804 result.SetStatus (eReturnStatusFailed);
805 return false;
806 }
807
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000808 Mutex::Locker locker;
809 target->GetBreakpointList().GetListMutex(locker);
810
Chris Lattner24943d22010-06-08 16:52:24 +0000811 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000812
Chris Lattner24943d22010-06-08 16:52:24 +0000813 size_t num_breakpoints = breakpoints.GetSize();
814
815 if (num_breakpoints == 0)
816 {
817 result.AppendError ("No breakpoints exist to be enabled.");
818 result.SetStatus (eReturnStatusFailed);
819 return false;
820 }
821
822 if (args.GetArgumentCount() == 0)
823 {
824 // No breakpoint selected; enable all currently set breakpoints.
825 target->EnableAllBreakpoints ();
826 result.AppendMessageWithFormat ("All breakpoints enabled. (%d breakpoints)\n", num_breakpoints);
827 result.SetStatus (eReturnStatusSuccessFinishNoResult);
828 }
829 else
830 {
831 // Particular breakpoint selected; enable that breakpoint.
832 BreakpointIDList valid_bp_ids;
833 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
834
835 if (result.Succeeded())
836 {
837 int enable_count = 0;
838 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000839 const size_t count = valid_bp_ids.GetSize();
840 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000841 {
842 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
843
844 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
845 {
846 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
847 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
848 {
849 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
850 if (location)
851 {
852 location->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000853 ++loc_count;
854 }
855 }
856 else
857 {
Jim Ingham10622a22010-06-18 00:58:52 +0000858 breakpoint->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000859 ++enable_count;
Chris Lattner24943d22010-06-08 16:52:24 +0000860 }
861 }
862 }
863 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
864 result.SetStatus (eReturnStatusSuccessFinishNoResult);
865 }
866 }
867
868 return result.Succeeded();
869}
870
871//-------------------------------------------------------------------------
872// CommandObjectBreakpointDisable
873//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000874#pragma mark Disable
Chris Lattner24943d22010-06-08 16:52:24 +0000875
Greg Clayton238c0a12010-09-18 01:14:36 +0000876CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
877 CommandObject (interpreter,
878 "disable",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000879 "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.",
Chris Lattner24943d22010-06-08 16:52:24 +0000880 "disable [<breakpoint-id> | <breakpoint-id-list>]")
881{
882 // This command object can either be called via 'enable' or 'breakpoint enable'. Because it has two different
883 // potential invocation methods, we need to be a little tricky about generating the syntax string.
884 //StreamString tmp_string;
885 //tmp_string.Printf ("%s <breakpoint-id>", GetCommandName());
886 //m_cmd_syntax.assign(tmp_string.GetData(), tmp_string.GetSize());
887}
888
889CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable ()
890{
891}
892
893bool
Greg Clayton63094e02010-06-23 01:19:29 +0000894CommandObjectBreakpointDisable::Execute
895(
Greg Clayton63094e02010-06-23 01:19:29 +0000896 Args& args,
897 CommandReturnObject &result
898)
Chris Lattner24943d22010-06-08 16:52:24 +0000899{
Greg Clayton238c0a12010-09-18 01:14:36 +0000900 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000901 if (target == NULL)
902 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000903 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000904 result.SetStatus (eReturnStatusFailed);
905 return false;
906 }
907
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000908 Mutex::Locker locker;
909 target->GetBreakpointList().GetListMutex(locker);
910
Chris Lattner24943d22010-06-08 16:52:24 +0000911 const BreakpointList &breakpoints = target->GetBreakpointList();
912 size_t num_breakpoints = breakpoints.GetSize();
913
914 if (num_breakpoints == 0)
915 {
916 result.AppendError ("No breakpoints exist to be disabled.");
917 result.SetStatus (eReturnStatusFailed);
918 return false;
919 }
920
921 if (args.GetArgumentCount() == 0)
922 {
923 // No breakpoint selected; disable all currently set breakpoints.
924 target->DisableAllBreakpoints ();
925 result.AppendMessageWithFormat ("All breakpoints disabled. (%d breakpoints)\n", num_breakpoints);
926 result.SetStatus (eReturnStatusSuccessFinishNoResult);
927 }
928 else
929 {
930 // Particular breakpoint selected; disable that breakpoint.
931 BreakpointIDList valid_bp_ids;
932
933 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
934
935 if (result.Succeeded())
936 {
937 int disable_count = 0;
938 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000939 const size_t count = valid_bp_ids.GetSize();
940 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000941 {
942 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
943
944 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
945 {
946 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
947 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
948 {
949 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
950 if (location)
951 {
952 location->SetEnabled (false);
953 ++loc_count;
954 }
955 }
956 else
957 {
Jim Ingham10622a22010-06-18 00:58:52 +0000958 breakpoint->SetEnabled (false);
Chris Lattner24943d22010-06-08 16:52:24 +0000959 ++disable_count;
Chris Lattner24943d22010-06-08 16:52:24 +0000960 }
961 }
962 }
963 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
964 result.SetStatus (eReturnStatusSuccessFinishNoResult);
965 }
966 }
967
968 return result.Succeeded();
969}
970
971//-------------------------------------------------------------------------
972// CommandObjectBreakpointDelete
973//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000974#pragma mark Delete
Chris Lattner24943d22010-06-08 16:52:24 +0000975
Greg Clayton238c0a12010-09-18 01:14:36 +0000976CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) :
977 CommandObject (interpreter,
978 "breakpoint delete",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000979 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
Chris Lattner24943d22010-06-08 16:52:24 +0000980 "breakpoint delete [<breakpoint-id> | <breakpoint-id-list>]")
981{
982}
983
984
985CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete ()
986{
987}
988
989bool
Greg Clayton63094e02010-06-23 01:19:29 +0000990CommandObjectBreakpointDelete::Execute
991(
Greg Clayton63094e02010-06-23 01:19:29 +0000992 Args& args,
993 CommandReturnObject &result
994)
Chris Lattner24943d22010-06-08 16:52:24 +0000995{
Greg Clayton238c0a12010-09-18 01:14:36 +0000996 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000997 if (target == NULL)
998 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000999 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +00001000 result.SetStatus (eReturnStatusFailed);
1001 return false;
1002 }
1003
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001004 Mutex::Locker locker;
1005 target->GetBreakpointList().GetListMutex(locker);
1006
Chris Lattner24943d22010-06-08 16:52:24 +00001007 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001008
Chris Lattner24943d22010-06-08 16:52:24 +00001009 size_t num_breakpoints = breakpoints.GetSize();
1010
1011 if (num_breakpoints == 0)
1012 {
1013 result.AppendError ("No breakpoints exist to be deleted.");
1014 result.SetStatus (eReturnStatusFailed);
1015 return false;
1016 }
1017
1018 if (args.GetArgumentCount() == 0)
1019 {
1020 // No breakpoint selected; disable all currently set breakpoints.
1021 if (args.GetArgumentCount() != 0)
1022 {
1023 result.AppendErrorWithFormat ("Specify breakpoints to delete with the -i option.\n");
1024 result.SetStatus (eReturnStatusFailed);
1025 return false;
1026 }
1027
1028 target->RemoveAllBreakpoints ();
1029 result.AppendMessageWithFormat ("All breakpoints removed. (%d breakpoints)\n", num_breakpoints);
1030 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1031 }
1032 else
1033 {
1034 // Particular breakpoint selected; disable that breakpoint.
1035 BreakpointIDList valid_bp_ids;
1036 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
1037
1038 if (result.Succeeded())
1039 {
1040 int delete_count = 0;
1041 int disable_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001042 const size_t count = valid_bp_ids.GetSize();
1043 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +00001044 {
1045 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1046
1047 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1048 {
1049 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1050 {
1051 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1052 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1053 // It makes no sense to try to delete individual locations, so we disable them instead.
1054 if (location)
1055 {
1056 location->SetEnabled (false);
1057 ++disable_count;
1058 }
1059 }
1060 else
1061 {
1062 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1063 ++delete_count;
1064 }
1065 }
1066 }
1067 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1068 delete_count, disable_count);
1069 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1070 }
1071 }
1072 return result.Succeeded();
1073}
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001074
1075//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001076// CommandObjectBreakpointModify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001077//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001078#pragma mark Modify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001079
Jim Ingham10622a22010-06-18 00:58:52 +00001080CommandObjectBreakpointModify::CommandOptions::CommandOptions() :
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001081 Options (),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001082 m_ignore_count (0),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001083 m_thread_id(LLDB_INVALID_THREAD_ID),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001084 m_thread_index (UINT32_MAX),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001085 m_thread_name(),
1086 m_queue_name(),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001087 m_enable_passed (false),
1088 m_enable_value (false),
1089 m_name_passed (false),
1090 m_queue_passed (false)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001091{
1092}
1093
Jim Ingham10622a22010-06-18 00:58:52 +00001094CommandObjectBreakpointModify::CommandOptions::~CommandOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001095{
1096}
1097
1098lldb::OptionDefinition
Jim Ingham10622a22010-06-18 00:58:52 +00001099CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001100{
Greg Claytonfe424a92010-09-18 03:37:20 +00001101{ LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, NULL, "<n>", "Set the number of times this breakpoint is skipped before stopping." },
1102{ 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."},
1103{ 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."},
1104{ 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."},
1105{ 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."},
1106{ LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, NULL, "Enable the breakpoint."},
1107{ LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, NULL, "Disable the breakpoint."},
1108{ 0, false, NULL, 0 , 0, NULL, 0, NULL, NULL }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001109};
1110
1111const lldb::OptionDefinition*
Jim Ingham10622a22010-06-18 00:58:52 +00001112CommandObjectBreakpointModify::CommandOptions::GetDefinitions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001113{
1114 return g_option_table;
1115}
1116
1117Error
Jim Ingham10622a22010-06-18 00:58:52 +00001118CommandObjectBreakpointModify::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001119{
1120 Error error;
1121 char short_option = (char) m_getopt_table[option_idx].val;
1122
1123 switch (short_option)
1124 {
Jim Ingham10622a22010-06-18 00:58:52 +00001125 case 'd':
1126 m_enable_passed = true;
1127 m_enable_value = false;
1128 break;
1129 case 'e':
1130 m_enable_passed = true;
1131 m_enable_value = true;
1132 break;
Greg Claytonfe424a92010-09-18 03:37:20 +00001133 case 'i':
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001134 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001135 m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0);
1136 if (m_ignore_count == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001137 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg);
1138 }
Jim Ingham10622a22010-06-18 00:58:52 +00001139 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001140 case 't' :
1141 {
1142 m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0);
1143 if (m_thread_id == LLDB_INVALID_THREAD_ID)
1144 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg);
1145 }
1146 break;
1147 case 'T':
Jim Inghamd4571222010-06-19 04:35:20 +00001148 if (option_arg != NULL)
1149 m_thread_name = option_arg;
1150 else
1151 m_thread_name.clear();
1152 m_name_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001153 break;
1154 case 'q':
Jim Inghamd4571222010-06-19 04:35:20 +00001155 if (option_arg != NULL)
1156 m_queue_name = option_arg;
1157 else
1158 m_queue_name.clear();
1159 m_queue_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001160 break;
1161 case 'x':
1162 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001163 m_thread_index = Args::StringToUInt32 (optarg, UINT32_MAX, 0);
1164 if (m_thread_id == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001165 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg);
1166
1167 }
1168 break;
1169 default:
1170 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1171 break;
1172 }
1173
1174 return error;
1175}
1176
1177void
Jim Ingham10622a22010-06-18 00:58:52 +00001178CommandObjectBreakpointModify::CommandOptions::ResetOptionValues ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001179{
1180 Options::ResetOptionValues();
1181
Greg Clayton54e7afa2010-07-09 20:39:50 +00001182 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001183 m_thread_id = LLDB_INVALID_THREAD_ID;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001184 m_thread_index = UINT32_MAX;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001185 m_thread_name.clear();
1186 m_queue_name.clear();
Jim Ingham10622a22010-06-18 00:58:52 +00001187 m_enable_passed = false;
Jim Inghamd4571222010-06-19 04:35:20 +00001188 m_queue_passed = false;
1189 m_name_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001190}
1191
1192//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001193// CommandObjectBreakpointModify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001194//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001195#pragma mark Modify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001196
Greg Clayton238c0a12010-09-18 01:14:36 +00001197CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
1198 CommandObject (interpreter,
1199 "breakpoint modify",
1200 "Modify the options on a breakpoint or set of breakpoints in the executable.",
Caroline Tice31fbb642010-09-08 22:08:58 +00001201 "breakpoint modify <cmd-options> <breakpoint-id> [<breakpoint-id> ...]")
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001202{
1203}
1204
Jim Ingham10622a22010-06-18 00:58:52 +00001205CommandObjectBreakpointModify::~CommandObjectBreakpointModify ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001206{
1207}
1208
1209Options *
Jim Ingham10622a22010-06-18 00:58:52 +00001210CommandObjectBreakpointModify::GetOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001211{
1212 return &m_options;
1213}
1214
1215bool
Jim Ingham10622a22010-06-18 00:58:52 +00001216CommandObjectBreakpointModify::Execute
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001217(
1218 Args& command,
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001219 CommandReturnObject &result
1220)
1221{
1222 if (command.GetArgumentCount() == 0)
1223 {
1224 result.AppendError ("No breakpoints specified.");
1225 result.SetStatus (eReturnStatusFailed);
1226 return false;
1227 }
1228
Greg Clayton238c0a12010-09-18 01:14:36 +00001229 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001230 if (target == NULL)
1231 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001232 result.AppendError ("Invalid target. No existing target or breakpoints.");
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001233 result.SetStatus (eReturnStatusFailed);
1234 return false;
1235 }
1236
1237 Mutex::Locker locker;
1238 target->GetBreakpointList().GetListMutex(locker);
1239
1240 BreakpointIDList valid_bp_ids;
1241
1242 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1243
1244 if (result.Succeeded())
1245 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001246 const size_t count = valid_bp_ids.GetSize();
1247 for (size_t i = 0; i < count; ++i)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001248 {
1249 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1250
1251 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1252 {
1253 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1254 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1255 {
1256 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
1257 if (location)
1258 {
1259 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
1260 location->SetThreadID (m_options.m_thread_id);
1261
Greg Clayton54e7afa2010-07-09 20:39:50 +00001262 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001263 location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1264
Jim Inghamd4571222010-06-19 04:35:20 +00001265 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001266 location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1267
Jim Inghamd4571222010-06-19 04:35:20 +00001268 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001269 location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1270
Greg Clayton54e7afa2010-07-09 20:39:50 +00001271 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001272 location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001273
1274 if (m_options.m_enable_passed)
1275 location->SetEnabled (m_options.m_enable_value);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001276 }
1277 }
1278 else
1279 {
1280 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
1281 bp->SetThreadID (m_options.m_thread_id);
1282
Greg Clayton54e7afa2010-07-09 20:39:50 +00001283 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001284 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1285
Jim Inghamd4571222010-06-19 04:35:20 +00001286 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001287 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1288
Jim Inghamd4571222010-06-19 04:35:20 +00001289 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001290 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1291
Greg Clayton54e7afa2010-07-09 20:39:50 +00001292 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001293 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001294
1295 if (m_options.m_enable_passed)
1296 bp->SetEnabled (m_options.m_enable_value);
1297
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001298 }
1299 }
1300 }
1301 }
1302
1303 return result.Succeeded();
1304}
1305
1306