blob: 6a71389a3f693f08ccf917b55794630e1402ff72 [file] [log] [blame]
Chris Lattner30fdc8d2010-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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000010// C Includes
11// C++ Includes
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +000012#include <vector>
13
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014// Other libraries and framework includes
15// Project includes
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +000016#include "CommandObjectBreakpoint.h"
17#include "CommandObjectBreakpointCommand.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/Breakpoint/Breakpoint.h"
19#include "lldb/Breakpoint/BreakpointIDList.h"
20#include "lldb/Breakpoint/BreakpointLocation.h"
Vince Harron5275aaa2015-01-15 20:08:35 +000021#include "lldb/Host/StringConvert.h"
Jim Ingham40af72e2010-06-15 19:49:27 +000022#include "lldb/Interpreter/Options.h"
Zachary Turner32abc6e2015-03-03 19:23:09 +000023#include "lldb/Interpreter/OptionValueBoolean.h"
Jim Ingham5e09c8c2014-12-16 23:40:14 +000024#include "lldb/Interpreter/OptionValueString.h"
25#include "lldb/Interpreter/OptionValueUInt64.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Core/RegularExpression.h"
27#include "lldb/Core/StreamString.h"
28#include "lldb/Interpreter/CommandInterpreter.h"
29#include "lldb/Interpreter/CommandReturnObject.h"
Jim Ingham0e0984e2015-09-02 01:06:46 +000030#include "lldb/Target/Language.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Target/Target.h"
32#include "lldb/Interpreter/CommandCompletions.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000033#include "lldb/Target/StackFrame.h"
Jim Ingham1b54c882010-06-16 02:00:15 +000034#include "lldb/Target/Thread.h"
35#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036
37using namespace lldb;
38using namespace lldb_private;
39
40static void
Jim Ingham85e8b812011-02-19 02:53:09 +000041AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042{
43 s->IndentMore();
44 bp->GetDescription (s, level, true);
45 s->IndentLess();
46 s->EOL();
47}
48
49//-------------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +000050// CommandObjectBreakpointSet
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051//-------------------------------------------------------------------------
52
Jim Ingham5a988412012-06-08 21:56:10 +000053class CommandObjectBreakpointSet : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054{
Jim Ingham5a988412012-06-08 21:56:10 +000055public:
Jim Ingham5a988412012-06-08 21:56:10 +000056 typedef enum BreakpointSetType
57 {
58 eSetTypeInvalid,
59 eSetTypeFileAndLine,
60 eSetTypeAddress,
61 eSetTypeFunctionName,
62 eSetTypeFunctionRegexp,
63 eSetTypeSourceRegexp,
64 eSetTypeException
65 } BreakpointSetType;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
Jim Ingham5a988412012-06-08 21:56:10 +000067 CommandObjectBreakpointSet (CommandInterpreter &interpreter) :
68 CommandObjectParsed (interpreter,
69 "breakpoint set",
70 "Sets a breakpoint or set of breakpoints in the executable.",
71 "breakpoint set <cmd-options>"),
72 m_options (interpreter)
73 {
74 }
75
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +000076 ~CommandObjectBreakpointSet() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +000077
Bruce Mitchener13d21e92015-10-07 16:56:17 +000078 Options *
79 GetOptions () override
Jim Ingham5a988412012-06-08 21:56:10 +000080 {
81 return &m_options;
82 }
83
84 class CommandOptions : public Options
85 {
86 public:
Jim Ingham5a988412012-06-08 21:56:10 +000087 CommandOptions (CommandInterpreter &interpreter) :
88 Options (interpreter),
89 m_condition (),
90 m_filenames (),
91 m_line_num (0),
92 m_column (0),
Jim Ingham5a988412012-06-08 21:56:10 +000093 m_func_names (),
94 m_func_name_type_mask (eFunctionNameTypeNone),
95 m_func_regexp (),
96 m_source_text_regexp(),
97 m_modules (),
98 m_load_addr(),
99 m_ignore_count (0),
100 m_thread_id(LLDB_INVALID_THREAD_ID),
101 m_thread_index (UINT32_MAX),
102 m_thread_name(),
103 m_queue_name(),
104 m_catch_bp (false),
Greg Clayton1f746072012-08-29 21:13:06 +0000105 m_throw_bp (true),
Greg Claytoneb023e72013-10-11 19:48:25 +0000106 m_hardware (false),
Jim Inghama72b31c2015-04-22 19:42:18 +0000107 m_exception_language (eLanguageTypeUnknown),
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000108 m_language (lldb::eLanguageTypeUnknown),
Jim Inghamca36cd12012-10-05 19:16:31 +0000109 m_skip_prologue (eLazyBoolCalculate),
Jim Inghame7320522015-02-12 17:37:46 +0000110 m_one_shot (false),
Ilia K055ad9b2015-05-18 13:41:01 +0000111 m_all_files (false),
112 m_move_to_nearest_code (eLazyBoolCalculate)
Jim Ingham5a988412012-06-08 21:56:10 +0000113 {
114 }
115
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000116 ~CommandOptions() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +0000117
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000118 Error
119 SetOptionValue (uint32_t option_idx, const char *option_arg) override
Jim Ingham5a988412012-06-08 21:56:10 +0000120 {
121 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000122 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham5a988412012-06-08 21:56:10 +0000123
124 switch (short_option)
125 {
126 case 'a':
Greg Claytonb9d5df52012-12-06 22:49:16 +0000127 {
128 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
129 m_load_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
130 }
Jim Ingham5a988412012-06-08 21:56:10 +0000131 break;
132
Jim Inghame7320522015-02-12 17:37:46 +0000133 case 'A':
134 m_all_files = true;
135 break;
136
Jim Inghamca36cd12012-10-05 19:16:31 +0000137 case 'b':
138 m_func_names.push_back (option_arg);
139 m_func_name_type_mask |= eFunctionNameTypeBase;
140 break;
141
Jim Ingham5a988412012-06-08 21:56:10 +0000142 case 'C':
Jim Ingham63129912015-03-16 22:47:38 +0000143 {
144 bool success;
145 m_column = StringConvert::ToUInt32 (option_arg, 0, 0, &success);
146 if (!success)
147 error.SetErrorStringWithFormat("invalid column number: %s", option_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000148 break;
Jim Ingham63129912015-03-16 22:47:38 +0000149 }
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000150
Jim Ingham5a988412012-06-08 21:56:10 +0000151 case 'c':
152 m_condition.assign(option_arg);
153 break;
154
Jim Ingham33df7cd2014-12-06 01:28:03 +0000155 case 'D':
156 m_use_dummy = true;
157 break;
158
Jim Ingham5a988412012-06-08 21:56:10 +0000159 case 'E':
160 {
Jim Ingham0e0984e2015-09-02 01:06:46 +0000161 LanguageType language = Language::GetLanguageTypeFromString (option_arg);
Jim Ingham5a988412012-06-08 21:56:10 +0000162
163 switch (language)
164 {
165 case eLanguageTypeC89:
166 case eLanguageTypeC:
167 case eLanguageTypeC99:
Bruce Mitchener1d0089f2014-07-03 00:49:08 +0000168 case eLanguageTypeC11:
Jim Inghama72b31c2015-04-22 19:42:18 +0000169 m_exception_language = eLanguageTypeC;
Jim Ingham5a988412012-06-08 21:56:10 +0000170 break;
171 case eLanguageTypeC_plus_plus:
Bruce Mitchener1d0089f2014-07-03 00:49:08 +0000172 case eLanguageTypeC_plus_plus_03:
173 case eLanguageTypeC_plus_plus_11:
Bruce Mitchener2ba84a62015-02-06 06:46:52 +0000174 case eLanguageTypeC_plus_plus_14:
Jim Inghama72b31c2015-04-22 19:42:18 +0000175 m_exception_language = eLanguageTypeC_plus_plus;
Jim Ingham5a988412012-06-08 21:56:10 +0000176 break;
177 case eLanguageTypeObjC:
Jim Inghama72b31c2015-04-22 19:42:18 +0000178 m_exception_language = eLanguageTypeObjC;
Jim Ingham5a988412012-06-08 21:56:10 +0000179 break;
180 case eLanguageTypeObjC_plus_plus:
181 error.SetErrorStringWithFormat ("Set exception breakpoints separately for c++ and objective-c");
182 break;
183 case eLanguageTypeUnknown:
184 error.SetErrorStringWithFormat ("Unknown language type: '%s' for exception breakpoint", option_arg);
185 break;
186 default:
187 error.SetErrorStringWithFormat ("Unsupported language type: '%s' for exception breakpoint", option_arg);
188 }
189 }
190 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000191
192 case 'f':
193 m_filenames.AppendIfUnique (FileSpec(option_arg, false));
194 break;
195
196 case 'F':
197 m_func_names.push_back (option_arg);
198 m_func_name_type_mask |= eFunctionNameTypeFull;
199 break;
200
Jim Ingham5a988412012-06-08 21:56:10 +0000201 case 'h':
Greg Claytoneb023e72013-10-11 19:48:25 +0000202 {
203 bool success;
204 m_catch_bp = Args::StringToBoolean (option_arg, true, &success);
205 if (!success)
206 error.SetErrorStringWithFormat ("Invalid boolean value for on-catch option: '%s'", option_arg);
207 }
208 break;
209
210 case 'H':
211 m_hardware = true;
212 break;
213
Jim Inghamca36cd12012-10-05 19:16:31 +0000214 case 'i':
Vince Harron5275aaa2015-01-15 20:08:35 +0000215 m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
Jim Inghamca36cd12012-10-05 19:16:31 +0000216 if (m_ignore_count == UINT32_MAX)
217 error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
218 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000219
Jim Ingham5a988412012-06-08 21:56:10 +0000220 case 'K':
221 {
222 bool success;
223 bool value;
224 value = Args::StringToBoolean (option_arg, true, &success);
225 if (value)
226 m_skip_prologue = eLazyBoolYes;
227 else
228 m_skip_prologue = eLazyBoolNo;
229
230 if (!success)
231 error.SetErrorStringWithFormat ("Invalid boolean value for skip prologue option: '%s'", option_arg);
232 }
233 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000234
235 case 'l':
Jim Ingham63129912015-03-16 22:47:38 +0000236 {
237 bool success;
238 m_line_num = StringConvert::ToUInt32 (option_arg, 0, 0, &success);
239 if (!success)
240 error.SetErrorStringWithFormat ("invalid line number: %s.", option_arg);
Jim Inghamca36cd12012-10-05 19:16:31 +0000241 break;
Jim Ingham63129912015-03-16 22:47:38 +0000242 }
Ilia K055ad9b2015-05-18 13:41:01 +0000243
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000244 case 'L':
Jim Ingham0e0984e2015-09-02 01:06:46 +0000245 m_language = Language::GetLanguageTypeFromString (option_arg);
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000246 if (m_language == eLanguageTypeUnknown)
247 error.SetErrorStringWithFormat ("Unknown language type: '%s' for breakpoint", option_arg);
248 break;
249
Ilia K055ad9b2015-05-18 13:41:01 +0000250 case 'm':
251 {
252 bool success;
253 bool value;
254 value = Args::StringToBoolean (option_arg, true, &success);
255 if (value)
256 m_move_to_nearest_code = eLazyBoolYes;
257 else
258 m_move_to_nearest_code = eLazyBoolNo;
259
260 if (!success)
261 error.SetErrorStringWithFormat ("Invalid boolean value for move-to-nearest-code option: '%s'", option_arg);
262 break;
263 }
264
Jim Inghamca36cd12012-10-05 19:16:31 +0000265 case 'M':
266 m_func_names.push_back (option_arg);
267 m_func_name_type_mask |= eFunctionNameTypeMethod;
268 break;
269
270 case 'n':
271 m_func_names.push_back (option_arg);
272 m_func_name_type_mask |= eFunctionNameTypeAuto;
273 break;
274
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000275 case 'N':
276 if (BreakpointID::StringIsBreakpointName(option_arg, error))
277 m_breakpoint_names.push_back (option_arg);
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000278 break;
279
Jim Ingham24111672016-03-09 18:59:13 +0000280 case 'R':
281 {
282 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
283 lldb::addr_t tmp_offset_addr;
284 tmp_offset_addr = Args::StringToAddress(&exe_ctx, option_arg, 0, &error);
285 if (error.Success())
286 m_offset_addr = tmp_offset_addr;
287 }
288 break;
289
Jim Inghamca36cd12012-10-05 19:16:31 +0000290 case 'o':
291 m_one_shot = true;
292 break;
293
Jim Inghama72b31c2015-04-22 19:42:18 +0000294 case 'O':
295 m_exception_extra_args.AppendArgument ("-O");
296 m_exception_extra_args.AppendArgument (option_arg);
297 break;
298
Jim Inghamca36cd12012-10-05 19:16:31 +0000299 case 'p':
300 m_source_text_regexp.assign (option_arg);
301 break;
302
303 case 'q':
304 m_queue_name.assign (option_arg);
305 break;
306
307 case 'r':
308 m_func_regexp.assign (option_arg);
309 break;
310
311 case 's':
Jim Inghamca36cd12012-10-05 19:16:31 +0000312 m_modules.AppendIfUnique (FileSpec (option_arg, false));
313 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000314
315 case 'S':
316 m_func_names.push_back (option_arg);
317 m_func_name_type_mask |= eFunctionNameTypeSelector;
318 break;
319
320 case 't' :
Vince Harron5275aaa2015-01-15 20:08:35 +0000321 m_thread_id = StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Inghamca36cd12012-10-05 19:16:31 +0000322 if (m_thread_id == LLDB_INVALID_THREAD_ID)
323 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000324 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000325
326 case 'T':
327 m_thread_name.assign (option_arg);
328 break;
329
330 case 'w':
331 {
332 bool success;
333 m_throw_bp = Args::StringToBoolean (option_arg, true, &success);
334 if (!success)
335 error.SetErrorStringWithFormat ("Invalid boolean value for on-throw option: '%s'", option_arg);
336 }
337 break;
338
339 case 'x':
Vince Harron5275aaa2015-01-15 20:08:35 +0000340 m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
Jim Inghamca36cd12012-10-05 19:16:31 +0000341 if (m_thread_id == UINT32_MAX)
342 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000343 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000344
Jim Ingham76bb8d62016-04-28 01:40:57 +0000345 case 'X':
346 m_source_regex_func_names.insert(option_arg);
347 break;
348
Jim Ingham5a988412012-06-08 21:56:10 +0000349 default:
350 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
351 break;
352 }
353
354 return error;
355 }
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000356
Jim Ingham5a988412012-06-08 21:56:10 +0000357 void
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000358 OptionParsingStarting () override
Jim Ingham5a988412012-06-08 21:56:10 +0000359 {
360 m_condition.clear();
361 m_filenames.Clear();
362 m_line_num = 0;
363 m_column = 0;
364 m_func_names.clear();
Greg Clayton1f746072012-08-29 21:13:06 +0000365 m_func_name_type_mask = eFunctionNameTypeNone;
Jim Ingham5a988412012-06-08 21:56:10 +0000366 m_func_regexp.clear();
Greg Clayton1f746072012-08-29 21:13:06 +0000367 m_source_text_regexp.clear();
Jim Ingham5a988412012-06-08 21:56:10 +0000368 m_modules.Clear();
Greg Clayton1f746072012-08-29 21:13:06 +0000369 m_load_addr = LLDB_INVALID_ADDRESS;
Jim Ingham24111672016-03-09 18:59:13 +0000370 m_offset_addr = 0;
Jim Ingham5a988412012-06-08 21:56:10 +0000371 m_ignore_count = 0;
372 m_thread_id = LLDB_INVALID_THREAD_ID;
373 m_thread_index = UINT32_MAX;
374 m_thread_name.clear();
375 m_queue_name.clear();
Jim Ingham5a988412012-06-08 21:56:10 +0000376 m_catch_bp = false;
377 m_throw_bp = true;
Greg Claytoneb023e72013-10-11 19:48:25 +0000378 m_hardware = false;
Jim Inghama72b31c2015-04-22 19:42:18 +0000379 m_exception_language = eLanguageTypeUnknown;
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000380 m_language = lldb::eLanguageTypeUnknown;
Jim Ingham5a988412012-06-08 21:56:10 +0000381 m_skip_prologue = eLazyBoolCalculate;
Jim Inghamca36cd12012-10-05 19:16:31 +0000382 m_one_shot = false;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000383 m_use_dummy = false;
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000384 m_breakpoint_names.clear();
Jim Inghame7320522015-02-12 17:37:46 +0000385 m_all_files = false;
Jim Inghama72b31c2015-04-22 19:42:18 +0000386 m_exception_extra_args.Clear();
Ilia K055ad9b2015-05-18 13:41:01 +0000387 m_move_to_nearest_code = eLazyBoolCalculate;
Jim Ingham76bb8d62016-04-28 01:40:57 +0000388 m_source_regex_func_names.clear();
Jim Ingham5a988412012-06-08 21:56:10 +0000389 }
390
391 const OptionDefinition*
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000392 GetDefinitions () override
Jim Ingham5a988412012-06-08 21:56:10 +0000393 {
394 return g_option_table;
395 }
396
397 // Options table: Required for subclasses of Options.
398
399 static OptionDefinition g_option_table[];
400
401 // Instance variables to hold the values for command options.
402
403 std::string m_condition;
404 FileSpecList m_filenames;
405 uint32_t m_line_num;
406 uint32_t m_column;
Jim Ingham5a988412012-06-08 21:56:10 +0000407 std::vector<std::string> m_func_names;
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000408 std::vector<std::string> m_breakpoint_names;
Jim Ingham5a988412012-06-08 21:56:10 +0000409 uint32_t m_func_name_type_mask;
410 std::string m_func_regexp;
411 std::string m_source_text_regexp;
412 FileSpecList m_modules;
413 lldb::addr_t m_load_addr;
Jim Ingham24111672016-03-09 18:59:13 +0000414 lldb::addr_t m_offset_addr;
Jim Ingham5a988412012-06-08 21:56:10 +0000415 uint32_t m_ignore_count;
416 lldb::tid_t m_thread_id;
417 uint32_t m_thread_index;
418 std::string m_thread_name;
419 std::string m_queue_name;
420 bool m_catch_bp;
421 bool m_throw_bp;
Greg Claytoneb023e72013-10-11 19:48:25 +0000422 bool m_hardware; // Request to use hardware breakpoints
Jim Inghama72b31c2015-04-22 19:42:18 +0000423 lldb::LanguageType m_exception_language;
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000424 lldb::LanguageType m_language;
Jim Ingham5a988412012-06-08 21:56:10 +0000425 LazyBool m_skip_prologue;
Jim Inghamca36cd12012-10-05 19:16:31 +0000426 bool m_one_shot;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000427 bool m_use_dummy;
Jim Inghame7320522015-02-12 17:37:46 +0000428 bool m_all_files;
Jim Inghama72b31c2015-04-22 19:42:18 +0000429 Args m_exception_extra_args;
Ilia K055ad9b2015-05-18 13:41:01 +0000430 LazyBool m_move_to_nearest_code;
Jim Ingham76bb8d62016-04-28 01:40:57 +0000431 std::unordered_set<std::string> m_source_regex_func_names;
Jim Ingham5a988412012-06-08 21:56:10 +0000432 };
433
434protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000435 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000436 DoExecute (Args& command,
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000437 CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +0000438 {
Jim Ingham33df7cd2014-12-06 01:28:03 +0000439 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
440
Jim Ingham893c9322014-11-22 01:42:44 +0000441 if (target == nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +0000442 {
443 result.AppendError ("Invalid target. Must set target before setting breakpoints (see 'target create' command).");
444 result.SetStatus (eReturnStatusFailed);
445 return false;
446 }
447
448 // The following are the various types of breakpoints that could be set:
449 // 1). -f -l -p [-s -g] (setting breakpoint by source location)
450 // 2). -a [-s -g] (setting breakpoint by address)
451 // 3). -n [-s -g] (setting breakpoint by function name)
452 // 4). -r [-s -g] (setting breakpoint by function name regular expression)
453 // 5). -p -f (setting a breakpoint by comparing a reg-exp to source text)
454 // 6). -E [-w -h] (setting a breakpoint for exceptions for a given language.)
455
456 BreakpointSetType break_type = eSetTypeInvalid;
457
458 if (m_options.m_line_num != 0)
459 break_type = eSetTypeFileAndLine;
460 else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
461 break_type = eSetTypeAddress;
462 else if (!m_options.m_func_names.empty())
463 break_type = eSetTypeFunctionName;
464 else if (!m_options.m_func_regexp.empty())
465 break_type = eSetTypeFunctionRegexp;
466 else if (!m_options.m_source_text_regexp.empty())
467 break_type = eSetTypeSourceRegexp;
Jim Inghama72b31c2015-04-22 19:42:18 +0000468 else if (m_options.m_exception_language != eLanguageTypeUnknown)
Jim Ingham5a988412012-06-08 21:56:10 +0000469 break_type = eSetTypeException;
470
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000471 Breakpoint *bp = nullptr;
Jim Ingham5a988412012-06-08 21:56:10 +0000472 FileSpec module_spec;
Jim Ingham5a988412012-06-08 21:56:10 +0000473 const bool internal = false;
Jim Ingham24111672016-03-09 18:59:13 +0000474
475 // If the user didn't specify skip-prologue, having an offset should turn that off.
476 if (m_options.m_offset_addr != 0 && m_options.m_skip_prologue == eLazyBoolCalculate)
477 m_options.m_skip_prologue = eLazyBoolNo;
Jim Ingham5a988412012-06-08 21:56:10 +0000478
Jim Ingham5a988412012-06-08 21:56:10 +0000479 switch (break_type)
480 {
481 case eSetTypeFileAndLine: // Breakpoint by source position
482 {
483 FileSpec file;
Greg Claytonc7bece562013-01-25 18:06:21 +0000484 const size_t num_files = m_options.m_filenames.GetSize();
Jim Ingham5a988412012-06-08 21:56:10 +0000485 if (num_files == 0)
486 {
487 if (!GetDefaultFile (target, file, result))
488 {
489 result.AppendError("No file supplied and no default file available.");
490 result.SetStatus (eReturnStatusFailed);
491 return false;
492 }
493 }
494 else if (num_files > 1)
495 {
496 result.AppendError("Only one file at a time is allowed for file and line breakpoints.");
497 result.SetStatus (eReturnStatusFailed);
498 return false;
499 }
500 else
501 file = m_options.m_filenames.GetFileSpecAtIndex(0);
Greg Clayton1f746072012-08-29 21:13:06 +0000502
503 // Only check for inline functions if
504 LazyBool check_inlines = eLazyBoolCalculate;
505
Jim Ingham5a988412012-06-08 21:56:10 +0000506 bp = target->CreateBreakpoint (&(m_options.m_modules),
507 file,
508 m_options.m_line_num,
Jim Ingham24111672016-03-09 18:59:13 +0000509 m_options.m_offset_addr,
Greg Clayton1f746072012-08-29 21:13:06 +0000510 check_inlines,
Jim Ingham5a988412012-06-08 21:56:10 +0000511 m_options.m_skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000512 internal,
Ilia K055ad9b2015-05-18 13:41:01 +0000513 m_options.m_hardware,
514 m_options.m_move_to_nearest_code).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000515 }
516 break;
517
518 case eSetTypeAddress: // Breakpoint by address
Jim Ingham055a08a2015-11-17 03:39:13 +0000519 {
520 // If a shared library has been specified, make an lldb_private::Address with the library, and
521 // use that. That way the address breakpoint will track the load location of the library.
522 size_t num_modules_specified = m_options.m_modules.GetSize();
523 if (num_modules_specified == 1)
524 {
525 const FileSpec *file_spec = m_options.m_modules.GetFileSpecPointerAtIndex(0);
526 bp = target->CreateAddressInModuleBreakpoint (m_options.m_load_addr,
527 internal,
528 file_spec,
529 m_options.m_hardware).get();
530 }
531 else if (num_modules_specified == 0)
532 {
533 bp = target->CreateBreakpoint (m_options.m_load_addr,
534 internal,
535 m_options.m_hardware).get();
536 }
537 else
538 {
539 result.AppendError("Only one shared library can be specified for address breakpoints.");
540 result.SetStatus(eReturnStatusFailed);
541 return false;
542 }
Jim Ingham5a988412012-06-08 21:56:10 +0000543 break;
Jim Ingham055a08a2015-11-17 03:39:13 +0000544 }
Jim Ingham5a988412012-06-08 21:56:10 +0000545 case eSetTypeFunctionName: // Breakpoint by function name
546 {
547 uint32_t name_type_mask = m_options.m_func_name_type_mask;
548
549 if (name_type_mask == 0)
550 name_type_mask = eFunctionNameTypeAuto;
551
552 bp = target->CreateBreakpoint (&(m_options.m_modules),
553 &(m_options.m_filenames),
554 m_options.m_func_names,
555 name_type_mask,
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000556 m_options.m_language,
Jim Ingham24111672016-03-09 18:59:13 +0000557 m_options.m_offset_addr,
Jim Ingham5a988412012-06-08 21:56:10 +0000558 m_options.m_skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000559 internal,
560 m_options.m_hardware).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000561 }
562 break;
563
564 case eSetTypeFunctionRegexp: // Breakpoint by regular expression function name
565 {
566 RegularExpression regexp(m_options.m_func_regexp.c_str());
567 if (!regexp.IsValid())
568 {
569 char err_str[1024];
570 regexp.GetErrorAsCString(err_str, sizeof(err_str));
571 result.AppendErrorWithFormat("Function name regular expression could not be compiled: \"%s\"",
572 err_str);
573 result.SetStatus (eReturnStatusFailed);
574 return false;
575 }
576
577 bp = target->CreateFuncRegexBreakpoint (&(m_options.m_modules),
578 &(m_options.m_filenames),
579 regexp,
Jim Ingham0fcdac32015-11-06 22:48:59 +0000580 m_options.m_language,
Jim Ingham5a988412012-06-08 21:56:10 +0000581 m_options.m_skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000582 internal,
583 m_options.m_hardware).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000584 }
585 break;
586 case eSetTypeSourceRegexp: // Breakpoint by regexp on source text.
587 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000588 const size_t num_files = m_options.m_filenames.GetSize();
Jim Ingham5a988412012-06-08 21:56:10 +0000589
Jim Inghame7320522015-02-12 17:37:46 +0000590 if (num_files == 0 && !m_options.m_all_files)
Jim Ingham5a988412012-06-08 21:56:10 +0000591 {
592 FileSpec file;
593 if (!GetDefaultFile (target, file, result))
594 {
595 result.AppendError ("No files provided and could not find default file.");
596 result.SetStatus (eReturnStatusFailed);
597 return false;
598 }
599 else
600 {
601 m_options.m_filenames.Append (file);
602 }
603 }
604
605 RegularExpression regexp(m_options.m_source_text_regexp.c_str());
606 if (!regexp.IsValid())
607 {
608 char err_str[1024];
609 regexp.GetErrorAsCString(err_str, sizeof(err_str));
610 result.AppendErrorWithFormat("Source text regular expression could not be compiled: \"%s\"",
611 err_str);
612 result.SetStatus (eReturnStatusFailed);
613 return false;
614 }
Greg Claytoneb023e72013-10-11 19:48:25 +0000615 bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules),
616 &(m_options.m_filenames),
Jim Ingham76bb8d62016-04-28 01:40:57 +0000617 m_options.m_source_regex_func_names,
Greg Claytoneb023e72013-10-11 19:48:25 +0000618 regexp,
619 internal,
Ilia K055ad9b2015-05-18 13:41:01 +0000620 m_options.m_hardware,
621 m_options.m_move_to_nearest_code).get();
Jim Ingham5a988412012-06-08 21:56:10 +0000622 }
623 break;
624 case eSetTypeException:
625 {
Jim Inghama72b31c2015-04-22 19:42:18 +0000626 Error precond_error;
627 bp = target->CreateExceptionBreakpoint (m_options.m_exception_language,
Greg Claytoneb023e72013-10-11 19:48:25 +0000628 m_options.m_catch_bp,
629 m_options.m_throw_bp,
Jim Inghama72b31c2015-04-22 19:42:18 +0000630 internal,
631 &m_options.m_exception_extra_args,
632 &precond_error).get();
633 if (precond_error.Fail())
634 {
635 result.AppendErrorWithFormat("Error setting extra exception arguments: %s",
636 precond_error.AsCString());
637 target->RemoveBreakpointByID(bp->GetID());
638 result.SetStatus(eReturnStatusFailed);
639 return false;
640 }
Jim Ingham5a988412012-06-08 21:56:10 +0000641 }
642 break;
643 default:
644 break;
645 }
646
647 // Now set the various options that were passed in:
648 if (bp)
649 {
650 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
651 bp->SetThreadID (m_options.m_thread_id);
652
653 if (m_options.m_thread_index != UINT32_MAX)
654 bp->GetOptions()->GetThreadSpec()->SetIndex(m_options.m_thread_index);
655
656 if (!m_options.m_thread_name.empty())
657 bp->GetOptions()->GetThreadSpec()->SetName(m_options.m_thread_name.c_str());
658
659 if (!m_options.m_queue_name.empty())
660 bp->GetOptions()->GetThreadSpec()->SetQueueName(m_options.m_queue_name.c_str());
661
662 if (m_options.m_ignore_count != 0)
663 bp->GetOptions()->SetIgnoreCount(m_options.m_ignore_count);
664
665 if (!m_options.m_condition.empty())
666 bp->GetOptions()->SetCondition(m_options.m_condition.c_str());
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000667
668 if (!m_options.m_breakpoint_names.empty())
669 {
670 Error error; // We don't need to check the error here, since the option parser checked it...
671 for (auto name : m_options.m_breakpoint_names)
672 bp->AddName(name.c_str(), error);
673 }
Jim Inghamca36cd12012-10-05 19:16:31 +0000674
675 bp->SetOneShot (m_options.m_one_shot);
Jim Ingham5a988412012-06-08 21:56:10 +0000676 }
677
678 if (bp)
679 {
680 Stream &output_stream = result.GetOutputStream();
Jim Ingham1391cc72012-09-22 00:04:04 +0000681 const bool show_locations = false;
682 bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, show_locations);
Jim Ingham4aeb1982014-12-19 19:45:31 +0000683 if (target == m_interpreter.GetDebugger().GetDummyTarget())
684 output_stream.Printf ("Breakpoint set in dummy target, will get copied into future targets.\n");
685 else
686 {
687 // Don't print out this warning for exception breakpoints. They can get set before the target
688 // is set, but we won't know how to actually set the breakpoint till we run.
689 if (bp->GetNumLocations() == 0 && break_type != eSetTypeException)
690 {
691 output_stream.Printf ("WARNING: Unable to resolve breakpoint to any actual locations.\n");
692 }
693 }
Jim Ingham5a988412012-06-08 21:56:10 +0000694 result.SetStatus (eReturnStatusSuccessFinishResult);
695 }
696 else if (!bp)
697 {
698 result.AppendError ("Breakpoint creation failed: No breakpoint created.");
699 result.SetStatus (eReturnStatusFailed);
700 }
701
702 return result.Succeeded();
703 }
704
705private:
706 bool
707 GetDefaultFile (Target *target, FileSpec &file, CommandReturnObject &result)
708 {
709 uint32_t default_line;
710 // First use the Source Manager's default file.
711 // Then use the current stack frame's file.
712 if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line))
713 {
Jason Molendab57e4a12013-11-04 09:33:30 +0000714 StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000715 if (cur_frame == nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +0000716 {
717 result.AppendError ("No selected frame to use to find the default file.");
718 result.SetStatus (eReturnStatusFailed);
719 return false;
720 }
721 else if (!cur_frame->HasDebugInformation())
722 {
723 result.AppendError ("Cannot use the selected frame to find the default file, it has no debug info.");
724 result.SetStatus (eReturnStatusFailed);
725 return false;
726 }
727 else
728 {
729 const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
730 if (sc.line_entry.file)
731 {
732 file = sc.line_entry.file;
733 }
734 else
735 {
736 result.AppendError ("Can't find the file for the selected frame to use as the default file.");
737 result.SetStatus (eReturnStatusFailed);
738 return false;
739 }
740 }
741 }
742 return true;
743 }
744
745 CommandOptions m_options;
746};
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000747
Johnny Chen6943e7c2012-05-08 00:43:20 +0000748// If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to
749// update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately.
Johnny Chen4ab2e6b2012-05-07 23:23:41 +0000750#define LLDB_OPT_FILE ( LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2 )
751#define LLDB_OPT_NOT_10 ( LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10 )
Jim Inghama8558b62012-05-22 00:12:20 +0000752#define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) )
Jim Ingham24111672016-03-09 18:59:13 +0000753#define LLDB_OPT_OFFSET_APPLIES (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) )
Ilia K055ad9b2015-05-18 13:41:01 +0000754#define LLDB_OPT_MOVE_TO_NEAREST_CODE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_9 )
Jim Ingham0fcdac32015-11-06 22:48:59 +0000755#define LLDB_OPT_EXPR_LANGUAGE ( LLDB_OPT_SET_FROM_TO(3, 8) )
Jim Ingham87df91b2011-09-23 00:54:11 +0000756
Greg Claytone0d378b2011-03-24 21:19:54 +0000757OptionDefinition
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000758CommandObjectBreakpointSet::CommandOptions::g_option_table[] =
759{
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000760 { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000761 "Set the breakpoint only in this shared library. "
762 "Can repeat this option multiple times to specify multiple shared libraries."},
Jim Ingham86511212010-06-15 18:47:14 +0000763
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000764 { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount,
Caroline Ticedeaab222010-10-01 19:59:14 +0000765 "Set the number of times this breakpoint is skipped before stopping." },
Jim Ingham1b54c882010-06-16 02:00:15 +0000766
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000767 { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
Jim Inghamb2b256a2013-04-09 18:05:22 +0000768 "The breakpoint is deleted the first time it causes a stop." },
Jim Inghamca36cd12012-10-05 19:16:31 +0000769
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000770 { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression,
Johnny Chen7d49c9c2012-05-25 21:10:46 +0000771 "The breakpoint stops only if this condition expression evaluates to true."},
772
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000773 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex,
Jim Inghama89be912013-03-26 18:29:03 +0000774 "The breakpoint stops only for the thread whose indeX matches this argument."},
Jim Ingham1b54c882010-06-16 02:00:15 +0000775
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000776 { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID,
Jim Ingham1b54c882010-06-16 02:00:15 +0000777 "The breakpoint stops only for the thread whose TID matches this argument."},
778
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000779 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName,
Jim Ingham1b54c882010-06-16 02:00:15 +0000780 "The breakpoint stops only for the thread whose thread name matches this argument."},
781
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000782 { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
Greg Claytoneb023e72013-10-11 19:48:25 +0000783 "Require the breakpoint to use hardware breakpoints."},
784
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000785 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName,
Jim Ingham1b54c882010-06-16 02:00:15 +0000786 "The breakpoint stops only for threads in the queue whose name is given by this argument."},
787
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000788 { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
Jim Ingham289aca62013-02-14 19:10:36 +0000789 "Specifies the source file in which to set this breakpoint. "
790 "Note, by default lldb only looks for files that are #included if they use the standard include file extensions. "
Jim Ingham63944792013-02-14 19:30:35 +0000791 "To set breakpoints on .c/.cpp/.m/.mm files that are #included, set target.inline-breakpoint-strategy"
Jim Ingham289aca62013-02-14 19:10:36 +0000792 " to \"always\"."},
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000793
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000794 { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum,
Jim Ingham87df91b2011-09-23 00:54:11 +0000795 "Specifies the line number on which to set this breakpoint."},
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797 // Comment out this option for the moment, as we don't actually use it, but will in the future.
798 // This way users won't see it, but the infrastructure is left in place.
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000799 // { 0, false, "column", 'C', OptionParser::eRequiredArgument, nullptr, "<column>",
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000800 // "Set the breakpoint by source location at this particular column."},
801
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000802 { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression,
Jim Ingham055a08a2015-11-17 03:39:13 +0000803 "Set the breakpoint at the specified address. "
804 "If the address maps uniquely to a particular "
805 "binary, then the address will be converted to a \"file\" address, so that the breakpoint will track that binary+offset no matter where "
806 "the binary eventually loads. "
807 "Alternately, if you also specify the module - with the -s option - then the address will be treated as "
808 "a file address in that module, and resolved accordingly. Again, this will allow lldb to track that offset on "
809 "subsequent reloads. The module need not have been loaded at the time you specify this breakpoint, and will "
810 "get resolved when the module is loaded."},
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000811
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000812 { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Jim Ingham551262d2013-03-27 17:36:54 +0000813 "Set the breakpoint by function name. Can be repeated multiple times to make one breakpoint for multiple names" },
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000814
Jim Ingham76bb8d62016-04-28 01:40:57 +0000815 { LLDB_OPT_SET_9, false, "source-regexp-function", 'X', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
816 "When used with '-p' limits the source regex to source contained in the named functions. Can be repeated multiple times." },
817
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000818 { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFullName,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000819 "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and "
Jason Molendac8badb72015-09-28 23:02:00 +0000820 "for Objective C this means a full function prototype with class and selector. "
Jim Ingham64cc29c2012-05-03 20:30:08 +0000821 "Can be repeated multiple times to make one breakpoint for multiple names." },
Greg Clayton0c5cd902010-06-28 21:30:43 +0000822
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000823 { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSelector,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000824 "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." },
Greg Clayton0c5cd902010-06-28 21:30:43 +0000825
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000826 { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeMethod,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000827 "Set the breakpoint by C++ method names. Can be repeated multiple times to make one breakpoint for multiple methods." },
Greg Clayton0c5cd902010-06-28 21:30:43 +0000828
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000829 { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000830 "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." },
831
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000832 { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Jim Ingham64cc29c2012-05-03 20:30:08 +0000833 "Set the breakpoint by function basename (C++ namespaces and arguments will be ignored). "
834 "Can be repeated multiple times to make one breakpoint for multiple symbols." },
Greg Claytone02b8502010-10-12 04:29:14 +0000835
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000836 { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression,
Jim Inghame96ade82013-06-07 01:13:00 +0000837 "Set the breakpoint by specifying a regular expression which is matched against the source text in a source file or files "
838 "specified with the -f option. The -f option can be specified more than once. "
Jim Inghamcc3a4592016-02-09 18:53:49 +0000839 "If no source files are specified, uses the current \"default source file\". "
840 "If you want to match against all source files, pass the \"--all-files\" option." },
Jim Ingham969795f2011-09-21 01:17:13 +0000841
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000842 { LLDB_OPT_SET_9, false, "all-files", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
Jim Inghame7320522015-02-12 17:37:46 +0000843 "All files are searched for source pattern matches." },
844
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000845 { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage,
Jim Inghamfab10e82012-03-06 00:37:27 +0000846 "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" },
847
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000848 { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
Jim Inghamb4a5aa22016-02-10 22:30:20 +0000849 "Set the breakpoint on exception throW." },
Jim Inghamfab10e82012-03-06 00:37:27 +0000850
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000851 { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
Jim Inghamb4a5aa22016-02-10 22:30:20 +0000852 "Set the breakpoint on exception catcH." },
Jim Ingham969795f2011-09-21 01:17:13 +0000853
Jim Inghama72b31c2015-04-22 19:42:18 +0000854// Don't add this option till it actually does something useful...
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000855// { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName,
Jim Inghama72b31c2015-04-22 19:42:18 +0000856// "The breakpoint will only stop if an exception Object of this type is thrown. Can be repeated multiple times to stop for multiple object types" },
857
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000858 { LLDB_OPT_EXPR_LANGUAGE, false, "language", 'L', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage,
Dawn Perchik4112ab92015-07-22 02:01:32 +0000859 "Specifies the Language to use when interpreting the breakpoint's expression (note: currently only implemented for setting breakpoints on identifiers). If not set the target.language setting is used." },
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000860
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000861 { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
Jim Inghama8558b62012-05-22 00:12:20 +0000862 "sKip the prologue if the breakpoint is at the beginning of a function. If not set the target.skip-prologue setting is used." },
863
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000864 { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
Jim Ingham33df7cd2014-12-06 01:28:03 +0000865 "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
866
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000867 { LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName,
Jim Ingham76bb8d62016-04-28 01:40:57 +0000868 "Adds this to the list of names for this breakpoint."},
Jim Ingham5e09c8c2014-12-16 23:40:14 +0000869
Jim Ingham24111672016-03-09 18:59:13 +0000870 { LLDB_OPT_OFFSET_APPLIES, false, "address-slide", 'R', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddress,
871 "Add the specified offset to whatever address(es) the breakpoint resolves to. "
872 "At present this applies the offset directly as given, and doesn't try to align it to instruction boundaries."},
873
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000874 { LLDB_OPT_MOVE_TO_NEAREST_CODE, false, "move-to-nearest-code", 'm', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,
Ilia K055ad9b2015-05-18 13:41:01 +0000875 "Move breakpoints to nearest code. If not set the target.move-to-nearest-code setting is used." },
876
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000877 { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000878};
879
Jim Ingham5a988412012-06-08 21:56:10 +0000880//-------------------------------------------------------------------------
881// CommandObjectBreakpointModify
882//-------------------------------------------------------------------------
883#pragma mark Modify
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000884
Jim Ingham5a988412012-06-08 21:56:10 +0000885class CommandObjectBreakpointModify : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000886{
Jim Ingham5a988412012-06-08 21:56:10 +0000887public:
Jim Ingham5a988412012-06-08 21:56:10 +0000888 CommandObjectBreakpointModify (CommandInterpreter &interpreter) :
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000889 CommandObjectParsed(interpreter,
890 "breakpoint modify",
891 "Modify the options on a breakpoint or set of breakpoints in the executable. "
892 "If no breakpoint is specified, acts on the last created breakpoint. "
893 "With the exception of -e, -d and -i, passing an empty argument clears the modification.",
894 nullptr),
Jim Ingham5a988412012-06-08 21:56:10 +0000895 m_options (interpreter)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000896 {
Jim Ingham5a988412012-06-08 21:56:10 +0000897 CommandArgumentEntry arg;
898 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
899 // Add the entry for the first argument for this command to the object's arguments vector.
900 m_arguments.push_back (arg);
901 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000902
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000903 ~CommandObjectBreakpointModify() override = default;
Greg Clayton0c5cd902010-06-28 21:30:43 +0000904
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000905 Options *
906 GetOptions () override
Jim Ingham5a988412012-06-08 21:56:10 +0000907 {
908 return &m_options;
909 }
Johnny Chen7d49c9c2012-05-25 21:10:46 +0000910
Jim Ingham5a988412012-06-08 21:56:10 +0000911 class CommandOptions : public Options
912 {
913 public:
Jim Ingham5a988412012-06-08 21:56:10 +0000914 CommandOptions (CommandInterpreter &interpreter) :
915 Options (interpreter),
916 m_ignore_count (0),
917 m_thread_id(LLDB_INVALID_THREAD_ID),
918 m_thread_id_passed(false),
919 m_thread_index (UINT32_MAX),
920 m_thread_index_passed(false),
921 m_thread_name(),
922 m_queue_name(),
923 m_condition (),
Jim Inghamca36cd12012-10-05 19:16:31 +0000924 m_one_shot (false),
Jim Ingham5a988412012-06-08 21:56:10 +0000925 m_enable_passed (false),
926 m_enable_value (false),
927 m_name_passed (false),
928 m_queue_passed (false),
Jim Inghamca36cd12012-10-05 19:16:31 +0000929 m_condition_passed (false),
Jim Ingham33df7cd2014-12-06 01:28:03 +0000930 m_one_shot_passed (false),
931 m_use_dummy (false)
Jim Ingham5a988412012-06-08 21:56:10 +0000932 {
933 }
Greg Clayton0c5cd902010-06-28 21:30:43 +0000934
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000935 ~CommandOptions() override = default;
Greg Clayton0c5cd902010-06-28 21:30:43 +0000936
Bruce Mitchener13d21e92015-10-07 16:56:17 +0000937 Error
938 SetOptionValue (uint32_t option_idx, const char *option_arg) override
Jim Ingham5a988412012-06-08 21:56:10 +0000939 {
940 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000941 const int short_option = m_getopt_table[option_idx].val;
Greg Claytone02b8502010-10-12 04:29:14 +0000942
Jim Ingham5a988412012-06-08 21:56:10 +0000943 switch (short_option)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000944 {
Jim Ingham5a988412012-06-08 21:56:10 +0000945 case 'c':
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000946 if (option_arg != nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +0000947 m_condition.assign (option_arg);
948 else
949 m_condition.clear();
950 m_condition_passed = true;
951 break;
952 case 'd':
953 m_enable_passed = true;
954 m_enable_value = false;
955 break;
Jim Ingham33df7cd2014-12-06 01:28:03 +0000956 case 'D':
957 m_use_dummy = true;
958 break;
Jim Ingham5a988412012-06-08 21:56:10 +0000959 case 'e':
960 m_enable_passed = true;
961 m_enable_value = true;
962 break;
963 case 'i':
Vince Harron5275aaa2015-01-15 20:08:35 +0000964 m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
Jim Ingham5a988412012-06-08 21:56:10 +0000965 if (m_ignore_count == UINT32_MAX)
966 error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000967 break;
Jim Inghamca36cd12012-10-05 19:16:31 +0000968 case 'o':
969 {
970 bool value, success;
971 value = Args::StringToBoolean(option_arg, false, &success);
972 if (success)
973 {
974 m_one_shot_passed = true;
975 m_one_shot = value;
976 }
977 else
978 error.SetErrorStringWithFormat("invalid boolean value '%s' passed for -o option", option_arg);
979 }
980 break;
Jim Ingham5a988412012-06-08 21:56:10 +0000981 case 't' :
Jim Ingham5a988412012-06-08 21:56:10 +0000982 if (option_arg[0] == '\0')
Jim Ingham87df91b2011-09-23 00:54:11 +0000983 {
Jim Ingham5a988412012-06-08 21:56:10 +0000984 m_thread_id = LLDB_INVALID_THREAD_ID;
985 m_thread_id_passed = true;
Jim Ingham87df91b2011-09-23 00:54:11 +0000986 }
987 else
988 {
Vince Harron5275aaa2015-01-15 20:08:35 +0000989 m_thread_id = StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Ingham5a988412012-06-08 21:56:10 +0000990 if (m_thread_id == LLDB_INVALID_THREAD_ID)
991 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
992 else
993 m_thread_id_passed = true;
Jim Ingham87df91b2011-09-23 00:54:11 +0000994 }
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000995 break;
Jim Ingham5a988412012-06-08 21:56:10 +0000996 case 'T':
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +0000997 if (option_arg != nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +0000998 m_thread_name.assign (option_arg);
999 else
1000 m_thread_name.clear();
1001 m_name_passed = true;
1002 break;
1003 case 'q':
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001004 if (option_arg != nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +00001005 m_queue_name.assign (option_arg);
1006 else
1007 m_queue_name.clear();
1008 m_queue_passed = true;
1009 break;
1010 case 'x':
Jim Ingham5a988412012-06-08 21:56:10 +00001011 if (option_arg[0] == '\n')
1012 {
1013 m_thread_index = UINT32_MAX;
1014 m_thread_index_passed = true;
1015 }
1016 else
1017 {
Vince Harron5275aaa2015-01-15 20:08:35 +00001018 m_thread_index = StringConvert::ToUInt32 (option_arg, UINT32_MAX, 0);
Jim Ingham5a988412012-06-08 21:56:10 +00001019 if (m_thread_id == UINT32_MAX)
1020 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
1021 else
1022 m_thread_index_passed = true;
1023 }
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001024 break;
Jim Ingham5a988412012-06-08 21:56:10 +00001025 default:
1026 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1027 break;
Jim Ingham969795f2011-09-21 01:17:13 +00001028 }
Jim Ingham5a988412012-06-08 21:56:10 +00001029
1030 return error;
1031 }
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001032
Jim Ingham5a988412012-06-08 21:56:10 +00001033 void
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001034 OptionParsingStarting () override
Jim Ingham5a988412012-06-08 21:56:10 +00001035 {
1036 m_ignore_count = 0;
1037 m_thread_id = LLDB_INVALID_THREAD_ID;
1038 m_thread_id_passed = false;
1039 m_thread_index = UINT32_MAX;
1040 m_thread_index_passed = false;
1041 m_thread_name.clear();
1042 m_queue_name.clear();
1043 m_condition.clear();
Jim Inghamca36cd12012-10-05 19:16:31 +00001044 m_one_shot = false;
Jim Ingham5a988412012-06-08 21:56:10 +00001045 m_enable_passed = false;
1046 m_queue_passed = false;
1047 m_name_passed = false;
1048 m_condition_passed = false;
Jim Inghamca36cd12012-10-05 19:16:31 +00001049 m_one_shot_passed = false;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001050 m_use_dummy = false;
Jim Ingham5a988412012-06-08 21:56:10 +00001051 }
1052
1053 const OptionDefinition*
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001054 GetDefinitions () override
Jim Ingham5a988412012-06-08 21:56:10 +00001055 {
1056 return g_option_table;
1057 }
1058
Jim Ingham5a988412012-06-08 21:56:10 +00001059 // Options table: Required for subclasses of Options.
1060
1061 static OptionDefinition g_option_table[];
1062
1063 // Instance variables to hold the values for command options.
1064
1065 uint32_t m_ignore_count;
1066 lldb::tid_t m_thread_id;
1067 bool m_thread_id_passed;
1068 uint32_t m_thread_index;
1069 bool m_thread_index_passed;
1070 std::string m_thread_name;
1071 std::string m_queue_name;
1072 std::string m_condition;
Jim Inghamca36cd12012-10-05 19:16:31 +00001073 bool m_one_shot;
Jim Ingham5a988412012-06-08 21:56:10 +00001074 bool m_enable_passed;
1075 bool m_enable_value;
1076 bool m_name_passed;
1077 bool m_queue_passed;
1078 bool m_condition_passed;
Jim Inghamca36cd12012-10-05 19:16:31 +00001079 bool m_one_shot_passed;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001080 bool m_use_dummy;
Jim Ingham5a988412012-06-08 21:56:10 +00001081 };
1082
1083protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001084 bool
1085 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +00001086 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001087 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001088 if (target == nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +00001089 {
1090 result.AppendError ("Invalid target. No existing target or breakpoints.");
1091 result.SetStatus (eReturnStatusFailed);
1092 return false;
1093 }
1094
Saleem Abdulrasoolbb19a132016-05-19 05:13:57 +00001095 std::unique_lock<std::recursive_mutex> lock;
1096 target->GetBreakpointList().GetListMutex(lock);
1097
Jim Ingham5a988412012-06-08 21:56:10 +00001098 BreakpointIDList valid_bp_ids;
1099
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001100 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +00001101
1102 if (result.Succeeded())
1103 {
1104 const size_t count = valid_bp_ids.GetSize();
1105 for (size_t i = 0; i < count; ++i)
Jim Inghamfab10e82012-03-06 00:37:27 +00001106 {
Jim Ingham5a988412012-06-08 21:56:10 +00001107 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1108
1109 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1110 {
1111 Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1112 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1113 {
1114 BreakpointLocation *location = bp->FindLocationByID (cur_bp_id.GetLocationID()).get();
1115 if (location)
1116 {
1117 if (m_options.m_thread_id_passed)
1118 location->SetThreadID (m_options.m_thread_id);
1119
1120 if (m_options.m_thread_index_passed)
1121 location->SetThreadIndex(m_options.m_thread_index);
1122
1123 if (m_options.m_name_passed)
1124 location->SetThreadName(m_options.m_thread_name.c_str());
1125
1126 if (m_options.m_queue_passed)
1127 location->SetQueueName(m_options.m_queue_name.c_str());
1128
1129 if (m_options.m_ignore_count != 0)
1130 location->SetIgnoreCount(m_options.m_ignore_count);
1131
1132 if (m_options.m_enable_passed)
1133 location->SetEnabled (m_options.m_enable_value);
1134
1135 if (m_options.m_condition_passed)
1136 location->SetCondition (m_options.m_condition.c_str());
1137 }
1138 }
1139 else
1140 {
1141 if (m_options.m_thread_id_passed)
1142 bp->SetThreadID (m_options.m_thread_id);
1143
1144 if (m_options.m_thread_index_passed)
1145 bp->SetThreadIndex(m_options.m_thread_index);
1146
1147 if (m_options.m_name_passed)
1148 bp->SetThreadName(m_options.m_thread_name.c_str());
1149
1150 if (m_options.m_queue_passed)
1151 bp->SetQueueName(m_options.m_queue_name.c_str());
1152
1153 if (m_options.m_ignore_count != 0)
1154 bp->SetIgnoreCount(m_options.m_ignore_count);
1155
1156 if (m_options.m_enable_passed)
1157 bp->SetEnabled (m_options.m_enable_value);
1158
1159 if (m_options.m_condition_passed)
1160 bp->SetCondition (m_options.m_condition.c_str());
1161 }
1162 }
Jim Inghamfab10e82012-03-06 00:37:27 +00001163 }
Jim Ingham5a988412012-06-08 21:56:10 +00001164 }
1165
1166 return result.Succeeded();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001167 }
1168
Jim Ingham5a988412012-06-08 21:56:10 +00001169private:
1170 CommandOptions m_options;
1171};
Johnny Chen7d49c9c2012-05-25 21:10:46 +00001172
Jim Ingham5a988412012-06-08 21:56:10 +00001173#pragma mark Modify::CommandOptions
1174OptionDefinition
1175CommandObjectBreakpointModify::CommandOptions::g_option_table[] =
1176{
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001177{ LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." },
1178{ LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "The breakpoint is deleted the first time it stop causes a stop." },
1179{ LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose index matches this argument."},
1180{ LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."},
1181{ LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."},
1182{ LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."},
1183{ LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."},
1184{ LLDB_OPT_SET_1, false, "enable", 'e', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable the breakpoint."},
1185{ LLDB_OPT_SET_2, false, "disable", 'd', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Disable the breakpoint."},
1186{ LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
Jim Ingham33df7cd2014-12-06 01:28:03 +00001187
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001188{ 0, false, nullptr, 0 , 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
Jim Ingham5a988412012-06-08 21:56:10 +00001189};
1190
1191//-------------------------------------------------------------------------
1192// CommandObjectBreakpointEnable
1193//-------------------------------------------------------------------------
1194#pragma mark Enable
1195
1196class CommandObjectBreakpointEnable : public CommandObjectParsed
1197{
1198public:
1199 CommandObjectBreakpointEnable (CommandInterpreter &interpreter) :
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001200 CommandObjectParsed(interpreter,
1201 "enable",
1202 "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.",
1203 nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +00001204 {
1205 CommandArgumentEntry arg;
1206 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1207 // Add the entry for the first argument for this command to the object's arguments vector.
1208 m_arguments.push_back (arg);
1209 }
1210
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001211 ~CommandObjectBreakpointEnable() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +00001212
1213protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001214 bool
1215 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +00001216 {
Jim Ingham893c9322014-11-22 01:42:44 +00001217 Target *target = GetSelectedOrDummyTarget();
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001218 if (target == nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +00001219 {
1220 result.AppendError ("Invalid target. No existing target or breakpoints.");
1221 result.SetStatus (eReturnStatusFailed);
1222 return false;
1223 }
1224
Saleem Abdulrasoolbb19a132016-05-19 05:13:57 +00001225 std::unique_lock<std::recursive_mutex> lock;
1226 target->GetBreakpointList().GetListMutex(lock);
Jim Ingham5a988412012-06-08 21:56:10 +00001227
1228 const BreakpointList &breakpoints = target->GetBreakpointList();
1229
1230 size_t num_breakpoints = breakpoints.GetSize();
1231
1232 if (num_breakpoints == 0)
1233 {
1234 result.AppendError ("No breakpoints exist to be enabled.");
1235 result.SetStatus (eReturnStatusFailed);
1236 return false;
1237 }
1238
1239 if (command.GetArgumentCount() == 0)
1240 {
1241 // No breakpoint selected; enable all currently set breakpoints.
1242 target->EnableAllBreakpoints ();
Greg Clayton6fea17e2014-03-03 19:15:20 +00001243 result.AppendMessageWithFormat ("All breakpoints enabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints);
Jim Ingham5a988412012-06-08 21:56:10 +00001244 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1245 }
1246 else
1247 {
1248 // Particular breakpoint selected; enable that breakpoint.
1249 BreakpointIDList valid_bp_ids;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001250 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +00001251
1252 if (result.Succeeded())
1253 {
1254 int enable_count = 0;
1255 int loc_count = 0;
1256 const size_t count = valid_bp_ids.GetSize();
1257 for (size_t i = 0; i < count; ++i)
1258 {
1259 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1260
1261 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1262 {
1263 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1264 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1265 {
1266 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1267 if (location)
1268 {
1269 location->SetEnabled (true);
1270 ++loc_count;
1271 }
1272 }
1273 else
1274 {
1275 breakpoint->SetEnabled (true);
1276 ++enable_count;
1277 }
1278 }
1279 }
1280 result.AppendMessageWithFormat ("%d breakpoints enabled.\n", enable_count + loc_count);
1281 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1282 }
1283 }
1284
1285 return result.Succeeded();
1286 }
1287};
1288
1289//-------------------------------------------------------------------------
1290// CommandObjectBreakpointDisable
1291//-------------------------------------------------------------------------
1292#pragma mark Disable
1293
1294class CommandObjectBreakpointDisable : public CommandObjectParsed
1295{
1296public:
Kate Stone7428a182016-07-14 22:03:10 +00001297 CommandObjectBreakpointDisable(CommandInterpreter &interpreter)
1298 : CommandObjectParsed(interpreter, "breakpoint disable", "Disable the specified breakpoint(s) without deleting "
1299 "them. If none are specified, disable all "
1300 "breakpoints.",
1301 nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +00001302 {
Kate Stone7428a182016-07-14 22:03:10 +00001303 SetHelpLong("Disable the specified breakpoint(s) without deleting them. \
1304If none are specified, disable all breakpoints."
1305 R"(
Kate Stoneea671fb2015-07-14 05:48:36 +00001306
Kate Stone7428a182016-07-14 22:03:10 +00001307)"
1308 "Note: disabling a breakpoint will cause none of its locations to be hit \
1309regardless of whether individual locations are enabled or disabled. After the sequence:"
1310 R"(
Kate Stoneea671fb2015-07-14 05:48:36 +00001311
1312 (lldb) break disable 1
1313 (lldb) break enable 1.1
1314
1315execution will NOT stop at location 1.1. To achieve that, type:
1316
1317 (lldb) break disable 1.*
1318 (lldb) break enable 1.1
1319
Kate Stone7428a182016-07-14 22:03:10 +00001320)"
1321 "The first command disables all locations for breakpoint 1, \
1322the second re-enables the first location.");
1323
Jim Ingham5a988412012-06-08 21:56:10 +00001324 CommandArgumentEntry arg;
1325 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1326 // Add the entry for the first argument for this command to the object's arguments vector.
Jim Inghamb0fac502013-03-08 00:31:40 +00001327 m_arguments.push_back (arg);
Jim Ingham5a988412012-06-08 21:56:10 +00001328 }
1329
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001330 ~CommandObjectBreakpointDisable() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +00001331
1332protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001333 bool
1334 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +00001335 {
Jim Ingham893c9322014-11-22 01:42:44 +00001336 Target *target = GetSelectedOrDummyTarget();
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001337 if (target == nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +00001338 {
1339 result.AppendError ("Invalid target. No existing target or breakpoints.");
1340 result.SetStatus (eReturnStatusFailed);
1341 return false;
1342 }
1343
Saleem Abdulrasoolbb19a132016-05-19 05:13:57 +00001344 std::unique_lock<std::recursive_mutex> lock;
1345 target->GetBreakpointList().GetListMutex(lock);
Jim Ingham5a988412012-06-08 21:56:10 +00001346
1347 const BreakpointList &breakpoints = target->GetBreakpointList();
1348 size_t num_breakpoints = breakpoints.GetSize();
1349
1350 if (num_breakpoints == 0)
1351 {
1352 result.AppendError ("No breakpoints exist to be disabled.");
1353 result.SetStatus (eReturnStatusFailed);
1354 return false;
1355 }
1356
1357 if (command.GetArgumentCount() == 0)
1358 {
1359 // No breakpoint selected; disable all currently set breakpoints.
1360 target->DisableAllBreakpoints ();
Greg Clayton6fea17e2014-03-03 19:15:20 +00001361 result.AppendMessageWithFormat ("All breakpoints disabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints);
Jim Ingham5a988412012-06-08 21:56:10 +00001362 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1363 }
1364 else
1365 {
1366 // Particular breakpoint selected; disable that breakpoint.
1367 BreakpointIDList valid_bp_ids;
1368
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001369 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +00001370
1371 if (result.Succeeded())
1372 {
1373 int disable_count = 0;
1374 int loc_count = 0;
1375 const size_t count = valid_bp_ids.GetSize();
1376 for (size_t i = 0; i < count; ++i)
1377 {
1378 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1379
1380 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1381 {
1382 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1383 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1384 {
1385 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1386 if (location)
1387 {
1388 location->SetEnabled (false);
1389 ++loc_count;
1390 }
1391 }
1392 else
1393 {
1394 breakpoint->SetEnabled (false);
1395 ++disable_count;
1396 }
1397 }
1398 }
1399 result.AppendMessageWithFormat ("%d breakpoints disabled.\n", disable_count + loc_count);
1400 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1401 }
1402 }
1403
1404 return result.Succeeded();
1405 }
Jim Ingham5a988412012-06-08 21:56:10 +00001406};
1407
1408//-------------------------------------------------------------------------
1409// CommandObjectBreakpointList
1410//-------------------------------------------------------------------------
1411#pragma mark List
1412
1413class CommandObjectBreakpointList : public CommandObjectParsed
1414{
1415public:
1416 CommandObjectBreakpointList (CommandInterpreter &interpreter) :
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001417 CommandObjectParsed(interpreter,
1418 "breakpoint list",
1419 "List some or all breakpoints at configurable levels of detail.",
1420 nullptr),
Jim Ingham5a988412012-06-08 21:56:10 +00001421 m_options (interpreter)
1422 {
1423 CommandArgumentEntry arg;
1424 CommandArgumentData bp_id_arg;
1425
1426 // Define the first (and only) variant of this arg.
1427 bp_id_arg.arg_type = eArgTypeBreakpointID;
1428 bp_id_arg.arg_repetition = eArgRepeatOptional;
1429
1430 // There is only one variant this argument could be; put it into the argument entry.
1431 arg.push_back (bp_id_arg);
1432
1433 // Push the data for the first argument into the m_arguments vector.
1434 m_arguments.push_back (arg);
1435 }
1436
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001437 ~CommandObjectBreakpointList() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +00001438
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001439 Options *
1440 GetOptions () override
Jim Ingham5a988412012-06-08 21:56:10 +00001441 {
1442 return &m_options;
Jim Ingham1b54c882010-06-16 02:00:15 +00001443 }
1444
Jim Ingham5a988412012-06-08 21:56:10 +00001445 class CommandOptions : public Options
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001446 {
Jim Ingham5a988412012-06-08 21:56:10 +00001447 public:
Jim Ingham5a988412012-06-08 21:56:10 +00001448 CommandOptions (CommandInterpreter &interpreter) :
1449 Options (interpreter),
Jim Ingham33df7cd2014-12-06 01:28:03 +00001450 m_level (lldb::eDescriptionLevelBrief),
1451 m_use_dummy(false)
Jim Ingham5a988412012-06-08 21:56:10 +00001452 {
1453 }
1454
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001455 ~CommandOptions() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +00001456
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001457 Error
1458 SetOptionValue (uint32_t option_idx, const char *option_arg) override
Jim Ingham5a988412012-06-08 21:56:10 +00001459 {
1460 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00001461 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham5a988412012-06-08 21:56:10 +00001462
1463 switch (short_option)
1464 {
1465 case 'b':
1466 m_level = lldb::eDescriptionLevelBrief;
1467 break;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001468 case 'D':
1469 m_use_dummy = true;
1470 break;
Jim Ingham5a988412012-06-08 21:56:10 +00001471 case 'f':
1472 m_level = lldb::eDescriptionLevelFull;
1473 break;
1474 case 'v':
1475 m_level = lldb::eDescriptionLevelVerbose;
1476 break;
1477 case 'i':
1478 m_internal = true;
1479 break;
1480 default:
1481 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1482 break;
1483 }
1484
1485 return error;
1486 }
1487
1488 void
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001489 OptionParsingStarting () override
Jim Ingham5a988412012-06-08 21:56:10 +00001490 {
1491 m_level = lldb::eDescriptionLevelFull;
1492 m_internal = false;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001493 m_use_dummy = false;
Jim Ingham5a988412012-06-08 21:56:10 +00001494 }
1495
1496 const OptionDefinition *
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001497 GetDefinitions () override
Jim Ingham5a988412012-06-08 21:56:10 +00001498 {
1499 return g_option_table;
1500 }
1501
1502 // Options table: Required for subclasses of Options.
1503
1504 static OptionDefinition g_option_table[];
1505
1506 // Instance variables to hold the values for command options.
1507
1508 lldb::DescriptionLevel m_level;
1509
1510 bool m_internal;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001511 bool m_use_dummy;
Jim Ingham5a988412012-06-08 21:56:10 +00001512 };
1513
1514protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001515 bool
1516 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +00001517 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001518 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
1519
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001520 if (target == nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +00001521 {
1522 result.AppendError ("Invalid target. No current target or breakpoints.");
1523 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1524 return true;
1525 }
1526
1527 const BreakpointList &breakpoints = target->GetBreakpointList(m_options.m_internal);
Saleem Abdulrasoolbb19a132016-05-19 05:13:57 +00001528 std::unique_lock<std::recursive_mutex> lock;
1529 target->GetBreakpointList(m_options.m_internal).GetListMutex(lock);
Jim Ingham5a988412012-06-08 21:56:10 +00001530
1531 size_t num_breakpoints = breakpoints.GetSize();
1532
1533 if (num_breakpoints == 0)
1534 {
1535 result.AppendMessage ("No breakpoints currently set.");
1536 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1537 return true;
1538 }
1539
Jim Ingham85e8b812011-02-19 02:53:09 +00001540 Stream &output_stream = result.GetOutputStream();
Jim Ingham5a988412012-06-08 21:56:10 +00001541
1542 if (command.GetArgumentCount() == 0)
1543 {
1544 // No breakpoint selected; show info about all currently set breakpoints.
1545 result.AppendMessage ("Current breakpoints:");
1546 for (size_t i = 0; i < num_breakpoints; ++i)
1547 {
1548 Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex (i).get();
1549 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
1550 }
1551 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1552 }
1553 else
1554 {
1555 // Particular breakpoints selected; show info about that breakpoint.
1556 BreakpointIDList valid_bp_ids;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001557 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +00001558
1559 if (result.Succeeded())
1560 {
1561 for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i)
1562 {
1563 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1564 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1565 AddBreakpointDescription (&output_stream, breakpoint, m_options.m_level);
1566 }
1567 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1568 }
1569 else
1570 {
Kate Stone7428a182016-07-14 22:03:10 +00001571 result.AppendError("Invalid breakpoint ID.");
Jim Ingham5a988412012-06-08 21:56:10 +00001572 result.SetStatus (eReturnStatusFailed);
1573 }
1574 }
1575
1576 return result.Succeeded();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001577 }
1578
Jim Ingham5a988412012-06-08 21:56:10 +00001579private:
1580 CommandOptions m_options;
1581};
1582
1583#pragma mark List::CommandOptions
1584OptionDefinition
1585CommandObjectBreakpointList::CommandOptions::g_option_table[] =
1586{
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001587 { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
Jim Ingham5a988412012-06-08 21:56:10 +00001588 "Show debugger internal breakpoints" },
1589
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001590 { LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
Jim Ingham5a988412012-06-08 21:56:10 +00001591 "Give a brief description of the breakpoint (no location info)."},
1592
1593 // FIXME: We need to add an "internal" command, and then add this sort of thing to it.
1594 // But I need to see it for now, and don't want to wait.
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001595 { LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
Jim Ingham5a988412012-06-08 21:56:10 +00001596 "Give a full description of the breakpoint and its locations."},
1597
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001598 { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
Jim Ingham5a988412012-06-08 21:56:10 +00001599 "Explain everything we know about the breakpoint (for debugging debugger bugs)." },
1600
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001601 { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
Jim Ingham33df7cd2014-12-06 01:28:03 +00001602 "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
1603
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001604 { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
Jim Ingham5a988412012-06-08 21:56:10 +00001605};
1606
1607//-------------------------------------------------------------------------
1608// CommandObjectBreakpointClear
1609//-------------------------------------------------------------------------
1610#pragma mark Clear
1611
1612class CommandObjectBreakpointClear : public CommandObjectParsed
1613{
1614public:
Jim Ingham5a988412012-06-08 21:56:10 +00001615 typedef enum BreakpointClearType
1616 {
1617 eClearTypeInvalid,
1618 eClearTypeFileAndLine
1619 } BreakpointClearType;
1620
Kate Stone7428a182016-07-14 22:03:10 +00001621 CommandObjectBreakpointClear(CommandInterpreter &interpreter)
1622 : CommandObjectParsed(interpreter, "breakpoint clear",
1623 "Delete or disable breakpoints matching the specified source file and line.",
1624 "breakpoint clear <cmd-options>"),
1625 m_options(interpreter)
Jim Ingham5a988412012-06-08 21:56:10 +00001626 {
1627 }
1628
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001629 ~CommandObjectBreakpointClear() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +00001630
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001631 Options *
1632 GetOptions () override
Jim Ingham5a988412012-06-08 21:56:10 +00001633 {
1634 return &m_options;
1635 }
1636
1637 class CommandOptions : public Options
1638 {
1639 public:
Jim Ingham5a988412012-06-08 21:56:10 +00001640 CommandOptions (CommandInterpreter &interpreter) :
1641 Options (interpreter),
1642 m_filename (),
1643 m_line_num (0)
1644 {
1645 }
1646
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001647 ~CommandOptions() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +00001648
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001649 Error
1650 SetOptionValue (uint32_t option_idx, const char *option_arg) override
Jim Ingham5a988412012-06-08 21:56:10 +00001651 {
1652 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00001653 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham5a988412012-06-08 21:56:10 +00001654
1655 switch (short_option)
1656 {
1657 case 'f':
1658 m_filename.assign (option_arg);
1659 break;
1660
1661 case 'l':
Vince Harron5275aaa2015-01-15 20:08:35 +00001662 m_line_num = StringConvert::ToUInt32 (option_arg, 0);
Jim Ingham5a988412012-06-08 21:56:10 +00001663 break;
1664
1665 default:
1666 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1667 break;
1668 }
1669
1670 return error;
1671 }
1672
1673 void
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001674 OptionParsingStarting () override
Jim Ingham5a988412012-06-08 21:56:10 +00001675 {
1676 m_filename.clear();
1677 m_line_num = 0;
1678 }
1679
1680 const OptionDefinition*
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001681 GetDefinitions () override
Jim Ingham5a988412012-06-08 21:56:10 +00001682 {
1683 return g_option_table;
1684 }
1685
1686 // Options table: Required for subclasses of Options.
1687
1688 static OptionDefinition g_option_table[];
1689
1690 // Instance variables to hold the values for command options.
1691
1692 std::string m_filename;
1693 uint32_t m_line_num;
1694
1695 };
1696
1697protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001698 bool
1699 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +00001700 {
Jim Ingham893c9322014-11-22 01:42:44 +00001701 Target *target = GetSelectedOrDummyTarget();
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001702 if (target == nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +00001703 {
1704 result.AppendError ("Invalid target. No existing target or breakpoints.");
1705 result.SetStatus (eReturnStatusFailed);
1706 return false;
1707 }
1708
1709 // The following are the various types of breakpoints that could be cleared:
1710 // 1). -f -l (clearing breakpoint by source location)
1711
1712 BreakpointClearType break_type = eClearTypeInvalid;
1713
1714 if (m_options.m_line_num != 0)
1715 break_type = eClearTypeFileAndLine;
1716
Saleem Abdulrasoolbb19a132016-05-19 05:13:57 +00001717 std::unique_lock<std::recursive_mutex> lock;
1718 target->GetBreakpointList().GetListMutex(lock);
Jim Ingham5a988412012-06-08 21:56:10 +00001719
1720 BreakpointList &breakpoints = target->GetBreakpointList();
1721 size_t num_breakpoints = breakpoints.GetSize();
1722
1723 // Early return if there's no breakpoint at all.
1724 if (num_breakpoints == 0)
1725 {
1726 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1727 result.SetStatus (eReturnStatusFailed);
1728 return result.Succeeded();
1729 }
1730
1731 // Find matching breakpoints and delete them.
1732
1733 // First create a copy of all the IDs.
1734 std::vector<break_id_t> BreakIDs;
1735 for (size_t i = 0; i < num_breakpoints; ++i)
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001736 BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID());
Jim Ingham5a988412012-06-08 21:56:10 +00001737
1738 int num_cleared = 0;
1739 StreamString ss;
1740 switch (break_type)
1741 {
1742 case eClearTypeFileAndLine: // Breakpoint by source position
1743 {
1744 const ConstString filename(m_options.m_filename.c_str());
1745 BreakpointLocationCollection loc_coll;
1746
1747 for (size_t i = 0; i < num_breakpoints; ++i)
1748 {
1749 Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get();
1750
1751 if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll))
1752 {
1753 // If the collection size is 0, it's a full match and we can just remove the breakpoint.
1754 if (loc_coll.GetSize() == 0)
1755 {
1756 bp->GetDescription(&ss, lldb::eDescriptionLevelBrief);
1757 ss.EOL();
1758 target->RemoveBreakpointByID (bp->GetID());
1759 ++num_cleared;
1760 }
1761 }
1762 }
1763 }
1764 break;
1765
1766 default:
1767 break;
1768 }
1769
1770 if (num_cleared > 0)
1771 {
1772 Stream &output_stream = result.GetOutputStream();
1773 output_stream.Printf ("%d breakpoints cleared:\n", num_cleared);
1774 output_stream << ss.GetData();
1775 output_stream.EOL();
1776 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1777 }
1778 else
1779 {
1780 result.AppendError ("Breakpoint clear: No breakpoint cleared.");
1781 result.SetStatus (eReturnStatusFailed);
1782 }
1783
1784 return result.Succeeded();
1785 }
1786
1787private:
1788 CommandOptions m_options;
1789};
1790
1791#pragma mark Clear::CommandOptions
1792
1793OptionDefinition
1794CommandObjectBreakpointClear::CommandOptions::g_option_table[] =
1795{
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001796 { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
Jim Ingham5a988412012-06-08 21:56:10 +00001797 "Specify the breakpoint by source location in this particular file."},
1798
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001799 { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum,
Jim Ingham5a988412012-06-08 21:56:10 +00001800 "Specify the breakpoint by source location at this particular line."},
1801
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001802 { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
Jim Ingham5a988412012-06-08 21:56:10 +00001803};
1804
1805//-------------------------------------------------------------------------
1806// CommandObjectBreakpointDelete
1807//-------------------------------------------------------------------------
1808#pragma mark Delete
1809
1810class CommandObjectBreakpointDelete : public CommandObjectParsed
1811{
1812public:
1813 CommandObjectBreakpointDelete (CommandInterpreter &interpreter) :
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001814 CommandObjectParsed(interpreter,
1815 "breakpoint delete",
1816 "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.",
1817 nullptr),
Jim Ingham33df7cd2014-12-06 01:28:03 +00001818 m_options (interpreter)
Jim Ingham5a988412012-06-08 21:56:10 +00001819 {
1820 CommandArgumentEntry arg;
1821 CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, eArgTypeBreakpointIDRange);
1822 // Add the entry for the first argument for this command to the object's arguments vector.
1823 m_arguments.push_back (arg);
1824 }
1825
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001826 ~CommandObjectBreakpointDelete() override = default;
Jim Ingham5a988412012-06-08 21:56:10 +00001827
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001828 Options *
1829 GetOptions () override
Jim Ingham33df7cd2014-12-06 01:28:03 +00001830 {
1831 return &m_options;
1832 }
1833
1834 class CommandOptions : public Options
1835 {
1836 public:
Jim Ingham33df7cd2014-12-06 01:28:03 +00001837 CommandOptions (CommandInterpreter &interpreter) :
1838 Options (interpreter),
1839 m_use_dummy (false),
1840 m_force (false)
1841 {
1842 }
1843
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001844 ~CommandOptions() override = default;
Jim Ingham33df7cd2014-12-06 01:28:03 +00001845
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001846 Error
1847 SetOptionValue (uint32_t option_idx, const char *option_arg) override
Jim Ingham33df7cd2014-12-06 01:28:03 +00001848 {
1849 Error error;
1850 const int short_option = m_getopt_table[option_idx].val;
1851
1852 switch (short_option)
1853 {
1854 case 'f':
1855 m_force = true;
1856 break;
1857
1858 case 'D':
1859 m_use_dummy = true;
1860 break;
1861
1862 default:
1863 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1864 break;
1865 }
1866
1867 return error;
1868 }
1869
1870 void
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001871 OptionParsingStarting () override
Jim Ingham33df7cd2014-12-06 01:28:03 +00001872 {
1873 m_use_dummy = false;
1874 m_force = false;
1875 }
1876
1877 const OptionDefinition*
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001878 GetDefinitions () override
Jim Ingham33df7cd2014-12-06 01:28:03 +00001879 {
1880 return g_option_table;
1881 }
1882
1883 // Options table: Required for subclasses of Options.
1884
1885 static OptionDefinition g_option_table[];
1886
1887 // Instance variables to hold the values for command options.
1888 bool m_use_dummy;
1889 bool m_force;
1890 };
1891
Jim Ingham5a988412012-06-08 21:56:10 +00001892protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00001893 bool
1894 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5a988412012-06-08 21:56:10 +00001895 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001896 Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
1897
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001898 if (target == nullptr)
Jim Ingham5a988412012-06-08 21:56:10 +00001899 {
1900 result.AppendError ("Invalid target. No existing target or breakpoints.");
1901 result.SetStatus (eReturnStatusFailed);
1902 return false;
1903 }
1904
Saleem Abdulrasoolbb19a132016-05-19 05:13:57 +00001905 std::unique_lock<std::recursive_mutex> lock;
1906 target->GetBreakpointList().GetListMutex(lock);
1907
Jim Ingham5a988412012-06-08 21:56:10 +00001908 const BreakpointList &breakpoints = target->GetBreakpointList();
1909
1910 size_t num_breakpoints = breakpoints.GetSize();
1911
1912 if (num_breakpoints == 0)
1913 {
1914 result.AppendError ("No breakpoints exist to be deleted.");
1915 result.SetStatus (eReturnStatusFailed);
1916 return false;
1917 }
1918
1919 if (command.GetArgumentCount() == 0)
1920 {
Jim Ingham33df7cd2014-12-06 01:28:03 +00001921 if (!m_options.m_force && !m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true))
Jim Ingham5a988412012-06-08 21:56:10 +00001922 {
1923 result.AppendMessage("Operation cancelled...");
1924 }
1925 else
1926 {
1927 target->RemoveAllBreakpoints ();
Greg Clayton6fea17e2014-03-03 19:15:20 +00001928 result.AppendMessageWithFormat ("All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : "");
Jim Ingham5a988412012-06-08 21:56:10 +00001929 }
1930 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1931 }
1932 else
1933 {
1934 // Particular breakpoint selected; disable that breakpoint.
1935 BreakpointIDList valid_bp_ids;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001936 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids);
Jim Ingham5a988412012-06-08 21:56:10 +00001937
1938 if (result.Succeeded())
1939 {
1940 int delete_count = 0;
1941 int disable_count = 0;
1942 const size_t count = valid_bp_ids.GetSize();
1943 for (size_t i = 0; i < count; ++i)
1944 {
1945 BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
1946
1947 if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
1948 {
1949 if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
1950 {
1951 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
1952 BreakpointLocation *location = breakpoint->FindLocationByID (cur_bp_id.GetLocationID()).get();
1953 // It makes no sense to try to delete individual locations, so we disable them instead.
1954 if (location)
1955 {
1956 location->SetEnabled (false);
1957 ++disable_count;
1958 }
1959 }
1960 else
1961 {
1962 target->RemoveBreakpointByID (cur_bp_id.GetBreakpointID());
1963 ++delete_count;
1964 }
1965 }
1966 }
1967 result.AppendMessageWithFormat ("%d breakpoints deleted; %d breakpoint locations disabled.\n",
1968 delete_count, disable_count);
1969 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1970 }
1971 }
1972 return result.Succeeded();
1973 }
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001974
Jim Ingham33df7cd2014-12-06 01:28:03 +00001975private:
1976 CommandOptions m_options;
1977};
1978
1979OptionDefinition
1980CommandObjectBreakpointDelete::CommandOptions::g_option_table[] =
1981{
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001982 { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
Jim Ingham33df7cd2014-12-06 01:28:03 +00001983 "Delete all breakpoints without querying for confirmation."},
1984
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001985 { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
Jim Ingham33df7cd2014-12-06 01:28:03 +00001986 "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
1987
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00001988 { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
Jim Ingham5a988412012-06-08 21:56:10 +00001989};
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001990
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001991//-------------------------------------------------------------------------
Jim Ingham5e09c8c2014-12-16 23:40:14 +00001992// CommandObjectBreakpointName
1993//-------------------------------------------------------------------------
1994
Kate Stone7428a182016-07-14 22:03:10 +00001995static OptionDefinition g_breakpoint_name_options[] = {
1996 {LLDB_OPT_SET_1, false, "name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName,
1997 "Specifies a breakpoint name to use."},
1998 {LLDB_OPT_SET_2, false, "breakpoint-id", 'B', OptionParser::eRequiredArgument, nullptr, nullptr, 0,
1999 eArgTypeBreakpointID, "Specify a breakpoint ID to use."},
2000 {LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
2001 "Operate on Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."},
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002002};
2003class BreakpointNameOptionGroup : public OptionGroup
2004{
2005public:
2006 BreakpointNameOptionGroup() :
2007 OptionGroup(),
2008 m_breakpoint(LLDB_INVALID_BREAK_ID),
2009 m_use_dummy (false)
2010 {
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002011 }
2012
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002013 ~BreakpointNameOptionGroup() override = default;
2014
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002015 uint32_t
2016 GetNumDefinitions () override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002017 {
2018 return sizeof (g_breakpoint_name_options) / sizeof (OptionDefinition);
2019 }
2020
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002021 const OptionDefinition*
2022 GetDefinitions () override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002023 {
2024 return g_breakpoint_name_options;
2025 }
2026
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002027 Error
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002028 SetOptionValue (CommandInterpreter &interpreter,
2029 uint32_t option_idx,
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002030 const char *option_value) override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002031 {
2032 Error error;
2033 const int short_option = g_breakpoint_name_options[option_idx].short_option;
2034
2035 switch (short_option)
2036 {
2037 case 'N':
2038 if (BreakpointID::StringIsBreakpointName(option_value, error) && error.Success())
Pavel Labathc95f7e22015-02-20 11:14:59 +00002039 m_name.SetValueFromString(option_value);
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002040 break;
2041
2042 case 'B':
Pavel Labathc95f7e22015-02-20 11:14:59 +00002043 if (m_breakpoint.SetValueFromString(option_value).Fail())
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002044 error.SetErrorStringWithFormat ("unrecognized value \"%s\" for breakpoint", option_value);
2045 break;
2046 case 'D':
Pavel Labathc95f7e22015-02-20 11:14:59 +00002047 if (m_use_dummy.SetValueFromString(option_value).Fail())
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002048 error.SetErrorStringWithFormat ("unrecognized value \"%s\" for use-dummy", option_value);
2049 break;
2050
2051 default:
2052 error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
2053 break;
2054 }
2055 return error;
2056 }
2057
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002058 void
2059 OptionParsingStarting (CommandInterpreter &interpreter) override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002060 {
2061 m_name.Clear();
2062 m_breakpoint.Clear();
2063 m_use_dummy.Clear();
2064 m_use_dummy.SetDefaultValue(false);
2065 }
2066
2067 OptionValueString m_name;
2068 OptionValueUInt64 m_breakpoint;
2069 OptionValueBoolean m_use_dummy;
2070};
2071
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002072class CommandObjectBreakpointNameAdd : public CommandObjectParsed
2073{
2074public:
2075 CommandObjectBreakpointNameAdd (CommandInterpreter &interpreter) :
2076 CommandObjectParsed (interpreter,
2077 "add",
2078 "Add a name to the breakpoints provided.",
2079 "breakpoint name add <command-options> <breakpoint-id-list>"),
2080 m_name_options(),
2081 m_option_group(interpreter)
2082 {
2083 // Create the first variant for the first (and only) argument for this command.
2084 CommandArgumentEntry arg1;
2085 CommandArgumentData id_arg;
2086 id_arg.arg_type = eArgTypeBreakpointID;
2087 id_arg.arg_repetition = eArgRepeatOptional;
2088 arg1.push_back(id_arg);
2089 m_arguments.push_back (arg1);
2090
2091 m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
2092 m_option_group.Finalize();
2093 }
2094
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002095 ~CommandObjectBreakpointNameAdd() override = default;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002096
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002097 Options *
2098 GetOptions() override
2099 {
2100 return &m_option_group;
2101 }
2102
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002103protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002104 bool
2105 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002106 {
2107 if (!m_name_options.m_name.OptionWasSet())
2108 {
2109 result.SetError("No name option provided.");
2110 return false;
2111 }
2112
2113 Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
2114
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002115 if (target == nullptr)
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002116 {
2117 result.AppendError ("Invalid target. No existing target or breakpoints.");
2118 result.SetStatus (eReturnStatusFailed);
2119 return false;
2120 }
2121
Saleem Abdulrasoolbb19a132016-05-19 05:13:57 +00002122 std::unique_lock<std::recursive_mutex> lock;
2123 target->GetBreakpointList().GetListMutex(lock);
2124
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002125 const BreakpointList &breakpoints = target->GetBreakpointList();
2126
2127 size_t num_breakpoints = breakpoints.GetSize();
2128 if (num_breakpoints == 0)
2129 {
2130 result.SetError("No breakpoints, cannot add names.");
2131 result.SetStatus (eReturnStatusFailed);
2132 return false;
2133 }
2134
2135 // Particular breakpoint selected; disable that breakpoint.
2136 BreakpointIDList valid_bp_ids;
2137 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
2138
2139 if (result.Succeeded())
2140 {
2141 if (valid_bp_ids.GetSize() == 0)
2142 {
2143 result.SetError("No breakpoints specified, cannot add names.");
2144 result.SetStatus (eReturnStatusFailed);
2145 return false;
2146 }
2147 size_t num_valid_ids = valid_bp_ids.GetSize();
2148 for (size_t index = 0; index < num_valid_ids; index++)
2149 {
2150 lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
2151 BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
2152 Error error; // We don't need to check the error here, since the option parser checked it...
2153 bp_sp->AddName(m_name_options.m_name.GetCurrentValue(), error);
2154 }
2155 }
2156
2157 return true;
2158 }
2159
2160private:
2161 BreakpointNameOptionGroup m_name_options;
2162 OptionGroupOptions m_option_group;
2163};
2164
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002165class CommandObjectBreakpointNameDelete : public CommandObjectParsed
2166{
2167public:
2168 CommandObjectBreakpointNameDelete (CommandInterpreter &interpreter) :
2169 CommandObjectParsed (interpreter,
2170 "delete",
2171 "Delete a name from the breakpoints provided.",
2172 "breakpoint name delete <command-options> <breakpoint-id-list>"),
2173 m_name_options(),
2174 m_option_group(interpreter)
2175 {
2176 // Create the first variant for the first (and only) argument for this command.
2177 CommandArgumentEntry arg1;
2178 CommandArgumentData id_arg;
2179 id_arg.arg_type = eArgTypeBreakpointID;
2180 id_arg.arg_repetition = eArgRepeatOptional;
2181 arg1.push_back(id_arg);
2182 m_arguments.push_back (arg1);
2183
2184 m_option_group.Append (&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
2185 m_option_group.Finalize();
2186 }
2187
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002188 ~CommandObjectBreakpointNameDelete() override = default;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002189
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002190 Options *
2191 GetOptions() override
2192 {
2193 return &m_option_group;
2194 }
2195
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002196protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002197 bool
2198 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002199 {
2200 if (!m_name_options.m_name.OptionWasSet())
2201 {
2202 result.SetError("No name option provided.");
2203 return false;
2204 }
2205
2206 Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
2207
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002208 if (target == nullptr)
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002209 {
2210 result.AppendError ("Invalid target. No existing target or breakpoints.");
2211 result.SetStatus (eReturnStatusFailed);
2212 return false;
2213 }
2214
Saleem Abdulrasoolbb19a132016-05-19 05:13:57 +00002215 std::unique_lock<std::recursive_mutex> lock;
2216 target->GetBreakpointList().GetListMutex(lock);
2217
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002218 const BreakpointList &breakpoints = target->GetBreakpointList();
2219
2220 size_t num_breakpoints = breakpoints.GetSize();
2221 if (num_breakpoints == 0)
2222 {
2223 result.SetError("No breakpoints, cannot delete names.");
2224 result.SetStatus (eReturnStatusFailed);
2225 return false;
2226 }
2227
2228 // Particular breakpoint selected; disable that breakpoint.
2229 BreakpointIDList valid_bp_ids;
2230 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
2231
2232 if (result.Succeeded())
2233 {
2234 if (valid_bp_ids.GetSize() == 0)
2235 {
2236 result.SetError("No breakpoints specified, cannot delete names.");
2237 result.SetStatus (eReturnStatusFailed);
2238 return false;
2239 }
2240 size_t num_valid_ids = valid_bp_ids.GetSize();
2241 for (size_t index = 0; index < num_valid_ids; index++)
2242 {
2243 lldb::break_id_t bp_id = valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID();
2244 BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id);
2245 bp_sp->RemoveName(m_name_options.m_name.GetCurrentValue());
2246 }
2247 }
2248
2249 return true;
2250 }
2251
2252private:
2253 BreakpointNameOptionGroup m_name_options;
2254 OptionGroupOptions m_option_group;
2255};
2256
2257class CommandObjectBreakpointNameList : public CommandObjectParsed
2258{
2259public:
2260 CommandObjectBreakpointNameList (CommandInterpreter &interpreter) :
2261 CommandObjectParsed (interpreter,
2262 "list",
2263 "List either the names for a breakpoint or the breakpoints for a given name.",
2264 "breakpoint name list <command-options>"),
2265 m_name_options(),
2266 m_option_group(interpreter)
2267 {
2268 m_option_group.Append (&m_name_options);
2269 m_option_group.Finalize();
2270 }
2271
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002272 ~CommandObjectBreakpointNameList() override = default;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002273
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002274 Options *
2275 GetOptions() override
2276 {
2277 return &m_option_group;
2278 }
2279
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002280protected:
Bruce Mitchener13d21e92015-10-07 16:56:17 +00002281 bool
2282 DoExecute (Args& command, CommandReturnObject &result) override
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002283 {
2284 Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue());
2285
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002286 if (target == nullptr)
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002287 {
2288 result.AppendError ("Invalid target. No existing target or breakpoints.");
2289 result.SetStatus (eReturnStatusFailed);
2290 return false;
2291 }
2292
2293 if (m_name_options.m_name.OptionWasSet())
2294 {
2295 const char *name = m_name_options.m_name.GetCurrentValue();
Saleem Abdulrasoolbb19a132016-05-19 05:13:57 +00002296 std::unique_lock<std::recursive_mutex> lock;
2297 target->GetBreakpointList().GetListMutex(lock);
2298
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002299 BreakpointList &breakpoints = target->GetBreakpointList();
2300 for (BreakpointSP bp_sp : breakpoints.Breakpoints())
2301 {
2302 if (bp_sp->MatchesName(name))
2303 {
2304 StreamString s;
2305 bp_sp->GetDescription(&s, eDescriptionLevelBrief);
2306 s.EOL();
2307 result.AppendMessage(s.GetData());
2308 }
2309 }
2310
2311 }
2312 else if (m_name_options.m_breakpoint.OptionWasSet())
2313 {
2314 BreakpointSP bp_sp = target->GetBreakpointList().FindBreakpointByID(m_name_options.m_breakpoint.GetCurrentValue());
2315 if (bp_sp)
2316 {
2317 std::vector<std::string> names;
2318 bp_sp->GetNames (names);
2319 result.AppendMessage ("Names:");
2320 for (auto name : names)
2321 result.AppendMessageWithFormat (" %s\n", name.c_str());
2322 }
2323 else
2324 {
2325 result.AppendErrorWithFormat ("Could not find breakpoint %" PRId64 ".\n",
2326 m_name_options.m_breakpoint.GetCurrentValue());
2327 result.SetStatus (eReturnStatusFailed);
2328 return false;
2329 }
2330 }
2331 else
2332 {
2333 result.SetError ("Must specify -N or -B option to list.");
2334 result.SetStatus (eReturnStatusFailed);
2335 return false;
2336 }
2337 return true;
2338 }
2339
2340private:
2341 BreakpointNameOptionGroup m_name_options;
2342 OptionGroupOptions m_option_group;
2343};
2344
2345//-------------------------------------------------------------------------
2346// CommandObjectMultiwordBreakpoint
2347//-------------------------------------------------------------------------
2348class CommandObjectBreakpointName : public CommandObjectMultiword
2349{
2350public:
Kate Stone7428a182016-07-14 22:03:10 +00002351 CommandObjectBreakpointName(CommandInterpreter &interpreter)
2352 : CommandObjectMultiword(interpreter, "name", "Commands to manage name tags for breakpoints",
2353 "breakpoint name <subcommand> [<command-options>]")
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002354 {
2355 CommandObjectSP add_command_object (new CommandObjectBreakpointNameAdd (interpreter));
2356 CommandObjectSP delete_command_object (new CommandObjectBreakpointNameDelete (interpreter));
2357 CommandObjectSP list_command_object (new CommandObjectBreakpointNameList (interpreter));
2358
2359 LoadSubCommand ("add", add_command_object);
2360 LoadSubCommand ("delete", delete_command_object);
2361 LoadSubCommand ("list", list_command_object);
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002362 }
2363
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002364 ~CommandObjectBreakpointName() override = default;
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002365};
2366
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002367//-------------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002368// CommandObjectMultiwordBreakpoint
2369//-------------------------------------------------------------------------
Jim Inghamae1c4cf2010-06-18 00:58:52 +00002370#pragma mark MultiwordBreakpoint
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002371
Kate Stone7428a182016-07-14 22:03:10 +00002372CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint(CommandInterpreter &interpreter)
2373 : CommandObjectMultiword(interpreter, "breakpoint",
2374 "Commands for operating on breakpoints (see 'help b' for shorthand.)",
2375 "breakpoint <subcommand> [<command-options>]")
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002376{
Greg Claytona7015092010-09-18 01:14:36 +00002377 CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter));
Greg Claytona7015092010-09-18 01:14:36 +00002378 CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter));
2379 CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter));
Johnny Chenb7234e42010-10-28 17:27:46 +00002380 CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter));
2381 CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter));
Greg Claytona7015092010-09-18 01:14:36 +00002382 CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002383 CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter));
Greg Claytona7015092010-09-18 01:14:36 +00002384 CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter));
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002385 CommandObjectSP name_command_object (new CommandObjectBreakpointName(interpreter));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002386
Johnny Chenb7234e42010-10-28 17:27:46 +00002387 list_command_object->SetCommandName ("breakpoint list");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002388 enable_command_object->SetCommandName("breakpoint enable");
2389 disable_command_object->SetCommandName("breakpoint disable");
Johnny Chenb7234e42010-10-28 17:27:46 +00002390 clear_command_object->SetCommandName("breakpoint clear");
2391 delete_command_object->SetCommandName("breakpoint delete");
Jim Inghamae1c4cf2010-06-18 00:58:52 +00002392 set_command_object->SetCommandName("breakpoint set");
Johnny Chenb7234e42010-10-28 17:27:46 +00002393 command_command_object->SetCommandName ("breakpoint command");
2394 modify_command_object->SetCommandName ("breakpoint modify");
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002395 name_command_object->SetCommandName ("breakpoint name");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002396
Greg Clayton23f59502012-07-17 03:23:13 +00002397 LoadSubCommand ("list", list_command_object);
2398 LoadSubCommand ("enable", enable_command_object);
2399 LoadSubCommand ("disable", disable_command_object);
2400 LoadSubCommand ("clear", clear_command_object);
2401 LoadSubCommand ("delete", delete_command_object);
2402 LoadSubCommand ("set", set_command_object);
2403 LoadSubCommand ("command", command_command_object);
2404 LoadSubCommand ("modify", modify_command_object);
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002405 LoadSubCommand ("name", name_command_object);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002406}
2407
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002408CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002409
2410void
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002411CommandObjectMultiwordBreakpoint::VerifyIDs (Args &args,
2412 Target *target,
2413 bool allow_locations,
2414 CommandReturnObject &result,
2415 BreakpointIDList *valid_ids)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002416{
2417 // args can be strings representing 1). integers (for breakpoint ids)
2418 // 2). the full breakpoint & location canonical representation
2419 // 3). the word "to" or a hyphen, representing a range (in which case there
2420 // had *better* be an entry both before & after of one of the first two types.
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002421 // 4). A breakpoint name
Jim Ingham36f3b362010-10-14 23:45:03 +00002422 // If args is empty, we will use the last created breakpoint (if there is one.)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002423
2424 Args temp_args;
2425
Jim Ingham36f3b362010-10-14 23:45:03 +00002426 if (args.GetArgumentCount() == 0)
2427 {
Greg Clayton4d122c42011-09-17 08:33:22 +00002428 if (target->GetLastCreatedBreakpoint())
Jim Ingham36f3b362010-10-14 23:45:03 +00002429 {
2430 valid_ids->AddBreakpointID (BreakpointID(target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID));
2431 result.SetStatus (eReturnStatusSuccessFinishNoResult);
2432 }
2433 else
2434 {
2435 result.AppendError("No breakpoint specified and no last created breakpoint.");
2436 result.SetStatus (eReturnStatusFailed);
2437 }
2438 return;
2439 }
2440
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002441 // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff directly from the old ARGS to
2442 // the new TEMP_ARGS. Do not copy breakpoint id range strings over; instead generate a list of strings for
2443 // all the breakpoint ids in the range, and shove all of those breakpoint id strings into TEMP_ARGS.
2444
Jim Ingham5e09c8c2014-12-16 23:40:14 +00002445 BreakpointIDList::FindAndReplaceIDRanges (args, target, allow_locations, result, temp_args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002446
2447 // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList:
2448
Greg Claytonc982c762010-07-09 20:39:50 +00002449 valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002450
2451 // At this point, all of the breakpoint ids that the user passed in have been converted to breakpoint IDs
2452 // and put into valid_ids.
2453
2454 if (result.Succeeded())
2455 {
2456 // Now that we've converted everything from args into a list of breakpoint ids, go through our tentative list
2457 // of breakpoint id's and verify that they correspond to valid/currently set breakpoints.
2458
Greg Claytonc982c762010-07-09 20:39:50 +00002459 const size_t count = valid_ids->GetSize();
2460 for (size_t i = 0; i < count; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002461 {
2462 BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i);
2463 Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
Eugene Zelenko9e85e5a2016-02-18 22:39:14 +00002464 if (breakpoint != nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002465 {
Greg Claytonc7bece562013-01-25 18:06:21 +00002466 const size_t num_locations = breakpoint->GetNumLocations();
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +00002467 if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002468 {
2469 StreamString id_str;
Greg Claytonc982c762010-07-09 20:39:50 +00002470 BreakpointID::GetCanonicalReference (&id_str,
2471 cur_bp_id.GetBreakpointID(),
2472 cur_bp_id.GetLocationID());
2473 i = valid_ids->GetSize() + 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002474 result.AppendErrorWithFormat ("'%s' is not a currently valid breakpoint/location id.\n",
2475 id_str.GetData());
2476 result.SetStatus (eReturnStatusFailed);
2477 }
2478 }
2479 else
2480 {
Greg Claytonc982c762010-07-09 20:39:50 +00002481 i = valid_ids->GetSize() + 1;
Kate Stone7428a182016-07-14 22:03:10 +00002482 result.AppendErrorWithFormat("'%d' is not a currently valid breakpoint ID.\n",
2483 cur_bp_id.GetBreakpointID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002484 result.SetStatus (eReturnStatusFailed);
2485 }
2486 }
2487 }
2488}