diff options
author | Chaoren Lin <chaorenl@google.com> | 2015-05-29 19:52:29 +0000 |
---|---|---|
committer | Chaoren Lin <chaorenl@google.com> | 2015-05-29 19:52:29 +0000 |
commit | d3173f34e8546a96b8d0df0d9de133f88f10c127 (patch) | |
tree | 5e778446085cbd4a4d43fc3b488b3ac6ff17f2b5 /lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp | |
parent | 375432e4d8f50212bca3d9228e349b5a00f770d7 (diff) | |
download | bcm5719-llvm-d3173f34e8546a96b8d0df0d9de133f88f10c127.tar.gz bcm5719-llvm-d3173f34e8546a96b8d0df0d9de133f88f10c127.zip |
Refactor many file functions to use FileSpec over strings.
Summary:
This should solve the issue of sending denormalized paths over gdb-remote
if we stick to GetPath(false) in GDBRemoteCommunicationClient, and let the
server handle any denormalization.
Reviewers: ovyalov, zturner, vharron, clayborg
Reviewed By: clayborg
Subscribers: tberghammer, emaste, lldb-commits
Differential Revision: http://reviews.llvm.org/D9728
llvm-svn: 238604
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp')
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp | 102 |
1 files changed, 58 insertions, 44 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 3e9278853a7..0a1ec3f962c 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -1325,7 +1325,7 @@ GDBRemoteCommunicationClient::SendArgumentsPacket (const ProcessLaunchInfo &laun const char *arg = NULL; const Args &launch_args = launch_info.GetArguments(); if (exe_file) - exe_path = exe_file.GetPath(); + exe_path = exe_file.GetPath(false); else { arg = launch_args.GetArgumentAtIndex(0); @@ -2221,13 +2221,14 @@ GDBRemoteCommunicationClient::GetWatchpointsTriggerAfterInstruction (bool &after } int -GDBRemoteCommunicationClient::SetSTDIN (char const *path) +GDBRemoteCommunicationClient::SetSTDIN(const FileSpec &file_spec) { - if (path && path[0]) + if (file_spec) { + std::string path{file_spec.GetPath(false)}; StreamString packet; packet.PutCString("QSetSTDIN:"); - packet.PutBytesAsRawHex8(path, strlen(path)); + packet.PutCStringAsRawHex8(path.c_str()); StringExtractorGDBRemote response; if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) @@ -2243,14 +2244,15 @@ GDBRemoteCommunicationClient::SetSTDIN (char const *path) } int -GDBRemoteCommunicationClient::SetSTDOUT (char const *path) +GDBRemoteCommunicationClient::SetSTDOUT(const FileSpec &file_spec) { - if (path && path[0]) + if (file_spec) { + std::string path{file_spec.GetPath(false)}; StreamString packet; packet.PutCString("QSetSTDOUT:"); - packet.PutBytesAsRawHex8(path, strlen(path)); - + packet.PutCStringAsRawHex8(path.c_str()); + StringExtractorGDBRemote response; if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) { @@ -2265,14 +2267,15 @@ GDBRemoteCommunicationClient::SetSTDOUT (char const *path) } int -GDBRemoteCommunicationClient::SetSTDERR (char const *path) +GDBRemoteCommunicationClient::SetSTDERR(const FileSpec &file_spec) { - if (path && path[0]) + if (file_spec) { + std::string path{file_spec.GetPath(false)}; StreamString packet; packet.PutCString("QSetSTDERR:"); - packet.PutBytesAsRawHex8(path, strlen(path)); - + packet.PutCStringAsRawHex8(path.c_str()); + StringExtractorGDBRemote response; if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) { @@ -2287,7 +2290,7 @@ GDBRemoteCommunicationClient::SetSTDERR (char const *path) } bool -GDBRemoteCommunicationClient::GetWorkingDir (std::string &cwd) +GDBRemoteCommunicationClient::GetWorkingDir(FileSpec &working_dir) { StringExtractorGDBRemote response; if (SendPacketAndWaitForResponse ("qGetWorkingDir", response, false) == PacketResult::Success) @@ -2296,21 +2299,24 @@ GDBRemoteCommunicationClient::GetWorkingDir (std::string &cwd) return false; if (response.IsErrorResponse()) return false; - response.GetHexByteString (cwd); + std::string cwd; + response.GetHexByteString(cwd); + working_dir.SetFile(cwd, false); return !cwd.empty(); } return false; } int -GDBRemoteCommunicationClient::SetWorkingDir (char const *path) +GDBRemoteCommunicationClient::SetWorkingDir(const FileSpec &working_dir) { - if (path && path[0]) + if (working_dir) { + std::string path{working_dir.GetPath(false)}; StreamString packet; packet.PutCString("QSetWorkingDir:"); - packet.PutBytesAsRawHex8(path, strlen(path)); - + packet.PutCStringAsRawHex8(path.c_str()); + StringExtractorGDBRemote response; if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) { @@ -3262,22 +3268,23 @@ GDBRemoteCommunicationClient::GetShlibInfoAddr() } lldb_private::Error -GDBRemoteCommunicationClient::RunShellCommand (const char *command, // Shouldn't be NULL - const char *working_dir, // Pass NULL to use the current working directory - int *status_ptr, // Pass NULL if you don't want the process exit status - int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit - std::string *command_output, // Pass NULL if you don't want the command output - uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish +GDBRemoteCommunicationClient::RunShellCommand(const char *command, // Shouldn't be NULL + const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory + int *status_ptr, // Pass NULL if you don't want the process exit status + int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit + std::string *command_output, // Pass NULL if you don't want the command output + uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish { lldb_private::StreamString stream; stream.PutCString("qPlatform_shell:"); stream.PutBytesAsRawHex8(command, strlen(command)); stream.PutChar(','); stream.PutHex32(timeout_sec); - if (working_dir && *working_dir) + if (working_dir) { + std::string path{working_dir.GetPath(false)}; stream.PutChar(','); - stream.PutBytesAsRawHex8(working_dir, strlen(working_dir)); + stream.PutCStringAsRawHex8(path.c_str()); } const char *packet = stream.GetData(); int packet_len = stream.GetSize(); @@ -3310,14 +3317,15 @@ GDBRemoteCommunicationClient::RunShellCommand (const char *command, // } Error -GDBRemoteCommunicationClient::MakeDirectory (const char *path, - uint32_t file_permissions) +GDBRemoteCommunicationClient::MakeDirectory(const FileSpec &file_spec, + uint32_t file_permissions) { + std::string path{file_spec.GetPath(false)}; lldb_private::StreamString stream; stream.PutCString("qPlatform_mkdir:"); stream.PutHex32(file_permissions); stream.PutChar(','); - stream.PutBytesAsRawHex8(path, strlen(path)); + stream.PutCStringAsRawHex8(path.c_str()); const char *packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; @@ -3332,14 +3340,15 @@ GDBRemoteCommunicationClient::MakeDirectory (const char *path, } Error -GDBRemoteCommunicationClient::SetFilePermissions (const char *path, - uint32_t file_permissions) +GDBRemoteCommunicationClient::SetFilePermissions(const FileSpec &file_spec, + uint32_t file_permissions) { + std::string path{file_spec.GetPath(false)}; lldb_private::StreamString stream; stream.PutCString("qPlatform_chmod:"); stream.PutHex32(file_permissions); stream.PutChar(','); - stream.PutBytesAsRawHex8(path, strlen(path)); + stream.PutCStringAsRawHex8(path.c_str()); const char *packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; @@ -3382,9 +3391,9 @@ GDBRemoteCommunicationClient::OpenFile (const lldb_private::FileSpec& file_spec, mode_t mode, Error &error) { + std::string path(file_spec.GetPath(false)); lldb_private::StreamString stream; stream.PutCString("vFile:open:"); - std::string path (file_spec.GetPath(false)); if (path.empty()) return UINT64_MAX; stream.PutCStringAsRawHex8(path.c_str()); @@ -3422,9 +3431,9 @@ GDBRemoteCommunicationClient::CloseFile (lldb::user_id_t fd, lldb::user_id_t GDBRemoteCommunicationClient::GetFileSize (const lldb_private::FileSpec& file_spec) { + std::string path(file_spec.GetPath(false)); lldb_private::StreamString stream; stream.PutCString("vFile:size:"); - std::string path (file_spec.GetPath()); stream.PutCStringAsRawHex8(path.c_str()); const char* packet = stream.GetData(); int packet_len = stream.GetSize(); @@ -3440,12 +3449,14 @@ GDBRemoteCommunicationClient::GetFileSize (const lldb_private::FileSpec& file_sp } Error -GDBRemoteCommunicationClient::GetFilePermissions(const char *path, uint32_t &file_permissions) +GDBRemoteCommunicationClient::GetFilePermissions(const FileSpec &file_spec, + uint32_t &file_permissions) { + std::string path{file_spec.GetPath(false)}; Error error; lldb_private::StreamString stream; stream.PutCString("vFile:mode:"); - stream.PutCStringAsRawHex8(path); + stream.PutCStringAsRawHex8(path.c_str()); const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; @@ -3564,16 +3575,18 @@ GDBRemoteCommunicationClient::WriteFile (lldb::user_id_t fd, } Error -GDBRemoteCommunicationClient::CreateSymlink (const char *src, const char *dst) +GDBRemoteCommunicationClient::CreateSymlink(const FileSpec &src, const FileSpec &dst) { + std::string src_path{src.GetPath(false)}, + dst_path{dst.GetPath(false)}; Error error; lldb_private::StreamGDBRemote stream; stream.PutCString("vFile:symlink:"); // the unix symlink() command reverses its parameters where the dst if first, // so we follow suit here - stream.PutCStringAsRawHex8(dst); + stream.PutCStringAsRawHex8(dst_path.c_str()); stream.PutChar(','); - stream.PutCStringAsRawHex8(src); + stream.PutCStringAsRawHex8(src_path.c_str()); const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; @@ -3607,14 +3620,15 @@ GDBRemoteCommunicationClient::CreateSymlink (const char *src, const char *dst) } Error -GDBRemoteCommunicationClient::Unlink (const char *path) +GDBRemoteCommunicationClient::Unlink(const FileSpec &file_spec) { + std::string path{file_spec.GetPath(false)}; Error error; lldb_private::StreamGDBRemote stream; stream.PutCString("vFile:unlink:"); // the unix symlink() command reverses its parameters where the dst if first, // so we follow suit here - stream.PutCStringAsRawHex8(path); + stream.PutCStringAsRawHex8(path.c_str()); const char* packet = stream.GetData(); int packet_len = stream.GetSize(); StringExtractorGDBRemote response; @@ -3651,9 +3665,9 @@ GDBRemoteCommunicationClient::Unlink (const char *path) bool GDBRemoteCommunicationClient::GetFileExists (const lldb_private::FileSpec& file_spec) { + std::string path(file_spec.GetPath(false)); lldb_private::StreamString stream; stream.PutCString("vFile:exists:"); - std::string path (file_spec.GetPath()); stream.PutCStringAsRawHex8(path.c_str()); const char* packet = stream.GetData(); int packet_len = stream.GetSize(); @@ -3675,9 +3689,9 @@ GDBRemoteCommunicationClient::CalculateMD5 (const lldb_private::FileSpec& file_s uint64_t &high, uint64_t &low) { + std::string path(file_spec.GetPath(false)); lldb_private::StreamString stream; stream.PutCString("vFile:MD5:"); - std::string path (file_spec.GetPath()); stream.PutCStringAsRawHex8(path.c_str()); const char* packet = stream.GetData(); int packet_len = stream.GetSize(); @@ -3874,7 +3888,7 @@ GDBRemoteCommunicationClient::GetModuleInfo (const FileSpec& module_file_spec, packet.PutCStringAsRawHex8(module_path.c_str()); packet.PutCString(";"); const auto& triple = arch_spec.GetTriple().getTriple(); - packet.PutBytesAsRawHex8(triple.c_str(), triple.size()); + packet.PutCStringAsRawHex8(triple.c_str()); StringExtractorGDBRemote response; if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) != PacketResult::Success) |