forked from OSchip/llvm-project
Start converting usages of off_t to other types.
off_t is a type which is used for file offsets. Even more specifically, it is only used by a limited number of C APIs that deal with files. Any usage of off_t where the variable is not intended to be used with one of these APIs is a bug, by definition. This patch corrects some easy mis-uses of off_t, generally by converting them to lldb::offset_t, but sometimes by using other types such as size_t, when appropriate. The use of off_t to represent these offsets has worked fine in practice on linux-y platforms, since we used _FILE_OFFSET_64 to guarantee that off_t was a uint64. On Windows, however, _FILE_OFFSET_64 is unrecognized, and off_t will always be 32-bit. So the usage of off_t on Windows actually leads to legitimate bugs. Reviewed by: Greg Clayton Differential Revision: http://reviews.llvm.org/D4358 llvm-svn: 212192
This commit is contained in:
parent
379b97f285
commit
a746e8e58a
|
@ -88,7 +88,7 @@ public:
|
|||
Module (const FileSpec& file_spec,
|
||||
const ArchSpec& arch,
|
||||
const ConstString *object_name = NULL,
|
||||
off_t object_offset = 0,
|
||||
lldb::offset_t object_offset = 0,
|
||||
const TimeValue *object_mod_time_ptr = NULL);
|
||||
|
||||
Module (const ModuleSpec &module_spec);
|
||||
|
|
|
@ -468,7 +468,7 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
virtual off_t
|
||||
virtual lldb::offset_t
|
||||
GetByteOffset()
|
||||
{
|
||||
return 0;
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
return m_byte_size;
|
||||
}
|
||||
|
||||
virtual off_t
|
||||
virtual lldb::offset_t
|
||||
GetByteOffset()
|
||||
{
|
||||
return m_byte_offset;
|
||||
|
|
|
@ -167,7 +167,7 @@ public:
|
|||
const ConstString &name,
|
||||
llvm::Value *value,
|
||||
size_t size,
|
||||
off_t alignment);
|
||||
lldb::offset_t alignment);
|
||||
|
||||
//------------------------------------------------------------------
|
||||
/// [Used by IRForTarget] Finalize the struct, laying out the position
|
||||
|
@ -198,7 +198,7 @@ public:
|
|||
bool
|
||||
GetStructInfo (uint32_t &num_elements,
|
||||
size_t &size,
|
||||
off_t &alignment);
|
||||
lldb::offset_t &alignment);
|
||||
|
||||
//------------------------------------------------------------------
|
||||
/// [Used by IRForTarget] Get specific information about one field
|
||||
|
@ -234,7 +234,7 @@ public:
|
|||
bool
|
||||
GetStructElement (const clang::NamedDecl *&decl,
|
||||
llvm::Value *&value,
|
||||
off_t &offset,
|
||||
lldb::offset_t &offset,
|
||||
ConstString &name,
|
||||
uint32_t index);
|
||||
|
||||
|
@ -461,7 +461,7 @@ private:
|
|||
{
|
||||
}
|
||||
|
||||
off_t m_struct_alignment; ///< The alignment of the struct in bytes.
|
||||
lldb::offset_t m_struct_alignment; ///< The alignment of the struct in bytes.
|
||||
size_t m_struct_size; ///< The size of the struct in bytes.
|
||||
bool m_struct_laid_out; ///< True if the struct has been laid out and the layout is valid (that is, no new fields have been added since).
|
||||
ConstString m_result_name; ///< The name of the result variable ($1, for example)
|
||||
|
|
|
@ -162,9 +162,9 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
off_t m_alignment; ///< The required alignment of the variable, in bytes
|
||||
size_t m_size; ///< The space required for the variable, in bytes
|
||||
off_t m_offset; ///< The offset of the variable in the struct, in bytes
|
||||
lldb::offset_t m_alignment; ///< The required alignment of the variable, in bytes
|
||||
size_t m_size; ///< The space required for the variable, in bytes
|
||||
lldb::offset_t m_offset; ///< The offset of the variable in the struct, in bytes
|
||||
};
|
||||
|
||||
private:
|
||||
|
|
|
@ -100,7 +100,7 @@ private:
|
|||
|
||||
typedef std::shared_ptr<CIE> CIESP;
|
||||
|
||||
typedef std::map<off_t, CIESP> cie_map_t;
|
||||
typedef std::map<dw_offset_t, CIESP> cie_map_t;
|
||||
|
||||
// Start address (file address), size, offset of FDE location
|
||||
// used for finding an FDE for a given File address; the start address field is
|
||||
|
|
|
@ -798,14 +798,14 @@ public:
|
|||
size_t byte_size);
|
||||
|
||||
size_t
|
||||
GetData (off_t offset, size_t length, DataExtractor &data) const;
|
||||
GetData (lldb::offset_t offset, size_t length, DataExtractor &data) const;
|
||||
|
||||
size_t
|
||||
CopyData (off_t offset, size_t length, void *dst) const;
|
||||
CopyData (lldb::offset_t offset, size_t length, void *dst) const;
|
||||
|
||||
virtual size_t
|
||||
ReadSectionData (const Section *section,
|
||||
off_t section_offset,
|
||||
lldb::offset_t section_offset,
|
||||
void *dst,
|
||||
size_t dst_len) const;
|
||||
virtual size_t
|
||||
|
|
|
@ -78,7 +78,7 @@ public:
|
|||
bool notify);
|
||||
|
||||
bool
|
||||
Remove (off_t index, bool notify);
|
||||
Remove (size_t index, bool notify);
|
||||
|
||||
bool
|
||||
Remove (const ConstString &path, bool notify);
|
||||
|
|
|
@ -235,7 +235,7 @@ Module::Module (const ModuleSpec &module_spec) :
|
|||
Module::Module(const FileSpec& file_spec,
|
||||
const ArchSpec& arch,
|
||||
const ConstString *object_name,
|
||||
off_t object_offset,
|
||||
lldb::offset_t object_offset,
|
||||
const TimeValue *object_mod_time_ptr) :
|
||||
m_mutex (Mutex::eMutexTypeRecursive),
|
||||
m_mod_time (file_spec.GetModificationTime()),
|
||||
|
|
|
@ -304,7 +304,7 @@ ClangExpressionDeclMap::AddValueToStruct
|
|||
const ConstString &name,
|
||||
llvm::Value *value,
|
||||
size_t size,
|
||||
off_t alignment
|
||||
lldb::offset_t alignment
|
||||
)
|
||||
{
|
||||
assert (m_struct_vars.get());
|
||||
|
@ -412,7 +412,7 @@ bool ClangExpressionDeclMap::GetStructInfo
|
|||
(
|
||||
uint32_t &num_elements,
|
||||
size_t &size,
|
||||
off_t &alignment
|
||||
lldb::offset_t &alignment
|
||||
)
|
||||
{
|
||||
assert (m_struct_vars.get());
|
||||
|
@ -432,7 +432,7 @@ ClangExpressionDeclMap::GetStructElement
|
|||
(
|
||||
const NamedDecl *&decl,
|
||||
llvm::Value *&value,
|
||||
off_t &offset,
|
||||
lldb::offset_t &offset,
|
||||
ConstString &name,
|
||||
uint32_t index
|
||||
)
|
||||
|
|
|
@ -1519,11 +1519,11 @@ IRForTarget::MaybeHandleVariable (Value *llvm_value_ptr)
|
|||
}
|
||||
|
||||
const uint64_t value_size = clang_type.GetByteSize();
|
||||
off_t value_alignment = (clang_type.GetTypeBitAlign() + 7ull) / 8ull;
|
||||
lldb::offset_t value_alignment = (clang_type.GetTypeBitAlign() + 7ull) / 8ull;
|
||||
|
||||
if (log)
|
||||
{
|
||||
log->Printf("Type of \"%s\" is [clang \"%s\", llvm \"%s\"] [size %" PRIu64 ", align %" PRId64 "]",
|
||||
log->Printf("Type of \"%s\" is [clang \"%s\", llvm \"%s\"] [size %" PRIu64 ", align %" PRIu64 "]",
|
||||
name.c_str(),
|
||||
clang_type.GetQualType().getAsString().c_str(),
|
||||
PrintType(value_type).c_str(),
|
||||
|
@ -2258,7 +2258,7 @@ IRForTarget::ReplaceVariables (Function &llvm_function)
|
|||
uint32_t element_index;
|
||||
|
||||
size_t size;
|
||||
off_t alignment;
|
||||
lldb::offset_t alignment;
|
||||
|
||||
if (!m_decl_map->GetStructInfo (num_elements, size, alignment))
|
||||
return false;
|
||||
|
@ -2359,7 +2359,7 @@ IRForTarget::ReplaceVariables (Function &llvm_function)
|
|||
{
|
||||
const clang::NamedDecl *decl = NULL;
|
||||
Value *value = NULL;
|
||||
off_t offset;
|
||||
lldb::offset_t offset;
|
||||
lldb_private::ConstString name;
|
||||
|
||||
if (!m_decl_map->GetStructElement (decl, value, offset, name, element_index))
|
||||
|
@ -2371,7 +2371,7 @@ IRForTarget::ReplaceVariables (Function &llvm_function)
|
|||
}
|
||||
|
||||
if (log)
|
||||
log->Printf(" \"%s\" (\"%s\") placed at %" PRId64,
|
||||
log->Printf(" \"%s\" (\"%s\") placed at %" PRIu64,
|
||||
name.GetCString(),
|
||||
decl->getNameAsString().c_str(),
|
||||
offset);
|
||||
|
|
|
@ -322,14 +322,14 @@ ObjectFileJIT::SetLoadAddress (Target &target,
|
|||
|
||||
size_t
|
||||
ObjectFileJIT::ReadSectionData (const lldb_private::Section *section,
|
||||
off_t section_offset,
|
||||
lldb::offset_t section_offset,
|
||||
void *dst,
|
||||
size_t dst_len) const
|
||||
{
|
||||
lldb::offset_t file_size = section->GetFileSize();
|
||||
if (section_offset < static_cast<off_t>(file_size))
|
||||
if (section_offset < file_size)
|
||||
{
|
||||
uint64_t src_len = file_size - section_offset;
|
||||
size_t src_len = file_size - section_offset;
|
||||
if (src_len > dst_len)
|
||||
src_len = dst_len;
|
||||
const uint8_t *src = ((uint8_t *)(uintptr_t)section->GetFileOffset()) + section_offset;
|
||||
|
@ -339,6 +339,7 @@ ObjectFileJIT::ReadSectionData (const lldb_private::Section *section,
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t
|
||||
ObjectFileJIT::ReadSectionData (const lldb_private::Section *section,
|
||||
lldb_private::DataExtractor& section_data) const
|
||||
|
|
|
@ -108,7 +108,7 @@ public:
|
|||
|
||||
virtual size_t
|
||||
ReadSectionData (const lldb_private::Section *section,
|
||||
off_t section_offset,
|
||||
lldb::offset_t section_offset,
|
||||
void *dst,
|
||||
size_t dst_len) const;
|
||||
virtual size_t
|
||||
|
|
|
@ -680,32 +680,32 @@ GDBRemoteRegisterContext::WriteAllRegisterValues (const lldb::DataBufferSP &data
|
|||
// If the slice registers are not included, then using the byte_offset values into the
|
||||
// data buffer is the best way to find individual register values.
|
||||
|
||||
int size_including_slice_registers = 0;
|
||||
int size_not_including_slice_registers = 0;
|
||||
int size_by_highest_offset = 0;
|
||||
uint64_t size_including_slice_registers = 0;
|
||||
uint64_t size_not_including_slice_registers = 0;
|
||||
uint64_t size_by_highest_offset = 0;
|
||||
|
||||
for (uint32_t reg_idx=0; (reg_info = GetRegisterInfoAtIndex (reg_idx)) != NULL; ++reg_idx)
|
||||
{
|
||||
size_including_slice_registers += reg_info->byte_size;
|
||||
if (reg_info->value_regs == NULL)
|
||||
size_not_including_slice_registers += reg_info->byte_size;
|
||||
if (static_cast<off_t>(reg_info->byte_offset) >= size_by_highest_offset)
|
||||
if (reg_info->byte_offset >= size_by_highest_offset)
|
||||
size_by_highest_offset = reg_info->byte_offset + reg_info->byte_size;
|
||||
}
|
||||
|
||||
bool use_byte_offset_into_buffer;
|
||||
if (static_cast<size_t>(size_by_highest_offset) == restore_data.GetByteSize())
|
||||
if (size_by_highest_offset == restore_data.GetByteSize())
|
||||
{
|
||||
// The size of the packet agrees with the highest offset: + size in the register file
|
||||
use_byte_offset_into_buffer = true;
|
||||
}
|
||||
else if (static_cast<size_t>(size_not_including_slice_registers) == restore_data.GetByteSize())
|
||||
else if (size_not_including_slice_registers == restore_data.GetByteSize())
|
||||
{
|
||||
// The size of the packet is the same as concatenating all of the registers sequentially,
|
||||
// skipping the slice registers
|
||||
use_byte_offset_into_buffer = true;
|
||||
}
|
||||
else if (static_cast<size_t>(size_including_slice_registers) == restore_data.GetByteSize())
|
||||
else if (size_including_slice_registers == restore_data.GetByteSize())
|
||||
{
|
||||
// The slice registers are present in the packet (when they shouldn't be).
|
||||
// Don't try to use the RegisterInfo byte_offset into the restore_data, it will
|
||||
|
|
|
@ -439,7 +439,7 @@ ObjectFile::ReadMemory (const ProcessSP &process_sp, lldb::addr_t addr, size_t b
|
|||
}
|
||||
|
||||
size_t
|
||||
ObjectFile::GetData (off_t offset, size_t length, DataExtractor &data) const
|
||||
ObjectFile::GetData (lldb::offset_t offset, size_t length, DataExtractor &data) const
|
||||
{
|
||||
// The entire file has already been mmap'ed into m_data, so just copy from there
|
||||
// as the back mmap buffer will be shared with shared pointers.
|
||||
|
@ -447,7 +447,7 @@ ObjectFile::GetData (off_t offset, size_t length, DataExtractor &data) const
|
|||
}
|
||||
|
||||
size_t
|
||||
ObjectFile::CopyData (off_t offset, size_t length, void *dst) const
|
||||
ObjectFile::CopyData (lldb::offset_t offset, size_t length, void *dst) const
|
||||
{
|
||||
// The entire file has already been mmap'ed into m_data, so just copy from there
|
||||
// Note that the data remains in target byte order.
|
||||
|
@ -456,7 +456,7 @@ ObjectFile::CopyData (off_t offset, size_t length, void *dst) const
|
|||
|
||||
|
||||
size_t
|
||||
ObjectFile::ReadSectionData (const Section *section, off_t section_offset, void *dst, size_t dst_len) const
|
||||
ObjectFile::ReadSectionData (const Section *section, lldb::offset_t section_offset, void *dst, size_t dst_len) const
|
||||
{
|
||||
// If some other objectfile owns this data, pass this to them.
|
||||
if (section->GetObjectFile() != this)
|
||||
|
@ -475,11 +475,11 @@ ObjectFile::ReadSectionData (const Section *section, off_t section_offset, void
|
|||
}
|
||||
else
|
||||
{
|
||||
const uint64_t section_file_size = section->GetFileSize();
|
||||
if (section_offset < static_cast<off_t>(section_file_size))
|
||||
const lldb::offset_t section_file_size = section->GetFileSize();
|
||||
if (section_offset < section_file_size)
|
||||
{
|
||||
const uint64_t section_bytes_left = section_file_size - section_offset;
|
||||
uint64_t section_dst_len = dst_len;
|
||||
const size_t section_bytes_left = section_file_size - section_offset;
|
||||
size_t section_dst_len = dst_len;
|
||||
if (section_dst_len > section_bytes_left)
|
||||
section_dst_len = section_bytes_left;
|
||||
return CopyData (section->GetFileOffset() + section_offset, section_dst_len, dst);
|
||||
|
|
|
@ -132,9 +132,9 @@ PathMappingList::Replace (const ConstString &path,
|
|||
}
|
||||
|
||||
bool
|
||||
PathMappingList::Remove (off_t index, bool notify)
|
||||
PathMappingList::Remove (size_t index, bool notify)
|
||||
{
|
||||
if (static_cast<size_t>(index) >= m_pairs.size())
|
||||
if (index >= m_pairs.size())
|
||||
return false;
|
||||
|
||||
++m_mod_id;
|
||||
|
|
Loading…
Reference in New Issue