blob: 8208ea8123c21086e9ce15fdfd14987867ef6b8e [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
Johnny Chena62ad7c2010-10-28 17:27:46 +000031#include <vector>
32
Chris Lattner24943d22010-06-08 16:52:24 +000033using namespace lldb;
34using namespace lldb_private;
35
36static void
Jim Ingham2e8cb8a2011-02-19 02:53:09 +000037AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level)
Chris Lattner24943d22010-06-08 16:52:24 +000038{
39 s->IndentMore();
40 bp->GetDescription (s, level, true);
41 s->IndentLess();
42 s->EOL();
43}
44
45//-------------------------------------------------------------------------
46// CommandObjectBreakpointSet::CommandOptions
47//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +000048#pragma mark Set::CommandOptions
Chris Lattner24943d22010-06-08 16:52:24 +000049
50CommandObjectBreakpointSet::CommandOptions::CommandOptions() :
51 Options (),
52 m_filename (),
53 m_line_num (0),
54 m_column (0),
Greg Clayton2dfe4c62010-11-02 03:02:38 +000055 m_check_inlines (true),
Chris Lattner24943d22010-06-08 16:52:24 +000056 m_func_name (),
Greg Clayton12bec712010-06-28 21:30:43 +000057 m_func_name_type_mask (0),
Chris Lattner24943d22010-06-08 16:52:24 +000058 m_func_regexp (),
59 m_modules (),
Jim Ingham3c7b5b92010-06-16 02:00:15 +000060 m_load_addr(),
Greg Clayton54e7afa2010-07-09 20:39:50 +000061 m_ignore_count (0),
Jim Ingham3c7b5b92010-06-16 02:00:15 +000062 m_thread_id(LLDB_INVALID_THREAD_ID),
Greg Clayton54e7afa2010-07-09 20:39:50 +000063 m_thread_index (UINT32_MAX),
Jim Ingham3c7b5b92010-06-16 02:00:15 +000064 m_thread_name(),
Greg Clayton54e7afa2010-07-09 20:39:50 +000065 m_queue_name()
Chris Lattner24943d22010-06-08 16:52:24 +000066{
Chris Lattner24943d22010-06-08 16:52:24 +000067}
68
69CommandObjectBreakpointSet::CommandOptions::~CommandOptions ()
70{
71}
72
Greg Claytonb3448432011-03-24 21:19:54 +000073OptionDefinition
Chris Lattner24943d22010-06-08 16:52:24 +000074CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
75{
Caroline Tice4d6675c2010-10-01 19:59:14 +000076 { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
Jim Ingham34e9a982010-06-15 18:47:14 +000077 "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."},
78
Caroline Tice4d6675c2010-10-01 19:59:14 +000079 { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount,
80 "Set the number of times this breakpoint is skipped before stopping." },
Jim Ingham3c7b5b92010-06-16 02:00:15 +000081
Caroline Tice4d6675c2010-10-01 19:59:14 +000082 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex,
Greg Claytonfe424a92010-09-18 03:37:20 +000083 "The breakpoint stops only for the thread whose index matches this argument."},
Jim Ingham3c7b5b92010-06-16 02:00:15 +000084
Caroline Tice4d6675c2010-10-01 19:59:14 +000085 { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, eArgTypeThreadID,
Jim Ingham3c7b5b92010-06-16 02:00:15 +000086 "The breakpoint stops only for the thread whose TID matches this argument."},
87
Caroline Tice4d6675c2010-10-01 19:59:14 +000088 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, eArgTypeThreadName,
Jim Ingham3c7b5b92010-06-16 02:00:15 +000089 "The breakpoint stops only for the thread whose thread name matches this argument."},
90
Caroline Tice4d6675c2010-10-01 19:59:14 +000091 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, eArgTypeQueueName,
Jim Ingham3c7b5b92010-06-16 02:00:15 +000092 "The breakpoint stops only for threads in the queue whose name is given by this argument."},
93
Caroline Tice4d6675c2010-10-01 19:59:14 +000094 { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
Chris Lattner24943d22010-06-08 16:52:24 +000095 "Set the breakpoint by source location in this particular file."},
96
Caroline Tice4d6675c2010-10-01 19:59:14 +000097 { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
Chris Lattner24943d22010-06-08 16:52:24 +000098 "Set the breakpoint by source location at this particular line."},
99
Chris Lattner24943d22010-06-08 16:52:24 +0000100 // Comment out this option for the moment, as we don't actually use it, but will in the future.
101 // This way users won't see it, but the infrastructure is left in place.
102 // { 0, false, "column", 'c', required_argument, NULL, "<column>",
103 // "Set the breakpoint by source location at this particular column."},
104
Caroline Tice4d6675c2010-10-01 19:59:14 +0000105 { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress,
Chris Lattner24943d22010-06-08 16:52:24 +0000106 "Set the breakpoint by address, at the specified address."},
107
Caroline Tice4d6675c2010-10-01 19:59:14 +0000108 { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Greg Clayton48fbdf72010-10-12 04:29:14 +0000109 "Set the breakpoint by function name." },
Chris Lattner24943d22010-06-08 16:52:24 +0000110
Caroline Tice4d6675c2010-10-01 19:59:14 +0000111 { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
Jim Inghamd9e2b762010-08-26 23:56:11 +0000112 "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguemnts, and "
113 "for Objective C this means a full function prototype with class and selector." },
Greg Clayton12bec712010-06-28 21:30:43 +0000114
Caroline Tice4d6675c2010-10-01 19:59:14 +0000115 { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector,
Jim Inghamd9e2b762010-08-26 23:56:11 +0000116 "Set the breakpoint by ObjC selector name." },
Greg Clayton12bec712010-06-28 21:30:43 +0000117
Caroline Tice4d6675c2010-10-01 19:59:14 +0000118 { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod,
Jim Inghamd9e2b762010-08-26 23:56:11 +0000119 "Set the breakpoint by C++ method names." },
Greg Clayton12bec712010-06-28 21:30:43 +0000120
Caroline Tice4d6675c2010-10-01 19:59:14 +0000121 { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression,
Chris Lattner24943d22010-06-08 16:52:24 +0000122 "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
123
Greg Clayton48fbdf72010-10-12 04:29:14 +0000124 { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
125 "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored)." },
126
Caroline Tice4d6675c2010-10-01 19:59:14 +0000127 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000128};
129
Greg Claytonb3448432011-03-24 21:19:54 +0000130const OptionDefinition*
Chris Lattner24943d22010-06-08 16:52:24 +0000131CommandObjectBreakpointSet::CommandOptions::GetDefinitions ()
132{
133 return g_option_table;
134}
135
136Error
137CommandObjectBreakpointSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
138{
139 Error error;
140 char short_option = (char) m_getopt_table[option_idx].val;
141
142 switch (short_option)
143 {
144 case 'a':
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000145 m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0);
Chris Lattner24943d22010-06-08 16:52:24 +0000146 if (m_load_addr == LLDB_INVALID_ADDRESS)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000147 m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16);
Chris Lattner24943d22010-06-08 16:52:24 +0000148
149 if (m_load_addr == LLDB_INVALID_ADDRESS)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000150 error.SetErrorStringWithFormat ("Invalid address string '%s'.\n", option_arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000151 break;
152
153 case 'c':
154 m_column = Args::StringToUInt32 (option_arg, 0);
155 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000156
Chris Lattner24943d22010-06-08 16:52:24 +0000157 case 'f':
Greg Clayton889fbd02011-03-26 19:14:58 +0000158 m_filename.assign (option_arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000159 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000160
Chris Lattner24943d22010-06-08 16:52:24 +0000161 case 'l':
162 m_line_num = Args::StringToUInt32 (option_arg, 0);
163 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000164
Greg Clayton48fbdf72010-10-12 04:29:14 +0000165 case 'b':
Greg Clayton889fbd02011-03-26 19:14:58 +0000166 m_func_name.assign (option_arg);
Greg Clayton12bec712010-06-28 21:30:43 +0000167 m_func_name_type_mask |= eFunctionNameTypeBase;
168 break;
169
Greg Clayton48fbdf72010-10-12 04:29:14 +0000170 case 'n':
Greg Clayton889fbd02011-03-26 19:14:58 +0000171 m_func_name.assign (option_arg);
Greg Clayton48fbdf72010-10-12 04:29:14 +0000172 m_func_name_type_mask |= eFunctionNameTypeAuto;
173 break;
174
Greg Clayton12bec712010-06-28 21:30:43 +0000175 case 'F':
Greg Clayton889fbd02011-03-26 19:14:58 +0000176 m_func_name.assign (option_arg);
Greg Clayton12bec712010-06-28 21:30:43 +0000177 m_func_name_type_mask |= eFunctionNameTypeFull;
178 break;
179
180 case 'S':
Greg Clayton889fbd02011-03-26 19:14:58 +0000181 m_func_name.assign (option_arg);
Greg Clayton12bec712010-06-28 21:30:43 +0000182 m_func_name_type_mask |= eFunctionNameTypeSelector;
183 break;
184
Jim Inghamd9e2b762010-08-26 23:56:11 +0000185 case 'M':
Greg Clayton889fbd02011-03-26 19:14:58 +0000186 m_func_name.assign (option_arg);
Greg Clayton12bec712010-06-28 21:30:43 +0000187 m_func_name_type_mask |= eFunctionNameTypeMethod;
188 break;
189
Chris Lattner24943d22010-06-08 16:52:24 +0000190 case 'r':
Greg Clayton889fbd02011-03-26 19:14:58 +0000191 m_func_regexp.assign (option_arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000192 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000193
Chris Lattner24943d22010-06-08 16:52:24 +0000194 case 's':
195 {
196 m_modules.push_back (std::string (option_arg));
197 break;
198 }
Greg Claytonfe424a92010-09-18 03:37:20 +0000199 case 'i':
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000200 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000201 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Greg Clayton54e7afa2010-07-09 20:39:50 +0000202 if (m_ignore_count == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000203 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000204 }
Jim Ingham10622a22010-06-18 00:58:52 +0000205 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000206 case 't' :
207 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000208 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000209 if (m_thread_id == LLDB_INVALID_THREAD_ID)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000210 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000211 }
212 break;
213 case 'T':
Greg Clayton889fbd02011-03-26 19:14:58 +0000214 m_thread_name.assign (option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000215 break;
216 case 'q':
Greg Clayton889fbd02011-03-26 19:14:58 +0000217 m_queue_name.assign (option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000218 break;
219 case 'x':
220 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000221 m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Greg Clayton54e7afa2010-07-09 20:39:50 +0000222 if (m_thread_id == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000223 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000224
225 }
226 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000227 default:
228 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
229 break;
230 }
231
232 return error;
233}
234
235void
236CommandObjectBreakpointSet::CommandOptions::ResetOptionValues ()
237{
Chris Lattner24943d22010-06-08 16:52:24 +0000238 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,
Greg Clayton2dfe4c62010-11-02 03:02:38 +0000368 m_options.m_check_inlines).get();
Greg Clayton887aa282010-10-11 01:05:37 +0000369 if (bp)
370 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000371 Stream &output_stream = result.GetOutputStream();
372 result.AppendMessage ("Breakpoint created: ");
Greg Clayton887aa282010-10-11 01:05:37 +0000373 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,
Greg Clayton2dfe4c62010-11-02 03:02:38 +0000392 m_options.m_check_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 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000418 Stream &output_stream = result.GetOutputStream();
Greg Clayton12bec712010-06-28 21:30:43 +0000419 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 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000451 Stream &output_stream = result.GetOutputStream();
Chris Lattner24943d22010-06-08 16:52:24 +0000452 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 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000498 Stream &output_stream = result.GetOutputStream();
Chris Lattner24943d22010-06-08 16:52:24 +0000499 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));
Greg Clayton238c0a12010-09-18 01:14:36 +0000529 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
530 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
Johnny Chena62ad7c2010-10-28 17:27:46 +0000531 CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
532 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000533 CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +0000534 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000535 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +0000536
Johnny Chena62ad7c2010-10-28 17:27:46 +0000537 list_command_object->SetCommandName ("breakpoint list");
Chris Lattner24943d22010-06-08 16:52:24 +0000538 enable_command_object->SetCommandName("breakpoint enable");
539 disable_command_object->SetCommandName("breakpoint disable");
Johnny Chena62ad7c2010-10-28 17:27:46 +0000540 clear_command_object->SetCommandName("breakpoint clear");
541 delete_command_object->SetCommandName("breakpoint delete");
Jim Ingham10622a22010-06-18 00:58:52 +0000542 set_command_object->SetCommandName("breakpoint set");
Johnny Chena62ad7c2010-10-28 17:27:46 +0000543 command_command_object->SetCommandName ("breakpoint command");
544 modify_command_object->SetCommandName ("breakpoint modify");
Chris Lattner24943d22010-06-08 16:52:24 +0000545
Greg Clayton238c0a12010-09-18 01:14:36 +0000546 status = LoadSubCommand ("list", list_command_object);
547 status = LoadSubCommand ("enable", enable_command_object);
548 status = LoadSubCommand ("disable", disable_command_object);
Johnny Chena62ad7c2010-10-28 17:27:46 +0000549 status = LoadSubCommand ("clear", clear_command_object);
Greg Clayton238c0a12010-09-18 01:14:36 +0000550 status = LoadSubCommand ("delete", delete_command_object);
551 status = LoadSubCommand ("set", set_command_object);
552 status = LoadSubCommand ("command", command_command_object);
553 status = LoadSubCommand ("modify", modify_command_object);
Chris Lattner24943d22010-06-08 16:52:24 +0000554}
555
556CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
557{
558}
559
560void
561CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result,
562 BreakpointIDList *valid_ids)
563{
564 // args can be strings representing 1). integers (for breakpoint ids)
565 // 2). the full breakpoint & location canonical representation
566 // 3). the word "to" or a hyphen, representing a range (in which case there
567 // had *better* be an entry both before & after of one of the first two types.
Jim Inghamd1686902010-10-14 23:45:03 +0000568 // If args is empty, we will use the last created breakpoint (if there is one.)
Chris Lattner24943d22010-06-08 16:52:24 +0000569
570 Args temp_args;
571
Jim Inghamd1686902010-10-14 23:45:03 +0000572 if (args.GetArgumentCount() == 0)
573 {
574 if (target->GetLastCreatedBreakpoint() != NULL)
575 {
576 valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
577 result.SetStatus (eReturnStatusSuccessFinishNoResult);
578 }
579 else
580 {
581 result.AppendError("No breakpoint specified and no last created breakpoint.");
582 result.SetStatus (eReturnStatusFailed);
583 }
584 return;
585 }
586
Chris Lattner24943d22010-06-08 16:52:24 +0000587 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
588 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
589 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
590
591 BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
592
593 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
594
Greg Clayton54e7afa2010-07-09 20:39:50 +0000595 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
Chris Lattner24943d22010-06-08 16:52:24 +0000596
597 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
598 // and put into valid_ids.
599
600 if (result.Succeeded())
601 {
602 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
603 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
604
Greg Clayton54e7afa2010-07-09 20:39:50 +0000605 const size_t count = valid_ids->GetSize();
606 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000607 {
608 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
609 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
610 if (breakpoint != NULL)
611 {
612 int num_locations = breakpoint->GetNumLocations();
613 if (cur_bp_id.GetLocationID() > num_locations)
614 {
615 StreamString id_str;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000616 BreakpointID::GetCanonicalReference (&id_str,
617 cur_bp_id.GetBreakpointID(),
618 cur_bp_id.GetLocationID());
619 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000620 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
621 id_str.GetData());
622 result.SetStatus (eReturnStatusFailed);
623 }
624 }
625 else
626 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000627 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000628 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
629 result.SetStatus (eReturnStatusFailed);
630 }
631 }
632 }
633}
634
635//-------------------------------------------------------------------------
636// CommandObjectBreakpointList::Options
637//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000638#pragma mark List::CommandOptions
Chris Lattner24943d22010-06-08 16:52:24 +0000639
640CommandObjectBreakpointList::CommandOptions::CommandOptions() :
641 Options (),
Caroline Tice41950cc2011-02-04 22:59:41 +0000642 m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions
Chris Lattner24943d22010-06-08 16:52:24 +0000643{
Chris Lattner24943d22010-06-08 16:52:24 +0000644}
645
646CommandObjectBreakpointList::CommandOptions::~CommandOptions ()
647{
648}
649
Greg Claytonb3448432011-03-24 21:19:54 +0000650OptionDefinition
Chris Lattner24943d22010-06-08 16:52:24 +0000651CommandObjectBreakpointList::CommandOptions::g_option_table[] =
652{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000653 { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone,
Jim Ingham34e9a982010-06-15 18:47:14 +0000654 "Show debugger internal breakpoints" },
655
Caroline Tice4d6675c2010-10-01 19:59:14 +0000656 { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000657 "Give a brief description of the breakpoint (no location info)."},
658
659 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
660 // But I need to see it for now, and don't want to wait.
Caroline Tice4d6675c2010-10-01 19:59:14 +0000661 { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000662 "Give a full description of the breakpoint and its locations."},
Chris Lattner24943d22010-06-08 16:52:24 +0000663
Caroline Tice4d6675c2010-10-01 19:59:14 +0000664 { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000665 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
Chris Lattner24943d22010-06-08 16:52:24 +0000666
Caroline Tice4d6675c2010-10-01 19:59:14 +0000667 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000668};
669
Greg Claytonb3448432011-03-24 21:19:54 +0000670const OptionDefinition*
Chris Lattner24943d22010-06-08 16:52:24 +0000671CommandObjectBreakpointList::CommandOptions::GetDefinitions ()
672{
673 return g_option_table;
674}
675
676Error
677CommandObjectBreakpointList::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
678{
679 Error error;
680 char short_option = (char) m_getopt_table[option_idx].val;
681
682 switch (short_option)
683 {
684 case 'b':
685 m_level = lldb::eDescriptionLevelBrief;
686 break;
687 case 'f':
688 m_level = lldb::eDescriptionLevelFull;
689 break;
690 case 'v':
691 m_level = lldb::eDescriptionLevelVerbose;
692 break;
693 case 'i':
694 m_internal = true;
695 break;
696 default:
697 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
698 break;
699 }
700
701 return error;
702}
703
704void
705CommandObjectBreakpointList::CommandOptions::ResetOptionValues ()
706{
Caroline Tice41950cc2011-02-04 22:59:41 +0000707 m_level = lldb::eDescriptionLevelBrief;
Chris Lattner24943d22010-06-08 16:52:24 +0000708 m_internal = false;
709}
710
711//-------------------------------------------------------------------------
712// CommandObjectBreakpointList
713//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000714#pragma mark List
Chris Lattner24943d22010-06-08 16:52:24 +0000715
Greg Clayton238c0a12010-09-18 01:14:36 +0000716CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) :
717 CommandObject (interpreter,
718 "breakpoint list",
719 "List some or all breakpoints at configurable levels of detail.",
Caroline Ticefb355112010-10-01 17:46:38 +0000720 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000721{
Caroline Ticefb355112010-10-01 17:46:38 +0000722 CommandArgumentEntry arg;
723 CommandArgumentData bp_id_arg;
724
725 // Define the first (and only) variant of this arg.
726 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +0000727 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000728
729 // There is only one variant this argument could be; put it into the argument entry.
730 arg.push_back (bp_id_arg);
731
732 // Push the data for the first argument into the m_arguments vector.
733 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000734}
735
736CommandObjectBreakpointList::~CommandObjectBreakpointList ()
737{
738}
739
740Options *
741CommandObjectBreakpointList::GetOptions ()
742{
743 return &m_options;
744}
745
746bool
747CommandObjectBreakpointList::Execute
748(
749 Args& args,
Chris Lattner24943d22010-06-08 16:52:24 +0000750 CommandReturnObject &result
751)
752{
Greg Clayton238c0a12010-09-18 01:14:36 +0000753 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000754 if (target == NULL)
755 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000756 result.AppendError ("Invalid target. No current target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000757 result.SetStatus (eReturnStatusSuccessFinishNoResult);
758 return true;
759 }
760
761 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000762 Mutex::Locker locker;
763 target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
764
Chris Lattner24943d22010-06-08 16:52:24 +0000765 size_t num_breakpoints = breakpoints.GetSize();
766
767 if (num_breakpoints == 0)
768 {
769 result.AppendMessage ("No breakpoints currently set.");
770 result.SetStatus (eReturnStatusSuccessFinishNoResult);
771 return true;
772 }
773
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000774 Stream &output_stream = result.GetOutputStream();
Chris Lattner24943d22010-06-08 16:52:24 +0000775
776 if (args.GetArgumentCount() == 0)
777 {
778 // No breakpoint selected; show info about all currently set breakpoints.
779 result.AppendMessage ("Current breakpoints:");
Greg Clayton54e7afa2010-07-09 20:39:50 +0000780 for (size_t i = 0; i < num_breakpoints; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000781 {
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000782 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).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 // Particular breakpoints selected; show info about that breakpoint.
790 BreakpointIDList valid_bp_ids;
791 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
792
793 if (result.Succeeded())
794 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000795 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000796 {
797 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
798 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000799 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000800 }
801 result.SetStatus (eReturnStatusSuccessFinishNoResult);
802 }
803 else
804 {
805 result.AppendError ("Invalid breakpoint id.");
806 result.SetStatus (eReturnStatusFailed);
807 }
808 }
809
810 return result.Succeeded();
811}
812
813//-------------------------------------------------------------------------
814// CommandObjectBreakpointEnable
815//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000816#pragma mark Enable
Chris Lattner24943d22010-06-08 16:52:24 +0000817
Greg Clayton238c0a12010-09-18 01:14:36 +0000818CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
819 CommandObject (interpreter,
820 "enable",
Caroline Ticefb355112010-10-01 17:46:38 +0000821 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
822 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000823{
Caroline Ticefb355112010-10-01 17:46:38 +0000824 CommandArgumentEntry arg;
825 CommandArgumentData bp_id_arg;
826 CommandArgumentData bp_id_range_arg;
827
828 // Create the first variant for the first (and only) argument for this command.
829 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +0000830 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000831
832 // Create the second variant for the first (and only) argument for this command.
833 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +0000834 bp_id_range_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000835
836 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
837 // Push both variants into the entry for the first argument for this command.
838 arg.push_back (bp_id_arg);
839 arg.push_back (bp_id_range_arg);
840
841 // Add the entry for the first argument for this command to the object's arguments vector.
842 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000843}
844
845
846CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable ()
847{
848}
849
850
851bool
Greg Clayton63094e02010-06-23 01:19:29 +0000852CommandObjectBreakpointEnable::Execute
853(
Greg Clayton63094e02010-06-23 01:19:29 +0000854 Args& args,
855 CommandReturnObject &result
856)
Chris Lattner24943d22010-06-08 16:52:24 +0000857{
Greg Clayton238c0a12010-09-18 01:14:36 +0000858 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000859 if (target == NULL)
860 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000861 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000862 result.SetStatus (eReturnStatusFailed);
863 return false;
864 }
865
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000866 Mutex::Locker locker;
867 target->GetBreakpointList().GetListMutex(locker);
868
Chris Lattner24943d22010-06-08 16:52:24 +0000869 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000870
Chris Lattner24943d22010-06-08 16:52:24 +0000871 size_t num_breakpoints = breakpoints.GetSize();
872
873 if (num_breakpoints == 0)
874 {
875 result.AppendError ("No breakpoints exist to be enabled.");
876 result.SetStatus (eReturnStatusFailed);
877 return false;
878 }
879
880 if (args.GetArgumentCount() == 0)
881 {
882 // No breakpoint selected; enable all currently set breakpoints.
883 target->EnableAllBreakpoints ();
884 result.AppendMessageWithFormat ("All breakpoints enabled. (%d breakpoints)\n", num_breakpoints);
885 result.SetStatus (eReturnStatusSuccessFinishNoResult);
886 }
887 else
888 {
889 // Particular breakpoint selected; enable that breakpoint.
890 BreakpointIDList valid_bp_ids;
891 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
892
893 if (result.Succeeded())
894 {
895 int enable_count = 0;
896 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000897 const size_t count = valid_bp_ids.GetSize();
898 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000899 {
900 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
901
902 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
903 {
904 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
905 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
906 {
907 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
908 if (location)
909 {
910 location->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000911 ++loc_count;
912 }
913 }
914 else
915 {
Jim Ingham10622a22010-06-18 00:58:52 +0000916 breakpoint->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000917 ++enable_count;
Chris Lattner24943d22010-06-08 16:52:24 +0000918 }
919 }
920 }
921 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
922 result.SetStatus (eReturnStatusSuccessFinishNoResult);
923 }
924 }
925
926 return result.Succeeded();
927}
928
929//-------------------------------------------------------------------------
930// CommandObjectBreakpointDisable
931//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000932#pragma mark Disable
Chris Lattner24943d22010-06-08 16:52:24 +0000933
Greg Clayton238c0a12010-09-18 01:14:36 +0000934CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
935 CommandObject (interpreter,
Caroline Ticefb355112010-10-01 17:46:38 +0000936 "breakpoint disable",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000937 "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.",
Caroline Ticefb355112010-10-01 17:46:38 +0000938 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000939{
Caroline Ticefb355112010-10-01 17:46:38 +0000940 CommandArgumentEntry arg;
941 CommandArgumentData bp_id_arg;
942 CommandArgumentData bp_id_range_arg;
943
944 // Create the first variant for the first (and only) argument for this command.
945 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +0000946 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000947
948 // Create the second variant for the first (and only) argument for this command.
949 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +0000950 bp_id_range_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000951
952 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
953 // Push both variants into the entry for the first argument for this command.
954 arg.push_back (bp_id_arg);
955 arg.push_back (bp_id_range_arg);
956
957 // Add the entry for the first argument for this command to the object's arguments vector.
958 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000959}
960
961CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable ()
962{
963}
964
965bool
Greg Clayton63094e02010-06-23 01:19:29 +0000966CommandObjectBreakpointDisable::Execute
967(
Greg Clayton63094e02010-06-23 01:19:29 +0000968 Args& args,
969 CommandReturnObject &result
970)
Chris Lattner24943d22010-06-08 16:52:24 +0000971{
Greg Clayton238c0a12010-09-18 01:14:36 +0000972 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000973 if (target == NULL)
974 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000975 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000976 result.SetStatus (eReturnStatusFailed);
977 return false;
978 }
979
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000980 Mutex::Locker locker;
981 target->GetBreakpointList().GetListMutex(locker);
982
Chris Lattner24943d22010-06-08 16:52:24 +0000983 const BreakpointList &breakpoints = target->GetBreakpointList();
984 size_t num_breakpoints = breakpoints.GetSize();
985
986 if (num_breakpoints == 0)
987 {
988 result.AppendError ("No breakpoints exist to be disabled.");
989 result.SetStatus (eReturnStatusFailed);
990 return false;
991 }
992
993 if (args.GetArgumentCount() == 0)
994 {
995 // No breakpoint selected; disable all currently set breakpoints.
996 target->DisableAllBreakpoints ();
997 result.AppendMessageWithFormat ("All breakpoints disabled. (%d breakpoints)\n", num_breakpoints);
998 result.SetStatus (eReturnStatusSuccessFinishNoResult);
999 }
1000 else
1001 {
1002 // Particular breakpoint selected; disable that breakpoint.
1003 BreakpointIDList valid_bp_ids;
1004
1005 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
1006
1007 if (result.Succeeded())
1008 {
1009 int disable_count = 0;
1010 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001011 const size_t count = valid_bp_ids.GetSize();
1012 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +00001013 {
1014 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1015
1016 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1017 {
1018 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1019 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1020 {
1021 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1022 if (location)
1023 {
1024 location->SetEnabled (false);
1025 ++loc_count;
1026 }
1027 }
1028 else
1029 {
Jim Ingham10622a22010-06-18 00:58:52 +00001030 breakpoint->SetEnabled (false);
Chris Lattner24943d22010-06-08 16:52:24 +00001031 ++disable_count;
Chris Lattner24943d22010-06-08 16:52:24 +00001032 }
1033 }
1034 }
1035 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
1036 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1037 }
1038 }
1039
1040 return result.Succeeded();
1041}
1042
1043//-------------------------------------------------------------------------
Johnny Chena62ad7c2010-10-28 17:27:46 +00001044// CommandObjectBreakpointClear::CommandOptions
1045//-------------------------------------------------------------------------
1046#pragma mark Clear::CommandOptions
1047
1048CommandObjectBreakpointClear::CommandOptions::CommandOptions() :
1049 Options (),
1050 m_filename (),
1051 m_line_num (0)
1052{
1053}
1054
1055CommandObjectBreakpointClear::CommandOptions::~CommandOptions ()
1056{
1057}
1058
Greg Claytonb3448432011-03-24 21:19:54 +00001059OptionDefinition
Johnny Chena62ad7c2010-10-28 17:27:46 +00001060CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
1061{
1062 { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
1063 "Specify the breakpoint by source location in this particular file."},
1064
1065 { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
1066 "Specify the breakpoint by source location at this particular line."},
1067
1068 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1069};
1070
Greg Claytonb3448432011-03-24 21:19:54 +00001071const OptionDefinition*
Johnny Chena62ad7c2010-10-28 17:27:46 +00001072CommandObjectBreakpointClear::CommandOptions::GetDefinitions ()
1073{
1074 return g_option_table;
1075}
1076
1077Error
1078CommandObjectBreakpointClear::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
1079{
1080 Error error;
1081 char short_option = (char) m_getopt_table[option_idx].val;
1082
1083 switch (short_option)
1084 {
1085 case 'f':
Greg Clayton889fbd02011-03-26 19:14:58 +00001086 m_filename.assign (option_arg);
Johnny Chena62ad7c2010-10-28 17:27:46 +00001087 break;
1088
1089 case 'l':
1090 m_line_num = Args::StringToUInt32 (option_arg, 0);
1091 break;
1092
1093 default:
1094 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1095 break;
1096 }
1097
1098 return error;
1099}
1100
1101void
1102CommandObjectBreakpointClear::CommandOptions::ResetOptionValues ()
1103{
Johnny Chena62ad7c2010-10-28 17:27:46 +00001104 m_filename.clear();
1105 m_line_num = 0;
1106}
1107
1108//-------------------------------------------------------------------------
1109// CommandObjectBreakpointClear
1110//-------------------------------------------------------------------------
1111#pragma mark Clear
1112
1113CommandObjectBreakpointClear::CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
1114 CommandObject (interpreter,
1115 "breakpoint clear",
1116 "Clears a breakpoint or set of breakpoints in the executable.",
1117 "breakpoint clear <cmd-options>")
1118{
1119}
1120
1121CommandObjectBreakpointClear::~CommandObjectBreakpointClear ()
1122{
1123}
1124
1125Options *
1126CommandObjectBreakpointClear::GetOptions ()
1127{
1128 return &m_options;
1129}
1130
1131bool
1132CommandObjectBreakpointClear::Execute
1133(
1134 Args& command,
1135 CommandReturnObject &result
1136)
1137{
1138 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1139 if (target == NULL)
1140 {
1141 result.AppendError ("Invalid target. No existing target or breakpoints.");
1142 result.SetStatus (eReturnStatusFailed);
1143 return false;
1144 }
1145
1146 // The following are the various types of breakpoints that could be cleared:
1147 // 1). -f -l (clearing breakpoint by source location)
1148
1149 BreakpointClearType break_type = eClearTypeInvalid;
1150
1151 if (m_options.m_line_num != 0)
1152 break_type = eClearTypeFileAndLine;
1153
1154 Mutex::Locker locker;
1155 target->GetBreakpointList().GetListMutex(locker);
1156
1157 BreakpointList &breakpoints = target->GetBreakpointList();
1158 size_t num_breakpoints = breakpoints.GetSize();
1159
1160 // Early return if there's no breakpoint at all.
1161 if (num_breakpoints == 0)
1162 {
1163 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1164 result.SetStatus (eReturnStatusFailed);
1165 return result.Succeeded();
1166 }
1167
1168 // Find matching breakpoints and delete them.
1169
1170 // First create a copy of all the IDs.
1171 std::vector<break_id_t> BreakIDs;
1172 for (size_t i = 0; i < num_breakpoints; ++i)
1173 BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID());
1174
1175 int num_cleared = 0;
1176 StreamString ss;
1177 switch (break_type)
1178 {
1179 case eClearTypeFileAndLine: // Breakpoint by source position
1180 {
1181 const ConstString filename(m_options.m_filename.c_str());
1182 BreakpointLocationCollection loc_coll;
1183
1184 for (size_t i = 0; i < num_breakpoints; ++i)
1185 {
1186 Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
1187
1188 if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
1189 {
1190 // If the collection size is 0, it's a full match and we can just remove the breakpoint.
1191 if (loc_coll.GetSize() == 0)
1192 {
1193 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
1194 ss.EOL();
1195 target->RemoveBreakpointByID (bp->GetID());
1196 ++num_cleared;
1197 }
1198 }
1199 }
1200 }
1201 break;
1202
1203 default:
1204 break;
1205 }
1206
1207 if (num_cleared > 0)
1208 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +00001209 Stream &output_stream = result.GetOutputStream();
Johnny Chena62ad7c2010-10-28 17:27:46 +00001210 output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
1211 output_stream << ss.GetData();
1212 output_stream.EOL();
1213 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1214 }
1215 else
1216 {
1217 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1218 result.SetStatus (eReturnStatusFailed);
1219 }
1220
1221 return result.Succeeded();
1222}
1223
1224//-------------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +00001225// CommandObjectBreakpointDelete
1226//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001227#pragma mark Delete
Chris Lattner24943d22010-06-08 16:52:24 +00001228
Greg Clayton238c0a12010-09-18 01:14:36 +00001229CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) :
1230 CommandObject (interpreter,
1231 "breakpoint delete",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001232 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
Caroline Ticefb355112010-10-01 17:46:38 +00001233 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +00001234{
Caroline Ticefb355112010-10-01 17:46:38 +00001235 CommandArgumentEntry arg;
1236 CommandArgumentData bp_id_arg;
1237 CommandArgumentData bp_id_range_arg;
1238
1239 // Create the first variant for the first (and only) argument for this command.
1240 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +00001241 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +00001242
1243 // Create the second variant for the first (and only) argument for this command.
1244 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +00001245 bp_id_range_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +00001246
1247 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1248 // Push both variants into the entry for the first argument for this command.
1249 arg.push_back (bp_id_arg);
1250 arg.push_back (bp_id_range_arg);
1251
1252 // Add the entry for the first argument for this command to the object's arguments vector.
1253 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +00001254}
1255
1256
1257CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete ()
1258{
1259}
1260
1261bool
Greg Clayton63094e02010-06-23 01:19:29 +00001262CommandObjectBreakpointDelete::Execute
1263(
Greg Clayton63094e02010-06-23 01:19:29 +00001264 Args& args,
1265 CommandReturnObject &result
1266)
Chris Lattner24943d22010-06-08 16:52:24 +00001267{
Greg Clayton238c0a12010-09-18 01:14:36 +00001268 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001269 if (target == NULL)
1270 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001271 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +00001272 result.SetStatus (eReturnStatusFailed);
1273 return false;
1274 }
1275
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001276 Mutex::Locker locker;
1277 target->GetBreakpointList().GetListMutex(locker);
1278
Chris Lattner24943d22010-06-08 16:52:24 +00001279 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001280
Chris Lattner24943d22010-06-08 16:52:24 +00001281 size_t num_breakpoints = breakpoints.GetSize();
1282
1283 if (num_breakpoints == 0)
1284 {
1285 result.AppendError ("No breakpoints exist to be deleted.");
1286 result.SetStatus (eReturnStatusFailed);
1287 return false;
1288 }
1289
1290 if (args.GetArgumentCount() == 0)
1291 {
Jim Inghamd1686902010-10-14 23:45:03 +00001292 if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
Chris Lattner24943d22010-06-08 16:52:24 +00001293 {
Jim Inghamd1686902010-10-14 23:45:03 +00001294 result.AppendMessage("Operation cancelled...");
Chris Lattner24943d22010-06-08 16:52:24 +00001295 }
Jim Inghamd1686902010-10-14 23:45:03 +00001296 else
1297 {
1298 target->RemoveAllBreakpoints ();
1299 result.AppendMessageWithFormat ("All breakpoints removed. (%d breakpoints)\n", num_breakpoints);
1300 }
Chris Lattner24943d22010-06-08 16:52:24 +00001301 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1302 }
1303 else
1304 {
1305 // Particular breakpoint selected; disable that breakpoint.
1306 BreakpointIDList valid_bp_ids;
1307 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
1308
1309 if (result.Succeeded())
1310 {
1311 int delete_count = 0;
1312 int disable_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001313 const size_t count = valid_bp_ids.GetSize();
1314 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +00001315 {
1316 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1317
1318 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1319 {
1320 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1321 {
1322 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1323 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1324 // It makes no sense to try to delete individual locations, so we disable them instead.
1325 if (location)
1326 {
1327 location->SetEnabled (false);
1328 ++disable_count;
1329 }
1330 }
1331 else
1332 {
1333 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1334 ++delete_count;
1335 }
1336 }
1337 }
1338 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1339 delete_count, disable_count);
1340 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1341 }
1342 }
1343 return result.Succeeded();
1344}
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001345
1346//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001347// CommandObjectBreakpointModify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001348//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001349#pragma mark Modify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001350
Jim Ingham10622a22010-06-18 00:58:52 +00001351CommandObjectBreakpointModify::CommandOptions::CommandOptions() :
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001352 Options (),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001353 m_ignore_count (0),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001354 m_thread_id(LLDB_INVALID_THREAD_ID),
Jim Ingham9a7b2912010-12-03 23:04:19 +00001355 m_thread_id_passed(false),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001356 m_thread_index (UINT32_MAX),
Jim Ingham9a7b2912010-12-03 23:04:19 +00001357 m_thread_index_passed(false),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001358 m_thread_name(),
1359 m_queue_name(),
Jim Inghamd1686902010-10-14 23:45:03 +00001360 m_condition (),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001361 m_enable_passed (false),
1362 m_enable_value (false),
1363 m_name_passed (false),
Jim Inghamd1686902010-10-14 23:45:03 +00001364 m_queue_passed (false),
1365 m_condition_passed (false)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001366{
1367}
1368
Jim Ingham10622a22010-06-18 00:58:52 +00001369CommandObjectBreakpointModify::CommandOptions::~CommandOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001370{
1371}
1372
Greg Claytonb3448432011-03-24 21:19:54 +00001373OptionDefinition
Jim Ingham10622a22010-06-18 00:58:52 +00001374CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001375{
Caroline Tice4d6675c2010-10-01 19:59:14 +00001376{ LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, NULL, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." },
1377{ 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."},
1378{ 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."},
1379{ 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."},
1380{ 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 +00001381{ 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 +00001382{ LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, eArgTypeNone, "Enable the breakpoint."},
1383{ LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, eArgTypeNone, "Disable the breakpoint."},
Jim Inghamd1686902010-10-14 23:45:03 +00001384{ 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001385};
1386
Greg Claytonb3448432011-03-24 21:19:54 +00001387const OptionDefinition*
Jim Ingham10622a22010-06-18 00:58:52 +00001388CommandObjectBreakpointModify::CommandOptions::GetDefinitions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001389{
1390 return g_option_table;
1391}
1392
1393Error
Jim Ingham10622a22010-06-18 00:58:52 +00001394CommandObjectBreakpointModify::CommandOptions::SetOptionValue (int option_idx, const char *option_arg)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001395{
1396 Error error;
1397 char short_option = (char) m_getopt_table[option_idx].val;
1398
1399 switch (short_option)
1400 {
Jim Inghamd1686902010-10-14 23:45:03 +00001401 case 'c':
1402 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001403 m_condition.assign (option_arg);
Jim Inghamd1686902010-10-14 23:45:03 +00001404 else
1405 m_condition.clear();
1406 m_condition_passed = true;
1407 break;
Jim Ingham10622a22010-06-18 00:58:52 +00001408 case 'd':
1409 m_enable_passed = true;
1410 m_enable_value = false;
1411 break;
1412 case 'e':
1413 m_enable_passed = true;
1414 m_enable_value = true;
1415 break;
Greg Claytonfe424a92010-09-18 03:37:20 +00001416 case 'i':
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001417 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001418 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Greg Clayton54e7afa2010-07-09 20:39:50 +00001419 if (m_ignore_count == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001420 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001421 }
Jim Ingham10622a22010-06-18 00:58:52 +00001422 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001423 case 't' :
1424 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001425 if (option_arg[0] == '\0')
Jim Ingham9a7b2912010-12-03 23:04:19 +00001426 {
1427 m_thread_id = LLDB_INVALID_THREAD_ID;
1428 m_thread_id_passed = true;
1429 }
1430 else
1431 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001432 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001433 if (m_thread_id == LLDB_INVALID_THREAD_ID)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001434 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", option_arg);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001435 else
1436 m_thread_id_passed = true;
1437 }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001438 }
1439 break;
1440 case 'T':
Jim Inghamd4571222010-06-19 04:35:20 +00001441 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001442 m_thread_name.assign (option_arg);
Jim Inghamd4571222010-06-19 04:35:20 +00001443 else
1444 m_thread_name.clear();
1445 m_name_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001446 break;
1447 case 'q':
Jim Inghamd4571222010-06-19 04:35:20 +00001448 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001449 m_queue_name.assign (option_arg);
Jim Inghamd4571222010-06-19 04:35:20 +00001450 else
1451 m_queue_name.clear();
1452 m_queue_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001453 break;
1454 case 'x':
1455 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001456 if (option_arg[0] == '\n')
Jim Ingham9a7b2912010-12-03 23:04:19 +00001457 {
1458 m_thread_index = UINT32_MAX;
1459 m_thread_index_passed = true;
1460 }
1461 else
1462 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001463 m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001464 if (m_thread_id == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001465 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", option_arg);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001466 else
1467 m_thread_index_passed = true;
1468 }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001469 }
1470 break;
1471 default:
1472 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1473 break;
1474 }
1475
1476 return error;
1477}
1478
1479void
Jim Ingham10622a22010-06-18 00:58:52 +00001480CommandObjectBreakpointModify::CommandOptions::ResetOptionValues ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001481{
Greg Clayton54e7afa2010-07-09 20:39:50 +00001482 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001483 m_thread_id = LLDB_INVALID_THREAD_ID;
Jim Ingham9a7b2912010-12-03 23:04:19 +00001484 m_thread_id_passed = false;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001485 m_thread_index = UINT32_MAX;
Jim Ingham9a7b2912010-12-03 23:04:19 +00001486 m_thread_index_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001487 m_thread_name.clear();
1488 m_queue_name.clear();
Jim Inghamd1686902010-10-14 23:45:03 +00001489 m_condition.clear();
Jim Ingham10622a22010-06-18 00:58:52 +00001490 m_enable_passed = false;
Jim Inghamd4571222010-06-19 04:35:20 +00001491 m_queue_passed = false;
1492 m_name_passed = false;
Jim Inghamd1686902010-10-14 23:45:03 +00001493 m_condition_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001494}
1495
1496//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001497// CommandObjectBreakpointModify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001498//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001499#pragma mark Modify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001500
Greg Clayton238c0a12010-09-18 01:14:36 +00001501CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
1502 CommandObject (interpreter,
1503 "breakpoint modify",
Jim Ingham19ac0bd2010-12-03 22:37:19 +00001504 "Modify the options on a breakpoint or set of breakpoints in the executable. "
Jim Ingham9a7b2912010-12-03 23:04:19 +00001505 "If no breakpoint is specified, acts on the last created breakpoint. "
1506 "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
Caroline Ticefb355112010-10-01 17:46:38 +00001507 NULL)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001508{
Caroline Ticefb355112010-10-01 17:46:38 +00001509 CommandArgumentEntry arg;
1510 CommandArgumentData bp_id_arg;
1511 CommandArgumentData bp_id_range_arg;
1512
1513 // Create the first variant for the first (and only) argument for this command.
1514 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +00001515 bp_id_arg.arg_repetition = eArgRepeatPlain;
Caroline Ticefb355112010-10-01 17:46:38 +00001516
1517 // Create the second variant for the first (and only) argument for this command.
1518 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +00001519 bp_id_range_arg.arg_repetition = eArgRepeatPlain;
Caroline Ticefb355112010-10-01 17:46:38 +00001520
1521 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1522 // Push both variants into the entry for the first argument for this command.
1523 arg.push_back (bp_id_arg);
1524 arg.push_back (bp_id_range_arg);
1525
1526 // Add the entry for the first argument for this command to the object's arguments vector.
1527 m_arguments.push_back (arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001528}
1529
Jim Ingham10622a22010-06-18 00:58:52 +00001530CommandObjectBreakpointModify::~CommandObjectBreakpointModify ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001531{
1532}
1533
1534Options *
Jim Ingham10622a22010-06-18 00:58:52 +00001535CommandObjectBreakpointModify::GetOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001536{
1537 return &m_options;
1538}
1539
1540bool
Jim Ingham10622a22010-06-18 00:58:52 +00001541CommandObjectBreakpointModify::Execute
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001542(
1543 Args& command,
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001544 CommandReturnObject &result
1545)
1546{
Greg Clayton238c0a12010-09-18 01:14:36 +00001547 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001548 if (target == NULL)
1549 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001550 result.AppendError ("Invalid target. No existing target or breakpoints.");
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001551 result.SetStatus (eReturnStatusFailed);
1552 return false;
1553 }
1554
1555 Mutex::Locker locker;
1556 target->GetBreakpointList().GetListMutex(locker);
1557
1558 BreakpointIDList valid_bp_ids;
1559
1560 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1561
1562 if (result.Succeeded())
1563 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001564 const size_t count = valid_bp_ids.GetSize();
1565 for (size_t i = 0; i < count; ++i)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001566 {
1567 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1568
1569 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1570 {
1571 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1572 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1573 {
1574 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
1575 if (location)
1576 {
Jim Ingham9a7b2912010-12-03 23:04:19 +00001577 if (m_options.m_thread_id_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001578 location->SetThreadID (m_options.m_thread_id);
1579
Jim Ingham9a7b2912010-12-03 23:04:19 +00001580 if (m_options.m_thread_index_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001581 location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1582
Jim Inghamd4571222010-06-19 04:35:20 +00001583 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001584 location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1585
Jim Inghamd4571222010-06-19 04:35:20 +00001586 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001587 location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1588
Greg Clayton54e7afa2010-07-09 20:39:50 +00001589 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001590 location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001591
1592 if (m_options.m_enable_passed)
1593 location->SetEnabled (m_options.m_enable_value);
Jim Inghamd1686902010-10-14 23:45:03 +00001594
1595 if (m_options.m_condition_passed)
1596 location->SetCondition (m_options.m_condition.c_str());
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001597 }
1598 }
1599 else
1600 {
Jim Ingham9a7b2912010-12-03 23:04:19 +00001601 if (m_options.m_thread_id_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001602 bp->SetThreadID (m_options.m_thread_id);
1603
Jim Ingham9a7b2912010-12-03 23:04:19 +00001604 if (m_options.m_thread_index_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001605 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1606
Jim Inghamd4571222010-06-19 04:35:20 +00001607 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001608 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1609
Jim Inghamd4571222010-06-19 04:35:20 +00001610 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001611 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1612
Greg Clayton54e7afa2010-07-09 20:39:50 +00001613 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001614 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001615
1616 if (m_options.m_enable_passed)
1617 bp->SetEnabled (m_options.m_enable_value);
Jim Inghamd1686902010-10-14 23:45:03 +00001618
1619 if (m_options.m_condition_passed)
1620 bp->SetCondition (m_options.m_condition.c_str());
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001621 }
1622 }
1623 }
1624 }
1625
1626 return result.Succeeded();
1627}
1628
1629