diff options
| author | Greg Clayton <gclayton@apple.com> | 2012-01-06 02:01:06 +0000 |
|---|---|---|
| committer | Greg Clayton <gclayton@apple.com> | 2012-01-06 02:01:06 +0000 |
| commit | 4017fa399b0018a08bf6ae81fcb6900848034a6f (patch) | |
| tree | fa20a55c9b42182c5a3ba150989e484958201173 /lldb | |
| parent | 8e2fc5c5e997b21721b91d97e6b12ce40e5d5791 (diff) | |
| download | bcm5719-llvm-4017fa399b0018a08bf6ae81fcb6900848034a6f.tar.gz bcm5719-llvm-4017fa399b0018a08bf6ae81fcb6900848034a6f.zip | |
<rdar://problem/10652336>
Fixed a crasher when trying to load an expression prefix file:
% touch /tmp/carp.txt
% xcrun lldb
(lldb) settings set target.expr-prefix /tmp/carp.txt
Segmentation fault
llvm-svn: 147646
Diffstat (limited to 'lldb')
| -rw-r--r-- | lldb/include/lldb/Host/FileSpec.h | 4 | ||||
| -rw-r--r-- | lldb/source/Core/Section.cpp | 2 | ||||
| -rw-r--r-- | lldb/source/Host/common/FileSpec.cpp | 20 | ||||
| -rw-r--r-- | lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp | 2 | ||||
| -rw-r--r-- | lldb/source/Target/Target.cpp | 18 |
5 files changed, 32 insertions, 14 deletions
diff --git a/lldb/include/lldb/Host/FileSpec.h b/lldb/include/lldb/Host/FileSpec.h index b1d25256ee2..3ff405e0489 100644 --- a/lldb/include/lldb/Host/FileSpec.h +++ b/lldb/include/lldb/Host/FileSpec.h @@ -462,10 +462,10 @@ public: /// pointer must be checked prior to using it. //------------------------------------------------------------------ lldb::DataBufferSP - ReadFileContents (off_t offset = 0, size_t length = SIZE_MAX) const; + ReadFileContents (off_t offset = 0, size_t length = SIZE_MAX, Error *error_ptr = NULL) const; size_t - ReadFileContents (off_t file_offset, void *dst, size_t dst_len) const; + ReadFileContents (off_t file_offset, void *dst, size_t dst_len, Error *error_ptr) const; //------------------------------------------------------------------ /// Change the file specificed with a new path. diff --git a/lldb/source/Core/Section.cpp b/lldb/source/Core/Section.cpp index b8b9ddf3d18..09394b266f3 100644 --- a/lldb/source/Core/Section.cpp +++ b/lldb/source/Core/Section.cpp @@ -339,7 +339,7 @@ Section::ReadSectionDataFromObjectFile (const ObjectFile* objfile, off_t section if (section_offset < file_size) { off_t section_file_offset = objfile->GetOffset() + GetFileOffset() + section_offset; - bytes_read = file.ReadFileContents (section_file_offset, dst, dst_len); + bytes_read = file.ReadFileContents (section_file_offset, dst, dst_len, NULL); if (bytes_read >= dst_len) return bytes_read; bytes_left -= bytes_read; diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp index 1f0942d5bb5..f769d2e39f9 100644 --- a/lldb/source/Host/common/FileSpec.cpp +++ b/lldb/source/Host/common/FileSpec.cpp @@ -771,13 +771,13 @@ FileSpec::MemorySize() const size_t -FileSpec::ReadFileContents (off_t file_offset, void *dst, size_t dst_len) const +FileSpec::ReadFileContents (off_t file_offset, void *dst, size_t dst_len, Error *error_ptr) const { + Error error; size_t bytes_read = 0; char resolved_path[PATH_MAX]; if (GetPath(resolved_path, sizeof(resolved_path))) { - Error error; File file; error = file.Open(resolved_path, File::eOpenOptionRead); if (error.Success()) @@ -787,6 +787,12 @@ FileSpec::ReadFileContents (off_t file_offset, void *dst, size_t dst_len) const error = file.Read(dst, bytes_read, file_offset_after_seek); } } + else + { + error.SetErrorString("invalid file specification"); + } + if (error_ptr) + *error_ptr = error; return bytes_read; } @@ -802,18 +808,24 @@ FileSpec::ReadFileContents (off_t file_offset, void *dst, size_t dst_len) 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, Error *error_ptr) const { + Error error; DataBufferSP data_sp; char resolved_path[PATH_MAX]; if (GetPath(resolved_path, sizeof(resolved_path))) { - Error error; File file; error = file.Open(resolved_path, File::eOpenOptionRead); if (error.Success()) error = file.Read (file_size, file_offset, data_sp); } + else + { + error.SetErrorString("invalid file specification"); + } + if (error_ptr) + *error_ptr = error; return data_sp; } diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp index 62d85451249..12c104b24de 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp @@ -234,7 +234,7 @@ PlatformRemoteiOS::GetDeviceSupportDirectory() xcode_dir_path.append (xcode_select_prefix_dir); xcode_dir_path.append ("/usr/share/xcode-select/xcode_dir_path"); temp_file_spec.SetFile(xcode_dir_path.c_str(), false); - size_t bytes_read = temp_file_spec.ReadFileContents(0, developer_dir_path, sizeof(developer_dir_path)); + size_t bytes_read = temp_file_spec.ReadFileContents(0, developer_dir_path, sizeof(developer_dir_path), NULL); if (bytes_read > 0) { developer_dir_path[bytes_read] = '\0'; diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index c31b0b1d9d4..3ff461d6173 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -2308,6 +2308,8 @@ TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_n case eVarSetOperationAssign: case eVarSetOperationAppend: { + m_expr_prefix_contents.clear(); + if (!m_expr_prefix_file.GetCurrentValue().Exists()) { err.SetErrorToGenericError (); @@ -2315,15 +2317,19 @@ TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_n return; } - DataBufferSP file_contents = m_expr_prefix_file.GetCurrentValue().ReadFileContents(); + DataBufferSP file_data_sp (m_expr_prefix_file.GetCurrentValue().ReadFileContents(0, SIZE_MAX, &err)); - if (!file_contents && file_contents->GetByteSize() == 0) + if (err.Success()) { - err.SetErrorStringWithFormat ("couldn't read data from '%s'", value); - m_expr_prefix_contents.clear(); + if (file_data_sp && file_data_sp->GetByteSize() > 0) + { + m_expr_prefix_contents.assign((const char*)file_data_sp->GetBytes(), file_data_sp->GetByteSize()); + } + else + { + err.SetErrorStringWithFormat ("couldn't read data from '%s'", value); + } } - - m_expr_prefix_contents.assign((const char*)file_contents->GetBytes(), file_contents->GetByteSize()); } break; case eVarSetOperationClear: |

