blob: cc2051d318451bbc4c7daaefeb03ab230e8f2021 [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 (),
Jim Ingham03c8ee52011-09-21 01:17:13 +000059 m_source_text_regexp(),
Chris Lattner24943d22010-06-08 16:52:24 +000060 m_modules (),
Jim Ingham3c7b5b92010-06-16 02:00:15 +000061 m_load_addr(),
Greg Clayton54e7afa2010-07-09 20:39:50 +000062 m_ignore_count (0),
Jim Ingham3c7b5b92010-06-16 02:00:15 +000063 m_thread_id(LLDB_INVALID_THREAD_ID),
Greg Clayton54e7afa2010-07-09 20:39:50 +000064 m_thread_index (UINT32_MAX),
Jim Ingham3c7b5b92010-06-16 02:00:15 +000065 m_thread_name(),
Greg Clayton54e7afa2010-07-09 20:39:50 +000066 m_queue_name()
Chris Lattner24943d22010-06-08 16:52:24 +000067{
Chris Lattner24943d22010-06-08 16:52:24 +000068}
69
70CommandObjectBreakpointSet::CommandOptions::~CommandOptions ()
71{
72}
73
Greg Claytonb3448432011-03-24 21:19:54 +000074OptionDefinition
Chris Lattner24943d22010-06-08 16:52:24 +000075CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
76{
Caroline Tice4d6675c2010-10-01 19:59:14 +000077 { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
Jim Ingham34e9a982010-06-15 18:47:14 +000078 "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."},
79
Caroline Tice4d6675c2010-10-01 19:59:14 +000080 { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount,
81 "Set the number of times this breakpoint is skipped before stopping." },
Jim Ingham3c7b5b92010-06-16 02:00:15 +000082
Caroline Tice4d6675c2010-10-01 19:59:14 +000083 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex,
Greg Claytonfe424a92010-09-18 03:37:20 +000084 "The breakpoint stops only for the thread whose index matches this argument."},
Jim Ingham3c7b5b92010-06-16 02:00:15 +000085
Caroline Tice4d6675c2010-10-01 19:59:14 +000086 { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, eArgTypeThreadID,
Jim Ingham3c7b5b92010-06-16 02:00:15 +000087 "The breakpoint stops only for the thread whose TID matches this argument."},
88
Caroline Tice4d6675c2010-10-01 19:59:14 +000089 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, eArgTypeThreadName,
Jim Ingham3c7b5b92010-06-16 02:00:15 +000090 "The breakpoint stops only for the thread whose thread name matches this argument."},
91
Caroline Tice4d6675c2010-10-01 19:59:14 +000092 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, eArgTypeQueueName,
Jim Ingham3c7b5b92010-06-16 02:00:15 +000093 "The breakpoint stops only for threads in the queue whose name is given by this argument."},
94
Jim Ingham03c8ee52011-09-21 01:17:13 +000095 { LLDB_OPT_SET_1 | LLDB_OPT_SET_9, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
Chris Lattner24943d22010-06-08 16:52:24 +000096 "Set the breakpoint by source location in this particular file."},
97
Caroline Tice4d6675c2010-10-01 19:59:14 +000098 { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
Chris Lattner24943d22010-06-08 16:52:24 +000099 "Set the breakpoint by source location at this particular line."},
100
Chris Lattner24943d22010-06-08 16:52:24 +0000101 // Comment out this option for the moment, as we don't actually use it, but will in the future.
102 // This way users won't see it, but the infrastructure is left in place.
103 // { 0, false, "column", 'c', required_argument, NULL, "<column>",
104 // "Set the breakpoint by source location at this particular column."},
105
Caroline Tice4d6675c2010-10-01 19:59:14 +0000106 { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress,
Chris Lattner24943d22010-06-08 16:52:24 +0000107 "Set the breakpoint by address, at the specified address."},
108
Caroline Tice4d6675c2010-10-01 19:59:14 +0000109 { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Greg Clayton48fbdf72010-10-12 04:29:14 +0000110 "Set the breakpoint by function name." },
Chris Lattner24943d22010-06-08 16:52:24 +0000111
Caroline Tice4d6675c2010-10-01 19:59:14 +0000112 { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
Jim Inghamd9e2b762010-08-26 23:56:11 +0000113 "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguemnts, and "
114 "for Objective C this means a full function prototype with class and selector." },
Greg Clayton12bec712010-06-28 21:30:43 +0000115
Caroline Tice4d6675c2010-10-01 19:59:14 +0000116 { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector,
Jim Inghamd9e2b762010-08-26 23:56:11 +0000117 "Set the breakpoint by ObjC selector name." },
Greg Clayton12bec712010-06-28 21:30:43 +0000118
Caroline Tice4d6675c2010-10-01 19:59:14 +0000119 { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod,
Jim Inghamd9e2b762010-08-26 23:56:11 +0000120 "Set the breakpoint by C++ method names." },
Greg Clayton12bec712010-06-28 21:30:43 +0000121
Caroline Tice4d6675c2010-10-01 19:59:14 +0000122 { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression,
Chris Lattner24943d22010-06-08 16:52:24 +0000123 "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
124
Greg Clayton48fbdf72010-10-12 04:29:14 +0000125 { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
126 "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored)." },
127
Jim Ingham03c8ee52011-09-21 01:17:13 +0000128 { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', required_argument, NULL, 0, eArgTypeRegularExpression,
129 "Set the breakpoint specifying a regular expression to match a pattern in the source text in a given source file." },
130
131
Caroline Tice4d6675c2010-10-01 19:59:14 +0000132 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000133};
134
Greg Claytonb3448432011-03-24 21:19:54 +0000135const OptionDefinition*
Chris Lattner24943d22010-06-08 16:52:24 +0000136CommandObjectBreakpointSet::CommandOptions::GetDefinitions ()
137{
138 return g_option_table;
139}
140
141Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000142CommandObjectBreakpointSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Chris Lattner24943d22010-06-08 16:52:24 +0000143{
144 Error error;
145 char short_option = (char) m_getopt_table[option_idx].val;
146
147 switch (short_option)
148 {
149 case 'a':
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000150 m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0);
Chris Lattner24943d22010-06-08 16:52:24 +0000151 if (m_load_addr == LLDB_INVALID_ADDRESS)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000152 m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16);
Chris Lattner24943d22010-06-08 16:52:24 +0000153
154 if (m_load_addr == LLDB_INVALID_ADDRESS)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000155 error.SetErrorStringWithFormat ("Invalid address string '%s'.\n", option_arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000156 break;
157
158 case 'c':
159 m_column = Args::StringToUInt32 (option_arg, 0);
160 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000161
Chris Lattner24943d22010-06-08 16:52:24 +0000162 case 'f':
Greg Clayton889fbd02011-03-26 19:14:58 +0000163 m_filename.assign (option_arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000164 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000165
Chris Lattner24943d22010-06-08 16:52:24 +0000166 case 'l':
167 m_line_num = Args::StringToUInt32 (option_arg, 0);
168 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000169
Greg Clayton48fbdf72010-10-12 04:29:14 +0000170 case 'b':
Greg Clayton889fbd02011-03-26 19:14:58 +0000171 m_func_name.assign (option_arg);
Greg Clayton12bec712010-06-28 21:30:43 +0000172 m_func_name_type_mask |= eFunctionNameTypeBase;
173 break;
174
Greg Clayton48fbdf72010-10-12 04:29:14 +0000175 case 'n':
Greg Clayton889fbd02011-03-26 19:14:58 +0000176 m_func_name.assign (option_arg);
Greg Clayton48fbdf72010-10-12 04:29:14 +0000177 m_func_name_type_mask |= eFunctionNameTypeAuto;
178 break;
179
Greg Clayton12bec712010-06-28 21:30:43 +0000180 case 'F':
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 |= eFunctionNameTypeFull;
183 break;
184
185 case 'S':
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 |= eFunctionNameTypeSelector;
188 break;
189
Jim Inghamd9e2b762010-08-26 23:56:11 +0000190 case 'M':
Greg Clayton889fbd02011-03-26 19:14:58 +0000191 m_func_name.assign (option_arg);
Greg Clayton12bec712010-06-28 21:30:43 +0000192 m_func_name_type_mask |= eFunctionNameTypeMethod;
193 break;
194
Jim Ingham03c8ee52011-09-21 01:17:13 +0000195 case 'p':
196 m_source_text_regexp.assign (option_arg);
197 break;
198
Chris Lattner24943d22010-06-08 16:52:24 +0000199 case 'r':
Greg Clayton889fbd02011-03-26 19:14:58 +0000200 m_func_regexp.assign (option_arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000201 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000202
Chris Lattner24943d22010-06-08 16:52:24 +0000203 case 's':
204 {
205 m_modules.push_back (std::string (option_arg));
206 break;
207 }
Greg Claytonfe424a92010-09-18 03:37:20 +0000208 case 'i':
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000209 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000210 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Greg Clayton54e7afa2010-07-09 20:39:50 +0000211 if (m_ignore_count == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000212 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000213 }
Jim Ingham10622a22010-06-18 00:58:52 +0000214 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000215 case 't' :
216 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000217 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000218 if (m_thread_id == LLDB_INVALID_THREAD_ID)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000219 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000220 }
221 break;
222 case 'T':
Greg Clayton889fbd02011-03-26 19:14:58 +0000223 m_thread_name.assign (option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000224 break;
225 case 'q':
Greg Clayton889fbd02011-03-26 19:14:58 +0000226 m_queue_name.assign (option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000227 break;
228 case 'x':
229 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000230 m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Greg Clayton54e7afa2010-07-09 20:39:50 +0000231 if (m_thread_id == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000232 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000233
234 }
235 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000236 default:
237 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
238 break;
239 }
240
241 return error;
242}
243
244void
Greg Clayton143fcc32011-04-13 00:18:08 +0000245CommandObjectBreakpointSet::CommandOptions::OptionParsingStarting ()
Chris Lattner24943d22010-06-08 16:52:24 +0000246{
Chris Lattner24943d22010-06-08 16:52:24 +0000247 m_filename.clear();
248 m_line_num = 0;
249 m_column = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000250 m_func_name.clear();
Greg Clayton12bec712010-06-28 21:30:43 +0000251 m_func_name_type_mask = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000252 m_func_regexp.clear();
253 m_load_addr = LLDB_INVALID_ADDRESS;
254 m_modules.clear();
Greg Clayton54e7afa2010-07-09 20:39:50 +0000255 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000256 m_thread_id = LLDB_INVALID_THREAD_ID;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000257 m_thread_index = UINT32_MAX;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000258 m_thread_name.clear();
259 m_queue_name.clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000260}
261
262//-------------------------------------------------------------------------
263// CommandObjectBreakpointSet
264//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000265#pragma mark Set
Chris Lattner24943d22010-06-08 16:52:24 +0000266
Greg Clayton238c0a12010-09-18 01:14:36 +0000267CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
268 CommandObject (interpreter,
269 "breakpoint set",
270 "Sets a breakpoint or set of breakpoints in the executable.",
Greg Claytonf15996e2011-04-07 22:46:35 +0000271 "breakpoint set <cmd-options>"),
272 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000273{
274}
275
276CommandObjectBreakpointSet::~CommandObjectBreakpointSet ()
277{
278}
279
280Options *
281CommandObjectBreakpointSet::GetOptions ()
282{
283 return &m_options;
284}
285
286bool
Jim Ingham03c8ee52011-09-21 01:17:13 +0000287CommandObjectBreakpointSet::ChooseFile (Target *target, FileSpec &file, CommandReturnObject &result)
288{
289 if (m_options.m_filename.empty())
290 {
291 uint32_t default_line;
292 // First use the Source Manager's default file.
293 // Then use the current stack frame's file.
294 if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line))
295 {
296 StackFrame *cur_frame = m_interpreter.GetExecutionContext().frame;
297 if (cur_frame == NULL)
298 {
299 result.AppendError ("Attempting to set breakpoint by line number alone with no selected frame.");
300 result.SetStatus (eReturnStatusFailed);
301 return false;
302 }
303 else if (!cur_frame->HasDebugInformation())
304 {
305 result.AppendError ("Attempting to set breakpoint by line number alone but selected frame has no debug info.");
306 result.SetStatus (eReturnStatusFailed);
307 return false;
308 }
309 else
310 {
311 const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
312 if (sc.line_entry.file)
313 {
314 file = sc.line_entry.file;
315 }
316 else
317 {
318 result.AppendError ("Attempting to set breakpoint by line number alone but can't find the file for the selected frame.");
319 result.SetStatus (eReturnStatusFailed);
320 return false;
321 }
322 }
323 }
324 }
325 else
326 {
327 file.SetFile(m_options.m_filename.c_str(), false);
328 }
329 return true;
330}
331
332bool
Chris Lattner24943d22010-06-08 16:52:24 +0000333CommandObjectBreakpointSet::Execute
334(
335 Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000336 CommandReturnObject &result
337)
338{
Greg Clayton238c0a12010-09-18 01:14:36 +0000339 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000340 if (target == NULL)
341 {
Greg Claytone1f50b92011-05-03 22:09:39 +0000342 result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command).");
Chris Lattner24943d22010-06-08 16:52:24 +0000343 result.SetStatus (eReturnStatusFailed);
344 return false;
345 }
346
347 // The following are the various types of breakpoints that could be set:
348 // 1). -f -l -p [-s -g] (setting breakpoint by source location)
349 // 2). -a [-s -g] (setting breakpoint by address)
350 // 3). -n [-s -g] (setting breakpoint by function name)
351 // 4). -r [-s -g] (setting breakpoint by function name regular expression)
Jim Ingham03c8ee52011-09-21 01:17:13 +0000352 // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text)
Chris Lattner24943d22010-06-08 16:52:24 +0000353
354 BreakpointSetType break_type = eSetTypeInvalid;
355
356 if (m_options.m_line_num != 0)
357 break_type = eSetTypeFileAndLine;
358 else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
359 break_type = eSetTypeAddress;
360 else if (!m_options.m_func_name.empty())
361 break_type = eSetTypeFunctionName;
362 else if (!m_options.m_func_regexp.empty())
363 break_type = eSetTypeFunctionRegexp;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000364 else if (!m_options.m_source_text_regexp.empty())
365 break_type = eSetTypeSourceRegexp;
Chris Lattner24943d22010-06-08 16:52:24 +0000366
Chris Lattner24943d22010-06-08 16:52:24 +0000367 Breakpoint *bp = NULL;
Greg Clayton537a7a82010-10-20 20:54:39 +0000368 FileSpec module_spec;
Chris Lattner24943d22010-06-08 16:52:24 +0000369 bool use_module = false;
370 int num_modules = m_options.m_modules.size();
371
Jim Ingham03c8ee52011-09-21 01:17:13 +0000372 FileSpecList module_spec_list;
373 FileSpecList *module_spec_list_ptr = NULL;
374
Chris Lattner24943d22010-06-08 16:52:24 +0000375 if ((num_modules > 0) && (break_type != eSetTypeAddress))
376 use_module = true;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000377
378 if (use_module)
379 {
380 module_spec_list_ptr = &module_spec_list;
381 for (int i = 0; i < num_modules; ++i)
382 {
383 module_spec.SetFile(m_options.m_modules[i].c_str(), false);
384 module_spec_list.AppendIfUnique (module_spec);
385 }
386 }
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000387
Chris Lattner24943d22010-06-08 16:52:24 +0000388 switch (break_type)
389 {
390 case eSetTypeFileAndLine: // Breakpoint by source position
Chris Lattner24943d22010-06-08 16:52:24 +0000391 {
Greg Clayton887aa282010-10-11 01:05:37 +0000392 FileSpec file;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000393 if (!ChooseFile (target, file, result))
394 break;
395
396 bp = target->CreateBreakpoint (module_spec_list_ptr,
397 file,
398 m_options.m_line_num,
399 m_options.m_check_inlines).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000400 }
Greg Clayton887aa282010-10-11 01:05:37 +0000401 break;
402
Chris Lattner24943d22010-06-08 16:52:24 +0000403 case eSetTypeAddress: // Breakpoint by address
404 bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
405 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000406
Chris Lattner24943d22010-06-08 16:52:24 +0000407 case eSetTypeFunctionName: // Breakpoint by function name
Chris Lattner24943d22010-06-08 16:52:24 +0000408 {
Greg Clayton12bec712010-06-28 21:30:43 +0000409 uint32_t name_type_mask = m_options.m_func_name_type_mask;
410
411 if (name_type_mask == 0)
Greg Clayton48fbdf72010-10-12 04:29:14 +0000412 name_type_mask = eFunctionNameTypeAuto;
413
Jim Ingham03c8ee52011-09-21 01:17:13 +0000414 bp = target->CreateBreakpoint (module_spec_list_ptr,
415 m_options.m_func_name.c_str(),
416 name_type_mask,
417 Breakpoint::Exact).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000418 }
Chris Lattner24943d22010-06-08 16:52:24 +0000419 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000420
Chris Lattner24943d22010-06-08 16:52:24 +0000421 case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
422 {
423 RegularExpression regexp(m_options.m_func_regexp.c_str());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000424 if (!regexp.IsValid())
Chris Lattner24943d22010-06-08 16:52:24 +0000425 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000426 char err_str[1024];
427 regexp.GetErrorAsCString(err_str, sizeof(err_str));
428 result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"",
429 err_str);
430 result.SetStatus (eReturnStatusFailed);
431 return false;
Chris Lattner24943d22010-06-08 16:52:24 +0000432 }
Jim Ingham03c8ee52011-09-21 01:17:13 +0000433 bp = target->CreateBreakpoint (module_spec_list_ptr, regexp).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000434 }
435 break;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000436 case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
437 {
438 FileSpec file;
439 if (!ChooseFile (target, file, result))
440 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000441
Jim Ingham03c8ee52011-09-21 01:17:13 +0000442 RegularExpression regexp(m_options.m_source_text_regexp.c_str());
443 if (!regexp.IsValid())
444 {
445 char err_str[1024];
446 regexp.GetErrorAsCString(err_str, sizeof(err_str));
447 result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"",
448 err_str);
449 result.SetStatus (eReturnStatusFailed);
450 return false;
451 }
452 bp = target->CreateBreakpoint (module_spec_list_ptr, file, regexp).get();
453 }
454 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000455 default:
456 break;
457 }
458
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000459 // Now set the various options that were passed in:
460 if (bp)
461 {
462 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
463 bp->SetThreadID (m_options.m_thread_id);
464
Greg Clayton54e7afa2010-07-09 20:39:50 +0000465 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000466 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
467
468 if (!m_options.m_thread_name.empty())
469 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
470
471 if (!m_options.m_queue_name.empty())
472 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
473
Greg Clayton54e7afa2010-07-09 20:39:50 +0000474 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000475 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
476 }
477
Jim Ingham03c8ee52011-09-21 01:17:13 +0000478 if (bp)
Chris Lattner24943d22010-06-08 16:52:24 +0000479 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000480 Stream &output_stream = result.GetOutputStream();
Chris Lattner24943d22010-06-08 16:52:24 +0000481 output_stream.Printf ("Breakpoint created: ");
482 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
483 output_stream.EOL();
Caroline Ticecf2f3052010-10-28 16:28:56 +0000484 if (bp->GetNumLocations() == 0)
485 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000486 result.SetStatus (eReturnStatusSuccessFinishResult);
487 }
488 else if (!bp)
489 {
490 result.AppendError ("Breakpoint creation failed: No breakpoint created.");
491 result.SetStatus (eReturnStatusFailed);
492 }
493
494 return result.Succeeded();
495}
496
Chris Lattner24943d22010-06-08 16:52:24 +0000497//-------------------------------------------------------------------------
498// CommandObjectMultiwordBreakpoint
499//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000500#pragma mark MultiwordBreakpoint
Chris Lattner24943d22010-06-08 16:52:24 +0000501
Greg Clayton63094e02010-06-23 01:19:29 +0000502CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000503 CommandObjectMultiword (interpreter,
504 "breakpoint",
Jim Ingham7224aab2011-05-26 20:39:01 +0000505 "A set of commands for operating on breakpoints. Also see _regexp-break.",
Greg Clayton238c0a12010-09-18 01:14:36 +0000506 "breakpoint <command> [<command-options>]")
Chris Lattner24943d22010-06-08 16:52:24 +0000507{
508 bool status;
509
Greg Clayton238c0a12010-09-18 01:14:36 +0000510 CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000511 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
512 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
Johnny Chena62ad7c2010-10-28 17:27:46 +0000513 CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
514 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000515 CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +0000516 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000517 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +0000518
Johnny Chena62ad7c2010-10-28 17:27:46 +0000519 list_command_object->SetCommandName ("breakpoint list");
Chris Lattner24943d22010-06-08 16:52:24 +0000520 enable_command_object->SetCommandName("breakpoint enable");
521 disable_command_object->SetCommandName("breakpoint disable");
Johnny Chena62ad7c2010-10-28 17:27:46 +0000522 clear_command_object->SetCommandName("breakpoint clear");
523 delete_command_object->SetCommandName("breakpoint delete");
Jim Ingham10622a22010-06-18 00:58:52 +0000524 set_command_object->SetCommandName("breakpoint set");
Johnny Chena62ad7c2010-10-28 17:27:46 +0000525 command_command_object->SetCommandName ("breakpoint command");
526 modify_command_object->SetCommandName ("breakpoint modify");
Chris Lattner24943d22010-06-08 16:52:24 +0000527
Greg Clayton238c0a12010-09-18 01:14:36 +0000528 status = LoadSubCommand ("list", list_command_object);
529 status = LoadSubCommand ("enable", enable_command_object);
530 status = LoadSubCommand ("disable", disable_command_object);
Johnny Chena62ad7c2010-10-28 17:27:46 +0000531 status = LoadSubCommand ("clear", clear_command_object);
Greg Clayton238c0a12010-09-18 01:14:36 +0000532 status = LoadSubCommand ("delete", delete_command_object);
533 status = LoadSubCommand ("set", set_command_object);
534 status = LoadSubCommand ("command", command_command_object);
535 status = LoadSubCommand ("modify", modify_command_object);
Chris Lattner24943d22010-06-08 16:52:24 +0000536}
537
538CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
539{
540}
541
542void
543CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result,
544 BreakpointIDList *valid_ids)
545{
546 // args can be strings representing 1). integers (for breakpoint ids)
547 // 2). the full breakpoint & location canonical representation
548 // 3). the word "to" or a hyphen, representing a range (in which case there
549 // had *better* be an entry both before & after of one of the first two types.
Jim Inghamd1686902010-10-14 23:45:03 +0000550 // If args is empty, we will use the last created breakpoint (if there is one.)
Chris Lattner24943d22010-06-08 16:52:24 +0000551
552 Args temp_args;
553
Jim Inghamd1686902010-10-14 23:45:03 +0000554 if (args.GetArgumentCount() == 0)
555 {
Greg Clayton987c7eb2011-09-17 08:33:22 +0000556 if (target->GetLastCreatedBreakpoint())
Jim Inghamd1686902010-10-14 23:45:03 +0000557 {
558 valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
559 result.SetStatus (eReturnStatusSuccessFinishNoResult);
560 }
561 else
562 {
563 result.AppendError("No breakpoint specified and no last created breakpoint.");
564 result.SetStatus (eReturnStatusFailed);
565 }
566 return;
567 }
568
Chris Lattner24943d22010-06-08 16:52:24 +0000569 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
570 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
571 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
572
573 BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
574
575 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
576
Greg Clayton54e7afa2010-07-09 20:39:50 +0000577 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
Chris Lattner24943d22010-06-08 16:52:24 +0000578
579 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
580 // and put into valid_ids.
581
582 if (result.Succeeded())
583 {
584 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
585 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
586
Greg Clayton54e7afa2010-07-09 20:39:50 +0000587 const size_t count = valid_ids->GetSize();
588 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000589 {
590 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
591 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
592 if (breakpoint != NULL)
593 {
594 int num_locations = breakpoint->GetNumLocations();
595 if (cur_bp_id.GetLocationID() > num_locations)
596 {
597 StreamString id_str;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000598 BreakpointID::GetCanonicalReference (&id_str,
599 cur_bp_id.GetBreakpointID(),
600 cur_bp_id.GetLocationID());
601 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000602 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
603 id_str.GetData());
604 result.SetStatus (eReturnStatusFailed);
605 }
606 }
607 else
608 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000609 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000610 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
611 result.SetStatus (eReturnStatusFailed);
612 }
613 }
614 }
615}
616
617//-------------------------------------------------------------------------
618// CommandObjectBreakpointList::Options
619//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000620#pragma mark List::CommandOptions
Chris Lattner24943d22010-06-08 16:52:24 +0000621
Greg Claytonf15996e2011-04-07 22:46:35 +0000622CommandObjectBreakpointList::CommandOptions::CommandOptions(CommandInterpreter &interpreter) :
623 Options (interpreter),
Caroline Tice41950cc2011-02-04 22:59:41 +0000624 m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions
Chris Lattner24943d22010-06-08 16:52:24 +0000625{
Chris Lattner24943d22010-06-08 16:52:24 +0000626}
627
628CommandObjectBreakpointList::CommandOptions::~CommandOptions ()
629{
630}
631
Greg Claytonb3448432011-03-24 21:19:54 +0000632OptionDefinition
Chris Lattner24943d22010-06-08 16:52:24 +0000633CommandObjectBreakpointList::CommandOptions::g_option_table[] =
634{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000635 { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone,
Jim Ingham34e9a982010-06-15 18:47:14 +0000636 "Show debugger internal breakpoints" },
637
Caroline Tice4d6675c2010-10-01 19:59:14 +0000638 { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000639 "Give a brief description of the breakpoint (no location info)."},
640
641 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
642 // But I need to see it for now, and don't want to wait.
Caroline Tice4d6675c2010-10-01 19:59:14 +0000643 { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000644 "Give a full description of the breakpoint and its locations."},
Chris Lattner24943d22010-06-08 16:52:24 +0000645
Caroline Tice4d6675c2010-10-01 19:59:14 +0000646 { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000647 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
Chris Lattner24943d22010-06-08 16:52:24 +0000648
Caroline Tice4d6675c2010-10-01 19:59:14 +0000649 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000650};
651
Greg Claytonb3448432011-03-24 21:19:54 +0000652const OptionDefinition*
Chris Lattner24943d22010-06-08 16:52:24 +0000653CommandObjectBreakpointList::CommandOptions::GetDefinitions ()
654{
655 return g_option_table;
656}
657
658Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000659CommandObjectBreakpointList::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Chris Lattner24943d22010-06-08 16:52:24 +0000660{
661 Error error;
662 char short_option = (char) m_getopt_table[option_idx].val;
663
664 switch (short_option)
665 {
666 case 'b':
667 m_level = lldb::eDescriptionLevelBrief;
668 break;
669 case 'f':
670 m_level = lldb::eDescriptionLevelFull;
671 break;
672 case 'v':
673 m_level = lldb::eDescriptionLevelVerbose;
674 break;
675 case 'i':
676 m_internal = true;
677 break;
678 default:
679 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
680 break;
681 }
682
683 return error;
684}
685
686void
Greg Clayton143fcc32011-04-13 00:18:08 +0000687CommandObjectBreakpointList::CommandOptions::OptionParsingStarting ()
Chris Lattner24943d22010-06-08 16:52:24 +0000688{
Jim Inghamdc259052011-05-17 01:21:41 +0000689 m_level = lldb::eDescriptionLevelFull;
Chris Lattner24943d22010-06-08 16:52:24 +0000690 m_internal = false;
691}
692
693//-------------------------------------------------------------------------
694// CommandObjectBreakpointList
695//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000696#pragma mark List
Chris Lattner24943d22010-06-08 16:52:24 +0000697
Greg Clayton238c0a12010-09-18 01:14:36 +0000698CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) :
699 CommandObject (interpreter,
700 "breakpoint list",
701 "List some or all breakpoints at configurable levels of detail.",
Greg Claytonf15996e2011-04-07 22:46:35 +0000702 NULL),
703 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000704{
Caroline Ticefb355112010-10-01 17:46:38 +0000705 CommandArgumentEntry arg;
706 CommandArgumentData bp_id_arg;
707
708 // Define the first (and only) variant of this arg.
709 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +0000710 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000711
712 // There is only one variant this argument could be; put it into the argument entry.
713 arg.push_back (bp_id_arg);
714
715 // Push the data for the first argument into the m_arguments vector.
716 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000717}
718
719CommandObjectBreakpointList::~CommandObjectBreakpointList ()
720{
721}
722
723Options *
724CommandObjectBreakpointList::GetOptions ()
725{
726 return &m_options;
727}
728
729bool
730CommandObjectBreakpointList::Execute
731(
732 Args& args,
Chris Lattner24943d22010-06-08 16:52:24 +0000733 CommandReturnObject &result
734)
735{
Greg Clayton238c0a12010-09-18 01:14:36 +0000736 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000737 if (target == NULL)
738 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000739 result.AppendError ("Invalid target. No current target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000740 result.SetStatus (eReturnStatusSuccessFinishNoResult);
741 return true;
742 }
743
744 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000745 Mutex::Locker locker;
746 target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
747
Chris Lattner24943d22010-06-08 16:52:24 +0000748 size_t num_breakpoints = breakpoints.GetSize();
749
750 if (num_breakpoints == 0)
751 {
752 result.AppendMessage ("No breakpoints currently set.");
753 result.SetStatus (eReturnStatusSuccessFinishNoResult);
754 return true;
755 }
756
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000757 Stream &output_stream = result.GetOutputStream();
Chris Lattner24943d22010-06-08 16:52:24 +0000758
759 if (args.GetArgumentCount() == 0)
760 {
761 // No breakpoint selected; show info about all currently set breakpoints.
762 result.AppendMessage ("Current breakpoints:");
Greg Clayton54e7afa2010-07-09 20:39:50 +0000763 for (size_t i = 0; i < num_breakpoints; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000764 {
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000765 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000766 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000767 }
768 result.SetStatus (eReturnStatusSuccessFinishNoResult);
769 }
770 else
771 {
772 // Particular breakpoints selected; show info about that breakpoint.
773 BreakpointIDList valid_bp_ids;
774 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
775
776 if (result.Succeeded())
777 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000778 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000779 {
780 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
781 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000782 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000783 }
784 result.SetStatus (eReturnStatusSuccessFinishNoResult);
785 }
786 else
787 {
788 result.AppendError ("Invalid breakpoint id.");
789 result.SetStatus (eReturnStatusFailed);
790 }
791 }
792
793 return result.Succeeded();
794}
795
796//-------------------------------------------------------------------------
797// CommandObjectBreakpointEnable
798//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000799#pragma mark Enable
Chris Lattner24943d22010-06-08 16:52:24 +0000800
Greg Clayton238c0a12010-09-18 01:14:36 +0000801CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
802 CommandObject (interpreter,
803 "enable",
Caroline Ticefb355112010-10-01 17:46:38 +0000804 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
805 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000806{
Caroline Ticefb355112010-10-01 17:46:38 +0000807 CommandArgumentEntry arg;
Johnny Chen0576c242011-09-21 01:00:02 +0000808 CommandObject::AddIDsArgumentData(arg);
Caroline Ticefb355112010-10-01 17:46:38 +0000809 // Add the entry for the first argument for this command to the object's arguments vector.
810 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000811}
812
813
814CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable ()
815{
816}
817
818
819bool
Greg Clayton63094e02010-06-23 01:19:29 +0000820CommandObjectBreakpointEnable::Execute
821(
Greg Clayton63094e02010-06-23 01:19:29 +0000822 Args& args,
823 CommandReturnObject &result
824)
Chris Lattner24943d22010-06-08 16:52:24 +0000825{
Greg Clayton238c0a12010-09-18 01:14:36 +0000826 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000827 if (target == NULL)
828 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000829 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000830 result.SetStatus (eReturnStatusFailed);
831 return false;
832 }
833
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000834 Mutex::Locker locker;
835 target->GetBreakpointList().GetListMutex(locker);
836
Chris Lattner24943d22010-06-08 16:52:24 +0000837 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000838
Chris Lattner24943d22010-06-08 16:52:24 +0000839 size_t num_breakpoints = breakpoints.GetSize();
840
841 if (num_breakpoints == 0)
842 {
843 result.AppendError ("No breakpoints exist to be enabled.");
844 result.SetStatus (eReturnStatusFailed);
845 return false;
846 }
847
848 if (args.GetArgumentCount() == 0)
849 {
850 // No breakpoint selected; enable all currently set breakpoints.
851 target->EnableAllBreakpoints ();
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000852 result.AppendMessageWithFormat ("All breakpoints enabled. (%lu breakpoints)\n", num_breakpoints);
Chris Lattner24943d22010-06-08 16:52:24 +0000853 result.SetStatus (eReturnStatusSuccessFinishNoResult);
854 }
855 else
856 {
857 // Particular breakpoint selected; enable that breakpoint.
858 BreakpointIDList valid_bp_ids;
859 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
860
861 if (result.Succeeded())
862 {
863 int enable_count = 0;
864 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000865 const size_t count = valid_bp_ids.GetSize();
866 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000867 {
868 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
869
870 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
871 {
872 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
873 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
874 {
875 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
876 if (location)
877 {
878 location->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000879 ++loc_count;
880 }
881 }
882 else
883 {
Jim Ingham10622a22010-06-18 00:58:52 +0000884 breakpoint->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000885 ++enable_count;
Chris Lattner24943d22010-06-08 16:52:24 +0000886 }
887 }
888 }
889 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
890 result.SetStatus (eReturnStatusSuccessFinishNoResult);
891 }
892 }
893
894 return result.Succeeded();
895}
896
897//-------------------------------------------------------------------------
898// CommandObjectBreakpointDisable
899//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000900#pragma mark Disable
Chris Lattner24943d22010-06-08 16:52:24 +0000901
Greg Clayton238c0a12010-09-18 01:14:36 +0000902CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
903 CommandObject (interpreter,
Caroline Ticefb355112010-10-01 17:46:38 +0000904 "breakpoint disable",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000905 "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.",
Caroline Ticefb355112010-10-01 17:46:38 +0000906 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000907{
Caroline Ticefb355112010-10-01 17:46:38 +0000908 CommandArgumentEntry arg;
Johnny Chen0576c242011-09-21 01:00:02 +0000909 CommandObject::AddIDsArgumentData(arg);
Caroline Ticefb355112010-10-01 17:46:38 +0000910 // Add the entry for the first argument for this command to the object's arguments vector.
911 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000912}
913
914CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable ()
915{
916}
917
918bool
Greg Clayton63094e02010-06-23 01:19:29 +0000919CommandObjectBreakpointDisable::Execute
920(
Greg Clayton63094e02010-06-23 01:19:29 +0000921 Args& args,
922 CommandReturnObject &result
923)
Chris Lattner24943d22010-06-08 16:52:24 +0000924{
Greg Clayton238c0a12010-09-18 01:14:36 +0000925 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000926 if (target == NULL)
927 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000928 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000929 result.SetStatus (eReturnStatusFailed);
930 return false;
931 }
932
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000933 Mutex::Locker locker;
934 target->GetBreakpointList().GetListMutex(locker);
935
Chris Lattner24943d22010-06-08 16:52:24 +0000936 const BreakpointList &breakpoints = target->GetBreakpointList();
937 size_t num_breakpoints = breakpoints.GetSize();
938
939 if (num_breakpoints == 0)
940 {
941 result.AppendError ("No breakpoints exist to be disabled.");
942 result.SetStatus (eReturnStatusFailed);
943 return false;
944 }
945
946 if (args.GetArgumentCount() == 0)
947 {
948 // No breakpoint selected; disable all currently set breakpoints.
949 target->DisableAllBreakpoints ();
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000950 result.AppendMessageWithFormat ("All breakpoints disabled. (%lu breakpoints)\n", num_breakpoints);
Chris Lattner24943d22010-06-08 16:52:24 +0000951 result.SetStatus (eReturnStatusSuccessFinishNoResult);
952 }
953 else
954 {
955 // Particular breakpoint selected; disable that breakpoint.
956 BreakpointIDList valid_bp_ids;
957
958 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
959
960 if (result.Succeeded())
961 {
962 int disable_count = 0;
963 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000964 const size_t count = valid_bp_ids.GetSize();
965 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000966 {
967 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
968
969 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
970 {
971 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
972 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
973 {
974 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
975 if (location)
976 {
977 location->SetEnabled (false);
978 ++loc_count;
979 }
980 }
981 else
982 {
Jim Ingham10622a22010-06-18 00:58:52 +0000983 breakpoint->SetEnabled (false);
Chris Lattner24943d22010-06-08 16:52:24 +0000984 ++disable_count;
Chris Lattner24943d22010-06-08 16:52:24 +0000985 }
986 }
987 }
988 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
989 result.SetStatus (eReturnStatusSuccessFinishNoResult);
990 }
991 }
992
993 return result.Succeeded();
994}
995
996//-------------------------------------------------------------------------
Johnny Chena62ad7c2010-10-28 17:27:46 +0000997// CommandObjectBreakpointClear::CommandOptions
998//-------------------------------------------------------------------------
999#pragma mark Clear::CommandOptions
1000
Greg Claytonf15996e2011-04-07 22:46:35 +00001001CommandObjectBreakpointClear::CommandOptions::CommandOptions(CommandInterpreter &interpreter) :
1002 Options (interpreter),
Johnny Chena62ad7c2010-10-28 17:27:46 +00001003 m_filename (),
1004 m_line_num (0)
1005{
1006}
1007
1008CommandObjectBreakpointClear::CommandOptions::~CommandOptions ()
1009{
1010}
1011
Greg Claytonb3448432011-03-24 21:19:54 +00001012OptionDefinition
Johnny Chena62ad7c2010-10-28 17:27:46 +00001013CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
1014{
1015 { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
1016 "Specify the breakpoint by source location in this particular file."},
1017
1018 { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
1019 "Specify the breakpoint by source location at this particular line."},
1020
1021 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1022};
1023
Greg Claytonb3448432011-03-24 21:19:54 +00001024const OptionDefinition*
Johnny Chena62ad7c2010-10-28 17:27:46 +00001025CommandObjectBreakpointClear::CommandOptions::GetDefinitions ()
1026{
1027 return g_option_table;
1028}
1029
1030Error
Greg Clayton143fcc32011-04-13 00:18:08 +00001031CommandObjectBreakpointClear::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Johnny Chena62ad7c2010-10-28 17:27:46 +00001032{
1033 Error error;
1034 char short_option = (char) m_getopt_table[option_idx].val;
1035
1036 switch (short_option)
1037 {
1038 case 'f':
Greg Clayton889fbd02011-03-26 19:14:58 +00001039 m_filename.assign (option_arg);
Johnny Chena62ad7c2010-10-28 17:27:46 +00001040 break;
1041
1042 case 'l':
1043 m_line_num = Args::StringToUInt32 (option_arg, 0);
1044 break;
1045
1046 default:
1047 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1048 break;
1049 }
1050
1051 return error;
1052}
1053
1054void
Greg Clayton143fcc32011-04-13 00:18:08 +00001055CommandObjectBreakpointClear::CommandOptions::OptionParsingStarting ()
Johnny Chena62ad7c2010-10-28 17:27:46 +00001056{
Johnny Chena62ad7c2010-10-28 17:27:46 +00001057 m_filename.clear();
1058 m_line_num = 0;
1059}
1060
1061//-------------------------------------------------------------------------
1062// CommandObjectBreakpointClear
1063//-------------------------------------------------------------------------
1064#pragma mark Clear
1065
1066CommandObjectBreakpointClear::CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
1067 CommandObject (interpreter,
1068 "breakpoint clear",
1069 "Clears a breakpoint or set of breakpoints in the executable.",
Greg Claytonf15996e2011-04-07 22:46:35 +00001070 "breakpoint clear <cmd-options>"),
1071 m_options (interpreter)
Johnny Chena62ad7c2010-10-28 17:27:46 +00001072{
1073}
1074
1075CommandObjectBreakpointClear::~CommandObjectBreakpointClear ()
1076{
1077}
1078
1079Options *
1080CommandObjectBreakpointClear::GetOptions ()
1081{
1082 return &m_options;
1083}
1084
1085bool
1086CommandObjectBreakpointClear::Execute
1087(
1088 Args& command,
1089 CommandReturnObject &result
1090)
1091{
1092 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1093 if (target == NULL)
1094 {
1095 result.AppendError ("Invalid target. No existing target or breakpoints.");
1096 result.SetStatus (eReturnStatusFailed);
1097 return false;
1098 }
1099
1100 // The following are the various types of breakpoints that could be cleared:
1101 // 1). -f -l (clearing breakpoint by source location)
1102
1103 BreakpointClearType break_type = eClearTypeInvalid;
1104
1105 if (m_options.m_line_num != 0)
1106 break_type = eClearTypeFileAndLine;
1107
1108 Mutex::Locker locker;
1109 target->GetBreakpointList().GetListMutex(locker);
1110
1111 BreakpointList &breakpoints = target->GetBreakpointList();
1112 size_t num_breakpoints = breakpoints.GetSize();
1113
1114 // Early return if there's no breakpoint at all.
1115 if (num_breakpoints == 0)
1116 {
1117 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1118 result.SetStatus (eReturnStatusFailed);
1119 return result.Succeeded();
1120 }
1121
1122 // Find matching breakpoints and delete them.
1123
1124 // First create a copy of all the IDs.
1125 std::vector<break_id_t> BreakIDs;
1126 for (size_t i = 0; i < num_breakpoints; ++i)
1127 BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID());
1128
1129 int num_cleared = 0;
1130 StreamString ss;
1131 switch (break_type)
1132 {
1133 case eClearTypeFileAndLine: // Breakpoint by source position
1134 {
1135 const ConstString filename(m_options.m_filename.c_str());
1136 BreakpointLocationCollection loc_coll;
1137
1138 for (size_t i = 0; i < num_breakpoints; ++i)
1139 {
1140 Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
1141
1142 if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
1143 {
1144 // If the collection size is 0, it's a full match and we can just remove the breakpoint.
1145 if (loc_coll.GetSize() == 0)
1146 {
1147 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
1148 ss.EOL();
1149 target->RemoveBreakpointByID (bp->GetID());
1150 ++num_cleared;
1151 }
1152 }
1153 }
1154 }
1155 break;
1156
1157 default:
1158 break;
1159 }
1160
1161 if (num_cleared > 0)
1162 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +00001163 Stream &output_stream = result.GetOutputStream();
Johnny Chena62ad7c2010-10-28 17:27:46 +00001164 output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
1165 output_stream << ss.GetData();
1166 output_stream.EOL();
1167 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1168 }
1169 else
1170 {
1171 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1172 result.SetStatus (eReturnStatusFailed);
1173 }
1174
1175 return result.Succeeded();
1176}
1177
1178//-------------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +00001179// CommandObjectBreakpointDelete
1180//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001181#pragma mark Delete
Chris Lattner24943d22010-06-08 16:52:24 +00001182
Greg Clayton238c0a12010-09-18 01:14:36 +00001183CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) :
1184 CommandObject (interpreter,
1185 "breakpoint delete",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001186 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
Caroline Ticefb355112010-10-01 17:46:38 +00001187 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +00001188{
Caroline Ticefb355112010-10-01 17:46:38 +00001189 CommandArgumentEntry arg;
Johnny Chen0576c242011-09-21 01:00:02 +00001190 CommandObject::AddIDsArgumentData(arg);
Caroline Ticefb355112010-10-01 17:46:38 +00001191 // Add the entry for the first argument for this command to the object's arguments vector.
1192 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +00001193}
1194
1195
1196CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete ()
1197{
1198}
1199
1200bool
Greg Clayton63094e02010-06-23 01:19:29 +00001201CommandObjectBreakpointDelete::Execute
1202(
Greg Clayton63094e02010-06-23 01:19:29 +00001203 Args& args,
1204 CommandReturnObject &result
1205)
Chris Lattner24943d22010-06-08 16:52:24 +00001206{
Greg Clayton238c0a12010-09-18 01:14:36 +00001207 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001208 if (target == NULL)
1209 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001210 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +00001211 result.SetStatus (eReturnStatusFailed);
1212 return false;
1213 }
1214
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001215 Mutex::Locker locker;
1216 target->GetBreakpointList().GetListMutex(locker);
1217
Chris Lattner24943d22010-06-08 16:52:24 +00001218 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001219
Chris Lattner24943d22010-06-08 16:52:24 +00001220 size_t num_breakpoints = breakpoints.GetSize();
1221
1222 if (num_breakpoints == 0)
1223 {
1224 result.AppendError ("No breakpoints exist to be deleted.");
1225 result.SetStatus (eReturnStatusFailed);
1226 return false;
1227 }
1228
1229 if (args.GetArgumentCount() == 0)
1230 {
Jim Inghamd1686902010-10-14 23:45:03 +00001231 if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
Chris Lattner24943d22010-06-08 16:52:24 +00001232 {
Jim Inghamd1686902010-10-14 23:45:03 +00001233 result.AppendMessage("Operation cancelled...");
Chris Lattner24943d22010-06-08 16:52:24 +00001234 }
Jim Inghamd1686902010-10-14 23:45:03 +00001235 else
1236 {
1237 target->RemoveAllBreakpoints ();
Jason Molenda7e5fa7f2011-09-20 21:44:10 +00001238 result.AppendMessageWithFormat ("All breakpoints removed. (%lu breakpoints)\n", num_breakpoints);
Jim Inghamd1686902010-10-14 23:45:03 +00001239 }
Chris Lattner24943d22010-06-08 16:52:24 +00001240 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1241 }
1242 else
1243 {
1244 // Particular breakpoint selected; disable that breakpoint.
1245 BreakpointIDList valid_bp_ids;
1246 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
1247
1248 if (result.Succeeded())
1249 {
1250 int delete_count = 0;
1251 int disable_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001252 const size_t count = valid_bp_ids.GetSize();
1253 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +00001254 {
1255 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1256
1257 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1258 {
1259 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1260 {
1261 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1262 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1263 // It makes no sense to try to delete individual locations, so we disable them instead.
1264 if (location)
1265 {
1266 location->SetEnabled (false);
1267 ++disable_count;
1268 }
1269 }
1270 else
1271 {
1272 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1273 ++delete_count;
1274 }
1275 }
1276 }
1277 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1278 delete_count, disable_count);
1279 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1280 }
1281 }
1282 return result.Succeeded();
1283}
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001284
1285//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001286// CommandObjectBreakpointModify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001287//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001288#pragma mark Modify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001289
Greg Claytonf15996e2011-04-07 22:46:35 +00001290CommandObjectBreakpointModify::CommandOptions::CommandOptions(CommandInterpreter &interpreter) :
1291 Options (interpreter),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001292 m_ignore_count (0),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001293 m_thread_id(LLDB_INVALID_THREAD_ID),
Jim Ingham9a7b2912010-12-03 23:04:19 +00001294 m_thread_id_passed(false),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001295 m_thread_index (UINT32_MAX),
Jim Ingham9a7b2912010-12-03 23:04:19 +00001296 m_thread_index_passed(false),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001297 m_thread_name(),
1298 m_queue_name(),
Jim Inghamd1686902010-10-14 23:45:03 +00001299 m_condition (),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001300 m_enable_passed (false),
1301 m_enable_value (false),
1302 m_name_passed (false),
Jim Inghamd1686902010-10-14 23:45:03 +00001303 m_queue_passed (false),
1304 m_condition_passed (false)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001305{
1306}
1307
Jim Ingham10622a22010-06-18 00:58:52 +00001308CommandObjectBreakpointModify::CommandOptions::~CommandOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001309{
1310}
1311
Greg Claytonb3448432011-03-24 21:19:54 +00001312OptionDefinition
Jim Ingham10622a22010-06-18 00:58:52 +00001313CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001314{
Caroline Tice4d6675c2010-10-01 19:59:14 +00001315{ LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, NULL, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." },
1316{ 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."},
1317{ 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."},
1318{ 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."},
1319{ 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 +00001320{ 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 +00001321{ LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, eArgTypeNone, "Enable the breakpoint."},
1322{ LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, eArgTypeNone, "Disable the breakpoint."},
Jim Inghamd1686902010-10-14 23:45:03 +00001323{ 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001324};
1325
Greg Claytonb3448432011-03-24 21:19:54 +00001326const OptionDefinition*
Jim Ingham10622a22010-06-18 00:58:52 +00001327CommandObjectBreakpointModify::CommandOptions::GetDefinitions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001328{
1329 return g_option_table;
1330}
1331
1332Error
Greg Clayton143fcc32011-04-13 00:18:08 +00001333CommandObjectBreakpointModify::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001334{
1335 Error error;
1336 char short_option = (char) m_getopt_table[option_idx].val;
1337
1338 switch (short_option)
1339 {
Jim Inghamd1686902010-10-14 23:45:03 +00001340 case 'c':
1341 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001342 m_condition.assign (option_arg);
Jim Inghamd1686902010-10-14 23:45:03 +00001343 else
1344 m_condition.clear();
1345 m_condition_passed = true;
1346 break;
Jim Ingham10622a22010-06-18 00:58:52 +00001347 case 'd':
1348 m_enable_passed = true;
1349 m_enable_value = false;
1350 break;
1351 case 'e':
1352 m_enable_passed = true;
1353 m_enable_value = true;
1354 break;
Greg Claytonfe424a92010-09-18 03:37:20 +00001355 case 'i':
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001356 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001357 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Greg Clayton54e7afa2010-07-09 20:39:50 +00001358 if (m_ignore_count == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001359 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001360 }
Jim Ingham10622a22010-06-18 00:58:52 +00001361 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001362 case 't' :
1363 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001364 if (option_arg[0] == '\0')
Jim Ingham9a7b2912010-12-03 23:04:19 +00001365 {
1366 m_thread_id = LLDB_INVALID_THREAD_ID;
1367 m_thread_id_passed = true;
1368 }
1369 else
1370 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001371 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001372 if (m_thread_id == LLDB_INVALID_THREAD_ID)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001373 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", option_arg);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001374 else
1375 m_thread_id_passed = true;
1376 }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001377 }
1378 break;
1379 case 'T':
Jim Inghamd4571222010-06-19 04:35:20 +00001380 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001381 m_thread_name.assign (option_arg);
Jim Inghamd4571222010-06-19 04:35:20 +00001382 else
1383 m_thread_name.clear();
1384 m_name_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001385 break;
1386 case 'q':
Jim Inghamd4571222010-06-19 04:35:20 +00001387 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001388 m_queue_name.assign (option_arg);
Jim Inghamd4571222010-06-19 04:35:20 +00001389 else
1390 m_queue_name.clear();
1391 m_queue_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001392 break;
1393 case 'x':
1394 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001395 if (option_arg[0] == '\n')
Jim Ingham9a7b2912010-12-03 23:04:19 +00001396 {
1397 m_thread_index = UINT32_MAX;
1398 m_thread_index_passed = true;
1399 }
1400 else
1401 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001402 m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001403 if (m_thread_id == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001404 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", option_arg);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001405 else
1406 m_thread_index_passed = true;
1407 }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001408 }
1409 break;
1410 default:
1411 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1412 break;
1413 }
1414
1415 return error;
1416}
1417
1418void
Greg Clayton143fcc32011-04-13 00:18:08 +00001419CommandObjectBreakpointModify::CommandOptions::OptionParsingStarting ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001420{
Greg Clayton54e7afa2010-07-09 20:39:50 +00001421 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001422 m_thread_id = LLDB_INVALID_THREAD_ID;
Jim Ingham9a7b2912010-12-03 23:04:19 +00001423 m_thread_id_passed = false;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001424 m_thread_index = UINT32_MAX;
Jim Ingham9a7b2912010-12-03 23:04:19 +00001425 m_thread_index_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001426 m_thread_name.clear();
1427 m_queue_name.clear();
Jim Inghamd1686902010-10-14 23:45:03 +00001428 m_condition.clear();
Jim Ingham10622a22010-06-18 00:58:52 +00001429 m_enable_passed = false;
Jim Inghamd4571222010-06-19 04:35:20 +00001430 m_queue_passed = false;
1431 m_name_passed = false;
Jim Inghamd1686902010-10-14 23:45:03 +00001432 m_condition_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001433}
1434
1435//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001436// CommandObjectBreakpointModify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001437//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001438#pragma mark Modify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001439
Greg Clayton238c0a12010-09-18 01:14:36 +00001440CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
1441 CommandObject (interpreter,
1442 "breakpoint modify",
Jim Ingham19ac0bd2010-12-03 22:37:19 +00001443 "Modify the options on a breakpoint or set of breakpoints in the executable. "
Jim Ingham9a7b2912010-12-03 23:04:19 +00001444 "If no breakpoint is specified, acts on the last created breakpoint. "
1445 "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
Greg Claytonf15996e2011-04-07 22:46:35 +00001446 NULL),
1447 m_options (interpreter)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001448{
Caroline Ticefb355112010-10-01 17:46:38 +00001449 CommandArgumentEntry arg;
Johnny Chen0576c242011-09-21 01:00:02 +00001450 CommandObject::AddIDsArgumentData(arg);
Caroline Ticefb355112010-10-01 17:46:38 +00001451 // Add the entry for the first argument for this command to the object's arguments vector.
1452 m_arguments.push_back (arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001453}
1454
Jim Ingham10622a22010-06-18 00:58:52 +00001455CommandObjectBreakpointModify::~CommandObjectBreakpointModify ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001456{
1457}
1458
1459Options *
Jim Ingham10622a22010-06-18 00:58:52 +00001460CommandObjectBreakpointModify::GetOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001461{
1462 return &m_options;
1463}
1464
1465bool
Jim Ingham10622a22010-06-18 00:58:52 +00001466CommandObjectBreakpointModify::Execute
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001467(
1468 Args& command,
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001469 CommandReturnObject &result
1470)
1471{
Greg Clayton238c0a12010-09-18 01:14:36 +00001472 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001473 if (target == NULL)
1474 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001475 result.AppendError ("Invalid target. No existing target or breakpoints.");
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001476 result.SetStatus (eReturnStatusFailed);
1477 return false;
1478 }
1479
1480 Mutex::Locker locker;
1481 target->GetBreakpointList().GetListMutex(locker);
1482
1483 BreakpointIDList valid_bp_ids;
1484
1485 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1486
1487 if (result.Succeeded())
1488 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001489 const size_t count = valid_bp_ids.GetSize();
1490 for (size_t i = 0; i < count; ++i)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001491 {
1492 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1493
1494 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1495 {
1496 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1497 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1498 {
1499 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
1500 if (location)
1501 {
Jim Ingham9a7b2912010-12-03 23:04:19 +00001502 if (m_options.m_thread_id_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001503 location->SetThreadID (m_options.m_thread_id);
1504
Jim Ingham9a7b2912010-12-03 23:04:19 +00001505 if (m_options.m_thread_index_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001506 location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1507
Jim Inghamd4571222010-06-19 04:35:20 +00001508 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001509 location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1510
Jim Inghamd4571222010-06-19 04:35:20 +00001511 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001512 location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1513
Greg Clayton54e7afa2010-07-09 20:39:50 +00001514 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001515 location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001516
1517 if (m_options.m_enable_passed)
1518 location->SetEnabled (m_options.m_enable_value);
Jim Inghamd1686902010-10-14 23:45:03 +00001519
1520 if (m_options.m_condition_passed)
1521 location->SetCondition (m_options.m_condition.c_str());
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001522 }
1523 }
1524 else
1525 {
Jim Ingham9a7b2912010-12-03 23:04:19 +00001526 if (m_options.m_thread_id_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001527 bp->SetThreadID (m_options.m_thread_id);
1528
Jim Ingham9a7b2912010-12-03 23:04:19 +00001529 if (m_options.m_thread_index_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001530 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1531
Jim Inghamd4571222010-06-19 04:35:20 +00001532 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001533 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1534
Jim Inghamd4571222010-06-19 04:35:20 +00001535 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001536 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1537
Greg Clayton54e7afa2010-07-09 20:39:50 +00001538 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001539 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001540
1541 if (m_options.m_enable_passed)
1542 bp->SetEnabled (m_options.m_enable_value);
Jim Inghamd1686902010-10-14 23:45:03 +00001543
1544 if (m_options.m_condition_passed)
1545 bp->SetCondition (m_options.m_condition.c_str());
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001546 }
1547 }
1548 }
1549 }
1550
1551 return result.Succeeded();
1552}
1553
1554