[Lldb-commits] [lldb] r154449 - in /lldb/branches/lldb-platform-work: include/lldb/Host/Host.h include/lldb/Target/Platform.h source/Host/common/Host.cpp source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp source/Plugins/Platform/MacOSX/PlatformMacOSX.h
Johnny Chen
johnny.chen at apple.com
Tue Apr 10 15:57:11 PDT 2012
Author: johnny
Date: Tue Apr 10 17:57:10 2012
New Revision: 154449
URL: http://llvm.org/viewvc/llvm-project?rev=154449&view=rev
Log:
Add plugin implementation of the 'platform get-file' command for the MacOSX remote platform. Example:
(lldb) platform select remote-macosx
Platform: remote-macosx
Connected: no
(lldb) platform connect connect://localhost:12345
Platform: remote-macosx
Triple: x86_64-apple-darwin
OS Version: 10.8.0 (12A154q)
Kernel: Darwin Kernel Version 12.0.0: Thu Mar 8 20:07:40 PST 2012; root:xnu-2050.2.33~2/RELEASE_X86_64
Hostname: jchen.apple.com
Connected: yes
(lldb) log enable gdb-remote packets
(lldb) platform get-file /tmp/hello_world /tmp/hello_world.copy
<lldb.driver.main-thread> history[1] < 1> send packet: +
<lldb.driver.main-thread> history[2] < 19> send packet: $QStartNoAckMode#b0
<lldb.driver.main-thread> history[3] < 1> read packet: +
<lldb.driver.main-thread> history[4] < 6> read packet: $OK#9a
<lldb.driver.main-thread> history[5] < 1> send packet: +
<lldb.driver.main-thread> history[6] < 13> send packet: $qHostInfo#00
<lldb.driver.main-thread> history[7] < 387> read packet: $triple:7838365f36342d6170706c652d64617277696e;ptrsize:8;cputype:16777223;cpusubtype:3;endian:little;os_version:10.8.0;os_build:31324131353471;os_kernel:44617277696e204b65726e656c2056657273696f6e2031322e302e303a20546875204d61722020382032303a30373a34302050535420323031323b20726f6f743a786e752d323035302e322e33337e322f52454c454153455f5838365f3634;hostname:6a6368656e2e6170706c652e636f6d;#00
<lldb.driver.main-thread> < 65> send packet: $vFile:open:2f746d702f68656c6c6f5f776f726c64,00000001,0000000b#00
<lldb.driver.main-thread> < 21> read packet: $F000000000000000a#00
<lldb.driver.main-thread> < 50> send packet: $vFile:pread:000000000000000a,00000400,00000000#00
<lldb.driver.main-thread> < 28> read packet: $F0000000e;hello, world!
#00
<lldb.driver.main-thread> < 50> send packet: $vFile:pread:000000000000000a,00000400,0000000e#00
<lldb.driver.main-thread> < 14> read packet: $F00000000;#00
<lldb.driver.main-thread> < 32> send packet: $vFile:close:000000000000000a#00
<lldb.driver.main-thread> < 13> read packet: $F00000001#00
Successfully uploaded file from /tmp/hello_world (remote) to /tmp/hello_world.copy (host)
(lldb)
Modified:
lldb/branches/lldb-platform-work/include/lldb/Host/Host.h
lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h
lldb/branches/lldb-platform-work/source/Host/common/Host.cpp
lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.h
Modified: lldb/branches/lldb-platform-work/include/lldb/Host/Host.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/include/lldb/Host/Host.h?rev=154449&r1=154448&r2=154449&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/include/lldb/Host/Host.h (original)
+++ lldb/branches/lldb-platform-work/include/lldb/Host/Host.h Tue Apr 10 17:57:10 2012
@@ -471,6 +471,9 @@
static uint32_t
ReadFile (lldb::user_id_t fd, uint64_t offset, void* data_ptr, size_t len_wanted);
+
+ static lldb::user_id_t
+ GetFileSize (const FileSpec& file_spec);
};
} // namespace lldb_private
Modified: lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h?rev=154449&r1=154448&r2=154449&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h (original)
+++ lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h Tue Apr 10 17:57:10 2012
@@ -468,7 +468,7 @@
uint32_t flags,
mode_t mode)
{
- return UINT32_MAX;
+ return UINT64_MAX;
}
virtual bool
Modified: lldb/branches/lldb-platform-work/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Host/common/Host.cpp?rev=154449&r1=154448&r2=154449&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Host/common/Host.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Host/common/Host.cpp Tue Apr 10 17:57:10 2012
@@ -1365,3 +1365,9 @@
return len_wanted_;
}
+lldb::user_id_t
+Host::GetFileSize (const FileSpec& file_spec)
+{
+ return file_spec.GetByteSize();
+}
+
Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp?rev=154449&r1=154448&r2=154449&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp Tue Apr 10 17:57:10 2012
@@ -320,3 +320,71 @@
}
return Platform::PutFile(source,destination,uid,gid);
}
+
+lldb_private::Error
+PlatformMacOSX::GetFile (const lldb_private::FileSpec& source /* remote file path */,
+ const lldb_private::FileSpec& destination /* local file path */)
+{
+#define GETFILE_CHUNK_SIZE 1024
+ if (IsHost())
+ {
+ if (FileSpec::Equal(source, destination, true))
+ return Error("local scenario->source and destination are the same file path: no operation performed");
+ // cp src dst
+ char src_path[PATH_MAX];
+ char dst_path[PATH_MAX];
+ if (!source.GetPath(src_path, sizeof(src_path)) || !destination.GetPath(dst_path, sizeof(dst_path)))
+ {
+ return Error("max path length exceeded?");
+ }
+ std::stringstream cp_command("cp ");
+ cp_command << src_path << ' ' << dst_path;
+ if (RunShellCommand(cp_command.str()) != 0)
+ return Error("unable to perform copy");
+ return Error();
+ }
+ else if (IsRemote() && m_remote_platform_sp)
+ {
+ // open src and dst
+ // read, read, read, ...
+ // close src
+ // write dst
+ // close dst
+ user_id_t fd_src = OpenFile(source, File::eOpenOptionRead, File::ePermissionsDefault);
+ user_id_t fd_dst = Host::OpenFile(destination,
+ File::eOpenOptionCanCreate|File::eOpenOptionWrite,
+ File::ePermissionsDefault);
+ if (fd_src == UINT64_MAX)
+ return Error("unable to open source file");
+ if (fd_dst == UINT64_MAX)
+ return Error("unable to open destination file");
+
+ lldb::DataBufferSP buffer_sp(new DataBufferHeap(GETFILE_CHUNK_SIZE, 0));
+ uint8_t *cursor = buffer_sp->GetBytes();
+ Error err;
+ uint64_t offset = 0;
+ while (err.Success())
+ {
+ user_id_t n_read = ReadFile(fd_src, offset, cursor, GETFILE_CHUNK_SIZE);
+ if (n_read == UINT32_MAX)
+ return Error("error during read operation");
+ // Break out of the loop once we reach end of file.
+ if (n_read == 0)
+ break;
+
+ if (!Host::WriteFile(fd_dst, offset, cursor, n_read))
+ return Error("unable to write to destination file");
+
+ offset += n_read;
+ cursor += n_read;
+
+ }
+ // Ignore the close error of src.
+ CloseFile(fd_src);
+ // And close the dst file descriptot.
+ if (!Host::CloseFile(fd_dst))
+ return Error("unable to close destination file");
+ return Error();
+ }
+ return Platform::GetFile(source,destination);
+}
Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.h?rev=154449&r1=154448&r2=154449&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.h (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.h Tue Apr 10 17:57:10 2012
@@ -94,6 +94,10 @@
uint32_t uid = UINT32_MAX,
uint32_t gid = UINT32_MAX);
+ virtual lldb_private::Error
+ GetFile (const lldb_private::FileSpec& source,
+ const lldb_private::FileSpec& destination);
+
virtual lldb::user_id_t
OpenFile (const lldb_private::FileSpec& file_spec,
uint32_t flags,
More information about the lldb-commits
mailing list