Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 16 | #include "CommandObjectBreakpoint.h" |
| 17 | #include "CommandObjectBreakpointCommand.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Breakpoint/Breakpoint.h" |
| 19 | #include "lldb/Breakpoint/BreakpointIDList.h" |
| 20 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 21 | #include "lldb/Host/StringConvert.h" |
Jim Ingham | 40af72e | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 22 | #include "lldb/Interpreter/Options.h" |
Zachary Turner | 32abc6e | 2015-03-03 19:23:09 +0000 | [diff] [blame] | 23 | #include "lldb/Interpreter/OptionValueBoolean.h" |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 24 | #include "lldb/Interpreter/OptionValueString.h" |
| 25 | #include "lldb/Interpreter/OptionValueUInt64.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | #include "lldb/Core/RegularExpression.h" |
| 27 | #include "lldb/Core/StreamString.h" |
| 28 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 29 | #include "lldb/Interpreter/CommandReturnObject.h" |
Jim Ingham | 0e0984e | 2015-09-02 01:06:46 +0000 | [diff] [blame] | 30 | #include "lldb/Target/Language.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | #include "lldb/Target/Target.h" |
| 32 | #include "lldb/Interpreter/CommandCompletions.h" |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 33 | #include "lldb/Target/StackFrame.h" |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 34 | #include "lldb/Target/Thread.h" |
| 35 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | |
| 37 | using namespace lldb; |
| 38 | using namespace lldb_private; |
| 39 | |
| 40 | static void |
Jim Ingham | 85e8b81 | 2011-02-19 02:53:09 +0000 | [diff] [blame] | 41 | AddBreakpointDescription (Stream *s, Breakpoint *bp, lldb::DescriptionLevel level) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | { |
| 43 | s->IndentMore(); |
| 44 | bp->GetDescription (s, level, true); |
| 45 | s->IndentLess(); |
| 46 | s->EOL(); |
| 47 | } |
| 48 | |
| 49 | //------------------------------------------------------------------------- |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 50 | // CommandObjectBreakpointSet |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | //------------------------------------------------------------------------- |
| 52 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 53 | class CommandObjectBreakpointSet : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 55 | public: |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 56 | typedef enum BreakpointSetType |
| 57 | { |
| 58 | eSetTypeInvalid, |
| 59 | eSetTypeFileAndLine, |
| 60 | eSetTypeAddress, |
| 61 | eSetTypeFunctionName, |
| 62 | eSetTypeFunctionRegexp, |
| 63 | eSetTypeSourceRegexp, |
| 64 | eSetTypeException |
| 65 | } BreakpointSetType; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 67 | 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 76 | ~CommandObjectBreakpointSet() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 77 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 78 | Options * |
| 79 | GetOptions () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 80 | { |
| 81 | return &m_options; |
| 82 | } |
| 83 | |
| 84 | class CommandOptions : public Options |
| 85 | { |
| 86 | public: |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 87 | CommandOptions (CommandInterpreter &interpreter) : |
| 88 | Options (interpreter), |
| 89 | m_condition (), |
| 90 | m_filenames (), |
| 91 | m_line_num (0), |
| 92 | m_column (0), |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 93 | 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 Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 105 | m_throw_bp (true), |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 106 | m_hardware (false), |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 107 | m_exception_language (eLanguageTypeUnknown), |
Dawn Perchik | 23b1dec | 2015-07-21 22:05:07 +0000 | [diff] [blame] | 108 | m_language (lldb::eLanguageTypeUnknown), |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 109 | m_skip_prologue (eLazyBoolCalculate), |
Jim Ingham | e732052 | 2015-02-12 17:37:46 +0000 | [diff] [blame] | 110 | m_one_shot (false), |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 111 | m_all_files (false), |
| 112 | m_move_to_nearest_code (eLazyBoolCalculate) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 113 | { |
| 114 | } |
| 115 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 116 | ~CommandOptions() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 117 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 118 | Error |
| 119 | SetOptionValue (uint32_t option_idx, const char *option_arg) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 120 | { |
| 121 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 122 | const int short_option = m_getopt_table[option_idx].val; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 123 | |
| 124 | switch (short_option) |
| 125 | { |
| 126 | case 'a': |
Greg Clayton | b9d5df5 | 2012-12-06 22:49:16 +0000 | [diff] [blame] | 127 | { |
| 128 | ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); |
| 129 | m_load_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error); |
| 130 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 131 | break; |
| 132 | |
Jim Ingham | e732052 | 2015-02-12 17:37:46 +0000 | [diff] [blame] | 133 | case 'A': |
| 134 | m_all_files = true; |
| 135 | break; |
| 136 | |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 137 | case 'b': |
| 138 | m_func_names.push_back (option_arg); |
| 139 | m_func_name_type_mask |= eFunctionNameTypeBase; |
| 140 | break; |
| 141 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 142 | case 'C': |
Jim Ingham | 6312991 | 2015-03-16 22:47:38 +0000 | [diff] [blame] | 143 | { |
| 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 Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 148 | break; |
Jim Ingham | 6312991 | 2015-03-16 22:47:38 +0000 | [diff] [blame] | 149 | } |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 150 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 151 | case 'c': |
| 152 | m_condition.assign(option_arg); |
| 153 | break; |
| 154 | |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 155 | case 'D': |
| 156 | m_use_dummy = true; |
| 157 | break; |
| 158 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 159 | case 'E': |
| 160 | { |
Jim Ingham | 0e0984e | 2015-09-02 01:06:46 +0000 | [diff] [blame] | 161 | LanguageType language = Language::GetLanguageTypeFromString (option_arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 162 | |
| 163 | switch (language) |
| 164 | { |
| 165 | case eLanguageTypeC89: |
| 166 | case eLanguageTypeC: |
| 167 | case eLanguageTypeC99: |
Bruce Mitchener | 1d0089f | 2014-07-03 00:49:08 +0000 | [diff] [blame] | 168 | case eLanguageTypeC11: |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 169 | m_exception_language = eLanguageTypeC; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 170 | break; |
| 171 | case eLanguageTypeC_plus_plus: |
Bruce Mitchener | 1d0089f | 2014-07-03 00:49:08 +0000 | [diff] [blame] | 172 | case eLanguageTypeC_plus_plus_03: |
| 173 | case eLanguageTypeC_plus_plus_11: |
Bruce Mitchener | 2ba84a6 | 2015-02-06 06:46:52 +0000 | [diff] [blame] | 174 | case eLanguageTypeC_plus_plus_14: |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 175 | m_exception_language = eLanguageTypeC_plus_plus; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 176 | break; |
| 177 | case eLanguageTypeObjC: |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 178 | m_exception_language = eLanguageTypeObjC; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 179 | 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 Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 191 | |
| 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 Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 201 | case 'h': |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 202 | { |
| 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 Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 214 | case 'i': |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 215 | m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 216 | if (m_ignore_count == UINT32_MAX) |
| 217 | error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); |
| 218 | break; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 219 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 220 | 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 Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 234 | |
| 235 | case 'l': |
Jim Ingham | 6312991 | 2015-03-16 22:47:38 +0000 | [diff] [blame] | 236 | { |
| 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 Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 241 | break; |
Jim Ingham | 6312991 | 2015-03-16 22:47:38 +0000 | [diff] [blame] | 242 | } |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 243 | |
Dawn Perchik | 23b1dec | 2015-07-21 22:05:07 +0000 | [diff] [blame] | 244 | case 'L': |
Jim Ingham | 0e0984e | 2015-09-02 01:06:46 +0000 | [diff] [blame] | 245 | m_language = Language::GetLanguageTypeFromString (option_arg); |
Dawn Perchik | 23b1dec | 2015-07-21 22:05:07 +0000 | [diff] [blame] | 246 | if (m_language == eLanguageTypeUnknown) |
| 247 | error.SetErrorStringWithFormat ("Unknown language type: '%s' for breakpoint", option_arg); |
| 248 | break; |
| 249 | |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 250 | 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 Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 265 | 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 Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 275 | case 'N': |
| 276 | if (BreakpointID::StringIsBreakpointName(option_arg, error)) |
| 277 | m_breakpoint_names.push_back (option_arg); |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 278 | break; |
| 279 | |
Jim Ingham | 2411167 | 2016-03-09 18:59:13 +0000 | [diff] [blame] | 280 | 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 Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 290 | case 'o': |
| 291 | m_one_shot = true; |
| 292 | break; |
| 293 | |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 294 | case 'O': |
| 295 | m_exception_extra_args.AppendArgument ("-O"); |
| 296 | m_exception_extra_args.AppendArgument (option_arg); |
| 297 | break; |
| 298 | |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 299 | 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 Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 312 | m_modules.AppendIfUnique (FileSpec (option_arg, false)); |
| 313 | break; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 314 | |
| 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 Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 321 | m_thread_id = StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 322 | if (m_thread_id == LLDB_INVALID_THREAD_ID) |
| 323 | error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 324 | break; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 325 | |
| 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 Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 340 | m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 341 | if (m_thread_id == UINT32_MAX) |
| 342 | error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 343 | break; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 344 | |
Jim Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 345 | case 'X': |
| 346 | m_source_regex_func_names.insert(option_arg); |
| 347 | break; |
| 348 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 349 | default: |
| 350 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 351 | break; |
| 352 | } |
| 353 | |
| 354 | return error; |
| 355 | } |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 356 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 357 | void |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 358 | OptionParsingStarting () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 359 | { |
| 360 | m_condition.clear(); |
| 361 | m_filenames.Clear(); |
| 362 | m_line_num = 0; |
| 363 | m_column = 0; |
| 364 | m_func_names.clear(); |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 365 | m_func_name_type_mask = eFunctionNameTypeNone; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 366 | m_func_regexp.clear(); |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 367 | m_source_text_regexp.clear(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 368 | m_modules.Clear(); |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 369 | m_load_addr = LLDB_INVALID_ADDRESS; |
Jim Ingham | 2411167 | 2016-03-09 18:59:13 +0000 | [diff] [blame] | 370 | m_offset_addr = 0; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 371 | 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 Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 376 | m_catch_bp = false; |
| 377 | m_throw_bp = true; |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 378 | m_hardware = false; |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 379 | m_exception_language = eLanguageTypeUnknown; |
Dawn Perchik | 23b1dec | 2015-07-21 22:05:07 +0000 | [diff] [blame] | 380 | m_language = lldb::eLanguageTypeUnknown; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 381 | m_skip_prologue = eLazyBoolCalculate; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 382 | m_one_shot = false; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 383 | m_use_dummy = false; |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 384 | m_breakpoint_names.clear(); |
Jim Ingham | e732052 | 2015-02-12 17:37:46 +0000 | [diff] [blame] | 385 | m_all_files = false; |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 386 | m_exception_extra_args.Clear(); |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 387 | m_move_to_nearest_code = eLazyBoolCalculate; |
Jim Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 388 | m_source_regex_func_names.clear(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | const OptionDefinition* |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 392 | GetDefinitions () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 393 | { |
| 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 Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 407 | std::vector<std::string> m_func_names; |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 408 | std::vector<std::string> m_breakpoint_names; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 409 | 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 Ingham | 2411167 | 2016-03-09 18:59:13 +0000 | [diff] [blame] | 414 | lldb::addr_t m_offset_addr; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 415 | 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 Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 422 | bool m_hardware; // Request to use hardware breakpoints |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 423 | lldb::LanguageType m_exception_language; |
Dawn Perchik | 23b1dec | 2015-07-21 22:05:07 +0000 | [diff] [blame] | 424 | lldb::LanguageType m_language; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 425 | LazyBool m_skip_prologue; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 426 | bool m_one_shot; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 427 | bool m_use_dummy; |
Jim Ingham | e732052 | 2015-02-12 17:37:46 +0000 | [diff] [blame] | 428 | bool m_all_files; |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 429 | Args m_exception_extra_args; |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 430 | LazyBool m_move_to_nearest_code; |
Jim Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 431 | std::unordered_set<std::string> m_source_regex_func_names; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 432 | }; |
| 433 | |
| 434 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 435 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 436 | DoExecute (Args& command, |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 437 | CommandReturnObject &result) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 438 | { |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 439 | Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); |
| 440 | |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 441 | if (target == nullptr) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 442 | { |
| 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 Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 468 | else if (m_options.m_exception_language != eLanguageTypeUnknown) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 469 | break_type = eSetTypeException; |
| 470 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 471 | Breakpoint *bp = nullptr; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 472 | FileSpec module_spec; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 473 | const bool internal = false; |
Jim Ingham | 2411167 | 2016-03-09 18:59:13 +0000 | [diff] [blame] | 474 | |
| 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 Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 478 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 479 | switch (break_type) |
| 480 | { |
| 481 | case eSetTypeFileAndLine: // Breakpoint by source position |
| 482 | { |
| 483 | FileSpec file; |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 484 | const size_t num_files = m_options.m_filenames.GetSize(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 485 | 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 Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 502 | |
| 503 | // Only check for inline functions if |
| 504 | LazyBool check_inlines = eLazyBoolCalculate; |
| 505 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 506 | bp = target->CreateBreakpoint (&(m_options.m_modules), |
| 507 | file, |
| 508 | m_options.m_line_num, |
Jim Ingham | 2411167 | 2016-03-09 18:59:13 +0000 | [diff] [blame] | 509 | m_options.m_offset_addr, |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 510 | check_inlines, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 511 | m_options.m_skip_prologue, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 512 | internal, |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 513 | m_options.m_hardware, |
| 514 | m_options.m_move_to_nearest_code).get(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 515 | } |
| 516 | break; |
| 517 | |
| 518 | case eSetTypeAddress: // Breakpoint by address |
Jim Ingham | 055a08a | 2015-11-17 03:39:13 +0000 | [diff] [blame] | 519 | { |
| 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 Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 543 | break; |
Jim Ingham | 055a08a | 2015-11-17 03:39:13 +0000 | [diff] [blame] | 544 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 545 | 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 Perchik | 23b1dec | 2015-07-21 22:05:07 +0000 | [diff] [blame] | 556 | m_options.m_language, |
Jim Ingham | 2411167 | 2016-03-09 18:59:13 +0000 | [diff] [blame] | 557 | m_options.m_offset_addr, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 558 | m_options.m_skip_prologue, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 559 | internal, |
| 560 | m_options.m_hardware).get(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 561 | } |
| 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 Ingham | 0fcdac3 | 2015-11-06 22:48:59 +0000 | [diff] [blame] | 580 | m_options.m_language, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 581 | m_options.m_skip_prologue, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 582 | internal, |
| 583 | m_options.m_hardware).get(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 584 | } |
| 585 | break; |
| 586 | case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. |
| 587 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 588 | const size_t num_files = m_options.m_filenames.GetSize(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 589 | |
Jim Ingham | e732052 | 2015-02-12 17:37:46 +0000 | [diff] [blame] | 590 | if (num_files == 0 && !m_options.m_all_files) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 591 | { |
| 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 Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 615 | bp = target->CreateSourceRegexBreakpoint (&(m_options.m_modules), |
| 616 | &(m_options.m_filenames), |
Jim Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 617 | m_options.m_source_regex_func_names, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 618 | regexp, |
| 619 | internal, |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 620 | m_options.m_hardware, |
| 621 | m_options.m_move_to_nearest_code).get(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 622 | } |
| 623 | break; |
| 624 | case eSetTypeException: |
| 625 | { |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 626 | Error precond_error; |
| 627 | bp = target->CreateExceptionBreakpoint (m_options.m_exception_language, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 628 | m_options.m_catch_bp, |
| 629 | m_options.m_throw_bp, |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 630 | 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 Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 641 | } |
| 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 Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 667 | |
| 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 Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 674 | |
| 675 | bp->SetOneShot (m_options.m_one_shot); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | if (bp) |
| 679 | { |
| 680 | Stream &output_stream = result.GetOutputStream(); |
Jim Ingham | 1391cc7 | 2012-09-22 00:04:04 +0000 | [diff] [blame] | 681 | const bool show_locations = false; |
| 682 | bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, show_locations); |
Jim Ingham | 4aeb198 | 2014-12-19 19:45:31 +0000 | [diff] [blame] | 683 | 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 Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 694 | 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 | |
| 705 | private: |
| 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 Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 714 | StackFrame *cur_frame = m_exe_ctx.GetFramePtr(); |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 715 | if (cur_frame == nullptr) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 716 | { |
| 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 747 | |
Johnny Chen | 6943e7c | 2012-05-08 00:43:20 +0000 | [diff] [blame] | 748 | // 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 Chen | 4ab2e6b | 2012-05-07 23:23:41 +0000 | [diff] [blame] | 750 | #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 Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 752 | #define LLDB_OPT_SKIP_PROLOGUE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) ) |
Jim Ingham | 2411167 | 2016-03-09 18:59:13 +0000 | [diff] [blame] | 753 | #define LLDB_OPT_OFFSET_APPLIES (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3,8) ) |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 754 | #define LLDB_OPT_MOVE_TO_NEAREST_CODE ( LLDB_OPT_SET_1 | LLDB_OPT_SET_9 ) |
Jim Ingham | 0fcdac3 | 2015-11-06 22:48:59 +0000 | [diff] [blame] | 755 | #define LLDB_OPT_EXPR_LANGUAGE ( LLDB_OPT_SET_FROM_TO(3, 8) ) |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 756 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 757 | OptionDefinition |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 758 | CommandObjectBreakpointSet::CommandOptions::g_option_table[] = |
| 759 | { |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 760 | { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, |
Jim Ingham | 64cc29c | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 761 | "Set the breakpoint only in this shared library. " |
| 762 | "Can repeat this option multiple times to specify multiple shared libraries."}, |
Jim Ingham | 8651121 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 763 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 764 | { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, |
Caroline Tice | deaab22 | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 765 | "Set the number of times this breakpoint is skipped before stopping." }, |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 766 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 767 | { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, |
Jim Ingham | b2b256a | 2013-04-09 18:05:22 +0000 | [diff] [blame] | 768 | "The breakpoint is deleted the first time it causes a stop." }, |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 769 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 770 | { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, |
Johnny Chen | 7d49c9c | 2012-05-25 21:10:46 +0000 | [diff] [blame] | 771 | "The breakpoint stops only if this condition expression evaluates to true."}, |
| 772 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 773 | { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, |
Jim Ingham | a89be91 | 2013-03-26 18:29:03 +0000 | [diff] [blame] | 774 | "The breakpoint stops only for the thread whose indeX matches this argument."}, |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 775 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 776 | { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID, |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 777 | "The breakpoint stops only for the thread whose TID matches this argument."}, |
| 778 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 779 | { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName, |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 780 | "The breakpoint stops only for the thread whose thread name matches this argument."}, |
| 781 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 782 | { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 783 | "Require the breakpoint to use hardware breakpoints."}, |
| 784 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 785 | { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName, |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 786 | "The breakpoint stops only for threads in the queue whose name is given by this argument."}, |
| 787 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 788 | { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, |
Jim Ingham | 289aca6 | 2013-02-14 19:10:36 +0000 | [diff] [blame] | 789 | "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 Ingham | 6394479 | 2013-02-14 19:30:35 +0000 | [diff] [blame] | 791 | "To set breakpoints on .c/.cpp/.m/.mm files that are #included, set target.inline-breakpoint-strategy" |
Jim Ingham | 289aca6 | 2013-02-14 19:10:36 +0000 | [diff] [blame] | 792 | " to \"always\"."}, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 793 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 794 | { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 795 | "Specifies the line number on which to set this breakpoint."}, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 796 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 797 | // 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 799 | // { 0, false, "column", 'C', OptionParser::eRequiredArgument, nullptr, "<column>", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 800 | // "Set the breakpoint by source location at this particular column."}, |
| 801 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 802 | { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, |
Jim Ingham | 055a08a | 2015-11-17 03:39:13 +0000 | [diff] [blame] | 803 | "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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 811 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 812 | { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, |
Jim Ingham | 551262d | 2013-03-27 17:36:54 +0000 | [diff] [blame] | 813 | "Set the breakpoint by function name. Can be repeated multiple times to make one breakpoint for multiple names" }, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 814 | |
Jim Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 815 | { 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 818 | { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFullName, |
Jim Ingham | 64cc29c | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 819 | "Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and " |
Jason Molenda | c8badb7 | 2015-09-28 23:02:00 +0000 | [diff] [blame] | 820 | "for Objective C this means a full function prototype with class and selector. " |
Jim Ingham | 64cc29c | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 821 | "Can be repeated multiple times to make one breakpoint for multiple names." }, |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 822 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 823 | { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSelector, |
Jim Ingham | 64cc29c | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 824 | "Set the breakpoint by ObjC selector name. Can be repeated multiple times to make one breakpoint for multiple Selectors." }, |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 825 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 826 | { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeMethod, |
Jim Ingham | 64cc29c | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 827 | "Set the breakpoint by C++ method names. Can be repeated multiple times to make one breakpoint for multiple methods." }, |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 828 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 829 | { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 830 | "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." }, |
| 831 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 832 | { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, |
Jim Ingham | 64cc29c | 2012-05-03 20:30:08 +0000 | [diff] [blame] | 833 | "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 Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 835 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 836 | { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, |
Jim Ingham | e96ade8 | 2013-06-07 01:13:00 +0000 | [diff] [blame] | 837 | "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 Ingham | cc3a459 | 2016-02-09 18:53:49 +0000 | [diff] [blame] | 839 | "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 Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 841 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 842 | { LLDB_OPT_SET_9, false, "all-files", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, |
Jim Ingham | e732052 | 2015-02-12 17:37:46 +0000 | [diff] [blame] | 843 | "All files are searched for source pattern matches." }, |
| 844 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 845 | { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 846 | "Set the breakpoint on exceptions thrown by the specified language (without options, on throw but not catch.)" }, |
| 847 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 848 | { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, |
Jim Ingham | b4a5aa2 | 2016-02-10 22:30:20 +0000 | [diff] [blame] | 849 | "Set the breakpoint on exception throW." }, |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 850 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 851 | { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, |
Jim Ingham | b4a5aa2 | 2016-02-10 22:30:20 +0000 | [diff] [blame] | 852 | "Set the breakpoint on exception catcH." }, |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 853 | |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 854 | // Don't add this option till it actually does something useful... |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 855 | // { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName, |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 856 | // "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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 858 | { LLDB_OPT_EXPR_LANGUAGE, false, "language", 'L', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, |
Dawn Perchik | 4112ab9 | 2015-07-22 02:01:32 +0000 | [diff] [blame] | 859 | "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 Perchik | 23b1dec | 2015-07-21 22:05:07 +0000 | [diff] [blame] | 860 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 861 | { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 862 | "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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 864 | { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 865 | "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, |
| 866 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 867 | { LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, |
Jim Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 868 | "Adds this to the list of names for this breakpoint."}, |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 869 | |
Jim Ingham | 2411167 | 2016-03-09 18:59:13 +0000 | [diff] [blame] | 870 | { 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 874 | { LLDB_OPT_MOVE_TO_NEAREST_CODE, false, "move-to-nearest-code", 'm', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 875 | "Move breakpoints to nearest code. If not set the target.move-to-nearest-code setting is used." }, |
| 876 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 877 | { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 878 | }; |
| 879 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 880 | //------------------------------------------------------------------------- |
| 881 | // CommandObjectBreakpointModify |
| 882 | //------------------------------------------------------------------------- |
| 883 | #pragma mark Modify |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 884 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 885 | class CommandObjectBreakpointModify : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 886 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 887 | public: |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 888 | CommandObjectBreakpointModify (CommandInterpreter &interpreter) : |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 889 | 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 Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 895 | m_options (interpreter) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 896 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 897 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 902 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 903 | ~CommandObjectBreakpointModify() override = default; |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 904 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 905 | Options * |
| 906 | GetOptions () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 907 | { |
| 908 | return &m_options; |
| 909 | } |
Johnny Chen | 7d49c9c | 2012-05-25 21:10:46 +0000 | [diff] [blame] | 910 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 911 | class CommandOptions : public Options |
| 912 | { |
| 913 | public: |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 914 | 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 Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 924 | m_one_shot (false), |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 925 | m_enable_passed (false), |
| 926 | m_enable_value (false), |
| 927 | m_name_passed (false), |
| 928 | m_queue_passed (false), |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 929 | m_condition_passed (false), |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 930 | m_one_shot_passed (false), |
| 931 | m_use_dummy (false) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 932 | { |
| 933 | } |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 934 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 935 | ~CommandOptions() override = default; |
Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 936 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 937 | Error |
| 938 | SetOptionValue (uint32_t option_idx, const char *option_arg) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 939 | { |
| 940 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 941 | const int short_option = m_getopt_table[option_idx].val; |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 942 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 943 | switch (short_option) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 944 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 945 | case 'c': |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 946 | if (option_arg != nullptr) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 947 | 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 Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 956 | case 'D': |
| 957 | m_use_dummy = true; |
| 958 | break; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 959 | case 'e': |
| 960 | m_enable_passed = true; |
| 961 | m_enable_value = true; |
| 962 | break; |
| 963 | case 'i': |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 964 | m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 965 | if (m_ignore_count == UINT32_MAX) |
| 966 | error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 967 | break; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 968 | 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 Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 981 | case 't' : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 982 | if (option_arg[0] == '\0') |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 983 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 984 | m_thread_id = LLDB_INVALID_THREAD_ID; |
| 985 | m_thread_id_passed = true; |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 986 | } |
| 987 | else |
| 988 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 989 | m_thread_id = StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 990 | 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 Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 994 | } |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 995 | break; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 996 | case 'T': |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 997 | if (option_arg != nullptr) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 998 | m_thread_name.assign (option_arg); |
| 999 | else |
| 1000 | m_thread_name.clear(); |
| 1001 | m_name_passed = true; |
| 1002 | break; |
| 1003 | case 'q': |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1004 | if (option_arg != nullptr) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1005 | m_queue_name.assign (option_arg); |
| 1006 | else |
| 1007 | m_queue_name.clear(); |
| 1008 | m_queue_passed = true; |
| 1009 | break; |
| 1010 | case 'x': |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1011 | if (option_arg[0] == '\n') |
| 1012 | { |
| 1013 | m_thread_index = UINT32_MAX; |
| 1014 | m_thread_index_passed = true; |
| 1015 | } |
| 1016 | else |
| 1017 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 1018 | m_thread_index = StringConvert::ToUInt32 (option_arg, UINT32_MAX, 0); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1019 | 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1024 | break; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1025 | default: |
| 1026 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 1027 | break; |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1028 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1029 | |
| 1030 | return error; |
| 1031 | } |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1032 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1033 | void |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1034 | OptionParsingStarting () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1035 | { |
| 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 Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 1044 | m_one_shot = false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1045 | m_enable_passed = false; |
| 1046 | m_queue_passed = false; |
| 1047 | m_name_passed = false; |
| 1048 | m_condition_passed = false; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 1049 | m_one_shot_passed = false; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1050 | m_use_dummy = false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | const OptionDefinition* |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1054 | GetDefinitions () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1055 | { |
| 1056 | return g_option_table; |
| 1057 | } |
| 1058 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1059 | // 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 Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 1073 | bool m_one_shot; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1074 | 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 Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 1079 | bool m_one_shot_passed; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1080 | bool m_use_dummy; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1081 | }; |
| 1082 | |
| 1083 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1084 | bool |
| 1085 | DoExecute (Args& command, CommandReturnObject &result) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1086 | { |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1087 | Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1088 | if (target == nullptr) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1089 | { |
| 1090 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 1091 | result.SetStatus (eReturnStatusFailed); |
| 1092 | return false; |
| 1093 | } |
| 1094 | |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 1095 | std::unique_lock<std::recursive_mutex> lock; |
| 1096 | target->GetBreakpointList().GetListMutex(lock); |
| 1097 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1098 | BreakpointIDList valid_bp_ids; |
| 1099 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1100 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1101 | |
| 1102 | if (result.Succeeded()) |
| 1103 | { |
| 1104 | const size_t count = valid_bp_ids.GetSize(); |
| 1105 | for (size_t i = 0; i < count; ++i) |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1106 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1107 | 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 Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1163 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | return result.Succeeded(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1167 | } |
| 1168 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1169 | private: |
| 1170 | CommandOptions m_options; |
| 1171 | }; |
Johnny Chen | 7d49c9c | 2012-05-25 21:10:46 +0000 | [diff] [blame] | 1172 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1173 | #pragma mark Modify::CommandOptions |
| 1174 | OptionDefinition |
| 1175 | CommandObjectBreakpointModify::CommandOptions::g_option_table[] = |
| 1176 | { |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1177 | { 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 Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1187 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1188 | { 0, false, nullptr, 0 , 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1189 | }; |
| 1190 | |
| 1191 | //------------------------------------------------------------------------- |
| 1192 | // CommandObjectBreakpointEnable |
| 1193 | //------------------------------------------------------------------------- |
| 1194 | #pragma mark Enable |
| 1195 | |
| 1196 | class CommandObjectBreakpointEnable : public CommandObjectParsed |
| 1197 | { |
| 1198 | public: |
| 1199 | CommandObjectBreakpointEnable (CommandInterpreter &interpreter) : |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1200 | CommandObjectParsed(interpreter, |
| 1201 | "enable", |
| 1202 | "Enable the specified disabled breakpoint(s). If no breakpoints are specified, enable all of them.", |
| 1203 | nullptr) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1204 | { |
| 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1211 | ~CommandObjectBreakpointEnable() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1212 | |
| 1213 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1214 | bool |
| 1215 | DoExecute (Args& command, CommandReturnObject &result) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1216 | { |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 1217 | Target *target = GetSelectedOrDummyTarget(); |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1218 | if (target == nullptr) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1219 | { |
| 1220 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 1221 | result.SetStatus (eReturnStatusFailed); |
| 1222 | return false; |
| 1223 | } |
| 1224 | |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 1225 | std::unique_lock<std::recursive_mutex> lock; |
| 1226 | target->GetBreakpointList().GetListMutex(lock); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1227 | |
| 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 Clayton | 6fea17e | 2014-03-03 19:15:20 +0000 | [diff] [blame] | 1243 | result.AppendMessageWithFormat ("All breakpoints enabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1244 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1245 | } |
| 1246 | else |
| 1247 | { |
| 1248 | // Particular breakpoint selected; enable that breakpoint. |
| 1249 | BreakpointIDList valid_bp_ids; |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1250 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1251 | |
| 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 | |
| 1294 | class CommandObjectBreakpointDisable : public CommandObjectParsed |
| 1295 | { |
| 1296 | public: |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame^] | 1297 | 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 Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1302 | { |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame^] | 1303 | SetHelpLong("Disable the specified breakpoint(s) without deleting them. \ |
| 1304 | If none are specified, disable all breakpoints." |
| 1305 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 1306 | |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame^] | 1307 | )" |
| 1308 | "Note: disabling a breakpoint will cause none of its locations to be hit \ |
| 1309 | regardless of whether individual locations are enabled or disabled. After the sequence:" |
| 1310 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 1311 | |
| 1312 | (lldb) break disable 1 |
| 1313 | (lldb) break enable 1.1 |
| 1314 | |
| 1315 | execution 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 Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame^] | 1320 | )" |
| 1321 | "The first command disables all locations for breakpoint 1, \ |
| 1322 | the second re-enables the first location."); |
| 1323 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1324 | 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 Ingham | b0fac50 | 2013-03-08 00:31:40 +0000 | [diff] [blame] | 1327 | m_arguments.push_back (arg); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1330 | ~CommandObjectBreakpointDisable() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1331 | |
| 1332 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1333 | bool |
| 1334 | DoExecute (Args& command, CommandReturnObject &result) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1335 | { |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 1336 | Target *target = GetSelectedOrDummyTarget(); |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1337 | if (target == nullptr) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1338 | { |
| 1339 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 1340 | result.SetStatus (eReturnStatusFailed); |
| 1341 | return false; |
| 1342 | } |
| 1343 | |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 1344 | std::unique_lock<std::recursive_mutex> lock; |
| 1345 | target->GetBreakpointList().GetListMutex(lock); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1346 | |
| 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 Clayton | 6fea17e | 2014-03-03 19:15:20 +0000 | [diff] [blame] | 1361 | result.AppendMessageWithFormat ("All breakpoints disabled. (%" PRIu64 " breakpoints)\n", (uint64_t)num_breakpoints); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1362 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1363 | } |
| 1364 | else |
| 1365 | { |
| 1366 | // Particular breakpoint selected; disable that breakpoint. |
| 1367 | BreakpointIDList valid_bp_ids; |
| 1368 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1369 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1370 | |
| 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 Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1406 | }; |
| 1407 | |
| 1408 | //------------------------------------------------------------------------- |
| 1409 | // CommandObjectBreakpointList |
| 1410 | //------------------------------------------------------------------------- |
| 1411 | #pragma mark List |
| 1412 | |
| 1413 | class CommandObjectBreakpointList : public CommandObjectParsed |
| 1414 | { |
| 1415 | public: |
| 1416 | CommandObjectBreakpointList (CommandInterpreter &interpreter) : |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1417 | CommandObjectParsed(interpreter, |
| 1418 | "breakpoint list", |
| 1419 | "List some or all breakpoints at configurable levels of detail.", |
| 1420 | nullptr), |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1421 | 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1437 | ~CommandObjectBreakpointList() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1438 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1439 | Options * |
| 1440 | GetOptions () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1441 | { |
| 1442 | return &m_options; |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1445 | class CommandOptions : public Options |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1446 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1447 | public: |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1448 | CommandOptions (CommandInterpreter &interpreter) : |
| 1449 | Options (interpreter), |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1450 | m_level (lldb::eDescriptionLevelBrief), |
| 1451 | m_use_dummy(false) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1452 | { |
| 1453 | } |
| 1454 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1455 | ~CommandOptions() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1456 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1457 | Error |
| 1458 | SetOptionValue (uint32_t option_idx, const char *option_arg) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1459 | { |
| 1460 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 1461 | const int short_option = m_getopt_table[option_idx].val; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1462 | |
| 1463 | switch (short_option) |
| 1464 | { |
| 1465 | case 'b': |
| 1466 | m_level = lldb::eDescriptionLevelBrief; |
| 1467 | break; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1468 | case 'D': |
| 1469 | m_use_dummy = true; |
| 1470 | break; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1471 | 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 Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1489 | OptionParsingStarting () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1490 | { |
| 1491 | m_level = lldb::eDescriptionLevelFull; |
| 1492 | m_internal = false; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1493 | m_use_dummy = false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | const OptionDefinition * |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1497 | GetDefinitions () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1498 | { |
| 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 Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1511 | bool m_use_dummy; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1512 | }; |
| 1513 | |
| 1514 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1515 | bool |
| 1516 | DoExecute (Args& command, CommandReturnObject &result) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1517 | { |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1518 | Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); |
| 1519 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1520 | if (target == nullptr) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1521 | { |
| 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 Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 1528 | std::unique_lock<std::recursive_mutex> lock; |
| 1529 | target->GetBreakpointList(m_options.m_internal).GetListMutex(lock); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1530 | |
| 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 Ingham | 85e8b81 | 2011-02-19 02:53:09 +0000 | [diff] [blame] | 1540 | Stream &output_stream = result.GetOutputStream(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1541 | |
| 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 Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1557 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1558 | |
| 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 Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame^] | 1571 | result.AppendError("Invalid breakpoint ID."); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1572 | result.SetStatus (eReturnStatusFailed); |
| 1573 | } |
| 1574 | } |
| 1575 | |
| 1576 | return result.Succeeded(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1579 | private: |
| 1580 | CommandOptions m_options; |
| 1581 | }; |
| 1582 | |
| 1583 | #pragma mark List::CommandOptions |
| 1584 | OptionDefinition |
| 1585 | CommandObjectBreakpointList::CommandOptions::g_option_table[] = |
| 1586 | { |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1587 | { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1588 | "Show debugger internal breakpoints" }, |
| 1589 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1590 | { LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1591 | "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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1595 | { LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1596 | "Give a full description of the breakpoint and its locations."}, |
| 1597 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1598 | { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1599 | "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, |
| 1600 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1601 | { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1602 | "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, |
| 1603 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1604 | { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1605 | }; |
| 1606 | |
| 1607 | //------------------------------------------------------------------------- |
| 1608 | // CommandObjectBreakpointClear |
| 1609 | //------------------------------------------------------------------------- |
| 1610 | #pragma mark Clear |
| 1611 | |
| 1612 | class CommandObjectBreakpointClear : public CommandObjectParsed |
| 1613 | { |
| 1614 | public: |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1615 | typedef enum BreakpointClearType |
| 1616 | { |
| 1617 | eClearTypeInvalid, |
| 1618 | eClearTypeFileAndLine |
| 1619 | } BreakpointClearType; |
| 1620 | |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame^] | 1621 | 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 Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1626 | { |
| 1627 | } |
| 1628 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1629 | ~CommandObjectBreakpointClear() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1630 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1631 | Options * |
| 1632 | GetOptions () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1633 | { |
| 1634 | return &m_options; |
| 1635 | } |
| 1636 | |
| 1637 | class CommandOptions : public Options |
| 1638 | { |
| 1639 | public: |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1640 | CommandOptions (CommandInterpreter &interpreter) : |
| 1641 | Options (interpreter), |
| 1642 | m_filename (), |
| 1643 | m_line_num (0) |
| 1644 | { |
| 1645 | } |
| 1646 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1647 | ~CommandOptions() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1648 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1649 | Error |
| 1650 | SetOptionValue (uint32_t option_idx, const char *option_arg) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1651 | { |
| 1652 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 1653 | const int short_option = m_getopt_table[option_idx].val; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1654 | |
| 1655 | switch (short_option) |
| 1656 | { |
| 1657 | case 'f': |
| 1658 | m_filename.assign (option_arg); |
| 1659 | break; |
| 1660 | |
| 1661 | case 'l': |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 1662 | m_line_num = StringConvert::ToUInt32 (option_arg, 0); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1663 | break; |
| 1664 | |
| 1665 | default: |
| 1666 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 1667 | break; |
| 1668 | } |
| 1669 | |
| 1670 | return error; |
| 1671 | } |
| 1672 | |
| 1673 | void |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1674 | OptionParsingStarting () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1675 | { |
| 1676 | m_filename.clear(); |
| 1677 | m_line_num = 0; |
| 1678 | } |
| 1679 | |
| 1680 | const OptionDefinition* |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1681 | GetDefinitions () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1682 | { |
| 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 | |
| 1697 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1698 | bool |
| 1699 | DoExecute (Args& command, CommandReturnObject &result) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1700 | { |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 1701 | Target *target = GetSelectedOrDummyTarget(); |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1702 | if (target == nullptr) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1703 | { |
| 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 Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 1717 | std::unique_lock<std::recursive_mutex> lock; |
| 1718 | target->GetBreakpointList().GetListMutex(lock); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1719 | |
| 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1736 | BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID()); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1737 | |
| 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 | |
| 1787 | private: |
| 1788 | CommandOptions m_options; |
| 1789 | }; |
| 1790 | |
| 1791 | #pragma mark Clear::CommandOptions |
| 1792 | |
| 1793 | OptionDefinition |
| 1794 | CommandObjectBreakpointClear::CommandOptions::g_option_table[] = |
| 1795 | { |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1796 | { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1797 | "Specify the breakpoint by source location in this particular file."}, |
| 1798 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1799 | { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1800 | "Specify the breakpoint by source location at this particular line."}, |
| 1801 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1802 | { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1803 | }; |
| 1804 | |
| 1805 | //------------------------------------------------------------------------- |
| 1806 | // CommandObjectBreakpointDelete |
| 1807 | //------------------------------------------------------------------------- |
| 1808 | #pragma mark Delete |
| 1809 | |
| 1810 | class CommandObjectBreakpointDelete : public CommandObjectParsed |
| 1811 | { |
| 1812 | public: |
| 1813 | CommandObjectBreakpointDelete (CommandInterpreter &interpreter) : |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1814 | CommandObjectParsed(interpreter, |
| 1815 | "breakpoint delete", |
| 1816 | "Delete the specified breakpoint(s). If no breakpoints are specified, delete them all.", |
| 1817 | nullptr), |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1818 | m_options (interpreter) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1819 | { |
| 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1826 | ~CommandObjectBreakpointDelete() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1827 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1828 | Options * |
| 1829 | GetOptions () override |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1830 | { |
| 1831 | return &m_options; |
| 1832 | } |
| 1833 | |
| 1834 | class CommandOptions : public Options |
| 1835 | { |
| 1836 | public: |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1837 | CommandOptions (CommandInterpreter &interpreter) : |
| 1838 | Options (interpreter), |
| 1839 | m_use_dummy (false), |
| 1840 | m_force (false) |
| 1841 | { |
| 1842 | } |
| 1843 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1844 | ~CommandOptions() override = default; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1845 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1846 | Error |
| 1847 | SetOptionValue (uint32_t option_idx, const char *option_arg) override |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1848 | { |
| 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 Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1871 | OptionParsingStarting () override |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1872 | { |
| 1873 | m_use_dummy = false; |
| 1874 | m_force = false; |
| 1875 | } |
| 1876 | |
| 1877 | const OptionDefinition* |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1878 | GetDefinitions () override |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1879 | { |
| 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 Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1892 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1893 | bool |
| 1894 | DoExecute (Args& command, CommandReturnObject &result) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1895 | { |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1896 | Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); |
| 1897 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1898 | if (target == nullptr) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1899 | { |
| 1900 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 1901 | result.SetStatus (eReturnStatusFailed); |
| 1902 | return false; |
| 1903 | } |
| 1904 | |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 1905 | std::unique_lock<std::recursive_mutex> lock; |
| 1906 | target->GetBreakpointList().GetListMutex(lock); |
| 1907 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1908 | 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 Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1921 | if (!m_options.m_force && !m_interpreter.Confirm ("About to delete all breakpoints, do you want to do that?", true)) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1922 | { |
| 1923 | result.AppendMessage("Operation cancelled..."); |
| 1924 | } |
| 1925 | else |
| 1926 | { |
| 1927 | target->RemoveAllBreakpoints (); |
Greg Clayton | 6fea17e | 2014-03-03 19:15:20 +0000 | [diff] [blame] | 1928 | result.AppendMessageWithFormat ("All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : ""); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1929 | } |
| 1930 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1931 | } |
| 1932 | else |
| 1933 | { |
| 1934 | // Particular breakpoint selected; disable that breakpoint. |
| 1935 | BreakpointIDList valid_bp_ids; |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1936 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs (command, target, result, &valid_bp_ids); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1937 | |
| 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1974 | |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1975 | private: |
| 1976 | CommandOptions m_options; |
| 1977 | }; |
| 1978 | |
| 1979 | OptionDefinition |
| 1980 | CommandObjectBreakpointDelete::CommandOptions::g_option_table[] = |
| 1981 | { |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1982 | { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1983 | "Delete all breakpoints without querying for confirmation."}, |
| 1984 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1985 | { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1986 | "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, |
| 1987 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1988 | { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1989 | }; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1990 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1991 | //------------------------------------------------------------------------- |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1992 | // CommandObjectBreakpointName |
| 1993 | //------------------------------------------------------------------------- |
| 1994 | |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame^] | 1995 | static 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 Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2002 | }; |
| 2003 | class BreakpointNameOptionGroup : public OptionGroup |
| 2004 | { |
| 2005 | public: |
| 2006 | BreakpointNameOptionGroup() : |
| 2007 | OptionGroup(), |
| 2008 | m_breakpoint(LLDB_INVALID_BREAK_ID), |
| 2009 | m_use_dummy (false) |
| 2010 | { |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2011 | } |
| 2012 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2013 | ~BreakpointNameOptionGroup() override = default; |
| 2014 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2015 | uint32_t |
| 2016 | GetNumDefinitions () override |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2017 | { |
| 2018 | return sizeof (g_breakpoint_name_options) / sizeof (OptionDefinition); |
| 2019 | } |
| 2020 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2021 | const OptionDefinition* |
| 2022 | GetDefinitions () override |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2023 | { |
| 2024 | return g_breakpoint_name_options; |
| 2025 | } |
| 2026 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2027 | Error |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2028 | SetOptionValue (CommandInterpreter &interpreter, |
| 2029 | uint32_t option_idx, |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2030 | const char *option_value) override |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2031 | { |
| 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 Labath | c95f7e2 | 2015-02-20 11:14:59 +0000 | [diff] [blame] | 2039 | m_name.SetValueFromString(option_value); |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2040 | break; |
| 2041 | |
| 2042 | case 'B': |
Pavel Labath | c95f7e2 | 2015-02-20 11:14:59 +0000 | [diff] [blame] | 2043 | if (m_breakpoint.SetValueFromString(option_value).Fail()) |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2044 | error.SetErrorStringWithFormat ("unrecognized value \"%s\" for breakpoint", option_value); |
| 2045 | break; |
| 2046 | case 'D': |
Pavel Labath | c95f7e2 | 2015-02-20 11:14:59 +0000 | [diff] [blame] | 2047 | if (m_use_dummy.SetValueFromString(option_value).Fail()) |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2048 | 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 Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2058 | void |
| 2059 | OptionParsingStarting (CommandInterpreter &interpreter) override |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2060 | { |
| 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 Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2072 | class CommandObjectBreakpointNameAdd : public CommandObjectParsed |
| 2073 | { |
| 2074 | public: |
| 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2095 | ~CommandObjectBreakpointNameAdd() override = default; |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2096 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2097 | Options * |
| 2098 | GetOptions() override |
| 2099 | { |
| 2100 | return &m_option_group; |
| 2101 | } |
| 2102 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2103 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2104 | bool |
| 2105 | DoExecute (Args& command, CommandReturnObject &result) override |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2106 | { |
| 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2115 | if (target == nullptr) |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2116 | { |
| 2117 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 2118 | result.SetStatus (eReturnStatusFailed); |
| 2119 | return false; |
| 2120 | } |
| 2121 | |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 2122 | std::unique_lock<std::recursive_mutex> lock; |
| 2123 | target->GetBreakpointList().GetListMutex(lock); |
| 2124 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2125 | 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 | |
| 2160 | private: |
| 2161 | BreakpointNameOptionGroup m_name_options; |
| 2162 | OptionGroupOptions m_option_group; |
| 2163 | }; |
| 2164 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2165 | class CommandObjectBreakpointNameDelete : public CommandObjectParsed |
| 2166 | { |
| 2167 | public: |
| 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2188 | ~CommandObjectBreakpointNameDelete() override = default; |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2189 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2190 | Options * |
| 2191 | GetOptions() override |
| 2192 | { |
| 2193 | return &m_option_group; |
| 2194 | } |
| 2195 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2196 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2197 | bool |
| 2198 | DoExecute (Args& command, CommandReturnObject &result) override |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2199 | { |
| 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2208 | if (target == nullptr) |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2209 | { |
| 2210 | result.AppendError ("Invalid target. No existing target or breakpoints."); |
| 2211 | result.SetStatus (eReturnStatusFailed); |
| 2212 | return false; |
| 2213 | } |
| 2214 | |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 2215 | std::unique_lock<std::recursive_mutex> lock; |
| 2216 | target->GetBreakpointList().GetListMutex(lock); |
| 2217 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2218 | 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 | |
| 2252 | private: |
| 2253 | BreakpointNameOptionGroup m_name_options; |
| 2254 | OptionGroupOptions m_option_group; |
| 2255 | }; |
| 2256 | |
| 2257 | class CommandObjectBreakpointNameList : public CommandObjectParsed |
| 2258 | { |
| 2259 | public: |
| 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 Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2272 | ~CommandObjectBreakpointNameList() override = default; |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2273 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2274 | Options * |
| 2275 | GetOptions() override |
| 2276 | { |
| 2277 | return &m_option_group; |
| 2278 | } |
| 2279 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2280 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2281 | bool |
| 2282 | DoExecute (Args& command, CommandReturnObject &result) override |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2283 | { |
| 2284 | Target *target = GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); |
| 2285 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2286 | if (target == nullptr) |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2287 | { |
| 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 Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 2296 | std::unique_lock<std::recursive_mutex> lock; |
| 2297 | target->GetBreakpointList().GetListMutex(lock); |
| 2298 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2299 | 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 | |
| 2340 | private: |
| 2341 | BreakpointNameOptionGroup m_name_options; |
| 2342 | OptionGroupOptions m_option_group; |
| 2343 | }; |
| 2344 | |
| 2345 | //------------------------------------------------------------------------- |
| 2346 | // CommandObjectMultiwordBreakpoint |
| 2347 | //------------------------------------------------------------------------- |
| 2348 | class CommandObjectBreakpointName : public CommandObjectMultiword |
| 2349 | { |
| 2350 | public: |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame^] | 2351 | CommandObjectBreakpointName(CommandInterpreter &interpreter) |
| 2352 | : CommandObjectMultiword(interpreter, "name", "Commands to manage name tags for breakpoints", |
| 2353 | "breakpoint name <subcommand> [<command-options>]") |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2354 | { |
| 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 Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2362 | } |
| 2363 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2364 | ~CommandObjectBreakpointName() override = default; |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2365 | }; |
| 2366 | |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2367 | //------------------------------------------------------------------------- |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2368 | // CommandObjectMultiwordBreakpoint |
| 2369 | //------------------------------------------------------------------------- |
Jim Ingham | ae1c4cf | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 2370 | #pragma mark MultiwordBreakpoint |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2371 | |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame^] | 2372 | CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint(CommandInterpreter &interpreter) |
| 2373 | : CommandObjectMultiword(interpreter, "breakpoint", |
| 2374 | "Commands for operating on breakpoints (see 'help b' for shorthand.)", |
| 2375 | "breakpoint <subcommand> [<command-options>]") |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2376 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2377 | CommandObjectSP list_command_object (new CommandObjectBreakpointList (interpreter)); |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2378 | CommandObjectSP enable_command_object (new CommandObjectBreakpointEnable (interpreter)); |
| 2379 | CommandObjectSP disable_command_object (new CommandObjectBreakpointDisable (interpreter)); |
Johnny Chen | b7234e4 | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 2380 | CommandObjectSP clear_command_object (new CommandObjectBreakpointClear (interpreter)); |
| 2381 | CommandObjectSP delete_command_object (new CommandObjectBreakpointDelete (interpreter)); |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2382 | CommandObjectSP set_command_object (new CommandObjectBreakpointSet (interpreter)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2383 | CommandObjectSP command_command_object (new CommandObjectBreakpointCommand (interpreter)); |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2384 | CommandObjectSP modify_command_object (new CommandObjectBreakpointModify(interpreter)); |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2385 | CommandObjectSP name_command_object (new CommandObjectBreakpointName(interpreter)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2386 | |
Johnny Chen | b7234e4 | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 2387 | list_command_object->SetCommandName ("breakpoint list"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2388 | enable_command_object->SetCommandName("breakpoint enable"); |
| 2389 | disable_command_object->SetCommandName("breakpoint disable"); |
Johnny Chen | b7234e4 | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 2390 | clear_command_object->SetCommandName("breakpoint clear"); |
| 2391 | delete_command_object->SetCommandName("breakpoint delete"); |
Jim Ingham | ae1c4cf | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 2392 | set_command_object->SetCommandName("breakpoint set"); |
Johnny Chen | b7234e4 | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 2393 | command_command_object->SetCommandName ("breakpoint command"); |
| 2394 | modify_command_object->SetCommandName ("breakpoint modify"); |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2395 | name_command_object->SetCommandName ("breakpoint name"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2396 | |
Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 2397 | 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 Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2405 | LoadSubCommand ("name", name_command_object); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2406 | } |
| 2407 | |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2408 | CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2409 | |
| 2410 | void |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2411 | CommandObjectMultiwordBreakpoint::VerifyIDs (Args &args, |
| 2412 | Target *target, |
| 2413 | bool allow_locations, |
| 2414 | CommandReturnObject &result, |
| 2415 | BreakpointIDList *valid_ids) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2416 | { |
| 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 Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2421 | // 4). A breakpoint name |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 2422 | // If args is empty, we will use the last created breakpoint (if there is one.) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2423 | |
| 2424 | Args temp_args; |
| 2425 | |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 2426 | if (args.GetArgumentCount() == 0) |
| 2427 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 2428 | if (target->GetLastCreatedBreakpoint()) |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 2429 | { |
| 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2441 | // 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 Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2445 | BreakpointIDList::FindAndReplaceIDRanges (args, target, allow_locations, result, temp_args); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2446 | |
| 2447 | // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual BreakpointIDList: |
| 2448 | |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 2449 | valid_ids->InsertStringArray (temp_args.GetConstArgumentVector(), temp_args.GetArgumentCount(), result); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2450 | |
| 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 Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 2459 | const size_t count = valid_ids->GetSize(); |
| 2460 | for (size_t i = 0; i < count; ++i) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2461 | { |
| 2462 | BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex (i); |
| 2463 | Breakpoint *breakpoint = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get(); |
Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2464 | if (breakpoint != nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2465 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2466 | const size_t num_locations = breakpoint->GetNumLocations(); |
Saleem Abdulrasool | 3985c8c | 2014-04-02 03:51:35 +0000 | [diff] [blame] | 2467 | if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2468 | { |
| 2469 | StreamString id_str; |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 2470 | BreakpointID::GetCanonicalReference (&id_str, |
| 2471 | cur_bp_id.GetBreakpointID(), |
| 2472 | cur_bp_id.GetLocationID()); |
| 2473 | i = valid_ids->GetSize() + 1; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2474 | 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 Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 2481 | i = valid_ids->GetSize() + 1; |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame^] | 2482 | result.AppendErrorWithFormat("'%d' is not a currently valid breakpoint ID.\n", |
| 2483 | cur_bp_id.GetBreakpointID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2484 | result.SetStatus (eReturnStatusFailed); |
| 2485 | } |
| 2486 | } |
| 2487 | } |
| 2488 | } |