blob: 88a130d3982e98b248679f3b7f92ae85931baa05 [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 {
Jim Inghamfdf24ef2011-09-08 22:13:49 +0000324 uint32_t default_line;
325 // First use the Source Manager's default file.
326 // Then use the current stack frame's file.
327 if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line))
Chris Lattner24943d22010-06-08 16:52:24 +0000328 {
Jim Inghamfdf24ef2011-09-08 22:13:49 +0000329 StackFrame *cur_frame = m_interpreter.GetExecutionContext().frame;
330 if (cur_frame == NULL)
Greg Clayton887aa282010-10-11 01:05:37 +0000331 {
Jim Inghamfdf24ef2011-09-08 22:13:49 +0000332 result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame.");
333 result.SetStatus (eReturnStatusFailed);
334 break;
335 }
336 else if (!cur_frame->HasDebugInformation())
337 {
338 result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info.");
339 result.SetStatus (eReturnStatusFailed);
340 break;
Greg Clayton887aa282010-10-11 01:05:37 +0000341 }
342 else
343 {
Jim Inghamfdf24ef2011-09-08 22:13:49 +0000344 const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
345 if (sc.line_entry.file)
346 {
347 file = sc.line_entry.file;
348 }
349 else
350 {
351 result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame.");
352 result.SetStatus (eReturnStatusFailed);
353 break;
354 }
Greg Clayton887aa282010-10-11 01:05:37 +0000355 }
Chris Lattner24943d22010-06-08 16:52:24 +0000356 }
357 }
Greg Clayton887aa282010-10-11 01:05:37 +0000358 else
359 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000360 file.SetFile(m_options.m_filename.c_str(), false);
Greg Clayton887aa282010-10-11 01:05:37 +0000361 }
362
363 if (use_module)
364 {
365 for (int i = 0; i < num_modules; ++i)
366 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000367 module_spec.SetFile(m_options.m_modules[i].c_str(), false);
368 bp = target->CreateBreakpoint (&module_spec,
Greg Clayton887aa282010-10-11 01:05:37 +0000369 file,
370 m_options.m_line_num,
Greg Clayton2dfe4c62010-11-02 03:02:38 +0000371 m_options.m_check_inlines).get();
Greg Clayton887aa282010-10-11 01:05:37 +0000372 if (bp)
373 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000374 Stream &output_stream = result.GetOutputStream();
375 result.AppendMessage ("Breakpoint created: ");
Greg Clayton887aa282010-10-11 01:05:37 +0000376 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
377 output_stream.EOL();
Caroline Ticecf2f3052010-10-28 16:28:56 +0000378 if (bp->GetNumLocations() == 0)
379 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual"
380 " locations.\n");
Greg Clayton887aa282010-10-11 01:05:37 +0000381 result.SetStatus (eReturnStatusSuccessFinishResult);
382 }
383 else
384 {
385 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
386 m_options.m_modules[i].c_str());
387 result.SetStatus (eReturnStatusFailed);
388 }
389 }
390 }
391 else
392 bp = target->CreateBreakpoint (NULL,
393 file,
394 m_options.m_line_num,
Greg Clayton2dfe4c62010-11-02 03:02:38 +0000395 m_options.m_check_inlines).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000396 }
Greg Clayton887aa282010-10-11 01:05:37 +0000397 break;
398
Chris Lattner24943d22010-06-08 16:52:24 +0000399 case eSetTypeAddress: // Breakpoint by address
400 bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
401 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000402
Chris Lattner24943d22010-06-08 16:52:24 +0000403 case eSetTypeFunctionName: // Breakpoint by function name
Chris Lattner24943d22010-06-08 16:52:24 +0000404 {
Greg Clayton12bec712010-06-28 21:30:43 +0000405 uint32_t name_type_mask = m_options.m_func_name_type_mask;
406
407 if (name_type_mask == 0)
Greg Clayton48fbdf72010-10-12 04:29:14 +0000408 name_type_mask = eFunctionNameTypeAuto;
409
Greg Clayton12bec712010-06-28 21:30:43 +0000410 if (use_module)
411 {
412 for (int i = 0; i < num_modules; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000413 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000414 module_spec.SetFile(m_options.m_modules[i].c_str(), false);
415 bp = target->CreateBreakpoint (&module_spec,
416 m_options.m_func_name.c_str(),
417 name_type_mask,
418 Breakpoint::Exact).get();
Greg Clayton12bec712010-06-28 21:30:43 +0000419 if (bp)
420 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000421 Stream &output_stream = result.GetOutputStream();
Greg Clayton12bec712010-06-28 21:30:43 +0000422 output_stream.Printf ("Breakpoint created: ");
423 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
424 output_stream.EOL();
Caroline Ticecf2f3052010-10-28 16:28:56 +0000425 if (bp->GetNumLocations() == 0)
426 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual"
427 " locations.\n");
Greg Clayton12bec712010-06-28 21:30:43 +0000428 result.SetStatus (eReturnStatusSuccessFinishResult);
429 }
430 else
431 {
432 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
433 m_options.m_modules[i].c_str());
434 result.SetStatus (eReturnStatusFailed);
435 }
Chris Lattner24943d22010-06-08 16:52:24 +0000436 }
437 }
Greg Clayton12bec712010-06-28 21:30:43 +0000438 else
439 bp = target->CreateBreakpoint (NULL, m_options.m_func_name.c_str(), name_type_mask, Breakpoint::Exact).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000440 }
Chris Lattner24943d22010-06-08 16:52:24 +0000441 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000442
Chris Lattner24943d22010-06-08 16:52:24 +0000443 case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
444 {
445 RegularExpression regexp(m_options.m_func_regexp.c_str());
446 if (use_module)
447 {
448 for (int i = 0; i < num_modules; ++i)
449 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000450 module_spec.SetFile(m_options.m_modules[i].c_str(), false);
451 bp = target->CreateBreakpoint (&module_spec, regexp).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000452 if (bp)
453 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000454 Stream &output_stream = result.GetOutputStream();
Chris Lattner24943d22010-06-08 16:52:24 +0000455 output_stream.Printf ("Breakpoint created: ");
456 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
457 output_stream.EOL();
Caroline Ticecf2f3052010-10-28 16:28:56 +0000458 if (bp->GetNumLocations() == 0)
459 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual"
460 " locations.\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000461 result.SetStatus (eReturnStatusSuccessFinishResult);
462 }
463 else
464 {
465 result.AppendErrorWithFormat("Breakpoint creation failed: No breakpoint created in module '%s'.\n",
466 m_options.m_modules[i].c_str());
467 result.SetStatus (eReturnStatusFailed);
468 }
469 }
470 }
471 else
472 bp = target->CreateBreakpoint (NULL, regexp).get();
473 }
474 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000475
Chris Lattner24943d22010-06-08 16:52:24 +0000476 default:
477 break;
478 }
479
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000480 // Now set the various options that were passed in:
481 if (bp)
482 {
483 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
484 bp->SetThreadID (m_options.m_thread_id);
485
Greg Clayton54e7afa2010-07-09 20:39:50 +0000486 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000487 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
488
489 if (!m_options.m_thread_name.empty())
490 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
491
492 if (!m_options.m_queue_name.empty())
493 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
494
Greg Clayton54e7afa2010-07-09 20:39:50 +0000495 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000496 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
497 }
498
Chris Lattner24943d22010-06-08 16:52:24 +0000499 if (bp && !use_module)
500 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000501 Stream &output_stream = result.GetOutputStream();
Chris Lattner24943d22010-06-08 16:52:24 +0000502 output_stream.Printf ("Breakpoint created: ");
503 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
504 output_stream.EOL();
Caroline Ticecf2f3052010-10-28 16:28:56 +0000505 if (bp->GetNumLocations() == 0)
506 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000507 result.SetStatus (eReturnStatusSuccessFinishResult);
508 }
509 else if (!bp)
510 {
511 result.AppendError ("Breakpoint creation failed: No breakpoint created.");
512 result.SetStatus (eReturnStatusFailed);
513 }
514
515 return result.Succeeded();
516}
517
Chris Lattner24943d22010-06-08 16:52:24 +0000518//-------------------------------------------------------------------------
519// CommandObjectMultiwordBreakpoint
520//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000521#pragma mark MultiwordBreakpoint
Chris Lattner24943d22010-06-08 16:52:24 +0000522
Greg Clayton63094e02010-06-23 01:19:29 +0000523CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000524 CommandObjectMultiword (interpreter,
525 "breakpoint",
Jim Ingham7224aab2011-05-26 20:39:01 +0000526 "A set of commands for operating on breakpoints. Also see _regexp-break.",
Greg Clayton238c0a12010-09-18 01:14:36 +0000527 "breakpoint <command> [<command-options>]")
Chris Lattner24943d22010-06-08 16:52:24 +0000528{
529 bool status;
530
Greg Clayton238c0a12010-09-18 01:14:36 +0000531 CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000532 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
533 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
Johnny Chena62ad7c2010-10-28 17:27:46 +0000534 CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
535 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000536 CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +0000537 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000538 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +0000539
Johnny Chena62ad7c2010-10-28 17:27:46 +0000540 list_command_object->SetCommandName ("breakpoint list");
Chris Lattner24943d22010-06-08 16:52:24 +0000541 enable_command_object->SetCommandName("breakpoint enable");
542 disable_command_object->SetCommandName("breakpoint disable");
Johnny Chena62ad7c2010-10-28 17:27:46 +0000543 clear_command_object->SetCommandName("breakpoint clear");
544 delete_command_object->SetCommandName("breakpoint delete");
Jim Ingham10622a22010-06-18 00:58:52 +0000545 set_command_object->SetCommandName("breakpoint set");
Johnny Chena62ad7c2010-10-28 17:27:46 +0000546 command_command_object->SetCommandName ("breakpoint command");
547 modify_command_object->SetCommandName ("breakpoint modify");
Chris Lattner24943d22010-06-08 16:52:24 +0000548
Greg Clayton238c0a12010-09-18 01:14:36 +0000549 status = LoadSubCommand ("list", list_command_object);
550 status = LoadSubCommand ("enable", enable_command_object);
551 status = LoadSubCommand ("disable", disable_command_object);
Johnny Chena62ad7c2010-10-28 17:27:46 +0000552 status = LoadSubCommand ("clear", clear_command_object);
Greg Clayton238c0a12010-09-18 01:14:36 +0000553 status = LoadSubCommand ("delete", delete_command_object);
554 status = LoadSubCommand ("set", set_command_object);
555 status = LoadSubCommand ("command", command_command_object);
556 status = LoadSubCommand ("modify", modify_command_object);
Chris Lattner24943d22010-06-08 16:52:24 +0000557}
558
559CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
560{
561}
562
563void
564CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result,
565 BreakpointIDList *valid_ids)
566{
567 // args can be strings representing 1). integers (for breakpoint ids)
568 // 2). the full breakpoint & location canonical representation
569 // 3). the word "to" or a hyphen, representing a range (in which case there
570 // had *better* be an entry both before & after of one of the first two types.
Jim Inghamd1686902010-10-14 23:45:03 +0000571 // If args is empty, we will use the last created breakpoint (if there is one.)
Chris Lattner24943d22010-06-08 16:52:24 +0000572
573 Args temp_args;
574
Jim Inghamd1686902010-10-14 23:45:03 +0000575 if (args.GetArgumentCount() == 0)
576 {
Greg Clayton987c7eb2011-09-17 08:33:22 +0000577 if (target->GetLastCreatedBreakpoint())
Jim Inghamd1686902010-10-14 23:45:03 +0000578 {
579 valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
580 result.SetStatus (eReturnStatusSuccessFinishNoResult);
581 }
582 else
583 {
584 result.AppendError("No breakpoint specified and no last created breakpoint.");
585 result.SetStatus (eReturnStatusFailed);
586 }
587 return;
588 }
589
Chris Lattner24943d22010-06-08 16:52:24 +0000590 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
591 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
592 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
593
594 BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
595
596 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
597
Greg Clayton54e7afa2010-07-09 20:39:50 +0000598 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
Chris Lattner24943d22010-06-08 16:52:24 +0000599
600 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
601 // and put into valid_ids.
602
603 if (result.Succeeded())
604 {
605 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
606 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
607
Greg Clayton54e7afa2010-07-09 20:39:50 +0000608 const size_t count = valid_ids->GetSize();
609 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000610 {
611 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
612 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
613 if (breakpoint != NULL)
614 {
615 int num_locations = breakpoint->GetNumLocations();
616 if (cur_bp_id.GetLocationID() > num_locations)
617 {
618 StreamString id_str;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000619 BreakpointID::GetCanonicalReference (&id_str,
620 cur_bp_id.GetBreakpointID(),
621 cur_bp_id.GetLocationID());
622 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000623 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
624 id_str.GetData());
625 result.SetStatus (eReturnStatusFailed);
626 }
627 }
628 else
629 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000630 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000631 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
632 result.SetStatus (eReturnStatusFailed);
633 }
634 }
635 }
636}
637
638//-------------------------------------------------------------------------
639// CommandObjectBreakpointList::Options
640//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000641#pragma mark List::CommandOptions
Chris Lattner24943d22010-06-08 16:52:24 +0000642
Greg Claytonf15996e2011-04-07 22:46:35 +0000643CommandObjectBreakpointList::CommandOptions::CommandOptions(CommandInterpreter &interpreter) :
644 Options (interpreter),
Caroline Tice41950cc2011-02-04 22:59:41 +0000645 m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions
Chris Lattner24943d22010-06-08 16:52:24 +0000646{
Chris Lattner24943d22010-06-08 16:52:24 +0000647}
648
649CommandObjectBreakpointList::CommandOptions::~CommandOptions ()
650{
651}
652
Greg Claytonb3448432011-03-24 21:19:54 +0000653OptionDefinition
Chris Lattner24943d22010-06-08 16:52:24 +0000654CommandObjectBreakpointList::CommandOptions::g_option_table[] =
655{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000656 { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone,
Jim Ingham34e9a982010-06-15 18:47:14 +0000657 "Show debugger internal breakpoints" },
658
Caroline Tice4d6675c2010-10-01 19:59:14 +0000659 { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000660 "Give a brief description of the breakpoint (no location info)."},
661
662 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
663 // But I need to see it for now, and don't want to wait.
Caroline Tice4d6675c2010-10-01 19:59:14 +0000664 { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000665 "Give a full description of the breakpoint and its locations."},
Chris Lattner24943d22010-06-08 16:52:24 +0000666
Caroline Tice4d6675c2010-10-01 19:59:14 +0000667 { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000668 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
Chris Lattner24943d22010-06-08 16:52:24 +0000669
Caroline Tice4d6675c2010-10-01 19:59:14 +0000670 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000671};
672
Greg Claytonb3448432011-03-24 21:19:54 +0000673const OptionDefinition*
Chris Lattner24943d22010-06-08 16:52:24 +0000674CommandObjectBreakpointList::CommandOptions::GetDefinitions ()
675{
676 return g_option_table;
677}
678
679Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000680CommandObjectBreakpointList::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Chris Lattner24943d22010-06-08 16:52:24 +0000681{
682 Error error;
683 char short_option = (char) m_getopt_table[option_idx].val;
684
685 switch (short_option)
686 {
687 case 'b':
688 m_level = lldb::eDescriptionLevelBrief;
689 break;
690 case 'f':
691 m_level = lldb::eDescriptionLevelFull;
692 break;
693 case 'v':
694 m_level = lldb::eDescriptionLevelVerbose;
695 break;
696 case 'i':
697 m_internal = true;
698 break;
699 default:
700 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
701 break;
702 }
703
704 return error;
705}
706
707void
Greg Clayton143fcc32011-04-13 00:18:08 +0000708CommandObjectBreakpointList::CommandOptions::OptionParsingStarting ()
Chris Lattner24943d22010-06-08 16:52:24 +0000709{
Jim Inghamdc259052011-05-17 01:21:41 +0000710 m_level = lldb::eDescriptionLevelFull;
Chris Lattner24943d22010-06-08 16:52:24 +0000711 m_internal = false;
712}
713
714//-------------------------------------------------------------------------
715// CommandObjectBreakpointList
716//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000717#pragma mark List
Chris Lattner24943d22010-06-08 16:52:24 +0000718
Greg Clayton238c0a12010-09-18 01:14:36 +0000719CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) :
720 CommandObject (interpreter,
721 "breakpoint list",
722 "List some or all breakpoints at configurable levels of detail.",
Greg Claytonf15996e2011-04-07 22:46:35 +0000723 NULL),
724 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000725{
Caroline Ticefb355112010-10-01 17:46:38 +0000726 CommandArgumentEntry arg;
727 CommandArgumentData bp_id_arg;
728
729 // Define the first (and only) variant of this arg.
730 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +0000731 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000732
733 // There is only one variant this argument could be; put it into the argument entry.
734 arg.push_back (bp_id_arg);
735
736 // Push the data for the first argument into the m_arguments vector.
737 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000738}
739
740CommandObjectBreakpointList::~CommandObjectBreakpointList ()
741{
742}
743
744Options *
745CommandObjectBreakpointList::GetOptions ()
746{
747 return &m_options;
748}
749
750bool
751CommandObjectBreakpointList::Execute
752(
753 Args& args,
Chris Lattner24943d22010-06-08 16:52:24 +0000754 CommandReturnObject &result
755)
756{
Greg Clayton238c0a12010-09-18 01:14:36 +0000757 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000758 if (target == NULL)
759 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000760 result.AppendError ("Invalid target. No current target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000761 result.SetStatus (eReturnStatusSuccessFinishNoResult);
762 return true;
763 }
764
765 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000766 Mutex::Locker locker;
767 target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
768
Chris Lattner24943d22010-06-08 16:52:24 +0000769 size_t num_breakpoints = breakpoints.GetSize();
770
771 if (num_breakpoints == 0)
772 {
773 result.AppendMessage ("No breakpoints currently set.");
774 result.SetStatus (eReturnStatusSuccessFinishNoResult);
775 return true;
776 }
777
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000778 Stream &output_stream = result.GetOutputStream();
Chris Lattner24943d22010-06-08 16:52:24 +0000779
780 if (args.GetArgumentCount() == 0)
781 {
782 // No breakpoint selected; show info about all currently set breakpoints.
783 result.AppendMessage ("Current breakpoints:");
Greg Clayton54e7afa2010-07-09 20:39:50 +0000784 for (size_t i = 0; i < num_breakpoints; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000785 {
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000786 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000787 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000788 }
789 result.SetStatus (eReturnStatusSuccessFinishNoResult);
790 }
791 else
792 {
793 // Particular breakpoints selected; show info about that breakpoint.
794 BreakpointIDList valid_bp_ids;
795 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
796
797 if (result.Succeeded())
798 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000799 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000800 {
801 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
802 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000803 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000804 }
805 result.SetStatus (eReturnStatusSuccessFinishNoResult);
806 }
807 else
808 {
809 result.AppendError ("Invalid breakpoint id.");
810 result.SetStatus (eReturnStatusFailed);
811 }
812 }
813
814 return result.Succeeded();
815}
816
817//-------------------------------------------------------------------------
818// CommandObjectBreakpointEnable
819//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000820#pragma mark Enable
Chris Lattner24943d22010-06-08 16:52:24 +0000821
Greg Clayton238c0a12010-09-18 01:14:36 +0000822CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
823 CommandObject (interpreter,
824 "enable",
Caroline Ticefb355112010-10-01 17:46:38 +0000825 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
826 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000827{
Caroline Ticefb355112010-10-01 17:46:38 +0000828 CommandArgumentEntry arg;
829 CommandArgumentData bp_id_arg;
830 CommandArgumentData bp_id_range_arg;
831
832 // Create the first variant for the first (and only) argument for this command.
833 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +0000834 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000835
836 // Create the second variant for the first (and only) argument for this command.
837 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +0000838 bp_id_range_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000839
840 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
841 // Push both variants into the entry for the first argument for this command.
842 arg.push_back (bp_id_arg);
843 arg.push_back (bp_id_range_arg);
844
845 // Add the entry for the first argument for this command to the object's arguments vector.
846 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000847}
848
849
850CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable ()
851{
852}
853
854
855bool
Greg Clayton63094e02010-06-23 01:19:29 +0000856CommandObjectBreakpointEnable::Execute
857(
Greg Clayton63094e02010-06-23 01:19:29 +0000858 Args& args,
859 CommandReturnObject &result
860)
Chris Lattner24943d22010-06-08 16:52:24 +0000861{
Greg Clayton238c0a12010-09-18 01:14:36 +0000862 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000863 if (target == NULL)
864 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000865 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000866 result.SetStatus (eReturnStatusFailed);
867 return false;
868 }
869
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000870 Mutex::Locker locker;
871 target->GetBreakpointList().GetListMutex(locker);
872
Chris Lattner24943d22010-06-08 16:52:24 +0000873 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000874
Chris Lattner24943d22010-06-08 16:52:24 +0000875 size_t num_breakpoints = breakpoints.GetSize();
876
877 if (num_breakpoints == 0)
878 {
879 result.AppendError ("No breakpoints exist to be enabled.");
880 result.SetStatus (eReturnStatusFailed);
881 return false;
882 }
883
884 if (args.GetArgumentCount() == 0)
885 {
886 // No breakpoint selected; enable all currently set breakpoints.
887 target->EnableAllBreakpoints ();
888 result.AppendMessageWithFormat ("All breakpoints enabled. (%d breakpoints)\n", num_breakpoints);
889 result.SetStatus (eReturnStatusSuccessFinishNoResult);
890 }
891 else
892 {
893 // Particular breakpoint selected; enable that breakpoint.
894 BreakpointIDList valid_bp_ids;
895 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
896
897 if (result.Succeeded())
898 {
899 int enable_count = 0;
900 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000901 const size_t count = valid_bp_ids.GetSize();
902 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000903 {
904 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
905
906 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
907 {
908 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
909 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
910 {
911 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
912 if (location)
913 {
914 location->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000915 ++loc_count;
916 }
917 }
918 else
919 {
Jim Ingham10622a22010-06-18 00:58:52 +0000920 breakpoint->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000921 ++enable_count;
Chris Lattner24943d22010-06-08 16:52:24 +0000922 }
923 }
924 }
925 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
926 result.SetStatus (eReturnStatusSuccessFinishNoResult);
927 }
928 }
929
930 return result.Succeeded();
931}
932
933//-------------------------------------------------------------------------
934// CommandObjectBreakpointDisable
935//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000936#pragma mark Disable
Chris Lattner24943d22010-06-08 16:52:24 +0000937
Greg Clayton238c0a12010-09-18 01:14:36 +0000938CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
939 CommandObject (interpreter,
Caroline Ticefb355112010-10-01 17:46:38 +0000940 "breakpoint disable",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000941 "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.",
Caroline Ticefb355112010-10-01 17:46:38 +0000942 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000943{
Caroline Ticefb355112010-10-01 17:46:38 +0000944 CommandArgumentEntry arg;
945 CommandArgumentData bp_id_arg;
946 CommandArgumentData bp_id_range_arg;
947
948 // Create the first variant for the first (and only) argument for this command.
949 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +0000950 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000951
952 // Create the second variant for the first (and only) argument for this command.
953 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +0000954 bp_id_range_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000955
956 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
957 // Push both variants into the entry for the first argument for this command.
958 arg.push_back (bp_id_arg);
959 arg.push_back (bp_id_range_arg);
960
961 // Add the entry for the first argument for this command to the object's arguments vector.
962 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000963}
964
965CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable ()
966{
967}
968
969bool
Greg Clayton63094e02010-06-23 01:19:29 +0000970CommandObjectBreakpointDisable::Execute
971(
Greg Clayton63094e02010-06-23 01:19:29 +0000972 Args& args,
973 CommandReturnObject &result
974)
Chris Lattner24943d22010-06-08 16:52:24 +0000975{
Greg Clayton238c0a12010-09-18 01:14:36 +0000976 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000977 if (target == NULL)
978 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000979 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000980 result.SetStatus (eReturnStatusFailed);
981 return false;
982 }
983
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000984 Mutex::Locker locker;
985 target->GetBreakpointList().GetListMutex(locker);
986
Chris Lattner24943d22010-06-08 16:52:24 +0000987 const BreakpointList &breakpoints = target->GetBreakpointList();
988 size_t num_breakpoints = breakpoints.GetSize();
989
990 if (num_breakpoints == 0)
991 {
992 result.AppendError ("No breakpoints exist to be disabled.");
993 result.SetStatus (eReturnStatusFailed);
994 return false;
995 }
996
997 if (args.GetArgumentCount() == 0)
998 {
999 // No breakpoint selected; disable all currently set breakpoints.
1000 target->DisableAllBreakpoints ();
1001 result.AppendMessageWithFormat ("All breakpoints disabled. (%d breakpoints)\n", num_breakpoints);
1002 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1003 }
1004 else
1005 {
1006 // Particular breakpoint selected; disable that breakpoint.
1007 BreakpointIDList valid_bp_ids;
1008
1009 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
1010
1011 if (result.Succeeded())
1012 {
1013 int disable_count = 0;
1014 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001015 const size_t count = valid_bp_ids.GetSize();
1016 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +00001017 {
1018 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1019
1020 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1021 {
1022 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1023 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1024 {
1025 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1026 if (location)
1027 {
1028 location->SetEnabled (false);
1029 ++loc_count;
1030 }
1031 }
1032 else
1033 {
Jim Ingham10622a22010-06-18 00:58:52 +00001034 breakpoint->SetEnabled (false);
Chris Lattner24943d22010-06-08 16:52:24 +00001035 ++disable_count;
Chris Lattner24943d22010-06-08 16:52:24 +00001036 }
1037 }
1038 }
1039 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
1040 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1041 }
1042 }
1043
1044 return result.Succeeded();
1045}
1046
1047//-------------------------------------------------------------------------
Johnny Chena62ad7c2010-10-28 17:27:46 +00001048// CommandObjectBreakpointClear::CommandOptions
1049//-------------------------------------------------------------------------
1050#pragma mark Clear::CommandOptions
1051
Greg Claytonf15996e2011-04-07 22:46:35 +00001052CommandObjectBreakpointClear::CommandOptions::CommandOptions(CommandInterpreter &interpreter) :
1053 Options (interpreter),
Johnny Chena62ad7c2010-10-28 17:27:46 +00001054 m_filename (),
1055 m_line_num (0)
1056{
1057}
1058
1059CommandObjectBreakpointClear::CommandOptions::~CommandOptions ()
1060{
1061}
1062
Greg Claytonb3448432011-03-24 21:19:54 +00001063OptionDefinition
Johnny Chena62ad7c2010-10-28 17:27:46 +00001064CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
1065{
1066 { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
1067 "Specify the breakpoint by source location in this particular file."},
1068
1069 { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
1070 "Specify the breakpoint by source location at this particular line."},
1071
1072 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1073};
1074
Greg Claytonb3448432011-03-24 21:19:54 +00001075const OptionDefinition*
Johnny Chena62ad7c2010-10-28 17:27:46 +00001076CommandObjectBreakpointClear::CommandOptions::GetDefinitions ()
1077{
1078 return g_option_table;
1079}
1080
1081Error
Greg Clayton143fcc32011-04-13 00:18:08 +00001082CommandObjectBreakpointClear::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Johnny Chena62ad7c2010-10-28 17:27:46 +00001083{
1084 Error error;
1085 char short_option = (char) m_getopt_table[option_idx].val;
1086
1087 switch (short_option)
1088 {
1089 case 'f':
Greg Clayton889fbd02011-03-26 19:14:58 +00001090 m_filename.assign (option_arg);
Johnny Chena62ad7c2010-10-28 17:27:46 +00001091 break;
1092
1093 case 'l':
1094 m_line_num = Args::StringToUInt32 (option_arg, 0);
1095 break;
1096
1097 default:
1098 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1099 break;
1100 }
1101
1102 return error;
1103}
1104
1105void
Greg Clayton143fcc32011-04-13 00:18:08 +00001106CommandObjectBreakpointClear::CommandOptions::OptionParsingStarting ()
Johnny Chena62ad7c2010-10-28 17:27:46 +00001107{
Johnny Chena62ad7c2010-10-28 17:27:46 +00001108 m_filename.clear();
1109 m_line_num = 0;
1110}
1111
1112//-------------------------------------------------------------------------
1113// CommandObjectBreakpointClear
1114//-------------------------------------------------------------------------
1115#pragma mark Clear
1116
1117CommandObjectBreakpointClear::CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
1118 CommandObject (interpreter,
1119 "breakpoint clear",
1120 "Clears a breakpoint or set of breakpoints in the executable.",
Greg Claytonf15996e2011-04-07 22:46:35 +00001121 "breakpoint clear <cmd-options>"),
1122 m_options (interpreter)
Johnny Chena62ad7c2010-10-28 17:27:46 +00001123{
1124}
1125
1126CommandObjectBreakpointClear::~CommandObjectBreakpointClear ()
1127{
1128}
1129
1130Options *
1131CommandObjectBreakpointClear::GetOptions ()
1132{
1133 return &m_options;
1134}
1135
1136bool
1137CommandObjectBreakpointClear::Execute
1138(
1139 Args& command,
1140 CommandReturnObject &result
1141)
1142{
1143 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1144 if (target == NULL)
1145 {
1146 result.AppendError ("Invalid target. No existing target or breakpoints.");
1147 result.SetStatus (eReturnStatusFailed);
1148 return false;
1149 }
1150
1151 // The following are the various types of breakpoints that could be cleared:
1152 // 1). -f -l (clearing breakpoint by source location)
1153
1154 BreakpointClearType break_type = eClearTypeInvalid;
1155
1156 if (m_options.m_line_num != 0)
1157 break_type = eClearTypeFileAndLine;
1158
1159 Mutex::Locker locker;
1160 target->GetBreakpointList().GetListMutex(locker);
1161
1162 BreakpointList &breakpoints = target->GetBreakpointList();
1163 size_t num_breakpoints = breakpoints.GetSize();
1164
1165 // Early return if there's no breakpoint at all.
1166 if (num_breakpoints == 0)
1167 {
1168 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1169 result.SetStatus (eReturnStatusFailed);
1170 return result.Succeeded();
1171 }
1172
1173 // Find matching breakpoints and delete them.
1174
1175 // First create a copy of all the IDs.
1176 std::vector<break_id_t> BreakIDs;
1177 for (size_t i = 0; i < num_breakpoints; ++i)
1178 BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID());
1179
1180 int num_cleared = 0;
1181 StreamString ss;
1182 switch (break_type)
1183 {
1184 case eClearTypeFileAndLine: // Breakpoint by source position
1185 {
1186 const ConstString filename(m_options.m_filename.c_str());
1187 BreakpointLocationCollection loc_coll;
1188
1189 for (size_t i = 0; i < num_breakpoints; ++i)
1190 {
1191 Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
1192
1193 if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
1194 {
1195 // If the collection size is 0, it's a full match and we can just remove the breakpoint.
1196 if (loc_coll.GetSize() == 0)
1197 {
1198 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
1199 ss.EOL();
1200 target->RemoveBreakpointByID (bp->GetID());
1201 ++num_cleared;
1202 }
1203 }
1204 }
1205 }
1206 break;
1207
1208 default:
1209 break;
1210 }
1211
1212 if (num_cleared > 0)
1213 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +00001214 Stream &output_stream = result.GetOutputStream();
Johnny Chena62ad7c2010-10-28 17:27:46 +00001215 output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
1216 output_stream << ss.GetData();
1217 output_stream.EOL();
1218 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1219 }
1220 else
1221 {
1222 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1223 result.SetStatus (eReturnStatusFailed);
1224 }
1225
1226 return result.Succeeded();
1227}
1228
1229//-------------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +00001230// CommandObjectBreakpointDelete
1231//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001232#pragma mark Delete
Chris Lattner24943d22010-06-08 16:52:24 +00001233
Greg Clayton238c0a12010-09-18 01:14:36 +00001234CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) :
1235 CommandObject (interpreter,
1236 "breakpoint delete",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001237 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
Caroline Ticefb355112010-10-01 17:46:38 +00001238 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +00001239{
Caroline Ticefb355112010-10-01 17:46:38 +00001240 CommandArgumentEntry arg;
1241 CommandArgumentData bp_id_arg;
1242 CommandArgumentData bp_id_range_arg;
1243
1244 // Create the first variant for the first (and only) argument for this command.
1245 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +00001246 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +00001247
1248 // Create the second variant for the first (and only) argument for this command.
1249 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +00001250 bp_id_range_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +00001251
1252 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1253 // Push both variants into the entry for the first argument for this command.
1254 arg.push_back (bp_id_arg);
1255 arg.push_back (bp_id_range_arg);
1256
1257 // Add the entry for the first argument for this command to the object's arguments vector.
1258 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +00001259}
1260
1261
1262CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete ()
1263{
1264}
1265
1266bool
Greg Clayton63094e02010-06-23 01:19:29 +00001267CommandObjectBreakpointDelete::Execute
1268(
Greg Clayton63094e02010-06-23 01:19:29 +00001269 Args& args,
1270 CommandReturnObject &result
1271)
Chris Lattner24943d22010-06-08 16:52:24 +00001272{
Greg Clayton238c0a12010-09-18 01:14:36 +00001273 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001274 if (target == NULL)
1275 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001276 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +00001277 result.SetStatus (eReturnStatusFailed);
1278 return false;
1279 }
1280
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001281 Mutex::Locker locker;
1282 target->GetBreakpointList().GetListMutex(locker);
1283
Chris Lattner24943d22010-06-08 16:52:24 +00001284 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001285
Chris Lattner24943d22010-06-08 16:52:24 +00001286 size_t num_breakpoints = breakpoints.GetSize();
1287
1288 if (num_breakpoints == 0)
1289 {
1290 result.AppendError ("No breakpoints exist to be deleted.");
1291 result.SetStatus (eReturnStatusFailed);
1292 return false;
1293 }
1294
1295 if (args.GetArgumentCount() == 0)
1296 {
Jim Inghamd1686902010-10-14 23:45:03 +00001297 if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
Chris Lattner24943d22010-06-08 16:52:24 +00001298 {
Jim Inghamd1686902010-10-14 23:45:03 +00001299 result.AppendMessage("Operation cancelled...");
Chris Lattner24943d22010-06-08 16:52:24 +00001300 }
Jim Inghamd1686902010-10-14 23:45:03 +00001301 else
1302 {
1303 target->RemoveAllBreakpoints ();
1304 result.AppendMessageWithFormat ("All breakpoints removed. (%d breakpoints)\n", num_breakpoints);
1305 }
Chris Lattner24943d22010-06-08 16:52:24 +00001306 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1307 }
1308 else
1309 {
1310 // Particular breakpoint selected; disable that breakpoint.
1311 BreakpointIDList valid_bp_ids;
1312 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
1313
1314 if (result.Succeeded())
1315 {
1316 int delete_count = 0;
1317 int disable_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001318 const size_t count = valid_bp_ids.GetSize();
1319 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +00001320 {
1321 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1322
1323 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1324 {
1325 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1326 {
1327 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1328 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1329 // It makes no sense to try to delete individual locations, so we disable them instead.
1330 if (location)
1331 {
1332 location->SetEnabled (false);
1333 ++disable_count;
1334 }
1335 }
1336 else
1337 {
1338 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1339 ++delete_count;
1340 }
1341 }
1342 }
1343 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1344 delete_count, disable_count);
1345 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1346 }
1347 }
1348 return result.Succeeded();
1349}
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001350
1351//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001352// CommandObjectBreakpointModify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001353//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001354#pragma mark Modify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001355
Greg Claytonf15996e2011-04-07 22:46:35 +00001356CommandObjectBreakpointModify::CommandOptions::CommandOptions(CommandInterpreter &interpreter) :
1357 Options (interpreter),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001358 m_ignore_count (0),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001359 m_thread_id(LLDB_INVALID_THREAD_ID),
Jim Ingham9a7b2912010-12-03 23:04:19 +00001360 m_thread_id_passed(false),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001361 m_thread_index (UINT32_MAX),
Jim Ingham9a7b2912010-12-03 23:04:19 +00001362 m_thread_index_passed(false),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001363 m_thread_name(),
1364 m_queue_name(),
Jim Inghamd1686902010-10-14 23:45:03 +00001365 m_condition (),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001366 m_enable_passed (false),
1367 m_enable_value (false),
1368 m_name_passed (false),
Jim Inghamd1686902010-10-14 23:45:03 +00001369 m_queue_passed (false),
1370 m_condition_passed (false)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001371{
1372}
1373
Jim Ingham10622a22010-06-18 00:58:52 +00001374CommandObjectBreakpointModify::CommandOptions::~CommandOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001375{
1376}
1377
Greg Claytonb3448432011-03-24 21:19:54 +00001378OptionDefinition
Jim Ingham10622a22010-06-18 00:58:52 +00001379CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001380{
Caroline Tice4d6675c2010-10-01 19:59:14 +00001381{ LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, NULL, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." },
1382{ 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."},
1383{ 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."},
1384{ 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."},
1385{ 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 +00001386{ 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 +00001387{ LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, eArgTypeNone, "Enable the breakpoint."},
1388{ LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, eArgTypeNone, "Disable the breakpoint."},
Jim Inghamd1686902010-10-14 23:45:03 +00001389{ 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001390};
1391
Greg Claytonb3448432011-03-24 21:19:54 +00001392const OptionDefinition*
Jim Ingham10622a22010-06-18 00:58:52 +00001393CommandObjectBreakpointModify::CommandOptions::GetDefinitions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001394{
1395 return g_option_table;
1396}
1397
1398Error
Greg Clayton143fcc32011-04-13 00:18:08 +00001399CommandObjectBreakpointModify::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001400{
1401 Error error;
1402 char short_option = (char) m_getopt_table[option_idx].val;
1403
1404 switch (short_option)
1405 {
Jim Inghamd1686902010-10-14 23:45:03 +00001406 case 'c':
1407 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001408 m_condition.assign (option_arg);
Jim Inghamd1686902010-10-14 23:45:03 +00001409 else
1410 m_condition.clear();
1411 m_condition_passed = true;
1412 break;
Jim Ingham10622a22010-06-18 00:58:52 +00001413 case 'd':
1414 m_enable_passed = true;
1415 m_enable_value = false;
1416 break;
1417 case 'e':
1418 m_enable_passed = true;
1419 m_enable_value = true;
1420 break;
Greg Claytonfe424a92010-09-18 03:37:20 +00001421 case 'i':
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001422 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001423 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Greg Clayton54e7afa2010-07-09 20:39:50 +00001424 if (m_ignore_count == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001425 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001426 }
Jim Ingham10622a22010-06-18 00:58:52 +00001427 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001428 case 't' :
1429 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001430 if (option_arg[0] == '\0')
Jim Ingham9a7b2912010-12-03 23:04:19 +00001431 {
1432 m_thread_id = LLDB_INVALID_THREAD_ID;
1433 m_thread_id_passed = true;
1434 }
1435 else
1436 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001437 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001438 if (m_thread_id == LLDB_INVALID_THREAD_ID)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001439 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", option_arg);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001440 else
1441 m_thread_id_passed = true;
1442 }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001443 }
1444 break;
1445 case 'T':
Jim Inghamd4571222010-06-19 04:35:20 +00001446 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001447 m_thread_name.assign (option_arg);
Jim Inghamd4571222010-06-19 04:35:20 +00001448 else
1449 m_thread_name.clear();
1450 m_name_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001451 break;
1452 case 'q':
Jim Inghamd4571222010-06-19 04:35:20 +00001453 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001454 m_queue_name.assign (option_arg);
Jim Inghamd4571222010-06-19 04:35:20 +00001455 else
1456 m_queue_name.clear();
1457 m_queue_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001458 break;
1459 case 'x':
1460 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001461 if (option_arg[0] == '\n')
Jim Ingham9a7b2912010-12-03 23:04:19 +00001462 {
1463 m_thread_index = UINT32_MAX;
1464 m_thread_index_passed = true;
1465 }
1466 else
1467 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001468 m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001469 if (m_thread_id == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001470 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", option_arg);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001471 else
1472 m_thread_index_passed = true;
1473 }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001474 }
1475 break;
1476 default:
1477 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1478 break;
1479 }
1480
1481 return error;
1482}
1483
1484void
Greg Clayton143fcc32011-04-13 00:18:08 +00001485CommandObjectBreakpointModify::CommandOptions::OptionParsingStarting ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001486{
Greg Clayton54e7afa2010-07-09 20:39:50 +00001487 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001488 m_thread_id = LLDB_INVALID_THREAD_ID;
Jim Ingham9a7b2912010-12-03 23:04:19 +00001489 m_thread_id_passed = false;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001490 m_thread_index = UINT32_MAX;
Jim Ingham9a7b2912010-12-03 23:04:19 +00001491 m_thread_index_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001492 m_thread_name.clear();
1493 m_queue_name.clear();
Jim Inghamd1686902010-10-14 23:45:03 +00001494 m_condition.clear();
Jim Ingham10622a22010-06-18 00:58:52 +00001495 m_enable_passed = false;
Jim Inghamd4571222010-06-19 04:35:20 +00001496 m_queue_passed = false;
1497 m_name_passed = false;
Jim Inghamd1686902010-10-14 23:45:03 +00001498 m_condition_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001499}
1500
1501//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001502// CommandObjectBreakpointModify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001503//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001504#pragma mark Modify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001505
Greg Clayton238c0a12010-09-18 01:14:36 +00001506CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
1507 CommandObject (interpreter,
1508 "breakpoint modify",
Jim Ingham19ac0bd2010-12-03 22:37:19 +00001509 "Modify the options on a breakpoint or set of breakpoints in the executable. "
Jim Ingham9a7b2912010-12-03 23:04:19 +00001510 "If no breakpoint is specified, acts on the last created breakpoint. "
1511 "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
Greg Claytonf15996e2011-04-07 22:46:35 +00001512 NULL),
1513 m_options (interpreter)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001514{
Caroline Ticefb355112010-10-01 17:46:38 +00001515 CommandArgumentEntry arg;
1516 CommandArgumentData bp_id_arg;
1517 CommandArgumentData bp_id_range_arg;
1518
1519 // Create the first variant for the first (and only) argument for this command.
1520 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +00001521 bp_id_arg.arg_repetition = eArgRepeatPlain;
Caroline Ticefb355112010-10-01 17:46:38 +00001522
1523 // Create the second variant for the first (and only) argument for this command.
1524 bp_id_range_arg.arg_type = eArgTypeBreakpointIDRange;
Caroline Tice43b014a2010-10-04 22:28:36 +00001525 bp_id_range_arg.arg_repetition = eArgRepeatPlain;
Caroline Ticefb355112010-10-01 17:46:38 +00001526
1527 // The first (and only) argument for this command could be either a bp_id or a bp_id_range.
1528 // Push both variants into the entry for the first argument for this command.
1529 arg.push_back (bp_id_arg);
1530 arg.push_back (bp_id_range_arg);
1531
1532 // Add the entry for the first argument for this command to the object's arguments vector.
1533 m_arguments.push_back (arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001534}
1535
Jim Ingham10622a22010-06-18 00:58:52 +00001536CommandObjectBreakpointModify::~CommandObjectBreakpointModify ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001537{
1538}
1539
1540Options *
Jim Ingham10622a22010-06-18 00:58:52 +00001541CommandObjectBreakpointModify::GetOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001542{
1543 return &m_options;
1544}
1545
1546bool
Jim Ingham10622a22010-06-18 00:58:52 +00001547CommandObjectBreakpointModify::Execute
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001548(
1549 Args& command,
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001550 CommandReturnObject &result
1551)
1552{
Greg Clayton238c0a12010-09-18 01:14:36 +00001553 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001554 if (target == NULL)
1555 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001556 result.AppendError ("Invalid target. No existing target or breakpoints.");
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001557 result.SetStatus (eReturnStatusFailed);
1558 return false;
1559 }
1560
1561 Mutex::Locker locker;
1562 target->GetBreakpointList().GetListMutex(locker);
1563
1564 BreakpointIDList valid_bp_ids;
1565
1566 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1567
1568 if (result.Succeeded())
1569 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001570 const size_t count = valid_bp_ids.GetSize();
1571 for (size_t i = 0; i < count; ++i)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001572 {
1573 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1574
1575 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1576 {
1577 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1578 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1579 {
1580 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
1581 if (location)
1582 {
Jim Ingham9a7b2912010-12-03 23:04:19 +00001583 if (m_options.m_thread_id_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001584 location->SetThreadID (m_options.m_thread_id);
1585
Jim Ingham9a7b2912010-12-03 23:04:19 +00001586 if (m_options.m_thread_index_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001587 location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1588
Jim Inghamd4571222010-06-19 04:35:20 +00001589 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001590 location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1591
Jim Inghamd4571222010-06-19 04:35:20 +00001592 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001593 location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1594
Greg Clayton54e7afa2010-07-09 20:39:50 +00001595 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001596 location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001597
1598 if (m_options.m_enable_passed)
1599 location->SetEnabled (m_options.m_enable_value);
Jim Inghamd1686902010-10-14 23:45:03 +00001600
1601 if (m_options.m_condition_passed)
1602 location->SetCondition (m_options.m_condition.c_str());
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001603 }
1604 }
1605 else
1606 {
Jim Ingham9a7b2912010-12-03 23:04:19 +00001607 if (m_options.m_thread_id_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001608 bp->SetThreadID (m_options.m_thread_id);
1609
Jim Ingham9a7b2912010-12-03 23:04:19 +00001610 if (m_options.m_thread_index_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001611 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1612
Jim Inghamd4571222010-06-19 04:35:20 +00001613 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001614 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1615
Jim Inghamd4571222010-06-19 04:35:20 +00001616 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001617 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1618
Greg Clayton54e7afa2010-07-09 20:39:50 +00001619 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001620 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001621
1622 if (m_options.m_enable_passed)
1623 bp->SetEnabled (m_options.m_enable_value);
Jim Inghamd1686902010-10-14 23:45:03 +00001624
1625 if (m_options.m_condition_passed)
1626 bp->SetCondition (m_options.m_condition.c_str());
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001627 }
1628 }
1629 }
1630 }
1631
1632 return result.Succeeded();
1633}
1634
1635