Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1 | //===-- CommandObjectPlatform.cpp -------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Greg Clayton | 1cf2aa8 | 2016-03-24 21:49:22 +0000 | [diff] [blame] | 9 | #include <mutex> |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 10 | #include "CommandObjectPlatform.h" |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 11 | #include "lldb/Core/Debugger.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Module.h" |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 13 | #include "lldb/Core/PluginManager.h" |
Zachary Turner | 3eb2b44 | 2017-03-22 23:33:16 +0000 | [diff] [blame] | 14 | #include "lldb/Host/OptionParser.h" |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 15 | #include "lldb/Host/StringConvert.h" |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 16 | #include "lldb/Interpreter/CommandInterpreter.h" |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 17 | #include "lldb/Interpreter/CommandOptionValidators.h" |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/CommandReturnObject.h" |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 19 | #include "lldb/Interpreter/OptionGroupFile.h" |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 20 | #include "lldb/Interpreter/OptionGroupPlatform.h" |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 21 | #include "lldb/Target/ExecutionContext.h" |
| 22 | #include "lldb/Target/Platform.h" |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 23 | #include "lldb/Target/Process.h" |
Pavel Labath | 145d95c | 2018-04-17 18:53:35 +0000 | [diff] [blame] | 24 | #include "lldb/Utility/Args.h" |
Zachary Turner | 666cc0b | 2017-03-04 01:30:05 +0000 | [diff] [blame] | 25 | #include "lldb/Utility/DataExtractor.h" |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 26 | |
Zachary Turner | ecbb0bb | 2016-09-19 17:54:06 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/SmallString.h" |
Kamil Rytarowski | c5f28e2 | 2017-02-06 17:55:02 +0000 | [diff] [blame] | 28 | #include "llvm/Support/Threading.h" |
Zachary Turner | ecbb0bb | 2016-09-19 17:54:06 +0000 | [diff] [blame] | 29 | |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 30 | using namespace lldb; |
| 31 | using namespace lldb_private; |
| 32 | |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 33 | static mode_t ParsePermissionString(const char *) = delete; |
| 34 | |
| 35 | static mode_t ParsePermissionString(llvm::StringRef permissions) { |
| 36 | if (permissions.size() != 9) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | return (mode_t)(-1); |
| 38 | bool user_r, user_w, user_x, group_r, group_w, group_x, world_r, world_w, |
| 39 | world_x; |
| 40 | |
| 41 | user_r = (permissions[0] == 'r'); |
| 42 | user_w = (permissions[1] == 'w'); |
| 43 | user_x = (permissions[2] == 'x'); |
| 44 | |
| 45 | group_r = (permissions[3] == 'r'); |
| 46 | group_w = (permissions[4] == 'w'); |
| 47 | group_x = (permissions[5] == 'x'); |
| 48 | |
| 49 | world_r = (permissions[6] == 'r'); |
| 50 | world_w = (permissions[7] == 'w'); |
| 51 | world_x = (permissions[8] == 'x'); |
| 52 | |
| 53 | mode_t user, group, world; |
| 54 | user = (user_r ? 4 : 0) | (user_w ? 2 : 0) | (user_x ? 1 : 0); |
| 55 | group = (group_r ? 4 : 0) | (group_w ? 2 : 0) | (group_x ? 1 : 0); |
| 56 | world = (world_r ? 4 : 0) | (world_w ? 2 : 0) | (world_x ? 1 : 0); |
| 57 | |
| 58 | return user | group | world; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Raphael Isemann | 2359fec | 2019-07-24 12:05:42 +0000 | [diff] [blame] | 61 | #define LLDB_OPTIONS_permissions |
Raphael Isemann | aaad1a8 | 2019-07-24 12:08:08 +0000 | [diff] [blame] | 62 | #include "CommandOptions.inc" |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 63 | |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 64 | class OptionPermissions : public OptionGroup { |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 65 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 66 | OptionPermissions() {} |
| 67 | |
| 68 | ~OptionPermissions() override = default; |
| 69 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 70 | lldb_private::Status |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 71 | SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | ExecutionContext *execution_context) override { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 73 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | char short_option = (char)GetDefinitions()[option_idx].short_option; |
| 75 | switch (short_option) { |
| 76 | case 'v': { |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 77 | if (option_arg.getAsInteger(8, m_permissions)) { |
| 78 | m_permissions = 0777; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 79 | error.SetErrorStringWithFormat("invalid value for permissions: %s", |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 80 | option_arg.str().c_str()); |
| 81 | } |
| 82 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 83 | } break; |
| 84 | case 's': { |
| 85 | mode_t perms = ParsePermissionString(option_arg); |
| 86 | if (perms == (mode_t)-1) |
| 87 | error.SetErrorStringWithFormat("invalid value for permissions: %s", |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 88 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 89 | else |
| 90 | m_permissions = perms; |
| 91 | } break; |
| 92 | case 'r': |
| 93 | m_permissions |= lldb::eFilePermissionsUserRead; |
| 94 | break; |
| 95 | case 'w': |
| 96 | m_permissions |= lldb::eFilePermissionsUserWrite; |
| 97 | break; |
| 98 | case 'x': |
| 99 | m_permissions |= lldb::eFilePermissionsUserExecute; |
| 100 | break; |
| 101 | case 'R': |
| 102 | m_permissions |= lldb::eFilePermissionsGroupRead; |
| 103 | break; |
| 104 | case 'W': |
| 105 | m_permissions |= lldb::eFilePermissionsGroupWrite; |
| 106 | break; |
| 107 | case 'X': |
| 108 | m_permissions |= lldb::eFilePermissionsGroupExecute; |
| 109 | break; |
| 110 | case 'd': |
| 111 | m_permissions |= lldb::eFilePermissionsWorldRead; |
| 112 | break; |
| 113 | case 't': |
| 114 | m_permissions |= lldb::eFilePermissionsWorldWrite; |
| 115 | break; |
| 116 | case 'e': |
| 117 | m_permissions |= lldb::eFilePermissionsWorldExecute; |
| 118 | break; |
| 119 | default: |
Raphael Isemann | 3616201 | 2019-08-22 08:08:05 +0000 | [diff] [blame] | 120 | llvm_unreachable("Unimplemented option"); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 121 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 122 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 123 | return error; |
| 124 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 125 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 126 | void OptionParsingStarting(ExecutionContext *execution_context) override { |
| 127 | m_permissions = 0; |
| 128 | } |
| 129 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 130 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 131 | return llvm::makeArrayRef(g_permissions_options); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | // Instance variables to hold the values for command options. |
| 135 | |
| 136 | uint32_t m_permissions; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 137 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 138 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 139 | DISALLOW_COPY_AND_ASSIGN(OptionPermissions); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 140 | }; |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 141 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 142 | // "platform select <platform-name>" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 143 | class CommandObjectPlatformSelect : public CommandObjectParsed { |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 144 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 145 | CommandObjectPlatformSelect(CommandInterpreter &interpreter) |
| 146 | : CommandObjectParsed(interpreter, "platform select", |
| 147 | "Create a platform if needed and select it as the " |
| 148 | "current platform.", |
| 149 | "platform select <platform-name>", 0), |
| 150 | m_option_group(), |
| 151 | m_platform_options( |
| 152 | false) // Don't include the "--platform" option by passing false |
| 153 | { |
| 154 | m_option_group.Append(&m_platform_options, LLDB_OPT_SET_ALL, 1); |
| 155 | m_option_group.Finalize(); |
| 156 | } |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 157 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 158 | ~CommandObjectPlatformSelect() override = default; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 159 | |
Raphael Isemann | ae34ed2 | 2019-08-22 07:41:23 +0000 | [diff] [blame] | 160 | void HandleCompletion(CompletionRequest &request) override { |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame] | 161 | CommandCompletions::PlatformPluginNames(GetCommandInterpreter(), request, |
| 162 | nullptr); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | Options *GetOptions() override { return &m_option_group; } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 166 | |
| 167 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 168 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 169 | if (args.GetArgumentCount() == 1) { |
| 170 | const char *platform_name = args.GetArgumentAtIndex(0); |
| 171 | if (platform_name && platform_name[0]) { |
| 172 | const bool select = true; |
| 173 | m_platform_options.SetPlatformName(platform_name); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 174 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 175 | ArchSpec platform_arch; |
| 176 | PlatformSP platform_sp(m_platform_options.CreatePlatformWithOptions( |
| 177 | m_interpreter, ArchSpec(), select, error, platform_arch)); |
| 178 | if (platform_sp) { |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 179 | GetDebugger().GetPlatformList().SetSelectedPlatform(platform_sp); |
Vince Harron | 1b5a74e | 2015-01-21 22:42:49 +0000 | [diff] [blame] | 180 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 181 | platform_sp->GetStatus(result.GetOutputStream()); |
| 182 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 183 | } else { |
| 184 | result.AppendError(error.AsCString()); |
| 185 | result.SetStatus(eReturnStatusFailed); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 186 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 187 | } else { |
| 188 | result.AppendError("invalid platform name"); |
| 189 | result.SetStatus(eReturnStatusFailed); |
| 190 | } |
| 191 | } else { |
| 192 | result.AppendError( |
| 193 | "platform create takes a platform name as an argument\n"); |
| 194 | result.SetStatus(eReturnStatusFailed); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 195 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 196 | return result.Succeeded(); |
| 197 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 198 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 199 | OptionGroupOptions m_option_group; |
| 200 | OptionGroupPlatform m_platform_options; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 201 | }; |
| 202 | |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 203 | // "platform list" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 204 | class CommandObjectPlatformList : public CommandObjectParsed { |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 205 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 206 | CommandObjectPlatformList(CommandInterpreter &interpreter) |
| 207 | : CommandObjectParsed(interpreter, "platform list", |
| 208 | "List all platforms that are available.", nullptr, |
| 209 | 0) {} |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 210 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 211 | ~CommandObjectPlatformList() override = default; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 212 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 213 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 214 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 215 | Stream &ostrm = result.GetOutputStream(); |
| 216 | ostrm.Printf("Available platforms:\n"); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 217 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 218 | PlatformSP host_platform_sp(Platform::GetHostPlatform()); |
| 219 | ostrm.Printf("%s: %s\n", host_platform_sp->GetPluginName().GetCString(), |
| 220 | host_platform_sp->GetDescription()); |
| 221 | |
| 222 | uint32_t idx; |
Jonas Devlieghere | 09ad8c8 | 2019-05-24 00:44:33 +0000 | [diff] [blame] | 223 | for (idx = 0; true; ++idx) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 224 | const char *plugin_name = |
| 225 | PluginManager::GetPlatformPluginNameAtIndex(idx); |
| 226 | if (plugin_name == nullptr) |
| 227 | break; |
| 228 | const char *plugin_desc = |
| 229 | PluginManager::GetPlatformPluginDescriptionAtIndex(idx); |
| 230 | if (plugin_desc == nullptr) |
| 231 | break; |
| 232 | ostrm.Printf("%s: %s\n", plugin_name, plugin_desc); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 233 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 234 | |
| 235 | if (idx == 0) { |
| 236 | result.AppendError("no platforms are available\n"); |
| 237 | result.SetStatus(eReturnStatusFailed); |
| 238 | } else |
| 239 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 240 | return result.Succeeded(); |
| 241 | } |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 242 | }; |
| 243 | |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 244 | // "platform status" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 245 | class CommandObjectPlatformStatus : public CommandObjectParsed { |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 246 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 247 | CommandObjectPlatformStatus(CommandInterpreter &interpreter) |
| 248 | : CommandObjectParsed(interpreter, "platform status", |
| 249 | "Display status for the current platform.", nullptr, |
| 250 | 0) {} |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 251 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 252 | ~CommandObjectPlatformStatus() override = default; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 253 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 254 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 255 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 256 | Stream &ostrm = result.GetOutputStream(); |
| 257 | |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 258 | Target *target = GetDebugger().GetSelectedTarget().get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 259 | PlatformSP platform_sp; |
| 260 | if (target) { |
| 261 | platform_sp = target->GetPlatform(); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 262 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 263 | if (!platform_sp) { |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 264 | platform_sp = GetDebugger().GetPlatformList().GetSelectedPlatform(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 265 | } |
| 266 | if (platform_sp) { |
| 267 | platform_sp->GetStatus(ostrm); |
| 268 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 269 | } else { |
Bruce Mitchener | 2b13913 | 2017-07-21 07:08:20 +0000 | [diff] [blame] | 270 | result.AppendError("no platform is currently selected\n"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 271 | result.SetStatus(eReturnStatusFailed); |
| 272 | } |
| 273 | return result.Succeeded(); |
| 274 | } |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 275 | }; |
| 276 | |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 277 | // "platform connect <connect-url>" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 278 | class CommandObjectPlatformConnect : public CommandObjectParsed { |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 279 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 280 | CommandObjectPlatformConnect(CommandInterpreter &interpreter) |
| 281 | : CommandObjectParsed( |
| 282 | interpreter, "platform connect", |
| 283 | "Select the current platform by providing a connection URL.", |
| 284 | "platform connect <connect-url>", 0) {} |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 285 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 286 | ~CommandObjectPlatformConnect() override = default; |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 287 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 288 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 289 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 290 | Stream &ostrm = result.GetOutputStream(); |
Tamas Berghammer | ccd6cff | 2015-12-08 14:08:19 +0000 | [diff] [blame] | 291 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 292 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 293 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 294 | if (platform_sp) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 295 | Status error(platform_sp->ConnectRemote(args)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 296 | if (error.Success()) { |
| 297 | platform_sp->GetStatus(ostrm); |
| 298 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 299 | |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 300 | platform_sp->ConnectToWaitingProcesses(GetDebugger(), error); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 301 | if (error.Fail()) { |
| 302 | result.AppendError(error.AsCString()); |
| 303 | result.SetStatus(eReturnStatusFailed); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 304 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 305 | } else { |
| 306 | result.AppendErrorWithFormat("%s\n", error.AsCString()); |
| 307 | result.SetStatus(eReturnStatusFailed); |
| 308 | } |
| 309 | } else { |
| 310 | result.AppendError("no platform is currently selected\n"); |
| 311 | result.SetStatus(eReturnStatusFailed); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 312 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 313 | return result.Succeeded(); |
| 314 | } |
| 315 | |
| 316 | Options *GetOptions() override { |
| 317 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 318 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 319 | OptionGroupOptions *m_platform_options = nullptr; |
| 320 | if (platform_sp) { |
| 321 | m_platform_options = platform_sp->GetConnectionOptions(m_interpreter); |
| 322 | if (m_platform_options != nullptr && !m_platform_options->m_did_finalize) |
| 323 | m_platform_options->Finalize(); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 324 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 325 | return m_platform_options; |
| 326 | } |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 327 | }; |
| 328 | |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 329 | // "platform disconnect" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 330 | class CommandObjectPlatformDisconnect : public CommandObjectParsed { |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 331 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 332 | CommandObjectPlatformDisconnect(CommandInterpreter &interpreter) |
| 333 | : CommandObjectParsed(interpreter, "platform disconnect", |
| 334 | "Disconnect from the current platform.", |
| 335 | "platform disconnect", 0) {} |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 336 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 337 | ~CommandObjectPlatformDisconnect() override = default; |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 338 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 339 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 340 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 341 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 342 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 343 | if (platform_sp) { |
| 344 | if (args.GetArgumentCount() == 0) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 345 | Status error; |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 346 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 347 | if (platform_sp->IsConnected()) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 348 | // Cache the instance name if there is one since we are about to |
| 349 | // disconnect and the name might go with it. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 350 | const char *hostname_cstr = platform_sp->GetHostname(); |
| 351 | std::string hostname; |
| 352 | if (hostname_cstr) |
| 353 | hostname.assign(hostname_cstr); |
| 354 | |
| 355 | error = platform_sp->DisconnectRemote(); |
| 356 | if (error.Success()) { |
| 357 | Stream &ostrm = result.GetOutputStream(); |
| 358 | if (hostname.empty()) |
| 359 | ostrm.Printf("Disconnected from \"%s\"\n", |
| 360 | platform_sp->GetPluginName().GetCString()); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 361 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 362 | ostrm.Printf("Disconnected from \"%s\"\n", hostname.c_str()); |
| 363 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 364 | } else { |
| 365 | result.AppendErrorWithFormat("%s", error.AsCString()); |
| 366 | result.SetStatus(eReturnStatusFailed); |
| 367 | } |
| 368 | } else { |
| 369 | // Not connected... |
| 370 | result.AppendErrorWithFormat( |
| 371 | "not connected to '%s'", |
| 372 | platform_sp->GetPluginName().GetCString()); |
| 373 | result.SetStatus(eReturnStatusFailed); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 374 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 375 | } else { |
| 376 | // Bad args |
| 377 | result.AppendError( |
| 378 | "\"platform disconnect\" doesn't take any arguments"); |
| 379 | result.SetStatus(eReturnStatusFailed); |
| 380 | } |
| 381 | } else { |
| 382 | result.AppendError("no platform is currently selected"); |
| 383 | result.SetStatus(eReturnStatusFailed); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 384 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 385 | return result.Succeeded(); |
| 386 | } |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 387 | }; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 388 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 389 | // "platform settings" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 390 | class CommandObjectPlatformSettings : public CommandObjectParsed { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 391 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 392 | CommandObjectPlatformSettings(CommandInterpreter &interpreter) |
| 393 | : CommandObjectParsed(interpreter, "platform settings", |
| 394 | "Set settings for the current target's platform, " |
| 395 | "or for a platform by name.", |
| 396 | "platform settings", 0), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 397 | m_options(), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 398 | m_option_working_dir(LLDB_OPT_SET_1, false, "working-dir", 'w', 0, |
| 399 | eArgTypePath, |
| 400 | "The working directory for the platform.") { |
| 401 | m_options.Append(&m_option_working_dir, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 402 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 403 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 404 | ~CommandObjectPlatformSettings() override = default; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 405 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 406 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 407 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 408 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 409 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 410 | if (platform_sp) { |
| 411 | if (m_option_working_dir.GetOptionValue().OptionWasSet()) |
| 412 | platform_sp->SetWorkingDirectory( |
| 413 | m_option_working_dir.GetOptionValue().GetCurrentValue()); |
| 414 | } else { |
| 415 | result.AppendError("no platform is currently selected"); |
| 416 | result.SetStatus(eReturnStatusFailed); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 417 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 418 | return result.Succeeded(); |
| 419 | } |
| 420 | |
| 421 | Options *GetOptions() override { |
| 422 | if (!m_options.DidFinalize()) |
| 423 | m_options.Finalize(); |
| 424 | return &m_options; |
| 425 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 426 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 427 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 428 | OptionGroupOptions m_options; |
| 429 | OptionGroupFile m_option_working_dir; |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 430 | }; |
| 431 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 432 | // "platform mkdir" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 433 | class CommandObjectPlatformMkDir : public CommandObjectParsed { |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 434 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 435 | CommandObjectPlatformMkDir(CommandInterpreter &interpreter) |
| 436 | : CommandObjectParsed(interpreter, "platform mkdir", |
| 437 | "Make a new directory on the remote end.", nullptr, |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 438 | 0), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 439 | m_options() {} |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 440 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 441 | ~CommandObjectPlatformMkDir() override = default; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 442 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 443 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 444 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 445 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 446 | if (platform_sp) { |
| 447 | std::string cmd_line; |
| 448 | args.GetCommandString(cmd_line); |
| 449 | uint32_t mode; |
| 450 | const OptionPermissions *options_permissions = |
| 451 | (const OptionPermissions *)m_options.GetGroupWithOption('r'); |
| 452 | if (options_permissions) |
| 453 | mode = options_permissions->m_permissions; |
| 454 | else |
| 455 | mode = lldb::eFilePermissionsUserRWX | lldb::eFilePermissionsGroupRWX | |
| 456 | lldb::eFilePermissionsWorldRX; |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 457 | Status error = platform_sp->MakeDirectory(FileSpec(cmd_line), mode); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 458 | if (error.Success()) { |
| 459 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 460 | } else { |
| 461 | result.AppendError(error.AsCString()); |
| 462 | result.SetStatus(eReturnStatusFailed); |
| 463 | } |
| 464 | } else { |
| 465 | result.AppendError("no platform currently selected\n"); |
| 466 | result.SetStatus(eReturnStatusFailed); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 467 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 468 | return result.Succeeded(); |
| 469 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 470 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 471 | Options *GetOptions() override { |
| 472 | if (!m_options.DidFinalize()) { |
| 473 | m_options.Append(new OptionPermissions()); |
| 474 | m_options.Finalize(); |
| 475 | } |
| 476 | return &m_options; |
| 477 | } |
| 478 | |
| 479 | OptionGroupOptions m_options; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 480 | }; |
| 481 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 482 | // "platform fopen" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 483 | class CommandObjectPlatformFOpen : public CommandObjectParsed { |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 484 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 485 | CommandObjectPlatformFOpen(CommandInterpreter &interpreter) |
| 486 | : CommandObjectParsed(interpreter, "platform file open", |
| 487 | "Open a file on the remote end.", nullptr, 0), |
| 488 | m_options() {} |
| 489 | |
| 490 | ~CommandObjectPlatformFOpen() override = default; |
| 491 | |
| 492 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 493 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 494 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 495 | if (platform_sp) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 496 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 497 | std::string cmd_line; |
| 498 | args.GetCommandString(cmd_line); |
| 499 | mode_t perms; |
| 500 | const OptionPermissions *options_permissions = |
| 501 | (const OptionPermissions *)m_options.GetGroupWithOption('r'); |
| 502 | if (options_permissions) |
| 503 | perms = options_permissions->m_permissions; |
| 504 | else |
| 505 | perms = lldb::eFilePermissionsUserRW | lldb::eFilePermissionsGroupRW | |
| 506 | lldb::eFilePermissionsWorldRead; |
| 507 | lldb::user_id_t fd = platform_sp->OpenFile( |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 508 | FileSpec(cmd_line), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 509 | File::eOpenOptionRead | File::eOpenOptionWrite | |
| 510 | File::eOpenOptionAppend | File::eOpenOptionCanCreate, |
| 511 | perms, error); |
| 512 | if (error.Success()) { |
| 513 | result.AppendMessageWithFormat("File Descriptor = %" PRIu64 "\n", fd); |
| 514 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 515 | } else { |
| 516 | result.AppendError(error.AsCString()); |
| 517 | result.SetStatus(eReturnStatusFailed); |
| 518 | } |
| 519 | } else { |
| 520 | result.AppendError("no platform currently selected\n"); |
| 521 | result.SetStatus(eReturnStatusFailed); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 522 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 523 | return result.Succeeded(); |
| 524 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 525 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 526 | Options *GetOptions() override { |
| 527 | if (!m_options.DidFinalize()) { |
| 528 | m_options.Append(new OptionPermissions()); |
| 529 | m_options.Finalize(); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 530 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 531 | return &m_options; |
| 532 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 533 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 534 | OptionGroupOptions m_options; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 535 | }; |
| 536 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 537 | // "platform fclose" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 538 | class CommandObjectPlatformFClose : public CommandObjectParsed { |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 539 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 540 | CommandObjectPlatformFClose(CommandInterpreter &interpreter) |
| 541 | : CommandObjectParsed(interpreter, "platform file close", |
| 542 | "Close a file on the remote end.", nullptr, 0) {} |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 543 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 544 | ~CommandObjectPlatformFClose() override = default; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 545 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 546 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 547 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 548 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 549 | if (platform_sp) { |
| 550 | std::string cmd_line; |
| 551 | args.GetCommandString(cmd_line); |
| 552 | const lldb::user_id_t fd = |
| 553 | StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 554 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 555 | bool success = platform_sp->CloseFile(fd, error); |
| 556 | if (success) { |
| 557 | result.AppendMessageWithFormat("file %" PRIu64 " closed.\n", fd); |
| 558 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 559 | } else { |
| 560 | result.AppendError(error.AsCString()); |
| 561 | result.SetStatus(eReturnStatusFailed); |
| 562 | } |
| 563 | } else { |
| 564 | result.AppendError("no platform currently selected\n"); |
| 565 | result.SetStatus(eReturnStatusFailed); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 566 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 567 | return result.Succeeded(); |
| 568 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 569 | }; |
| 570 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 571 | // "platform fread" |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 572 | |
Raphael Isemann | 2359fec | 2019-07-24 12:05:42 +0000 | [diff] [blame] | 573 | #define LLDB_OPTIONS_platform_fread |
| 574 | #include "CommandOptions.inc" |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 575 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 576 | class CommandObjectPlatformFRead : public CommandObjectParsed { |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 577 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 578 | CommandObjectPlatformFRead(CommandInterpreter &interpreter) |
| 579 | : CommandObjectParsed(interpreter, "platform file read", |
| 580 | "Read data from a file on the remote end.", nullptr, |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 581 | 0), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 582 | m_options() {} |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 583 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 584 | ~CommandObjectPlatformFRead() override = default; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 585 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 586 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 587 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 588 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 589 | if (platform_sp) { |
| 590 | std::string cmd_line; |
| 591 | args.GetCommandString(cmd_line); |
| 592 | const lldb::user_id_t fd = |
| 593 | StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX); |
| 594 | std::string buffer(m_options.m_count, 0); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 595 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 596 | uint32_t retcode = platform_sp->ReadFile( |
| 597 | fd, m_options.m_offset, &buffer[0], m_options.m_count, error); |
| 598 | result.AppendMessageWithFormat("Return = %d\n", retcode); |
| 599 | result.AppendMessageWithFormat("Data = \"%s\"\n", buffer.c_str()); |
| 600 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 601 | } else { |
| 602 | result.AppendError("no platform currently selected\n"); |
| 603 | result.SetStatus(eReturnStatusFailed); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 604 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 605 | return result.Succeeded(); |
| 606 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 607 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 608 | Options *GetOptions() override { return &m_options; } |
| 609 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 610 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 611 | class CommandOptions : public Options { |
| 612 | public: |
| 613 | CommandOptions() : Options() {} |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 614 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 615 | ~CommandOptions() override = default; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 616 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 617 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, |
| 618 | ExecutionContext *execution_context) override { |
| 619 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 620 | char short_option = (char)m_getopt_table[option_idx].val; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 621 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 622 | switch (short_option) { |
| 623 | case 'o': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 624 | if (option_arg.getAsInteger(0, m_offset)) |
| 625 | error.SetErrorStringWithFormat("invalid offset: '%s'", |
| 626 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 627 | break; |
| 628 | case 'c': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 629 | if (option_arg.getAsInteger(0, m_count)) |
| 630 | error.SetErrorStringWithFormat("invalid offset: '%s'", |
| 631 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 632 | break; |
| 633 | default: |
Raphael Isemann | 3616201 | 2019-08-22 08:08:05 +0000 | [diff] [blame] | 634 | llvm_unreachable("Unimplemented option"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | return error; |
| 638 | } |
| 639 | |
| 640 | void OptionParsingStarting(ExecutionContext *execution_context) override { |
| 641 | m_offset = 0; |
| 642 | m_count = 1; |
| 643 | } |
| 644 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 645 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 646 | return llvm::makeArrayRef(g_platform_fread_options); |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 647 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 648 | |
| 649 | // Instance variables to hold the values for command options. |
| 650 | |
| 651 | uint32_t m_offset; |
| 652 | uint32_t m_count; |
| 653 | }; |
| 654 | |
| 655 | CommandOptions m_options; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 656 | }; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 657 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 658 | // "platform fwrite" |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 659 | |
Raphael Isemann | 2359fec | 2019-07-24 12:05:42 +0000 | [diff] [blame] | 660 | #define LLDB_OPTIONS_platform_fwrite |
| 661 | #include "CommandOptions.inc" |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 662 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 663 | class CommandObjectPlatformFWrite : public CommandObjectParsed { |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 664 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 665 | CommandObjectPlatformFWrite(CommandInterpreter &interpreter) |
| 666 | : CommandObjectParsed(interpreter, "platform file write", |
| 667 | "Write data to a file on the remote end.", nullptr, |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 668 | 0), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 669 | m_options() {} |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 670 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 671 | ~CommandObjectPlatformFWrite() override = default; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 672 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 673 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 674 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 675 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 676 | if (platform_sp) { |
| 677 | std::string cmd_line; |
| 678 | args.GetCommandString(cmd_line); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 679 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 680 | const lldb::user_id_t fd = |
| 681 | StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX); |
| 682 | uint32_t retcode = |
| 683 | platform_sp->WriteFile(fd, m_options.m_offset, &m_options.m_data[0], |
| 684 | m_options.m_data.size(), error); |
| 685 | result.AppendMessageWithFormat("Return = %d\n", retcode); |
| 686 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 687 | } else { |
| 688 | result.AppendError("no platform currently selected\n"); |
| 689 | result.SetStatus(eReturnStatusFailed); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 690 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 691 | return result.Succeeded(); |
| 692 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 693 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 694 | Options *GetOptions() override { return &m_options; } |
| 695 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 696 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 697 | class CommandOptions : public Options { |
| 698 | public: |
| 699 | CommandOptions() : Options() {} |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 700 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 701 | ~CommandOptions() override = default; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 702 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 703 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, |
| 704 | ExecutionContext *execution_context) override { |
| 705 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 706 | char short_option = (char)m_getopt_table[option_idx].val; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 707 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 708 | switch (short_option) { |
| 709 | case 'o': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 710 | if (option_arg.getAsInteger(0, m_offset)) |
| 711 | error.SetErrorStringWithFormat("invalid offset: '%s'", |
| 712 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 713 | break; |
| 714 | case 'd': |
| 715 | m_data.assign(option_arg); |
| 716 | break; |
| 717 | default: |
Raphael Isemann | 3616201 | 2019-08-22 08:08:05 +0000 | [diff] [blame] | 718 | llvm_unreachable("Unimplemented option"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | return error; |
| 722 | } |
| 723 | |
| 724 | void OptionParsingStarting(ExecutionContext *execution_context) override { |
| 725 | m_offset = 0; |
| 726 | m_data.clear(); |
| 727 | } |
| 728 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 729 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 730 | return llvm::makeArrayRef(g_platform_fwrite_options); |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 731 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 732 | |
| 733 | // Instance variables to hold the values for command options. |
| 734 | |
| 735 | uint32_t m_offset; |
| 736 | std::string m_data; |
| 737 | }; |
| 738 | |
| 739 | CommandOptions m_options; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 740 | }; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 741 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 742 | class CommandObjectPlatformFile : public CommandObjectMultiword { |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 743 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 744 | // Constructors and Destructors |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 745 | CommandObjectPlatformFile(CommandInterpreter &interpreter) |
| 746 | : CommandObjectMultiword( |
| 747 | interpreter, "platform file", |
| 748 | "Commands to access files on the current platform.", |
| 749 | "platform file [open|close|read|write] ...") { |
| 750 | LoadSubCommand( |
| 751 | "open", CommandObjectSP(new CommandObjectPlatformFOpen(interpreter))); |
| 752 | LoadSubCommand( |
| 753 | "close", CommandObjectSP(new CommandObjectPlatformFClose(interpreter))); |
| 754 | LoadSubCommand( |
| 755 | "read", CommandObjectSP(new CommandObjectPlatformFRead(interpreter))); |
| 756 | LoadSubCommand( |
| 757 | "write", CommandObjectSP(new CommandObjectPlatformFWrite(interpreter))); |
| 758 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 759 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 760 | ~CommandObjectPlatformFile() override = default; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 761 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 762 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 763 | // For CommandObjectPlatform only |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 764 | DISALLOW_COPY_AND_ASSIGN(CommandObjectPlatformFile); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 765 | }; |
| 766 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 767 | // "platform get-file remote-file-path host-file-path" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 768 | class CommandObjectPlatformGetFile : public CommandObjectParsed { |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 769 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 770 | CommandObjectPlatformGetFile(CommandInterpreter &interpreter) |
| 771 | : CommandObjectParsed( |
| 772 | interpreter, "platform get-file", |
| 773 | "Transfer a file from the remote end to the local host.", |
| 774 | "platform get-file <remote-file-spec> <local-file-spec>", 0) { |
| 775 | SetHelpLong( |
| 776 | R"(Examples: |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 777 | |
| 778 | (lldb) platform get-file /the/remote/file/path /the/local/file/path |
| 779 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 780 | Transfer a file from the remote end with file path /the/remote/file/path to the local host.)"); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 781 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 782 | CommandArgumentEntry arg1, arg2; |
| 783 | CommandArgumentData file_arg_remote, file_arg_host; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 784 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 785 | // Define the first (and only) variant of this arg. |
| 786 | file_arg_remote.arg_type = eArgTypeFilename; |
| 787 | file_arg_remote.arg_repetition = eArgRepeatPlain; |
| 788 | // There is only one variant this argument could be; put it into the |
| 789 | // argument entry. |
| 790 | arg1.push_back(file_arg_remote); |
| 791 | |
| 792 | // Define the second (and only) variant of this arg. |
| 793 | file_arg_host.arg_type = eArgTypeFilename; |
| 794 | file_arg_host.arg_repetition = eArgRepeatPlain; |
| 795 | // There is only one variant this argument could be; put it into the |
| 796 | // argument entry. |
| 797 | arg2.push_back(file_arg_host); |
| 798 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 799 | // Push the data for the first and the second arguments into the |
| 800 | // m_arguments vector. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 801 | m_arguments.push_back(arg1); |
| 802 | m_arguments.push_back(arg2); |
| 803 | } |
| 804 | |
| 805 | ~CommandObjectPlatformGetFile() override = default; |
| 806 | |
| 807 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 808 | // If the number of arguments is incorrect, issue an error message. |
| 809 | if (args.GetArgumentCount() != 2) { |
| 810 | result.GetErrorStream().Printf("error: required arguments missing; " |
| 811 | "specify both the source and destination " |
| 812 | "file paths\n"); |
| 813 | result.SetStatus(eReturnStatusFailed); |
| 814 | return false; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 815 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 816 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 817 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 818 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 819 | if (platform_sp) { |
| 820 | const char *remote_file_path = args.GetArgumentAtIndex(0); |
| 821 | const char *local_file_path = args.GetArgumentAtIndex(1); |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 822 | Status error = platform_sp->GetFile(FileSpec(remote_file_path), |
| 823 | FileSpec(local_file_path)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 824 | if (error.Success()) { |
| 825 | result.AppendMessageWithFormat( |
| 826 | "successfully get-file from %s (remote) to %s (host)\n", |
| 827 | remote_file_path, local_file_path); |
| 828 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 829 | } else { |
| 830 | result.AppendMessageWithFormat("get-file failed: %s\n", |
| 831 | error.AsCString()); |
| 832 | result.SetStatus(eReturnStatusFailed); |
| 833 | } |
| 834 | } else { |
| 835 | result.AppendError("no platform currently selected\n"); |
| 836 | result.SetStatus(eReturnStatusFailed); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 837 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 838 | return result.Succeeded(); |
| 839 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 840 | }; |
| 841 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 842 | // "platform get-size remote-file-path" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 843 | class CommandObjectPlatformGetSize : public CommandObjectParsed { |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 844 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 845 | CommandObjectPlatformGetSize(CommandInterpreter &interpreter) |
| 846 | : CommandObjectParsed(interpreter, "platform get-size", |
| 847 | "Get the file size from the remote end.", |
| 848 | "platform get-size <remote-file-spec>", 0) { |
| 849 | SetHelpLong( |
| 850 | R"(Examples: |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 851 | |
| 852 | (lldb) platform get-size /the/remote/file/path |
| 853 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 854 | Get the file size from the remote end with path /the/remote/file/path.)"); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 855 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 856 | CommandArgumentEntry arg1; |
| 857 | CommandArgumentData file_arg_remote; |
| 858 | |
| 859 | // Define the first (and only) variant of this arg. |
| 860 | file_arg_remote.arg_type = eArgTypeFilename; |
| 861 | file_arg_remote.arg_repetition = eArgRepeatPlain; |
| 862 | // There is only one variant this argument could be; put it into the |
| 863 | // argument entry. |
| 864 | arg1.push_back(file_arg_remote); |
| 865 | |
| 866 | // Push the data for the first argument into the m_arguments vector. |
| 867 | m_arguments.push_back(arg1); |
| 868 | } |
| 869 | |
| 870 | ~CommandObjectPlatformGetSize() override = default; |
| 871 | |
| 872 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 873 | // If the number of arguments is incorrect, issue an error message. |
| 874 | if (args.GetArgumentCount() != 1) { |
| 875 | result.GetErrorStream().Printf("error: required argument missing; " |
| 876 | "specify the source file path as the only " |
| 877 | "argument\n"); |
| 878 | result.SetStatus(eReturnStatusFailed); |
| 879 | return false; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 880 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 881 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 882 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 883 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 884 | if (platform_sp) { |
| 885 | std::string remote_file_path(args.GetArgumentAtIndex(0)); |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 886 | user_id_t size = platform_sp->GetFileSize(FileSpec(remote_file_path)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 887 | if (size != UINT64_MAX) { |
| 888 | result.AppendMessageWithFormat("File size of %s (remote): %" PRIu64 |
| 889 | "\n", |
| 890 | remote_file_path.c_str(), size); |
| 891 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 892 | } else { |
| 893 | result.AppendMessageWithFormat( |
| 894 | "Error getting file size of %s (remote)\n", |
| 895 | remote_file_path.c_str()); |
| 896 | result.SetStatus(eReturnStatusFailed); |
| 897 | } |
| 898 | } else { |
| 899 | result.AppendError("no platform currently selected\n"); |
| 900 | result.SetStatus(eReturnStatusFailed); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 901 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 902 | return result.Succeeded(); |
| 903 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 904 | }; |
| 905 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 906 | // "platform put-file" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 907 | class CommandObjectPlatformPutFile : public CommandObjectParsed { |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 908 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 909 | CommandObjectPlatformPutFile(CommandInterpreter &interpreter) |
| 910 | : CommandObjectParsed( |
| 911 | interpreter, "platform put-file", |
| 912 | "Transfer a file from this system to the remote end.", nullptr, 0) { |
| 913 | } |
| 914 | |
| 915 | ~CommandObjectPlatformPutFile() override = default; |
| 916 | |
| 917 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 918 | const char *src = args.GetArgumentAtIndex(0); |
| 919 | const char *dst = args.GetArgumentAtIndex(1); |
| 920 | |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 921 | FileSpec src_fs(src); |
| 922 | FileSystem::Instance().Resolve(src_fs); |
| 923 | FileSpec dst_fs(dst ? dst : src_fs.GetFilename().GetCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 924 | |
| 925 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 926 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 927 | if (platform_sp) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 928 | Status error(platform_sp->PutFile(src_fs, dst_fs)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 929 | if (error.Success()) { |
| 930 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 931 | } else { |
| 932 | result.AppendError(error.AsCString()); |
| 933 | result.SetStatus(eReturnStatusFailed); |
| 934 | } |
| 935 | } else { |
| 936 | result.AppendError("no platform currently selected\n"); |
| 937 | result.SetStatus(eReturnStatusFailed); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 938 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 939 | return result.Succeeded(); |
| 940 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 941 | }; |
| 942 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 943 | // "platform process launch" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 944 | class CommandObjectPlatformProcessLaunch : public CommandObjectParsed { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 945 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 946 | CommandObjectPlatformProcessLaunch(CommandInterpreter &interpreter) |
| 947 | : CommandObjectParsed(interpreter, "platform process launch", |
| 948 | "Launch a new process on a remote platform.", |
| 949 | "platform process launch program", |
| 950 | eCommandRequiresTarget | eCommandTryTargetAPILock), |
| 951 | m_options() {} |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 952 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 953 | ~CommandObjectPlatformProcessLaunch() override = default; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 954 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 955 | Options *GetOptions() override { return &m_options; } |
| 956 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 957 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 958 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 959 | Target *target = GetDebugger().GetSelectedTarget().get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 960 | PlatformSP platform_sp; |
| 961 | if (target) { |
| 962 | platform_sp = target->GetPlatform(); |
| 963 | } |
| 964 | if (!platform_sp) { |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 965 | platform_sp = GetDebugger().GetPlatformList().GetSelectedPlatform(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 966 | } |
Jason Molenda | 8c1157c | 2013-04-05 02:59:09 +0000 | [diff] [blame] | 967 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 968 | if (platform_sp) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 969 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 970 | const size_t argc = args.GetArgumentCount(); |
| 971 | Target *target = m_exe_ctx.GetTargetPtr(); |
| 972 | Module *exe_module = target->GetExecutableModulePointer(); |
| 973 | if (exe_module) { |
| 974 | m_options.launch_info.GetExecutableFile() = exe_module->GetFileSpec(); |
Stella Stamenova | b3f44ad | 2018-12-10 17:23:28 +0000 | [diff] [blame] | 975 | llvm::SmallString<128> exe_path; |
Zachary Turner | ecbb0bb | 2016-09-19 17:54:06 +0000 | [diff] [blame] | 976 | m_options.launch_info.GetExecutableFile().GetPath(exe_path); |
| 977 | if (!exe_path.empty()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 978 | m_options.launch_info.GetArguments().AppendArgument(exe_path); |
| 979 | m_options.launch_info.GetArchitecture() = exe_module->GetArchitecture(); |
| 980 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 981 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 982 | if (argc > 0) { |
| 983 | if (m_options.launch_info.GetExecutableFile()) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 984 | // We already have an executable file, so we will use this and all |
| 985 | // arguments to this function are extra arguments |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 986 | m_options.launch_info.GetArguments().AppendArguments(args); |
| 987 | } else { |
| 988 | // We don't have any file yet, so the first argument is our |
| 989 | // executable, and the rest are program arguments |
| 990 | const bool first_arg_is_executable = true; |
| 991 | m_options.launch_info.SetArguments(args, first_arg_is_executable); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 992 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | if (m_options.launch_info.GetExecutableFile()) { |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 996 | Debugger &debugger = GetDebugger(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 997 | |
| 998 | if (argc == 0) |
| 999 | target->GetRunArguments(m_options.launch_info.GetArguments()); |
| 1000 | |
| 1001 | ProcessSP process_sp(platform_sp->DebugProcess( |
| 1002 | m_options.launch_info, debugger, target, error)); |
| 1003 | if (process_sp && process_sp->IsAlive()) { |
| 1004 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 1005 | return true; |
| 1006 | } |
| 1007 | |
| 1008 | if (error.Success()) |
| 1009 | result.AppendError("process launch failed"); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1010 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1011 | result.AppendError(error.AsCString()); |
| 1012 | result.SetStatus(eReturnStatusFailed); |
| 1013 | } else { |
| 1014 | result.AppendError("'platform process launch' uses the current target " |
| 1015 | "file and arguments, or the executable and its " |
| 1016 | "arguments can be specified in this command"); |
| 1017 | result.SetStatus(eReturnStatusFailed); |
| 1018 | return false; |
| 1019 | } |
| 1020 | } else { |
| 1021 | result.AppendError("no platform is selected\n"); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1022 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1023 | return result.Succeeded(); |
| 1024 | } |
| 1025 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1026 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1027 | ProcessLaunchCommandOptions m_options; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1028 | }; |
| 1029 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1030 | // "platform process list" |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1031 | |
Raphael Isemann | 0ab0bb9 | 2019-07-26 11:46:21 +0000 | [diff] [blame] | 1032 | static PosixPlatformCommandOptionValidator posix_validator; |
Raphael Isemann | 2359fec | 2019-07-24 12:05:42 +0000 | [diff] [blame] | 1033 | #define LLDB_OPTIONS_platform_process_list |
| 1034 | #include "CommandOptions.inc" |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1035 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1036 | class CommandObjectPlatformProcessList : public CommandObjectParsed { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1037 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1038 | CommandObjectPlatformProcessList(CommandInterpreter &interpreter) |
| 1039 | : CommandObjectParsed(interpreter, "platform process list", |
| 1040 | "List processes on a remote platform by name, pid, " |
| 1041 | "or many other matching attributes.", |
| 1042 | "platform process list", 0), |
| 1043 | m_options() {} |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1044 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1045 | ~CommandObjectPlatformProcessList() override = default; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1046 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1047 | Options *GetOptions() override { return &m_options; } |
| 1048 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1049 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1050 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 1051 | Target *target = GetDebugger().GetSelectedTarget().get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1052 | PlatformSP platform_sp; |
| 1053 | if (target) { |
| 1054 | platform_sp = target->GetPlatform(); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1055 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1056 | if (!platform_sp) { |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 1057 | platform_sp = GetDebugger().GetPlatformList().GetSelectedPlatform(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1058 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1059 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1060 | if (platform_sp) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1061 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1062 | if (args.GetArgumentCount() == 0) { |
| 1063 | if (platform_sp) { |
| 1064 | Stream &ostrm = result.GetOutputStream(); |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1065 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1066 | lldb::pid_t pid = |
| 1067 | m_options.match_info.GetProcessInfo().GetProcessID(); |
| 1068 | if (pid != LLDB_INVALID_PROCESS_ID) { |
| 1069 | ProcessInstanceInfo proc_info; |
| 1070 | if (platform_sp->GetProcessInfo(pid, proc_info)) { |
Pavel Labath | aa51e6a | 2019-03-04 18:48:00 +0000 | [diff] [blame] | 1071 | ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1072 | m_options.verbose); |
Pavel Labath | aa51e6a | 2019-03-04 18:48:00 +0000 | [diff] [blame] | 1073 | proc_info.DumpAsTableRow(ostrm, platform_sp->GetUserIDResolver(), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1074 | m_options.show_args, m_options.verbose); |
| 1075 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 1076 | } else { |
| 1077 | result.AppendErrorWithFormat( |
| 1078 | "no process found with pid = %" PRIu64 "\n", pid); |
| 1079 | result.SetStatus(eReturnStatusFailed); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1080 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1081 | } else { |
| 1082 | ProcessInstanceInfoList proc_infos; |
| 1083 | const uint32_t matches = |
| 1084 | platform_sp->FindProcesses(m_options.match_info, proc_infos); |
| 1085 | const char *match_desc = nullptr; |
| 1086 | const char *match_name = |
| 1087 | m_options.match_info.GetProcessInfo().GetName(); |
| 1088 | if (match_name && match_name[0]) { |
| 1089 | switch (m_options.match_info.GetNameMatchType()) { |
Pavel Labath | c4a3395 | 2017-02-20 11:35:33 +0000 | [diff] [blame] | 1090 | case NameMatch::Ignore: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1091 | break; |
Pavel Labath | c4a3395 | 2017-02-20 11:35:33 +0000 | [diff] [blame] | 1092 | case NameMatch::Equals: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1093 | match_desc = "matched"; |
| 1094 | break; |
Pavel Labath | c4a3395 | 2017-02-20 11:35:33 +0000 | [diff] [blame] | 1095 | case NameMatch::Contains: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1096 | match_desc = "contained"; |
| 1097 | break; |
Pavel Labath | c4a3395 | 2017-02-20 11:35:33 +0000 | [diff] [blame] | 1098 | case NameMatch::StartsWith: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1099 | match_desc = "started with"; |
| 1100 | break; |
Pavel Labath | c4a3395 | 2017-02-20 11:35:33 +0000 | [diff] [blame] | 1101 | case NameMatch::EndsWith: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1102 | match_desc = "ended with"; |
| 1103 | break; |
Pavel Labath | c4a3395 | 2017-02-20 11:35:33 +0000 | [diff] [blame] | 1104 | case NameMatch::RegularExpression: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1105 | match_desc = "matched the regular expression"; |
| 1106 | break; |
| 1107 | } |
| 1108 | } |
Greg Clayton | 1cf2aa8 | 2016-03-24 21:49:22 +0000 | [diff] [blame] | 1109 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1110 | if (matches == 0) { |
| 1111 | if (match_desc) |
| 1112 | result.AppendErrorWithFormat( |
| 1113 | "no processes were found that %s \"%s\" on the \"%s\" " |
| 1114 | "platform\n", |
| 1115 | match_desc, match_name, |
| 1116 | platform_sp->GetPluginName().GetCString()); |
| 1117 | else |
| 1118 | result.AppendErrorWithFormat( |
| 1119 | "no processes were found on the \"%s\" platform\n", |
| 1120 | platform_sp->GetPluginName().GetCString()); |
| 1121 | result.SetStatus(eReturnStatusFailed); |
| 1122 | } else { |
| 1123 | result.AppendMessageWithFormat( |
| 1124 | "%u matching process%s found on \"%s\"", matches, |
| 1125 | matches > 1 ? "es were" : " was", |
| 1126 | platform_sp->GetName().GetCString()); |
| 1127 | if (match_desc) |
| 1128 | result.AppendMessageWithFormat(" whose name %s \"%s\"", |
| 1129 | match_desc, match_name); |
| 1130 | result.AppendMessageWithFormat("\n"); |
Pavel Labath | aa51e6a | 2019-03-04 18:48:00 +0000 | [diff] [blame] | 1131 | ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1132 | m_options.verbose); |
| 1133 | for (uint32_t i = 0; i < matches; ++i) { |
| 1134 | proc_infos.GetProcessInfoAtIndex(i).DumpAsTableRow( |
Pavel Labath | aa51e6a | 2019-03-04 18:48:00 +0000 | [diff] [blame] | 1135 | ostrm, platform_sp->GetUserIDResolver(), |
| 1136 | m_options.show_args, m_options.verbose); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | } |
| 1141 | } else { |
| 1142 | result.AppendError("invalid args: process list takes only options\n"); |
| 1143 | result.SetStatus(eReturnStatusFailed); |
| 1144 | } |
| 1145 | } else { |
| 1146 | result.AppendError("no platform is selected\n"); |
| 1147 | result.SetStatus(eReturnStatusFailed); |
| 1148 | } |
| 1149 | return result.Succeeded(); |
| 1150 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1151 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1152 | class CommandOptions : public Options { |
| 1153 | public: |
| 1154 | CommandOptions() |
| 1155 | : Options(), match_info(), show_args(false), verbose(false) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | ~CommandOptions() override = default; |
| 1159 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1160 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, |
| 1161 | ExecutionContext *execution_context) override { |
| 1162 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1163 | const int short_option = m_getopt_table[option_idx].val; |
| 1164 | bool success = false; |
| 1165 | |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1166 | uint32_t id = LLDB_INVALID_PROCESS_ID; |
| 1167 | success = !option_arg.getAsInteger(0, id); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1168 | switch (short_option) { |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1169 | case 'p': { |
| 1170 | match_info.GetProcessInfo().SetProcessID(id); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1171 | if (!success) |
| 1172 | error.SetErrorStringWithFormat("invalid process ID string: '%s'", |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1173 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1174 | break; |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1175 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1176 | case 'P': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1177 | match_info.GetProcessInfo().SetParentProcessID(id); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1178 | if (!success) |
| 1179 | error.SetErrorStringWithFormat( |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1180 | "invalid parent process ID string: '%s'", |
| 1181 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1182 | break; |
| 1183 | |
| 1184 | case 'u': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1185 | match_info.GetProcessInfo().SetUserID(success ? id : UINT32_MAX); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1186 | if (!success) |
| 1187 | error.SetErrorStringWithFormat("invalid user ID string: '%s'", |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1188 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1189 | break; |
| 1190 | |
| 1191 | case 'U': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1192 | match_info.GetProcessInfo().SetEffectiveUserID(success ? id |
| 1193 | : UINT32_MAX); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1194 | if (!success) |
| 1195 | error.SetErrorStringWithFormat( |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1196 | "invalid effective user ID string: '%s'", |
| 1197 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1198 | break; |
| 1199 | |
| 1200 | case 'g': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1201 | match_info.GetProcessInfo().SetGroupID(success ? id : UINT32_MAX); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1202 | if (!success) |
| 1203 | error.SetErrorStringWithFormat("invalid group ID string: '%s'", |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1204 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1205 | break; |
| 1206 | |
| 1207 | case 'G': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1208 | match_info.GetProcessInfo().SetEffectiveGroupID(success ? id |
| 1209 | : UINT32_MAX); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1210 | if (!success) |
| 1211 | error.SetErrorStringWithFormat( |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1212 | "invalid effective group ID string: '%s'", |
| 1213 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1214 | break; |
| 1215 | |
| 1216 | case 'a': { |
| 1217 | TargetSP target_sp = |
| 1218 | execution_context ? execution_context->GetTargetSP() : TargetSP(); |
| 1219 | DebuggerSP debugger_sp = |
| 1220 | target_sp ? target_sp->GetDebugger().shared_from_this() |
| 1221 | : DebuggerSP(); |
| 1222 | PlatformSP platform_sp = |
| 1223 | debugger_sp ? debugger_sp->GetPlatformList().GetSelectedPlatform() |
| 1224 | : PlatformSP(); |
Pavel Labath | 7263f1b | 2017-10-31 10:56:03 +0000 | [diff] [blame] | 1225 | match_info.GetProcessInfo().GetArchitecture() = |
| 1226 | Platform::GetAugmentedArchSpec(platform_sp.get(), option_arg); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1227 | } break; |
| 1228 | |
| 1229 | case 'n': |
Jonas Devlieghere | 937348c | 2018-06-13 22:08:14 +0000 | [diff] [blame] | 1230 | match_info.GetProcessInfo().GetExecutableFile().SetFile( |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1231 | option_arg, FileSpec::Style::native); |
Pavel Labath | c4a3395 | 2017-02-20 11:35:33 +0000 | [diff] [blame] | 1232 | match_info.SetNameMatchType(NameMatch::Equals); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1233 | break; |
| 1234 | |
| 1235 | case 'e': |
Jonas Devlieghere | 937348c | 2018-06-13 22:08:14 +0000 | [diff] [blame] | 1236 | match_info.GetProcessInfo().GetExecutableFile().SetFile( |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1237 | option_arg, FileSpec::Style::native); |
Pavel Labath | c4a3395 | 2017-02-20 11:35:33 +0000 | [diff] [blame] | 1238 | match_info.SetNameMatchType(NameMatch::EndsWith); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1239 | break; |
| 1240 | |
| 1241 | case 's': |
Jonas Devlieghere | 937348c | 2018-06-13 22:08:14 +0000 | [diff] [blame] | 1242 | match_info.GetProcessInfo().GetExecutableFile().SetFile( |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1243 | option_arg, FileSpec::Style::native); |
Pavel Labath | c4a3395 | 2017-02-20 11:35:33 +0000 | [diff] [blame] | 1244 | match_info.SetNameMatchType(NameMatch::StartsWith); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1245 | break; |
| 1246 | |
| 1247 | case 'c': |
Jonas Devlieghere | 937348c | 2018-06-13 22:08:14 +0000 | [diff] [blame] | 1248 | match_info.GetProcessInfo().GetExecutableFile().SetFile( |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1249 | option_arg, FileSpec::Style::native); |
Pavel Labath | c4a3395 | 2017-02-20 11:35:33 +0000 | [diff] [blame] | 1250 | match_info.SetNameMatchType(NameMatch::Contains); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1251 | break; |
| 1252 | |
| 1253 | case 'r': |
Jonas Devlieghere | 937348c | 2018-06-13 22:08:14 +0000 | [diff] [blame] | 1254 | match_info.GetProcessInfo().GetExecutableFile().SetFile( |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1255 | option_arg, FileSpec::Style::native); |
Pavel Labath | c4a3395 | 2017-02-20 11:35:33 +0000 | [diff] [blame] | 1256 | match_info.SetNameMatchType(NameMatch::RegularExpression); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1257 | break; |
| 1258 | |
| 1259 | case 'A': |
| 1260 | show_args = true; |
| 1261 | break; |
| 1262 | |
| 1263 | case 'v': |
| 1264 | verbose = true; |
| 1265 | break; |
| 1266 | |
| 1267 | default: |
Raphael Isemann | 3616201 | 2019-08-22 08:08:05 +0000 | [diff] [blame] | 1268 | llvm_unreachable("Unimplemented option"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | return error; |
| 1272 | } |
| 1273 | |
| 1274 | void OptionParsingStarting(ExecutionContext *execution_context) override { |
| 1275 | match_info.Clear(); |
| 1276 | show_args = false; |
| 1277 | verbose = false; |
| 1278 | } |
| 1279 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1280 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 1281 | return llvm::makeArrayRef(g_platform_process_list_options); |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1282 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1283 | |
| 1284 | // Instance variables to hold the values for command options. |
| 1285 | |
| 1286 | ProcessInstanceInfoMatch match_info; |
| 1287 | bool show_args; |
| 1288 | bool verbose; |
| 1289 | }; |
| 1290 | |
| 1291 | CommandOptions m_options; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1292 | }; |
| 1293 | |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 1294 | // "platform process info" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1295 | class CommandObjectPlatformProcessInfo : public CommandObjectParsed { |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 1296 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1297 | CommandObjectPlatformProcessInfo(CommandInterpreter &interpreter) |
| 1298 | : CommandObjectParsed( |
| 1299 | interpreter, "platform process info", |
| 1300 | "Get detailed information for one or more process by process ID.", |
| 1301 | "platform process info <pid> [<pid> <pid> ...]", 0) { |
| 1302 | CommandArgumentEntry arg; |
| 1303 | CommandArgumentData pid_args; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1304 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1305 | // Define the first (and only) variant of this arg. |
| 1306 | pid_args.arg_type = eArgTypePid; |
| 1307 | pid_args.arg_repetition = eArgRepeatStar; |
| 1308 | |
| 1309 | // There is only one variant this argument could be; put it into the |
| 1310 | // argument entry. |
| 1311 | arg.push_back(pid_args); |
| 1312 | |
| 1313 | // Push the data for the first argument into the m_arguments vector. |
| 1314 | m_arguments.push_back(arg); |
| 1315 | } |
| 1316 | |
| 1317 | ~CommandObjectPlatformProcessInfo() override = default; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1318 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1319 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1320 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 1321 | Target *target = GetDebugger().GetSelectedTarget().get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1322 | PlatformSP platform_sp; |
| 1323 | if (target) { |
| 1324 | platform_sp = target->GetPlatform(); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 1325 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1326 | if (!platform_sp) { |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 1327 | platform_sp = GetDebugger().GetPlatformList().GetSelectedPlatform(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | if (platform_sp) { |
| 1331 | const size_t argc = args.GetArgumentCount(); |
| 1332 | if (argc > 0) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1333 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1334 | |
| 1335 | if (platform_sp->IsConnected()) { |
| 1336 | Stream &ostrm = result.GetOutputStream(); |
Zachary Turner | 97d2c40 | 2016-10-05 23:40:23 +0000 | [diff] [blame] | 1337 | for (auto &entry : args.entries()) { |
| 1338 | lldb::pid_t pid; |
| 1339 | if (entry.ref.getAsInteger(0, pid)) { |
| 1340 | result.AppendErrorWithFormat("invalid process ID argument '%s'", |
| 1341 | entry.ref.str().c_str()); |
| 1342 | result.SetStatus(eReturnStatusFailed); |
| 1343 | break; |
| 1344 | } else { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1345 | ProcessInstanceInfo proc_info; |
| 1346 | if (platform_sp->GetProcessInfo(pid, proc_info)) { |
| 1347 | ostrm.Printf("Process information for process %" PRIu64 ":\n", |
| 1348 | pid); |
Pavel Labath | aa51e6a | 2019-03-04 18:48:00 +0000 | [diff] [blame] | 1349 | proc_info.Dump(ostrm, platform_sp->GetUserIDResolver()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1350 | } else { |
| 1351 | ostrm.Printf("error: no process information is available for " |
| 1352 | "process %" PRIu64 "\n", |
| 1353 | pid); |
| 1354 | } |
| 1355 | ostrm.EOL(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1356 | } |
| 1357 | } |
| 1358 | } else { |
| 1359 | // Not connected... |
| 1360 | result.AppendErrorWithFormat( |
| 1361 | "not connected to '%s'", |
| 1362 | platform_sp->GetPluginName().GetCString()); |
| 1363 | result.SetStatus(eReturnStatusFailed); |
| 1364 | } |
| 1365 | } else { |
| 1366 | // No args |
| 1367 | result.AppendError("one or more process id(s) must be specified"); |
| 1368 | result.SetStatus(eReturnStatusFailed); |
| 1369 | } |
| 1370 | } else { |
| 1371 | result.AppendError("no platform is currently selected"); |
| 1372 | result.SetStatus(eReturnStatusFailed); |
| 1373 | } |
| 1374 | return result.Succeeded(); |
| 1375 | } |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 1376 | }; |
| 1377 | |
Raphael Isemann | 2359fec | 2019-07-24 12:05:42 +0000 | [diff] [blame] | 1378 | #define LLDB_OPTIONS_platform_process_attach |
| 1379 | #include "CommandOptions.inc" |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1380 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1381 | class CommandObjectPlatformProcessAttach : public CommandObjectParsed { |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1382 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1383 | class CommandOptions : public Options { |
| 1384 | public: |
| 1385 | CommandOptions() : Options() { |
| 1386 | // Keep default values of all options in one place: OptionParsingStarting |
| 1387 | // () |
| 1388 | OptionParsingStarting(nullptr); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1389 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1390 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1391 | ~CommandOptions() override = default; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1392 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1393 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, |
| 1394 | ExecutionContext *execution_context) override { |
| 1395 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1396 | char short_option = (char)m_getopt_table[option_idx].val; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1397 | switch (short_option) { |
| 1398 | case 'p': { |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1399 | lldb::pid_t pid = LLDB_INVALID_PROCESS_ID; |
| 1400 | if (option_arg.getAsInteger(0, pid)) { |
| 1401 | error.SetErrorStringWithFormat("invalid process ID '%s'", |
| 1402 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1403 | } else { |
| 1404 | attach_info.SetProcessID(pid); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1405 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1406 | } break; |
| 1407 | |
| 1408 | case 'P': |
| 1409 | attach_info.SetProcessPluginName(option_arg); |
| 1410 | break; |
| 1411 | |
| 1412 | case 'n': |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1413 | attach_info.GetExecutableFile().SetFile(option_arg, |
Jonas Devlieghere | 937348c | 2018-06-13 22:08:14 +0000 | [diff] [blame] | 1414 | FileSpec::Style::native); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1415 | break; |
| 1416 | |
| 1417 | case 'w': |
| 1418 | attach_info.SetWaitForLaunch(true); |
| 1419 | break; |
| 1420 | |
| 1421 | default: |
Raphael Isemann | 3616201 | 2019-08-22 08:08:05 +0000 | [diff] [blame] | 1422 | llvm_unreachable("Unimplemented option"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1423 | } |
| 1424 | return error; |
| 1425 | } |
| 1426 | |
| 1427 | void OptionParsingStarting(ExecutionContext *execution_context) override { |
| 1428 | attach_info.Clear(); |
| 1429 | } |
| 1430 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1431 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 1432 | return llvm::makeArrayRef(g_platform_process_attach_options); |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1433 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1434 | |
| 1435 | bool HandleOptionArgumentCompletion( |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame] | 1436 | CompletionRequest &request, OptionElementVector &opt_element_vector, |
| 1437 | int opt_element_index, CommandInterpreter &interpreter) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1438 | int opt_arg_pos = opt_element_vector[opt_element_index].opt_arg_pos; |
| 1439 | int opt_defs_index = opt_element_vector[opt_element_index].opt_defs_index; |
| 1440 | |
| 1441 | // We are only completing the name option for now... |
| 1442 | |
Raphael Isemann | 1153dc9 | 2019-08-22 09:02:54 +0000 | [diff] [blame^] | 1443 | // Are we in the name? |
| 1444 | if (GetDefinitions()[opt_defs_index].short_option != 'n') |
| 1445 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1446 | |
Raphael Isemann | 1153dc9 | 2019-08-22 09:02:54 +0000 | [diff] [blame^] | 1447 | // Look to see if there is a -P argument provided, and if so use that |
| 1448 | // plugin, otherwise use the default plugin. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1449 | |
Raphael Isemann | 1153dc9 | 2019-08-22 09:02:54 +0000 | [diff] [blame^] | 1450 | const char *partial_name = nullptr; |
| 1451 | partial_name = request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1452 | |
Raphael Isemann | 1153dc9 | 2019-08-22 09:02:54 +0000 | [diff] [blame^] | 1453 | PlatformSP platform_sp(interpreter.GetPlatform(true)); |
| 1454 | if (!platform_sp) |
| 1455 | return false; |
| 1456 | |
| 1457 | ProcessInstanceInfoList process_infos; |
| 1458 | ProcessInstanceInfoMatch match_info; |
| 1459 | if (partial_name) { |
| 1460 | match_info.GetProcessInfo().GetExecutableFile().SetFile( |
| 1461 | partial_name, FileSpec::Style::native); |
| 1462 | match_info.SetNameMatchType(NameMatch::StartsWith); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1463 | } |
Raphael Isemann | 1153dc9 | 2019-08-22 09:02:54 +0000 | [diff] [blame^] | 1464 | platform_sp->FindProcesses(match_info, process_infos); |
| 1465 | const uint32_t num_matches = process_infos.GetSize(); |
| 1466 | if (num_matches == 0) |
| 1467 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1468 | |
Raphael Isemann | 1153dc9 | 2019-08-22 09:02:54 +0000 | [diff] [blame^] | 1469 | for (uint32_t i = 0; i < num_matches; ++i) { |
| 1470 | request.AddCompletion( |
| 1471 | llvm::StringRef(process_infos.GetProcessNameAtIndex(i), |
| 1472 | process_infos.GetProcessNameLengthAtIndex(i))); |
| 1473 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1474 | return false; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1475 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1476 | |
| 1477 | // Options table: Required for subclasses of Options. |
| 1478 | |
| 1479 | static OptionDefinition g_option_table[]; |
| 1480 | |
| 1481 | // Instance variables to hold the values for command options. |
| 1482 | |
| 1483 | ProcessAttachInfo attach_info; |
| 1484 | }; |
| 1485 | |
| 1486 | CommandObjectPlatformProcessAttach(CommandInterpreter &interpreter) |
| 1487 | : CommandObjectParsed(interpreter, "platform process attach", |
| 1488 | "Attach to a process.", |
| 1489 | "platform process attach <cmd-options>"), |
| 1490 | m_options() {} |
| 1491 | |
| 1492 | ~CommandObjectPlatformProcessAttach() override = default; |
| 1493 | |
| 1494 | bool DoExecute(Args &command, CommandReturnObject &result) override { |
| 1495 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 1496 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1497 | if (platform_sp) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1498 | Status err; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1499 | ProcessSP remote_process_sp = platform_sp->Attach( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 1500 | m_options.attach_info, GetDebugger(), nullptr, err); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1501 | if (err.Fail()) { |
| 1502 | result.AppendError(err.AsCString()); |
| 1503 | result.SetStatus(eReturnStatusFailed); |
| 1504 | } else if (!remote_process_sp) { |
| 1505 | result.AppendError("could not attach: unknown reason"); |
| 1506 | result.SetStatus(eReturnStatusFailed); |
| 1507 | } else |
| 1508 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 1509 | } else { |
| 1510 | result.AppendError("no platform is currently selected"); |
| 1511 | result.SetStatus(eReturnStatusFailed); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1512 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1513 | return result.Succeeded(); |
| 1514 | } |
| 1515 | |
| 1516 | Options *GetOptions() override { return &m_options; } |
| 1517 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1518 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1519 | CommandOptions m_options; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1520 | }; |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 1521 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1522 | class CommandObjectPlatformProcess : public CommandObjectMultiword { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1523 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1524 | // Constructors and Destructors |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1525 | CommandObjectPlatformProcess(CommandInterpreter &interpreter) |
| 1526 | : CommandObjectMultiword(interpreter, "platform process", |
| 1527 | "Commands to query, launch and attach to " |
| 1528 | "processes on the current platform.", |
| 1529 | "platform process [attach|launch|list] ...") { |
| 1530 | LoadSubCommand( |
| 1531 | "attach", |
| 1532 | CommandObjectSP(new CommandObjectPlatformProcessAttach(interpreter))); |
| 1533 | LoadSubCommand( |
| 1534 | "launch", |
| 1535 | CommandObjectSP(new CommandObjectPlatformProcessLaunch(interpreter))); |
| 1536 | LoadSubCommand("info", CommandObjectSP(new CommandObjectPlatformProcessInfo( |
| 1537 | interpreter))); |
| 1538 | LoadSubCommand("list", CommandObjectSP(new CommandObjectPlatformProcessList( |
| 1539 | interpreter))); |
| 1540 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1541 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1542 | ~CommandObjectPlatformProcess() override = default; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1543 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1544 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1545 | // For CommandObjectPlatform only |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1546 | DISALLOW_COPY_AND_ASSIGN(CommandObjectPlatformProcess); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1547 | }; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1548 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1549 | // "platform shell" |
Raphael Isemann | 2359fec | 2019-07-24 12:05:42 +0000 | [diff] [blame] | 1550 | #define LLDB_OPTIONS_platform_shell |
| 1551 | #include "CommandOptions.inc" |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1552 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1553 | class CommandObjectPlatformShell : public CommandObjectRaw { |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 1554 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1555 | class CommandOptions : public Options { |
| 1556 | public: |
Pavel Labath | 19dd1a0 | 2018-05-10 10:46:03 +0000 | [diff] [blame] | 1557 | CommandOptions() : Options() {} |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1558 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1559 | ~CommandOptions() override = default; |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1560 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1561 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 1562 | return llvm::makeArrayRef(g_platform_shell_options); |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1563 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1564 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1565 | Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, |
| 1566 | ExecutionContext *execution_context) override { |
| 1567 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1568 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1569 | const char short_option = (char)GetDefinitions()[option_idx].short_option; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1570 | |
| 1571 | switch (short_option) { |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1572 | case 't': |
Pavel Labath | 19dd1a0 | 2018-05-10 10:46:03 +0000 | [diff] [blame] | 1573 | uint32_t timeout_sec; |
| 1574 | if (option_arg.getAsInteger(10, timeout_sec)) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1575 | error.SetErrorStringWithFormat( |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame] | 1576 | "could not convert \"%s\" to a numeric value.", |
| 1577 | option_arg.str().c_str()); |
Pavel Labath | 19dd1a0 | 2018-05-10 10:46:03 +0000 | [diff] [blame] | 1578 | else |
| 1579 | timeout = std::chrono::seconds(timeout_sec); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1580 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1581 | default: |
Raphael Isemann | 3616201 | 2019-08-22 08:08:05 +0000 | [diff] [blame] | 1582 | llvm_unreachable("Unimplemented option"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | return error; |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 1586 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1587 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1588 | void OptionParsingStarting(ExecutionContext *execution_context) override {} |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1589 | |
Pavel Labath | 19dd1a0 | 2018-05-10 10:46:03 +0000 | [diff] [blame] | 1590 | Timeout<std::micro> timeout = std::chrono::seconds(10); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1591 | }; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1592 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1593 | CommandObjectPlatformShell(CommandInterpreter &interpreter) |
| 1594 | : CommandObjectRaw(interpreter, "platform shell", |
| 1595 | "Run a shell command on the current platform.", |
| 1596 | "platform shell <shell-command>", 0), |
| 1597 | m_options() {} |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 1598 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1599 | ~CommandObjectPlatformShell() override = default; |
| 1600 | |
| 1601 | Options *GetOptions() override { return &m_options; } |
| 1602 | |
Raphael Isemann | 4d51a90 | 2018-07-12 22:28:52 +0000 | [diff] [blame] | 1603 | bool DoExecute(llvm::StringRef raw_command_line, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1604 | CommandReturnObject &result) override { |
| 1605 | ExecutionContext exe_ctx = GetCommandInterpreter().GetExecutionContext(); |
| 1606 | m_options.NotifyOptionParsingStarting(&exe_ctx); |
| 1607 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1608 | |
| 1609 | // Print out an usage syntax on an empty command line. |
Raphael Isemann | 4d51a90 | 2018-07-12 22:28:52 +0000 | [diff] [blame] | 1610 | if (raw_command_line.empty()) { |
Zachary Turner | 1e8016b | 2016-11-15 00:45:18 +0000 | [diff] [blame] | 1611 | result.GetOutputStream().Printf("%s\n", this->GetSyntax().str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1612 | return true; |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 1613 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1614 | |
Raphael Isemann | 3a0e127 | 2018-07-10 20:17:38 +0000 | [diff] [blame] | 1615 | OptionsWithRaw args(raw_command_line); |
| 1616 | const char *expr = args.GetRawPart().c_str(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1617 | |
Raphael Isemann | 3a0e127 | 2018-07-10 20:17:38 +0000 | [diff] [blame] | 1618 | if (args.HasArgs()) |
| 1619 | if (!ParseOptions(args.GetArgs(), result)) |
| 1620 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1621 | |
| 1622 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 1623 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1624 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1625 | if (platform_sp) { |
| 1626 | FileSpec working_dir{}; |
| 1627 | std::string output; |
| 1628 | int status = -1; |
| 1629 | int signo = -1; |
| 1630 | error = (platform_sp->RunShellCommand(expr, working_dir, &status, &signo, |
| 1631 | &output, m_options.timeout)); |
| 1632 | if (!output.empty()) |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 1633 | result.GetOutputStream().PutCString(output); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1634 | if (status > 0) { |
| 1635 | if (signo > 0) { |
| 1636 | const char *signo_cstr = Host::GetSignalAsCString(signo); |
| 1637 | if (signo_cstr) |
| 1638 | result.GetOutputStream().Printf( |
| 1639 | "error: command returned with status %i and signal %s\n", |
| 1640 | status, signo_cstr); |
| 1641 | else |
| 1642 | result.GetOutputStream().Printf( |
| 1643 | "error: command returned with status %i and signal %i\n", |
| 1644 | status, signo); |
| 1645 | } else |
| 1646 | result.GetOutputStream().Printf( |
| 1647 | "error: command returned with status %i\n", status); |
| 1648 | } |
| 1649 | } else { |
| 1650 | result.GetOutputStream().Printf( |
| 1651 | "error: cannot run remote shell commands without a platform\n"); |
| 1652 | error.SetErrorString( |
| 1653 | "error: cannot run remote shell commands without a platform"); |
| 1654 | } |
| 1655 | |
| 1656 | if (error.Fail()) { |
| 1657 | result.AppendError(error.AsCString()); |
| 1658 | result.SetStatus(eReturnStatusFailed); |
| 1659 | } else { |
| 1660 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 1661 | } |
| 1662 | return true; |
| 1663 | } |
| 1664 | |
| 1665 | CommandOptions m_options; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1666 | }; |
| 1667 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1668 | // "platform install" - install a target to a remote end |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1669 | class CommandObjectPlatformInstall : public CommandObjectParsed { |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1670 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1671 | CommandObjectPlatformInstall(CommandInterpreter &interpreter) |
| 1672 | : CommandObjectParsed( |
| 1673 | interpreter, "platform target-install", |
| 1674 | "Install a target (bundle or executable file) to the remote end.", |
| 1675 | "platform target-install <local-thing> <remote-sandbox>", 0) {} |
| 1676 | |
| 1677 | ~CommandObjectPlatformInstall() override = default; |
| 1678 | |
| 1679 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 1680 | if (args.GetArgumentCount() != 2) { |
| 1681 | result.AppendError("platform target-install takes two arguments"); |
| 1682 | result.SetStatus(eReturnStatusFailed); |
| 1683 | return false; |
| 1684 | } |
| 1685 | // TODO: move the bulk of this code over to the platform itself |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1686 | FileSpec src(args.GetArgumentAtIndex(0)); |
| 1687 | FileSystem::Instance().Resolve(src); |
| 1688 | FileSpec dst(args.GetArgumentAtIndex(1)); |
Jonas Devlieghere | dbd7fab | 2018-11-01 17:09:25 +0000 | [diff] [blame] | 1689 | if (!FileSystem::Instance().Exists(src)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1690 | result.AppendError("source location does not exist or is not accessible"); |
| 1691 | result.SetStatus(eReturnStatusFailed); |
| 1692 | return false; |
| 1693 | } |
| 1694 | PlatformSP platform_sp( |
Jonas Devlieghere | 5717986 | 2019-04-27 06:19:42 +0000 | [diff] [blame] | 1695 | GetDebugger().GetPlatformList().GetSelectedPlatform()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1696 | if (!platform_sp) { |
| 1697 | result.AppendError("no platform currently selected"); |
| 1698 | result.SetStatus(eReturnStatusFailed); |
| 1699 | return false; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1700 | } |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1701 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1702 | Status error = platform_sp->Install(src, dst); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1703 | if (error.Success()) { |
| 1704 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 1705 | } else { |
| 1706 | result.AppendErrorWithFormat("install failed: %s", error.AsCString()); |
| 1707 | result.SetStatus(eReturnStatusFailed); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1708 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1709 | return result.Succeeded(); |
| 1710 | } |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 1711 | }; |
| 1712 | |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 1713 | CommandObjectPlatform::CommandObjectPlatform(CommandInterpreter &interpreter) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1714 | : CommandObjectMultiword( |
| 1715 | interpreter, "platform", "Commands to manage and create platforms.", |
| 1716 | "platform [connect|disconnect|info|list|status|select] ...") { |
| 1717 | LoadSubCommand("select", |
| 1718 | CommandObjectSP(new CommandObjectPlatformSelect(interpreter))); |
| 1719 | LoadSubCommand("list", |
| 1720 | CommandObjectSP(new CommandObjectPlatformList(interpreter))); |
| 1721 | LoadSubCommand("status", |
| 1722 | CommandObjectSP(new CommandObjectPlatformStatus(interpreter))); |
| 1723 | LoadSubCommand("connect", CommandObjectSP( |
| 1724 | new CommandObjectPlatformConnect(interpreter))); |
| 1725 | LoadSubCommand( |
| 1726 | "disconnect", |
| 1727 | CommandObjectSP(new CommandObjectPlatformDisconnect(interpreter))); |
| 1728 | LoadSubCommand("settings", CommandObjectSP(new CommandObjectPlatformSettings( |
| 1729 | interpreter))); |
| 1730 | LoadSubCommand("mkdir", |
| 1731 | CommandObjectSP(new CommandObjectPlatformMkDir(interpreter))); |
| 1732 | LoadSubCommand("file", |
| 1733 | CommandObjectSP(new CommandObjectPlatformFile(interpreter))); |
| 1734 | LoadSubCommand("get-file", CommandObjectSP(new CommandObjectPlatformGetFile( |
| 1735 | interpreter))); |
| 1736 | LoadSubCommand("get-size", CommandObjectSP(new CommandObjectPlatformGetSize( |
| 1737 | interpreter))); |
| 1738 | LoadSubCommand("put-file", CommandObjectSP(new CommandObjectPlatformPutFile( |
| 1739 | interpreter))); |
| 1740 | LoadSubCommand("process", CommandObjectSP( |
| 1741 | new CommandObjectPlatformProcess(interpreter))); |
| 1742 | LoadSubCommand("shell", |
| 1743 | CommandObjectSP(new CommandObjectPlatformShell(interpreter))); |
| 1744 | LoadSubCommand( |
| 1745 | "target-install", |
| 1746 | CommandObjectSP(new CommandObjectPlatformInstall(interpreter))); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
Eugene Zelenko | 435c2c9 | 2016-02-22 19:02:01 +0000 | [diff] [blame] | 1749 | CommandObjectPlatform::~CommandObjectPlatform() = default; |