forked from OSchip/llvm-project
<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:
parent
8e2fc5c5e9
commit
4017fa399b
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
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.clear();
|
||||
}
|
||||
|
||||
m_expr_prefix_contents.assign((const char*)file_contents->GetBytes(), file_contents->GetByteSize());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case eVarSetOperationClear:
|
||||
|
|
Loading…
Reference in New Issue