Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1 | //===-- CommandObjectPlatform.cpp -------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "CommandObjectPlatform.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "lldb/Core/DataExtractor.h" |
| 17 | #include "lldb/Core/Debugger.h" |
| 18 | #include "lldb/Core/PluginManager.h" |
| 19 | #include "lldb/Interpreter/Args.h" |
| 20 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 21 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 22 | #include "lldb/Target/ExecutionContext.h" |
| 23 | #include "lldb/Target/Platform.h" |
| 24 | |
| 25 | using namespace lldb; |
| 26 | using namespace lldb_private; |
| 27 | |
| 28 | //---------------------------------------------------------------------- |
| 29 | // "platform create <platform-name>" |
| 30 | //---------------------------------------------------------------------- |
| 31 | class CommandObjectPlatformCreate : public CommandObject |
| 32 | { |
| 33 | public: |
| 34 | CommandObjectPlatformCreate (CommandInterpreter &interpreter) : |
| 35 | CommandObject (interpreter, |
| 36 | "platform create", |
| 37 | "Create a platform instance by name and select it as the current platform.", |
| 38 | "platform create <platform-name>", |
| 39 | 0) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | virtual |
| 44 | ~CommandObjectPlatformCreate () |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | virtual bool |
| 49 | Execute (Args& args, CommandReturnObject &result) |
| 50 | { |
| 51 | Error error; |
| 52 | if (args.GetArgumentCount() == 1) |
| 53 | { |
| 54 | PlatformSP platform_sp (Platform::Create (args.GetArgumentAtIndex (0), error)); |
| 55 | |
| 56 | if (platform_sp) |
| 57 | { |
| 58 | m_interpreter.GetDebugger().GetPlatformList().Append (platform_sp, true); |
| 59 | if (m_options.os_version_major != UINT32_MAX) |
| 60 | { |
| 61 | platform_sp->SetOSVersion (m_options.os_version_major, |
| 62 | m_options.os_version_minor, |
| 63 | m_options.os_version_update); |
| 64 | } |
| 65 | |
| 66 | platform_sp->GetStatus (result.GetOutputStream()); |
| 67 | } |
| 68 | } |
| 69 | else |
| 70 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 71 | result.AppendError ("platform create takes a platform name as an argument\n"); |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 72 | result.SetStatus (eReturnStatusFailed); |
| 73 | } |
| 74 | return result.Succeeded(); |
| 75 | } |
| 76 | |
| 77 | virtual Options * |
| 78 | GetOptions () |
| 79 | { |
| 80 | return &m_options; |
| 81 | } |
| 82 | |
| 83 | protected: |
| 84 | |
| 85 | class CommandOptions : public Options |
| 86 | { |
| 87 | public: |
| 88 | |
| 89 | CommandOptions () : |
| 90 | os_version_major (UINT32_MAX), |
| 91 | os_version_minor (UINT32_MAX), |
| 92 | os_version_update (UINT32_MAX) |
| 93 | { |
| 94 | } |
| 95 | |
| 96 | virtual |
| 97 | ~CommandOptions () |
| 98 | { |
| 99 | } |
| 100 | |
| 101 | virtual Error |
| 102 | SetOptionValue (int option_idx, const char *option_arg) |
| 103 | { |
| 104 | Error error; |
| 105 | char short_option = (char) m_getopt_table[option_idx].val; |
| 106 | |
| 107 | switch (short_option) |
| 108 | { |
| 109 | case 'v': |
| 110 | if (Args::StringToVersion (option_arg, |
| 111 | os_version_major, |
| 112 | os_version_minor, |
| 113 | os_version_update) == option_arg) |
| 114 | { |
| 115 | error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg); |
| 116 | } |
| 117 | break; |
| 118 | |
| 119 | default: |
| 120 | error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); |
| 121 | break; |
| 122 | } |
| 123 | |
| 124 | return error; |
| 125 | } |
| 126 | |
| 127 | void |
| 128 | ResetOptionValues () |
| 129 | { |
| 130 | os_version_major = UINT32_MAX; |
| 131 | os_version_minor = UINT32_MAX; |
| 132 | os_version_update = UINT32_MAX; |
| 133 | } |
| 134 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 135 | const OptionDefinition* |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 136 | GetDefinitions () |
| 137 | { |
| 138 | return g_option_table; |
| 139 | } |
| 140 | |
| 141 | // Options table: Required for subclasses of Options. |
| 142 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 143 | static OptionDefinition g_option_table[]; |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 144 | |
| 145 | // Instance variables to hold the values for command options. |
| 146 | |
| 147 | uint32_t os_version_major; |
| 148 | uint32_t os_version_minor; |
| 149 | uint32_t os_version_update; |
| 150 | }; |
| 151 | CommandOptions m_options; |
| 152 | }; |
| 153 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 154 | OptionDefinition |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 155 | CommandObjectPlatformCreate::CommandOptions::g_option_table[] = |
| 156 | { |
| 157 | { LLDB_OPT_SET_ALL, false, "sdk-version", 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." }, |
| 158 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
| 159 | }; |
| 160 | |
| 161 | //---------------------------------------------------------------------- |
| 162 | // "platform list" |
| 163 | //---------------------------------------------------------------------- |
| 164 | class CommandObjectPlatformList : public CommandObject |
| 165 | { |
| 166 | public: |
| 167 | CommandObjectPlatformList (CommandInterpreter &interpreter) : |
| 168 | CommandObject (interpreter, |
| 169 | "platform list", |
| 170 | "List all platforms that are available.", |
| 171 | NULL, |
| 172 | 0) |
| 173 | { |
| 174 | } |
| 175 | |
| 176 | virtual |
| 177 | ~CommandObjectPlatformList () |
| 178 | { |
| 179 | } |
| 180 | |
| 181 | virtual bool |
| 182 | Execute (Args& args, CommandReturnObject &result) |
| 183 | { |
| 184 | Stream &ostrm = result.GetOutputStream(); |
| 185 | ostrm.Printf("Available platforms:\n"); |
| 186 | |
| 187 | PlatformSP host_platform_sp (Platform::GetDefaultPlatform()); |
| 188 | ostrm.Printf ("%s: %s\n", |
| 189 | host_platform_sp->GetShortPluginName(), |
| 190 | host_platform_sp->GetDescription()); |
| 191 | |
| 192 | uint32_t idx; |
| 193 | for (idx = 0; 1; ++idx) |
| 194 | { |
| 195 | const char *plugin_name = PluginManager::GetPlatformPluginNameAtIndex (idx); |
| 196 | if (plugin_name == NULL) |
| 197 | break; |
| 198 | const char *plugin_desc = PluginManager::GetPlatformPluginDescriptionAtIndex (idx); |
| 199 | if (plugin_desc == NULL) |
| 200 | break; |
| 201 | ostrm.Printf("%s: %s\n", plugin_name, plugin_desc); |
| 202 | } |
| 203 | |
| 204 | if (idx == 0) |
| 205 | { |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 206 | result.AppendError ("no platforms are available\n"); |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 207 | result.SetStatus (eReturnStatusFailed); |
| 208 | } |
Johnny Chen | 0815031 | 2011-03-30 21:19:59 +0000 | [diff] [blame] | 209 | else |
| 210 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 211 | return result.Succeeded(); |
| 212 | } |
| 213 | }; |
| 214 | |
| 215 | //---------------------------------------------------------------------- |
| 216 | // "platform status" |
| 217 | //---------------------------------------------------------------------- |
| 218 | class CommandObjectPlatformStatus : public CommandObject |
| 219 | { |
| 220 | public: |
| 221 | CommandObjectPlatformStatus (CommandInterpreter &interpreter) : |
| 222 | CommandObject (interpreter, |
| 223 | "platform status", |
| 224 | "Display status for the currently selected platform.", |
| 225 | NULL, |
| 226 | 0) |
| 227 | { |
| 228 | } |
| 229 | |
| 230 | virtual |
| 231 | ~CommandObjectPlatformStatus () |
| 232 | { |
| 233 | } |
| 234 | |
| 235 | virtual bool |
| 236 | Execute (Args& args, CommandReturnObject &result) |
| 237 | { |
| 238 | Stream &ostrm = result.GetOutputStream(); |
| 239 | |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 240 | PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); |
| 241 | if (platform_sp) |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 242 | { |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 243 | platform_sp->GetStatus (ostrm); |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 244 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 245 | } |
| 246 | else |
| 247 | { |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 248 | result.AppendError ("no platform us currently selected\n"); |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 249 | result.SetStatus (eReturnStatusFailed); |
| 250 | } |
| 251 | return result.Succeeded(); |
| 252 | } |
| 253 | }; |
| 254 | |
| 255 | |
| 256 | //---------------------------------------------------------------------- |
| 257 | // "platform select <platform-name>" |
| 258 | //---------------------------------------------------------------------- |
| 259 | class CommandObjectPlatformSelect : public CommandObject |
| 260 | { |
| 261 | public: |
| 262 | CommandObjectPlatformSelect (CommandInterpreter &interpreter) : |
| 263 | CommandObject (interpreter, |
| 264 | "platform select", |
| 265 | "Select a platform by name to be the currently selected platform.", |
| 266 | "platform select <platform-name>", |
| 267 | 0) |
| 268 | { |
| 269 | } |
| 270 | |
| 271 | virtual |
| 272 | ~CommandObjectPlatformSelect () |
| 273 | { |
| 274 | } |
| 275 | |
| 276 | virtual bool |
| 277 | Execute (Args& args, CommandReturnObject &result) |
| 278 | { |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 279 | result.AppendError ("command not implemented\n"); |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 280 | result.SetStatus (eReturnStatusFailed); |
| 281 | return result.Succeeded(); |
| 282 | } |
| 283 | }; |
| 284 | |
| 285 | |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 286 | //---------------------------------------------------------------------- |
| 287 | // "platform connect <connect-url>" |
| 288 | //---------------------------------------------------------------------- |
| 289 | class CommandObjectPlatformConnect : public CommandObject |
| 290 | { |
| 291 | public: |
| 292 | CommandObjectPlatformConnect (CommandInterpreter &interpreter) : |
| 293 | CommandObject (interpreter, |
| 294 | "platform connect", |
| 295 | "Connect a platform by name to be the currently selected platform.", |
| 296 | "platform connect <connect-url>", |
| 297 | 0) |
| 298 | { |
| 299 | } |
| 300 | |
| 301 | virtual |
| 302 | ~CommandObjectPlatformConnect () |
| 303 | { |
| 304 | } |
| 305 | |
| 306 | virtual bool |
| 307 | Execute (Args& args, CommandReturnObject &result) |
| 308 | { |
| 309 | Stream &ostrm = result.GetOutputStream(); |
| 310 | |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 311 | PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); |
| 312 | if (platform_sp) |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 313 | { |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 314 | Error error (platform_sp->ConnectRemote (args)); |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 315 | if (error.Success()) |
| 316 | { |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 317 | platform_sp->GetStatus (ostrm); |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 318 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 319 | } |
| 320 | else |
| 321 | { |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 322 | result.AppendErrorWithFormat ("%s\n", error.AsCString()); |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 323 | result.SetStatus (eReturnStatusFailed); |
| 324 | } |
| 325 | } |
| 326 | else |
| 327 | { |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 328 | result.AppendError ("no platform us currently selected\n"); |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 329 | result.SetStatus (eReturnStatusFailed); |
| 330 | } |
| 331 | return result.Succeeded(); |
| 332 | } |
| 333 | }; |
| 334 | |
| 335 | //---------------------------------------------------------------------- |
| 336 | // "platform disconnect" |
| 337 | //---------------------------------------------------------------------- |
| 338 | class CommandObjectPlatformDisconnect : public CommandObject |
| 339 | { |
| 340 | public: |
| 341 | CommandObjectPlatformDisconnect (CommandInterpreter &interpreter) : |
| 342 | CommandObject (interpreter, |
| 343 | "platform disconnect", |
| 344 | "Disconnect a platform by name to be the currently selected platform.", |
| 345 | "platform disconnect", |
| 346 | 0) |
| 347 | { |
| 348 | } |
| 349 | |
| 350 | virtual |
| 351 | ~CommandObjectPlatformDisconnect () |
| 352 | { |
| 353 | } |
| 354 | |
| 355 | virtual bool |
| 356 | Execute (Args& args, CommandReturnObject &result) |
| 357 | { |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 358 | PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); |
| 359 | if (platform_sp) |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 360 | { |
| 361 | if (args.GetArgumentCount() == 0) |
| 362 | { |
| 363 | Error error; |
| 364 | |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 365 | if (platform_sp->IsConnected()) |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 366 | { |
| 367 | // Cache the instance name if there is one since we are |
| 368 | // about to disconnect and the name might go with it. |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 369 | const char *hostname_cstr = platform_sp->GetHostname(); |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 370 | std::string hostname; |
| 371 | if (hostname_cstr) |
| 372 | hostname.assign (hostname_cstr); |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 373 | |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 374 | error = platform_sp->DisconnectRemote (); |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 375 | if (error.Success()) |
| 376 | { |
| 377 | Stream &ostrm = result.GetOutputStream(); |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 378 | if (hostname.empty()) |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 379 | ostrm.Printf ("Disconnected from \"%s\"\n", platform_sp->GetShortPluginName()); |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 380 | else |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 381 | ostrm.Printf ("Disconnected from \"%s\"\n", hostname.c_str()); |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 382 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 383 | } |
| 384 | else |
| 385 | { |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 386 | result.AppendErrorWithFormat ("%s", error.AsCString()); |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 387 | result.SetStatus (eReturnStatusFailed); |
| 388 | } |
| 389 | } |
| 390 | else |
| 391 | { |
| 392 | // Not connected... |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 393 | result.AppendErrorWithFormat ("not connected to '%s'", platform_sp->GetShortPluginName()); |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 394 | result.SetStatus (eReturnStatusFailed); |
| 395 | } |
| 396 | } |
| 397 | else |
| 398 | { |
| 399 | // Bad args |
| 400 | result.AppendError ("\"platform disconnect\" doesn't take any arguments"); |
| 401 | result.SetStatus (eReturnStatusFailed); |
| 402 | } |
| 403 | } |
| 404 | else |
| 405 | { |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 406 | result.AppendError ("no platform is currently selected"); |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 407 | result.SetStatus (eReturnStatusFailed); |
| 408 | } |
| 409 | return result.Succeeded(); |
| 410 | } |
| 411 | }; |
| 412 | |
| 413 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 414 | //---------------------------------------------------------------------- |
| 415 | // "platform process list" |
| 416 | //---------------------------------------------------------------------- |
| 417 | class CommandObjectPlatformProcessList : public CommandObject |
| 418 | { |
| 419 | public: |
| 420 | CommandObjectPlatformProcessList (CommandInterpreter &interpreter) : |
| 421 | CommandObject (interpreter, |
| 422 | "platform process list", |
| 423 | "List processes on a remote platform by name, pid, or many other matching attributes.", |
| 424 | "platform process list", |
| 425 | 0) |
| 426 | { |
| 427 | } |
| 428 | |
| 429 | virtual |
| 430 | ~CommandObjectPlatformProcessList () |
| 431 | { |
| 432 | } |
| 433 | |
| 434 | virtual bool |
| 435 | Execute (Args& args, CommandReturnObject &result) |
| 436 | { |
| 437 | PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); |
| 438 | |
| 439 | if (platform_sp) |
| 440 | { |
| 441 | Error error; |
| 442 | if (args.GetArgumentCount() == 0) |
| 443 | { |
| 444 | |
| 445 | if (platform_sp) |
| 446 | { |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 447 | Stream &ostrm = result.GetOutputStream(); |
| 448 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 449 | lldb::pid_t pid = m_options.match_info.GetProcessInfo().GetProcessID(); |
| 450 | if (pid != LLDB_INVALID_PROCESS_ID) |
| 451 | { |
| 452 | ProcessInfo proc_info; |
| 453 | if (platform_sp->GetProcessInfo (pid, proc_info)) |
| 454 | { |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 455 | ProcessInfo::DumpTableHeader (ostrm, platform_sp.get()); |
| 456 | proc_info.DumpAsTableRow(ostrm, platform_sp.get()); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 457 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 458 | } |
| 459 | else |
| 460 | { |
| 461 | result.AppendErrorWithFormat ("no process found with pid = %i\n", pid); |
| 462 | result.SetStatus (eReturnStatusFailed); |
| 463 | } |
| 464 | } |
| 465 | else |
| 466 | { |
| 467 | ProcessInfoList proc_infos; |
| 468 | const uint32_t matches = platform_sp->FindProcesses (m_options.match_info, proc_infos); |
| 469 | if (matches == 0) |
| 470 | { |
| 471 | const char *match_desc = NULL; |
| 472 | const char *match_name = m_options.match_info.GetProcessInfo().GetName(); |
| 473 | if (match_name && match_name[0]) |
| 474 | { |
| 475 | switch (m_options.match_info.GetNameMatchType()) |
| 476 | { |
| 477 | case eNameMatchIgnore: break; |
| 478 | case eNameMatchEquals: match_desc = "match"; break; |
| 479 | case eNameMatchContains: match_desc = "contains"; break; |
| 480 | case eNameMatchStartsWith: match_desc = "starts with"; break; |
| 481 | case eNameMatchEndsWith: match_desc = "end with"; break; |
| 482 | case eNameMatchRegularExpression: match_desc = "match the regular expression"; break; |
| 483 | } |
| 484 | } |
| 485 | if (match_desc) |
| 486 | result.AppendErrorWithFormat ("no processes were found that %s \"%s\" on the \"%s\" platform\n", |
| 487 | match_desc, |
| 488 | match_name, |
| 489 | platform_sp->GetShortPluginName()); |
| 490 | else |
| 491 | result.AppendErrorWithFormat ("no processes were found on the \"%s\" platform\n", platform_sp->GetShortPluginName()); |
| 492 | result.SetStatus (eReturnStatusFailed); |
| 493 | } |
| 494 | else |
| 495 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 496 | |
| 497 | ProcessInfo::DumpTableHeader (ostrm, platform_sp.get()); |
| 498 | for (uint32_t i=0; i<matches; ++i) |
| 499 | { |
| 500 | proc_infos.GetProcessInfoAtIndex(i).DumpAsTableRow(ostrm, platform_sp.get()); |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | else |
| 507 | { |
| 508 | result.AppendError ("invalid args: process list takes only options\n"); |
| 509 | result.SetStatus (eReturnStatusFailed); |
| 510 | } |
| 511 | } |
| 512 | else |
| 513 | { |
| 514 | result.AppendError ("no platform is selected\n"); |
| 515 | result.SetStatus (eReturnStatusFailed); |
| 516 | } |
| 517 | return result.Succeeded(); |
| 518 | } |
| 519 | |
| 520 | virtual Options * |
| 521 | GetOptions () |
| 522 | { |
| 523 | return &m_options; |
| 524 | } |
| 525 | |
| 526 | protected: |
| 527 | |
| 528 | class CommandOptions : public Options |
| 529 | { |
| 530 | public: |
| 531 | |
| 532 | CommandOptions () : |
| 533 | match_info () |
| 534 | { |
| 535 | } |
| 536 | |
| 537 | virtual |
| 538 | ~CommandOptions () |
| 539 | { |
| 540 | } |
| 541 | |
| 542 | virtual Error |
| 543 | SetOptionValue (int option_idx, const char *option_arg) |
| 544 | { |
| 545 | Error error; |
| 546 | char short_option = (char) m_getopt_table[option_idx].val; |
| 547 | bool success = false; |
| 548 | |
| 549 | switch (short_option) |
| 550 | { |
| 551 | case 'p': |
| 552 | match_info.GetProcessInfo().SetProcessID (Args::StringToUInt32 (option_arg, LLDB_INVALID_PROCESS_ID, 0, &success)); |
| 553 | if (!success) |
| 554 | error.SetErrorStringWithFormat("invalid process ID string: '%s'", option_arg); |
| 555 | break; |
| 556 | |
| 557 | case 'P': |
| 558 | match_info.GetProcessInfo().SetParentProcessID (Args::StringToUInt32 (option_arg, LLDB_INVALID_PROCESS_ID, 0, &success)); |
| 559 | if (!success) |
| 560 | error.SetErrorStringWithFormat("invalid parent process ID string: '%s'", option_arg); |
| 561 | break; |
| 562 | |
| 563 | case 'u': |
| 564 | match_info.GetProcessInfo().SetRealUserID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success)); |
| 565 | if (!success) |
| 566 | error.SetErrorStringWithFormat("invalid user ID string: '%s'", option_arg); |
| 567 | break; |
| 568 | |
| 569 | case 'U': |
| 570 | match_info.GetProcessInfo().SetEffectiveUserID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success)); |
| 571 | if (!success) |
| 572 | error.SetErrorStringWithFormat("invalid effective user ID string: '%s'", option_arg); |
| 573 | break; |
| 574 | |
| 575 | case 'g': |
| 576 | match_info.GetProcessInfo().SetRealGroupID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success)); |
| 577 | if (!success) |
| 578 | error.SetErrorStringWithFormat("invalid group ID string: '%s'", option_arg); |
| 579 | break; |
| 580 | |
| 581 | case 'G': |
| 582 | match_info.GetProcessInfo().SetEffectiveGroupID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success)); |
| 583 | if (!success) |
| 584 | error.SetErrorStringWithFormat("invalid effective group ID string: '%s'", option_arg); |
| 585 | break; |
| 586 | |
| 587 | case 'a': |
| 588 | match_info.GetProcessInfo().GetArchitecture().SetTriple (option_arg); |
| 589 | break; |
| 590 | |
| 591 | case 'n': |
| 592 | match_info.GetProcessInfo().SetName (option_arg); |
| 593 | if (match_info.GetNameMatchType() == eNameMatchIgnore) |
| 594 | match_info.SetNameMatchType (eNameMatchEquals); |
| 595 | break; |
| 596 | |
| 597 | case 'e': |
| 598 | match_info.SetNameMatchType (eNameMatchEndsWith); |
| 599 | break; |
| 600 | |
| 601 | case 's': |
| 602 | match_info.SetNameMatchType (eNameMatchStartsWith); |
| 603 | break; |
| 604 | |
| 605 | case 'c': |
| 606 | match_info.SetNameMatchType (eNameMatchContains); |
| 607 | break; |
| 608 | |
| 609 | case 'r': |
| 610 | match_info.SetNameMatchType (eNameMatchRegularExpression); |
| 611 | break; |
| 612 | |
| 613 | default: |
| 614 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 615 | break; |
| 616 | } |
| 617 | |
| 618 | return error; |
| 619 | } |
| 620 | |
| 621 | void |
| 622 | ResetOptionValues () |
| 623 | { |
| 624 | match_info.Clear(); |
| 625 | } |
| 626 | |
| 627 | const OptionDefinition* |
| 628 | GetDefinitions () |
| 629 | { |
| 630 | return g_option_table; |
| 631 | } |
| 632 | |
| 633 | // Options table: Required for subclasses of Options. |
| 634 | |
| 635 | static OptionDefinition g_option_table[]; |
| 636 | |
| 637 | // Instance variables to hold the values for command options. |
| 638 | |
| 639 | ProcessInfoMatch match_info; |
| 640 | }; |
| 641 | CommandOptions m_options; |
| 642 | }; |
| 643 | |
| 644 | OptionDefinition |
| 645 | CommandObjectPlatformProcessList::CommandOptions::g_option_table[] = |
| 646 | { |
| 647 | { LLDB_OPT_SET_1, false, "pid" , 'p', required_argument, NULL, 0, eArgTypePid , "List the process info for a specific process ID." }, |
| 648 | { LLDB_OPT_SET_2| |
| 649 | LLDB_OPT_SET_3| |
| 650 | LLDB_OPT_SET_4| |
| 651 | LLDB_OPT_SET_5, true , "name" , 'n', required_argument, NULL, 0, eArgTypeProcessName , "Find processes that match the supplied name." }, |
| 652 | { LLDB_OPT_SET_2, false, "ends-with" , 'e', no_argument , NULL, 0, eArgTypeNone , "Process names must end with the name supplied with the --name option." }, |
| 653 | { LLDB_OPT_SET_3, false, "starts-with" , 's', no_argument , NULL, 0, eArgTypeNone , "Process names must start with the name supplied with the --name option." }, |
| 654 | { LLDB_OPT_SET_4, false, "contains" , 'c', no_argument , NULL, 0, eArgTypeNone , "Process names must contain the name supplied with the --name option." }, |
| 655 | { LLDB_OPT_SET_5, false, "regex" , 'r', no_argument , NULL, 0, eArgTypeNone , "Process names must match name supplied with the --name option as a regular expression." }, |
| 656 | { LLDB_OPT_SET_2| |
| 657 | LLDB_OPT_SET_3| |
| 658 | LLDB_OPT_SET_4| |
| 659 | LLDB_OPT_SET_5| |
| 660 | LLDB_OPT_SET_6, false, "parent" , 'P', required_argument, NULL, 0, eArgTypePid , "Find processes that have a matching parent process ID." }, |
| 661 | { LLDB_OPT_SET_2| |
| 662 | LLDB_OPT_SET_3| |
| 663 | LLDB_OPT_SET_4| |
| 664 | LLDB_OPT_SET_5| |
| 665 | LLDB_OPT_SET_6, false, "uid" , 'u', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching user ID." }, |
| 666 | { LLDB_OPT_SET_2| |
| 667 | LLDB_OPT_SET_3| |
| 668 | LLDB_OPT_SET_4| |
| 669 | LLDB_OPT_SET_5| |
| 670 | LLDB_OPT_SET_6, false, "euid" , 'U', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching effective user ID." }, |
| 671 | { LLDB_OPT_SET_2| |
| 672 | LLDB_OPT_SET_3| |
| 673 | LLDB_OPT_SET_4| |
| 674 | LLDB_OPT_SET_5| |
| 675 | LLDB_OPT_SET_6, false, "gid" , 'g', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching group ID." }, |
| 676 | { LLDB_OPT_SET_2| |
| 677 | LLDB_OPT_SET_3| |
| 678 | LLDB_OPT_SET_4| |
| 679 | LLDB_OPT_SET_5| |
| 680 | LLDB_OPT_SET_6, false, "egid" , 'G', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching effective group ID." }, |
| 681 | { LLDB_OPT_SET_2| |
| 682 | LLDB_OPT_SET_3| |
| 683 | LLDB_OPT_SET_4| |
| 684 | LLDB_OPT_SET_5| |
| 685 | LLDB_OPT_SET_6, false, "arch" , 'a', required_argument, NULL, 0, eArgTypeArchitecture , "Find processes that have a matching architecture." }, |
| 686 | { 0 , false, NULL , 0 , 0 , NULL, 0, eArgTypeNone , NULL } |
| 687 | }; |
| 688 | |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 689 | |
| 690 | //---------------------------------------------------------------------- |
| 691 | // "platform process info" |
| 692 | //---------------------------------------------------------------------- |
| 693 | class CommandObjectPlatformProcessInfo : public CommandObject |
| 694 | { |
| 695 | public: |
| 696 | CommandObjectPlatformProcessInfo (CommandInterpreter &interpreter) : |
| 697 | CommandObject (interpreter, |
| 698 | "platform process info", |
| 699 | "Get detailed information for one or more process by process ID.", |
| 700 | "platform process info <pid> [<pid> <pid> ...]", |
| 701 | 0) |
| 702 | { |
| 703 | CommandArgumentEntry arg; |
| 704 | CommandArgumentData pid_args; |
| 705 | |
| 706 | // Define the first (and only) variant of this arg. |
| 707 | pid_args.arg_type = eArgTypePid; |
| 708 | pid_args.arg_repetition = eArgRepeatStar; |
| 709 | |
| 710 | // There is only one variant this argument could be; put it into the argument entry. |
| 711 | arg.push_back (pid_args); |
| 712 | |
| 713 | // Push the data for the first argument into the m_arguments vector. |
| 714 | m_arguments.push_back (arg); |
| 715 | } |
| 716 | |
| 717 | virtual |
| 718 | ~CommandObjectPlatformProcessInfo () |
| 719 | { |
| 720 | } |
| 721 | |
| 722 | virtual bool |
| 723 | Execute (Args& args, CommandReturnObject &result) |
| 724 | { |
| 725 | PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); |
| 726 | if (platform_sp) |
| 727 | { |
| 728 | const size_t argc = args.GetArgumentCount(); |
| 729 | if (argc > 0) |
| 730 | { |
| 731 | Error error; |
| 732 | |
| 733 | if (platform_sp->IsConnected()) |
| 734 | { |
| 735 | Stream &ostrm = result.GetOutputStream(); |
| 736 | bool success; |
| 737 | for (size_t i=0; i<argc; ++ i) |
| 738 | { |
| 739 | const char *arg = args.GetArgumentAtIndex(i); |
| 740 | lldb::pid_t pid = Args::StringToUInt32 (arg, LLDB_INVALID_PROCESS_ID, 0, &success); |
| 741 | if (success) |
| 742 | { |
| 743 | ProcessInfo proc_info; |
| 744 | if (platform_sp->GetProcessInfo (pid, proc_info)) |
| 745 | { |
| 746 | ostrm.Printf ("Process information for process %i:\n", pid); |
| 747 | proc_info.Dump (ostrm, platform_sp.get()); |
| 748 | } |
| 749 | else |
| 750 | { |
| 751 | ostrm.Printf ("error: no process information is available for process %i\n", pid); |
| 752 | } |
| 753 | ostrm.EOL(); |
| 754 | } |
| 755 | else |
| 756 | { |
| 757 | result.AppendErrorWithFormat ("invalid process ID argument '%s'", arg); |
| 758 | result.SetStatus (eReturnStatusFailed); |
| 759 | break; |
| 760 | } |
| 761 | } |
| 762 | } |
| 763 | else |
| 764 | { |
| 765 | // Not connected... |
| 766 | result.AppendErrorWithFormat ("not connected to '%s'", platform_sp->GetShortPluginName()); |
| 767 | result.SetStatus (eReturnStatusFailed); |
| 768 | } |
| 769 | } |
| 770 | else |
| 771 | { |
| 772 | // Bad args |
| 773 | result.AppendError ("\"platform disconnect\" doesn't take any arguments"); |
| 774 | result.SetStatus (eReturnStatusFailed); |
| 775 | } |
| 776 | } |
| 777 | else |
| 778 | { |
| 779 | result.AppendError ("no platform is currently selected"); |
| 780 | result.SetStatus (eReturnStatusFailed); |
| 781 | } |
| 782 | return result.Succeeded(); |
| 783 | } |
| 784 | }; |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 789 | class CommandObjectPlatformProcess : public CommandObjectMultiword |
| 790 | { |
| 791 | public: |
| 792 | //------------------------------------------------------------------ |
| 793 | // Constructors and Destructors |
| 794 | //------------------------------------------------------------------ |
| 795 | CommandObjectPlatformProcess (CommandInterpreter &interpreter) : |
| 796 | CommandObjectMultiword (interpreter, |
| 797 | "platform process", |
| 798 | "A set of commands to query, launch and attach to platform processes", |
| 799 | "platform process [attach|launch|list] ...") |
| 800 | { |
| 801 | // LoadSubCommand ("attach", CommandObjectSP (new CommandObjectPlatformProcessAttach (interpreter))); |
| 802 | // LoadSubCommand ("launch", CommandObjectSP (new CommandObjectPlatformProcessLaunch (interpreter))); |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 803 | LoadSubCommand ("info" , CommandObjectSP (new CommandObjectPlatformProcessInfo (interpreter))); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 804 | LoadSubCommand ("list" , CommandObjectSP (new CommandObjectPlatformProcessList (interpreter))); |
| 805 | |
| 806 | } |
| 807 | |
| 808 | virtual |
| 809 | ~CommandObjectPlatformProcess () |
| 810 | { |
| 811 | } |
| 812 | |
| 813 | private: |
| 814 | //------------------------------------------------------------------ |
| 815 | // For CommandObjectPlatform only |
| 816 | //------------------------------------------------------------------ |
| 817 | DISALLOW_COPY_AND_ASSIGN (CommandObjectPlatformProcess); |
| 818 | }; |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 819 | |
| 820 | //---------------------------------------------------------------------- |
| 821 | // CommandObjectPlatform constructor |
| 822 | //---------------------------------------------------------------------- |
| 823 | CommandObjectPlatform::CommandObjectPlatform(CommandInterpreter &interpreter) : |
| 824 | CommandObjectMultiword (interpreter, |
| 825 | "platform", |
| 826 | "A set of commands to manage and create platforms.", |
Greg Clayton | ff39f74 | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 827 | "platform [connect|create|disconnect|info|list|status|select] ...") |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 828 | { |
| 829 | LoadSubCommand ("create", CommandObjectSP (new CommandObjectPlatformCreate (interpreter))); |
| 830 | LoadSubCommand ("list" , CommandObjectSP (new CommandObjectPlatformList (interpreter))); |
| 831 | LoadSubCommand ("select", CommandObjectSP (new CommandObjectPlatformSelect (interpreter))); |
| 832 | LoadSubCommand ("status", CommandObjectSP (new CommandObjectPlatformStatus (interpreter))); |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 833 | LoadSubCommand ("connect", CommandObjectSP (new CommandObjectPlatformConnect (interpreter))); |
| 834 | LoadSubCommand ("disconnect", CommandObjectSP (new CommandObjectPlatformDisconnect (interpreter))); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 835 | LoadSubCommand ("process", CommandObjectSP (new CommandObjectPlatformProcess (interpreter))); |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | |
| 839 | //---------------------------------------------------------------------- |
| 840 | // Destructor |
| 841 | //---------------------------------------------------------------------- |
| 842 | CommandObjectPlatform::~CommandObjectPlatform() |
| 843 | { |
| 844 | } |