| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandObjectBreakpoint.cpp -----------------------------*- C++ -*-===// | 
|  | 2 | // | 
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | 
|  | 4 | // See https://llvm.org/LICENSE.txt for license information. | 
|  | 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6 | // | 
|  | 7 | //===----------------------------------------------------------------------===// | 
|  | 8 |  | 
| Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 9 | #include "CommandObjectBreakpoint.h" | 
|  | 10 | #include "CommandObjectBreakpointCommand.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | #include "lldb/Breakpoint/Breakpoint.h" | 
|  | 12 | #include "lldb/Breakpoint/BreakpointIDList.h" | 
|  | 13 | #include "lldb/Breakpoint/BreakpointLocation.h" | 
| Zachary Turner | 3eb2b44 | 2017-03-22 23:33:16 +0000 | [diff] [blame] | 14 | #include "lldb/Host/OptionParser.h" | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 15 | #include "lldb/Interpreter/CommandCompletions.h" | 
|  | 16 | #include "lldb/Interpreter/CommandInterpreter.h" | 
|  | 17 | #include "lldb/Interpreter/CommandReturnObject.h" | 
| Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/OptionArgParser.h" | 
| Zachary Turner | 32abc6e | 2015-03-03 19:23:09 +0000 | [diff] [blame] | 19 | #include "lldb/Interpreter/OptionValueBoolean.h" | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 20 | #include "lldb/Interpreter/OptionValueString.h" | 
|  | 21 | #include "lldb/Interpreter/OptionValueUInt64.h" | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 22 | #include "lldb/Interpreter/Options.h" | 
| Jim Ingham | 0e0984e | 2015-09-02 01:06:46 +0000 | [diff] [blame] | 23 | #include "lldb/Target/Language.h" | 
| Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 24 | #include "lldb/Target/StackFrame.h" | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Target.h" | 
| Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 26 | #include "lldb/Target/Thread.h" | 
|  | 27 | #include "lldb/Target/ThreadSpec.h" | 
| Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 28 | #include "lldb/Utility/RegularExpression.h" | 
|  | 29 | #include "lldb/Utility/StreamString.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 |  | 
| Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 31 | #include <memory> | 
|  | 32 | #include <vector> | 
|  | 33 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | using namespace lldb; | 
|  | 35 | using namespace lldb_private; | 
|  | 36 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | static void AddBreakpointDescription(Stream *s, Breakpoint *bp, | 
|  | 38 | lldb::DescriptionLevel level) { | 
|  | 39 | s->IndentMore(); | 
|  | 40 | bp->GetDescription(s, level, true); | 
|  | 41 | s->IndentLess(); | 
|  | 42 | s->EOL(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | } | 
|  | 44 |  | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 45 | // Modifiable Breakpoint Options | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 46 | #pragma mark Modify::CommandOptions | 
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 47 | static constexpr OptionDefinition g_breakpoint_modify_options[] = { | 
| Raphael Isemann | f94668e | 2019-07-22 10:02:09 +0000 | [diff] [blame^] | 48 | #define LLDB_OPTIONS_breakpoint_modify | 
|  | 49 | #include "CommandOptions.inc" | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 50 | }; | 
|  | 51 | class lldb_private::BreakpointOptionGroup : public OptionGroup | 
|  | 52 | { | 
|  | 53 | public: | 
|  | 54 | BreakpointOptionGroup() : | 
|  | 55 | OptionGroup(), | 
|  | 56 | m_bp_opts(false) {} | 
|  | 57 |  | 
|  | 58 | ~BreakpointOptionGroup() override = default; | 
|  | 59 |  | 
|  | 60 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { | 
|  | 61 | return llvm::makeArrayRef(g_breakpoint_modify_options); | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, | 
|  | 65 | ExecutionContext *execution_context) override { | 
|  | 66 | Status error; | 
|  | 67 | const int short_option = g_breakpoint_modify_options[option_idx].short_option; | 
|  | 68 |  | 
|  | 69 | switch (short_option) { | 
|  | 70 | case 'c': | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 71 | // Normally an empty breakpoint condition marks is as unset. But we need | 
|  | 72 | // to say it was passed in. | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 73 | m_bp_opts.SetCondition(option_arg.str().c_str()); | 
|  | 74 | m_bp_opts.m_set_flags.Set(BreakpointOptions::eCondition); | 
|  | 75 | break; | 
|  | 76 | case 'C': | 
|  | 77 | m_commands.push_back(option_arg); | 
|  | 78 | break; | 
|  | 79 | case 'd': | 
|  | 80 | m_bp_opts.SetEnabled(false); | 
|  | 81 | break; | 
|  | 82 | case 'e': | 
|  | 83 | m_bp_opts.SetEnabled(true); | 
|  | 84 | break; | 
|  | 85 | case 'G': { | 
|  | 86 | bool value, success; | 
| Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 87 | value = OptionArgParser::ToBoolean(option_arg, false, &success); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 88 | if (success) { | 
|  | 89 | m_bp_opts.SetAutoContinue(value); | 
|  | 90 | } else | 
|  | 91 | error.SetErrorStringWithFormat( | 
|  | 92 | "invalid boolean value '%s' passed for -G option", | 
|  | 93 | option_arg.str().c_str()); | 
|  | 94 | } | 
|  | 95 | break; | 
|  | 96 | case 'i': | 
|  | 97 | { | 
|  | 98 | uint32_t ignore_count; | 
|  | 99 | if (option_arg.getAsInteger(0, ignore_count)) | 
|  | 100 | error.SetErrorStringWithFormat("invalid ignore count '%s'", | 
|  | 101 | option_arg.str().c_str()); | 
|  | 102 | else | 
|  | 103 | m_bp_opts.SetIgnoreCount(ignore_count); | 
|  | 104 | } | 
|  | 105 | break; | 
|  | 106 | case 'o': { | 
|  | 107 | bool value, success; | 
| Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 108 | value = OptionArgParser::ToBoolean(option_arg, false, &success); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 109 | if (success) { | 
|  | 110 | m_bp_opts.SetOneShot(value); | 
|  | 111 | } else | 
|  | 112 | error.SetErrorStringWithFormat( | 
|  | 113 | "invalid boolean value '%s' passed for -o option", | 
|  | 114 | option_arg.str().c_str()); | 
|  | 115 | } break; | 
|  | 116 | case 't': | 
|  | 117 | { | 
|  | 118 | lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID; | 
|  | 119 | if (option_arg[0] != '\0') { | 
|  | 120 | if (option_arg.getAsInteger(0, thread_id)) | 
|  | 121 | error.SetErrorStringWithFormat("invalid thread id string '%s'", | 
|  | 122 | option_arg.str().c_str()); | 
|  | 123 | } | 
|  | 124 | m_bp_opts.SetThreadID(thread_id); | 
|  | 125 | } | 
|  | 126 | break; | 
|  | 127 | case 'T': | 
|  | 128 | m_bp_opts.GetThreadSpec()->SetName(option_arg.str().c_str()); | 
|  | 129 | break; | 
|  | 130 | case 'q': | 
|  | 131 | m_bp_opts.GetThreadSpec()->SetQueueName(option_arg.str().c_str()); | 
|  | 132 | break; | 
|  | 133 | case 'x': | 
|  | 134 | { | 
|  | 135 | uint32_t thread_index = UINT32_MAX; | 
|  | 136 | if (option_arg[0] != '\n') { | 
|  | 137 | if (option_arg.getAsInteger(0, thread_index)) | 
|  | 138 | error.SetErrorStringWithFormat("invalid thread index string '%s'", | 
|  | 139 | option_arg.str().c_str()); | 
|  | 140 | } | 
|  | 141 | m_bp_opts.GetThreadSpec()->SetIndex(thread_index); | 
|  | 142 | } | 
|  | 143 | break; | 
|  | 144 | default: | 
|  | 145 | error.SetErrorStringWithFormat("unrecognized option '%c'", | 
|  | 146 | short_option); | 
|  | 147 | break; | 
|  | 148 | } | 
|  | 149 |  | 
|  | 150 | return error; | 
|  | 151 | } | 
|  | 152 |  | 
|  | 153 | void OptionParsingStarting(ExecutionContext *execution_context) override { | 
|  | 154 | m_bp_opts.Clear(); | 
|  | 155 | m_commands.clear(); | 
|  | 156 | } | 
|  | 157 |  | 
|  | 158 | Status OptionParsingFinished(ExecutionContext *execution_context) override { | 
|  | 159 | if (!m_commands.empty()) | 
|  | 160 | { | 
|  | 161 | if (!m_commands.empty()) | 
|  | 162 | { | 
|  | 163 | auto cmd_data = llvm::make_unique<BreakpointOptions::CommandData>(); | 
|  | 164 |  | 
|  | 165 | for (std::string &str : m_commands) | 
|  | 166 | cmd_data->user_source.AppendString(str); | 
|  | 167 |  | 
|  | 168 | cmd_data->stop_on_error = true; | 
|  | 169 | m_bp_opts.SetCommandDataCallback(cmd_data); | 
|  | 170 | } | 
|  | 171 | } | 
|  | 172 | return Status(); | 
|  | 173 | } | 
|  | 174 |  | 
|  | 175 | const BreakpointOptions &GetBreakpointOptions() | 
|  | 176 | { | 
|  | 177 | return m_bp_opts; | 
|  | 178 | } | 
|  | 179 |  | 
|  | 180 | std::vector<std::string> m_commands; | 
|  | 181 | BreakpointOptions m_bp_opts; | 
|  | 182 |  | 
|  | 183 | }; | 
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 184 | static constexpr OptionDefinition g_breakpoint_dummy_options[] = { | 
| Raphael Isemann | f94668e | 2019-07-22 10:02:09 +0000 | [diff] [blame^] | 185 | #define LLDB_OPTIONS_breakpoint_dummy | 
|  | 186 | #include "CommandOptions.inc" | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 187 | }; | 
|  | 188 |  | 
|  | 189 | class BreakpointDummyOptionGroup : public OptionGroup | 
|  | 190 | { | 
|  | 191 | public: | 
|  | 192 | BreakpointDummyOptionGroup() : | 
|  | 193 | OptionGroup() {} | 
|  | 194 |  | 
|  | 195 | ~BreakpointDummyOptionGroup() override = default; | 
|  | 196 |  | 
|  | 197 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { | 
|  | 198 | return llvm::makeArrayRef(g_breakpoint_dummy_options); | 
|  | 199 | } | 
|  | 200 |  | 
|  | 201 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, | 
|  | 202 | ExecutionContext *execution_context) override { | 
|  | 203 | Status error; | 
|  | 204 | const int short_option = g_breakpoint_modify_options[option_idx].short_option; | 
|  | 205 |  | 
|  | 206 | switch (short_option) { | 
|  | 207 | case 'D': | 
|  | 208 | m_use_dummy = true; | 
|  | 209 | break; | 
|  | 210 | default: | 
|  | 211 | error.SetErrorStringWithFormat("unrecognized option '%c'", | 
|  | 212 | short_option); | 
|  | 213 | break; | 
|  | 214 | } | 
|  | 215 |  | 
|  | 216 | return error; | 
|  | 217 | } | 
|  | 218 |  | 
|  | 219 | void OptionParsingStarting(ExecutionContext *execution_context) override { | 
|  | 220 | m_use_dummy = false; | 
|  | 221 | } | 
|  | 222 |  | 
|  | 223 | bool m_use_dummy; | 
|  | 224 |  | 
|  | 225 | }; | 
|  | 226 |  | 
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 227 | static constexpr OptionDefinition g_breakpoint_set_options[] = { | 
| Raphael Isemann | f94668e | 2019-07-22 10:02:09 +0000 | [diff] [blame^] | 228 | #define LLDB_OPTIONS_breakpoint_set | 
|  | 229 | #include "CommandOptions.inc" | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 230 | }; | 
|  | 231 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 232 | // CommandObjectBreakpointSet | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 233 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 234 | class CommandObjectBreakpointSet : public CommandObjectParsed { | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 235 | public: | 
| Fangrui Song | efe8e7e | 2019-05-14 08:55:50 +0000 | [diff] [blame] | 236 | enum BreakpointSetType { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 237 | eSetTypeInvalid, | 
|  | 238 | eSetTypeFileAndLine, | 
|  | 239 | eSetTypeAddress, | 
|  | 240 | eSetTypeFunctionName, | 
|  | 241 | eSetTypeFunctionRegexp, | 
|  | 242 | eSetTypeSourceRegexp, | 
| Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 243 | eSetTypeException, | 
|  | 244 | eSetTypeScripted, | 
| Fangrui Song | efe8e7e | 2019-05-14 08:55:50 +0000 | [diff] [blame] | 245 | }; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 246 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 247 | CommandObjectBreakpointSet(CommandInterpreter &interpreter) | 
|  | 248 | : CommandObjectParsed( | 
|  | 249 | interpreter, "breakpoint set", | 
|  | 250 | "Sets a breakpoint or set of breakpoints in the executable.", | 
|  | 251 | "breakpoint set <cmd-options>"), | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 252 | m_bp_opts(), m_options() { | 
|  | 253 | // We're picking up all the normal options, commands and disable. | 
|  | 254 | m_all_options.Append(&m_bp_opts, | 
|  | 255 | LLDB_OPT_SET_1 | LLDB_OPT_SET_3 | LLDB_OPT_SET_4, | 
|  | 256 | LLDB_OPT_SET_ALL); | 
|  | 257 | m_all_options.Append(&m_dummy_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); | 
|  | 258 | m_all_options.Append(&m_options); | 
|  | 259 | m_all_options.Finalize(); | 
|  | 260 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 261 |  | 
|  | 262 | ~CommandObjectBreakpointSet() override = default; | 
|  | 263 |  | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 264 | Options *GetOptions() override { return &m_all_options; } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 265 |  | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 266 | class CommandOptions : public OptionGroup { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 267 | public: | 
|  | 268 | CommandOptions() | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 269 | : OptionGroup(), m_condition(), m_filenames(), m_line_num(0), m_column(0), | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 270 | m_func_names(), m_func_name_type_mask(eFunctionNameTypeNone), | 
|  | 271 | m_func_regexp(), m_source_text_regexp(), m_modules(), m_load_addr(), | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 272 | m_catch_bp(false), m_throw_bp(true), m_hardware(false), | 
|  | 273 | m_exception_language(eLanguageTypeUnknown), | 
|  | 274 | m_language(lldb::eLanguageTypeUnknown), | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 275 | m_skip_prologue(eLazyBoolCalculate), | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 276 | m_all_files(false), m_move_to_nearest_code(eLazyBoolCalculate) {} | 
|  | 277 |  | 
|  | 278 | ~CommandOptions() override = default; | 
|  | 279 |  | 
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 280 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, | 
|  | 281 | ExecutionContext *execution_context) override { | 
|  | 282 | Status error; | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 283 | const int short_option = g_breakpoint_set_options[option_idx].short_option; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 284 |  | 
|  | 285 | switch (short_option) { | 
|  | 286 | case 'a': { | 
| Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 287 | m_load_addr = OptionArgParser::ToAddress(execution_context, option_arg, | 
|  | 288 | LLDB_INVALID_ADDRESS, &error); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 289 | } break; | 
|  | 290 |  | 
|  | 291 | case 'A': | 
|  | 292 | m_all_files = true; | 
|  | 293 | break; | 
|  | 294 |  | 
|  | 295 | case 'b': | 
|  | 296 | m_func_names.push_back(option_arg); | 
|  | 297 | m_func_name_type_mask |= eFunctionNameTypeBase; | 
|  | 298 | break; | 
|  | 299 |  | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 300 | case 'C': | 
|  | 301 | if (option_arg.getAsInteger(0, m_column)) | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 302 | error.SetErrorStringWithFormat("invalid column number: %s", | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 303 | option_arg.str().c_str()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 304 | break; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 305 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 306 | case 'E': { | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 307 | LanguageType language = Language::GetLanguageTypeFromString(option_arg); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 308 |  | 
|  | 309 | switch (language) { | 
|  | 310 | case eLanguageTypeC89: | 
|  | 311 | case eLanguageTypeC: | 
|  | 312 | case eLanguageTypeC99: | 
|  | 313 | case eLanguageTypeC11: | 
|  | 314 | m_exception_language = eLanguageTypeC; | 
|  | 315 | break; | 
|  | 316 | case eLanguageTypeC_plus_plus: | 
|  | 317 | case eLanguageTypeC_plus_plus_03: | 
|  | 318 | case eLanguageTypeC_plus_plus_11: | 
|  | 319 | case eLanguageTypeC_plus_plus_14: | 
|  | 320 | m_exception_language = eLanguageTypeC_plus_plus; | 
|  | 321 | break; | 
|  | 322 | case eLanguageTypeObjC: | 
|  | 323 | m_exception_language = eLanguageTypeObjC; | 
|  | 324 | break; | 
|  | 325 | case eLanguageTypeObjC_plus_plus: | 
|  | 326 | error.SetErrorStringWithFormat( | 
|  | 327 | "Set exception breakpoints separately for c++ and objective-c"); | 
|  | 328 | break; | 
|  | 329 | case eLanguageTypeUnknown: | 
|  | 330 | error.SetErrorStringWithFormat( | 
|  | 331 | "Unknown language type: '%s' for exception breakpoint", | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 332 | option_arg.str().c_str()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 333 | break; | 
|  | 334 | default: | 
|  | 335 | error.SetErrorStringWithFormat( | 
|  | 336 | "Unsupported language type: '%s' for exception breakpoint", | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 337 | option_arg.str().c_str()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 338 | } | 
|  | 339 | } break; | 
|  | 340 |  | 
|  | 341 | case 'f': | 
| Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 342 | m_filenames.AppendIfUnique(FileSpec(option_arg)); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 343 | break; | 
|  | 344 |  | 
|  | 345 | case 'F': | 
|  | 346 | m_func_names.push_back(option_arg); | 
|  | 347 | m_func_name_type_mask |= eFunctionNameTypeFull; | 
|  | 348 | break; | 
| Jim Ingham | f08f5c9 | 2017-08-03 18:13:24 +0000 | [diff] [blame] | 349 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 350 | case 'h': { | 
|  | 351 | bool success; | 
| Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 352 | m_catch_bp = OptionArgParser::ToBoolean(option_arg, true, &success); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 353 | if (!success) | 
|  | 354 | error.SetErrorStringWithFormat( | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 355 | "Invalid boolean value for on-catch option: '%s'", | 
|  | 356 | option_arg.str().c_str()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 357 | } break; | 
|  | 358 |  | 
|  | 359 | case 'H': | 
|  | 360 | m_hardware = true; | 
|  | 361 | break; | 
| Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 362 |  | 
|  | 363 | case 'k': { | 
|  | 364 | if (m_current_key.empty()) | 
|  | 365 | m_current_key.assign(option_arg); | 
|  | 366 | else | 
|  | 367 | error.SetErrorStringWithFormat("Key: %s missing value.", | 
|  | 368 | m_current_key.c_str()); | 
|  | 369 |  | 
|  | 370 | } break; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 371 | case 'K': { | 
|  | 372 | bool success; | 
|  | 373 | bool value; | 
| Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 374 | value = OptionArgParser::ToBoolean(option_arg, true, &success); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 375 | if (value) | 
|  | 376 | m_skip_prologue = eLazyBoolYes; | 
|  | 377 | else | 
|  | 378 | m_skip_prologue = eLazyBoolNo; | 
|  | 379 |  | 
|  | 380 | if (!success) | 
|  | 381 | error.SetErrorStringWithFormat( | 
|  | 382 | "Invalid boolean value for skip prologue option: '%s'", | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 383 | option_arg.str().c_str()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 384 | } break; | 
|  | 385 |  | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 386 | case 'l': | 
|  | 387 | if (option_arg.getAsInteger(0, m_line_num)) | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 388 | error.SetErrorStringWithFormat("invalid line number: %s.", | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 389 | option_arg.str().c_str()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 390 | break; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 391 |  | 
|  | 392 | case 'L': | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 393 | m_language = Language::GetLanguageTypeFromString(option_arg); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 394 | if (m_language == eLanguageTypeUnknown) | 
|  | 395 | error.SetErrorStringWithFormat( | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 396 | "Unknown language type: '%s' for breakpoint", | 
|  | 397 | option_arg.str().c_str()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 398 | break; | 
|  | 399 |  | 
|  | 400 | case 'm': { | 
|  | 401 | bool success; | 
|  | 402 | bool value; | 
| Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 403 | value = OptionArgParser::ToBoolean(option_arg, true, &success); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 404 | if (value) | 
|  | 405 | m_move_to_nearest_code = eLazyBoolYes; | 
|  | 406 | else | 
|  | 407 | m_move_to_nearest_code = eLazyBoolNo; | 
|  | 408 |  | 
|  | 409 | if (!success) | 
|  | 410 | error.SetErrorStringWithFormat( | 
|  | 411 | "Invalid boolean value for move-to-nearest-code option: '%s'", | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 412 | option_arg.str().c_str()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 413 | break; | 
|  | 414 | } | 
|  | 415 |  | 
|  | 416 | case 'M': | 
|  | 417 | m_func_names.push_back(option_arg); | 
|  | 418 | m_func_name_type_mask |= eFunctionNameTypeMethod; | 
|  | 419 | break; | 
|  | 420 |  | 
|  | 421 | case 'n': | 
|  | 422 | m_func_names.push_back(option_arg); | 
|  | 423 | m_func_name_type_mask |= eFunctionNameTypeAuto; | 
|  | 424 | break; | 
|  | 425 |  | 
| Zachary Turner | 6fa7681b | 2016-09-17 02:00:02 +0000 | [diff] [blame] | 426 | case 'N': { | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 427 | if (BreakpointID::StringIsBreakpointName(option_arg, error)) | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 428 | m_breakpoint_names.push_back(option_arg); | 
| Jim Ingham | ff9a91e | 2016-09-21 01:21:19 +0000 | [diff] [blame] | 429 | else | 
|  | 430 | error.SetErrorStringWithFormat("Invalid breakpoint name: %s", | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 431 | option_arg.str().c_str()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 432 | break; | 
| Zachary Turner | 6fa7681b | 2016-09-17 02:00:02 +0000 | [diff] [blame] | 433 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 434 |  | 
|  | 435 | case 'R': { | 
|  | 436 | lldb::addr_t tmp_offset_addr; | 
| Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 437 | tmp_offset_addr = OptionArgParser::ToAddress(execution_context, | 
|  | 438 | option_arg, 0, &error); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 439 | if (error.Success()) | 
|  | 440 | m_offset_addr = tmp_offset_addr; | 
|  | 441 | } break; | 
|  | 442 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 443 | case 'O': | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 444 | m_exception_extra_args.AppendArgument("-O"); | 
|  | 445 | m_exception_extra_args.AppendArgument(option_arg); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 446 | break; | 
|  | 447 |  | 
|  | 448 | case 'p': | 
|  | 449 | m_source_text_regexp.assign(option_arg); | 
|  | 450 | break; | 
| Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 451 |  | 
|  | 452 | case 'P': | 
|  | 453 | m_python_class.assign(option_arg); | 
|  | 454 | break; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 455 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 456 | case 'r': | 
|  | 457 | m_func_regexp.assign(option_arg); | 
|  | 458 | break; | 
|  | 459 |  | 
|  | 460 | case 's': | 
| Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 461 | m_modules.AppendIfUnique(FileSpec(option_arg)); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 462 | break; | 
|  | 463 |  | 
|  | 464 | case 'S': | 
|  | 465 | m_func_names.push_back(option_arg); | 
|  | 466 | m_func_name_type_mask |= eFunctionNameTypeSelector; | 
|  | 467 | break; | 
|  | 468 |  | 
| Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 469 | case 'v': { | 
|  | 470 | if (!m_current_key.empty()) { | 
|  | 471 | m_extra_args_sp->AddStringItem(m_current_key, option_arg); | 
|  | 472 | m_current_key.clear(); | 
|  | 473 | } | 
|  | 474 | else | 
|  | 475 | error.SetErrorStringWithFormat("Value \"%s\" missing matching key.", | 
|  | 476 | option_arg.str().c_str()); | 
|  | 477 | } break; | 
|  | 478 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 479 | case 'w': { | 
|  | 480 | bool success; | 
| Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 481 | m_throw_bp = OptionArgParser::ToBoolean(option_arg, true, &success); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 482 | if (!success) | 
|  | 483 | error.SetErrorStringWithFormat( | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 484 | "Invalid boolean value for on-throw option: '%s'", | 
|  | 485 | option_arg.str().c_str()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 486 | } break; | 
|  | 487 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 488 | case 'X': | 
|  | 489 | m_source_regex_func_names.insert(option_arg); | 
|  | 490 | break; | 
|  | 491 |  | 
|  | 492 | default: | 
|  | 493 | error.SetErrorStringWithFormat("unrecognized option '%c'", | 
|  | 494 | short_option); | 
|  | 495 | break; | 
|  | 496 | } | 
|  | 497 |  | 
|  | 498 | return error; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 499 | } | 
|  | 500 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 501 | void OptionParsingStarting(ExecutionContext *execution_context) override { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 502 | m_filenames.Clear(); | 
|  | 503 | m_line_num = 0; | 
|  | 504 | m_column = 0; | 
|  | 505 | m_func_names.clear(); | 
|  | 506 | m_func_name_type_mask = eFunctionNameTypeNone; | 
|  | 507 | m_func_regexp.clear(); | 
|  | 508 | m_source_text_regexp.clear(); | 
|  | 509 | m_modules.Clear(); | 
|  | 510 | m_load_addr = LLDB_INVALID_ADDRESS; | 
|  | 511 | m_offset_addr = 0; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 512 | m_catch_bp = false; | 
|  | 513 | m_throw_bp = true; | 
|  | 514 | m_hardware = false; | 
|  | 515 | m_exception_language = eLanguageTypeUnknown; | 
|  | 516 | m_language = lldb::eLanguageTypeUnknown; | 
|  | 517 | m_skip_prologue = eLazyBoolCalculate; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 518 | m_breakpoint_names.clear(); | 
|  | 519 | m_all_files = false; | 
|  | 520 | m_exception_extra_args.Clear(); | 
|  | 521 | m_move_to_nearest_code = eLazyBoolCalculate; | 
|  | 522 | m_source_regex_func_names.clear(); | 
| Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 523 | m_python_class.clear(); | 
| Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 524 | m_extra_args_sp = std::make_shared<StructuredData::Dictionary>(); | 
| Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 525 | m_current_key.clear(); | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 526 | } | 
|  | 527 |  | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 528 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { | 
| Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 529 | return llvm::makeArrayRef(g_breakpoint_set_options); | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 530 | } | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 531 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 532 | // Instance variables to hold the values for command options. | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 533 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 534 | std::string m_condition; | 
|  | 535 | FileSpecList m_filenames; | 
|  | 536 | uint32_t m_line_num; | 
|  | 537 | uint32_t m_column; | 
|  | 538 | std::vector<std::string> m_func_names; | 
|  | 539 | std::vector<std::string> m_breakpoint_names; | 
| Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 540 | lldb::FunctionNameType m_func_name_type_mask; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 541 | std::string m_func_regexp; | 
|  | 542 | std::string m_source_text_regexp; | 
|  | 543 | FileSpecList m_modules; | 
|  | 544 | lldb::addr_t m_load_addr; | 
|  | 545 | lldb::addr_t m_offset_addr; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 546 | bool m_catch_bp; | 
|  | 547 | bool m_throw_bp; | 
|  | 548 | bool m_hardware; // Request to use hardware breakpoints | 
|  | 549 | lldb::LanguageType m_exception_language; | 
|  | 550 | lldb::LanguageType m_language; | 
|  | 551 | LazyBool m_skip_prologue; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 552 | bool m_all_files; | 
|  | 553 | Args m_exception_extra_args; | 
|  | 554 | LazyBool m_move_to_nearest_code; | 
|  | 555 | std::unordered_set<std::string> m_source_regex_func_names; | 
| Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 556 | std::string m_python_class; | 
|  | 557 | StructuredData::DictionarySP m_extra_args_sp; | 
|  | 558 | std::string m_current_key; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 559 | }; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 560 |  | 
|  | 561 | protected: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 562 | bool DoExecute(Args &command, CommandReturnObject &result) override { | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 563 | Target *target = GetSelectedOrDummyTarget(m_dummy_options.m_use_dummy); | 
| Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 564 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 565 | if (target == nullptr) { | 
|  | 566 | result.AppendError("Invalid target.  Must set target before setting " | 
|  | 567 | "breakpoints (see 'target create' command)."); | 
|  | 568 | result.SetStatus(eReturnStatusFailed); | 
|  | 569 | return false; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 570 | } | 
|  | 571 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 572 | // The following are the various types of breakpoints that could be set: | 
|  | 573 | //   1).  -f -l -p  [-s -g]   (setting breakpoint by source location) | 
|  | 574 | //   2).  -a  [-s -g]         (setting breakpoint by address) | 
|  | 575 | //   3).  -n  [-s -g]         (setting breakpoint by function name) | 
|  | 576 | //   4).  -r  [-s -g]         (setting breakpoint by function name regular | 
|  | 577 | //   expression) | 
|  | 578 | //   5).  -p -f               (setting a breakpoint by comparing a reg-exp | 
|  | 579 | //   to source text) | 
|  | 580 | //   6).  -E [-w -h]          (setting a breakpoint for exceptions for a | 
|  | 581 | //   given language.) | 
|  | 582 |  | 
|  | 583 | BreakpointSetType break_type = eSetTypeInvalid; | 
|  | 584 |  | 
| Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 585 | if (!m_options.m_python_class.empty()) | 
|  | 586 | break_type = eSetTypeScripted; | 
|  | 587 | else if (m_options.m_line_num != 0) | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 588 | break_type = eSetTypeFileAndLine; | 
|  | 589 | else if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) | 
|  | 590 | break_type = eSetTypeAddress; | 
|  | 591 | else if (!m_options.m_func_names.empty()) | 
|  | 592 | break_type = eSetTypeFunctionName; | 
|  | 593 | else if (!m_options.m_func_regexp.empty()) | 
|  | 594 | break_type = eSetTypeFunctionRegexp; | 
|  | 595 | else if (!m_options.m_source_text_regexp.empty()) | 
|  | 596 | break_type = eSetTypeSourceRegexp; | 
|  | 597 | else if (m_options.m_exception_language != eLanguageTypeUnknown) | 
|  | 598 | break_type = eSetTypeException; | 
|  | 599 |  | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 600 | BreakpointSP bp_sp = nullptr; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 601 | FileSpec module_spec; | 
|  | 602 | const bool internal = false; | 
|  | 603 |  | 
|  | 604 | // If the user didn't specify skip-prologue, having an offset should turn | 
|  | 605 | // that off. | 
|  | 606 | if (m_options.m_offset_addr != 0 && | 
|  | 607 | m_options.m_skip_prologue == eLazyBoolCalculate) | 
|  | 608 | m_options.m_skip_prologue = eLazyBoolNo; | 
|  | 609 |  | 
|  | 610 | switch (break_type) { | 
|  | 611 | case eSetTypeFileAndLine: // Breakpoint by source position | 
|  | 612 | { | 
|  | 613 | FileSpec file; | 
|  | 614 | const size_t num_files = m_options.m_filenames.GetSize(); | 
|  | 615 | if (num_files == 0) { | 
|  | 616 | if (!GetDefaultFile(target, file, result)) { | 
|  | 617 | result.AppendError("No file supplied and no default file available."); | 
|  | 618 | result.SetStatus(eReturnStatusFailed); | 
|  | 619 | return false; | 
|  | 620 | } | 
|  | 621 | } else if (num_files > 1) { | 
|  | 622 | result.AppendError("Only one file at a time is allowed for file and " | 
|  | 623 | "line breakpoints."); | 
|  | 624 | result.SetStatus(eReturnStatusFailed); | 
|  | 625 | return false; | 
|  | 626 | } else | 
|  | 627 | file = m_options.m_filenames.GetFileSpecAtIndex(0); | 
|  | 628 |  | 
|  | 629 | // Only check for inline functions if | 
|  | 630 | LazyBool check_inlines = eLazyBoolCalculate; | 
|  | 631 |  | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 632 | bp_sp = target->CreateBreakpoint(&(m_options.m_modules), | 
|  | 633 | file, | 
| Adrian Prantl | 431b158 | 2018-08-30 15:11:00 +0000 | [diff] [blame] | 634 | m_options.m_line_num, | 
|  | 635 | m_options.m_column, | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 636 | m_options.m_offset_addr, | 
|  | 637 | check_inlines, | 
|  | 638 | m_options.m_skip_prologue, | 
|  | 639 | internal, | 
|  | 640 | m_options.m_hardware, | 
|  | 641 | m_options.m_move_to_nearest_code); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 642 | } break; | 
|  | 643 |  | 
|  | 644 | case eSetTypeAddress: // Breakpoint by address | 
|  | 645 | { | 
|  | 646 | // If a shared library has been specified, make an lldb_private::Address | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 647 | // with the library, and use that.  That way the address breakpoint | 
|  | 648 | //  will track the load location of the library. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 649 | size_t num_modules_specified = m_options.m_modules.GetSize(); | 
|  | 650 | if (num_modules_specified == 1) { | 
|  | 651 | const FileSpec *file_spec = | 
|  | 652 | m_options.m_modules.GetFileSpecPointerAtIndex(0); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 653 | bp_sp = target->CreateAddressInModuleBreakpoint(m_options.m_load_addr, | 
|  | 654 | internal, file_spec, | 
|  | 655 | m_options.m_hardware); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 656 | } else if (num_modules_specified == 0) { | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 657 | bp_sp = target->CreateBreakpoint(m_options.m_load_addr, internal, | 
|  | 658 | m_options.m_hardware); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 659 | } else { | 
|  | 660 | result.AppendError("Only one shared library can be specified for " | 
|  | 661 | "address breakpoints."); | 
|  | 662 | result.SetStatus(eReturnStatusFailed); | 
|  | 663 | return false; | 
|  | 664 | } | 
|  | 665 | break; | 
|  | 666 | } | 
|  | 667 | case eSetTypeFunctionName: // Breakpoint by function name | 
|  | 668 | { | 
| Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 669 | FunctionNameType name_type_mask = m_options.m_func_name_type_mask; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 670 |  | 
|  | 671 | if (name_type_mask == 0) | 
|  | 672 | name_type_mask = eFunctionNameTypeAuto; | 
|  | 673 |  | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 674 | bp_sp = target->CreateBreakpoint(&(m_options.m_modules), | 
|  | 675 | &(m_options.m_filenames), | 
|  | 676 | m_options.m_func_names, | 
|  | 677 | name_type_mask, | 
|  | 678 | m_options.m_language, | 
|  | 679 | m_options.m_offset_addr, | 
|  | 680 | m_options.m_skip_prologue, | 
|  | 681 | internal, | 
|  | 682 | m_options.m_hardware); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 683 | } break; | 
|  | 684 |  | 
|  | 685 | case eSetTypeFunctionRegexp: // Breakpoint by regular expression function | 
|  | 686 | // name | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 687 | { | 
| Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 688 | RegularExpression regexp(m_options.m_func_regexp); | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 689 | if (!regexp.IsValid()) { | 
|  | 690 | char err_str[1024]; | 
|  | 691 | regexp.GetErrorAsCString(err_str, sizeof(err_str)); | 
|  | 692 | result.AppendErrorWithFormat( | 
|  | 693 | "Function name regular expression could not be compiled: \"%s\"", | 
|  | 694 | err_str); | 
|  | 695 | result.SetStatus(eReturnStatusFailed); | 
|  | 696 | return false; | 
|  | 697 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 698 |  | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 699 | bp_sp = target->CreateFuncRegexBreakpoint(&(m_options.m_modules), | 
|  | 700 | &(m_options.m_filenames), | 
|  | 701 | regexp, | 
|  | 702 | m_options.m_language, | 
|  | 703 | m_options.m_skip_prologue, | 
|  | 704 | internal, | 
|  | 705 | m_options.m_hardware); | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 706 | } | 
|  | 707 | break; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 708 | case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. | 
|  | 709 | { | 
|  | 710 | const size_t num_files = m_options.m_filenames.GetSize(); | 
|  | 711 |  | 
|  | 712 | if (num_files == 0 && !m_options.m_all_files) { | 
|  | 713 | FileSpec file; | 
|  | 714 | if (!GetDefaultFile(target, file, result)) { | 
|  | 715 | result.AppendError( | 
|  | 716 | "No files provided and could not find default file."); | 
|  | 717 | result.SetStatus(eReturnStatusFailed); | 
|  | 718 | return false; | 
|  | 719 | } else { | 
|  | 720 | m_options.m_filenames.Append(file); | 
|  | 721 | } | 
|  | 722 | } | 
|  | 723 |  | 
| Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 724 | RegularExpression regexp(m_options.m_source_text_regexp); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 725 | if (!regexp.IsValid()) { | 
|  | 726 | char err_str[1024]; | 
|  | 727 | regexp.GetErrorAsCString(err_str, sizeof(err_str)); | 
|  | 728 | result.AppendErrorWithFormat( | 
|  | 729 | "Source text regular expression could not be compiled: \"%s\"", | 
|  | 730 | err_str); | 
|  | 731 | result.SetStatus(eReturnStatusFailed); | 
|  | 732 | return false; | 
|  | 733 | } | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 734 | bp_sp = | 
|  | 735 | target->CreateSourceRegexBreakpoint(&(m_options.m_modules), | 
|  | 736 | &(m_options.m_filenames), | 
|  | 737 | m_options | 
|  | 738 | .m_source_regex_func_names, | 
|  | 739 | regexp, | 
|  | 740 | internal, | 
|  | 741 | m_options.m_hardware, | 
|  | 742 | m_options.m_move_to_nearest_code); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 743 | } break; | 
|  | 744 | case eSetTypeException: { | 
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 745 | Status precond_error; | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 746 | bp_sp = target->CreateExceptionBreakpoint(m_options.m_exception_language, | 
|  | 747 | m_options.m_catch_bp, | 
|  | 748 | m_options.m_throw_bp, | 
|  | 749 | internal, | 
|  | 750 | &m_options | 
|  | 751 | .m_exception_extra_args, | 
|  | 752 | &precond_error); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 753 | if (precond_error.Fail()) { | 
|  | 754 | result.AppendErrorWithFormat( | 
|  | 755 | "Error setting extra exception arguments: %s", | 
|  | 756 | precond_error.AsCString()); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 757 | target->RemoveBreakpointByID(bp_sp->GetID()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 758 | result.SetStatus(eReturnStatusFailed); | 
|  | 759 | return false; | 
|  | 760 | } | 
|  | 761 | } break; | 
| Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 762 | case eSetTypeScripted: { | 
|  | 763 |  | 
|  | 764 | Status error; | 
|  | 765 | bp_sp = target->CreateScriptedBreakpoint(m_options.m_python_class, | 
|  | 766 | &(m_options.m_modules), | 
|  | 767 | &(m_options.m_filenames), | 
|  | 768 | false, | 
|  | 769 | m_options.m_hardware, | 
|  | 770 | m_options.m_extra_args_sp, | 
|  | 771 | &error); | 
|  | 772 | if (error.Fail()) { | 
|  | 773 | result.AppendErrorWithFormat( | 
|  | 774 | "Error setting extra exception arguments: %s", | 
|  | 775 | error.AsCString()); | 
|  | 776 | target->RemoveBreakpointByID(bp_sp->GetID()); | 
|  | 777 | result.SetStatus(eReturnStatusFailed); | 
|  | 778 | return false; | 
|  | 779 | } | 
|  | 780 | } break; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 781 | default: | 
|  | 782 | break; | 
|  | 783 | } | 
|  | 784 |  | 
|  | 785 | // Now set the various options that were passed in: | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 786 | if (bp_sp) { | 
|  | 787 | bp_sp->GetOptions()->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 788 |  | 
|  | 789 | if (!m_options.m_breakpoint_names.empty()) { | 
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 790 | Status name_error; | 
| Jim Ingham | ff9a91e | 2016-09-21 01:21:19 +0000 | [diff] [blame] | 791 | for (auto name : m_options.m_breakpoint_names) { | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 792 | target->AddNameToBreakpoint(bp_sp, name.c_str(), name_error); | 
| Jim Ingham | ff9a91e | 2016-09-21 01:21:19 +0000 | [diff] [blame] | 793 | if (name_error.Fail()) { | 
|  | 794 | result.AppendErrorWithFormat("Invalid breakpoint name: %s", | 
|  | 795 | name.c_str()); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 796 | target->RemoveBreakpointByID(bp_sp->GetID()); | 
| Jim Ingham | ff9a91e | 2016-09-21 01:21:19 +0000 | [diff] [blame] | 797 | result.SetStatus(eReturnStatusFailed); | 
|  | 798 | return false; | 
|  | 799 | } | 
|  | 800 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 801 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 802 | } | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 803 |  | 
|  | 804 | if (bp_sp) { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 805 | Stream &output_stream = result.GetOutputStream(); | 
|  | 806 | const bool show_locations = false; | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 807 | bp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 808 | show_locations); | 
| Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 809 | if (target == GetDebugger().GetDummyTarget()) | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 810 | output_stream.Printf("Breakpoint set in dummy target, will get copied " | 
|  | 811 | "into future targets.\n"); | 
|  | 812 | else { | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 813 | // Don't print out this warning for exception breakpoints.  They can | 
|  | 814 | // get set before the target is set, but we won't know how to actually | 
|  | 815 | // set the breakpoint till we run. | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 816 | if (bp_sp->GetNumLocations() == 0 && break_type != eSetTypeException) { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 817 | output_stream.Printf("WARNING:  Unable to resolve breakpoint to any " | 
|  | 818 | "actual locations.\n"); | 
|  | 819 | } | 
|  | 820 | } | 
|  | 821 | result.SetStatus(eReturnStatusSuccessFinishResult); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 822 | } else if (!bp_sp) { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 823 | result.AppendError("Breakpoint creation failed: No breakpoint created."); | 
|  | 824 | result.SetStatus(eReturnStatusFailed); | 
|  | 825 | } | 
|  | 826 |  | 
|  | 827 | return result.Succeeded(); | 
|  | 828 | } | 
|  | 829 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 830 | private: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 831 | bool GetDefaultFile(Target *target, FileSpec &file, | 
|  | 832 | CommandReturnObject &result) { | 
|  | 833 | uint32_t default_line; | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 834 | // First use the Source Manager's default file. Then use the current stack | 
|  | 835 | // frame's file. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 836 | if (!target->GetSourceManager().GetDefaultFileAndLine(file, default_line)) { | 
|  | 837 | StackFrame *cur_frame = m_exe_ctx.GetFramePtr(); | 
|  | 838 | if (cur_frame == nullptr) { | 
|  | 839 | result.AppendError( | 
|  | 840 | "No selected frame to use to find the default file."); | 
|  | 841 | result.SetStatus(eReturnStatusFailed); | 
|  | 842 | return false; | 
|  | 843 | } else if (!cur_frame->HasDebugInformation()) { | 
|  | 844 | result.AppendError("Cannot use the selected frame to find the default " | 
|  | 845 | "file, it has no debug info."); | 
|  | 846 | result.SetStatus(eReturnStatusFailed); | 
|  | 847 | return false; | 
|  | 848 | } else { | 
|  | 849 | const SymbolContext &sc = | 
|  | 850 | cur_frame->GetSymbolContext(eSymbolContextLineEntry); | 
|  | 851 | if (sc.line_entry.file) { | 
|  | 852 | file = sc.line_entry.file; | 
|  | 853 | } else { | 
|  | 854 | result.AppendError("Can't find the file for the selected frame to " | 
|  | 855 | "use as the default file."); | 
|  | 856 | result.SetStatus(eReturnStatusFailed); | 
|  | 857 | return false; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 858 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 859 | } | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 860 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 861 | return true; | 
|  | 862 | } | 
|  | 863 |  | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 864 | BreakpointOptionGroup m_bp_opts; | 
|  | 865 | BreakpointDummyOptionGroup m_dummy_options; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 866 | CommandOptions m_options; | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 867 | OptionGroupOptions m_all_options; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 868 | }; | 
| Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 869 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 870 | // CommandObjectBreakpointModify | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 871 | #pragma mark Modify | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 872 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 873 | class CommandObjectBreakpointModify : public CommandObjectParsed { | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 874 | public: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 875 | CommandObjectBreakpointModify(CommandInterpreter &interpreter) | 
|  | 876 | : CommandObjectParsed(interpreter, "breakpoint modify", | 
|  | 877 | "Modify the options on a breakpoint or set of " | 
|  | 878 | "breakpoints in the executable.  " | 
|  | 879 | "If no breakpoint is specified, acts on the last " | 
|  | 880 | "created breakpoint.  " | 
|  | 881 | "With the exception of -e, -d and -i, passing an " | 
|  | 882 | "empty argument clears the modification.", | 
| Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 883 | nullptr), | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 884 | m_options() { | 
|  | 885 | CommandArgumentEntry arg; | 
|  | 886 | CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, | 
|  | 887 | eArgTypeBreakpointIDRange); | 
|  | 888 | // Add the entry for the first argument for this command to the object's | 
|  | 889 | // arguments vector. | 
|  | 890 | m_arguments.push_back(arg); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 891 |  | 
|  | 892 | m_options.Append(&m_bp_opts, | 
|  | 893 | LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3, | 
|  | 894 | LLDB_OPT_SET_ALL); | 
|  | 895 | m_options.Append(&m_dummy_opts, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); | 
|  | 896 | m_options.Finalize(); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 897 | } | 
|  | 898 |  | 
|  | 899 | ~CommandObjectBreakpointModify() override = default; | 
|  | 900 |  | 
|  | 901 | Options *GetOptions() override { return &m_options; } | 
|  | 902 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 903 | protected: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 904 | bool DoExecute(Args &command, CommandReturnObject &result) override { | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 905 | Target *target = GetSelectedOrDummyTarget(m_dummy_opts.m_use_dummy); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 906 | if (target == nullptr) { | 
|  | 907 | result.AppendError("Invalid target.  No existing target or breakpoints."); | 
|  | 908 | result.SetStatus(eReturnStatusFailed); | 
|  | 909 | return false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 910 | } | 
|  | 911 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 912 | std::unique_lock<std::recursive_mutex> lock; | 
|  | 913 | target->GetBreakpointList().GetListMutex(lock); | 
|  | 914 |  | 
|  | 915 | BreakpointIDList valid_bp_ids; | 
|  | 916 |  | 
|  | 917 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 918 | command, target, result, &valid_bp_ids, | 
|  | 919 | BreakpointName::Permissions::PermissionKinds::disablePerm); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 920 |  | 
|  | 921 | if (result.Succeeded()) { | 
|  | 922 | const size_t count = valid_bp_ids.GetSize(); | 
|  | 923 | for (size_t i = 0; i < count; ++i) { | 
|  | 924 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); | 
|  | 925 |  | 
|  | 926 | if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { | 
|  | 927 | Breakpoint *bp = | 
|  | 928 | target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); | 
|  | 929 | if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { | 
|  | 930 | BreakpointLocation *location = | 
|  | 931 | bp->FindLocationByID(cur_bp_id.GetLocationID()).get(); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 932 | if (location) | 
|  | 933 | location->GetLocationOptions() | 
|  | 934 | ->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 935 | } else { | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 936 | bp->GetOptions() | 
|  | 937 | ->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 938 | } | 
|  | 939 | } | 
|  | 940 | } | 
|  | 941 | } | 
|  | 942 |  | 
|  | 943 | return result.Succeeded(); | 
|  | 944 | } | 
|  | 945 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 946 | private: | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 947 | BreakpointOptionGroup m_bp_opts; | 
|  | 948 | BreakpointDummyOptionGroup m_dummy_opts; | 
|  | 949 | OptionGroupOptions m_options; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 950 | }; | 
| Johnny Chen | 7d49c9c | 2012-05-25 21:10:46 +0000 | [diff] [blame] | 951 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 952 | // CommandObjectBreakpointEnable | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 953 | #pragma mark Enable | 
|  | 954 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 955 | class CommandObjectBreakpointEnable : public CommandObjectParsed { | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 956 | public: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 957 | CommandObjectBreakpointEnable(CommandInterpreter &interpreter) | 
|  | 958 | : CommandObjectParsed(interpreter, "enable", | 
|  | 959 | "Enable the specified disabled breakpoint(s). If " | 
|  | 960 | "no breakpoints are specified, enable all of them.", | 
|  | 961 | nullptr) { | 
|  | 962 | CommandArgumentEntry arg; | 
|  | 963 | CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, | 
|  | 964 | eArgTypeBreakpointIDRange); | 
|  | 965 | // Add the entry for the first argument for this command to the object's | 
|  | 966 | // arguments vector. | 
|  | 967 | m_arguments.push_back(arg); | 
|  | 968 | } | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 969 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 970 | ~CommandObjectBreakpointEnable() override = default; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 971 |  | 
|  | 972 | protected: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 973 | bool DoExecute(Args &command, CommandReturnObject &result) override { | 
|  | 974 | Target *target = GetSelectedOrDummyTarget(); | 
|  | 975 | if (target == nullptr) { | 
|  | 976 | result.AppendError("Invalid target.  No existing target or breakpoints."); | 
|  | 977 | result.SetStatus(eReturnStatusFailed); | 
|  | 978 | return false; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 979 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 980 |  | 
|  | 981 | std::unique_lock<std::recursive_mutex> lock; | 
|  | 982 | target->GetBreakpointList().GetListMutex(lock); | 
|  | 983 |  | 
|  | 984 | const BreakpointList &breakpoints = target->GetBreakpointList(); | 
|  | 985 |  | 
|  | 986 | size_t num_breakpoints = breakpoints.GetSize(); | 
|  | 987 |  | 
|  | 988 | if (num_breakpoints == 0) { | 
|  | 989 | result.AppendError("No breakpoints exist to be enabled."); | 
|  | 990 | result.SetStatus(eReturnStatusFailed); | 
|  | 991 | return false; | 
|  | 992 | } | 
|  | 993 |  | 
| Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 994 | if (command.empty()) { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 995 | // No breakpoint selected; enable all currently set breakpoints. | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 996 | target->EnableAllowedBreakpoints(); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 997 | result.AppendMessageWithFormat("All breakpoints enabled. (%" PRIu64 | 
|  | 998 | " breakpoints)\n", | 
|  | 999 | (uint64_t)num_breakpoints); | 
|  | 1000 | result.SetStatus(eReturnStatusSuccessFinishNoResult); | 
|  | 1001 | } else { | 
|  | 1002 | // Particular breakpoint selected; enable that breakpoint. | 
|  | 1003 | BreakpointIDList valid_bp_ids; | 
|  | 1004 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1005 | command, target, result, &valid_bp_ids, | 
|  | 1006 | BreakpointName::Permissions::PermissionKinds::disablePerm); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1007 |  | 
|  | 1008 | if (result.Succeeded()) { | 
|  | 1009 | int enable_count = 0; | 
|  | 1010 | int loc_count = 0; | 
|  | 1011 | const size_t count = valid_bp_ids.GetSize(); | 
|  | 1012 | for (size_t i = 0; i < count; ++i) { | 
|  | 1013 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); | 
|  | 1014 |  | 
|  | 1015 | if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { | 
|  | 1016 | Breakpoint *breakpoint = | 
|  | 1017 | target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); | 
|  | 1018 | if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { | 
|  | 1019 | BreakpointLocation *location = | 
|  | 1020 | breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); | 
|  | 1021 | if (location) { | 
|  | 1022 | location->SetEnabled(true); | 
|  | 1023 | ++loc_count; | 
|  | 1024 | } | 
|  | 1025 | } else { | 
|  | 1026 | breakpoint->SetEnabled(true); | 
|  | 1027 | ++enable_count; | 
|  | 1028 | } | 
|  | 1029 | } | 
|  | 1030 | } | 
|  | 1031 | result.AppendMessageWithFormat("%d breakpoints enabled.\n", | 
|  | 1032 | enable_count + loc_count); | 
|  | 1033 | result.SetStatus(eReturnStatusSuccessFinishNoResult); | 
|  | 1034 | } | 
|  | 1035 | } | 
|  | 1036 |  | 
|  | 1037 | return result.Succeeded(); | 
|  | 1038 | } | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1039 | }; | 
|  | 1040 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1041 | // CommandObjectBreakpointDisable | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1042 | #pragma mark Disable | 
|  | 1043 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1044 | class CommandObjectBreakpointDisable : public CommandObjectParsed { | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1045 | public: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1046 | CommandObjectBreakpointDisable(CommandInterpreter &interpreter) | 
|  | 1047 | : CommandObjectParsed( | 
|  | 1048 | interpreter, "breakpoint disable", | 
|  | 1049 | "Disable the specified breakpoint(s) without deleting " | 
|  | 1050 | "them.  If none are specified, disable all " | 
|  | 1051 | "breakpoints.", | 
|  | 1052 | nullptr) { | 
|  | 1053 | SetHelpLong( | 
|  | 1054 | "Disable the specified breakpoint(s) without deleting them.  \ | 
| Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 1055 | If none are specified, disable all breakpoints." | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1056 | R"( | 
| Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 1057 |  | 
| Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 1058 | )" | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1059 | "Note: disabling a breakpoint will cause none of its locations to be hit \ | 
| Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 1060 | regardless of whether individual locations are enabled or disabled.  After the sequence:" | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1061 | R"( | 
| Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 1062 |  | 
|  | 1063 | (lldb) break disable 1 | 
|  | 1064 | (lldb) break enable 1.1 | 
|  | 1065 |  | 
|  | 1066 | execution will NOT stop at location 1.1.  To achieve that, type: | 
|  | 1067 |  | 
|  | 1068 | (lldb) break disable 1.* | 
|  | 1069 | (lldb) break enable 1.1 | 
|  | 1070 |  | 
| Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 1071 | )" | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1072 | "The first command disables all locations for breakpoint 1, \ | 
| Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 1073 | the second re-enables the first location."); | 
|  | 1074 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1075 | CommandArgumentEntry arg; | 
|  | 1076 | CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, | 
|  | 1077 | eArgTypeBreakpointIDRange); | 
|  | 1078 | // Add the entry for the first argument for this command to the object's | 
|  | 1079 | // arguments vector. | 
|  | 1080 | m_arguments.push_back(arg); | 
|  | 1081 | } | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1082 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1083 | ~CommandObjectBreakpointDisable() override = default; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1084 |  | 
|  | 1085 | protected: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1086 | bool DoExecute(Args &command, CommandReturnObject &result) override { | 
|  | 1087 | Target *target = GetSelectedOrDummyTarget(); | 
|  | 1088 | if (target == nullptr) { | 
|  | 1089 | result.AppendError("Invalid target.  No existing target or breakpoints."); | 
|  | 1090 | result.SetStatus(eReturnStatusFailed); | 
|  | 1091 | return false; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1092 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1093 |  | 
|  | 1094 | std::unique_lock<std::recursive_mutex> lock; | 
|  | 1095 | target->GetBreakpointList().GetListMutex(lock); | 
|  | 1096 |  | 
|  | 1097 | const BreakpointList &breakpoints = target->GetBreakpointList(); | 
|  | 1098 | size_t num_breakpoints = breakpoints.GetSize(); | 
|  | 1099 |  | 
|  | 1100 | if (num_breakpoints == 0) { | 
|  | 1101 | result.AppendError("No breakpoints exist to be disabled."); | 
|  | 1102 | result.SetStatus(eReturnStatusFailed); | 
|  | 1103 | return false; | 
|  | 1104 | } | 
|  | 1105 |  | 
| Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1106 | if (command.empty()) { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1107 | // No breakpoint selected; disable all currently set breakpoints. | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1108 | target->DisableAllowedBreakpoints(); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1109 | result.AppendMessageWithFormat("All breakpoints disabled. (%" PRIu64 | 
|  | 1110 | " breakpoints)\n", | 
|  | 1111 | (uint64_t)num_breakpoints); | 
|  | 1112 | result.SetStatus(eReturnStatusSuccessFinishNoResult); | 
|  | 1113 | } else { | 
|  | 1114 | // Particular breakpoint selected; disable that breakpoint. | 
|  | 1115 | BreakpointIDList valid_bp_ids; | 
|  | 1116 |  | 
|  | 1117 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1118 | command, target, result, &valid_bp_ids, | 
|  | 1119 | BreakpointName::Permissions::PermissionKinds::disablePerm); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1120 |  | 
|  | 1121 | if (result.Succeeded()) { | 
|  | 1122 | int disable_count = 0; | 
|  | 1123 | int loc_count = 0; | 
|  | 1124 | const size_t count = valid_bp_ids.GetSize(); | 
|  | 1125 | for (size_t i = 0; i < count; ++i) { | 
|  | 1126 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); | 
|  | 1127 |  | 
|  | 1128 | if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { | 
|  | 1129 | Breakpoint *breakpoint = | 
|  | 1130 | target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); | 
|  | 1131 | if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { | 
|  | 1132 | BreakpointLocation *location = | 
|  | 1133 | breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); | 
|  | 1134 | if (location) { | 
|  | 1135 | location->SetEnabled(false); | 
|  | 1136 | ++loc_count; | 
|  | 1137 | } | 
|  | 1138 | } else { | 
|  | 1139 | breakpoint->SetEnabled(false); | 
|  | 1140 | ++disable_count; | 
|  | 1141 | } | 
|  | 1142 | } | 
|  | 1143 | } | 
|  | 1144 | result.AppendMessageWithFormat("%d breakpoints disabled.\n", | 
|  | 1145 | disable_count + loc_count); | 
|  | 1146 | result.SetStatus(eReturnStatusSuccessFinishNoResult); | 
|  | 1147 | } | 
|  | 1148 | } | 
|  | 1149 |  | 
|  | 1150 | return result.Succeeded(); | 
|  | 1151 | } | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1152 | }; | 
|  | 1153 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1154 | // CommandObjectBreakpointList | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1155 |  | 
|  | 1156 | #pragma mark List::CommandOptions | 
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1157 | static constexpr OptionDefinition g_breakpoint_list_options[] = { | 
| Raphael Isemann | 6f4fb4e | 2019-07-12 15:30:55 +0000 | [diff] [blame] | 1158 | #define LLDB_OPTIONS_breakpoint_list | 
| Raphael Isemann | c5a2d74 | 2019-07-16 09:27:02 +0000 | [diff] [blame] | 1159 | #include "CommandOptions.inc" | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1160 | }; | 
|  | 1161 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1162 | #pragma mark List | 
|  | 1163 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1164 | class CommandObjectBreakpointList : public CommandObjectParsed { | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1165 | public: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1166 | CommandObjectBreakpointList(CommandInterpreter &interpreter) | 
|  | 1167 | : CommandObjectParsed( | 
|  | 1168 | interpreter, "breakpoint list", | 
|  | 1169 | "List some or all breakpoints at configurable levels of detail.", | 
|  | 1170 | nullptr), | 
|  | 1171 | m_options() { | 
|  | 1172 | CommandArgumentEntry arg; | 
|  | 1173 | CommandArgumentData bp_id_arg; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1174 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1175 | // Define the first (and only) variant of this arg. | 
|  | 1176 | bp_id_arg.arg_type = eArgTypeBreakpointID; | 
|  | 1177 | bp_id_arg.arg_repetition = eArgRepeatOptional; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1178 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1179 | // There is only one variant this argument could be; put it into the | 
|  | 1180 | // argument entry. | 
|  | 1181 | arg.push_back(bp_id_arg); | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1182 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1183 | // Push the data for the first argument into the m_arguments vector. | 
|  | 1184 | m_arguments.push_back(arg); | 
|  | 1185 | } | 
|  | 1186 |  | 
|  | 1187 | ~CommandObjectBreakpointList() override = default; | 
|  | 1188 |  | 
|  | 1189 | Options *GetOptions() override { return &m_options; } | 
|  | 1190 |  | 
|  | 1191 | class CommandOptions : public Options { | 
|  | 1192 | public: | 
|  | 1193 | CommandOptions() | 
|  | 1194 | : Options(), m_level(lldb::eDescriptionLevelBrief), m_use_dummy(false) { | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1195 | } | 
|  | 1196 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1197 | ~CommandOptions() override = default; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1198 |  | 
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1199 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, | 
|  | 1200 | ExecutionContext *execution_context) override { | 
|  | 1201 | Status error; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1202 | const int short_option = m_getopt_table[option_idx].val; | 
|  | 1203 |  | 
|  | 1204 | switch (short_option) { | 
|  | 1205 | case 'b': | 
|  | 1206 | m_level = lldb::eDescriptionLevelBrief; | 
|  | 1207 | break; | 
|  | 1208 | case 'D': | 
|  | 1209 | m_use_dummy = true; | 
|  | 1210 | break; | 
|  | 1211 | case 'f': | 
|  | 1212 | m_level = lldb::eDescriptionLevelFull; | 
|  | 1213 | break; | 
|  | 1214 | case 'v': | 
|  | 1215 | m_level = lldb::eDescriptionLevelVerbose; | 
|  | 1216 | break; | 
|  | 1217 | case 'i': | 
|  | 1218 | m_internal = true; | 
|  | 1219 | break; | 
|  | 1220 | default: | 
|  | 1221 | error.SetErrorStringWithFormat("unrecognized option '%c'", | 
|  | 1222 | short_option); | 
|  | 1223 | break; | 
|  | 1224 | } | 
|  | 1225 |  | 
|  | 1226 | return error; | 
| Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1227 | } | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1228 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1229 | void OptionParsingStarting(ExecutionContext *execution_context) override { | 
|  | 1230 | m_level = lldb::eDescriptionLevelFull; | 
|  | 1231 | m_internal = false; | 
|  | 1232 | m_use_dummy = false; | 
|  | 1233 | } | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1234 |  | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1235 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { | 
| Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 1236 | return llvm::makeArrayRef(g_breakpoint_list_options); | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1237 | } | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1238 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1239 | // Instance variables to hold the values for command options. | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1240 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1241 | lldb::DescriptionLevel m_level; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1242 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1243 | bool m_internal; | 
|  | 1244 | bool m_use_dummy; | 
|  | 1245 | }; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1246 |  | 
|  | 1247 | protected: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1248 | bool DoExecute(Args &command, CommandReturnObject &result) override { | 
|  | 1249 | Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); | 
| Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1250 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1251 | if (target == nullptr) { | 
|  | 1252 | result.AppendError("Invalid target. No current target or breakpoints."); | 
|  | 1253 | result.SetStatus(eReturnStatusSuccessFinishNoResult); | 
|  | 1254 | return true; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1255 | } | 
|  | 1256 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1257 | const BreakpointList &breakpoints = | 
|  | 1258 | target->GetBreakpointList(m_options.m_internal); | 
|  | 1259 | std::unique_lock<std::recursive_mutex> lock; | 
|  | 1260 | target->GetBreakpointList(m_options.m_internal).GetListMutex(lock); | 
|  | 1261 |  | 
|  | 1262 | size_t num_breakpoints = breakpoints.GetSize(); | 
|  | 1263 |  | 
|  | 1264 | if (num_breakpoints == 0) { | 
|  | 1265 | result.AppendMessage("No breakpoints currently set."); | 
|  | 1266 | result.SetStatus(eReturnStatusSuccessFinishNoResult); | 
|  | 1267 | return true; | 
|  | 1268 | } | 
|  | 1269 |  | 
|  | 1270 | Stream &output_stream = result.GetOutputStream(); | 
|  | 1271 |  | 
| Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1272 | if (command.empty()) { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1273 | // No breakpoint selected; show info about all currently set breakpoints. | 
|  | 1274 | result.AppendMessage("Current breakpoints:"); | 
|  | 1275 | for (size_t i = 0; i < num_breakpoints; ++i) { | 
|  | 1276 | Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex(i).get(); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1277 | if (breakpoint->AllowList()) | 
|  | 1278 | AddBreakpointDescription(&output_stream, breakpoint, | 
|  | 1279 | m_options.m_level); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1280 | } | 
|  | 1281 | result.SetStatus(eReturnStatusSuccessFinishNoResult); | 
|  | 1282 | } else { | 
|  | 1283 | // Particular breakpoints selected; show info about that breakpoint. | 
|  | 1284 | BreakpointIDList valid_bp_ids; | 
|  | 1285 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1286 | command, target, result, &valid_bp_ids, | 
|  | 1287 | BreakpointName::Permissions::PermissionKinds::listPerm); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1288 |  | 
|  | 1289 | if (result.Succeeded()) { | 
|  | 1290 | for (size_t i = 0; i < valid_bp_ids.GetSize(); ++i) { | 
|  | 1291 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); | 
|  | 1292 | Breakpoint *breakpoint = | 
|  | 1293 | target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); | 
|  | 1294 | AddBreakpointDescription(&output_stream, breakpoint, | 
|  | 1295 | m_options.m_level); | 
|  | 1296 | } | 
|  | 1297 | result.SetStatus(eReturnStatusSuccessFinishNoResult); | 
|  | 1298 | } else { | 
|  | 1299 | result.AppendError("Invalid breakpoint ID."); | 
|  | 1300 | result.SetStatus(eReturnStatusFailed); | 
|  | 1301 | } | 
|  | 1302 | } | 
|  | 1303 |  | 
|  | 1304 | return result.Succeeded(); | 
|  | 1305 | } | 
|  | 1306 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1307 | private: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1308 | CommandOptions m_options; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1309 | }; | 
|  | 1310 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1311 | // CommandObjectBreakpointClear | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1312 | #pragma mark Clear::CommandOptions | 
|  | 1313 |  | 
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1314 | static constexpr OptionDefinition g_breakpoint_clear_options[] = { | 
| Raphael Isemann | f94668e | 2019-07-22 10:02:09 +0000 | [diff] [blame^] | 1315 | #define LLDB_OPTIONS_breakpoint_clear | 
|  | 1316 | #include "CommandOptions.inc" | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1317 | }; | 
|  | 1318 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1319 | #pragma mark Clear | 
|  | 1320 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1321 | class CommandObjectBreakpointClear : public CommandObjectParsed { | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1322 | public: | 
| Fangrui Song | efe8e7e | 2019-05-14 08:55:50 +0000 | [diff] [blame] | 1323 | enum BreakpointClearType { eClearTypeInvalid, eClearTypeFileAndLine }; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1324 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1325 | CommandObjectBreakpointClear(CommandInterpreter &interpreter) | 
|  | 1326 | : CommandObjectParsed(interpreter, "breakpoint clear", | 
|  | 1327 | "Delete or disable breakpoints matching the " | 
|  | 1328 | "specified source file and line.", | 
|  | 1329 | "breakpoint clear <cmd-options>"), | 
|  | 1330 | m_options() {} | 
|  | 1331 |  | 
|  | 1332 | ~CommandObjectBreakpointClear() override = default; | 
|  | 1333 |  | 
|  | 1334 | Options *GetOptions() override { return &m_options; } | 
|  | 1335 |  | 
|  | 1336 | class CommandOptions : public Options { | 
|  | 1337 | public: | 
|  | 1338 | CommandOptions() : Options(), m_filename(), m_line_num(0) {} | 
|  | 1339 |  | 
|  | 1340 | ~CommandOptions() override = default; | 
|  | 1341 |  | 
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1342 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, | 
|  | 1343 | ExecutionContext *execution_context) override { | 
|  | 1344 | Status error; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1345 | const int short_option = m_getopt_table[option_idx].val; | 
|  | 1346 |  | 
|  | 1347 | switch (short_option) { | 
|  | 1348 | case 'f': | 
|  | 1349 | m_filename.assign(option_arg); | 
|  | 1350 | break; | 
|  | 1351 |  | 
|  | 1352 | case 'l': | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1353 | option_arg.getAsInteger(0, m_line_num); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1354 | break; | 
|  | 1355 |  | 
|  | 1356 | default: | 
|  | 1357 | error.SetErrorStringWithFormat("unrecognized option '%c'", | 
|  | 1358 | short_option); | 
|  | 1359 | break; | 
|  | 1360 | } | 
|  | 1361 |  | 
|  | 1362 | return error; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1363 | } | 
|  | 1364 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1365 | void OptionParsingStarting(ExecutionContext *execution_context) override { | 
|  | 1366 | m_filename.clear(); | 
|  | 1367 | m_line_num = 0; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1368 | } | 
|  | 1369 |  | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1370 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { | 
| Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 1371 | return llvm::makeArrayRef(g_breakpoint_clear_options); | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1372 | } | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1373 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1374 | // Instance variables to hold the values for command options. | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1375 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1376 | std::string m_filename; | 
|  | 1377 | uint32_t m_line_num; | 
|  | 1378 | }; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1379 |  | 
|  | 1380 | protected: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1381 | bool DoExecute(Args &command, CommandReturnObject &result) override { | 
|  | 1382 | Target *target = GetSelectedOrDummyTarget(); | 
|  | 1383 | if (target == nullptr) { | 
|  | 1384 | result.AppendError("Invalid target. No existing target or breakpoints."); | 
|  | 1385 | result.SetStatus(eReturnStatusFailed); | 
|  | 1386 | return false; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1387 | } | 
|  | 1388 |  | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1389 | // The following are the various types of breakpoints that could be | 
|  | 1390 | // cleared: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1391 | //   1). -f -l (clearing breakpoint by source location) | 
|  | 1392 |  | 
|  | 1393 | BreakpointClearType break_type = eClearTypeInvalid; | 
|  | 1394 |  | 
|  | 1395 | if (m_options.m_line_num != 0) | 
|  | 1396 | break_type = eClearTypeFileAndLine; | 
|  | 1397 |  | 
|  | 1398 | std::unique_lock<std::recursive_mutex> lock; | 
|  | 1399 | target->GetBreakpointList().GetListMutex(lock); | 
|  | 1400 |  | 
|  | 1401 | BreakpointList &breakpoints = target->GetBreakpointList(); | 
|  | 1402 | size_t num_breakpoints = breakpoints.GetSize(); | 
|  | 1403 |  | 
|  | 1404 | // Early return if there's no breakpoint at all. | 
|  | 1405 | if (num_breakpoints == 0) { | 
|  | 1406 | result.AppendError("Breakpoint clear: No breakpoint cleared."); | 
|  | 1407 | result.SetStatus(eReturnStatusFailed); | 
|  | 1408 | return result.Succeeded(); | 
|  | 1409 | } | 
|  | 1410 |  | 
|  | 1411 | // Find matching breakpoints and delete them. | 
|  | 1412 |  | 
|  | 1413 | // First create a copy of all the IDs. | 
|  | 1414 | std::vector<break_id_t> BreakIDs; | 
|  | 1415 | for (size_t i = 0; i < num_breakpoints; ++i) | 
|  | 1416 | BreakIDs.push_back(breakpoints.GetBreakpointAtIndex(i)->GetID()); | 
|  | 1417 |  | 
|  | 1418 | int num_cleared = 0; | 
|  | 1419 | StreamString ss; | 
|  | 1420 | switch (break_type) { | 
|  | 1421 | case eClearTypeFileAndLine: // Breakpoint by source position | 
|  | 1422 | { | 
|  | 1423 | const ConstString filename(m_options.m_filename.c_str()); | 
|  | 1424 | BreakpointLocationCollection loc_coll; | 
|  | 1425 |  | 
|  | 1426 | for (size_t i = 0; i < num_breakpoints; ++i) { | 
|  | 1427 | Breakpoint *bp = breakpoints.FindBreakpointByID(BreakIDs[i]).get(); | 
|  | 1428 |  | 
|  | 1429 | if (bp->GetMatchingFileLine(filename, m_options.m_line_num, loc_coll)) { | 
|  | 1430 | // If the collection size is 0, it's a full match and we can just | 
|  | 1431 | // remove the breakpoint. | 
|  | 1432 | if (loc_coll.GetSize() == 0) { | 
|  | 1433 | bp->GetDescription(&ss, lldb::eDescriptionLevelBrief); | 
|  | 1434 | ss.EOL(); | 
|  | 1435 | target->RemoveBreakpointByID(bp->GetID()); | 
|  | 1436 | ++num_cleared; | 
|  | 1437 | } | 
|  | 1438 | } | 
|  | 1439 | } | 
|  | 1440 | } break; | 
|  | 1441 |  | 
|  | 1442 | default: | 
|  | 1443 | break; | 
|  | 1444 | } | 
|  | 1445 |  | 
|  | 1446 | if (num_cleared > 0) { | 
|  | 1447 | Stream &output_stream = result.GetOutputStream(); | 
|  | 1448 | output_stream.Printf("%d breakpoints cleared:\n", num_cleared); | 
| Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1449 | output_stream << ss.GetString(); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1450 | output_stream.EOL(); | 
|  | 1451 | result.SetStatus(eReturnStatusSuccessFinishNoResult); | 
|  | 1452 | } else { | 
|  | 1453 | result.AppendError("Breakpoint clear: No breakpoint cleared."); | 
|  | 1454 | result.SetStatus(eReturnStatusFailed); | 
|  | 1455 | } | 
|  | 1456 |  | 
|  | 1457 | return result.Succeeded(); | 
|  | 1458 | } | 
|  | 1459 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1460 | private: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1461 | CommandOptions m_options; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1462 | }; | 
|  | 1463 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1464 | // CommandObjectBreakpointDelete | 
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1465 | static constexpr OptionDefinition g_breakpoint_delete_options[] = { | 
| Raphael Isemann | f94668e | 2019-07-22 10:02:09 +0000 | [diff] [blame^] | 1466 | #define LLDB_OPTIONS_breakpoint_delete | 
|  | 1467 | #include "CommandOptions.inc" | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1468 | }; | 
|  | 1469 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1470 | #pragma mark Delete | 
|  | 1471 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1472 | class CommandObjectBreakpointDelete : public CommandObjectParsed { | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1473 | public: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1474 | CommandObjectBreakpointDelete(CommandInterpreter &interpreter) | 
|  | 1475 | : CommandObjectParsed(interpreter, "breakpoint delete", | 
|  | 1476 | "Delete the specified breakpoint(s).  If no " | 
|  | 1477 | "breakpoints are specified, delete them all.", | 
| Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1478 | nullptr), | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1479 | m_options() { | 
|  | 1480 | CommandArgumentEntry arg; | 
|  | 1481 | CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, | 
|  | 1482 | eArgTypeBreakpointIDRange); | 
|  | 1483 | // Add the entry for the first argument for this command to the object's | 
|  | 1484 | // arguments vector. | 
|  | 1485 | m_arguments.push_back(arg); | 
|  | 1486 | } | 
|  | 1487 |  | 
|  | 1488 | ~CommandObjectBreakpointDelete() override = default; | 
|  | 1489 |  | 
|  | 1490 | Options *GetOptions() override { return &m_options; } | 
|  | 1491 |  | 
|  | 1492 | class CommandOptions : public Options { | 
|  | 1493 | public: | 
|  | 1494 | CommandOptions() : Options(), m_use_dummy(false), m_force(false) {} | 
|  | 1495 |  | 
|  | 1496 | ~CommandOptions() override = default; | 
|  | 1497 |  | 
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1498 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, | 
|  | 1499 | ExecutionContext *execution_context) override { | 
|  | 1500 | Status error; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1501 | const int short_option = m_getopt_table[option_idx].val; | 
|  | 1502 |  | 
|  | 1503 | switch (short_option) { | 
|  | 1504 | case 'f': | 
|  | 1505 | m_force = true; | 
|  | 1506 | break; | 
|  | 1507 |  | 
|  | 1508 | case 'D': | 
|  | 1509 | m_use_dummy = true; | 
|  | 1510 | break; | 
|  | 1511 |  | 
|  | 1512 | default: | 
|  | 1513 | error.SetErrorStringWithFormat("unrecognized option '%c'", | 
|  | 1514 | short_option); | 
|  | 1515 | break; | 
|  | 1516 | } | 
|  | 1517 |  | 
|  | 1518 | return error; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1519 | } | 
|  | 1520 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1521 | void OptionParsingStarting(ExecutionContext *execution_context) override { | 
|  | 1522 | m_use_dummy = false; | 
|  | 1523 | m_force = false; | 
| Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1524 | } | 
|  | 1525 |  | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1526 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { | 
| Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 1527 | return llvm::makeArrayRef(g_breakpoint_delete_options); | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1528 | } | 
| Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1529 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1530 | // Instance variables to hold the values for command options. | 
|  | 1531 | bool m_use_dummy; | 
|  | 1532 | bool m_force; | 
|  | 1533 | }; | 
| Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1534 |  | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1535 | protected: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1536 | bool DoExecute(Args &command, CommandReturnObject &result) override { | 
|  | 1537 | Target *target = GetSelectedOrDummyTarget(m_options.m_use_dummy); | 
| Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1538 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1539 | if (target == nullptr) { | 
|  | 1540 | result.AppendError("Invalid target. No existing target or breakpoints."); | 
|  | 1541 | result.SetStatus(eReturnStatusFailed); | 
|  | 1542 | return false; | 
| Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1543 | } | 
| Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1544 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1545 | std::unique_lock<std::recursive_mutex> lock; | 
|  | 1546 | target->GetBreakpointList().GetListMutex(lock); | 
|  | 1547 |  | 
|  | 1548 | const BreakpointList &breakpoints = target->GetBreakpointList(); | 
|  | 1549 |  | 
|  | 1550 | size_t num_breakpoints = breakpoints.GetSize(); | 
|  | 1551 |  | 
|  | 1552 | if (num_breakpoints == 0) { | 
|  | 1553 | result.AppendError("No breakpoints exist to be deleted."); | 
|  | 1554 | result.SetStatus(eReturnStatusFailed); | 
|  | 1555 | return false; | 
|  | 1556 | } | 
|  | 1557 |  | 
| Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1558 | if (command.empty()) { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1559 | if (!m_options.m_force && | 
|  | 1560 | !m_interpreter.Confirm( | 
|  | 1561 | "About to delete all breakpoints, do you want to do that?", | 
|  | 1562 | true)) { | 
|  | 1563 | result.AppendMessage("Operation cancelled..."); | 
|  | 1564 | } else { | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1565 | target->RemoveAllowedBreakpoints(); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1566 | result.AppendMessageWithFormat( | 
|  | 1567 | "All breakpoints removed. (%" PRIu64 " breakpoint%s)\n", | 
|  | 1568 | (uint64_t)num_breakpoints, num_breakpoints > 1 ? "s" : ""); | 
|  | 1569 | } | 
|  | 1570 | result.SetStatus(eReturnStatusSuccessFinishNoResult); | 
|  | 1571 | } else { | 
|  | 1572 | // Particular breakpoint selected; disable that breakpoint. | 
|  | 1573 | BreakpointIDList valid_bp_ids; | 
|  | 1574 | CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs( | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1575 | command, target, result, &valid_bp_ids, | 
|  | 1576 | BreakpointName::Permissions::PermissionKinds::deletePerm); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1577 |  | 
|  | 1578 | if (result.Succeeded()) { | 
|  | 1579 | int delete_count = 0; | 
|  | 1580 | int disable_count = 0; | 
|  | 1581 | const size_t count = valid_bp_ids.GetSize(); | 
|  | 1582 | for (size_t i = 0; i < count; ++i) { | 
|  | 1583 | BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i); | 
|  | 1584 |  | 
|  | 1585 | if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) { | 
|  | 1586 | if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { | 
|  | 1587 | Breakpoint *breakpoint = | 
|  | 1588 | target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); | 
|  | 1589 | BreakpointLocation *location = | 
|  | 1590 | breakpoint->FindLocationByID(cur_bp_id.GetLocationID()).get(); | 
|  | 1591 | // It makes no sense to try to delete individual locations, so we | 
|  | 1592 | // disable them instead. | 
|  | 1593 | if (location) { | 
|  | 1594 | location->SetEnabled(false); | 
|  | 1595 | ++disable_count; | 
|  | 1596 | } | 
|  | 1597 | } else { | 
|  | 1598 | target->RemoveBreakpointByID(cur_bp_id.GetBreakpointID()); | 
|  | 1599 | ++delete_count; | 
|  | 1600 | } | 
|  | 1601 | } | 
|  | 1602 | } | 
|  | 1603 | result.AppendMessageWithFormat( | 
|  | 1604 | "%d breakpoints deleted; %d breakpoint locations disabled.\n", | 
|  | 1605 | delete_count, disable_count); | 
|  | 1606 | result.SetStatus(eReturnStatusSuccessFinishNoResult); | 
|  | 1607 | } | 
|  | 1608 | } | 
|  | 1609 | return result.Succeeded(); | 
|  | 1610 | } | 
|  | 1611 |  | 
| Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1612 | private: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1613 | CommandOptions m_options; | 
| Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1614 | }; | 
|  | 1615 |  | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1616 | // CommandObjectBreakpointName | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1617 |  | 
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1618 | static constexpr OptionDefinition g_breakpoint_name_options[] = { | 
| Raphael Isemann | f94668e | 2019-07-22 10:02:09 +0000 | [diff] [blame^] | 1619 | #define LLDB_OPTIONS_breakpoint_name | 
|  | 1620 | #include "CommandOptions.inc" | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1621 | }; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1622 | class BreakpointNameOptionGroup : public OptionGroup { | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1623 | public: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1624 | BreakpointNameOptionGroup() | 
|  | 1625 | : OptionGroup(), m_breakpoint(LLDB_INVALID_BREAK_ID), m_use_dummy(false) { | 
|  | 1626 | } | 
|  | 1627 |  | 
|  | 1628 | ~BreakpointNameOptionGroup() override = default; | 
|  | 1629 |  | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1630 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { | 
| Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 1631 | return llvm::makeArrayRef(g_breakpoint_name_options); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1632 | } | 
|  | 1633 |  | 
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1634 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, | 
|  | 1635 | ExecutionContext *execution_context) override { | 
|  | 1636 | Status error; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1637 | const int short_option = g_breakpoint_name_options[option_idx].short_option; | 
|  | 1638 |  | 
|  | 1639 | switch (short_option) { | 
|  | 1640 | case 'N': | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1641 | if (BreakpointID::StringIsBreakpointName(option_arg, error) && | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1642 | error.Success()) | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1643 | m_name.SetValueFromString(option_arg); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1644 | break; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1645 | case 'B': | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1646 | if (m_breakpoint.SetValueFromString(option_arg).Fail()) | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1647 | error.SetErrorStringWithFormat( | 
| Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 1648 | "unrecognized value \"%s\" for breakpoint", | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1649 | option_arg.str().c_str()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1650 | break; | 
|  | 1651 | case 'D': | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1652 | if (m_use_dummy.SetValueFromString(option_arg).Fail()) | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1653 | error.SetErrorStringWithFormat( | 
| Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 1654 | "unrecognized value \"%s\" for use-dummy", | 
| Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1655 | option_arg.str().c_str()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1656 | break; | 
| Jim Ingham | e9632eb | 2017-09-15 00:52:35 +0000 | [diff] [blame] | 1657 | case 'H': | 
|  | 1658 | m_help_string.SetValueFromString(option_arg); | 
|  | 1659 | break; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1660 |  | 
|  | 1661 | default: | 
|  | 1662 | error.SetErrorStringWithFormat("unrecognized short option '%c'", | 
|  | 1663 | short_option); | 
|  | 1664 | break; | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1665 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1666 | return error; | 
|  | 1667 | } | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1668 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1669 | void OptionParsingStarting(ExecutionContext *execution_context) override { | 
|  | 1670 | m_name.Clear(); | 
|  | 1671 | m_breakpoint.Clear(); | 
|  | 1672 | m_use_dummy.Clear(); | 
|  | 1673 | m_use_dummy.SetDefaultValue(false); | 
| Jim Ingham | e9632eb | 2017-09-15 00:52:35 +0000 | [diff] [blame] | 1674 | m_help_string.Clear(); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1675 | } | 
| Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1676 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1677 | OptionValueString m_name; | 
|  | 1678 | OptionValueUInt64 m_breakpoint; | 
|  | 1679 | OptionValueBoolean m_use_dummy; | 
| Jim Ingham | e9632eb | 2017-09-15 00:52:35 +0000 | [diff] [blame] | 1680 | OptionValueString m_help_string; | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1681 | }; | 
|  | 1682 |  | 
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1683 | static constexpr OptionDefinition g_breakpoint_access_options[] = { | 
| Raphael Isemann | f94668e | 2019-07-22 10:02:09 +0000 | [diff] [blame^] | 1684 | #define LLDB_OPTIONS_breakpoint_access | 
|  | 1685 | #include "CommandOptions.inc" | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1686 | }; | 
|  | 1687 |  | 
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1688 | class BreakpointAccessOptionGroup : public OptionGroup { | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1689 | public: | 
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1690 | BreakpointAccessOptionGroup() : OptionGroup() {} | 
|  | 1691 |  | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1692 | ~BreakpointAccessOptionGroup() override = default; | 
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1693 |  | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1694 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { | 
|  | 1695 | return llvm::makeArrayRef(g_breakpoint_access_options); | 
|  | 1696 | } | 
|  | 1697 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, | 
|  | 1698 | ExecutionContext *execution_context) override { | 
|  | 1699 | Status error; | 
|  | 1700 | const int short_option | 
|  | 1701 | = g_breakpoint_access_options[option_idx].short_option; | 
|  | 1702 |  | 
|  | 1703 | switch (short_option) { | 
|  | 1704 | case 'L': { | 
|  | 1705 | bool value, success; | 
| Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 1706 | value = OptionArgParser::ToBoolean(option_arg, false, &success); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1707 | if (success) { | 
|  | 1708 | m_permissions.SetAllowList(value); | 
|  | 1709 | } else | 
|  | 1710 | error.SetErrorStringWithFormat( | 
|  | 1711 | "invalid boolean value '%s' passed for -L option", | 
|  | 1712 | option_arg.str().c_str()); | 
|  | 1713 | } break; | 
|  | 1714 | case 'A': { | 
|  | 1715 | bool value, success; | 
| Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 1716 | value = OptionArgParser::ToBoolean(option_arg, false, &success); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1717 | if (success) { | 
|  | 1718 | m_permissions.SetAllowDisable(value); | 
|  | 1719 | } else | 
|  | 1720 | error.SetErrorStringWithFormat( | 
|  | 1721 | "invalid boolean value '%s' passed for -L option", | 
|  | 1722 | option_arg.str().c_str()); | 
|  | 1723 | } break; | 
|  | 1724 | case 'D': { | 
|  | 1725 | bool value, success; | 
| Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 1726 | value = OptionArgParser::ToBoolean(option_arg, false, &success); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1727 | if (success) { | 
|  | 1728 | m_permissions.SetAllowDelete(value); | 
|  | 1729 | } else | 
|  | 1730 | error.SetErrorStringWithFormat( | 
|  | 1731 | "invalid boolean value '%s' passed for -L option", | 
|  | 1732 | option_arg.str().c_str()); | 
|  | 1733 | } break; | 
|  | 1734 |  | 
|  | 1735 | } | 
|  | 1736 |  | 
|  | 1737 | return error; | 
|  | 1738 | } | 
|  | 1739 |  | 
|  | 1740 | void OptionParsingStarting(ExecutionContext *execution_context) override { | 
|  | 1741 | } | 
|  | 1742 |  | 
|  | 1743 | const BreakpointName::Permissions &GetPermissions() const | 
|  | 1744 | { | 
|  | 1745 | return m_permissions; | 
|  | 1746 | } | 
|  | 1747 | BreakpointName::Permissions m_permissions; | 
|  | 1748 | }; | 
|  | 1749 |  | 
|  | 1750 | class CommandObjectBreakpointNameConfigure : public CommandObjectParsed { | 
|  | 1751 | public: | 
|  | 1752 | CommandObjectBreakpointNameConfigure(CommandInterpreter &interpreter) | 
|  | 1753 | : CommandObjectParsed( | 
|  | 1754 | interpreter, "configure", "Configure the options for the breakpoint" | 
|  | 1755 | " name provided.  " | 
|  | 1756 | "If you provide a breakpoint id, the options will be copied from " | 
|  | 1757 | "the breakpoint, otherwise only the options specified will be set " | 
|  | 1758 | "on the name.", | 
|  | 1759 | "breakpoint name configure <command-options> " | 
|  | 1760 | "<breakpoint-name-list>"), | 
|  | 1761 | m_bp_opts(), m_option_group() { | 
|  | 1762 | // Create the first variant for the first (and only) argument for this | 
|  | 1763 | // command. | 
|  | 1764 | CommandArgumentEntry arg1; | 
|  | 1765 | CommandArgumentData id_arg; | 
|  | 1766 | id_arg.arg_type = eArgTypeBreakpointName; | 
|  | 1767 | id_arg.arg_repetition = eArgRepeatOptional; | 
|  | 1768 | arg1.push_back(id_arg); | 
|  | 1769 | m_arguments.push_back(arg1); | 
|  | 1770 |  | 
|  | 1771 | m_option_group.Append(&m_bp_opts, | 
|  | 1772 | LLDB_OPT_SET_ALL, | 
|  | 1773 | LLDB_OPT_SET_1); | 
|  | 1774 | m_option_group.Append(&m_access_options, | 
|  | 1775 | LLDB_OPT_SET_ALL, | 
|  | 1776 | LLDB_OPT_SET_ALL); | 
| Jim Ingham | e9632eb | 2017-09-15 00:52:35 +0000 | [diff] [blame] | 1777 | m_option_group.Append(&m_bp_id, | 
|  | 1778 | LLDB_OPT_SET_2|LLDB_OPT_SET_4, | 
|  | 1779 | LLDB_OPT_SET_ALL); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1780 | m_option_group.Finalize(); | 
|  | 1781 | } | 
|  | 1782 |  | 
|  | 1783 | ~CommandObjectBreakpointNameConfigure() override = default; | 
|  | 1784 |  | 
|  | 1785 | Options *GetOptions() override { return &m_option_group; } | 
|  | 1786 |  | 
|  | 1787 | protected: | 
|  | 1788 | bool DoExecute(Args &command, CommandReturnObject &result) override { | 
|  | 1789 |  | 
|  | 1790 | const size_t argc = command.GetArgumentCount(); | 
|  | 1791 | if (argc == 0) { | 
|  | 1792 | result.AppendError("No names provided."); | 
|  | 1793 | result.SetStatus(eReturnStatusFailed); | 
|  | 1794 | return false; | 
|  | 1795 | } | 
|  | 1796 |  | 
|  | 1797 | Target *target = | 
|  | 1798 | GetSelectedOrDummyTarget(false); | 
|  | 1799 |  | 
|  | 1800 | if (target == nullptr) { | 
|  | 1801 | result.AppendError("Invalid target. No existing target or breakpoints."); | 
|  | 1802 | result.SetStatus(eReturnStatusFailed); | 
|  | 1803 | return false; | 
|  | 1804 | } | 
|  | 1805 |  | 
|  | 1806 | std::unique_lock<std::recursive_mutex> lock; | 
|  | 1807 | target->GetBreakpointList().GetListMutex(lock); | 
|  | 1808 |  | 
|  | 1809 | // Make a pass through first to see that all the names are legal. | 
|  | 1810 | for (auto &entry : command.entries()) { | 
|  | 1811 | Status error; | 
|  | 1812 | if (!BreakpointID::StringIsBreakpointName(entry.ref, error)) | 
|  | 1813 | { | 
|  | 1814 | result.AppendErrorWithFormat("Invalid breakpoint name: %s - %s", | 
|  | 1815 | entry.c_str(), error.AsCString()); | 
|  | 1816 | result.SetStatus(eReturnStatusFailed); | 
|  | 1817 | return false; | 
|  | 1818 | } | 
|  | 1819 | } | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1820 | // Now configure them, we already pre-checked the names so we don't need to | 
|  | 1821 | // check the error: | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1822 | BreakpointSP bp_sp; | 
|  | 1823 | if (m_bp_id.m_breakpoint.OptionWasSet()) | 
|  | 1824 | { | 
|  | 1825 | lldb::break_id_t bp_id = m_bp_id.m_breakpoint.GetUInt64Value(); | 
|  | 1826 | bp_sp = target->GetBreakpointByID(bp_id); | 
|  | 1827 | if (!bp_sp) | 
|  | 1828 | { | 
|  | 1829 | result.AppendErrorWithFormatv("Could not find specified breakpoint {0}", | 
|  | 1830 | bp_id); | 
|  | 1831 | result.SetStatus(eReturnStatusFailed); | 
|  | 1832 | return false; | 
|  | 1833 | } | 
|  | 1834 | } | 
|  | 1835 |  | 
|  | 1836 | Status error; | 
|  | 1837 | for (auto &entry : command.entries()) { | 
|  | 1838 | ConstString name(entry.c_str()); | 
|  | 1839 | BreakpointName *bp_name = target->FindBreakpointName(name, true, error); | 
|  | 1840 | if (!bp_name) | 
|  | 1841 | continue; | 
| Jim Ingham | e9632eb | 2017-09-15 00:52:35 +0000 | [diff] [blame] | 1842 | if (m_bp_id.m_help_string.OptionWasSet()) | 
|  | 1843 | bp_name->SetHelp(m_bp_id.m_help_string.GetStringValue().str().c_str()); | 
|  | 1844 |  | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1845 | if (bp_sp) | 
|  | 1846 | target->ConfigureBreakpointName(*bp_name, | 
|  | 1847 | *bp_sp->GetOptions(), | 
|  | 1848 | m_access_options.GetPermissions()); | 
|  | 1849 | else | 
|  | 1850 | target->ConfigureBreakpointName(*bp_name, | 
|  | 1851 | m_bp_opts.GetBreakpointOptions(), | 
|  | 1852 | m_access_options.GetPermissions()); | 
|  | 1853 | } | 
|  | 1854 | return true; | 
|  | 1855 | } | 
|  | 1856 |  | 
|  | 1857 | private: | 
|  | 1858 | BreakpointNameOptionGroup m_bp_id; // Only using the id part of this. | 
|  | 1859 | BreakpointOptionGroup m_bp_opts; | 
|  | 1860 | BreakpointAccessOptionGroup m_access_options; | 
|  | 1861 | OptionGroupOptions m_option_group; | 
|  | 1862 | }; | 
|  | 1863 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1864 | class CommandObjectBreakpointNameAdd : public CommandObjectParsed { | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1865 | public: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1866 | CommandObjectBreakpointNameAdd(CommandInterpreter &interpreter) | 
|  | 1867 | : CommandObjectParsed( | 
|  | 1868 | interpreter, "add", "Add a name to the breakpoints provided.", | 
|  | 1869 | "breakpoint name add <command-options> <breakpoint-id-list>"), | 
|  | 1870 | m_name_options(), m_option_group() { | 
|  | 1871 | // Create the first variant for the first (and only) argument for this | 
|  | 1872 | // command. | 
|  | 1873 | CommandArgumentEntry arg1; | 
|  | 1874 | CommandArgumentData id_arg; | 
|  | 1875 | id_arg.arg_type = eArgTypeBreakpointID; | 
|  | 1876 | id_arg.arg_repetition = eArgRepeatOptional; | 
|  | 1877 | arg1.push_back(id_arg); | 
|  | 1878 | m_arguments.push_back(arg1); | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1879 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1880 | m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); | 
|  | 1881 | m_option_group.Finalize(); | 
|  | 1882 | } | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1883 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1884 | ~CommandObjectBreakpointNameAdd() override = default; | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1885 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1886 | Options *GetOptions() override { return &m_option_group; } | 
| Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1887 |  | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1888 | protected: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1889 | bool DoExecute(Args &command, CommandReturnObject &result) override { | 
|  | 1890 | if (!m_name_options.m_name.OptionWasSet()) { | 
|  | 1891 | result.SetError("No name option provided."); | 
|  | 1892 | return false; | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1893 | } | 
|  | 1894 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1895 | Target *target = | 
|  | 1896 | GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); | 
|  | 1897 |  | 
|  | 1898 | if (target == nullptr) { | 
|  | 1899 | result.AppendError("Invalid target. No existing target or breakpoints."); | 
|  | 1900 | result.SetStatus(eReturnStatusFailed); | 
|  | 1901 | return false; | 
|  | 1902 | } | 
|  | 1903 |  | 
|  | 1904 | std::unique_lock<std::recursive_mutex> lock; | 
|  | 1905 | target->GetBreakpointList().GetListMutex(lock); | 
|  | 1906 |  | 
|  | 1907 | const BreakpointList &breakpoints = target->GetBreakpointList(); | 
|  | 1908 |  | 
|  | 1909 | size_t num_breakpoints = breakpoints.GetSize(); | 
|  | 1910 | if (num_breakpoints == 0) { | 
|  | 1911 | result.SetError("No breakpoints, cannot add names."); | 
|  | 1912 | result.SetStatus(eReturnStatusFailed); | 
|  | 1913 | return false; | 
|  | 1914 | } | 
|  | 1915 |  | 
|  | 1916 | // Particular breakpoint selected; disable that breakpoint. | 
|  | 1917 | BreakpointIDList valid_bp_ids; | 
|  | 1918 | CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1919 | command, target, result, &valid_bp_ids, | 
|  | 1920 | BreakpointName::Permissions::PermissionKinds::listPerm); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1921 |  | 
|  | 1922 | if (result.Succeeded()) { | 
|  | 1923 | if (valid_bp_ids.GetSize() == 0) { | 
|  | 1924 | result.SetError("No breakpoints specified, cannot add names."); | 
|  | 1925 | result.SetStatus(eReturnStatusFailed); | 
|  | 1926 | return false; | 
|  | 1927 | } | 
|  | 1928 | size_t num_valid_ids = valid_bp_ids.GetSize(); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1929 | const char *bp_name = m_name_options.m_name.GetCurrentValue(); | 
|  | 1930 | Status error; // This error reports illegal names, but we've already | 
|  | 1931 | // checked that, so we don't need to check it again here. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1932 | for (size_t index = 0; index < num_valid_ids; index++) { | 
|  | 1933 | lldb::break_id_t bp_id = | 
|  | 1934 | valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); | 
|  | 1935 | BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1936 | target->AddNameToBreakpoint(bp_sp, bp_name, error); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1937 | } | 
|  | 1938 | } | 
|  | 1939 |  | 
|  | 1940 | return true; | 
|  | 1941 | } | 
|  | 1942 |  | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1943 | private: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1944 | BreakpointNameOptionGroup m_name_options; | 
|  | 1945 | OptionGroupOptions m_option_group; | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1946 | }; | 
|  | 1947 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1948 | class CommandObjectBreakpointNameDelete : public CommandObjectParsed { | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1949 | public: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1950 | CommandObjectBreakpointNameDelete(CommandInterpreter &interpreter) | 
|  | 1951 | : CommandObjectParsed( | 
|  | 1952 | interpreter, "delete", | 
|  | 1953 | "Delete a name from the breakpoints provided.", | 
|  | 1954 | "breakpoint name delete <command-options> <breakpoint-id-list>"), | 
|  | 1955 | m_name_options(), m_option_group() { | 
|  | 1956 | // Create the first variant for the first (and only) argument for this | 
|  | 1957 | // command. | 
|  | 1958 | CommandArgumentEntry arg1; | 
|  | 1959 | CommandArgumentData id_arg; | 
|  | 1960 | id_arg.arg_type = eArgTypeBreakpointID; | 
|  | 1961 | id_arg.arg_repetition = eArgRepeatOptional; | 
|  | 1962 | arg1.push_back(id_arg); | 
|  | 1963 | m_arguments.push_back(arg1); | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1964 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1965 | m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); | 
|  | 1966 | m_option_group.Finalize(); | 
|  | 1967 | } | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1968 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1969 | ~CommandObjectBreakpointNameDelete() override = default; | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1970 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1971 | Options *GetOptions() override { return &m_option_group; } | 
| Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 1972 |  | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1973 | protected: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1974 | bool DoExecute(Args &command, CommandReturnObject &result) override { | 
|  | 1975 | if (!m_name_options.m_name.OptionWasSet()) { | 
|  | 1976 | result.SetError("No name option provided."); | 
|  | 1977 | return false; | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1978 | } | 
|  | 1979 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1980 | Target *target = | 
|  | 1981 | GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); | 
|  | 1982 |  | 
|  | 1983 | if (target == nullptr) { | 
|  | 1984 | result.AppendError("Invalid target. No existing target or breakpoints."); | 
|  | 1985 | result.SetStatus(eReturnStatusFailed); | 
|  | 1986 | return false; | 
|  | 1987 | } | 
|  | 1988 |  | 
|  | 1989 | std::unique_lock<std::recursive_mutex> lock; | 
|  | 1990 | target->GetBreakpointList().GetListMutex(lock); | 
|  | 1991 |  | 
|  | 1992 | const BreakpointList &breakpoints = target->GetBreakpointList(); | 
|  | 1993 |  | 
|  | 1994 | size_t num_breakpoints = breakpoints.GetSize(); | 
|  | 1995 | if (num_breakpoints == 0) { | 
|  | 1996 | result.SetError("No breakpoints, cannot delete names."); | 
|  | 1997 | result.SetStatus(eReturnStatusFailed); | 
|  | 1998 | return false; | 
|  | 1999 | } | 
|  | 2000 |  | 
|  | 2001 | // Particular breakpoint selected; disable that breakpoint. | 
|  | 2002 | BreakpointIDList valid_bp_ids; | 
|  | 2003 | CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 2004 | command, target, result, &valid_bp_ids, | 
|  | 2005 | BreakpointName::Permissions::PermissionKinds::deletePerm); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2006 |  | 
|  | 2007 | if (result.Succeeded()) { | 
|  | 2008 | if (valid_bp_ids.GetSize() == 0) { | 
|  | 2009 | result.SetError("No breakpoints specified, cannot delete names."); | 
|  | 2010 | result.SetStatus(eReturnStatusFailed); | 
|  | 2011 | return false; | 
|  | 2012 | } | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 2013 | ConstString bp_name(m_name_options.m_name.GetCurrentValue()); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2014 | size_t num_valid_ids = valid_bp_ids.GetSize(); | 
|  | 2015 | for (size_t index = 0; index < num_valid_ids; index++) { | 
|  | 2016 | lldb::break_id_t bp_id = | 
|  | 2017 | valid_bp_ids.GetBreakpointIDAtIndex(index).GetBreakpointID(); | 
|  | 2018 | BreakpointSP bp_sp = breakpoints.FindBreakpointByID(bp_id); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 2019 | target->RemoveNameFromBreakpoint(bp_sp, bp_name); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2020 | } | 
|  | 2021 | } | 
|  | 2022 |  | 
|  | 2023 | return true; | 
|  | 2024 | } | 
|  | 2025 |  | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2026 | private: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2027 | BreakpointNameOptionGroup m_name_options; | 
|  | 2028 | OptionGroupOptions m_option_group; | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2029 | }; | 
|  | 2030 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2031 | class CommandObjectBreakpointNameList : public CommandObjectParsed { | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2032 | public: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2033 | CommandObjectBreakpointNameList(CommandInterpreter &interpreter) | 
|  | 2034 | : CommandObjectParsed(interpreter, "list", | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 2035 | "List either the names for a breakpoint or info " | 
|  | 2036 | "about a given name.  With no arguments, lists all " | 
|  | 2037 | "names", | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2038 | "breakpoint name list <command-options>"), | 
|  | 2039 | m_name_options(), m_option_group() { | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 2040 | m_option_group.Append(&m_name_options, LLDB_OPT_SET_3, LLDB_OPT_SET_ALL); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2041 | m_option_group.Finalize(); | 
|  | 2042 | } | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2043 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2044 | ~CommandObjectBreakpointNameList() override = default; | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2045 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2046 | Options *GetOptions() override { return &m_option_group; } | 
| Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2047 |  | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2048 | protected: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2049 | bool DoExecute(Args &command, CommandReturnObject &result) override { | 
|  | 2050 | Target *target = | 
|  | 2051 | GetSelectedOrDummyTarget(m_name_options.m_use_dummy.GetCurrentValue()); | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2052 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2053 | if (target == nullptr) { | 
|  | 2054 | result.AppendError("Invalid target. No existing target or breakpoints."); | 
|  | 2055 | result.SetStatus(eReturnStatusFailed); | 
|  | 2056 | return false; | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2057 | } | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 2058 |  | 
|  | 2059 |  | 
|  | 2060 | std::vector<std::string> name_list; | 
|  | 2061 | if (command.empty()) { | 
|  | 2062 | target->GetBreakpointNames(name_list); | 
|  | 2063 | } else { | 
|  | 2064 | for (const Args::ArgEntry &arg : command) | 
|  | 2065 | { | 
|  | 2066 | name_list.push_back(arg.c_str()); | 
|  | 2067 | } | 
|  | 2068 | } | 
|  | 2069 |  | 
|  | 2070 | if (name_list.empty()) { | 
|  | 2071 | result.AppendMessage("No breakpoint names found."); | 
|  | 2072 | } else { | 
|  | 2073 | for (const std::string &name_str : name_list) { | 
|  | 2074 | const char *name = name_str.c_str(); | 
|  | 2075 | // First print out the options for the name: | 
|  | 2076 | Status error; | 
|  | 2077 | BreakpointName *bp_name = target->FindBreakpointName(ConstString(name), | 
|  | 2078 | false, | 
|  | 2079 | error); | 
|  | 2080 | if (bp_name) | 
|  | 2081 | { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2082 | StreamString s; | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 2083 | result.AppendMessageWithFormat("Name: %s\n", name); | 
|  | 2084 | if (bp_name->GetDescription(&s, eDescriptionLevelFull)) | 
|  | 2085 | { | 
|  | 2086 | result.AppendMessage(s.GetString()); | 
|  | 2087 | } | 
|  | 2088 |  | 
|  | 2089 | std::unique_lock<std::recursive_mutex> lock; | 
|  | 2090 | target->GetBreakpointList().GetListMutex(lock); | 
|  | 2091 |  | 
|  | 2092 | BreakpointList &breakpoints = target->GetBreakpointList(); | 
|  | 2093 | bool any_set = false; | 
|  | 2094 | for (BreakpointSP bp_sp : breakpoints.Breakpoints()) { | 
|  | 2095 | if (bp_sp->MatchesName(name)) { | 
|  | 2096 | StreamString s; | 
|  | 2097 | any_set = true; | 
|  | 2098 | bp_sp->GetDescription(&s, eDescriptionLevelBrief); | 
|  | 2099 | s.EOL(); | 
|  | 2100 | result.AppendMessage(s.GetString()); | 
|  | 2101 | } | 
|  | 2102 | } | 
|  | 2103 | if (!any_set) | 
|  | 2104 | result.AppendMessage("No breakpoints using this name."); | 
|  | 2105 | } else { | 
|  | 2106 | result.AppendMessageWithFormat("Name: %s not found.\n", name); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2107 | } | 
|  | 2108 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2109 | } | 
|  | 2110 | return true; | 
|  | 2111 | } | 
|  | 2112 |  | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2113 | private: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2114 | BreakpointNameOptionGroup m_name_options; | 
|  | 2115 | OptionGroupOptions m_option_group; | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2116 | }; | 
|  | 2117 |  | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2118 | // CommandObjectBreakpointName | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2119 | class CommandObjectBreakpointName : public CommandObjectMultiword { | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2120 | public: | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2121 | CommandObjectBreakpointName(CommandInterpreter &interpreter) | 
|  | 2122 | : CommandObjectMultiword( | 
|  | 2123 | interpreter, "name", "Commands to manage name tags for breakpoints", | 
|  | 2124 | "breakpoint name <subcommand> [<command-options>]") { | 
|  | 2125 | CommandObjectSP add_command_object( | 
|  | 2126 | new CommandObjectBreakpointNameAdd(interpreter)); | 
|  | 2127 | CommandObjectSP delete_command_object( | 
|  | 2128 | new CommandObjectBreakpointNameDelete(interpreter)); | 
|  | 2129 | CommandObjectSP list_command_object( | 
|  | 2130 | new CommandObjectBreakpointNameList(interpreter)); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 2131 | CommandObjectSP configure_command_object( | 
|  | 2132 | new CommandObjectBreakpointNameConfigure(interpreter)); | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2133 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2134 | LoadSubCommand("add", add_command_object); | 
|  | 2135 | LoadSubCommand("delete", delete_command_object); | 
|  | 2136 | LoadSubCommand("list", list_command_object); | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 2137 | LoadSubCommand("configure", configure_command_object); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2138 | } | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2139 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2140 | ~CommandObjectBreakpointName() override = default; | 
| Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 2141 | }; | 
|  | 2142 |  | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2143 | // CommandObjectBreakpointRead | 
| Jim Ingham | 3acdf38 | 2016-09-22 22:20:28 +0000 | [diff] [blame] | 2144 | #pragma mark Read::CommandOptions | 
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 2145 | static constexpr OptionDefinition g_breakpoint_read_options[] = { | 
| Raphael Isemann | f94668e | 2019-07-22 10:02:09 +0000 | [diff] [blame^] | 2146 | #define LLDB_OPTIONS_breakpoint_read | 
|  | 2147 | #include "CommandOptions.inc" | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 2148 | }; | 
|  | 2149 |  | 
|  | 2150 | #pragma mark Read | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2151 |  | 
|  | 2152 | class CommandObjectBreakpointRead : public CommandObjectParsed { | 
|  | 2153 | public: | 
|  | 2154 | CommandObjectBreakpointRead(CommandInterpreter &interpreter) | 
|  | 2155 | : CommandObjectParsed(interpreter, "breakpoint read", | 
|  | 2156 | "Read and set the breakpoints previously saved to " | 
|  | 2157 | "a file with \"breakpoint write\".  ", | 
|  | 2158 | nullptr), | 
|  | 2159 | m_options() { | 
|  | 2160 | CommandArgumentEntry arg; | 
|  | 2161 | CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, | 
|  | 2162 | eArgTypeBreakpointIDRange); | 
|  | 2163 | // Add the entry for the first argument for this command to the object's | 
|  | 2164 | // arguments vector. | 
|  | 2165 | m_arguments.push_back(arg); | 
|  | 2166 | } | 
|  | 2167 |  | 
|  | 2168 | ~CommandObjectBreakpointRead() override = default; | 
|  | 2169 |  | 
|  | 2170 | Options *GetOptions() override { return &m_options; } | 
|  | 2171 |  | 
|  | 2172 | class CommandOptions : public Options { | 
|  | 2173 | public: | 
|  | 2174 | CommandOptions() : Options() {} | 
|  | 2175 |  | 
|  | 2176 | ~CommandOptions() override = default; | 
|  | 2177 |  | 
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2178 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, | 
|  | 2179 | ExecutionContext *execution_context) override { | 
|  | 2180 | Status error; | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2181 | const int short_option = m_getopt_table[option_idx].val; | 
|  | 2182 |  | 
|  | 2183 | switch (short_option) { | 
|  | 2184 | case 'f': | 
|  | 2185 | m_filename.assign(option_arg); | 
|  | 2186 | break; | 
| Jim Ingham | 3acdf38 | 2016-09-22 22:20:28 +0000 | [diff] [blame] | 2187 | case 'N': { | 
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2188 | Status name_error; | 
| Jim Ingham | 3acdf38 | 2016-09-22 22:20:28 +0000 | [diff] [blame] | 2189 | if (!BreakpointID::StringIsBreakpointName(llvm::StringRef(option_arg), | 
|  | 2190 | name_error)) { | 
|  | 2191 | error.SetErrorStringWithFormat("Invalid breakpoint name: %s", | 
|  | 2192 | name_error.AsCString()); | 
|  | 2193 | } | 
|  | 2194 | m_names.push_back(option_arg); | 
|  | 2195 | break; | 
|  | 2196 | } | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2197 | default: | 
|  | 2198 | error.SetErrorStringWithFormat("unrecognized option '%c'", | 
|  | 2199 | short_option); | 
|  | 2200 | break; | 
|  | 2201 | } | 
|  | 2202 |  | 
|  | 2203 | return error; | 
|  | 2204 | } | 
|  | 2205 |  | 
|  | 2206 | void OptionParsingStarting(ExecutionContext *execution_context) override { | 
|  | 2207 | m_filename.clear(); | 
| Jim Ingham | 3acdf38 | 2016-09-22 22:20:28 +0000 | [diff] [blame] | 2208 | m_names.clear(); | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2209 | } | 
|  | 2210 |  | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 2211 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { | 
| Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 2212 | return llvm::makeArrayRef(g_breakpoint_read_options); | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 2213 | } | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2214 |  | 
|  | 2215 | // Instance variables to hold the values for command options. | 
|  | 2216 |  | 
|  | 2217 | std::string m_filename; | 
| Jim Ingham | 3acdf38 | 2016-09-22 22:20:28 +0000 | [diff] [blame] | 2218 | std::vector<std::string> m_names; | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2219 | }; | 
|  | 2220 |  | 
|  | 2221 | protected: | 
|  | 2222 | bool DoExecute(Args &command, CommandReturnObject &result) override { | 
|  | 2223 | Target *target = GetSelectedOrDummyTarget(); | 
|  | 2224 | if (target == nullptr) { | 
|  | 2225 | result.AppendError("Invalid target.  No existing target or breakpoints."); | 
|  | 2226 | result.SetStatus(eReturnStatusFailed); | 
|  | 2227 | return false; | 
|  | 2228 | } | 
|  | 2229 |  | 
| Jim Ingham | 3acdf38 | 2016-09-22 22:20:28 +0000 | [diff] [blame] | 2230 | std::unique_lock<std::recursive_mutex> lock; | 
|  | 2231 | target->GetBreakpointList().GetListMutex(lock); | 
|  | 2232 |  | 
| Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 2233 | FileSpec input_spec(m_options.m_filename); | 
|  | 2234 | FileSystem::Instance().Resolve(input_spec); | 
| Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 2235 | BreakpointIDList new_bps; | 
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2236 | Status error = target->CreateBreakpointsFromFile( | 
|  | 2237 | input_spec, m_options.m_names, new_bps); | 
| Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 2238 |  | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2239 | if (!error.Success()) { | 
| Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 2240 | result.AppendError(error.AsCString()); | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2241 | result.SetStatus(eReturnStatusFailed); | 
|  | 2242 | return false; | 
|  | 2243 | } | 
| Jim Ingham | 3acdf38 | 2016-09-22 22:20:28 +0000 | [diff] [blame] | 2244 |  | 
|  | 2245 | Stream &output_stream = result.GetOutputStream(); | 
|  | 2246 |  | 
|  | 2247 | size_t num_breakpoints = new_bps.GetSize(); | 
|  | 2248 | if (num_breakpoints == 0) { | 
|  | 2249 | result.AppendMessage("No breakpoints added."); | 
|  | 2250 | } else { | 
|  | 2251 | // No breakpoint selected; show info about all currently set breakpoints. | 
|  | 2252 | result.AppendMessage("New breakpoints:"); | 
|  | 2253 | for (size_t i = 0; i < num_breakpoints; ++i) { | 
|  | 2254 | BreakpointID bp_id = new_bps.GetBreakpointIDAtIndex(i); | 
|  | 2255 | Breakpoint *bp = target->GetBreakpointList() | 
|  | 2256 | .FindBreakpointByID(bp_id.GetBreakpointID()) | 
|  | 2257 | .get(); | 
|  | 2258 | if (bp) | 
|  | 2259 | bp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, | 
|  | 2260 | false); | 
|  | 2261 | } | 
|  | 2262 | } | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2263 | return result.Succeeded(); | 
|  | 2264 | } | 
|  | 2265 |  | 
|  | 2266 | private: | 
|  | 2267 | CommandOptions m_options; | 
|  | 2268 | }; | 
|  | 2269 |  | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2270 | // CommandObjectBreakpointWrite | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 2271 | #pragma mark Write::CommandOptions | 
| Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 2272 | static constexpr OptionDefinition g_breakpoint_write_options[] = { | 
| Raphael Isemann | f94668e | 2019-07-22 10:02:09 +0000 | [diff] [blame^] | 2273 | #define LLDB_OPTIONS_breakpoint_write | 
|  | 2274 | #include "CommandOptions.inc" | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 2275 | }; | 
|  | 2276 |  | 
|  | 2277 | #pragma mark Write | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2278 | class CommandObjectBreakpointWrite : public CommandObjectParsed { | 
|  | 2279 | public: | 
|  | 2280 | CommandObjectBreakpointWrite(CommandInterpreter &interpreter) | 
|  | 2281 | : CommandObjectParsed(interpreter, "breakpoint write", | 
|  | 2282 | "Write the breakpoints listed to a file that can " | 
|  | 2283 | "be read in with \"breakpoint read\".  " | 
|  | 2284 | "If given no arguments, writes all breakpoints.", | 
|  | 2285 | nullptr), | 
|  | 2286 | m_options() { | 
|  | 2287 | CommandArgumentEntry arg; | 
|  | 2288 | CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID, | 
|  | 2289 | eArgTypeBreakpointIDRange); | 
|  | 2290 | // Add the entry for the first argument for this command to the object's | 
|  | 2291 | // arguments vector. | 
|  | 2292 | m_arguments.push_back(arg); | 
|  | 2293 | } | 
|  | 2294 |  | 
|  | 2295 | ~CommandObjectBreakpointWrite() override = default; | 
|  | 2296 |  | 
|  | 2297 | Options *GetOptions() override { return &m_options; } | 
|  | 2298 |  | 
|  | 2299 | class CommandOptions : public Options { | 
|  | 2300 | public: | 
|  | 2301 | CommandOptions() : Options() {} | 
|  | 2302 |  | 
|  | 2303 | ~CommandOptions() override = default; | 
|  | 2304 |  | 
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2305 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, | 
|  | 2306 | ExecutionContext *execution_context) override { | 
|  | 2307 | Status error; | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2308 | const int short_option = m_getopt_table[option_idx].val; | 
|  | 2309 |  | 
|  | 2310 | switch (short_option) { | 
|  | 2311 | case 'f': | 
|  | 2312 | m_filename.assign(option_arg); | 
|  | 2313 | break; | 
| Jim Ingham | 2d3628e | 2016-09-22 23:42:42 +0000 | [diff] [blame] | 2314 | case 'a': | 
|  | 2315 | m_append = true; | 
|  | 2316 | break; | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2317 | default: | 
|  | 2318 | error.SetErrorStringWithFormat("unrecognized option '%c'", | 
|  | 2319 | short_option); | 
|  | 2320 | break; | 
|  | 2321 | } | 
|  | 2322 |  | 
|  | 2323 | return error; | 
|  | 2324 | } | 
|  | 2325 |  | 
|  | 2326 | void OptionParsingStarting(ExecutionContext *execution_context) override { | 
|  | 2327 | m_filename.clear(); | 
| Jim Ingham | 2d3628e | 2016-09-22 23:42:42 +0000 | [diff] [blame] | 2328 | m_append = false; | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2329 | } | 
|  | 2330 |  | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 2331 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { | 
| Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 2332 | return llvm::makeArrayRef(g_breakpoint_write_options); | 
| Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 2333 | } | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2334 |  | 
|  | 2335 | // Instance variables to hold the values for command options. | 
|  | 2336 |  | 
|  | 2337 | std::string m_filename; | 
| Jim Ingham | 2d3628e | 2016-09-22 23:42:42 +0000 | [diff] [blame] | 2338 | bool m_append = false; | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2339 | }; | 
|  | 2340 |  | 
|  | 2341 | protected: | 
|  | 2342 | bool DoExecute(Args &command, CommandReturnObject &result) override { | 
|  | 2343 | Target *target = GetSelectedOrDummyTarget(); | 
|  | 2344 | if (target == nullptr) { | 
|  | 2345 | result.AppendError("Invalid target.  No existing target or breakpoints."); | 
|  | 2346 | result.SetStatus(eReturnStatusFailed); | 
|  | 2347 | return false; | 
|  | 2348 | } | 
|  | 2349 |  | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2350 | std::unique_lock<std::recursive_mutex> lock; | 
|  | 2351 | target->GetBreakpointList().GetListMutex(lock); | 
|  | 2352 |  | 
| Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 2353 | BreakpointIDList valid_bp_ids; | 
| Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 2354 | if (!command.empty()) { | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2355 | CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs( | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 2356 | command, target, result, &valid_bp_ids, | 
|  | 2357 | BreakpointName::Permissions::PermissionKinds::listPerm); | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2358 |  | 
| Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 2359 | if (!result.Succeeded()) { | 
|  | 2360 | result.SetStatus(eReturnStatusFailed); | 
|  | 2361 | return false; | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2362 | } | 
|  | 2363 | } | 
| Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 2364 | FileSpec file_spec(m_options.m_filename); | 
|  | 2365 | FileSystem::Instance().Resolve(file_spec); | 
|  | 2366 | Status error = target->SerializeBreakpointsToFile(file_spec, valid_bp_ids, | 
|  | 2367 | m_options.m_append); | 
| Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 2368 | if (!error.Success()) { | 
|  | 2369 | result.AppendErrorWithFormat("error serializing breakpoints: %s.", | 
|  | 2370 | error.AsCString()); | 
|  | 2371 | result.SetStatus(eReturnStatusFailed); | 
|  | 2372 | } | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2373 | return result.Succeeded(); | 
|  | 2374 | } | 
|  | 2375 |  | 
|  | 2376 | private: | 
|  | 2377 | CommandOptions m_options; | 
|  | 2378 | }; | 
|  | 2379 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2380 | // CommandObjectMultiwordBreakpoint | 
| Jim Ingham | ae1c4cf | 2010-06-18 00:58:52 +0000 | [diff] [blame] | 2381 | #pragma mark MultiwordBreakpoint | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2382 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2383 | CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint( | 
|  | 2384 | CommandInterpreter &interpreter) | 
|  | 2385 | : CommandObjectMultiword( | 
|  | 2386 | interpreter, "breakpoint", | 
|  | 2387 | "Commands for operating on breakpoints (see 'help b' for shorthand.)", | 
|  | 2388 | "breakpoint <subcommand> [<command-options>]") { | 
|  | 2389 | CommandObjectSP list_command_object( | 
|  | 2390 | new CommandObjectBreakpointList(interpreter)); | 
|  | 2391 | CommandObjectSP enable_command_object( | 
|  | 2392 | new CommandObjectBreakpointEnable(interpreter)); | 
|  | 2393 | CommandObjectSP disable_command_object( | 
|  | 2394 | new CommandObjectBreakpointDisable(interpreter)); | 
|  | 2395 | CommandObjectSP clear_command_object( | 
|  | 2396 | new CommandObjectBreakpointClear(interpreter)); | 
|  | 2397 | CommandObjectSP delete_command_object( | 
|  | 2398 | new CommandObjectBreakpointDelete(interpreter)); | 
|  | 2399 | CommandObjectSP set_command_object( | 
|  | 2400 | new CommandObjectBreakpointSet(interpreter)); | 
|  | 2401 | CommandObjectSP command_command_object( | 
|  | 2402 | new CommandObjectBreakpointCommand(interpreter)); | 
|  | 2403 | CommandObjectSP modify_command_object( | 
|  | 2404 | new CommandObjectBreakpointModify(interpreter)); | 
|  | 2405 | CommandObjectSP name_command_object( | 
|  | 2406 | new CommandObjectBreakpointName(interpreter)); | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2407 | CommandObjectSP write_command_object( | 
|  | 2408 | new CommandObjectBreakpointWrite(interpreter)); | 
|  | 2409 | CommandObjectSP read_command_object( | 
|  | 2410 | new CommandObjectBreakpointRead(interpreter)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2411 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2412 | list_command_object->SetCommandName("breakpoint list"); | 
|  | 2413 | enable_command_object->SetCommandName("breakpoint enable"); | 
|  | 2414 | disable_command_object->SetCommandName("breakpoint disable"); | 
|  | 2415 | clear_command_object->SetCommandName("breakpoint clear"); | 
|  | 2416 | delete_command_object->SetCommandName("breakpoint delete"); | 
|  | 2417 | set_command_object->SetCommandName("breakpoint set"); | 
|  | 2418 | command_command_object->SetCommandName("breakpoint command"); | 
|  | 2419 | modify_command_object->SetCommandName("breakpoint modify"); | 
|  | 2420 | name_command_object->SetCommandName("breakpoint name"); | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2421 | write_command_object->SetCommandName("breakpoint write"); | 
|  | 2422 | read_command_object->SetCommandName("breakpoint read"); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2423 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2424 | LoadSubCommand("list", list_command_object); | 
|  | 2425 | LoadSubCommand("enable", enable_command_object); | 
|  | 2426 | LoadSubCommand("disable", disable_command_object); | 
|  | 2427 | LoadSubCommand("clear", clear_command_object); | 
|  | 2428 | LoadSubCommand("delete", delete_command_object); | 
|  | 2429 | LoadSubCommand("set", set_command_object); | 
|  | 2430 | LoadSubCommand("command", command_command_object); | 
|  | 2431 | LoadSubCommand("modify", modify_command_object); | 
|  | 2432 | LoadSubCommand("name", name_command_object); | 
| Jim Ingham | e14dc26 | 2016-09-12 23:10:56 +0000 | [diff] [blame] | 2433 | LoadSubCommand("write", write_command_object); | 
|  | 2434 | LoadSubCommand("read", read_command_object); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2435 | } | 
|  | 2436 |  | 
| Eugene Zelenko | 9e85e5a | 2016-02-18 22:39:14 +0000 | [diff] [blame] | 2437 | CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2438 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2439 | void CommandObjectMultiwordBreakpoint::VerifyIDs(Args &args, Target *target, | 
|  | 2440 | bool allow_locations, | 
|  | 2441 | CommandReturnObject &result, | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 2442 | BreakpointIDList *valid_ids, | 
|  | 2443 | BreakpointName::Permissions | 
|  | 2444 | ::PermissionKinds | 
|  | 2445 | purpose) { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2446 | // args can be strings representing 1). integers (for breakpoint ids) | 
|  | 2447 | //                                  2). the full breakpoint & location | 
|  | 2448 | //                                  canonical representation | 
|  | 2449 | //                                  3). the word "to" or a hyphen, | 
|  | 2450 | //                                  representing a range (in which case there | 
|  | 2451 | //                                      had *better* be an entry both before & | 
|  | 2452 | //                                      after of one of the first two types. | 
|  | 2453 | //                                  4). A breakpoint name | 
|  | 2454 | // If args is empty, we will use the last created breakpoint (if there is | 
|  | 2455 | // one.) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2456 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2457 | Args temp_args; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2458 |  | 
| Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 2459 | if (args.empty()) { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2460 | if (target->GetLastCreatedBreakpoint()) { | 
|  | 2461 | valid_ids->AddBreakpointID(BreakpointID( | 
|  | 2462 | target->GetLastCreatedBreakpoint()->GetID(), LLDB_INVALID_BREAK_ID)); | 
|  | 2463 | result.SetStatus(eReturnStatusSuccessFinishNoResult); | 
|  | 2464 | } else { | 
|  | 2465 | result.AppendError( | 
|  | 2466 | "No breakpoint specified and no last created breakpoint."); | 
|  | 2467 | result.SetStatus(eReturnStatusFailed); | 
| Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 2468 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2469 | return; | 
|  | 2470 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2471 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2472 | // Create a new Args variable to use; copy any non-breakpoint-id-ranges stuff | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2473 | // directly from the old ARGS to the new TEMP_ARGS.  Do not copy breakpoint | 
|  | 2474 | // id range strings over; instead generate a list of strings for all the | 
|  | 2475 | // breakpoint ids in the range, and shove all of those breakpoint id strings | 
|  | 2476 | // into TEMP_ARGS. | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2477 |  | 
| Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 2478 | BreakpointIDList::FindAndReplaceIDRanges(args, target, allow_locations, | 
|  | 2479 | purpose, result, temp_args); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2480 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2481 | // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual | 
|  | 2482 | // BreakpointIDList: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2483 |  | 
| Pavel Labath | 16662f3 | 2018-06-20 08:12:50 +0000 | [diff] [blame] | 2484 | valid_ids->InsertStringArray(temp_args.GetArgumentArrayRef(), result); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2485 |  | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2486 | // At this point,  all of the breakpoint ids that the user passed in have | 
|  | 2487 | // been converted to breakpoint IDs and put into valid_ids. | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2488 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2489 | if (result.Succeeded()) { | 
|  | 2490 | // Now that we've converted everything from args into a list of breakpoint | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2491 | // ids, go through our tentative list of breakpoint id's and verify that | 
|  | 2492 | // they correspond to valid/currently set breakpoints. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2493 |  | 
|  | 2494 | const size_t count = valid_ids->GetSize(); | 
|  | 2495 | for (size_t i = 0; i < count; ++i) { | 
|  | 2496 | BreakpointID cur_bp_id = valid_ids->GetBreakpointIDAtIndex(i); | 
|  | 2497 | Breakpoint *breakpoint = | 
|  | 2498 | target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get(); | 
|  | 2499 | if (breakpoint != nullptr) { | 
|  | 2500 | const size_t num_locations = breakpoint->GetNumLocations(); | 
|  | 2501 | if (static_cast<size_t>(cur_bp_id.GetLocationID()) > num_locations) { | 
|  | 2502 | StreamString id_str; | 
|  | 2503 | BreakpointID::GetCanonicalReference( | 
|  | 2504 | &id_str, cur_bp_id.GetBreakpointID(), cur_bp_id.GetLocationID()); | 
|  | 2505 | i = valid_ids->GetSize() + 1; | 
|  | 2506 | result.AppendErrorWithFormat( | 
|  | 2507 | "'%s' is not a currently valid breakpoint/location id.\n", | 
|  | 2508 | id_str.GetData()); | 
|  | 2509 | result.SetStatus(eReturnStatusFailed); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2510 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2511 | } else { | 
|  | 2512 | i = valid_ids->GetSize() + 1; | 
|  | 2513 | result.AppendErrorWithFormat( | 
|  | 2514 | "'%d' is not a currently valid breakpoint ID.\n", | 
|  | 2515 | cur_bp_id.GetBreakpointID()); | 
|  | 2516 | result.SetStatus(eReturnStatusFailed); | 
|  | 2517 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2518 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2519 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2520 | } |