<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
This commit is contained in:
Greg Clayton 2012-01-06 02:01:06 +00:00
parent 8e2fc5c5e9
commit 4017fa399b
5 changed files with 32 additions and 14 deletions

View File

@ -462,10 +462,10 @@ public:
/// pointer must be checked prior to using it. /// pointer must be checked prior to using it.
//------------------------------------------------------------------ //------------------------------------------------------------------
lldb::DataBufferSP 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 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. /// Change the file specificed with a new path.

View File

@ -339,7 +339,7 @@ Section::ReadSectionDataFromObjectFile (const ObjectFile* objfile, off_t section
if (section_offset < file_size) if (section_offset < file_size)
{ {
off_t section_file_offset = objfile->GetOffset() + GetFileOffset() + section_offset; 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) if (bytes_read >= dst_len)
return bytes_read; return bytes_read;
bytes_left -= bytes_read; bytes_left -= bytes_read;

View File

@ -771,13 +771,13 @@ FileSpec::MemorySize() const
size_t 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; size_t bytes_read = 0;
char resolved_path[PATH_MAX]; char resolved_path[PATH_MAX];
if (GetPath(resolved_path, sizeof(resolved_path))) if (GetPath(resolved_path, sizeof(resolved_path)))
{ {
Error error;
File file; File file;
error = file.Open(resolved_path, File::eOpenOptionRead); error = file.Open(resolved_path, File::eOpenOptionRead);
if (error.Success()) 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); 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; 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. // verified using the DataBuffer::GetByteSize() function.
//------------------------------------------------------------------ //------------------------------------------------------------------
DataBufferSP 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; DataBufferSP data_sp;
char resolved_path[PATH_MAX]; char resolved_path[PATH_MAX];
if (GetPath(resolved_path, sizeof(resolved_path))) if (GetPath(resolved_path, sizeof(resolved_path)))
{ {
Error error;
File file; File file;
error = file.Open(resolved_path, File::eOpenOptionRead); error = file.Open(resolved_path, File::eOpenOptionRead);
if (error.Success()) if (error.Success())
error = file.Read (file_size, file_offset, data_sp); error = file.Read (file_size, file_offset, data_sp);
} }
else
{
error.SetErrorString("invalid file specification");
}
if (error_ptr)
*error_ptr = error;
return data_sp; return data_sp;
} }

View File

@ -234,7 +234,7 @@ PlatformRemoteiOS::GetDeviceSupportDirectory()
xcode_dir_path.append (xcode_select_prefix_dir); xcode_dir_path.append (xcode_select_prefix_dir);
xcode_dir_path.append ("/usr/share/xcode-select/xcode_dir_path"); xcode_dir_path.append ("/usr/share/xcode-select/xcode_dir_path");
temp_file_spec.SetFile(xcode_dir_path.c_str(), false); 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) if (bytes_read > 0)
{ {
developer_dir_path[bytes_read] = '\0'; developer_dir_path[bytes_read] = '\0';

View File

@ -2308,6 +2308,8 @@ TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_n
case eVarSetOperationAssign: case eVarSetOperationAssign:
case eVarSetOperationAppend: case eVarSetOperationAppend:
{ {
m_expr_prefix_contents.clear();
if (!m_expr_prefix_file.GetCurrentValue().Exists()) if (!m_expr_prefix_file.GetCurrentValue().Exists())
{ {
err.SetErrorToGenericError (); err.SetErrorToGenericError ();
@ -2315,15 +2317,19 @@ TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_n
return; 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())
{
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); err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
m_expr_prefix_contents.clear();
} }
}
m_expr_prefix_contents.assign((const char*)file_contents->GetBytes(), file_contents->GetByteSize());
} }
break; break;
case eVarSetOperationClear: case eVarSetOperationClear: