Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandObject.cpp ---------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "lldb/Interpreter/CommandObject.h" |
| 13 | |
| 14 | #include <string> |
| 15 | #include <map> |
| 16 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include <stdlib.h> |
| 18 | #include <ctype.h> |
| 19 | |
| 20 | #include "lldb/Core/Address.h" |
Johnny Chen | ca7835c | 2012-05-26 00:32:39 +0000 | [diff] [blame] | 21 | #include "lldb/Core/ArchSpec.h" |
Jim Ingham | 40af72e | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 22 | #include "lldb/Interpreter/Options.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | |
| 24 | // These are for the Sourcename completers. |
| 25 | // FIXME: Make a separate file for the completers. |
Greg Clayton | 53239f0 | 2011-02-08 05:05:52 +0000 | [diff] [blame] | 26 | #include "lldb/Host/FileSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "lldb/Core/FileSpecList.h" |
Zachary Turner | a78bd7f | 2015-03-03 23:11:11 +0000 | [diff] [blame] | 28 | #include "lldb/DataFormatters/FormatManager.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Target/Process.h" |
| 30 | #include "lldb/Target/Target.h" |
| 31 | |
| 32 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 33 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 34 | #include "lldb/Interpreter/ScriptInterpreter.h" |
| 35 | #include "lldb/Interpreter/ScriptInterpreterPython.h" |
| 36 | |
| 37 | using namespace lldb; |
| 38 | using namespace lldb_private; |
| 39 | |
| 40 | //------------------------------------------------------------------------- |
| 41 | // CommandObject |
| 42 | //------------------------------------------------------------------------- |
| 43 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 44 | CommandObject::CommandObject |
| 45 | ( |
| 46 | CommandInterpreter &interpreter, |
| 47 | const char *name, |
| 48 | const char *help, |
| 49 | const char *syntax, |
| 50 | uint32_t flags |
| 51 | ) : |
| 52 | m_interpreter (interpreter), |
Enrico Granata | 2f02fe0 | 2014-12-05 20:59:08 +0000 | [diff] [blame] | 53 | m_cmd_name (name ? name : ""), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | m_cmd_help_short (), |
| 55 | m_cmd_help_long (), |
| 56 | m_cmd_syntax (), |
Jim Ingham | 279a6c2 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 57 | m_is_alias (false), |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 58 | m_flags (flags), |
Greg Clayton | a9f7b79 | 2012-02-29 04:21:24 +0000 | [diff] [blame] | 59 | m_arguments(), |
Jim Ingham | 6d8873f | 2014-08-06 00:24:38 +0000 | [diff] [blame] | 60 | m_deprecated_command_override_callback (nullptr), |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 61 | m_command_override_callback (nullptr), |
| 62 | m_command_override_baton (nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | { |
| 64 | if (help && help[0]) |
| 65 | m_cmd_help_short = help; |
| 66 | if (syntax && syntax[0]) |
| 67 | m_cmd_syntax = syntax; |
| 68 | } |
| 69 | |
| 70 | CommandObject::~CommandObject () |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | const char * |
| 75 | CommandObject::GetHelp () |
| 76 | { |
| 77 | return m_cmd_help_short.c_str(); |
| 78 | } |
| 79 | |
| 80 | const char * |
| 81 | CommandObject::GetHelpLong () |
| 82 | { |
| 83 | return m_cmd_help_long.c_str(); |
| 84 | } |
| 85 | |
| 86 | const char * |
| 87 | CommandObject::GetSyntax () |
| 88 | { |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 89 | if (m_cmd_syntax.length() == 0) |
| 90 | { |
| 91 | StreamString syntax_str; |
| 92 | syntax_str.Printf ("%s", GetCommandName()); |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 93 | if (GetOptions() != nullptr) |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 94 | syntax_str.Printf (" <cmd-options>"); |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 95 | if (m_arguments.size() > 0) |
| 96 | { |
| 97 | syntax_str.Printf (" "); |
Enrico Granata | ca5acdb | 2013-06-18 01:17:46 +0000 | [diff] [blame] | 98 | if (WantsRawCommandString() && GetOptions() && GetOptions()->NumCommandOptions()) |
Sean Callanan | a4c6ad1 | 2012-01-04 19:11:25 +0000 | [diff] [blame] | 99 | syntax_str.Printf("-- "); |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 100 | GetFormattedCommandArguments (syntax_str); |
| 101 | } |
| 102 | m_cmd_syntax = syntax_str.GetData (); |
| 103 | } |
| 104 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 105 | return m_cmd_syntax.c_str(); |
| 106 | } |
| 107 | |
| 108 | const char * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 109 | CommandObject::GetCommandName () |
| 110 | { |
| 111 | return m_cmd_name.c_str(); |
| 112 | } |
| 113 | |
| 114 | void |
| 115 | CommandObject::SetCommandName (const char *name) |
| 116 | { |
| 117 | m_cmd_name = name; |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | CommandObject::SetHelp (const char *cstr) |
| 122 | { |
| 123 | m_cmd_help_short = cstr; |
| 124 | } |
| 125 | |
| 126 | void |
Enrico Granata | 6f79bb2 | 2015-03-13 22:22:28 +0000 | [diff] [blame] | 127 | CommandObject::SetHelp (std::string str) |
| 128 | { |
| 129 | m_cmd_help_short = str; |
| 130 | } |
| 131 | |
| 132 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 133 | CommandObject::SetHelpLong (const char *cstr) |
| 134 | { |
| 135 | m_cmd_help_long = cstr; |
| 136 | } |
| 137 | |
| 138 | void |
Enrico Granata | 99f0b8f | 2011-08-17 01:30:04 +0000 | [diff] [blame] | 139 | CommandObject::SetHelpLong (std::string str) |
| 140 | { |
| 141 | m_cmd_help_long = str; |
| 142 | } |
| 143 | |
| 144 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | CommandObject::SetSyntax (const char *cstr) |
| 146 | { |
| 147 | m_cmd_syntax = cstr; |
| 148 | } |
| 149 | |
| 150 | Options * |
| 151 | CommandObject::GetOptions () |
| 152 | { |
| 153 | // By default commands don't have options unless this virtual function |
| 154 | // is overridden by base classes. |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 155 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 158 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 159 | CommandObject::ParseOptions |
| 160 | ( |
| 161 | Args& args, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 162 | CommandReturnObject &result |
| 163 | ) |
| 164 | { |
| 165 | // See if the subclass has options? |
| 166 | Options *options = GetOptions(); |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 167 | if (options != nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 168 | { |
| 169 | Error error; |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 170 | options->NotifyOptionParsingStarting(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 171 | |
Greg Clayton | b7ad58a | 2013-04-04 20:35:24 +0000 | [diff] [blame] | 172 | // ParseOptions calls getopt_long_only, which always skips the zero'th item in the array and starts at position 1, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 173 | // so we need to push a dummy value into position zero. |
| 174 | args.Unshift("dummy_string"); |
| 175 | error = args.ParseOptions (*options); |
| 176 | |
| 177 | // The "dummy_string" will have already been removed by ParseOptions, |
| 178 | // so no need to remove it. |
| 179 | |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 180 | if (error.Success()) |
| 181 | error = options->NotifyOptionParsingFinished(); |
| 182 | |
| 183 | if (error.Success()) |
| 184 | { |
| 185 | if (options->VerifyOptions (result)) |
| 186 | return true; |
| 187 | } |
| 188 | else |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 189 | { |
| 190 | const char *error_cstr = error.AsCString(); |
| 191 | if (error_cstr) |
| 192 | { |
| 193 | // We got an error string, lets use that |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 194 | result.AppendError(error_cstr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 195 | } |
| 196 | else |
| 197 | { |
| 198 | // No error string, output the usage information into result |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 199 | options->GenerateOptionUsage (result.GetErrorStream(), this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 200 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 201 | } |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 202 | result.SetStatus (eReturnStatusFailed); |
| 203 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 204 | } |
| 205 | return true; |
| 206 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 207 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 208 | |
| 209 | |
| 210 | bool |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 211 | CommandObject::CheckRequirements (CommandReturnObject &result) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 212 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 213 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 214 | // Nothing should be stored in m_exe_ctx between running commands as m_exe_ctx |
| 215 | // has shared pointers to the target, process, thread and frame and we don't |
| 216 | // want any CommandObject instances to keep any of these objects around |
| 217 | // longer than for a single command. Every command should call |
| 218 | // CommandObject::Cleanup() after it has completed |
| 219 | assert (m_exe_ctx.GetTargetPtr() == NULL); |
| 220 | assert (m_exe_ctx.GetProcessPtr() == NULL); |
| 221 | assert (m_exe_ctx.GetThreadPtr() == NULL); |
| 222 | assert (m_exe_ctx.GetFramePtr() == NULL); |
| 223 | #endif |
| 224 | |
| 225 | // Lock down the interpreter's execution context prior to running the |
| 226 | // command so we guarantee the selected target, process, thread and frame |
| 227 | // can't go away during the execution |
| 228 | m_exe_ctx = m_interpreter.GetExecutionContext(); |
| 229 | |
| 230 | const uint32_t flags = GetFlags().Get(); |
| 231 | if (flags & (eFlagRequiresTarget | |
| 232 | eFlagRequiresProcess | |
| 233 | eFlagRequiresThread | |
| 234 | eFlagRequiresFrame | |
| 235 | eFlagTryTargetAPILock )) |
| 236 | { |
| 237 | |
| 238 | if ((flags & eFlagRequiresTarget) && !m_exe_ctx.HasTargetScope()) |
| 239 | { |
| 240 | result.AppendError (GetInvalidTargetDescription()); |
| 241 | return false; |
| 242 | } |
| 243 | |
| 244 | if ((flags & eFlagRequiresProcess) && !m_exe_ctx.HasProcessScope()) |
| 245 | { |
Jason Molenda | e59b0d2 | 2014-09-20 09:14:31 +0000 | [diff] [blame] | 246 | if (!m_exe_ctx.HasTargetScope()) |
| 247 | result.AppendError (GetInvalidTargetDescription()); |
| 248 | else |
| 249 | result.AppendError (GetInvalidProcessDescription()); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 250 | return false; |
| 251 | } |
| 252 | |
| 253 | if ((flags & eFlagRequiresThread) && !m_exe_ctx.HasThreadScope()) |
| 254 | { |
Jason Molenda | e59b0d2 | 2014-09-20 09:14:31 +0000 | [diff] [blame] | 255 | if (!m_exe_ctx.HasTargetScope()) |
| 256 | result.AppendError (GetInvalidTargetDescription()); |
| 257 | else if (!m_exe_ctx.HasProcessScope()) |
| 258 | result.AppendError (GetInvalidProcessDescription()); |
| 259 | else |
| 260 | result.AppendError (GetInvalidThreadDescription()); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 261 | return false; |
| 262 | } |
| 263 | |
| 264 | if ((flags & eFlagRequiresFrame) && !m_exe_ctx.HasFrameScope()) |
| 265 | { |
Jason Molenda | e59b0d2 | 2014-09-20 09:14:31 +0000 | [diff] [blame] | 266 | if (!m_exe_ctx.HasTargetScope()) |
| 267 | result.AppendError (GetInvalidTargetDescription()); |
| 268 | else if (!m_exe_ctx.HasProcessScope()) |
| 269 | result.AppendError (GetInvalidProcessDescription()); |
| 270 | else if (!m_exe_ctx.HasThreadScope()) |
| 271 | result.AppendError (GetInvalidThreadDescription()); |
| 272 | else |
| 273 | result.AppendError (GetInvalidFrameDescription()); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 274 | return false; |
| 275 | } |
| 276 | |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 277 | if ((flags & eFlagRequiresRegContext) && (m_exe_ctx.GetRegisterContext() == nullptr)) |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 278 | { |
| 279 | result.AppendError (GetInvalidRegContextDescription()); |
| 280 | return false; |
| 281 | } |
| 282 | |
| 283 | if (flags & eFlagTryTargetAPILock) |
| 284 | { |
| 285 | Target *target = m_exe_ctx.GetTargetPtr(); |
| 286 | if (target) |
Greg Clayton | 9b5442a | 2014-02-07 22:31:20 +0000 | [diff] [blame] | 287 | m_api_locker.Lock (target->GetAPIMutex()); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 291 | if (GetFlags().AnySet (CommandObject::eFlagProcessMustBeLaunched | CommandObject::eFlagProcessMustBePaused)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 292 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 293 | Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 294 | if (process == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 295 | { |
Jim Ingham | b8e8a5f | 2011-07-09 00:55:34 +0000 | [diff] [blame] | 296 | // A process that is not running is considered paused. |
| 297 | if (GetFlags().Test(CommandObject::eFlagProcessMustBeLaunched)) |
| 298 | { |
| 299 | result.AppendError ("Process must exist."); |
| 300 | result.SetStatus (eReturnStatusFailed); |
| 301 | return false; |
| 302 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 303 | } |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 304 | else |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 305 | { |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 306 | StateType state = process->GetState(); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 307 | switch (state) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 308 | { |
Greg Clayton | 7a5388b | 2011-03-20 04:57:14 +0000 | [diff] [blame] | 309 | case eStateInvalid: |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 310 | case eStateSuspended: |
| 311 | case eStateCrashed: |
| 312 | case eStateStopped: |
| 313 | break; |
| 314 | |
| 315 | case eStateConnected: |
| 316 | case eStateAttaching: |
| 317 | case eStateLaunching: |
| 318 | case eStateDetached: |
| 319 | case eStateExited: |
| 320 | case eStateUnloaded: |
| 321 | if (GetFlags().Test(CommandObject::eFlagProcessMustBeLaunched)) |
| 322 | { |
| 323 | result.AppendError ("Process must be launched."); |
| 324 | result.SetStatus (eReturnStatusFailed); |
| 325 | return false; |
| 326 | } |
| 327 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 328 | |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 329 | case eStateRunning: |
| 330 | case eStateStepping: |
| 331 | if (GetFlags().Test(CommandObject::eFlagProcessMustBePaused)) |
| 332 | { |
| 333 | result.AppendError ("Process is running. Use 'process interrupt' to pause execution."); |
| 334 | result.SetStatus (eReturnStatusFailed); |
| 335 | return false; |
| 336 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 340 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 343 | void |
| 344 | CommandObject::Cleanup () |
| 345 | { |
| 346 | m_exe_ctx.Clear(); |
| 347 | m_api_locker.Unlock(); |
| 348 | } |
| 349 | |
| 350 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 351 | class CommandDictCommandPartialMatch |
| 352 | { |
| 353 | public: |
| 354 | CommandDictCommandPartialMatch (const char *match_str) |
| 355 | { |
| 356 | m_match_str = match_str; |
| 357 | } |
| 358 | bool operator() (const std::pair<std::string, lldb::CommandObjectSP> map_element) const |
| 359 | { |
| 360 | // A NULL or empty string matches everything. |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 361 | if (m_match_str == nullptr || *m_match_str == '\0') |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 362 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 363 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 364 | return map_element.first.find (m_match_str, 0) == 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | private: |
| 368 | const char *m_match_str; |
| 369 | }; |
| 370 | |
| 371 | int |
| 372 | CommandObject::AddNamesMatchingPartialString (CommandObject::CommandMap &in_map, const char *cmd_str, |
| 373 | StringList &matches) |
| 374 | { |
| 375 | int number_added = 0; |
| 376 | CommandDictCommandPartialMatch matcher(cmd_str); |
| 377 | |
| 378 | CommandObject::CommandMap::iterator matching_cmds = std::find_if (in_map.begin(), in_map.end(), matcher); |
| 379 | |
| 380 | while (matching_cmds != in_map.end()) |
| 381 | { |
| 382 | ++number_added; |
| 383 | matches.AppendString((*matching_cmds).first.c_str()); |
| 384 | matching_cmds = std::find_if (++matching_cmds, in_map.end(), matcher);; |
| 385 | } |
| 386 | return number_added; |
| 387 | } |
| 388 | |
| 389 | int |
| 390 | CommandObject::HandleCompletion |
| 391 | ( |
| 392 | Args &input, |
| 393 | int &cursor_index, |
| 394 | int &cursor_char_position, |
| 395 | int match_start_point, |
| 396 | int max_return_elements, |
Jim Ingham | 558ce12 | 2010-06-30 05:02:46 +0000 | [diff] [blame] | 397 | bool &word_complete, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 398 | StringList &matches |
| 399 | ) |
| 400 | { |
Johnny Chen | 6561d15 | 2012-01-20 00:59:19 +0000 | [diff] [blame] | 401 | // Default implmentation of WantsCompletion() is !WantsRawCommandString(). |
| 402 | // Subclasses who want raw command string but desire, for example, |
| 403 | // argument completion should override WantsCompletion() to return true, |
| 404 | // instead. |
Johnny Chen | 6f99b63 | 2012-01-19 22:16:06 +0000 | [diff] [blame] | 405 | if (WantsRawCommandString() && !WantsCompletion()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 406 | { |
| 407 | // FIXME: Abstract telling the completion to insert the completion character. |
| 408 | matches.Clear(); |
| 409 | return -1; |
| 410 | } |
| 411 | else |
| 412 | { |
| 413 | // Can we do anything generic with the options? |
| 414 | Options *cur_options = GetOptions(); |
| 415 | CommandReturnObject result; |
| 416 | OptionElementVector opt_element_vector; |
| 417 | |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 418 | if (cur_options != nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 419 | { |
| 420 | // Re-insert the dummy command name string which will have been |
| 421 | // stripped off: |
| 422 | input.Unshift ("dummy-string"); |
| 423 | cursor_index++; |
| 424 | |
| 425 | |
| 426 | // I stick an element on the end of the input, because if the last element is |
Greg Clayton | b7ad58a | 2013-04-04 20:35:24 +0000 | [diff] [blame] | 427 | // option that requires an argument, getopt_long_only will freak out. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 428 | |
| 429 | input.AppendArgument ("<FAKE-VALUE>"); |
| 430 | |
Jim Ingham | d43e009 | 2010-06-24 20:31:04 +0000 | [diff] [blame] | 431 | input.ParseArgsForCompletion (*cur_options, opt_element_vector, cursor_index); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 432 | |
| 433 | input.DeleteArgumentAtIndex(input.GetArgumentCount() - 1); |
| 434 | |
| 435 | bool handled_by_options; |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 436 | handled_by_options = cur_options->HandleOptionCompletion (input, |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 437 | opt_element_vector, |
| 438 | cursor_index, |
| 439 | cursor_char_position, |
| 440 | match_start_point, |
| 441 | max_return_elements, |
Jim Ingham | 558ce12 | 2010-06-30 05:02:46 +0000 | [diff] [blame] | 442 | word_complete, |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 443 | matches); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 444 | if (handled_by_options) |
| 445 | return matches.GetSize(); |
| 446 | } |
| 447 | |
| 448 | // If we got here, the last word is not an option or an option argument. |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 449 | return HandleArgumentCompletion (input, |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 450 | cursor_index, |
| 451 | cursor_char_position, |
| 452 | opt_element_vector, |
| 453 | match_start_point, |
| 454 | max_return_elements, |
Jim Ingham | 558ce12 | 2010-06-30 05:02:46 +0000 | [diff] [blame] | 455 | word_complete, |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 456 | matches); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 460 | bool |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 461 | CommandObject::HelpTextContainsWord (const char *search_word) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 462 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 463 | std::string options_usage_help; |
| 464 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 465 | bool found_word = false; |
| 466 | |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 467 | const char *short_help = GetHelp(); |
| 468 | const char *long_help = GetHelpLong(); |
| 469 | const char *syntax_help = GetSyntax(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 470 | |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 471 | if (short_help && strcasestr (short_help, search_word)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 472 | found_word = true; |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 473 | else if (long_help && strcasestr (long_help, search_word)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 474 | found_word = true; |
Greg Clayton | 998255b | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 475 | else if (syntax_help && strcasestr (syntax_help, search_word)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 476 | found_word = true; |
| 477 | |
| 478 | if (!found_word |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 479 | && GetOptions() != nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 480 | { |
| 481 | StreamString usage_help; |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 482 | GetOptions()->GenerateOptionUsage (usage_help, this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 483 | if (usage_help.GetSize() > 0) |
| 484 | { |
| 485 | const char *usage_text = usage_help.GetData(); |
Caroline Tice | 4b6fbf3 | 2010-10-12 22:16:53 +0000 | [diff] [blame] | 486 | if (strcasestr (usage_text, search_word)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 487 | found_word = true; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | return found_word; |
| 492 | } |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 493 | |
| 494 | int |
| 495 | CommandObject::GetNumArgumentEntries () |
| 496 | { |
| 497 | return m_arguments.size(); |
| 498 | } |
| 499 | |
| 500 | CommandObject::CommandArgumentEntry * |
| 501 | CommandObject::GetArgumentEntryAtIndex (int idx) |
| 502 | { |
Saleem Abdulrasool | 3985c8c | 2014-04-02 03:51:35 +0000 | [diff] [blame] | 503 | if (static_cast<size_t>(idx) < m_arguments.size()) |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 504 | return &(m_arguments[idx]); |
| 505 | |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 506 | return nullptr; |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | CommandObject::ArgumentTableEntry * |
| 510 | CommandObject::FindArgumentDataByType (CommandArgumentType arg_type) |
| 511 | { |
| 512 | const ArgumentTableEntry *table = CommandObject::GetArgumentTable(); |
| 513 | |
| 514 | for (int i = 0; i < eArgTypeLastArg; ++i) |
| 515 | if (table[i].arg_type == arg_type) |
| 516 | return (ArgumentTableEntry *) &(table[i]); |
| 517 | |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 518 | return nullptr; |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | void |
| 522 | CommandObject::GetArgumentHelp (Stream &str, CommandArgumentType arg_type, CommandInterpreter &interpreter) |
| 523 | { |
| 524 | const ArgumentTableEntry* table = CommandObject::GetArgumentTable(); |
| 525 | ArgumentTableEntry *entry = (ArgumentTableEntry *) &(table[arg_type]); |
| 526 | |
| 527 | // The table is *supposed* to be kept in arg_type order, but someone *could* have messed it up... |
| 528 | |
| 529 | if (entry->arg_type != arg_type) |
| 530 | entry = CommandObject::FindArgumentDataByType (arg_type); |
| 531 | |
| 532 | if (!entry) |
| 533 | return; |
| 534 | |
| 535 | StreamString name_str; |
| 536 | name_str.Printf ("<%s>", entry->arg_name); |
| 537 | |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 538 | if (entry->help_function) |
Enrico Granata | 82a7d98 | 2011-07-07 00:38:40 +0000 | [diff] [blame] | 539 | { |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 540 | const char* help_text = entry->help_function(); |
Enrico Granata | 82a7d98 | 2011-07-07 00:38:40 +0000 | [diff] [blame] | 541 | if (!entry->help_function.self_formatting) |
| 542 | { |
| 543 | interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", help_text, |
| 544 | name_str.GetSize()); |
| 545 | } |
| 546 | else |
| 547 | { |
| 548 | interpreter.OutputHelpText(str, name_str.GetData(), "--", help_text, |
| 549 | name_str.GetSize()); |
| 550 | } |
| 551 | } |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 552 | else |
| 553 | interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", entry->help_text, name_str.GetSize()); |
| 554 | } |
| 555 | |
| 556 | const char * |
| 557 | CommandObject::GetArgumentName (CommandArgumentType arg_type) |
| 558 | { |
Caroline Tice | deaab22 | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 559 | ArgumentTableEntry *entry = (ArgumentTableEntry *) &(CommandObject::GetArgumentTable()[arg_type]); |
| 560 | |
| 561 | // The table is *supposed* to be kept in arg_type order, but someone *could* have messed it up... |
| 562 | |
| 563 | if (entry->arg_type != arg_type) |
| 564 | entry = CommandObject::FindArgumentDataByType (arg_type); |
| 565 | |
Johnny Chen | e6acf35 | 2010-10-08 22:01:52 +0000 | [diff] [blame] | 566 | if (entry) |
| 567 | return entry->arg_name; |
| 568 | |
| 569 | StreamString str; |
| 570 | str << "Arg name for type (" << arg_type << ") not in arg table!"; |
| 571 | return str.GetData(); |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 574 | bool |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 575 | CommandObject::IsPairType (ArgumentRepetitionType arg_repeat_type) |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 576 | { |
| 577 | if ((arg_repeat_type == eArgRepeatPairPlain) |
| 578 | || (arg_repeat_type == eArgRepeatPairOptional) |
| 579 | || (arg_repeat_type == eArgRepeatPairPlus) |
| 580 | || (arg_repeat_type == eArgRepeatPairStar) |
| 581 | || (arg_repeat_type == eArgRepeatPairRange) |
| 582 | || (arg_repeat_type == eArgRepeatPairRangeOptional)) |
| 583 | return true; |
| 584 | |
| 585 | return false; |
| 586 | } |
| 587 | |
Johnny Chen | 34ddc8d | 2012-02-08 01:13:31 +0000 | [diff] [blame] | 588 | static CommandObject::CommandArgumentEntry |
| 589 | OptSetFiltered(uint32_t opt_set_mask, CommandObject::CommandArgumentEntry &cmd_arg_entry) |
| 590 | { |
| 591 | CommandObject::CommandArgumentEntry ret_val; |
| 592 | for (unsigned i = 0; i < cmd_arg_entry.size(); ++i) |
| 593 | if (opt_set_mask & cmd_arg_entry[i].arg_opt_set_association) |
| 594 | ret_val.push_back(cmd_arg_entry[i]); |
| 595 | return ret_val; |
| 596 | } |
| 597 | |
| 598 | // Default parameter value of opt_set_mask is LLDB_OPT_SET_ALL, which means take |
| 599 | // all the argument data into account. On rare cases where some argument sticks |
| 600 | // with certain option sets, this function returns the option set filtered args. |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 601 | void |
Johnny Chen | 34ddc8d | 2012-02-08 01:13:31 +0000 | [diff] [blame] | 602 | CommandObject::GetFormattedCommandArguments (Stream &str, uint32_t opt_set_mask) |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 603 | { |
| 604 | int num_args = m_arguments.size(); |
| 605 | for (int i = 0; i < num_args; ++i) |
| 606 | { |
| 607 | if (i > 0) |
| 608 | str.Printf (" "); |
Johnny Chen | 34ddc8d | 2012-02-08 01:13:31 +0000 | [diff] [blame] | 609 | CommandArgumentEntry arg_entry = |
| 610 | opt_set_mask == LLDB_OPT_SET_ALL ? m_arguments[i] |
| 611 | : OptSetFiltered(opt_set_mask, m_arguments[i]); |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 612 | int num_alternatives = arg_entry.size(); |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 613 | |
| 614 | if ((num_alternatives == 2) |
| 615 | && IsPairType (arg_entry[0].arg_repetition)) |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 616 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 617 | const char *first_name = GetArgumentName (arg_entry[0].arg_type); |
| 618 | const char *second_name = GetArgumentName (arg_entry[1].arg_type); |
| 619 | switch (arg_entry[0].arg_repetition) |
| 620 | { |
| 621 | case eArgRepeatPairPlain: |
| 622 | str.Printf ("<%s> <%s>", first_name, second_name); |
| 623 | break; |
| 624 | case eArgRepeatPairOptional: |
| 625 | str.Printf ("[<%s> <%s>]", first_name, second_name); |
| 626 | break; |
| 627 | case eArgRepeatPairPlus: |
| 628 | str.Printf ("<%s> <%s> [<%s> <%s> [...]]", first_name, second_name, first_name, second_name); |
| 629 | break; |
| 630 | case eArgRepeatPairStar: |
| 631 | str.Printf ("[<%s> <%s> [<%s> <%s> [...]]]", first_name, second_name, first_name, second_name); |
| 632 | break; |
| 633 | case eArgRepeatPairRange: |
| 634 | str.Printf ("<%s_1> <%s_1> ... <%s_n> <%s_n>", first_name, second_name, first_name, second_name); |
| 635 | break; |
| 636 | case eArgRepeatPairRangeOptional: |
| 637 | str.Printf ("[<%s_1> <%s_1> ... <%s_n> <%s_n>]", first_name, second_name, first_name, second_name); |
| 638 | break; |
Caroline Tice | ca1176a | 2011-03-23 22:31:13 +0000 | [diff] [blame] | 639 | // Explicitly test for all the rest of the cases, so if new types get added we will notice the |
| 640 | // missing case statement(s). |
| 641 | case eArgRepeatPlain: |
| 642 | case eArgRepeatOptional: |
| 643 | case eArgRepeatPlus: |
| 644 | case eArgRepeatStar: |
| 645 | case eArgRepeatRange: |
| 646 | // These should not be reached, as they should fail the IsPairType test above. |
| 647 | break; |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 648 | } |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 649 | } |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 650 | else |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 651 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 652 | StreamString names; |
| 653 | for (int j = 0; j < num_alternatives; ++j) |
| 654 | { |
| 655 | if (j > 0) |
| 656 | names.Printf (" | "); |
| 657 | names.Printf ("%s", GetArgumentName (arg_entry[j].arg_type)); |
| 658 | } |
| 659 | switch (arg_entry[0].arg_repetition) |
| 660 | { |
| 661 | case eArgRepeatPlain: |
| 662 | str.Printf ("<%s>", names.GetData()); |
| 663 | break; |
| 664 | case eArgRepeatPlus: |
| 665 | str.Printf ("<%s> [<%s> [...]]", names.GetData(), names.GetData()); |
| 666 | break; |
| 667 | case eArgRepeatStar: |
| 668 | str.Printf ("[<%s> [<%s> [...]]]", names.GetData(), names.GetData()); |
| 669 | break; |
| 670 | case eArgRepeatOptional: |
| 671 | str.Printf ("[<%s>]", names.GetData()); |
| 672 | break; |
| 673 | case eArgRepeatRange: |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 674 | str.Printf ("<%s_1> .. <%s_n>", names.GetData(), names.GetData()); |
Caroline Tice | ca1176a | 2011-03-23 22:31:13 +0000 | [diff] [blame] | 675 | break; |
| 676 | // Explicitly test for all the rest of the cases, so if new types get added we will notice the |
| 677 | // missing case statement(s). |
| 678 | case eArgRepeatPairPlain: |
| 679 | case eArgRepeatPairOptional: |
| 680 | case eArgRepeatPairPlus: |
| 681 | case eArgRepeatPairStar: |
| 682 | case eArgRepeatPairRange: |
| 683 | case eArgRepeatPairRangeOptional: |
| 684 | // These should not be hit, as they should pass the IsPairType test above, and control should |
| 685 | // have gone into the other branch of the if statement. |
| 686 | break; |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 687 | } |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
Stephen Wilson | 0c16aa6 | 2011-03-23 02:12:10 +0000 | [diff] [blame] | 692 | CommandArgumentType |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 693 | CommandObject::LookupArgumentName (const char *arg_name) |
| 694 | { |
| 695 | CommandArgumentType return_type = eArgTypeLastArg; |
| 696 | |
| 697 | std::string arg_name_str (arg_name); |
| 698 | size_t len = arg_name_str.length(); |
| 699 | if (arg_name[0] == '<' |
| 700 | && arg_name[len-1] == '>') |
| 701 | arg_name_str = arg_name_str.substr (1, len-2); |
| 702 | |
Johnny Chen | 331eff3 | 2011-07-14 22:20:12 +0000 | [diff] [blame] | 703 | const ArgumentTableEntry *table = GetArgumentTable(); |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 704 | for (int i = 0; i < eArgTypeLastArg; ++i) |
Johnny Chen | 331eff3 | 2011-07-14 22:20:12 +0000 | [diff] [blame] | 705 | if (arg_name_str.compare (table[i].arg_name) == 0) |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 706 | return_type = g_arguments_data[i].arg_type; |
| 707 | |
| 708 | return return_type; |
| 709 | } |
| 710 | |
| 711 | static const char * |
Jim Ingham | 931e674 | 2012-08-23 23:37:31 +0000 | [diff] [blame] | 712 | RegisterNameHelpTextCallback () |
| 713 | { |
| 714 | return "Register names can be specified using the architecture specific names. " |
Jim Ingham | 84c7bd7 | 2012-08-23 23:47:08 +0000 | [diff] [blame] | 715 | "They can also be specified using generic names. Not all generic entities have " |
| 716 | "registers backing them on all architectures. When they don't the generic name " |
| 717 | "will return an error.\n" |
Jim Ingham | 931e674 | 2012-08-23 23:37:31 +0000 | [diff] [blame] | 718 | "The generic names defined in lldb are:\n" |
| 719 | "\n" |
| 720 | "pc - program counter register\n" |
| 721 | "ra - return address register\n" |
| 722 | "fp - frame pointer register\n" |
| 723 | "sp - stack pointer register\n" |
Jim Ingham | 84c7bd7 | 2012-08-23 23:47:08 +0000 | [diff] [blame] | 724 | "flags - the flags register\n" |
Jim Ingham | 931e674 | 2012-08-23 23:37:31 +0000 | [diff] [blame] | 725 | "arg{1-6} - integer argument passing registers.\n"; |
| 726 | } |
| 727 | |
| 728 | static const char * |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 729 | BreakpointIDHelpTextCallback () |
| 730 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 731 | return "Breakpoint ID's consist major and minor numbers; the major number " |
| 732 | "corresponds to the single entity that was created with a 'breakpoint set' " |
| 733 | "command; the minor numbers correspond to all the locations that were actually " |
| 734 | "found/set based on the major breakpoint. A full breakpoint ID might look like " |
| 735 | "3.14, meaning the 14th location set for the 3rd breakpoint. You can specify " |
| 736 | "all the locations of a breakpoint by just indicating the major breakpoint " |
| 737 | "number. A valid breakpoint id consists either of just the major id number, " |
| 738 | "or the major number, a dot, and the location number (e.g. 3 or 3.2 could " |
| 739 | "both be valid breakpoint ids)."; |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | static const char * |
| 743 | BreakpointIDRangeHelpTextCallback () |
| 744 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 745 | return "A 'breakpoint id list' is a manner of specifying multiple breakpoints. " |
| 746 | "This can be done through several mechanisms. The easiest way is to just " |
| 747 | "enter a space-separated list of breakpoint ids. To specify all the " |
| 748 | "breakpoint locations under a major breakpoint, you can use the major " |
| 749 | "breakpoint number followed by '.*', eg. '5.*' means all the locations under " |
| 750 | "breakpoint 5. You can also indicate a range of breakpoints by using " |
| 751 | "<start-bp-id> - <end-bp-id>. The start-bp-id and end-bp-id for a range can " |
| 752 | "be any valid breakpoint ids. It is not legal, however, to specify a range " |
| 753 | "using specific locations that cross major breakpoint numbers. I.e. 3.2 - 3.7" |
| 754 | " is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal."; |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 755 | } |
| 756 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 757 | static const char * |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 758 | BreakpointNameHelpTextCallback () |
| 759 | { |
| 760 | return "A name that can be added to a breakpoint when it is created, or later " |
| 761 | "on with the \"breakpoint name add\" command. " |
| 762 | "Breakpoint names can be used to specify breakpoints in all the places breakpoint ID's " |
| 763 | "and breakpoint ID ranges can be used. As such they provide a convenient way to group breakpoints, " |
| 764 | "and to operate on breakpoints you create without having to track the breakpoint number. " |
| 765 | "Note, the attributes you set when using a breakpoint name in a breakpoint command don't " |
| 766 | "adhere to the name, but instead are set individually on all the breakpoints currently tagged with that name. Future breakpoints " |
| 767 | "tagged with that name will not pick up the attributes previously given using that name. " |
| 768 | "In order to distinguish breakpoint names from breakpoint ID's and ranges, " |
| 769 | "names must start with a letter from a-z or A-Z and cannot contain spaces, \".\" or \"-\". " |
| 770 | "Also, breakpoint names can only be applied to breakpoints, not to breakpoint locations."; |
| 771 | } |
| 772 | |
| 773 | static const char * |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 774 | GDBFormatHelpTextCallback () |
| 775 | { |
Greg Clayton | f91381e | 2011-10-26 18:35:21 +0000 | [diff] [blame] | 776 | return "A GDB format consists of a repeat count, a format letter and a size letter. " |
| 777 | "The repeat count is optional and defaults to 1. The format letter is optional " |
| 778 | "and defaults to the previous format that was used. The size letter is optional " |
| 779 | "and defaults to the previous size that was used.\n" |
| 780 | "\n" |
| 781 | "Format letters include:\n" |
| 782 | "o - octal\n" |
| 783 | "x - hexadecimal\n" |
| 784 | "d - decimal\n" |
| 785 | "u - unsigned decimal\n" |
| 786 | "t - binary\n" |
| 787 | "f - float\n" |
| 788 | "a - address\n" |
| 789 | "i - instruction\n" |
| 790 | "c - char\n" |
| 791 | "s - string\n" |
| 792 | "T - OSType\n" |
| 793 | "A - float as hex\n" |
| 794 | "\n" |
| 795 | "Size letters include:\n" |
| 796 | "b - 1 byte (byte)\n" |
| 797 | "h - 2 bytes (halfword)\n" |
| 798 | "w - 4 bytes (word)\n" |
| 799 | "g - 8 bytes (giant)\n" |
| 800 | "\n" |
| 801 | "Example formats:\n" |
| 802 | "32xb - show 32 1 byte hexadecimal integer values\n" |
| 803 | "16xh - show 16 2 byte hexadecimal integer values\n" |
| 804 | "64 - show 64 2 byte hexadecimal integer values (format and size from the last format)\n" |
| 805 | "dw - show 1 4 byte decimal integer value\n" |
| 806 | ; |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | static const char * |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 810 | FormatHelpTextCallback () |
| 811 | { |
Enrico Granata | 82a7d98 | 2011-07-07 00:38:40 +0000 | [diff] [blame] | 812 | |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 813 | static char* help_text_ptr = nullptr; |
Enrico Granata | 82a7d98 | 2011-07-07 00:38:40 +0000 | [diff] [blame] | 814 | |
| 815 | if (help_text_ptr) |
| 816 | return help_text_ptr; |
| 817 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 818 | StreamString sstr; |
| 819 | sstr << "One of the format names (or one-character names) that can be used to show a variable's value:\n"; |
| 820 | for (Format f = eFormatDefault; f < kNumFormats; f = Format(f+1)) |
| 821 | { |
Enrico Granata | 82a7d98 | 2011-07-07 00:38:40 +0000 | [diff] [blame] | 822 | if (f != eFormatDefault) |
| 823 | sstr.PutChar('\n'); |
| 824 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 825 | char format_char = FormatManager::GetFormatAsFormatChar(f); |
| 826 | if (format_char) |
| 827 | sstr.Printf("'%c' or ", format_char); |
| 828 | |
Enrico Granata | 82a7d98 | 2011-07-07 00:38:40 +0000 | [diff] [blame] | 829 | sstr.Printf ("\"%s\"", FormatManager::GetFormatAsCString(f)); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | sstr.Flush(); |
| 833 | |
| 834 | std::string data = sstr.GetString(); |
| 835 | |
Enrico Granata | 82a7d98 | 2011-07-07 00:38:40 +0000 | [diff] [blame] | 836 | help_text_ptr = new char[data.length()+1]; |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 837 | |
Enrico Granata | 82a7d98 | 2011-07-07 00:38:40 +0000 | [diff] [blame] | 838 | data.copy(help_text_ptr, data.length()); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 839 | |
Enrico Granata | 82a7d98 | 2011-07-07 00:38:40 +0000 | [diff] [blame] | 840 | return help_text_ptr; |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | static const char * |
Sean Callanan | d947739 | 2012-10-23 00:50:09 +0000 | [diff] [blame] | 844 | LanguageTypeHelpTextCallback () |
| 845 | { |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 846 | static char* help_text_ptr = nullptr; |
Sean Callanan | d947739 | 2012-10-23 00:50:09 +0000 | [diff] [blame] | 847 | |
| 848 | if (help_text_ptr) |
| 849 | return help_text_ptr; |
| 850 | |
| 851 | StreamString sstr; |
| 852 | sstr << "One of the following languages:\n"; |
Jim Ingham | de50d36 | 2015-04-17 00:44:36 +0000 | [diff] [blame] | 853 | |
| 854 | LanguageRuntime::PrintAllLanguages(sstr, " ", "\n"); |
| 855 | |
Sean Callanan | d947739 | 2012-10-23 00:50:09 +0000 | [diff] [blame] | 856 | sstr.Flush(); |
| 857 | |
| 858 | std::string data = sstr.GetString(); |
| 859 | |
| 860 | help_text_ptr = new char[data.length()+1]; |
| 861 | |
| 862 | data.copy(help_text_ptr, data.length()); |
| 863 | |
| 864 | return help_text_ptr; |
| 865 | } |
| 866 | |
| 867 | static const char * |
Enrico Granata | 82a7d98 | 2011-07-07 00:38:40 +0000 | [diff] [blame] | 868 | SummaryStringHelpTextCallback() |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 869 | { |
Enrico Granata | 82a7d98 | 2011-07-07 00:38:40 +0000 | [diff] [blame] | 870 | return |
| 871 | "A summary string is a way to extract information from variables in order to present them using a summary.\n" |
| 872 | "Summary strings contain static text, variables, scopes and control sequences:\n" |
| 873 | " - Static text can be any sequence of non-special characters, i.e. anything but '{', '}', '$', or '\\'.\n" |
| 874 | " - Variables are sequences of characters beginning with ${, ending with } and that contain symbols in the format described below.\n" |
| 875 | " - Scopes are any sequence of text between { and }. Anything included in a scope will only appear in the output summary if there were no errors.\n" |
| 876 | " - Control sequences are the usual C/C++ '\\a', '\\n', ..., plus '\\$', '\\{' and '\\}'.\n" |
| 877 | "A summary string works by copying static text verbatim, turning control sequences into their character counterpart, expanding variables and trying to expand scopes.\n" |
| 878 | "A variable is expanded by giving it a value other than its textual representation, and the way this is done depends on what comes after the ${ marker.\n" |
| 879 | "The most common sequence if ${var followed by an expression path, which is the text one would type to access a member of an aggregate types, given a variable of that type" |
| 880 | " (e.g. if type T has a member named x, which has a member named y, and if t is of type T, the expression path would be .x.y and the way to fit that into a summary string would be" |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 881 | " ${var.x.y}). You can also use ${*var followed by an expression path and in that case the object referred by the path will be dereferenced before being displayed." |
| 882 | " If the object is not a pointer, doing so will cause an error. For additional details on expression paths, you can type 'help expr-path'. \n" |
Enrico Granata | 82a7d98 | 2011-07-07 00:38:40 +0000 | [diff] [blame] | 883 | "By default, summary strings attempt to display the summary for any variable they reference, and if that fails the value. If neither can be shown, nothing is displayed." |
| 884 | "In a summary string, you can also use an array index [n], or a slice-like range [n-m]. This can have two different meanings depending on what kind of object the expression" |
| 885 | " path refers to:\n" |
| 886 | " - if it is a scalar type (any basic type like int, float, ...) the expression is a bitfield, i.e. the bits indicated by the indexing operator are extracted out of the number" |
| 887 | " and displayed as an individual variable\n" |
| 888 | " - if it is an array or pointer the array items indicated by the indexing operator are shown as the result of the variable. if the expression is an array, real array items are" |
| 889 | " printed; if it is a pointer, the pointer-as-array syntax is used to obtain the values (this means, the latter case can have no range checking)\n" |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 890 | "If you are trying to display an array for which the size is known, you can also use [] instead of giving an exact range. This has the effect of showing items 0 thru size - 1.\n" |
| 891 | "Additionally, a variable can contain an (optional) format code, as in ${var.x.y%code}, where code can be any of the valid formats described in 'help format', or one of the" |
| 892 | " special symbols only allowed as part of a variable:\n" |
| 893 | " %V: show the value of the object by default\n" |
| 894 | " %S: show the summary of the object by default\n" |
| 895 | " %@: show the runtime-provided object description (for Objective-C, it calls NSPrintForDebugger; for C/C++ it does nothing)\n" |
| 896 | " %L: show the location of the object (memory address or a register name)\n" |
| 897 | " %#: show the number of children of the object\n" |
| 898 | " %T: show the type of the object\n" |
| 899 | "Another variable that you can use in summary strings is ${svar . This sequence works exactly like ${var, including the fact that ${*svar is an allowed sequence, but uses" |
| 900 | " the object's synthetic children provider instead of the actual objects. For instance, if you are using STL synthetic children providers, the following summary string would" |
| 901 | " count the number of actual elements stored in an std::list:\n" |
| 902 | "type summary add -s \"${svar%#}\" -x \"std::list<\""; |
| 903 | } |
| 904 | |
| 905 | static const char * |
| 906 | ExprPathHelpTextCallback() |
| 907 | { |
| 908 | return |
| 909 | "An expression path is the sequence of symbols that is used in C/C++ to access a member variable of an aggregate object (class).\n" |
| 910 | "For instance, given a class:\n" |
| 911 | " class foo {\n" |
| 912 | " int a;\n" |
| 913 | " int b; .\n" |
| 914 | " foo* next;\n" |
| 915 | " };\n" |
| 916 | "the expression to read item b in the item pointed to by next for foo aFoo would be aFoo.next->b.\n" |
| 917 | "Given that aFoo could just be any object of type foo, the string '.next->b' is the expression path, because it can be attached to any foo instance to achieve the effect.\n" |
| 918 | "Expression paths in LLDB include dot (.) and arrow (->) operators, and most commands using expression paths have ways to also accept the star (*) operator.\n" |
| 919 | "The meaning of these operators is the same as the usual one given to them by the C/C++ standards.\n" |
| 920 | "LLDB also has support for indexing ([ ]) in expression paths, and extends the traditional meaning of the square brackets operator to allow bitfield extraction:\n" |
| 921 | "for objects of native types (int, float, char, ...) saying '[n-m]' as an expression path (where n and m are any positive integers, e.g. [3-5]) causes LLDB to extract" |
| 922 | " bits n thru m from the value of the variable. If n == m, [n] is also allowed as a shortcut syntax. For arrays and pointers, expression paths can only contain one index" |
| 923 | " and the meaning of the operation is the same as the one defined by C/C++ (item extraction). Some commands extend bitfield-like syntax for arrays and pointers with the" |
| 924 | " meaning of array slicing (taking elements n thru m inside the array or pointed-to memory)."; |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 925 | } |
| 926 | |
Johnny Chen | 184d7a7 | 2011-09-21 01:00:02 +0000 | [diff] [blame] | 927 | void |
Enrico Granata | 9b62d1d | 2013-06-12 01:50:57 +0000 | [diff] [blame] | 928 | CommandObject::GenerateHelpText (CommandReturnObject &result) |
| 929 | { |
| 930 | GenerateHelpText(result.GetOutputStream()); |
| 931 | |
| 932 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 933 | } |
| 934 | |
| 935 | void |
| 936 | CommandObject::GenerateHelpText (Stream &output_strm) |
| 937 | { |
| 938 | CommandInterpreter& interpreter = GetCommandInterpreter(); |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 939 | if (GetOptions() != nullptr) |
Enrico Granata | 9b62d1d | 2013-06-12 01:50:57 +0000 | [diff] [blame] | 940 | { |
| 941 | if (WantsRawCommandString()) |
| 942 | { |
| 943 | std::string help_text (GetHelp()); |
| 944 | help_text.append (" This command takes 'raw' input (no need to quote stuff)."); |
| 945 | interpreter.OutputFormattedHelpText (output_strm, "", "", help_text.c_str(), 1); |
| 946 | } |
| 947 | else |
| 948 | interpreter.OutputFormattedHelpText (output_strm, "", "", GetHelp(), 1); |
| 949 | output_strm.Printf ("\nSyntax: %s\n", GetSyntax()); |
| 950 | GetOptions()->GenerateOptionUsage (output_strm, this); |
| 951 | const char *long_help = GetHelpLong(); |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 952 | if ((long_help != nullptr) |
Enrico Granata | 9b62d1d | 2013-06-12 01:50:57 +0000 | [diff] [blame] | 953 | && (strlen (long_help) > 0)) |
| 954 | output_strm.Printf ("\n%s", long_help); |
| 955 | if (WantsRawCommandString() && !WantsCompletion()) |
| 956 | { |
| 957 | // Emit the message about using ' -- ' between the end of the command options and the raw input |
| 958 | // conditionally, i.e., only if the command object does not want completion. |
| 959 | interpreter.OutputFormattedHelpText (output_strm, "", "", |
| 960 | "\nIMPORTANT NOTE: Because this command takes 'raw' input, if you use any command options" |
| 961 | " you must use ' -- ' between the end of the command options and the beginning of the raw input.", 1); |
| 962 | } |
| 963 | else if (GetNumArgumentEntries() > 0 |
| 964 | && GetOptions() |
| 965 | && GetOptions()->NumCommandOptions() > 0) |
| 966 | { |
| 967 | // Also emit a warning about using "--" in case you are using a command that takes options and arguments. |
| 968 | interpreter.OutputFormattedHelpText (output_strm, "", "", |
| 969 | "\nThis command takes options and free-form arguments. If your arguments resemble" |
| 970 | " option specifiers (i.e., they start with a - or --), you must use ' -- ' between" |
| 971 | " the end of the command options and the beginning of the arguments.", 1); |
| 972 | } |
| 973 | } |
| 974 | else if (IsMultiwordObject()) |
| 975 | { |
| 976 | if (WantsRawCommandString()) |
| 977 | { |
| 978 | std::string help_text (GetHelp()); |
| 979 | help_text.append (" This command takes 'raw' input (no need to quote stuff)."); |
| 980 | interpreter.OutputFormattedHelpText (output_strm, "", "", help_text.c_str(), 1); |
| 981 | } |
| 982 | else |
| 983 | interpreter.OutputFormattedHelpText (output_strm, "", "", GetHelp(), 1); |
| 984 | GenerateHelpText (output_strm); |
| 985 | } |
| 986 | else |
| 987 | { |
| 988 | const char *long_help = GetHelpLong(); |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 989 | if ((long_help != nullptr) |
Enrico Granata | 9b62d1d | 2013-06-12 01:50:57 +0000 | [diff] [blame] | 990 | && (strlen (long_help) > 0)) |
| 991 | output_strm.Printf ("%s", long_help); |
| 992 | else if (WantsRawCommandString()) |
| 993 | { |
| 994 | std::string help_text (GetHelp()); |
| 995 | help_text.append (" This command takes 'raw' input (no need to quote stuff)."); |
| 996 | interpreter.OutputFormattedHelpText (output_strm, "", "", help_text.c_str(), 1); |
| 997 | } |
| 998 | else |
| 999 | interpreter.OutputFormattedHelpText (output_strm, "", "", GetHelp(), 1); |
| 1000 | output_strm.Printf ("\nSyntax: %s\n", GetSyntax()); |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | void |
Johnny Chen | de75346 | 2011-09-22 22:34:09 +0000 | [diff] [blame] | 1005 | CommandObject::AddIDsArgumentData(CommandArgumentEntry &arg, CommandArgumentType ID, CommandArgumentType IDRange) |
Johnny Chen | 184d7a7 | 2011-09-21 01:00:02 +0000 | [diff] [blame] | 1006 | { |
| 1007 | CommandArgumentData id_arg; |
| 1008 | CommandArgumentData id_range_arg; |
| 1009 | |
| 1010 | // Create the first variant for the first (and only) argument for this command. |
Johnny Chen | de75346 | 2011-09-22 22:34:09 +0000 | [diff] [blame] | 1011 | id_arg.arg_type = ID; |
Johnny Chen | 184d7a7 | 2011-09-21 01:00:02 +0000 | [diff] [blame] | 1012 | id_arg.arg_repetition = eArgRepeatOptional; |
| 1013 | |
| 1014 | // Create the second variant for the first (and only) argument for this command. |
Johnny Chen | de75346 | 2011-09-22 22:34:09 +0000 | [diff] [blame] | 1015 | id_range_arg.arg_type = IDRange; |
Johnny Chen | 184d7a7 | 2011-09-21 01:00:02 +0000 | [diff] [blame] | 1016 | id_range_arg.arg_repetition = eArgRepeatOptional; |
| 1017 | |
Johnny Chen | a323473 | 2011-09-21 01:04:49 +0000 | [diff] [blame] | 1018 | // The first (and only) argument for this command could be either an id or an id_range. |
Johnny Chen | 184d7a7 | 2011-09-21 01:00:02 +0000 | [diff] [blame] | 1019 | // Push both variants into the entry for the first argument for this command. |
| 1020 | arg.push_back(id_arg); |
| 1021 | arg.push_back(id_range_arg); |
| 1022 | } |
| 1023 | |
Greg Clayton | 9d0402b | 2011-02-20 02:15:07 +0000 | [diff] [blame] | 1024 | const char * |
| 1025 | CommandObject::GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type) |
| 1026 | { |
Zachary Turner | 48b475c | 2015-04-02 20:57:38 +0000 | [diff] [blame] | 1027 | assert(arg_type < eArgTypeLastArg && "Invalid argument type passed to GetArgumentTypeAsCString"); |
| 1028 | return g_arguments_data[arg_type].arg_name; |
Greg Clayton | 9d0402b | 2011-02-20 02:15:07 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | const char * |
| 1032 | CommandObject::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type) |
| 1033 | { |
Zachary Turner | 48b475c | 2015-04-02 20:57:38 +0000 | [diff] [blame] | 1034 | assert(arg_type < eArgTypeLastArg && "Invalid argument type passed to GetArgumentDescriptionAsCString"); |
| 1035 | return g_arguments_data[arg_type].help_text; |
Greg Clayton | 9d0402b | 2011-02-20 02:15:07 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 1038 | Target * |
| 1039 | CommandObject::GetDummyTarget() |
| 1040 | { |
| 1041 | return m_interpreter.GetDebugger().GetDummyTarget(); |
| 1042 | } |
| 1043 | |
| 1044 | Target * |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1045 | CommandObject::GetSelectedOrDummyTarget(bool prefer_dummy) |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 1046 | { |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 1047 | return m_interpreter.GetDebugger().GetSelectedOrDummyTarget(prefer_dummy); |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1050 | bool |
| 1051 | CommandObjectParsed::Execute (const char *args_string, CommandReturnObject &result) |
| 1052 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1053 | bool handled = false; |
| 1054 | Args cmd_args (args_string); |
Jim Ingham | 3b65262 | 2014-08-06 00:10:12 +0000 | [diff] [blame] | 1055 | if (HasOverrideCallback()) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1056 | { |
| 1057 | Args full_args (GetCommandName ()); |
| 1058 | full_args.AppendArguments(cmd_args); |
Jim Ingham | 3b65262 | 2014-08-06 00:10:12 +0000 | [diff] [blame] | 1059 | handled = InvokeOverrideCallback (full_args.GetConstArgumentVector(), result); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1060 | } |
| 1061 | if (!handled) |
| 1062 | { |
| 1063 | for (size_t i = 0; i < cmd_args.GetArgumentCount(); ++i) |
| 1064 | { |
| 1065 | const char *tmp_str = cmd_args.GetArgumentAtIndex (i); |
| 1066 | if (tmp_str[0] == '`') // back-quote |
| 1067 | cmd_args.ReplaceArgumentAtIndex (i, m_interpreter.ProcessEmbeddedScriptCommands (tmp_str)); |
| 1068 | } |
| 1069 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1070 | if (CheckRequirements(result)) |
| 1071 | { |
| 1072 | if (ParseOptions (cmd_args, result)) |
| 1073 | { |
| 1074 | // Call the command-specific version of 'Execute', passing it the already processed arguments. |
| 1075 | handled = DoExecute (cmd_args, result); |
| 1076 | } |
| 1077 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1078 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1079 | Cleanup(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1080 | } |
| 1081 | return handled; |
| 1082 | } |
| 1083 | |
| 1084 | bool |
| 1085 | CommandObjectRaw::Execute (const char *args_string, CommandReturnObject &result) |
| 1086 | { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1087 | bool handled = false; |
Jim Ingham | 3b65262 | 2014-08-06 00:10:12 +0000 | [diff] [blame] | 1088 | if (HasOverrideCallback()) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1089 | { |
| 1090 | std::string full_command (GetCommandName ()); |
| 1091 | full_command += ' '; |
| 1092 | full_command += args_string; |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 1093 | const char *argv[2] = { nullptr, nullptr }; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1094 | argv[0] = full_command.c_str(); |
Jim Ingham | 3b65262 | 2014-08-06 00:10:12 +0000 | [diff] [blame] | 1095 | handled = InvokeOverrideCallback (argv, result); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1096 | } |
| 1097 | if (!handled) |
| 1098 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1099 | if (CheckRequirements(result)) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1100 | handled = DoExecute (args_string, result); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1101 | |
| 1102 | Cleanup(); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1103 | } |
| 1104 | return handled; |
| 1105 | } |
| 1106 | |
Johnny Chen | ca7835c | 2012-05-26 00:32:39 +0000 | [diff] [blame] | 1107 | static |
| 1108 | const char *arch_helper() |
| 1109 | { |
Greg Clayton | d70b14e | 2012-05-26 17:21:14 +0000 | [diff] [blame] | 1110 | static StreamString g_archs_help; |
Johnny Chen | 797a1b3 | 2012-05-29 20:04:10 +0000 | [diff] [blame] | 1111 | if (g_archs_help.Empty()) |
Greg Clayton | d70b14e | 2012-05-26 17:21:14 +0000 | [diff] [blame] | 1112 | { |
| 1113 | StringList archs; |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 1114 | ArchSpec::AutoComplete(nullptr, archs); |
Greg Clayton | d70b14e | 2012-05-26 17:21:14 +0000 | [diff] [blame] | 1115 | g_archs_help.Printf("These are the supported architecture names:\n"); |
Johnny Chen | 797a1b3 | 2012-05-29 20:04:10 +0000 | [diff] [blame] | 1116 | archs.Join("\n", g_archs_help); |
Greg Clayton | d70b14e | 2012-05-26 17:21:14 +0000 | [diff] [blame] | 1117 | } |
| 1118 | return g_archs_help.GetData(); |
Johnny Chen | ca7835c | 2012-05-26 00:32:39 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 1121 | CommandObject::ArgumentTableEntry |
| 1122 | CommandObject::g_arguments_data[] = |
| 1123 | { |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 1124 | { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid address in the target program's execution space." }, |
| 1125 | { eArgTypeAddressOrExpression, "address-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "An expression that resolves to an address." }, |
| 1126 | { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of an abbreviation (alias) for a debugger command." }, |
| 1127 | { eArgTypeAliasOptions, "options-for-aliased-command", CommandCompletions::eNoCompletion, { nullptr, false }, "Command options to be used as part of an alias (abbreviation) definition. (See 'help commands alias' for more information.)" }, |
Johnny Chen | ca7835c | 2012-05-26 00:32:39 +0000 | [diff] [blame] | 1128 | { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, { arch_helper, true }, "The architecture name, e.g. i386 or x86_64." }, |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 1129 | { eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, { nullptr, false }, "A Boolean value: 'true' or 'false'" }, |
| 1130 | { eArgTypeBreakpointID, "breakpt-id", CommandCompletions::eNoCompletion, { BreakpointIDHelpTextCallback, false }, nullptr }, |
| 1131 | { eArgTypeBreakpointIDRange, "breakpt-id-list", CommandCompletions::eNoCompletion, { BreakpointIDRangeHelpTextCallback, false }, nullptr }, |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 1132 | { eArgTypeBreakpointName, "breakpoint-name", CommandCompletions::eNoCompletion, { BreakpointNameHelpTextCallback, false }, nullptr }, |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 1133 | { eArgTypeByteSize, "byte-size", CommandCompletions::eNoCompletion, { nullptr, false }, "Number of bytes to use." }, |
| 1134 | { eArgTypeClassName, "class-name", CommandCompletions::eNoCompletion, { nullptr, false }, "Then name of a class from the debug information in the program." }, |
| 1135 | { eArgTypeCommandName, "cmd-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A debugger command (may be multiple words), without any options or arguments." }, |
| 1136 | { eArgTypeCount, "count", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." }, |
| 1137 | { eArgTypeDirectoryName, "directory", CommandCompletions::eDiskDirectoryCompletion, { nullptr, false }, "A directory name." }, |
| 1138 | { eArgTypeDisassemblyFlavor, "disassembly-flavor", CommandCompletions::eNoCompletion, { nullptr, false }, "A disassembly flavor recognized by your disassembly plugin. Currently the only valid options are \"att\" and \"intel\" for Intel targets" }, |
| 1139 | { eArgTypeDescriptionVerbosity, "description-verbosity", CommandCompletions::eNoCompletion, { nullptr, false }, "How verbose the output of 'po' should be." }, |
| 1140 | { eArgTypeEndAddress, "end-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, |
| 1141 | { eArgTypeExpression, "expr", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, |
| 1142 | { eArgTypeExpressionPath, "expr-path", CommandCompletions::eNoCompletion, { ExprPathHelpTextCallback, true }, nullptr }, |
| 1143 | { eArgTypeExprFormat, "expression-format", CommandCompletions::eNoCompletion, { nullptr, false }, "[ [bool|b] | [bin] | [char|c] | [oct|o] | [dec|i|d|u] | [hex|x] | [float|f] | [cstr|s] ]" }, |
| 1144 | { eArgTypeFilename, "filename", CommandCompletions::eDiskFileCompletion, { nullptr, false }, "The name of a file (can include path)." }, |
| 1145 | { eArgTypeFormat, "format", CommandCompletions::eNoCompletion, { FormatHelpTextCallback, true }, nullptr }, |
| 1146 | { eArgTypeFrameIndex, "frame-index", CommandCompletions::eNoCompletion, { nullptr, false }, "Index into a thread's list of frames." }, |
| 1147 | { eArgTypeFullName, "fullname", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, |
| 1148 | { eArgTypeFunctionName, "function-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a function." }, |
| 1149 | { eArgTypeFunctionOrSymbol, "function-or-symbol", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a function or symbol." }, |
| 1150 | { eArgTypeGDBFormat, "gdb-format", CommandCompletions::eNoCompletion, { GDBFormatHelpTextCallback, true }, nullptr }, |
Enrico Granata | 735152e | 2014-09-15 17:52:44 +0000 | [diff] [blame] | 1151 | { eArgTypeHelpText, "help-text", CommandCompletions::eNoCompletion, { nullptr, false }, "Text to be used as help for some other entity in LLDB" }, |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 1152 | { eArgTypeIndex, "index", CommandCompletions::eNoCompletion, { nullptr, false }, "An index into a list." }, |
| 1153 | { eArgTypeLanguage, "language", CommandCompletions::eNoCompletion, { LanguageTypeHelpTextCallback, true }, nullptr }, |
| 1154 | { eArgTypeLineNum, "linenum", CommandCompletions::eNoCompletion, { nullptr, false }, "Line number in a source file." }, |
| 1155 | { eArgTypeLogCategory, "log-category", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a category within a log channel, e.g. all (try \"log list\" to see a list of all channels and their categories." }, |
| 1156 | { eArgTypeLogChannel, "log-channel", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a log channel, e.g. process.gdb-remote (try \"log list\" to see a list of all channels and their categories)." }, |
| 1157 | { eArgTypeMethod, "method", CommandCompletions::eNoCompletion, { nullptr, false }, "A C++ method name." }, |
| 1158 | { eArgTypeName, "name", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, |
| 1159 | { eArgTypeNewPathPrefix, "new-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, |
| 1160 | { eArgTypeNumLines, "num-lines", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of lines to use." }, |
| 1161 | { eArgTypeNumberPerLine, "number-per-line", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of items per line to display." }, |
| 1162 | { eArgTypeOffset, "offset", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, |
| 1163 | { eArgTypeOldPathPrefix, "old-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, |
| 1164 | { eArgTypeOneLiner, "one-line-command", CommandCompletions::eNoCompletion, { nullptr, false }, "A command that is entered as a single line of text." }, |
| 1165 | { eArgTypePath, "path", CommandCompletions::eDiskFileCompletion, { nullptr, false }, "Path." }, |
| 1166 | { eArgTypePermissionsNumber, "perms-numeric", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as an octal number (e.g. 755)." }, |
| 1167 | { eArgTypePermissionsString, "perms=string", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as a string value (e.g. rw-r-xr--)." }, |
| 1168 | { eArgTypePid, "pid", CommandCompletions::eNoCompletion, { nullptr, false }, "The process ID number." }, |
| 1169 | { eArgTypePlugin, "plugin", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, |
| 1170 | { eArgTypeProcessName, "process-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of the process." }, |
| 1171 | { eArgTypePythonClass, "python-class", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python class." }, |
| 1172 | { eArgTypePythonFunction, "python-function", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python function." }, |
| 1173 | { eArgTypePythonScript, "python-script", CommandCompletions::eNoCompletion, { nullptr, false }, "Source code written in Python." }, |
| 1174 | { eArgTypeQueueName, "queue-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of the thread queue." }, |
| 1175 | { eArgTypeRegisterName, "register-name", CommandCompletions::eNoCompletion, { RegisterNameHelpTextCallback, true }, nullptr }, |
| 1176 | { eArgTypeRegularExpression, "regular-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "A regular expression." }, |
| 1177 | { eArgTypeRunArgs, "run-args", CommandCompletions::eNoCompletion, { nullptr, false }, "Arguments to be passed to the target program when it starts executing." }, |
| 1178 | { eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, |
| 1179 | { eArgTypeScriptedCommandSynchronicity, "script-cmd-synchronicity", CommandCompletions::eNoCompletion, { nullptr, false }, "The synchronicity to use to run scripted commands with regard to LLDB event system." }, |
| 1180 | { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { nullptr, false }, "The scripting language to be used for script-based commands. Currently only Python is valid." }, |
| 1181 | { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { nullptr, false }, "The word for which you wish to search for information about." }, |
| 1182 | { eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, { nullptr, false }, "An Objective-C selector name." }, |
| 1183 | { eArgTypeSettingIndex, "setting-index", CommandCompletions::eNoCompletion, { nullptr, false }, "An index into a settings variable that is an array (try 'settings list' to see all the possible settings variables and their types)." }, |
| 1184 | { eArgTypeSettingKey, "setting-key", CommandCompletions::eNoCompletion, { nullptr, false }, "A key into a settings variables that is a dictionary (try 'settings list' to see all the possible settings variables and their types)." }, |
| 1185 | { eArgTypeSettingPrefix, "setting-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a settable internal debugger variable up to a dot ('.'), e.g. 'target.process.'" }, |
| 1186 | { eArgTypeSettingVariableName, "setting-variable-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a settable internal debugger variable. Type 'settings list' to see a complete list of such variables." }, |
| 1187 | { eArgTypeShlibName, "shlib-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a shared library." }, |
| 1188 | { eArgTypeSourceFile, "source-file", CommandCompletions::eSourceFileCompletion, { nullptr, false }, "The name of a source file.." }, |
| 1189 | { eArgTypeSortOrder, "sort-order", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify a sort order when dumping lists." }, |
| 1190 | { eArgTypeStartAddress, "start-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, |
| 1191 | { eArgTypeSummaryString, "summary-string", CommandCompletions::eNoCompletion, { SummaryStringHelpTextCallback, true }, nullptr }, |
| 1192 | { eArgTypeSymbol, "symbol", CommandCompletions::eSymbolCompletion, { nullptr, false }, "Any symbol name (function name, variable, argument, etc.)" }, |
| 1193 | { eArgTypeThreadID, "thread-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Thread ID number." }, |
| 1194 | { eArgTypeThreadIndex, "thread-index", CommandCompletions::eNoCompletion, { nullptr, false }, "Index into the process' list of threads." }, |
| 1195 | { eArgTypeThreadName, "thread-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The thread's name." }, |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame^] | 1196 | { eArgTypeTypeName, "type-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A type name." }, |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 1197 | { eArgTypeUnsignedInteger, "unsigned-integer", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." }, |
| 1198 | { eArgTypeUnixSignal, "unix-signal", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid Unix signal name or number (e.g. SIGKILL, KILL or 9)." }, |
| 1199 | { eArgTypeVarName, "variable-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a variable in your program." }, |
| 1200 | { eArgTypeValue, "value", CommandCompletions::eNoCompletion, { nullptr, false }, "A value could be anything, depending on where and how it is used." }, |
| 1201 | { eArgTypeWidth, "width", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, |
| 1202 | { eArgTypeNone, "none", CommandCompletions::eNoCompletion, { nullptr, false }, "No help available for this." }, |
| 1203 | { eArgTypePlatform, "platform-name", CommandCompletions::ePlatformPluginCompletion, { nullptr, false }, "The name of an installed platform plug-in . Type 'platform list' to see a complete list of installed platforms." }, |
| 1204 | { eArgTypeWatchpointID, "watchpt-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Watchpoint IDs are positive integers." }, |
| 1205 | { eArgTypeWatchpointIDRange, "watchpt-id-list", CommandCompletions::eNoCompletion, { nullptr, false }, "For example, '1-3' or '1 to 3'." }, |
| 1206 | { eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify the type for a watchpoint." } |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 1207 | }; |
| 1208 | |
| 1209 | const CommandObject::ArgumentTableEntry* |
| 1210 | CommandObject::GetArgumentTable () |
| 1211 | { |
Greg Clayton | 9d0402b | 2011-02-20 02:15:07 +0000 | [diff] [blame] | 1212 | // If this assertion fires, then the table above is out of date with the CommandArgumentType enumeration |
| 1213 | assert ((sizeof (CommandObject::g_arguments_data) / sizeof (CommandObject::ArgumentTableEntry)) == eArgTypeLastArg); |
Caroline Tice | e139cf2 | 2010-10-01 17:46:38 +0000 | [diff] [blame] | 1214 | return CommandObject::g_arguments_data; |
| 1215 | } |
| 1216 | |
| 1217 | |