Skip to content

Revert "[lldb] Remote disk file/directory completion for platform com… #2221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions lldb/docs/lldb-platform-packets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,27 +237,6 @@ incompatible with the flags that gdb specifies.
// Continues to return the results of the qfProcessInfo. Once all matches
// have been sent, Exx is returned to indicate end of matches.

//----------------------------------------------------------------------
// qPathComplete
//
// BRIEF
// Get a list of matched disk files/directories by passing a boolean flag
// and a partial path.
//
// EXAMPLE
//
// receive: qPathComplete:0,6d61696e
// send: M6d61696e2e637070
// receive: qPathComplete:1,746573
// send: M746573742f,74657374732f
//
// If the first argument is zero, the result should contain all
// files (including directories) starting with the given path. If the
// argument is one, the result should contain only directories.
//
// The result should be a comma-separated list of hex-encoded paths.
// Paths denoting a directory should end with a directory separator ('/' or '\').

//----------------------------------------------------------------------
// vFile:size:
//
Expand Down
12 changes: 1 addition & 11 deletions lldb/include/lldb/Interpreter/CommandCompletions.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ class CommandCompletions {
eBreakpointNameCompletion = (1u << 19),
eProcessIDCompletion = (1u << 20),
eProcessNameCompletion = (1u << 21),
eRemoteDiskFileCompletion = (1u << 22),
eRemoteDiskDirectoryCompletion = (1u << 23),
eTypeCategoryNameCompletion = (1u << 24),
// This item serves two purposes. It is the last element in the enum, so
// you can add custom enums starting from here in your Option class. Also
// if you & in this bit the base code will not process the option.
eCustomCompletion = (1u << 24)
eCustomCompletion = (1u << 22)
};

