blob: c642ae5551f5e2caddad8bc970b8c5c5aff2df69 [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{
Caroline Tice4d6675c2010-10-01 19:59:14 +000074 { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
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
Caroline Tice4d6675c2010-10-01 19:59:14 +000077 { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount,
78 "Set the number of times this breakpoint is skipped before stopping." },
Jim Ingham3c7b5b92010-06-16 02:00:15 +000079
Caroline Tice4d6675c2010-10-01 19:59:14 +000080 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex,
Greg Claytonfe424a92010-09-18 03:37:20 +000081 "The breakpoint stops only for the thread whose index matches this argument."},
Jim Ingham3c7b5b92010-06-16 02:00:15 +000082
Caroline Tice4d6675c2010-10-01 19:59:14 +000083 { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, eArgTypeThreadID,
Jim Ingham3c7b5b92010-06-16 02:00:15 +000084 "The breakpoint stops only for the thread whose TID matches this argument."},
85
Caroline Tice4d6675c2010-10-01 19:59:14 +000086 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, eArgTypeThreadName,
Jim Ingham3c7b5b92010-06-16 02:00:15 +000087 "The breakpoint stops only for the thread whose thread name matches this argument."},
88
Caroline Tice4d6675c2010-10-01 19:59:14 +000089 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, eArgTypeQueueName,
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
Caroline Tice4d6675c2010-10-01 19:59:14 +000092 { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
Chris Lattner24943d22010-06-08 16:52:24 +000093 "Set the breakpoint by source location in this particular file."},
94
Caroline Tice4d6675c2010-10-01 19:59:14 +000095 { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
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
Caroline Tice4d6675c2010-10-01 19:59:14 +0000103 { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress,
Chris Lattner24943d22010-06-08 16:52:24 +0000104 "Set the breakpoint by address, at the specified address."},
105
Caroline Tice4d6675c2010-10-01 19:59:14 +0000106 { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Greg Clayton48fbdf72010-10-12 04:29:14 +0000107 "Set the breakpoint by function name." },
Chris Lattner24943d22010-06-08 16:52:24 +0000108
Caroline Tice4d6675c2010-10-01 19:59:14 +0000109 { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
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
Caroline Tice4d6675c2010-10-01 19:59:14 +0000113 { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector,
Jim Inghamd9e2b762010-08-26 23:56:11 +0000114 "Set the breakpoint by ObjC selector name." },
Greg Clayton12bec712010-06-28 21:30:43 +0000115
Caroline Tice4d6675c2010-10-01 19:59:14 +0000116 { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod,
Jim Inghamd9e2b762010-08-26 23:56:11 +0000117 "Set the breakpoint by C++ method names." },
Greg Clayton12bec712010-06-28 21:30:43 +0000118
Caroline Tice4d6675c2010-10-01 19:59:14 +0000119 { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression,
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
Greg Clayton48fbdf72010-10-12 04:29:14 +0000122 { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
123 "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored)." },
124
Caroline Tice4d6675c2010-10-01 19:59:14 +0000125 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000126};
127
128const lldb::OptionDefinition*
129CommandObjectBreakpointSet::CommandOptions::GetDefinitions ()
130{
131 return g_option_table;
132}
133
134Error
135CommandObjectBreakpointSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
136{
137 Error error;
138 char short_option = (char) m_getopt_table[option_idx].val;
139
140 switch (short_option)
141 {
142 case 'a':
143 m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 0);
144 if (m_load_addr == LLDB_INVALID_ADDRESS)
145 m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 16);
146
147 if (m_load_addr == LLDB_INVALID_ADDRESS)
148 error.SetErrorStringWithFormat ("Invalid address string '%s'.\n", optarg);
149 break;
150
151 case 'c':
152 m_column = Args::StringToUInt32 (option_arg, 0);
153 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000154
Chris Lattner24943d22010-06-08 16:52:24 +0000155 case 'f':
156 m_filename = option_arg;
157 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000158
Chris Lattner24943d22010-06-08 16:52:24 +0000159 case 'l':
160 m_line_num = Args::StringToUInt32 (option_arg, 0);
161 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000162
Greg Clayton48fbdf72010-10-12 04:29:14 +0000163 case 'b':
Chris Lattner24943d22010-06-08 16:52:24 +0000164 m_func_name = option_arg;
Greg Clayton12bec712010-06-28 21:30:43 +0000165 m_func_name_type_mask |= eFunctionNameTypeBase;
166 break;
167
Greg Clayton48fbdf72010-10-12 04:29:14 +0000168 case 'n':
169 m_func_name = option_arg;
170 m_func_name_type_mask |= eFunctionNameTypeAuto;
171 break;
172
Greg Clayton12bec712010-06-28 21:30:43 +0000173 case 'F':
Jim Inghamd9e2b762010-08-26 23:56:11 +0000174 m_func_name = option_arg;
Greg Clayton12bec712010-06-28 21:30:43 +0000175 m_func_name_type_mask |= eFunctionNameTypeFull;
176 break;
177
178 case 'S':
Jim Inghamd9e2b762010-08-26 23:56:11 +0000179 m_func_name = option_arg;
Greg Clayton12bec712010-06-28 21:30:43 +0000180 m_func_name_type_mask |= eFunctionNameTypeSelector;
181 break;
182
Jim Inghamd9e2b762010-08-26 23:56:11 +0000183 case 'M':
184 m_func_name = option_arg;
Greg Clayton12bec712010-06-28 21:30:43 +0000185 m_func_name_type_mask |= eFunctionNameTypeMethod;
186 break;
187
Chris Lattner24943d22010-06-08 16:52:24 +0000188 case 'r':
189 m_func_regexp = option_arg;
190 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000191
Chris Lattner24943d22010-06-08 16:52:24 +0000192 case 's':
193 {
194 m_modules.push_back (std::string (option_arg));
195 break;
196 }
Greg Claytonfe424a92010-09-18 03:37:20 +0000197 case 'i':
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000198 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000199 m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0);
200 if (m_ignore_count == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000201 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg);
202 }
Jim Ingham10622a22010-06-18 00:58:52 +0000203 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000204 case 't' :
205 {
206 m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0);
207 if (m_thread_id == LLDB_INVALID_THREAD_ID)
208 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg);
209 }
210 break;
211 case 'T':
212 m_thread_name = option_arg;
213 break;
214 case 'q':
215 m_queue_name = option_arg;
216 break;
217 case 'x':
218 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000219 m_thread_index = Args::StringToUInt32(optarg, UINT32_MAX, 0);
220 if (m_thread_id == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000221 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg);
222
223 }
224 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000225 default:
226 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
227 break;
228 }
229
230 return error;
231}
232
233void
234CommandObjectBreakpointSet::CommandOptions::ResetOptionValues ()
235{
236 Options::ResetOptionValues();
237
238 m_filename.clear();
239 m_line_num = 0;
240 m_column = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000241 m_func_name.clear();
Greg Clayton12bec712010-06-28 21:30:43 +0000242 m_func_name_type_mask = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000243 m_func_regexp.clear();
244 m_load_addr = LLDB_INVALID_ADDRESS;
245 m_modules.clear();
Greg Clayton54e7afa2010-07-09 20:39:50 +0000246 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000247 m_thread_id = LLDB_INVALID_THREAD_ID;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000248 m_thread_index = UINT32_MAX;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000249 m_thread_name.clear();
250 m_queue_name.clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000251}
252
253//-------------------------------------------------------------------------
254// CommandObjectBreakpointSet
255//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000256#pragma mark Set
Chris Lattner24943d22010-06-08 16:52:24 +0000257
Greg Clayton238c0a12010-09-18 01:14:36 +0000258CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
259 CommandObject (interpreter,
260 "breakpoint set",
261 "Sets a breakpoint or set of breakpoints in the executable.",
Chris Lattner24943d22010-06-08 16:52:24 +0000262 "breakpoint set <cmd-options>")
263{
264}
265
266CommandObjectBreakpointSet::~CommandObjectBreakpointSet ()
267{
268}
269
270Options *
271CommandObjectBreakpointSet::GetOptions ()
272{
273 return &m_options;
274}
275
276bool
277CommandObjectBreakpointSet::Execute
278(
279 Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000280 CommandReturnObject &result
281)
282{
Greg Clayton238c0a12010-09-18 01:14:36 +0000283 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000284 if (target == NULL)
285 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000286 result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'file' command).");
Chris Lattner24943d22010-06-08 16:52:24 +0000287 result.SetStatus (eReturnStatusFailed);
288 return false;
289 }
290
291 // The following are the various types of breakpoints that could be set:
292 // 1). -f -l -p [-s -g] (setting breakpoint by source location)
293 // 2). -a [-s -g] (setting breakpoint by address)
294 // 3). -n [-s -g] (setting breakpoint by function name)
295 // 4). -r [-s -g] (setting breakpoint by function name regular expression)
296
297 BreakpointSetType break_type = eSetTypeInvalid;
298
299 if (m_options.m_line_num != 0)
300 break_type = eSetTypeFileAndLine;
301 else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
302 break_type = eSetTypeAddress;
303 else if (!m_options.m_func_name.empty())
304 break_type = eSetTypeFunctionName;
305 else if (!m_options.m_func_regexp.empty())
306 break_type = eSetTypeFunctionRegexp;
307
308 ModuleSP module_sp = target->GetExecutableModule();
309 Breakpoint *bp = NULL;
310 FileSpec module;
311 bool use_module = false;
312 int num_modules = m_options.m_modules.size();
313
314 if ((num_modules > 0) && (break_type != eSetTypeAddress))
315 use_module = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000316
Chris Lattner24943d22010-06-08 16:52:24 +0000317 switch (break_type)
318 {
319 case eSetTypeFileAndLine: // Breakpoint by source position
Chris Lattner24943d22010-06-08 16:52:24 +0000320 {
Greg Clayton887aa282010-10-11 01:05:37 +0000321 FileSpec file;
322 if (m_options.m_filename.empty())
Chris Lattner24943d22010-06-08 16:52:24 +0000323 {
Greg Clayton887aa282010-10-11 01:05:37 +0000324 StackFrame *cur_frame = m_interpreter.GetDebugger().GetExecutionContext().frame;
325 if (cur_frame == NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000326 {
Greg Clayton887aa282010-10-11 01:05:37 +0000327 result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame.");
Chris Lattner24943d22010-06-08 16:52:24 +0000328 result.SetStatus (eReturnStatusFailed);
329 break;
330 }
Greg Clayton887aa282010-10-11 01:05:37 +0000331 else if (!cur_frame->HasDebugInformation())
Chris Lattner24943d22010-06-08 16:52:24 +0000332 {
Greg Clayton887aa282010-10-11 01:05:37 +0000333 result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info.");
334 result.SetStatus (eReturnStatusFailed);
335 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000336 }
337 else
338 {
Greg Clayton887aa282010-10-11 01:05:37 +0000339 const SymbolContext &context = cur_frame->GetSymbolContext(true);
340 if (context.line_entry.file)
341 {
342 file = context.line_entry.file;
343 }
344 else if (context.comp_unit != NULL)
345 { file = context.comp_unit;
346 }
347 else
348 {
349 result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame.");
350 result.SetStatus (eReturnStatusFailed);
351 break;
352 }
Chris Lattner24943d22010-06-08 16:52:24 +0000353 }
354 }
Greg Clayton887aa282010-10-11 01:05:37 +0000355 else
356 {
357 file.SetFile(m_options.m_filename.c_str());
358 }
359
360 if (use_module)
361 {
362 for (int i = 0; i < num_modules; ++i)
363 {
364 module.SetFile(m_options.m_modules[i].c_str());
365 bp = target->CreateBreakpoint (&module,
366 file,
367 m_options.m_line_num,
368 m_options.m_ignore_inlines).get();
369 if (bp)
370 {
371 StreamString &output_stream = result.GetOutputStream();
372 output_stream.Printf ("Breakpoint created: ");
373 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
374 output_stream.EOL();
375 result.SetStatus (eReturnStatusSuccessFinishResult);
376 }
377 else
378 {
379 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
380 m_options.m_modules[i].c_str());
381 result.SetStatus (eReturnStatusFailed);
382 }
383 }
384 }
385 else
386 bp = target->CreateBreakpoint (NULL,
387 file,
388 m_options.m_line_num,
389 m_options.m_ignore_inlines).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000390 }
Greg Clayton887aa282010-10-11 01:05:37 +0000391 break;
392
Chris Lattner24943d22010-06-08 16:52:24 +0000393 case eSetTypeAddress: // Breakpoint by address
394 bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
395 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000396
Chris Lattner24943d22010-06-08 16:52:24 +0000397 case eSetTypeFunctionName: // Breakpoint by function name
Chris Lattner24943d22010-06-08 16:52:24 +0000398 {
Greg Clayton12bec712010-06-28 21:30:43 +0000399 uint32_t name_type_mask = m_options.m_func_name_type_mask;
400
401 if (name_type_mask == 0)
Greg Clayton48fbdf72010-10-12 04:29:14 +0000402 name_type_mask = eFunctionNameTypeAuto;
403
Greg Clayton12bec712010-06-28 21:30:43 +0000404 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.
Jim Inghamd1686902010-10-14 23:45:03 +0000550 // If args is empty, we will use the last created breakpoint (if there is one.)
Chris Lattner24943d22010-06-08 16:52:24 +0000551
552 Args temp_args;
553
Jim Inghamd1686902010-10-14 23:45:03 +0000554 if (args.GetArgumentCount() == 0)
555 {
556 if (target->GetLastCreatedBreakpoint() != NULL)
557 {
558 valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
559 result.SetStatus (eReturnStatusSuccessFinishNoResult);
560 }
561 else
562 {
563 result.AppendError("No breakpoint specified and no last created breakpoint.");
564 result.SetStatus (eReturnStatusFailed);
565 }
566 return;
567 }
568
Chris Lattner24943d22010-06-08 16:52:24 +0000569 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
570 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
571 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
572
573 BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
574
575 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
576
Greg Clayton54e7afa2010-07-09 20:39:50 +0000577 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
Chris Lattner24943d22010-06-08 16:52:24 +0000578
579 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
580 // and put into valid_ids.
581
582 if (result.Succeeded())
583 {
584 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
585 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
586
Greg Clayton54e7afa2010-07-09 20:39:50 +0000587 const size_t count = valid_ids->GetSize();
588 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000589 {
590 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
591 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
592 if (breakpoint != NULL)
593 {
594 int num_locations = breakpoint->GetNumLocations();
595 if (cur_bp_id.GetLocationID() > num_locations)
596 {
597 StreamString id_str;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000598 BreakpointID::GetCanonicalReference (&id_str,
599 cur_bp_id.GetBreakpointID(),
600 cur_bp_id.GetLocationID());
601 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000602 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
603 id_str.GetData());
604 result.SetStatus (eReturnStatusFailed);
605 }
606 }
607 else
608 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000609 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000610 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
611 result.SetStatus (eReturnStatusFailed);
612 }
613 }
614 }
615}
616
617//-------------------------------------------------------------------------
618// CommandObjectBreakpointList::Options
619//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000620#pragma mark List::CommandOptions
Chris Lattner24943d22010-06-08 16:52:24 +0000621
622CommandObjectBreakpointList::CommandOptions::CommandOptions() :
623 Options (),
624 m_level (lldb::eDescriptionLevelFull) // Breakpoint List defaults to brief descriptions
625{
Chris Lattner24943d22010-06-08 16:52:24 +0000626}
627
628CommandObjectBreakpointList::CommandOptions::~CommandOptions ()
629{
630}
631
632lldb::OptionDefinition
633CommandObjectBreakpointList::CommandOptions::g_option_table[] =
634{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000635 { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone,
Jim Ingham34e9a982010-06-15 18:47:14 +0000636 "Show debugger internal breakpoints" },
637
Caroline Tice4d6675c2010-10-01 19:59:14 +0000638 { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000639 "Give a brief description of the breakpoint (no location info)."},
640
641 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
642 // But I need to see it for now, and don't want to wait.
Caroline Tice4d6675c2010-10-01 19:59:14 +0000643 { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000644 "Give a full description of the breakpoint and its locations."},
Chris Lattner24943d22010-06-08 16:52:24 +0000645
Caroline Tice4d6675c2010-10-01 19:59:14 +0000646 { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000647 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
Chris Lattner24943d22010-06-08 16:52:24 +0000648
Caroline Tice4d6675c2010-10-01 19:59:14 +0000649 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000650};
651
652const lldb::OptionDefinition*
653CommandObjectBreakpointList::CommandOptions::GetDefinitions ()
654{
655 return g_option_table;
656}
657
658Error
659CommandObjectBreakpointList::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
660{
661 Error error;
662 char short_option = (char) m_getopt_table[option_idx].val;
663
664 switch (short_option)
665 {
666 case 'b':
667 m_level = lldb::eDescriptionLevelBrief;
668 break;
669 case 'f':
670 m_level = lldb::eDescriptionLevelFull;
671 break;
672 case 'v':
673 m_level = lldb::eDescriptionLevelVerbose;
674 break;
675 case 'i':
676 m_internal = true;
677 break;
678 default:
679 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
680 break;
681 }
682
683 return error;
684}
685
686void
687CommandObjectBreakpointList::CommandOptions::ResetOptionValues ()
688{
689 Options::ResetOptionValues();
690
691 m_level = lldb::eDescriptionLevelFull;
692 m_internal = false;
693}
694
695//-------------------------------------------------------------------------
696// CommandObjectBreakpointList
697//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000698#pragma mark List
Chris Lattner24943d22010-06-08 16:52:24 +0000699
Greg Clayton238c0a12010-09-18 01:14:36 +0000700CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) :
701 CommandObject (interpreter,
702 "breakpoint list",
703 "List some or all breakpoints at configurable levels of detail.",
Caroline Ticefb355112010-10-01 17:46:38 +0000704 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000705{
Caroline Ticefb355112010-10-01 17:46:38 +0000706 CommandArgumentEntry arg;
707 CommandArgumentData bp_id_arg;
708
709 // Define the first (and only) variant of this arg.
710 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +0000711 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000712
713 // There is only one variant this argument could be; put it into the argument entry.
714 arg.push_back (bp_id_arg);
715
716 // Push the data for the first argument into the m_arguments vector.
717 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000718}
719
720CommandObjectBreakpointList::~CommandObjectBreakpointList ()
721{
722}
723
724Options *
725CommandObjectBreakpointList::GetOptions ()
726{
727 return &m_options;
728}
729
730bool
731CommandObjectBreakpointList::Execute
732(
733 Args& args,
Chris Lattner24943d22010-06-08 16:52:24 +0000734 CommandReturnObject &result
735)
736{
Greg Clayton238c0a12010-09-18 01:14:36 +0000737 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000738 if (target == NULL)
739 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000740 result.AppendError ("Invalid target. No current target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000741 result.SetStatus (eReturnStatusSuccessFinishNoResult);
742 return true;
743 }
744
745 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000746 Mutex::Locker locker;
747 target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
748
Chris Lattner24943d22010-06-08 16:52:24 +0000749 size_t num_breakpoints = breakpoints.GetSize();
750
751 if (num_breakpoints == 0)
752 {
753 result.AppendMessage ("No breakpoints currently set.");
754 result.SetStatus (eReturnStatusSuccessFinishNoResult);
755 return true;
756 }
757
758 StreamString &output_stream = result.GetOutputStream();
759
760 if (args.GetArgumentCount() == 0)
761 {
762 // No breakpoint selected; show info about all currently set breakpoints.
763 result.AppendMessage ("Current breakpoints:");
Greg Clayton54e7afa2010-07-09 20:39:50 +0000764 for (size_t i = 0; i < num_breakpoints; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000765 {
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000766 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000767 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000768 }
769 result.SetStatus (eReturnStatusSuccessFinishNoResult);
770 }
771 else
772 {
773 // Particular breakpoints selected; show info about that breakpoint.
774 BreakpointIDList valid_bp_ids;
775 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
776
777 if (result.Succeeded())
778 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000779 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000780 {
781 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
782 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000783 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000784 }
785 result.SetStatus (eReturnStatusSuccessFinishNoResult);
786 }
787 else
788 {
789 result.AppendError ("Invalid breakpoint id.");
790 result.SetStatus (eReturnStatusFailed);
791 }
792 }
793
794 return result.Succeeded();
795}
796
797//-------------------------------------------------------------------------
798// CommandObjectBreakpointEnable
799//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000800#pragma mark Enable
Chris Lattner24943d22010-06-08 16:52:24 +0000801
Greg Clayton238c0a12010-09-18 01:14:36 +0000802CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
803 CommandObject (interpreter,
804 "enable",
Caroline Ticefb355112010-10-01 17:46:38 +0000805 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
806 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000807{
Caroline Ticefb355112010-10-01 17:46:38 +0000808 CommandArgumentEntry arg;
809 CommandArgumentData bp_id_arg;
810 CommandArgumentData bp_id_range_arg;
811
812 // Create the first variant for the first (and only) argument for this command.
813 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +0000814 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000815
816 // Create the second variant for the first (and only) argument for this command.
817 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +0000818 bp_id_range_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000819
820 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
821 // Push both variants into the entry for the first argument for this command.
822 arg.push_back (bp_id_arg);
823 arg.push_back (bp_id_range_arg);
824
825 // Add the entry for the first argument for this command to the object's arguments vector.
826 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000827}
828
829
830CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable ()
831{
832}
833
834
835bool
Greg Clayton63094e02010-06-23 01:19:29 +0000836CommandObjectBreakpointEnable::Execute
837(
Greg Clayton63094e02010-06-23 01:19:29 +0000838 Args& args,
839 CommandReturnObject &result
840)
Chris Lattner24943d22010-06-08 16:52:24 +0000841{
Greg Clayton238c0a12010-09-18 01:14:36 +0000842 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000843 if (target == NULL)
844 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000845 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000846 result.SetStatus (eReturnStatusFailed);
847 return false;
848 }
849
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000850 Mutex::Locker locker;
851 target->GetBreakpointList().GetListMutex(locker);
852
Chris Lattner24943d22010-06-08 16:52:24 +0000853 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000854
Chris Lattner24943d22010-06-08 16:52:24 +0000855 size_t num_breakpoints = breakpoints.GetSize();
856
857 if (num_breakpoints == 0)
858 {
859 result.AppendError ("No breakpoints exist to be enabled.");
860 result.SetStatus (eReturnStatusFailed);
861 return false;
862 }
863
864 if (args.GetArgumentCount() == 0)
865 {
866 // No breakpoint selected; enable all currently set breakpoints.
867 target->EnableAllBreakpoints ();
868 result.AppendMessageWithFormat ("All breakpoints enabled. (%d breakpoints)\n", num_breakpoints);
869 result.SetStatus (eReturnStatusSuccessFinishNoResult);
870 }
871 else
872 {
873 // Particular breakpoint selected; enable that breakpoint.
874 BreakpointIDList valid_bp_ids;
875 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
876
877 if (result.Succeeded())
878 {
879 int enable_count = 0;
880 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000881 const size_t count = valid_bp_ids.GetSize();
882 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000883 {
884 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
885
886 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
887 {
888 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
889 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
890 {
891 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
892 if (location)
893 {
894 location->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000895 ++loc_count;
896 }
897 }
898 else
899 {
Jim Ingham10622a22010-06-18 00:58:52 +0000900 breakpoint->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000901 ++enable_count;
Chris Lattner24943d22010-06-08 16:52:24 +0000902 }
903 }
904 }
905 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
906 result.SetStatus (eReturnStatusSuccessFinishNoResult);
907 }
908 }
909
910 return result.Succeeded();
911}
912
913//-------------------------------------------------------------------------
914// CommandObjectBreakpointDisable
915//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000916#pragma mark Disable
Chris Lattner24943d22010-06-08 16:52:24 +0000917
Greg Clayton238c0a12010-09-18 01:14:36 +0000918CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
919 CommandObject (interpreter,
Caroline Ticefb355112010-10-01 17:46:38 +0000920 "breakpoint disable",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000921 "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.",
Caroline Ticefb355112010-10-01 17:46:38 +0000922 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000923{
Caroline Ticefb355112010-10-01 17:46:38 +0000924 CommandArgumentEntry arg;
925 CommandArgumentData bp_id_arg;
926 CommandArgumentData bp_id_range_arg;
927
928 // Create the first variant for the first (and only) argument for this command.
929 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +0000930 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000931
932 // Create the second variant for the first (and only) argument for this command.
933 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +0000934 bp_id_range_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000935
936 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
937 // Push both variants into the entry for the first argument for this command.
938 arg.push_back (bp_id_arg);
939 arg.push_back (bp_id_range_arg);
940
941 // Add the entry for the first argument for this command to the object's arguments vector.
942 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000943}
944
945CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable ()
946{
947}
948
949bool
Greg Clayton63094e02010-06-23 01:19:29 +0000950CommandObjectBreakpointDisable::Execute
951(
Greg Clayton63094e02010-06-23 01:19:29 +0000952 Args& args,
953 CommandReturnObject &result
954)
Chris Lattner24943d22010-06-08 16:52:24 +0000955{
Greg Clayton238c0a12010-09-18 01:14:36 +0000956 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000957 if (target == NULL)
958 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000959 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000960 result.SetStatus (eReturnStatusFailed);
961 return false;
962 }
963
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000964 Mutex::Locker locker;
965 target->GetBreakpointList().GetListMutex(locker);
966
Chris Lattner24943d22010-06-08 16:52:24 +0000967 const BreakpointList &breakpoints = target->GetBreakpointList();
968 size_t num_breakpoints = breakpoints.GetSize();
969
970 if (num_breakpoints == 0)
971 {
972 result.AppendError ("No breakpoints exist to be disabled.");
973 result.SetStatus (eReturnStatusFailed);
974 return false;
975 }
976
977 if (args.GetArgumentCount() == 0)
978 {
979 // No breakpoint selected; disable all currently set breakpoints.
980 target->DisableAllBreakpoints ();
981 result.AppendMessageWithFormat ("All breakpoints disabled. (%d breakpoints)\n", num_breakpoints);
982 result.SetStatus (eReturnStatusSuccessFinishNoResult);
983 }
984 else
985 {
986 // Particular breakpoint selected; disable that breakpoint.
987 BreakpointIDList valid_bp_ids;
988
989 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
990
991 if (result.Succeeded())
992 {
993 int disable_count = 0;
994 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000995 const size_t count = valid_bp_ids.GetSize();
996 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000997 {
998 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
999
1000 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1001 {
1002 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1003 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1004 {
1005 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1006 if (location)
1007 {
1008 location->SetEnabled (false);
1009 ++loc_count;
1010 }
1011 }
1012 else
1013 {
Jim Ingham10622a22010-06-18 00:58:52 +00001014 breakpoint->SetEnabled (false);
Chris Lattner24943d22010-06-08 16:52:24 +00001015 ++disable_count;
Chris Lattner24943d22010-06-08 16:52:24 +00001016 }
1017 }
1018 }
1019 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
1020 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1021 }
1022 }
1023
1024 return result.Succeeded();
1025}
1026
1027//-------------------------------------------------------------------------
1028// CommandObjectBreakpointDelete
1029//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001030#pragma mark Delete
Chris Lattner24943d22010-06-08 16:52:24 +00001031
Greg Clayton238c0a12010-09-18 01:14:36 +00001032CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) :
1033 CommandObject (interpreter,
1034 "breakpoint delete",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001035 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
Caroline Ticefb355112010-10-01 17:46:38 +00001036 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +00001037{
Caroline Ticefb355112010-10-01 17:46:38 +00001038 CommandArgumentEntry arg;
1039 CommandArgumentData bp_id_arg;
1040 CommandArgumentData bp_id_range_arg;
1041
1042 // Create the first variant for the first (and only) argument for this command.
1043 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +00001044 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +00001045
1046 // Create the second variant for the first (and only) argument for this command.
1047 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +00001048 bp_id_range_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +00001049
1050 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1051 // Push both variants into the entry for the first argument for this command.
1052 arg.push_back (bp_id_arg);
1053 arg.push_back (bp_id_range_arg);
1054
1055 // Add the entry for the first argument for this command to the object's arguments vector.
1056 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +00001057}
1058
1059
1060CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete ()
1061{
1062}
1063
1064bool
Greg Clayton63094e02010-06-23 01:19:29 +00001065CommandObjectBreakpointDelete::Execute
1066(
Greg Clayton63094e02010-06-23 01:19:29 +00001067 Args& args,
1068 CommandReturnObject &result
1069)
Chris Lattner24943d22010-06-08 16:52:24 +00001070{
Greg Clayton238c0a12010-09-18 01:14:36 +00001071 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001072 if (target == NULL)
1073 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001074 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +00001075 result.SetStatus (eReturnStatusFailed);
1076 return false;
1077 }
1078
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001079 Mutex::Locker locker;
1080 target->GetBreakpointList().GetListMutex(locker);
1081
Chris Lattner24943d22010-06-08 16:52:24 +00001082 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001083
Chris Lattner24943d22010-06-08 16:52:24 +00001084 size_t num_breakpoints = breakpoints.GetSize();
1085
1086 if (num_breakpoints == 0)
1087 {
1088 result.AppendError ("No breakpoints exist to be deleted.");
1089 result.SetStatus (eReturnStatusFailed);
1090 return false;
1091 }
1092
1093 if (args.GetArgumentCount() == 0)
1094 {
Jim Inghamd1686902010-10-14 23:45:03 +00001095 if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
Chris Lattner24943d22010-06-08 16:52:24 +00001096 {
Jim Inghamd1686902010-10-14 23:45:03 +00001097 result.AppendMessage("Operation cancelled...");
Chris Lattner24943d22010-06-08 16:52:24 +00001098 }
Jim Inghamd1686902010-10-14 23:45:03 +00001099 else
1100 {
1101 target->RemoveAllBreakpoints ();
1102 result.AppendMessageWithFormat ("All breakpoints removed. (%d breakpoints)\n", num_breakpoints);
1103 }
Chris Lattner24943d22010-06-08 16:52:24 +00001104 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1105 }
1106 else
1107 {
1108 // Particular breakpoint selected; disable that breakpoint.
1109 BreakpointIDList valid_bp_ids;
1110 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
1111
1112 if (result.Succeeded())
1113 {
1114 int delete_count = 0;
1115 int disable_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001116 const size_t count = valid_bp_ids.GetSize();
1117 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +00001118 {
1119 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1120
1121 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1122 {
1123 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1124 {
1125 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1126 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1127 // It makes no sense to try to delete individual locations, so we disable them instead.
1128 if (location)
1129 {
1130 location->SetEnabled (false);
1131 ++disable_count;
1132 }
1133 }
1134 else
1135 {
1136 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1137 ++delete_count;
1138 }
1139 }
1140 }
1141 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1142 delete_count, disable_count);
1143 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1144 }
1145 }
1146 return result.Succeeded();
1147}
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001148
1149//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001150// CommandObjectBreakpointModify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001151//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001152#pragma mark Modify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001153
Jim Ingham10622a22010-06-18 00:58:52 +00001154CommandObjectBreakpointModify::CommandOptions::CommandOptions() :
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001155 Options (),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001156 m_ignore_count (0),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001157 m_thread_id(LLDB_INVALID_THREAD_ID),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001158 m_thread_index (UINT32_MAX),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001159 m_thread_name(),
1160 m_queue_name(),
Jim Inghamd1686902010-10-14 23:45:03 +00001161 m_condition (),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001162 m_enable_passed (false),
1163 m_enable_value (false),
1164 m_name_passed (false),
Jim Inghamd1686902010-10-14 23:45:03 +00001165 m_queue_passed (false),
1166 m_condition_passed (false)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001167{
1168}
1169
Jim Ingham10622a22010-06-18 00:58:52 +00001170CommandObjectBreakpointModify::CommandOptions::~CommandOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001171{
1172}
1173
1174lldb::OptionDefinition
Jim Ingham10622a22010-06-18 00:58:52 +00001175CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001176{
Caroline Tice4d6675c2010-10-01 19:59:14 +00001177{ LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, NULL, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." },
1178{ LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose indeX matches this argument."},
1179{ LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."},
1180{ LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."},
1181{ LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."},
Jim Inghamd1686902010-10-14 23:45:03 +00001182{ LLDB_OPT_SET_ALL, false, "condition", 'c', required_argument, NULL, NULL, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."},
Caroline Tice4d6675c2010-10-01 19:59:14 +00001183{ LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, eArgTypeNone, "Enable the breakpoint."},
1184{ LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, eArgTypeNone, "Disable the breakpoint."},
Jim Inghamd1686902010-10-14 23:45:03 +00001185{ 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001186};
1187
1188const lldb::OptionDefinition*
Jim Ingham10622a22010-06-18 00:58:52 +00001189CommandObjectBreakpointModify::CommandOptions::GetDefinitions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001190{
1191 return g_option_table;
1192}
1193
1194Error
Jim Ingham10622a22010-06-18 00:58:52 +00001195CommandObjectBreakpointModify::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001196{
1197 Error error;
1198 char short_option = (char) m_getopt_table[option_idx].val;
1199
1200 switch (short_option)
1201 {
Jim Inghamd1686902010-10-14 23:45:03 +00001202 case 'c':
1203 if (option_arg != NULL)
1204 m_condition = option_arg;
1205 else
1206 m_condition.clear();
1207 m_condition_passed = true;
1208 break;
Jim Ingham10622a22010-06-18 00:58:52 +00001209 case 'd':
1210 m_enable_passed = true;
1211 m_enable_value = false;
1212 break;
1213 case 'e':
1214 m_enable_passed = true;
1215 m_enable_value = true;
1216 break;
Greg Claytonfe424a92010-09-18 03:37:20 +00001217 case 'i':
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001218 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001219 m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0);
1220 if (m_ignore_count == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001221 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg);
1222 }
Jim Ingham10622a22010-06-18 00:58:52 +00001223 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001224 case 't' :
1225 {
1226 m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0);
1227 if (m_thread_id == LLDB_INVALID_THREAD_ID)
1228 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg);
1229 }
1230 break;
1231 case 'T':
Jim Inghamd4571222010-06-19 04:35:20 +00001232 if (option_arg != NULL)
1233 m_thread_name = option_arg;
1234 else
1235 m_thread_name.clear();
1236 m_name_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001237 break;
1238 case 'q':
Jim Inghamd4571222010-06-19 04:35:20 +00001239 if (option_arg != NULL)
1240 m_queue_name = option_arg;
1241 else
1242 m_queue_name.clear();
1243 m_queue_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001244 break;
1245 case 'x':
1246 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001247 m_thread_index = Args::StringToUInt32 (optarg, UINT32_MAX, 0);
1248 if (m_thread_id == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001249 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg);
1250
1251 }
1252 break;
1253 default:
1254 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1255 break;
1256 }
1257
1258 return error;
1259}
1260
1261void
Jim Ingham10622a22010-06-18 00:58:52 +00001262CommandObjectBreakpointModify::CommandOptions::ResetOptionValues ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001263{
1264 Options::ResetOptionValues();
1265
Greg Clayton54e7afa2010-07-09 20:39:50 +00001266 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001267 m_thread_id = LLDB_INVALID_THREAD_ID;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001268 m_thread_index = UINT32_MAX;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001269 m_thread_name.clear();
1270 m_queue_name.clear();
Jim Inghamd1686902010-10-14 23:45:03 +00001271 m_condition.clear();
Jim Ingham10622a22010-06-18 00:58:52 +00001272 m_enable_passed = false;
Jim Inghamd4571222010-06-19 04:35:20 +00001273 m_queue_passed = false;
1274 m_name_passed = false;
Jim Inghamd1686902010-10-14 23:45:03 +00001275 m_condition_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001276}
1277
1278//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001279// CommandObjectBreakpointModify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001280//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001281#pragma mark Modify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001282
Greg Clayton238c0a12010-09-18 01:14:36 +00001283CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
1284 CommandObject (interpreter,
1285 "breakpoint modify",
1286 "Modify the options on a breakpoint or set of breakpoints in the executable.",
Caroline Ticefb355112010-10-01 17:46:38 +00001287 NULL)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001288{
Caroline Ticefb355112010-10-01 17:46:38 +00001289 CommandArgumentEntry arg;
1290 CommandArgumentData bp_id_arg;
1291 CommandArgumentData bp_id_range_arg;
1292
1293 // Create the first variant for the first (and only) argument for this command.
1294 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +00001295 bp_id_arg.arg_repetition = eArgRepeatPlain;
Caroline Ticefb355112010-10-01 17:46:38 +00001296
1297 // Create the second variant for the first (and only) argument for this command.
1298 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +00001299 bp_id_range_arg.arg_repetition = eArgRepeatPlain;
Caroline Ticefb355112010-10-01 17:46:38 +00001300
1301 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1302 // Push both variants into the entry for the first argument for this command.
1303 arg.push_back (bp_id_arg);
1304 arg.push_back (bp_id_range_arg);
1305
1306 // Add the entry for the first argument for this command to the object's arguments vector.
1307 m_arguments.push_back (arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001308}
1309
Jim Ingham10622a22010-06-18 00:58:52 +00001310CommandObjectBreakpointModify::~CommandObjectBreakpointModify ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001311{
1312}
1313
1314Options *
Jim Ingham10622a22010-06-18 00:58:52 +00001315CommandObjectBreakpointModify::GetOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001316{
1317 return &m_options;
1318}
1319
1320bool
Jim Ingham10622a22010-06-18 00:58:52 +00001321CommandObjectBreakpointModify::Execute
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001322(
1323 Args& command,
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001324 CommandReturnObject &result
1325)
1326{
Greg Clayton238c0a12010-09-18 01:14:36 +00001327 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001328 if (target == NULL)
1329 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001330 result.AppendError ("Invalid target. No existing target or breakpoints.");
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001331 result.SetStatus (eReturnStatusFailed);
1332 return false;
1333 }
1334
1335 Mutex::Locker locker;
1336 target->GetBreakpointList().GetListMutex(locker);
1337
1338 BreakpointIDList valid_bp_ids;
1339
1340 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1341
1342 if (result.Succeeded())
1343 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001344 const size_t count = valid_bp_ids.GetSize();
1345 for (size_t i = 0; i < count; ++i)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001346 {
1347 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1348
1349 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1350 {
1351 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1352 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1353 {
1354 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
1355 if (location)
1356 {
1357 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
1358 location->SetThreadID (m_options.m_thread_id);
1359
Greg Clayton54e7afa2010-07-09 20:39:50 +00001360 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001361 location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1362
Jim Inghamd4571222010-06-19 04:35:20 +00001363 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001364 location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1365
Jim Inghamd4571222010-06-19 04:35:20 +00001366 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001367 location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1368
Greg Clayton54e7afa2010-07-09 20:39:50 +00001369 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001370 location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001371
1372 if (m_options.m_enable_passed)
1373 location->SetEnabled (m_options.m_enable_value);
Jim Inghamd1686902010-10-14 23:45:03 +00001374
1375 if (m_options.m_condition_passed)
1376 location->SetCondition (m_options.m_condition.c_str());
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001377 }
1378 }
1379 else
1380 {
1381 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
1382 bp->SetThreadID (m_options.m_thread_id);
1383
Greg Clayton54e7afa2010-07-09 20:39:50 +00001384 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001385 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1386
Jim Inghamd4571222010-06-19 04:35:20 +00001387 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001388 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1389
Jim Inghamd4571222010-06-19 04:35:20 +00001390 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001391 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1392
Greg Clayton54e7afa2010-07-09 20:39:50 +00001393 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001394 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001395
1396 if (m_options.m_enable_passed)
1397 bp->SetEnabled (m_options.m_enable_value);
Jim Inghamd1686902010-10-14 23:45:03 +00001398
1399 if (m_options.m_condition_passed)
1400 bp->SetCondition (m_options.m_condition.c_str());
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001401 }
1402 }
1403 }
1404 }
1405
1406 return result.Succeeded();
1407}
1408
1409