summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2012-08-30 18:15:10 +0000
committerGreg Clayton <gclayton@apple.com>2012-08-30 18:15:10 +0000
commit0b0b512fd6eaa15626d0b1caad24ae66a79e8408 (patch)
treeec79472f787c96799b79d9d0556c20bf7e477278 /lldb/source
parent738ea2590ffde414777efe26bffd27d97f5cc351 (diff)
downloadbcm5719-llvm-0b0b512fd6eaa15626d0b1caad24ae66a79e8408.tar.gz
bcm5719-llvm-0b0b512fd6eaa15626d0b1caad24ae66a79e8408.zip
OptionValueFileSpec had an accessor to read the contents of the file and return the data. This can end up being used to get the string contents of a text file and could end up not being NULL terminated. I added accessors to get the file contents raw, or with a null terminator. Added the needed calls to make this happen in the FileSpec and File classes.
llvm-svn: 162921
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Host/common/File.cpp4
-rw-r--r--lldb/source/Host/common/FileSpec.cpp32
-rw-r--r--lldb/source/Interpreter/OptionValueFileSpec.cpp9
-rw-r--r--lldb/source/Target/Target.cpp3
4 files changed, 42 insertions, 6 deletions
diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp
index a84266f7110..ca0c223e629 100644
--- a/lldb/source/Host/common/File.cpp
+++ b/lldb/source/Host/common/File.cpp
@@ -538,7 +538,7 @@ File::Read (void *buf, size_t &num_bytes, off_t &offset)
}
Error
-File::Read (size_t &num_bytes, off_t &offset, DataBufferSP &data_buffer_sp)
+File::Read (size_t &num_bytes, off_t &offset, bool null_terminate, DataBufferSP &data_buffer_sp)
{
Error error;
@@ -557,7 +557,7 @@ File::Read (size_t &num_bytes, off_t &offset, DataBufferSP &data_buffer_sp)
num_bytes = bytes_left;
std::auto_ptr<DataBufferHeap> data_heap_ap;
- data_heap_ap.reset(new DataBufferHeap(num_bytes, '\0'));
+ data_heap_ap.reset(new DataBufferHeap(num_bytes + (null_terminate ? 1 : 0), '\0'));
if (data_heap_ap.get())
{
diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp
index 0faa274a47f..d104bd21c47 100644
--- a/lldb/source/Host/common/FileSpec.cpp
+++ b/lldb/source/Host/common/FileSpec.cpp
@@ -812,7 +812,37 @@ FileSpec::ReadFileContents (off_t file_offset, size_t file_size, Error *error_pt
File file;
error = file.Open(resolved_path, File::eOpenOptionRead);
if (error.Success())
- error = file.Read (file_size, file_offset, data_sp);
+ {
+ const bool null_terminate = false;
+ error = file.Read (file_size, file_offset, null_terminate, data_sp);
+ }
+ }
+ else
+ {
+ error.SetErrorString("invalid file specification");
+ }
+ if (error_ptr)
+ *error_ptr = error;
+ return data_sp;
+}
+
+DataBufferSP
+FileSpec::ReadFileContentsAsCString(Error *error_ptr)
+{
+ Error error;
+ DataBufferSP data_sp;
+ char resolved_path[PATH_MAX];
+ if (GetPath(resolved_path, sizeof(resolved_path)))
+ {
+ File file;
+ error = file.Open(resolved_path, File::eOpenOptionRead);
+ if (error.Success())
+ {
+ off_t offset = 0;
+ size_t length = SIZE_MAX;
+ const bool null_terminate = true;
+ error = file.Read (length, offset, null_terminate, data_sp);
+ }
}
else
{
diff --git a/lldb/source/Interpreter/OptionValueFileSpec.cpp b/lldb/source/Interpreter/OptionValueFileSpec.cpp
index 3a1f26dd5f6..03608753658 100644
--- a/lldb/source/Interpreter/OptionValueFileSpec.cpp
+++ b/lldb/source/Interpreter/OptionValueFileSpec.cpp
@@ -114,10 +114,15 @@ OptionValueFileSpec::AutoComplete (CommandInterpreter &interpreter,
const lldb::DataBufferSP &
-OptionValueFileSpec::GetFileContents()
+OptionValueFileSpec::GetFileContents(bool null_terminate)
{
if (!m_data_sp && m_current_value)
- m_data_sp = m_current_value.ReadFileContents();
+ {
+ if (null_terminate)
+ m_data_sp = m_current_value.ReadFileContentsAsCString();
+ else
+ m_data_sp = m_current_value.ReadFileContents();
+ }
return m_data_sp;
}
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 2298a1fa3a0..23c8678c47e 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -2474,7 +2474,8 @@ TargetProperties::GetExpressionPrefixContentsAsCString ()
OptionValueFileSpec *file = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec (NULL, false, idx);
if (file)
{
- DataBufferSP data_sp(file->GetFileContents());
+ const bool null_terminate = true;
+ DataBufferSP data_sp(file->GetFileContents(null_terminate));
if (data_sp)
return (const char *) data_sp->GetBytes();
}
OpenPOWER on IntegriCloud