blob: 7894f55c313c3a25833a817b1472e33f927267fe [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;
Greg Clayton537a7a82010-10-20 20:54:39 +0000310 FileSpec module_spec;
Chris Lattner24943d22010-06-08 16:52:24 +0000311 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 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000357 file.SetFile(m_options.m_filename.c_str(), false);
Greg Clayton887aa282010-10-11 01:05:37 +0000358 }
359
360 if (use_module)
361 {
362 for (int i = 0; i < num_modules; ++i)
363 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000364 module_spec.SetFile(m_options.m_modules[i].c_str(), false);
365 bp = target->CreateBreakpoint (&module_spec,
Greg Clayton887aa282010-10-11 01:05:37 +0000366 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();
Caroline Ticecf2f3052010-10-28 16:28:56 +0000375 if (bp->GetNumLocations() == 0)
376 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual"
377 " locations.\n");
Greg Clayton887aa282010-10-11 01:05:37 +0000378 result.SetStatus (eReturnStatusSuccessFinishResult);
379 }
380 else
381 {
382 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
383 m_options.m_modules[i].c_str());
384 result.SetStatus (eReturnStatusFailed);
385 }
386 }
387 }
388 else
389 bp = target->CreateBreakpoint (NULL,
390 file,
391 m_options.m_line_num,
392 m_options.m_ignore_inlines).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000393 }
Greg Clayton887aa282010-10-11 01:05:37 +0000394 break;
395
Chris Lattner24943d22010-06-08 16:52:24 +0000396 case eSetTypeAddress: // Breakpoint by address
397 bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
398 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000399
Chris Lattner24943d22010-06-08 16:52:24 +0000400 case eSetTypeFunctionName: // Breakpoint by function name
Chris Lattner24943d22010-06-08 16:52:24 +0000401 {
Greg Clayton12bec712010-06-28 21:30:43 +0000402 uint32_t name_type_mask = m_options.m_func_name_type_mask;
403
404 if (name_type_mask == 0)
Greg Clayton48fbdf72010-10-12 04:29:14 +0000405 name_type_mask = eFunctionNameTypeAuto;
406
Greg Clayton12bec712010-06-28 21:30:43 +0000407 if (use_module)
408 {
409 for (int i = 0; i < num_modules; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000410 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000411 module_spec.SetFile(m_options.m_modules[i].c_str(), false);
412 bp = target->CreateBreakpoint (&module_spec,
413 m_options.m_func_name.c_str(),
414 name_type_mask,
415 Breakpoint::Exact).get();
Greg Clayton12bec712010-06-28 21:30:43 +0000416 if (bp)
417 {
418 StreamString &output_stream = result.GetOutputStream();
419 output_stream.Printf ("Breakpoint created: ");
420 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
421 output_stream.EOL();
Caroline Ticecf2f3052010-10-28 16:28:56 +0000422 if (bp->GetNumLocations() == 0)
423 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual"
424 " locations.\n");
Greg Clayton12bec712010-06-28 21:30:43 +0000425 result.SetStatus (eReturnStatusSuccessFinishResult);
426 }
427 else
428 {
429 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
430 m_options.m_modules[i].c_str());
431 result.SetStatus (eReturnStatusFailed);
432 }
Chris Lattner24943d22010-06-08 16:52:24 +0000433 }
434 }
Greg Clayton12bec712010-06-28 21:30:43 +0000435 else
436 bp = target->CreateBreakpoint (NULL, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000437 }
Chris Lattner24943d22010-06-08 16:52:24 +0000438 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000439
Chris Lattner24943d22010-06-08 16:52:24 +0000440 case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
441 {
442 RegularExpression regexp(m_options.m_func_regexp.c_str());
443 if (use_module)
444 {
445 for (int i = 0; i < num_modules; ++i)
446 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000447 module_spec.SetFile(m_options.m_modules[i].c_str(), false);
448 bp = target->CreateBreakpoint (&module_spec, regexp).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000449 if (bp)
450 {
451 StreamString &output_stream = result.GetOutputStream();
452 output_stream.Printf ("Breakpoint created: ");
453 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
454 output_stream.EOL();
Caroline Ticecf2f3052010-10-28 16:28:56 +0000455 if (bp->GetNumLocations() == 0)
456 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual"
457 " locations.\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000458 result.SetStatus (eReturnStatusSuccessFinishResult);
459 }
460 else
461 {
462 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
463 m_options.m_modules[i].c_str());
464 result.SetStatus (eReturnStatusFailed);
465 }
466 }
467 }
468 else
469 bp = target->CreateBreakpoint (NULL, regexp).get();
470 }
471 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000472
Chris Lattner24943d22010-06-08 16:52:24 +0000473 default:
474 break;
475 }
476
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000477 // Now set the various options that were passed in:
478 if (bp)
479 {
480 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
481 bp->SetThreadID (m_options.m_thread_id);
482
Greg Clayton54e7afa2010-07-09 20:39:50 +0000483 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000484 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
485
486 if (!m_options.m_thread_name.empty())
487 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
488
489 if (!m_options.m_queue_name.empty())
490 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
491
Greg Clayton54e7afa2010-07-09 20:39:50 +0000492 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000493 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
494 }
495
Chris Lattner24943d22010-06-08 16:52:24 +0000496 if (bp && !use_module)
497 {
498 StreamString &output_stream = result.GetOutputStream();
499 output_stream.Printf ("Breakpoint created: ");
500 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
501 output_stream.EOL();
Caroline Ticecf2f3052010-10-28 16:28:56 +0000502 if (bp->GetNumLocations() == 0)
503 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000504 result.SetStatus (eReturnStatusSuccessFinishResult);
505 }
506 else if (!bp)
507 {
508 result.AppendError ("Breakpoint creation failed: No breakpoint created.");
509 result.SetStatus (eReturnStatusFailed);
510 }
511
512 return result.Succeeded();
513}
514
Chris Lattner24943d22010-06-08 16:52:24 +0000515//-------------------------------------------------------------------------
516// CommandObjectMultiwordBreakpoint
517//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000518#pragma mark MultiwordBreakpoint
Chris Lattner24943d22010-06-08 16:52:24 +0000519
Greg Clayton63094e02010-06-23 01:19:29 +0000520CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000521 CommandObjectMultiword (interpreter,
522 "breakpoint",
523 "A set of commands for operating on breakpoints. Also see regexp-break.",
524 "breakpoint <command> [<command-options>]")
Chris Lattner24943d22010-06-08 16:52:24 +0000525{
526 bool status;
527
Greg Clayton238c0a12010-09-18 01:14:36 +0000528 CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
529 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
530 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
531 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
532 CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +0000533 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000534 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +0000535
Jim Ingham10622a22010-06-18 00:58:52 +0000536 command_command_object->SetCommandName ("breakpoint command");
Chris Lattner24943d22010-06-08 16:52:24 +0000537 enable_command_object->SetCommandName("breakpoint enable");
538 disable_command_object->SetCommandName("breakpoint disable");
Chris Lattner24943d22010-06-08 16:52:24 +0000539 list_command_object->SetCommandName ("breakpoint list");
Jim Ingham10622a22010-06-18 00:58:52 +0000540 modify_command_object->SetCommandName ("breakpoint modify");
541 set_command_object->SetCommandName("breakpoint set");
Chris Lattner24943d22010-06-08 16:52:24 +0000542
Greg Clayton238c0a12010-09-18 01:14:36 +0000543 status = LoadSubCommand ("list", list_command_object);
544 status = LoadSubCommand ("enable", enable_command_object);
545 status = LoadSubCommand ("disable", disable_command_object);
546 status = LoadSubCommand ("delete", delete_command_object);
547 status = LoadSubCommand ("set", set_command_object);
548 status = LoadSubCommand ("command", command_command_object);
549 status = LoadSubCommand ("modify", modify_command_object);
Chris Lattner24943d22010-06-08 16:52:24 +0000550}
551
552CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
553{
554}
555
556void
557CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result,
558 BreakpointIDList *valid_ids)
559{
560 // args can be strings representing 1). integers (for breakpoint ids)
561 // 2). the full breakpoint & location canonical representation
562 // 3). the word "to" or a hyphen, representing a range (in which case there
563 // had *better* be an entry both before & after of one of the first two types.
Jim Inghamd1686902010-10-14 23:45:03 +0000564 // If args is empty, we will use the last created breakpoint (if there is one.)
Chris Lattner24943d22010-06-08 16:52:24 +0000565
566 Args temp_args;
567
Jim Inghamd1686902010-10-14 23:45:03 +0000568 if (args.GetArgumentCount() == 0)
569 {
570 if (target->GetLastCreatedBreakpoint() != NULL)
571 {
572 valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
573 result.SetStatus (eReturnStatusSuccessFinishNoResult);
574 }
575 else
576 {
577 result.AppendError("No breakpoint specified and no last created breakpoint.");
578 result.SetStatus (eReturnStatusFailed);
579 }
580 return;
581 }
582
Chris Lattner24943d22010-06-08 16:52:24 +0000583 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
584 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
585 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
586
587 BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
588
589 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
590
Greg Clayton54e7afa2010-07-09 20:39:50 +0000591 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
Chris Lattner24943d22010-06-08 16:52:24 +0000592
593 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
594 // and put into valid_ids.
595
596 if (result.Succeeded())
597 {
598 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
599 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
600
Greg Clayton54e7afa2010-07-09 20:39:50 +0000601 const size_t count = valid_ids->GetSize();
602 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000603 {
604 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
605 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
606 if (breakpoint != NULL)
607 {
608 int num_locations = breakpoint->GetNumLocations();
609 if (cur_bp_id.GetLocationID() > num_locations)
610 {
611 StreamString id_str;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000612 BreakpointID::GetCanonicalReference (&id_str,
613 cur_bp_id.GetBreakpointID(),
614 cur_bp_id.GetLocationID());
615 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000616 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
617 id_str.GetData());
618 result.SetStatus (eReturnStatusFailed);
619 }
620 }
621 else
622 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000623 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000624 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
625 result.SetStatus (eReturnStatusFailed);
626 }
627 }
628 }
629}
630
631//-------------------------------------------------------------------------
632// CommandObjectBreakpointList::Options
633//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000634#pragma mark List::CommandOptions
Chris Lattner24943d22010-06-08 16:52:24 +0000635
636CommandObjectBreakpointList::CommandOptions::CommandOptions() :
637 Options (),
638 m_level (lldb::eDescriptionLevelFull) // Breakpoint List defaults to brief descriptions
639{
Chris Lattner24943d22010-06-08 16:52:24 +0000640}
641
642CommandObjectBreakpointList::CommandOptions::~CommandOptions ()
643{
644}
645
646lldb::OptionDefinition
647CommandObjectBreakpointList::CommandOptions::g_option_table[] =
648{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000649 { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone,
Jim Ingham34e9a982010-06-15 18:47:14 +0000650 "Show debugger internal breakpoints" },
651
Caroline Tice4d6675c2010-10-01 19:59:14 +0000652 { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000653 "Give a brief description of the breakpoint (no location info)."},
654
655 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
656 // But I need to see it for now, and don't want to wait.
Caroline Tice4d6675c2010-10-01 19:59:14 +0000657 { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000658 "Give a full description of the breakpoint and its locations."},
Chris Lattner24943d22010-06-08 16:52:24 +0000659
Caroline Tice4d6675c2010-10-01 19:59:14 +0000660 { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000661 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
Chris Lattner24943d22010-06-08 16:52:24 +0000662
Caroline Tice4d6675c2010-10-01 19:59:14 +0000663 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000664};
665
666const lldb::OptionDefinition*
667CommandObjectBreakpointList::CommandOptions::GetDefinitions ()
668{
669 return g_option_table;
670}
671
672Error
673CommandObjectBreakpointList::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
674{
675 Error error;
676 char short_option = (char) m_getopt_table[option_idx].val;
677
678 switch (short_option)
679 {
680 case 'b':
681 m_level = lldb::eDescriptionLevelBrief;
682 break;
683 case 'f':
684 m_level = lldb::eDescriptionLevelFull;
685 break;
686 case 'v':
687 m_level = lldb::eDescriptionLevelVerbose;
688 break;
689 case 'i':
690 m_internal = true;
691 break;
692 default:
693 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
694 break;
695 }
696
697 return error;
698}
699
700void
701CommandObjectBreakpointList::CommandOptions::ResetOptionValues ()
702{
703 Options::ResetOptionValues();
704
705 m_level = lldb::eDescriptionLevelFull;
706 m_internal = false;
707}
708
709//-------------------------------------------------------------------------
710// CommandObjectBreakpointList
711//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000712#pragma mark List
Chris Lattner24943d22010-06-08 16:52:24 +0000713
Greg Clayton238c0a12010-09-18 01:14:36 +0000714CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) :
715 CommandObject (interpreter,
716 "breakpoint list",
717 "List some or all breakpoints at configurable levels of detail.",
Caroline Ticefb355112010-10-01 17:46:38 +0000718 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000719{
Caroline Ticefb355112010-10-01 17:46:38 +0000720 CommandArgumentEntry arg;
721 CommandArgumentData bp_id_arg;
722
723 // Define the first (and only) variant of this arg.
724 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +0000725 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000726
727 // There is only one variant this argument could be; put it into the argument entry.
728 arg.push_back (bp_id_arg);
729
730 // Push the data for the first argument into the m_arguments vector.
731 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000732}
733
734CommandObjectBreakpointList::~CommandObjectBreakpointList ()
735{
736}
737
738Options *
739CommandObjectBreakpointList::GetOptions ()
740{
741 return &m_options;
742}
743
744bool
745CommandObjectBreakpointList::Execute
746(
747 Args& args,
Chris Lattner24943d22010-06-08 16:52:24 +0000748 CommandReturnObject &result
749)
750{
Greg Clayton238c0a12010-09-18 01:14:36 +0000751 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000752 if (target == NULL)
753 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000754 result.AppendError ("Invalid target. No current target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000755 result.SetStatus (eReturnStatusSuccessFinishNoResult);
756 return true;
757 }
758
759 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000760 Mutex::Locker locker;
761 target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
762
Chris Lattner24943d22010-06-08 16:52:24 +0000763 size_t num_breakpoints = breakpoints.GetSize();
764
765 if (num_breakpoints == 0)
766 {
767 result.AppendMessage ("No breakpoints currently set.");
768 result.SetStatus (eReturnStatusSuccessFinishNoResult);
769 return true;
770 }
771
772 StreamString &output_stream = result.GetOutputStream();
773
774 if (args.GetArgumentCount() == 0)
775 {
776 // No breakpoint selected; show info about all currently set breakpoints.
777 result.AppendMessage ("Current breakpoints:");
Greg Clayton54e7afa2010-07-09 20:39:50 +0000778 for (size_t i = 0; i < num_breakpoints; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000779 {
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000780 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000781 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000782 }
783 result.SetStatus (eReturnStatusSuccessFinishNoResult);
784 }
785 else
786 {
787 // Particular breakpoints selected; show info about that breakpoint.
788 BreakpointIDList valid_bp_ids;
789 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
790
791 if (result.Succeeded())
792 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000793 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000794 {
795 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
796 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000797 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000798 }
799 result.SetStatus (eReturnStatusSuccessFinishNoResult);
800 }
801 else
802 {
803 result.AppendError ("Invalid breakpoint id.");
804 result.SetStatus (eReturnStatusFailed);
805 }
806 }
807
808 return result.Succeeded();
809}
810
811//-------------------------------------------------------------------------
812// CommandObjectBreakpointEnable
813//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000814#pragma mark Enable
Chris Lattner24943d22010-06-08 16:52:24 +0000815
Greg Clayton238c0a12010-09-18 01:14:36 +0000816CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
817 CommandObject (interpreter,
818 "enable",
Caroline Ticefb355112010-10-01 17:46:38 +0000819 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
820 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000821{
Caroline Ticefb355112010-10-01 17:46:38 +0000822 CommandArgumentEntry arg;
823 CommandArgumentData bp_id_arg;
824 CommandArgumentData bp_id_range_arg;
825
826 // Create the first variant for the first (and only) argument for this command.
827 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +0000828 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000829
830 // Create the second variant for the first (and only) argument for this command.
831 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +0000832 bp_id_range_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000833
834 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
835 // Push both variants into the entry for the first argument for this command.
836 arg.push_back (bp_id_arg);
837 arg.push_back (bp_id_range_arg);
838
839 // Add the entry for the first argument for this command to the object's arguments vector.
840 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000841}
842
843
844CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable ()
845{
846}
847
848
849bool
Greg Clayton63094e02010-06-23 01:19:29 +0000850CommandObjectBreakpointEnable::Execute
851(
Greg Clayton63094e02010-06-23 01:19:29 +0000852 Args& args,
853 CommandReturnObject &result
854)
Chris Lattner24943d22010-06-08 16:52:24 +0000855{
Greg Clayton238c0a12010-09-18 01:14:36 +0000856 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000857 if (target == NULL)
858 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000859 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000860 result.SetStatus (eReturnStatusFailed);
861 return false;
862 }
863
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000864 Mutex::Locker locker;
865 target->GetBreakpointList().GetListMutex(locker);
866
Chris Lattner24943d22010-06-08 16:52:24 +0000867 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000868
Chris Lattner24943d22010-06-08 16:52:24 +0000869 size_t num_breakpoints = breakpoints.GetSize();
870
871 if (num_breakpoints == 0)
872 {
873 result.AppendError ("No breakpoints exist to be enabled.");
874 result.SetStatus (eReturnStatusFailed);
875 return false;
876 }
877
878 if (args.GetArgumentCount() == 0)
879 {
880 // No breakpoint selected; enable all currently set breakpoints.
881 target->EnableAllBreakpoints ();
882 result.AppendMessageWithFormat ("All breakpoints enabled. (%d breakpoints)\n", num_breakpoints);
883 result.SetStatus (eReturnStatusSuccessFinishNoResult);
884 }
885 else
886 {
887 // Particular breakpoint selected; enable that breakpoint.
888 BreakpointIDList valid_bp_ids;
889 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
890
891 if (result.Succeeded())
892 {
893 int enable_count = 0;
894 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000895 const size_t count = valid_bp_ids.GetSize();
896 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000897 {
898 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
899
900 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
901 {
902 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
903 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
904 {
905 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
906 if (location)
907 {
908 location->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000909 ++loc_count;
910 }
911 }
912 else
913 {
Jim Ingham10622a22010-06-18 00:58:52 +0000914 breakpoint->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000915 ++enable_count;
Chris Lattner24943d22010-06-08 16:52:24 +0000916 }
917 }
918 }
919 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
920 result.SetStatus (eReturnStatusSuccessFinishNoResult);
921 }
922 }
923
924 return result.Succeeded();
925}
926
927//-------------------------------------------------------------------------
928// CommandObjectBreakpointDisable
929//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000930#pragma mark Disable
Chris Lattner24943d22010-06-08 16:52:24 +0000931
Greg Clayton238c0a12010-09-18 01:14:36 +0000932CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
933 CommandObject (interpreter,
Caroline Ticefb355112010-10-01 17:46:38 +0000934 "breakpoint disable",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000935 "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.",
Caroline Ticefb355112010-10-01 17:46:38 +0000936 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000937{
Caroline Ticefb355112010-10-01 17:46:38 +0000938 CommandArgumentEntry arg;
939 CommandArgumentData bp_id_arg;
940 CommandArgumentData bp_id_range_arg;
941
942 // Create the first variant for the first (and only) argument for this command.
943 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +0000944 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000945
946 // Create the second variant for the first (and only) argument for this command.
947 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +0000948 bp_id_range_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000949
950 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
951 // Push both variants into the entry for the first argument for this command.
952 arg.push_back (bp_id_arg);
953 arg.push_back (bp_id_range_arg);
954
955 // Add the entry for the first argument for this command to the object's arguments vector.
956 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000957}
958
959CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable ()
960{
961}
962
963bool
Greg Clayton63094e02010-06-23 01:19:29 +0000964CommandObjectBreakpointDisable::Execute
965(
Greg Clayton63094e02010-06-23 01:19:29 +0000966 Args& args,
967 CommandReturnObject &result
968)
Chris Lattner24943d22010-06-08 16:52:24 +0000969{
Greg Clayton238c0a12010-09-18 01:14:36 +0000970 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000971 if (target == NULL)
972 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000973 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000974 result.SetStatus (eReturnStatusFailed);
975 return false;
976 }
977
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000978 Mutex::Locker locker;
979 target->GetBreakpointList().GetListMutex(locker);
980
Chris Lattner24943d22010-06-08 16:52:24 +0000981 const BreakpointList &breakpoints = target->GetBreakpointList();
982 size_t num_breakpoints = breakpoints.GetSize();
983
984 if (num_breakpoints == 0)
985 {
986 result.AppendError ("No breakpoints exist to be disabled.");
987 result.SetStatus (eReturnStatusFailed);
988 return false;
989 }
990
991 if (args.GetArgumentCount() == 0)
992 {
993 // No breakpoint selected; disable all currently set breakpoints.
994 target->DisableAllBreakpoints ();
995 result.AppendMessageWithFormat ("All breakpoints disabled. (%d breakpoints)\n", num_breakpoints);
996 result.SetStatus (eReturnStatusSuccessFinishNoResult);
997 }
998 else
999 {
1000 // Particular breakpoint selected; disable that breakpoint.
1001 BreakpointIDList valid_bp_ids;
1002
1003 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
1004
1005 if (result.Succeeded())
1006 {
1007 int disable_count = 0;
1008 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001009 const size_t count = valid_bp_ids.GetSize();
1010 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +00001011 {
1012 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1013
1014 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1015 {
1016 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1017 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1018 {
1019 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1020 if (location)
1021 {
1022 location->SetEnabled (false);
1023 ++loc_count;
1024 }
1025 }
1026 else
1027 {
Jim Ingham10622a22010-06-18 00:58:52 +00001028 breakpoint->SetEnabled (false);
Chris Lattner24943d22010-06-08 16:52:24 +00001029 ++disable_count;
Chris Lattner24943d22010-06-08 16:52:24 +00001030 }
1031 }
1032 }
1033 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
1034 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1035 }
1036 }
1037
1038 return result.Succeeded();
1039}
1040
1041//-------------------------------------------------------------------------
1042// CommandObjectBreakpointDelete
1043//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001044#pragma mark Delete
Chris Lattner24943d22010-06-08 16:52:24 +00001045
Greg Clayton238c0a12010-09-18 01:14:36 +00001046CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) :
1047 CommandObject (interpreter,
1048 "breakpoint delete",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001049 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
Caroline Ticefb355112010-10-01 17:46:38 +00001050 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +00001051{
Caroline Ticefb355112010-10-01 17:46:38 +00001052 CommandArgumentEntry arg;
1053 CommandArgumentData bp_id_arg;
1054 CommandArgumentData bp_id_range_arg;
1055
1056 // Create the first variant for the first (and only) argument for this command.
1057 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +00001058 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +00001059
1060 // Create the second variant for the first (and only) argument for this command.
1061 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +00001062 bp_id_range_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +00001063
1064 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1065 // Push both variants into the entry for the first argument for this command.
1066 arg.push_back (bp_id_arg);
1067 arg.push_back (bp_id_range_arg);
1068
1069 // Add the entry for the first argument for this command to the object's arguments vector.
1070 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +00001071}
1072
1073
1074CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete ()
1075{
1076}
1077
1078bool
Greg Clayton63094e02010-06-23 01:19:29 +00001079CommandObjectBreakpointDelete::Execute
1080(
Greg Clayton63094e02010-06-23 01:19:29 +00001081 Args& args,
1082 CommandReturnObject &result
1083)
Chris Lattner24943d22010-06-08 16:52:24 +00001084{
Greg Clayton238c0a12010-09-18 01:14:36 +00001085 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001086 if (target == NULL)
1087 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001088 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +00001089 result.SetStatus (eReturnStatusFailed);
1090 return false;
1091 }
1092
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001093 Mutex::Locker locker;
1094 target->GetBreakpointList().GetListMutex(locker);
1095
Chris Lattner24943d22010-06-08 16:52:24 +00001096 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001097
Chris Lattner24943d22010-06-08 16:52:24 +00001098 size_t num_breakpoints = breakpoints.GetSize();
1099
1100 if (num_breakpoints == 0)
1101 {
1102 result.AppendError ("No breakpoints exist to be deleted.");
1103 result.SetStatus (eReturnStatusFailed);
1104 return false;
1105 }
1106
1107 if (args.GetArgumentCount() == 0)
1108 {
Jim Inghamd1686902010-10-14 23:45:03 +00001109 if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
Chris Lattner24943d22010-06-08 16:52:24 +00001110 {
Jim Inghamd1686902010-10-14 23:45:03 +00001111 result.AppendMessage("Operation cancelled...");
Chris Lattner24943d22010-06-08 16:52:24 +00001112 }
Jim Inghamd1686902010-10-14 23:45:03 +00001113 else
1114 {
1115 target->RemoveAllBreakpoints ();
1116 result.AppendMessageWithFormat ("All breakpoints removed. (%d breakpoints)\n", num_breakpoints);
1117 }
Chris Lattner24943d22010-06-08 16:52:24 +00001118 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1119 }
1120 else
1121 {
1122 // Particular breakpoint selected; disable that breakpoint.
1123 BreakpointIDList valid_bp_ids;
1124 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
1125
1126 if (result.Succeeded())
1127 {
1128 int delete_count = 0;
1129 int disable_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001130 const size_t count = valid_bp_ids.GetSize();
1131 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +00001132 {
1133 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1134
1135 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1136 {
1137 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1138 {
1139 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1140 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1141 // It makes no sense to try to delete individual locations, so we disable them instead.
1142 if (location)
1143 {
1144 location->SetEnabled (false);
1145 ++disable_count;
1146 }
1147 }
1148 else
1149 {
1150 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1151 ++delete_count;
1152 }
1153 }
1154 }
1155 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1156 delete_count, disable_count);
1157 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1158 }
1159 }
1160 return result.Succeeded();
1161}
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001162
1163//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001164// CommandObjectBreakpointModify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001165//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001166#pragma mark Modify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001167
Jim Ingham10622a22010-06-18 00:58:52 +00001168CommandObjectBreakpointModify::CommandOptions::CommandOptions() :
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001169 Options (),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001170 m_ignore_count (0),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001171 m_thread_id(LLDB_INVALID_THREAD_ID),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001172 m_thread_index (UINT32_MAX),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001173 m_thread_name(),
1174 m_queue_name(),
Jim Inghamd1686902010-10-14 23:45:03 +00001175 m_condition (),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001176 m_enable_passed (false),
1177 m_enable_value (false),
1178 m_name_passed (false),
Jim Inghamd1686902010-10-14 23:45:03 +00001179 m_queue_passed (false),
1180 m_condition_passed (false)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001181{
1182}
1183
Jim Ingham10622a22010-06-18 00:58:52 +00001184CommandObjectBreakpointModify::CommandOptions::~CommandOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001185{
1186}
1187
1188lldb::OptionDefinition
Jim Ingham10622a22010-06-18 00:58:52 +00001189CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001190{
Caroline Tice4d6675c2010-10-01 19:59:14 +00001191{ LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, NULL, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." },
1192{ 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."},
1193{ 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."},
1194{ 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."},
1195{ 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 +00001196{ 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 +00001197{ LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, eArgTypeNone, "Enable the breakpoint."},
1198{ LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, eArgTypeNone, "Disable the breakpoint."},
Jim Inghamd1686902010-10-14 23:45:03 +00001199{ 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001200};
1201
1202const lldb::OptionDefinition*
Jim Ingham10622a22010-06-18 00:58:52 +00001203CommandObjectBreakpointModify::CommandOptions::GetDefinitions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001204{
1205 return g_option_table;
1206}
1207
1208Error
Jim Ingham10622a22010-06-18 00:58:52 +00001209CommandObjectBreakpointModify::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001210{
1211 Error error;
1212 char short_option = (char) m_getopt_table[option_idx].val;
1213
1214 switch (short_option)
1215 {
Jim Inghamd1686902010-10-14 23:45:03 +00001216 case 'c':
1217 if (option_arg != NULL)
1218 m_condition = option_arg;
1219 else
1220 m_condition.clear();
1221 m_condition_passed = true;
1222 break;
Jim Ingham10622a22010-06-18 00:58:52 +00001223 case 'd':
1224 m_enable_passed = true;
1225 m_enable_value = false;
1226 break;
1227 case 'e':
1228 m_enable_passed = true;
1229 m_enable_value = true;
1230 break;
Greg Claytonfe424a92010-09-18 03:37:20 +00001231 case 'i':
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001232 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001233 m_ignore_count = Args::StringToUInt32(optarg, UINT32_MAX, 0);
1234 if (m_ignore_count == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001235 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", optarg);
1236 }
Jim Ingham10622a22010-06-18 00:58:52 +00001237 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001238 case 't' :
1239 {
1240 m_thread_id = Args::StringToUInt64(optarg, LLDB_INVALID_THREAD_ID, 0);
1241 if (m_thread_id == LLDB_INVALID_THREAD_ID)
1242 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", optarg);
1243 }
1244 break;
1245 case 'T':
Jim Inghamd4571222010-06-19 04:35:20 +00001246 if (option_arg != NULL)
1247 m_thread_name = option_arg;
1248 else
1249 m_thread_name.clear();
1250 m_name_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001251 break;
1252 case 'q':
Jim Inghamd4571222010-06-19 04:35:20 +00001253 if (option_arg != NULL)
1254 m_queue_name = option_arg;
1255 else
1256 m_queue_name.clear();
1257 m_queue_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001258 break;
1259 case 'x':
1260 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001261 m_thread_index = Args::StringToUInt32 (optarg, UINT32_MAX, 0);
1262 if (m_thread_id == UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001263 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", optarg);
1264
1265 }
1266 break;
1267 default:
1268 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1269 break;
1270 }
1271
1272 return error;
1273}
1274
1275void
Jim Ingham10622a22010-06-18 00:58:52 +00001276CommandObjectBreakpointModify::CommandOptions::ResetOptionValues ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001277{
1278 Options::ResetOptionValues();
1279
Greg Clayton54e7afa2010-07-09 20:39:50 +00001280 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001281 m_thread_id = LLDB_INVALID_THREAD_ID;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001282 m_thread_index = UINT32_MAX;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001283 m_thread_name.clear();
1284 m_queue_name.clear();
Jim Inghamd1686902010-10-14 23:45:03 +00001285 m_condition.clear();
Jim Ingham10622a22010-06-18 00:58:52 +00001286 m_enable_passed = false;
Jim Inghamd4571222010-06-19 04:35:20 +00001287 m_queue_passed = false;
1288 m_name_passed = false;
Jim Inghamd1686902010-10-14 23:45:03 +00001289 m_condition_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001290}
1291
1292//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001293// CommandObjectBreakpointModify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001294//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001295#pragma mark Modify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001296
Greg Clayton238c0a12010-09-18 01:14:36 +00001297CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
1298 CommandObject (interpreter,
1299 "breakpoint modify",
1300 "Modify the options on a breakpoint or set of breakpoints in the executable.",
Caroline Ticefb355112010-10-01 17:46:38 +00001301 NULL)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001302{
Caroline Ticefb355112010-10-01 17:46:38 +00001303 CommandArgumentEntry arg;
1304 CommandArgumentData bp_id_arg;
1305 CommandArgumentData bp_id_range_arg;
1306
1307 // Create the first variant for the first (and only) argument for this command.
1308 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +00001309 bp_id_arg.arg_repetition = eArgRepeatPlain;
Caroline Ticefb355112010-10-01 17:46:38 +00001310
1311 // Create the second variant for the first (and only) argument for this command.
1312 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +00001313 bp_id_range_arg.arg_repetition = eArgRepeatPlain;
Caroline Ticefb355112010-10-01 17:46:38 +00001314
1315 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1316 // Push both variants into the entry for the first argument for this command.
1317 arg.push_back (bp_id_arg);
1318 arg.push_back (bp_id_range_arg);
1319
1320 // Add the entry for the first argument for this command to the object's arguments vector.
1321 m_arguments.push_back (arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001322}
1323
Jim Ingham10622a22010-06-18 00:58:52 +00001324CommandObjectBreakpointModify::~CommandObjectBreakpointModify ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001325{
1326}
1327
1328Options *
Jim Ingham10622a22010-06-18 00:58:52 +00001329CommandObjectBreakpointModify::GetOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001330{
1331 return &m_options;
1332}
1333
1334bool
Jim Ingham10622a22010-06-18 00:58:52 +00001335CommandObjectBreakpointModify::Execute
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001336(
1337 Args& command,
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001338 CommandReturnObject &result
1339)
1340{
Greg Clayton238c0a12010-09-18 01:14:36 +00001341 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001342 if (target == NULL)
1343 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001344 result.AppendError ("Invalid target. No existing target or breakpoints.");
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001345 result.SetStatus (eReturnStatusFailed);
1346 return false;
1347 }
1348
1349 Mutex::Locker locker;
1350 target->GetBreakpointList().GetListMutex(locker);
1351
1352 BreakpointIDList valid_bp_ids;
1353
1354 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1355
1356 if (result.Succeeded())
1357 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001358 const size_t count = valid_bp_ids.GetSize();
1359 for (size_t i = 0; i < count; ++i)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001360 {
1361 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1362
1363 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1364 {
1365 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1366 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1367 {
1368 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
1369 if (location)
1370 {
1371 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
1372 location->SetThreadID (m_options.m_thread_id);
1373
Greg Clayton54e7afa2010-07-09 20:39:50 +00001374 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001375 location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1376
Jim Inghamd4571222010-06-19 04:35:20 +00001377 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001378 location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1379
Jim Inghamd4571222010-06-19 04:35:20 +00001380 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001381 location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1382
Greg Clayton54e7afa2010-07-09 20:39:50 +00001383 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001384 location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001385
1386 if (m_options.m_enable_passed)
1387 location->SetEnabled (m_options.m_enable_value);
Jim Inghamd1686902010-10-14 23:45:03 +00001388
1389 if (m_options.m_condition_passed)
1390 location->SetCondition (m_options.m_condition.c_str());
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001391 }
1392 }
1393 else
1394 {
1395 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
1396 bp->SetThreadID (m_options.m_thread_id);
1397
Greg Clayton54e7afa2010-07-09 20:39:50 +00001398 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001399 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1400
Jim Inghamd4571222010-06-19 04:35:20 +00001401 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001402 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1403
Jim Inghamd4571222010-06-19 04:35:20 +00001404 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001405 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1406
Greg Clayton54e7afa2010-07-09 20:39:50 +00001407 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001408 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001409
1410 if (m_options.m_enable_passed)
1411 bp->SetEnabled (m_options.m_enable_value);
Jim Inghamd1686902010-10-14 23:45:03 +00001412
1413 if (m_options.m_condition_passed)
1414 bp->SetCondition (m_options.m_condition.c_str());
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001415 }
1416 }
1417 }
1418 }
1419
1420 return result.Succeeded();
1421}
1422
1423