diff options
author | Greg Clayton <gclayton@apple.com> | 2010-06-30 23:03:03 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2010-06-30 23:03:03 +0000 |
commit | dda4f7b520827fb1cce38dbef9a00758067df99a (patch) | |
tree | 622c1e19dfdda4764cb606030d83e030c22a92e0 /lldb/source/Core/FileSpec.cpp | |
parent | 56f2e34a6a0810f28fa4d7ab171a9e12415e29a3 (diff) | |
download | bcm5719-llvm-dda4f7b520827fb1cce38dbef9a00758067df99a.tar.gz bcm5719-llvm-dda4f7b520827fb1cce38dbef9a00758067df99a.zip |
Centralized all disassembly into static functions in source/Core/Disassembler.cpp.
Added the ability to read memory from the target's object files when we aren't
running, so disassembling works before you run!
Cleaned up the API to lldb_private::Target::ReadMemory().
Cleaned up the API to the Disassembler to use actual "lldb_private::Address"
objects instead of just an "addr_t". This is nice because the Address objects
when resolved carry along their section and module which can get us the
object file. This allows Target::ReadMemory to be used when we are not
running.
Added a new lldb_private::Address dump style: DumpStyleDetailedSymbolContext
This will show a full breakdown of what an address points to. To see some
sample output, execute a "image lookup --address <addr>".
Fixed SymbolContext::DumpStopContext(...) to not require a live process in
order to be able to print function and symbol offsets.
llvm-svn: 107350
Diffstat (limited to 'lldb/source/Core/FileSpec.cpp')
-rw-r--r-- | lldb/source/Core/FileSpec.cpp | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/lldb/source/Core/FileSpec.cpp b/lldb/source/Core/FileSpec.cpp index 91ad6b04351..ea3d3af3c75 100644 --- a/lldb/source/Core/FileSpec.cpp +++ b/lldb/source/Core/FileSpec.cpp @@ -496,6 +496,41 @@ FileSpec::MemorySize() const return m_filename.MemorySize() + m_directory.MemorySize(); } + +size_t +FileSpec::ReadFileContents (off_t file_offset, void *dst, size_t dst_len) const +{ + size_t bytes_read = 0; + char resolved_path[PATH_MAX]; + if (GetPath(resolved_path, sizeof(resolved_path))) + { + int fd = ::open (resolved_path, O_RDONLY, 0); + if (fd != -1) + { + struct stat file_stats; + if (::fstat (fd, &file_stats) == 0) + { + // Read bytes directly into our basic_string buffer + if (file_stats.st_size > 0) + { + off_t lseek_result = 0; + if (file_offset > 0) + lseek_result = ::lseek (fd, file_offset, SEEK_SET); + + if (lseek_result == file_offset) + { + ssize_t n = ::read (fd, dst, dst_len); + if (n >= 0) + bytes_read = n; + } + } + } + } + close(fd); + } + return bytes_read; +} + //------------------------------------------------------------------ // Returns a shared pointer to a data buffer that contains all or // part of the contents of a file. The data copies into a heap based @@ -508,7 +543,7 @@ FileSpec::MemorySize() const // verified using the DataBuffer::GetByteSize() function. //------------------------------------------------------------------ DataBufferSP -FileSpec::ReadFileContents(off_t file_offset, size_t file_size) const +FileSpec::ReadFileContents (off_t file_offset, size_t file_size) const { DataBufferSP data_sp; char resolved_path[PATH_MAX]; @@ -520,7 +555,6 @@ FileSpec::ReadFileContents(off_t file_offset, size_t file_size) const struct stat file_stats; if (::fstat (fd, &file_stats) == 0) { - // Read bytes directly into our basic_string buffer if (file_stats.st_size > 0) { off_t lseek_result = 0; @@ -533,11 +567,13 @@ FileSpec::ReadFileContents(off_t file_offset, size_t file_size) const } else if (lseek_result == file_offset) { + const size_t bytes_left = file_stats.st_size - file_offset; + size_t num_bytes_to_read = file_size; + if (num_bytes_to_read > bytes_left) + num_bytes_to_read = bytes_left; + std::auto_ptr<DataBufferHeap> data_heap_ap; - if (file_stats.st_size < file_size) - data_heap_ap.reset(new DataBufferHeap(file_stats.st_size, '\0')); - else - data_heap_ap.reset(new DataBufferHeap(file_size, '\0')); + data_heap_ap.reset(new DataBufferHeap(num_bytes_to_read, '\0')); if (data_heap_ap.get()) { |