blob: ffff9f63c8f563a81eb8ab545d3cbcfc7e3a1988 [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),
Jim Inghamd6d47972011-09-23 00:54:11 +000052 m_filenames (),
Chris Lattner24943d22010-06-08 16:52:24 +000053 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
Jim Inghamd6d47972011-09-23 00:54:11 +000074#define LLDB_OPT_FILE (LLDB_OPT_SET_ALL & ~(LLDB_OPT_SET_2))
75
Greg Claytonb3448432011-03-24 21:19:54 +000076OptionDefinition
Chris Lattner24943d22010-06-08 16:52:24 +000077CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
78{
Caroline Tice4d6675c2010-10-01 19:59:14 +000079 { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
Jim Ingham34e9a982010-06-15 18:47:14 +000080 "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."},
81
Caroline Tice4d6675c2010-10-01 19:59:14 +000082 { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount,
83 "Set the number of times this breakpoint is skipped before stopping." },
Jim Ingham3c7b5b92010-06-16 02:00:15 +000084
Caroline Tice4d6675c2010-10-01 19:59:14 +000085 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex,
Greg Claytonfe424a92010-09-18 03:37:20 +000086 "The breakpoint stops only for the thread whose index matches this argument."},
Jim Ingham3c7b5b92010-06-16 02:00:15 +000087
Caroline Tice4d6675c2010-10-01 19:59:14 +000088 { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, eArgTypeThreadID,
Jim Ingham3c7b5b92010-06-16 02:00:15 +000089 "The breakpoint stops only for the thread whose TID matches this argument."},
90
Caroline Tice4d6675c2010-10-01 19:59:14 +000091 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, eArgTypeThreadName,
Jim Ingham3c7b5b92010-06-16 02:00:15 +000092 "The breakpoint stops only for the thread whose thread name matches this argument."},
93
Caroline Tice4d6675c2010-10-01 19:59:14 +000094 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, eArgTypeQueueName,
Jim Ingham3c7b5b92010-06-16 02:00:15 +000095 "The breakpoint stops only for threads in the queue whose name is given by this argument."},
96
Jim Inghamd6d47972011-09-23 00:54:11 +000097 { LLDB_OPT_FILE, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
98 "Specifies the source file in which to set this breakpoint."},
Chris Lattner24943d22010-06-08 16:52:24 +000099
Caroline Tice4d6675c2010-10-01 19:59:14 +0000100 { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
Jim Inghamd6d47972011-09-23 00:54:11 +0000101 "Specifies the line number on which to set this breakpoint."},
Chris Lattner24943d22010-06-08 16:52:24 +0000102
Chris Lattner24943d22010-06-08 16:52:24 +0000103 // Comment out this option for the moment, as we don't actually use it, but will in the future.
104 // This way users won't see it, but the infrastructure is left in place.
105 // { 0, false, "column", 'c', required_argument, NULL, "<column>",
106 // "Set the breakpoint by source location at this particular column."},
107
Caroline Tice4d6675c2010-10-01 19:59:14 +0000108 { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress,
Chris Lattner24943d22010-06-08 16:52:24 +0000109 "Set the breakpoint by address, at the specified address."},
110
Caroline Tice4d6675c2010-10-01 19:59:14 +0000111 { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Greg Clayton48fbdf72010-10-12 04:29:14 +0000112 "Set the breakpoint by function name." },
Chris Lattner24943d22010-06-08 16:52:24 +0000113
Caroline Tice4d6675c2010-10-01 19:59:14 +0000114 { LLDB_OPT_SET_4, true, "fullname", 'F', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
Jim Inghamd9e2b762010-08-26 23:56:11 +0000115 "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguemnts, and "
116 "for Objective C this means a full function prototype with class and selector." },
Greg Clayton12bec712010-06-28 21:30:43 +0000117
Caroline Tice4d6675c2010-10-01 19:59:14 +0000118 { LLDB_OPT_SET_5, true, "selector", 'S', required_argument, NULL, 0, eArgTypeSelector,
Jim Inghamd9e2b762010-08-26 23:56:11 +0000119 "Set the breakpoint by ObjC selector name." },
Greg Clayton12bec712010-06-28 21:30:43 +0000120
Caroline Tice4d6675c2010-10-01 19:59:14 +0000121 { LLDB_OPT_SET_6, true, "method", 'M', required_argument, NULL, 0, eArgTypeMethod,
Jim Inghamd9e2b762010-08-26 23:56:11 +0000122 "Set the breakpoint by C++ method names." },
Greg Clayton12bec712010-06-28 21:30:43 +0000123
Caroline Tice4d6675c2010-10-01 19:59:14 +0000124 { LLDB_OPT_SET_7, true, "func-regex", 'r', required_argument, NULL, 0, eArgTypeRegularExpression,
Chris Lattner24943d22010-06-08 16:52:24 +0000125 "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
126
Greg Clayton48fbdf72010-10-12 04:29:14 +0000127 { LLDB_OPT_SET_8, true, "basename", 'b', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
128 "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored)." },
129
Jim Ingham03c8ee52011-09-21 01:17:13 +0000130 { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', required_argument, NULL, 0, eArgTypeRegularExpression,
131 "Set the breakpoint specifying a regular expression to match a pattern in the source text in a given source file." },
132
133
Caroline Tice4d6675c2010-10-01 19:59:14 +0000134 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000135};
136
Greg Claytonb3448432011-03-24 21:19:54 +0000137const OptionDefinition*
Chris Lattner24943d22010-06-08 16:52:24 +0000138CommandObjectBreakpointSet::CommandOptions::GetDefinitions ()
139{
140 return g_option_table;
141}
142
143Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000144CommandObjectBreakpointSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Chris Lattner24943d22010-06-08 16:52:24 +0000145{
146 Error error;
147 char short_option = (char) m_getopt_table[option_idx].val;
148
149 switch (short_option)
150 {
151 case 'a':
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000152 m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0);
Chris Lattner24943d22010-06-08 16:52:24 +0000153 if (m_load_addr == LLDB_INVALID_ADDRESS)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000154 m_load_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16);
Chris Lattner24943d22010-06-08 16:52:24 +0000155
156 if (m_load_addr == LLDB_INVALID_ADDRESS)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000157 error.SetErrorStringWithFormat ("Invalid address string '%s'.\n", option_arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000158 break;
159
160 case 'c':
161 m_column = Args::StringToUInt32 (option_arg, 0);
162 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000163
Chris Lattner24943d22010-06-08 16:52:24 +0000164 case 'f':
Jim Inghamd6d47972011-09-23 00:54:11 +0000165 m_filenames.AppendIfUnique (FileSpec(option_arg, false));
Chris Lattner24943d22010-06-08 16:52:24 +0000166 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000167
Chris Lattner24943d22010-06-08 16:52:24 +0000168 case 'l':
169 m_line_num = Args::StringToUInt32 (option_arg, 0);
170 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000171
Greg Clayton48fbdf72010-10-12 04:29:14 +0000172 case 'b':
Greg Clayton889fbd02011-03-26 19:14:58 +0000173 m_func_name.assign (option_arg);
Greg Clayton12bec712010-06-28 21:30:43 +0000174 m_func_name_type_mask |= eFunctionNameTypeBase;
175 break;
176
Greg Clayton48fbdf72010-10-12 04:29:14 +0000177 case 'n':
Greg Clayton889fbd02011-03-26 19:14:58 +0000178 m_func_name.assign (option_arg);
Greg Clayton48fbdf72010-10-12 04:29:14 +0000179 m_func_name_type_mask |= eFunctionNameTypeAuto;
180 break;
181
Greg Clayton12bec712010-06-28 21:30:43 +0000182 case 'F':
Greg Clayton889fbd02011-03-26 19:14:58 +0000183 m_func_name.assign (option_arg);
Greg Clayton12bec712010-06-28 21:30:43 +0000184 m_func_name_type_mask |= eFunctionNameTypeFull;
185 break;
186
187 case 'S':
Greg Clayton889fbd02011-03-26 19:14:58 +0000188 m_func_name.assign (option_arg);
Greg Clayton12bec712010-06-28 21:30:43 +0000189 m_func_name_type_mask |= eFunctionNameTypeSelector;
190 break;
191
Jim Inghamd9e2b762010-08-26 23:56:11 +0000192 case 'M':
Greg Clayton889fbd02011-03-26 19:14:58 +0000193 m_func_name.assign (option_arg);
Greg Clayton12bec712010-06-28 21:30:43 +0000194 m_func_name_type_mask |= eFunctionNameTypeMethod;
195 break;
196
Jim Ingham03c8ee52011-09-21 01:17:13 +0000197 case 'p':
198 m_source_text_regexp.assign (option_arg);
199 break;
200
Chris Lattner24943d22010-06-08 16:52:24 +0000201 case 'r':
Greg Clayton889fbd02011-03-26 19:14:58 +0000202 m_func_regexp.assign (option_arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000203 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000204
Chris Lattner24943d22010-06-08 16:52:24 +0000205 case 's':
206 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000207 m_modules.AppendIfUnique (FileSpec (option_arg, false));
Chris Lattner24943d22010-06-08 16:52:24 +0000208 break;
209 }
Greg Claytonfe424a92010-09-18 03:37:20 +0000210 case 'i':
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000211 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000212 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Greg Clayton54e7afa2010-07-09 20:39:50 +0000213 if (m_ignore_count == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000214 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000215 }
Jim Ingham10622a22010-06-18 00:58:52 +0000216 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000217 case 't' :
218 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000219 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000220 if (m_thread_id == LLDB_INVALID_THREAD_ID)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000221 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000222 }
223 break;
224 case 'T':
Greg Clayton889fbd02011-03-26 19:14:58 +0000225 m_thread_name.assign (option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000226 break;
227 case 'q':
Greg Clayton889fbd02011-03-26 19:14:58 +0000228 m_queue_name.assign (option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000229 break;
230 case 'x':
231 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000232 m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Greg Clayton54e7afa2010-07-09 20:39:50 +0000233 if (m_thread_id == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +0000234 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000235
236 }
237 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000238 default:
239 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
240 break;
241 }
242
243 return error;
244}
245
246void
Greg Clayton143fcc32011-04-13 00:18:08 +0000247CommandObjectBreakpointSet::CommandOptions::OptionParsingStarting ()
Chris Lattner24943d22010-06-08 16:52:24 +0000248{
Jim Inghamd6d47972011-09-23 00:54:11 +0000249 m_filenames.Clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000250 m_line_num = 0;
251 m_column = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000252 m_func_name.clear();
Greg Clayton12bec712010-06-28 21:30:43 +0000253 m_func_name_type_mask = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000254 m_func_regexp.clear();
255 m_load_addr = LLDB_INVALID_ADDRESS;
Jim Inghamd6d47972011-09-23 00:54:11 +0000256 m_modules.Clear();
Greg Clayton54e7afa2010-07-09 20:39:50 +0000257 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000258 m_thread_id = LLDB_INVALID_THREAD_ID;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000259 m_thread_index = UINT32_MAX;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000260 m_thread_name.clear();
261 m_queue_name.clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000262}
263
264//-------------------------------------------------------------------------
265// CommandObjectBreakpointSet
266//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000267#pragma mark Set
Chris Lattner24943d22010-06-08 16:52:24 +0000268
Greg Clayton238c0a12010-09-18 01:14:36 +0000269CommandObjectBreakpointSet::CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
270 CommandObject (interpreter,
271 "breakpoint set",
272 "Sets a breakpoint or set of breakpoints in the executable.",
Greg Claytonf15996e2011-04-07 22:46:35 +0000273 "breakpoint set <cmd-options>"),
274 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000275{
276}
277
278CommandObjectBreakpointSet::~CommandObjectBreakpointSet ()
279{
280}
281
282Options *
283CommandObjectBreakpointSet::GetOptions ()
284{
285 return &m_options;
286}
287
288bool
Jim Inghamd6d47972011-09-23 00:54:11 +0000289CommandObjectBreakpointSet::GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result)
Jim Ingham03c8ee52011-09-21 01:17:13 +0000290{
Jim Inghamd6d47972011-09-23 00:54:11 +0000291 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))
Jim Ingham03c8ee52011-09-21 01:17:13 +0000295 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000296 StackFrame *cur_frame = m_interpreter.GetExecutionContext().GetFramePtr();
297 if (cur_frame == NULL)
Jim Ingham03c8ee52011-09-21 01:17:13 +0000298 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000299 result.AppendError ("No selected frame to use to find the default file.");
300 result.SetStatus (eReturnStatusFailed);
301 return false;
302 }
303 else if (!cur_frame->HasDebugInformation())
304 {
305 result.AppendError ("Cannot use the selected frame to find the default file, it 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)
Jim Ingham03c8ee52011-09-21 01:17:13 +0000313 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000314 file = sc.line_entry.file;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000315 }
316 else
317 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000318 result.AppendError ("Can't find the file for the selected frame to use as the default file.");
319 result.SetStatus (eReturnStatusFailed);
320 return false;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000321 }
322 }
323 }
Jim Ingham03c8ee52011-09-21 01:17:13 +0000324 return true;
325}
326
327bool
Chris Lattner24943d22010-06-08 16:52:24 +0000328CommandObjectBreakpointSet::Execute
329(
330 Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000331 CommandReturnObject &result
332)
333{
Greg Clayton238c0a12010-09-18 01:14:36 +0000334 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000335 if (target == NULL)
336 {
Greg Claytone1f50b92011-05-03 22:09:39 +0000337 result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command).");
Chris Lattner24943d22010-06-08 16:52:24 +0000338 result.SetStatus (eReturnStatusFailed);
339 return false;
340 }
341
342 // The following are the various types of breakpoints that could be set:
343 // 1). -f -l -p [-s -g] (setting breakpoint by source location)
344 // 2). -a [-s -g] (setting breakpoint by address)
345 // 3). -n [-s -g] (setting breakpoint by function name)
346 // 4). -r [-s -g] (setting breakpoint by function name regular expression)
Jim Ingham03c8ee52011-09-21 01:17:13 +0000347 // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text)
Chris Lattner24943d22010-06-08 16:52:24 +0000348
349 BreakpointSetType break_type = eSetTypeInvalid;
350
351 if (m_options.m_line_num != 0)
352 break_type = eSetTypeFileAndLine;
353 else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
354 break_type = eSetTypeAddress;
355 else if (!m_options.m_func_name.empty())
356 break_type = eSetTypeFunctionName;
357 else if (!m_options.m_func_regexp.empty())
358 break_type = eSetTypeFunctionRegexp;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000359 else if (!m_options.m_source_text_regexp.empty())
360 break_type = eSetTypeSourceRegexp;
Chris Lattner24943d22010-06-08 16:52:24 +0000361
Chris Lattner24943d22010-06-08 16:52:24 +0000362 Breakpoint *bp = NULL;
Greg Clayton537a7a82010-10-20 20:54:39 +0000363 FileSpec module_spec;
Chris Lattner24943d22010-06-08 16:52:24 +0000364 bool use_module = false;
Jim Inghamd6d47972011-09-23 00:54:11 +0000365 int num_modules = m_options.m_modules.GetSize();
Jim Ingham03c8ee52011-09-21 01:17:13 +0000366
Chris Lattner24943d22010-06-08 16:52:24 +0000367 if ((num_modules > 0) && (break_type != eSetTypeAddress))
368 use_module = true;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000369
Chris Lattner24943d22010-06-08 16:52:24 +0000370 switch (break_type)
371 {
372 case eSetTypeFileAndLine: // Breakpoint by source position
Chris Lattner24943d22010-06-08 16:52:24 +0000373 {
Greg Clayton887aa282010-10-11 01:05:37 +0000374 FileSpec file;
Jim Inghamd6d47972011-09-23 00:54:11 +0000375 uint32_t num_files = m_options.m_filenames.GetSize();
376 if (num_files == 0)
377 {
378 if (!GetDefaultFile (target, file, result))
379 {
380 result.AppendError("No file supplied and no default file available.");
381 result.SetStatus (eReturnStatusFailed);
382 return false;
383 }
384 }
385 else if (num_files > 1)
386 {
387 result.AppendError("Only one file at a time is allowed for file and line breakpoints.");
388 result.SetStatus (eReturnStatusFailed);
389 return false;
390 }
391 else
392 file = m_options.m_filenames.GetFileSpecAtIndex(0);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000393
Jim Inghamd6d47972011-09-23 00:54:11 +0000394 bp = target->CreateBreakpoint (&(m_options.m_modules),
Jim Ingham03c8ee52011-09-21 01:17:13 +0000395 file,
396 m_options.m_line_num,
397 m_options.m_check_inlines).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000398 }
Greg Clayton887aa282010-10-11 01:05:37 +0000399 break;
400
Chris Lattner24943d22010-06-08 16:52:24 +0000401 case eSetTypeAddress: // Breakpoint by address
402 bp = target->CreateBreakpoint (m_options.m_load_addr, false).get();
403 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000404
Chris Lattner24943d22010-06-08 16:52:24 +0000405 case eSetTypeFunctionName: // Breakpoint by function name
Chris Lattner24943d22010-06-08 16:52:24 +0000406 {
Greg Clayton12bec712010-06-28 21:30:43 +0000407 uint32_t name_type_mask = m_options.m_func_name_type_mask;
408
409 if (name_type_mask == 0)
Greg Clayton48fbdf72010-10-12 04:29:14 +0000410 name_type_mask = eFunctionNameTypeAuto;
Jim Inghamd6d47972011-09-23 00:54:11 +0000411
412 bp = target->CreateBreakpoint (&(m_options.m_modules),
413 &(m_options.m_filenames),
Jim Ingham03c8ee52011-09-21 01:17:13 +0000414 m_options.m_func_name.c_str(),
415 name_type_mask,
416 Breakpoint::Exact).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000417 }
Chris Lattner24943d22010-06-08 16:52:24 +0000418 break;
Greg Clayton12bec712010-06-28 21:30:43 +0000419
Chris Lattner24943d22010-06-08 16:52:24 +0000420 case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
421 {
422 RegularExpression regexp(m_options.m_func_regexp.c_str());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000423 if (!regexp.IsValid())
Chris Lattner24943d22010-06-08 16:52:24 +0000424 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000425 char err_str[1024];
426 regexp.GetErrorAsCString(err_str, sizeof(err_str));
427 result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"",
428 err_str);
429 result.SetStatus (eReturnStatusFailed);
430 return false;
Chris Lattner24943d22010-06-08 16:52:24 +0000431 }
Jim Inghamd6d47972011-09-23 00:54:11 +0000432
433 bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules), &(m_options.m_filenames), 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 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000438 int num_files = m_options.m_filenames.GetSize();
439
440 if (num_files == 0)
441 {
442 FileSpec file;
443 if (!GetDefaultFile (target, file, result))
444 {
445 result.AppendError ("No files provided and could not find default file.");
446 result.SetStatus (eReturnStatusFailed);
447 return false;
448 }
449 else
450 {
451 m_options.m_filenames.Append (file);
452 }
453 }
454
Jim Ingham03c8ee52011-09-21 01:17:13 +0000455 RegularExpression regexp(m_options.m_source_text_regexp.c_str());
456 if (!regexp.IsValid())
457 {
458 char err_str[1024];
459 regexp.GetErrorAsCString(err_str, sizeof(err_str));
460 result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"",
461 err_str);
462 result.SetStatus (eReturnStatusFailed);
463 return false;
464 }
Jim Inghamd6d47972011-09-23 00:54:11 +0000465 bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules), &(m_options.m_filenames), regexp).get();
Jim Ingham03c8ee52011-09-21 01:17:13 +0000466 }
467 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000468 default:
469 break;
470 }
471
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000472 // Now set the various options that were passed in:
473 if (bp)
474 {
475 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
476 bp->SetThreadID (m_options.m_thread_id);
477
Greg Clayton54e7afa2010-07-09 20:39:50 +0000478 if (m_options.m_thread_index != UINT32_MAX)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000479 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
480
481 if (!m_options.m_thread_name.empty())
482 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
483
484 if (!m_options.m_queue_name.empty())
485 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
486
Greg Clayton54e7afa2010-07-09 20:39:50 +0000487 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000488 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
489 }
490
Jim Ingham03c8ee52011-09-21 01:17:13 +0000491 if (bp)
Chris Lattner24943d22010-06-08 16:52:24 +0000492 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000493 Stream &output_stream = result.GetOutputStream();
Chris Lattner24943d22010-06-08 16:52:24 +0000494 output_stream.Printf ("Breakpoint created: ");
495 bp->GetDescription(&output_stream, lldb::eDescriptionLevelBrief);
496 output_stream.EOL();
Caroline Ticecf2f3052010-10-28 16:28:56 +0000497 if (bp->GetNumLocations() == 0)
498 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000499 result.SetStatus (eReturnStatusSuccessFinishResult);
500 }
501 else if (!bp)
502 {
503 result.AppendError ("Breakpoint creation failed: No breakpoint created.");
504 result.SetStatus (eReturnStatusFailed);
505 }
506
507 return result.Succeeded();
508}
509
Chris Lattner24943d22010-06-08 16:52:24 +0000510//-------------------------------------------------------------------------
511// CommandObjectMultiwordBreakpoint
512//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000513#pragma mark MultiwordBreakpoint
Chris Lattner24943d22010-06-08 16:52:24 +0000514
Greg Clayton63094e02010-06-23 01:19:29 +0000515CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000516 CommandObjectMultiword (interpreter,
517 "breakpoint",
Jim Ingham7224aab2011-05-26 20:39:01 +0000518 "A set of commands for operating on breakpoints. Also see _regexp-break.",
Greg Clayton238c0a12010-09-18 01:14:36 +0000519 "breakpoint <command> [<command-options>]")
Chris Lattner24943d22010-06-08 16:52:24 +0000520{
521 bool status;
522
Greg Clayton238c0a12010-09-18 01:14:36 +0000523 CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000524 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
525 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
Johnny Chena62ad7c2010-10-28 17:27:46 +0000526 CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
527 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000528 CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +0000529 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
Greg Clayton238c0a12010-09-18 01:14:36 +0000530 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
Chris Lattner24943d22010-06-08 16:52:24 +0000531
Johnny Chena62ad7c2010-10-28 17:27:46 +0000532 list_command_object->SetCommandName ("breakpoint list");
Chris Lattner24943d22010-06-08 16:52:24 +0000533 enable_command_object->SetCommandName("breakpoint enable");
534 disable_command_object->SetCommandName("breakpoint disable");
Johnny Chena62ad7c2010-10-28 17:27:46 +0000535 clear_command_object->SetCommandName("breakpoint clear");
536 delete_command_object->SetCommandName("breakpoint delete");
Jim Ingham10622a22010-06-18 00:58:52 +0000537 set_command_object->SetCommandName("breakpoint set");
Johnny Chena62ad7c2010-10-28 17:27:46 +0000538 command_command_object->SetCommandName ("breakpoint command");
539 modify_command_object->SetCommandName ("breakpoint modify");
Chris Lattner24943d22010-06-08 16:52:24 +0000540
Greg Clayton238c0a12010-09-18 01:14:36 +0000541 status = LoadSubCommand ("list", list_command_object);
542 status = LoadSubCommand ("enable", enable_command_object);
543 status = LoadSubCommand ("disable", disable_command_object);
Johnny Chena62ad7c2010-10-28 17:27:46 +0000544 status = LoadSubCommand ("clear", clear_command_object);
Greg Clayton238c0a12010-09-18 01:14:36 +0000545 status = LoadSubCommand ("delete", delete_command_object);
546 status = LoadSubCommand ("set", set_command_object);
547 status = LoadSubCommand ("command", command_command_object);
548 status = LoadSubCommand ("modify", modify_command_object);
Chris Lattner24943d22010-06-08 16:52:24 +0000549}
550
551CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint ()
552{
553}
554
555void
556CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (Args &args, Target *target, CommandReturnObject &result,
557 BreakpointIDList *valid_ids)
558{
559 // args can be strings representing 1). integers (for breakpoint ids)
560 // 2). the full breakpoint & location canonical representation
561 // 3). the word "to" or a hyphen, representing a range (in which case there
562 // had *better* be an entry both before & after of one of the first two types.
Jim Inghamd1686902010-10-14 23:45:03 +0000563 // If args is empty, we will use the last created breakpoint (if there is one.)
Chris Lattner24943d22010-06-08 16:52:24 +0000564
565 Args temp_args;
566
Jim Inghamd1686902010-10-14 23:45:03 +0000567 if (args.GetArgumentCount() == 0)
568 {
Greg Clayton987c7eb2011-09-17 08:33:22 +0000569 if (target->GetLastCreatedBreakpoint())
Jim Inghamd1686902010-10-14 23:45:03 +0000570 {
571 valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
572 result.SetStatus (eReturnStatusSuccessFinishNoResult);
573 }
574 else
575 {
576 result.AppendError("No breakpoint specified and no last created breakpoint.");
577 result.SetStatus (eReturnStatusFailed);
578 }
579 return;
580 }
581
Chris Lattner24943d22010-06-08 16:52:24 +0000582 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
583 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
584 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
585
586 BreakpointIDList::FindAndReplaceIDRanges (args, target, result, temp_args);
587
588 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
589
Greg Clayton54e7afa2010-07-09 20:39:50 +0000590 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
Chris Lattner24943d22010-06-08 16:52:24 +0000591
592 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
593 // and put into valid_ids.
594
595 if (result.Succeeded())
596 {
597 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
598 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
599
Greg Clayton54e7afa2010-07-09 20:39:50 +0000600 const size_t count = valid_ids->GetSize();
601 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000602 {
603 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
604 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
605 if (breakpoint != NULL)
606 {
607 int num_locations = breakpoint->GetNumLocations();
608 if (cur_bp_id.GetLocationID() > num_locations)
609 {
610 StreamString id_str;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000611 BreakpointID::GetCanonicalReference (&id_str,
612 cur_bp_id.GetBreakpointID(),
613 cur_bp_id.GetLocationID());
614 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000615 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
616 id_str.GetData());
617 result.SetStatus (eReturnStatusFailed);
618 }
619 }
620 else
621 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000622 i = valid_ids->GetSize() + 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000623 result.AppendErrorWithFormat ("'%d' is not a currently valid breakpoint id.\n", cur_bp_id.GetBreakpointID());
624 result.SetStatus (eReturnStatusFailed);
625 }
626 }
627 }
628}
629
630//-------------------------------------------------------------------------
631// CommandObjectBreakpointList::Options
632//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000633#pragma mark List::CommandOptions
Chris Lattner24943d22010-06-08 16:52:24 +0000634
Greg Claytonf15996e2011-04-07 22:46:35 +0000635CommandObjectBreakpointList::CommandOptions::CommandOptions(CommandInterpreter &interpreter) :
636 Options (interpreter),
Caroline Tice41950cc2011-02-04 22:59:41 +0000637 m_level (lldb::eDescriptionLevelBrief) // Breakpoint List defaults to brief descriptions
Chris Lattner24943d22010-06-08 16:52:24 +0000638{
Chris Lattner24943d22010-06-08 16:52:24 +0000639}
640
641CommandObjectBreakpointList::CommandOptions::~CommandOptions ()
642{
643}
644
Greg Claytonb3448432011-03-24 21:19:54 +0000645OptionDefinition
Chris Lattner24943d22010-06-08 16:52:24 +0000646CommandObjectBreakpointList::CommandOptions::g_option_table[] =
647{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000648 { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, eArgTypeNone,
Jim Ingham34e9a982010-06-15 18:47:14 +0000649 "Show debugger internal breakpoints" },
650
Caroline Tice4d6675c2010-10-01 19:59:14 +0000651 { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000652 "Give a brief description of the breakpoint (no location info)."},
653
654 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
655 // But I need to see it for now, and don't want to wait.
Caroline Tice4d6675c2010-10-01 19:59:14 +0000656 { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000657 "Give a full description of the breakpoint and its locations."},
Chris Lattner24943d22010-06-08 16:52:24 +0000658
Caroline Tice4d6675c2010-10-01 19:59:14 +0000659 { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone,
Chris Lattner24943d22010-06-08 16:52:24 +0000660 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
Chris Lattner24943d22010-06-08 16:52:24 +0000661
Caroline Tice4d6675c2010-10-01 19:59:14 +0000662 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000663};
664
Greg Claytonb3448432011-03-24 21:19:54 +0000665const OptionDefinition*
Chris Lattner24943d22010-06-08 16:52:24 +0000666CommandObjectBreakpointList::CommandOptions::GetDefinitions ()
667{
668 return g_option_table;
669}
670
671Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000672CommandObjectBreakpointList::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Chris Lattner24943d22010-06-08 16:52:24 +0000673{
674 Error error;
675 char short_option = (char) m_getopt_table[option_idx].val;
676
677 switch (short_option)
678 {
679 case 'b':
680 m_level = lldb::eDescriptionLevelBrief;
681 break;
682 case 'f':
683 m_level = lldb::eDescriptionLevelFull;
684 break;
685 case 'v':
686 m_level = lldb::eDescriptionLevelVerbose;
687 break;
688 case 'i':
689 m_internal = true;
690 break;
691 default:
692 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
693 break;
694 }
695
696 return error;
697}
698
699void
Greg Clayton143fcc32011-04-13 00:18:08 +0000700CommandObjectBreakpointList::CommandOptions::OptionParsingStarting ()
Chris Lattner24943d22010-06-08 16:52:24 +0000701{
Jim Inghamdc259052011-05-17 01:21:41 +0000702 m_level = lldb::eDescriptionLevelFull;
Chris Lattner24943d22010-06-08 16:52:24 +0000703 m_internal = false;
704}
705
706//-------------------------------------------------------------------------
707// CommandObjectBreakpointList
708//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000709#pragma mark List
Chris Lattner24943d22010-06-08 16:52:24 +0000710
Greg Clayton238c0a12010-09-18 01:14:36 +0000711CommandObjectBreakpointList::CommandObjectBreakpointList (CommandInterpreter &interpreter) :
712 CommandObject (interpreter,
713 "breakpoint list",
714 "List some or all breakpoints at configurable levels of detail.",
Greg Claytonf15996e2011-04-07 22:46:35 +0000715 NULL),
716 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000717{
Caroline Ticefb355112010-10-01 17:46:38 +0000718 CommandArgumentEntry arg;
719 CommandArgumentData bp_id_arg;
720
721 // Define the first (and only) variant of this arg.
722 bp_id_arg.arg_type = eArgTypeBreakpointID;
Caroline Tice43b014a2010-10-04 22:28:36 +0000723 bp_id_arg.arg_repetition = eArgRepeatOptional;
Caroline Ticefb355112010-10-01 17:46:38 +0000724
725 // There is only one variant this argument could be; put it into the argument entry.
726 arg.push_back (bp_id_arg);
727
728 // Push the data for the first argument into the m_arguments vector.
729 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000730}
731
732CommandObjectBreakpointList::~CommandObjectBreakpointList ()
733{
734}
735
736Options *
737CommandObjectBreakpointList::GetOptions ()
738{
739 return &m_options;
740}
741
742bool
743CommandObjectBreakpointList::Execute
744(
745 Args& args,
Chris Lattner24943d22010-06-08 16:52:24 +0000746 CommandReturnObject &result
747)
748{
Greg Clayton238c0a12010-09-18 01:14:36 +0000749 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000750 if (target == NULL)
751 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000752 result.AppendError ("Invalid target. No current target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000753 result.SetStatus (eReturnStatusSuccessFinishNoResult);
754 return true;
755 }
756
757 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000758 Mutex::Locker locker;
759 target->GetBreakpointList(m_options.m_internal).GetListMutex(locker);
760
Chris Lattner24943d22010-06-08 16:52:24 +0000761 size_t num_breakpoints = breakpoints.GetSize();
762
763 if (num_breakpoints == 0)
764 {
765 result.AppendMessage ("No breakpoints currently set.");
766 result.SetStatus (eReturnStatusSuccessFinishNoResult);
767 return true;
768 }
769
Jim Ingham2e8cb8a2011-02-19 02:53:09 +0000770 Stream &output_stream = result.GetOutputStream();
Chris Lattner24943d22010-06-08 16:52:24 +0000771
772 if (args.GetArgumentCount() == 0)
773 {
774 // No breakpoint selected; show info about all currently set breakpoints.
775 result.AppendMessage ("Current breakpoints:");
Greg Clayton54e7afa2010-07-09 20:39:50 +0000776 for (size_t i = 0; i < num_breakpoints; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000777 {
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000778 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000779 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000780 }
781 result.SetStatus (eReturnStatusSuccessFinishNoResult);
782 }
783 else
784 {
785 // Particular breakpoints selected; show info about that breakpoint.
786 BreakpointIDList valid_bp_ids;
787 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
788
789 if (result.Succeeded())
790 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000791 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000792 {
793 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
794 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
Greg Clayton63094e02010-06-23 01:19:29 +0000795 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
Chris Lattner24943d22010-06-08 16:52:24 +0000796 }
797 result.SetStatus (eReturnStatusSuccessFinishNoResult);
798 }
799 else
800 {
801 result.AppendError ("Invalid breakpoint id.");
802 result.SetStatus (eReturnStatusFailed);
803 }
804 }
805
806 return result.Succeeded();
807}
808
809//-------------------------------------------------------------------------
810// CommandObjectBreakpointEnable
811//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000812#pragma mark Enable
Chris Lattner24943d22010-06-08 16:52:24 +0000813
Greg Clayton238c0a12010-09-18 01:14:36 +0000814CommandObjectBreakpointEnable::CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
815 CommandObject (interpreter,
816 "enable",
Caroline Ticefb355112010-10-01 17:46:38 +0000817 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
818 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000819{
Caroline Ticefb355112010-10-01 17:46:38 +0000820 CommandArgumentEntry arg;
Johnny Chencacedfb2011-09-22 22:34:09 +0000821 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
Caroline Ticefb355112010-10-01 17:46:38 +0000822 // Add the entry for the first argument for this command to the object's arguments vector.
823 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000824}
825
826
827CommandObjectBreakpointEnable::~CommandObjectBreakpointEnable ()
828{
829}
830
831
832bool
Greg Clayton63094e02010-06-23 01:19:29 +0000833CommandObjectBreakpointEnable::Execute
834(
Greg Clayton63094e02010-06-23 01:19:29 +0000835 Args& args,
836 CommandReturnObject &result
837)
Chris Lattner24943d22010-06-08 16:52:24 +0000838{
Greg Clayton238c0a12010-09-18 01:14:36 +0000839 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000840 if (target == NULL)
841 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000842 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000843 result.SetStatus (eReturnStatusFailed);
844 return false;
845 }
846
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000847 Mutex::Locker locker;
848 target->GetBreakpointList().GetListMutex(locker);
849
Chris Lattner24943d22010-06-08 16:52:24 +0000850 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000851
Chris Lattner24943d22010-06-08 16:52:24 +0000852 size_t num_breakpoints = breakpoints.GetSize();
853
854 if (num_breakpoints == 0)
855 {
856 result.AppendError ("No breakpoints exist to be enabled.");
857 result.SetStatus (eReturnStatusFailed);
858 return false;
859 }
860
861 if (args.GetArgumentCount() == 0)
862 {
863 // No breakpoint selected; enable all currently set breakpoints.
864 target->EnableAllBreakpoints ();
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000865 result.AppendMessageWithFormat ("All breakpoints enabled. (%lu breakpoints)\n", num_breakpoints);
Chris Lattner24943d22010-06-08 16:52:24 +0000866 result.SetStatus (eReturnStatusSuccessFinishNoResult);
867 }
868 else
869 {
870 // Particular breakpoint selected; enable that breakpoint.
871 BreakpointIDList valid_bp_ids;
872 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
873
874 if (result.Succeeded())
875 {
876 int enable_count = 0;
877 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000878 const size_t count = valid_bp_ids.GetSize();
879 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000880 {
881 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
882
883 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
884 {
885 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
886 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
887 {
888 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
889 if (location)
890 {
891 location->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000892 ++loc_count;
893 }
894 }
895 else
896 {
Jim Ingham10622a22010-06-18 00:58:52 +0000897 breakpoint->SetEnabled (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000898 ++enable_count;
Chris Lattner24943d22010-06-08 16:52:24 +0000899 }
900 }
901 }
902 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
903 result.SetStatus (eReturnStatusSuccessFinishNoResult);
904 }
905 }
906
907 return result.Succeeded();
908}
909
910//-------------------------------------------------------------------------
911// CommandObjectBreakpointDisable
912//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +0000913#pragma mark Disable
Chris Lattner24943d22010-06-08 16:52:24 +0000914
Greg Clayton238c0a12010-09-18 01:14:36 +0000915CommandObjectBreakpointDisable::CommandObjectBreakpointDisable (CommandInterpreter &interpreter) :
916 CommandObject (interpreter,
Caroline Ticefb355112010-10-01 17:46:38 +0000917 "breakpoint disable",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000918 "Disable the specified breakpoint(s) without removing it/them. If no breakpoints are specified, disable them all.",
Caroline Ticefb355112010-10-01 17:46:38 +0000919 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000920{
Caroline Ticefb355112010-10-01 17:46:38 +0000921 CommandArgumentEntry arg;
Johnny Chencacedfb2011-09-22 22:34:09 +0000922 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
Caroline Ticefb355112010-10-01 17:46:38 +0000923 // Add the entry for the first argument for this command to the object's arguments vector.
924 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000925}
926
927CommandObjectBreakpointDisable::~CommandObjectBreakpointDisable ()
928{
929}
930
931bool
Greg Clayton63094e02010-06-23 01:19:29 +0000932CommandObjectBreakpointDisable::Execute
933(
Greg Clayton63094e02010-06-23 01:19:29 +0000934 Args& args,
935 CommandReturnObject &result
936)
Chris Lattner24943d22010-06-08 16:52:24 +0000937{
Greg Clayton238c0a12010-09-18 01:14:36 +0000938 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000939 if (target == NULL)
940 {
Caroline Tice17dce1c2010-09-29 19:42:33 +0000941 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +0000942 result.SetStatus (eReturnStatusFailed);
943 return false;
944 }
945
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000946 Mutex::Locker locker;
947 target->GetBreakpointList().GetListMutex(locker);
948
Chris Lattner24943d22010-06-08 16:52:24 +0000949 const BreakpointList &breakpoints = target->GetBreakpointList();
950 size_t num_breakpoints = breakpoints.GetSize();
951
952 if (num_breakpoints == 0)
953 {
954 result.AppendError ("No breakpoints exist to be disabled.");
955 result.SetStatus (eReturnStatusFailed);
956 return false;
957 }
958
959 if (args.GetArgumentCount() == 0)
960 {
961 // No breakpoint selected; disable all currently set breakpoints.
962 target->DisableAllBreakpoints ();
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000963 result.AppendMessageWithFormat ("All breakpoints disabled. (%lu breakpoints)\n", num_breakpoints);
Chris Lattner24943d22010-06-08 16:52:24 +0000964 result.SetStatus (eReturnStatusSuccessFinishNoResult);
965 }
966 else
967 {
968 // Particular breakpoint selected; disable that breakpoint.
969 BreakpointIDList valid_bp_ids;
970
971 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
972
973 if (result.Succeeded())
974 {
975 int disable_count = 0;
976 int loc_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000977 const size_t count = valid_bp_ids.GetSize();
978 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000979 {
980 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
981
982 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
983 {
984 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
985 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
986 {
987 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
988 if (location)
989 {
990 location->SetEnabled (false);
991 ++loc_count;
992 }
993 }
994 else
995 {
Jim Ingham10622a22010-06-18 00:58:52 +0000996 breakpoint->SetEnabled (false);
Chris Lattner24943d22010-06-08 16:52:24 +0000997 ++disable_count;
Chris Lattner24943d22010-06-08 16:52:24 +0000998 }
999 }
1000 }
1001 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
1002 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1003 }
1004 }
1005
1006 return result.Succeeded();
1007}
1008
1009//-------------------------------------------------------------------------
Johnny Chena62ad7c2010-10-28 17:27:46 +00001010// CommandObjectBreakpointClear::CommandOptions
1011//-------------------------------------------------------------------------
1012#pragma mark Clear::CommandOptions
1013
Greg Claytonf15996e2011-04-07 22:46:35 +00001014CommandObjectBreakpointClear::CommandOptions::CommandOptions(CommandInterpreter &interpreter) :
1015 Options (interpreter),
Johnny Chena62ad7c2010-10-28 17:27:46 +00001016 m_filename (),
1017 m_line_num (0)
1018{
1019}
1020
1021CommandObjectBreakpointClear::CommandOptions::~CommandOptions ()
1022{
1023}
1024
Greg Claytonb3448432011-03-24 21:19:54 +00001025OptionDefinition
Johnny Chena62ad7c2010-10-28 17:27:46 +00001026CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
1027{
1028 { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
1029 "Specify the breakpoint by source location in this particular file."},
1030
1031 { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
1032 "Specify the breakpoint by source location at this particular line."},
1033
1034 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1035};
1036
Greg Claytonb3448432011-03-24 21:19:54 +00001037const OptionDefinition*
Johnny Chena62ad7c2010-10-28 17:27:46 +00001038CommandObjectBreakpointClear::CommandOptions::GetDefinitions ()
1039{
1040 return g_option_table;
1041}
1042
1043Error
Greg Clayton143fcc32011-04-13 00:18:08 +00001044CommandObjectBreakpointClear::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Johnny Chena62ad7c2010-10-28 17:27:46 +00001045{
1046 Error error;
1047 char short_option = (char) m_getopt_table[option_idx].val;
1048
1049 switch (short_option)
1050 {
1051 case 'f':
Greg Clayton889fbd02011-03-26 19:14:58 +00001052 m_filename.assign (option_arg);
Johnny Chena62ad7c2010-10-28 17:27:46 +00001053 break;
1054
1055 case 'l':
1056 m_line_num = Args::StringToUInt32 (option_arg, 0);
1057 break;
1058
1059 default:
1060 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1061 break;
1062 }
1063
1064 return error;
1065}
1066
1067void
Greg Clayton143fcc32011-04-13 00:18:08 +00001068CommandObjectBreakpointClear::CommandOptions::OptionParsingStarting ()
Johnny Chena62ad7c2010-10-28 17:27:46 +00001069{
Johnny Chena62ad7c2010-10-28 17:27:46 +00001070 m_filename.clear();
1071 m_line_num = 0;
1072}
1073
1074//-------------------------------------------------------------------------
1075// CommandObjectBreakpointClear
1076//-------------------------------------------------------------------------
1077#pragma mark Clear
1078
1079CommandObjectBreakpointClear::CommandObjectBreakpointClear (CommandInterpreter &interpreter) :
1080 CommandObject (interpreter,
1081 "breakpoint clear",
1082 "Clears a breakpoint or set of breakpoints in the executable.",
Greg Claytonf15996e2011-04-07 22:46:35 +00001083 "breakpoint clear <cmd-options>"),
1084 m_options (interpreter)
Johnny Chena62ad7c2010-10-28 17:27:46 +00001085{
1086}
1087
1088CommandObjectBreakpointClear::~CommandObjectBreakpointClear ()
1089{
1090}
1091
1092Options *
1093CommandObjectBreakpointClear::GetOptions ()
1094{
1095 return &m_options;
1096}
1097
1098bool
1099CommandObjectBreakpointClear::Execute
1100(
1101 Args& command,
1102 CommandReturnObject &result
1103)
1104{
1105 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1106 if (target == NULL)
1107 {
1108 result.AppendError ("Invalid target. No existing target or breakpoints.");
1109 result.SetStatus (eReturnStatusFailed);
1110 return false;
1111 }
1112
1113 // The following are the various types of breakpoints that could be cleared:
1114 // 1). -f -l (clearing breakpoint by source location)
1115
1116 BreakpointClearType break_type = eClearTypeInvalid;
1117
1118 if (m_options.m_line_num != 0)
1119 break_type = eClearTypeFileAndLine;
1120
1121 Mutex::Locker locker;
1122 target->GetBreakpointList().GetListMutex(locker);
1123
1124 BreakpointList &breakpoints = target->GetBreakpointList();
1125 size_t num_breakpoints = breakpoints.GetSize();
1126
1127 // Early return if there's no breakpoint at all.
1128 if (num_breakpoints == 0)
1129 {
1130 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1131 result.SetStatus (eReturnStatusFailed);
1132 return result.Succeeded();
1133 }
1134
1135 // Find matching breakpoints and delete them.
1136
1137 // First create a copy of all the IDs.
1138 std::vector<break_id_t> BreakIDs;
1139 for (size_t i = 0; i < num_breakpoints; ++i)
1140 BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i).get()->GetID());
1141
1142 int num_cleared = 0;
1143 StreamString ss;
1144 switch (break_type)
1145 {
1146 case eClearTypeFileAndLine: // Breakpoint by source position
1147 {
1148 const ConstString filename(m_options.m_filename.c_str());
1149 BreakpointLocationCollection loc_coll;
1150
1151 for (size_t i = 0; i < num_breakpoints; ++i)
1152 {
1153 Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
1154
1155 if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
1156 {
1157 // If the collection size is 0, it's a full match and we can just remove the breakpoint.
1158 if (loc_coll.GetSize() == 0)
1159 {
1160 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
1161 ss.EOL();
1162 target->RemoveBreakpointByID (bp->GetID());
1163 ++num_cleared;
1164 }
1165 }
1166 }
1167 }
1168 break;
1169
1170 default:
1171 break;
1172 }
1173
1174 if (num_cleared > 0)
1175 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +00001176 Stream &output_stream = result.GetOutputStream();
Johnny Chena62ad7c2010-10-28 17:27:46 +00001177 output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
1178 output_stream << ss.GetData();
1179 output_stream.EOL();
1180 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1181 }
1182 else
1183 {
1184 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1185 result.SetStatus (eReturnStatusFailed);
1186 }
1187
1188 return result.Succeeded();
1189}
1190
1191//-------------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +00001192// CommandObjectBreakpointDelete
1193//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001194#pragma mark Delete
Chris Lattner24943d22010-06-08 16:52:24 +00001195
Greg Clayton238c0a12010-09-18 01:14:36 +00001196CommandObjectBreakpointDelete::CommandObjectBreakpointDelete(CommandInterpreter &interpreter) :
1197 CommandObject (interpreter,
1198 "breakpoint delete",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001199 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
Caroline Ticefb355112010-10-01 17:46:38 +00001200 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +00001201{
Caroline Ticefb355112010-10-01 17:46:38 +00001202 CommandArgumentEntry arg;
Johnny Chencacedfb2011-09-22 22:34:09 +00001203 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
Caroline Ticefb355112010-10-01 17:46:38 +00001204 // Add the entry for the first argument for this command to the object's arguments vector.
1205 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +00001206}
1207
1208
1209CommandObjectBreakpointDelete::~CommandObjectBreakpointDelete ()
1210{
1211}
1212
1213bool
Greg Clayton63094e02010-06-23 01:19:29 +00001214CommandObjectBreakpointDelete::Execute
1215(
Greg Clayton63094e02010-06-23 01:19:29 +00001216 Args& args,
1217 CommandReturnObject &result
1218)
Chris Lattner24943d22010-06-08 16:52:24 +00001219{
Greg Clayton238c0a12010-09-18 01:14:36 +00001220 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001221 if (target == NULL)
1222 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001223 result.AppendError ("Invalid target. No existing target or breakpoints.");
Chris Lattner24943d22010-06-08 16:52:24 +00001224 result.SetStatus (eReturnStatusFailed);
1225 return false;
1226 }
1227
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001228 Mutex::Locker locker;
1229 target->GetBreakpointList().GetListMutex(locker);
1230
Chris Lattner24943d22010-06-08 16:52:24 +00001231 const BreakpointList &breakpoints = target->GetBreakpointList();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001232
Chris Lattner24943d22010-06-08 16:52:24 +00001233 size_t num_breakpoints = breakpoints.GetSize();
1234
1235 if (num_breakpoints == 0)
1236 {
1237 result.AppendError ("No breakpoints exist to be deleted.");
1238 result.SetStatus (eReturnStatusFailed);
1239 return false;
1240 }
1241
1242 if (args.GetArgumentCount() == 0)
1243 {
Jim Inghamd1686902010-10-14 23:45:03 +00001244 if (!m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
Chris Lattner24943d22010-06-08 16:52:24 +00001245 {
Jim Inghamd1686902010-10-14 23:45:03 +00001246 result.AppendMessage("Operation cancelled...");
Chris Lattner24943d22010-06-08 16:52:24 +00001247 }
Jim Inghamd1686902010-10-14 23:45:03 +00001248 else
1249 {
1250 target->RemoveAllBreakpoints ();
Jason Molenda7e5fa7f2011-09-20 21:44:10 +00001251 result.AppendMessageWithFormat ("All breakpoints removed. (%lu breakpoints)\n", num_breakpoints);
Jim Inghamd1686902010-10-14 23:45:03 +00001252 }
Chris Lattner24943d22010-06-08 16:52:24 +00001253 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1254 }
1255 else
1256 {
1257 // Particular breakpoint selected; disable that breakpoint.
1258 BreakpointIDList valid_bp_ids;
1259 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (args, target, result, &valid_bp_ids);
1260
1261 if (result.Succeeded())
1262 {
1263 int delete_count = 0;
1264 int disable_count = 0;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001265 const size_t count = valid_bp_ids.GetSize();
1266 for (size_t i = 0; i < count; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +00001267 {
1268 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1269
1270 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1271 {
1272 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1273 {
1274 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1275 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1276 // It makes no sense to try to delete individual locations, so we disable them instead.
1277 if (location)
1278 {
1279 location->SetEnabled (false);
1280 ++disable_count;
1281 }
1282 }
1283 else
1284 {
1285 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1286 ++delete_count;
1287 }
1288 }
1289 }
1290 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1291 delete_count, disable_count);
1292 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1293 }
1294 }
1295 return result.Succeeded();
1296}
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001297
1298//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001299// CommandObjectBreakpointModify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001300//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001301#pragma mark Modify::CommandOptions
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001302
Greg Claytonf15996e2011-04-07 22:46:35 +00001303CommandObjectBreakpointModify::CommandOptions::CommandOptions(CommandInterpreter &interpreter) :
1304 Options (interpreter),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001305 m_ignore_count (0),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001306 m_thread_id(LLDB_INVALID_THREAD_ID),
Jim Ingham9a7b2912010-12-03 23:04:19 +00001307 m_thread_id_passed(false),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001308 m_thread_index (UINT32_MAX),
Jim Ingham9a7b2912010-12-03 23:04:19 +00001309 m_thread_index_passed(false),
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001310 m_thread_name(),
1311 m_queue_name(),
Jim Inghamd1686902010-10-14 23:45:03 +00001312 m_condition (),
Greg Clayton54e7afa2010-07-09 20:39:50 +00001313 m_enable_passed (false),
1314 m_enable_value (false),
1315 m_name_passed (false),
Jim Inghamd1686902010-10-14 23:45:03 +00001316 m_queue_passed (false),
1317 m_condition_passed (false)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001318{
1319}
1320
Jim Ingham10622a22010-06-18 00:58:52 +00001321CommandObjectBreakpointModify::CommandOptions::~CommandOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001322{
1323}
1324
Greg Claytonb3448432011-03-24 21:19:54 +00001325OptionDefinition
Jim Ingham10622a22010-06-18 00:58:52 +00001326CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001327{
Caroline Tice4d6675c2010-10-01 19:59:14 +00001328{ LLDB_OPT_SET_ALL, false, "ignore-count", 'i', required_argument, NULL, NULL, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." },
1329{ 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."},
1330{ 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."},
1331{ 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."},
1332{ 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 +00001333{ 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 +00001334{ LLDB_OPT_SET_1, false, "enable", 'e', no_argument, NULL, NULL, eArgTypeNone, "Enable the breakpoint."},
1335{ LLDB_OPT_SET_2, false, "disable", 'd', no_argument, NULL, NULL, eArgTypeNone, "Disable the breakpoint."},
Jim Inghamd1686902010-10-14 23:45:03 +00001336{ 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001337};
1338
Greg Claytonb3448432011-03-24 21:19:54 +00001339const OptionDefinition*
Jim Ingham10622a22010-06-18 00:58:52 +00001340CommandObjectBreakpointModify::CommandOptions::GetDefinitions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001341{
1342 return g_option_table;
1343}
1344
1345Error
Greg Clayton143fcc32011-04-13 00:18:08 +00001346CommandObjectBreakpointModify::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001347{
1348 Error error;
1349 char short_option = (char) m_getopt_table[option_idx].val;
1350
1351 switch (short_option)
1352 {
Jim Inghamd1686902010-10-14 23:45:03 +00001353 case 'c':
1354 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001355 m_condition.assign (option_arg);
Jim Inghamd1686902010-10-14 23:45:03 +00001356 else
1357 m_condition.clear();
1358 m_condition_passed = true;
1359 break;
Jim Ingham10622a22010-06-18 00:58:52 +00001360 case 'd':
1361 m_enable_passed = true;
1362 m_enable_value = false;
1363 break;
1364 case 'e':
1365 m_enable_passed = true;
1366 m_enable_value = true;
1367 break;
Greg Claytonfe424a92010-09-18 03:37:20 +00001368 case 'i':
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001369 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001370 m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Greg Clayton54e7afa2010-07-09 20:39:50 +00001371 if (m_ignore_count == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001372 error.SetErrorStringWithFormat ("Invalid ignore count '%s'.\n", option_arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001373 }
Jim Ingham10622a22010-06-18 00:58:52 +00001374 break;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001375 case 't' :
1376 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001377 if (option_arg[0] == '\0')
Jim Ingham9a7b2912010-12-03 23:04:19 +00001378 {
1379 m_thread_id = LLDB_INVALID_THREAD_ID;
1380 m_thread_id_passed = true;
1381 }
1382 else
1383 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001384 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001385 if (m_thread_id == LLDB_INVALID_THREAD_ID)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001386 error.SetErrorStringWithFormat ("Invalid thread id string '%s'.\n", option_arg);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001387 else
1388 m_thread_id_passed = true;
1389 }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001390 }
1391 break;
1392 case 'T':
Jim Inghamd4571222010-06-19 04:35:20 +00001393 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001394 m_thread_name.assign (option_arg);
Jim Inghamd4571222010-06-19 04:35:20 +00001395 else
1396 m_thread_name.clear();
1397 m_name_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001398 break;
1399 case 'q':
Jim Inghamd4571222010-06-19 04:35:20 +00001400 if (option_arg != NULL)
Greg Clayton889fbd02011-03-26 19:14:58 +00001401 m_queue_name.assign (option_arg);
Jim Inghamd4571222010-06-19 04:35:20 +00001402 else
1403 m_queue_name.clear();
1404 m_queue_passed = true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001405 break;
1406 case 'x':
1407 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001408 if (option_arg[0] == '\n')
Jim Ingham9a7b2912010-12-03 23:04:19 +00001409 {
1410 m_thread_index = UINT32_MAX;
1411 m_thread_index_passed = true;
1412 }
1413 else
1414 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001415 m_thread_index = Args::StringToUInt32 (option_arg, UINT32_MAX, 0);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001416 if (m_thread_id == UINT32_MAX)
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00001417 error.SetErrorStringWithFormat ("Invalid thread index string '%s'.\n", option_arg);
Jim Ingham9a7b2912010-12-03 23:04:19 +00001418 else
1419 m_thread_index_passed = true;
1420 }
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001421 }
1422 break;
1423 default:
1424 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
1425 break;
1426 }
1427
1428 return error;
1429}
1430
1431void
Greg Clayton143fcc32011-04-13 00:18:08 +00001432CommandObjectBreakpointModify::CommandOptions::OptionParsingStarting ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001433{
Greg Clayton54e7afa2010-07-09 20:39:50 +00001434 m_ignore_count = 0;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001435 m_thread_id = LLDB_INVALID_THREAD_ID;
Jim Ingham9a7b2912010-12-03 23:04:19 +00001436 m_thread_id_passed = false;
Greg Clayton54e7afa2010-07-09 20:39:50 +00001437 m_thread_index = UINT32_MAX;
Jim Ingham9a7b2912010-12-03 23:04:19 +00001438 m_thread_index_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001439 m_thread_name.clear();
1440 m_queue_name.clear();
Jim Inghamd1686902010-10-14 23:45:03 +00001441 m_condition.clear();
Jim Ingham10622a22010-06-18 00:58:52 +00001442 m_enable_passed = false;
Jim Inghamd4571222010-06-19 04:35:20 +00001443 m_queue_passed = false;
1444 m_name_passed = false;
Jim Inghamd1686902010-10-14 23:45:03 +00001445 m_condition_passed = false;
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001446}
1447
1448//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001449// CommandObjectBreakpointModify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001450//-------------------------------------------------------------------------
Jim Ingham10622a22010-06-18 00:58:52 +00001451#pragma mark Modify
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001452
Greg Clayton238c0a12010-09-18 01:14:36 +00001453CommandObjectBreakpointModify::CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
1454 CommandObject (interpreter,
1455 "breakpoint modify",
Jim Ingham19ac0bd2010-12-03 22:37:19 +00001456 "Modify the options on a breakpoint or set of breakpoints in the executable. "
Jim Ingham9a7b2912010-12-03 23:04:19 +00001457 "If no breakpoint is specified, acts on the last created breakpoint. "
1458 "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
Greg Claytonf15996e2011-04-07 22:46:35 +00001459 NULL),
1460 m_options (interpreter)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001461{
Caroline Ticefb355112010-10-01 17:46:38 +00001462 CommandArgumentEntry arg;
Johnny Chencacedfb2011-09-22 22:34:09 +00001463 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
Caroline Ticefb355112010-10-01 17:46:38 +00001464 // Add the entry for the first argument for this command to the object's arguments vector.
1465 m_arguments.push_back (arg);
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001466}
1467
Jim Ingham10622a22010-06-18 00:58:52 +00001468CommandObjectBreakpointModify::~CommandObjectBreakpointModify ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001469{
1470}
1471
1472Options *
Jim Ingham10622a22010-06-18 00:58:52 +00001473CommandObjectBreakpointModify::GetOptions ()
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001474{
1475 return &m_options;
1476}
1477
1478bool
Jim Ingham10622a22010-06-18 00:58:52 +00001479CommandObjectBreakpointModify::Execute
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001480(
1481 Args& command,
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001482 CommandReturnObject &result
1483)
1484{
Greg Clayton238c0a12010-09-18 01:14:36 +00001485 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001486 if (target == NULL)
1487 {
Caroline Tice17dce1c2010-09-29 19:42:33 +00001488 result.AppendError ("Invalid target. No existing target or breakpoints.");
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001489 result.SetStatus (eReturnStatusFailed);
1490 return false;
1491 }
1492
1493 Mutex::Locker locker;
1494 target->GetBreakpointList().GetListMutex(locker);
1495
1496 BreakpointIDList valid_bp_ids;
1497
1498 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
1499
1500 if (result.Succeeded())
1501 {
Greg Clayton54e7afa2010-07-09 20:39:50 +00001502 const size_t count = valid_bp_ids.GetSize();
1503 for (size_t i = 0; i < count; ++i)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001504 {
1505 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1506
1507 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1508 {
1509 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1510 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1511 {
1512 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
1513 if (location)
1514 {
Jim Ingham9a7b2912010-12-03 23:04:19 +00001515 if (m_options.m_thread_id_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001516 location->SetThreadID (m_options.m_thread_id);
1517
Jim Ingham9a7b2912010-12-03 23:04:19 +00001518 if (m_options.m_thread_index_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001519 location->GetLocationOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1520
Jim Inghamd4571222010-06-19 04:35:20 +00001521 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001522 location->GetLocationOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1523
Jim Inghamd4571222010-06-19 04:35:20 +00001524 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001525 location->GetLocationOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1526
Greg Clayton54e7afa2010-07-09 20:39:50 +00001527 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001528 location->GetLocationOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001529
1530 if (m_options.m_enable_passed)
1531 location->SetEnabled (m_options.m_enable_value);
Jim Inghamd1686902010-10-14 23:45:03 +00001532
1533 if (m_options.m_condition_passed)
1534 location->SetCondition (m_options.m_condition.c_str());
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001535 }
1536 }
1537 else
1538 {
Jim Ingham9a7b2912010-12-03 23:04:19 +00001539 if (m_options.m_thread_id_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001540 bp->SetThreadID (m_options.m_thread_id);
1541
Jim Ingham9a7b2912010-12-03 23:04:19 +00001542 if (m_options.m_thread_index_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001543 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
1544
Jim Inghamd4571222010-06-19 04:35:20 +00001545 if (m_options.m_name_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001546 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
1547
Jim Inghamd4571222010-06-19 04:35:20 +00001548 if (m_options.m_queue_passed)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001549 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
1550
Greg Clayton54e7afa2010-07-09 20:39:50 +00001551 if (m_options.m_ignore_count != 0)
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001552 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
Jim Ingham10622a22010-06-18 00:58:52 +00001553
1554 if (m_options.m_enable_passed)
1555 bp->SetEnabled (m_options.m_enable_value);
Jim Inghamd1686902010-10-14 23:45:03 +00001556
1557 if (m_options.m_condition_passed)
1558 bp->SetCondition (m_options.m_condition.c_str());
Jim Ingham3c7b5b92010-06-16 02:00:15 +00001559 }
1560 }
1561 }
1562 }
1563
1564 return result.Succeeded();
1565}
1566
1567