blob: 3bbd282aca62884c2d7ae7bbfd8e01c4aaa01967 [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 Clayton12bec712010-06-28 21:30:43 +000077 { LLDB_OPT_SET_ALL, false, "ignore_count", 'k', 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 Clayton12bec712010-06-28 21:30:43 +000080 { LLDB_OPT_SET_ALL, false, "thread_index", 'x', required_argument, NULL, NULL, "<thread_index>",
Jim Ingham3c7b5b92010-06-16 02:00:15 +000081 "The breakpoint stops only for the thread whose indeX matches this argument."},
82
Greg Clayton12bec712010-06-28 21:30:43 +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 Clayton12bec712010-06-28 21:30:43 +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 Clayton12bec712010-06-28 21:30:43 +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>",
Chris Lattner24943d22010-06-08 16:52:24 +0000107 "Set the breakpoint by function name." },
108
Greg Clayton12bec712010-06-28 21:30:43 +0000109 { LLDB_OPT_SET_3, false, "basename", 'b', no_argument, NULL, 0, NULL,
110 "Used in conjuction with --name <name> to search function basenames." },
111
112 { LLDB_OPT_SET_3, false, "fullname", 'F', no_argument, NULL, 0, NULL,
113 "Used in conjuction with --name <name> to search fully qualified function names. For C++ this means namespaces and all arguemnts, and for Objective C this means a full function prototype with class and selector." },
114
115 { LLDB_OPT_SET_3, false, "selector", 'S', no_argument, NULL, 0, NULL,
116 "Used in conjuction with --name <name> to search objective C selector names." },
117
118 { LLDB_OPT_SET_3, false, "method", 'm', no_argument, NULL, 0, NULL,
119 "Used in conjuction with --name <name> to search objective C selector C++ method names." },
120
Jim Ingham34e9a982010-06-15 18:47:14 +0000121 { LLDB_OPT_SET_4, true, "func_regex", 'r', required_argument, NULL, 0, "<regular-expression>",
Chris Lattner24943d22010-06-08 16:52:24 +0000122 "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
123
Chris Lattner24943d22010-06-08 16:52:24 +0000124 { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL }
125};
126
127const lldb::OptionDefinition*
128CommandObjectBreakpointSet::CommandOptions::GetDefinitions ()
129{
130 return g_option_table;
131}
132
133Error
134CommandObjectBreakpointSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
135{
136 Error error;
137 char short_option = (char) m_getopt_table[option_idx].val;
138
139 switch (short_option)
140 {
141 case 'a':
142 m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 0);
143 if (m_load_addr == LLDB_INVALID_ADDRESS)
144 m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 16);
145
146 if (m_load_addr == LLDB_INVALID_ADDRESS)
147 error.SetErrorStringWithFormat ("Invalid address string '%s'.\n", optarg);
148 break;
149
150 case 'c':
151 m_column = Args::StringToUInt32 (option_arg, 0);
152 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000153
Chris Lattner24943d22010-06-08 16:52:24 +0000154 case 'f':
155 m_filename = option_arg;
156 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000157
Chris Lattner24943d22010-06-08 16:52:24 +0000158 case 'l':
159 m_line_num = Args::StringToUInt32 (option_arg, 0);
160 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000161
Chris Lattner24943d22010-06-08 16:52:24 +0000162 case 'n':
163 m_func_name = option_arg;
164 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000165
166 case 'b':
167 m_func_name_type_mask |= eFunctionNameTypeBase;
168 break;
169
170 case 'F':
171 m_func_name_type_mask |= eFunctionNameTypeFull;
172 break;
173
174 case 'S':
175 m_func_name_type_mask |= eFunctionNameTypeSelector;
176 break;
177
178 case 'm':
179 m_func_name_type_mask |= eFunctionNameTypeMethod;
180 break;
181
Chris Lattner24943d22010-06-08 16:52:24 +0000182 case 'r':
183 m_func_regexp = option_arg;
184 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000185
Chris Lattner24943d22010-06-08 16:52:24 +0000186 case 's':
187 {
188 m_modules.push_back (std::string (option_arg));
189 break;
190 }
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000191 case 'k':
192 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000193 m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0);
194 if (m_ignore_count == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000195 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg);
196 }
Jim Ingham10622a22010-06-18 00:58:52 +0000197 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000198 case 't' :
199 {
200 m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0);
201 if (m_thread_id == LLDB_INVALID_THREAD_ID)
202 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg);
203 }
204 break;
205 case 'T':
206 m_thread_name = option_arg;
207 break;
208 case 'q':
209 m_queue_name = option_arg;
210 break;
211 case 'x':
212 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000213 m_thread_index = Args::StringToUInt32(optarg, UINT32_MAX, 0);
214 if (m_thread_id == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000215 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg);
216
217 }
218 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000219 default:
220 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
221 break;
222 }
223
224 return error;
225}
226
227void
228CommandObjectBreakpointSet::CommandOptions::ResetOptionValues ()
229{
230 Options::ResetOptionValues();
231
232 m_filename.clear();
233 m_line_num = 0;
234 m_column = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000235 m_func_name.clear();
Greg Clayton12bec712010-06-28 21:30:43 +0000236 m_func_name_type_mask = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000237 m_func_regexp.clear();
238 m_load_addr = LLDB_INVALID_ADDRESS;
239 m_modules.clear();
Greg Clayton54e7afa2010-07-09 20:39:50 +0000240 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000241 m_thread_id = LLDB_INVALID_THREAD_ID;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000242 m_thread_index = UINT32_MAX;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000243 m_thread_name.clear();
244 m_queue_name.clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000245}
246
247//-------------------------------------------------------------------------
248// CommandObjectBreakpointSet
249//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000250#pragma mark Set
Chris Lattner24943d22010-06-08 16:52:24 +0000251
252CommandObjectBreakpointSet::CommandObjectBreakpointSet () :
253 CommandObject ("breakpoint set", "Sets a breakpoint or set of breakpoints in the executable.",
254 "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(
Greg Clayton63094e02010-06-23 01:19:29 +0000271 CommandInterpreter &interpreter,
Chris Lattner24943d22010-06-08 16:52:24 +0000272 Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000273 CommandReturnObject &result
274)
275{
Jim Inghamc8332952010-08-26 21:32:51 +0000276 Target *target = interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000277 if (target == NULL)
278 {
279 result.AppendError ("Invalid target, set executable file using 'file' command.");
280 result.SetStatus (eReturnStatusFailed);
281 return false;
282 }
283
284 // The following are the various types of breakpoints that could be set:
285 // 1). -f -l -p [-s -g] (setting breakpoint by source location)
286 // 2). -a [-s -g] (setting breakpoint by address)
287 // 3). -n [-s -g] (setting breakpoint by function name)
288 // 4). -r [-s -g] (setting breakpoint by function name regular expression)
289
290 BreakpointSetType break_type = eSetTypeInvalid;
291
292 if (m_options.m_line_num != 0)
293 break_type = eSetTypeFileAndLine;
294 else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
295 break_type = eSetTypeAddress;
296 else if (!m_options.m_func_name.empty())
297 break_type = eSetTypeFunctionName;
298 else if (!m_options.m_func_regexp.empty())
299 break_type = eSetTypeFunctionRegexp;
300
301 ModuleSP module_sp = target->GetExecutableModule();
302 Breakpoint *bp = NULL;
303 FileSpec module;
304 bool use_module = false;
305 int num_modules = m_options.m_modules.size();
306
307 if ((num_modules > 0) && (break_type != eSetTypeAddress))
308 use_module = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000309
Chris Lattner24943d22010-06-08 16:52:24 +0000310 switch (break_type)
311 {
312 case eSetTypeFileAndLine: // Breakpoint by source position
313 {
314 FileSpec file;
315 if (m_options.m_filename.empty())
316 {
Greg Clayton63094e02010-06-23 01:19:29 +0000317 StackFrame *cur_frame = interpreter.GetDebugger().GetExecutionContext().frame;
Chris Lattner24943d22010-06-08 16:52:24 +0000318 if (cur_frame == NULL)
319 {
320 result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame.");
321 result.SetStatus (eReturnStatusFailed);
322 break;
323 }
324 else if (!cur_frame->HasDebugInformation())
325 {
326 result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info.");
327 result.SetStatus (eReturnStatusFailed);
328 break;
329 }
330 else
331 {
332 const SymbolContext &context = cur_frame->GetSymbolContext(true);
333 if (context.line_entry.file)
334 {
335 file = context.line_entry.file;
336 }
337 else if (context.comp_unit != NULL)
338 { file = context.comp_unit;
339 }
340 else
341 {
342 result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame.");
343 result.SetStatus (eReturnStatusFailed);
344 break;
345 }
346 }
347 }
348 else
349 {
350 file.SetFile(m_options.m_filename.c_str());
351 }
352
353 if (use_module)
354 {
355 for (int i = 0; i < num_modules; ++i)
356 {
357 module.SetFile(m_options.m_modules[i].c_str());
358 bp = target->CreateBreakpoint (&module,
359 file,
360 m_options.m_line_num,
361 m_options.m_ignore_inlines).get();
362 if (bp)
363 {
364 StreamString &output_stream = result.GetOutputStream();
365 output_stream.Printf ("Breakpoint created: ");
366 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
367 output_stream.EOL();
368 result.SetStatus (eReturnStatusSuccessFinishResult);
369 }
370 else
371 {
372 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
373 m_options.m_modules[i].c_str());
374 result.SetStatus (eReturnStatusFailed);
375 }
376 }
377 }
378 else
379 bp = target->CreateBreakpoint (NULL,
380 file,
381 m_options.m_line_num,
382 m_options.m_ignore_inlines).get();
383 }
384 break;
385 case eSetTypeAddress: // Breakpoint by address
386 bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
387 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000388
Chris Lattner24943d22010-06-08 16:52:24 +0000389 case eSetTypeFunctionName: // Breakpoint by function name
Chris Lattner24943d22010-06-08 16:52:24 +0000390 {
Greg Clayton12bec712010-06-28 21:30:43 +0000391 uint32_t name_type_mask = m_options.m_func_name_type_mask;
392
393 if (name_type_mask == 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000394 {
Greg Clayton12bec712010-06-28 21:30:43 +0000395
396 if (m_options.m_func_name.find('(') != std::string::npos ||
397 m_options.m_func_name.find("-[") == 0 ||
398 m_options.m_func_name.find("+[") == 0)
399 name_type_mask |= eFunctionNameTypeFull;
Chris Lattner24943d22010-06-08 16:52:24 +0000400 else
Greg Clayton12bec712010-06-28 21:30:43 +0000401 name_type_mask |= eFunctionNameTypeBase;
402 }
403
404
405 if (use_module)
406 {
407 for (int i = 0; i < num_modules; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000408 {
Greg Clayton12bec712010-06-28 21:30:43 +0000409 module.SetFile(m_options.m_modules[i].c_str());
410 bp = target->CreateBreakpoint (&module, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get();
411 if (bp)
412 {
413 StreamString &output_stream = result.GetOutputStream();
414 output_stream.Printf ("Breakpoint created: ");
415 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
416 output_stream.EOL();
417 result.SetStatus (eReturnStatusSuccessFinishResult);
418 }
419 else
420 {
421 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
422 m_options.m_modules[i].c_str());
423 result.SetStatus (eReturnStatusFailed);
424 }
Chris Lattner24943d22010-06-08 16:52:24 +0000425 }
426 }
Greg Clayton12bec712010-06-28 21:30:43 +0000427 else
428 bp = target->CreateBreakpoint (NULL, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000429 }
Chris Lattner24943d22010-06-08 16:52:24 +0000430 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000431
Chris Lattner24943d22010-06-08 16:52:24 +0000432 case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
433 {
434 RegularExpression regexp(m_options.m_func_regexp.c_str());
435 if (use_module)
436 {
437 for (int i = 0; i < num_modules; ++i)
438 {
439 module.SetFile(m_options.m_modules[i].c_str());
440 bp = target->CreateBreakpoint (&module, regexp).get();
441 if (bp)
442 {
443 StreamString &output_stream = result.GetOutputStream();
444 output_stream.Printf ("Breakpoint created: ");
445 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
446 output_stream.EOL();
447 result.SetStatus (eReturnStatusSuccessFinishResult);
448 }
449 else
450 {
451 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
452 m_options.m_modules[i].c_str());
453 result.SetStatus (eReturnStatusFailed);
454 }
455 }
456 }
457 else
458 bp = target->CreateBreakpoint (NULL, regexp).get();
459 }
460 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000461
Chris Lattner24943d22010-06-08 16:52:24 +0000462 default:
463 break;
464 }
465
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000466 // Now set the various options that were passed in:
467 if (bp)
468 {
469 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
470 bp->SetThreadID (m_options.m_thread_id);
471
Greg Clayton54e7afa2010-07-09 20:39:50 +0000472 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000473 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
474
475 if (!m_options.m_thread_name.empty())
476 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
477
478 if (!m_options.m_queue_name.empty())
479 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
480
Greg Clayton54e7afa2010-07-09 20:39:50 +0000481 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000482 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
483 }
484
Chris Lattner24943d22010-06-08 16:52:24 +0000485 if (bp && !use_module)
486 {
487 StreamString &output_stream = result.GetOutputStream();
488 output_stream.Printf ("Breakpoint created: ");
489 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
490 output_stream.EOL();
491 result.SetStatus (eReturnStatusSuccessFinishResult);
492 }
493 else if (!bp)
494 {
495 result.AppendError ("Breakpoint creation failed: No breakpoint created.");
496 result.SetStatus (eReturnStatusFailed);
497 }
498
499 return result.Succeeded();
500}
501
Chris Lattner24943d22010-06-08 16:52:24 +0000502//-------------------------------------------------------------------------
503// CommandObjectMultiwordBreakpoint
504//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000505#pragma mark MultiwordBreakpoint
Chris Lattner24943d22010-06-08 16:52:24 +0000506
Greg Clayton63094e02010-06-23 01:19:29 +0000507CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
Chris Lattner24943d22010-06-08 16:52:24 +0000508 CommandObjectMultiword ("breakpoint",
509 "A set of commands for operating on breakpoints.",
510 "breakpoint <command> [<command-options>]")
511{
512 bool status;
513
514 CommandObjectSP list_command_object (new CommandObjectBreakpointList ());
515 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete ());
516 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable ());
517 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable ());
518 CommandObjectSP set_command_object (new CommandObjectBreakpointSet ());
519 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
Jim Ingham10622a22010-06-18 00:58:52 +0000520 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify());
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 Clayton63094e02010-06-23 01:19:29 +0000529 status = LoadSubCommand (interpreter, "list", list_command_object);
530 status = LoadSubCommand (interpreter, "enable", enable_command_object);
531 status = LoadSubCommand (interpreter, "disable", disable_command_object);
532 status = LoadSubCommand (interpreter, "delete", delete_command_object);
533 status = LoadSubCommand (interpreter, "set", set_command_object);
534 status = LoadSubCommand (interpreter, "command", command_command_object);
535 status = LoadSubCommand (interpreter, "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
684CommandObjectBreakpointList::CommandObjectBreakpointList () :
685 CommandObject ("breakpoint list",
686 "List some or all breakpoints at configurable levels of detail.",
687 "breakpoint list [<breakpoint-id>]")
688{
689}
690
691CommandObjectBreakpointList::~CommandObjectBreakpointList ()
692{
693}
694
695Options *
696CommandObjectBreakpointList::GetOptions ()
697{
698 return &m_options;
699}
700
701bool
702CommandObjectBreakpointList::Execute
703(
Greg Clayton63094e02010-06-23 01:19:29 +0000704 CommandInterpreter &interpreter,
Chris Lattner24943d22010-06-08 16:52:24 +0000705 Args& args,
Chris Lattner24943d22010-06-08 16:52:24 +0000706 CommandReturnObject &result
707)
708{
Jim Inghamc8332952010-08-26 21:32:51 +0000709 Target *target = interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000710 if (target == NULL)
711 {
712 result.AppendError ("Invalid target, set executable file using 'file' command.");
713 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
774CommandObjectBreakpointEnable::CommandObjectBreakpointEnable () :
775 CommandObject ("enable",
776 "Enables the specified disabled breakpoint(s). If no breakpoints are specified, enables all of them.",
777 "breakpoint enable [<breakpoint-id> | <breakpoint-id-list>]")
778{
779 // This command object can either be called via 'enable' or 'breakpoint enable'. Because it has two different
780 // potential invocation methods, we need to be a little tricky about generating the syntax string.
781 //StreamString tmp_string;
782 //tmp_string.Printf ("%s <breakpoint-id>", GetCommandName());
783 //m_cmd_syntax.assign (tmp_string.GetData(), tmp_string.GetSize());
784}
785
786
787CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable ()
788{
789}
790
791
792bool
Greg Clayton63094e02010-06-23 01:19:29 +0000793CommandObjectBreakpointEnable::Execute
794(
795 CommandInterpreter &interpreter,
796 Args& args,
797 CommandReturnObject &result
798)
Chris Lattner24943d22010-06-08 16:52:24 +0000799{
Jim Inghamc8332952010-08-26 21:32:51 +0000800 Target *target = interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000801 if (target == NULL)
802 {
803 result.AppendError ("Invalid target, set executable file using 'file' command.");
804 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
876CommandObjectBreakpointDisable::CommandObjectBreakpointDisable () :
877 CommandObject ("disable",
878 "Disables the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disables them all.",
879 "disable [<breakpoint-id> | <breakpoint-id-list>]")
880{
881 // This command object can either be called via 'enable' or 'breakpoint enable'. Because it has two different
882 // potential invocation methods, we need to be a little tricky about generating the syntax string.
883 //StreamString tmp_string;
884 //tmp_string.Printf ("%s <breakpoint-id>", GetCommandName());
885 //m_cmd_syntax.assign(tmp_string.GetData(), tmp_string.GetSize());
886}
887
888CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable ()
889{
890}
891
892bool
Greg Clayton63094e02010-06-23 01:19:29 +0000893CommandObjectBreakpointDisable::Execute
894(
895 CommandInterpreter &interpreter,
896 Args& args,
897 CommandReturnObject &result
898)
Chris Lattner24943d22010-06-08 16:52:24 +0000899{
Jim Inghamc8332952010-08-26 21:32:51 +0000900 Target *target = interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000901 if (target == NULL)
902 {
903 result.AppendError ("Invalid target, set executable file using 'file' command.");
904 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
976CommandObjectBreakpointDelete::CommandObjectBreakpointDelete() :
977 CommandObject ("breakpoint delete",
978 "Delete the specified breakpoint(s). If no breakpoints are specified, deletes them all.",
979 "breakpoint delete [<breakpoint-id> | <breakpoint-id-list>]")
980{
981}
982
983
984CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete ()
985{
986}
987
988bool
Greg Clayton63094e02010-06-23 01:19:29 +0000989CommandObjectBreakpointDelete::Execute
990(
991 CommandInterpreter &interpreter,
992 Args& args,
993 CommandReturnObject &result
994)
Chris Lattner24943d22010-06-08 16:52:24 +0000995{
Jim Inghamc8332952010-08-26 21:32:51 +0000996 Target *target = interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000997 if (target == NULL)
998 {
999 result.AppendError ("Invalid target, set executable file using 'file' command.");
1000 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{
1101 { LLDB_OPT_SET_ALL, false, "ignore_count", 'k', required_argument, NULL, 0, NULL,
1102 "Set the number of times this breakpoint is sKipped before stopping." },
1103
1104 { LLDB_OPT_SET_ALL, false, "thread_index", 'x', required_argument, NULL, NULL, "<thread_index>",
1105 "The breakpoint stops only for the thread whose indeX matches this argument."},
1106
1107 { LLDB_OPT_SET_ALL, false, "thread_id", 't', required_argument, NULL, NULL, "<thread_id>",
1108 "The breakpoint stops only for the thread whose TID matches this argument."},
1109
1110 { LLDB_OPT_SET_ALL, false, "thread_name", 'T', required_argument, NULL, NULL, "<thread_name>",
1111 "The breakpoint stops only for the thread whose thread name matches this argument."},
1112
1113 { LLDB_OPT_SET_ALL, false, "queue_name", 'q', required_argument, NULL, NULL, "<queue_name>",
1114 "The breakpoint stops only for threads in the queue whose name is given by this argument."},
1115
Jim Ingham10622a22010-06-18 00:58:52 +00001116 { LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, NULL,
1117 "Enable the breakpoint."},
1118
1119 { LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, NULL,
1120 "Disable the breakpoint."},
1121
1122
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001123 { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL }
1124};
1125
1126const lldb::OptionDefinition*
Jim Ingham10622a22010-06-18 00:58:52 +00001127CommandObjectBreakpointModify::CommandOptions::GetDefinitions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001128{
1129 return g_option_table;
1130}
1131
1132Error
Jim Ingham10622a22010-06-18 00:58:52 +00001133CommandObjectBreakpointModify::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001134{
1135 Error error;
1136 char short_option = (char) m_getopt_table[option_idx].val;
1137
1138 switch (short_option)
1139 {
Jim Ingham10622a22010-06-18 00:58:52 +00001140 case 'd':
1141 m_enable_passed = true;
1142 m_enable_value = false;
1143 break;
1144 case 'e':
1145 m_enable_passed = true;
1146 m_enable_value = true;
1147 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001148 case 'k':
1149 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001150 m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0);
1151 if (m_ignore_count == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001152 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg);
1153 }
Jim Ingham10622a22010-06-18 00:58:52 +00001154 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001155 case 't' :
1156 {
1157 m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0);
1158 if (m_thread_id == LLDB_INVALID_THREAD_ID)
1159 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg);
1160 }
1161 break;
1162 case 'T':
Jim Inghamd4571222010-06-19 04:35:20 +00001163 if (option_arg != NULL)
1164 m_thread_name = option_arg;
1165 else
1166 m_thread_name.clear();
1167 m_name_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001168 break;
1169 case 'q':
Jim Inghamd4571222010-06-19 04:35:20 +00001170 if (option_arg != NULL)
1171 m_queue_name = option_arg;
1172 else
1173 m_queue_name.clear();
1174 m_queue_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001175 break;
1176 case 'x':
1177 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001178 m_thread_index = Args::StringToUInt32 (optarg, UINT32_MAX, 0);
1179 if (m_thread_id == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001180 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg);
1181
1182 }
1183 break;
1184 default:
1185 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1186 break;
1187 }
1188
1189 return error;
1190}
1191
1192void
Jim Ingham10622a22010-06-18 00:58:52 +00001193CommandObjectBreakpointModify::CommandOptions::ResetOptionValues ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001194{
1195 Options::ResetOptionValues();
1196
Greg Clayton54e7afa2010-07-09 20:39:50 +00001197 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001198 m_thread_id = LLDB_INVALID_THREAD_ID;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001199 m_thread_index = UINT32_MAX;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001200 m_thread_name.clear();
1201 m_queue_name.clear();
Jim Ingham10622a22010-06-18 00:58:52 +00001202 m_enable_passed = false;
Jim Inghamd4571222010-06-19 04:35:20 +00001203 m_queue_passed = false;
1204 m_name_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001205}
1206
1207//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001208// CommandObjectBreakpointModify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001209//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001210#pragma mark Modify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001211
Jim Ingham10622a22010-06-18 00:58:52 +00001212CommandObjectBreakpointModify::CommandObjectBreakpointModify () :
1213 CommandObject ("breakpoint modify", "Modifys the options on a breakpoint or set of breakpoints in the executable.",
1214 "breakpoint modify <cmd-options> break-id [break-id ...]")
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001215{
1216}
1217
Jim Ingham10622a22010-06-18 00:58:52 +00001218CommandObjectBreakpointModify::~CommandObjectBreakpointModify ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001219{
1220}
1221
1222Options *
Jim Ingham10622a22010-06-18 00:58:52 +00001223CommandObjectBreakpointModify::GetOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001224{
1225 return &m_options;
1226}
1227
1228bool
Jim Ingham10622a22010-06-18 00:58:52 +00001229CommandObjectBreakpointModify::Execute
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001230(
Greg Clayton63094e02010-06-23 01:19:29 +00001231 CommandInterpreter &interpreter,
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001232 Args& command,
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001233 CommandReturnObject &result
1234)
1235{
1236 if (command.GetArgumentCount() == 0)
1237 {
1238 result.AppendError ("No breakpoints specified.");
1239 result.SetStatus (eReturnStatusFailed);
1240 return false;
1241 }
1242
Jim Inghamc8332952010-08-26 21:32:51 +00001243 Target *target = interpreter.GetDebugger().GetSelectedTarget().get();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001244 if (target == NULL)
1245 {
1246 result.AppendError ("Invalid target, set executable file using 'file' command.");
1247 result.SetStatus (eReturnStatusFailed);
1248 return false;
1249 }
1250
1251 Mutex::Locker locker;
1252 target->GetBreakpointList().GetListMutex(locker);
1253
1254 BreakpointIDList valid_bp_ids;
1255
1256 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1257
1258 if (result.Succeeded())
1259 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001260 const size_t count = valid_bp_ids.GetSize();
1261 for (size_t i = 0; i < count; ++i)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001262 {
1263 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1264
1265 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1266 {
1267 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1268 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1269 {
1270 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
1271 if (location)
1272 {
1273 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
1274 location->SetThreadID (m_options.m_thread_id);
1275
Greg Clayton54e7afa2010-07-09 20:39:50 +00001276 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001277 location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1278
Jim Inghamd4571222010-06-19 04:35:20 +00001279 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001280 location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1281
Jim Inghamd4571222010-06-19 04:35:20 +00001282 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001283 location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1284
Greg Clayton54e7afa2010-07-09 20:39:50 +00001285 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001286 location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001287
1288 if (m_options.m_enable_passed)
1289 location->SetEnabled (m_options.m_enable_value);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001290 }
1291 }
1292 else
1293 {
1294 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
1295 bp->SetThreadID (m_options.m_thread_id);
1296
Greg Clayton54e7afa2010-07-09 20:39:50 +00001297 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001298 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1299
Jim Inghamd4571222010-06-19 04:35:20 +00001300 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001301 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1302
Jim Inghamd4571222010-06-19 04:35:20 +00001303 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001304 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1305
Greg Clayton54e7afa2010-07-09 20:39:50 +00001306 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001307 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001308
1309 if (m_options.m_enable_passed)
1310 bp->SetEnabled (m_options.m_enable_value);
1311
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001312 }
1313 }
1314 }
1315 }
1316
1317 return result.Succeeded();
1318}
1319
1320