blob: 2e894edae1120f37125eb51a3c6a1fd1868baf16 [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
Greg Claytonf15996e2011-04-07 22:46:35 +000050CommandObjectBreakpointSet::CommandOptions::CommandOptions(CommandInterpreter &interpreter) :
51 Options (interpreter),
Chris Lattner24943d22010-06-08 16:52:24 +000052 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
Greg Clayton143fcc32011-04-13 00:18:08 +0000137CommandObjectBreakpointSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Chris Lattner24943d22010-06-08 16:52:24 +0000138{
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
Greg Clayton143fcc32011-04-13 00:18:08 +0000236CommandObjectBreakpointSet::CommandOptions::OptionParsingStarting ()
Chris Lattner24943d22010-06-08 16:52:24 +0000237{
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.",
Greg Claytonf15996e2011-04-07 22:46:35 +0000262 "breakpoint set <cmd-options>"),
263 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000264{
265}
266
267CommandObjectBreakpointSet::~CommandObjectBreakpointSet ()
268{
269}
270
271Options *
272CommandObjectBreakpointSet::GetOptions ()
273{
274 return &m_options;
275}
276
277bool
278CommandObjectBreakpointSet::Execute
279(
280 Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000281 CommandReturnObject &result
282)
283{
Greg Clayton238c0a12010-09-18 01:14:36 +0000284 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000285 if (target == NULL)
286 {
Greg Claytone1f50b92011-05-03 22:09:39 +0000287 result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command).");
Chris Lattner24943d22010-06-08 16:52:24 +0000288 result.SetStatus (eReturnStatusFailed);
289 return false;
290 }
291
292 // The following are the various types of breakpoints that could be set:
293 // 1). -f -l -p [-s -g] (setting breakpoint by source location)
294 // 2). -a [-s -g] (setting breakpoint by address)
295 // 3). -n [-s -g] (setting breakpoint by function name)
296 // 4). -r [-s -g] (setting breakpoint by function name regular expression)
297
298 BreakpointSetType break_type = eSetTypeInvalid;
299
300 if (m_options.m_line_num != 0)
301 break_type = eSetTypeFileAndLine;
302 else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
303 break_type = eSetTypeAddress;
304 else if (!m_options.m_func_name.empty())
305 break_type = eSetTypeFunctionName;
306 else if (!m_options.m_func_regexp.empty())
307 break_type = eSetTypeFunctionRegexp;
308
Chris Lattner24943d22010-06-08 16:52:24 +0000309 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 Claytonb72d0f02011-04-12 05:54:46 +0000324 StackFrame *cur_frame = m_interpreter.GetExecutionContext().frame;
Greg Clayton887aa282010-10-11 01:05:37 +0000325 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 Clayton52c8b6e2011-04-19 04:19:37 +0000339 const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
340 if (sc.line_entry.file)
Greg Clayton887aa282010-10-11 01:05:37 +0000341 {
Greg Clayton52c8b6e2011-04-19 04:19:37 +0000342 file = sc.line_entry.file;
Greg Clayton887aa282010-10-11 01:05:37 +0000343 }
344 else
345 {
346 result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame.");
347 result.SetStatus (eReturnStatusFailed);
348 break;
349 }
Chris Lattner24943d22010-06-08 16:52:24 +0000350 }
351 }
Greg Clayton887aa282010-10-11 01:05:37 +0000352 else
353 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000354 file.SetFile(m_options.m_filename.c_str(), false);
Greg Clayton887aa282010-10-11 01:05:37 +0000355 }
356
357 if (use_module)
358 {
359 for (int i = 0; i < num_modules; ++i)
360 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000361 module_spec.SetFile(m_options.m_modules[i].c_str(), false);
362 bp = target->CreateBreakpoint (&module_spec,
Greg Clayton887aa282010-10-11 01:05:37 +0000363 file,
364 m_options.m_line_num,
Greg Clayton2dfe4c62010-11-02 03:02:38 +0000365 m_options.m_check_inlines).get();
Greg Clayton887aa282010-10-11 01:05:37 +0000366 if (bp)
367 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000368 Stream &output_stream = result.GetOutputStream();
369 result.AppendMessage ("Breakpoint created: ");
Greg Clayton887aa282010-10-11 01:05:37 +0000370 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
371 output_stream.EOL();
Caroline Ticecf2f3052010-10-28 16:28:56 +0000372 if (bp->GetNumLocations() == 0)
373 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual"
374 " locations.\n");
Greg Clayton887aa282010-10-11 01:05:37 +0000375 result.SetStatus (eReturnStatusSuccessFinishResult);
376 }
377 else
378 {
379 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
380 m_options.m_modules[i].c_str());
381 result.SetStatus (eReturnStatusFailed);
382 }
383 }
384 }
385 else
386 bp = target->CreateBreakpoint (NULL,
387 file,
388 m_options.m_line_num,
Greg Clayton2dfe4c62010-11-02 03:02:38 +0000389 m_options.m_check_inlines).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000390 }
Greg Clayton887aa282010-10-11 01:05:37 +0000391 break;
392
Chris Lattner24943d22010-06-08 16:52:24 +0000393 case eSetTypeAddress: // Breakpoint by address
394 bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
395 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000396
Chris Lattner24943d22010-06-08 16:52:24 +0000397 case eSetTypeFunctionName: // Breakpoint by function name
Chris Lattner24943d22010-06-08 16:52:24 +0000398 {
Greg Clayton12bec712010-06-28 21:30:43 +0000399 uint32_t name_type_mask = m_options.m_func_name_type_mask;
400
401 if (name_type_mask == 0)
Greg Clayton48fbdf72010-10-12 04:29:14 +0000402 name_type_mask = eFunctionNameTypeAuto;
403
Greg Clayton12bec712010-06-28 21:30:43 +0000404 if (use_module)
405 {
406 for (int i = 0; i < num_modules; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000407 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000408 module_spec.SetFile(m_options.m_modules[i].c_str(), false);
409 bp = target->CreateBreakpoint (&module_spec,
410 m_options.m_func_name.c_str(),
411 name_type_mask,
412 Breakpoint::Exact).get();
Greg Clayton12bec712010-06-28 21:30:43 +0000413 if (bp)
414 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000415 Stream &output_stream = result.GetOutputStream();
Greg Clayton12bec712010-06-28 21:30:43 +0000416 output_stream.Printf ("Breakpoint created: ");
417 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
418 output_stream.EOL();
Caroline Ticecf2f3052010-10-28 16:28:56 +0000419 if (bp->GetNumLocations() == 0)
420 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual"
421 " locations.\n");
Greg Clayton12bec712010-06-28 21:30:43 +0000422 result.SetStatus (eReturnStatusSuccessFinishResult);
423 }
424 else
425 {
426 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
427 m_options.m_modules[i].c_str());
428 result.SetStatus (eReturnStatusFailed);
429 }
Chris Lattner24943d22010-06-08 16:52:24 +0000430 }
431 }
Greg Clayton12bec712010-06-28 21:30:43 +0000432 else
433 bp = target->CreateBreakpoint (NULL, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000434 }
Chris Lattner24943d22010-06-08 16:52:24 +0000435 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000436
Chris Lattner24943d22010-06-08 16:52:24 +0000437 case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
438 {
439 RegularExpression regexp(m_options.m_func_regexp.c_str());
440 if (use_module)
441 {
442 for (int i = 0; i < num_modules; ++i)
443 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000444 module_spec.SetFile(m_options.m_modules[i].c_str(), false);
445 bp = target->CreateBreakpoint (&module_spec, regexp).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000446 if (bp)
447 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000448 Stream &output_stream = result.GetOutputStream();
Chris Lattner24943d22010-06-08 16:52:24 +0000449 output_stream.Printf ("Breakpoint created: ");
450 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
451 output_stream.EOL();
Caroline Ticecf2f3052010-10-28 16:28:56 +0000452 if (bp->GetNumLocations() == 0)
453 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual"
454 " locations.\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000455 result.SetStatus (eReturnStatusSuccessFinishResult);
456 }
457 else
458 {
459 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
460 m_options.m_modules[i].c_str());
461 result.SetStatus (eReturnStatusFailed);
462 }
463 }
464 }
465 else
466 bp = target->CreateBreakpoint (NULL, regexp).get();
467 }
468 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000469
Chris Lattner24943d22010-06-08 16:52:24 +0000470 default:
471 break;
472 }
473
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000474 // Now set the various options that were passed in:
475 if (bp)
476 {
477 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
478 bp->SetThreadID (m_options.m_thread_id);
479
Greg Clayton54e7afa2010-07-09 20:39:50 +0000480 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000481 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
482
483 if (!m_options.m_thread_name.empty())
484 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
485
486 if (!m_options.m_queue_name.empty())
487 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
488
Greg Clayton54e7afa2010-07-09 20:39:50 +0000489 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000490 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
491 }
492
Chris Lattner24943d22010-06-08 16:52:24 +0000493 if (bp && !use_module)
494 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000495 Stream &output_stream = result.GetOutputStream();
Chris Lattner24943d22010-06-08 16:52:24 +0000496 output_stream.Printf ("Breakpoint created: ");
497 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
498 output_stream.EOL();
Caroline Ticecf2f3052010-10-28 16:28:56 +0000499 if (bp->GetNumLocations() == 0)
500 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000501 result.SetStatus (eReturnStatusSuccessFinishResult);
502 }
503 else if (!bp)
504 {
505 result.AppendError ("Breakpoint creation failed: No breakpoint created.");
506 result.SetStatus (eReturnStatusFailed);
507 }
508
509 return result.Succeeded();
510}
511
Chris Lattner24943d22010-06-08 16:52:24 +0000512//-------------------------------------------------------------------------
513// CommandObjectMultiwordBreakpoint
514//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000515#pragma mark MultiwordBreakpoint
Chris Lattner24943d22010-06-08 16:52:24 +0000516
Greg Clayton63094e02010-06-23 01:19:29 +0000517CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000518 CommandObjectMultiword (interpreter,
519 "breakpoint",
Jim Ingham7224aab2011-05-26 20:39:01 +0000520 "A set of commands for operating on breakpoints. Also see _regexp-break.",
Greg Clayton238c0a12010-09-18 01:14:36 +0000521 "breakpoint <command> [<command-options>]")
Chris Lattner24943d22010-06-08 16:52:24 +0000522{
523 bool status;
524
Greg Clayton238c0a12010-09-18 01:14:36 +0000525 CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000526 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
527 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
Johnny Chena62ad7c2010-10-28 17:27:46 +0000528 CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
529 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000530 CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +0000531 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000532 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +0000533
Johnny Chena62ad7c2010-10-28 17:27:46 +0000534 list_command_object->SetCommandName ("breakpoint list");
Chris Lattner24943d22010-06-08 16:52:24 +0000535 enable_command_object->SetCommandName("breakpoint enable");
536 disable_command_object->SetCommandName("breakpoint disable");
Johnny Chena62ad7c2010-10-28 17:27:46 +0000537 clear_command_object->SetCommandName("breakpoint clear");
538 delete_command_object->SetCommandName("breakpoint delete");
Jim Ingham10622a22010-06-18 00:58:52 +0000539 set_command_object->SetCommandName("breakpoint set");
Johnny Chena62ad7c2010-10-28 17:27:46 +0000540 command_command_object->SetCommandName ("breakpoint command");
541 modify_command_object->SetCommandName ("breakpoint modify");
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);
Johnny Chena62ad7c2010-10-28 17:27:46 +0000546 status = LoadSubCommand ("clear", clear_command_object);
Greg Clayton238c0a12010-09-18 01:14:36 +0000547 status = LoadSubCommand ("delete", delete_command_object);
548 status = LoadSubCommand ("set", set_command_object);
549 status = LoadSubCommand ("command", command_command_object);
550 status = LoadSubCommand ("modify", modify_command_object);
Chris Lattner24943d22010-06-08 16:52:24 +0000551}
552
553CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
554{
555}
556
557void
558CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result,
559 BreakpointIDList *valid_ids)
560{
561 // args can be strings representing 1). integers (for breakpoint ids)
562 // 2). the full breakpoint & location canonical representation
563 // 3). the word "to" or a hyphen, representing a range (in which case there
564 // had *better* be an entry both before & after of one of the first two types.
Jim Inghamd1686902010-10-14 23:45:03 +0000565 // If args is empty, we will use the last created breakpoint (if there is one.)
Chris Lattner24943d22010-06-08 16:52:24 +0000566
567 Args temp_args;
568
Jim Inghamd1686902010-10-14 23:45:03 +0000569 if (args.GetArgumentCount() == 0)
570 {
571 if (target->GetLastCreatedBreakpoint() != NULL)
572 {
573 valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
574 result.SetStatus (eReturnStatusSuccessFinishNoResult);
575 }
576 else
577 {
578 result.AppendError("No breakpoint specified and no last created breakpoint.");
579 result.SetStatus (eReturnStatusFailed);
580 }
581 return;
582 }
583
Chris Lattner24943d22010-06-08 16:52:24 +0000584 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
585 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
586 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
587
588 BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
589
590 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
591
Greg Clayton54e7afa2010-07-09 20:39:50 +0000592 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
Chris Lattner24943d22010-06-08 16:52:24 +0000593
594 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
595 // and put into valid_ids.
596
597 if (result.Succeeded())
598 {
599 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
600 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
601
Greg Clayton54e7afa2010-07-09 20:39:50 +0000602 const size_t count = valid_ids->GetSize();
603 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000604 {
605 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
606 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
607 if (breakpoint != NULL)
608 {
609 int num_locations = breakpoint->GetNumLocations();
610 if (cur_bp_id.GetLocationID() > num_locations)
611 {
612 StreamString id_str;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000613 BreakpointID::GetCanonicalReference (&id_str,
614 cur_bp_id.GetBreakpointID(),
615 cur_bp_id.GetLocationID());
616 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000617 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
618 id_str.GetData());
619 result.SetStatus (eReturnStatusFailed);
620 }
621 }
622 else
623 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000624 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000625 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
626 result.SetStatus (eReturnStatusFailed);
627 }
628 }
629 }
630}
631
632//-------------------------------------------------------------------------
633// CommandObjectBreakpointList::Options
634//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000635#pragma mark List::CommandOptions
Chris Lattner24943d22010-06-08 16:52:24 +0000636
Greg Claytonf15996e2011-04-07 22:46:35 +0000637CommandObjectBreakpointList::CommandOptions::CommandOptions(CommandInterpreter &interpreter) :
638 Options (interpreter),
Caroline Tice41950cc2011-02-04 22:59:41 +0000639 m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions
Chris Lattner24943d22010-06-08 16:52:24 +0000640{
Chris Lattner24943d22010-06-08 16:52:24 +0000641}
642
643CommandObjectBreakpointList::CommandOptions::~CommandOptions ()
644{
645}
646
Greg Claytonb3448432011-03-24 21:19:54 +0000647OptionDefinition
Chris Lattner24943d22010-06-08 16:52:24 +0000648CommandObjectBreakpointList::CommandOptions::g_option_table[] =
649{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000650 { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone,
Jim Ingham34e9a982010-06-15 18:47:14 +0000651 "Show debugger internal breakpoints" },
652
Caroline Tice4d6675c2010-10-01 19:59:14 +0000653 { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000654 "Give a brief description of the breakpoint (no location info)."},
655
656 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
657 // But I need to see it for now, and don't want to wait.
Caroline Tice4d6675c2010-10-01 19:59:14 +0000658 { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000659 "Give a full description of the breakpoint and its locations."},
Chris Lattner24943d22010-06-08 16:52:24 +0000660
Caroline Tice4d6675c2010-10-01 19:59:14 +0000661 { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000662 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
Chris Lattner24943d22010-06-08 16:52:24 +0000663
Caroline Tice4d6675c2010-10-01 19:59:14 +0000664 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000665};
666
Greg Claytonb3448432011-03-24 21:19:54 +0000667const OptionDefinition*
Chris Lattner24943d22010-06-08 16:52:24 +0000668CommandObjectBreakpointList::CommandOptions::GetDefinitions ()
669{
670 return g_option_table;
671}
672
673Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000674CommandObjectBreakpointList::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Chris Lattner24943d22010-06-08 16:52:24 +0000675{
676 Error error;
677 char short_option = (char) m_getopt_table[option_idx].val;
678
679 switch (short_option)
680 {
681 case 'b':
682 m_level = lldb::eDescriptionLevelBrief;
683 break;
684 case 'f':
685 m_level = lldb::eDescriptionLevelFull;
686 break;
687 case 'v':
688 m_level = lldb::eDescriptionLevelVerbose;
689 break;
690 case 'i':
691 m_internal = true;
692 break;
693 default:
694 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
695 break;
696 }
697
698 return error;
699}
700
701void
Greg Clayton143fcc32011-04-13 00:18:08 +0000702CommandObjectBreakpointList::CommandOptions::OptionParsingStarting ()
Chris Lattner24943d22010-06-08 16:52:24 +0000703{
Jim Inghamdc259052011-05-17 01:21:41 +0000704 m_level = lldb::eDescriptionLevelFull;
Chris Lattner24943d22010-06-08 16:52:24 +0000705 m_internal = false;
706}
707
708//-------------------------------------------------------------------------
709// CommandObjectBreakpointList
710//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000711#pragma mark List
Chris Lattner24943d22010-06-08 16:52:24 +0000712
Greg Clayton238c0a12010-09-18 01:14:36 +0000713CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) :
714 CommandObject (interpreter,
715 "breakpoint list",
716 "List some or all breakpoints at configurable levels of detail.",
Greg Claytonf15996e2011-04-07 22:46:35 +0000717 NULL),
718 m_options (interpreter)
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
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000772 Stream &output_stream = result.GetOutputStream();
Chris Lattner24943d22010-06-08 16:52:24 +0000773
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//-------------------------------------------------------------------------
Johnny Chena62ad7c2010-10-28 17:27:46 +00001042// CommandObjectBreakpointClear::CommandOptions
1043//-------------------------------------------------------------------------
1044#pragma mark Clear::CommandOptions
1045
Greg Claytonf15996e2011-04-07 22:46:35 +00001046CommandObjectBreakpointClear::CommandOptions::CommandOptions(CommandInterpreter &interpreter) :
1047 Options (interpreter),
Johnny Chena62ad7c2010-10-28 17:27:46 +00001048 m_filename (),
1049 m_line_num (0)
1050{
1051}
1052
1053CommandObjectBreakpointClear::CommandOptions::~CommandOptions ()
1054{
1055}
1056
Greg Claytonb3448432011-03-24 21:19:54 +00001057OptionDefinition
Johnny Chena62ad7c2010-10-28 17:27:46 +00001058CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
1059{
1060 { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
1061 "Specify the breakpoint by source location in this particular file."},
1062
1063 { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
1064 "Specify the breakpoint by source location at this particular line."},
1065
1066 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1067};
1068
Greg Claytonb3448432011-03-24 21:19:54 +00001069const OptionDefinition*
Johnny Chena62ad7c2010-10-28 17:27:46 +00001070CommandObjectBreakpointClear::CommandOptions::GetDefinitions ()
1071{
1072 return g_option_table;
1073}
1074
1075Error
Greg Clayton143fcc32011-04-13 00:18:08 +00001076CommandObjectBreakpointClear::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Johnny Chena62ad7c2010-10-28 17:27:46 +00001077{
1078 Error error;
1079 char short_option = (char) m_getopt_table[option_idx].val;
1080
1081 switch (short_option)
1082 {
1083 case 'f':
Greg Clayton889fbd02011-03-26 19:14:58 +00001084 m_filename.assign (option_arg);
Johnny Chena62ad7c2010-10-28 17:27:46 +00001085 break;
1086
1087 case 'l':
1088 m_line_num = Args::StringToUInt32 (option_arg, 0);
1089 break;
1090
1091 default:
1092 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1093 break;
1094 }
1095
1096 return error;
1097}
1098
1099void
Greg Clayton143fcc32011-04-13 00:18:08 +00001100CommandObjectBreakpointClear::CommandOptions::OptionParsingStarting ()
Johnny Chena62ad7c2010-10-28 17:27:46 +00001101{
Johnny Chena62ad7c2010-10-28 17:27:46 +00001102 m_filename.clear();
1103 m_line_num = 0;
1104}
1105
1106//-------------------------------------------------------------------------
1107// CommandObjectBreakpointClear
1108//-------------------------------------------------------------------------
1109#pragma mark Clear
1110
1111CommandObjectBreakpointClear::CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
1112 CommandObject (interpreter,
1113 "breakpoint clear",
1114 "Clears a breakpoint or set of breakpoints in the executable.",
Greg Claytonf15996e2011-04-07 22:46:35 +00001115 "breakpoint clear <cmd-options>"),
1116 m_options (interpreter)
Johnny Chena62ad7c2010-10-28 17:27:46 +00001117{
1118}
1119
1120CommandObjectBreakpointClear::~CommandObjectBreakpointClear ()
1121{
1122}
1123
1124Options *
1125CommandObjectBreakpointClear::GetOptions ()
1126{
1127 return &m_options;
1128}
1129
1130bool
1131CommandObjectBreakpointClear::Execute
1132(
1133 Args& command,
1134 CommandReturnObject &result
1135)
1136{
1137 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1138 if (target == NULL)
1139 {
1140 result.AppendError ("Invalid target. No existing target or breakpoints.");
1141 result.SetStatus (eReturnStatusFailed);
1142 return false;
1143 }
1144
1145 // The following are the various types of breakpoints that could be cleared:
1146 // 1). -f -l (clearing breakpoint by source location)
1147
1148 BreakpointClearType break_type = eClearTypeInvalid;
1149
1150 if (m_options.m_line_num != 0)
1151 break_type = eClearTypeFileAndLine;
1152
1153 Mutex::Locker locker;
1154 target->GetBreakpointList().GetListMutex(locker);
1155
1156 BreakpointList &breakpoints = target->GetBreakpointList();
1157 size_t num_breakpoints = breakpoints.GetSize();
1158
1159 // Early return if there's no breakpoint at all.
1160 if (num_breakpoints == 0)
1161 {
1162 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1163 result.SetStatus (eReturnStatusFailed);
1164 return result.Succeeded();
1165 }
1166
1167 // Find matching breakpoints and delete them.
1168
1169 // First create a copy of all the IDs.
1170 std::vector<break_id_t> BreakIDs;
1171 for (size_t i = 0; i < num_breakpoints; ++i)
1172 BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID());
1173
1174 int num_cleared = 0;
1175 StreamString ss;
1176 switch (break_type)
1177 {
1178 case eClearTypeFileAndLine: // Breakpoint by source position
1179 {
1180 const ConstString filename(m_options.m_filename.c_str());
1181 BreakpointLocationCollection loc_coll;
1182
1183 for (size_t i = 0; i < num_breakpoints; ++i)
1184 {
1185 Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
1186
1187 if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
1188 {
1189 // If the collection size is 0, it's a full match and we can just remove the breakpoint.
1190 if (loc_coll.GetSize() == 0)
1191 {
1192 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
1193 ss.EOL();
1194 target->RemoveBreakpointByID (bp->GetID());
1195 ++num_cleared;
1196 }
1197 }
1198 }
1199 }
1200 break;
1201
1202 default:
1203 break;
1204 }
1205
1206 if (num_cleared > 0)
1207 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +00001208 Stream &output_stream = result.GetOutputStream();
Johnny Chena62ad7c2010-10-28 17:27:46 +00001209 output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
1210 output_stream << ss.GetData();
1211 output_stream.EOL();
1212 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1213 }
1214 else
1215 {
1216 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1217 result.SetStatus (eReturnStatusFailed);
1218 }
1219
1220 return result.Succeeded();
1221}
1222
1223//-------------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +00001224// CommandObjectBreakpointDelete
1225//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001226#pragma mark Delete
Chris Lattner24943d22010-06-08 16:52:24 +00001227
Greg Clayton238c0a12010-09-18 01:14:36 +00001228CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) :
1229 CommandObject (interpreter,
1230 "breakpoint delete",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001231 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
Caroline Ticefb355112010-10-01 17:46:38 +00001232 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +00001233{
Caroline Ticefb355112010-10-01 17:46:38 +00001234 CommandArgumentEntry arg;
1235 CommandArgumentData bp_id_arg;
1236 CommandArgumentData bp_id_range_arg;
1237
1238 // Create the first variant for the first (and only) argument for this command.
1239 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +00001240 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +00001241
1242 // Create the second variant for the first (and only) argument for this command.
1243 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +00001244 bp_id_range_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +00001245
1246 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1247 // Push both variants into the entry for the first argument for this command.
1248 arg.push_back (bp_id_arg);
1249 arg.push_back (bp_id_range_arg);
1250
1251 // Add the entry for the first argument for this command to the object's arguments vector.
1252 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +00001253}
1254
1255
1256CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete ()
1257{
1258}
1259
1260bool
Greg Clayton63094e02010-06-23 01:19:29 +00001261CommandObjectBreakpointDelete::Execute
1262(
Greg Clayton63094e02010-06-23 01:19:29 +00001263 Args& args,
1264 CommandReturnObject &result
1265)
Chris Lattner24943d22010-06-08 16:52:24 +00001266{
Greg Clayton238c0a12010-09-18 01:14:36 +00001267 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001268 if (target == NULL)
1269 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001270 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +00001271 result.SetStatus (eReturnStatusFailed);
1272 return false;
1273 }
1274
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001275 Mutex::Locker locker;
1276 target->GetBreakpointList().GetListMutex(locker);
1277
Chris Lattner24943d22010-06-08 16:52:24 +00001278 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001279
Chris Lattner24943d22010-06-08 16:52:24 +00001280 size_t num_breakpoints = breakpoints.GetSize();
1281
1282 if (num_breakpoints == 0)
1283 {
1284 result.AppendError ("No breakpoints exist to be deleted.");
1285 result.SetStatus (eReturnStatusFailed);
1286 return false;
1287 }
1288
1289 if (args.GetArgumentCount() == 0)
1290 {
Jim Inghamd1686902010-10-14 23:45:03 +00001291 if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
Chris Lattner24943d22010-06-08 16:52:24 +00001292 {
Jim Inghamd1686902010-10-14 23:45:03 +00001293 result.AppendMessage("Operation cancelled...");
Chris Lattner24943d22010-06-08 16:52:24 +00001294 }
Jim Inghamd1686902010-10-14 23:45:03 +00001295 else
1296 {
1297 target->RemoveAllBreakpoints ();
1298 result.AppendMessageWithFormat ("All breakpoints removed. (%d breakpoints)\n", num_breakpoints);
1299 }
Chris Lattner24943d22010-06-08 16:52:24 +00001300 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1301 }
1302 else
1303 {
1304 // Particular breakpoint selected; disable that breakpoint.
1305 BreakpointIDList valid_bp_ids;
1306 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
1307
1308 if (result.Succeeded())
1309 {
1310 int delete_count = 0;
1311 int disable_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001312 const size_t count = valid_bp_ids.GetSize();
1313 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +00001314 {
1315 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1316
1317 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1318 {
1319 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1320 {
1321 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1322 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1323 // It makes no sense to try to delete individual locations, so we disable them instead.
1324 if (location)
1325 {
1326 location->SetEnabled (false);
1327 ++disable_count;
1328 }
1329 }
1330 else
1331 {
1332 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1333 ++delete_count;
1334 }
1335 }
1336 }
1337 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1338 delete_count, disable_count);
1339 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1340 }
1341 }
1342 return result.Succeeded();
1343}
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001344
1345//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001346// CommandObjectBreakpointModify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001347//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001348#pragma mark Modify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001349
Greg Claytonf15996e2011-04-07 22:46:35 +00001350CommandObjectBreakpointModify::CommandOptions::CommandOptions(CommandInterpreter &interpreter) :
1351 Options (interpreter),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001352 m_ignore_count (0),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001353 m_thread_id(LLDB_INVALID_THREAD_ID),
Jim Ingham9a7b2912010-12-03 23:04:19 +00001354 m_thread_id_passed(false),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001355 m_thread_index (UINT32_MAX),
Jim Ingham9a7b2912010-12-03 23:04:19 +00001356 m_thread_index_passed(false),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001357 m_thread_name(),
1358 m_queue_name(),
Jim Inghamd1686902010-10-14 23:45:03 +00001359 m_condition (),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001360 m_enable_passed (false),
1361 m_enable_value (false),
1362 m_name_passed (false),
Jim Inghamd1686902010-10-14 23:45:03 +00001363 m_queue_passed (false),
1364 m_condition_passed (false)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001365{
1366}
1367
Jim Ingham10622a22010-06-18 00:58:52 +00001368CommandObjectBreakpointModify::CommandOptions::~CommandOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001369{
1370}
1371
Greg Claytonb3448432011-03-24 21:19:54 +00001372OptionDefinition
Jim Ingham10622a22010-06-18 00:58:52 +00001373CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001374{
Caroline Tice4d6675c2010-10-01 19:59:14 +00001375{ LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, NULL, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." },
1376{ 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."},
1377{ 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."},
1378{ 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."},
1379{ 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 +00001380{ 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 +00001381{ LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, eArgTypeNone, "Enable the breakpoint."},
1382{ LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, eArgTypeNone, "Disable the breakpoint."},
Jim Inghamd1686902010-10-14 23:45:03 +00001383{ 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001384};
1385
Greg Claytonb3448432011-03-24 21:19:54 +00001386const OptionDefinition*
Jim Ingham10622a22010-06-18 00:58:52 +00001387CommandObjectBreakpointModify::CommandOptions::GetDefinitions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001388{
1389 return g_option_table;
1390}
1391
1392Error
Greg Clayton143fcc32011-04-13 00:18:08 +00001393CommandObjectBreakpointModify::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001394{
1395 Error error;
1396 char short_option = (char) m_getopt_table[option_idx].val;
1397
1398 switch (short_option)
1399 {
Jim Inghamd1686902010-10-14 23:45:03 +00001400 case 'c':
1401 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001402 m_condition.assign (option_arg);
Jim Inghamd1686902010-10-14 23:45:03 +00001403 else
1404 m_condition.clear();
1405 m_condition_passed = true;
1406 break;
Jim Ingham10622a22010-06-18 00:58:52 +00001407 case 'd':
1408 m_enable_passed = true;
1409 m_enable_value = false;
1410 break;
1411 case 'e':
1412 m_enable_passed = true;
1413 m_enable_value = true;
1414 break;
Greg Claytonfe424a92010-09-18 03:37:20 +00001415 case 'i':
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001416 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001417 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Greg Clayton54e7afa2010-07-09 20:39:50 +00001418 if (m_ignore_count == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001419 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001420 }
Jim Ingham10622a22010-06-18 00:58:52 +00001421 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001422 case 't' :
1423 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001424 if (option_arg[0] == '\0')
Jim Ingham9a7b2912010-12-03 23:04:19 +00001425 {
1426 m_thread_id = LLDB_INVALID_THREAD_ID;
1427 m_thread_id_passed = true;
1428 }
1429 else
1430 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001431 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001432 if (m_thread_id == LLDB_INVALID_THREAD_ID)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001433 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", option_arg);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001434 else
1435 m_thread_id_passed = true;
1436 }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001437 }
1438 break;
1439 case 'T':
Jim Inghamd4571222010-06-19 04:35:20 +00001440 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001441 m_thread_name.assign (option_arg);
Jim Inghamd4571222010-06-19 04:35:20 +00001442 else
1443 m_thread_name.clear();
1444 m_name_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001445 break;
1446 case 'q':
Jim Inghamd4571222010-06-19 04:35:20 +00001447 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001448 m_queue_name.assign (option_arg);
Jim Inghamd4571222010-06-19 04:35:20 +00001449 else
1450 m_queue_name.clear();
1451 m_queue_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001452 break;
1453 case 'x':
1454 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001455 if (option_arg[0] == '\n')
Jim Ingham9a7b2912010-12-03 23:04:19 +00001456 {
1457 m_thread_index = UINT32_MAX;
1458 m_thread_index_passed = true;
1459 }
1460 else
1461 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001462 m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001463 if (m_thread_id == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001464 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", option_arg);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001465 else
1466 m_thread_index_passed = true;
1467 }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001468 }
1469 break;
1470 default:
1471 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1472 break;
1473 }
1474
1475 return error;
1476}
1477
1478void
Greg Clayton143fcc32011-04-13 00:18:08 +00001479CommandObjectBreakpointModify::CommandOptions::OptionParsingStarting ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001480{
Greg Clayton54e7afa2010-07-09 20:39:50 +00001481 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001482 m_thread_id = LLDB_INVALID_THREAD_ID;
Jim Ingham9a7b2912010-12-03 23:04:19 +00001483 m_thread_id_passed = false;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001484 m_thread_index = UINT32_MAX;
Jim Ingham9a7b2912010-12-03 23:04:19 +00001485 m_thread_index_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001486 m_thread_name.clear();
1487 m_queue_name.clear();
Jim Inghamd1686902010-10-14 23:45:03 +00001488 m_condition.clear();
Jim Ingham10622a22010-06-18 00:58:52 +00001489 m_enable_passed = false;
Jim Inghamd4571222010-06-19 04:35:20 +00001490 m_queue_passed = false;
1491 m_name_passed = false;
Jim Inghamd1686902010-10-14 23:45:03 +00001492 m_condition_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001493}
1494
1495//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001496// CommandObjectBreakpointModify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001497//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001498#pragma mark Modify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001499
Greg Clayton238c0a12010-09-18 01:14:36 +00001500CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
1501 CommandObject (interpreter,
1502 "breakpoint modify",
Jim Ingham19ac0bd2010-12-03 22:37:19 +00001503 "Modify the options on a breakpoint or set of breakpoints in the executable. "
Jim Ingham9a7b2912010-12-03 23:04:19 +00001504 "If no breakpoint is specified, acts on the last created breakpoint. "
1505 "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
Greg Claytonf15996e2011-04-07 22:46:35 +00001506 NULL),
1507 m_options (interpreter)
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