diff options
Diffstat (limited to 'lldb/source/Commands/CommandObjectPlatform.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectPlatform.cpp | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index 0274605..7760eba 100644 --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -926,6 +926,141 @@ public: } }; +// "platform get-permissions remote-file-path" +class CommandObjectPlatformGetPermissions : public CommandObjectParsed { +public: + CommandObjectPlatformGetPermissions(CommandInterpreter &interpreter) + : CommandObjectParsed(interpreter, "platform get-permissions", + "Get the file permission bits from the remote end.", + "platform get-permissions <remote-file-spec>", 0) { + SetHelpLong( + R"(Examples: + +(lldb) platform get-permissions /the/remote/file/path + + Get the file permissions from the remote end with path /the/remote/file/path.)"); + + CommandArgumentEntry arg1; + CommandArgumentData file_arg_remote; + + // Define the first (and only) variant of this arg. + file_arg_remote.arg_type = eArgTypeFilename; + file_arg_remote.arg_repetition = eArgRepeatPlain; + // There is only one variant this argument could be; put it into the + // argument entry. + arg1.push_back(file_arg_remote); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back(arg1); + } + + ~CommandObjectPlatformGetPermissions() override = default; + + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + if (request.GetCursorIndex() != 0) + return; + + CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), CommandCompletions::eRemoteDiskFileCompletion, + request, nullptr); + } + + bool DoExecute(Args &args, CommandReturnObject &result) override { + // If the number of arguments is incorrect, issue an error message. + if (args.GetArgumentCount() != 1) { + result.AppendError("required argument missing; specify the source file " + "path as the only argument"); + return false; + } + + PlatformSP platform_sp( + GetDebugger().GetPlatformList().GetSelectedPlatform()); + if (platform_sp) { + std::string remote_file_path(args.GetArgumentAtIndex(0)); + uint32_t permissions; + Status error = platform_sp->GetFilePermissions(FileSpec(remote_file_path), + permissions); + if (error.Success()) { + result.AppendMessageWithFormat( + "File permissions of %s (remote): 0o%04" PRIo32 "\n", + remote_file_path.c_str(), permissions); + result.SetStatus(eReturnStatusSuccessFinishResult); + } else + result.AppendError(error.AsCString()); + } else { + result.AppendError("no platform currently selected\n"); + } + return result.Succeeded(); + } +}; + +// "platform file-exists remote-file-path" +class CommandObjectPlatformFileExists : public CommandObjectParsed { +public: + CommandObjectPlatformFileExists(CommandInterpreter &interpreter) + : CommandObjectParsed(interpreter, "platform file-exists", + "Check if the file exists on the remote end.", + "platform file-exists <remote-file-spec>", 0) { + SetHelpLong( + R"(Examples: + +(lldb) platform file-exists /the/remote/file/path + + Check if /the/remote/file/path exists on the remote end.)"); + + CommandArgumentEntry arg1; + CommandArgumentData file_arg_remote; + + // Define the first (and only) variant of this arg. + file_arg_remote.arg_type = eArgTypeFilename; + file_arg_remote.arg_repetition = eArgRepeatPlain; + // There is only one variant this argument could be; put it into the + // argument entry. + arg1.push_back(file_arg_remote); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back(arg1); + } + + ~CommandObjectPlatformFileExists() override = default; + + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + if (request.GetCursorIndex() != 0) + return; + + CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), CommandCompletions::eRemoteDiskFileCompletion, + request, nullptr); + } + + bool DoExecute(Args &args, CommandReturnObject &result) override { + // If the number of arguments is incorrect, issue an error message. + if (args.GetArgumentCount() != 1) { + result.AppendError("required argument missing; specify the source file " + "path as the only argument"); + return false; + } + + PlatformSP platform_sp( + GetDebugger().GetPlatformList().GetSelectedPlatform()); + if (platform_sp) { + std::string remote_file_path(args.GetArgumentAtIndex(0)); + bool exists = platform_sp->GetFileExists(FileSpec(remote_file_path)); + result.AppendMessageWithFormat( + "File %s (remote) %s\n", + remote_file_path.c_str(), exists ? "exists" : "does not exist"); + result.SetStatus(eReturnStatusSuccessFinishResult); + } else { + result.AppendError("no platform currently selected\n"); + } + return result.Succeeded(); + } +}; + // "platform put-file" class CommandObjectPlatformPutFile : public CommandObjectParsed { public: @@ -1759,8 +1894,12 @@ CommandObjectPlatform::CommandObjectPlatform(CommandInterpreter &interpreter) CommandObjectSP(new CommandObjectPlatformMkDir(interpreter))); LoadSubCommand("file", CommandObjectSP(new CommandObjectPlatformFile(interpreter))); + LoadSubCommand("file-exists", + CommandObjectSP(new CommandObjectPlatformFileExists(interpreter))); LoadSubCommand("get-file", CommandObjectSP(new CommandObjectPlatformGetFile( interpreter))); + LoadSubCommand("get-permissions", + CommandObjectSP(new CommandObjectPlatformGetPermissions(interpreter))); LoadSubCommand("get-size", CommandObjectSP(new CommandObjectPlatformGetSize( interpreter))); LoadSubCommand("put-file", CommandObjectSP(new CommandObjectPlatformPutFile( |