static bool InvokeCommonCompletionCallbacks(
Expand All @@ -75,14 +73,6 @@ class CommandCompletions {
StringList &matches,
TildeExpressionResolver &Resolver);

static void RemoteDiskFiles(CommandInterpreter &interpreter,
CompletionRequest &request,
SearchFilter *searcher);

static void RemoteDiskDirectories(CommandInterpreter &interpreter,
CompletionRequest &request,
SearchFilter *searcher);

static void SourceFiles(CommandInterpreter &interpreter,
CompletionRequest &request, SearchFilter *searcher);

Expand Down
3 changes: 0 additions & 3 deletions lldb/include/lldb/Target/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,6 @@ class Platform : public PluginInterface {
return UINT64_MAX;
}

virtual void AutoCompleteDiskFileOrDirectory(CompletionRequest &request,
bool only_dir) {}

virtual uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst,
uint64_t dst_len, Status &error) {
error.SetErrorStringWithFormat(
Expand Down
1 change: 0 additions & 1 deletion lldb/include/lldb/Utility/StringExtractorGDBRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class StringExtractorGDBRemote : public StringExtractor {
eServerPacketType_QSetSTDERR,
eServerPacketType_QSetWorkingDir,
eServerPacketType_QStartNoAckMode,
eServerPacketType_qPathComplete,
eServerPacketType_qPlatform_shell,
eServerPacketType_qPlatform_mkdir,
eServerPacketType_qPlatform_chmod,
Expand Down
21 changes: 0 additions & 21 deletions lldb/source/Commands/CommandCompletions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ bool CommandCompletions::InvokeCommonCompletionCallbacks(
{eBreakpointNameCompletion, CommandCompletions::BreakpointNames},
{eProcessIDCompletion, CommandCompletions::ProcessIDs},
{eProcessNameCompletion, CommandCompletions::ProcessNames},
{eRemoteDiskFileCompletion, CommandCompletions::RemoteDiskFiles},
{eRemoteDiskDirectoryCompletion,
CommandCompletions::RemoteDiskDirectories},
{eTypeCategoryNameCompletion, CommandCompletions::TypeCategoryNames},
{eNoCompletion, nullptr} // This one has to be last in the list.
};
Expand Down Expand Up @@ -491,24 +488,6 @@ void CommandCompletions::DiskDirectories(const llvm::Twine &partial_file_name,
DiskFilesOrDirectories(partial_file_name, true, matches, Resolver);
}

void CommandCompletions::RemoteDiskFiles(CommandInterpreter &interpreter,
CompletionRequest &request,
SearchFilter *searcher) {
lldb::PlatformSP platform_sp =
interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform();
if (platform_sp)
platform_sp->AutoCompleteDiskFileOrDirectory(request, false);
}

void CommandCompletions::RemoteDiskDirectories(CommandInterpreter &interpreter,
CompletionRequest &request,
SearchFilter *searcher) {
lldb::PlatformSP platform_sp =
interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform();
if (platform_sp)
platform_sp->AutoCompleteDiskFileOrDirectory(request, true);
}

void CommandCompletions::Modules(CommandInterpreter &interpreter,
CompletionRequest &request,
SearchFilter *searcher) {
Expand Down
49 changes: 1 addition & 48 deletions lldb/source/Commands/CommandObjectPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,7 @@ class CommandObjectPlatformSettings : public CommandObjectParsed {
"or for a platform by name.",
"platform settings", 0),
m_options(),
m_option_working_dir(LLDB_OPT_SET_1, false, "working-dir", 'w',
CommandCompletions::eRemoteDiskDirectoryCompletion,
m_option_working_dir(LLDB_OPT_SET_1, false, "working-dir", 'w', 0,
eArgTypePath,
"The working directory for the platform.") {
m_options.Append(&m_option_working_dir, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Expand Down Expand Up @@ -486,15 +485,6 @@ class CommandObjectPlatformFOpen : public CommandObjectParsed {

~CommandObjectPlatformFOpen() override = default;

void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
if (request.GetCursorIndex() == 0)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(),
CommandCompletions::eRemoteDiskFileCompletion, request, nullptr);
}

bool DoExecute(Args &args, CommandReturnObject &result) override {
PlatformSP platform_sp(
GetDebugger().GetPlatformList().GetSelectedPlatform());
Expand Down Expand Up @@ -827,19 +817,6 @@ class CommandObjectPlatformGetFile : public CommandObjectParsed {

~CommandObjectPlatformGetFile() override = default;

void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
if (request.GetCursorIndex() == 0)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(),
CommandCompletions::eRemoteDiskFileCompletion, request, nullptr);
else if (request.GetCursorIndex() == 1)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
}

bool DoExecute(Args &args, CommandReturnObject &result) override {
// If the number of arguments is incorrect, issue an error message.
if (args.GetArgumentCount() != 2) {
Expand Down Expand Up @@ -905,17 +882,6 @@ class CommandObjectPlatformGetSize : public CommandObjectParsed {

~CommandObjectPlatformGetSize() 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) {
Expand Down Expand Up @@ -961,19 +927,6 @@ class CommandObjectPlatformPutFile : public CommandObjectParsed {

~CommandObjectPlatformPutFile() override = default;

void
HandleArgumentCompletion(CompletionRequest &request,
OptionElementVector &opt_element_vector) override {
if (request.GetCursorIndex() == 0)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
request, nullptr);
else if (request.GetCursorIndex() == 1)
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(),
CommandCompletions::eRemoteDiskFileCompletion, request, nullptr);
}

bool DoExecute(Args &args, CommandReturnObject &result) override {
const char *src = args.GetArgumentAtIndex(0);
const char *dst = args.GetArgumentAtIndex(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,6 @@ PlatformRemoteGDBServer::GetFileSize(const FileSpec &file_spec) {
return m_gdb_client.GetFileSize(file_spec);
}

void PlatformRemoteGDBServer::AutoCompleteDiskFileOrDirectory(
CompletionRequest &request, bool only_dir) {
m_gdb_client.AutoCompleteDiskFileOrDirectory(request, only_dir);
}

uint64_t PlatformRemoteGDBServer::ReadFile(lldb::user_id_t fd, uint64_t offset,
void *dst, uint64_t dst_len,
Status &error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ class PlatformRemoteGDBServer : public Platform, private UserIDResolver {

lldb::user_id_t GetFileSize(const FileSpec &file_spec) override;

void AutoCompleteDiskFileOrDirectory(CompletionRequest &request,
bool only_dir) override;

Status PutFile(const FileSpec &source, const FileSpec &destination,
uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2981,31 +2981,6 @@ lldb::user_id_t GDBRemoteCommunicationClient::GetFileSize(
return UINT64_MAX;
}

void GDBRemoteCommunicationClient::AutoCompleteDiskFileOrDirectory(
CompletionRequest &request, bool only_dir) {
lldb_private::StreamString stream;
stream.PutCString("qPathComplete:");
stream.PutHex32(only_dir ? 1 : 0);
stream.PutChar(',');
stream.PutStringAsRawHex8(request.GetCursorArgumentPrefix());
StringExtractorGDBRemote response;
if (SendPacketAndWaitForResponse(stream.GetString(), response, false) ==
PacketResult::Success) {
StreamString strm;
char ch = response.GetChar();
if (ch != 'M')
return;
while (response.Peek()) {
strm.Clear();
while ((ch = response.GetHexU8(0, false)) != '\0')
strm.PutChar(ch);
request.AddCompletion(strm.GetString());
if (response.GetChar() != ',')
break;
}
}
}

Status
GDBRemoteCommunicationClient::GetFilePermissions(const FileSpec &file_spec,
uint32_t &file_permissions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,6 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase {

lldb::user_id_t GetFileSize(const FileSpec &file_spec);

void AutoCompleteDiskFileOrDirectory(CompletionRequest &request,
bool only_dir);

Status GetFilePermissions(const FileSpec &file_spec,
uint32_t &file_permissions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@
#include "lldb/Host/FileAction.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Interpreter/CommandCompletions.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/UnixSignals.h"
#include "lldb/Utility/GDBRemote.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/StructuredData.h"
#include "lldb/Utility/TildeExpressionResolver.h"
#include "lldb/Utility/UriParser.h"

#include "lldb/Utility/StringExtractorGDBRemote.h"
Expand Down Expand Up @@ -70,9 +68,6 @@ GDBRemoteCommunicationServerPlatform::GDBRemoteCommunicationServerPlatform(
RegisterMemberFunctionHandler(
StringExtractorGDBRemote::eServerPacketType_qProcessInfo,
&GDBRemoteCommunicationServerPlatform::Handle_qProcessInfo);
RegisterMemberFunctionHandler(
StringExtractorGDBRemote::eServerPacketType_qPathComplete,
&GDBRemoteCommunicationServerPlatform::Handle_qPathComplete);
RegisterMemberFunctionHandler(
StringExtractorGDBRemote::eServerPacketType_QSetWorkingDir,
&GDBRemoteCommunicationServerPlatform::Handle_QSetWorkingDir);
Expand Down Expand Up @@ -338,38 +333,6 @@ GDBRemoteCommunicationServerPlatform::Handle_qProcessInfo(
return SendPacketNoLock(response.GetString());
}

GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerPlatform::Handle_qPathComplete(
StringExtractorGDBRemote &packet) {
packet.SetFilePos(::strlen("qPathComplete:"));
const bool only_dir = (packet.GetHexMaxU32(false, 0) == 1);
if (packet.GetChar() != ',')
return SendErrorResponse(85);
std::string path;
packet.GetHexByteString(path);

StringList matches;
StandardTildeExpressionResolver resolver;
if (only_dir)
CommandCompletions::DiskDirectories(path, matches, resolver);
else
CommandCompletions::DiskFiles(path, matches, resolver);

StreamString response;
response.PutChar('M');
llvm::StringRef separator;
std::sort(matches.begin(), matches.end());
for (const auto &match : matches) {
response << separator;
separator = ",";
// encode result strings into hex bytes to avoid unexpected error caused by
// special characters like '$'.
response.PutStringAsRawHex8(match.c_str());
}

return SendPacketNoLock(response.GetString());
}

GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerPlatform::Handle_qGetWorkingDir(
StringExtractorGDBRemote &packet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ class GDBRemoteCommunicationServerPlatform

PacketResult Handle_qKillSpawnedProcess(StringExtractorGDBRemote &packet);

PacketResult Handle_qPathComplete(StringExtractorGDBRemote &packet);

PacketResult Handle_qProcessInfo(StringExtractorGDBRemote &packet);

PacketResult Handle_qGetWorkingDir(StringExtractorGDBRemote &packet);
Expand Down
2 changes: 0 additions & 2 deletions lldb/source/Utility/StringExtractorGDBRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ StringExtractorGDBRemote::GetServerPacketType() const {
return eServerPacketType_qPlatform_chmod;
if (PACKET_MATCHES("qProcessInfo"))
return eServerPacketType_qProcessInfo;
if (PACKET_STARTS_WITH("qPathComplete:"))
return eServerPacketType_qPathComplete;
break;

case 'Q':
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ def respond(self, packet):
return self.qsProcessInfo()
if packet.startswith("qfProcessInfo"):
return self.qfProcessInfo(packet)
if packet.startswith("qPathComplete:"):
return self.qPathComplete()

return self.other(packet)

Expand Down Expand Up @@ -284,9 +282,6 @@ def QListThreadsInStopReply(self):
def qMemoryRegionInfo(self):
return ""

def qPathComplete(self):
return ""

"""
Raised when we receive a packet for which there is no default action.
Override the responder class to implement behavior suitable for the test at
Expand Down
Loading